ok, apparently didn't commit this either. apparently includes a merge with trunk...
[blender-staging.git] / source / blender / editors / interface / interface_handlers.c
index c912a4aad6574687273a78be75c6de6f749fb31f..5db2d8e0551b50fe563c2c081bbb70f2e04064cc 100644 (file)
@@ -183,8 +183,6 @@ typedef struct uiAfterFunc {
 static int ui_mouse_inside_button(ARegion *ar, uiBut *but, int x, int y);
 static void button_activate_state(bContext *C, uiBut *but, uiHandleButtonState state);
 static int ui_handler_region_menu(bContext *C, wmEvent *event, void *userdata);
-static int ui_handler_popup(bContext *C, wmEvent *event, void *userdata);
-static void ui_handler_remove_popup(bContext *C, void *userdata);
 static void ui_handle_button_activate(bContext *C, ARegion *ar, uiBut *but, uiButtonActivateType type);
 static void button_timers_tooltip_remove(bContext *C, uiBut *but);
 
@@ -754,6 +752,13 @@ static void ui_apply_but_LINK(bContext *C, uiBut *but, uiHandleButtonData *data)
        data->applied= 1;
 }
 
+static void ui_apply_but_IMAGE(bContext *C, uiBut *but, uiHandleButtonData *data)
+{
+       ui_apply_but_func(C, but);
+
+       data->retval= but->retval;
+       data->applied= 1;
+}
 
 static void ui_apply_button(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, int interactive)
 {
@@ -874,6 +879,9 @@ static void ui_apply_button(bContext *C, uiBlock *block, uiBut *but, uiHandleBut
                case INLINK:
                        ui_apply_but_LINK(C, but, data);
                        break;
+               case BUT_IMAGE: 
+                       ui_apply_but_IMAGE(C, but, data);
+                       break;
                default:
                        break;
        }
@@ -2224,14 +2232,6 @@ static int ui_do_but_NUM(bContext *C, uiBlock *block, uiBut *but, uiHandleButton
                        fac= 1.0f;
                        if(event->shift) fac /= 10.0f;
                        if(event->alt) fac /= 20.0f;
-
-                       if(event->custom == EVT_DATA_TABLET) {
-                               wmTabletData *wmtab= event->customdata;
-
-                               /* de-sensitise based on tablet pressure */
-                               if (wmtab->Active != EVT_TABLET_NONE)
-                                       fac *= wmtab->Pressure;
-                       }
                        
                        snap= (event->ctrl)? (event->shift)? 2: 1: 0;
 
@@ -3364,7 +3364,7 @@ static uiBlock *menu_change_hotkey(bContext *C, ARegion *ar, void *arg_but)
        dummy[1]= 0;
        
        block= uiBeginBlock(C, ar, "_popup", UI_EMBOSSP);
-       uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_MOVEMOUSE_QUIT|UI_BLOCK_RET_1);
+       uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_MOVEMOUSE_QUIT|UI_BLOCK_RET_1|UI_BLOCK_MOVEMOUSE_QUIT);
        
        BLI_strncpy(buf, ot->name, OP_MAX_TYPENAME);
        strcat(buf, " |");
@@ -3399,11 +3399,14 @@ static int ui_but_menu(bContext *C, uiBut *but)
 
        pup= uiPupMenuBegin(C, name, 0);
        layout= uiPupMenuLayout(pup);
+       
+       uiLayoutSetOperatorContext(layout, WM_OP_INVOKE_DEFAULT);
 
        if(but->rnapoin.data && but->rnaprop) {
 
                length= RNA_property_array_length(&but->rnapoin, but->rnaprop);
-
+               
+               /* Keyframes */
                if(but->flag & UI_BUT_ANIMATED_KEY) {
                        if(length) {
                                uiItemBooleanO(layout, "Replace Keyframes", 0, "ANIM_OT_insert_keyframe_button", "all", 1);
@@ -3425,7 +3428,8 @@ static int ui_but_menu(bContext *C, uiBut *but)
                        else
                                uiItemBooleanO(layout, "Insert Keyframe", 0, "ANIM_OT_insert_keyframe_button", "all", 0);
                }
-
+               
+               /* Drivers */
                if(but->flag & UI_BUT_DRIVEN) {
                        uiItemS(layout);
 
@@ -3454,7 +3458,8 @@ static int ui_but_menu(bContext *C, uiBut *but)
                        if (ANIM_driver_can_paste())
                                uiItemO(layout, "Paste Driver", 0, "ANIM_OT_paste_driver_button");
                }
-
+               
+               /* Keying Sets */
                if(RNA_property_animateable(&but->rnapoin, but->rnaprop)) {
                        uiItemS(layout);
 
@@ -3468,14 +3473,19 @@ static int ui_but_menu(bContext *C, uiBut *but)
                                uiItemO(layout, "Remove from Keying Set", 0, "ANIM_OT_remove_keyingset_button");
                        }
                }
-
+               
                uiItemS(layout);
-
+               
+               /* Property Operators */
+               
+               //Copy Property Value
+               //Paste Property Value
+               
+               //uiItemO(layout, "Reset to Default Value", 0, "WM_OT_property_value_reset_button");
+               
                uiItemO(layout, "Copy Data Path", 0, "ANIM_OT_copy_clipboard_button");
 
                uiItemS(layout);
-
-
        }
 
 
@@ -3495,7 +3505,7 @@ static int ui_but_menu(bContext *C, uiBut *but)
                        RNA_string_set(&ptr_props, "doc_id", buf);
                        RNA_string_set(&ptr_props, "doc_new", RNA_property_description(but->rnaprop));
 
