svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r22935:23022
[blender.git] / source / blender / editors / space_info / space_info.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. 
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2008 Blender Foundation.
21  * All rights reserved.
22  *
23  * 
24  * Contributor(s): Blender Foundation
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 #include <string.h>
30 #include <stdio.h>
31
32 #include "DNA_object_types.h"
33 #include "DNA_space_types.h"
34 #include "DNA_scene_types.h"
35 #include "DNA_screen_types.h"
36
37 #include "MEM_guardedalloc.h"
38
39 #include "BLI_blenlib.h"
40 #include "BLI_arithb.h"
41 #include "BLI_rand.h"
42
43 #include "BKE_context.h"
44 #include "BKE_colortools.h"
45 #include "BKE_screen.h"
46 #include "BKE_utildefines.h"
47
48 #include "ED_space_api.h"
49 #include "ED_screen.h"
50
51 #include "BIF_gl.h"
52
53 #include "WM_api.h"
54 #include "WM_types.h"
55
56 #include "UI_interface.h"
57 #include "UI_resources.h"
58 #include "UI_view2d.h"
59
60 #include "ED_markers.h"
61 #include "ED_object.h"
62
63 #include "info_intern.h"        // own include
64
65 /* ******************** default callbacks for info space ***************** */
66
67 static SpaceLink *info_new(const bContext *C)
68 {
69         ARegion *ar;
70         SpaceInfo *sinfo;
71         
72         sinfo= MEM_callocN(sizeof(SpaceInfo), "initinfo");
73         sinfo->spacetype= SPACE_INFO;
74         
75         /* header */
76         ar= MEM_callocN(sizeof(ARegion), "header for info");
77         
78         BLI_addtail(&sinfo->regionbase, ar);
79         ar->regiontype= RGN_TYPE_HEADER;
80         ar->alignment= RGN_ALIGN_BOTTOM;
81         
82         /* main area */
83         ar= MEM_callocN(sizeof(ARegion), "main area for info");
84         
85         BLI_addtail(&sinfo->regionbase, ar);
86         ar->regiontype= RGN_TYPE_WINDOW;
87         
88         return (SpaceLink *)sinfo;
89 }
90
91 /* not spacelink itself */
92 static void info_free(SpaceLink *sl)
93 {       
94 //      SpaceInfo *sinfo= (SpaceInfo*) sl;
95         
96 }
97
98
99 /* spacetype; init callback */
100 static void info_init(struct wmWindowManager *wm, ScrArea *sa)
101 {
102
103 }
104
105 static SpaceLink *info_duplicate(SpaceLink *sl)
106 {
107         SpaceInfo *sinfon= MEM_dupallocN(sl);
108         
109         /* clear or remove stuff from old */
110         
111         return (SpaceLink *)sinfon;
112 }
113
114
115
116 /* add handlers, stuff you only do once or on area/region changes */
117 static void info_main_area_init(wmWindowManager *wm, ARegion *ar)
118 {
119         ED_region_panels_init(wm, ar);
120 }
121
122 static void info_main_area_draw(const bContext *C, ARegion *ar)
123 {
124         ED_region_panels(C, ar, 1, NULL, -1);
125 }
126
127 void info_operatortypes(void)
128 {
129         WM_operatortype_append(FILE_OT_pack_all);
130         WM_operatortype_append(FILE_OT_unpack_all);
131         WM_operatortype_append(FILE_OT_make_paths_relative);
132         WM_operatortype_append(FILE_OT_make_paths_absolute);
133         WM_operatortype_append(FILE_OT_report_missing_files);
134         WM_operatortype_append(FILE_OT_find_missing_files);
135 }
136
137 void info_keymap(struct wmWindowManager *wm)
138 {
139         
140 }
141
142 /* add handlers, stuff you only do once or on area/region changes */
143 static void info_header_area_init(wmWindowManager *wm, ARegion *ar)
144 {
145         ED_region_header_init(ar);
146 }
147
148 static void info_header_area_draw(const bContext *C, ARegion *ar)
149 {
150         ED_region_header(C, ar);
151 }
152
153 static void info_main_area_listener(ARegion *ar, wmNotifier *wmn)
154 {
155         /* context changes */
156 }
157
158 static void info_header_listener(ARegion *ar, wmNotifier *wmn)
159 {
160         /* context changes */
161         switch(wmn->category) {
162                 case NC_SCREEN:
163                         if(ELEM(wmn->data, ND_SCREENCAST, ND_ANIMPLAY))
164                                 ED_region_tag_redraw(ar);
165                         break;
166                 case NC_SCENE:
167                         if(wmn->data==ND_RENDER_RESULT)
168                                 ED_region_tag_redraw(ar);
169                         break;
170                 case NC_SPACE:  
171                         if(wmn->data == ND_SPACE_INFO)
172                                 ED_region_tag_redraw(ar);
173                         break;
174         }
175         
176 }
177
178 /* only called once, from space/spacetypes.c */
179 void ED_spacetype_info(void)
180 {
181         SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype info");
182         ARegionType *art;
183         
184         st->spaceid= SPACE_INFO;
185         
186         st->new= info_new;
187         st->free= info_free;
188         st->init= info_init;
189         st->duplicate= info_duplicate;
190         st->operatortypes= info_operatortypes;
191         st->keymap= info_keymap;
192         
193         /* regions: main window */
194         art= MEM_callocN(sizeof(ARegionType), "spacetype info region");
195         art->regionid = RGN_TYPE_WINDOW;
196         art->init= info_main_area_init;
197         art->draw= info_main_area_draw;
198         art->listener= info_main_area_listener;
199         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
200
201         BLI_addhead(&st->regiontypes, art);
202         
203         /* regions: header */
204         art= MEM_callocN(sizeof(ARegionType), "spacetype info region");
205         art->regionid = RGN_TYPE_HEADER;
206         art->minsizey= HEADERY;
207         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
208         art->listener= info_header_listener;
209         art->init= info_header_area_init;
210         art->draw= info_header_area_draw;
211         
212         BLI_addhead(&st->regiontypes, art);
213         
214         
215         BKE_spacetype_register(st);
216 }
217