svn merge -r 21041:21301 https://svn.blender.org/svnroot/bf-blender/branches/blender2...
[blender.git] / source / blender / editors / interface / interface.c
index 5ffc6440dc46ed7c2cd3f215c630eb3392976c9f..00ec875bd86c3688200c3487e17bd4da67f9c84a 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * $Id: interface.c 16882 2008-10-02 12:29:45Z ton $
+ * $Id$
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
@@ -80,7 +80,6 @@
  */
 
 static void ui_free_but(const bContext *C, uiBut *but);
-static void ui_rna_ID_autocomplete(bContext *C, char *str, void *arg_but);
 
 /* ************* translation ************** */
 
@@ -671,7 +670,8 @@ void uiDrawBlock(const bContext *C, uiBlock *block)
        /* widgets */
        for(but= block->buttons.first; but; but= but->next) {
                ui_but_to_pixelrect(&rect, ar, block, but);
-               ui_draw_but(C, ar, &style, but, &rect);
+               if(!(but->flag & UI_HIDDEN))
+                       ui_draw_but(C, ar, &style, but, &rect);
        }
        
        /* restore matrix */
@@ -1281,17 +1281,13 @@ void ui_get_but_string(uiBut *but, char *str, int maxlen)
                else if(type == PROP_POINTER) {
                        /* RNA pointer */
                        PointerRNA ptr= RNA_property_pointer_get(&but->rnapoin, but->rnaprop);
-                       PropertyRNA *nameprop;
-
-                       if(ptr.data && (nameprop = RNA_struct_name_property(ptr.type)))
-                               buf= RNA_property_string_get_alloc(&ptr, nameprop, str, maxlen);
-                       else
-                               BLI_strncpy(str, "", maxlen);
+                       buf= RNA_struct_name_get_alloc(&ptr, str, maxlen);
                }
-               else
-                       BLI_strncpy(str, "", maxlen);
 
-               if(buf && buf != str) {
+               if(!buf) {
+                       BLI_strncpy(str, "", maxlen);
+               }
+               else if(buf && buf != str) {
                        /* string was too long, we have to truncate */
                        BLI_strncpy(str, buf, maxlen);
                        MEM_freeN(buf);
@@ -1337,72 +1333,6 @@ void ui_get_but_string(uiBut *but, char *str, int maxlen)
        }
 }
 
-static void ui_rna_ID_collection(bContext *C, uiBut *but, PointerRNA *ptr, PropertyRNA **prop)
-{
-       CollectionPropertyIterator iter;
-       PropertyRNA *iterprop, *iprop;
-       StructRNA *srna;
-
-       /* look for collection property in Main */
-       RNA_pointer_create(NULL, &RNA_Main, CTX_data_main(C), ptr);
-
-       iterprop= RNA_struct_iterator_property(ptr->type);
-       RNA_property_collection_begin(ptr, iterprop, &iter);
-       *prop= NULL;
-
-       for(; iter.valid; RNA_property_collection_next(&iter)) {
-               iprop= iter.ptr.data;
-
-               /* if it's a collection and has same pointer type, we've got it */
-               if(RNA_property_type(iprop) == PROP_COLLECTION) {
-                       srna= RNA_property_pointer_type(ptr, iprop);
-
-                       if(RNA_property_pointer_type(ptr, but->rnaprop) == srna) {
-                               *prop= iprop;
-                               break;
-                       }
-               }
-       }
-
-       RNA_property_collection_end(&iter);
-}
-
-/* autocomplete callback for RNA pointers */
-static void ui_rna_ID_autocomplete(bContext *C, char *str, void *arg_but)
-{
-       uiBut *but= arg_but;
-       AutoComplete *autocpl;
-       CollectionPropertyIterator iter;
-       PointerRNA ptr;
-       PropertyRNA *prop, *nameprop;
-       char *name;
-       
-       if(str[0]==0) return;
-
-       /* get the collection */
-       ui_rna_ID_collection(C, but, &ptr, &prop);
-       if(prop==NULL) return;
-
-       autocpl= autocomplete_begin(str, ui_get_but_string_max_length(but));
-       RNA_property_collection_begin(&ptr, prop, &iter);
-
-       /* loop over items in collection */
-       for(; iter.valid; RNA_property_collection_next(&iter)) {
-               if(iter.ptr.data && (nameprop = RNA_struct_name_property(iter.ptr.type))) {
-                       name= RNA_property_string_get_alloc(&iter.ptr, nameprop, NULL, 0);
-
-                       if(name) {
-                               /* test item name */
-                               autocomplete_do_name(autocpl, name);
-                               MEM_freeN(name);
-                       }
-               }
-       }
-
-       RNA_property_collection_end(&iter);
-       autocomplete_end(autocpl, str);
-}
-
 int ui_set_but_string(bContext *C, uiBut *but, const char *str)
 {
        if(but->rnaprop && ELEM3(but->type, TEX, IDPOIN, SEARCH_MENU)) {
@@ -1421,21 +1351,21 @@ int ui_set_but_string(bContext *C, uiBut *but, const char *str)
                                PointerRNA ptr, rptr;
                                PropertyRNA *prop;
 
-                               /* XXX only ID pointers at the moment, needs to support
-                                * custom collection too for bones, vertex groups, .. */
-                               ui_rna_ID_collection(C, but, &ptr, &prop);
-
                                if(str == NULL || str[0] == '\0') {
-                                       memset(&rptr, 0, sizeof(rptr));
-                                       RNA_property_pointer_set(&but->rnapoin, but->rnaprop, rptr);
+                                       RNA_property_pointer_set(&but->rnapoin, but->rnaprop, PointerRNA_NULL);
                                        return 1;
                                }
-                               else if(prop && RNA_property_collection_lookup_string(&ptr, prop, str, &rptr)) {
-                                       RNA_property_pointer_set(&but->rnapoin, but->rnaprop, rptr);
+                               else {
+                                       ptr= but->rnasearchpoin;
+                                       prop= but->rnasearchprop;
+                                       
+                                       if(prop && RNA_property_collection_lookup_string(&ptr, prop, str, &rptr))
+                                               RNA_property_pointer_set(&but->rnapoin, but->rnaprop, rptr);
+
                                        return 1;
                                }
-                               else
-                                       return 0;
+
+                               return 0;
                        }
                }
        }
