Revision: 18835
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18835
Author:   blendix
Date:     2009-02-06 17:40:14 +0100 (Fri, 06 Feb 2009)

Log Message:
-----------
2.5: ID datablock button back, previously known as std_libbuttons. The
way this worked in 2.4x wasn't really clean, with events going all over
the place and using dubious variables such as G.but->lockpoin or
G.sima->menunr. It works as follows now, for example:

xco= uiDefIDPoinButs(block, CTX_data_main(C), NULL, (ID**)&sima->image, ID_IM, 
&sima->pin, xco, yco,
        sima_idpoin_handle, 
UI_ID_BROWSE|UI_ID_RENAME|UI_ID_ADD_NEW|UI_ID_OPEN|UI_ID_DELETE|UI_ID_ALONE|UI_ID_PIN);

The last two parameters are a callback function, and a list of events
or functionalities that are supported. The callback function will then
get the ID pointer + event to handle.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/editors/include/UI_interface.h
    branches/blender2.5/blender/source/blender/editors/interface/interface.c
    
branches/blender2.5/blender/source/blender/editors/interface/interface_handlers.c
    
branches/blender2.5/blender/source/blender/editors/interface/interface_intern.h
    
branches/blender2.5/blender/source/blender/editors/interface/interface_utils.c
    
branches/blender2.5/blender/source/blender/editors/space_image/image_header.c
    branches/blender2.5/blender/source/blender/editors/space_image/space_image.c
    
branches/blender2.5/blender/source/blender/editors/transform/transform_orientations.c

Modified: 
branches/blender2.5/blender/source/blender/editors/include/UI_interface.h
===================================================================
--- branches/blender2.5/blender/source/blender/editors/include/UI_interface.h   
2009-02-06 16:38:53 UTC (rev 18834)
+++ branches/blender2.5/blender/source/blender/editors/include/UI_interface.h   
2009-02-06 16:40:14 UTC (rev 18835)
@@ -33,6 +33,7 @@
 /* Struct Declarations */
 
 struct ID;
+struct Main;
 struct ListBase;
 struct ARegion;
 struct wmWindow;
@@ -395,10 +396,25 @@
  * - PickerButtons: buttons like the color picker (for code sharing).
  * - AutoButR: RNA property button with type automatically defined. */
 
-typedef void     (*uiIDPoinFuncFP)(struct bContext *C, char *str, struct ID 
**idpp);
+#define UI_ID_RENAME           1
+#define UI_ID_BROWSE           2
+#define UI_ID_ADD_NEW          4
+#define UI_ID_OPEN                     8
+#define UI_ID_ALONE                    16
+#define UI_ID_DELETE           32
+#define UI_ID_LOCAL                    64
+#define UI_ID_AUTO_NAME                128
+#define UI_ID_FAKE_USER                256
+#define UI_ID_PIN                      512
+#define UI_ID_BROWSE_RENDER    1024
+#define UI_ID_FULL                     
(UI_ID_RENAME|UI_ID_BROWSE|UI_ID_ADD_NEW|UI_ID_OPEN|UI_ID_ALONE|UI_ID_DELETE|UI_ID_LOCAL)
 
