spacebar for the search menu was overriding space in the text editor
[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 <float.h>
30 #define _USE_MATH_DEFINES
31 #include <math.h>
32 #include <string.h>
33 #include <ctype.h>
34 #include <stdio.h>
35
36 #include "DNA_ID.h"
37 #include "DNA_screen_types.h"
38 #include "DNA_scene_types.h"
39 #include "DNA_userdef_types.h"
40 #include "DNA_windowmanager_types.h"
41
42 #include "MEM_guardedalloc.h"
43
44 #include "PIL_time.h"
45
46 #include "BLI_blenlib.h"
47 #include "BLI_dynstr.h" /*for WM_operator_pystring */
48
49 #include "BKE_blender.h"
50 #include "BKE_context.h"
51 #include "BKE_idprop.h"
52 #include "BKE_library.h"
53 #include "BKE_global.h"
54 #include "BKE_main.h"
55 #include "BKE_scene.h"
56 #include "BKE_utildefines.h"
57
58 #include "BIF_gl.h"
59 #include "BIF_glutil.h" /* for paint cursor */
60
61 #include "IMB_imbuf_types.h"
62
63 #include "ED_screen.h"
64 #include "ED_util.h"
65
66 #include "RNA_access.h"
67 #include "RNA_define.h"
68
69 #include "UI_interface.h"
70 #include "UI_resources.h"
71
72 #include "WM_api.h"
73 #include "WM_types.h"
74
75 #include "wm.h"
76 #include "wm_draw.h"
77 #include "wm_event_system.h"
78 #include "wm_subwindow.h"
79 #include "wm_window.h"
80
81
82
83 static ListBase global_ops= {NULL, NULL};
84
85 /* ************ operator API, exported ********** */
86
87
88 wmOperatorType *WM_operatortype_find(const char *idname, int quiet)
89 {
90         wmOperatorType *ot;
91         
92         char idname_bl[OP_MAX_TYPENAME]; // XXX, needed to support python style names without the _OT_ syntax
93         WM_operator_bl_idname(idname_bl, idname);
94
95         for(ot= global_ops.first; ot; ot= ot->next) {
96                 if(strncmp(ot->idname, idname_bl, OP_MAX_TYPENAME)==0)
97                    return ot;
98         }
99         
100         if(!quiet)
101                 printf("search for unknown operator %s, %s\n", idname_bl, idname);
102         
103         return NULL;
104 }
105
106 wmOperatorType *WM_operatortype_exists(const char *idname)
107 {
108         wmOperatorType *ot;
109         
110         char idname_bl[OP_MAX_TYPENAME]; // XXX, needed to support python style names without the _OT_ syntax
111         WM_operator_bl_idname(idname_bl, idname);
112
113         for(ot= global_ops.first; ot; ot= ot->next) {
114                 if(strncmp(ot->idname, idname_bl, OP_MAX_TYPENAME)==0)
115                    return ot;
116         }
117         return NULL;
118 }
119
120 wmOperatorType *WM_operatortype_first(void)
121 {
122         return global_ops.first;
123 }
124
125 /* all ops in 1 list (for time being... needs evaluation later) */
126 void WM_operatortype_append(void (*opfunc)(wmOperatorType*))
127 {
128         wmOperatorType *ot;
129         
130         ot= MEM_callocN(sizeof(wmOperatorType), "operatortype");
131         ot->srna= RNA_def_struct(&BLENDER_RNA, "", "OperatorProperties");
132         opfunc(ot);
133
134         if(ot->name==NULL) {
135                 static char dummy_name[] = "Dummy Name";
136                 fprintf(stderr, "ERROR: Operator %s has no name property!\n", ot->idname);
137                 ot->name= dummy_name;
138         }
139
140         RNA_def_struct_ui_text(ot->srna, ot->name, ot->description ? ot->description:"(undocumented operator)"); // XXX All ops should have a description but for now allow them not to.
141         RNA_def_struct_identifier(ot->srna, ot->idname);
142         BLI_addtail(&global_ops, ot);
143 }
144
145 void WM_operatortype_append_ptr(void (*opfunc)(wmOperatorType*, void*), void *userdata)
146 {
147         wmOperatorType *ot;
148
149         ot= MEM_callocN(sizeof(wmOperatorType), "operatortype");
150         ot->srna= RNA_def_struct(&BLENDER_RNA, "", "OperatorProperties");
151         opfunc(ot, userdata);
152         RNA_def_struct_ui_text(ot->srna, ot->name, ot->description ? ot->description:"(undocumented operator)");
153         RNA_def_struct_identifier(ot->srna, ot->idname);
154         BLI_addtail(&global_ops, ot);
155 }
156
157 /* ********************* macro operator ******************** */
158
159 /* macro exec only runs exec calls */
160 static int wm_macro_exec(bContext *C, wmOperator *op)
161 {
162         wmOperator *opm;
163         int retval= OPERATOR_FINISHED;
164         
165 //      printf("macro exec %s\n", op->type->idname);
166         
167         for(opm= op->macro.first; opm; opm= opm->next) {
168                 
169                 if(opm->type->exec) {
170 //                      printf("macro exec %s\n", opm->type->idname);
171                         retval= opm->type->exec(C, opm);
172                 
173                         if(!(retval & OPERATOR_FINISHED))
174                                 break;
175                 }
176         }
177 //      if(opm)
178 //              printf("macro ended not finished\n");
179 //      else
180 //              printf("macro end\n");
181         
182         return retval;
183 }
184
185 static int wm_macro_invoke(bContext *C, wmOperator *op, wmEvent *event)
186 {
187         wmOperator *opm;
188         int retval= OPERATOR_FINISHED;
189         
190 //      printf("macro invoke %s\n", op->type->idname);
191         
192         for(opm= op->macro.first; opm; opm= opm->next) {
193                 
194                 if(opm->type->invoke)
195                         retval= opm->type->invoke(C, opm, event);
196                 else if(opm->type->exec)
197                         retval= opm->type->exec(C, opm);
198                 
199                 if(!(retval & OPERATOR_FINISHED))
200                         break;
201         }
202         
203 //      if(opm)
204 //              printf("macro ended not finished\n");
205 //      else
206 //              printf("macro end\n");
207         
208         
209         return retval;
210 }
211
212 static int wm_macro_modal(bContext *C, wmOperator *op, wmEvent *event)
213 {
214 //      printf("macro modal %s\n", op->type->idname);
215         
216         if(op->opm==NULL)
217                 printf("macro error, calling NULL modal()\n");
218         else {
219 //              printf("macro modal %s\n", op->opm->type->idname);
220                 return op->opm->type->modal(C, op->opm, event);
221         }       
222         
223         return OPERATOR_FINISHED;
224 }
225
226 /* Names have to be static for now */
227 wmOperatorType *WM_operatortype_append_macro(char *idname, char *name, int flag)
228 {
229         wmOperatorType *ot;
230         
231         if(WM_operatortype_exists(idname)) {
232                 printf("Macro error: operator %s exists\n", idname);
233                 return NULL;
234         }
235         
236         ot= MEM_callocN(sizeof(wmOperatorType), "operatortype");
237         ot->srna= RNA_def_struct(&BLENDER_RNA, "", "OperatorProperties");
238         
239         ot->idname= idname;
240         ot->name= name;
241         ot->flag= OPTYPE_MACRO | flag;
242         
243         ot->exec= wm_macro_exec;
244         ot->invoke= wm_macro_invoke;
245         ot->modal= wm_macro_modal;
246         ot->poll= NULL;
247         
248         RNA_def_struct_ui_text(ot->srna, ot->name, ot->description ? ot->description:"(undocumented operator)"); // XXX All ops should have a description but for now allow them not to.
249         RNA_def_struct_identifier(ot->srna, ot->idname);
250
251         BLI_addtail(&global_ops, ot);
252
253         return ot;
254 }
255
256 wmOperatorTypeMacro *WM_operatortype_macro_define(wmOperatorType *ot, const char *idname)
257 {
258         wmOperatorTypeMacro *otmacro= MEM_callocN(sizeof(wmOperatorTypeMacro), "wmOperatorTypeMacro");
259         
260         BLI_strncpy(otmacro->idname, idname, OP_MAX_TYPENAME);
261
262         /* do this on first use, since operatordefinitions might have been not done yet */
263 //      otmacro->ptr= MEM_callocN(sizeof(PointerRNA), "optype macro ItemPtr");
264 //      WM_operator_properties_create(otmacro->ptr, idname);
265         
266         BLI_addtail(&ot->macro, otmacro);
267         
268         return otmacro;
269 }
270
271 static void wm_operatortype_free_macro(wmOperatorType *ot)
272 {
273         wmOperatorTypeMacro *otmacro;
274         
275         for(otmacro= ot->macro.first; otmacro; otmacro= otmacro->next) {
276                 if(otmacro->ptr) {
277                         WM_operator_properties_free(otmacro->ptr);
278                         MEM_freeN(otmacro->ptr);
279                 }
280         }
281         BLI_freelistN(&ot->macro);
282 }
283
284
285 int WM_operatortype_remove(const char *idname)
286 {
287         wmOperatorType *ot = WM_operatortype_find(idname, 0);
288
289         if (ot==NULL)
290                 return 0;
291         
292         BLI_remlink(&global_ops, ot);
293         RNA_struct_free(&BLENDER_RNA, ot->srna);
294         
295         if(ot->macro.first)
296                 wm_operatortype_free_macro(ot);
297         
298         MEM_freeN(ot);
299
300         return 1;
301 }
302
303 /* SOME_OT_op -> some.op */
304 void WM_operator_py_idname(char *to, const char *from)
305 {
306         char *sep= strstr(from, "_OT_");
307         if(sep) {
308                 int i, ofs= (sep-from);
309
310                 for(i=0; i<ofs; i++)
311                         to[i]= tolower(from[i]);
312
313                 to[ofs] = '.';
314                 BLI_strncpy(to+(ofs+1), sep+4, OP_MAX_TYPENAME);
315         }
316         else {
317                 /* should not happen but support just incase */
318                 BLI_strncpy(to, from, OP_MAX_TYPENAME);
319         }
320 }
321
322 /* some.op -> SOME_OT_op */
323 void WM_operator_bl_idname(char *to, const char *from)
324 {
325         char *sep= strchr(from, '.');
326
327         if(sep) {
328                 int i, ofs= (sep-from);
329
330                 for(i=0; i<ofs; i++)
331                         to[i]= toupper(from[i]);
332
333                 BLI_strncpy(to+ofs, "_OT_", OP_MAX_TYPENAME);
334                 BLI_strncpy(to+(ofs+4), sep+1, OP_MAX_TYPENAME);
335         }
336         else {
337                 /* should not happen but support just incase */
338                 BLI_strncpy(to, from, OP_MAX_TYPENAME);
339         }
340 }
341
342 /* print a string representation of the operator, with the args that it runs 
343  * so python can run it again,
344  *
345  * When calling from an existing wmOperator do.
346  * WM_operator_pystring(op->type, op->ptr);
347  */
348 char *WM_operator_pystring(bContext *C, wmOperatorType *ot, PointerRNA *opptr, int all_args)
349 {
350         const char *arg_name= NULL;
351         char idname_py[OP_MAX_TYPENAME];
352
353         PropertyRNA *prop, *iterprop;
354
355         /* for building the string */
356         DynStr *dynstr= BLI_dynstr_new();
357         char *cstring, *buf;
358         int first_iter=1, ok= 1;
359
360
361         /* only to get the orginal props for comparisons */
362         PointerRNA opptr_default;
363         PropertyRNA *prop_default;
364         char *buf_default;
365         if(!all_args) {
366                 WM_operator_properties_create(&opptr_default, ot->idname);
367         }
368
369
370         WM_operator_py_idname(idname_py, ot->idname);
371         BLI_dynstr_appendf(dynstr, "bpy.ops.%s(", idname_py);
372
373         iterprop= RNA_struct_iterator_property(opptr->type);
374
375         RNA_PROP_BEGIN(opptr, propptr, iterprop) {
376                 prop= propptr.data;
377                 arg_name= RNA_property_identifier(prop);
378
379                 if (strcmp(arg_name, "rna_type")==0) continue;
380
381                 buf= RNA_property_as_string(C, opptr, prop);
382                 
383                 ok= 1;
384
385                 if(!all_args) {
386                         /* not verbose, so only add in attributes that use non-default values
387                          * slow but good for tooltips */
388                         prop_default= RNA_struct_find_property(&opptr_default, arg_name);
389
390                         if(prop_default) {
391                                 buf_default= RNA_property_as_string(C, &opptr_default, prop_default);
392
393                                 if(strcmp(buf, buf_default)==0)
394                                         ok= 0; /* values match, dont bother printing */
395
396                                 MEM_freeN(buf_default);
397                         }
398
399                 }
400                 if(ok) {
401                         BLI_dynstr_appendf(dynstr, first_iter?"%s=%s":", %s=%s", arg_name, buf);
402                         first_iter = 0;
403                 }
404
405                 MEM_freeN(buf);
406
407         }
408         RNA_PROP_END;
409
410         if(all_args==0)
411                 WM_operator_properties_free(&opptr_default);
412
413         BLI_dynstr_append(dynstr, ")");
414
415         cstring = BLI_dynstr_get_cstring(dynstr);
416         BLI_dynstr_free(dynstr);
417         return cstring;
418 }
419
420 void WM_operator_properties_create(PointerRNA *ptr, const char *opstring)
421 {
422         wmOperatorType *ot= WM_operatortype_find(opstring, 0);
423
424         if(ot)
425                 RNA_pointer_create(NULL, ot->srna, NULL, ptr);
426         else
427                 RNA_pointer_create(NULL, &RNA_OperatorProperties, NULL, ptr);
428 }
429
430 void WM_operator_properties_free(PointerRNA *ptr)
431 {
432         IDProperty *properties= ptr->data;
433
434         if(properties) {
435                 IDP_FreeProperty(properties);
436                 MEM_freeN(properties);
437         }
438 }
439
440 /* ************ default op callbacks, exported *********** */
441
442 /* invoke callback, uses enum property named "type" */
443 /* only weak thing is the fixed property name... */
444 int WM_menu_invoke(bContext *C, wmOperator *op, wmEvent *event)
445 {
446         PropertyRNA *prop= RNA_struct_find_property(op->ptr, "type");
447         uiPopupMenu *pup;
448         uiLayout *layout;
449
450         if(prop==NULL) {
451                 printf("WM_menu_invoke: %s has no \"type\" enum property\n", op->type->idname);
452         }
453         else if (RNA_property_type(prop) != PROP_ENUM) {
454                 printf("WM_menu_invoke: %s \"type\" is not an enum property\n", op->type->idname);
455         }
456         else {
457                 pup= uiPupMenuBegin(C, op->type->name, 0);
458                 layout= uiPupMenuLayout(pup);
459                 uiItemsEnumO(layout, op->type->idname, "type");
460                 uiPupMenuEnd(C, pup);
461         }
462
463         return OPERATOR_CANCELLED;
464 }
465
466 /* op->invoke */
467 int WM_operator_confirm(bContext *C, wmOperator *op, wmEvent *event)
468 {
469         uiPopupMenu *pup;
470         uiLayout *layout;
471
472         pup= uiPupMenuBegin(C, "OK?", ICON_QUESTION);
473         layout= uiPupMenuLayout(pup);
474         uiItemO(layout, NULL, 0, op->type->idname);
475         uiPupMenuEnd(C, pup);
476         
477         return OPERATOR_CANCELLED;
478 }
479
480 /* op->invoke, opens fileselect if filename property not set, otherwise executes */
481 int WM_operator_filesel(bContext *C, wmOperator *op, wmEvent *event)
482 {
483         if (RNA_property_is_set(op->ptr, "filename")) {
484                 return WM_operator_call(C, op);
485         } 
486         else {
487                 WM_event_add_fileselect(C, op);
488                 return OPERATOR_RUNNING_MODAL;
489         }
490 }
491
492 /* default properties for fileselect */
493 void WM_operator_properties_filesel(wmOperatorType *ot, int filter)
494 {
495         RNA_def_string_file_path(ot->srna, "filename", "", FILE_MAX, "Filename", "Path to file.");
496
497         RNA_def_boolean(ot->srna, "filter_blender", (filter & BLENDERFILE), "Filter .blend files", "");
498         RNA_def_boolean(ot->srna, "filter_image", (filter & IMAGEFILE), "Filter image files", "");
499         RNA_def_boolean(ot->srna, "filter_movie", (filter & MOVIEFILE), "Filter movie files", "");
500         RNA_def_boolean(ot->srna, "filter_python", (filter & PYSCRIPTFILE), "Filter python files", "");
501         RNA_def_boolean(ot->srna, "filter_font", (filter & FTFONTFILE), "Filter font files", "");
502         RNA_def_boolean(ot->srna, "filter_sound", (filter & SOUNDFILE), "Filter sound files", "");
503         RNA_def_boolean(ot->srna, "filter_text", (filter & TEXTFILE), "Filter text files", "");
504         RNA_def_boolean(ot->srna, "filter_folder", (filter & FOLDERFILE), "Filter folders", "");
505 }
506
507 /* op->poll */
508 int WM_operator_winactive(bContext *C)
509 {
510         if(CTX_wm_window(C)==NULL) return 0;
511         return 1;
512 }
513
514 /* op->invoke */
515 static void redo_cb(bContext *C, void *arg_op, void *arg2)
516 {
517         wmOperator *lastop= arg_op;
518         
519         if(lastop) {
520                 ED_undo_pop_op(C, lastop);
521                 WM_operator_repeat(C, lastop);
522         }
523 }
524
525 static uiBlock *wm_block_create_redo(bContext *C, ARegion *ar, void *arg_op)
526 {
527         wmWindowManager *wm= CTX_wm_manager(C);
528         wmOperator *op= arg_op;
529         PointerRNA ptr;
530         uiBlock *block;
531         uiLayout *layout;
532         uiStyle *style= U.uistyles.first;
533         
534         block= uiBeginBlock(C, ar, "redo_popup", UI_EMBOSS);
535         uiBlockClearFlag(block, UI_BLOCK_LOOP);
536         uiBlockSetFlag(block, UI_BLOCK_KEEP_OPEN|UI_BLOCK_RET_1);
537         uiBlockSetFunc(block, redo_cb, arg_op, NULL);
538
539         if(!op->properties) {
540                 IDPropertyTemplate val = {0};
541                 op->properties= IDP_New(IDP_GROUP, val, "wmOperatorProperties");
542         }
543
544         RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
545         layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, 300, 20, style);
546         uiItemL(layout, op->type->name, 0);
547
548         if(op->type->ui)
549                 op->type->ui((bContext*)C, &ptr, layout);
550         else
551                 uiDefAutoButsRNA(C, layout, &ptr, 2);
552
553         uiPopupBoundsBlock(block, 4.0f, 0, 0);
554         uiEndBlock(C, block);
555
556         return block;
557 }
558
559 int WM_operator_props_popup(bContext *C, wmOperator *op, wmEvent *event)
560 {
561         int retval= OPERATOR_CANCELLED;
562         
563         if(op->type->exec)
564                 retval= op->type->exec(C, op);
565
566         if(retval != OPERATOR_CANCELLED)
567                 uiPupBlock(C, wm_block_create_redo, op);
568
569         return retval;
570 }
571
572 int WM_operator_redo_popup(bContext *C, wmOperator *op)
573 {
574         uiPupBlock(C, wm_block_create_redo, op);
575
576         return OPERATOR_CANCELLED;
577 }
578
579 /* ***************** Debug menu ************************* */
580
581 static uiBlock *wm_block_create_menu(bContext *C, ARegion *ar, void *arg_op)
582 {
583         wmOperator *op= arg_op;
584         uiBlock *block;
585         uiLayout *layout;
586         uiStyle *style= U.uistyles.first;
587         
588         block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
589         uiBlockClearFlag(block, UI_BLOCK_LOOP);
590         uiBlockSetFlag(block, UI_BLOCK_KEEP_OPEN|UI_BLOCK_RET_1);
591         
592         layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, 300, 20, style);
593         uiItemL(layout, op->type->name, 0);
594
595         if(op->type->ui)
596                 op->type->ui(C, op->ptr, layout);
597         else
598                 uiDefAutoButsRNA(C, layout, op->ptr, 2);
599         
600         uiPopupBoundsBlock(block, 4.0f, 0, 0);
601         uiEndBlock(C, block);
602         
603         return block;
604 }
605
606 static int wm_debug_menu_exec(bContext *C, wmOperator *op)
607 {
608         G.rt= RNA_int_get(op->ptr, "debugval");
609         ED_screen_refresh(CTX_wm_manager(C), CTX_wm_window(C));
610         WM_event_add_notifier(C, NC_WINDOW, NULL);
611         
612         return OPERATOR_FINISHED;       
613 }
614
615 static int wm_debug_menu_invoke(bContext *C, wmOperator *op, wmEvent *event)
616 {
617         
618         RNA_int_set(op->ptr, "debugval", G.rt);
619         
620         /* pass on operator, so return modal */
621         uiPupBlockOperator(C, wm_block_create_menu, op, WM_OP_EXEC_DEFAULT);
622         
623         return OPERATOR_RUNNING_MODAL;
624 }
625
626 static void WM_OT_debug_menu(wmOperatorType *ot)
627 {
628         ot->name= "Debug Menu";
629         ot->idname= "WM_OT_debug_menu";
630         
631         ot->invoke= wm_debug_menu_invoke;
632         ot->exec= wm_debug_menu_exec;
633         ot->poll= WM_operator_winactive;
634         
635         RNA_def_int(ot->srna, "debugval", 0, -10000, 10000, "Debug Value", "", INT_MIN, INT_MAX);
636 }
637
638 /* ***************** Search menu ************************* */
639 static void operator_call_cb(struct bContext *C, void *arg1, void *arg2)
640 {
641         wmOperatorType *ot= arg2;
642         
643         if(ot)
644                 WM_operator_name_call(C, ot->idname, WM_OP_INVOKE_DEFAULT, NULL);
645 }
646
647 static void operator_search_cb(const struct bContext *C, void *arg, char *str, uiSearchItems *items)
648 {
649         wmOperatorType *ot = WM_operatortype_first();
650         
651         for(; ot; ot= ot->next) {
652                 
653                 if(BLI_strcasestr(ot->name, str)) {
654                         if(ot->poll==NULL || ot->poll((bContext *)C)) {
655                                 char name[256];
656                                 int len= strlen(ot->name);
657                                 
658                                 /* display name for menu, can hold hotkey */
659                                 BLI_strncpy(name, ot->name, 256);
660                                 
661                                 /* check for hotkey */
662                                 if(len < 256-6) {
663                                         if(WM_key_event_operator_string(C, ot->idname, WM_OP_EXEC_DEFAULT, NULL, &name[len+1], 256-len-1))
664                                                 name[len]= '|';
665                                 }
666                                 
667                                 if(0==uiSearchItemAdd(items, name, ot, 0))
668                                         break;
669                         }
670                 }
671         }
672 }
673
674 static uiBlock *wm_block_search_menu(bContext *C, ARegion *ar, void *arg_op)
675 {
676         static char search[256]= "";
677         wmEvent event;
678         wmWindow *win= CTX_wm_window(C);
679         uiBlock *block;
680         uiBut *but;
681         
682         block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
683         uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_RET_1);
684         
685         but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, 256, 10, 10, 180, 19, "");
686         uiButSetSearchFunc(but, operator_search_cb, NULL, operator_call_cb, NULL);
687         
688         /* fake button, it holds space for search items */
689         uiDefBut(block, LABEL, 0, "", 10, 10 - uiSearchBoxhHeight(), 180, uiSearchBoxhHeight(), NULL, 0, 0, 0, 0, NULL);
690         
691         uiPopupBoundsBlock(block, 6.0f, 0, -20); /* move it downwards, mouse over button */
692         uiEndBlock(C, block);
693         
694         event= *(win->eventstate);      /* XXX huh huh? make api call */
695         event.type= EVT_BUT_OPEN;
696         event.val= KM_PRESS;
697         event.customdata= but;
698         event.customdatafree= FALSE;
699         wm_event_add(win, &event);
700         
701         return block;
702 }
703
704 static int wm_search_menu_exec(bContext *C, wmOperator *op)
705 {
706         
707         return OPERATOR_FINISHED;       
708 }
709
710 static int wm_search_menu_invoke(bContext *C, wmOperator *op, wmEvent *event)
711 {
712         
713         uiPupBlock(C, wm_block_search_menu, op);
714         
715         return OPERATOR_CANCELLED;
716 }
717
718 /* op->poll */
719 int wm_search_menu_poll(bContext *C)
720 {
721         if(CTX_wm_window(C)==NULL) return 0;
722         if(CTX_wm_area(C) && CTX_wm_area(C)->spacetype==SPACE_CONSOLE) return 0;  // XXX - so we can use the shortcut in the console
723         if(CTX_wm_area(C) && CTX_wm_area(C)->spacetype==SPACE_TEXT) return 0;  // XXX - so we can use the spacebar in the text editor
724         return 1;
725 }
726
727 static void WM_OT_search_menu(wmOperatorType *ot)
728 {
729         ot->name= "Search Menu";
730         ot->idname= "WM_OT_search_menu";
731         
732         ot->invoke= wm_search_menu_invoke;
733         ot->exec= wm_search_menu_exec;
734         ot->poll= wm_search_menu_poll;
735 }
736
737
738 /* ************ window / screen operator definitions ************** */
739
740 static void WM_OT_window_duplicate(wmOperatorType *ot)
741 {
742         ot->name= "Duplicate Window";
743         ot->idname= "WM_OT_window_duplicate";
744         
745         ot->exec= wm_window_duplicate_op;
746         ot->poll= WM_operator_winactive;
747 }
748
749 static void WM_OT_save_homefile(wmOperatorType *ot)
750 {
751         ot->name= "Save User Settings";
752         ot->idname= "WM_OT_save_homefile";
753         
754         ot->invoke= WM_operator_confirm;
755         ot->exec= WM_write_homefile;
756         ot->poll= WM_operator_winactive;
757 }
758
759 static void WM_OT_read_homefile(wmOperatorType *ot)
760 {
761         ot->name= "Reload Start-Up File";
762         ot->idname= "WM_OT_read_homefile";
763         
764         ot->invoke= WM_operator_confirm;
765         ot->exec= WM_read_homefile;
766         ot->poll= WM_operator_winactive;
767         
768         RNA_def_boolean(ot->srna, "factory", 0, "Factory Settings", "");
769 }
770
771
772 /* ********* recent file *********** */
773
774 static int recentfile_exec(bContext *C, wmOperator *op)
775 {
776         int event= RNA_enum_get(op->ptr, "file");
777
778         // XXX wm in context is not set correctly after WM_read_file -> crash
779         // do it before for now, but is this correct with multiple windows?
780
781         if(event>0) {
782                 if (G.sce[0] && (event==1)) {
783                         WM_event_add_notifier(C, NC_WINDOW, NULL);
784                         WM_read_file(C, G.sce, op->reports);
785                 }
786                 else {
787                         struct RecentFile *recent = BLI_findlink(&(G.recent_files), event-2);
788                         if(recent) {
789                                 WM_event_add_notifier(C, NC_WINDOW, NULL);
790                                 WM_read_file(C, recent->filename, op->reports);
791                         }
792                 }
793         }
794         return 0;
795 }
796
797 static int wm_recentfile_invoke(bContext *C, wmOperator *op, wmEvent *event)
798 {
799         uiPopupMenu *pup;
800         uiLayout *layout;
801
802         pup= uiPupMenuBegin(C, "Open Recent", 0);
803         layout= uiPupMenuLayout(pup);
804         uiItemsEnumO(layout, op->type->idname, "file");
805         uiPupMenuEnd(C, pup);
806         
807         return OPERATOR_CANCELLED;
808 }
809
810 static EnumPropertyItem *open_recentfile_itemf(bContext *C, PointerRNA *ptr, int *free)
811 {
812         EnumPropertyItem tmp = {0, "", 0, "", ""};
813         EnumPropertyItem *item= NULL;
814         struct RecentFile *recent;
815         int totitem= 0, i, ofs= 0;
816
817         if(G.sce[0]) {
818                 tmp.value= 1;
819                 tmp.identifier= G.sce;
820                 tmp.name= G.sce;
821                 RNA_enum_item_add(&item, &totitem, &tmp);
822                 ofs = 1;
823         }
824
825         /* dynamically construct enum */
826         for(recent = G.recent_files.first, i=0; (i<U.recent_files) && (recent); recent = recent->next, i++) {
827                 if(strcmp(recent->filename, G.sce)) {
828                         tmp.value= i+ofs+1;
829                         tmp.identifier= recent->filename;
830                         tmp.name= recent->filename;
831                         RNA_enum_item_add(&item, &totitem, &tmp);
832                 }
833         }
834
835         RNA_enum_item_end(&item, &totitem);
836         *free= 1;
837
838         return item;
839 }
840
841 static void WM_OT_open_recentfile(wmOperatorType *ot)
842 {
843         PropertyRNA *prop;
844         static EnumPropertyItem file_items[]= {
845                 {0, NULL, 0, NULL, NULL}};
846
847         ot->name= "Open Recent File";
848         ot->idname= "WM_OT_open_recentfile";
849         
850         ot->invoke= wm_recentfile_invoke;
851         ot->exec= recentfile_exec;
852         ot->poll= WM_operator_winactive;
853         
854         prop= RNA_def_enum(ot->srna, "file", file_items, 1, "File", "");
855         RNA_def_enum_funcs(prop, open_recentfile_itemf);
856 }
857
858 /* ********* main file *********** */
859
860 static void untitled(char *name)
861 {
862         if (G.save_over == 0 && strlen(name) < FILE_MAX-16) {
863                 char *c= BLI_last_slash(name);
864                 
865                 if (c)
866                         strcpy(&c[1], "untitled.blend");
867                 else
868                         strcpy(name, "untitled.blend");
869         }
870 }
871
872 static void load_set_load_ui(wmOperator *op)
873 {
874         if(!RNA_property_is_set(op->ptr, "load_ui"))
875                 RNA_boolean_set(op->ptr, "load_ui", !(U.flag & USER_FILENOUI));
876 }
877
878 static int wm_open_mainfile_invoke(bContext *C, wmOperator *op, wmEvent *event)
879 {
880         RNA_string_set(op->ptr, "filename", G.sce);
881         load_set_load_ui(op);
882
883         WM_event_add_fileselect(C, op);
884
885         return OPERATOR_RUNNING_MODAL;
886 }
887
888 static int wm_open_mainfile_exec(bContext *C, wmOperator *op)
889 {
890         char filename[FILE_MAX];
891
892         RNA_string_get(op->ptr, "filename", filename);
893         load_set_load_ui(op);
894
895         if(RNA_boolean_get(op->ptr, "load_ui"))
896                 G.fileflags &= ~G_FILE_NO_UI;
897         else
898                 G.fileflags |= G_FILE_NO_UI;
899         
900         // XXX wm in context is not set correctly after WM_read_file -> crash
901         // do it before for now, but is this correct with multiple windows?
902         WM_event_add_notifier(C, NC_WINDOW, NULL);
903
904         WM_read_file(C, filename, op->reports);
905         
906         return 0;
907 }
908
909 static void WM_OT_open_mainfile(wmOperatorType *ot)
910 {
911         ot->name= "Open Blender File";
912         ot->idname= "WM_OT_open_mainfile";
913         
914         ot->invoke= wm_open_mainfile_invoke;
915         ot->exec= wm_open_mainfile_exec;
916         ot->poll= WM_operator_winactive;
917         
918         WM_operator_properties_filesel(ot, FOLDERFILE|BLENDERFILE);
919
920         RNA_def_boolean(ot->srna, "load_ui", 1, "Load UI", "Load user interface setup in the .blend file.");
921 }
922
923 static int wm_recover_last_session_exec(bContext *C, wmOperator *op)
924 {
925         char scestr[FILE_MAX], filename[FILE_MAX];
926         int save_over;
927
928         /* back up some values */
929         BLI_strncpy(scestr, G.sce, sizeof(scestr));
930         save_over = G.save_over;
931
932         // XXX wm in context is not set correctly after WM_read_file -> crash
933         // do it before for now, but is this correct with multiple windows?
934         WM_event_add_notifier(C, NC_WINDOW, NULL);
935
936         /* load file */
937         BLI_make_file_string("/", filename, btempdir, "quit.blend");
938         WM_read_file(C, filename, op->reports);
939
940         /* restore */
941         G.save_over = save_over;
942         BLI_strncpy(G.sce, scestr, sizeof(G.sce));
943
944         return 0;
945 }
946
947 static void WM_OT_recover_last_session(wmOperatorType *ot)
948 {
949         ot->name= "Recover Last Session";
950         ot->idname= "WM_OT_recover_last_session";
951         
952         ot->exec= wm_recover_last_session_exec;
953         ot->poll= WM_operator_winactive;
954 }
955
956 static void save_set_compress(wmOperator *op)
957 {
958         if(!RNA_property_is_set(op->ptr, "compress")) {
959                 if(G.save_over) /* keep flag for existing file */
960                         RNA_boolean_set(op->ptr, "compress", G.fileflags & G_FILE_COMPRESS);
961                 else /* use userdef for new file */
962                         RNA_boolean_set(op->ptr, "compress", U.flag & USER_FILECOMPRESS);
963         }
964 }
965
966 static int wm_save_as_mainfile_invoke(bContext *C, wmOperator *op, wmEvent *event)
967 {
968         char name[FILE_MAX];
969
970         save_set_compress(op);
971         
972         BLI_strncpy(name, G.sce, FILE_MAX);
973         untitled(name);
974         RNA_string_set(op->ptr, "filename", name);
975         
976         WM_event_add_fileselect(C, op);
977
978         return OPERATOR_RUNNING_MODAL;
979 }
980
981 /* function used for WM_OT_save_mainfile too */
982 static int wm_save_as_mainfile_exec(bContext *C, wmOperator *op)
983 {
984         char filename[FILE_MAX];
985         int compress;
986
987         save_set_compress(op);
988         compress= RNA_boolean_get(op->ptr, "compress");
989         
990         if(RNA_property_is_set(op->ptr, "filename"))
991                 RNA_string_get(op->ptr, "filename", filename);
992         else {
993                 BLI_strncpy(filename, G.sce, FILE_MAX);
994                 untitled(filename);
995         }
996
997         WM_write_file(C, filename, compress, op->reports);
998         
999         WM_event_add_notifier(C, NC_WM|ND_FILESAVE, NULL);
1000
1001         return 0;
1002 }
1003
1004 static void WM_OT_save_as_mainfile(wmOperatorType *ot)
1005 {
1006         ot->name= "Save As Blender File";
1007         ot->idname= "WM_OT_save_as_mainfile";
1008         
1009         ot->invoke= wm_save_as_mainfile_invoke;
1010         ot->exec= wm_save_as_mainfile_exec;
1011         ot->poll= WM_operator_winactive;
1012         
1013         WM_operator_properties_filesel(ot, FOLDERFILE|BLENDERFILE);
1014         RNA_def_boolean(ot->srna, "compress", 0, "Compress", "Write compressed .blend file.");
1015 }
1016
1017 /* *************** Save file directly ******** */
1018
1019 static int wm_save_mainfile_invoke(bContext *C, wmOperator *op, wmEvent *event)
1020 {
1021         char name[FILE_MAX];
1022
1023         save_set_compress(op);
1024         
1025         BLI_strncpy(name, G.sce, FILE_MAX);
1026         untitled(name);
1027         RNA_string_set(op->ptr, "filename", name);
1028         uiPupMenuSaveOver(C, op, name);
1029
1030         return OPERATOR_RUNNING_MODAL;
1031 }
1032
1033 static void WM_OT_save_mainfile(wmOperatorType *ot)
1034 {
1035         ot->name= "Save Blender File";
1036         ot->idname= "WM_OT_save_mainfile";
1037         
1038         ot->invoke= wm_save_mainfile_invoke;
1039         ot->exec= wm_save_as_mainfile_exec;
1040         ot->poll= WM_operator_winactive;
1041         
1042         WM_operator_properties_filesel(ot, FOLDERFILE|BLENDERFILE);
1043         RNA_def_boolean(ot->srna, "compress", 0, "Compress", "Write compressed .blend file.");
1044 }
1045
1046
1047 /* *********************** */
1048
1049 static void WM_OT_window_fullscreen_toggle(wmOperatorType *ot)
1050 {
1051     ot->name= "Toggle Fullscreen";
1052     ot->idname= "WM_OT_window_fullscreen_toggle";
1053
1054     ot->exec= wm_window_fullscreen_toggle_op;
1055     ot->poll= WM_operator_winactive;
1056 }
1057
1058 static int wm_exit_blender_op(bContext *C, wmOperator *op)
1059 {
1060         WM_operator_free(op);
1061         
1062         WM_exit(C);     
1063         
1064         return OPERATOR_FINISHED;
1065 }
1066
1067 static void WM_OT_exit_blender(wmOperatorType *ot)
1068 {
1069         ot->name= "Exit Blender";
1070         ot->idname= "WM_OT_exit_blender";
1071
1072         ot->invoke= WM_operator_confirm;
1073         ot->exec= wm_exit_blender_op;
1074         ot->poll= WM_operator_winactive;
1075 }
1076
1077 /* ************ default paint cursors, draw always around cursor *********** */
1078 /*
1079  - returns handler to free 
1080  - poll(bContext): returns 1 if draw should happen
1081  - draw(bContext): drawing callback for paint cursor
1082 */
1083
1084 void *WM_paint_cursor_activate(wmWindowManager *wm, int (*poll)(bContext *C),
1085                                wmPaintCursorDraw draw, void *customdata)
1086 {
1087         wmPaintCursor *pc= MEM_callocN(sizeof(wmPaintCursor), "paint cursor");
1088         
1089         BLI_addtail(&wm->paintcursors, pc);
1090         
1091         pc->customdata = customdata;
1092         pc->poll= poll;
1093         pc->draw= draw;
1094         
1095         return pc;
1096 }
1097
1098 void WM_paint_cursor_end(wmWindowManager *wm, void *handle)
1099 {
1100         wmPaintCursor *pc;
1101         
1102         for(pc= wm->paintcursors.first; pc; pc= pc->next) {
1103                 if(pc == (wmPaintCursor *)handle) {
1104                         BLI_remlink(&wm->paintcursors, pc);
1105                         MEM_freeN(pc);
1106                         return;
1107                 }
1108         }
1109 }
1110
1111 /* ************ window gesture operator-callback definitions ************** */
1112 /*
1113  * These are default callbacks for use in operators requiring gesture input
1114  */
1115
1116 /* **************** Border gesture *************** */
1117
1118 /* Border gesture has two types:
1119    1) WM_GESTURE_CROSS_RECT: starts a cross, on mouse click it changes to border 
1120    2) WM_GESTURE_RECT: starts immediate as a border, on mouse click or release it ends
1121
1122    It stores 4 values (xmin, xmax, ymin, ymax) and event it ended with (event_type)
1123 */
1124
1125 static int border_apply(bContext *C, wmOperator *op, int event_type, int event_orig)
1126 {
1127         wmGesture *gesture= op->customdata;
1128         rcti *rect= gesture->customdata;
1129         
1130         if(rect->xmin > rect->xmax)
1131                 SWAP(int, rect->xmin, rect->xmax);
1132         if(rect->ymin > rect->ymax)
1133                 SWAP(int, rect->ymin, rect->ymax);
1134         
1135         if(rect->xmin==rect->xmax || rect->ymin==rect->ymax)
1136                 return 0;
1137                 
1138         /* operator arguments and storage. */
1139         RNA_int_set(op->ptr, "xmin", rect->xmin);
1140         RNA_int_set(op->ptr, "ymin", rect->ymin);
1141         RNA_int_set(op->ptr, "xmax", rect->xmax);
1142         RNA_int_set(op->ptr, "ymax", rect->ymax);
1143         
1144         /* XXX weak; border should be configured for this without reading event types */
1145         if( RNA_struct_find_property(op->ptr, "event_type") ) {
1146                 if(ELEM4(event_orig, EVT_TWEAK_L, EVT_TWEAK_R, EVT_TWEAK_A, EVT_TWEAK_S))
1147                         event_type= LEFTMOUSE;
1148                 
1149                 RNA_int_set(op->ptr, "event_type", event_type);
1150         }
1151         op->type->exec(C, op);
1152         
1153         return 1;
1154 }
1155
1156 static void wm_gesture_end(bContext *C, wmOperator *op)
1157 {
1158         wmGesture *gesture= op->customdata;
1159         
1160         WM_gesture_end(C, gesture);     /* frees gesture itself, and unregisters from window */
1161         op->customdata= NULL;
1162
1163         ED_area_tag_redraw(CTX_wm_area(C));
1164         
1165         if( RNA_struct_find_property(op->ptr, "cursor") )
1166                 WM_cursor_restore(CTX_wm_window(C));
1167 }
1168
1169 int WM_border_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
1170 {
1171         if(WM_key_event_is_tweak(event->type))
1172                 op->customdata= WM_gesture_new(C, event, WM_GESTURE_RECT);
1173         else
1174                 op->customdata= WM_gesture_new(C, event, WM_GESTURE_CROSS_RECT);
1175
1176         /* add modal handler */
1177         WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
1178         
1179         wm_gesture_tag_redraw(C);
1180
1181         return OPERATOR_RUNNING_MODAL;
1182 }
1183
1184 int WM_border_select_modal(bContext *C, wmOperator *op, wmEvent *event)
1185 {
1186         wmGesture *gesture= op->customdata;
1187         rcti *rect= gesture->customdata;
1188         int sx, sy;
1189         
1190         switch(event->type) {
1191                 case MOUSEMOVE:
1192                         
1193                         wm_subwindow_getorigin(CTX_wm_window(C), gesture->swinid, &sx, &sy);
1194                         
1195                         if(gesture->type==WM_GESTURE_CROSS_RECT && gesture->mode==0) {
1196                                 rect->xmin= rect->xmax= event->x - sx;
1197                                 rect->ymin= rect->ymax= event->y - sy;
1198                         }
1199                         else {
1200                                 rect->xmax= event->x - sx;
1201                                 rect->ymax= event->y - sy;
1202                         }
1203                         
1204                         wm_gesture_tag_redraw(C);
1205
1206                         break;
1207                         
1208                 case LEFTMOUSE:
1209                 case MIDDLEMOUSE:
1210                 case RIGHTMOUSE:
1211                         if(event->val==KM_PRESS) {
1212                                 if(gesture->type==WM_GESTURE_CROSS_RECT && gesture->mode==0) {
1213                                         gesture->mode= 1;
1214                                         wm_gesture_tag_redraw(C);
1215                                 }
1216                         }
1217                         else {
1218                                 if(border_apply(C, op, event->type, gesture->event_type)) {
1219                                         wm_gesture_end(C, op);
1220                                         return OPERATOR_FINISHED;
1221                                 }
1222                                 wm_gesture_end(C, op);
1223                                 return OPERATOR_CANCELLED;
1224                         }
1225                         break;
1226                 case ESCKEY:
1227                         wm_gesture_end(C, op);
1228                         return OPERATOR_CANCELLED;
1229         }
1230         return OPERATOR_RUNNING_MODAL;
1231 }
1232
1233 /* **************** circle gesture *************** */
1234 /* works now only for selection or modal paint stuff, calls exec while hold mouse, exit on release */
1235
1236 int WM_gesture_circle_invoke(bContext *C, wmOperator *op, wmEvent *event)
1237 {
1238         op->customdata= WM_gesture_new(C, event, WM_GESTURE_CIRCLE);
1239         
1240         /* add modal handler */
1241         WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
1242         
1243         wm_gesture_tag_redraw(C);
1244         
1245         return OPERATOR_RUNNING_MODAL;
1246 }
1247
1248 static void gesture_circle_apply(bContext *C, wmOperator *op)
1249 {
1250         wmGesture *gesture= op->customdata;
1251         rcti *rect= gesture->customdata;
1252         
1253         /* operator arguments and storage. */
1254         RNA_int_set(op->ptr, "x", rect->xmin);
1255         RNA_int_set(op->ptr, "y", rect->ymin);
1256         RNA_int_set(op->ptr, "radius", rect->xmax);
1257         
1258         if(op->type->exec)
1259                 op->type->exec(C, op);
1260 }
1261
1262 int WM_gesture_circle_modal(bContext *C, wmOperator *op, wmEvent *event)
1263 {
1264         wmGesture *gesture= op->customdata;
1265         rcti *rect= gesture->customdata;
1266         int sx, sy;
1267         
1268         switch(event->type) {
1269                 case MOUSEMOVE:
1270                         
1271                         wm_subwindow_getorigin(CTX_wm_window(C), gesture->swinid, &sx, &sy);
1272                         
1273                         rect->xmin= event->x - sx;
1274                         rect->ymin= event->y - sy;
1275                         
1276                         wm_gesture_tag_redraw(C);
1277                         
1278                         if(gesture->mode)
1279                                 gesture_circle_apply(C, op);
1280
1281                         break;
1282                 case WHEELUPMOUSE:
1283                         rect->xmax += 2 + rect->xmax/10;
1284                         wm_gesture_tag_redraw(C);
1285                         break;
1286                 case WHEELDOWNMOUSE:
1287                         rect->xmax -= 2 + rect->xmax/10;
1288                         if(rect->xmax < 1) rect->xmax= 1;
1289                         wm_gesture_tag_redraw(C);
1290                         break;
1291                 case LEFTMOUSE:
1292                 case MIDDLEMOUSE:
1293                 case RIGHTMOUSE:
1294                         if(event->val==0) {     /* key release */
1295                                 wm_gesture_end(C, op);
1296                                 return OPERATOR_FINISHED;
1297                         }
1298                         else {
1299                                 if( RNA_struct_find_property(op->ptr, "event_type") )
1300                                         RNA_int_set(op->ptr, "event_type", event->type);
1301                                 
1302                                 /* apply first click */
1303                                 gesture_circle_apply(C, op);
1304                                 gesture->mode= 1;
1305                         }
1306                         break;
1307                 case ESCKEY:
1308                         wm_gesture_end(C, op);
1309                         return OPERATOR_CANCELLED;
1310         }
1311         return OPERATOR_RUNNING_MODAL;
1312 }
1313
1314 #if 0
1315 /* template to copy from */
1316 void WM_OT_circle_gesture(wmOperatorType *ot)
1317 {
1318         ot->name= "Circle Gesture";
1319         ot->idname= "WM_OT_circle_gesture";
1320         
1321         ot->invoke= WM_gesture_circle_invoke;
1322         ot->modal= WM_gesture_circle_modal;
1323         
1324         ot->poll= WM_operator_winactive;
1325         
1326         RNA_def_property(ot->srna, "x", PROP_INT, PROP_NONE);
1327         RNA_def_property(ot->srna, "y", PROP_INT, PROP_NONE);
1328         RNA_def_property(ot->srna, "radius", PROP_INT, PROP_NONE);
1329
1330 }
1331 #endif
1332
1333 /* **************** Tweak gesture *************** */
1334
1335 static void tweak_gesture_modal(bContext *C, wmEvent *event)
1336 {
1337         wmWindow *window= CTX_wm_window(C);
1338         wmGesture *gesture= window->tweak;
1339         rcti *rect= gesture->customdata;
1340         int sx, sy, val;
1341         
1342         switch(event->type) {
1343                 case MOUSEMOVE:
1344                         
1345                         wm_subwindow_getorigin(window, gesture->swinid, &sx, &sy);
1346                         
1347                         rect->xmax= event->x - sx;
1348                         rect->ymax= event->y - sy;
1349                         
1350                         if((val= wm_gesture_evaluate(C, gesture))) {
1351                                 wmEvent event;
1352
1353                                 event= *(window->eventstate);
1354                                 if(gesture->event_type==LEFTMOUSE)
1355                                         event.type= EVT_TWEAK_L;
1356                                 else if(gesture->event_type==RIGHTMOUSE)
1357                                         event.type= EVT_TWEAK_R;
1358                                 else
1359                                         event.type= EVT_TWEAK_M;
1360                                 event.val= val;
1361                                 /* mouse coords! */
1362                                 wm_event_add(window, &event);
1363                                 
1364                                 WM_gesture_end(C, gesture);     /* frees gesture itself, and unregisters from window */
1365                                 window->tweak= NULL;
1366                         }
1367                         
1368                         break;
1369                         
1370                 case LEFTMOUSE:
1371                 case RIGHTMOUSE:
1372                 case MIDDLEMOUSE:
1373                         if(gesture->event_type==event->type) {
1374                                 WM_gesture_end(C, gesture);
1375                                 window->tweak= NULL;
1376                                 
1377                                 /* when tweak fails we should give the other keymap entries a chance */
1378                                 event->val= KM_RELEASE;
1379                         }
1380                         break;
1381                 default:
1382                         WM_gesture_end(C, gesture);
1383                         window->tweak= NULL;
1384         }
1385 }
1386
1387 /* standard tweak, called after window handlers passed on event */
1388 void wm_tweakevent_test(bContext *C, wmEvent *event, int action)
1389 {
1390         wmWindow *win= CTX_wm_window(C);
1391         
1392         if(win->tweak==NULL) {
1393                 if(CTX_wm_region(C)) {
1394                         if(event->val) { // pressed
1395                                 if( ELEM3(event->type, LEFTMOUSE, MIDDLEMOUSE, RIGHTMOUSE) )
1396                                         win->tweak= WM_gesture_new(C, event, WM_GESTURE_TWEAK);
1397                         }
1398                 }
1399         }
1400         else {
1401                 if(action==WM_HANDLER_BREAK) {
1402                         WM_gesture_end(C, win->tweak);
1403                         win->tweak= NULL;
1404                 }
1405                 else
1406                         tweak_gesture_modal(C, event);
1407         }
1408 }
1409
1410 /* *********************** lasso gesture ****************** */
1411
1412 int WM_gesture_lasso_invoke(bContext *C, wmOperator *op, wmEvent *event)
1413 {
1414         op->customdata= WM_gesture_new(C, event, WM_GESTURE_LASSO);
1415         
1416         /* add modal handler */
1417         WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
1418         
1419         wm_gesture_tag_redraw(C);
1420         
1421         if( RNA_struct_find_property(op->ptr, "cursor") )
1422                 WM_cursor_modal(CTX_wm_window(C), RNA_int_get(op->ptr, "cursor"));
1423         
1424         return OPERATOR_RUNNING_MODAL;
1425 }
1426
1427 int WM_gesture_lines_invoke(bContext *C, wmOperator *op, wmEvent *event)
1428 {
1429         op->customdata= WM_gesture_new(C, event, WM_GESTURE_LINES);
1430         
1431         /* add modal handler */
1432         WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
1433         
1434         wm_gesture_tag_redraw(C);
1435         
1436         if( RNA_struct_find_property(op->ptr, "cursor") )
1437                 WM_cursor_modal(CTX_wm_window(C), RNA_int_get(op->ptr, "cursor"));
1438         
1439         return OPERATOR_RUNNING_MODAL;
1440 }
1441
1442
1443 static void gesture_lasso_apply(bContext *C, wmOperator *op, int event_type)
1444 {
1445         wmGesture *gesture= op->customdata;
1446         PointerRNA itemptr;
1447         float loc[2];
1448         int i;
1449         short *lasso= gesture->customdata;
1450         
1451         /* operator storage as path. */
1452
1453         for(i=0; i<gesture->points; i++, lasso+=2) {
1454                 loc[0]= lasso[0];
1455                 loc[1]= lasso[1];
1456                 RNA_collection_add(op->ptr, "path", &itemptr);
1457                 RNA_float_set_array(&itemptr, "loc", loc);
1458         }
1459         
1460         wm_gesture_end(C, op);
1461                 
1462         if(op->type->exec)
1463                 op->type->exec(C, op);
1464         
1465 }
1466
1467 int WM_gesture_lasso_modal(bContext *C, wmOperator *op, wmEvent *event)
1468 {
1469         wmGesture *gesture= op->customdata;
1470         int sx, sy;
1471         
1472         switch(event->type) {
1473                 case MOUSEMOVE:
1474                         
1475                         wm_gesture_tag_redraw(C);
1476                         
1477                         wm_subwindow_getorigin(CTX_wm_window(C), gesture->swinid, &sx, &sy);
1478                         if(gesture->points < WM_LASSO_MAX_POINTS) {
1479                                 short *lasso= gesture->customdata;
1480                                 lasso += 2 * gesture->points;
1481                                 lasso[0] = event->x - sx;
1482                                 lasso[1] = event->y - sy;
1483                                 gesture->points++;
1484                         }
1485                         else {
1486                                 gesture_lasso_apply(C, op, event->type);
1487                                 return OPERATOR_FINISHED;
1488                         }
1489                         break;
1490                         
1491                 case LEFTMOUSE:
1492                 case MIDDLEMOUSE:
1493                 case RIGHTMOUSE:
1494                         if(event->val==0) {     /* key release */
1495                                 gesture_lasso_apply(C, op, event->type);
1496                                 return OPERATOR_FINISHED;
1497                         }
1498                         break;
1499                 case ESCKEY:
1500                         wm_gesture_end(C, op);
1501                         return OPERATOR_CANCELLED;
1502         }
1503         return OPERATOR_RUNNING_MODAL;
1504 }
1505
1506 int WM_gesture_lines_modal(bContext *C, wmOperator *op, wmEvent *event)
1507 {
1508         return WM_gesture_lasso_modal(C, op, event);
1509 }
1510
1511 #if 0
1512 /* template to copy from */
1513
1514 static int gesture_lasso_exec(bContext *C, wmOperator *op)
1515 {
1516         RNA_BEGIN(op->ptr, itemptr, "path") {
1517                 float loc[2];
1518                 
1519                 RNA_float_get_array(&itemptr, "loc", loc);
1520                 printf("Location: %f %f\n", loc[0], loc[1]);
1521         }
1522         RNA_END;
1523         
1524         return OPERATOR_FINISHED;
1525 }
1526
1527 void WM_OT_lasso_gesture(wmOperatorType *ot)
1528 {
1529         PropertyRNA *prop;
1530         
1531         ot->name= "Lasso Gesture";
1532         ot->idname= "WM_OT_lasso_gesture";
1533         
1534         ot->invoke= WM_gesture_lasso_invoke;
1535         ot->modal= WM_gesture_lasso_modal;
1536         ot->exec= gesture_lasso_exec;
1537         
1538         ot->poll= WM_operator_winactive;
1539         
1540         prop= RNA_def_property(ot->srna, "path", PROP_COLLECTION, PROP_NONE);
1541         RNA_def_property_struct_runtime(prop, &RNA_OperatorMousePath);
1542 }
1543 #endif
1544
1545 /* *********************** radial control ****************** */
1546
1547 const int WM_RADIAL_CONTROL_DISPLAY_SIZE = 200;
1548
1549 typedef struct wmRadialControl {
1550         int mode;
1551         float initial_value, value, max_value;
1552         int initial_mouse[2];
1553         void *cursor;
1554         GLuint tex;
1555 } wmRadialControl;
1556
1557 static void wm_radial_control_paint(bContext *C, int x, int y, void *customdata)
1558 {
1559         wmRadialControl *rc = (wmRadialControl*)customdata;
1560         ARegion *ar = CTX_wm_region(C);
1561         float r1=0.0f, r2=0.0f, r3=0.0f, angle=0.0f;
1562
1563         /* Keep cursor in the original place */
1564         x = rc->initial_mouse[0] - ar->winrct.xmin;
1565         y = rc->initial_mouse[1] - ar->winrct.ymin;
1566
1567         glPushMatrix();
1568         
1569         glTranslatef((float)x, (float)y, 0.0f);
1570
1571         if(rc->mode == WM_RADIALCONTROL_SIZE) {
1572                 r1= rc->value;
1573                 r2= rc->initial_value;
1574                 r3= r1;
1575         } else if(rc->mode == WM_RADIALCONTROL_STRENGTH) {
1576                 r1= (1 - rc->value) * WM_RADIAL_CONTROL_DISPLAY_SIZE;
1577                 r2= WM_RADIAL_CONTROL_DISPLAY_SIZE;
1578                 r3= WM_RADIAL_CONTROL_DISPLAY_SIZE;
1579         } else if(rc->mode == WM_RADIALCONTROL_ANGLE) {
1580                 r1= r2= WM_RADIAL_CONTROL_DISPLAY_SIZE;
1581                 r3= WM_RADIAL_CONTROL_DISPLAY_SIZE;
1582                 angle = rc->value;
1583         }
1584
1585         glColor4ub(255, 255, 255, 128);
1586         glEnable( GL_LINE_SMOOTH );
1587         glEnable(GL_BLEND);
1588
1589         if(rc->mode == WM_RADIALCONTROL_ANGLE)
1590                 fdrawline(0, 0, WM_RADIAL_CONTROL_DISPLAY_SIZE, 0);
1591
1592         if(rc->tex) {
1593                 const float str = rc->mode == WM_RADIALCONTROL_STRENGTH ? (rc->value + 0.5) : 1;
1594
1595                 if(rc->mode == WM_RADIALCONTROL_ANGLE) {
1596                         glRotatef(angle, 0, 0, 1);
1597                         fdrawline(0, 0, WM_RADIAL_CONTROL_DISPLAY_SIZE, 0);
1598                 }
1599
1600                 glBindTexture(GL_TEXTURE_2D, rc->tex);
1601
1602                 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1603                 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1604
1605                 glEnable(GL_TEXTURE_2D);
1606                 glBegin(GL_QUADS);
1607                 glColor4f(0,0,0, str);
1608                 glTexCoord2f(0,0);
1609                 glVertex2f(-r3, -r3);
1610                 glTexCoord2f(1,0);
1611                 glVertex2f(r3, -r3);
1612                 glTexCoord2f(1,1);
1613                 glVertex2f(r3, r3);
1614                 glTexCoord2f(0,1);
1615                 glVertex2f(-r3, r3);
1616                 glEnd();
1617                 glDisable(GL_TEXTURE_2D);
1618         }
1619
1620         glColor4ub(255, 255, 255, 128); 
1621         glutil_draw_lined_arc(0.0, M_PI*2.0, r1, 40);
1622         glutil_draw_lined_arc(0.0, M_PI*2.0, r2, 40);
1623         glDisable(GL_BLEND);
1624         glDisable( GL_LINE_SMOOTH );
1625         
1626         glPopMatrix();
1627 }
1628
1629 int WM_radial_control_modal(bContext *C, wmOperator *op, wmEvent *event)
1630 {
1631         wmRadialControl *rc = (wmRadialControl*)op->customdata;
1632         int mode, initial_mouse[2], delta[2];
1633         float dist;
1634         double new_value = RNA_float_get(op->ptr, "new_value");
1635         int ret = OPERATOR_RUNNING_MODAL;
1636
1637         mode = RNA_int_get(op->ptr, "mode");
1638         RNA_int_get_array(op->ptr, "initial_mouse", initial_mouse);
1639
1640         switch(event->type) {
1641         case MOUSEMOVE:
1642                 delta[0]= initial_mouse[0] - event->x;
1643                 delta[1]= initial_mouse[1] - event->y;
1644                 dist= sqrt(delta[0]*delta[0]+delta[1]*delta[1]);
1645
1646                 if(mode == WM_RADIALCONTROL_SIZE)
1647                         new_value = dist;
1648                 else if(mode == WM_RADIALCONTROL_STRENGTH) {
1649                         new_value = 1 - dist / WM_RADIAL_CONTROL_DISPLAY_SIZE;
1650                 } else if(mode == WM_RADIALCONTROL_ANGLE)
1651                         new_value = ((int)(atan2(delta[1], delta[0]) * (180.0 / M_PI)) + 180);
1652                 
1653                 if(event->ctrl) {
1654                         if(mode == WM_RADIALCONTROL_STRENGTH)
1655                                 new_value = ((int)(new_value * 100) / 10*10) / 100.0f;
1656                         else
1657                                 new_value = ((int)new_value + 5) / 10*10;
1658                 }
1659                 
1660                 break;
1661         case ESCKEY:
1662         case RIGHTMOUSE:
1663                 ret = OPERATOR_CANCELLED;
1664                 break;
1665         case LEFTMOUSE:
1666         case PADENTER:
1667                 op->type->exec(C, op);
1668                 ret = OPERATOR_FINISHED;
1669                 break;
1670         }
1671
1672         /* Clamp */
1673         if(new_value > rc->max_value)
1674                 new_value = rc->max_value;
1675         else if(new_value < 0)
1676                 new_value = 0;
1677
1678         /* Update paint data */
1679         rc->value = new_value;
1680
1681         RNA_float_set(op->ptr, "new_value", new_value);
1682
1683         if(ret != OPERATOR_RUNNING_MODAL) {
1684                 WM_paint_cursor_end(CTX_wm_manager(C), rc->cursor);
1685                 MEM_freeN(rc);
1686         }
1687         
1688         ED_region_tag_redraw(CTX_wm_region(C));
1689
1690         return ret;
1691 }
1692
1693 /* Expects the operator customdata to be an ImBuf (or NULL) */
1694 int WM_radial_control_invoke(bContext *C, wmOperator *op, wmEvent *event)
1695 {
1696         wmRadialControl *rc = MEM_callocN(sizeof(wmRadialControl), "radial control");
1697         int mode = RNA_int_get(op->ptr, "mode");
1698         float initial_value = RNA_float_get(op->ptr, "initial_value");
1699         int mouse[2] = {event->x, event->y};
1700
1701         if(mode == WM_RADIALCONTROL_SIZE) {
1702                 rc->max_value = 200;
1703                 mouse[0]-= initial_value;
1704         }
1705         else if(mode == WM_RADIALCONTROL_STRENGTH) {
1706                 rc->max_value = 1;
1707                 mouse[0]-= WM_RADIAL_CONTROL_DISPLAY_SIZE * (1 - initial_value);
1708         }
1709         else if(mode == WM_RADIALCONTROL_ANGLE) {
1710                 rc->max_value = 360;
1711                 mouse[0]-= WM_RADIAL_CONTROL_DISPLAY_SIZE * cos(initial_value);
1712                 mouse[1]-= WM_RADIAL_CONTROL_DISPLAY_SIZE * sin(initial_value);
1713                 initial_value *= 180.0f/M_PI;
1714         }
1715
1716         if(op->customdata) {
1717                 ImBuf *im = (ImBuf*)op->customdata;
1718                 /* Build GL texture */
1719                 glGenTextures(1, &rc->tex);
1720                 glBindTexture(GL_TEXTURE_2D, rc->tex);
1721                 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, im->x, im->y, 0, GL_ALPHA, GL_FLOAT, im->rect_float);
1722                 MEM_freeN(im->rect_float);
1723                 MEM_freeN(im);
1724         }
1725
1726         RNA_int_set_array(op->ptr, "initial_mouse", mouse);
1727         RNA_float_set(op->ptr, "new_value", initial_value);
1728                 
1729         op->customdata = rc;
1730         rc->mode = mode;
1731         rc->initial_value = initial_value;
1732         rc->initial_mouse[0] = mouse[0];
1733         rc->initial_mouse[1] = mouse[1];
1734         rc->cursor = WM_paint_cursor_activate(CTX_wm_manager(C), op->type->poll,
1735                                               wm_radial_control_paint, op->customdata);
1736
1737         /* add modal handler */
1738         WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
1739         
1740         WM_radial_control_modal(C, op, event);
1741         
1742         return OPERATOR_RUNNING_MODAL;
1743 }
1744
1745 /* Gets a descriptive string of the operation */
1746 void WM_radial_control_string(wmOperator *op, char str[], int maxlen)
1747 {
1748         int mode = RNA_int_get(op->ptr, "mode");
1749         float v = RNA_float_get(op->ptr, "new_value");
1750
1751         if(mode == WM_RADIALCONTROL_SIZE)
1752                 sprintf(str, "Size: %d", (int)v);
1753         else if(mode == WM_RADIALCONTROL_STRENGTH)
1754                 sprintf(str, "Strength: %d", (int)v);
1755         else if(mode == WM_RADIALCONTROL_ANGLE)
1756                 sprintf(str, "Angle: %d", (int)(v * 180.0f/M_PI));
1757 }
1758
1759 /** Important: this doesn't define an actual operator, it
1760     just sets up the common parts of the radial control op. **/
1761 void WM_OT_radial_control_partial(wmOperatorType *ot)
1762 {
1763         static EnumPropertyItem prop_mode_items[] = {
1764                 {WM_RADIALCONTROL_SIZE, "SIZE", 0, "Size", ""},
1765                 {WM_RADIALCONTROL_STRENGTH, "STRENGTH", 0, "Strength", ""},
1766                 {WM_RADIALCONTROL_ANGLE, "ANGLE", 0, "Angle", ""},
1767                 {0, NULL, 0, NULL, NULL}};
1768
1769         /* Should be set in custom invoke() */
1770         RNA_def_float(ot->srna, "initial_value", 0, 0, FLT_MAX, "Initial Value", "", 0, FLT_MAX);
1771
1772         /* Set internally, should be used in custom exec() to get final value */
1773         RNA_def_float(ot->srna, "new_value", 0, 0, FLT_MAX, "New Value", "", 0, FLT_MAX);
1774
1775         /* Should be set before calling operator */
1776         RNA_def_enum(ot->srna, "mode", prop_mode_items, 0, "Mode", "");
1777
1778         /* Internal */
1779         RNA_def_int_vector(ot->srna, "initial_mouse", 2, NULL, INT_MIN, INT_MAX, "initial_mouse", "", INT_MIN, INT_MAX);
1780 }
1781
1782 /* ************************** timer for testing ***************** */
1783
1784 /* uses no type defines, fully local testing function anyway... ;) */
1785
1786 static int ten_timer_exec(bContext *C, wmOperator *op)
1787 {
1788         ARegion *ar= CTX_wm_region(C);
1789         double stime= PIL_check_seconds_timer();
1790         int type = RNA_int_get(op->ptr, "type");
1791         int a, time;
1792         char tmpstr[128];
1793         
1794         WM_cursor_wait(1);
1795         
1796         for(a=0; a<10; a++) {
1797                 if (type==0) {
1798                         ED_region_do_draw(C, ar);
1799                 } 
1800                 else if (type==1) {
1801                         wmWindow *win= CTX_wm_window(C);
1802                         
1803                         ED_region_tag_redraw(ar);
1804                         wm_draw_update(C);
1805                         
1806                         CTX_wm_window_set(C, win);      /* XXX context manipulation warning! */
1807                 }
1808                 else if (type==2) {
1809                         wmWindow *win= CTX_wm_window(C);
1810                         ScrArea *sa;
1811                         
1812                         for(sa= CTX_wm_screen(C)->areabase.first; sa; sa= sa->next)
1813                                 ED_area_tag_redraw(sa);
1814                         wm_draw_update(C);
1815                         
1816                         CTX_wm_window_set(C, win);      /* XXX context manipulation warning! */
1817                 }
1818                 else if (type==3) {
1819                         Scene *scene= CTX_data_scene(C);
1820                         
1821                         if(a & 1) scene->r.cfra--;
1822                         else scene->r.cfra++;
1823                         scene_update_for_newframe(scene, scene->lay);
1824                 }
1825                 else {
1826                         ED_undo_pop(C);
1827                         ED_undo_redo(C);
1828                 }
1829         }
1830         
1831         time= (int) ((PIL_check_seconds_timer()-stime)*1000);
1832         
1833         if(type==0) sprintf(tmpstr, "10 x Draw Region: %d ms", time);
1834         if(type==1) sprintf(tmpstr, "10 x Draw Region and Swap: %d ms", time);
1835         if(type==2) sprintf(tmpstr, "10 x Draw Window and Swap: %d ms", time);
1836         if(type==3) sprintf(tmpstr, "Anim Step: %d ms", time);
1837         if(type==4) sprintf(tmpstr, "10 x Undo/Redo: %d ms", time);
1838         
1839         WM_cursor_wait(0);
1840         
1841         uiPupMenuNotice(C, tmpstr);
1842         
1843         return OPERATOR_FINISHED;
1844 }
1845
1846 static void WM_OT_ten_timer(wmOperatorType *ot)
1847 {
1848         static EnumPropertyItem prop_type_items[] = {
1849         {0, "DRAW", 0, "Draw Region", ""},
1850         {1, "DRAWSWAP", 0, "Draw Region + Swap", ""},
1851         {2, "DRAWWINSWAP", 0, "Draw Window + Swap", ""},
1852         {3, "ANIMSTEP", 0, "Anim Step", ""},
1853         {4, "UNDO", 0, "Undo/Redo", ""},
1854         {0, NULL, 0, NULL, NULL}};
1855         
1856         ot->name= "Ten Timer";
1857         ot->idname= "WM_OT_ten_timer";
1858         
1859         ot->invoke= WM_menu_invoke;
1860         ot->exec= ten_timer_exec;
1861         ot->poll= WM_operator_winactive;
1862         
1863         RNA_def_enum(ot->srna, "type", prop_type_items, 0, "Type", "");
1864
1865 }
1866
1867
1868
1869 /* ******************************************************* */
1870  
1871 /* called on initialize WM_exit() */
1872 void wm_operatortype_free(void)
1873 {
1874         wmOperatorType *ot;
1875         
1876         for(ot= global_ops.first; ot; ot= ot->next)
1877                 if(ot->macro.first)
1878                         wm_operatortype_free_macro(ot);
1879         
1880         BLI_freelistN(&global_ops);
1881 }
1882
1883 /* called on initialize WM_init() */
1884 void wm_operatortype_init(void)
1885 {
1886         WM_operatortype_append(WM_OT_window_duplicate);
1887         WM_operatortype_append(WM_OT_read_homefile);
1888         WM_operatortype_append(WM_OT_save_homefile);
1889         WM_operatortype_append(WM_OT_window_fullscreen_toggle);
1890         WM_operatortype_append(WM_OT_exit_blender);
1891         WM_operatortype_append(WM_OT_open_recentfile);
1892         WM_operatortype_append(WM_OT_open_mainfile);
1893         WM_operatortype_append(WM_OT_recover_last_session);
1894         WM_operatortype_append(WM_OT_jobs_timer);
1895         WM_operatortype_append(WM_OT_save_as_mainfile);
1896         WM_operatortype_append(WM_OT_save_mainfile);
1897         WM_operatortype_append(WM_OT_ten_timer);
1898         WM_operatortype_append(WM_OT_debug_menu);
1899         WM_operatortype_append(WM_OT_search_menu);
1900 }
1901
1902 /* default keymap for windows and screens, only call once per WM */
1903 void wm_window_keymap(wmWindowManager *wm)
1904 {
1905         ListBase *keymap= WM_keymap_listbase(wm, "Window", 0, 0);
1906         
1907         /* items to make WM work */
1908         WM_keymap_verify_item(keymap, "WM_OT_jobs_timer", TIMERJOBS, KM_ANY, KM_ANY, 0);
1909         
1910         /* note, this doesn't replace existing keymap items */
1911         WM_keymap_verify_item(keymap, "WM_OT_window_duplicate", WKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
1912         WM_keymap_add_item(keymap, "WM_OT_read_homefile", NKEY, KM_PRESS, KM_CTRL, 0);
1913         WM_keymap_add_item(keymap, "WM_OT_read_homefile", NKEY, KM_PRESS, KM_OSKEY, 0);
1914         WM_keymap_add_item(keymap, "WM_OT_read_homefile", XKEY, KM_PRESS, KM_CTRL, 0);
1915         WM_keymap_add_item(keymap, "WM_OT_save_homefile", UKEY, KM_PRESS, KM_CTRL, 0);
1916         WM_keymap_add_item(keymap, "WM_OT_save_homefile", UKEY, KM_PRESS, KM_OSKEY, 0);
1917         WM_keymap_add_item(keymap, "WM_OT_open_recentfile", OKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
1918         WM_keymap_add_item(keymap, "WM_OT_open_recentfile", OKEY, KM_PRESS, KM_SHIFT|KM_OSKEY, 0);
1919         WM_keymap_add_item(keymap, "WM_OT_open_mainfile", OKEY, KM_PRESS, KM_CTRL, 0);
1920         WM_keymap_add_item(keymap, "WM_OT_open_mainfile", OKEY, KM_PRESS, KM_OSKEY, 0);
1921         WM_keymap_add_item(keymap, "WM_OT_open_mainfile", F1KEY, KM_PRESS, 0, 0);
1922         WM_keymap_add_item(keymap, "WM_OT_save_mainfile", SKEY, KM_PRESS, KM_CTRL, 0);
1923         WM_keymap_add_item(keymap, "WM_OT_save_mainfile", SKEY, KM_PRESS, KM_OSKEY, 0);
1924         WM_keymap_add_item(keymap, "WM_OT_save_mainfile", WKEY, KM_PRESS, KM_CTRL, 0);
1925         WM_keymap_add_item(keymap, "WM_OT_save_as_mainfile", SKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
1926         WM_keymap_add_item(keymap, "WM_OT_save_as_mainfile", SKEY, KM_PRESS, KM_SHIFT|KM_OSKEY, 0);
1927         WM_keymap_add_item(keymap, "WM_OT_save_as_mainfile", F2KEY, KM_PRESS, 0, 0);
1928         WM_keymap_verify_item(keymap, "WM_OT_window_fullscreen_toggle", F11KEY, KM_PRESS, KM_SHIFT, 0);
1929         WM_keymap_verify_item(keymap, "WM_OT_exit_blender", QKEY, KM_PRESS, KM_CTRL, 0);
1930
1931         /* debug/testing */
1932         WM_keymap_verify_item(keymap, "WM_OT_ten_timer", TKEY, KM_PRESS, KM_ALT|KM_CTRL, 0);
1933         WM_keymap_verify_item(keymap, "WM_OT_debug_menu", DKEY, KM_PRESS, KM_ALT|KM_CTRL, 0);
1934         WM_keymap_verify_item(keymap, "WM_OT_search_menu", SPACEKEY, KM_PRESS, 0, 0);
1935         
1936 }
1937