4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * The Original Code is Copyright (C) 2007 Blender Foundation.
21 * All rights reserved.
24 * Contributor(s): Blender Foundation
26 * ***** END GPL LICENSE BLOCK *****
35 #include "DNA_object_types.h"
36 #include "DNA_screen_types.h"
37 #include "DNA_scene_types.h"
38 #include "DNA_userdef_types.h"
39 #include "DNA_windowmanager_types.h"
41 #include "MEM_guardedalloc.h"
47 #include "BLI_blenlib.h"
48 #include "BLI_dynstr.h" /*for WM_operator_pystring */
51 #include "BLO_readfile.h"
53 #include "BKE_blender.h"
54 #include "BKE_context.h"
55 #include "BKE_depsgraph.h"
56 #include "BKE_idprop.h"
57 #include "BKE_library.h"
58 #include "BKE_global.h"
60 #include "BKE_report.h"
61 #include "BKE_scene.h"
62 #include "BKE_screen.h" /* BKE_ST_MAXNAME */
63 #include "BKE_utildefines.h"
66 #include "BIF_glutil.h" /* for paint cursor */
68 #include "IMB_imbuf_types.h"
70 #include "ED_screen.h"
73 #include "RNA_access.h"
74 #include "RNA_define.h"
76 #include "UI_interface.h"
77 #include "UI_resources.h"
84 #include "wm_event_system.h"
85 #include "wm_event_types.h"
86 #include "wm_subwindow.h"
87 #include "wm_window.h"
91 static ListBase global_ops= {NULL, NULL};
93 /* ************ operator API, exported ********** */
96 wmOperatorType *WM_operatortype_find(const char *idname, int quiet)
100 char idname_bl[OP_MAX_TYPENAME]; // XXX, needed to support python style names without the _OT_ syntax
101 WM_operator_bl_idname(idname_bl, idname);
104 for(ot= global_ops.first; ot; ot= ot->next) {
105 if(strncmp(ot->idname, idname_bl, OP_MAX_TYPENAME)==0)
111 printf("search for unknown operator %s, %s\n", idname_bl, idname);
116 wmOperatorType *WM_operatortype_exists(const char *idname)
120 char idname_bl[OP_MAX_TYPENAME]; // XXX, needed to support python style names without the _OT_ syntax
121 WM_operator_bl_idname(idname_bl, idname);
124 for(ot= global_ops.first; ot; ot= ot->next) {
125 if(strncmp(ot->idname, idname_bl, OP_MAX_TYPENAME)==0)
132 wmOperatorType *WM_operatortype_first(void)
134 return global_ops.first;
137 /* all ops in 1 list (for time being... needs evaluation later) */
138 void WM_operatortype_append(void (*opfunc)(wmOperatorType*))
142 ot= MEM_callocN(sizeof(wmOperatorType), "operatortype");
143 ot->srna= RNA_def_struct(&BLENDER_RNA, "", "OperatorProperties");
147 static char dummy_name[] = "Dummy Name";
148 fprintf(stderr, "ERROR: Operator %s has no name property!\n", ot->idname);
149 ot->name= dummy_name;
152 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.
153 RNA_def_struct_identifier(ot->srna, ot->idname);
154 BLI_addtail(&global_ops, ot);
157 void WM_operatortype_append_ptr(void (*opfunc)(wmOperatorType*, void*), void *userdata)
161 ot= MEM_callocN(sizeof(wmOperatorType), "operatortype");
162 ot->srna= RNA_def_struct(&BLENDER_RNA, "", "OperatorProperties");
163 opfunc(ot, userdata);
164 RNA_def_struct_ui_text(ot->srna, ot->name, ot->description ? ot->description:"(undocumented operator)");
165 RNA_def_struct_identifier(ot->srna, ot->idname);
166 BLI_addtail(&global_ops, ot);
169 /* ********************* macro operator ******************** */
175 static void wm_macro_start(wmOperator *op)
177 if (op->customdata == NULL) {
178 op->customdata = MEM_callocN(sizeof(MacroData), "MacroData");
182 static int wm_macro_end(wmOperator *op, int retval)
184 if (retval & OPERATOR_CANCELLED) {
185 MacroData *md = op->customdata;
187 if (md->retval & OPERATOR_FINISHED) {
188 retval |= OPERATOR_FINISHED;
189 retval &= ~OPERATOR_CANCELLED;
193 /* if modal is ending, free custom data */
194 if (retval & (OPERATOR_FINISHED|OPERATOR_CANCELLED)) {
195 if (op->customdata) {
196 MEM_freeN(op->customdata);
197 op->customdata = NULL;
204 /* macro exec only runs exec calls */
205 static int wm_macro_exec(bContext *C, wmOperator *op)
208 int retval= OPERATOR_FINISHED;
212 for(opm= op->macro.first; opm; opm= opm->next) {
214 if(opm->type->exec) {
215 retval= opm->type->exec(C, opm);
217 if (retval & OPERATOR_FINISHED) {
218 MacroData *md = op->customdata;
219 md->retval = OPERATOR_FINISHED; /* keep in mind that at least one operator finished */
221 break; /* operator didn't finish, end macro */
226 return wm_macro_end(op, retval);
229 int wm_macro_invoke_internal(bContext *C, wmOperator *op, wmEvent *event, wmOperator *opm)
231 int retval= OPERATOR_FINISHED;
233 /* start from operator received as argument */
234 for( ; opm; opm= opm->next) {
235 if(opm->type->invoke)
236 retval= opm->type->invoke(C, opm, event);
237 else if(opm->type->exec)
238 retval= opm->type->exec(C, opm);
240 if (retval & OPERATOR_FINISHED) {
241 MacroData *md = op->customdata;
242 md->retval = OPERATOR_FINISHED; /* keep in mind that at least one operator finished */
244 break; /* operator didn't finish, end macro */
248 return wm_macro_end(op, retval);
251 static int wm_macro_invoke(bContext *C, wmOperator *op, wmEvent *event)
254 return wm_macro_invoke_internal(C, op, event, op->macro.first);
257 static int wm_macro_modal(bContext *C, wmOperator *op, wmEvent *event)
259 wmOperator *opm = op->opm;
260 int retval= OPERATOR_FINISHED;
263 printf("macro error, calling NULL modal()\n");
265 retval = opm->type->modal(C, opm, event);
267 /* if this one is done but it's not the last operator in the macro */
268 if ((retval & OPERATOR_FINISHED) && opm->next) {
269 MacroData *md = op->customdata;
271 md->retval = OPERATOR_FINISHED; /* keep in mind that at least one operator finished */
273 retval = wm_macro_invoke_internal(C, op, event, opm->next);
275 /* if new operator is modal and also added its own handler */
276 if (retval & OPERATOR_RUNNING_MODAL && op->opm != opm) {
277 wmWindow *win = CTX_wm_window(C);
278 wmEventHandler *handler = NULL;
280 for (handler = win->modalhandlers.first; handler; handler = handler->next) {
281 /* first handler in list is the new one */
282 if (handler->op == op)
287 BLI_remlink(&win->modalhandlers, handler);
288 wm_event_free_handler(handler);
291 /* if operator is blocking, grab cursor
292 * This may end up grabbing twice, but we don't care.
294 if(op->opm->type->flag & OPTYPE_BLOCKING) {
295 int bounds[4] = {-1,-1,-1,-1};
296 int wrap = (U.uiflag & USER_CONTINUOUS_MOUSE) && ((op->opm->flag & OP_GRAB_POINTER) || (op->opm->type->flag & OPTYPE_GRAB_POINTER));
299 ARegion *ar= CTX_wm_region(C);
301 bounds[0]= ar->winrct.xmin;
302 bounds[1]= ar->winrct.ymax;
303 bounds[2]= ar->winrct.xmax;
304 bounds[3]= ar->winrct.ymin;
308 WM_cursor_grab(CTX_wm_window(C), wrap, FALSE, bounds);
314 return wm_macro_end(op, retval);
317 static int wm_macro_cancel(bContext *C, wmOperator *op)
319 /* call cancel on the current modal operator, if any */
320 if (op->opm && op->opm->type->cancel) {
321 op->opm->type->cancel(C, op->opm);
324 return wm_macro_end(op, OPERATOR_CANCELLED);
327 /* Names have to be static for now */
328 wmOperatorType *WM_operatortype_append_macro(char *idname, char *name, int flag)
332 if(WM_operatortype_exists(idname)) {
333 printf("Macro error: operator %s exists\n", idname);
337 ot= MEM_callocN(sizeof(wmOperatorType), "operatortype");
338 ot->srna= RNA_def_struct(&BLENDER_RNA, "", "OperatorProperties");
342 ot->flag= OPTYPE_MACRO|flag;
344 ot->exec= wm_macro_exec;
345 ot->invoke= wm_macro_invoke;
346 ot->modal= wm_macro_modal;
347 ot->cancel= wm_macro_cancel;
351 ot->description= "(undocumented operator)";
353 RNA_def_struct_ui_text(ot->srna, ot->name, ot->description); // XXX All ops should have a description but for now allow them not to.
354 RNA_def_struct_identifier(ot->srna, ot->idname);
356 BLI_addtail(&global_ops, ot);
361 void WM_operatortype_append_macro_ptr(void (*opfunc)(wmOperatorType*, void*), void *userdata)
365 ot= MEM_callocN(sizeof(wmOperatorType), "operatortype");
366 ot->srna= RNA_def_struct(&BLENDER_RNA, "", "OperatorProperties");
368 ot->flag= OPTYPE_MACRO;
369 ot->exec= wm_macro_exec;
370 ot->invoke= wm_macro_invoke;
371 ot->modal= wm_macro_modal;
372 ot->cancel= wm_macro_cancel;
376 ot->description= "(undocumented operator)";
378 opfunc(ot, userdata);
380 RNA_def_struct_ui_text(ot->srna, ot->name, ot->description);
381 RNA_def_struct_identifier(ot->srna, ot->idname);
383 BLI_addtail(&global_ops, ot);
386 wmOperatorTypeMacro *WM_operatortype_macro_define(wmOperatorType *ot, const char *idname)
388 wmOperatorTypeMacro *otmacro= MEM_callocN(sizeof(wmOperatorTypeMacro), "wmOperatorTypeMacro");
390 BLI_strncpy(otmacro->idname, idname, OP_MAX_TYPENAME);
392 /* do this on first use, since operatordefinitions might have been not done yet */
393 WM_operator_properties_alloc(&(otmacro->ptr), &(otmacro->properties), idname);
394 WM_operator_properties_sanitize(otmacro->ptr, 1);
396 BLI_addtail(&ot->macro, otmacro);
399 wmOperatorType *otsub = WM_operatortype_find(idname, 0);
400 RNA_def_pointer_runtime(ot->srna, otsub->idname, otsub->srna,
401 otsub->name, otsub->description);
407 static void wm_operatortype_free_macro(wmOperatorType *ot)
409 wmOperatorTypeMacro *otmacro;
411 for(otmacro= ot->macro.first; otmacro; otmacro= otmacro->next) {
413 WM_operator_properties_free(otmacro->ptr);
414 MEM_freeN(otmacro->ptr);
417 BLI_freelistN(&ot->macro);
421 int WM_operatortype_remove(const char *idname)
423 wmOperatorType *ot = WM_operatortype_find(idname, 0);
428 BLI_remlink(&global_ops, ot);
429 RNA_struct_free(&BLENDER_RNA, ot->srna);
432 wm_operatortype_free_macro(ot);
439 /* SOME_OT_op -> some.op */
440 void WM_operator_py_idname(char *to, const char *from)
442 char *sep= strstr(from, "_OT_");
444 int i, ofs= (sep-from);
447 to[i]= tolower(from[i]);
450 BLI_strncpy(to+(ofs+1), sep+4, OP_MAX_TYPENAME);
453 /* should not happen but support just incase */
454 BLI_strncpy(to, from, OP_MAX_TYPENAME);
458 /* some.op -> SOME_OT_op */
459 void WM_operator_bl_idname(char *to, const char *from)
462 char *sep= strchr(from, '.');
465 int i, ofs= (sep-from);
468 to[i]= toupper(from[i]);
470 BLI_strncpy(to+ofs, "_OT_", OP_MAX_TYPENAME);
471 BLI_strncpy(to+(ofs+4), sep+1, OP_MAX_TYPENAME);
474 /* should not happen but support just incase */
475 BLI_strncpy(to, from, OP_MAX_TYPENAME);
482 /* print a string representation of the operator, with the args that it runs
483 * so python can run it again,
485 * When calling from an existing wmOperator do.
486 * WM_operator_pystring(op->type, op->ptr);
488 char *WM_operator_pystring(bContext *C, wmOperatorType *ot, PointerRNA *opptr, int all_args)
490 const char *arg_name= NULL;
491 char idname_py[OP_MAX_TYPENAME];
493 PropertyRNA *prop, *iterprop;
495 /* for building the string */
496 DynStr *dynstr= BLI_dynstr_new();
498 int first_iter=1, ok= 1;
501 /* only to get the orginal props for comparisons */
502 PointerRNA opptr_default;
503 PropertyRNA *prop_default;
505 if(all_args==0 || opptr==NULL) {
506 WM_operator_properties_create_ptr(&opptr_default, ot);
509 opptr = &opptr_default;
513 WM_operator_py_idname(idname_py, ot->idname);
514 BLI_dynstr_appendf(dynstr, "bpy.ops.%s(", idname_py);
516 iterprop= RNA_struct_iterator_property(opptr->type);
518 RNA_PROP_BEGIN(opptr, propptr, iterprop) {
520 arg_name= RNA_property_identifier(prop);
522 if (strcmp(arg_name, "rna_type")==0) continue;
524 buf= RNA_property_as_string(C, opptr, prop);
529 /* not verbose, so only add in attributes that use non-default values
530 * slow but good for tooltips */
531 prop_default= RNA_struct_find_property(&opptr_default, arg_name);
534 buf_default= RNA_property_as_string(C, &opptr_default, prop_default);
536 if(strcmp(buf, buf_default)==0)
537 ok= 0; /* values match, dont bother printing */
539 MEM_freeN(buf_default);
544 BLI_dynstr_appendf(dynstr, first_iter?"%s=%s":", %s=%s", arg_name, buf);
553 if(all_args==0 || opptr==&opptr_default )
554 WM_operator_properties_free(&opptr_default);
556 BLI_dynstr_append(dynstr, ")");
558 cstring = BLI_dynstr_get_cstring(dynstr);
559 BLI_dynstr_free(dynstr);
563 void WM_operator_properties_create_ptr(PointerRNA *ptr, wmOperatorType *ot)
565 RNA_pointer_create(NULL, ot->srna, NULL, ptr);
568 void WM_operator_properties_create(PointerRNA *ptr, const char *opstring)
570 wmOperatorType *ot= WM_operatortype_find(opstring, 0);
573 WM_operator_properties_create_ptr(ptr, ot);
575 RNA_pointer_create(NULL, &RNA_OperatorProperties, NULL, ptr);
578 /* similar to the function above except its uses ID properties
579 * used for keymaps and macros */
580 void WM_operator_properties_alloc(PointerRNA **ptr, IDProperty **properties, const char *opstring)
582 if(*properties==NULL) {
583 IDPropertyTemplate val = {0};
584 *properties= IDP_New(IDP_GROUP, val, "wmOpItemProp");
588 *ptr= MEM_callocN(sizeof(PointerRNA), "wmOpItemPtr");
589 WM_operator_properties_create(*ptr, opstring);
592 (*ptr)->data= *properties;
596 void WM_operator_properties_sanitize(PointerRNA *ptr, int val)
598 RNA_STRUCT_BEGIN(ptr, prop) {
599 switch(RNA_property_type(prop)) {
602 RNA_def_property_flag(prop, PROP_ENUM_NO_CONTEXT);
604 RNA_def_property_clear_flag(prop, PROP_ENUM_NO_CONTEXT);
608 StructRNA *ptype= RNA_property_pointer_type(ptr, prop);
610 /* recurse into operator properties */
611 if (RNA_struct_is_a(ptype, &RNA_OperatorProperties)) {
612 PointerRNA opptr = RNA_property_pointer_get(ptr, prop);
613 WM_operator_properties_sanitize(&opptr, val);
624 void WM_operator_properties_free(PointerRNA *ptr)
626 IDProperty *properties= ptr->data;
629 IDP_FreeProperty(properties);
630 MEM_freeN(properties);
634 /* ************ default op callbacks, exported *********** */
636 /* invoke callback, uses enum property named "type" */
637 int WM_menu_invoke(bContext *C, wmOperator *op, wmEvent *event)
639 PropertyRNA *prop= op->type->prop;
644 printf("WM_menu_invoke: %s has no enum property set\n", op->type->idname);
646 else if (RNA_property_type(prop) != PROP_ENUM) {
647 printf("WM_menu_invoke: %s \"%s\" is not an enum property\n", op->type->idname, RNA_property_identifier(prop));
649 else if (RNA_property_is_set(op->ptr, RNA_property_identifier(prop))) {
650 return op->type->exec(C, op);
653 pup= uiPupMenuBegin(C, op->type->name, 0);
654 layout= uiPupMenuLayout(pup);
655 uiItemsFullEnumO(layout, op->type->idname, (char*)RNA_property_identifier(prop), op->ptr->data, WM_OP_EXEC_REGION_WIN, 0);
656 uiPupMenuEnd(C, pup);
659 return OPERATOR_CANCELLED;
663 /* generic enum search invoke popup */
664 static void operator_enum_search_cb(const struct bContext *C, void *arg_ot, char *str, uiSearchItems *items)
666 wmOperatorType *ot = (wmOperatorType *)arg_ot;
667 PropertyRNA *prop= ot->prop;
670 printf("WM_enum_search_invoke: %s has no enum property set\n", ot->idname);
672 else if (RNA_property_type(prop) != PROP_ENUM) {
673 printf("WM_enum_search_invoke: %s \"%s\" is not an enum property\n", ot->idname, RNA_property_identifier(prop));
678 EnumPropertyItem *item, *item_array;
681 RNA_pointer_create(NULL, ot->srna, NULL, &ptr);
682 RNA_property_enum_items((bContext *)C, &ptr, prop, &item_array, NULL, &free);
684 for(item= item_array; item->identifier; item++) {
685 /* note: need to give the intex rather then the dientifier because the enum can be freed */
686 if(BLI_strcasestr(item->name, str))
687 if(0==uiSearchItemAdd(items, item->name, SET_INT_IN_POINTER(item->value), 0))
692 MEM_freeN(item_array);
696 static void operator_enum_call_cb(struct bContext *C, void *arg1, void *arg2)
698 wmOperatorType *ot= arg1;
701 PointerRNA props_ptr;
702 WM_operator_properties_create_ptr(&props_ptr, ot);
703 RNA_property_enum_set(&props_ptr, ot->prop, GET_INT_FROM_POINTER(arg2));
704 WM_operator_name_call(C, ot->idname, WM_OP_EXEC_DEFAULT, &props_ptr);
705 WM_operator_properties_free(&props_ptr);
709 static uiBlock *wm_enum_search_menu(bContext *C, ARegion *ar, void *arg_op)
711 static char search[256]= "";
713 wmWindow *win= CTX_wm_window(C);
716 wmOperator *op= (wmOperator *)arg_op;
718 block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
719 uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_RET_1|UI_BLOCK_MOVEMOUSE_QUIT);
721 //uiDefBut(block, LABEL, 0, op->type->name, 10, 10, 180, 19, NULL, 0.0, 0.0, 0, 0, ""); // ok, this isnt so easy...
722 but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, 256, 10, 10, 180, 19, 0, 0, "");
723 uiButSetSearchFunc(but, operator_enum_search_cb, op->type, operator_enum_call_cb, NULL);
725 /* fake button, it holds space for search items */
726 uiDefBut(block, LABEL, 0, "", 10, 10 - uiSearchBoxhHeight(), 180, uiSearchBoxhHeight(), NULL, 0, 0, 0, 0, NULL);
728 uiPopupBoundsBlock(block, 6.0f, 0, -20); /* move it downwards, mouse over button */
729 uiEndBlock(C, block);
731 event= *(win->eventstate); /* XXX huh huh? make api call */
732 event.type= EVT_BUT_OPEN;
734 event.customdata= but;
735 event.customdatafree= FALSE;
736 wm_event_add(win, &event);
742 int WM_enum_search_invoke(bContext *C, wmOperator *op, wmEvent *event)
744 uiPupBlock(C, wm_enum_search_menu, op);
745 return OPERATOR_CANCELLED;
748 /* Can't be used as an invoke directly, needs message arg (can be NULL) */
749 int WM_operator_confirm_message(bContext *C, wmOperator *op, char *message)
753 IDProperty *properties= op->ptr->data;
755 if(properties && properties->len)
756 properties= IDP_CopyProperty(op->ptr->data);
760 pup= uiPupMenuBegin(C, "OK?", ICON_QUESTION);
761 layout= uiPupMenuLayout(pup);
762 uiItemFullO(layout, message, 0, op->type->idname, properties, WM_OP_EXEC_REGION_WIN, 0);
763 uiPupMenuEnd(C, pup);
765 return OPERATOR_CANCELLED;
769 int WM_operator_confirm(bContext *C, wmOperator *op, wmEvent *event)
771 return WM_operator_confirm_message(C, op, NULL);
774 /* op->invoke, opens fileselect if path property not set, otherwise executes */
775 int WM_operator_filesel(bContext *C, wmOperator *op, wmEvent *event)
777 if (RNA_property_is_set(op->ptr, "path")) {
778 return WM_operator_call(C, op);
781 WM_event_add_fileselect(C, op);
782 return OPERATOR_RUNNING_MODAL;
786 /* default properties for fileselect */
787 void WM_operator_properties_filesel(wmOperatorType *ot, int filter, short type, short action)
791 RNA_def_string_file_path(ot->srna, "path", "", FILE_MAX, "File Path", "Path to file");
792 RNA_def_string_file_name(ot->srna, "filename", "", FILE_MAX, "File Name", "Name of the file");
793 RNA_def_string_dir_path(ot->srna, "directory", "", FILE_MAX, "Directory", "Directory of the file");
795 if (action == FILE_SAVE) {
796 prop= RNA_def_boolean(ot->srna, "check_existing", 1, "Check Existing", "Check and warn on overwriting existing files");
797 RNA_def_property_flag(prop, PROP_HIDDEN);
800 prop= RNA_def_boolean(ot->srna, "filter_blender", (filter & BLENDERFILE), "Filter .blend files", "");
801 RNA_def_property_flag(prop, PROP_HIDDEN);
802 prop= RNA_def_boolean(ot->srna, "filter_image", (filter & IMAGEFILE), "Filter image files", "");
803 RNA_def_property_flag(prop, PROP_HIDDEN);
804 prop= RNA_def_boolean(ot->srna, "filter_movie", (filter & MOVIEFILE), "Filter movie files", "");
805 RNA_def_property_flag(prop, PROP_HIDDEN);
806 prop= RNA_def_boolean(ot->srna, "filter_python", (filter & PYSCRIPTFILE), "Filter python files", "");
807 RNA_def_property_flag(prop, PROP_HIDDEN);
808 prop= RNA_def_boolean(ot->srna, "filter_font", (filter & FTFONTFILE), "Filter font files", "");
809 RNA_def_property_flag(prop, PROP_HIDDEN);
810 prop= RNA_def_boolean(ot->srna, "filter_sound", (filter & SOUNDFILE), "Filter sound files", "");
811 RNA_def_property_flag(prop, PROP_HIDDEN);
812 prop= RNA_def_boolean(ot->srna, "filter_text", (filter & TEXTFILE), "Filter text files", "");
813 RNA_def_property_flag(prop, PROP_HIDDEN);
814 prop= RNA_def_boolean(ot->srna, "filter_btx", (filter & BTXFILE), "Filter btx files", "");
815 RNA_def_property_flag(prop, PROP_HIDDEN);
816 prop= RNA_def_boolean(ot->srna, "filter_folder", (filter & FOLDERFILE), "Filter folders", "");
817 RNA_def_property_flag(prop, PROP_HIDDEN);
819 prop= RNA_def_int(ot->srna, "filemode", type, FILE_LOADLIB, FILE_SPECIAL,
820 "File Browser Mode", "The setting for the file browser mode to load a .blend file, a library or a special file",
821 FILE_LOADLIB, FILE_SPECIAL);
822 RNA_def_property_flag(prop, PROP_HIDDEN);
825 void WM_operator_properties_select_all(wmOperatorType *ot) {
826 static EnumPropertyItem select_all_actions[] = {
827 {SEL_TOGGLE, "TOGGLE", 0, "Toggle", "Toggle selection for all elements"},
828 {SEL_SELECT, "SELECT", 0, "Select", "Select all elements"},
829 {SEL_DESELECT, "DESELECT", 0, "Deselect", "Deselect all elements"},
830 {SEL_INVERT, "INVERT", 0, "Invert", "Invert selection of all elements"},
831 {0, NULL, 0, NULL, NULL}
834 RNA_def_enum(ot->srna, "action", select_all_actions, SEL_TOGGLE, "Action", "Selection action to execute");
837 void WM_operator_properties_gesture_border(wmOperatorType *ot, int extend)
839 RNA_def_int(ot->srna, "gesture_mode", 0, INT_MIN, INT_MAX, "Gesture Mode", "", INT_MIN, INT_MAX);
840 RNA_def_int(ot->srna, "xmin", 0, INT_MIN, INT_MAX, "X Min", "", INT_MIN, INT_MAX);
841 RNA_def_int(ot->srna, "xmax", 0, INT_MIN, INT_MAX, "X Max", "", INT_MIN, INT_MAX);
842 RNA_def_int(ot->srna, "ymin", 0, INT_MIN, INT_MAX, "Y Min", "", INT_MIN, INT_MAX);
843 RNA_def_int(ot->srna, "ymax", 0, INT_MIN, INT_MAX, "Y Max", "", INT_MIN, INT_MAX);
846 RNA_def_boolean(ot->srna, "extend", 1, "Extend", "Extend selection instead of deselecting everything first");
851 int WM_operator_winactive(bContext *C)
853 if(CTX_wm_window(C)==NULL) return 0;
858 static void redo_cb(bContext *C, void *arg_op, int event)
860 wmOperator *lastop= arg_op;
863 ED_undo_pop_op(C, lastop);
864 WM_operator_repeat(C, lastop);
868 static uiBlock *wm_block_create_redo(bContext *C, ARegion *ar, void *arg_op)
870 wmWindowManager *wm= CTX_wm_manager(C);
871 wmOperator *op= arg_op;
875 uiStyle *style= U.uistyles.first;
876 int columns= 2, width= 300;
879 block= uiBeginBlock(C, ar, "redo_popup", UI_EMBOSS);
880 uiBlockClearFlag(block, UI_BLOCK_LOOP);
881 uiBlockSetFlag(block, UI_BLOCK_KEEP_OPEN|UI_BLOCK_RET_1|UI_BLOCK_MOVEMOUSE_QUIT);
882 uiBlockSetHandleFunc(block, redo_cb, arg_op);
884 if(!op->properties) {
885 IDPropertyTemplate val = {0};
886 op->properties= IDP_New(IDP_GROUP, val, "wmOperatorProperties");
889 // XXX - hack, only for editing docs
890 if(strcmp(op->type->idname, "WM_OT_doc_edit")==0) {
895 RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
896 layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, width, 20, style);
897 uiItemL(layout, op->type->name, 0);
901 op->type->ui((bContext*)C, op);
905 uiDefAutoButsRNA(C, layout, &ptr, columns);
907 uiPopupBoundsBlock(block, 4.0f, 0, 0);
908 uiEndBlock(C, block);
914 static uiBlock *wm_operator_create_ui(bContext *C, ARegion *ar, void *userData)
916 struct { wmOperator *op; int width; int height; } * data = userData;
917 wmWindowManager *wm= CTX_wm_manager(C);
918 wmOperator *op= data->op;
922 uiStyle *style= U.uistyles.first;
924 block= uiBeginBlock(C, ar, "opui_popup", UI_EMBOSS);
925 uiBlockClearFlag(block, UI_BLOCK_LOOP);
926 uiBlockSetFlag(block, UI_BLOCK_KEEP_OPEN|UI_BLOCK_RET_1|UI_BLOCK_MOVEMOUSE_QUIT);
928 if(!op->properties) {
929 IDPropertyTemplate val = {0};
930 op->properties= IDP_New(IDP_GROUP, val, "wmOperatorProperties");
933 RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
934 layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, data->width, data->height, style);
938 op->type->ui((bContext*)C, op);
942 uiPopupBoundsBlock(block, 4.0f, 0, 0);
943 uiEndBlock(C, block);
948 int WM_operator_props_popup(bContext *C, wmOperator *op, wmEvent *event)
950 int retval= OPERATOR_CANCELLED;
953 retval= op->type->exec(C, op);
955 if(retval != OPERATOR_CANCELLED)
956 uiPupBlock(C, wm_block_create_redo, op);
961 void WM_operator_ui_popup(bContext *C, wmOperator *op, int width, int height)
963 struct { wmOperator *op; int width; int height; } data;
966 data.height = height;
967 uiPupBlock(C, wm_operator_create_ui, &data);
970 int WM_operator_redo_popup(bContext *C, wmOperator *op)
972 uiPupBlock(C, wm_block_create_redo, op);
974 return OPERATOR_CANCELLED;
977 /* ***************** Debug menu ************************* */
979 static uiBlock *wm_block_create_menu(bContext *C, ARegion *ar, void *arg_op)
981 wmOperator *op= arg_op;
984 uiStyle *style= U.uistyles.first;
986 block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
987 uiBlockClearFlag(block, UI_BLOCK_LOOP);
988 uiBlockSetFlag(block, UI_BLOCK_KEEP_OPEN|UI_BLOCK_RET_1|UI_BLOCK_MOVEMOUSE_QUIT);
990 layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, 300, 20, style);
991 uiItemL(layout, op->type->name, 0);
999 uiDefAutoButsRNA(C, layout, op->ptr, 2);
1001 uiPopupBoundsBlock(block, 4.0f, 0, 0);
1002 uiEndBlock(C, block);
1007 static int wm_debug_menu_exec(bContext *C, wmOperator *op)
1009 G.rt= RNA_int_get(op->ptr, "debugval");
1010 ED_screen_refresh(CTX_wm_manager(C), CTX_wm_window(C));
1011 WM_event_add_notifier(C, NC_WINDOW, NULL);
1013 return OPERATOR_FINISHED;
1016 static int wm_debug_menu_invoke(bContext *C, wmOperator *op, wmEvent *event)
1019 RNA_int_set(op->ptr, "debugval", G.rt);
1021 /* pass on operator, so return modal */
1022 uiPupBlockOperator(C, wm_block_create_menu, op, WM_OP_EXEC_DEFAULT);
1024 return OPERATOR_RUNNING_MODAL;
1027 static void WM_OT_debug_menu(wmOperatorType *ot)
1029 ot->name= "Debug Menu";
1030 ot->idname= "WM_OT_debug_menu";
1031 ot->description= "Open a popup to set the debug level";
1033 ot->invoke= wm_debug_menu_invoke;
1034 ot->exec= wm_debug_menu_exec;
1035 ot->poll= WM_operator_winactive;
1037 RNA_def_int(ot->srna, "debugval", 0, -10000, 10000, "Debug Value", "", INT_MIN, INT_MAX);
1041 /* ***************** Splash Screen ************************* */
1043 static void wm_block_splash_close(bContext *C, void *arg_block, void *arg_unused)
1045 uiPupBlockClose(C, arg_block);
1048 static uiBlock *wm_block_create_splash(bContext *C, ARegion *ar, void *arg_unused)
1052 uiLayout *layout, *split, *col;
1053 uiStyle *style= U.uistyles.first;
1054 struct RecentFile *recent;
1057 #ifdef NAN_BUILDINFO
1058 int ver_width, rev_width;
1059 char *version_str = NULL;
1060 char *revision_str = NULL;
1061 char version_buf[128];
1062 char revision_buf[128];
1063 extern char * build_rev;
1066 version_str = &version_buf[0];
1067 revision_str = &revision_buf[0];
1069 sprintf(version_str, "%d.%02d.%d", BLENDER_VERSION/100, BLENDER_VERSION%100, BLENDER_SUBVERSION);
1070 sprintf(revision_str, "r%s", build_rev);
1072 /* here on my system I get ugly double quotes around the revision number.
1073 * if so, clip it off: */
1074 cp = strchr(revision_str, '"');
1076 memmove(cp, cp+1, strlen(cp+1));
1077 cp = strchr(revision_str, '"');
1082 BLF_size(style->widgetlabel.points, U.dpi);
1083 ver_width = BLF_width(version_str)+5;
1084 rev_width = BLF_width(revision_str)+5;
1085 #endif //NAN_BUILDINFO
1087 block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
1088 uiBlockSetFlag(block, UI_BLOCK_KEEP_OPEN|UI_BLOCK_RET_1);
1090 but= uiDefBut(block, BUT_IMAGE, 0, "", 0, 10, 501, 282, NULL, 0.0, 0.0, 0, 0, "");
1091 uiButSetFunc(but, wm_block_splash_close, block, NULL);
1093 #ifdef NAN_BUILDINFO
1094 uiDefBut(block, LABEL, 0, version_str, 500-ver_width, 282-24, ver_width, 20, NULL, 0, 0, 0, 0, NULL);
1095 uiDefBut(block, LABEL, 0, revision_str, 500-rev_width, 282-36, rev_width, 20, NULL, 0, 0, 0, 0, NULL);
1096 #endif //NAN_BUILDINFO
1099 uiBlockSetEmboss(block, UI_EMBOSSP);
1101 layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_MENU, 10, 10, 480, 110, style);
1103 uiLayoutSetOperatorContext(layout, WM_OP_EXEC_REGION_WIN);
1105 split = uiLayoutSplit(layout, 0, 0);
1106 col = uiLayoutColumn(split, 0);
1107 uiItemL(col, "Links", 0);
1108 uiItemO(col, NULL, ICON_URL, "HELP_OT_release_logs");
1109 uiItemO(col, NULL, ICON_URL, "HELP_OT_manual");
1110 uiItemO(col, NULL, ICON_URL, "HELP_OT_blender_website");
1111 uiItemO(col, NULL, ICON_URL, "HELP_OT_user_community");
1112 uiItemO(col, NULL, ICON_URL, "HELP_OT_python_api");
1113 uiItemL(col, "", 0);
1115 col = uiLayoutColumn(split, 0);
1116 uiItemL(col, "Recent", 0);
1117 for(recent = G.recent_files.first, i=0; (i<6) && (recent); recent = recent->next, i++) {
1118 char *display_name= BLI_last_slash(recent->filename);
1119 if(display_name) display_name++; /* skip the slash */
1120 else display_name= recent->filename;
1121 uiItemStringO(col, display_name, ICON_FILE_BLEND, "WM_OT_open_mainfile", "path", recent->filename);
1123 uiItemL(col, "Recovery", 0);
1124 uiItemO(col, NULL, ICON_FILE_BLEND, "WM_OT_recover_last_session");
1125 uiItemO(col, NULL, ICON_FILE_BLEND, "WM_OT_recover_auto_save");
1127 uiItemL(col, "", 0);
1129 uiCenteredBoundsBlock(block, 0.0f);
1130 uiEndBlock(C, block);
1135 static int wm_splash_invoke(bContext *C, wmOperator *op, wmEvent *event)
1137 uiPupBlock(C, wm_block_create_splash, NULL);
1139 return OPERATOR_FINISHED;
1142 static void WM_OT_splash(wmOperatorType *ot)
1144 ot->name= "Splash Screen";
1145 ot->idname= "WM_OT_splash";
1146 ot->description= "Opens a blocking popup region with release info";
1148 ot->invoke= wm_splash_invoke;
1149 ot->poll= WM_operator_winactive;
1153 /* ***************** Search menu ************************* */
1154 static void operator_call_cb(struct bContext *C, void *arg1, void *arg2)
1156 wmOperatorType *ot= arg2;
1159 WM_operator_name_call(C, ot->idname, WM_OP_INVOKE_DEFAULT, NULL);
1162 static void operator_search_cb(const struct bContext *C, void *arg, char *str, uiSearchItems *items)
1164 wmOperatorType *ot = WM_operatortype_first();
1166 for(; ot; ot= ot->next) {
1168 if(BLI_strcasestr(ot->name, str)) {
1169 if(WM_operator_poll((bContext*)C, ot)) {
1171 int len= strlen(ot->name);
1173 /* display name for menu, can hold hotkey */
1174 BLI_strncpy(name, ot->name, 256);
1176 /* check for hotkey */
1178 if(WM_key_event_operator_string(C, ot->idname, WM_OP_EXEC_DEFAULT, NULL, &name[len+1], 256-len-1))
1182 if(0==uiSearchItemAdd(items, name, ot, 0))
1189 static uiBlock *wm_block_search_menu(bContext *C, ARegion *ar, void *arg_op)
1191 static char search[256]= "";
1193 wmWindow *win= CTX_wm_window(C);
1197 block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
1198 uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_RET_1|UI_BLOCK_MOVEMOUSE_QUIT);
1200 but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, 256, 10, 10, 180, 19, 0, 0, "");
1201 uiButSetSearchFunc(but, operator_search_cb, NULL, operator_call_cb, NULL);
1203 /* fake button, it holds space for search items */
1204 uiDefBut(block, LABEL, 0, "", 10, 10 - uiSearchBoxhHeight(), 180, uiSearchBoxhHeight(), NULL, 0, 0, 0, 0, NULL);
1206 uiPopupBoundsBlock(block, 6.0f, 0, -20); /* move it downwards, mouse over button */
1207 uiEndBlock(C, block);
1209 event= *(win->eventstate); /* XXX huh huh? make api call */
1210 event.type= EVT_BUT_OPEN;
1211 event.val= KM_PRESS;
1212 event.customdata= but;
1213 event.customdatafree= FALSE;
1214 wm_event_add(win, &event);
1219 static int wm_search_menu_exec(bContext *C, wmOperator *op)
1222 return OPERATOR_FINISHED;
1225 static int wm_search_menu_invoke(bContext *C, wmOperator *op, wmEvent *event)
1228 uiPupBlock(C, wm_block_search_menu, op);
1230 return OPERATOR_CANCELLED;
1234 static int wm_search_menu_poll(bContext *C)
1236 if(CTX_wm_window(C)==NULL) return 0;
1237 if(CTX_wm_area(C) && CTX_wm_area(C)->spacetype==SPACE_CONSOLE) return 0; // XXX - so we can use the shortcut in the console
1238 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
1239 if(CTX_data_edit_object(C) && CTX_data_edit_object(C)->type==OB_CURVE) return 0; // XXX - so we can use the spacebar for entering text
1243 static void WM_OT_search_menu(wmOperatorType *ot)
1245 ot->name= "Search Menu";
1246 ot->idname= "WM_OT_search_menu";
1248 ot->invoke= wm_search_menu_invoke;
1249 ot->exec= wm_search_menu_exec;
1250 ot->poll= wm_search_menu_poll;
1253 static int wm_call_menu_exec(bContext *C, wmOperator *op)
1255 char idname[BKE_ST_MAXNAME];
1256 RNA_string_get(op->ptr, "name", idname);
1258 uiPupMenuInvoke(C, idname);
1260 return OPERATOR_CANCELLED;
1263 static void WM_OT_call_menu(wmOperatorType *ot)
1265 ot->name= "Call Menu";
1266 ot->idname= "WM_OT_call_menu";
1268 ot->exec= wm_call_menu_exec;
1270 RNA_def_string(ot->srna, "name", "", BKE_ST_MAXNAME, "Name", "Name of the menu");
1273 /* ************ window / screen operator definitions ************** */
1275 /* this poll functions is needed in place of WM_operator_winactive
1276 * while it crashes on full screen */
1277 static int wm_operator_winactive_normal(bContext *C)
1279 wmWindow *win= CTX_wm_window(C);
1281 if(win==NULL || win->screen==NULL || win->screen->full != SCREENNORMAL)
1287 static void WM_OT_window_duplicate(wmOperatorType *ot)
1289 ot->name= "Duplicate Window";
1290 ot->idname= "WM_OT_window_duplicate";
1291 ot->description="Duplicate the current Blender window";
1293 ot->exec= wm_window_duplicate_op;
1294 ot->poll= wm_operator_winactive_normal;
1297 static void WM_OT_save_homefile(wmOperatorType *ot)
1299 ot->name= "Save User Settings";
1300 ot->idname= "WM_OT_save_homefile";
1301 ot->description="Make the current file the default .blend file";
1303 ot->invoke= WM_operator_confirm;
1304 ot->exec= WM_write_homefile;
1305 ot->poll= WM_operator_winactive;
1308 static void WM_OT_read_homefile(wmOperatorType *ot)
1310 ot->name= "Reload Start-Up File";
1311 ot->idname= "WM_OT_read_homefile";
1312 ot->description="Open the default file (doesn't save the current file)";
1314 ot->invoke= WM_operator_confirm;
1315 ot->exec= WM_read_homefile;
1316 ot->poll= WM_operator_winactive;
1318 RNA_def_boolean(ot->srna, "factory", 0, "Factory Settings", "");
1321 /* *************** open file **************** */
1323 static void open_set_load_ui(wmOperator *op)
1325 if(!RNA_property_is_set(op->ptr, "load_ui"))
1326 RNA_boolean_set(op->ptr, "load_ui", !(U.flag & USER_FILENOUI));
1329 static void open_set_use_scripts(wmOperator *op)
1331 if(!RNA_property_is_set(op->ptr, "use_scripts"))
1332 RNA_boolean_set(op->ptr, "use_scripts", (U.flag & USER_SCRIPT_AUTOEXEC_DISABLE));
1335 static int wm_open_mainfile_invoke(bContext *C, wmOperator *op, wmEvent *event)
1337 RNA_string_set(op->ptr, "path", G.sce);
1338 open_set_load_ui(op);
1339 open_set_use_scripts(op);
1341 WM_event_add_fileselect(C, op);
1343 return OPERATOR_RUNNING_MODAL;
1346 static int wm_open_mainfile_exec(bContext *C, wmOperator *op)
1348 char path[FILE_MAX];
1350 RNA_string_get(op->ptr, "path", path);
1351 open_set_load_ui(op);
1352 open_set_use_scripts(op);
1354 if(RNA_boolean_get(op->ptr, "load_ui"))
1355 G.fileflags &= ~G_FILE_NO_UI;
1357 G.fileflags |= G_FILE_NO_UI;
1359 if(RNA_boolean_get(op->ptr, "use_scripts"))
1360 G.fileflags |= G_SCRIPT_AUTOEXEC;
1362 G.fileflags &= ~G_SCRIPT_AUTOEXEC;
1364 // XXX wm in context is not set correctly after WM_read_file -> crash
1365 // do it before for now, but is this correct with multiple windows?
1366 WM_event_add_notifier(C, NC_WINDOW, NULL);
1368 WM_read_file(C, path, op->reports);
1370 return OPERATOR_FINISHED;
1373 static void WM_OT_open_mainfile(wmOperatorType *ot)
1375 ot->name= "Open Blender File";
1376 ot->idname= "WM_OT_open_mainfile";
1377 ot->description="Open a Blender file";
1379 ot->invoke= wm_open_mainfile_invoke;
1380 ot->exec= wm_open_mainfile_exec;
1381 ot->poll= WM_operator_winactive;
1383 WM_operator_properties_filesel(ot, FOLDERFILE|BLENDERFILE, FILE_BLENDER, FILE_OPENFILE);
1385 RNA_def_boolean(ot->srna, "load_ui", 1, "Load UI", "Load user interface setup in the .blend file");
1386 RNA_def_boolean(ot->srna, "use_scripts", 1, "Trusted Source", "Allow blend file execute scripts automatically, default available from system preferences");
1389 /* **************** link/append *************** */
1391 static int wm_link_append_invoke(bContext *C, wmOperator *op, wmEvent *event)
1393 if(RNA_property_is_set(op->ptr, "path")) {
1394 return WM_operator_call(C, op);
1397 /* XXX TODO solve where to get last linked library from */
1398 RNA_string_set(op->ptr, "path", G.lib);
1399 WM_event_add_fileselect(C, op);
1400 return OPERATOR_RUNNING_MODAL;
1404 static short wm_link_append_flag(wmOperator *op)
1408 if(RNA_boolean_get(op->ptr, "autoselect")) flag |= FILE_AUTOSELECT;
1409 if(RNA_boolean_get(op->ptr, "active_layer")) flag |= FILE_ACTIVELAY;
1410 if(RNA_boolean_get(op->ptr, "relative_paths")) flag |= FILE_STRINGCODE;
1411 if(RNA_boolean_get(op->ptr, "link")) flag |= FILE_LINK;
1412 if(RNA_boolean_get(op->ptr, "instance_groups")) flag |= FILE_GROUP_INSTANCE;
1416 static void wm_link_make_library_local(Main *main, const char *libname)
1420 /* and now find the latest append lib file */
1421 for(lib= main->library.first; lib; lib=lib->id.next)
1422 if(BLI_streq(libname, lib->filename))
1431 static int wm_link_append_exec(bContext *C, wmOperator *op)
1433 Main *bmain= CTX_data_main(C);
1434 Scene *scene= CTX_data_scene(C);
1438 char name[FILE_MAX], dir[FILE_MAX], libname[FILE_MAX], group[GROUP_MAX];
1439 int idcode, totfiles=0;
1443 RNA_string_get(op->ptr, "filename", name);
1444 RNA_string_get(op->ptr, "directory", dir);
1446 /* test if we have a valid data */
1447 if(BLO_is_a_library(dir, libname, group) == 0) {
1448 BKE_report(op->reports, RPT_ERROR, "Not a library");
1449 return OPERATOR_CANCELLED;
1451 else if(group[0] == 0) {
1452 BKE_report(op->reports, RPT_ERROR, "Nothing indicated");
1453 return OPERATOR_CANCELLED;
1455 else if(BLI_streq(bmain->name, libname)) {
1456 BKE_report(op->reports, RPT_ERROR, "Cannot use current file as library");
1457 return OPERATOR_CANCELLED;
1460 /* check if something is indicated for append/link */
1461 prop = RNA_struct_find_property(op->ptr, "files");
1463 totfiles= RNA_property_collection_length(op->ptr, prop);
1465 if(name[0] == '\0') {
1466 BKE_report(op->reports, RPT_ERROR, "Nothing indicated");
1467 return OPERATOR_CANCELLED;
1471 else if(name[0] == '\0') {
1472 BKE_report(op->reports, RPT_ERROR, "Nothing indicated");
1473 return OPERATOR_CANCELLED;
1476 /* now we have or selected, or an indicated file */
1477 if(RNA_boolean_get(op->ptr, "autoselect"))
1478 scene_deselect_all(scene);
1480 bh = BLO_blendhandle_from_file(libname);
1481 idcode = BLO_idcode_from_name(group);
1483 flag = wm_link_append_flag(op);
1485 /* tag everything, all untagged data can be made local
1486 * its also generally useful to know what is new
1488 * take extra care flag_all_listbases_ids(LIB_LINK_TAG, 0) is called after! */
1489 flag_all_listbases_ids(LIB_PRE_EXISTING, 1);
1491 /* here appending/linking starts */
1492 mainl = BLO_library_append_begin(C, &bh, libname);
1494 BLO_library_append_named_part(C, mainl, &bh, name, idcode, flag);
1497 RNA_BEGIN(op->ptr, itemptr, "files") {
1498 RNA_string_get(&itemptr, "name", name);
1499 BLO_library_append_named_part(C, mainl, &bh, name, idcode, flag);
1503 BLO_library_append_end(C, mainl, &bh, idcode, flag);
1505 /* mark all library linked objects to be updated */
1506 recalc_all_library_objects(bmain);
1508 /* append, rather than linking */
1509 if((flag & FILE_LINK)==0)
1510 wm_link_make_library_local(bmain, libname);
1512 /* important we unset, otherwise these object wont
1513 * link into other scenes from this blend file */
1514 flag_all_listbases_ids(LIB_PRE_EXISTING, 0);
1516 /* recreate dependency graph to include new objects */
1517 DAG_scene_sort(scene);
1518 DAG_ids_flush_update(0);
1520 BLO_blendhandle_close(bh);
1522 /* XXX TODO: align G.lib with other directory storage (like last opened image etc...) */
1523 BLI_strncpy(G.lib, dir, FILE_MAX);
1525 WM_event_add_notifier(C, NC_WINDOW, NULL);
1527 return OPERATOR_FINISHED;
1530 static void WM_OT_link_append(wmOperatorType *ot)
1532 ot->name= "Link/Append from Library";
1533 ot->idname= "WM_OT_link_append";
1534 ot->description= "Link or Append from a Library .blend file";
1536 ot->invoke= wm_link_append_invoke;
1537 ot->exec= wm_link_append_exec;
1538 ot->poll= WM_operator_winactive;
1540 ot->flag |= OPTYPE_UNDO;
1542 WM_operator_properties_filesel(ot, FOLDERFILE|BLENDERFILE, FILE_LOADLIB, FILE_OPENFILE);
1544 RNA_def_boolean(ot->srna, "link", 1, "Link", "Link the objects or datablocks rather than appending");
1545 RNA_def_boolean(ot->srna, "autoselect", 1, "Select", "Select the linked objects");
1546 RNA_def_boolean(ot->srna, "active_layer", 1, "Active Layer", "Put the linked objects on the active layer");
1547 RNA_def_boolean(ot->srna, "instance_groups", 1, "Instance Groups", "Create instances for each group as a DupliGroup");
1548 RNA_def_boolean(ot->srna, "relative_paths", 1, "Relative Paths", "Store the library path as a relative path to current .blend file");
1550 RNA_def_collection_runtime(ot->srna, "files", &RNA_OperatorFileListElement, "Files", "");
1553 /* *************** recover last session **************** */
1555 static int wm_recover_last_session_exec(bContext *C, wmOperator *op)
1557 char filename[FILE_MAX];
1559 G.fileflags |= G_FILE_RECOVER;
1561 // XXX wm in context is not set correctly after WM_read_file -> crash
1562 // do it before for now, but is this correct with multiple windows?
1563 WM_event_add_notifier(C, NC_WINDOW, NULL);
1566 BLI_make_file_string("/", filename, btempdir, "quit.blend");
1567 WM_read_file(C, filename, op->reports);
1569 G.fileflags &= ~G_FILE_RECOVER;
1571 return OPERATOR_FINISHED;
1574 static void WM_OT_recover_last_session(wmOperatorType *ot)
1576 ot->name= "Recover Last Session";
1577 ot->idname= "WM_OT_recover_last_session";
1578 ot->description="Open the last closed file (\"quit.blend\")";
1580 ot->exec= wm_recover_last_session_exec;
1581 ot->poll= WM_operator_winactive;
1584 /* *************** recover auto save **************** */
1586 static int wm_recover_auto_save_exec(bContext *C, wmOperator *op)
1588 char path[FILE_MAX];
1590 RNA_string_get(op->ptr, "path", path);
1592 G.fileflags |= G_FILE_RECOVER;
1594 // XXX wm in context is not set correctly after WM_read_file -> crash
1595 // do it before for now, but is this correct with multiple windows?
1596 WM_event_add_notifier(C, NC_WINDOW, NULL);
1599 WM_read_file(C, path, op->reports);
1601 G.fileflags &= ~G_FILE_RECOVER;
1603 return OPERATOR_FINISHED;
1606 static int wm_recover_auto_save_invoke(bContext *C, wmOperator *op, wmEvent *event)
1608 char filename[FILE_MAX];
1610 wm_autosave_location(filename);
1611 RNA_string_set(op->ptr, "path", filename);
1612 WM_event_add_fileselect(C, op);
1614 return OPERATOR_RUNNING_MODAL;
1617 static void WM_OT_recover_auto_save(wmOperatorType *ot)
1619 ot->name= "Recover Auto Save";
1620 ot->idname= "WM_OT_recover_auto_save";
1621 ot->description="Open an automatically saved file to recover it";
1623 ot->exec= wm_recover_auto_save_exec;
1624 ot->invoke= wm_recover_auto_save_invoke;
1625 ot->poll= WM_operator_winactive;
1627 WM_operator_properties_filesel(ot, BLENDERFILE, FILE_BLENDER, FILE_OPENFILE);
1630 /* *************** save file as **************** */
1632 static void untitled(char *name)
1634 if(G.save_over == 0 && strlen(name) < FILE_MAX-16) {
1635 char *c= BLI_last_slash(name);
1638 strcpy(&c[1], "untitled.blend");
1640 strcpy(name, "untitled.blend");
1644 static void save_set_compress(wmOperator *op)
1646 if(!RNA_property_is_set(op->ptr, "compress")) {
1647 if(G.save_over) /* keep flag for existing file */
1648 RNA_boolean_set(op->ptr, "compress", G.fileflags & G_FILE_COMPRESS);
1649 else /* use userdef for new file */
1650 RNA_boolean_set(op->ptr, "compress", U.flag & USER_FILECOMPRESS);
1654 static int wm_save_as_mainfile_invoke(bContext *C, wmOperator *op, wmEvent *event)
1656 char name[FILE_MAX];
1658 save_set_compress(op);
1660 BLI_strncpy(name, G.sce, FILE_MAX);
1662 RNA_string_set(op->ptr, "path", name);
1664 WM_event_add_fileselect(C, op);
1666 return OPERATOR_RUNNING_MODAL;
1669 /* function used for WM_OT_save_mainfile too */
1670 static int wm_save_as_mainfile_exec(bContext *C, wmOperator *op)
1672 char path[FILE_MAX];
1675 save_set_compress(op);
1677 if(RNA_property_is_set(op->ptr, "path"))
1678 RNA_string_get(op->ptr, "path", path);
1680 BLI_strncpy(path, G.sce, FILE_MAX);
1684 fileflags= G.fileflags;
1686 /* set compression flag */
1687 if(RNA_boolean_get(op->ptr, "compress")) fileflags |= G_FILE_COMPRESS;
1688 else fileflags &= ~G_FILE_COMPRESS;
1689 if(RNA_boolean_get(op->ptr, "relative_remap")) fileflags |= G_FILE_RELATIVE_REMAP;
1690 else fileflags &= ~G_FILE_RELATIVE_REMAP;
1692 WM_write_file(C, path, fileflags, op->reports);
1694 WM_event_add_notifier(C, NC_WM|ND_FILESAVE, NULL);
1699 static void WM_OT_save_as_mainfile(wmOperatorType *ot)
1701 ot->name= "Save As Blender File";
1702 ot->idname= "WM_OT_save_as_mainfile";
1703 ot->description="Save the current file in the desired location";
1705 ot->invoke= wm_save_as_mainfile_invoke;
1706 ot->exec= wm_save_as_mainfile_exec;
1707 ot->poll= WM_operator_winactive;
1709 WM_operator_properties_filesel(ot, FOLDERFILE|BLENDERFILE, FILE_BLENDER, FILE_SAVE);
1710 RNA_def_boolean(ot->srna, "compress", 0, "Compress", "Write compressed .blend file");
1711 RNA_def_boolean(ot->srna, "relative_remap", 0, "Remap Relative", "Remap relative paths when saving in a different directory");
1714 /* *************** save file directly ******** */
1716 static int wm_save_mainfile_invoke(bContext *C, wmOperator *op, wmEvent *event)
1718 char name[FILE_MAX];
1719 int check_existing=1;
1721 /* cancel if no active window */
1722 if (CTX_wm_window(C) == NULL)
1723 return OPERATOR_CANCELLED;
1725 save_set_compress(op);
1727 BLI_strncpy(name, G.sce, FILE_MAX);
1729 RNA_string_set(op->ptr, "path", name);
1731 if (RNA_struct_find_property(op->ptr, "check_existing"))
1732 if (RNA_boolean_get(op->ptr, "check_existing")==0)
1737 uiPupMenuSaveOver(C, op, name);
1739 WM_operator_call(C, op);
1742 WM_event_add_fileselect(C, op);
1745 return OPERATOR_RUNNING_MODAL;
1748 static void WM_OT_save_mainfile(wmOperatorType *ot)
1750 ot->name= "Save Blender File";
1751 ot->idname= "WM_OT_save_mainfile";
1752 ot->description="Save the current Blender file";
1754 ot->invoke= wm_save_mainfile_invoke;
1755 ot->exec= wm_save_as_mainfile_exec;
1758 WM_operator_properties_filesel(ot, FOLDERFILE|BLENDERFILE, FILE_BLENDER, FILE_SAVE);
1759 RNA_def_boolean(ot->srna, "compress", 0, "Compress", "Write compressed .blend file");
1760 RNA_def_boolean(ot->srna, "relative_remap", 0, "Remap Relative", "Remap relative paths when saving in a different directory");
1764 /* XXX: move these collada operators to a more appropriate place */
1767 #include "../../collada/collada.h"
1769 static int wm_collada_export_invoke(bContext *C, wmOperator *op, wmEvent *event)
1771 //char name[FILE_MAX];
1772 //BLI_strncpy(name, G.sce, FILE_MAX);
1775 /* RNA_string_set(op->ptr, "path", "/tmp/test.dae"); */
1777 WM_event_add_fileselect(C, op);
1779 return OPERATOR_RUNNING_MODAL;
1782 /* function used for WM_OT_save_mainfile too */
1783 static int wm_collada_export_exec(bContext *C, wmOperator *op)
1785 char filename[FILE_MAX];
1787 if(RNA_property_is_set(op->ptr, "path"))
1788 RNA_string_get(op->ptr, "path", filename);
1790 BLI_strncpy(filename, G.sce, FILE_MAX);
1794 //WM_write_file(C, filename, op->reports);
1795 collada_export(CTX_data_scene(C), filename);
1797 /* WM_event_add_notifier(C, NC_WM|ND_FILESAVE, NULL); */
1799 return OPERATOR_FINISHED;
1802 static void WM_OT_collada_export(wmOperatorType *ot)
1804 ot->name= "Export COLLADA";
1805 ot->idname= "WM_OT_collada_export";
1807 ot->invoke= wm_collada_export_invoke;
1808 ot->exec= wm_collada_export_exec;
1809 ot->poll= WM_operator_winactive;
1813 RNA_def_property(ot->srna, "path", PROP_STRING, PROP_FILEPATH);
1816 static int wm_collada_import_invoke(bContext *C, wmOperator *op, wmEvent *event)
1818 /* RNA_string_set(op->ptr, "path", "/tmp/test.dae"); */
1820 WM_event_add_fileselect(C, op);
1822 return OPERATOR_RUNNING_MODAL;
1825 /* function used for WM_OT_save_mainfile too */
1826 static int wm_collada_import_exec(bContext *C, wmOperator *op)
1828 char filename[FILE_MAX];
1830 if(RNA_property_is_set(op->ptr, "path"))
1831 RNA_string_get(op->ptr, "path", filename);
1833 BLI_strncpy(filename, G.sce, FILE_MAX);
1837 //WM_write_file(C, filename, op->reports);
1838 collada_import(C, filename);
1840 /* WM_event_add_notifier(C, NC_WM|ND_FILESAVE, NULL); */
1842 return OPERATOR_FINISHED;
1845 static void WM_OT_collada_import(wmOperatorType *ot)
1847 ot->name= "Import COLLADA";
1848 ot->idname= "WM_OT_collada_import";
1850 ot->invoke= wm_collada_import_invoke;
1851 ot->exec= wm_collada_import_exec;
1852 ot->poll= WM_operator_winactive;
1856 RNA_def_property(ot->srna, "path", PROP_STRING, PROP_FILEPATH);
1863 /* *********************** */
1865 static void WM_OT_window_fullscreen_toggle(wmOperatorType *ot)
1867 ot->name= "Toggle Fullscreen";
1868 ot->idname= "WM_OT_window_fullscreen_toggle";
1869 ot->description="Toggle the current window fullscreen";
1871 ot->exec= wm_window_fullscreen_toggle_op;
1872 ot->poll= WM_operator_winactive;
1875 static int wm_exit_blender_op(bContext *C, wmOperator *op)
1877 WM_operator_free(op);
1881 return OPERATOR_FINISHED;
1884 static void WM_OT_exit_blender(wmOperatorType *ot)
1886 ot->name= "Exit Blender";
1887 ot->idname= "WM_OT_exit_blender";
1888 ot->description= "Quit Blender";
1890 ot->invoke= WM_operator_confirm;
1891 ot->exec= wm_exit_blender_op;
1892 ot->poll= WM_operator_winactive;
1895 /* ************ default paint cursors, draw always around cursor *********** */
1897 - returns handler to free
1898 - poll(bContext): returns 1 if draw should happen
1899 - draw(bContext): drawing callback for paint cursor
1902 void *WM_paint_cursor_activate(wmWindowManager *wm, int (*poll)(bContext *C),
1903 wmPaintCursorDraw draw, void *customdata)
1905 wmPaintCursor *pc= MEM_callocN(sizeof(wmPaintCursor), "paint cursor");
1907 BLI_addtail(&wm->paintcursors, pc);
1909 pc->customdata = customdata;
1916 void WM_paint_cursor_end(wmWindowManager *wm, void *handle)
1920 for(pc= wm->paintcursors.first; pc; pc= pc->next) {
1921 if(pc == (wmPaintCursor *)handle) {
1922 BLI_remlink(&wm->paintcursors, pc);
1929 /* ************ window gesture operator-callback definitions ************** */
1931 * These are default callbacks for use in operators requiring gesture input
1934 /* **************** Border gesture *************** */
1936 /* Border gesture has two types:
1937 1) WM_GESTURE_CROSS_RECT: starts a cross, on mouse click it changes to border
1938 2) WM_GESTURE_RECT: starts immediate as a border, on mouse click or release it ends
1940 It stores 4 values (xmin, xmax, ymin, ymax) and event it ended with (event_type)
1943 static int border_apply(bContext *C, wmOperator *op, int gesture_mode)
1945 wmGesture *gesture= op->customdata;
1946 rcti *rect= gesture->customdata;
1948 if(rect->xmin > rect->xmax)
1949 SWAP(int, rect->xmin, rect->xmax);
1950 if(rect->ymin > rect->ymax)
1951 SWAP(int, rect->ymin, rect->ymax);
1953 if(rect->xmin==rect->xmax || rect->ymin==rect->ymax)
1956 /* operator arguments and storage. */
1957 RNA_int_set(op->ptr, "xmin", rect->xmin);
1958 RNA_int_set(op->ptr, "ymin", rect->ymin);
1959 RNA_int_set(op->ptr, "xmax", rect->xmax);
1960 RNA_int_set(op->ptr, "ymax", rect->ymax);
1962 /* XXX weak; border should be configured for this without reading event types */
1963 if( RNA_struct_find_property(op->ptr, "gesture_mode") )
1964 RNA_int_set(op->ptr, "gesture_mode", gesture_mode);
1966 op->type->exec(C, op);
1971 static void wm_gesture_end(bContext *C, wmOperator *op)
1973 wmGesture *gesture= op->customdata;
1975 WM_gesture_end(C, gesture); /* frees gesture itself, and unregisters from window */
1976 op->customdata= NULL;
1978 ED_area_tag_redraw(CTX_wm_area(C));
1980 if( RNA_struct_find_property(op->ptr, "cursor") )
1981 WM_cursor_restore(CTX_wm_window(C));
1984 int WM_border_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
1986 if(ISTWEAK(event->type))
1987 op->customdata= WM_gesture_new(C, event, WM_GESTURE_RECT);
1989 op->customdata= WM_gesture_new(C, event, WM_GESTURE_CROSS_RECT);
1991 /* add modal handler */
1992 WM_event_add_modal_handler(C, op);
1994 wm_gesture_tag_redraw(C);
1996 return OPERATOR_RUNNING_MODAL;
1999 int WM_border_select_modal(bContext *C, wmOperator *op, wmEvent *event)
2001 wmGesture *gesture= op->customdata;
2002 rcti *rect= gesture->customdata;
2005 if(event->type== MOUSEMOVE) {
2006 wm_subwindow_getorigin(CTX_wm_window(C), gesture->swinid, &sx, &sy);
2008 if(gesture->type==WM_GESTURE_CROSS_RECT && gesture->mode==0) {
2009 rect->xmin= rect->xmax= event->x - sx;
2010 rect->ymin= rect->ymax= event->y - sy;
2013 rect->xmax= event->x - sx;
2014 rect->ymax= event->y - sy;
2017 wm_gesture_tag_redraw(C);
2019 else if (event->type==EVT_MODAL_MAP) {
2020 switch (event->val) {
2021 case GESTURE_MODAL_BORDER_BEGIN:
2022 if(gesture->type==WM_GESTURE_CROSS_RECT && gesture->mode==0) {
2024 wm_gesture_tag_redraw(C);
2027 case GESTURE_MODAL_SELECT:
2028 case GESTURE_MODAL_DESELECT:
2029 if(border_apply(C, op, event->val)) {
2030 wm_gesture_end(C, op);
2031 return OPERATOR_FINISHED;
2033 wm_gesture_end(C, op);
2034 return OPERATOR_CANCELLED;
2037 case GESTURE_MODAL_CANCEL:
2038 wm_gesture_end(C, op);
2039 return OPERATOR_CANCELLED;
2043 // // Allow view navigation???
2045 // return OPERATOR_PASS_THROUGH;
2048 return OPERATOR_RUNNING_MODAL;
2051 /* **************** circle gesture *************** */
2052 /* works now only for selection or modal paint stuff, calls exec while hold mouse, exit on release */
2054 #ifdef GESTURE_MEMORY
2055 int circle_select_size= 25; // XXX - need some operator memory thing\!
2058 int WM_gesture_circle_invoke(bContext *C, wmOperator *op, wmEvent *event)
2060 op->customdata= WM_gesture_new(C, event, WM_GESTURE_CIRCLE);
2062 /* add modal handler */
2063 WM_event_add_modal_handler(C, op);
2065 wm_gesture_tag_redraw(C);
2067 return OPERATOR_RUNNING_MODAL;
2070 static void gesture_circle_apply(bContext *C, wmOperator *op)
2072 wmGesture *gesture= op->customdata;
2073 rcti *rect= gesture->customdata;
2075 if(RNA_int_get(op->ptr, "gesture_mode")==GESTURE_MODAL_NOP)
2078 /* operator arguments and storage. */
2079 RNA_int_set(op->ptr, "x", rect->xmin);
2080 RNA_int_set(op->ptr, "y", rect->ymin);
2081 RNA_int_set(op->ptr, "radius", rect->xmax);
2084 op->type->exec(C, op);
2086 #ifdef GESTURE_MEMORY
2087 circle_select_size= rect->xmax;
2091 int WM_gesture_circle_modal(bContext *C, wmOperator *op, wmEvent *event)
2093 wmGesture *gesture= op->customdata;
2094 rcti *rect= gesture->customdata;
2097 if(event->type== MOUSEMOVE) {
2098 wm_subwindow_getorigin(CTX_wm_window(C), gesture->swinid, &sx, &sy);
2100 rect->xmin= event->x - sx;
2101 rect->ymin= event->y - sy;
2103 wm_gesture_tag_redraw(C);
2106 gesture_circle_apply(C, op);
2108 else if (event->type==EVT_MODAL_MAP) {
2109 switch (event->val) {
2110 case GESTURE_MODAL_CIRCLE_ADD:
2111 rect->xmax += 2 + rect->xmax/10;
2112 wm_gesture_tag_redraw(C);
2114 case GESTURE_MODAL_CIRCLE_SUB:
2115 rect->xmax -= 2 + rect->xmax/10;
2116 if(rect->xmax < 1) rect->xmax= 1;
2117 wm_gesture_tag_redraw(C);
2119 case GESTURE_MODAL_SELECT:
2120 case GESTURE_MODAL_DESELECT:
2121 case GESTURE_MODAL_NOP:
2122 if(RNA_struct_find_property(op->ptr, "gesture_mode"))
2123 RNA_int_set(op->ptr, "gesture_mode", event->val);
2125 if(event->val != GESTURE_MODAL_NOP) {
2126 /* apply first click */
2127 gesture_circle_apply(C, op);
2129 wm_gesture_tag_redraw(C);
2133 case GESTURE_MODAL_CANCEL:
2134 case GESTURE_MODAL_CONFIRM:
2135 wm_gesture_end(C, op);
2136 return OPERATOR_FINISHED; /* use finish or we dont get an undo */
2139 // // Allow view navigation???
2141 // return OPERATOR_PASS_THROUGH;
2144 return OPERATOR_RUNNING_MODAL;
2148 /* template to copy from */
2149 void WM_OT_circle_gesture(wmOperatorType *ot)
2151 ot->name= "Circle Gesture";
2152 ot->idname= "WM_OT_circle_gesture";
2153 ot->description="Enter rotate mode with a circular gesture";
2155 ot->invoke= WM_gesture_circle_invoke;
2156 ot->modal= WM_gesture_circle_modal;
2158 ot->poll= WM_operator_winactive;
2160 RNA_def_property(ot->srna, "x", PROP_INT, PROP_NONE);
2161 RNA_def_property(ot->srna, "y", PROP_INT, PROP_NONE);
2162 RNA_def_property(ot->srna, "radius", PROP_INT, PROP_NONE);
2167 /* **************** Tweak gesture *************** */
2169 static void tweak_gesture_modal(bContext *C, wmEvent *event)
2171 wmWindow *window= CTX_wm_window(C);
2172 wmGesture *gesture= window->tweak;
2173 rcti *rect= gesture->customdata;
2176 switch(event->type) {
2179 wm_subwindow_getorigin(window, gesture->swinid, &sx, &sy);
2181 rect->xmax= event->x - sx;
2182 rect->ymax= event->y - sy;
2184 if((val= wm_gesture_evaluate(C, gesture))) {
2187 event= *(window->eventstate);
2188 if(gesture->event_type==LEFTMOUSE)
2189 event.type= EVT_TWEAK_L;
2190 else if(gesture->event_type==RIGHTMOUSE)
2191 event.type= EVT_TWEAK_R;
2193 event.type= EVT_TWEAK_M;
2196 wm_event_add(window, &event);
2198 WM_gesture_end(C, gesture); /* frees gesture itself, and unregisters from window */
2206 if(gesture->event_type==event->type) {
2207 WM_gesture_end(C, gesture);
2209 /* when tweak fails we should give the other keymap entries a chance */
2210 event->val= KM_RELEASE;
2214 if(!ISTIMER(event->type)) {
2215 WM_gesture_end(C, gesture);
2221 /* standard tweak, called after window handlers passed on event */
2222 void wm_tweakevent_test(bContext *C, wmEvent *event, int action)
2224 wmWindow *win= CTX_wm_window(C);
2226 if(win->tweak==NULL) {
2227 if(CTX_wm_region(C)) {
2228 if(event->val==KM_PRESS) {
2229 if( ELEM3(event->type, LEFTMOUSE, MIDDLEMOUSE, RIGHTMOUSE) )
2230 win->tweak= WM_gesture_new(C, event, WM_GESTURE_TWEAK);
2235 /* no tweaks if event was handled */
2236 if((action & WM_HANDLER_BREAK)) {
2237 WM_gesture_end(C, win->tweak);
2240 tweak_gesture_modal(C, event);
2244 /* *********************** lasso gesture ****************** */
2246 int WM_gesture_lasso_invoke(bContext *C, wmOperator *op, wmEvent *event)
2248 op->customdata= WM_gesture_new(C, event, WM_GESTURE_LASSO);
2250 /* add modal handler */
2251 WM_event_add_modal_handler(C, op);
2253 wm_gesture_tag_redraw(C);
2255 if( RNA_struct_find_property(op->ptr, "cursor") )
2256 WM_cursor_modal(CTX_wm_window(C), RNA_int_get(op->ptr, "cursor"));
2258 return OPERATOR_RUNNING_MODAL;
2261 int WM_gesture_lines_invoke(bContext *C, wmOperator *op, wmEvent *event)
2263 op->customdata= WM_gesture_new(C, event, WM_GESTURE_LINES);
2265 /* add modal handler */
2266 WM_event_add_modal_handler(C, op);
2268 wm_gesture_tag_redraw(C);
2270 if( RNA_struct_find_property(op->ptr, "cursor") )
2271 WM_cursor_modal(CTX_wm_window(C), RNA_int_get(op->ptr, "cursor"));
2273 return OPERATOR_RUNNING_MODAL;
2277 static void gesture_lasso_apply(bContext *C, wmOperator *op, int event_type)
2279 wmGesture *gesture= op->customdata;
2283 short *lasso= gesture->customdata;
2285 /* operator storage as path. */
2287 for(i=0; i<gesture->points; i++, lasso+=2) {
2290 RNA_collection_add(op->ptr, "path", &itemptr);
2291 RNA_float_set_array(&itemptr, "loc", loc);
2294 wm_gesture_end(C, op);
2297 op->type->exec(C, op);
2301 int WM_gesture_lasso_modal(bContext *C, wmOperator *op, wmEvent *event)
2303 wmGesture *gesture= op->customdata;
2306 switch(event->type) {
2309 wm_gesture_tag_redraw(C);
2311 wm_subwindow_getorigin(CTX_wm_window(C), gesture->swinid, &sx, &sy);
2313 if(gesture->points == gesture->size) {
2314 short *old_lasso = gesture->customdata;
2315 gesture->customdata= MEM_callocN(2*sizeof(short)*(gesture->size + WM_LASSO_MIN_POINTS), "lasso points");
2316 memcpy(gesture->customdata, old_lasso, 2*sizeof(short)*gesture->size);
2317 gesture->size = gesture->size + WM_LASSO_MIN_POINTS;
2318 MEM_freeN(old_lasso);
2319 printf("realloc\n");
2323 short *lasso= gesture->customdata;
2324 lasso += 2 * gesture->points;
2325 lasso[0] = event->x - sx;
2326 lasso[1] = event->y - sy;
2334 if(event->val==KM_RELEASE) { /* key release */
2335 gesture_lasso_apply(C, op, event->type);
2336 return OPERATOR_FINISHED;
2340 wm_gesture_end(C, op);
2341 return OPERATOR_CANCELLED;
2343 return OPERATOR_RUNNING_MODAL;
2346 int WM_gesture_lines_modal(bContext *C, wmOperator *op, wmEvent *event)
2348 return WM_gesture_lasso_modal(C, op, event);
2352 /* template to copy from */
2354 static int gesture_lasso_exec(bContext *C, wmOperator *op)
2356 RNA_BEGIN(op->ptr, itemptr, "path") {
2359 RNA_float_get_array(&itemptr, "loc", loc);
2360 printf("Location: %f %f\n", loc[0], loc[1]);
2364 return OPERATOR_FINISHED;
2367 void WM_OT_lasso_gesture(wmOperatorType *ot)
2371 ot->name= "Lasso Gesture";
2372 ot->idname= "WM_OT_lasso_gesture";
2373 ot->description="Select objects within the lasso as you move the pointer";
2375 ot->invoke= WM_gesture_lasso_invoke;
2376 ot->modal= WM_gesture_lasso_modal;
2377 ot->exec= gesture_lasso_exec;
2379 ot->poll= WM_operator_winactive;
2381 prop= RNA_def_property(ot->srna, "path", PROP_COLLECTION, PROP_NONE);
2382 RNA_def_property_struct_runtime(prop, &RNA_OperatorMousePath);
2386 /* *********************** radial control ****************** */
2388 const int WM_RADIAL_CONTROL_DISPLAY_SIZE = 200;
2390 typedef struct wmRadialControl {
2392 float initial_value, value, max_value;
2393 int initial_mouse[2];
2398 static void wm_radial_control_paint(bContext *C, int x, int y, void *customdata)
2400 wmRadialControl *rc = (wmRadialControl*)customdata;
2401 ARegion *ar = CTX_wm_region(C);
2402 float r1=0.0f, r2=0.0f, r3=0.0f, angle=0.0f;
2404 /* Keep cursor in the original place */
2405 x = rc->initial_mouse[0] - ar->winrct.xmin;
2406 y = rc->initial_mouse[1] - ar->winrct.ymin;
2410 glTranslatef((float)x, (float)y, 0.0f);
2412 if(rc->mode == WM_RADIALCONTROL_SIZE) {
2414 r2= rc->initial_value;
2416 } else if(rc->mode == WM_RADIALCONTROL_STRENGTH) {
2417 r1= (1 - rc->value) * WM_RADIAL_CONTROL_DISPLAY_SIZE;
2418 r2= WM_RADIAL_CONTROL_DISPLAY_SIZE;
2419 r3= WM_RADIAL_CONTROL_DISPLAY_SIZE;
2420 } else if(rc->mode == WM_RADIALCONTROL_ANGLE) {
2421 r1= r2= WM_RADIAL_CONTROL_DISPLAY_SIZE;
2422 r3= WM_RADIAL_CONTROL_DISPLAY_SIZE;
2426 glColor4ub(255, 255, 255, 128);
2427 glEnable( GL_LINE_SMOOTH );
2430 if(rc->mode == WM_RADIALCONTROL_ANGLE)
2431 fdrawline(0, 0, WM_RADIAL_CONTROL_DISPLAY_SIZE, 0);
2434 const float str = rc->mode == WM_RADIALCONTROL_STRENGTH ? (rc->value + 0.5) : 1;
2436 if(rc->mode == WM_RADIALCONTROL_ANGLE) {
2437 glRotatef(angle, 0, 0, 1);
2438 fdrawline(0, 0, WM_RADIAL_CONTROL_DISPLAY_SIZE, 0);
2441 glBindTexture(GL_TEXTURE_2D, rc->tex);
2443 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
2444 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2446 glEnable(GL_TEXTURE_2D);
2448 glColor4f(0,0,0, str);
2450 glVertex2f(-r3, -r3);
2452 glVertex2f(r3, -r3);
2456 glVertex2f(-r3, r3);
2458 glDisable(GL_TEXTURE_2D);
2461 glColor4ub(255, 255, 255, 128);
2462 glutil_draw_lined_arc(0.0, M_PI*2.0, r1, 40);
2463 glutil_draw_lined_arc(0.0, M_PI*2.0, r2, 40);
2464 glDisable(GL_BLEND);
2465 glDisable( GL_LINE_SMOOTH );
2470 int WM_radial_control_modal(bContext *C, wmOperator *op, wmEvent *event)
2472 wmRadialControl *rc = (wmRadialControl*)op->customdata;
2473 int mode, initial_mouse[2], delta[2];
2475 double new_value = RNA_float_get(op->ptr, "new_value");
2476 int ret = OPERATOR_RUNNING_MODAL;
2478 mode = RNA_int_get(op->ptr, "mode");
2479 RNA_int_get_array(op->ptr, "initial_mouse", initial_mouse);
2481 switch(event->type) {
2483 delta[0]= initial_mouse[0] - event->x;
2484 delta[1]= initial_mouse[1] - event->y;
2485 dist= sqrt(delta[0]*delta[0]+delta[1]*delta[1]);
2487 if(mode == WM_RADIALCONTROL_SIZE)
2489 else if(mode == WM_RADIALCONTROL_STRENGTH) {
2490 new_value = 1 - dist / WM_RADIAL_CONTROL_DISPLAY_SIZE;
2491 } else if(mode == WM_RADIALCONTROL_ANGLE)
2492 new_value = ((int)(atan2(delta[1], delta[0]) * (180.0 / M_PI)) + 180);
2495 if(mode == WM_RADIALCONTROL_STRENGTH)
2496 new_value = ((int)ceil(new_value * 10.f) * 10.0f) / 100.f;
2498 new_value = ((int)new_value + 5) / 10*10;
2504 ret = OPERATOR_CANCELLED;
2508 op->type->exec(C, op);
2509 ret = OPERATOR_FINISHED;
2514 if(new_value > rc->max_value)
2515 new_value = rc->max_value;
2516 else if(new_value < 0)
2519 /* Update paint data */
2520 rc->value = new_value;
2522 RNA_float_set(op->ptr, "new_value", new_value);
2524 if(ret != OPERATOR_RUNNING_MODAL) {
2525 WM_paint_cursor_end(CTX_wm_manager(C), rc->cursor);
2529 ED_region_tag_redraw(CTX_wm_region(C));
2534 /* Expects the operator customdata to be an ImBuf (or NULL) */
2535 int WM_radial_control_invoke(bContext *C, wmOperator *op, wmEvent *event)
2537 wmRadialControl *rc = MEM_callocN(sizeof(wmRadialControl), "radial control");
2538 int mode = RNA_int_get(op->ptr, "mode");
2539 float initial_value = RNA_float_get(op->ptr, "initial_value");
2540 int mouse[2] = {event->x, event->y};
2542 if(mode == WM_RADIALCONTROL_SIZE) {
2543 rc->max_value = 200;
2544 mouse[0]-= initial_value;
2546 else if(mode == WM_RADIALCONTROL_STRENGTH) {
2548 mouse[0]-= WM_RADIAL_CONTROL_DISPLAY_SIZE * (1 - initial_value);
2550 else if(mode == WM_RADIALCONTROL_ANGLE) {
2551 rc->max_value = 360;
2552 mouse[0]-= WM_RADIAL_CONTROL_DISPLAY_SIZE * cos(initial_value);
2553 mouse[1]-= WM_RADIAL_CONTROL_DISPLAY_SIZE * sin(initial_value);
2554 initial_value *= 180.0f/M_PI;
2557 if(op->customdata) {
2558 ImBuf *im = (ImBuf*)op->customdata;
2559 /* Build GL texture */
2560 glGenTextures(1, &rc->tex);
2561 glBindTexture(GL_TEXTURE_2D, rc->tex);
2562 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, im->x, im->y, 0, GL_ALPHA, GL_FLOAT, im->rect_float);
2563 MEM_freeN(im->rect_float);
2567 RNA_int_set_array(op->ptr, "initial_mouse", mouse);
2568 RNA_float_set(op->ptr, "new_value", initial_value);
2570 op->customdata = rc;
2572 rc->initial_value = initial_value;
2573 rc->initial_mouse[0] = mouse[0];
2574 rc->initial_mouse[1] = mouse[1];
2575 rc->cursor = WM_paint_cursor_activate(CTX_wm_manager(C), op->type->poll,
2576 wm_radial_control_paint, op->customdata);
2578 /* add modal handler */
2579 WM_event_add_modal_handler(C, op);
2581 WM_radial_control_modal(C, op, event);
2583 return OPERATOR_RUNNING_MODAL;
2586 /* Gets a descriptive string of the operation */
2587 void WM_radial_control_string(wmOperator *op, char str[], int maxlen)
2589 int mode = RNA_int_get(op->ptr, "mode");
2590 float v = RNA_float_get(op->ptr, "new_value");
2592 if(mode == WM_RADIALCONTROL_SIZE)
2593 sprintf(str, "Size: %d", (int)v);
2594 else if(mode == WM_RADIALCONTROL_STRENGTH)
2595 sprintf(str, "Strength: %d", (int)v);
2596 else if(mode == WM_RADIALCONTROL_ANGLE)
2597 sprintf(str, "Angle: %d", (int)(v * 180.0f/M_PI));
2600 /** Important: this doesn't define an actual operator, it
2601 just sets up the common parts of the radial control op. **/
2602 void WM_OT_radial_control_partial(wmOperatorType *ot)
2604 static EnumPropertyItem radial_mode_items[] = {
2605 {WM_RADIALCONTROL_SIZE, "SIZE", 0, "Size", ""},
2606 {WM_RADIALCONTROL_STRENGTH, "STRENGTH", 0, "Strength", ""},
2607 {WM_RADIALCONTROL_ANGLE, "ANGLE", 0, "Angle", ""},
2608 {0, NULL, 0, NULL, NULL}};
2610 /* Should be set in custom invoke() */
2611 RNA_def_float(ot->srna, "initial_value", 0, 0, FLT_MAX, "Initial Value", "", 0, FLT_MAX);
2613 /* Set internally, should be used in custom exec() to get final value */
2614 RNA_def_float(ot->srna, "new_value", 0, 0, FLT_MAX, "New Value", "", 0, FLT_MAX);
2616 /* Should be set before calling operator */
2617 RNA_def_enum(ot->srna, "mode", radial_mode_items, 0, "Mode", "");
2620 RNA_def_int_vector(ot->srna, "initial_mouse", 2, NULL, INT_MIN, INT_MAX, "initial_mouse", "", INT_MIN, INT_MAX);
2623 /* ************************** timer for testing ***************** */
2625 /* uses no type defines, fully local testing function anyway... ;) */
2627 static int redraw_timer_exec(bContext *C, wmOperator *op)
2629 ARegion *ar= CTX_wm_region(C);
2630 double stime= PIL_check_seconds_timer();
2631 int type = RNA_int_get(op->ptr, "type");
2632 int iter = RNA_int_get(op->ptr, "iterations");
2639 for(a=0; a<iter; a++) {
2641 ED_region_do_draw(C, ar);
2644 wmWindow *win= CTX_wm_window(C);
2646 ED_region_tag_redraw(ar);
2649 CTX_wm_window_set(C, win); /* XXX context manipulation warning! */
2652 wmWindow *win= CTX_wm_window(C);
2655 ScrArea *sa_back= CTX_wm_area(C);
2656 ARegion *ar_back= CTX_wm_region(C);
2658 for(sa= CTX_wm_screen(C)->areabase.first; sa; sa= sa->next) {
2660 CTX_wm_area_set(C, sa);
2662 for(ar_iter= sa->regionbase.first; ar_iter; ar_iter= ar_iter->next) {
2663 if(ar_iter->swinid) {
2664 CTX_wm_region_set(C, ar_iter);
2665 ED_region_do_draw(C, ar_iter);
2670 CTX_wm_window_set(C, win); /* XXX context manipulation warning! */
2672 CTX_wm_area_set(C, sa_back);
2673 CTX_wm_region_set(C, ar_back);
2676 wmWindow *win= CTX_wm_window(C);
2679 for(sa= CTX_wm_screen(C)->areabase.first; sa; sa= sa->next)
2680 ED_area_tag_redraw(sa);
2683 CTX_wm_window_set(C, win); /* XXX context manipulation warning! */
2686 Scene *scene= CTX_data_scene(C);
2688 if(a & 1) scene->r.cfra--;
2689 else scene->r.cfra++;
2690 scene_update_for_newframe(scene, scene->lay);
2698 time= ((PIL_check_seconds_timer()-stime)*1000);
2700 if(type==0) infostr= "Draw Region";
2701 if(type==1) infostr= "Draw Region and Swap";
2702 if(type==2) infostr= "Draw Window";
2703 if(type==3) infostr= "Draw Window and Swap";
2704 if(type==4) infostr= "Animation Steps";
2705 if(type==5) infostr= "Undo/Redo";
2709 BKE_reportf(op->reports, RPT_WARNING, "%d x %s: %.2f ms, average: %.4f", iter, infostr, time, time/iter);
2711 return OPERATOR_FINISHED;
2714 static void WM_OT_redraw_timer(wmOperatorType *ot)
2716 static EnumPropertyItem prop_type_items[] = {
2717 {0, "DRAW", 0, "Draw Region", ""},
2718 {1, "DRAW_SWAP", 0, "Draw Region + Swap", ""},
2719 {2, "DRAW_WIN", 0, "Draw Window", ""},
2720 {3, "DRAW_WIN_SWAP", 0, "Draw Window + Swap", ""},
2721 {4, "ANIM_STEP", 0, "Anim Step", ""},
2722 {5, "UNDO", 0, "Undo/Redo", ""},
2723 {0, NULL, 0, NULL, NULL}};
2725 ot->name= "Redraw Timer";
2726 ot->idname= "WM_OT_redraw_timer";
2727 ot->description="Simple redraw timer to test the speed of updating the interface";
2729 ot->invoke= WM_menu_invoke;
2730 ot->exec= redraw_timer_exec;
2731 ot->poll= WM_operator_winactive;
2733 ot->prop= RNA_def_enum(ot->srna, "type", prop_type_items, 0, "Type", "");
2734 RNA_def_int(ot->srna, "iterations", 10, 1,INT_MAX, "Iterations", "Number of times to redraw", 1,1000);
2738 /* ************************** memory statistics for testing ***************** */
2740 static int memory_statistics_exec(bContext *C, wmOperator *op)
2742 MEM_printmemlist_stats();
2743 return OPERATOR_FINISHED;
2746 static void WM_OT_memory_statistics(wmOperatorType *ot)
2748 ot->name= "Memory Statistics";
2749 ot->idname= "WM_OT_memory_statistics";
2750 ot->description= "Print memory statistics to the console";
2752 ot->exec= memory_statistics_exec;
2755 /* ******************************************************* */
2757 /* called on initialize WM_exit() */
2758 void wm_operatortype_free(void)
2762 for(ot= global_ops.first; ot; ot= ot->next) {
2764 wm_operatortype_free_macro(ot);
2766 if(ot->ext.srna) /* python operator, allocs own string */
2767 MEM_freeN(ot->idname);
2770 BLI_freelistN(&global_ops);
2773 /* called on initialize WM_init() */
2774 void wm_operatortype_init(void)
2776 WM_operatortype_append(WM_OT_window_duplicate);
2777 WM_operatortype_append(WM_OT_read_homefile);
2778 WM_operatortype_append(WM_OT_save_homefile);
2779 WM_operatortype_append(WM_OT_window_fullscreen_toggle);
2780 WM_operatortype_append(WM_OT_exit_blender);
2781 WM_operatortype_append(WM_OT_open_mainfile);
2782 WM_operatortype_append(WM_OT_link_append);
2783 WM_operatortype_append(WM_OT_recover_last_session);
2784 WM_operatortype_append(WM_OT_recover_auto_save);
2785 WM_operatortype_append(WM_OT_save_as_mainfile);
2786 WM_operatortype_append(WM_OT_save_mainfile);
2787 WM_operatortype_append(WM_OT_redraw_timer);
2788 WM_operatortype_append(WM_OT_memory_statistics);
2789 WM_operatortype_append(WM_OT_debug_menu);
2790 WM_operatortype_append(WM_OT_splash);
2791 WM_operatortype_append(WM_OT_search_menu);
2792 WM_operatortype_append(WM_OT_call_menu);
2795 /* XXX: move these */
2796 WM_operatortype_append(WM_OT_collada_export);
2797 WM_operatortype_append(WM_OT_collada_import);
2802 /* called in transform_ops.c, on each regeneration of keymaps */
2803 static void gesture_circle_modal_keymap(wmKeyConfig *keyconf)
2805 static EnumPropertyItem modal_items[] = {
2806 {GESTURE_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""},
2807 {GESTURE_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""},
2808 {GESTURE_MODAL_CIRCLE_ADD, "ADD", 0, "Add", ""},
2809 {GESTURE_MODAL_CIRCLE_SUB, "SUBTRACT", 0, "Subtract", ""},
2811 {GESTURE_MODAL_SELECT, "SELECT", 0, "Select", ""},
2812 {GESTURE_MODAL_DESELECT,"DESELECT", 0, "DeSelect", ""},
2813 {GESTURE_MODAL_NOP,"NOP", 0, "No Operation", ""},
2816 {0, NULL, 0, NULL, NULL}};
2818 wmKeyMap *keymap= WM_modalkeymap_get(keyconf, "View3D Gesture Circle");
2820 /* this function is called for each spacetype, only needs to add map once */
2823 keymap= WM_modalkeymap_add(keyconf, "View3D Gesture Circle", modal_items);
2825 /* items for modal map */
2826 WM_modalkeymap_add_item(keymap, ESCKEY, KM_PRESS, KM_ANY, 0, GESTURE_MODAL_CANCEL);
2827 WM_modalkeymap_add_item(keymap, RIGHTMOUSE, KM_ANY, KM_ANY, 0, GESTURE_MODAL_CANCEL);
2829 WM_modalkeymap_add_item(keymap, RETKEY, KM_PRESS, KM_ANY, 0, GESTURE_MODAL_CONFIRM);
2830 WM_modalkeymap_add_item(keymap, PADENTER, KM_PRESS, 0, 0, GESTURE_MODAL_CONFIRM);
2832 WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_PRESS, 0, 0, GESTURE_MODAL_SELECT);
2834 #if 0 // Durien guys like this :S
2835 WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_PRESS, KM_SHIFT, 0, GESTURE_MODAL_DESELECT);
2836 WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_RELEASE, KM_SHIFT, 0, GESTURE_MODAL_NOP);
2838 WM_modalkeymap_add_item(keymap, MIDDLEMOUSE, KM_PRESS, 0, 0, GESTURE_MODAL_DESELECT); // defailt 2.4x
2839 WM_modalkeymap_add_item(keymap, MIDDLEMOUSE, KM_RELEASE, 0, 0, GESTURE_MODAL_NOP); // defailt 2.4x
2842 WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_RELEASE, 0, 0, GESTURE_MODAL_NOP);
2844 WM_modalkeymap_add_item(keymap, WHEELUPMOUSE, KM_PRESS, 0, 0, GESTURE_MODAL_CIRCLE_SUB);
2845 WM_modalkeymap_add_item(keymap, PADMINUS, KM_PRESS, 0, 0, GESTURE_MODAL_CIRCLE_SUB);
2846 WM_modalkeymap_add_item(keymap, WHEELDOWNMOUSE, KM_PRESS, 0, 0, GESTURE_MODAL_CIRCLE_ADD);
2847 WM_modalkeymap_add_item(keymap, PADPLUSKEY, KM_PRESS, 0, 0, GESTURE_MODAL_CIRCLE_ADD);
2849 /* assign map to operators */
2850 WM_modalkeymap_assign(keymap, "VIEW3D_OT_select_circle");
2851 WM_modalkeymap_assign(keymap, "UV_OT_circle_select");
2855 /* called in transform_ops.c, on each regeneration of keymaps */
2856 static void gesture_border_modal_keymap(wmKeyConfig *keyconf)
2858 static EnumPropertyItem modal_items[] = {
2859 {GESTURE_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""},
2860 {GESTURE_MODAL_SELECT, "SELECT", 0, "Select", ""},
2861 {GESTURE_MODAL_DESELECT,"DESELECT", 0, "DeSelect", ""},
2862 {GESTURE_MODAL_BORDER_BEGIN, "BEGIN", 0, "Begin", ""},
2863 {0, NULL, 0, NULL, NULL}};
2865 wmKeyMap *keymap= WM_modalkeymap_get(keyconf, "Gesture Border");
2867 /* this function is called for each spacetype, only needs to add map once */
2870 keymap= WM_modalkeymap_add(keyconf, "Gesture Border", modal_items);
2872 /* items for modal map */
2873 WM_modalkeymap_add_item(keymap, ESCKEY, KM_PRESS, KM_ANY, 0, GESTURE_MODAL_CANCEL);
2874 WM_modalkeymap_add_item(keymap, RIGHTMOUSE, KM_ANY, KM_ANY, 0, GESTURE_MODAL_CANCEL);
2876 WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_PRESS, 0, 0, GESTURE_MODAL_BORDER_BEGIN);
2877 WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_RELEASE, 0, 0, GESTURE_MODAL_SELECT);
2879 #if 0 // Durian guys like this
2880 WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_PRESS, KM_SHIFT, 0, GESTURE_MODAL_BORDER_BEGIN);
2881 WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_RELEASE, KM_SHIFT, 0, GESTURE_MODAL_DESELECT);
2883 WM_modalkeymap_add_item(keymap, MIDDLEMOUSE, KM_PRESS, 0, 0, GESTURE_MODAL_BORDER_BEGIN);
2884 WM_modalkeymap_add_item(keymap, MIDDLEMOUSE, KM_RELEASE, 0, 0, GESTURE_MODAL_DESELECT);
2887 /* assign map to operators */
2888 WM_modalkeymap_assign(keymap, "ACTION_OT_select_border");
2889 WM_modalkeymap_assign(keymap, "ANIM_OT_channels_select_border");
2890 WM_modalkeymap_assign(keymap, "ANIM_OT_previewrange_set");
2891 WM_modalkeymap_assign(keymap, "CONSOLE_OT_select_border");
2892 WM_modalkeymap_assign(keymap, "FILE_OT_select_border");
2893 WM_modalkeymap_assign(keymap, "GRAPH_OT_select_border");
2894 WM_modalkeymap_assign(keymap, "MARKER_OT_select_border");
2895 WM_modalkeymap_assign(keymap, "NLA_OT_select_border");
2896 WM_modalkeymap_assign(keymap, "NODE_OT_select_border");
2897 // WM_modalkeymap_assign(keymap, "SCREEN_OT_border_select"); // template
2898 WM_modalkeymap_assign(keymap, "SEQUENCER_OT_select_border");
2899 WM_modalkeymap_assign(keymap, "UV_OT_select_border");
2900 WM_modalkeymap_assign(keymap, "VIEW2D_OT_zoom_border");
2901 WM_modalkeymap_assign(keymap, "VIEW3D_OT_clip_border");
2902 WM_modalkeymap_assign(keymap, "VIEW3D_OT_render_border");
2903 WM_modalkeymap_assign(keymap, "VIEW3D_OT_select_border");
2904 WM_modalkeymap_assign(keymap, "VIEW3D_OT_zoom_border"); // XXX TODO: zoom border should perhaps map rightmouse to zoom out instead of in+cancel
2907 /* default keymap for windows and screens, only call once per WM */
2908 void wm_window_keymap(wmKeyConfig *keyconf)
2910 wmKeyMap *keymap= WM_keymap_find(keyconf, "Window", 0, 0);
2913 /* note, this doesn't replace existing keymap items */
2914 WM_keymap_verify_item(keymap, "WM_OT_window_duplicate", WKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
2916 WM_keymap_add_item(keymap, "WM_OT_read_homefile", NKEY, KM_PRESS, KM_OSKEY, 0);
2917 WM_keymap_add_menu(keymap, "INFO_MT_file_open_recent", OKEY, KM_PRESS, KM_SHIFT|KM_OSKEY, 0);
2918 WM_keymap_add_item(keymap, "WM_OT_open_mainfile", OKEY, KM_PRESS, KM_OSKEY, 0);
2919 WM_keymap_add_item(keymap, "WM_OT_save_mainfile", SKEY, KM_PRESS, KM_OSKEY, 0);
2920 WM_keymap_add_item(keymap, "WM_OT_save_as_mainfile", SKEY, KM_PRESS, KM_SHIFT|KM_OSKEY, 0);
2921 WM_keymap_add_item(keymap, "WM_OT_exit_blender", QKEY, KM_PRESS, KM_OSKEY, 0);
2923 WM_keymap_add_item(keymap, "WM_OT_read_homefile", NKEY, KM_PRESS, KM_CTRL, 0);
2924 WM_keymap_add_item(keymap, "WM_OT_save_homefile", UKEY, KM_PRESS, KM_CTRL, 0);
2925 WM_keymap_add_menu(keymap, "INFO_MT_file_open_recent", OKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
2926 WM_keymap_add_item(keymap, "WM_OT_open_mainfile", OKEY, KM_PRESS, KM_CTRL, 0);
2927 WM_keymap_add_item(keymap, "WM_OT_open_mainfile", F1KEY, KM_PRESS, 0, 0);
2928 WM_keymap_add_item(keymap, "WM_OT_link_append", OKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
2929 kmi= WM_keymap_add_item(keymap, "WM_OT_link_append", F1KEY, KM_PRESS, KM_SHIFT, 0);
2930 RNA_boolean_set(kmi->ptr, "link", FALSE);
2932 WM_keymap_add_item(keymap, "WM_OT_save_mainfile", SKEY, KM_PRESS, KM_CTRL, 0);
2933 WM_keymap_add_item(keymap, "WM_OT_save_mainfile", WKEY, KM_PRESS, KM_CTRL, 0);
2934 WM_keymap_add_item(keymap, "WM_OT_save_as_mainfile", SKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
2935 WM_keymap_add_item(keymap, "WM_OT_save_as_mainfile", F2KEY, KM_PRESS, 0, 0);
2937 WM_keymap_verify_item(keymap, "WM_OT_window_fullscreen_toggle", F11KEY, KM_PRESS, KM_ALT, 0);
2938 WM_keymap_add_item(keymap, "WM_OT_exit_blender", QKEY, KM_PRESS, KM_CTRL, 0);
2941 WM_keymap_verify_item(keymap, "WM_OT_redraw_timer", TKEY, KM_PRESS, KM_ALT|KM_CTRL, 0);
2942 WM_keymap_verify_item(keymap, "WM_OT_debug_menu", DKEY, KM_PRESS, KM_ALT|KM_CTRL, 0);
2943 WM_keymap_verify_item(keymap, "WM_OT_search_menu", SPACEKEY, KM_PRESS, 0, 0);
2945 /* Space switching */
2948 kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F2KEY, KM_PRESS, KM_SHIFT, 0); /* new in 2.5x, was DXF export */
2949 RNA_string_set(kmi->ptr, "path", "area.type");
2950 RNA_string_set(kmi->ptr, "value", "LOGIC_EDITOR");
2952 kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F3KEY, KM_PRESS, KM_SHIFT, 0);
2953 RNA_string_set(kmi->ptr, "path", "area.type");
2954 RNA_string_set(kmi->ptr, "value", "NODE_EDITOR");
2956 kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F4KEY, KM_PRESS, KM_SHIFT, 0); /* new in 2.5x, was data browser */
2957 RNA_string_set(kmi->ptr, "path", "area.type");
2958 RNA_string_set(kmi->ptr, "value", "CONSOLE");
2960 kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F5KEY, KM_PRESS, KM_SHIFT, 0);
2961 RNA_string_set(kmi->ptr, "path", "area.type");
2962 RNA_string_set(kmi->ptr, "value", "VIEW_3D");
2964 kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F6KEY, KM_PRESS, KM_SHIFT, 0);
2965 RNA_string_set(kmi->ptr, "path", "area.type");
2966 RNA_string_set(kmi->ptr, "value", "GRAPH_EDITOR");
2968 kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F7KEY, KM_PRESS, KM_SHIFT, 0);
2969 RNA_string_set(kmi->ptr, "path", "area.type");
2970 RNA_string_set(kmi->ptr, "value", "PROPERTIES");
2972 kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F8KEY, KM_PRESS, KM_SHIFT, 0);
2973 RNA_string_set(kmi->ptr, "path", "area.type");
2974 RNA_string_set(kmi->ptr, "value", "SEQUENCE_EDITOR");
2976 kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F9KEY, KM_PRESS, KM_SHIFT, 0);
2977 RNA_string_set(kmi->ptr, "path", "area.type");
2978 RNA_string_set(kmi->ptr, "value", "OUTLINER");
2980 kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F10KEY, KM_PRESS, KM_SHIFT, 0);
2981 RNA_string_set(kmi->ptr, "path", "area.type");
2982 RNA_string_set(kmi->ptr, "value", "IMAGE_EDITOR");
2984 kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F11KEY, KM_PRESS, KM_SHIFT, 0);
2985 RNA_string_set(kmi->ptr, "path", "area.type");
2986 RNA_string_set(kmi->ptr, "value", "TEXT_EDITOR");
2988 kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F12KEY, KM_PRESS, KM_SHIFT, 0);
2989 RNA_string_set(kmi->ptr, "path", "area.type");
2990 RNA_string_set(kmi->ptr, "value", "DOPESHEET_EDITOR");
2992 gesture_circle_modal_keymap(keyconf);
2993 gesture_border_modal_keymap(keyconf);
2996 /* Generic itemf's for operators that take library args */
2997 static EnumPropertyItem *rna_id_itemf(bContext *C, PointerRNA *ptr, int *free, ID *id)
2999 EnumPropertyItem *item= NULL, item_tmp;
3003 memset(&item_tmp, 0, sizeof(item_tmp));
3005 for( ; id; id= id->next) {
3006 item_tmp.identifier= item_tmp.name= id->name+2;
3007 item_tmp.value= i++;
3008 RNA_enum_item_add(&item, &totitem, &item_tmp);
3011 RNA_enum_item_end(&item, &totitem);
3017 /* can add more as needed */
3018 EnumPropertyItem *RNA_action_itemf(bContext *C, PointerRNA *ptr, int *free)
3020 return rna_id_itemf(C, ptr, free, C ? (ID *)CTX_data_main(C)->action.first : NULL);
3022 EnumPropertyItem *RNA_group_itemf(bContext *C, PointerRNA *ptr, int *free)
3024 return rna_id_itemf(C, ptr, free, C ? (ID *)CTX_data_main(C)->group.first : NULL);
3026 EnumPropertyItem *RNA_scene_itemf(bContext *C, PointerRNA *ptr, int *free)
3028 return rna_id_itemf(C, ptr, free, C ? (ID *)CTX_data_main(C)->scene.first : NULL);