merge with 2.5 at r18679
[blender.git] / source / blender / editors / interface / interface_handlers.c
index c11e81554bf971de5aec53a03f16519053417d9d..bfe6057cfce429114fa865435d491b91d6142a77 100644 (file)
 
 #include "UI_interface.h"
 #include "UI_text.h"
-#include "interface.h"
+#include "interface_intern.h"
+
+#include "RNA_access.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
 
 /***************** structs and defines ****************/
 
-#define BUTTON_TOOLTIP_DELAY           500
-#define BUTTON_FLASH_DELAY                     20
+#define BUTTON_TOOLTIP_DELAY           0.500
+#define BUTTON_FLASH_DELAY                     0.020
 #define BUTTON_AUTO_OPEN_THRESH                0.3
 #define BUTTON_MOUSE_TOWARDS_THRESH    1.0
 
@@ -94,7 +96,7 @@ typedef struct uiHandleButtonData {
        uiHandleButtonState state;
        int cancel, retval;
        int applied, appliedinteractive;
-       wmTimerHandle *flashtimer;
+       wmTimer *flashtimer;
 
        /* edited value */
        char *str, *origstr;
@@ -106,8 +108,8 @@ typedef struct uiHandleButtonData {
 
        /* tooltip */
        ARegion *tooltip;
-       wmTimerHandle *tooltiptimer;
-       wmTimerHandle *autoopentimer;
+       wmTimer *tooltiptimer;
+       wmTimer *autoopentimer;
 
        /* text selection/editing */
        int maxlen, selextend, selstartx;
@@ -145,7 +147,10 @@ typedef struct uiAfterFunc {
 
        const char *opname;
        int opcontext;
-       IDProperty *opproperties;
+       PointerRNA *opptr;
+
+       PointerRNA rnapoin;
+       PropertyRNA *rnaprop;
 } uiAfterFunc;
 
 static void button_activate_state(bContext *C, uiBut *but, uiHandleButtonState state);
@@ -166,7 +171,7 @@ static void ui_apply_but_func(bContext *C, uiBut *but)
         * handling is done, i.e. menus are closed, in order to avoid conflicts
         * with these functions removing the buttons we are working with */
 
-       if(but->func || block->handle_func || (but->type == BUTM && block->butm_func) || but->opname) {
+       if(but->func || block->handle_func || (but->type == BUTM && block->butm_func) || but->opname || but->rnaprop) {
                after= MEM_callocN(sizeof(uiAfterFunc), "uiAfterFunc");
 
                after->func= but->func;
@@ -185,11 +190,14 @@ static void ui_apply_but_func(bContext *C, uiBut *but)
 
                after->opname= but->opname;
                after->opcontext= but->opcontext;
-               after->opproperties= but->opproperties;
+               after->opptr= but->opptr;
+
+               after->rnapoin= but->rnapoin;
+               after->rnaprop= but->rnaprop;
 
                but->opname= NULL;
                but->opcontext= 0;
-               but->opproperties= NULL;
+               but->opptr= NULL;
 
                BLI_addtail(&UIAfterFuncs, after);
        }
@@ -214,11 +222,14 @@ static void ui_apply_but_funcs_after(bContext *C)
                        after->butm_func(C, after->butm_func_arg, after->a2);
 
                if(after->opname)
-                       WM_operator_call(C, after->opname, after->opcontext, after->opproperties);
-               if(after->opproperties) {
-                       IDP_FreeProperty(after->opproperties);
-                       MEM_freeN(after->opproperties);
+                       WM_operator_name_call(C, after->opname, after->opcontext, after->opptr);
+               if(after->opptr) {
+                       WM_operator_properties_free(after->opptr);
+                       MEM_freeN(after->opptr);
                }
+
+               if(after->rnapoin.data)
+                       RNA_property_update(C, &after->rnapoin, after->rnaprop);
        }
 
        BLI_freelistN(&funcs);
@@ -1415,7 +1426,7 @@ static void ui_blockopen_begin(bContext *C, uiBut *but, uiHandleButtonData *data
        }
 
        /* this makes adjacent blocks auto open from now on */
-       if(but->block->auto_open==0) but->block->auto_open= 1;
+       //if(but->block->auto_open==0) but->block->auto_open= 1;
 }
 
 static void ui_blockopen_end(bContext *C, uiBut *but, uiHandleButtonData *data)
@@ -2761,7 +2772,7 @@ static void button_tooltip_timer_reset(uiBut *but)
 
        if(U.flag & USER_TOOLTIPS)
                if(!but->block->tooltipdisabled)
-                       data->tooltiptimer= WM_event_add_window_timer(data->window, BUTTON_TOOLTIP_DELAY, ~0);
+                       data->tooltiptimer= WM_event_add_window_timer(data->window, TIMER, BUTTON_TOOLTIP_DELAY);
 }
 
 static void button_activate_state(bContext *C, uiBut *but, uiHandleButtonState state)
@@ -2789,7 +2800,7 @@ static void button_activate_state(bContext *C, uiBut *but, uiHandleButtonState s
                                else time= -1;
 
                                if(time >= 0)
-                                       data->autoopentimer= WM_event_add_window_timer(data->window, time*20, ~0);
+                                       data->autoopentimer= WM_event_add_window_timer(data->window, TIMER, 0.02*(double)time);
                        }
                }
        }
