- added GCC warning -Wstrict-prototypes
[blender.git] / source / blender / editors / space_outliner / outliner.c
index fc08f3390c9781bb2620ed75ab8634e78bb98371..f9c5661b51d833827e771c34938d41c6caaa8eda 100644 (file)
@@ -59,7 +59,6 @@
 # include <fnmatch.h>
 #endif
 
-#include "IMB_imbuf_types.h"
 
 #include "BKE_animsys.h"
 #include "BKE_context.h"
 #define OL_H   19
 #define OL_X   18
 
+#define OL_Y_OFFSET    2
+
 #define OL_TOG_RESTRICT_VIEWX  54
 #define OL_TOG_RESTRICT_SELECTX        36
 #define OL_TOG_RESTRICT_RENDERX        18
 
 /* ************* XXX **************** */
 
-static void error(const char *dummy, ...) {}
+static void error(const char *UNUSED(arg), ...) {}
 
 /* ********************************** */
 
@@ -339,7 +340,7 @@ static int treesort_alpha(const void *v1, const void *v2)
        if(comp==1) return 1;
        else if(comp==2) return -1;
        else if(comp==3) {
-               int comp= strcmp(x1->name, x2->name);
+               comp= strcmp(x1->name, x2->name);
                
                if( comp>0 ) return 1;
                else if( comp<0) return -1;
@@ -1552,17 +1553,44 @@ static void outliner_set_flag(SpaceOops *soops, ListBase *lb, short flag, short
 
 /* --- */
 
-void object_toggle_visibility_cb(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
+/* same check needed for both object operation and restrict column button func
+ * return 0 when in edit mode (cannot restrict view or select)
+ * otherwise return 1 */
+static int common_restrict_check(bContext *C, Object *ob)
+{
+       /* Don't allow hide an object in edit mode,
+        * check the bug #22153 and #21609, #23977
+        */
+       Object *obedit= CTX_data_edit_object(C);
+       if (obedit && obedit == ob) {
+               /* found object is hidden, reset */
+               if (ob->restrictflag & OB_RESTRICT_VIEW)
+                       ob->restrictflag &= ~OB_RESTRICT_VIEW;
+               /* found object is unselectable, reset */
+               if (ob->restrictflag & OB_RESTRICT_SELECT)
+                       ob->restrictflag &= ~OB_RESTRICT_SELECT;
+               return 0;
+       }
+       
+       return 1;
+}
+
+void object_toggle_visibility_cb(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
 {
        Base *base= (Base *)te->directdata;
+       Object *ob = (Object *)tselem->id;
        
-       if(base==NULL) base= object_in_scene((Object *)tselem->id, scene);
-       if(base) {
-               base->object->restrictflag^=OB_RESTRICT_VIEW;
+       /* add check for edit mode */
+       if(!common_restrict_check(C, ob)) return;
+       
+       if(base || (base= object_in_scene(ob, scene))) {
+               if((base->object->restrictflag ^= OB_RESTRICT_VIEW)) {
+                       ED_base_object_select(base, BA_DESELECT);
+               }
        }
 }
 
-static int outliner_toggle_visibility_exec(bContext *C, wmOperator *op)
+static int outliner_toggle_visibility_exec(bContext *C, wmOperator *UNUSED(op))
 {
        SpaceOops *soops= CTX_wm_space_outliner(C);
        Scene *scene= CTX_data_scene(C);
@@ -1570,6 +1598,7 @@ static int outliner_toggle_visibility_exec(bContext *C, wmOperator *op)
        
        outliner_do_object_operation(C, scene, soops, &soops->tree, object_toggle_visibility_cb);
        
+       WM_event_add_notifier(C, NC_SCENE|ND_OB_VISIBLE, scene);
        ED_region_tag_redraw(ar);
        
        return OPERATOR_FINISHED;
@@ -1578,20 +1607,20 @@ static int outliner_toggle_visibility_exec(bContext *C, wmOperator *op)
 void OUTLINER_OT_visibility_toggle(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Toggle Visability";
+       ot->name= "Toggle Visibility";
        ot->idname= "OUTLINER_OT_visibility_toggle";
        ot->description= "Toggle the visibility of selected items";
        
        /* callbacks */
        ot->exec= outliner_toggle_visibility_exec;
-       ot->poll= ED_operator_outliner_active;
+       ot->poll= ED_operator_outliner_active_no_editobject;
        
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
 /* --- */
 
-static void object_toggle_selectability_cb(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
+static void object_toggle_selectability_cb(bContext *UNUSED(C), Scene *scene, TreeElement *te, TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
 {
        Base *base= (Base *)te->directdata;
        
@@ -1601,7 +1630,7 @@ static void object_toggle_selectability_cb(bContext *C, Scene *scene, TreeElemen
        }
 }
 
-static int outliner_toggle_selectability_exec(bContext *C, wmOperator *op)
+static int outliner_toggle_selectability_exec(bContext *C, wmOperator *UNUSED(op))
 {
        SpaceOops *soops= CTX_wm_space_outliner(C);
        Scene *scene= CTX_data_scene(C);
@@ -1609,6 +1638,7 @@ static int outliner_toggle_selectability_exec(bContext *C, wmOperator *op)
        
        outliner_do_object_operation(C, scene, soops, &soops->tree, object_toggle_selectability_cb);
        
+       WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene);
        ED_region_tag_redraw(ar);
        
        return OPERATOR_FINISHED;
@@ -1623,12 +1653,12 @@ void OUTLINER_OT_selectability_toggle(wmOperatorType *ot)
        
        /* callbacks */
        ot->exec= outliner_toggle_selectability_exec;
-       ot->poll= ED_operator_outliner_active;
+       ot->poll= ED_operator_outliner_active_no_editobject;
        
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
-void object_toggle_renderability_cb(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
+void object_toggle_renderability_cb(bContext *UNUSED(C), Scene *scene, TreeElement *te, TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
 {
        Base *base= (Base *)te->directdata;
        
@@ -1638,7 +1668,7 @@ void object_toggle_renderability_cb(bContext *C, Scene *scene, TreeElement *te,
        }
 }
 
-static int outliner_toggle_renderability_exec(bContext *C, wmOperator *op)
+static int outliner_toggle_renderability_exec(bContext *C, wmOperator *UNUSED(op))
 {
        SpaceOops *soops= CTX_wm_space_outliner(C);
        Scene *scene= CTX_data_scene(C);
@@ -1667,7 +1697,7 @@ void OUTLINER_OT_renderability_toggle(wmOperatorType *ot)
 
 /* --- */
 
-static int outliner_toggle_expanded_exec(bContext *C, wmOperator *op)
+static int outliner_toggle_expanded_exec(bContext *C, wmOperator *UNUSED(op))
 {
        SpaceOops *soops= CTX_wm_space_outliner(C);
        ARegion *ar= CTX_wm_region(C);
@@ -1698,10 +1728,11 @@ void OUTLINER_OT_expanded_toggle(wmOperatorType *ot)
 
 /* --- */
 
-static int outliner_toggle_selected_exec(bContext *C, wmOperator *op)
+static int outliner_toggle_selected_exec(bContext *C, wmOperator *UNUSED(op))
 {
        SpaceOops *soops= CTX_wm_space_outliner(C);
        ARegion *ar= CTX_wm_region(C);
+       Scene *scene= CTX_data_scene(C);
        
        if (outliner_has_one_flag(soops, &soops->tree, TSE_SELECTED, 1))
                outliner_set_flag(soops, &soops->tree, TSE_SELECTED, 0);
@@ -1710,6 +1741,7 @@ static int outliner_toggle_selected_exec(bContext *C, wmOperator *op)
        
        soops->storeflag |= SO_TREESTORE_REDRAW;
        
+       WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene);
        ED_region_tag_redraw(ar);
        
        return OPERATOR_FINISHED;
@@ -1788,6 +1820,8 @@ void OUTLINER_OT_show_one_level(wmOperatorType *ot)
        RNA_def_boolean(ot->srna, "open", 1, "Open", "Expand all entries one level deep.");
 }
 
+/* This is not used anywhere at the moment */
+#if 0
 /* return 1 when levels were opened */
 static int outliner_open_back(SpaceOops *soops, TreeElement *te)
 {
@@ -1804,8 +1838,6 @@ static int outliner_open_back(SpaceOops *soops, TreeElement *te)
        return retval;
 }
 
-/* This is not used anywhere at the moment */
-#if 0
 static void outliner_open_reveal(SpaceOops *soops, ListBase *lb, TreeElement *teFind, int *found)
 {
        TreeElement *te;
@@ -1831,7 +1863,7 @@ static void outliner_open_reveal(SpaceOops *soops, ListBase *lb, TreeElement *te
 #endif
 
 // XXX just use View2D ops for this?
-void outliner_page_up_down(Scene *scene, ARegion *ar, SpaceOops *soops, int up)
+void outliner_page_up_down(Scene *UNUSED(scene), ARegion *ar, SpaceOops *soops, int up)
 {
        int dy= ar->v2d.mask.ymax-ar->v2d.mask.ymin;
        
@@ -1884,8 +1916,8 @@ static void tree_element_set_active_object(bContext *C, Scene *scene, SpaceOops
        }
        
        /* find associated base in current scene */
-       for(base= FIRSTBASE; base; base= base->next) 
-               if(base->object==ob) break;
+       base= object_in_scene(ob, scene);
+
        if(base) {
                if(set==2) {
                        /* swap select */
@@ -1895,23 +1927,18 @@ static void tree_element_set_active_object(bContext *C, Scene *scene, SpaceOops
                                ED_base_object_select(base, BA_SELECT);
                }
                else {
-                       Base *b;
                        /* deleselect all */
-                       for(b= FIRSTBASE; b; b= b->next) {
-                               b->flag &= ~SELECT;
-                               b->object->flag= b->flag;
-                       }
+                       scene_deselect_all(scene);
                        ED_base_object_select(base, BA_SELECT);
                }
-               if(C)
+               if(C) {
                        ED_base_object_activate(C, base); /* adds notifier */
+                       WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene);
+               }
        }
        
        if(ob!=scene->obedit) 
                ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR|EM_DO_UNDO);
-       
-       WM_event_add_notifier(C, NC_SCENE|ND_OB_ACTIVE, scene);
-
 }
 
 static int tree_element_active_material(bContext *C, Scene *scene, SpaceOops *soops, TreeElement *te, int set)
@@ -2022,11 +2049,14 @@ static int tree_element_active_texture(bContext *C, Scene *scene, SpaceOops *soo
                }
        }
        
+       if(set)
+               WM_event_add_notifier(C, NC_TEXTURE, NULL);
+
        return 0;
 }
 
 
-static int tree_element_active_lamp(bContext *C, Scene *scene, SpaceOops *soops, TreeElement *te, int set)
+static int tree_element_active_lamp(bContext *UNUSED(C), Scene *scene, SpaceOops *soops, TreeElement *te, int set)
 {
        Object *ob;
        
@@ -2116,8 +2146,8 @@ static int tree_element_active_posechannel(bContext *C, Scene *scene, TreeElemen
        if(set) {
                if(!(pchan->bone->flag & BONE_HIDDEN_P)) {
                        
-                       if(set==2) ED_pose_deselectall(ob, 2, 0);       // 2 = clear active tag
-                       else ED_pose_deselectall(ob, 0, 0);     // 0 = deselect 
+                       if(set==2) ED_pose_deselectall(ob, 2);  // 2 = clear active tag
+                       else ED_pose_deselectall(ob, 0);        // 0 = deselect 
                        
                        if(set==2 && (pchan->bone->flag & BONE_SELECTED)) {
                                pchan->bone->flag &= ~BONE_SELECTED;
@@ -2147,8 +2177,8 @@ static int tree_element_active_bone(bContext *C, Scene *scene, TreeElement *te,
        
        if(set) {
                if(!(bone->flag & BONE_HIDDEN_P)) {
-                       if(set==2) ED_pose_deselectall(OBACT, 2, 0);    // 2 is clear active tag
-                       else ED_pose_deselectall(OBACT, 0, 0);
+                       if(set==2) ED_pose_deselectall(OBACT, 2);       // 2 is clear active tag
+                       else ED_pose_deselectall(OBACT, 0);
                        
                        if(set==2 && (bone->flag & BONE_SELECTED)) {
                                bone->flag &= ~BONE_SELECTED;
@@ -2174,15 +2204,15 @@ static int tree_element_active_bone(bContext *C, Scene *scene, TreeElement *te,
 
 
 /* ebones only draw in editmode armature */
-static int tree_element_active_ebone(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
+static int tree_element_active_ebone(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *UNUSED(tselem), int set)
 {
        EditBone *ebone= te->directdata;
        
        if(set) {
                if(!(ebone->flag & BONE_HIDDEN_A)) {
                        bArmature *arm= scene->obedit->data;
-                       if(set==2) ED_armature_deselectall(scene->obedit, 2, 0);        // only clear active tag
-                       else ED_armature_deselectall(scene->obedit, 0, 0);      // deselect
+                       if(set==2) ED_armature_deselect_all(scene->obedit, 2);  // only clear active tag
+                       else ED_armature_deselect_all(scene->obedit, 0);        // deselect
 
                        ebone->flag |= BONE_SELECTED|BONE_ROOTSEL|BONE_TIPSEL;
                        arm->act_edbone= ebone;
@@ -2199,7 +2229,7 @@ static int tree_element_active_ebone(bContext *C, Scene *scene, TreeElement *te,
        return 0;
 }
 
-static int tree_element_active_modifier(bContext *C, TreeElement *te, TreeStoreElem *tselem, int set)
+static int tree_element_active_modifier(bContext *C, TreeElement *UNUSED(te), TreeStoreElem *tselem, int set)
 {
        if(set) {
                Object *ob= (Object *)tselem->id;
@@ -2212,7 +2242,7 @@ static int tree_element_active_modifier(bContext *C, TreeElement *te, TreeStoreE
        return 0;
 }
 
-static int tree_element_active_psys(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
+static int tree_element_active_psys(bContext *C, Scene *UNUSED(scene), TreeElement *UNUSED(te), TreeStoreElem *tselem, int set)
 {
        if(set) {
                Object *ob= (Object *)tselem->id;
@@ -2225,7 +2255,7 @@ static int tree_element_active_psys(bContext *C, Scene *scene, TreeElement *te,
        return 0;
 }
 
-static int tree_element_active_constraint(bContext *C, TreeElement *te, TreeStoreElem *tselem, int set)
+static int tree_element_active_constraint(bContext *C, TreeElement *UNUSED(te), TreeStoreElem *tselem, int set)
 {
        if(set) {
                Object *ob= (Object *)tselem->id;
@@ -2237,7 +2267,7 @@ static int tree_element_active_constraint(bContext *C, TreeElement *te, TreeStor
        return 0;
 }
 
-static int tree_element_active_text(bContext *C, Scene *scene, SpaceOops *soops, TreeElement *te, int set)
+static int tree_element_active_text(bContext *UNUSED(C), Scene *UNUSED(scene), SpaceOops *UNUSED(soops), TreeElement *UNUSED(te), int UNUSED(set))
 {
        // XXX removed
        return 0;
@@ -2262,7 +2292,7 @@ static int tree_element_active(bContext *C, Scene *scene, SpaceOops *soops, Tree
        return 0;
 }
 
-static int tree_element_active_pose(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
+static int tree_element_active_pose(bContext *C, Scene *scene, TreeElement *UNUSED(te), TreeStoreElem *tselem, int set)
 {
        Object *ob= (Object *)tselem->id;
        Base *base= object_in_scene(ob, scene);
@@ -2282,7 +2312,7 @@ static int tree_element_active_pose(bContext *C, Scene *scene, TreeElement *te,
        return 0;
 }
 
-static int tree_element_active_sequence(bContext *C, TreeElement *te, TreeStoreElem *tselem, int set)
+static int tree_element_active_sequence(TreeElement *te, TreeStoreElem *UNUSED(tselem), int set)
 {
        Sequence *seq= (Sequence*) te->directdata;
 
@@ -2296,7 +2326,7 @@ static int tree_element_active_sequence(bContext *C, TreeElement *te, TreeStoreE
        return(0);
 }
 
-static int tree_element_active_sequence_dup(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
+static int tree_element_active_sequence_dup(Scene *scene, TreeElement *te, TreeStoreElem *UNUSED(tselem), int set)
 {
        Sequence *seq, *p;
        Editing *ed= seq_give_editing(scene, FALSE);
@@ -2323,7 +2353,7 @@ static int tree_element_active_sequence_dup(bContext *C, Scene *scene, TreeEleme
        return(0);
 }
 
-static int tree_element_active_keymap_item(bContext *C, TreeElement *te, TreeStoreElem *tselem, int set)
+static int tree_element_active_keymap_item(bContext *UNUSED(C), TreeElement *te, TreeStoreElem *UNUSED(tselem), int set)
 {
        wmKeyMapItem *kmi= te->directdata;
        
@@ -2368,9 +2398,9 @@ static int tree_element_type_active(bContext *C, Scene *scene, SpaceOops *soops,
                case TSE_POSEGRP:
                        return tree_element_active_posegroup(C, scene, te, tselem, set);
                case TSE_SEQUENCE:
-                       return tree_element_active_sequence(C, te, tselem, set);
+                       return tree_element_active_sequence(te, tselem, set);
                case TSE_SEQUENCE_DUP:
-                       return tree_element_active_sequence_dup(C, scene, te, tselem, set);
+                       return tree_element_active_sequence_dup(scene, te, tselem, set);
                case TSE_KEYMAP_ITEM:
                        return tree_element_active_keymap_item(C, te, tselem, set);
                        
@@ -2406,7 +2436,7 @@ static int do_outliner_item_activate(bContext *C, Scene *scene, ARegion *ar, Spa
                        return 1;
                }
                /* name and first icon */
-               else if(mval[0]>te->xs && mval[0]<te->xend) {
+               else if(mval[0]>te->xs+OL_X && mval[0]<te->xend) {
                        
                        /* always makes active object */
                        if(tselem->type!=TSE_SEQUENCE && tselem->type!=TSE_SEQ_STRIP && tselem->type!=TSE_SEQUENCE_DUP)
@@ -2502,7 +2532,7 @@ static int outliner_item_activate(bContext *C, wmOperator *op, wmEvent *event)
                int row;
                
                /* get row number - 100 here is just a dummy value since we don't need the column */
-               UI_view2d_listview_view_to_cell(&ar->v2d, 1000, OL_H, 0.0f, 0.0f
+               UI_view2d_listview_view_to_cell(&ar->v2d, 1000, OL_H, 0.0f, OL_Y_OFFSET
                                                fmval[0], fmval[1], NULL, &row);
                
                /* select relevant row */
@@ -2603,7 +2633,7 @@ static int do_outliner_item_rename(bContext *C, ARegion *ar, SpaceOops *soops, T
                TreeStoreElem *tselem= TREESTORE(te);
                
                /* name and first icon */
-               if(mval[0]>te->xs && mval[0]<te->xend) {
+               if(mval[0]>te->xs+OL_X && mval[0]<te->xend) {
                        
                        /* can't rename rna datablocks entries */
                        if(ELEM3(tselem->type, TSE_RNA_STRUCT, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM))
@@ -2630,7 +2660,7 @@ static int do_outliner_item_rename(bContext *C, ARegion *ar, SpaceOops *soops, T
        return 0;
 }
 
-static int outliner_item_rename(bContext *C, wmOperator *op, wmEvent *event)
+static int outliner_item_rename(bContext *C, wmOperator *UNUSED(op), wmEvent *event)
 {
        ARegion *ar= CTX_wm_region(C);
        SpaceOops *soops= CTX_wm_space_outliner(C);
@@ -2657,39 +2687,6 @@ void OUTLINER_OT_item_rename(wmOperatorType *ot)
        ot->poll= ED_operator_outliner_active;
 }
 
-
-
-/* recursive helper for function below */
-static void outliner_set_coordinates_element(SpaceOops *soops, TreeElement *te, int startx, int *starty)
-{
-       TreeStoreElem *tselem= TREESTORE(te);
-       
-       /* store coord and continue, we need coordinates for elements outside view too */
-       te->xs= (float)startx;
-       te->ys= (float)(*starty);
-       *starty-= OL_H;
-       
-       if((tselem->flag & TSE_CLOSED)==0) {
-               TreeElement *ten;
-               for(ten= te->subtree.first; ten; ten= ten->next) {
-                       outliner_set_coordinates_element(soops, ten, startx+OL_X, starty);
-               }
-       }
-       
-}
-
-/* to retrieve coordinates with redrawing the entire tree */
-static void outliner_set_coordinates(ARegion *ar, SpaceOops *soops)
-{
-       TreeElement *te;
-       int starty= (int)(ar->v2d.tot.ymax)-OL_H;
-       int startx= 0;
-       
-       for(te= soops->tree.first; te; te= te->next) {
-               outliner_set_coordinates_element(soops, te, startx, &starty);
-       }
-}
-
 static TreeElement *outliner_find_id(SpaceOops *soops, ListBase *lb, ID *id)
 {
        TreeElement *te, *tes;
@@ -2709,7 +2706,7 @@ static TreeElement *outliner_find_id(SpaceOops *soops, ListBase *lb, ID *id)
        return NULL;
 }
 
-static int outliner_show_active_exec(bContext *C, wmOperator *op)
+static int outliner_show_active_exec(bContext *C, wmOperator *UNUSED(op))
 {
        SpaceOops *so= CTX_wm_space_outliner(C);
        Scene *scene= CTX_data_scene(C);
@@ -2759,6 +2756,66 @@ void OUTLINER_OT_show_active(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
+/* tse is not in the treestore, we use its contents to find a match */
+static TreeElement *outliner_find_tse(SpaceOops *soops, TreeStoreElem *tse)
+{
+       TreeStore *ts= soops->treestore;
+       TreeStoreElem *tselem;
+       int a;
+       
+       if(tse->id==NULL) return NULL;
+       
+       /* check if 'tse' is in treestore */
+       tselem= ts->data;
+       for(a=0; a<ts->usedelem; a++, tselem++) {
+               if((tse->type==0 && tselem->type==0) || (tselem->type==tse->type && tselem->nr==tse->nr)) {
+                       if(tselem->id==tse->id) {
+                               break;
+                       }
+               }
+       }
+       if(tselem) 
+               return outliner_find_tree_element(&soops->tree, a);
+       
+       return NULL;
+}
+
+
+/* Called to find an item based on name.
+ */
+#if 0
+
+/* recursive helper for function below */
+static void outliner_set_coordinates_element(SpaceOops *soops, TreeElement *te, int startx, int *starty)
+{
+       TreeStoreElem *tselem= TREESTORE(te);
+       
+       /* store coord and continue, we need coordinates for elements outside view too */
+       te->xs= (float)startx;
+       te->ys= (float)(*starty);
+       *starty-= OL_H;
+       
+       if((tselem->flag & TSE_CLOSED)==0) {
+               TreeElement *ten;
+               for(ten= te->subtree.first; ten; ten= ten->next) {
+                       outliner_set_coordinates_element(soops, ten, startx+OL_X, starty);
+               }
+       }
+       
+}
+
+/* to retrieve coordinates with redrawing the entire tree */
+static void outliner_set_coordinates(ARegion *ar, SpaceOops *soops)
+{
+       TreeElement *te;
+       int starty= (int)(ar->v2d.tot.ymax)-OL_H;
+       int startx= 0;
+       
+       for(te= soops->tree.first; te; te= te->next) {
+               outliner_set_coordinates_element(soops, te, startx, &starty);
+       }
+}
+
 /* find next element that has this name */
 static TreeElement *outliner_find_named(SpaceOops *soops, ListBase *lb, char *name, int flags, TreeElement *prev, int *prevFound)
 {
@@ -2788,34 +2845,7 @@ static TreeElement *outliner_find_named(SpaceOops *soops, ListBase *lb, char *na
        return NULL;
 }
 
-/* tse is not in the treestore, we use its contents to find a match */
-static TreeElement *outliner_find_tse(SpaceOops *soops, TreeStoreElem *tse)
-{
-       TreeStore *ts= soops->treestore;
-       TreeStoreElem *tselem;
-       int a;
-       
-       if(tse->id==NULL) return NULL;
-       
-       /* check if 'tse' is in treestore */
-       tselem= ts->data;
-       for(a=0; a<ts->usedelem; a++, tselem++) {
-               if((tse->type==0 && tselem->type==0) || (tselem->type==tse->type && tselem->nr==tse->nr)) {
-                       if(tselem->id==tse->id) {
-                               break;
-                       }
-               }
-       }
-       if(tselem) 
-               return outliner_find_tree_element(&soops->tree, a);
-       
-       return NULL;
-}
-
-
-/* Called to find an item based on name.
- */
-void outliner_find_panel(Scene *scene, ARegion *ar, SpaceOops *soops, int again, int flags) 
+static void outliner_find_panel(Scene *UNUSED(scene), ARegion *ar, SpaceOops *soops, int again, int flags) 
 {
        TreeElement *te= NULL;
        TreeElement *last_find;
@@ -2887,6 +2917,7 @@ void outliner_find_panel(Scene *scene, ARegion *ar, SpaceOops *soops, int again,
                error("Not found: %s", name);
        }
 }
+#endif
 
 /* helper function for tree_element_shwo_hierarchy() - recursively checks whether subtrees have any objects*/
 static int subtree_has_objects(SpaceOops *soops, ListBase *lb)
@@ -2929,7 +2960,7 @@ static void tree_element_show_hierarchy(Scene *scene, SpaceOops *soops, ListBase
 }
 
 /* show entire object level hierarchy */
-static int outliner_show_hierarchy_exec(bContext *C, wmOperator *op)
+static int outliner_show_hierarchy_exec(bContext *C, wmOperator *UNUSED(op))
 {
        SpaceOops *soops= CTX_wm_space_outliner(C);
        ARegion *ar= CTX_wm_region(C);
@@ -3047,7 +3078,7 @@ static void set_operation_types(SpaceOops *soops, ListBase *lb,
        }
 }
 
-static void unlink_material_cb(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
+static void unlink_material_cb(bContext *UNUSED(C), Scene *UNUSED(scene), TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *UNUSED(tselem))
 {
        Material **matar=NULL;
        int a, totcol=0;
@@ -3081,7 +3112,7 @@ static void unlink_material_cb(bContext *C, Scene *scene, TreeElement *te, TreeS
        }
 }
 
-static void unlink_texture_cb(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
+static void unlink_texture_cb(bContext *UNUSED(C), Scene *UNUSED(scene), TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *UNUSED(tselem))
 {
        MTex **mtex= NULL;
        int a;
@@ -3110,7 +3141,7 @@ static void unlink_texture_cb(bContext *C, Scene *scene, TreeElement *te, TreeSt
        }
 }
 
-static void unlink_group_cb(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
+static void unlink_group_cb(bContext *UNUSED(C), Scene *UNUSED(scene), TreeElement *UNUSED(te), TreeStoreElem *tsep, TreeStoreElem *tselem)
 {
        Group *group= (Group *)tselem->id;
        
@@ -3147,7 +3178,7 @@ static void outliner_do_libdata_operation(bContext *C, Scene *scene, SpaceOops *
 
 /* */
 
-static void object_select_cb(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
+static void object_select_cb(bContext *UNUSED(C), Scene *scene, TreeElement *te, TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
 {
        Base *base= (Base *)te->directdata;
        
@@ -3158,7 +3189,7 @@ static void object_select_cb(bContext *C, Scene *scene, TreeElement *te, TreeSto
        }
 }
 
-static void object_deselect_cb(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
+static void object_deselect_cb(bContext *UNUSED(C), Scene *scene, TreeElement *te, TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
 {
        Base *base= (Base *)te->directdata;
        
@@ -3169,7 +3200,7 @@ static void object_deselect_cb(bContext *C, Scene *scene, TreeElement *te, TreeS
        }
 }
 
-static void object_delete_cb(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
+static void object_delete_cb(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
 {
        Base *base= (Base *)te->directdata;
        
@@ -3184,12 +3215,10 @@ static void object_delete_cb(bContext *C, Scene *scene, TreeElement *te, TreeSto
                te->directdata= NULL;
                tselem->id= NULL;
        }
-       
-       WM_event_add_notifier(C, NC_SCENE|ND_OB_ACTIVE, scene);
 
 }
 
-static void id_local_cb(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
+static void id_local_cb(bContext *UNUSED(C), Scene *UNUSED(scene), TreeElement *UNUSED(te), TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
 {
        if(tselem->id->lib && (tselem->id->flag & LIB_EXTERN)) {
                tselem->id->lib= NULL;
@@ -3198,7 +3227,7 @@ static void id_local_cb(bContext *C, Scene *scene, TreeElement *te, TreeStoreEle
        }
 }
 
-static void group_linkobs2scene_cb(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
+static void group_linkobs2scene_cb(bContext *UNUSED(C), Scene *scene, TreeElement *UNUSED(te), TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
 {
        Group *group= (Group *)tselem->id;
        GroupObject *gob;
@@ -3222,7 +3251,7 @@ static void group_linkobs2scene_cb(bContext *C, Scene *scene, TreeElement *te, T
        }
 }
 
-static void outliner_do_object_operation(bContext *C, Scene *scene, SpaceOops *soops, ListBase *lb, 
+static void outliner_do_object_operation(bContext *C, Scene *scene_act, SpaceOops *soops, ListBase *lb, 
                                                                                 void (*operation_cb)(bContext *C, Scene *scene, TreeElement *, TreeStoreElem *, TreeStoreElem *))
 {
        TreeElement *te;
@@ -3233,23 +3262,25 @@ static void outliner_do_object_operation(bContext *C, Scene *scene, SpaceOops *s
                if(tselem->flag & TSE_SELECTED) {
                        if(tselem->type==0 && te->idcode==ID_OB) {
                                // when objects selected in other scenes... dunno if that should be allowed
-                               Scene *sce= (Scene *)outliner_search_back(soops, te, ID_SCE);
-                               if(sce && scene != sce) {
-                                       ED_screen_set_scene(C, sce);
+                               Scene *scene_owner= (Scene *)outliner_search_back(soops, te, ID_SCE);
+                               if(scene_owner && scene_act != scene_owner) {
+                                       ED_screen_set_scene(C, scene_owner);
                                }
-                               
-                               operation_cb(C, scene, te, NULL, tselem);
+                               /* important to use 'scene_owner' not scene_act else deleting objects can crash.
+                                * only use 'scene_act' when 'scene_owner' is NULL, which can happen when the
+                                * outliner isnt showing scenes: Visible Layer draw mode for eg. */
+                               operation_cb(C, scene_owner ? scene_owner : scene_act, te, NULL, tselem);
                        }
                }
                if((tselem->flag & TSE_CLOSED)==0) {
-                       outliner_do_object_operation(C, scene, soops, &te->subtree, operation_cb);
+                       outliner_do_object_operation(C, scene_act, soops, &te->subtree, operation_cb);
                }
        }
 }
 
 /* ******************************************** */
 
-static void pchan_cb(int event, TreeElement *te, TreeStoreElem *tselem)
+static void pchan_cb(int event, TreeElement *te, TreeStoreElem *UNUSED(tselem))
 {
        bPoseChannel *pchan= (bPoseChannel *)te->directdata;
        
@@ -3265,7 +3296,7 @@ static void pchan_cb(int event, TreeElement *te, TreeStoreElem *tselem)
                pchan->bone->flag &= ~BONE_HIDDEN_P;
 }
 
-static void bone_cb(int event, TreeElement *te, TreeStoreElem *tselem)
+static void bone_cb(int event, TreeElement *te, TreeStoreElem *UNUSED(tselem))
 {
        Bone *bone= (Bone *)te->directdata;
        
@@ -3281,7 +3312,7 @@ static void bone_cb(int event, TreeElement *te, TreeStoreElem *tselem)
                bone->flag &= ~BONE_HIDDEN_P;
 }
 
-static void ebone_cb(int event, TreeElement *te, TreeStoreElem *tselem)
+static void ebone_cb(int event, TreeElement *te, TreeStoreElem *UNUSED(tselem))
 {
        EditBone *ebone= (EditBone *)te->directdata;
        
@@ -3297,7 +3328,7 @@ static void ebone_cb(int event, TreeElement *te, TreeStoreElem *tselem)
                ebone->flag &= ~BONE_HIDDEN_A;
 }
 
-static void sequence_cb(int event, TreeElement *te, TreeStoreElem *tselem)
+static void sequence_cb(int event, TreeElement *UNUSED(te), TreeStoreElem *UNUSED(tselem))
 {
 //     Sequence *seq= (Sequence*) te->directdata;
        if(event==1) {
@@ -3324,7 +3355,7 @@ static void outliner_do_data_operation(SpaceOops *soops, int type, int event, Li
        }
 }
 
-void outliner_del(bContext *C, Scene *scene, ARegion *ar, SpaceOops *soops)
+void outliner_del(bContext *C, Scene *scene, ARegion *UNUSED(ar), SpaceOops *soops)
 {
        
        if(soops->outlinevis==SO_SEQUENCE)
@@ -3333,6 +3364,7 @@ void outliner_del(bContext *C, Scene *scene, ARegion *ar, SpaceOops *soops)
                outliner_do_object_operation(C, scene, soops, &soops->tree, object_delete_cb);
                DAG_scene_sort(CTX_data_main(C), scene);
                ED_undo_push(C, "Delete Objects");
+               WM_event_add_notifier(C, NC_SCENE|ND_OB_ACTIVE, scene);
        }
 }
 
@@ -3370,34 +3402,38 @@ static int outliner_object_operation_exec(bContext *C, wmOperator *op)
                }
                
                str= "Select Objects";
+               WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene);
        }
        else if(event==2) {
                outliner_do_object_operation(C, scene, soops, &soops->tree, object_deselect_cb);
                str= "Deselect Objects";
+               WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene);
        }
        else if(event==4) {
                outliner_do_object_operation(C, scene, soops, &soops->tree, object_delete_cb);
                DAG_scene_sort(bmain, scene);
                str= "Delete Objects";
+               WM_event_add_notifier(C, NC_SCENE|ND_OB_ACTIVE, scene);
        }
-       else if(event==5) {     /* disabled, see above (ton) */
+       else if(event==5) {     /* disabled, see above enum (ton) */
                outliner_do_object_operation(C, scene, soops, &soops->tree, id_local_cb);
                str= "Localized Objects";
        }
        else if(event==6) {
                outliner_do_object_operation(C, scene, soops, &soops->tree, object_toggle_visibility_cb);
                str= "Toggle Visibility";
+               WM_event_add_notifier(C, NC_SCENE|ND_OB_VISIBLE, scene);
        }
        else if(event==7) {
                outliner_do_object_operation(C, scene, soops, &soops->tree, object_toggle_selectability_cb);
                str= "Toggle Selectability";
+               WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene);
        }
        else if(event==8) {
                outliner_do_object_operation(C, scene, soops, &soops->tree, object_toggle_renderability_cb);
                str= "Toggle Renderability";
+               WM_event_add_notifier(C, NC_SCENE|ND_OB_RENDER, scene);
        }
-       
-       WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene);
 
        ED_undo_push(C, str);
        
@@ -3679,7 +3715,7 @@ static int do_outliner_operation_event(bContext *C, Scene *scene, ARegion *ar, S
 }
 
 
-static int outliner_operation(bContext *C, wmOperator *op, wmEvent *event)
+static int outliner_operation(bContext *C, wmOperator *UNUSED(op), wmEvent *event)
 {
        Scene *scene= CTX_data_scene(C);
        ARegion *ar= CTX_wm_region(C);
@@ -3729,7 +3765,7 @@ static int ed_operator_outliner_datablocks_active(bContext *C)
  * this function does not do that yet 
  */
 static void tree_element_to_path(SpaceOops *soops, TreeElement *te, TreeStoreElem *tselem, 
-                                                       ID **id, char **path, int *array_index, short *flag, short *groupmode)
+                                                       ID **id, char **path, int *array_index, short *flag, short *UNUSED(groupmode))
 {
        ListBase hierarchy = {NULL, NULL};
        LinkData *ld;
@@ -3945,7 +3981,7 @@ static void do_outliner_drivers_editop(SpaceOops *soops, ListBase *tree, short m
 
 /* Add Operator ---------------------------------- */
 
-static int outliner_drivers_addsel_exec(bContext *C, wmOperator *op)
+static int outliner_drivers_addsel_exec(bContext *C, wmOperator *UNUSED(op))
 {
        SpaceOops *soutliner= CTX_wm_space_outliner(C);
        
@@ -3980,7 +4016,7 @@ void OUTLINER_OT_drivers_add_selected(wmOperatorType *ot)
 
 /* Remove Operator ---------------------------------- */
 
-static int outliner_drivers_deletesel_exec(bContext *C, wmOperator *op)
+static int outliner_drivers_deletesel_exec(bContext *C, wmOperator *UNUSED(op))
 {
        SpaceOops *soutliner= CTX_wm_space_outliner(C);
        
@@ -4155,7 +4191,7 @@ void OUTLINER_OT_keyingset_add_selected(wmOperatorType *ot)
 
 /* Remove Operator ---------------------------------- */
 
-static int outliner_keyingset_removeitems_exec(bContext *C, wmOperator *op)
+static int outliner_keyingset_removeitems_exec(bContext *C, wmOperator *UNUSED(op))
 {
        SpaceOops *soutliner= CTX_wm_space_outliner(C);
        Scene *scene= CTX_data_scene(C);
@@ -4715,13 +4751,13 @@ static void outliner_draw_struct_marks(ARegion *ar, SpaceOops *soops, ListBase *
                /* selection status */
                if((tselem->flag & TSE_CLOSED)==0)
                        if(tselem->type == TSE_RNA_STRUCT)
-                               glRecti(0, *starty+1, (int)ar->v2d.cur.xmax, *starty+OL_H-1);
+                               glRecti(0, *starty+1, (int)ar->v2d.cur.xmax+V2D_SCROLL_WIDTH, *starty+OL_H-1);
 
                *starty-= OL_H;
                if((tselem->flag & TSE_CLOSED)==0) {
                        outliner_draw_struct_marks(ar, soops, &te->subtree, starty);
                        if(tselem->type == TSE_RNA_STRUCT)
-                               fdrawline(0, (float)*starty+OL_H-1, ar->v2d.cur.xmax, (float)*starty+OL_H-1);
+                               fdrawline(0, (float)*starty+OL_H, ar->v2d.cur.xmax+V2D_SCROLL_WIDTH, (float)*starty+OL_H);
                }
        }
 }
@@ -4756,24 +4792,24 @@ static void outliner_draw_tree(bContext *C, uiBlock *block, Scene *scene, ARegio
                /* struct marks */
                UI_ThemeColorShadeAlpha(TH_BACK, -15, -200);
                //UI_ThemeColorShade(TH_BACK, -20);
-               starty= (int)ar->v2d.tot.ymax-OL_H;
+               starty= (int)ar->v2d.tot.ymax-OL_H-OL_Y_OFFSET;
                outliner_draw_struct_marks(ar, soops, &soops->tree, &starty);
        }
        
        /* always draw selection fill before hierarchy */
        UI_GetThemeColor3fv(TH_BACK, col);
        glColor3f(col[0]+0.06f, col[1]+0.08f, col[2]+0.10f);
-       starty= (int)ar->v2d.tot.ymax-OL_H;
+       starty= (int)ar->v2d.tot.ymax-OL_H-OL_Y_OFFSET;
        outliner_draw_selection(ar, soops, &soops->tree, &starty);
        
        // grey hierarchy lines
        UI_ThemeColorBlend(TH_BACK, TH_TEXT, 0.2f);
-       starty= (int)ar->v2d.tot.ymax-OL_H/2;
+       starty= (int)ar->v2d.tot.ymax-OL_H/2-OL_Y_OFFSET;
        startx= 6;
        outliner_draw_hierarchy(soops, &soops->tree, startx, &starty);
        
        // items themselves
-       starty= (int)ar->v2d.tot.ymax-OL_H;
+       starty= (int)ar->v2d.tot.ymax-OL_H-OL_Y_OFFSET;
        startx= 0;
        for(te= soops->tree.first; te; te= te->next) {
                outliner_draw_tree_element(C, block, scene, ar, soops, te, startx, &starty);
@@ -4781,31 +4817,31 @@ static void outliner_draw_tree(bContext *C, uiBlock *block, Scene *scene, ARegio
 }
 
 
-static void outliner_back(ARegion *ar, SpaceOops *soops)
+static void outliner_back(ARegion *ar)
 {
        int ystart;
        
        UI_ThemeColorShade(TH_BACK, 6);
        ystart= (int)ar->v2d.tot.ymax;
-       ystart= OL_H*(ystart/(OL_H));
+       ystart= OL_H*(ystart/(OL_H))-OL_Y_OFFSET;
        
        while(ystart+2*OL_H > ar->v2d.cur.ymin) {
-               glRecti(0, ystart, (int)ar->v2d.cur.xmax, ystart+OL_H);
+               glRecti(0, ystart, (int)ar->v2d.cur.xmax+V2D_SCROLL_WIDTH, ystart+OL_H);
                ystart-= 2*OL_H;
        }
 }
 
-static void outliner_draw_restrictcols(ARegion *ar, SpaceOops *soops)
+static void outliner_draw_restrictcols(ARegion *ar)
 {
        int ystart;
        
        /* background underneath */
        UI_ThemeColor(TH_BACK);
-       glRecti((int)ar->v2d.cur.xmax-OL_TOGW, (int)ar->v2d.cur.ymin, (int)ar->v2d.cur.xmax, (int)ar->v2d.cur.ymax);
+       glRecti((int)ar->v2d.cur.xmax-OL_TOGW, (int)ar->v2d.cur.ymin-V2D_SCROLL_HEIGHT-1, (int)ar->v2d.cur.xmax+V2D_SCROLL_WIDTH, (int)ar->v2d.cur.ymax);
        
        UI_ThemeColorShade(TH_BACK, 6);
        ystart= (int)ar->v2d.tot.ymax;
-       ystart= OL_H*(ystart/(OL_H));
+       ystart= OL_H*(ystart/(OL_H))-OL_Y_OFFSET;
        
        while(ystart+2*OL_H > ar->v2d.cur.ymin) {
                glRecti((int)ar->v2d.cur.xmax-OL_TOGW, ystart, (int)ar->v2d.cur.xmax, ystart+OL_H);
@@ -4818,48 +4854,33 @@ static void outliner_draw_restrictcols(ARegion *ar, SpaceOops *soops)
        fdrawline(ar->v2d.cur.xmax-OL_TOG_RESTRICT_VIEWX,
                ar->v2d.cur.ymax,
                ar->v2d.cur.xmax-OL_TOG_RESTRICT_VIEWX,
-               ar->v2d.cur.ymin);
+               ar->v2d.cur.ymin - V2D_SCROLL_HEIGHT);
 
        /* render */
        fdrawline(ar->v2d.cur.xmax-OL_TOG_RESTRICT_SELECTX,
                ar->v2d.cur.ymax,
                ar->v2d.cur.xmax-OL_TOG_RESTRICT_SELECTX,
-               ar->v2d.cur.ymin);
+               ar->v2d.cur.ymin - V2D_SCROLL_HEIGHT);
 
        /* render */
        fdrawline(ar->v2d.cur.xmax-OL_TOG_RESTRICT_RENDERX,
                ar->v2d.cur.ymax,
                ar->v2d.cur.xmax-OL_TOG_RESTRICT_RENDERX,
-               ar->v2d.cur.ymin);
+               ar->v2d.cur.ymin - V2D_SCROLL_HEIGHT);
 }
 
 static void restrictbutton_view_cb(bContext *C, void *poin, void *poin2)
 {
-       Base *base;
        Scene *scene = (Scene *)poin;
        Object *ob = (Object *)poin2;
-       Object *obedit= CTX_data_edit_object(C);
 
-       /* Don't allow hide an objet in edit mode,
-        * check the bug #22153 and #21609
-        */
-       if (obedit && obedit == ob) {
-               if (ob->restrictflag & OB_RESTRICT_VIEW)
-                       ob->restrictflag &= ~OB_RESTRICT_VIEW;
-               return;
-       }
+       if(!common_restrict_check(C, ob)) return;
        
        /* deselect objects that are invisible */
        if (ob->restrictflag & OB_RESTRICT_VIEW) {
-       
                /* Ouch! There is no backwards pointer from Object to Base, 
                 * so have to do loop to find it. */
-               for(base= FIRSTBASE; base; base= base->next) {
-                       if(base->object==ob) {
-                               base->flag &= ~SELECT;
-                               base->object->flag= base->flag;
-                       }
-               }
+               ED_base_object_select(object_in_scene(ob, scene), BA_DESELECT);
        }
        WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene);
 
@@ -4867,37 +4888,32 @@ static void restrictbutton_view_cb(bContext *C, void *poin, void *poin2)
 
 static void restrictbutton_sel_cb(bContext *C, void *poin, void *poin2)
 {
-       Base *base;
        Scene *scene = (Scene *)poin;
        Object *ob = (Object *)poin2;
        
+       if(!common_restrict_check(C, ob)) return;
+       
        /* if select restriction has just been turned on */
        if (ob->restrictflag & OB_RESTRICT_SELECT) {
-       
                /* Ouch! There is no backwards pointer from Object to Base, 
                 * so have to do loop to find it. */
-               for(base= FIRSTBASE; base; base= base->next) {
-                       if(base->object==ob) {
-                               base->flag &= ~SELECT;
-                               base->object->flag= base->flag;
-                       }
-               }
+               ED_base_object_select(object_in_scene(ob, scene), BA_DESELECT);
        }
        WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene);
 
 }
 
-static void restrictbutton_rend_cb(bContext *C, void *poin, void *poin2)
+static void restrictbutton_rend_cb(bContext *C, void *poin, void *UNUSED(poin2))
 {
-       WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, poin);
+       WM_event_add_notifier(C, NC_SCENE|ND_OB_RENDER, poin);
 }
 
-static void restrictbutton_r_lay_cb(bContext *C, void *poin, void *poin2)
+static void restrictbutton_r_lay_cb(bContext *C, void *poin, void *UNUSED(poin2))
 {
        WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, poin);
 }
 
-static void restrictbutton_modifier_cb(bContext *C, void *poin, void *poin2)
+static void restrictbutton_modifier_cb(bContext *C, void *UNUSED(poin), void *poin2)
 {
        Object *ob = (Object *)poin2;
        
@@ -4906,11 +4922,22 @@ static void restrictbutton_modifier_cb(bContext *C, void *poin, void *poin2)
        WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
 }
 
-static void restrictbutton_bone_cb(bContext *C, void *poin, void *poin2)
+static void restrictbutton_bone_cb(bContext *C, void *UNUSED(poin), void *poin2)
 {
+       Bone *bone= (Bone *)poin2;
+       if(bone && (bone->flag & BONE_HIDDEN_P))
+               bone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL);
        WM_event_add_notifier(C, NC_OBJECT|ND_POSE, NULL);
 }
 
+static void restrictbutton_ebone_cb(bContext *C, void *UNUSED(poin), void *poin2)
+{
+       EditBone *ebone= (EditBone *)poin2;
+       if(ebone && (ebone->flag & BONE_HIDDEN_A))
+               ebone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL);
+
+       WM_event_add_notifier(C, NC_OBJECT|ND_POSE, NULL);
+}
 
 static int group_restrict_flag(Group *gr, int flag)
 {
@@ -4935,7 +4962,7 @@ static int group_select_flag(Group *gr)
        return 0;
 }
 
-static void restrictbutton_gr_restrict_flag(bContext *C, void *poin, void *poin2, int flag)
+static void restrictbutton_gr_restrict_flag(void *poin, void *poin2, int flag)
 {      
        Scene *scene = (Scene *)poin;           
        GroupObject *gob;
@@ -4963,17 +4990,17 @@ static void restrictbutton_gr_restrict_flag(bContext *C, void *poin, void *poin2
 
 static void restrictbutton_gr_restrict_view(bContext *C, void *poin, void *poin2)
 {
-       restrictbutton_gr_restrict_flag(C, poin, poin2, OB_RESTRICT_VIEW);
+       restrictbutton_gr_restrict_flag(poin, poin2, OB_RESTRICT_VIEW);
        WM_event_add_notifier(C, NC_GROUP, NULL);
 }
 static void restrictbutton_gr_restrict_select(bContext *C, void *poin, void *poin2)
 {
-       restrictbutton_gr_restrict_flag(C, poin, poin2, OB_RESTRICT_SELECT);
+       restrictbutton_gr_restrict_flag(poin, poin2, OB_RESTRICT_SELECT);
        WM_event_add_notifier(C, NC_GROUP, NULL);
 }
 static void restrictbutton_gr_restrict_render(bContext *C, void *poin, void *poin2)
 {
-       restrictbutton_gr_restrict_flag(C, poin, poin2, OB_RESTRICT_RENDER);
+       restrictbutton_gr_restrict_flag(poin, poin2, OB_RESTRICT_RENDER);
        WM_event_add_notifier(C, NC_GROUP, NULL);
 }
 
@@ -5008,7 +5035,7 @@ static void namebutton_cb(bContext *C, void *tsep, char *oldname)
                        if (te->idcode == ID_LI) {
                                char expanded[FILE_MAXDIR + FILE_MAXFILE];
                                BLI_strncpy(expanded, ((Library *)tselem->id)->name, FILE_MAXDIR + FILE_MAXFILE);
-                               BLI_path_abs(expanded, G.sce);
+                               BLI_path_abs(expanded, G.main->name);
                                if (!BLI_exists(expanded)) {
                                        error("This path does not exist, correct this before saving");
                                }
@@ -5027,11 +5054,11 @@ static void namebutton_cb(bContext *C, void *tsep, char *oldname)
                                bArmature *arm= (bArmature *)tselem->id;
                                if(arm->edbo) {
                                        EditBone *ebone= te->directdata;
-                                       char newname[32];
+                                       char newname[sizeof(ebone->name)];
                                        
                                        /* restore bone name */
-                                       BLI_strncpy(newname, ebone->name, 32);
-                                       BLI_strncpy(ebone->name, oldname, 32);
+                                       BLI_strncpy(newname, ebone->name, sizeof(ebone->name));
+                                       BLI_strncpy(ebone->name, oldname, sizeof(ebone->name));
                                        ED_armature_bone_rename(obedit->data, oldname, newname);
                                        WM_event_add_notifier(C, NC_OBJECT|ND_POSE, OBACT);
                                }
@@ -5042,15 +5069,15 @@ static void namebutton_cb(bContext *C, void *tsep, char *oldname)
                                {
                                        Bone *bone= te->directdata;
                                        Object *ob;
-                                       char newname[32];
+                                       char newname[sizeof(bone->name)];
                                        
                                        // always make current object active
                                        tree_element_set_active_object(C, scene, soops, te, 1);
                                        ob= OBACT;
                                        
                                        /* restore bone name */
-                                       BLI_strncpy(newname, bone->name, 32);
-                                       BLI_strncpy(bone->name, oldname, 32);
+                                       BLI_strncpy(newname, bone->name, sizeof(bone->name));
+                                       BLI_strncpy(bone->name, oldname, sizeof(bone->name));
                                        ED_armature_bone_rename(ob->data, oldname, newname);
                                        WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob);
                                }
@@ -5059,15 +5086,15 @@ static void namebutton_cb(bContext *C, void *tsep, char *oldname)
                                {
                                        bPoseChannel *pchan= te->directdata;
                                        Object *ob;
-                                       char newname[32];
+                                       char newname[sizeof(pchan->name)];
                                        
                                        // always make current object active
                                        tree_element_set_active_object(C, scene, soops, te, 1);
                                        ob= OBACT;
                                        
                                        /* restore bone name */
-                                       BLI_strncpy(newname, pchan->name, 32);
-                                       BLI_strncpy(pchan->name, oldname, 32);
+                                       BLI_strncpy(newname, pchan->name, sizeof(pchan->name));
+                                       BLI_strncpy(pchan->name, oldname, sizeof(pchan->name));
                                        ED_armature_bone_rename(ob->data, oldname, newname);
                                        WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob);
                                }
@@ -5195,7 +5222,7 @@ static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar
                                uiBlockSetEmboss(block, UI_EMBOSSN);
                                bt= uiDefIconButBitI(block, ICONTOG, BONE_HIDDEN_P, 0, ICON_RESTRICT_VIEW_OFF, 
                                                (int)ar->v2d.cur.xmax-OL_TOG_RESTRICT_VIEWX, (short)te->ys, 17, OL_H-1, &(bone->flag), 0, 0, 0, 0, "Restrict/Allow visibility in the 3D View");
-                               uiButSetFunc(bt, restrictbutton_bone_cb, NULL, NULL);
+                               uiButSetFunc(bt, restrictbutton_bone_cb, NULL, bone);
                                
                                bt= uiDefIconButBitI(block, ICONTOG, BONE_UNSELECTABLE, 0, ICON_RESTRICT_SELECT_OFF, 
                                                (int)ar->v2d.cur.xmax-OL_TOG_RESTRICT_SELECTX, (short)te->ys, 17, OL_H-1, &(bone->flag), 0, 0, 0, 0, "Restrict/Allow selection in the 3D View");
@@ -5207,11 +5234,11 @@ static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar
                                uiBlockSetEmboss(block, UI_EMBOSSN);
                                bt= uiDefIconButBitI(block, ICONTOG, BONE_HIDDEN_A, 0, ICON_RESTRICT_VIEW_OFF, 
                                                (int)ar->v2d.cur.xmax-OL_TOG_RESTRICT_VIEWX, (short)te->ys, 17, OL_H-1, &(ebone->flag), 0, 0, 0, 0, "Restrict/Allow visibility in the 3D View");
-                               uiButSetFunc(bt, restrictbutton_bone_cb, NULL, NULL);
+                               uiButSetFunc(bt, restrictbutton_ebone_cb, NULL, ebone);
                                
                                bt= uiDefIconButBitI(block, ICONTOG, BONE_UNSELECTABLE, 0, ICON_RESTRICT_SELECT_OFF, 
                                                (int)ar->v2d.cur.xmax-OL_TOG_RESTRICT_SELECTX, (short)te->ys, 17, OL_H-1, &(ebone->flag), 0, 0, 0, 0, "Restrict/Allow selection in the 3D View");
-                               uiButSetFunc(bt, restrictbutton_bone_cb, NULL, NULL);
+                               uiButSetFunc(bt, restrictbutton_ebone_cb, NULL, NULL);
                        }
                }
                
@@ -5219,22 +5246,25 @@ static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar
        }
 }
 
-static void outliner_draw_rnacols(ARegion *ar, SpaceOops *soops, int sizex)
+static void outliner_draw_rnacols(ARegion *ar, int sizex)
 {
        View2D *v2d= &ar->v2d;
-       
+
+       float miny = v2d->cur.ymin-V2D_SCROLL_HEIGHT;
+       if(miny<v2d->tot.ymin) miny = v2d->tot.ymin;
+
        UI_ThemeColorShadeAlpha(TH_BACK, -15, -200);
 
        /* draw column separator lines */
        fdrawline((float)sizex,
                v2d->cur.ymax,
                (float)sizex,
-               v2d->cur.ymin);
+               miny);
 
        fdrawline((float)sizex+OL_RNA_COL_SIZEX,
                v2d->cur.ymax,
                (float)sizex+OL_RNA_COL_SIZEX,
-               v2d->cur.ymin);
+               miny);
 }
 
 static void outliner_draw_rnabuts(uiBlock *block, Scene *scene, ARegion *ar, SpaceOops *soops, int sizex, ListBase *lb)
@@ -5268,7 +5298,7 @@ static void outliner_draw_rnabuts(uiBlock *block, Scene *scene, ARegion *ar, Spa
        }
 }
 
-static void operator_call_cb(struct bContext *C, void *arg_kmi, void *arg2)
+static void operator_call_cb(struct bContext *UNUSED(C), void *arg_kmi, void *arg2)
 {
        wmOperatorType *ot= arg2;
        wmKeyMapItem *kmi= arg_kmi;
@@ -5277,7 +5307,7 @@ static void operator_call_cb(struct bContext *C, void *arg_kmi, void *arg2)
                BLI_strncpy(kmi->idname, ot->idname, OP_MAX_TYPENAME);
 }
 
-static void operator_search_cb(const struct bContext *C, void *arg_kmi, char *str, uiSearchItems *items)
+static void operator_search_cb(const struct bContext *UNUSED(C), void *UNUSED(arg_kmi), const char *str, uiSearchItems *items)
 {
        wmOperatorType *ot = WM_operatortype_first();
        
@@ -5428,7 +5458,7 @@ static char *keymap_tweak_dir_menu(void)
 }
 
 
-static void keymap_type_cb(bContext *C, void *kmi_v, void *unused_v)
+static void keymap_type_cb(bContext *C, void *kmi_v, void *UNUSED(arg_v))
 {
        wmKeyMapItem *kmi= kmi_v;
        short maptype= keymap_menu_type(kmi->type);
@@ -5515,7 +5545,7 @@ static void outliner_draw_keymapbuts(uiBlock *block, ARegion *ar, SpaceOops *soo
                                uiDefButS(block, OPTION, 0, "Shift",    xstart, (int)te->ys+1, butw3+5, OL_H-1, &kmi->shift, 0, 0, 0, 0, "Modifier"); xstart+= butw3+5;
                                uiDefButS(block, OPTION, 0, "Ctrl",     xstart, (int)te->ys+1, butw3, OL_H-1, &kmi->ctrl, 0, 0, 0, 0, "Modifier"); xstart+= butw3;
                                uiDefButS(block, OPTION, 0, "Alt",      xstart, (int)te->ys+1, butw3, OL_H-1, &kmi->alt, 0, 0, 0, 0, "Modifier"); xstart+= butw3;
-                               uiDefButS(block, OPTION, 0, "Cmd",      xstart, (int)te->ys+1, butw3, OL_H-1, &kmi->oskey, 0, 0, 0, 0, "Modifier"); xstart+= butw3;
+                               uiDefButS(block, OPTION, 0, "OS",       xstart, (int)te->ys+1, butw3, OL_H-1, &kmi->oskey, 0, 0, 0, 0, "Modifier"); xstart+= butw3;
                                xstart+= 5;
                                uiDefKeyevtButS(block, 0, "", xstart, (int)te->ys+1, butw3, OL_H-1, &kmi->keymodifier, "Key Modifier code");
                                xstart+= butw3+5;
@@ -5538,7 +5568,7 @@ static void outliner_buttons(const bContext *C, uiBlock *block, ARegion *ar, Spa
        uiBut *bt;
        TreeElement *te;
        TreeStoreElem *tselem;
-       int dx, len;
+       int spx, dx, len;
        
        for(te= lb->first; te; te= te->next) {
                tselem= TREESTORE(te);
@@ -5559,8 +5589,10 @@ static void outliner_buttons(const bContext *C, uiBlock *block, ARegion *ar, Spa
 
                                dx= (int)UI_GetStringWidth(te->name);
                                if(dx<100) dx= 100;
-                               
-                               bt= uiDefBut(block, TEX, OL_NAMEBUTTON, "",  (short)te->xs+2*OL_X-4, (short)te->ys, dx+10, OL_H-1, te->name, 1.0, (float)len-1, 0, 0, "");
+                               spx=te->xs+2*OL_X-4;
+                               if(spx+dx+10>ar->v2d.cur.xmax) dx = ar->v2d.cur.xmax-spx-10;
+
+                               bt= uiDefBut(block, TEX, OL_NAMEBUTTON, "", spx, (short)te->ys, dx+10, OL_H-1, te->name, 1.0, (float)len, 0, 0, "");
                                uiButSetRenameFunc(bt, namebutton_cb, tselem);
                                
                                /* returns false if button got removed */
@@ -5621,23 +5653,23 @@ void draw_outliner(const bContext *C)
        /* tweak to display last line (when list bigger than window) */
        sizey += V2D_SCROLL_HEIGHT;
        
+       /* adds vertical offset */
+       sizey += OL_Y_OFFSET;
+
        /* update size of tot-rect (extents of data/viewable area) */
        UI_view2d_totRect_set(v2d, sizex, sizey);
 
        /* set matrix for 2d-view controls */
-       UI_view2d_view_ortho(C, v2d);
+       UI_view2d_view_ortho(v2d);
 
-       /* draw outliner stuff (background and hierachy lines) */
-       outliner_back(ar, soops);
+       /* draw outliner stuff (background, hierachy lines and names) */
+       outliner_back(ar);
        block= uiBeginBlock(C, ar, "outliner buttons", UI_EMBOSS);
        outliner_draw_tree((bContext *)C, block, scene, ar, soops);
-
-       /* draw icons and names */
-       outliner_buttons(C, block, ar, soops, &soops->tree);
        
        if(ELEM(soops->outlinevis, SO_DATABLOCKS, SO_USERDEF)) {
                /* draw rna buttons */
-               outliner_draw_rnacols(ar, soops, sizex_rna);
+               outliner_draw_rnacols(ar, sizex_rna);
                outliner_draw_rnabuts(block, scene, ar, soops, sizex_rna, &soops->tree);
        }
        else if(soops->outlinevis == SO_KEYMAP) {
@@ -5645,10 +5677,13 @@ void draw_outliner(const bContext *C)
        }
        else if (!(soops->flag & SO_HIDE_RESTRICTCOLS)) {
                /* draw restriction columns */
-               outliner_draw_restrictcols(ar, soops);
+               outliner_draw_restrictcols(ar);
                outliner_draw_restrictbuts(block, scene, ar, soops, &soops->tree);
        }
-       
+
+       /* draw edit buttons if nessecery */
+       outliner_buttons(C, block, ar, soops, &soops->tree);    
+
        uiEndBlock(C, block);
        uiDrawBlock(C, block);