-uiBut *uiDefIDPoinBut(struct uiBlock *block, uiIDPoinFuncFP func, short 
blocktype, int retval, char *str,
+typedef void (*uiIDPoinFuncFP)(struct bContext *C, char *str, struct ID 
**idpp);
+typedef void (*uiIDPoinFunc)(struct bContext *C, struct ID *id, int event);
+
+uiBut *uiDefIDPoinBut(uiBlock *block, uiIDPoinFuncFP func, short blocktype, 
int retval, char *str,
                                                short x1, short y1, short x2, 
short y2, void *idpp, char *tip);
+int uiDefIDPoinButs(uiBlock *block, struct Main *main, struct ID *parid, 
struct ID **id_p, int id_code, short *pin_p, int x, int y, uiIDPoinFunc func, 
int events);
 
 uiBut *uiDefPulldownBut(uiBlock *block, uiBlockCreateFunc func, void *arg, 
char *str, short x1, short y1, short x2, short y2, char *tip);
 uiBut *uiDefMenuBut(uiBlock *block, uiMenuCreateFunc func, void *arg, char 
*str, short x1, short y1, short x2, short y2, char *tip);
@@ -434,9 +450,12 @@
  * uiButSetCompleteFunc is for tab completion.
  *
  * uiBlockSetFunc and uiButSetFunc are callbacks run when a button is used,
- * in case events, operators or RNA are not sufficient to handle the button. */
+ * in case events, operators or RNA are not sufficient to handle the button.
+ *
+ * uiButSetNFunc will free the argument with MEM_freeN. */
 
 typedef void (*uiButHandleFunc)(struct bContext *C, void *arg1, void *arg2);
+typedef void (*uiButHandleNFunc)(struct bContext *C, void *argN, void *arg2);
 typedef void (*uiButCompleteFunc)(struct bContext *C, char *str, void *arg);
 typedef void (*uiBlockHandleFunc)(struct bContext *C, void *arg, int event);
 
@@ -445,6 +464,7 @@
 
 void   uiBlockSetFunc          (uiBlock *block,        uiButHandleFunc func, 
void *arg1, void *arg2);
 void   uiButSetFunc            (uiBut *but,            uiButHandleFunc func, 
void *arg1, void *arg2);
+void   uiButSetNFunc           (uiBut *but,            uiButHandleNFunc func, 
void *argN, void *arg2);
 
 void   uiButSetCompleteFunc(uiBut *but,                uiButCompleteFunc func, 
void *arg);
 

Modified: 
branches/blender2.5/blender/source/blender/editors/interface/interface.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/interface/interface.c    
2009-02-06 16:38:53 UTC (rev 18834)
+++ branches/blender2.5/blender/source/blender/editors/interface/interface.c    
2009-02-06 16:40:14 UTC (rev 18835)
@@ -503,13 +503,14 @@
        /* various properties are being compared here, hopfully sufficient
         * to catch all cases, but it is simple to add more checks later */
        if(but->retval != oldbut->retval) return 0;
-       if(but->poin != oldbut->poin || but->pointype != oldbut->pointype) 
return 0;
        if(but->rnapoin.data != oldbut->rnapoin.data) return 0;
        if(but->rnaprop != oldbut->rnaprop)
        if(but->rnaindex != oldbut->rnaindex) return 0;
        if(but->func != oldbut->func) return 0;
+       if(but->funcN != oldbut->funcN) return 0;
        if(oldbut->func_arg1 != oldbut && but->func_arg1 != oldbut->func_arg1) 
return 0;
        if(oldbut->func_arg2 != oldbut && but->func_arg2 != oldbut->func_arg2) 
return 0;
+       if(!but->funcN && (but->poin != oldbut->poin || but->pointype != 
oldbut->pointype)) return 0;
 
        return 1;
 }
@@ -902,8 +903,10 @@
 
 void uiBlockSetButLock(uiBlock *block, int val, char *lockstr)
 {
-       block->lock |= val;
-       if(val) block->lockstr= lockstr;
+       if(val) {
+               block->lock |= val;
+               block->lockstr= lockstr;
+       }
 }
 
 void uiBlockClearButLock(uiBlock *block)
@@ -1496,6 +1499,7 @@
                WM_operator_properties_free(but->opptr);
                MEM_freeN(but->opptr);
        }
+       if(but->func_argN) MEM_freeN(but->func_argN);
        if(but->active) ui_button_active_cancel(C, but);
        if(but->str && but->str != but->strdata) MEM_freeN(but->str);
        ui_free_link(but->link);
@@ -2852,19 +2856,19 @@
        return but->opptr;
 }
 
-void uiBlockSetHandleFunc(uiBlock *block, void (*func)(struct bContext *C, 
void *arg, int event), void *arg)
+void uiBlockSetHandleFunc(uiBlock *block, uiBlockHandleFunc func, void *arg)
 {
        block->handle_func= func;
        block->handle_func_arg= arg;
 }
 
-void uiBlockSetButmFunc(uiBlock *block, void (*func)(struct bContext *C, void 
*arg, int but_a2), void *arg)
+void uiBlockSetButmFunc(uiBlock *block, uiMenuHandleFunc func, void *arg)
 {
        block->butm_func= func;
        block->butm_func_arg= arg;
 }
 
-void uiBlockSetFunc(uiBlock *block, void (*func)(struct bContext *C, void 
*arg1, void *arg2), void *arg1, void *arg2)
+void uiBlockSetFunc(uiBlock *block, uiButHandleFunc func, void *arg1, void 
*arg2)
 {
        block->func= func;
        block->func_arg1= arg1;
@@ -2876,15 +2880,22 @@
        block->drawextra= func;
 }
 
-void uiButSetFunc(uiBut *but, void (*func)(struct bContext *C, void *arg1, 
void *arg2), void *arg1, void *arg2)
+void uiButSetFunc(uiBut *but, uiButHandleFunc func, void *arg1, void *arg2)
 {
        but->func= func;
        but->func_arg1= arg1;
        but->func_arg2= arg2;
 }
 
-void uiButSetCompleteFunc(uiBut *but, void (*func)(struct bContext *C, char 
*str, void *arg), void *arg)
+void uiButSetNFunc(uiBut *but, uiButHandleNFunc funcN, void *argN, void *arg2)
 {
+       but->funcN= funcN;
+       but->func_argN= argN;
+       but->func_arg2= arg2;
+}
+
+void uiButSetCompleteFunc(uiBut *but, uiButCompleteFunc func, void *arg)
+{
        but->autocomplete_func= func;
        but->autofunc_arg= arg;
 }

