~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to source/blender/editors/space_outliner/outliner_select.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
#include "DNA_world_types.h"
44
44
 
45
45
#include "BLI_utildefines.h"
 
46
#include "BLI_listbase.h"
46
47
 
47
48
#include "BKE_context.h"
48
49
#include "BKE_depsgraph.h"
52
53
#include "ED_armature.h"
53
54
#include "ED_object.h"
54
55
#include "ED_screen.h"
 
56
#include "ED_sequencer.h"
55
57
#include "ED_util.h"
56
58
 
57
59
#include "WM_api.h"
67
69
#include "outliner_intern.h"
68
70
 
69
71
/* ****************************************************** */
70
 
/* Outliner Selection (grey-blue highlight for rows) */
 
72
/* Outliner Selection (gray-blue highlight for rows) */
71
73
 
72
74
static int outliner_select(SpaceOops *soops, ListBase *lb, int *index, short *selecting)
73
75
{
74
76
        TreeElement *te;
75
77
        TreeStoreElem *tselem;
76
 
        int change= 0;
 
78
        int change = 0;
77
79
        
78
 
        for (te= lb->first; te && *index >= 0; te=te->next, (*index)--) {
79
 
                tselem= TREESTORE(te);
 
80
        for (te = lb->first; te && *index >= 0; te = te->next, (*index)--) {
 
81
                tselem = TREESTORE(te);
80
82
                
81
83
                /* if we've encountered the right item, set its 'Outliner' selection status */
82
84
                if (*index == 0) {
83
85
                        /* this should be the last one, so no need to do anything with index */
84
 
                        if ((te->flag & TE_ICONROW)==0) {
 
86
                        if ((te->flag & TE_ICONROW) == 0) {
85
87
                                /* -1 value means toggle testing for now... */
86
88
                                if (*selecting == -1) {
87
89
                                        if (tselem->flag & TSE_SELECTED) 
88
 
                                                *selecting= 0;
 
90
                                                *selecting = 0;
89
91
                                        else 
90
 
                                                *selecting= 1;
 
92
                                                *selecting = 1;
91
93
                                }
92
94
                                
93
95
                                /* set selection */
99
101
                                change |= 1;
100
102
                        }
101
103
                }
102
 
                else if (TSELEM_OPEN(tselem,soops)) {
 
104
                else if (TSELEM_OPEN(tselem, soops)) {
103
105
                        /* Only try selecting sub-elements if we haven't hit the right element yet
104
106
                         *
105
107
                         * Hack warning:
106
 
                         *      Index must be reduced before supplying it to the sub-tree to try to do
107
 
                         *      selection, however, we need to increment it again for the next loop to 
108
 
                         *      function correctly
 
108
                         *  Index must be reduced before supplying it to the sub-tree to try to do
 
109
                         *  selection, however, we need to increment it again for the next loop to
 
110
                         *  function correctly
109
111
                         */
110
112
                        (*index)--;
111
113
                        change |= outliner_select(soops, &te->subtree, index, selecting);
124
126
        Scene *sce;
125
127
        
126
128
        /* paranoia check */
127
 
        if (te->idcode!=ID_SCE)
 
129
        if (te->idcode != ID_SCE)
128
130
                return 0;
129
 
        sce= (Scene *)tselem->id;
 
131
        sce = (Scene *)tselem->id;
130
132
        
131
133
        if (set) {
132
 
                sce->r.actlay= tselem->nr;
133
 
                WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, sce);
 
134
                sce->r.actlay = tselem->nr;
 
135
                WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, sce);
134
136
        }
135
137
        else {
136
 
                return sce->r.actlay==tselem->nr;
 
138
                return sce->r.actlay == tselem->nr;
137
139
        }
138
140
        return 0;
139
141
}
140
142
 
141
143
static int  tree_element_set_active_object(bContext *C, Scene *scene, SpaceOops *soops, TreeElement *te, int set)
142
144
{
143
 
        TreeStoreElem *tselem= TREESTORE(te);
 
145
        TreeStoreElem *tselem = TREESTORE(te);
144
146
        Scene *sce;
145
147
        Base *base;
146
 
        Object *ob= NULL;
 
148
        Object *ob = NULL;
147
149
        
148
150
        /* if id is not object, we search back */
149
 
        if (te->idcode==ID_OB) ob= (Object *)tselem->id;
 
151
        if (te->idcode == ID_OB) ob = (Object *)tselem->id;
150
152
        else {
151
 
                ob= (Object *)outliner_search_back(soops, te, ID_OB);
152
 
                if (ob==OBACT) return 0;
 
153
                ob = (Object *)outliner_search_back(soops, te, ID_OB);
 
154
                if (ob == OBACT) return 0;
153
155
        }
154
 
        if (ob==NULL) return 0;
 
156
        if (ob == NULL) return 0;
155
157
        
156
 
        sce= (Scene *)outliner_search_back(soops, te, ID_SCE);
 
158
        sce = (Scene *)outliner_search_back(soops, te, ID_SCE);
157
159
        if (sce && scene != sce) {
158
160
                ED_screen_set_scene(C, CTX_wm_screen(C), sce);
159
161
        }
160
162
        
161
163
        /* find associated base in current scene */
162
 
        base= object_in_scene(ob, scene);
 
164
        base = BKE_scene_base_find(scene, ob);
163
165
 
164
166
        if (base) {
165
 
                if (set==2) {
 
167
                if (set == 2) {
166
168
                        /* swap select */
167
169
                        if (base->flag & SELECT)
168
170
                                ED_base_object_select(base, BA_DESELECT);
171
173
                }
172
174
                else {
173
175
                        /* deleselect all */
174
 
                        scene_deselect_all(scene);
 
176
                        BKE_scene_base_deselect_all(scene);
175
177
                        ED_base_object_select(base, BA_SELECT);
176
178
                }
177
179
                if (C) {
178
180
                        ED_base_object_activate(C, base); /* adds notifier */
179
 
                        WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene);
 
181
                        WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
180
182
                }
181
183
        }
182
184
        
183
 
        if (ob!=scene->obedit)
184
 
                ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR|EM_DO_UNDO);
 
185
        if (ob != scene->obedit)
 
186
                ED_object_exit_editmode(C, EM_FREEDATA | EM_FREEUNDO | EM_WAITCURSOR | EM_DO_UNDO);
185
187
                
186
188
        return 1;
187
189
}
192
194
        Object *ob;
193
195
        
194
196
        /* we search for the object parent */
195
 
        ob= (Object *)outliner_search_back(soops, te, ID_OB);
 
197
        ob = (Object *)outliner_search_back(soops, te, ID_OB);
196
198
        // note: ob->matbits can be NULL when a local object points to a library mesh.
197
 
        if (ob==NULL || ob!=OBACT || ob->matbits==NULL) return 0;       // just paranoia
 
199
        if (ob == NULL || ob != OBACT || ob->matbits == NULL) return 0;  // just paranoia
198
200
        
199
201
        /* searching in ob mat array? */
200
 
        tes= te->parent;
201
 
        if (tes->idcode==ID_OB) {
 
202
        tes = te->parent;
 
203
        if (tes->idcode == ID_OB) {
202
204
                if (set) {
203
 
                        ob->actcol= te->index+1;
204
 
                        ob->matbits[te->index]= 1;      // make ob material active too
 
205
                        ob->actcol = te->index + 1;
 
206
                        ob->matbits[te->index] = 1;  // make ob material active too
205
207
                }
206
208
                else {
207
 
                        if (ob->actcol == te->index+1)
 
209
                        if (ob->actcol == te->index + 1)
208
210
                                if (ob->matbits[te->index]) return 1;
209
211
                }
210
212
        }
211
213
        /* or we search for obdata material */
212
214
        else {
213
215
                if (set) {
214
 
                        ob->actcol= te->index+1;
215
 
                        ob->matbits[te->index]= 0;      // make obdata material active too
 
216
                        ob->actcol = te->index + 1;
 
217
                        ob->matbits[te->index] = 0;  // make obdata material active too
216
218
                }
217
219
                else {
218
 
                        if (ob->actcol == te->index+1)
219
 
                                if (ob->matbits[te->index]==0) return 1;
 
220
                        if (ob->actcol == te->index + 1)
 
221
                                if (ob->matbits[te->index] == 0) return 1;
220
222
                }
221
223
        }
222
224
        if (set) {
223
 
                WM_event_add_notifier(C, NC_MATERIAL|ND_SHADING, NULL);
 
225
                WM_event_add_notifier(C, NC_MATERIAL | ND_SHADING_LINKS, NULL);
224
226
        }
225
227
        return 0;
226
228
}
229
231
{
230
232
        TreeElement *tep;
231
233
        TreeStoreElem /* *tselem,*/ *tselemp;
232
 
        Object *ob=OBACT;
233
 
        SpaceButs *sbuts=NULL;
234
 
        
235
 
        if (ob==NULL) return 0; // no active object
236
 
        
237
 
        /*tselem= TREESTORE(te);*/ /*UNUSED*/
 
234
        Object *ob = OBACT;
 
235
        SpaceButs *sbuts = NULL;
 
236
        
 
237
        if (ob == NULL) return 0;  // no active object
 
238
        
 
239
        /*tselem = TREESTORE(te);*/ /*UNUSED*/
238
240
        
239
241
        /* find buttons area (note, this is undefined really still, needs recode in blender) */
240
242
        /* XXX removed finding sbuts */
241
243
        
242
244
        /* where is texture linked to? */
243
 
        tep= te->parent;
244
 
        tselemp= TREESTORE(tep);
 
245
        tep = te->parent;
 
246
        tselemp = TREESTORE(tep);
245
247
        
246
 
        if (tep->idcode==ID_WO) {
247
 
                World *wrld= (World *)tselemp->id;
 
248
        if (tep->idcode == ID_WO) {
 
249
                World *wrld = (World *)tselemp->id;
248
250
 
249
251
                if (set) {
250
252
                        if (sbuts) {
251
 
                                // XXX sbuts->tabo= TAB_SHADING_TEX;    // hack from header_buttonswin.c
252
 
                                // XXX sbuts->texfrom= 1;
 
253
                                // XXX sbuts->tabo = TAB_SHADING_TEX;   // hack from header_buttonswin.c
 
254
                                // XXX sbuts->texfrom = 1;
253
255
                        }
254
256
// XXX                  extern_set_butspace(F6KEY, 0);  // force shading buttons texture
255
 
                        wrld->texact= te->index;
 
257
                        wrld->texact = te->index;
256
258
                }
257
259
                else if (tselemp->id == (ID *)(scene->world)) {
258
 
                        if (wrld->texact==te->index) return 1;
 
260
                        if (wrld->texact == te->index) return 1;
259
261
                }
260
262
        }
261
 
        else if (tep->idcode==ID_LA) {
262
 
                Lamp *la= (Lamp *)tselemp->id;
 
263
        else if (tep->idcode == ID_LA) {
 
264
                Lamp *la = (Lamp *)tselemp->id;
263
265
                if (set) {
264
266
                        if (sbuts) {
265
 
                                // XXX sbuts->tabo= TAB_SHADING_TEX;    // hack from header_buttonswin.c
266
 
                                // XXX sbuts->texfrom= 2;
 
267
                                // XXX sbuts->tabo = TAB_SHADING_TEX;   // hack from header_buttonswin.c
 
268
                                // XXX sbuts->texfrom = 2;
267
269
                        }
268
270
// XXX                  extern_set_butspace(F6KEY, 0);  // force shading buttons texture
269
 
                        la->texact= te->index;
 
271
                        la->texact = te->index;
270
272
                }
271
273
                else {
272
274
                        if (tselemp->id == ob->data) {
273
 
                                if (la->texact==te->index) return 1;
 
275
                                if (la->texact == te->index) return 1;
274
276
                        }
275
277
                }
276
278
        }
277
 
        else if (tep->idcode==ID_MA) {
278
 
                Material *ma= (Material *)tselemp->id;
 
279
        else if (tep->idcode == ID_MA) {
 
280
                Material *ma = (Material *)tselemp->id;
279
281
                if (set) {
280
282
                        if (sbuts) {
281
 
                                //sbuts->tabo= TAB_SHADING_TEX; // hack from header_buttonswin.c
282
 
                                // XXX sbuts->texfrom= 0;
 
283
                                //sbuts->tabo = TAB_SHADING_TEX;        // hack from header_buttonswin.c
 
284
                                // XXX sbuts->texfrom = 0;
283
285
                        }
284
286
// XXX                  extern_set_butspace(F6KEY, 0);  // force shading buttons texture
285
 
                        ma->texact= (char)te->index;
 
287
                        ma->texact = (char)te->index;
286
288
                        
287
289
                        /* also set active material */
288
 
                        ob->actcol= tep->index+1;
 
290
                        ob->actcol = tep->index + 1;
289
291
                }
290
 
                else if (tep->flag & TE_ACTIVE) {       // this is active material
291
 
                        if (ma->texact==te->index) return 1;
 
292
                else if (tep->flag & TE_ACTIVE) {   // this is active material
 
293
                        if (ma->texact == te->index) return 1;
292
294
                }
293
295
        }
294
296
        
304
306
        Object *ob;
305
307
        
306
308
        /* we search for the object parent */
307
 
        ob= (Object *)outliner_search_back(soops, te, ID_OB);
308
 
        if (ob==NULL || ob!=OBACT) return 0;    // just paranoia
 
309
        ob = (Object *)outliner_search_back(soops, te, ID_OB);
 
310
        if (ob == NULL || ob != OBACT) return 0;  // just paranoia
309
311
        
310
312
        if (set) {
311
313
// XXX          extern_set_butspace(F5KEY, 0);
317
319
 
318
320
static int tree_element_active_camera(bContext *UNUSED(C), Scene *scene, SpaceOops *soops, TreeElement *te, int set)
319
321
{
320
 
        Object *ob= (Object *)outliner_search_back(soops, te, ID_OB);
 
322
        Object *ob = (Object *)outliner_search_back(soops, te, ID_OB);
321
323
 
322
324
        if (set)
323
325
                return 0;
328
330
static int tree_element_active_world(bContext *C, Scene *scene, SpaceOops *soops, TreeElement *te, int set)
329
331
{
330
332
        TreeElement *tep;
331
 
        TreeStoreElem *tselem=NULL;
332
 
        Scene *sce=NULL;
 
333
        TreeStoreElem *tselem = NULL;
 
334
        Scene *sce = NULL;
333
335
        
334
 
        tep= te->parent;
 
336
        tep = te->parent;
335
337
        if (tep) {
336
 
                tselem= TREESTORE(tep);
337
 
                sce= (Scene *)tselem->id;
 
338
                tselem = TREESTORE(tep);
 
339
                if (tselem->type == 0)
 
340
                        sce = (Scene *)tselem->id;
338
341
        }
339
342
        
340
 
        if (set) {      // make new scene active
 
343
        if (set) {  // make new scene active
341
344
                if (sce && scene != sce) {
342
345
                        ED_screen_set_scene(C, CTX_wm_screen(C), sce);
343
346
                }
344
347
        }
345
348
        
346
 
        if (tep==NULL || tselem->id == (ID *)scene) {
 
349
        if (tep == NULL || tselem->id == (ID *)scene) {
347
350
                if (set) {
348
351
// XXX                  extern_set_butspace(F8KEY, 0);
349
352
                }
359
362
        Object *ob;
360
363
        
361
364
        /* id in tselem is object */
362
 
        ob= (Object *)tselem->id;
 
365
        ob = (Object *)tselem->id;
363
366
        if (set) {
364
 
                BLI_assert(te->index+1 >= 0);
365
 
                ob->actdef= te->index+1;
 
367
                BLI_assert(te->index + 1 >= 0);
 
368
                ob->actdef = te->index + 1;
366
369
 
367
370
                DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
368
 
                WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, ob);
 
371
                WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, ob);
369
372
        }
370
373
        else {
371
 
                if (ob==OBACT)
372
 
                        if (ob->actdef== te->index+1) return 1;
 
374
                if (ob == OBACT)
 
375
                        if (ob->actdef == te->index + 1) return 1;
373
376
        }
374
377
        return 0;
375
378
}
376
379
 
377
380
static int tree_element_active_posegroup(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
378
381
{
379
 
        Object *ob= (Object *)tselem->id;
 
382
        Object *ob = (Object *)tselem->id;
380
383
        
381
384
        if (set) {
382
385
                if (ob->pose) {
383
 
                        ob->pose->active_group= te->index+1;
384
 
                        WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
 
386
                        ob->pose->active_group = te->index + 1;
 
387
                        WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
385
388
                }
386
389
        }
387
390
        else {
388
 
                if (ob==OBACT && ob->pose) {
389
 
                        if (ob->pose->active_group== te->index+1) return 1;
 
391
                if (ob == OBACT && ob->pose) {
 
392
                        if (ob->pose->active_group == te->index + 1) return 1;
390
393
                }
391
394
        }
392
395
        return 0;
394
397
 
395
398
static int tree_element_active_posechannel(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
396
399
{
397
 
        Object *ob= (Object *)tselem->id;
398
 
        bArmature *arm= ob->data;
399
 
        bPoseChannel *pchan= te->directdata;
 
400
        Object *ob = (Object *)tselem->id;
 
401
        bArmature *arm = ob->data;
 
402
        bPoseChannel *pchan = te->directdata;
400
403
        
401
404
        if (set) {
402
405
                if (!(pchan->bone->flag & BONE_HIDDEN_P)) {
403
406
                        
404
 
                        if (set==2) ED_pose_deselectall(ob, 2); // 2 = clear active tag
405
 
                        else ED_pose_deselectall(ob, 0);        // 0 = deselect 
 
407
                        if (set == 2) ED_pose_deselectall(ob, 2);  // 2 = clear active tag
 
408
                        else ED_pose_deselectall(ob, 0);    // 0 = deselect
406
409
                        
407
 
                        if (set==2 && (pchan->bone->flag & BONE_SELECTED)) {
 
410
                        if (set == 2 && (pchan->bone->flag & BONE_SELECTED)) {
408
411
                                pchan->bone->flag &= ~BONE_SELECTED;
409
412
                        }
410
413
                        else {
411
414
                                pchan->bone->flag |= BONE_SELECTED;
412
 
                                arm->act_bone= pchan->bone;
 
415
                                arm->act_bone = pchan->bone;
413
416
                        }
414
417
                        
415
 
                        WM_event_add_notifier(C, NC_OBJECT|ND_BONE_ACTIVE, ob);
 
418
                        WM_event_add_notifier(C, NC_OBJECT | ND_BONE_ACTIVE, ob);
416
419
 
417
420
                }
418
421
        }
419
422
        else {
420
 
                if (ob==OBACT && ob->pose) {
 
423
                if (ob == OBACT && ob->pose) {
421
424
                        if (pchan->bone->flag & BONE_SELECTED) return 1;
422
425
                }
423
426
        }
426
429
 
427
430
static int tree_element_active_bone(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
428
431
{
429
 
        bArmature *arm= (bArmature *)tselem->id;
430
 
        Bone *bone= te->directdata;
 
432
        bArmature *arm = (bArmature *)tselem->id;
 
433
        Bone *bone = te->directdata;
431
434
        
432
435
        if (set) {
433
436
                if (!(bone->flag & BONE_HIDDEN_P)) {
434
 
                        if (set==2) ED_pose_deselectall(OBACT, 2);      // 2 is clear active tag
435
 
                        else ED_pose_deselectall(OBACT, 0);
 
437
                        Object *ob = OBACT;
 
438
                        if (ob) {
 
439
                                if (set == 2) ED_pose_deselectall(ob, 2);  // 2 is clear active tag
 
440
                                else ED_pose_deselectall(ob, 0);
 
441
                        }
436
442
                        
437
 
                        if (set==2 && (bone->flag & BONE_SELECTED)) {
 
443
                        if (set == 2 && (bone->flag & BONE_SELECTED)) {
438
444
                                bone->flag &= ~BONE_SELECTED;
439
445
                        }
440
446
                        else {
441
447
                                bone->flag |= BONE_SELECTED;
442
 
                                arm->act_bone= bone;
 
448
                                arm->act_bone = bone;
443
449
                        }
444
450
                        
445
 
                        WM_event_add_notifier(C, NC_OBJECT|ND_BONE_ACTIVE, OBACT);
 
451
                        WM_event_add_notifier(C, NC_OBJECT | ND_BONE_ACTIVE, ob);
446
452
                }
447
453
        }
448
454
        else {
449
 
                Object *ob= OBACT;
 
455
                Object *ob = OBACT;
450
456
                
451
 
                if (ob && ob->data==arm) {
 
457
                if (ob && ob->data == arm) {
452
458
                        if (bone->flag & BONE_SELECTED) return 1;
453
459
                }
454
460
        }
460
466
static void tree_element_active_ebone__sel(bContext *C, Scene *scene, bArmature *arm, EditBone *ebone, short sel)
461
467
{
462
468
        if (sel) {
463
 
                ebone->flag |= BONE_SELECTED|BONE_ROOTSEL|BONE_TIPSEL;
464
 
                arm->act_edbone= ebone;
 
469
                ebone->flag |= BONE_SELECTED | BONE_ROOTSEL | BONE_TIPSEL;
 
470
                arm->act_edbone = ebone;
465
471
                // flush to parent?
466
472
                if (ebone->parent && (ebone->flag & BONE_CONNECTED)) ebone->parent->flag |= BONE_TIPSEL;
467
473
        }
468
474
        else {
469
 
                ebone->flag &= ~(BONE_SELECTED|BONE_ROOTSEL|BONE_TIPSEL);
 
475
                ebone->flag &= ~(BONE_SELECTED | BONE_ROOTSEL | BONE_TIPSEL);
470
476
                // flush to parent?
471
477
                if (ebone->parent && (ebone->flag & BONE_CONNECTED)) ebone->parent->flag &= ~BONE_TIPSEL;
472
478
        }
473
479
 
474
 
        WM_event_add_notifier(C, NC_OBJECT|ND_BONE_ACTIVE, scene->obedit);
 
480
        WM_event_add_notifier(C, NC_OBJECT | ND_BONE_ACTIVE, scene->obedit);
475
481
}
476
482
static int tree_element_active_ebone(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *UNUSED(tselem), int set)
477
483
{
478
 
        bArmature *arm= scene->obedit->data;
479
 
        EditBone *ebone= te->directdata;
 
484
        bArmature *arm = scene->obedit->data;
 
485
        EditBone *ebone = te->directdata;
480
486
 
481
 
        if (set==1) {
 
487
        if (set == 1) {
482
488
                if (!(ebone->flag & BONE_HIDDEN_A)) {
483
 
                        ED_armature_deselect_all(scene->obedit, 0);     // deselect
 
489
                        ED_armature_deselect_all(scene->obedit, 0); // deselect
484
490
                        tree_element_active_ebone__sel(C, scene, arm, ebone, TRUE);
485
491
                        return 1;
486
492
                }
487
493
        }
488
 
        else if (set==2) {
 
494
        else if (set == 2) {
489
495
                if (!(ebone->flag & BONE_HIDDEN_A)) {
490
496
                        if (!(ebone->flag & BONE_SELECTED)) {
491
497
                                tree_element_active_ebone__sel(C, scene, arm, ebone, TRUE);
507
513
static int tree_element_active_modifier(bContext *C, TreeElement *UNUSED(te), TreeStoreElem *tselem, int set)
508
514
{
509
515
        if (set) {
510
 
                Object *ob= (Object *)tselem->id;
 
516
                Object *ob = (Object *)tselem->id;
511
517
                
512
 
                WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob);
 
518
                WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
513
519
 
514
520
// XXX          extern_set_butspace(F9KEY, 0);
515
521
        }
520
526
static int tree_element_active_psys(bContext *C, Scene *UNUSED(scene), TreeElement *UNUSED(te), TreeStoreElem *tselem, int set)
521
527
{
522
528
        if (set) {
523
 
                Object *ob= (Object *)tselem->id;
 
529
                Object *ob = (Object *)tselem->id;
524
530
                
525
 
                WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_EDITED, ob);
 
531
                WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE | NA_EDITED, ob);
526
532
                
527
533
// XXX          extern_set_butspace(F7KEY, 0);
528
534
        }
533
539
static int tree_element_active_constraint(bContext *C, TreeElement *UNUSED(te), TreeStoreElem *tselem, int set)
534
540
{
535
541
        if (set) {
536
 
                Object *ob= (Object *)tselem->id;
 
542
                Object *ob = (Object *)tselem->id;
537
543
                
538
 
                WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT, ob);
 
544
                WM_event_add_notifier(C, NC_OBJECT | ND_CONSTRAINT, ob);
539
545
// XXX          extern_set_butspace(F7KEY, 0);
540
546
        }
541
547
        
550
556
 
551
557
static int tree_element_active_pose(bContext *C, Scene *scene, TreeElement *UNUSED(te), TreeStoreElem *tselem, int set)
552
558
{
553
 
        Object *ob= (Object *)tselem->id;
554
 
        Base *base= object_in_scene(ob, scene);
 
559
        Object *ob = (Object *)tselem->id;
 
560
        Base *base = BKE_scene_base_find(scene, ob);
555
561
        
556
562
        if (set) {
557
563
                if (scene->obedit)
558
 
                        ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR|EM_DO_UNDO);
 
564
                        ED_object_exit_editmode(C, EM_FREEDATA | EM_FREEUNDO | EM_WAITCURSOR | EM_DO_UNDO);
559
565
                
560
566
                if (ob->mode & OB_MODE_POSE)
561
567
                        ED_armature_exit_posemode(C, base);
568
574
        return 0;
569
575
}
570
576
 
571
 
static int tree_element_active_sequence(TreeElement *te, TreeStoreElem *UNUSED(tselem), int set)
 
577
static int tree_element_active_sequence(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *UNUSED(tselem), int set)
572
578
{
573
 
        Sequence *seq= (Sequence*) te->directdata;
 
579
        Sequence *seq = (Sequence *) te->directdata;
 
580
        Editing *ed = BKE_sequencer_editing_get(scene, FALSE);
574
581
 
575
582
        if (set) {
576
 
// XXX          select_single_seq(seq, 1);
 
583
                /* only check on setting */
 
584
                if (BLI_findindex(ed->seqbasep, seq) != -1) {
 
585
                        if (set == 2) {
 
586
                                BKE_sequencer_active_set(scene, NULL);
 
587
                        }
 
588
                        ED_sequencer_deselect_all(scene);
 
589
 
 
590
                        if (set == 2 && seq->flag & SELECT) {
 
591
                                seq->flag &= ~SELECT;
 
592
                        }
 
593
                        else {
 
594
                                seq->flag |= SELECT;
 
595
                                BKE_sequencer_active_set(scene, seq);
 
596
                        }
 
597
                }
 
598
 
 
599
                WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER | NA_SELECTED, scene);
577
600
        }
578
601
        else {
579
 
                if (seq->flag & SELECT)
580
 
                        return(1);
 
602
                if (ed->act_seq == seq && seq->flag & SELECT) {
 
603
                        return 1;
 
604
                }
581
605
        }
582
606
        return(0);
583
607
}
585
609
static int tree_element_active_sequence_dup(Scene *scene, TreeElement *te, TreeStoreElem *UNUSED(tselem), int set)
586
610
{
587
611
        Sequence *seq, *p;
588
 
        Editing *ed= seq_give_editing(scene, FALSE);
 
612
        Editing *ed = BKE_sequencer_editing_get(scene, FALSE);
589
613
 
590
 
        seq= (Sequence*)te->directdata;
591
 
        if (set==0) {
 
614
        seq = (Sequence *)te->directdata;
 
615
        if (set == 0) {
592
616
                if (seq->flag & SELECT)
593
617
                        return(1);
594
618
                return(0);
595
619
        }
596
620
 
597
621
// XXX  select_single_seq(seq, 1);
598
 
        p= ed->seqbasep->first;
 
622
        p = ed->seqbasep->first;
599
623
        while (p) {
600
624
                if ((!p->strip) || (!p->strip->stripdata) || (!p->strip->stripdata->name)) {
601
 
                        p= p->next;
 
625
                        p = p->next;
602
626
                        continue;
603
627
                }
604
628
 
605
629
//              if (!strcmp(p->strip->stripdata->name, seq->strip->stripdata->name))
606
630
// XXX                  select_single_seq(p, 0);
607
 
                p= p->next;
 
631
                p = p->next;
608
632
        }
609
633
        return(0);
610
634
}
613
637
{
614
638
        wmKeyMapItem *kmi = te->directdata;
615
639
        
616
 
        if (set==0) {
 
640
        if (set == 0) {
617
641
                if (kmi->flag & KMI_INACTIVE) return 0;
618
642
                return 1;
619
643
        }
629
653
int tree_element_active(bContext *C, Scene *scene, SpaceOops *soops, TreeElement *te, int set)
630
654
{
631
655
 
632
 
        switch(te->idcode) {
 
656
        switch (te->idcode) {
633
657
                /* Note: no ID_OB: objects are handled specially to allow multiple
634
658
                 * selection. See do_outliner_item_activate. */
635
659
                case ID_MA:
650
674
 
651
675
/* generic call for non-id data to make/check active in UI */
652
676
/* Context can be NULL when set==0 */
653
 
int tree_element_type_active(bContext *C, Scene *scene, SpaceOops *soops, TreeElement *te, TreeStoreElem *tselem, int set)
 
677
int tree_element_type_active(bContext *C, Scene *scene, SpaceOops *soops,
 
678
                             TreeElement *te, TreeStoreElem *tselem, int set)
654
679
{
655
 
        switch(tselem->type) {
 
680
        switch (tselem->type) {
656
681
                case TSE_DEFGROUP:
657
682
                        return tree_element_active_defgroup(C, scene, te, tselem, set);
658
683
                case TSE_BONE:
663
688
                        return tree_element_active_modifier(C, te, tselem, set);
664
689
                case TSE_LINKED_OB:
665
690
                        if (set) tree_element_set_active_object(C, scene, soops, te, set);
666
 
                        else if (tselem->id==(ID *)OBACT) return 1;
 
691
                        else if (tselem->id == (ID *)OBACT) return 1;
667
692
                        break;
668
693
                case TSE_LINKED_PSYS:
669
694
                        return tree_element_active_psys(C, scene, te, tselem, set);
678
703
                case TSE_POSEGRP:
679
704
                        return tree_element_active_posegroup(C, scene, te, tselem, set);
680
705
                case TSE_SEQUENCE:
681
 
                        return tree_element_active_sequence(te, tselem, set);
 
706
                        return tree_element_active_sequence(C, scene, te, tselem, set);
682
707
                case TSE_SEQUENCE_DUP:
683
708
                        return tree_element_active_sequence_dup(scene, te, tselem, set);
684
709
                case TSE_KEYMAP_ITEM:
690
715
 
691
716
/* ================================================ */
692
717
 
693
 
static int do_outliner_item_activate(bContext *C, Scene *scene, ARegion *ar, SpaceOops *soops, TreeElement *te, int extend, const float mval[2])
 
718
static int do_outliner_item_activate(bContext *C, Scene *scene, ARegion *ar, SpaceOops *soops,
 
719
                                     TreeElement *te, int extend, const float mval[2])
694
720
{
695
721
        
696
 
        if (mval[1]>te->ys && mval[1]<te->ys+UI_UNIT_Y) {
697
 
                TreeStoreElem *tselem= TREESTORE(te);
698
 
                int openclose= 0;
 
722
        if (mval[1] > te->ys && mval[1] < te->ys + UI_UNIT_Y) {
 
723
                TreeStoreElem *tselem = TREESTORE(te);
 
724
                int openclose = 0;
699
725
                
700
726
                /* open close icon */
701
 
                if ((te->flag & TE_ICONROW)==0) {                               // hidden icon, no open/close
702
 
                        if ( mval[0]>te->xs && mval[0]<te->xs+UI_UNIT_X)
703
 
                                openclose= 1;
 
727
                if ((te->flag & TE_ICONROW) == 0) {               // hidden icon, no open/close
 
728
                        if (mval[0] > te->xs && mval[0] < te->xs + UI_UNIT_X)
 
729
                                openclose = 1;
704
730
                }
705
731
                
706
732
                if (openclose) {
718
744
                        return 1;
719
745
                }
720
746
                /* name and first icon */
721
 
                else if (mval[0]>te->xs+UI_UNIT_X && mval[0]<te->xend) {
 
747
                else if (mval[0] > te->xs + UI_UNIT_X && mval[0] < te->xend) {
722
748
                        
723
749
                        /* always makes active object */
724
 
                        if (tselem->type!=TSE_SEQUENCE && tselem->type!=TSE_SEQ_STRIP && tselem->type!=TSE_SEQUENCE_DUP)
725
 
                                tree_element_set_active_object(C, scene, soops, te, 1 + (extend!=0 && tselem->type==0));
 
750
                        if (tselem->type != TSE_SEQUENCE && tselem->type != TSE_SEQ_STRIP && tselem->type != TSE_SEQUENCE_DUP)
 
751
                                tree_element_set_active_object(C, scene, soops, te, 1 + (extend != 0 && tselem->type == 0));
726
752
                        
727
 
                        if (tselem->type==0) { // the lib blocks
 
753
                        if (tselem->type == 0) { // the lib blocks
728
754
                                /* editmode? */
729
 
                                if (te->idcode==ID_SCE) {
730
 
                                        if (scene!=(Scene *)tselem->id) {
 
755
                                if (te->idcode == ID_SCE) {
 
756
                                        if (scene != (Scene *)tselem->id) {
731
757
                                                ED_screen_set_scene(C, CTX_wm_screen(C), (Scene *)tselem->id);
732
758
                                        }
733
759
                                }
734
 
                                else if (te->idcode==ID_GR) {
735
 
                                        Group *gr= (Group *)tselem->id;
 
760
                                else if (te->idcode == ID_GR) {
 
761
                                        Group *gr = (Group *)tselem->id;
736
762
                                        GroupObject *gob;
737
763
                                        
738
764
                                        if (extend) {
739
 
                                                int sel= BA_SELECT;
740
 
                                                for (gob= gr->gobject.first; gob; gob= gob->next) {
 
765
                                                int sel = BA_SELECT;
 
766
                                                for (gob = gr->gobject.first; gob; gob = gob->next) {
741
767
                                                        if (gob->ob->flag & SELECT) {
742
 
                                                                sel= BA_DESELECT;
 
768
                                                                sel = BA_DESELECT;
743
769
                                                                break;
744
770
                                                        }
745
771
                                                }
746
772
                                                
747
 
                                                for (gob= gr->gobject.first; gob; gob= gob->next) {
748
 
                                                        ED_base_object_select(object_in_scene(gob->ob, scene), sel);
 
773
                                                for (gob = gr->gobject.first; gob; gob = gob->next) {
 
774
                                                        ED_base_object_select(BKE_scene_base_find(scene, gob->ob), sel);
749
775
                                                }
750
776
                                        }
751
777
                                        else {
752
 
                                                scene_deselect_all(scene);
 
778
                                                BKE_scene_base_deselect_all(scene);
753
779
                                                
754
 
                                                for (gob= gr->gobject.first; gob; gob= gob->next) {
 
780
                                                for (gob = gr->gobject.first; gob; gob = gob->next) {
755
781
                                                        if ((gob->ob->flag & SELECT) == 0)
756
 
                                                                ED_base_object_select(object_in_scene(gob->ob, scene), BA_SELECT);
 
782
                                                                ED_base_object_select(BKE_scene_base_find(scene, gob->ob), BA_SELECT);
757
783
                                                }
758
784
                                        }
759
785
                                        
760
 
                                        WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene);
 
786
                                        WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
761
787
                                }
762
788
                                else if (ELEM5(te->idcode, ID_ME, ID_CU, ID_MB, ID_LT, ID_AR)) {
763
789
                                        WM_operator_name_call(C, "OBJECT_OT_editmode_toggle", WM_OP_INVOKE_REGION_WIN, NULL);
764
790
                                }
765
 
                                else {  // rest of types
 
791
                                else {  // rest of types
766
792
                                        tree_element_active(C, scene, soops, te, 1);
767
793
                                }
768
794
                                
769
795
                        }
770
 
                        else tree_element_type_active(C, scene, soops, te, tselem, 1+(extend!=0));
 
796
                        else tree_element_type_active(C, scene, soops, te, tselem, 1 + (extend != 0));
771
797
                        
772
798
                        return 1;
773
799
                }
774
800
        }
775
801
        
776
 
        for (te= te->subtree.first; te; te= te->next) {
 
802
        for (te = te->subtree.first; te; te = te->next) {
777
803
                if (do_outliner_item_activate(C, scene, ar, soops, te, extend, mval)) return 1;
778
804
        }
779
805
        return 0;
782
808
/* event can enterkey, then it opens/closes */
783
809
static int outliner_item_activate(bContext *C, wmOperator *op, wmEvent *event)
784
810
{
785
 
        Scene *scene= CTX_data_scene(C);
786
 
        ARegion *ar= CTX_wm_region(C);
787
 
        SpaceOops *soops= CTX_wm_space_outliner(C);
 
811
        Scene *scene = CTX_data_scene(C);
 
812
        ARegion *ar = CTX_wm_region(C);
 
813
        SpaceOops *soops = CTX_wm_space_outliner(C);
788
814
        TreeElement *te;
789
815
        float fmval[2];
790
 
        int extend= RNA_boolean_get(op->ptr, "extend");
791
 
 
792
 
        UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], fmval, fmval+1);
793
 
 
794
 
        if ( !ELEM3(soops->outlinevis, SO_DATABLOCKS, SO_USERDEF, SO_KEYMAP) &&
795
 
             !(soops->flag & SO_HIDE_RESTRICTCOLS) &&
796
 
             (fmval[0] > ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX))
 
816
        int extend = RNA_boolean_get(op->ptr, "extend");
 
817
 
 
818
        UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], fmval, fmval + 1);
 
819
 
 
820
        if (!ELEM3(soops->outlinevis, SO_DATABLOCKS, SO_USERDEF, SO_KEYMAP) &&
 
821
            !(soops->flag & SO_HIDE_RESTRICTCOLS) &&
 
822
            (fmval[0] > ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX))
797
823
        {
798
824
                return OPERATOR_CANCELLED;
799
825
        }
800
826
 
801
 
        for (te= soops->tree.first; te; te= te->next) {
 
827
        for (te = soops->tree.first; te; te = te->next) {
802
828
                if (do_outliner_item_activate(C, scene, ar, soops, te, extend, fmval)) break;
803
829
        }
804
830
        
806
832
                ED_undo_push(C, "Outliner click event");
807
833
        }
808
834
        else {
809
 
                short selecting= -1;
 
835
                short selecting = -1;
810
836
                int row;
811
837
                
812
838
                /* get row number - 100 here is just a dummy value since we don't need the column */
813
839
                UI_view2d_listview_view_to_cell(&ar->v2d, 1000, UI_UNIT_Y, 0.0f, OL_Y_OFFSET, 
814
 
                                                fmval[0], fmval[1], NULL, &row);
 
840
                                                fmval[0], fmval[1], NULL, &row);
815
841
                
816
842
                /* select relevant row */
817
843
                if (outliner_select(soops, &soops->tree, &row, &selecting)) {
847
873
/* **************** Border Select Tool ****************** */
848
874
static void outliner_item_border_select(Scene *scene, SpaceOops *soops, rctf *rectf, TreeElement *te, int gesture_mode)
849
875
{
850
 
        TreeStoreElem *tselem= TREESTORE(te);
 
876
        TreeStoreElem *tselem = TREESTORE(te);
851
877
 
852
878
        if (te->ys <= rectf->ymax && te->ys + UI_UNIT_Y >= rectf->ymin) {
853
879
                if (gesture_mode == GESTURE_MODAL_SELECT) {
869
895
 
870
896
static int outliner_border_select_exec(bContext *C, wmOperator *op)
871
897
{
872
 
        Scene *scene= CTX_data_scene(C);
873
 
        SpaceOops *soops= CTX_wm_space_outliner(C);
874
 
        ARegion *ar= CTX_wm_region(C);
 
898
        Scene *scene = CTX_data_scene(C);
 
899
        SpaceOops *soops = CTX_wm_space_outliner(C);
 
900
        ARegion *ar = CTX_wm_region(C);
875
901
        TreeElement *te;
876
902
        rcti rect;
877
903
        rctf rectf;
878
 
        int gesture_mode= RNA_int_get(op->ptr, "gesture_mode");
879
 
 
880
 
        rect.xmin = RNA_int_get(op->ptr, "xmin");
881
 
        rect.ymin = RNA_int_get(op->ptr, "ymin");
 
904
        int gesture_mode = RNA_int_get(op->ptr, "gesture_mode");
 
905
 
 
906
        WM_operator_properties_border_to_rcti(op, &rect);
 
907
 
882
908
        UI_view2d_region_to_view(&ar->v2d, rect.xmin, rect.ymin, &rectf.xmin, &rectf.ymin);
883
 
 
884
 
        rect.xmax = RNA_int_get(op->ptr, "xmax");
885
 
        rect.ymax = RNA_int_get(op->ptr, "ymax");
886
909
        UI_view2d_region_to_view(&ar->v2d, rect.xmax, rect.ymax, &rectf.xmax, &rectf.ymax);
887
910
 
888
 
        for (te= soops->tree.first; te; te= te->next) {
 
911
        for (te = soops->tree.first; te; te = te->next) {
889
912
                outliner_item_border_select(scene, soops, &rectf, te, gesture_mode);
890
913
        }
891
914
 
892
 
        WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene);
 
915
        WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
893
916
        ED_region_tag_redraw(ar);
894
917
 
895
918
        return OPERATOR_FINISHED;
911
934
        ot->poll = ED_operator_outliner_active;
912
935
 
913
936
        /* flags */
914
 
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 
937
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
915
938
 
916
939
        /* rna */
917
940
        WM_operator_properties_gesture_border(ot, FALSE);