Merge with 2.5 -r 21756:22173.
[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
62 #include "info_intern.h"        // own include
63
64 /* ******************** default callbacks for info space ***************** */
65
66 static SpaceLink *info_new(const bContext *C)
67 {
68         ARegion *ar;
69         SpaceInfo *sinfo;
70         
71         sinfo= MEM_callocN(sizeof(SpaceInfo), "initinfo");
72         sinfo->spacetype= SPACE_INFO;
73         
74         /* header */
75         ar= MEM_callocN(sizeof(ARegion), "header for info");
76         
77         BLI_addtail(&sinfo->regionbase, ar);
78         ar->regiontype= RGN_TYPE_HEADER;
79         ar->alignment= RGN_ALIGN_BOTTOM;
80         
81         /* main area */
82         ar= MEM_callocN(sizeof(ARegion), "main area for info");
83         
84         BLI_addtail(&sinfo->regionbase, ar);
85         ar->regiontype= RGN_TYPE_WINDOW;
86         
87         return (SpaceLink *)sinfo;
88 }
89
90 /* not spacelink itself */
91 static void info_free(SpaceLink *sl)
92 {       
93 //      SpaceInfo *sinfo= (SpaceInfo*) sl;
94         
95 }
96
97
98 /* spacetype; init callback */
99 static void info_init(struct wmWindowManager *wm, ScrArea *sa)
100 {
101
102 }
103
104 static SpaceLink *info_duplicate(SpaceLink *sl)
105 {
106         SpaceInfo *sinfon= MEM_dupallocN(sl);
107         
108         /* clear or remove stuff from old */
109         
110         return (SpaceLink *)sinfon;
111 }
112
113
114
115 /* add handlers, stuff you only do once or on area/region changes */
116 static void info_main_area_init(wmWindowManager *wm, ARegion *ar)
117 {
118         ED_region_panels_init(wm, ar);
119 }
120
121 static void info_main_area_draw(const bContext *C, ARegion *ar)
122 {
123         ED_region_panels(C, ar, 1, NULL, -1);
124 }
125
126 void info_operatortypes(void)
127 {
128         WM_operatortype_append(FILE_OT_pack_all);
129         WM_operatortype_append(FILE_OT_unpack_all);
130         WM_operatortype_append(FILE_OT_make_paths_relative);
131         WM_operatortype_append(FILE_OT_make_paths_absolute);
132         WM_operatortype_append(FILE_OT_report_missing_files);
133         WM_operatortype_append(FILE_OT_find_missing_files);
134 }
135
136 void info_keymap(struct wmWindowManager *wm)
137 {
138         
139 }
140
141 /* add handlers, stuff you only do once or on area/region changes */
142 static void info_header_area_init(wmWindowManager *wm, ARegion *ar)
143 {
144         ED_region_header_init(ar);
145 }
146
147 static void info_header_area_draw(const bContext *C, ARegion *ar)
148 {
149         ED_region_header(C, ar);
150 }
151
152 static void info_main_area_listener(ARegion *ar, wmNotifier *wmn)
153 {
154         /* context changes */
155 }
156
157 static void info_header_listener(ARegion *ar, wmNotifier *wmn)
158 {
159         /* context changes */
160         switch(wmn->category) {
161                 case NC_SCREEN:
162                         if(ELEM(wmn->data, ND_SCREENCAST, ND_ANIMPLAY))
163                                 ED_region_tag_redraw(ar);
164                         break;
165                 case NC_SCENE:
166                         if(wmn->data==ND_RENDER_RESULT)
167                                 ED_region_tag_redraw(ar);
168                         break;
169         }
170         
171 }
172
173 /* only called once, from space/spacetypes.c */
174 void ED_spacetype_info(void)
175 {
176         SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype info");
177         ARegionType *art;
178         
179         st->spaceid= SPACE_INFO;
180         
181         st->new= info_new;
182         st->free= info_free;
183         st->init= info_init;
184         st->duplicate= info_duplicate;
185         st->operatortypes= info_operatortypes;
186         st->keymap= info_keymap;
187         
188         /* regions: main window */
189         art= MEM_callocN(sizeof(ARegionType), "spacetype info region");
190         art->regionid = RGN_TYPE_WINDOW;
191         art->init= info_main_area_init;
192         art->draw= info_main_area_draw;
193         art->listener= info_main_area_listener;
194         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
195
196         BLI_addhead(&st->regiontypes, art);
197         
198         /* regions: header */
199         art= MEM_callocN(sizeof(ARegionType), "spacetype info region");
200         art->regionid = RGN_TYPE_HEADER;
201         art->minsizey= HEADERY;
202         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
203         art->listener= info_header_listener;
204         art->init= info_header_area_init;
205         art->draw= info_header_area_draw;
206         
207         BLI_addhead(&st->regiontypes, art);
208         
209         
210         BKE_spacetype_register(st);
211 }
212