Merging r39717 through r39983 from trunk into soc-2011-tomato
[blender.git] / source / blender / editors / interface / interface_templates.c
index 3d7d1bf95ccd99f774c39cf8f8b5058e3d6a7e50..129f921e5fc05aca91bee40343c5d64f08aa769c 100644 (file)
@@ -40,6 +40,7 @@
 
 #include "BLI_string.h"
 #include "BLI_utildefines.h"
+#include "BLI_ghash.h"
 
 #include "BKE_animsys.h"
 #include "BKE_colortools.h"
@@ -54,6 +55,7 @@
 #include "BKE_displist.h"
 
 #include "ED_screen.h"
+#include "ED_object.h"
 #include "ED_render.h"
 
 #include "RNA_access.h"
@@ -276,8 +278,22 @@ static void template_id_cb(bContext *C, void *arg_litem, void *arg_event)
                        }
                        break;
                case UI_ID_ALONE:
-                       if(id) 
-                               id_single_user(C, id, &template->ptr, template->prop);
+                       if(id) {
+                               const int do_scene_obj= (GS(id->name) == ID_OB) &&
+                                                       (template->ptr.type == &RNA_SceneObjects);
+
+                               /* make copy */
+                               if(do_scene_obj) {
+                                       Scene *scene= CTX_data_scene(C);
+                                       ED_object_single_user(scene, (struct Object *)id);
+                                       WM_event_add_notifier(C, NC_SCENE|ND_OB_ACTIVE, scene);
+                               }
+                               else {
+                                       if(id) {
+                                               id_single_user(C, id, &template->ptr, template->prop);
+                                       }
+                               }
+                       }
                        break;
 #if 0
                case UI_ID_AUTO_NAME:
@@ -298,11 +314,13 @@ static const char *template_id_browse_tip(StructRNA *type)
                        case ID_MA: return "Browse Material to be linked";
                        case ID_TE: return "Browse Texture to be linked";
                        case ID_IM: return "Browse Image to be linked";
-                       case ID_LA: return "Browse Lattice Data to be linked";
+                       case ID_LT: return "Browse Lattice Data to be linked";
+                       case ID_LA: return "Browse Lamp Data to be linked";
                        case ID_CA: return "Browse Camera Data to be linked";
                        case ID_WO: return "Browse World Settings to be linked";
                        case ID_SCR: return "Choose Screen lay-out";
                        case ID_TXT: return "Browse Text to be linked";
+                       case ID_SPK: return "Browse Speaker Data to be linked";
                        case ID_SO: return "Browse Sound to be linked";
                        case ID_AR: return "Browse Armature data to be linked";
                        case ID_AC: return "Browse Action to be linked";
@@ -393,10 +411,7 @@ static void template_ID(bContext *C, uiLayout *layout, TemplateID *template, Str
 
                        sprintf(str, "%d", id->us);
 
-                       if(id->us<10)
-                               but= uiDefBut(block, BUT, 0, str, 0,0,UI_UNIT_X,UI_UNIT_Y, NULL, 0, 0, 0, 0, "Displays number of users of this data. Click to make a single-user copy.");
-                       else
-                               but= uiDefBut(block, BUT, 0, str, 0,0,UI_UNIT_X+10,UI_UNIT_Y, NULL, 0, 0, 0, 0, "Displays number of users of this data. Click to make a single-user copy.");
+                       but= uiDefBut(block, BUT, 0, str, 0,0,UI_UNIT_X + ((id->us < 10) ? 0:10), UI_UNIT_Y, NULL, 0, 0, 0, 0, "Displays number of users of this data. Click to make a single-user copy.");
 
                        uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_ALONE));
                        if(!id_copy(id, NULL, 1 /* test only */) || (idfrom && idfrom->lib) || !editable)
