* add exit app with CTRLKEY+QKEY.
[blender-staging.git] / source / blender / windowmanager / intern / wm_operators.c
index a6992f5fbdbf00adf55296558589c14a4200df1a..05d27c1321abe798f5a39c091544125cd38296d1 100644 (file)
@@ -28,6 +28,7 @@
 
 #include <string.h>
 
 
 #include <string.h>
 
+#include "DNA_ID.h"
 #include "DNA_windowmanager_types.h"
 
 #include "MEM_guardedalloc.h"
 #include "DNA_windowmanager_types.h"
 
 #include "MEM_guardedalloc.h"
@@ -38,8 +39,7 @@
 #include "BKE_global.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
 #include "BKE_global.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
-
-#include "BIF_toolbox.h"
+#include "BKE_idprop.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
@@ -61,6 +61,12 @@ wmOperatorType *WM_operatortype_find(const char *idname)
        return NULL;
 }
 
        return NULL;
 }
 
+/* all ops in 1 list (for time being... needs evaluation later) */
+void WM_operatortypelist_append(ListBase *lb)
+{
+       addlisttolist(&global_ops, lb);
+}
+
 /* ************ default ops, exported *********** */
 
 int WM_operator_confirm(bContext *C, wmOperator *op, wmEvent *event)
 /* ************ default ops, exported *********** */
 
 int WM_operator_confirm(bContext *C, wmOperator *op, wmEvent *event)
@@ -83,7 +89,7 @@ static void WM_OT_window_duplicate(wmOperatorType *ot)
        ot->name= "Duplicate Window";
        ot->idname= "WM_OT_window_duplicate";
        
        ot->name= "Duplicate Window";
        ot->idname= "WM_OT_window_duplicate";
        
-       ot->interactive= NULL; //WM_operator_confirm;
+       ot->invoke= NULL; //WM_operator_confirm;
        ot->exec= wm_window_duplicate_op;
        ot->poll= WM_operator_winactive;
 }
        ot->exec= wm_window_duplicate_op;
        ot->poll= WM_operator_winactive;
 }
@@ -93,7 +99,7 @@ static void WM_OT_save_homefile(wmOperatorType *ot)
        ot->name= "Save User Settings";
        ot->idname= "WM_OT_save_homefile";
        
        ot->name= "Save User Settings";
        ot->idname= "WM_OT_save_homefile";
        
-       ot->interactive= NULL; //WM_operator_confirm;
+       ot->invoke= NULL; //WM_operator_confirm;
        ot->exec= WM_write_homefile;
        ot->poll= WM_operator_winactive;
        
        ot->exec= WM_write_homefile;
        ot->poll= WM_operator_winactive;
        
@@ -105,11 +111,20 @@ static void WM_OT_window_fullscreen_toggle(wmOperatorType *ot)
     ot->name= "Toggle Fullscreen";
     ot->idname= "WM_OT_window_fullscreen_toggle";
 
     ot->name= "Toggle Fullscreen";
     ot->idname= "WM_OT_window_fullscreen_toggle";
 
-    ot->interactive= NULL;
+    ot->invoke= NULL;
     ot->exec= wm_window_fullscreen_toggle_op;
     ot->poll= WM_operator_winactive;
 }
 
     ot->exec= wm_window_fullscreen_toggle_op;
     ot->poll= WM_operator_winactive;
 }
 
+static void WM_OT_exit_blender(wmOperatorType *ot)
+{
+       ot->name= "Exit Blender";
+       ot->idname= "WM_OT_exit_blender";
+
+       ot->invoke= NULL; /* do confirm stuff */
+       ot->exec= wm_exit_blender_op;
+       ot->poll= WM_operator_winactive;
+}
 
 
 #define ADD_OPTYPE(opfunc)     ot= MEM_callocN(sizeof(wmOperatorType), "operatortype"); \
 
 
 #define ADD_OPTYPE(opfunc)     ot= MEM_callocN(sizeof(wmOperatorType), "operatortype"); \
@@ -131,6 +146,185 @@ void wm_operatortype_init(void)
        ADD_OPTYPE(WM_OT_window_duplicate);
        ADD_OPTYPE(WM_OT_save_homefile);
     ADD_OPTYPE(WM_OT_window_fullscreen_toggle);
        ADD_OPTYPE(WM_OT_window_duplicate);
        ADD_OPTYPE(WM_OT_save_homefile);
     ADD_OPTYPE(WM_OT_window_fullscreen_toggle);
