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) 2007 Blender Foundation.
21 * All rights reserved.
24 * Contributor(s): Blender Foundation
26 * ***** END GPL LICENSE BLOCK *****
29 #include "DNA_windowmanager_types.h"
31 #include "MEM_guardedalloc.h"
33 #include "GHOST_C-api.h"
35 #include "BLI_blenlib.h"
37 #include "BKE_blender.h"
38 #include "BKE_context.h"
39 #include "BKE_idprop.h"
40 #include "BKE_library.h"
42 #include "BKE_report.h"
46 #include "wm_window.h"
47 #include "wm_event_system.h"
48 #include "wm_event_types.h"
52 #include "ED_screen.h"
54 #include "RNA_types.h"
56 /* ****************************************************** */
58 #define MAX_OP_REGISTERED 32
60 void WM_operator_free(wmOperator *op)
63 op->properties= op->ptr->data;
68 IDP_FreeProperty(op->properties);
69 MEM_freeN(op->properties);
73 BKE_reports_clear(op->reports);
74 MEM_freeN(op->reports);
80 /* all operations get registered in the windowmanager here */
81 /* called on event handling by event_system.c */
82 void wm_operator_register(bContext *C, wmOperator *op)
84 wmWindowManager *wm= CTX_wm_manager(C);
88 BLI_addtail(&wm->operators, op);
89 tot= BLI_countlist(&wm->operators);
91 while(tot>MAX_OP_REGISTERED) {
92 wmOperator *opt= wm->operators.first;
93 BLI_remlink(&wm->operators, opt);
94 WM_operator_free(opt);
99 /* Report the string representation of the operator */
100 buf = WM_operator_pystring(op);
101 BKE_report(wm->reports, RPT_OPERATOR, buf);
104 /* so the console is redrawn */
105 WM_event_add_notifier(C, NC_CONSOLE|ND_CONSOLE_REPORT, NULL);
109 void WM_operator_stack_clear(bContext *C)
111 wmWindowManager *wm= CTX_wm_manager(C);
114 while((op= wm->operators.first)) {
115 BLI_remlink(&wm->operators, op);
116 WM_operator_free(op);
121 /* ****************************************** */
123 void wm_check(bContext *C)
125 wmWindowManager *wm= CTX_wm_manager(C);
129 wm= CTX_data_main(C)->wm.first;
130 CTX_wm_manager_set(C, wm);
133 if(wm->windows.first==NULL) return;
135 /* case: no open windows at all, for old file reads */
136 wm_window_add_ghostwindows(wm);
139 if(wm->initialized==0) {
141 wm_window_keymap(wm);
142 ED_spacetypes_keymap(wm);
144 ED_screens_initialize(wm);
149 void wm_clear_default_size(bContext *C)
151 wmWindowManager *wm= CTX_wm_manager(C);
156 wm= CTX_data_main(C)->wm.first;
157 CTX_wm_manager_set(C, wm);
160 if(wm->windows.first==NULL) return;
162 for(win= wm->windows.first; win; win= win->next) {
171 /* on startup, it adds all data, for matching */
172 void wm_add_default(bContext *C)
174 wmWindowManager *wm= alloc_libblock(&CTX_data_main(C)->wm, ID_WM, "WinMan");
176 bScreen *screen= CTX_wm_screen(C); /* XXX from file read hrmf */
178 CTX_wm_manager_set(C, wm);
179 win= wm_window_new(C);
181 screen->winid= win->winid;
182 BLI_strncpy(win->screenname, screen->id.name+2, 21);
186 wm_window_make_drawable(C, win);
190 /* context is allowed to be NULL, do not free wm itself (library.c) */
191 void wm_close_and_free(bContext *C, wmWindowManager *wm)
198 while((win= wm->windows.first)) {
199 BLI_remlink(&wm->windows, win);
200 win->screen= NULL; /* prevent draw clear to use screen */
201 wm_draw_window_clear(win);
202 wm_window_free(C, win);
205 while((op= wm->operators.first)) {
206 BLI_remlink(&wm->operators, op);
207 WM_operator_free(op);
210 while((km= wm->keymaps.first)) {
211 for(kmi=km->keymap.first; kmi; kmi=kmi->next) {
213 WM_operator_properties_free(kmi->ptr);
218 BLI_freelistN(&km->keymap);
219 BLI_remlink(&wm->keymaps, km);
223 BLI_freelistN(&wm->queue);
225 BLI_freelistN(&wm->paintcursors);
227 if(C && CTX_wm_manager(C)==wm) CTX_wm_manager_set(C, NULL);
230 void wm_close_and_free_all(bContext *C, ListBase *wmlist)
234 while((wm=wmlist->first)) {
235 wm_close_and_free(C, wm);
236 BLI_remlink(wmlist, wm);
241 void WM_main(bContext *C)
245 /* get events from ghost, handle window events, add to window queues */
246 wm_window_process_events(C);
248 /* per window, all events to the window, screen, area and region handlers */
249 wm_event_do_handlers(C);
251 /* events have left notes about changes, we handle and cache it */
252 wm_event_do_notifiers(C);
254 /* execute cached changes draw */