a744d949e8172762d1819d64fd2fd546a7e4af77
[blender.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 /* ************ default ops, exported *********** */
63
64 int WM_operator_confirm(bContext *C, wmOperator *op, wmEvent *event)
65 {
66 //      if(okee(op->type->name)) {
67 //              return op->type->exec(C, op);
68 //      }
69         return 0;
70 }
71 int WM_operator_winactive(bContext *C)
72 {
73         if(C->window==NULL) return 0;
74         return 1;
75 }
76
77 /* ************ window / screen operator definitions ************** */
78
79 static void WM_OT_window_duplicate(wmOperatorType *ot)
80 {
81         ot->name= "Duplicate Window";
82         ot->idname= "WM_OT_window_duplicate";
83         
84         ot->interactive= NULL; //WM_operator_confirm;
85         ot->exec= wm_window_duplicate_op;
86         ot->poll= WM_operator_winactive;
87 }
88
89 static void WM_OT_save_homefile(wmOperatorType *ot)
90 {
91         ot->name= "Save User Settings";
92         ot->idname= "WM_OT_save_homefile";
93         
94         ot->interactive= NULL; //WM_operator_confirm;
95         ot->exec= WM_write_homefile;
96         ot->poll= WM_operator_winactive;
97         
98         ot->flag= OPTYPE_REGISTER;
99 }
100
101 static void WM_OT_window_fullscreen_toggle(wmOperatorType *ot)
102 {
103     ot->name= "Toggle Fullscreen";
104     ot->idname= "WM_OT_window_fullscreen_toggle";
105
106     ot->interactive= NULL;
107     ot->exec= wm_window_fullscreen_toggle_op;
108     ot->poll= WM_operator_winactive;
109 }
110
111
112
113 #define ADD_OPTYPE(opfunc)      ot= MEM_callocN(sizeof(wmOperatorType), "operatortype"); \
114                                                         opfunc(ot);  \
115                                                         BLI_addtail(&global_ops, ot)
116
117
118 /* called on initialize WM_exit() */
119 void wm_operatortype_free(void)
120 {
121         BLI_freelistN(&global_ops);
122 }
123
124 /* called on initialize WM_init() */
125 void wm_operatortype_init(void)
126 {
127         wmOperatorType *ot;
128         
129         ADD_OPTYPE(WM_OT_window_duplicate);
130         ADD_OPTYPE(WM_OT_save_homefile);
131     ADD_OPTYPE(WM_OT_window_fullscreen_toggle);
132 }
133
134