-                       uiItemFullO(layout, "Edit Docs (TODO)", 0, "WM_OT_doc_edit", ptr_props.data, WM_OP_INVOKE_DEFAULT, 0);
+                       uiItemFullO(layout, "Submit Description", 0, "WM_OT_doc_edit", ptr_props.data, WM_OP_INVOKE_DEFAULT, 0);
                }
                else if (but->optype) {
                        WM_operator_py_idname(buf, but->optype->idname);
@@ -3509,7 +3519,7 @@ static int ui_but_menu(bContext *C, uiBut *but)
                        RNA_string_set(&ptr_props, "doc_id", buf);
                        RNA_string_set(&ptr_props, "doc_new", but->optype->description);
 
-                       uiItemFullO(layout, "Edit Docs (TODO)", 0, "WM_OT_doc_edit", ptr_props.data, WM_OP_INVOKE_DEFAULT, 0);
+                       uiItemFullO(layout, "Submit Description", 0, "WM_OT_doc_edit", ptr_props.data, WM_OP_INVOKE_DEFAULT, 0);
                }
        }
 
@@ -3645,6 +3655,7 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, wmEvent *event)
        case TOG3:      
        case ROW:
        case LISTROW:
+       case BUT_IMAGE:
                retval= ui_do_but_EXIT(C, but, data, event);
                break;
        case TEX:
@@ -3739,26 +3750,55 @@ static void ui_blocks_set_tooltips(ARegion *ar, int enable)
 static int ui_mouse_inside_region(ARegion *ar, int x, int y)
 {
        uiBlock *block;
-       int mx, my;
+       
 
-       /* check if the mouse is in the region, and in case of a view2d also check
-        * if it is inside the view2d itself, not over scrollbars for example */
+       /* check if the mouse is in the region */
        if(!BLI_in_rcti(&ar->winrct, x, y)) {
                for(block=ar->uiblocks.first; block; block=block->next)
                        block->auto_open= 0;
-
+               
                return 0;
        }
 
+       /* also, check that with view2d, that the mouse is not over the scrollbars 
+        * NOTE: care is needed here, since the mask rect may include the scrollbars
+        * even when they are not visible, so we need to make a copy of the mask to
+        * use to check
+        */
        if(ar->v2d.mask.xmin!=ar->v2d.mask.xmax) {
+               View2D *v2d= &ar->v2d;
+               rcti mask_rct;
+               int mx, my;
+               
+               /* convert window coordinates to region coordinates */
                mx= x;
                my= y;
                ui_window_to_region(ar, &mx, &my);
-
-               if(!BLI_in_rcti(&ar->v2d.mask, mx, my))
+               
+               /* make a copy of the mask rect, and tweak accordingly for hidden scrollbars */
+               mask_rct.xmin= v2d->mask.xmin;
+               mask_rct.xmax= v2d->mask.xmax;
+               mask_rct.ymin= v2d->mask.ymin;
+               mask_rct.ymax= v2d->mask.ymax;
+               
+               if (v2d->scroll & V2D_SCROLL_VERTICAL_HIDE) {
+                       if (v2d->scroll & V2D_SCROLL_LEFT)
+                               mask_rct.xmin= v2d->vert.xmin;
+                       else if (v2d->scroll & V2D_SCROLL_RIGHT)
+                               mask_rct.xmax= v2d->vert.xmax;
+               }
+               if (v2d->scroll & V2D_SCROLL_HORIZONTAL_HIDE) {
+                       if (v2d->scroll & (V2D_SCROLL_BOTTOM|V2D_SCROLL_BOTTOM_O))
+                               mask_rct.ymin= v2d->hor.ymin;
+                       else if (v2d->scroll & V2D_SCROLL_TOP)
+                               mask_rct.ymax= v2d->hor.ymax;
+               }
+               
+               /* check if in the rect */
+               if(!BLI_in_rcti(&mask_rct, mx, my)) 
                        return 0;
        }
-
+       
        return 1;
 }
 
@@ -4951,7 +4991,7 @@ static int ui_handler_popup(bContext *C, wmEvent *event, void *userdata)
                uiPopupBlockHandle temp= *menu;
                
                ui_popup_block_free(C, menu);
-               WM_event_remove_ui_handler(&CTX_wm_window(C)->modalhandlers, ui_handler_popup, ui_handler_remove_popup, menu);
+               UI_remove_popup_handlers(&CTX_wm_window(C)->modalhandlers, menu);
 
                if(temp.menuretval == UI_RETURN_OK) {
                        if(temp.popup_func)
@@ -4992,8 +5032,14 @@ void UI_add_region_handlers(ListBase *handlers)
        WM_event_add_ui_handler(NULL, handlers, ui_handler_region, ui_handler_remove_region, NULL);
 }
 
-void UI_add_popup_handlers(bContext *C, ListBase *handlers, uiPopupBlockHandle *menu)
+void UI_add_popup_handlers(bContext *C, ListBase *handlers, uiPopupBlockHandle *popup)
 {
-       WM_event_add_ui_handler(C, handlers, ui_handler_popup, ui_handler_remove_popup, menu);
+       WM_event_add_ui_handler(C, handlers, ui_handler_popup, ui_handler_remove_popup, popup);
 }
 
+void UI_remove_popup_handlers(ListBase *handlers, uiPopupBlockHandle *popup)
+{
+       WM_event_remove_ui_handler(handlers, ui_handler_popup, ui_handler_remove_popup, popup);
+}
+
+