UI
[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 <float.h>
30 #define _USE_MATH_DEFINES
31 #include <math.h>
32 #include <string.h>
33
34 #include "DNA_ID.h"
35 #include "DNA_screen_types.h"
36 #include "DNA_userdef_types.h"
37 #include "DNA_windowmanager_types.h"
38
39 #include "MEM_guardedalloc.h"
40
41 #include "BLI_blenlib.h"
42 #include "BLI_dynstr.h" /*for WM_operator_pystring */
43
44 #include "BKE_blender.h"
45 #include "BKE_context.h"
46 #include "BKE_idprop.h"
47 #include "BKE_library.h"
48 #include "BKE_global.h"
49 #include "BKE_main.h"
50 #include "BKE_utildefines.h"
51
52 #include "BIF_gl.h"
53 #include "BIF_glutil.h" /* for paint cursor */
54 #include "IMB_imbuf_types.h"
55
56 #include "ED_screen.h"
57 #include "ED_util.h"
58
59 #include "RNA_access.h"
60 #include "RNA_define.h"
61
62 #include "UI_interface.h"
63 #include "UI_resources.h"
64
65 #include "WM_api.h"
66 #include "WM_types.h"
67
68 #include "wm.h"
69 #include "wm_window.h"
70 #include "wm_subwindow.h"
71 #include "wm_event_system.h"
72
73
74
75 static ListBase global_ops= {NULL, NULL};
76
77 /* ************ operator API, exported ********** */
78
79 wmOperatorType *WM_operatortype_find(const char *idname)
80 {
81         wmOperatorType *ot;
82         
83         for(ot= global_ops.first; ot; ot= ot->next) {
84                 if(strncmp(ot->idname, idname, OP_MAX_TYPENAME)==0)
85                    return ot;
86         }
87         printf("search for unknown operator %s\n", idname);
88         return NULL;
89 }
90
91 wmOperatorType *WM_operatortype_first(void)
92 {
93         return global_ops.first;
94 }
95
96 /* all ops in 1 list (for time being... needs evaluation later) */
97 void WM_operatortype_append(void (*opfunc)(wmOperatorType*))
98 {
99         wmOperatorType *ot;
100         
101         ot= MEM_callocN(sizeof(wmOperatorType), "operatortype");
102         ot->srna= RNA_def_struct(&BLENDER_RNA, "", "OperatorProperties");
103         opfunc(ot);
104         RNA_def_struct_ui_text(ot->srna, ot->name, ot->description ? ot->description:""); // XXX All ops should have a description but for now allow them not to.
105         RNA_def_struct_identifier(ot->srna, ot->idname);
106         BLI_addtail(&global_ops, ot);
107 }
108
109 void WM_operatortype_append_ptr(void (*opfunc)(wmOperatorType*, void*), void *userdata)
110 {
111         wmOperatorType *ot;
112
113         ot= MEM_callocN(sizeof(wmOperatorType), "operatortype");
114         ot->srna= RNA_def_struct(&BLENDER_RNA, "", "OperatorProperties");
115         opfunc(ot, userdata);
116         RNA_def_struct_ui_text(ot->srna, ot->name, "DOC_BROKEN"); /* TODO - add a discription to wmOperatorType? */
117         RNA_def_struct_identifier(ot->srna, ot->idname);
118         BLI_addtail(&global_ops, ot);
119 }
120
121 int WM_operatortype_remove(const char *idname)
122 {
123         wmOperatorType *ot = WM_operatortype_find(idname);
124
125         if (ot==NULL)
126                 return 0;
127         
128         BLI_remlink(&global_ops, ot);
129         RNA_struct_free(&BLENDER_RNA, ot->srna);
130         MEM_freeN(ot);
131
132         return 1;
133 }
134
135 /* print a string representation of the operator, with the args that it runs 
136  * so python can run it again */
137 char *WM_operator_pystring(wmOperator *op)
138 {
139         const char *arg_name= NULL;
140
141         PropertyRNA *prop, *iterprop;
142         CollectionPropertyIterator iter;
143
144         /* for building the string */
145         DynStr *dynstr= BLI_dynstr_new();
146         char *cstring, *buf;
147         int first_iter=1;
148
149         BLI_dynstr_appendf(dynstr, "%s(", op->idname);
150
151         iterprop= RNA_struct_iterator_property(op->ptr->type);
152         RNA_property_collection_begin(op->ptr, iterprop, &iter);
153
154         for(; iter.valid; RNA_property_collection_next(&iter)) {
155                 prop= iter.ptr.data;
156                 arg_name= RNA_property_identifier(prop);
157
158                 if (strcmp(arg_name, "rna_type")==0) continue;
159
160                 buf= RNA_property_as_string(op->ptr, prop);
161                 
162                 BLI_dynstr_appendf(dynstr, first_iter?"%s=%s":", %s=%s", arg_name, buf);
163
164                 MEM_freeN(buf);
165                 first_iter = 0;
166         }
167
168         RNA_property_collection_end(&iter);
169
170         BLI_dynstr_append(dynstr, ")");
171
172         cstring = BLI_dynstr_get_cstring(dynstr);
173         BLI_dynstr_free(dynstr);
174         return cstring;
175 }
176
177 void WM_operator_properties_create(PointerRNA *ptr, const char *opstring)
178 {
179         wmOperatorType *ot= WM_operatortype_find(opstring);
180
181         if(ot)
182                 RNA_pointer_create(NULL, ot->srna, NULL, ptr);
183         else
184                 RNA_pointer_create(NULL, &RNA_OperatorProperties, NULL, ptr);
185 }
186
187 void WM_operator_properties_free(PointerRNA *ptr)
188 {
189         IDProperty *properties= ptr->data;
190
191         if(properties) {
192                 IDP_FreeProperty(properties);
193                 MEM_freeN(properties);
194         }
195 }
196
197 /* ************ default op callbacks, exported *********** */
198
199 /* invoke callback, uses enum property named "type" */
200 /* only weak thing is the fixed property name... */
201 int WM_menu_invoke(bContext *C, wmOperator *op, wmEvent *event)
202 {
203         PropertyRNA *prop= RNA_struct_find_property(op->ptr, "type");
204         uiPopupMenu *pup;
205         uiLayout *layout;
206
207         if(prop==NULL) {
208                 printf("WM_menu_invoke: %s has no \"type\" enum property\n", op->type->idname);
209         }
210         else if (RNA_property_type(prop) != PROP_ENUM) {
211                 printf("WM_menu_invoke: %s \"type\" is not an enum property\n", op->type->idname);
212         }
213         else {
214                 pup= uiPupMenuBegin(op->type->name, 0);
215                 layout= uiPupMenuLayout(pup);
216                 uiItemsEnumO(layout, op->type->idname, "type");
217                 uiPupMenuEnd(C, pup);
218         }
219
220         return OPERATOR_CANCELLED;
221 }
222
223 /* op->invoke */
224 int WM_operator_confirm(bContext *C, wmOperator *op, wmEvent *event)
225 {
226         uiPopupMenu *pup;
227         uiLayout *layout;
228
229         pup= uiPupMenuBegin("OK?", ICON_HELP);
230         layout= uiPupMenuLayout(pup);
231         uiItemO(layout, NULL, 0, op->type->idname);
232         uiPupMenuEnd(C, pup);
233         
234         return OPERATOR_CANCELLED;
235 }
236
237 /* op->invoke, opens fileselect if filename property not set, otherwise executes */
238 int WM_operator_filesel(bContext *C, wmOperator *op, wmEvent *event)
239 {
240         if (RNA_property_is_set(op->ptr, "filename")) {
241                 return WM_operator_call(C, op);
242         } 
243         else {
244                 WM_event_add_fileselect(C, op);
245                 return OPERATOR_RUNNING_MODAL;
246         }
247 }
248
249 /* op->poll */
250 int WM_operator_winactive(bContext *C)
251 {
252         if(CTX_wm_window(C)==NULL) return 0;
253         return 1;
254 }
255
256 /* op->invoke */
257 static void redo_cb(bContext *C, void *arg_op, void *arg2)
258 {
259         wmOperator *lastop= arg_op;
260         
261         if(lastop) {
262                 ED_undo_pop(C);
263                 WM_operator_repeat(C, lastop);
264         }
265 }
266
267 static uiBlock *wm_block_create_redo(bContext *C, ARegion *ar, void *arg_op)
268 {
269         wmWindowManager *wm= CTX_wm_manager(C);
270         wmOperator *op= arg_op;
271         PointerRNA ptr;
272         uiBlock *block;
273         int height;
274         
275         block= uiBeginBlock(C, ar, "redo_popup", UI_EMBOSS);
276         uiBlockClearFlag(block, UI_BLOCK_LOOP);
277         uiBlockSetFlag(block, UI_BLOCK_KEEP_OPEN|UI_BLOCK_RET_1);
278         uiBlockSetFunc(block, redo_cb, arg_op, NULL);
279
280         if(!op->properties) {
281                 IDPropertyTemplate val = {0};
282                 op->properties= IDP_New(IDP_GROUP, val, "wmOperatorProperties");
283         }
284
285         RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
286         height= uiDefAutoButsRNA(C, block, &ptr);
287
288         uiPopupBoundsBlock(block, 4.0f, 0, 0);
289         uiEndBlock(C, block);
290
291         return block;
292 }
293
294 int WM_operator_redo(bContext *C, wmOperator *op, wmEvent *event)
295 {
296         int retval= OPERATOR_CANCELLED;
297         
298         if(op->type->exec)
299                 retval= op->type->exec(C, op);
300
301         if(retval != OPERATOR_CANCELLED)
302                 uiPupBlock(C, wm_block_create_redo, op);
303
304         return retval;
305 }
306
307 int WM_operator_redo_popup(bContext *C, wmOperator *op)
308 {
309         uiPupBlock(C, wm_block_create_redo, op);
310
311         return OPERATOR_CANCELLED;
312 }
313
314 /* ************ window / screen operator definitions ************** */
315
316 static void WM_OT_window_duplicate(wmOperatorType *ot)
317 {
318         ot->name= "Duplicate Window";
319         ot->idname= "WM_OT_window_duplicate";
320         
321         ot->invoke= WM_operator_confirm;
322         ot->exec= wm_window_duplicate_op;
323         ot->poll= WM_operator_winactive;
324 }
325
326 static void WM_OT_save_homefile(wmOperatorType *ot)
327 {
328         ot->name= "Save User Settings";
329         ot->idname= "WM_OT_save_homefile";
330         
331         ot->invoke= WM_operator_confirm;
332         ot->exec= WM_write_homefile;
333         ot->poll= WM_operator_winactive;
334 }
335
336 static void WM_OT_read_homefile(wmOperatorType *ot)
337 {
338         ot->name= "Reload Start-Up File";
339         ot->idname= "WM_OT_read_homefile";
340         
341         ot->invoke= WM_operator_confirm;
342         ot->exec= WM_read_homefile;
343         ot->poll= WM_operator_winactive;
344         
345         RNA_def_boolean(ot->srna, "factory", 0, "Factory Settings", "");
346 }
347
348
349 /* ********* recent file *********** */
350
351 static int recentfile_exec(bContext *C, wmOperator *op)
352 {
353         int event= RNA_enum_get(op->ptr, "nr");
354
355         // XXX wm in context is not set correctly after WM_read_file -> crash
356         // do it before for now, but is this correct with multiple windows?
357
358         if(event>0) {
359                 if (G.sce[0] && (event==1)) {
360                         WM_event_add_notifier(C, NC_WINDOW, NULL);
361                         WM_read_file(C, G.sce, op->reports);
362                 }
363                 else {
364                         struct RecentFile *recent = BLI_findlink(&(G.recent_files), event-2);
365                         if(recent) {
366                                 WM_event_add_notifier(C, NC_WINDOW, NULL);
367                                 WM_read_file(C, recent->filename, op->reports);
368                         }
369                 }
370         }
371         return 0;
372 }
373
374 static int wm_recentfile_invoke(bContext *C, wmOperator *op, wmEvent *event)
375 {
376         struct RecentFile *recent;
377         uiPopupMenu *pup;
378         uiLayout *layout;
379         int i, ofs= 0;
380
381         pup= uiPupMenuBegin("Open Recent", 0);
382         layout= uiPupMenuLayout(pup);
383
384         if(G.sce[0]) {
385                 uiItemIntO(layout, G.sce, 0, op->type->idname, "nr", 1);
386                 ofs = 1;
387         }
388         
389         for(recent = G.recent_files.first, i=0; (i<U.recent_files) && (recent); recent = recent->next, i++)
390                 if(strcmp(recent->filename, G.sce))
391                         uiItemIntO(layout, recent->filename, 0, op->type->idname, "nr", i+ofs+1);
392
393         uiPupMenuEnd(C, pup);
394         
395         return OPERATOR_CANCELLED;
396 }
397
398 static void WM_OT_open_recentfile(wmOperatorType *ot)
399 {
400         ot->name= "Open Recent File";
401         ot->idname= "WM_OT_open_recentfile";
402         
403         ot->invoke= wm_recentfile_invoke;
404         ot->exec= recentfile_exec;
405         ot->poll= WM_operator_winactive;
406         
407         RNA_def_property(ot->srna, "nr", PROP_ENUM, PROP_NONE);
408 }
409
410 /* ********* main file *********** */
411
412 static void untitled(char *name)
413 {
414         if (G.save_over == 0 && strlen(name) < FILE_MAX-16) {
415                 char *c= BLI_last_slash(name);
416                 
417                 if (c)
418                         strcpy(&c[1], "untitled.blend");
419                 else
420                         strcpy(name, "untitled.blend");
421         }
422 }
423
424
425 static int wm_open_mainfile_invoke(bContext *C, wmOperator *op, wmEvent *event)
426 {
427
428         RNA_string_set(op->ptr, "filename", G.sce);
429         WM_event_add_fileselect(C, op);
430
431         return OPERATOR_RUNNING_MODAL;
432 }
433
434 static int wm_open_mainfile_exec(bContext *C, wmOperator *op)
435 {
436         char filename[FILE_MAX];
437         RNA_string_get(op->ptr, "filename", filename);
438         
439         // XXX wm in context is not set correctly after WM_read_file -> crash
440         // do it before for now, but is this correct with multiple windows?
441         WM_event_add_notifier(C, NC_WINDOW, NULL);
442
443         WM_read_file(C, filename, op->reports);
444         
445         return 0;
446 }
447
448 static void WM_OT_open_mainfile(wmOperatorType *ot)
449 {
450         ot->name= "Open Blender File";
451         ot->idname= "WM_OT_open_mainfile";
452         
453         ot->invoke= wm_open_mainfile_invoke;
454         ot->exec= wm_open_mainfile_exec;
455         ot->poll= WM_operator_winactive;
456         
457         ot->flag= 0;
458         
459         RNA_def_property(ot->srna, "filename", PROP_STRING, PROP_FILEPATH);
460
461 }
462
463 static int wm_save_as_mainfile_invoke(bContext *C, wmOperator *op, wmEvent *event)
464 {
465         char name[FILE_MAX];
466         
467         BLI_strncpy(name, G.sce, FILE_MAX);
468         untitled(name);
469         RNA_string_set(op->ptr, "filename", name);
470         
471         WM_event_add_fileselect(C, op);
472
473         return OPERATOR_RUNNING_MODAL;
474 }
475
476 /* function used for WM_OT_save_mainfile too */
477 static int wm_save_as_mainfile_exec(bContext *C, wmOperator *op)
478 {
479         char filename[FILE_MAX];
480         
481         if(RNA_property_is_set(op->ptr, "filename"))
482                 RNA_string_get(op->ptr, "filename", filename);
483         else {
484                 BLI_strncpy(filename, G.sce, FILE_MAX);
485                 untitled(filename);
486         }
487         WM_write_file(C, filename, op->reports);
488         
489         WM_event_add_notifier(C, NC_WM|ND_FILESAVE, NULL);
490
491         return 0;
492 }
493
494 static void WM_OT_save_as_mainfile(wmOperatorType *ot)
495 {
496         ot->name= "Save As Blender File";
497         ot->idname= "WM_OT_save_as_mainfile";
498         
499         ot->invoke= wm_save_as_mainfile_invoke;
500         ot->exec= wm_save_as_mainfile_exec;
501         ot->poll= WM_operator_winactive;
502         
503         ot->flag= 0;
504         
505         RNA_def_property(ot->srna, "filename", PROP_STRING, PROP_FILEPATH);
506
507 }
508
509 /* *************** Save file directly ******** */
510
511 static int wm_save_mainfile_invoke(bContext *C, wmOperator *op, wmEvent *event)
512 {
513         char name[FILE_MAX];
514         
515         BLI_strncpy(name, G.sce, FILE_MAX);
516         untitled(name);
517         RNA_string_set(op->ptr, "filename", name);
518         uiPupMenuSaveOver(C, op, name);
519
520         return OPERATOR_RUNNING_MODAL;
521 }
522
523 static void WM_OT_save_mainfile(wmOperatorType *ot)
524 {
525         ot->name= "Save Blender File";
526         ot->idname= "WM_OT_save_mainfile";
527         
528         ot->invoke= wm_save_mainfile_invoke;
529         ot->exec= wm_save_as_mainfile_exec;
530         ot->poll= WM_operator_winactive;
531         
532         ot->flag= 0;
533         
534         RNA_def_property(ot->srna, "filename", PROP_STRING, PROP_FILEPATH);
535         
536 }
537
538
539 /* *********************** */
540
541 static void WM_OT_window_fullscreen_toggle(wmOperatorType *ot)
542 {
543     ot->name= "Toggle Fullscreen";
544     ot->idname= "WM_OT_window_fullscreen_toggle";
545
546     ot->invoke= WM_operator_confirm;
547     ot->exec= wm_window_fullscreen_toggle_op;
548     ot->poll= WM_operator_winactive;
549 }
550
551 static int wm_exit_blender_op(bContext *C, wmOperator *op)
552 {
553         WM_operator_free(op);
554         
555         WM_exit(C);     
556         
557         return OPERATOR_FINISHED;
558 }
559
560 static void WM_OT_exit_blender(wmOperatorType *ot)
561 {
562         ot->name= "Exit Blender";
563         ot->idname= "WM_OT_exit_blender";
564
565         ot->invoke= WM_operator_confirm;
566         ot->exec= wm_exit_blender_op;
567         ot->poll= WM_operator_winactive;
568 }
569
570 /* ************ default paint cursors, draw always around cursor *********** */
571 /*
572  - returns handler to free 
573  - poll(bContext): returns 1 if draw should happen
574  - draw(bContext): drawing callback for paint cursor
575 */
576
577 void *WM_paint_cursor_activate(wmWindowManager *wm, int (*poll)(bContext *C),
578                                void (*draw)(bContext *C, int, int, void *customdata), void *customdata)
579 {
580         wmPaintCursor *pc= MEM_callocN(sizeof(wmPaintCursor), "paint cursor");
581         
582         BLI_addtail(&wm->paintcursors, pc);
583         
584         pc->customdata = customdata;
585         pc->poll= poll;
586         pc->draw= draw;
587         
588         return pc;
589 }
590
591 void WM_paint_cursor_end(wmWindowManager *wm, void *handle)
592 {
593         wmPaintCursor *pc;
594         
595         for(pc= wm->paintcursors.first; pc; pc= pc->next) {
596                 if(pc == (wmPaintCursor *)handle) {
597                         BLI_remlink(&wm->paintcursors, pc);
598                         MEM_freeN(pc);
599                         return;
600                 }
601         }
602 }
603
604 /* ************ window gesture operator-callback definitions ************** */
605 /*
606  * These are default callbacks for use in operators requiring gesture input
607  */
608
609 /* **************** Border gesture *************** */
610
611 /* Border gesture has two types:
612    1) WM_GESTURE_CROSS_RECT: starts a cross, on mouse click it changes to border 
613    2) WM_GESTURE_RECT: starts immediate as a border, on mouse click or release it ends
614
615    It stores 4 values (xmin, xmax, ymin, ymax) and event it ended with (event_type)
616 */
617
618 static int border_apply(bContext *C, wmOperator *op, int event_type)
619 {
620         wmGesture *gesture= op->customdata;
621         rcti *rect= gesture->customdata;
622         
623         if(rect->xmin > rect->xmax)
624                 SWAP(int, rect->xmin, rect->xmax);
625         if(rect->ymin > rect->ymax)
626                 SWAP(int, rect->ymin, rect->ymax);
627         
628         if(rect->xmin==rect->xmax || rect->ymin==rect->ymax)
629                 return 0;
630                 
631         /* operator arguments and storage. */
632         RNA_int_set(op->ptr, "xmin", rect->xmin);
633         RNA_int_set(op->ptr, "ymin", rect->ymin);
634         RNA_int_set(op->ptr, "xmax", rect->xmax);
635         RNA_int_set(op->ptr, "ymax", rect->ymax);
636         if( RNA_struct_find_property(op->ptr, "event_type") )
637                 RNA_int_set(op->ptr, "event_type", event_type);
638         
639         op->type->exec(C, op);
640         
641         return 1;
642 }
643
644 static void wm_gesture_end(bContext *C, wmOperator *op)
645 {
646         wmGesture *gesture= op->customdata;
647         
648         WM_gesture_end(C, gesture);     /* frees gesture itself, and unregisters from window */
649         op->customdata= NULL;
650
651         ED_area_tag_redraw(CTX_wm_area(C));
652         
653         if( RNA_struct_find_property(op->ptr, "cursor") )
654                 WM_cursor_restore(CTX_wm_window(C));
655 }
656
657 int WM_border_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
658 {
659         op->customdata= WM_gesture_new(C, event, WM_GESTURE_CROSS_RECT);
660
661         /* add modal handler */
662         WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
663         
664         wm_gesture_tag_redraw(C);
665
666         return OPERATOR_RUNNING_MODAL;
667 }
668
669 int WM_border_select_modal(bContext *C, wmOperator *op, wmEvent *event)
670 {
671         wmGesture *gesture= op->customdata;
672         rcti *rect= gesture->customdata;
673         int sx, sy;
674         
675         switch(event->type) {
676                 case MOUSEMOVE:
677                         
678                         wm_subwindow_getorigin(CTX_wm_window(C), gesture->swinid, &sx, &sy);
679                         
680                         if(gesture->type==WM_GESTURE_CROSS_RECT && gesture->mode==0) {
681                                 rect->xmin= rect->xmax= event->x - sx;
682                                 rect->ymin= rect->ymax= event->y - sy;
683                         }
684                         else {
685                                 rect->xmax= event->x - sx;
686                                 rect->ymax= event->y - sy;
687                         }
688                         
689                         wm_gesture_tag_redraw(C);
690
691                         break;
692                         
693                 case LEFTMOUSE:
694                 case MIDDLEMOUSE:
695                 case RIGHTMOUSE:
696                         if(event->val==1) {
697                                 if(gesture->type==WM_GESTURE_CROSS_RECT && gesture->mode==0) {
698                                         gesture->mode= 1;
699                                         wm_gesture_tag_redraw(C);
700                                 }
701                         }
702                         else {
703                                 if(border_apply(C, op, event->type)) {
704                                         wm_gesture_end(C, op);
705                                         return OPERATOR_FINISHED;
706                                 }
707                                 wm_gesture_end(C, op);
708                                 return OPERATOR_CANCELLED;
709                         }
710                         break;
711                 case ESCKEY:
712                         wm_gesture_end(C, op);
713                         return OPERATOR_CANCELLED;
714         }
715         return OPERATOR_RUNNING_MODAL;
716 }
717
718 /* **************** circle gesture *************** */
719 /* works now only for selection or modal paint stuff, calls exec while hold mouse, exit on release */
720
721 int WM_gesture_circle_invoke(bContext *C, wmOperator *op, wmEvent *event)
722 {
723         op->customdata= WM_gesture_new(C, event, WM_GESTURE_CIRCLE);
724         
725         /* add modal handler */
726         WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
727         
728         wm_gesture_tag_redraw(C);
729         
730         return OPERATOR_RUNNING_MODAL;
731 }
732
733 static void gesture_circle_apply(bContext *C, wmOperator *op)
734 {
735         wmGesture *gesture= op->customdata;
736         rcti *rect= gesture->customdata;
737         
738         /* operator arguments and storage. */
739         RNA_int_set(op->ptr, "x", rect->xmin);
740         RNA_int_set(op->ptr, "y", rect->ymin);
741         RNA_int_set(op->ptr, "radius", rect->xmax);
742         
743         if(op->type->exec)
744                 op->type->exec(C, op);
745 }
746
747 int WM_gesture_circle_modal(bContext *C, wmOperator *op, wmEvent *event)
748 {
749         wmGesture *gesture= op->customdata;
750         rcti *rect= gesture->customdata;
751         int sx, sy;
752         
753         switch(event->type) {
754                 case MOUSEMOVE:
755                         
756                         wm_subwindow_getorigin(CTX_wm_window(C), gesture->swinid, &sx, &sy);
757                         
758                         rect->xmin= event->x - sx;
759                         rect->ymin= event->y - sy;
760                         
761                         wm_gesture_tag_redraw(C);
762                         
763                         if(gesture->mode)
764                                 gesture_circle_apply(C, op);
765
766                         break;
767                 case WHEELUPMOUSE:
768                         rect->xmax += 2 + rect->xmax/10;
769                         wm_gesture_tag_redraw(C);
770                         break;
771                 case WHEELDOWNMOUSE:
772                         rect->xmax -= 2 + rect->xmax/10;
773                         if(rect->xmax < 1) rect->xmax= 1;
774                         wm_gesture_tag_redraw(C);
775                         break;
776                 case LEFTMOUSE:
777                 case MIDDLEMOUSE:
778                 case RIGHTMOUSE:
779                         if(event->val==0) {     /* key release */
780                                 wm_gesture_end(C, op);
781                                 return OPERATOR_FINISHED;
782                         }
783                         else {
784                                 if( RNA_struct_find_property(op->ptr, "event_type") )
785                                         RNA_int_set(op->ptr, "event_type", event->type);
786                                 
787                                 /* apply first click */
788                                 gesture_circle_apply(C, op);
789                                 gesture->mode= 1;
790                         }
791                         break;
792                 case ESCKEY:
793                         wm_gesture_end(C, op);
794                         return OPERATOR_CANCELLED;
795         }
796         return OPERATOR_RUNNING_MODAL;
797 }
798
799 #if 0
800 /* template to copy from */
801 void WM_OT_circle_gesture(wmOperatorType *ot)
802 {
803         ot->name= "Circle Gesture";
804         ot->idname= "WM_OT_circle_gesture";
805         
806         ot->invoke= WM_gesture_circle_invoke;
807         ot->modal= WM_gesture_circle_modal;
808         
809         ot->poll= WM_operator_winactive;
810         
811         RNA_def_property(ot->srna, "x", PROP_INT, PROP_NONE);
812         RNA_def_property(ot->srna, "y", PROP_INT, PROP_NONE);
813         RNA_def_property(ot->srna, "radius", PROP_INT, PROP_NONE);
814
815 }
816 #endif
817
818 /* **************** Tweak gesture *************** */
819
820 static void tweak_gesture_modal(bContext *C, wmEvent *event)
821 {
822         wmWindow *window= CTX_wm_window(C);
823         wmGesture *gesture= window->tweak;
824         rcti *rect= gesture->customdata;
825         int sx, sy, val;
826         
827         switch(event->type) {
828                 case MOUSEMOVE:
829                         
830                         wm_subwindow_getorigin(window, gesture->swinid, &sx, &sy);
831                         
832                         rect->xmax= event->x - sx;
833                         rect->ymax= event->y - sy;
834                         
835                         if((val= wm_gesture_evaluate(C, gesture))) {
836                                 wmEvent event;
837
838                                 event= *(window->eventstate);
839                                 if(gesture->event_type==LEFTMOUSE)
840                                         event.type= EVT_TWEAK_L;
841                                 else if(gesture->event_type==RIGHTMOUSE)
842                                         event.type= EVT_TWEAK_R;
843                                 else
844                                         event.type= EVT_TWEAK_M;
845                                 event.val= val;
846                                 /* mouse coords! */
847                                 wm_event_add(window, &event);
848                                 
849                                 WM_gesture_end(C, gesture);     /* frees gesture itself, and unregisters from window */
850                                 window->tweak= NULL;
851                         }
852                         
853                         break;
854                         
855                 case LEFTMOUSE:
856                 case RIGHTMOUSE:
857                 case MIDDLEMOUSE:
858                         if(gesture->event_type==event->type) {
859                                 WM_gesture_end(C, gesture);
860                                 window->tweak= NULL;
861                                 
862                                 /* when tweak fails we should give the other keymap entries a chance */
863                                 event->val= KM_RELEASE;
864                         }
865                         break;
866                 default:
867                         WM_gesture_end(C, gesture);
868                         window->tweak= NULL;
869         }
870 }
871
872 /* standard tweak, called after window handlers passed on event */
873 void wm_tweakevent_test(bContext *C, wmEvent *event, int action)
874 {
875         wmWindow *win= CTX_wm_window(C);
876         
877         if(win->tweak==NULL) {
878                 if(CTX_wm_region(C)) {
879                         if(event->val) { // pressed
880                                 if( ELEM3(event->type, LEFTMOUSE, MIDDLEMOUSE, RIGHTMOUSE) )
881                                         win->tweak= WM_gesture_new(C, event, WM_GESTURE_TWEAK);
882                         }
883                 }
884         }
885         else {
886                 if(action==WM_HANDLER_BREAK) {
887                         WM_gesture_end(C, win->tweak);
888                         win->tweak= NULL;
889                 }
890                 else
891                         tweak_gesture_modal(C, event);
892         }
893 }
894
895 /* *********************** lasso gesture ****************** */
896
897 int WM_gesture_lasso_invoke(bContext *C, wmOperator *op, wmEvent *event)
898 {
899         op->customdata= WM_gesture_new(C, event, WM_GESTURE_LASSO);
900         
901         /* add modal handler */
902         WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
903         
904         wm_gesture_tag_redraw(C);
905         
906         if( RNA_struct_find_property(op->ptr, "cursor") )
907                 WM_cursor_modal(CTX_wm_window(C), RNA_int_get(op->ptr, "cursor"));
908         
909         return OPERATOR_RUNNING_MODAL;
910 }
911
912 int WM_gesture_lines_invoke(bContext *C, wmOperator *op, wmEvent *event)
913 {
914         op->customdata= WM_gesture_new(C, event, WM_GESTURE_LINES);
915         
916         /* add modal handler */
917         WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
918         
919         wm_gesture_tag_redraw(C);
920         
921         if( RNA_struct_find_property(op->ptr, "cursor") )
922                 WM_cursor_modal(CTX_wm_window(C), RNA_int_get(op->ptr, "cursor"));
923         
924         return OPERATOR_RUNNING_MODAL;
925 }
926
927
928 static void gesture_lasso_apply(bContext *C, wmOperator *op, int event_type)
929 {
930         wmGesture *gesture= op->customdata;
931         PointerRNA itemptr;
932         float loc[2];
933         int i;
934         short *lasso= gesture->customdata;
935         
936         /* operator storage as path. */
937
938         for(i=0; i<gesture->points; i++, lasso+=2) {
939                 loc[0]= lasso[0];
940                 loc[1]= lasso[1];
941                 RNA_collection_add(op->ptr, "path", &itemptr);
942                 RNA_float_set_array(&itemptr, "loc", loc);
943         }
944         
945         wm_gesture_end(C, op);
946                 
947         if(op->type->exec)
948                 op->type->exec(C, op);
949         
950 }
951
952 int WM_gesture_lasso_modal(bContext *C, wmOperator *op, wmEvent *event)
953 {
954         wmGesture *gesture= op->customdata;
955         int sx, sy;
956         
957         switch(event->type) {
958                 case MOUSEMOVE:
959                         
960                         wm_gesture_tag_redraw(C);
961                         
962                         wm_subwindow_getorigin(CTX_wm_window(C), gesture->swinid, &sx, &sy);
963                         if(gesture->points < WM_LASSO_MAX_POINTS) {
964                                 short *lasso= gesture->customdata;
965                                 lasso += 2 * gesture->points;
966                                 lasso[0] = event->x - sx;
967                                 lasso[1] = event->y - sy;
968                                 gesture->points++;
969                         }
970                         else {
971                                 gesture_lasso_apply(C, op, event->type);
972                                 return OPERATOR_FINISHED;
973                         }
974                         break;
975                         
976                 case LEFTMOUSE:
977                 case MIDDLEMOUSE:
978                 case RIGHTMOUSE:
979                         if(event->val==0) {     /* key release */
980                                 gesture_lasso_apply(C, op, event->type);
981                                 return OPERATOR_FINISHED;
982                         }
983                         break;
984                 case ESCKEY:
985                         wm_gesture_end(C, op);
986                         return OPERATOR_CANCELLED;
987         }
988         return OPERATOR_RUNNING_MODAL;
989 }
990
991 int WM_gesture_lines_modal(bContext *C, wmOperator *op, wmEvent *event)
992 {
993         return WM_gesture_lasso_modal(C, op, event);
994 }
995
996 #if 0
997 /* template to copy from */
998
999 static int gesture_lasso_exec(bContext *C, wmOperator *op)
1000 {
1001         RNA_BEGIN(op->ptr, itemptr, "path") {
1002                 float loc[2];
1003                 
1004                 RNA_float_get_array(&itemptr, "loc", loc);
1005                 printf("Location: %f %f\n", loc[0], loc[1]);
1006         }
1007         RNA_END;
1008         
1009         return OPERATOR_FINISHED;
1010 }
1011
1012 void WM_OT_lasso_gesture(wmOperatorType *ot)
1013 {
1014         PropertyRNA *prop;
1015         
1016         ot->name= "Lasso Gesture";
1017         ot->idname= "WM_OT_lasso_gesture";
1018         
1019         ot->invoke= WM_gesture_lasso_invoke;
1020         ot->modal= WM_gesture_lasso_modal;
1021         ot->exec= gesture_lasso_exec;
1022         
1023         ot->poll= WM_operator_winactive;
1024         
1025         prop= RNA_def_property(ot->srna, "path", PROP_COLLECTION, PROP_NONE);
1026         RNA_def_property_struct_runtime(prop, &RNA_OperatorMousePath);
1027 }
1028 #endif
1029
1030 /* *********************** radial control ****************** */
1031
1032 const int WM_RADIAL_CONTROL_DISPLAY_SIZE = 200;
1033
1034 typedef struct wmRadialControl {
1035         int mode;
1036         float initial_value, value, max_value;
1037         int initial_mouse[2];
1038         void *cursor;
1039         GLuint tex;
1040 } wmRadialControl;
1041
1042 static void wm_radial_control_paint(bContext *C, int x, int y, void *customdata)
1043 {
1044         wmRadialControl *rc = (wmRadialControl*)customdata;
1045         ARegion *ar = CTX_wm_region(C);
1046         float r1=0.0f, r2=0.0f, r3=0.0f, angle=0.0f;
1047
1048         /* Keep cursor in the original place */
1049         x = rc->initial_mouse[0] - ar->winrct.xmin;
1050         y = rc->initial_mouse[1] - ar->winrct.ymin;
1051
1052         glPushMatrix();
1053         
1054         glTranslatef((float)x, (float)y, 0.0f);
1055
1056         if(rc->mode == WM_RADIALCONTROL_SIZE) {
1057                 r1= rc->value;
1058                 r2= rc->initial_value;
1059                 r3= r1;
1060         } else if(rc->mode == WM_RADIALCONTROL_STRENGTH) {
1061                 r1= (1 - rc->value) * WM_RADIAL_CONTROL_DISPLAY_SIZE;
1062                 r2= WM_RADIAL_CONTROL_DISPLAY_SIZE;
1063                 r3= WM_RADIAL_CONTROL_DISPLAY_SIZE;
1064         } else if(rc->mode == WM_RADIALCONTROL_ANGLE) {
1065                 r1= r2= WM_RADIAL_CONTROL_DISPLAY_SIZE;
1066                 r3= WM_RADIAL_CONTROL_DISPLAY_SIZE;
1067                 angle = rc->value;
1068         }
1069
1070         glColor4ub(255, 255, 255, 128);
1071         glEnable( GL_LINE_SMOOTH );
1072         glEnable(GL_BLEND);
1073
1074         if(rc->mode == WM_RADIALCONTROL_ANGLE)
1075                 fdrawline(0, 0, WM_RADIAL_CONTROL_DISPLAY_SIZE, 0);
1076
1077         if(rc->tex) {
1078                 const float str = rc->mode == WM_RADIALCONTROL_STRENGTH ? (rc->value + 0.5) : 1;
1079
1080                 if(rc->mode == WM_RADIALCONTROL_ANGLE) {
1081                         glRotatef(angle, 0, 0, 1);
1082                         fdrawline(0, 0, WM_RADIAL_CONTROL_DISPLAY_SIZE, 0);
1083                 }
1084
1085                 glBindTexture(GL_TEXTURE_2D, rc->tex);
1086
1087                 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1088                 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1089
1090                 glEnable(GL_TEXTURE_2D);
1091                 glBegin(GL_QUADS);
1092                 glColor4f(0,0,0, str);
1093                 glTexCoord2f(0,0);
1094                 glVertex2f(-r3, -r3);
1095                 glTexCoord2f(1,0);
1096                 glVertex2f(r3, -r3);
1097                 glTexCoord2f(1,1);
1098                 glVertex2f(r3, r3);
1099                 glTexCoord2f(0,1);
1100                 glVertex2f(-r3, r3);
1101                 glEnd();
1102                 glDisable(GL_TEXTURE_2D);
1103         }
1104
1105         glColor4ub(255, 255, 255, 128); 
1106         glutil_draw_lined_arc(0.0, M_PI*2.0, r1, 40);
1107         glutil_draw_lined_arc(0.0, M_PI*2.0, r2, 40);
1108         glDisable(GL_BLEND);
1109         glDisable( GL_LINE_SMOOTH );
1110         
1111         glPopMatrix();
1112 }
1113
1114 int WM_radial_control_modal(bContext *C, wmOperator *op, wmEvent *event)
1115 {
1116         wmRadialControl *rc = (wmRadialControl*)op->customdata;
1117         int mode, initial_mouse[2], delta[2];
1118         float dist;
1119         double new_value = RNA_float_get(op->ptr, "new_value");
1120         int ret = OPERATOR_RUNNING_MODAL;
1121
1122         mode = RNA_int_get(op->ptr, "mode");
1123         RNA_int_get_array(op->ptr, "initial_mouse", initial_mouse);
1124
1125         switch(event->type) {
1126         case MOUSEMOVE:
1127                 delta[0]= initial_mouse[0] - event->x;
1128                 delta[1]= initial_mouse[1] - event->y;
1129                 dist= sqrt(delta[0]*delta[0]+delta[1]*delta[1]);
1130
1131                 if(mode == WM_RADIALCONTROL_SIZE)
1132                         new_value = dist;
1133                 else if(mode == WM_RADIALCONTROL_STRENGTH) {
1134                         new_value = 1 - dist / WM_RADIAL_CONTROL_DISPLAY_SIZE;
1135                 } else if(mode == WM_RADIALCONTROL_ANGLE)
1136                         new_value = ((int)(atan2(delta[1], delta[0]) * (180.0 / M_PI)) + 180);
1137                 
1138                 if(event->ctrl) {
1139                         if(mode == WM_RADIALCONTROL_STRENGTH)
1140                                 new_value = ((int)(new_value * 100) / 10*10) / 100.0f;
1141                         else
1142                                 new_value = ((int)new_value + 5) / 10*10;
1143                 }
1144                 
1145                 break;
1146         case ESCKEY:
1147         case RIGHTMOUSE:
1148                 ret = OPERATOR_CANCELLED;
1149                 break;
1150         case LEFTMOUSE:
1151         case PADENTER:
1152                 op->type->exec(C, op);
1153                 ret = OPERATOR_FINISHED;
1154                 break;
1155         }
1156
1157         /* Clamp */
1158         if(new_value > rc->max_value)
1159                 new_value = rc->max_value;
1160         else if(new_value < 0)
1161                 new_value = 0;
1162
1163         /* Update paint data */
1164         rc->value = new_value;
1165
1166         RNA_float_set(op->ptr, "new_value", new_value);
1167
1168         if(ret != OPERATOR_RUNNING_MODAL) {
1169                 WM_paint_cursor_end(CTX_wm_manager(C), rc->cursor);
1170                 MEM_freeN(rc);
1171         }
1172         
1173         ED_region_tag_redraw(CTX_wm_region(C));
1174
1175         return ret;
1176 }
1177
1178 /* Expects the operator customdata to be an ImBuf (or NULL) */
1179 int WM_radial_control_invoke(bContext *C, wmOperator *op, wmEvent *event)
1180 {
1181         wmRadialControl *rc = MEM_callocN(sizeof(wmRadialControl), "radial control");
1182         int mode = RNA_int_get(op->ptr, "mode");
1183         float initial_value = RNA_float_get(op->ptr, "initial_value");
1184         int mouse[2] = {event->x, event->y};
1185
1186         if(mode == WM_RADIALCONTROL_SIZE) {
1187                 rc->max_value = 200;
1188                 mouse[0]-= initial_value;
1189         }
1190         else if(mode == WM_RADIALCONTROL_STRENGTH) {
1191                 rc->max_value = 1;
1192                 mouse[0]-= WM_RADIAL_CONTROL_DISPLAY_SIZE * (1 - initial_value);
1193         }
1194         else if(mode == WM_RADIALCONTROL_ANGLE) {
1195                 rc->max_value = 360;
1196                 mouse[0]-= WM_RADIAL_CONTROL_DISPLAY_SIZE * cos(initial_value);
1197                 mouse[1]-= WM_RADIAL_CONTROL_DISPLAY_SIZE * sin(initial_value);
1198                 initial_value *= 180.0f/M_PI;
1199         }
1200
1201         if(op->customdata) {
1202                 ImBuf *im = (ImBuf*)op->customdata;
1203                 /* Build GL texture */
1204                 glGenTextures(1, &rc->tex);
1205                 glBindTexture(GL_TEXTURE_2D, rc->tex);
1206                 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, im->x, im->y, 0, GL_ALPHA, GL_FLOAT, im->rect_float);
1207                 MEM_freeN(im->rect_float);
1208                 MEM_freeN(im);
1209         }
1210
1211         RNA_int_set_array(op->ptr, "initial_mouse", mouse);
1212         RNA_float_set(op->ptr, "new_value", initial_value);
1213                 
1214         op->customdata = rc;
1215         rc->mode = mode;
1216         rc->initial_value = initial_value;
1217         rc->initial_mouse[0] = mouse[0];
1218         rc->initial_mouse[1] = mouse[1];
1219         rc->cursor = WM_paint_cursor_activate(CTX_wm_manager(C), op->type->poll,
1220                                               wm_radial_control_paint, op->customdata);
1221
1222         /* add modal handler */
1223         WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
1224         
1225         WM_radial_control_modal(C, op, event);
1226         
1227         return OPERATOR_RUNNING_MODAL;
1228 }
1229
1230 /* Gets a descriptive string of the operation */
1231 void WM_radial_control_string(wmOperator *op, char str[], int maxlen)
1232 {
1233         int mode = RNA_int_get(op->ptr, "mode");
1234         float v = RNA_float_get(op->ptr, "new_value");
1235
1236         if(mode == WM_RADIALCONTROL_SIZE)
1237                 sprintf(str, "Size: %d", (int)v);
1238         else if(mode == WM_RADIALCONTROL_STRENGTH)
1239                 sprintf(str, "Strength: %d", (int)v);
1240         else if(mode == WM_RADIALCONTROL_ANGLE)
1241                 sprintf(str, "Angle: %d", (int)(v * 180.0f/M_PI));
1242 }
1243
1244 /** Important: this doesn't define an actual operator, it
1245     just sets up the common parts of the radial control op. **/
1246 void WM_OT_radial_control_partial(wmOperatorType *ot)
1247 {
1248         static EnumPropertyItem prop_mode_items[] = {
1249                 {WM_RADIALCONTROL_SIZE, "SIZE", "Size", ""},
1250                 {WM_RADIALCONTROL_STRENGTH, "STRENGTH", "Strength", ""},
1251                 {WM_RADIALCONTROL_ANGLE, "ANGLE", "Angle", ""},
1252                 {0, NULL, NULL, NULL}};
1253
1254         /* Should be set in custom invoke() */
1255         RNA_def_float(ot->srna, "initial_value", 0, 0, FLT_MAX, "Initial Value", "", 0, FLT_MAX);
1256
1257         /* Set internally, should be used in custom exec() to get final value */
1258         RNA_def_float(ot->srna, "new_value", 0, 0, FLT_MAX, "New Value", "", 0, FLT_MAX);
1259
1260         /* Should be set before calling operator */
1261         RNA_def_enum(ot->srna, "mode", prop_mode_items, 0, "Mode", "");
1262
1263         /* Internal */
1264         RNA_def_int_vector(ot->srna, "initial_mouse", 2, NULL, INT_MIN, INT_MAX, "initial_mouse", "", INT_MIN, INT_MAX);
1265 }
1266
1267 /* ******************************************************* */
1268  
1269 /* called on initialize WM_exit() */
1270 void wm_operatortype_free(void)
1271 {
1272         BLI_freelistN(&global_ops);
1273 }
1274
1275 /* called on initialize WM_init() */
1276 void wm_operatortype_init(void)
1277 {
1278         WM_operatortype_append(WM_OT_window_duplicate);
1279         WM_operatortype_append(WM_OT_read_homefile);
1280         WM_operatortype_append(WM_OT_save_homefile);
1281         WM_operatortype_append(WM_OT_window_fullscreen_toggle);
1282         WM_operatortype_append(WM_OT_exit_blender);
1283         WM_operatortype_append(WM_OT_open_recentfile);
1284         WM_operatortype_append(WM_OT_open_mainfile);
1285         WM_operatortype_append(WM_OT_jobs_timer);
1286         WM_operatortype_append(WM_OT_save_as_mainfile);
1287         WM_operatortype_append(WM_OT_save_mainfile);
1288 }
1289
1290 /* default keymap for windows and screens, only call once per WM */
1291 void wm_window_keymap(wmWindowManager *wm)
1292 {
1293         ListBase *keymap= WM_keymap_listbase(wm, "Window", 0, 0);
1294         
1295         /* items to make WM work */
1296         WM_keymap_verify_item(keymap, "WM_OT_jobs_timer", TIMERJOBS, KM_ANY, KM_ANY, 0);
1297         
1298         /* note, this doesn't replace existing keymap items */
1299         WM_keymap_verify_item(keymap, "WM_OT_window_duplicate", WKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
1300         WM_keymap_verify_item(keymap, "WM_OT_read_homefile", XKEY, KM_PRESS, KM_CTRL, 0);
1301         WM_keymap_verify_item(keymap, "WM_OT_save_homefile", UKEY, KM_PRESS, KM_CTRL, 0);
1302         WM_keymap_verify_item(keymap, "WM_OT_open_recentfile", OKEY, KM_PRESS, KM_CTRL, 0);
1303         WM_keymap_verify_item(keymap, "WM_OT_open_mainfile", F1KEY, KM_PRESS, 0, 0);
1304         WM_keymap_verify_item(keymap, "WM_OT_save_mainfile", WKEY, KM_PRESS, KM_CTRL, 0);
1305         WM_keymap_verify_item(keymap, "WM_OT_save_as_mainfile", F2KEY, KM_PRESS, 0, 0);
1306         WM_keymap_verify_item(keymap, "WM_OT_window_fullscreen_toggle", F11KEY, KM_PRESS, 0, 0);
1307         WM_keymap_verify_item(keymap, "WM_OT_exit_blender", QKEY, KM_PRESS, KM_CTRL, 0);
1308
1309 }
1310