WM: move dropbox handler to it's own type
authorCampbell Barton <ideasman42@gmail.com>
Tue, 19 Feb 2019 04:32:01 +0000 (15:32 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 19 Feb 2019 05:17:21 +0000 (16:17 +1100)
source/blender/windowmanager/intern/wm_dragdrop.c
source/blender/windowmanager/intern/wm_event_system.c
source/blender/windowmanager/wm_event_system.h

index 714312e..7a066ef 100644 (file)
@@ -194,16 +194,17 @@ void WM_drag_free_list(struct ListBase *lb)
 
 static const char *dropbox_active(bContext *C, ListBase *handlers, wmDrag *drag, const wmEvent *event)
 {
-       wmEventHandler *handler = handlers->first;
-       for (; handler; handler = handler->next) {
-               if (handler->dropboxes) {
-                       wmDropBox *drop = handler->dropboxes->first;
-                       for (; drop; drop = drop->next) {
-                               const char *tooltip = NULL;
-                               if (drop->poll(C, drag, event, &tooltip)) {
-                                       /* XXX Doing translation here might not be ideal, but later we have no more
-                                        *     access to ot (and hence op context)... */
-                                       return (tooltip) ? tooltip : RNA_struct_ui_name(drop->ot->srna);
+       for (wmEventHandler *handler_base = handlers->first; handler_base; handler_base = handler_base->next) {
+               if (handler_base->type == WM_HANDLER_TYPE_DROPBOX) {
+                       wmEventHandler_Dropbox *handler = (wmEventHandler_Dropbox *)handler_base;
+                       if (handler->dropboxes) {
+                               for (wmDropBox *drop = handler->dropboxes->first; drop; drop = drop->next) {
+                                       const char *tooltip = NULL;
+                                       if (drop->poll(C, drag, event, &tooltip)) {
+                                               /* XXX Doing translation here might not be ideal, but later we have no more
+                                                *     access to ot (and hence op context)... */
+                                               return (tooltip) ? tooltip : RNA_struct_ui_name(drop->ot->srna);
+                                       }
                                }
                        }
                }
index 95dcae9..41f1132 100644 (file)
@@ -2432,9 +2432,10 @@ static int wm_handlers_do_intern(bContext *C, wmEvent *event, ListBase *handlers
                                        action |= wm_handler_fileselect_call(C, handlers, handler_op, event);
                                }
                        }
-                       else if (handler->dropboxes) {
+                       else if (handler->type == WM_HANDLER_TYPE_DROPBOX) {
+                               wmEventHandler_Dropbox *handler_db = (wmEventHandler_Dropbox *)handler;
                                if (!wm->is_interface_locked && event->type == EVT_DROP) {
-                                       wmDropBox *drop = handler->dropboxes->first;
+                                       wmDropBox *drop = handler_db->dropboxes->first;
                                        for (; drop; drop = drop->next) {
                                                /* other drop custom types allowed */
                                                if (event->custom == EVT_DATA_DRAGDROP) {
@@ -3518,20 +3519,24 @@ void WM_event_free_ui_handler_all(
 
 wmEventHandler *WM_event_add_dropbox_handler(ListBase *handlers, ListBase *dropboxes)
 {
-       wmEventHandler *handler;
-
        /* only allow same dropbox once */
-       for (handler = handlers->first; handler; handler = handler->next)
-               if (handler->dropboxes == dropboxes)
-                       return handler;
+       for (wmEventHandler *handler_base = handlers->first; handler_base; handler_base = handler_base->next) {
+               if (handler_base->type == WM_HANDLER_TYPE_DROPBOX) {
+                       wmEventHandler_Dropbox *handler = (wmEventHandler_Dropbox *)handler_base;
+                       if (handler->dropboxes == dropboxes) {
+                               return &handler->base;
+                       }
+               }
+       }
 
-       handler = MEM_callocN(sizeof(wmEventHandler), "dropbox handler");
+       wmEventHandler_Dropbox *handler = MEM_callocN(sizeof(*handler), __func__);
+       handler->base.type = WM_HANDLER_TYPE_DROPBOX;
 
        /* dropbox stored static, no free or copy */
        handler->dropboxes = dropboxes;
        BLI_addhead(handlers, handler);
 
-       return handler;
+       return &handler->base;
 }
 
 /* XXX solution works, still better check the real cause (ton) */
index 5346ec5..9448bba 100644 (file)
@@ -46,6 +46,7 @@ enum eWM_EventHandlerType {
        WM_HANDLER_TYPE_GIZMO,
        WM_HANDLER_TYPE_UI,
        WM_HANDLER_TYPE_OP,
+       WM_HANDLER_TYPE_DROPBOX,
 };
 
 typedef struct wmEventHandler {
@@ -61,10 +62,6 @@ typedef struct wmEventHandler {
        struct wmEventHandler_KeymapFn keymap_callback;
 
        struct bToolRef *keymap_tool;
-
-
-       /* drop box handler */
-       ListBase *dropboxes;
 } wmEventHandler;
 
 /** #WM_HANDLER_TYPE_GIZMO */
@@ -109,6 +106,13 @@ typedef struct wmEventHandler_Op {
        } context;
 } wmEventHandler_Op;
 
+/** #WM_HANDLER_TYPE_DROPBOX */
+typedef struct wmEventHandler_Dropbox {
+       wmEventHandler base;
+
+       /** Never NULL. */
+       ListBase *dropboxes;
+} wmEventHandler_Dropbox;
 
 /* wm_event_system.c */
 void        wm_event_free_all       (wmWindow *win);