Modified: 
branches/blender2.5/blender/source/blender/editors/interface/interface_handlers.c
===================================================================
--- 
branches/blender2.5/blender/source/blender/editors/interface/interface_handlers.c
   2009-02-06 16:38:53 UTC (rev 18834)
+++ 
branches/blender2.5/blender/source/blender/editors/interface/interface_handlers.c
   2009-02-06 16:40:14 UTC (rev 18835)
@@ -134,15 +134,18 @@
 typedef struct uiAfterFunc {
        struct uiAfterFunc *next, *prev;
 
-       void (*func)(struct bContext*, void *, void *);
+       uiButHandleFunc func;
        void *func_arg1;
        void *func_arg2;
 
-       void (*handle_func)(struct bContext*, void *arg, int event);
+       uiButHandleNFunc funcN;
+       void *func_argN;
+
+       uiBlockHandleFunc handle_func;
        void *handle_func_arg;
        int retval;
 
-       void (*butm_func)(struct bContext*, void *arg, int event);
+       uiMenuHandleFunc butm_func;
        void *butm_func_arg;
        int a2;
 
@@ -217,13 +220,16 @@
         * 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 || but->rnaprop) {
+       if(but->func || but->funcN || block->handle_func || (but->type == BUTM 
&& block->butm_func) || but->opname || but->rnaprop) {
                after= MEM_callocN(sizeof(uiAfterFunc), "uiAfterFunc");
 
                after->func= but->func;
                after->func_arg1= but->func_arg1;
                after->func_arg2= but->func_arg2;
 
+               after->funcN= but->funcN;
+               after->func_argN= but->func_argN;
+
                after->handle_func= block->handle_func;
                after->handle_func_arg= block->handle_func_arg;
                after->retval= but->retval;
@@ -264,6 +270,8 @@
 
                if(after.func)
                        after.func(C, after.func_arg1, after.func_arg2);
+               if(after.funcN)
+                       after.funcN(C, after.func_argN, after.func_arg2);
                
                if(after.handle_func)
                        after.handle_func(C, after.handle_func_arg, 
after.retval);
@@ -2611,6 +2619,9 @@
        data= but->active;
        retval= WM_UI_HANDLER_CONTINUE;
 
+       if(but->flag & UI_BUT_DISABLED)
+               return WM_UI_HANDLER_BREAK;
+
        /* handle copy-paste */
        if(data->state == BUTTON_STATE_HIGHLIGHT) {
                if(ELEM(event->type, CKEY, VKEY) && event->val==KM_PRESS && 
(event->ctrl || event->oskey)) {

Modified: 
branches/blender2.5/blender/source/blender/editors/interface/interface_intern.h
===================================================================
--- 
branches/blender2.5/blender/source/blender/editors/interface/interface_intern.h 
    2009-02-06 16:38:53 UTC (rev 18834)
+++ 
branches/blender2.5/blender/source/blender/editors/interface/interface_intern.h 
    2009-02-06 16:40:14 UTC (rev 18835)
@@ -125,6 +125,9 @@
        void *func_arg1;
        void *func_arg2;
 
+       uiButHandleNFunc funcN;
+       void *func_argN;
+
        void (*embossfunc)(int , int , float, float, float, float, float, int);
        void (*sliderfunc)(int , float, float, float, float, float, float, int);
 

Modified: 
branches/blender2.5/blender/source/blender/editors/interface/interface_utils.c
===================================================================
--- 
branches/blender2.5/blender/source/blender/editors/interface/interface_utils.c  
    2009-02-06 16:38:53 UTC (rev 18834)
+++ 
branches/blender2.5/blender/source/blender/editors/interface/interface_utils.c  
    2009-02-06 16:40:14 UTC (rev 18835)
@@ -30,11 +30,14 @@
 #include "MEM_guardedalloc.h"
 
 #include "DNA_listBase.h"
+#include "DNA_material_types.h"
 #include "DNA_screen_types.h"
 #include "DNA_windowmanager_types.h"
 
 #include "BKE_context.h"
 #include "BKE_idprop.h"
+#include "BKE_library.h"
+#include "BKE_main.h"
 #include "BKE_utildefines.h"
 
 #include "RNA_access.h"
@@ -47,6 +50,10 @@
 #include "WM_api.h"
 #include "WM_types.h"
 
+#define DEF_BUT_WIDTH          150
+#define DEF_ICON_BUT_WIDTH     20
+#define DEF_BUT_HEIGHT         20
+
 /*************************** RNA Utilities ******************************/
 
 int UI_GetIconRNA(PointerRNA *ptr)
@@ -287,9 +294,6 @@
        return but;
 }
 
-#define RNA_BUT_WIDTH 150
-#define RNA_BUT_HEIGHT 20
-
 int uiDefAutoButsRNA(uiBlock *block, PointerRNA *ptr)
 {
        CollectionPropertyIterator iter;
@@ -303,8 +307,8 @@
 
        /* create buttons */

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to