4 * ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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.
20 * The Original Code is Copyright (C) 2008 Blender Foundation.
21 * All rights reserved.
24 * Contributor(s): Blender Foundation
26 * ***** END GPL LICENSE BLOCK *****
32 #include "DNA_object_types.h"
33 #include "DNA_space_types.h"
34 #include "DNA_scene_types.h"
35 #include "DNA_screen_types.h"
37 #include "MEM_guardedalloc.h"
39 #include "BLO_readfile.h"
41 #include "BLI_blenlib.h"
42 #include "BLI_arithb.h"
45 #include "BKE_colortools.h"
46 #include "BKE_context.h"
47 #include "BKE_screen.h"
49 #include "ED_space_api.h"
50 #include "ED_screen.h"
57 #include "UI_interface.h"
58 #include "UI_resources.h"
59 #include "UI_view2d.h"
61 #include "ED_markers.h"
63 #include "file_intern.h" // own include
65 /* ******************** default callbacks for file space ***************** */
67 static SpaceLink *file_new(void)
72 sfile= MEM_callocN(sizeof(SpaceFile), "initfile");
73 sfile->spacetype= SPACE_FILE;
76 sfile->type= FILE_UNIX;
79 ar= MEM_callocN(sizeof(ARegion), "header for file");
81 BLI_addtail(&sfile->regionbase, ar);
82 ar->regiontype= RGN_TYPE_HEADER;
83 ar->alignment= RGN_ALIGN_BOTTOM;
86 ar= MEM_callocN(sizeof(ARegion), "main area for file");
88 BLI_addtail(&sfile->regionbase, ar);
89 ar->regiontype= RGN_TYPE_WINDOW;
91 /* channel list region XXX */
94 return (SpaceLink *)sfile;
97 /* not spacelink itself */
98 static void file_free(SpaceLink *sl)
100 SpaceFile *sfile= (SpaceFile *) sl;
102 if(sfile->libfiledata)
103 BLO_blendhandle_close(sfile->libfiledata);
107 MEM_freeN(sfile->pupmenu);
112 /* spacetype; init callback */
113 static void file_init(struct wmWindowManager *wm, ScrArea *sa)
118 static SpaceLink *file_duplicate(SpaceLink *sl)
120 SpaceFile *sfilen= MEM_dupallocN(sl);
122 /* clear or remove stuff from old */
124 return (SpaceLink *)sfilen;
129 /* add handlers, stuff you only do once or on area/region changes */
130 static void file_main_area_init(wmWindowManager *wm, ARegion *ar)
134 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_LIST, ar->winx, ar->winy);
137 keymap= WM_keymap_listbase(wm, "File", SPACE_FILE, 0); /* XXX weak? */
138 WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
141 static void file_main_area_draw(const bContext *C, ARegion *ar)
143 /* draw entirely, view changes should be handled here */
144 // SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
145 View2D *v2d= &ar->v2d;
148 /* clear and setup matrix */
149 UI_GetThemeColor3fv(TH_BACK, col);
150 glClearColor(col[0], col[1], col[2], 0.0);
151 glClear(GL_COLOR_BUFFER_BIT);
153 UI_view2d_view_ortho(C, v2d);
158 /* reset view matrix */
159 UI_view2d_view_restore(C);
164 void file_operatortypes(void)
169 void file_keymap(struct wmWindowManager *wm)
174 /* add handlers, stuff you only do once or on area/region changes */
175 static void file_header_area_init(wmWindowManager *wm, ARegion *ar)
177 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy);
180 static void file_header_area_draw(const bContext *C, ARegion *ar)
185 if(ED_screen_area_active(C))
186 UI_GetThemeColor3fv(TH_HEADER, col);
188 UI_GetThemeColor3fv(TH_HEADERDESEL, col);
190 glClearColor(col[0], col[1], col[2], 0.0);
191 glClear(GL_COLOR_BUFFER_BIT);
193 /* set view2d view matrix for scrolling (without scrollers) */
194 UI_view2d_view_ortho(C, &ar->v2d);
196 file_header_buttons(C, ar);
198 /* restore view matrix? */
199 UI_view2d_view_restore(C);
202 static void file_main_area_listener(ARegion *ar, wmNotifier *wmn)
204 /* context changes */
207 /* only called once, from space/spacetypes.c */
208 void ED_spacetype_file(void)
210 SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype file");
213 st->spaceid= SPACE_FILE;
218 st->duplicate= file_duplicate;
219 st->operatortypes= file_operatortypes;
220 st->keymap= file_keymap;
222 /* regions: main window */
223 art= MEM_callocN(sizeof(ARegionType), "spacetype file region");
224 art->regionid = RGN_TYPE_WINDOW;
225 art->init= file_main_area_init;
226 art->draw= file_main_area_draw;
227 art->listener= file_main_area_listener;
228 art->keymapflag= ED_KEYMAP_VIEW2D;
230 BLI_addhead(&st->regiontypes, art);
232 /* regions: header */
233 art= MEM_callocN(sizeof(ARegionType), "spacetype file region");
234 art->regionid = RGN_TYPE_HEADER;
235 art->minsizey= HEADERY;
236 art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
238 art->init= file_header_area_init;
239 art->draw= file_header_area_draw;
241 BLI_addhead(&st->regiontypes, art);
243 /* regions: channels */
244 art= MEM_callocN(sizeof(ARegionType), "spacetype file region");
245 art->regionid = RGN_TYPE_CHANNELS;
247 art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
249 // art->init= file_channel_area_init;
250 // art->draw= file_channel_area_draw;
252 BLI_addhead(&st->regiontypes, art);
255 BKE_spacetype_register(st);