svn merge -r 30566:30717 https://svn.blender.org/svnroot/bf-blender/trunk/blender
[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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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
33 #include "MEM_guardedalloc.h"
34
35 #include "BLI_blenlib.h"
36 #include "BLI_math.h"
37 #include "BLI_rand.h"
38
39 #include "BKE_context.h"
40 #include "BKE_colortools.h"
41 #include "BKE_global.h"
42 #include "BKE_screen.h"
43 #include "BKE_utildefines.h"
44
45 #include "ED_screen.h"
46
47 #include "BIF_gl.h"
48
49 #include "WM_api.h"
50 #include "WM_types.h"
51
52 #include "UI_resources.h"
53 #include "UI_interface.h"
54
55
56 #include "info_intern.h"        // own include
57
58 /* ******************** default callbacks for info space ***************** */
59
60 static SpaceLink *info_new(const bContext *C)
61 {
62         ARegion *ar;
63         SpaceInfo *sinfo;
64         
65         sinfo= MEM_callocN(sizeof(SpaceInfo), "initinfo");
66         sinfo->spacetype= SPACE_INFO;
67         
68         /* header */
69         ar= MEM_callocN(sizeof(ARegion), "header for info");
70         
71         BLI_addtail(&sinfo->regionbase, ar);
72         ar->regiontype= RGN_TYPE_HEADER;
73         ar->alignment= RGN_ALIGN_BOTTOM;
74         
75         /* main area */
76         ar= MEM_callocN(sizeof(ARegion), "main area for info");
77         
78         BLI_addtail(&sinfo->regionbase, ar);
79         ar->regiontype= RGN_TYPE_WINDOW;
80         
81         return (SpaceLink *)sinfo;
82 }
83
84 /* not spacelink itself */
85 static void info_free(SpaceLink *sl)
86 {       
87 //      SpaceInfo *sinfo= (SpaceInfo*) sl;
88         
89 }
90
91
92 /* spacetype; init callback */
93 static void info_init(struct wmWindowManager *wm, ScrArea *sa)
94 {
95
96 }
97
98 static SpaceLink *info_duplicate(SpaceLink *sl)
99 {
100         SpaceInfo *sinfon= MEM_dupallocN(sl);
101         
102         /* clear or remove stuff from old */
103         
104         return (SpaceLink *)sinfon;
105 }
106
107
108
109 /* add handlers, stuff you only do once or on area/region changes */
110 static void info_main_area_init(wmWindowManager *wm, ARegion *ar)
111 {
112 }
113
114 static void info_main_area_draw(const bContext *C, ARegion *ar)
115 {
116         
117         /* clear and setup matrix */
118         UI_ThemeClearColor(TH_BACK);
119         glClear(GL_COLOR_BUFFER_BIT);
120 }
121
122 void info_operatortypes(void)
123 {
124         WM_operatortype_append(FILE_OT_pack_all);
125         WM_operatortype_append(FILE_OT_unpack_all);
126         WM_operatortype_append(FILE_OT_make_paths_relative);
127         WM_operatortype_append(FILE_OT_make_paths_absolute);
128         WM_operatortype_append(FILE_OT_report_missing_files);
129         WM_operatortype_append(FILE_OT_find_missing_files);
130         
131         WM_operatortype_append(INFO_OT_reports_display_update);
132 }
133
134 void info_keymap(struct wmKeyConfig *keyconf)
135 {
136         wmKeyMap *keymap= WM_keymap_find(keyconf, "Window", 0, 0);
137         
138         WM_keymap_verify_item(keymap, "INFO_OT_reports_display_update", TIMER, KM_ANY, KM_ANY, 0);
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_WM:     
166                         if(wmn->data == ND_JOB)
167                                 ED_region_tag_redraw(ar);
168                         break;
169                 case NC_SCENE:
170                         if(wmn->data==ND_RENDER_RESULT)
171                                 ED_region_tag_redraw(ar);
172                         break;
173                 case NC_SPACE:  
174                         if(wmn->data == ND_SPACE_INFO)
175                                 ED_region_tag_redraw(ar);
176                         break;
177                 case NC_ID:
178                         if(wmn->action == NA_RENAME)
179                                 ED_region_tag_redraw(ar);
180         }
181         
182 }
183
184 static void recent_files_menu(const bContext *C, Menu *menu)
185 {
186         struct RecentFile *recent;
187         uiLayout *layout= menu->layout;
188         uiLayoutSetOperatorContext(layout, WM_OP_EXEC_REGION_WIN);
189         if (G.recent_files.first) {
190                 for(recent = G.recent_files.first; (recent); recent = recent->next) {
191                         uiItemStringO(layout, BLI_path_basename(recent->filepath), ICON_FILE_BLEND, "WM_OT_open_mainfile", "filepath", recent->filepath);
192                 }
193         } else {
194                 uiItemL(layout, "No Recent Files", 0);
195         }
196 }
197
198 void recent_files_menu_register()
199 {
200         MenuType *mt;
201
202         mt= MEM_callocN(sizeof(MenuType), "spacetype info menu recent files");
203         strcpy(mt->idname, "INFO_MT_file_open_recent");
204         strcpy(mt->label, "Open Recent...");
205         mt->draw= recent_files_menu;
206         WM_menutype_add(mt);
207 }
208
209 /* only called once, from space/spacetypes.c */
210 void ED_spacetype_info(void)
211 {
212         SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype info");
213         ARegionType *art;
214         
215         st->spaceid= SPACE_INFO;
216         strncpy(st->name, "Info", BKE_ST_MAXNAME);
217         
218         st->new= info_new;
219         st->free= info_free;
220         st->init= info_init;
221         st->duplicate= info_duplicate;
222         st->operatortypes= info_operatortypes;
223         st->keymap= info_keymap;
224         
225         /* regions: main window */
226         art= MEM_callocN(sizeof(ARegionType), "spacetype info region");
227         art->regionid = RGN_TYPE_WINDOW;
228         art->init= info_main_area_init;
229         art->draw= info_main_area_draw;
230         art->listener= info_main_area_listener;
231         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
232
233         BLI_addhead(&st->regiontypes, art);
234         
235         /* regions: header */
236         art= MEM_callocN(sizeof(ARegionType), "spacetype info region");
237         art->regionid = RGN_TYPE_HEADER;
238         art->prefsizey= HEADERY;
239         
240         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_FRAMES|ED_KEYMAP_HEADER;
241         art->listener= info_header_listener;
242         art->init= info_header_area_init;
243         art->draw= info_header_area_draw;
244         
245         BLI_addhead(&st->regiontypes, art);
246         
247         recent_files_menu_register();
248
249         BKE_spacetype_register(st);
250 }
251