@@ -1873,7 +1888,7 @@ void uiTemplateColorWheel(uiLayout *layout, PointerRNA *ptr, const char *propnam
        col = uiLayoutColumn(layout, 0);
        row= uiLayoutRow(col, 1);
        
-       but= uiDefButR(block, HSVCIRCLE, 0, "", 0, 0, WHEEL_SIZE, WHEEL_SIZE, ptr, propname, -1, 0.0, 0.0, 0, 0, "");
+       but= uiDefButR_prop(block, HSVCIRCLE, 0, "",    0, 0, WHEEL_SIZE, WHEEL_SIZE, ptr, prop, -1, 0.0, 0.0, 0, 0, "");
 
        if(lock) {
                but->flag |= UI_BUT_COLOR_LOCK;
@@ -1892,7 +1907,7 @@ void uiTemplateColorWheel(uiLayout *layout, PointerRNA *ptr, const char *propnam
        uiItemS(row);
        
        if (value_slider)
-               uiDefButR(block, HSVCUBE, 0, "", WHEEL_SIZE+6, 0, 14, WHEEL_SIZE, ptr, propname, -1, softmin, softmax, UI_GRAD_V_ALT, 0, "");
+               uiDefButR_prop(block, HSVCUBE, 0, "", WHEEL_SIZE+6, 0, 14, WHEEL_SIZE, ptr, prop, -1, softmin, softmax, UI_GRAD_V_ALT, 0, "");
 }
 
 /********************* Layer Buttons Template ************************/
@@ -2023,7 +2038,7 @@ static int list_item_icon_get(bContext *C, PointerRNA *itemptr, int rnaicon, int
        return rnaicon;
 }
 
-static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, PointerRNA *itemptr, int i, int rnaicon, PointerRNA *activeptr, const char *activepropname)
+static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, PointerRNA *itemptr, int i, int rnaicon, PointerRNA *activeptr, PropertyRNA *activeprop)
 {
        uiBlock *block= uiLayoutGetBlock(layout);
        uiBut *but;
@@ -2037,7 +2052,7 @@ static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, Pointe
        /* list item behind label & other buttons */
        sub= uiLayoutRow(overlap, 0);
 
-       but= uiDefButR(block, LISTROW, 0, "", 0,0, UI_UNIT_X*10,UI_UNIT_Y, activeptr, activepropname, 0, 0, i, 0, 0, "");
+       but= uiDefButR_prop(block, LISTROW, 0, "", 0,0, UI_UNIT_X*10,UI_UNIT_Y, activeptr, activeprop, 0, 0, i, 0, 0, "");
        uiButSetFlag(but, UI_BUT_NO_TOOLTIP);
 
        sub= uiLayoutRow(overlap, 0);
@@ -2091,7 +2106,7 @@ static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, Pointe
        }
        else if(itemptr->type == &RNA_ShapeKey) {
                Object *ob= (Object*)activeptr->data;
-               Key *key= (Key*)itemptr->data;
+               Key *key= (Key*)itemptr->id.data;
 
                split= uiLayoutSplit(sub, 0.75f, 0);
 
@@ -2199,7 +2214,7 @@ void uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *
                                        row= uiLayoutRow(col, 0);
 
                                icon= list_item_icon_get(C, &itemptr, rnaicon, 1);
-                               but= uiDefIconButR(block, LISTROW, 0, icon, 0,0,UI_UNIT_X*10,UI_UNIT_Y, activeptr, activepropname, 0, 0, i, 0, 0, "");
+                               but= uiDefIconButR_prop(block, LISTROW, 0, icon, 0,0,UI_UNIT_X*10,UI_UNIT_Y, activeptr, activeprop, 0, 0, i, 0, 0, "");
                                uiButSetFlag(but, UI_BUT_NO_TOOLTIP);
                                
 
@@ -2239,7 +2254,7 @@ void uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *
 
                /* next/prev button */
                sprintf(str, "%d :", i);
-               but= uiDefIconTextButR(block, NUM, 0, 0, str, 0,0,UI_UNIT_X*5,UI_UNIT_Y, activeptr, activepropname, 0, 0, 0, 0, 0, "");
+               but= uiDefIconTextButR_prop(block, NUM, 0, 0, str, 0,0,UI_UNIT_X*5,UI_UNIT_Y, activeptr, activeprop, 0, 0, 0, 0, 0, "");
                if(i == 0)
                        uiButSetFlag(but, UI_BUT_DISABLED);
        }
@@ -2278,7 +2293,7 @@ void uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *
                        /* create list items */
                        RNA_PROP_BEGIN(ptr, itemptr, prop) {
                                if(i >= pa->list_scroll && i<pa->list_scroll+items)
-                                       list_item_row(C, col, ptr, &itemptr, i, rnaicon, activeptr, activepropname);
+                                       list_item_row(C, col, ptr, &itemptr, i, rnaicon, activeptr, activeprop);
 
                                i++;
                        }
@@ -2312,10 +2327,11 @@ static void operator_call_cb(bContext *C, void *UNUSED(arg1), void *arg2)
 
 static void operator_search_cb(const bContext *C, void *UNUSED(arg), const char *str, uiSearchItems *items)
 {
-       wmOperatorType *ot = WM_operatortype_first();
-       
-       for(; ot; ot= ot->next) {
-               
+       GHashIterator *iter= WM_operatortype_iter();
+
+       for( ; !BLI_ghashIterator_isDone(iter); BLI_ghashIterator_step(iter)) {
+               wmOperatorType *ot= BLI_ghashIterator_getValue(iter);
+
                if(BLI_strcasestr(ot->name, str)) {
                        if(WM_operator_poll((bContext*)C, ot)) {
                                char name[256];
@@ -2335,6 +2351,7 @@ static void operator_search_cb(const bContext *C, void *UNUSED(arg), const char
                        }
                }
        }
+       BLI_ghashIterator_free(iter);
 }
 
 void uiTemplateOperatorSearch(uiLayout *layout)
@@ -2356,6 +2373,8 @@ void uiTemplateOperatorSearch(uiLayout *layout)
 #define B_STOPCAST             2
 #define B_STOPANIM             3
 #define B_STOPCOMPO            4
+#define B_STOPSEQ              5
+#define B_STOPCLIP             6
 
 static void do_running_jobs(bContext *C, void *UNUSED(arg), int event)
 {
@@ -2372,6 +2391,12 @@ static void do_running_jobs(bContext *C, void *UNUSED(arg), int event)
                case B_STOPCOMPO:
                        WM_jobs_stop(CTX_wm_manager(C), CTX_wm_area(C), NULL);
                        break;
+               case B_STOPSEQ:
+                       WM_jobs_stop(CTX_wm_manager(C), CTX_wm_area(C), NULL);
+                       break;
+               case B_STOPCLIP:
+                       WM_jobs_stop(CTX_wm_manager(C), CTX_wm_area(C), NULL);
+                       break;
        }
 }
 
@@ -2393,8 +2418,15 @@ void uiTemplateRunningJobs(uiLayout *layout, bContext *C)
                if(WM_jobs_test(wm, sa))
                   owner = sa;
                handle_event= B_STOPCOMPO;
-       } 
-       else {
+       } else if (sa->spacetype==SPACE_SEQ) {
+               if(WM_jobs_test(wm, sa))
+                       owner = sa;
+               handle_event = B_STOPSEQ;
+       } else if(sa->spacetype==SPACE_CLIP) {
+               if(WM_jobs_test(wm, sa))
+                  owner = sa;
+               handle_event= B_STOPCLIP;
+       } else {
                Scene *scene;
                /* another scene can be rendering too, for example via compositor */
                for(scene= CTX_data_main(C)->scene.first; scene; scene= scene->id.next)