@@ -2147,13 +2077,10 @@ static uiBut *ui_def_but(uiBlock *block, int type, int retval, char *str, short
                rgb_to_hsv(rgb[0], rgb[1], rgb[2], but->hsv, but->hsv+1, but->hsv+2);
        }
 
-       if((block->flag & UI_BLOCK_LOOP) || ELEM6(but->type, MENU, TEX, LABEL, IDPOIN, BLOCK, BUTM)) {
-               but->flag |= UI_TEXT_LEFT;
-       }
-       
-       if(but->type==BUT_TOGDUAL) {
+       if((block->flag & UI_BLOCK_LOOP) || ELEM7(but->type, MENU, TEX, LABEL, IDPOIN, BLOCK, BUTM, SEARCH_MENU))
+               but->flag |= (UI_TEXT_LEFT|UI_ICON_LEFT);
+       else if(but->type==BUT_TOGDUAL)
                but->flag |= UI_ICON_LEFT;
-       }
 
        but->flag |= (block->flag & UI_BUT_ALIGN);
 
@@ -2257,7 +2184,7 @@ uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, char *str, short x1,
                                RNA_property_int_range(ptr, prop, &hardmin, &hardmax);
                                RNA_property_int_ui_range(ptr, prop, &softmin, &softmax, &step);
 
-                               if(min == max) {
+                               if(type != ROW && min == max) {
                                        min= hardmin;
                                        max= hardmax;
                                }
@@ -2272,7 +2199,7 @@ uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, char *str, short x1,
                                RNA_property_float_range(ptr, prop, &hardmin, &hardmax);
                                RNA_property_float_ui_range(ptr, prop, &softmin, &softmax, &step, &precision);
 
-                               if(min == max) {
+                               if(type != ROW && min == max) {
                                        min= hardmin;
                                        max= hardmax;
                                }
@@ -2303,10 +2230,6 @@ uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, char *str, short x1,
                        but->rnaindex= index;
                else
                        but->rnaindex= 0;
-
-               if(type == IDPOIN)
-                       uiButSetCompleteFunc(but, ui_rna_ID_autocomplete, but);
-
        }
 
        if(icon) {
@@ -2422,7 +2345,11 @@ void autocomplete_do_name(AutoComplete *autocpl, const char *name)
                else {
                        /* remove from truncate what is not in bone->name */
                        for(a=0; a<autocpl->maxlen-1; a++) {
-                               if(truncate[a]!=name[a])
+                               if(name[a] == 0) {
+                                       truncate[a]= 0;
+                                       break;
+                               }
+                               else if(truncate[a]!=name[a])
                                        truncate[a]= 0;
                        }
                }
@@ -2753,7 +2680,7 @@ void uiBlockFlipOrder(uiBlock *block)
        uiBut *but, *next;
        float centy, miny=10000, maxy= -10000;
 
-       if(!(U.uiflag & USER_DIRECTIONALORDER))
+       if(U.uiflag & USER_MENUFIXEDORDER)
                return;
        
        for(but= block->buttons.first; but; but= but->next) {
@@ -2992,15 +2919,15 @@ uiBut *uiDefSearchBut(uiBlock *block, void *arg, int retval, int icon, int maxle
 }
 
 /* arg is user value, searchfunc and handlefunc both get it as arg */
-void uiButSetSearchFunc(uiBut *but, uiButSearchFunc sfunc, void *arg, uiButHandleFunc bfunc)
+/* if active set, button opens with this item visible and selected */
+void uiButSetSearchFunc(uiBut *but, uiButSearchFunc sfunc, void *arg, uiButHandleFunc bfunc, void *active)
 {
        but->search_func= sfunc;
        but->search_arg= arg;
        
-       uiButSetFunc(but, bfunc, arg, NULL);
+       uiButSetFunc(but, bfunc, arg, active);
 }
 
-
 /* Program Init/Exit */
 
 void UI_init(void)