+       ADD_OPTYPE(WM_OT_exit_blender);
+}
+
+/* wrapped to get property from a operator. */
+IDProperty *op_get_property(wmOperator *op, char *name)
+{
+       IDProperty *prop= IDP_GetPropertyFromGroup(op->properties, name);
+       return(prop);
+}
+
+/*
+ * We need create a "group" to store the operator properties.
+ * We don't have a WM_operator_new or some thing like that,
+ * so this function is called by all the OP_set_* function
+ * in case that op->properties is equal to NULL.
+ */
+void op_init_property(wmOperator *op)
+{
+       IDPropertyTemplate val;
+       op->properties= IDP_New(IDP_GROUP, val, "property");
+}
+
+/* ***** Property API, exported ***** */
+void OP_free_property(wmOperator *op)
+{
+       IDP_FreeProperty(op->properties);
+       /*
+        * This need change, when the idprop code only
+        * need call IDP_FreeProperty. (check BKE_idprop.h)
+        */
+       MEM_freeN(op->properties);
+       op->properties= NULL;
+}
+
+void OP_set_int(wmOperator *op, char *name, int value)
+{
+       IDPropertyTemplate val;
+       IDProperty *prop;
+
+       if(!op->properties)
+               op_init_property(op);
+
+       val.i= value;
+       prop= IDP_New(IDP_INT, val, name);
+       IDP_ReplaceInGroup(op->properties, prop);
+}
+
+void OP_set_float(wmOperator *op, char *name, float value)
+{
+       IDPropertyTemplate val;
+       IDProperty *prop;
+
+       if(!op->properties)
+               op_init_property(op);
+
+       val.f= value;
+       prop= IDP_New(IDP_FLOAT, val, name);
+       IDP_ReplaceInGroup(op->properties, prop);
+}
+
+void OP_set_int_array(wmOperator *op, char *name, int *array, short len)
+{
+       IDPropertyTemplate val;
+       IDProperty *prop;
+       short i;
+       int *pointer;
+
+       if(!op->properties)
+               op_init_property(op);
+
+       val.array.len= len;
+       val.array.type= IDP_INT;
+       prop= IDP_New(IDP_ARRAY, val, name);
+
+       pointer= (int *)prop->data.pointer;
+       for(i= 0; i < len; i++)
+               pointer[i]= array[i];
+       IDP_ReplaceInGroup(op->properties, prop);
+}
+
+void OP_set_float_array(wmOperator *op, char *name, float *array, short len)
+{
+       IDPropertyTemplate val;
+       IDProperty *prop;
+       short i;
+       float *pointer;
+
+       if(!op->properties)
+               op_init_property(op);
+
+       val.array.len= len;
+       val.array.type= IDP_FLOAT;
+       prop= IDP_New(IDP_ARRAY, val, name);
+
+       pointer= (float *) prop->data.pointer;
+       for(i= 0; i < len; i++)
+               pointer[i]= array[i];
+       IDP_ReplaceInGroup(op->properties, prop);
+}
+
+void OP_set_string(wmOperator *op, char *name, char *str)
+{
+       IDPropertyTemplate val;
+       IDProperty *prop;
+
+       if(!op->properties)
+               op_init_property(op);
+
+       val.str= str;
+       prop= IDP_New(IDP_STRING, val, name);
+       IDP_ReplaceInGroup(op->properties, prop);
 }
 
 }
 
+int OP_get_int(wmOperator *op, char *name, int *value)
+{
+       IDProperty *prop= op_get_property(op, name);
+       int status= 1;
+
+       if ((prop) && (prop->type == IDP_INT)) {
+               (*value)= prop->data.val;
+               status= 0;
+       }
+       return (status);
+}
 
 
+int OP_get_float(wmOperator *op, char *name, float *value)
+{
+       IDProperty *prop= op_get_property(op, name);
+       int status= 1;
+
+       if ((prop) && (prop->type == IDP_FLOAT)) {
+               (*value)= *(float*)&prop->data.val;
+               status= 0;
+       }
+       return (status);
+}
+
+int OP_get_int_array(wmOperator *op, char *name, int *array, short *len)
+{
+       IDProperty *prop= op_get_property(op, name);
+       short i;
+       int status= 1;
+       int *pointer;
+
+       if ((prop) && (prop->type == IDP_ARRAY)) {
+               pointer= (int *) prop->data.pointer;
+
+               for(i= 0; (i < prop->len) && (i < *len); i++)
+                       array[i]= pointer[i];
+
+               (*len)= i;
+               status= 0;
+       }
+       return (status);
+}
+
+int OP_get_float_array(wmOperator *op, char *name, float *array, short *len)
+{
+       IDProperty *prop= op_get_property(op, name);
+       short i;
+       float *pointer;
+       int status= 1;
+
+       if ((prop) && (prop->type == IDP_ARRAY)) {
+               pointer= (float *) prop->data.pointer;
+
+               for(i= 0; (i < prop->len) && (i < *len); i++)
+                       array[i]= pointer[i];
+
+               (*len)= i;
+               status= 0;
+       }
+       return (status);
+}
+
+char *OP_get_string(wmOperator *op, char *name)
+{
+       IDProperty *prop= op_get_property(op, name);
+       if ((prop) && (prop->type == IDP_STRING))
+               return ((char *) prop->data.pointer);
+       return (NULL);
+}