code cleanup: favor braces when blocks have mixed brace use.
[blender.git] / source / blender / editors / interface / interface_templates.c
index b7cc4dd..9cc45f5 100644 (file)
 
 #include "MEM_guardedalloc.h"
 
-#include "DNA_anim_types.h"
 #include "DNA_dynamicpaint_types.h"
-#include "DNA_key_types.h"
 #include "DNA_scene_types.h"
-#include "DNA_userdef_types.h"
+#include "DNA_object_types.h"
+#include "DNA_object_force.h"
 
 #include "BLI_utildefines.h"
 #include "BLI_string.h"
 #include "BLI_ghash.h"
 #include "BLI_rect.h"
+#include "BLI_math.h"
+#include "BLI_listbase.h"
 
+#include "BLF_api.h"
 #include "BLF_translation.h"
 
 #include "BKE_animsys.h"
 #include "BKE_colortools.h"
 #include "BKE_context.h"
+#include "BKE_depsgraph.h"
+#include "BKE_displist.h"
 #include "BKE_dynamicpaint.h"
 #include "BKE_global.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
-#include "BKE_object.h"
 #include "BKE_material.h"
-#include "BKE_texture.h"
+#include "BKE_modifier.h"
+#include "BKE_object.h"
+#include "BKE_packedFile.h"
+#include "BKE_particle.h"
 #include "BKE_report.h"
-#include "BKE_displist.h"
+#include "BKE_sca.h"
 #include "BKE_scene.h"
+#include "BKE_screen.h"
+#include "BKE_texture.h"
 
 #include "ED_screen.h"
 #include "ED_object.h"
 #include "ED_render.h"
+#include "ED_util.h"
 
 #include "RNA_access.h"
 #include "RNA_enum_types.h"
 #include "WM_types.h"
 
 #include "UI_interface.h"
+#include "UI_interface_icons.h"
 #include "interface_intern.h"
 
-#include "BLF_api.h"
-#include "BLF_translation.h"
-
 void UI_template_fix_linking(void)
 {
 }
@@ -173,31 +180,34 @@ static uiBlock *id_search_menu(bContext *C, ARegion *ar, void *arg_litem)
        idptr = RNA_property_pointer_get(&template.ptr, template.prop);
 
        block = uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
-       uiBlockSetFlag(block, UI_BLOCK_LOOP | UI_BLOCK_REDRAW | UI_BLOCK_RET_1);
+       uiBlockSetFlag(block, UI_BLOCK_LOOP | UI_BLOCK_REDRAW | UI_BLOCK_SEARCH_MENU);
        
        /* preview thumbnails */
        if (template.prv_rows > 0 && template.prv_cols > 0) {
-               int w = 96 * template.prv_cols;
-               int h = 96 * template.prv_rows + 20;
+               int w = 4 * U.widget_unit * template.prv_cols;
+               int h = 4 * U.widget_unit * template.prv_rows + U.widget_unit;
                
                /* fake button, it holds space for search items */
                uiDefBut(block, LABEL, 0, "", 10, 15, w, h, NULL, 0, 0, 0, 0, NULL);
                
-               but = uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, sizeof(search), 10, 0, w, 19, template.prv_rows, template.prv_cols, "");
+               but = uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, sizeof(search), 10, 0, w, UI_UNIT_Y,
+                                    template.prv_rows, template.prv_cols, "");
                uiButSetSearchFunc(but, id_search_cb, &template, id_search_call_cb, idptr.data);
        }
        /* list view */
        else {
-               /* fake button, it holds space for search items */
-               uiDefBut(block, LABEL, 0, "", 10, 15, 150, uiSearchBoxhHeight(), NULL, 0, 0, 0, 0, NULL);
+               const int searchbox_width  = uiSearchBoxWidth();
+               const int searchbox_height = uiSearchBoxHeight();
                
-               but = uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, sizeof(search), 10, 0, 150, 19, 0, 0, "");
+               /* fake button, it holds space for search items */
+               uiDefBut(block, LABEL, 0, "", 10, 15, searchbox_width, searchbox_height, NULL, 0, 0, 0, 0, NULL);
+               but = uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, sizeof(search), 10, 0, searchbox_width, UI_UNIT_Y - 1, 0, 0, "");
                uiButSetSearchFunc(but, id_search_cb, &template, id_search_call_cb, idptr.data);
        }
                
        
-       uiBoundsBlock(block, 6);
-       uiBlockSetDirection(block, UI_DOWN);    
+       uiBoundsBlock(block, 0.3f * U.widget_unit);
+       uiBlockSetDirection(block, UI_DOWN);
        uiEndBlock(C, block);
        
        /* give search-field focus */
@@ -271,7 +281,9 @@ static void template_id_cb(bContext *C, void *arg_litem, void *arg_event)
                                if (id->flag & LIB_FAKEUSER) id_us_plus(id);
                                else id_us_min(id);
                        }
-                       else return;
+                       else {
+                               return;
+                       }
                        break;
                case UI_ID_LOCAL:
                        if (id) {
@@ -313,33 +325,70 @@ static const char *template_id_browse_tip(StructRNA *type)
        if (type) {
                switch (RNA_type_to_ID_code(type)) {
                        case ID_SCE: return N_("Browse Scene to be linked");
-                       case ID_OB: return N_("Browse Object to be linked");
-                       case ID_ME: return N_("Browse Mesh Data to be linked");
-                       case ID_CU: return N_("Browse Curve Data to be linked");
-                       case ID_MB: return N_("Browse Metaball Data to be linked");
-                       case ID_MA: return N_("Browse Material to be linked");
-                       case ID_TE: return N_("Browse Texture to be linked");
-                       case ID_IM: return N_("Browse Image to be linked");
-                       case ID_LT: return N_("Browse Lattice Data to be linked");
-                       case ID_LA: return N_("Browse Lamp Data to be linked");
-                       case ID_CA: return N_("Browse Camera Data to be linked");
-                       case ID_WO: return N_("Browse World Settings to be linked");
+                       case ID_OB:  return N_("Browse Object to be linked");
+                       case ID_ME:  return N_("Browse Mesh Data to be linked");
+                       case ID_CU:  return N_("Browse Curve Data to be linked");
+                       case ID_MB:  return N_("Browse Metaball Data to be linked");
+                       case ID_MA:  return N_("Browse Material to be linked");
+                       case ID_TE:  return N_("Browse Texture to be linked");
+                       case ID_IM:  return N_("Browse Image to be linked");
+                       case ID_LT:  return N_("Browse Lattice Data to be linked");
+                       case ID_LA:  return N_("Browse Lamp Data to be linked");
+                       case ID_CA:  return N_("Browse Camera Data to be linked");
+                       case ID_WO:  return N_("Browse World Settings to be linked");
                        case ID_SCR: return N_("Choose Screen lay-out");
                        case ID_TXT: return N_("Browse Text to be linked");
                        case ID_SPK: return N_("Browse Speaker Data to be linked");
-                       case ID_SO: return N_("Browse Sound to be linked");
-                       case ID_AR: return N_("Browse Armature data to be linked");
-                       case ID_AC: return N_("Browse Action to be linked");
-                       case ID_NT: return N_("Browse Node Tree to be linked");
-                       case ID_BR: return N_("Browse Brush to be linked");
-                       case ID_PA: return N_("Browse Particle System to be linked");
-                       case ID_GD: return N_("Browse Grease Pencil Data to be linked");
+                       case ID_SO:  return N_("Browse Sound to be linked");
+                       case ID_AR:  return N_("Browse Armature data to be linked");
+                       case ID_AC:  return N_("Browse Action to be linked");
+                       case ID_NT:  return N_("Browse Node Tree to be linked");
+                       case ID_BR:  return N_("Browse Brush to be linked");
+                       case ID_PA:  return N_("Browse Particle System to be linked");
+                       case ID_GD:  return N_("Browse Grease Pencil Data to be linked");
                }
        }
        return N_("Browse ID data to be linked");
 }
 