@@ -2831,7 +2842,7 @@ static void button_activate_state(bContext *C, uiBut *but, uiHandleButtonState s
 
        /* add a short delay before exiting, to ensure there is some feedback */
        if(state == BUTTON_STATE_WAIT_FLASH) {
-               data->flashtimer= WM_event_add_window_timer(data->window, BUTTON_FLASH_DELAY, ~0);
+               data->flashtimer= WM_event_add_window_timer(data->window, TIMER, BUTTON_FLASH_DELAY);
        }
        else if(data->flashtimer) {
                WM_event_remove_window_timer(data->window, data->flashtimer);
@@ -2865,7 +2876,7 @@ static void button_activate_init(bContext *C, ARegion *ar, uiBut *but, uiButtonA
        data= MEM_callocN(sizeof(uiHandleButtonData), "uiHandleButtonData");
        data->window= CTX_wm_window(C);
        data->region= ar;
-       data->interactive= 0;
+       data->interactive= 1;
        data->state = BUTTON_STATE_INIT;
 
        /* activate button */
@@ -3327,16 +3338,15 @@ int ui_handle_menu_event(bContext *C, wmEvent *event, uiMenuBlockHandle *menu, i
                                if(inside || (block->flag & UI_BLOCK_LOOP)) {
                                        if(event->val) {
                                                but= ui_but_find_activated(ar);
-
                                                if(but) {
-                                                       if(ELEM(event->type, UPARROWKEY, WHEELUPMOUSE)) {
-                                                               if(block->direction & UI_TOP) but= ui_but_next(but);
-                                                               else but= ui_but_prev(but);
-                                                       }
-                                                       else {
+                                                       if(ELEM(event->type, DOWNARROWKEY, WHEELDOWNMOUSE)) {
                                                                if(block->direction & UI_TOP) but= ui_but_prev(but);
                                                                else but= ui_but_next(but);
                                                        }
+                                                       else {
+                                                               if(block->direction & UI_TOP) but= ui_but_next(but);
+                                                               else but= ui_but_prev(but);
+                                                       }
 
                                                        if(but)
                                                                ui_handle_button_activate(C, ar, but, BUTTON_ACTIVATE);
@@ -3566,10 +3576,15 @@ static int ui_handler_region(bContext *C, wmEvent *event, void *userdata)
        /* either handle events for already activated button or try to activate */
        but= ui_but_find_activated(ar);
 
-       if(but)
-               retval= ui_handle_button_event(C, event, but);
-       else
-               retval= ui_handle_button_over(C, event, ar);
+       if(!but || !button_modal_state(but->active->state))
+               retval= ui_handler_panel_region(C, event);
+
+       if(retval == WM_UI_HANDLER_CONTINUE) {
+               if(but)
+                       retval= ui_handle_button_event(C, event, but);
+               else
+                       retval= ui_handle_button_over(C, event, ar);
+       }
 
        /* re-enable tooltips */
        if(event->type == MOUSEMOVE && (event->x!=event->prevx || event->y!=event->prevy))
@@ -3647,28 +3662,35 @@ static int ui_handler_region_menu(bContext *C, wmEvent *event, void *userdata)
        return WM_UI_HANDLER_BREAK;
 }
 
+/* two types of popups, one with operator + enum, other with regular callbacks */
 static int ui_handler_popup(bContext *C, wmEvent *event, void *userdata)
 {
        uiMenuBlockHandle *menu= userdata;
-       void (*popup_func)(struct bContext *C, void *arg, int event)= NULL;
-       void *popup_arg= NULL;
-       int retval= 0;
 
        ui_handle_menus_recursive(C, event, menu);
 
        /* free if done, does not free handle itself */
        if(menu->menuretval) {
-               if(menu->menuretval == UI_RETURN_OK) {
-                       popup_func= menu->popup_func;
-                       popup_arg= menu->popup_arg;
-                       retval= menu->retvalue;
-               }
-
+               /* copy values, we have to free first (closes region) */
+               uiMenuBlockHandle temp= *menu;
+               
                ui_menu_block_free(C, menu);
                WM_event_remove_ui_handler(&CTX_wm_window(C)->handlers, ui_handler_popup, ui_handler_remove_popup, menu);
 
-               if(popup_func)
-                       popup_func(C, popup_arg, retval);
+               if(temp.menuretval == UI_RETURN_OK) {
+                       if(temp.popup_func) {
+                               temp.popup_func(C, temp.op_arg, temp.retvalue);
+                       }
+                       else if(temp.op_arg) {
+                               if(temp.propname)
+                                       RNA_enum_set(temp.op_arg->ptr, temp.propname, temp.retvalue);
+                               WM_operator_call(C, temp.op_arg);
+                       }
+               }
+               /* always free operator */
+               else if(temp.op_arg)
+                       WM_operator_free(temp.op_arg);
+               
        }
        else {
                /* re-enable tooltips */
@@ -3704,4 +3726,3 @@ void UI_add_popup_handlers(ListBase *handlers, uiMenuBlockHandle *menu)
 {
        WM_event_add_ui_handler(NULL, handlers, ui_handler_popup, ui_handler_remove_popup, menu);
 }
-