Blender 2.5 project: added first more complex handler + operator
[blender-staging.git] / source / blender / windowmanager / intern / wm_operators.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) 2007 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
31 #include "DNA_windowmanager_types.h"
32
33 #include "MEM_guardedalloc.h"
34
35 #include "BLI_blenlib.h"
36
37 #include "BKE_blender.h"
38 #include "BKE_global.h"
39 #include "BKE_library.h"
40 #include "BKE_main.h"
41
42 #include "WM_api.h"
43 #include "WM_types.h"
44 #include "wm_window.h"
45 #include "wm_event_system.h"
46
47 static ListBase global_ops= {NULL, NULL};
48
49 /* ************ operator API, exported ********** */
50
51 wmOperatorType *WM_operatortype_find(const char *idname)
52 {
53         wmOperatorType *ot;
54         
55         for(ot= global_ops.first; ot; ot= ot->next) {
56                 if(strncmp(ot->idname, idname, OP_MAX_TYPENAME)==0)
57                    return ot;
58         }
59         return NULL;
60 }
61
62 /* all ops in 1 list (for time being... needs evaluation later) */
63 void WM_operatortypelist_append(ListBase *lb)
64 {
65         addlisttolist(&global_ops, lb);
66 }
67
68 /* ************ default ops, exported *********** */
69
70 int WM_operator_confirm(bContext *C, wmOperator *op, wmEvent *event)
71 {
72 //      if(okee(op->type->name)) {
73 //              return op->type->exec(C, op);
74 //      }
75         return 0;
76 }
77 int WM_operator_winactive(bContext *C)
78 {
79         if(C->window==NULL) return 0;
80         return 1;
81 }
82
83 /* ************ window / screen operator definitions ************** */
84
85 static void WM_OT_window_duplicate(wmOperatorType *ot)
86 {
87         ot->name= "Duplicate Window";
88         ot->idname= "WM_OT_window_duplicate";
89         
90         ot->invoke= NULL; //WM_operator_confirm;
91         ot->exec= wm_window_duplicate_op;
92         ot->poll= WM_operator_winactive;
93 }
94
95 static void WM_OT_save_homefile(wmOperatorType *ot)
96 {
97         ot->name= "Save User Settings";
98         ot->idname= "WM_OT_save_homefile";
99         
100         ot->invoke= NULL; //WM_operator_confirm;
101         ot->exec= WM_write_homefile;
102         ot->poll= WM_operator_winactive;
103         
104         ot->flag= OPTYPE_REGISTER;
105 }
106
107 static void WM_OT_window_fullscreen_toggle(wmOperatorType *ot)
108 {
109     ot->name= "Toggle Fullscreen";
110     ot->idname= "WM_OT_window_fullscreen_toggle";
111
112     ot->invoke= NULL;
113     ot->exec= wm_window_fullscreen_toggle_op;
114     ot->poll= WM_operator_winactive;
115 }
116
117
118 #define ADD_OPTYPE(opfunc)      ot= MEM_callocN(sizeof(wmOperatorType), "operatortype"); \
119                                                         opfunc(ot);  \
120                                                         BLI_addtail(&global_ops, ot)
121
122
123 /* called on initialize WM_exit() */
124 void wm_operatortype_free(void)
125 {
126         BLI_freelistN(&global_ops);
127 }
128
129 /* called on initialize WM_init() */
130 void wm_operatortype_init(void)
131 {
132         wmOperatorType *ot;
133         
134         ADD_OPTYPE(WM_OT_window_duplicate);
135         ADD_OPTYPE(WM_OT_save_homefile);
136     ADD_OPTYPE(WM_OT_window_fullscreen_toggle);
137 }
138
139
140
141
142