-static void template_ID(bContext *C, uiLayout *layout, TemplateID *template, StructRNA *type, short idcode, int flag, const char *newop, const char *openop, const char *unlinkop)
+/* Return a type-based i18n context, needed e.g. by "New" button.
+ * In most languages, this adjective takes different form based on gender of type name...
+ */
+#ifdef WITH_INTERNATIONAL
+static const char *template_id_context(StructRNA *type)
+{
+       if (type) {
+               switch (RNA_type_to_ID_code(type)) {
+                       case ID_SCE: return BLF_I18NCONTEXT_ID_SCENE;
+                       case ID_OB:  return BLF_I18NCONTEXT_ID_OBJECT;
+                       case ID_ME:  return BLF_I18NCONTEXT_ID_MESH;
+                       case ID_CU:  return BLF_I18NCONTEXT_ID_CURVE;
+                       case ID_MB:  return BLF_I18NCONTEXT_ID_METABALL;
+                       case ID_MA:  return BLF_I18NCONTEXT_ID_MATERIAL;
+                       case ID_TE:  return BLF_I18NCONTEXT_ID_TEXTURE;
+                       case ID_IM:  return BLF_I18NCONTEXT_ID_IMAGE;
+                       case ID_LT:  return BLF_I18NCONTEXT_ID_LATTICE;
+                       case ID_LA:  return BLF_I18NCONTEXT_ID_LAMP;
+                       case ID_CA:  return BLF_I18NCONTEXT_ID_CAMERA;
+                       case ID_WO:  return BLF_I18NCONTEXT_ID_WORLD;
+                       case ID_SCR: return BLF_I18NCONTEXT_ID_SCREEN;
+                       case ID_TXT: return BLF_I18NCONTEXT_ID_TEXT;
+                       case ID_SPK: return BLF_I18NCONTEXT_ID_SPEAKER;
+                       case ID_SO:  return BLF_I18NCONTEXT_ID_SOUND;
+                       case ID_AR:  return BLF_I18NCONTEXT_ID_ARMATURE;
+                       case ID_AC:  return BLF_I18NCONTEXT_ID_ACTION;
+                       case ID_NT:  return BLF_I18NCONTEXT_ID_NODETREE;
+                       case ID_BR:  return BLF_I18NCONTEXT_ID_BRUSH;
+                       case ID_PA:  return BLF_I18NCONTEXT_ID_PARTICLESETTINGS;
+                       case ID_GD:  return BLF_I18NCONTEXT_ID_GPENCIL;
+               }
+       }
+       return BLF_I18NCONTEXT_DEFAULT;
+}
+#endif
+
+static void template_ID(bContext *C, uiLayout *layout, TemplateID *template, StructRNA *type, short idcode, int flag,
+                        const char *newop, const char *openop, const char *unlinkop)
 {
        uiBut *but;
        uiBlock *block;
@@ -360,6 +409,7 @@ static void template_ID(bContext *C, uiLayout *layout, TemplateID *template, Str
                type = idptr.type;
 
        if (flag & UI_ID_PREVIEWS) {
+               template->preview = TRUE;
 
                but = uiDefBlockButN(block, id_search_menu, MEM_dupallocN(template), "", 0, 0, UI_UNIT_X * 6, UI_UNIT_Y * 6,
                                     TIP_(template_id_browse_tip(type)));
@@ -372,7 +422,6 @@ static void template_ID(bContext *C, uiLayout *layout, TemplateID *template, Str
                        uiButSetFlag(but, UI_BUT_DISABLED);
                
                uiLayoutRow(layout, TRUE);
-               template->preview = 1;
        }
        else if (flag & UI_ID_BROWSE) {
                but = uiDefBlockButN(block, id_search_menu, MEM_dupallocN(template), "", 0, 0, UI_UNIT_X * 1.6, UI_UNIT_Y,
@@ -398,19 +447,20 @@ static void template_ID(bContext *C, uiLayout *layout, TemplateID *template, Str
 
                //text_idbutton(id, name);
                name[0] = '\0';
-               but = uiDefButR(block, TEX, 0, name, 0, 0, UI_UNIT_X * 6, UI_UNIT_Y, &idptr, "name", -1, 0, 0, -1, -1, NULL);
+               but = uiDefButR(block, TEX, 0, name, 0, 0, UI_UNIT_X * 6, UI_UNIT_Y,
+                               &idptr, "name", -1, 0, 0, -1, -1, RNA_struct_ui_description(type));
                uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_RENAME));
                if (user_alert) uiButSetFlag(but, UI_BUT_REDALERT);
 
                if (id->lib) {
                        if (id->flag & LIB_INDIRECT) {
-                               but = uiDefIconBut(block, BUT, 0, ICON_LIBRARY_DATA_INDIRECT, 0, 0, UI_UNIT_X, UI_UNIT_Y, NULL, 0, 0, 0, 0,
-                                                  TIP_("Indirect library datablock, cannot change"));
+                               but = uiDefIconBut(block, BUT, 0, ICON_LIBRARY_DATA_INDIRECT, 0, 0, UI_UNIT_X, UI_UNIT_Y,
+                                                  NULL, 0, 0, 0, 0, TIP_("Indirect library datablock, cannot change"));
                                uiButSetFlag(but, UI_BUT_DISABLED);
                        }
                        else {
-                               but = uiDefIconBut(block, BUT, 0, ICON_LIBRARY_DATA_DIRECT, 0, 0, UI_UNIT_X, UI_UNIT_Y, NULL, 0, 0, 0, 0,
-                                                  TIP_("Direct linked library datablock, click to make local"));
+                               but = uiDefIconBut(block, BUT, 0, ICON_LIBRARY_DATA_DIRECT, 0, 0, UI_UNIT_X, UI_UNIT_Y,
+                                                  NULL, 0, 0, 0, 0, TIP_("Direct linked library datablock, click to make local"));
                                if (!id_make_local(id, 1 /* test */) || (idfrom && idfrom->lib))
                                        uiButSetFlag(but, UI_BUT_DISABLED);
                        }
@@ -423,12 +473,20 @@ static void template_ID(bContext *C, uiLayout *layout, TemplateID *template, Str
 
                        BLI_snprintf(numstr, sizeof(numstr), "%d", id->us);
 
-                       but = uiDefBut(block, BUT, 0, numstr, 0, 0, UI_UNIT_X + ((id->us < 10) ? 0 : 10), UI_UNIT_Y, NULL, 0, 0, 0, 0,
+                       but = uiDefBut(block, BUT, 0, numstr, 0, 0, UI_UNIT_X + ((id->us < 10) ? 0 : 10), UI_UNIT_Y,
+                                      NULL, 0, 0, 0, 0,
                                       TIP_("Display 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)
+                       if (/* test only */
+                           (id_copy(id, NULL, 1) == FALSE) ||
+                           (idfrom && idfrom->lib) ||
+                           (editable == FALSE) ||
+                           /* object in editmode - don't change data */
+                           (idfrom && GS(idfrom->name) == ID_OB && (((Object *)idfrom)->mode & OB_MODE_EDIT)))
+                       {
                                uiButSetFlag(but, UI_BUT_DISABLED);
+                       }
                }
        
                if (user_alert) uiButSetFlag(but, UI_BUT_REDALERT);
@@ -441,12 +499,41 @@ static void template_ID(bContext *C, uiLayout *layout, TemplateID *template, Str
        if (flag & UI_ID_ADD_NEW) {
                int w = id ? UI_UNIT_X : (flag & UI_ID_OPEN) ? UI_UNIT_X * 3 : UI_UNIT_X * 6;
                
+               /* i18n markup, does nothing! */
+               BLF_I18N_MSGID_MULTI_CTXT("New", BLF_I18NCONTEXT_DEFAULT,
+                                                BLF_I18NCONTEXT_ID_SCENE,
+                                                BLF_I18NCONTEXT_ID_OBJECT,
+                                                BLF_I18NCONTEXT_ID_MESH,
+                                                BLF_I18NCONTEXT_ID_CURVE,
+                                                BLF_I18NCONTEXT_ID_METABALL,
+                                                BLF_I18NCONTEXT_ID_MATERIAL,
+                                                BLF_I18NCONTEXT_ID_TEXTURE,
+                                                BLF_I18NCONTEXT_ID_IMAGE,
+                                                BLF_I18NCONTEXT_ID_LATTICE,
+                                                BLF_I18NCONTEXT_ID_LAMP,
+                                                BLF_I18NCONTEXT_ID_CAMERA,
+                                                BLF_I18NCONTEXT_ID_WORLD,
+                                                BLF_I18NCONTEXT_ID_SCREEN,
+                                                BLF_I18NCONTEXT_ID_TEXT,
+               );
+               BLF_I18N_MSGID_MULTI_CTXT("New", BLF_I18NCONTEXT_ID_SPEAKER,
+                                                BLF_I18NCONTEXT_ID_SOUND,
+                                                BLF_I18NCONTEXT_ID_ARMATURE,
+                                                BLF_I18NCONTEXT_ID_ACTION,
+                                                BLF_I18NCONTEXT_ID_NODETREE,
+                                                BLF_I18NCONTEXT_ID_BRUSH,
+                                                BLF_I18NCONTEXT_ID_PARTICLESETTINGS,
+                                                BLF_I18NCONTEXT_ID_GPENCIL,
+               );
+               
                if (newop) {
-                       but = uiDefIconTextButO(block, BUT, newop, WM_OP_INVOKE_DEFAULT, ICON_ZOOMIN, (id) ? "" : IFACE_("New"), 0, 0, w, UI_UNIT_Y, NULL);
+                       but = uiDefIconTextButO(block, BUT, newop, WM_OP_INVOKE_DEFAULT, ICON_ZOOMIN,
+                                               (id) ? "" : CTX_IFACE_(template_id_context(type), "New"), 0, 0, w, UI_UNIT_Y, NULL);
                        uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_ADD_NEW));
                }
                else {
-                       but = uiDefIconTextBut(block, BUT, 0, ICON_ZOOMIN, (id) ? "" : IFACE_("New"), 0, 0, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, NULL);
+                       but = uiDefIconTextBut(block, BUT, 0, ICON_ZOOMIN, (id) ? "" : CTX_IFACE_(template_id_context(type), "New"),
+                                              0, 0, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, NULL);
                        uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_ADD_NEW));
                }
 
@@ -454,15 +541,28 @@ static void template_ID(bContext *C, uiLayout *layout, TemplateID *template, Str
                        uiButSetFlag(but, UI_BUT_DISABLED);
        }
 
-       if (flag & UI_ID_OPEN) {
+       /* Due to space limit in UI - skip the "open" icon for packed data, and allow to unpack.
+          Only for images, sound and fonts */
+       if (id && BKE_pack_check(id)) {
+               but = uiDefIconButO(block, BUT, "FILE_OT_unpack_item", WM_OP_INVOKE_REGION_WIN, ICON_PACKAGE, 0, 0,
+                                   UI_UNIT_X, UI_UNIT_Y, TIP_("Packed File, click to unpack"));
+               uiButGetOperatorPtrRNA(but);
+               
+               RNA_string_set(but->opptr, "id_name", id->name + 2);
+               RNA_int_set(but->opptr, "id_type", GS(id->name));
+               
+       }
+       else if (flag & UI_ID_OPEN) {
                int w = id ? UI_UNIT_X : (flag & UI_ID_ADD_NEW) ? UI_UNIT_X * 3 : UI_UNIT_X * 6;
                
                if (openop) {
-                       but = uiDefIconTextButO(block, BUT, openop, WM_OP_INVOKE_DEFAULT, ICON_FILESEL, (id) ? "" : IFACE_("Open"), 0, 0, w, UI_UNIT_Y, NULL);
+                       but = uiDefIconTextButO(block, BUT, openop, WM_OP_INVOKE_DEFAULT, ICON_FILESEL, (id) ? "" : IFACE_("Open"),
+                                               0, 0, w, UI_UNIT_Y, NULL);
                        uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_OPEN));
                }
                else {
-                       but = uiDefIconTextBut(block, BUT, 0, ICON_FILESEL, (id) ? "" : IFACE_("Open"), 0, 0, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, NULL);
+                       but = uiDefIconTextBut(block, BUT, 0, ICON_FILESEL, (id) ? "" : IFACE_("Open"), 0, 0, w, UI_UNIT_Y,
+                                              NULL, 0, 0, 0, 0, NULL);
                        uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_OPEN));
                }
 
@@ -479,7 +579,8 @@ static void template_ID(bContext *C, uiLayout *layout, TemplateID *template, Str
                }
                else {
                        but = uiDefIconBut(block, BUT, 0, ICON_X, 0, 0, UI_UNIT_X, UI_UNIT_Y, NULL, 0, 0, 0, 0,
-                                          TIP_("Unlink datablock. Shift + Click to set users to zero, data will then not be saved"));
+                                          TIP_("Unlink datablock "
+                                               "(Shift + Click to set users to zero, data will then not be saved)"));
                        uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_DELETE));
 
                        if (RNA_property_flag(template->prop) & PROP_NEVER_NULL)
@@ -496,7 +597,8 @@ static void template_ID(bContext *C, uiLayout *layout, TemplateID *template, Str
        uiBlockEndAlign(block);
 }
 
-static void ui_template_id(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, const char *newop, const char *openop, const char *unlinkop, int flag, int prv_rows, int prv_cols)
+static void ui_template_id(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, const char *newop,
+                           const char *openop, const char *unlinkop, int flag, int prv_rows, int prv_cols)
 {
        TemplateID *template;
        PropertyRNA *prop;
@@ -536,19 +638,24 @@ static void ui_template_id(uiLayout *layout, bContext *C, PointerRNA *ptr, const
        MEM_freeN(template);
 }
 
-void uiTemplateID(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, const char *newop, const char *openop, const char *unlinkop)
+void uiTemplateID(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, const char *newop,
+                  const char *openop, const char *unlinkop)
 {
-       ui_template_id(layout, C, ptr, propname, newop, openop, unlinkop, UI_ID_BROWSE | UI_ID_RENAME | UI_ID_DELETE, 0, 0);
+       ui_template_id(layout, C, ptr, propname, newop, openop, unlinkop,
+                      UI_ID_BROWSE | UI_ID_RENAME | UI_ID_DELETE, 0, 0);
 }
 
-void uiTemplateIDBrowse(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, const char *newop, const char *openop, const char *unlinkop)
+void uiTemplateIDBrowse(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, const char *newop,
+                        const char *openop, const char *unlinkop)
 {
        ui_template_id(layout, C, ptr, propname, newop, openop, unlinkop, UI_ID_BROWSE | UI_ID_RENAME, 0, 0);
 }
 
-void uiTemplateIDPreview(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, const char *newop, const char *openop, const char *unlinkop, int rows, int cols)
+void uiTemplateIDPreview(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, const char *newop,
+                         const char *openop, const char *unlinkop, int rows, int cols)
 {
-       ui_template_id(layout, C, ptr, propname, newop, openop, unlinkop, UI_ID_BROWSE | UI_ID_RENAME | UI_ID_DELETE | UI_ID_PREVIEWS, rows, cols);
+       ui_template_id(layout, C, ptr, propname, newop, openop, unlinkop,
+                      UI_ID_BROWSE | UI_ID_RENAME | UI_ID_DELETE | UI_ID_PREVIEWS, rows, cols);
 }
 
 /************************ ID Chooser Template ***************************/
@@ -558,7 +665,8 @@ void uiTemplateIDPreview(uiLayout *layout, bContext *C, PointerRNA *ptr, const c
  * - propname: property identifier for property that ID-pointer gets stored to
  * - proptypename: property identifier for property used to determine the type of ID-pointer that can be used
  */
-void uiTemplateAnyID(uiLayout *layout, PointerRNA *ptr, const char *propname, const char *proptypename, const char *text)
+void uiTemplateAnyID(uiLayout *layout, PointerRNA *ptr, const char *propname, const char *proptypename,
+                     const char *text)
 {
        PropertyRNA *propID, *propType;
        uiLayout *row;
@@ -571,7 +679,7 @@ void uiTemplateAnyID(uiLayout *layout, PointerRNA *ptr, const char *propname, co
                RNA_warning("pointer property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
                return;
        }
-       if (!propType || RNA_property_type(propType) != PROP_ENUM) { 
+       if (!propType || RNA_property_type(propType) != PROP_ENUM) {
                RNA_warning("pointer-type property not found: %s.%s", RNA_struct_identifier(ptr->type), proptypename);
                return;
        }
@@ -585,7 +693,7 @@ void uiTemplateAnyID(uiLayout *layout, PointerRNA *ptr, const char *propname, co
                        uiItemL(row, text, ICON_NONE);
        }
        else
-               uiItemL(row, "ID-Block:", ICON_NONE);
+               uiItemL(row, IFACE_("ID-Block:"), ICON_NONE);
        
        /* ID-Type Selector - just have a menu of icons */
        /* FIXME: the icon-only setting doesn't work when we supply a blank name */
@@ -605,7 +713,8 @@ void uiTemplateAnyID(uiLayout *layout, PointerRNA *ptr, const char *propname, co
  * - propname: property identifier for property that path gets stored to
  * - root_ptr: struct that path gets built from
  */
-void uiTemplatePathBuilder(uiLayout *layout, PointerRNA *ptr, const char *propname, PointerRNA *UNUSED(root_ptr), const char *text)
+void uiTemplatePathBuilder(uiLayout *layout, PointerRNA *ptr, const char *propname, PointerRNA *UNUSED(root_ptr),
+                           const char *text)
 {
        PropertyRNA *propPath;
        uiLayout *row;
@@ -628,22 +737,7 @@ void uiTemplatePathBuilder(uiLayout *layout, PointerRNA *ptr, const char *propna
 
 /************************ Modifier Template *************************/
 
-#define ERROR_LIBDATA_MESSAGE "Can't edit external libdata"
-
-#include <string.h>
-
-#include "DNA_object_force.h"
-
-#include "BKE_depsgraph.h"
-#include "BKE_modifier.h"
-#include "BKE_particle.h"
-
-#include "ED_util.h"
-
-#include "BLI_math.h"
-#include "BLI_listbase.h"
-
-#include "ED_object.h"
+#define ERROR_LIBDATA_MESSAGE IFACE_("Can't edit external libdata")
 
 static void modifiers_setOnCage(bContext *C, void *ob_v, void *md_v)
 {
@@ -698,7 +792,7 @@ static int modifier_can_delete(ModifierData *md)
        return 1;
 }
 
-/* Check wheter Modifier is a simulation or not, this is used for switching to the physics/particles context tab */
+/* Check whether Modifier is a simulation or not, this is used for switching to the physics/particles context tab */
 static int modifier_is_simulation(ModifierData *md)
 {
        /* Physic Tab */
@@ -743,8 +837,8 @@ static uiLayout *draw_modifier(uiLayout *layout, Scene *scene, Object *ob,
                block = uiLayoutGetBlock(row);
                /* VIRTUAL MODIFIER */
                /* XXX this is not used now, since these cannot be accessed via RNA */
-               BLI_snprintf(str, sizeof(str), "%s parent deform", md->name);
-               uiDefBut(block, LABEL, 0, str, 0, 0, 185, UI_UNIT_Y, NULL, 0.0, 0.0, 0.0, 0.0, "Modifier name"); 
+               BLI_snprintf(str, sizeof(str), IFACE_("%s parent deform"), md->name);
+               uiDefBut(block, LABEL, 0, str, 0, 0, 185, UI_UNIT_Y, NULL, 0.0, 0.0, 0.0, 0.0, TIP_("Modifier name"));
                
                but = uiDefBut(block, BUT, 0, IFACE_("Make Real"), 0, 0, 80, 16, NULL, 0.0, 0.0, 0.0, 0.0,
                               TIP_("Convert virtual modifier to a real modifier"));
@@ -770,7 +864,7 @@ static uiLayout *draw_modifier(uiLayout *layout, Scene *scene, Object *ob,
                uiBlockBeginAlign(block);
                /* Softbody not allowed in this situation, enforce! */
                if (((md->type != eModifierType_Softbody && md->type != eModifierType_Collision) || !(ob->pd && ob->pd->deflect)) &&
-                    (md->type != eModifierType_Surface) )
+                   (md->type != eModifierType_Surface) )
                {
                        uiItemR(row, &ptr, "show_render", 0, "", ICON_NONE);
                        uiItemR(row, &ptr, "show_viewport", 0, "", ICON_NONE);
@@ -782,7 +876,8 @@ static uiLayout *draw_modifier(uiLayout *layout, Scene *scene, Object *ob,
                if (ob->type == OB_MESH) {
                        if (modifier_couldBeCage(scene, md) && (index <= lastCageIndex)) {
                                /* -- convert to rna ? */
-                               but = uiDefIconButBitI(block, TOG, eModifierMode_OnCage, 0, ICON_MESH_DATA, 0, 0, UI_UNIT_X - 2, UI_UNIT_Y, &md->mode, 0.0, 0.0, 0.0, 0.0,
+                               but = uiDefIconButBitI(block, TOG, eModifierMode_OnCage, 0, ICON_MESH_DATA, 0, 0,
+                                                      UI_UNIT_X - 2, UI_UNIT_Y, &md->mode, 0.0, 0.0, 0.0, 0.0,
                                                       TIP_("Apply modifier to editing cage during Edit mode"));
                                if (index < cageIndex)
                                        uiButSetFlag(but, UI_BUT_DISABLED);
@@ -793,7 +888,8 @@ static uiLayout *draw_modifier(uiLayout *layout, Scene *scene, Object *ob,
 
                                /* place holder button */
                                uiBlockSetEmboss(block, UI_EMBOSSN);
-                               but = uiDefIconBut(block, BUT, 0, ICON_NONE, 0, 0, UI_UNIT_X - 2, UI_UNIT_Y, NULL, 0.0, 0.0, 0.0, 0.0, NULL);
+                               but = uiDefIconBut(block, BUT, 0, ICON_NONE, 0, 0, UI_UNIT_X - 2, UI_UNIT_Y,
+                                                  NULL, 0.0, 0.0, 0.0, 0.0, NULL);
                                uiButSetFlag(but, UI_BUT_DISABLED);
                                uiBlockSetEmboss(block, UI_EMBOSS);
                        }
@@ -803,7 +899,8 @@ static uiLayout *draw_modifier(uiLayout *layout, Scene *scene, Object *ob,
                        if (ELEM3(md->type, eModifierType_Hook, eModifierType_Softbody, eModifierType_MeshDeform)) {
                                /* add disabled pre-tessellated button, so users could have
                                 * message for this modifiers */
-                               but = uiDefIconButBitI(block, TOG, eModifierMode_ApplyOnSpline, 0, ICON_SURFACE_DATA, 0, 0, UI_UNIT_X - 2, UI_UNIT_Y, &md->mode, 0.0, 0.0, 0.0, 0.0,
+                               but = uiDefIconButBitI(block, TOG, eModifierMode_ApplyOnSpline, 0, ICON_SURFACE_DATA, 0, 0,
+                                                      UI_UNIT_X - 2, UI_UNIT_Y, &md->mode, 0.0, 0.0, 0.0, 0.0,
                                                       TIP_("This modifier could be applied on splines' points only"));
                                uiButSetFlag(but, UI_BUT_DISABLED);
                        }
@@ -848,24 +945,34 @@ static uiLayout *draw_modifier(uiLayout *layout, Scene *scene, Object *ob,
                                
                                if (!(ob->mode & OB_MODE_PARTICLE_EDIT) && psys->pathcache) {
                                        if (ELEM(psys->part->ren_as, PART_DRAW_GR, PART_DRAW_OB))
-                                               uiItemO(row, "Convert", ICON_NONE, "OBJECT_OT_duplicates_make_real");
+                                               uiItemO(row, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Convert"), ICON_NONE,
+                                                       "OBJECT_OT_duplicates_make_real");
                                        else if (psys->part->ren_as == PART_DRAW_PATH)
-                                               uiItemO(row, "Convert", ICON_NONE, "OBJECT_OT_modifier_convert");
+                                               uiItemO(row, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Convert"), ICON_NONE,
+                                                       "OBJECT_OT_modifier_convert");
                                }
                        }
                        else {
                                uiLayoutSetOperatorContext(row, WM_OP_INVOKE_DEFAULT);
-                               uiItemEnumO(row, "OBJECT_OT_modifier_apply", IFACE_("Apply"), 0, "apply_as", MODIFIER_APPLY_DATA);
+                               uiItemEnumO(row, "OBJECT_OT_modifier_apply", CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Apply"),
+                                           0, "apply_as", MODIFIER_APPLY_DATA);
                                
-                               if (modifier_sameTopology(md) && !modifier_nonGeometrical(md))
-                                       uiItemEnumO(row, "OBJECT_OT_modifier_apply", IFACE_("Apply as Shape Key"), 0, "apply_as", MODIFIER_APPLY_SHAPE);
+                               if (modifier_isSameTopology(md) && !modifier_isNonGeometrical(md)) {
+                                       uiItemEnumO(row, "OBJECT_OT_modifier_apply",
+                                                   CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Apply as Shape Key"),
+                                                   0, "apply_as", MODIFIER_APPLY_SHAPE);
+                               }
                        }
                        
                        uiBlockClearButLock(block);
                        uiBlockSetButLock(block, ob && ob->id.lib, ERROR_LIBDATA_MESSAGE);
                        
-                       if (!ELEM5(md->type, eModifierType_Fluidsim, eModifierType_Softbody, eModifierType_ParticleSystem, eModifierType_Cloth, eModifierType_Smoke))
-                               uiItemO(row, IFACE_("Copy"), ICON_NONE, "OBJECT_OT_modifier_copy");
+                       if (!ELEM5(md->type, eModifierType_Fluidsim, eModifierType_Softbody, eModifierType_ParticleSystem,
+                                  eModifierType_Cloth, eModifierType_Smoke))
+                       {
+                               uiItemO(row, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Copy"), ICON_NONE,
+                                       "OBJECT_OT_modifier_copy");
+                       }
                }
                
                /* result is the layout block inside the box, that we return so that modifier settings can be drawn */
@@ -929,28 +1036,25 @@ uiLayout *uiTemplateModifier(uiLayout *layout, bContext *C, PointerRNA *ptr)
 #include "BKE_action.h"
 #include "BKE_constraint.h"
 
-#define REDRAWIPO                   1
-#define REDRAWNLA                   2
-#define REDRAWBUTSOBJECT            3
-#define REDRAWACTION                4
 #define B_CONSTRAINT_TEST           5
-#define B_CONSTRAINT_CHANGETARGET   6
-#define REMAKEIPO                   8
-#define B_DIFF                      9
+// #define B_CONSTRAINT_CHANGETARGET   6
 
 static void do_constraint_panels(bContext *C, void *ob_pt, int event)
 {
-       Main *bmain = CTX_data_main(C);
-       Scene *scene = CTX_data_scene(C);
        Object *ob = (Object *)ob_pt;
 
        switch (event) {
                case B_CONSTRAINT_TEST:
                        break; /* no handling */
+#if 0  /* UNUSED */
                case B_CONSTRAINT_CHANGETARGET:
+               {
+                       Main *bmain = CTX_data_main(C);
                        if (ob->pose) ob->pose->flag |= POSE_RECALC;  /* checks & sorts pose channels */
-                       DAG_scene_sort(bmain, scene);
+                       DAG_relations_tag_update(bmain);
                        break;
+               }
+#endif
                default:
                        break;
        }
@@ -985,16 +1089,16 @@ static uiLayout *draw_constraint(uiLayout *layout, Object *ob, bConstraint *con)
        // int rb_col; // UNUSED
 
        /* get constraint typeinfo */
-       cti = constraint_get_typeinfo(con);
+       cti = BKE_constraint_get_typeinfo(con);
        if (cti == NULL) {
                /* exception for 'Null' constraint - it doesn't have constraint typeinfo! */
-               BLI_strncpy(typestr, (con->type == CONSTRAINT_TYPE_NULL) ? "Null" : "Unknown", sizeof(typestr));
+               BLI_strncpy(typestr, (con->type == CONSTRAINT_TYPE_NULL) ? IFACE_("Null") : IFACE_("Unknown"), sizeof(typestr));
        }
        else
-               BLI_strncpy(typestr, cti->name, sizeof(typestr));
+               BLI_strncpy(typestr, IFACE_(cti->name), sizeof(typestr));
                
        /* determine whether constraint is proxy protected or not */
-       if (proxylocked_constraints_owner(ob, pchan))
+       if (BKE_proxylocked_constraints_owner(ob, pchan))
                proxy_protected = (con->flag & CONSTRAINT_PROXY_LOCAL) == 0;
        else
                proxy_protected = 0;
@@ -1039,8 +1143,10 @@ static uiLayout *draw_constraint(uiLayout *layout, Object *ob, bConstraint *con)
                uiBlockSetEmboss(block, UI_EMBOSSN);
                
                /* draw a ghost icon (for proxy) and also a lock beside it, to show that constraint is "proxy locked" */
-               uiDefIconBut(block, BUT, B_CONSTRAINT_TEST, ICON_GHOST, xco + 244, yco, 19, 19, NULL, 0.0, 0.0, 0.0, 0.0, TIP_("Proxy Protected"));
-               uiDefIconBut(block, BUT, B_CONSTRAINT_TEST, ICON_LOCKED, xco + 262, yco, 19, 19, NULL, 0.0, 0.0, 0.0, 0.0, TIP_("Proxy Protected"));
+               uiDefIconBut(block, BUT, B_CONSTRAINT_TEST, ICON_GHOST, xco + 244, yco, 19, 19,
+                            NULL, 0.0, 0.0, 0.0, 0.0, TIP_("Proxy Protected"));
+               uiDefIconBut(block, BUT, B_CONSTRAINT_TEST, ICON_LOCKED, xco + 262, yco, 19, 19,
+                            NULL, 0.0, 0.0, 0.0, 0.0, TIP_("Proxy Protected"));
                
                uiBlockSetEmboss(block, UI_EMBOSS);
        }
@@ -1054,7 +1160,7 @@ static uiLayout *draw_constraint(uiLayout *layout, Object *ob, bConstraint *con)
                 *
                 *  Up/Down buttons should only be shown (or not grayed - todo) if they serve some purpose.
                 */
-               if (proxylocked_constraints_owner(ob, pchan)) {
+               if (BKE_proxylocked_constraints_owner(ob, pchan)) {
                        if (con->prev) {
                                prev_proxylock = (con->prev->flag & CONSTRAINT_PROXY_LOCAL) ? 0 : 1;
                        }
@@ -1069,7 +1175,8 @@ static uiLayout *draw_constraint(uiLayout *layout, Object *ob, bConstraint *con)
                
                /* enabled */
                uiBlockSetEmboss(block, UI_EMBOSSN);
-               uiItemR(row, &ptr, "mute", 0, "", (con->flag & CONSTRAINT_OFF) ? ICON_RESTRICT_VIEW_ON : ICON_RESTRICT_VIEW_OFF);
+               uiItemR(row, &ptr, "mute", 0, "",
+                       (con->flag & CONSTRAINT_OFF) ? ICON_RESTRICT_VIEW_ON : ICON_RESTRICT_VIEW_OFF);
                uiBlockSetEmboss(block, UI_EMBOSS);
                
                uiLayoutSetOperatorContext(row, WM_OP_INVOKE_DEFAULT);
@@ -1093,7 +1200,7 @@ static uiLayout *draw_constraint(uiLayout *layout, Object *ob, bConstraint *con)
 
        /* Set but-locks for protected settings (magic numbers are used here!) */
        if (proxy_protected)
-               uiBlockSetButLock(block, 1, "Cannot edit Proxy-Protected Constraint");
+               uiBlockSetButLock(block, 1, IFACE_("Cannot edit Proxy-Protected Constraint"));
 
        /* Draw constraint data */
        if ((con->flag & CONSTRAINT_EXPAND) == 0) {
@@ -1214,7 +1321,7 @@ void uiTemplatePreview(uiLayout *layout, ID *id, int show_buttons, ID *parent, M
                        else ma = (Material *)pparent;
                        
                        /* Create RNA Pointer */
-                       RNA_pointer_create(id, &RNA_Material, ma, &material_ptr);
+                       RNA_pointer_create(&ma->id, &RNA_Material, ma, &material_ptr);
 
                        col = uiLayoutColumn(row, TRUE);
                        uiLayoutSetScaleX(col, 1.5);
@@ -1226,14 +1333,22 @@ void uiTemplatePreview(uiLayout *layout, ID *id, int show_buttons, ID *parent, M
                        RNA_pointer_create(id, &RNA_Texture, tex, &texture_ptr);
                        
                        uiLayoutRow(layout, TRUE);
-                       uiDefButS(block, ROW, B_MATPRV, IFACE_("Texture"),  0, 0, UI_UNIT_X * 10, UI_UNIT_Y, pr_texture, 10, TEX_PR_TEXTURE, 0, 0, "");
-                       if (GS(parent->name) == ID_MA)
-                               uiDefButS(block, ROW, B_MATPRV, IFACE_("Material"),  0, 0, UI_UNIT_X * 10, UI_UNIT_Y, pr_texture, 10, TEX_PR_OTHER, 0, 0, "");
-                       else if (GS(parent->name) == ID_LA)
-                               uiDefButS(block, ROW, B_MATPRV, IFACE_("Lamp"),  0, 0, UI_UNIT_X * 10, UI_UNIT_Y, pr_texture, 10, TEX_PR_OTHER, 0, 0, "");
-                       else if (GS(parent->name) == ID_WO)
-                               uiDefButS(block, ROW, B_MATPRV, IFACE_("World"),  0, 0, UI_UNIT_X * 10, UI_UNIT_Y, pr_texture, 10, TEX_PR_OTHER, 0, 0, "");
-                       uiDefButS(block, ROW, B_MATPRV, IFACE_("Both"),  0, 0, UI_UNIT_X * 10, UI_UNIT_Y, pr_texture, 10, TEX_PR_BOTH, 0, 0, "");
+                       uiDefButS(block, ROW, B_MATPRV, IFACE_("Texture"),  0, 0, UI_UNIT_X * 10, UI_UNIT_Y,
+                                 pr_texture, 10, TEX_PR_TEXTURE, 0, 0, "");
+                       if (GS(parent->name) == ID_MA) {
+                               uiDefButS(block, ROW, B_MATPRV, IFACE_("Material"),  0, 0, UI_UNIT_X * 10, UI_UNIT_Y,
+                                         pr_texture, 10, TEX_PR_OTHER, 0, 0, "");
+                       }
+                       else if (GS(parent->name) == ID_LA) {
+                               uiDefButS(block, ROW, B_MATPRV, IFACE_("Lamp"),  0, 0, UI_UNIT_X * 10, UI_UNIT_Y,
+                                         pr_texture, 10, TEX_PR_OTHER, 0, 0, "");
+                       }
+                       else if (GS(parent->name) == ID_WO) {
+                               uiDefButS(block, ROW, B_MATPRV, IFACE_("World"),  0, 0, UI_UNIT_X * 10, UI_UNIT_Y,
+                                         pr_texture, 10, TEX_PR_OTHER, 0, 0, "");
+                       }
+                       uiDefButS(block, ROW, B_MATPRV, IFACE_("Both"),  0, 0, UI_UNIT_X * 10, UI_UNIT_Y,
+                                 pr_texture, 10, TEX_PR_BOTH, 0, 0, "");
                        
                        /* Alpha button for texture preview */
                        if (*pr_texture != TEX_PR_OTHER) {
@@ -1262,8 +1377,6 @@ static void rna_update_cb(bContext *C, void *arg_cb, void *UNUSED(arg))
        RNA_property_update(C, &cb->ptr, cb->prop);
 }
 
-#define B_BANDCOL 1
-
 static void colorband_add_cb(bContext *C, void *cb_v, void *coba_v)
 {
        ColorBand *coba = coba_v;
@@ -1276,7 +1389,7 @@ static void colorband_add_cb(bContext *C, void *cb_v, void *coba_v)
 
        if (colorband_element_add(coba, pos)) {
                rna_update_cb(C, cb_v, NULL);
-               ED_undo_push(C, "Add colorband");       
+               ED_undo_push(C, "Add colorband");
        }
 }
 
@@ -1325,7 +1438,8 @@ static void colorband_update_cb(bContext *UNUSED(C), void *bt_v, void *coba_v)
 }
 
 /* offset aligns from bottom, standard width 300, height 115 */
-static void colorband_buttons_large(uiLayout *layout, uiBlock *block, ColorBand *coba, int xoffs, int yoffs, RNAUpdateCb *cb)
+static void colorband_buttons_large(uiLayout *layout, uiBlock *block, ColorBand *coba,
+                                    int xoffs, int yoffs, RNAUpdateCb *cb)
 {
        uiBut *bt;
        uiLayout *row;
@@ -1333,7 +1447,7 @@ static void colorband_buttons_large(uiLayout *layout, uiBlock *block, ColorBand
        const int line2_y = yoffs + 65;
 
        if (coba == NULL) return;
-
+       
        bt = uiDefBut(block, BUT, 0, IFACE_("Add"), 0 + xoffs, line1_y, 40, UI_UNIT_Y, NULL, 0, 0, 0, 0,
                      TIP_("Add a new color stop to the colorband"));
        uiButSetNFunc(bt, colorband_add_cb, MEM_dupallocN(cb), coba);
@@ -1344,13 +1458,16 @@ static void colorband_buttons_large(uiLayout *layout, uiBlock *block, ColorBand
 
 
        /* XXX, todo for later - convert to operator - campbell */
-       bt = uiDefBut(block, BUT, 0, "F",        95 + xoffs, line1_y, 20, UI_UNIT_Y, NULL, 0, 0, 0, 0, TIP_("Flip colorband"));
+       bt = uiDefBut(block, BUT, 0, "F",        95 + xoffs, line1_y, 20, UI_UNIT_Y,
+                     NULL, 0, 0, 0, 0, TIP_("Flip colorband"));
        uiButSetNFunc(bt, colorband_flip_cb, MEM_dupallocN(cb), coba);
 
-       uiDefButS(block, NUM, 0,        "",             120 + xoffs, line1_y, 80, UI_UNIT_Y, &coba->cur, 0.0, (float)(MAX2(0, coba->tot - 1)), 0, 0, TIP_("Choose active color stop"));
+       uiDefButS(block, NUM, 0, "", 120 + xoffs, line1_y, 80, UI_UNIT_Y, &coba->cur, 0.0, (float)(MAX2(0, coba->tot - 1)),
+                 0, 0, TIP_("Choose active color stop"));
 
-       bt = uiDefButS(block, MENU, 0,       IFACE_("Interpolation %t|Ease %x1|Cardinal %x3|Linear %x0|B-Spline %x2|Constant %x4"),
-                      210 + xoffs, line1_y, 90, UI_UNIT_Y,      &coba->ipotype, 0.0, 0.0, 0, 0, TIP_("Set interpolation between color stops"));
+       bt = uiDefButS(block, MENU, 0, IFACE_("Interpolation %t|Ease %x1|Cardinal %x3|Linear %x0|B-Spline %x2|Constant %x4"),
+                      210 + xoffs, line1_y, 90, UI_UNIT_Y, &coba->ipotype, 0.0, 0.0, 0, 0,
+                      TIP_("Set interpolation between color stops"));
        uiButSetNFunc(bt, rna_update_cb, MEM_dupallocN(cb), NULL);
        uiBlockEndAlign(block);
 
@@ -1367,7 +1484,7 @@ static void colorband_buttons_large(uiLayout *layout, uiBlock *block, ColorBand
                RNA_pointer_create(cb->ptr.id.data, &RNA_ColorRampElement, cbd, &ptr);
                row = uiLayoutRow(layout, FALSE);
 
-               uiItemR(row, &ptr, "position", 0, "Pos", ICON_NONE);
+               uiItemR(row, &ptr, "position", 0, IFACE_("Pos"), ICON_NONE);
                bt = block->buttons.last;
                uiButSetFunc(bt, colorband_update_cb, bt, coba);
 
@@ -1386,10 +1503,11 @@ static void colorband_buttons_small(uiLayout *layout, uiBlock *block, ColorBand
        bt = uiDefBut(block, BUT, 0, IFACE_("Add"), xs, butr->ymin + UI_UNIT_Y, 2.0f * unit, UI_UNIT_Y, NULL, 0, 0, 0, 0,
                      TIP_("Add a new color stop to the colorband"));
        uiButSetNFunc(bt, colorband_add_cb, MEM_dupallocN(cb), coba);
-       bt = uiDefBut(block, BUT, 0, IFACE_("Delete"), xs + 2.0f * unit, butr->ymin + UI_UNIT_Y, 1.5f * unit, UI_UNIT_Y,    NULL, 0, 0, 0, 0,
-                     TIP_("Delete the active position"));
+       bt = uiDefBut(block, BUT, 0, IFACE_("Delete"), xs + 2.0f * unit, butr->ymin + UI_UNIT_Y, 1.5f * unit, UI_UNIT_Y,
+                     NULL, 0, 0, 0, 0, TIP_("Delete the active position"));
        uiButSetNFunc(bt, colorband_del_cb, MEM_dupallocN(cb), coba);
-       bt = uiDefBut(block, BUT, 0, "F",        xs + 3.5f * unit, butr->ymin + UI_UNIT_Y, 0.5f * unit, UI_UNIT_Y,  NULL, 0, 0, 0, 0, TIP_("Flip the color ramp"));
+       bt = uiDefBut(block, BUT, 0, "F", xs + 3.5f * unit, butr->ymin + UI_UNIT_Y, 0.5f * unit, UI_UNIT_Y,
+                     NULL, 0, 0, 0, 0, TIP_("Flip the color ramp"));
        uiButSetNFunc(bt, colorband_flip_cb, MEM_dupallocN(cb), coba);
        uiBlockEndAlign(block);
 
@@ -1400,8 +1518,8 @@ static void colorband_buttons_small(uiLayout *layout, uiBlock *block, ColorBand
                uiItemR(layout, &ptr, "color", 0, "", ICON_NONE);
        }
 
-       bt = uiDefButS(block, MENU, 0, TIP_("Interpolation %t|Ease %x1|Cardinal %x3|Linear %x0|B-Spline %x2|Constant %x4"),
-                      xs + 10.0f * unit, butr->ymin + UI_UNIT_Y, unit * 4, UI_UNIT_Y,     &coba->ipotype, 0.0, 0.0, 0, 0,
+       bt = uiDefButS(block, MENU, 0, IFACE_("Interpolation %t|Ease %x1|Cardinal %x3|Linear %x0|B-Spline %x2|Constant %x4"),
+                      xs + 10.0f * unit, butr->ymin + UI_UNIT_Y, unit * 4, UI_UNIT_Y, &coba->ipotype, 0.0, 0.0, 0, 0,
                       TIP_("Set interpolation between color stops"));
        uiButSetNFunc(bt, rna_update_cb, MEM_dupallocN(cb), NULL);
 
@@ -1411,7 +1529,8 @@ static void colorband_buttons_small(uiLayout *layout, uiBlock *block, ColorBand
        uiBlockEndAlign(block);
 }
 
-static void colorband_buttons_layout(uiLayout *layout, uiBlock *block, ColorBand *coba, rctf *butr, int small, RNAUpdateCb *cb)
+static void colorband_buttons_layout(uiLayout *layout, uiBlock *block, ColorBand *coba, rctf *butr,
+                                     int small, RNAUpdateCb *cb)
 {
        if (small)
                colorband_buttons_small(layout, block, coba, butr, cb);
@@ -1438,8 +1557,8 @@ void uiTemplateColorRamp(uiLayout *layout, PointerRNA *ptr, const char *propname
        cb->ptr = *ptr;
        cb->prop = prop;
 
-       rect.xmin = 0; rect.xmax = 200;
-       rect.ymin = 0; rect.ymax = 190;
+       rect.xmin = 0; rect.xmax = 10.0f * UI_UNIT_X;
+       rect.ymin = 0; rect.ymax = 19.5f * UI_UNIT_X;
 
        block = uiLayoutAbsoluteBlock(layout);
        colorband_buttons_layout(layout, block, cptr.data, &rect, !expand, cb);
@@ -1447,6 +1566,90 @@ void uiTemplateColorRamp(uiLayout *layout, PointerRNA *ptr, const char *propname
        MEM_freeN(cb);
 }
 
+
+/********************* Icon viewer Template ************************/
+
+/* ID Search browse menu, open */
+static uiBlock *icon_view_menu(bContext *C, ARegion *ar, void *arg_litem)
+{
+       static RNAUpdateCb cb;
+       uiBlock *block;
+       uiBut *but;
+       int icon;
+       EnumPropertyItem *item;
+       int a, free;
+
+       /* arg_litem is malloced, can be freed by parent button */
+       cb = *((RNAUpdateCb *)arg_litem);
+       
+       /* unused */
+       // icon = RNA_property_enum_get(&cb.ptr, cb.prop);
+       
+       block = uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
+       uiBlockSetFlag(block, UI_BLOCK_LOOP | UI_BLOCK_REDRAW);
+       
+       
+       RNA_property_enum_items(C, &cb.ptr, cb.prop, &item, NULL, &free);
+       
+       for (a = 0; item[a].identifier; a++) {
+               int x, y;
+               
+               /* XXX hardcoded size to 5 x unit */
+               x = (a % 8) * UI_UNIT_X * 5;
+               y = (a / 8) * UI_UNIT_X * 5;
+               
+               icon = item[a].icon;
+               but = uiDefIconButR_prop(block, ROW, 0, icon, x, y, UI_UNIT_X * 5, UI_UNIT_Y * 5, &cb.ptr, cb.prop, -1, 0, icon, -1, -1, NULL);
+               uiButSetFlag(but, UI_HAS_ICON | UI_ICON_PREVIEW);
+       }
+
+       uiBoundsBlock(block, 0.3f * U.widget_unit);
+       uiBlockSetDirection(block, UI_TOP);
+       uiEndBlock(C, block);
+               
+       if (free) {
+               MEM_freeN(item);
+       }
+       
+       return block;
+}
+
+void uiTemplateIconView(uiLayout *layout, PointerRNA *ptr, const char *propname)
+{
+       PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
+       RNAUpdateCb *cb;
+       uiBlock *block;
+       uiBut *but;
+//     rctf rect;  /* UNUSED */
+       int icon;
+       
+       if (!prop || RNA_property_type(prop) != PROP_ENUM)
+               return;
+       
+       icon = RNA_property_enum_get(ptr, prop);
+       
+       cb = MEM_callocN(sizeof(RNAUpdateCb), "RNAUpdateCb");
+       cb->ptr = *ptr;
+       cb->prop = prop;
+       
+//     rect.xmin = 0; rect.xmax = 10.0f * UI_UNIT_X;
+//     rect.ymin = 0; rect.ymax = 10.0f * UI_UNIT_X;
+       
+       block = uiLayoutAbsoluteBlock(layout);
+
+       but = uiDefBlockButN(block, icon_view_menu, MEM_dupallocN(cb), "", 0, 0, UI_UNIT_X * 6, UI_UNIT_Y * 6, "");
+
+       
+//     but = uiDefIconButR_prop(block, ROW, 0, icon, 0, 0, BLI_rctf_size_x(&rect), BLI_rctf_size_y(&rect), ptr, prop, -1, 0, icon, -1, -1, NULL);
+       
+       but->icon = icon;
+       uiButSetFlag(but, UI_HAS_ICON | UI_ICON_PREVIEW);
+       
+       uiButSetNFunc(but, rna_update_cb, MEM_dupallocN(cb), NULL);
+       
+       MEM_freeN(cb);
+}
+
 /********************* Histogram Template ************************/
 
 void uiTemplateHistogram(uiLayout *layout, PointerRNA *ptr, const char *propname)
@@ -1470,17 +1673,19 @@ void uiTemplateHistogram(uiLayout *layout, PointerRNA *ptr, const char *propname
        cb->ptr = *ptr;
        cb->prop = prop;
        
-       rect.xmin = 0; rect.xmax = 200;
-       rect.ymin = 0; rect.ymax = 190;
+       rect.xmin = 0; rect.xmax = 10.0f * UI_UNIT_X;
+       rect.ymin = 0; rect.ymax = 9.5f * UI_UNIT_Y;
        
        block = uiLayoutAbsoluteBlock(layout);
        //colorband_buttons_layout(layout, block, cptr.data, &rect, !expand, cb);
 
        hist = (Histogram *)cptr.data;
 
-       hist->height = (hist->height <= UI_UNIT_Y) ? UI_UNIT_Y : hist->height;
+       hist->height = (hist->height <= 20) ? 20 : hist->height;
+
+       bt = uiDefBut(block, HISTOGRAM, 0, "", rect.xmin, rect.ymin, BLI_rctf_size_x(&rect), UI_DPI_FAC * hist->height,
+                     hist, 0, 0, 0, 0, "");
 
-       bt = uiDefBut(block, HISTOGRAM, 0, "", rect.xmin, rect.ymin, BLI_rctf_size_x(&rect), hist->height, hist, 0, 0, 0, 0, "");
        uiButSetNFunc(bt, rna_update_cb, MEM_dupallocN(cb), NULL);
 
        MEM_freeN(cb);
@@ -1510,14 +1715,15 @@ void uiTemplateWaveform(uiLayout *layout, PointerRNA *ptr, const char *propname)
        cb->ptr = *ptr;
        cb->prop = prop;
        
-       rect.xmin = 0; rect.xmax = 200;
-       rect.ymin = 0; rect.ymax = 190;
+       rect.xmin = 0; rect.xmax = 10.0f * UI_UNIT_X;
+       rect.ymin = 0; rect.ymax = 9.5f * UI_UNIT_Y;
        
        block = uiLayoutAbsoluteBlock(layout);
        
-       scopes->wavefrm_height = (scopes->wavefrm_height <= UI_UNIT_Y) ? UI_UNIT_Y : scopes->wavefrm_height;
+       scopes->wavefrm_height = (scopes->wavefrm_height <= 20) ? 20 : scopes->wavefrm_height;
 
-       bt = uiDefBut(block, WAVEFORM, 0, "", rect.xmin, rect.ymin, BLI_rctf_size_x(&rect), scopes->wavefrm_height, scopes, 0, 0, 0, 0, "");
+       bt = uiDefBut(block, WAVEFORM, 0, "", rect.xmin, rect.ymin, BLI_rctf_size_x(&rect), UI_DPI_FAC * scopes->wavefrm_height,
+                     scopes, 0, 0, 0, 0, "");
        (void)bt;  /* UNUSED */
        
        MEM_freeN(cb);
@@ -1547,14 +1753,15 @@ void uiTemplateVectorscope(uiLayout *layout, PointerRNA *ptr, const char *propna
        cb->ptr = *ptr;
        cb->prop = prop;
        
-       rect.xmin = 0; rect.xmax = 200;
-       rect.ymin = 0; rect.ymax = 190;
+       rect.xmin = 0; rect.xmax = 10.0f * UI_UNIT_X;
+       rect.ymin = 0; rect.ymax = 9.5f * UI_UNIT_Y;
        
        block = uiLayoutAbsoluteBlock(layout);
 
-       scopes->vecscope_height = (scopes->vecscope_height <= UI_UNIT_Y) ? UI_UNIT_Y : scopes->vecscope_height;
+       scopes->vecscope_height = (scopes->vecscope_height <= 20) ? 20 : scopes->vecscope_height;
        
-       bt = uiDefBut(block, VECTORSCOPE, 0, "", rect.xmin, rect.ymin, BLI_rctf_size_x(&rect), scopes->vecscope_height, scopes, 0, 0, 0, 0, "");
+       bt = uiDefBut(block, VECTORSCOPE, 0, "", rect.xmin, rect.ymin, BLI_rctf_size_x(&rect),
+                     UI_DPI_FAC * scopes->vecscope_height, scopes, 0, 0, 0, 0, "");
        uiButSetNFunc(bt, rna_update_cb, MEM_dupallocN(cb), NULL);
        
        MEM_freeN(cb);
@@ -1648,15 +1855,19 @@ static uiBlock *curvemap_clipping_func(bContext *C, ARegion *ar, void *cumap_v)
        /* use this for a fake extra empy space around the buttons */
        uiDefBut(block, LABEL, 0, "",           -4, 16, width + 8, 6 * UI_UNIT_Y, NULL, 0, 0, 0, 0, "");
 
-       bt = uiDefButBitI(block, TOG, CUMA_DO_CLIP, 1, "Use Clipping",
+       bt = uiDefButBitI(block, TOG, CUMA_DO_CLIP, 1, IFACE_("Use Clipping"),
                          0, 5 * UI_UNIT_Y, width, UI_UNIT_Y, &cumap->flag, 0.0, 0.0, 10, 0, "");
        uiButSetFunc(bt, curvemap_buttons_setclip, cumap, NULL);
 
        uiBlockBeginAlign(block);
-       uiDefButF(block, NUM, 0, IFACE_("Min X "),   0, 4 * UI_UNIT_Y, width, UI_UNIT_Y, &cumap->clipr.xmin, -100.0, cumap->clipr.xmax, 10, 0, "");
-       uiDefButF(block, NUM, 0, IFACE_("Min Y "),   0, 3 * UI_UNIT_Y, width, UI_UNIT_Y, &cumap->clipr.ymin, -100.0, cumap->clipr.ymax, 10, 0, "");
-       uiDefButF(block, NUM, 0, IFACE_("Max X "),   0, 2 * UI_UNIT_Y, width, UI_UNIT_Y, &cumap->clipr.xmax, cumap->clipr.xmin, 100.0, 10, 0, "");
-       uiDefButF(block, NUM, 0, IFACE_("Max Y "),   0, UI_UNIT_Y, width, UI_UNIT_Y, &cumap->clipr.ymax, cumap->clipr.ymin, 100.0, 10, 0, "");
+       uiDefButF(block, NUM, 0, IFACE_("Min X "),   0, 4 * UI_UNIT_Y, width, UI_UNIT_Y,
+                 &cumap->clipr.xmin, -100.0, cumap->clipr.xmax, 10, 0, "");
+       uiDefButF(block, NUM, 0, IFACE_("Min Y "),   0, 3 * UI_UNIT_Y, width, UI_UNIT_Y,
+                 &cumap->clipr.ymin, -100.0, cumap->clipr.ymax, 10, 0, "");
+       uiDefButF(block, NUM, 0, IFACE_("Max X "),   0, 2 * UI_UNIT_Y, width, UI_UNIT_Y,
+                 &cumap->clipr.xmax, cumap->clipr.xmin, 100.0, 10, 0, "");
+       uiDefButF(block, NUM, 0, IFACE_("Max Y "),   0, UI_UNIT_Y, width, UI_UNIT_Y,
+                 &cumap->clipr.ymax, cumap->clipr.ymin, 100.0, 10, 0, "");
 
        uiBlockSetDirection(block, UI_RIGHT);
 
@@ -1705,12 +1916,18 @@ static uiBlock *curvemap_tools_func(bContext *C, ARegion *ar, void *cumap_v)
        block = uiBeginBlock(C, ar, __func__, UI_EMBOSS);
        uiBlockSetButmFunc(block, curvemap_tools_dofunc, cumap_v);
 
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, IFACE_("Reset View"),         0, yco -= UI_UNIT_Y, menuwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 1, "");
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, IFACE_("Vector Handle"),      0, yco -= UI_UNIT_Y, menuwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 2, "");
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, IFACE_("Auto Handle"),            0, yco -= UI_UNIT_Y, menuwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 3, "");
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, IFACE_("Extend Horizontal"),  0, yco -= UI_UNIT_Y, menuwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 4, "");
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, IFACE_("Extend Extrapolated"),    0, yco -= UI_UNIT_Y, menuwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 5, "");
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, IFACE_("Reset Curve"),            0, yco -= UI_UNIT_Y, menuwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "");
+       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, IFACE_("Reset View"),          0, yco -= UI_UNIT_Y,
+                        menuwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 1, "");
+       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, IFACE_("Vector Handle"),       0, yco -= UI_UNIT_Y,
+                        menuwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 2, "");
+       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, IFACE_("Auto Handle"),         0, yco -= UI_UNIT_Y,
+                        menuwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 3, "");
+       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, IFACE_("Extend Horizontal"),   0, yco -= UI_UNIT_Y,
+                        menuwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 4, "");
+       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, IFACE_("Extend Extrapolated"), 0, yco -= UI_UNIT_Y,
+                        menuwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 5, "");
+       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, IFACE_("Reset Curve"),         0, yco -= UI_UNIT_Y,
+                        menuwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "");
 
        uiBlockSetDirection(block, UI_RIGHT);
        uiTextBoundsBlock(block, 50);
@@ -1727,10 +1944,14 @@ static uiBlock *curvemap_brush_tools_func(bContext *C, ARegion *ar, void *cumap_
        block = uiBeginBlock(C, ar, __func__, UI_EMBOSS);
        uiBlockSetButmFunc(block, curvemap_tools_dofunc, cumap_v);
 
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, IFACE_("Reset View"),     0, yco -= UI_UNIT_Y, menuwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 1, "");
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, IFACE_("Vector Handle"),  0, yco -= UI_UNIT_Y, menuwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 2, "");
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, IFACE_("Auto Handle"),        0, yco -= UI_UNIT_Y, menuwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 3, "");
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, IFACE_("Reset Curve"),        0, yco -= UI_UNIT_Y, menuwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "");
+       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, IFACE_("Reset View"),    0, yco -= UI_UNIT_Y,
+                        menuwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 1, "");
+       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, IFACE_("Vector Handle"), 0, yco -= UI_UNIT_Y,
+                        menuwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 2, "");
+       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, IFACE_("Auto Handle"),   0, yco -= UI_UNIT_Y,
+                        menuwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 3, "");
+       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, IFACE_("Reset Curve"),   0, yco -= UI_UNIT_Y,
+                        menuwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "");
 
        uiBlockSetDirection(block, UI_RIGHT);
        uiTextBoundsBlock(block, 50);
@@ -1744,11 +1965,11 @@ static void curvemap_buttons_redraw(bContext *C, void *UNUSED(arg1), void *UNUSE
        ED_region_tag_redraw(CTX_wm_region(C));
 }
 
-static void curvemap_buttons_update(bContext *UNUSED(C), void *UNUSED(arg1), void *cumap_v)
+static void curvemap_buttons_update(bContext *C, void *arg1_v, void *cumap_v)
 {
        CurveMapping *cumap = cumap_v;
-
        curvemapping_changed(cumap, TRUE);
+       rna_update_cb(C, arg1_v, NULL);
 }
 
 static void curvemap_buttons_reset(bContext *C, void *cb_v, void *cumap_v)
@@ -1770,7 +1991,8 @@ static void curvemap_buttons_reset(bContext *C, void *cb_v, void *cumap_v)
 }
 
 /* still unsure how this call evolves... we use labeltype for defining what curve-channels to show */
-static void curvemap_buttons_layout(uiLayout *layout, PointerRNA *ptr, char labeltype, int levels, int brush, RNAUpdateCb *cb)
+static void curvemap_buttons_layout(uiLayout *layout, PointerRNA *ptr, char labeltype, int levels,
+                                    int brush, RNAUpdateCb *cb)
 {
        CurveMapping *cumap = ptr->data;
        CurveMap *cm = &cumap->cm[cumap->cur];
@@ -1883,7 +2105,7 @@ static void curvemap_buttons_layout(uiLayout *layout, PointerRNA *ptr, char labe
        /* curve itself */
        size = uiLayoutGetWidth(layout);
        row = uiLayoutRow(layout, FALSE);
-       uiDefBut(block, BUT_CURVE, 0, "", 0, 0, size, MIN2(size, 200), cumap, 0.0f, 1.0f, bg, 0, "");
+       uiDefBut(block, BUT_CURVE, 0, "", 0, 0, size, MIN2(size, 10.0f * UI_UNIT_X), cumap, 0.0f, 1.0f, bg, 0, "");
 
        /* sliders for selected point */
        for (i = 0; i < cm->totpoint; i++) {
@@ -1894,10 +2116,22 @@ static void curvemap_buttons_layout(uiLayout *layout, PointerRNA *ptr, char labe
        }
 
        if (cmp) {
+               rctf bounds;
+
+               if (cumap->flag & CUMA_DO_CLIP) {
+                       bounds = cumap->clipr;
+               }
+               else {
+                       bounds.xmin = bounds.ymin = -1000.0;
+                       bounds.xmax = bounds.ymax =  1000.0;
+               }
+
                uiLayoutRow(layout, TRUE);
-               uiBlockSetNFunc(block, curvemap_buttons_update, NULL, cumap);
-               uiDefButF(block, NUM, 0, "X", 0, 2 * UI_UNIT_Y, UI_UNIT_X * 10, UI_UNIT_Y, &cmp->x, 0.0f, 1.0f, 1, 5, "");
-               uiDefButF(block, NUM, 0, "Y", 0, 1 * UI_UNIT_Y, UI_UNIT_X * 10, UI_UNIT_Y, &cmp->y, 0.0f, 1.0f, 1, 5, "");
+               uiBlockSetNFunc(block, curvemap_buttons_update, MEM_dupallocN(cb), cumap);
+               bt = uiDefButF(block, NUM, 0, "X", 0, 2 * UI_UNIT_Y, UI_UNIT_X * 10, UI_UNIT_Y,
+                              &cmp->x, bounds.xmin, bounds.xmax, 1, 5, "");
+               bt = uiDefButF(block, NUM, 0, "Y", 0, 1 * UI_UNIT_Y, UI_UNIT_X * 10, UI_UNIT_Y,
+                              &cmp->y, bounds.ymin, bounds.ymax, 1, 5, "");
        }
 
        /* black/white levels */
@@ -1946,29 +2180,48 @@ void uiTemplateCurveMapping(uiLayout *layout, PointerRNA *ptr, const char *propn
        MEM_freeN(cb);
 }
 
-/********************* ColorWheel Template ************************/
+/********************* ColorPicker Template ************************/
 
-#define WHEEL_SIZE  100
+#define WHEEL_SIZE  (5 * U.widget_unit)
 
-void uiTemplateColorWheel(uiLayout *layout, PointerRNA *ptr, const char *propname, int value_slider, int lock, int lock_luminosity, int cubic)
+/* This template now follows User Preference for type - name is not correct anymore... */
+void uiTemplateColorPicker(uiLayout *layout, PointerRNA *ptr, const char *propname, int value_slider,
+                           int lock, int lock_luminosity, int cubic)
 {
        PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
        uiBlock *block = uiLayoutGetBlock(layout);
        uiLayout *col, *row;
-       uiBut *but;
+       uiBut *but = NULL;
        float softmin, softmax, step, precision;
-       
+
        if (!prop) {
                RNA_warning("property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
                return;
        }
 
        RNA_property_float_ui_range(ptr, prop, &softmin, &softmax, &step, &precision);
-       
-       col = uiLayoutColumn(layout, FALSE);
+
+       col = uiLayoutColumn(layout, TRUE);
        row = uiLayoutRow(col, TRUE);
-       
-       but = uiDefButR_prop(block, HSVCIRCLE, 0, "",   0, 0, WHEEL_SIZE, WHEEL_SIZE, ptr, prop, -1, 0.0, 0.0, 0, 0, "");
+
+       switch (U.color_picker_type) {
+               case USER_CP_CIRCLE:
+                       but = uiDefButR_prop(block, HSVCIRCLE, 0, "", 0, 0, WHEEL_SIZE, WHEEL_SIZE, ptr, prop,
+                                            -1, 0.0, 0.0, 0, 0, "");
+                       break;
+               case USER_CP_SQUARE_SV:
+                       but = uiDefButR_prop(block, HSVCUBE, 0, "", 0, 0, WHEEL_SIZE, WHEEL_SIZE, ptr, prop,
+                                            -1, 0.0, 0.0, UI_GRAD_SV, 0, "");
+                       break;
+               case USER_CP_SQUARE_HS:
+                       but = uiDefButR_prop(block, HSVCUBE, 0, "", 0, 0, WHEEL_SIZE, WHEEL_SIZE, ptr, prop,
+                                            -1, 0.0, 0.0, UI_GRAD_HS, 0, "");
+                       break;
+               case USER_CP_SQUARE_HV:
+                       but = uiDefButR_prop(block, HSVCUBE, 0, "", 0, 0, WHEEL_SIZE, WHEEL_SIZE, ptr, prop,
+                                            -1, 0.0, 0.0, UI_GRAD_HV, 0, "");
+                       break;
+       }
 
        if (lock) {
                but->flag |= UI_BUT_COLOR_LOCK;
@@ -1984,10 +2237,31 @@ void uiTemplateColorWheel(uiLayout *layout, PointerRNA *ptr, const char *propnam
        if (cubic)
                but->flag |= UI_BUT_COLOR_CUBIC;
 
-       uiItemS(row);
        
-       if (value_slider)
-               uiDefButR_prop(block, HSVCUBE, 0, "", WHEEL_SIZE + 6, 0, 14, WHEEL_SIZE, ptr, prop, -1, softmin, softmax, UI_GRAD_V_ALT, 0, "");
+       if (value_slider) {
+               switch (U.color_picker_type) {
+                       case USER_CP_CIRCLE:
+                               uiItemS(row);
+                               uiDefButR_prop(block, HSVCUBE, 0, "", WHEEL_SIZE + 6, 0, 14, WHEEL_SIZE, ptr, prop,
+                                              -1, softmin, softmax, UI_GRAD_V_ALT, 0, "");
+                               break;
+                       case USER_CP_SQUARE_SV:
+                               uiItemS(col);
+                               uiDefButR_prop(block, HSVCUBE, 0, "", 0, 4, WHEEL_SIZE, 18, ptr, prop,
+                                              -1, softmin, softmax, UI_GRAD_SV + 3, 0, "");
+                               break;
+                       case USER_CP_SQUARE_HS:
+                               uiItemS(col);
+                               uiDefButR_prop(block, HSVCUBE, 0, "", 0, 4, WHEEL_SIZE, 18, ptr, prop,
+                                              -1, softmin, softmax, UI_GRAD_HS + 3, 0, "");
+                               break;
+                       case USER_CP_SQUARE_HV:
+                               uiItemS(col);
+                               uiDefButR_prop(block, HSVCUBE, 0, "", 0, 4, WHEEL_SIZE, 18, ptr, prop,
+                                              -1, softmin, softmax, UI_GRAD_HV + 3, 0, "");
+                               break;
+               }
+       }
 }
 
 /********************* Layer Buttons Template ************************/
@@ -2085,252 +2359,99 @@ void uiTemplateLayers(uiLayout *layout, PointerRNA *ptr, const char *propname,
        }
 }
 
-
-/************************* List Template **************************/
-
-static int list_item_icon_get(bContext *C, PointerRNA *itemptr, int rnaicon, int big)
+void uiTemplateGameStates(uiLayout *layout, PointerRNA *ptr, const char *propname,
+                      PointerRNA *used_ptr, const char *used_propname, int active_state)
 {
-       ID *id = NULL;
-       int icon;
-
-       if (!itemptr->data)
-               return rnaicon;
+       uiLayout *uRow, *uCol;
+       PropertyRNA *prop, *used_prop = NULL;
+       int groups, cols, states;
+       int group, col, state, row;
+       int cols_per_group = 5;
+       Object *ob = (Object *)ptr->id.data;
 
-       /* try ID, material or texture slot */
-       if (RNA_struct_is_ID(itemptr->type)) {
-               id = itemptr->id.data;
-       }
-       else if (RNA_struct_is_a(itemptr->type, &RNA_MaterialSlot)) {
-               id = RNA_pointer_get(itemptr, "material").data;
-       }
-       else if (RNA_struct_is_a(itemptr->type, &RNA_TextureSlot)) {
-               id = RNA_pointer_get(itemptr, "texture").data;
+       prop = RNA_struct_find_property(ptr, propname);
+       if (!prop) {
+               RNA_warning("states property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
+               return;
        }
-       else if (RNA_struct_is_a(itemptr->type, &RNA_DynamicPaintSurface)) {
-               DynamicPaintSurface *surface = (DynamicPaintSurface *)itemptr->data;
+       
+       /* the number of states determines the way we group them 
+        *      - we want 2 rows only (for now)
+        *      - the number of columns (cols) is the total number of buttons per row
+        *        the 'remainder' is added to this, as it will be ok to have first row slightly wider if need be
+        *      - for now, only split into groups if group will have at least 5 items
+        */
+       states = RNA_property_array_length(ptr, prop);
+       cols = (states / 2) + (states % 2);
+       groups = ((cols / 2) < cols_per_group) ? (1) : (cols / cols_per_group);
+
+       if (used_ptr && used_propname) {
+               used_prop = RNA_struct_find_property(used_ptr, used_propname);
+               if (!used_prop) {
+                       RNA_warning("used layers property not found: %s.%s", RNA_struct_identifier(ptr->type), used_propname);
+                       return;
+               }
 
-               if (surface->format == MOD_DPAINT_SURFACE_F_PTEX) return ICON_TEXTURE_SHADED;
-               else if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) return ICON_OUTLINER_DATA_MESH;
-               else if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) return ICON_FILE_IMAGE;
+               if (RNA_property_array_length(used_ptr, used_prop) < states)
+                       used_prop = NULL;
        }
+       
+       /* layers are laid out going across rows, with the columns being divided into groups */
+       
+       for (group = 0; group < groups; group++) {
+               uCol = uiLayoutColumn(layout, TRUE);
+               
+               for (row = 0; row < 2; row++) {
+                       uiBlock *block;
+                       uiBut *but;
 
-       /* get icon from ID */
-       if (id) {
-               icon = ui_id_icon_get(C, id, big);
+                       uRow = uiLayoutRow(uCol, TRUE);
+                       block = uiLayoutGetBlock(uRow);
+                       state = groups * cols_per_group * row + cols_per_group * group;
+                       
+                       /* add layers as toggle buts */
+                       for (col = 0; (col < cols_per_group) && (state < states); col++, state++) {
+                               int icon = 0;
+                               int butlay = 1 << state;
 
-               if (icon)
-                       return icon;
+                               if (active_state & butlay)
+                                       icon = ICON_LAYER_ACTIVE;
+                               else if (used_prop && RNA_property_boolean_get_index(used_ptr, used_prop, state))
+                                       icon = ICON_LAYER_USED;
+                               
+                               but = uiDefIconButR_prop(block, ICONTOG, 0, icon, 0, 0, UI_UNIT_X / 2, UI_UNIT_Y / 2, ptr, prop,
+                                                        state, 0, 0, -1, -1, sca_state_name_get(ob, state));
+                               uiButSetFunc(but, handle_layer_buttons, but, SET_INT_IN_POINTER(state));
+                               but->type = TOG;
+                       }
+               }
        }
-
-       return rnaicon;
 }
 
-static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, PointerRNA *itemptr, int i, int rnaicon, PointerRNA *activeptr, PropertyRNA *activeprop, const char *prop_list_id)
+
+/************************* List Template **************************/
+static void uilist_draw_item_default(struct uiList *ui_list, struct bContext *UNUSED(C), struct uiLayout *layout,
+                                     struct PointerRNA *UNUSED(dataptr), struct PointerRNA *itemptr, int icon,
+                                     struct PointerRNA *UNUSED(active_dataptr), const char *UNUSED(active_propname),
+                                     int UNUSED(index))
 {
-       uiBlock *block = uiLayoutGetBlock(layout);
-       uiBut *but;
-       uiLayout *split, *overlap, *sub, *row;
        char *namebuf;
        const char *name;
-       int icon;
-
-       overlap = uiLayoutOverlap(layout);
-
-       /* list item behind label & other buttons */
-       sub = uiLayoutRow(overlap, FALSE);
-
-       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, FALSE);
-
-       /* retrieve icon and name */
-       icon = list_item_icon_get(C, itemptr, rnaicon, 0);
-       if (icon == ICON_NONE || icon == ICON_DOT)
-               icon = 0;
 
        namebuf = RNA_struct_name_get_alloc(itemptr, NULL, 0, NULL);
        name = (namebuf) ? namebuf : "";
 
-       /* hardcoded types */
-       if (itemptr->type == &RNA_MeshTexturePolyLayer || itemptr->type == &RNA_MeshLoopColorLayer) {
-               uiItemL(sub, name, icon);
-               uiBlockSetEmboss(block, UI_EMBOSSN);
-               uiDefIconButR(block, TOG, 0, ICON_SCENE, 0, 0, UI_UNIT_X, UI_UNIT_Y, itemptr, "active_render", 0, 0, 0, 0, 0, NULL);
-               uiBlockSetEmboss(block, UI_EMBOSS);
-       }
-       else if (RNA_struct_is_a(itemptr->type, &RNA_MaterialTextureSlot)) {
-               uiItemL(sub, name, icon);
-               uiBlockSetEmboss(block, UI_EMBOSS);
-               uiDefButR(block, OPTION, 0, "", 0, 0, UI_UNIT_X, UI_UNIT_Y, ptr, "use_textures", i, 0, 0, 0, 0,  NULL);
-       }
-       else if (RNA_struct_is_a(itemptr->type, &RNA_SceneRenderLayer)) {
-               uiItemL(sub, name, icon);
-               uiBlockSetEmboss(block, UI_EMBOSS);
-               uiDefButR(block, OPTION, 0, "", 0, 0, UI_UNIT_X, UI_UNIT_Y, itemptr, "use", 0, 0, 0, 0, 0,  NULL);
-       }
-       else if (RNA_struct_is_a(itemptr->type, &RNA_MaterialSlot)) {
-               /* provision to draw active node name */
-               Material *ma, *manode;
-               Scene *scene = CTX_data_scene(C);
-               Object *ob = (Object *)ptr->id.data;
-               int index = (Material **)itemptr->data - ob->mat;
-               
-               /* default item with material base name */
-               uiItemL(sub, name, icon);
-               
-               ma = give_current_material(ob, index + 1);
-               if (ma && !BKE_scene_use_new_shading_nodes(scene)) {
-                       manode = give_node_material(ma);
-                       if (manode) {
-                               char str[MAX_ID_NAME + 12];
-                               BLI_snprintf(str, sizeof(str), IFACE_("Node %s"), manode->id.name + 2);
-                               uiItemL(sub, str, ui_id_icon_get(C, &manode->id, 1));
-                       }
-                       else if (ma->use_nodes) {
-                               uiItemL(sub, IFACE_("Node <none>"), ICON_NONE);
-                       }
-               }
+       /* Simplest one! */
+       switch (ui_list->layout_type) {
+       case UILST_LAYOUT_GRID:
+               uiItemL(layout, "", icon);
+               break;
+       case UILST_LAYOUT_DEFAULT:
+       case UILST_LAYOUT_COMPACT:
+       default:
+               uiItemL(layout, name, icon);
+               break;
        }
-       else if (itemptr->type == &RNA_ShapeKey) {
-               Object *ob = (Object *)activeptr->data;
-               Key *key = (Key *)itemptr->id.data;
-               KeyBlock *kb = (KeyBlock *)itemptr->data;
-
-               split = uiLayoutSplit(sub, 0.66f, FALSE);
-
-               uiItemL(split, name, icon);
-
-               uiBlockSetEmboss(block, UI_EMBOSSN);
-               row = uiLayoutRow(split, TRUE);
-               if (i == 0 || (key->type != KEY_RELATIVE)) uiItemL(row, "", ICON_NONE);
-               else uiItemR(row, itemptr, "value", 0, "", ICON_NONE);
-               uiItemR(row, itemptr, "mute", 0, "", ICON_NONE);
-
-               if ((kb->flag & KEYBLOCK_MUTE) ||
-                   (ob->mode == OB_MODE_EDIT && !((ob->shapeflag & OB_SHAPE_EDIT_MODE) && ob->type == OB_MESH)))
-               {
-                       uiLayoutSetActive(row, FALSE);
-               }
-               uiBlockSetEmboss(block, UI_EMBOSS);
-       }
-       else if (itemptr->type == &RNA_VertexGroup) {
-               bDeformGroup *dg = (bDeformGroup *)itemptr->data;
-               uiItemL(sub, name, icon);
-               /* RNA does not allow nice lock icons, use lower level buttons */
-#if 0
-               uiDefButR(block, OPTION, 0, "", 0, 0, UI_UNIT_X, UI_UNIT_Y, itemptr, "lock_weight", 0, 0, 0, 0, 0,  NULL);
-#else
-               uiBlockSetEmboss(block, UI_EMBOSSN);
-               uiDefIconButBitC(block, TOG, DG_LOCK_WEIGHT, 0, (dg->flag & DG_LOCK_WEIGHT) ? ICON_LOCKED : ICON_UNLOCKED,
-                                0, 0, UI_UNIT_X, UI_UNIT_Y, &dg->flag, 0, 0, 0, 0,
-                                TIP_("Maintain relative weights while painting"));
-               uiBlockSetEmboss(block, UI_EMBOSS);
-#endif
-       }
-       else if (itemptr->type == &RNA_KeyingSetPath) {
-               KS_Path *ksp = (KS_Path *)itemptr->data;
-               
-               /* icon needs to be the type of ID which is currently active */
-               RNA_enum_icon_from_value(id_type_items, ksp->idtype, &icon);
-               
-               /* nothing else special to do... */
-               uiItemL(sub, name, icon); /* fails, backdrop LISTROW... */
-       }
-       else if (itemptr->type == &RNA_DynamicPaintSurface) {
-               char name_final[96];
-               const char *enum_name;
-               PropertyRNA *prop = RNA_struct_find_property(itemptr, "surface_type");
-               DynamicPaintSurface *surface = (DynamicPaintSurface *)itemptr->data;
-
-               RNA_property_enum_name(C, itemptr, prop, RNA_property_enum_get(itemptr, prop), &enum_name);
-
-               BLI_snprintf(name_final, sizeof(name_final), "%s (%s)", name, enum_name);
-               uiItemL(sub, name_final, icon);
-               if (dynamicPaint_surfaceHasColorPreview(surface)) {
-                       uiBlockSetEmboss(block, UI_EMBOSSN);
-                       uiDefIconButR(block, OPTION, 0, (surface->flags & MOD_DPAINT_PREVIEW) ? ICON_RESTRICT_VIEW_OFF : ICON_RESTRICT_VIEW_ON,
-                                     0, 0, UI_UNIT_X, UI_UNIT_Y, itemptr, "show_preview", 0, 0, 0, 0, 0, NULL);
-                       uiBlockSetEmboss(block, UI_EMBOSS);
-               }
-               uiDefButR(block, OPTION, 0, "", 0, 0, UI_UNIT_X, UI_UNIT_Y, itemptr, "is_active", i, 0, 0, 0, 0,  NULL);
-       }
-       else if (itemptr->type == &RNA_MovieTrackingObject) {
-               MovieTrackingObject *tracking_object = (MovieTrackingObject *)itemptr->data;
-
-               split = uiLayoutSplit(sub, 0.75f, FALSE);
-               if (tracking_object->flag & TRACKING_OBJECT_CAMERA) {
-                       uiItemL(split, name, ICON_CAMERA_DATA);
-               }
-               else {
-                       uiItemL(split, name, ICON_OBJECT_DATA);
-               }
-       }
-       else if (itemptr->type == &RNA_MaskLayer) {
-               split = uiLayoutRow(sub, FALSE);
-
-               uiItemL(split, name, icon);
-
-               uiBlockSetEmboss(block, UI_EMBOSSN);
-               row = uiLayoutRow(split, TRUE);
-               uiItemR(row, itemptr, "alpha", 0, "", ICON_NONE);
-               uiItemR(row, itemptr, "hide", 0, "", ICON_NONE);
-               uiItemR(row, itemptr, "hide_select", 0, "", ICON_NONE);
-               uiItemR(row, itemptr, "hide_render", 0, "", ICON_NONE);
-
-               uiBlockSetEmboss(block, UI_EMBOSS);
-       }
-
-       /* There is a last chance to display custom controls (in addition to the name/label):
-        * If the given item property group features a string property named as prop_list,
-        * this tries to add controls for all properties of the item listed in that string property.
-        * (colon-separated names).
-        *
-        * This is especially useful for python. E.g., if you list a collection of this property
-        * group:
-        *
-        * class TestPropertyGroup(bpy.types.PropertyGroup):
-        *     bool    = BoolProperty(default=False)
-        *     integer = IntProperty()
-        *     string  = StringProperty()
-        * 
-        *     # A string of all identifiers (colon-separated) which property's controls should be
-        *     # displayed in a template_list.
-        *     template_list_controls = StringProperty(default="integer:bool:string", options={"HIDDEN"})
-        *
-        * ... you'll get a numfield for the integer prop, a check box for the bool prop, and a textfield
-        * for the string prop, after the name of each item of the collection.
-        */
-       else if (prop_list_id) {
-               row = uiLayoutRow(sub, TRUE);
-               uiItemL(row, name, icon);
-
-               /* XXX: Check, as sometimes we get an itemptr looking like
-                *      {id = {data = 0x0}, type = 0x0, data = 0x0}
-                *      which would obviously produce a sigsev... */
-               if (itemptr->type) {
-                       /* If the special property is set for the item, and it is a collection... */
-                       PropertyRNA *prop_list = RNA_struct_find_property(itemptr, prop_list_id);
-
-                       if (prop_list && RNA_property_type(prop_list) == PROP_STRING) {
-                               int prop_names_len;
-                               char *prop_names = RNA_property_string_get_alloc(itemptr, prop_list, NULL, 0, &prop_names_len);
-                               char *prop_names_end = prop_names + prop_names_len;
-                               char *id = prop_names;
-                               char *id_next;
-                               while (id < prop_names_end) {
-                                       if ((id_next = strchr(id, ':'))) *id_next++ = '\0';
-                                       else id_next = prop_names_end;
-                                       uiItemR(row, itemptr, id, 0, NULL, ICON_NONE);
-                                       id = id_next;
-                               }
-                               MEM_freeN(prop_names);
-                       }
-               }
-       }
-
-       else
-               uiItemL(sub, name, icon);  /* fails, backdrop LISTROW... */
 
        /* free name */
        if (namebuf) {
@@ -2338,174 +2459,174 @@ static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, Pointe
        }
 }
 
-void uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, PointerRNA *activeptr, const char *activepropname, const char *prop_list, int rows, int maxrows, int listtype)
+void uiTemplateList(uiLayout *layout, bContext *C, const char *listtype_name, const char *list_id,
+                    PointerRNA *dataptr, const char *propname, PointerRNA *active_dataptr,
+                    const char *active_propname, int rows, int maxrows, int layout_type)
 {
+       uiListType *ui_list_type;
+       uiList *ui_list = NULL;
+       ARegion *ar;
+       uiListDrawItemFunc draw_item;
+
        PropertyRNA *prop = NULL, *activeprop;
        PropertyType type, activetype;
        StructRNA *ptype;
-       uiLayout *box, *row, *col;
-       uiBlock *block;
+       uiLayout *box, *row, *col, *sub, *overlap;
+       uiBlock *block, *subblock;
        uiBut *but;
-       Panel *pa;
-       const char *name;
+
+       char ui_list_id[UI_MAX_NAME_STR];
        char numstr[32];
-       int rnaicon = 0, icon = 0, i = 0, activei = 0, len = 0, items, found, min, max;
+       int rnaicon = ICON_NONE, icon = ICON_NONE;
+       int i = 0, activei = 0;
+       int len = 0;
+       int items;
+       int found;
+       int min, max;
 
        /* validate arguments */
+       /* Forbid default UI_UL_DEFAULT_CLASS_NAME list class without a custom list_id! */
+       if (!strcmp(UI_UL_DEFAULT_CLASS_NAME, listtype_name) && !(list_id && list_id[0])) {
+               RNA_warning("template_list using default '%s' UIList class must provide a custom list_id",
+                           UI_UL_DEFAULT_CLASS_NAME);
+               return;
+       }
+
        block = uiLayoutGetBlock(layout);
-       pa = block->panel;
 
-       if (!pa) {
-               RNA_warning("Only works inside a panel");
+       if (!active_dataptr->data) {
+               RNA_warning("No active data");
                return;
        }
 
-       if (!activeptr->data)
-               return;
-       
-       if (ptr->data) {
-               prop = RNA_struct_find_property(ptr, propname);
+       if (dataptr->data) {
+               prop = RNA_struct_find_property(dataptr, propname);
                if (!prop) {
-                       RNA_warning("Property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
+                       RNA_warning("Property not found: %s.%s", RNA_struct_identifier(dataptr->type), propname);
                        return;
                }
        }
 
-       activeprop = RNA_struct_find_property(activeptr, activepropname);
+       activeprop = RNA_struct_find_property(active_dataptr, active_propname);
        if (!activeprop) {
-               RNA_warning("Property not found: %s.%s", RNA_struct_identifier(ptr->type), activepropname);
+               RNA_warning("Property not found: %s.%s", RNA_struct_identifier(active_dataptr->type), active_propname);
                return;
        }
 
        if (prop) {
                type = RNA_property_type(prop);
                if (type != PROP_COLLECTION) {
-                       RNA_warning("uiExpected collection property");
+                       RNA_warning("Expected a collection data property");
                        return;
                }
        }
 
        activetype = RNA_property_type(activeprop);
        if (activetype != PROP_INT) {
-               RNA_warning("Expected integer property");
+               RNA_warning("Expected an integer active data property");
                return;
        }
 
        /* get icon */
-       if (ptr->data && prop) {
-               ptype = RNA_property_pointer_type(ptr, prop);
+       if (dataptr->data && prop) {
+               ptype = RNA_property_pointer_type(dataptr, prop);
                rnaicon = RNA_struct_ui_icon(ptype);
        }
 
        /* get active data */
-       activei = RNA_property_int_get(activeptr, activeprop);
+       activei = RNA_property_int_get(active_dataptr, activeprop);
 
-       if (listtype == 'i') {
-               box = uiLayoutListBox(layout, ptr, prop, activeptr, activeprop);
-               col = uiLayoutColumn(box, TRUE);
-               row = uiLayoutRow(col, FALSE);
+       /* Find the uiList type. */
+       ui_list_type = WM_uilisttype_find(listtype_name, FALSE);
 
-               if (ptr->data && prop) {
-                       /* create list items */
-                       RNA_PROP_BEGIN (ptr, itemptr, prop)
-                       {
-                               /* create button */
-                               if (!(i % 9))
-                                       row = uiLayoutRow(col, FALSE);
-
-                               icon = list_item_icon_get(C, &itemptr, rnaicon, 1);
-                               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);
-                               
-
-                               i++;
-                       }
-                       RNA_PROP_END;
-               }
+       if (ui_list_type == NULL) {
+               RNA_warning("List type %s not found", listtype_name);
+               return;
        }
-       else if (listtype == 'c') {
-               /* compact layout */
 
-               row = uiLayoutRow(layout, TRUE);
+       draw_item = ui_list_type->draw_item ? ui_list_type->draw_item : uilist_draw_item_default;
 
-               if (ptr->data && prop) {
-                       /* create list items */
-                       RNA_PROP_BEGIN (ptr, itemptr, prop)
-                       {
-                               found = (activei == i);
-
-                               if (found) {
-                                       /* create button */
-                                       name = RNA_struct_name_get_alloc(&itemptr, NULL, 0, NULL);
-                                       icon = list_item_icon_get(C, &itemptr, rnaicon, 0);
-                                       uiItemL(row, (name) ? name : "", icon);
+       /* Find or add the uiList to the current Region. */
+       /* We tag the list id with the list type... */
+       BLI_snprintf(ui_list_id, sizeof(ui_list_id), "%s_%s", ui_list_type->idname, list_id ? list_id : "");
 
-                                       if (name) {
-                                               MEM_freeN((void *)name);
-                                       }
-                               }
+       ar = CTX_wm_region(C);
+       ui_list = BLI_findstring(&ar->ui_lists, ui_list_id, offsetof(uiList, list_id));
 
-                               i++;
-                       }
-                       RNA_PROP_END;
-               }
+       if (!ui_list) {
+               ui_list = MEM_callocN(sizeof(uiList), __func__);
+               BLI_strncpy(ui_list->list_id, ui_list_id, sizeof(ui_list->list_id));
+               BLI_addtail(&ar->ui_lists, ui_list);
+       }
 
-               /* if not found, add in dummy button */
-               if (i == 0)
-                       uiItemL(row, "", ICON_NONE);
+       /* Because we can't actually pass type across save&load... */
+       ui_list->type = ui_list_type;
+       ui_list->layout_type = layout_type;
 
-               /* next/prev button */
-               BLI_snprintf(numstr, sizeof(numstr), "%d :", i);
-               but = uiDefIconTextButR_prop(block, NUM, 0, 0, numstr, 0, 0, UI_UNIT_X * 5, UI_UNIT_Y, activeptr, activeprop, 0, 0, 0, 0, 0, "");
-               if (i == 0)
-                       uiButSetFlag(but, UI_BUT_DISABLED);
-       }
-       else {
+       switch (layout_type) {
+       case UILST_LAYOUT_DEFAULT:
                /* default rows */
                if (rows == 0)
                        rows = 5;
                if (maxrows == 0)
                        maxrows = 5;
-               if (pa->list_grip_size != 0)
-                       rows = pa->list_grip_size;
+               if (ui_list->list_grip_size != 0)
+                       rows = ui_list->list_grip_size;
 
                /* layout */
-               box = uiLayoutListBox(layout, ptr, prop, activeptr, activeprop);
+               box = uiLayoutListBox(layout, ui_list, dataptr, prop, active_dataptr, activeprop);
                row = uiLayoutRow(box, FALSE);
                col = uiLayoutColumn(row, TRUE);
 
                /* init numbers */
-               RNA_property_int_range(activeptr, activeprop, &min, &max);
+               RNA_property_int_range(active_dataptr, activeprop, &min, &max);
 
                if (prop)
-                       len = RNA_property_collection_length(ptr, prop);
+                       len = RNA_property_collection_length(dataptr, prop);
                items = CLAMPIS(len, rows, MAX2(rows, maxrows));
 
                /* if list length changes and active is out of view, scroll to it */
-               if (pa->list_last_len != len)
-                       if ((activei < pa->list_scroll || activei >= pa->list_scroll + items))
-                               pa->list_scroll = activei;
+               if ((ui_list->list_last_len != len) &&
+                   (activei < ui_list->list_scroll || activei >= ui_list->list_scroll + items))
+               {
+                       ui_list->list_scroll = activei;
+               }
 
-               pa->list_scroll = MIN2(pa->list_scroll, len - items);
-               pa->list_scroll = MAX2(pa->list_scroll, 0);
-               pa->list_size = items;
-               pa->list_last_len = len;
+               ui_list->list_scroll = min_ii(ui_list->list_scroll, len - items);
+               ui_list->list_scroll = max_ii(ui_list->list_scroll, 0);
+               ui_list->list_size = items;
+               ui_list->list_last_len = len;
 
-               if (ptr->data && prop) {
+               if (dataptr->data && prop) {
                        /* create list items */
-                       RNA_PROP_BEGIN (ptr, itemptr, prop)
+                       RNA_PROP_BEGIN (dataptr, itemptr, prop)
                        {
-                               if (i >= pa->list_scroll && i < pa->list_scroll + items)
-                                       list_item_row(C, col, ptr, &itemptr, i, rnaicon, activeptr, activeprop, prop_list);
+                               if (i >= ui_list->list_scroll && i < ui_list->list_scroll + items) {
+                                       subblock = uiLayoutGetBlock(col);
+                                       overlap = uiLayoutOverlap(col);
+
+                                       /* list item behind label & other buttons */
+                                       sub = uiLayoutRow(overlap, FALSE);
+
+                                       but = uiDefButR_prop(subblock, LISTROW, 0, "", 0, 0, UI_UNIT_X * 10, UI_UNIT_Y,
+                                                            active_dataptr, activeprop, 0, 0, i, 0, 0, "");
+                                       uiButSetFlag(but, UI_BUT_NO_TOOLTIP);
 
+                                       sub = uiLayoutRow(overlap, FALSE);
+
+                                       icon = UI_rnaptr_icon_get(C, &itemptr, rnaicon, FALSE);
+                                       if (icon == ICON_DOT)
+                                               icon = ICON_NONE;
+                                       draw_item(ui_list, C, sub, dataptr, &itemptr, icon, active_dataptr, active_propname, i);
+                               }
                                i++;
                        }
                        RNA_PROP_END;
                }
 
                /* add dummy buttons to fill space */
-               while (i < pa->list_scroll + items) {
-                       if (i >= pa->list_scroll)
+               while (i < ui_list->list_scroll + items) {
+                       if (i >= ui_list->list_scroll)
                                uiItemL(col, "", ICON_NONE);
                        i++;
                }
@@ -2513,8 +2634,75 @@ void uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *
                /* add scrollbar */
                if (len > items) {
                        col = uiLayoutColumn(row, FALSE);
-                       uiDefButI(block, SCROLL, 0, "", 0, 0, UI_UNIT_X * 0.75, UI_UNIT_Y * items, &pa->list_scroll, 0, len - items, items, 0, "");
+                       uiDefButI(block, SCROLL, 0, "", 0, 0, UI_UNIT_X * 0.75, UI_UNIT_Y * items, &ui_list->list_scroll,
+                                 0, len - items, items, 0, "");
+               }
+               break;
+       case UILST_LAYOUT_COMPACT:
+               row = uiLayoutRow(layout, TRUE);
+
+               if (dataptr->data && prop) {
+                       /* create list items */
+                       RNA_PROP_BEGIN (dataptr, itemptr, prop)
+                       {
+                               found = (activei == i);
+
+                               if (found) {
+                                       icon = UI_rnaptr_icon_get(C, &itemptr, rnaicon, FALSE);
+                                       if (icon == ICON_DOT)
+                                               icon = ICON_NONE;
+                                       draw_item(ui_list, C, row, dataptr, &itemptr, icon, active_dataptr, active_propname, i);
+                               }
+
+                               i++;
+                       }
+                       RNA_PROP_END;
+               }
+
+               /* if list is empty, add in dummy button */
+               if (i == 0)
+                       uiItemL(row, "", ICON_NONE);
+
+               /* next/prev button */
+               BLI_snprintf(numstr, sizeof(numstr), "%d :", i);
+               but = uiDefIconTextButR_prop(block, NUM, 0, 0, numstr, 0, 0, UI_UNIT_X * 5, UI_UNIT_Y,
+                                            active_dataptr, activeprop, 0, 0, 0, 0, 0, "");
+               if (i == 0)
+                       uiButSetFlag(but, UI_BUT_DISABLED);
+               break;
+       case UILST_LAYOUT_GRID:
+               box = uiLayoutListBox(layout, ui_list, dataptr, prop, active_dataptr, activeprop);
+               col = uiLayoutColumn(box, TRUE);
+               row = uiLayoutRow(col, FALSE);
+
+               if (dataptr->data && prop) {
+                       /* create list items */
+                       RNA_PROP_BEGIN (dataptr, itemptr, prop)
+                       {
+                               /* create button */
+                               if (!(i % 9))
+                                       row = uiLayoutRow(col, FALSE);
+
+                               subblock = uiLayoutGetBlock(row);
+                               overlap = uiLayoutOverlap(row);
+
+                               /* list item behind label & other buttons */
+                               sub = uiLayoutRow(overlap, FALSE);
+
+                               but = uiDefButR_prop(subblock, LISTROW, 0, "", 0, 0, UI_UNIT_X * 10, UI_UNIT_Y,
+                                                    active_dataptr, activeprop, 0, 0, i, 0, 0, "");
+                               uiButSetFlag(but, UI_BUT_NO_TOOLTIP);
+
+                               sub = uiLayoutRow(overlap, FALSE);
+
+                               icon = UI_rnaptr_icon_get(C, &itemptr, rnaicon, FALSE);
+                               draw_item(ui_list, C, sub, dataptr, &itemptr, icon, active_dataptr, active_propname, i);
+
+                               i++;
+                       }
+                       RNA_PROP_END;
                }
+               break;
        }
 }
 
@@ -2532,9 +2720,12 @@ static void operator_search_cb(const bContext *C, void *UNUSED(arg), const char
 {
        GHashIterator *iter = WM_operatortype_iter();
 
-       for (; !BLI_ghashIterator_isDone(iter); BLI_ghashIterator_step(iter)) {
+       for (; BLI_ghashIterator_notDone(iter); BLI_ghashIterator_step(iter)) {
                wmOperatorType *ot = BLI_ghashIterator_getValue(iter);
 
+               if ((ot->flag & OPTYPE_INTERNAL) && (G.debug & G_DEBUG_WM) == 0)
+                       continue;
+
                if (BLI_strcasestr(ot->name, str)) {
                        if (WM_operator_poll((bContext *)C, ot)) {
                                char name[256];
@@ -2560,6 +2751,11 @@ static void operator_search_cb(const bContext *C, void *UNUSED(arg), const char
        BLI_ghashIterator_free(iter);
 }
 
+void uiOperatorSearch_But(uiBut *but)
+{
+       uiButSetSearchFunc(but, operator_search_cb, NULL, operator_call_cb, NULL);
+}
+
 void uiTemplateOperatorSearch(uiLayout *layout)
 {
        uiBlock *block;
@@ -2570,7 +2766,7 @@ void uiTemplateOperatorSearch(uiLayout *layout)
        uiBlockSetCurLayout(block, layout);
 
        but = uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, sizeof(search), 0, 0, UI_UNIT_X * 6, UI_UNIT_Y, 0, 0, "");
-       uiButSetSearchFunc(but, operator_search_cb, NULL, operator_call_cb, NULL);
+       uiOperatorSearch_But(but);
 }
 
 /************************* Running Jobs Template **************************/
@@ -2660,19 +2856,19 @@ void uiTemplateRunningJobs(uiLayout *layout, bContext *C)
                ui_abs = uiLayoutAbsolute(layout, FALSE);
                (void)ui_abs;  /* UNUSED */
                
-               uiDefIconBut(block, BUT, handle_event, ICON_PANEL_CLOSE, 
-                            0, UI_UNIT_Y * 0.1, UI_UNIT_X * 0.8, UI_UNIT_Y * 0.8, NULL, 0.0f, 0.0f, 0, 0, TIP_("Stop this job"));
+               uiDefIconBut(block, BUT, handle_event, ICON_PANEL_CLOSE, 0, UI_UNIT_Y * 0.1, UI_UNIT_X * 0.8, UI_UNIT_Y * 0.8,
+                            NULL, 0.0f, 0.0f, 0, 0, TIP_("Stop this job"));
                uiDefBut(block, PROGRESSBAR, 0, WM_jobs_name(wm, owner), 
                         UI_UNIT_X, 0, 100, UI_UNIT_Y, NULL, 0.0f, 0.0f, WM_jobs_progress(wm, owner), 0, TIP_("Progress"));
                
                uiLayoutRow(layout, FALSE);
        }
        if (WM_jobs_test(wm, screen, WM_JOB_TYPE_SCREENCAST))
-               uiDefIconTextBut(block, BUT, B_STOPCAST, ICON_CANCEL, IFACE_("Capture"), 0, 0, 85, UI_UNIT_Y, NULL, 0.0f, 0.0f, 0, 0,
-                                TIP_("Stop screencast"));
+               uiDefIconTextBut(block, BUT, B_STOPCAST, ICON_CANCEL, IFACE_("Capture"), 0, 0, 85, UI_UNIT_Y,
+                                NULL, 0.0f, 0.0f, 0, 0, TIP_("Stop screencast"));
        if (screen->animtimer)
-               uiDefIconTextBut(block, BUT, B_STOPANIM, ICON_CANCEL, TIP_("Anim Player"), 0, 0, 100, UI_UNIT_Y, NULL, 0.0f, 0.0f, 0, 0,
-                                TIP_("Stop animation playback"));
+               uiDefIconTextBut(block, BUT, B_STOPANIM, ICON_CANCEL, IFACE_("Anim Player"), 0, 0, 100, UI_UNIT_Y,
+                                NULL, 0.0f, 0.0f, 0, 0, TIP_("Stop animation playback"));
 }
 
 /************************* Reports for Last Operator Template **************************/
@@ -2701,8 +2897,8 @@ void uiTemplateReportsBanner(uiLayout *layout, bContext *C)
        block = uiLayoutGetBlock(ui_abs);
        
        width = BLF_width(style->widget.uifont_id, report->message);
-       width = MIN2(rti->widthfac * width, width);
-       width = MAX2(width, 10);
+       width = min_ii((int)(rti->widthfac * width), width);
+       width = max_ii(width, 10);
        
        /* make a box around the report to make it stand out */
        uiBlockBeginAlign(block);
@@ -2711,7 +2907,8 @@ void uiTemplateReportsBanner(uiLayout *layout, bContext *C)
        rgb_float_to_uchar(but->col, rti->col);
        but->col[3] = 255;
 
-       but = uiDefBut(block, ROUNDBOX, 0, "", UI_UNIT_X + 10, 0, UI_UNIT_X + width, UI_UNIT_Y, NULL, 0.0f, 0.0f, 0, 0, "");
+       but = uiDefBut(block, ROUNDBOX, 0, "", UI_UNIT_X + 10, 0, UI_UNIT_X + width, UI_UNIT_Y,
+                      NULL, 0.0f, 0.0f, 0, 0, "");
        but->col[0] = but->col[1] = but->col[2] = FTOCHAR(rti->grayscale);
        but->col[3] = 255;
 
@@ -2732,14 +2929,15 @@ void uiTemplateReportsBanner(uiLayout *layout, bContext *C)
        uiBlockSetEmboss(block, UI_EMBOSSN);
 
        if (reports->list.first != reports->list.last)
-               uiDefIconButO(block, BUT, "UI_OT_reports_to_textblock", WM_OP_INVOKE_REGION_WIN, icon, 2, 0,
-                             UI_UNIT_X, UI_UNIT_Y, TIP_("Click to see the remaining reports in text block: 'Recent Reports'"));
+               uiDefIconButO(block, BUT, "UI_OT_reports_to_textblock", WM_OP_INVOKE_REGION_WIN, icon, 2, 0, UI_UNIT_X,
+                             UI_UNIT_Y, TIP_("Click to see the remaining reports in text block: 'Recent Reports'"));
        else
                uiDefIconBut(block, LABEL, 0, icon, 2, 0, UI_UNIT_X, UI_UNIT_Y, NULL, 0.0f, 0.0f, 0, 0, "");
 
        uiBlockSetEmboss(block, UI_EMBOSS);
        
-       uiDefBut(block, LABEL, 0, report->message, UI_UNIT_X + 10, 0, UI_UNIT_X + width, UI_UNIT_Y, NULL, 0.0f, 0.0f, 0, 0, "");
+       uiDefBut(block, LABEL, 0, report->message, UI_UNIT_X + 10, 0, UI_UNIT_X + width, UI_UNIT_Y,
+                NULL, 0.0f, 0.0f, 0, 0, "");
 }
 
 /********************************* Keymap *************************************/
@@ -2818,7 +3016,7 @@ void uiTemplateColorspaceSettings(uiLayout *layout, PointerRNA *ptr, const char
 
        colorspace_settings_ptr = RNA_property_pointer_get(ptr, prop);
 
-       uiItemL(layout, "Color Space:", ICON_NONE);
+       uiItemL(layout, IFACE_("Input Color Space:"), ICON_NONE);
        uiItemR(layout, &colorspace_settings_ptr, "name", 0, "", ICON_NONE);
 }