Merge branch 'master' into blender2.8
[blender.git] / source / blender / editors / screen / screen_context.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2008 Blender Foundation.
19  * All rights reserved.
20  *
21  *
22  * ***** END GPL LICENSE BLOCK *****
23  */
24
25 /** \file blender/editors/screen/screen_context.c
26  *  \ingroup edscr
27  */
28
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32
33 #include "MEM_guardedalloc.h"
34
35 #include "DNA_object_types.h"
36 #include "DNA_armature_types.h"
37 #include "DNA_gpencil_types.h"
38 #include "DNA_sequence_types.h"
39 #include "DNA_scene_types.h"
40 #include "DNA_screen_types.h"
41 #include "DNA_space_types.h"
42 #include "DNA_windowmanager_types.h"
43 #include "DNA_workspace_types.h"
44
45 #include "BLI_utildefines.h"
46
47 #include "BKE_context.h"
48 #include "BKE_object.h"
49 #include "BKE_action.h"
50 #include "BKE_armature.h"
51 #include "BKE_gpencil.h"
52 #include "BKE_layer.h"
53 #include "BKE_screen.h"
54 #include "BKE_sequencer.h"
55 #include "BKE_workspace.h"
56
57 #include "DEG_depsgraph.h"
58
59 #include "RNA_access.h"
60
61 #include "ED_armature.h"
62 #include "ED_gpencil.h"
63 #include "ED_anim_api.h"
64
65 #include "WM_api.h"
66 #include "UI_interface.h"
67
68 #include "screen_intern.h"
69
70 const char *screen_context_dir[] = {
71         "scene", "view_layer", "visible_objects", "visible_bases", "selectable_objects", "selectable_bases",
72         "selected_objects", "selected_bases",
73         "editable_objects", "editable_bases",
74         "selected_editable_objects", "selected_editable_bases",
75         "visible_bones", "editable_bones", "selected_bones", "selected_editable_bones",
76         "visible_pose_bones", "selected_pose_bones", "active_bone", "active_pose_bone",
77         "active_base", "active_object", "object", "edit_object",
78         "sculpt_object", "vertex_paint_object", "weight_paint_object",
79         "image_paint_object", "particle_edit_object",
80         "sequences", "selected_sequences", "selected_editable_sequences", /* sequencer */
81         "gpencil_data", "gpencil_data_owner", /* grease pencil data */
82         "visible_gpencil_layers", "editable_gpencil_layers", "editable_gpencil_strokes",
83         "active_gpencil_layer", "active_gpencil_frame", "active_gpencil_palette",
84         "active_gpencil_palettecolor", "active_gpencil_brush",
85         "active_operator", "selected_editable_fcurves",
86         NULL};
87
88 int ed_screen_context(const bContext *C, const char *member, bContextDataResult *result)
89 {
90         wmWindow *win = CTX_wm_window(C);
91         bScreen *sc = CTX_wm_screen(C);
92         ScrArea *sa = CTX_wm_area(C);
93         Scene *scene = WM_window_get_active_scene(win);
94         WorkSpace *workspace = BKE_workspace_active_get(win->workspace_hook);
95         ViewLayer *view_layer = BKE_view_layer_from_workspace_get(scene, workspace);
96         Object *obact = (view_layer && view_layer->basact) ? view_layer->basact->object : NULL;
97         Object *obedit = view_layer ? OBEDIT_FROM_VIEW_LAYER(view_layer) : NULL;
98
99         if (CTX_data_dir(member)) {
100                 CTX_data_dir_set(result, screen_context_dir);
101                 return 1;
102         }
103         else if (CTX_data_equals(member, "scene")) {
104                 CTX_data_id_pointer_set(result, &scene->id);
105                 return 1;
106         }
107         else if (CTX_data_equals(member, "visible_objects")) {
108                 FOREACH_VISIBLE_OBJECT_BEGIN(view_layer, ob)
109                 {
110                         CTX_data_id_list_add(result, &ob->id);
111                 }
112                 FOREACH_VISIBLE_BASE_END;
113                 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
114                 return 1;
115         }
116         else if (CTX_data_equals(member, "selectable_objects")) {
117                 for (Base *base = view_layer->object_bases.first; base; base = base->next) {
118                         if (((base->flag & BASE_VISIBLED) != 0) && ((base->flag & BASE_SELECTABLED) != 0)) {
119                                 CTX_data_id_list_add(result, &base->object->id);
120                         }
121                 }
122                 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
123                 return 1;
124         }
125         else if (CTX_data_equals(member, "selected_objects")) {
126                 FOREACH_SELECTED_OBJECT_BEGIN(view_layer, ob)
127                 {
128                         CTX_data_id_list_add(result, &ob->id);
129                 }
130                 FOREACH_SELECTED_OBJECT_END;
131                 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
132                 return 1;
133         }
134         else if (CTX_data_equals(member, "selected_editable_objects")) {
135                 FOREACH_SELECTED_OBJECT_BEGIN(view_layer, ob)
136                 {
137                         if (0 == BKE_object_is_libdata(ob)) {
138                                 CTX_data_id_list_add(result, &ob->id);
139                         }
140                 }
141                 FOREACH_SELECTED_OBJECT_END;
142                 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
143                 return 1;
144         }
145         else if (CTX_data_equals(member, "editable_objects")) {
146                 /* Visible + Editable, but not necessarily selected */
147                 FOREACH_VISIBLE_OBJECT_BEGIN(view_layer, ob)
148                 {
149                         if (0 == BKE_object_is_libdata(ob)) {
150                                 CTX_data_id_list_add(result, &ob->id);
151                         }
152                 }
153                 FOREACH_VISIBLE_OBJECT_END;
154                 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
155                 return 1;
156         }
157         else if ( CTX_data_equals(member, "visible_bases")) {
158                 FOREACH_VISIBLE_BASE_BEGIN(view_layer, base)
159                 {
160                         CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
161                 }
162                 FOREACH_VISIBLE_BASE_END;
163                 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
164                 return 1;
165         }
166         else if (CTX_data_equals(member, "selectable_bases")) {
167                 for (Base *base = view_layer->object_bases.first; base; base = base->next) {
168                         if ((base->flag & BASE_SELECTABLED) != 0) {
169                                 CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
170                         }
171                 }
172                 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
173                 return 1;
174         }
175         else if (CTX_data_equals(member, "selected_bases")) {
176                 for (Base *base = view_layer->object_bases.first; base; base = base->next) {
177                         if ((base->flag & BASE_SELECTED) != 0) {
178                                 CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
179                         }
180                 }
181                 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
182                 return 1;
183         }
184         else if (CTX_data_equals(member, "selected_editable_bases")) {
185                 for (Base *base = view_layer->object_bases.first; base; base = base->next) {
186                         if ((base->flag & BASE_SELECTED) != 0) {
187                                 if (0 == BKE_object_is_libdata(base->object)) {
188                                         CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
189                                 }
190                         }
191                 }
192                 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
193                 return 1;
194         }
195         else if (CTX_data_equals(member, "editable_bases")) {
196                 /* Visible + Editable, but not necessarily selected */
197                 for (Base *base = view_layer->object_bases.first; base; base = base->next) {
198                         if ((base->flag & BASE_VISIBLED) != 0) {
199                                 if (0 == BKE_object_is_libdata(base->object)) {
200                                         CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
201                                 }
202                         }
203                 }
204                 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
205                 return 1;
206         }
207         else if (CTX_data_equals(member, "visible_bones") || CTX_data_equals(member, "editable_bones")) {
208                 bArmature *arm = (obedit && obedit->type == OB_ARMATURE) ? obedit->data : NULL;
209                 EditBone *ebone, *flipbone = NULL;
210                 const bool editable_bones = CTX_data_equals(member, "editable_bones");
211
212                 if (arm && arm->edbo) {
213                         uint objects_len;
214                         Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
215                         for (uint i = 0; i < objects_len; i++) {
216                                 Object *ob = objects[i];
217                                 arm = ob->data;
218
219                                 /* Attention: X-Axis Mirroring is also handled here... */
220                                 for (ebone = arm->edbo->first; ebone; ebone = ebone->next) {
221                                         /* first and foremost, bone must be visible and selected */
222                                         if (EBONE_VISIBLE(arm, ebone)) {
223                                                 /* Get 'x-axis mirror equivalent' bone if the X-Axis Mirroring option is enabled
224                                                  * so that most users of this data don't need to explicitly check for it themselves.
225                                                  *
226                                                  * We need to make sure that these mirrored copies are not selected, otherwise some
227                                                  * bones will be operated on twice.
228                                                  */
229                                                 if (arm->flag & ARM_MIRROR_EDIT)
230                                                         flipbone = ED_armature_ebone_get_mirrored(arm->edbo, ebone);
231
232                                                 /* if we're filtering for editable too, use the check for that instead, as it has selection check too */
233                                                 if (editable_bones) {
234                                                         /* only selected + editable */
235                                                         if (EBONE_EDITABLE(ebone)) {
236                                                                 CTX_data_list_add(result, &arm->id, &RNA_EditBone, ebone);
237
238                                                                 if ((flipbone) && !(flipbone->flag & BONE_SELECTED))
239                                                                         CTX_data_list_add(result, &arm->id, &RNA_EditBone, flipbone);
240                                                         }
241                                                 }
242                                                 else {
243                                                         /* only include bones if visible */
244                                                         CTX_data_list_add(result, &arm->id, &RNA_EditBone, ebone);
245
246                                                         if ((flipbone) && EBONE_VISIBLE(arm, flipbone) == 0)
247                                                                 CTX_data_list_add(result, &arm->id, &RNA_EditBone, flipbone);
248                                                 }
249                                         }
250                                 }
251                         }
252                         MEM_freeN(objects);
253
254                         CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
255                         return 1;
256                 }
257         }
258         else if (CTX_data_equals(member, "selected_bones") || CTX_data_equals(member, "selected_editable_bones")) {
259                 bArmature *arm = (obedit && obedit->type == OB_ARMATURE) ? obedit->data : NULL;
260                 EditBone *ebone, *flipbone = NULL;
261                 const bool selected_editable_bones = CTX_data_equals(member, "selected_editable_bones");
262
263                 if (arm && arm->edbo) {
264                         uint objects_len;
265                         Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
266                         for (uint i = 0; i < objects_len; i++) {
267                                 Object *ob = objects[i];
268                                 arm = ob->data;
269
270                                 /* Attention: X-Axis Mirroring is also handled here... */
271                                 for (ebone = arm->edbo->first; ebone; ebone = ebone->next) {
272                                         /* first and foremost, bone must be visible and selected */
273                                         if (EBONE_VISIBLE(arm, ebone) && (ebone->flag & BONE_SELECTED)) {
274                                                 /* Get 'x-axis mirror equivalent' bone if the X-Axis Mirroring option is enabled
275                                                  * so that most users of this data don't need to explicitly check for it themselves.
276                                                  *
277                                                  * We need to make sure that these mirrored copies are not selected, otherwise some
278                                                  * bones will be operated on twice.
279                                                  */
280                                                 if (arm->flag & ARM_MIRROR_EDIT)
281                                                         flipbone = ED_armature_ebone_get_mirrored(arm->edbo, ebone);
282
283                                                 /* if we're filtering for editable too, use the check for that instead, as it has selection check too */
284                                                 if (selected_editable_bones) {
285                                                         /* only selected + editable */
286                                                         if (EBONE_EDITABLE(ebone)) {
287                                                                 CTX_data_list_add(result, &arm->id, &RNA_EditBone, ebone);
288
289                                                                 if ((flipbone) && !(flipbone->flag & BONE_SELECTED))
290                                                                         CTX_data_list_add(result, &arm->id, &RNA_EditBone, flipbone);
291                                                         }
292                                                 }
293                                                 else {
294                                                         /* only include bones if selected */
295                                                         CTX_data_list_add(result, &arm->id, &RNA_EditBone, ebone);
296
297                                                         if ((flipbone) && !(flipbone->flag & BONE_SELECTED))
298                                                                 CTX_data_list_add(result, &arm->id, &RNA_EditBone, flipbone);
299                                                 }
300                                         }
301                                 }
302                         }
303                         MEM_freeN(objects);
304
305                         CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
306                         return 1;
307                 }
308         }
309         else if (CTX_data_equals(member, "visible_pose_bones")) {
310                 Object *obpose = BKE_object_pose_armature_get(obact);
311                 if (obpose && obpose->pose && obpose->data) {
312                         if (obpose != obact) {
313                                 FOREACH_PCHAN_VISIBLE_IN_OBJECT_BEGIN (obpose, pchan) {
314                                         CTX_data_list_add(result, &obpose->id, &RNA_PoseBone, pchan);
315                                 } FOREACH_PCHAN_SELECTED_IN_OBJECT_END;
316                         }
317                         else if (obact->mode & OB_MODE_POSE) {
318                                 FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, OB_MODE_POSE, ob_iter) {
319                                         FOREACH_PCHAN_VISIBLE_IN_OBJECT_BEGIN (ob_iter, pchan) {
320                                                 CTX_data_list_add(result, &ob_iter->id, &RNA_PoseBone, pchan);
321                                         } FOREACH_PCHAN_VISIBLE_IN_OBJECT_END;
322                                 } FOREACH_OBJECT_IN_MODE_END;
323                         }
324                         CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
325                         return 1;
326                 }
327         }
328         else if (CTX_data_equals(member, "selected_pose_bones")) {
329                 Object *obpose = BKE_object_pose_armature_get(obact);
330                 if (obpose && obpose->pose && obpose->data) {
331                         if (obpose != obact) {
332                                 FOREACH_PCHAN_SELECTED_IN_OBJECT_BEGIN (obpose, pchan) {
333                                         CTX_data_list_add(result, &obpose->id, &RNA_PoseBone, pchan);
334                                 } FOREACH_PCHAN_SELECTED_IN_OBJECT_END;
335                         }
336                         else if (obact->mode & OB_MODE_POSE) {
337                                 FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, OB_MODE_POSE, ob_iter) {
338                                         FOREACH_PCHAN_SELECTED_IN_OBJECT_BEGIN (ob_iter, pchan) {
339                                                 CTX_data_list_add(result, &ob_iter->id, &RNA_PoseBone, pchan);
340                                         } FOREACH_PCHAN_SELECTED_IN_OBJECT_END;
341                                 } FOREACH_OBJECT_IN_MODE_END;
342                         }
343                         CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
344                         return 1;
345                 }
346         }
347         else if (CTX_data_equals(member, "active_bone")) {
348                 if (obact && obact->type == OB_ARMATURE) {
349                         bArmature *arm = obact->data;
350                         if (arm->edbo) {
351                                 if (arm->act_edbone) {
352                                         CTX_data_pointer_set(result, &arm->id, &RNA_EditBone, arm->act_edbone);
353                                         return 1;
354                                 }
355                         }
356                         else {
357                                 if (arm->act_bone) {
358                                         CTX_data_pointer_set(result, &arm->id, &RNA_Bone, arm->act_bone);
359                                         return 1;
360                                 }
361                         }
362                 }
363         }
364         else if (CTX_data_equals(member, "active_pose_bone")) {
365                 bPoseChannel *pchan;
366                 Object *obpose = BKE_object_pose_armature_get(obact);
367
368                 pchan = BKE_pose_channel_active(obpose);
369                 if (pchan) {
370                         CTX_data_pointer_set(result, &obpose->id, &RNA_PoseBone, pchan);
371                         return 1;
372                 }
373         }
374         else if (CTX_data_equals(member, "active_base")) {
375                 if (view_layer->basact)
376                         CTX_data_pointer_set(result, &scene->id, &RNA_ObjectBase, view_layer->basact);
377
378                 return 1;
379         }
380         else if (CTX_data_equals(member, "active_object")) {
381                 if (obact)
382                         CTX_data_id_pointer_set(result, &obact->id);
383
384                 return 1;
385         }
386         else if (CTX_data_equals(member, "object")) {
387                 if (obact)
388                         CTX_data_id_pointer_set(result, &obact->id);
389
390                 return 1;
391         }
392         else if (CTX_data_equals(member, "edit_object")) {
393                 /* convenience for now, 1 object per scene in editmode */
394                 if (obedit)
395                         CTX_data_id_pointer_set(result, &obedit->id);
396
397                 return 1;
398         }
399         else if (CTX_data_equals(member, "sculpt_object")) {
400                 if (obact && (obact->mode & OB_MODE_SCULPT))
401                         CTX_data_id_pointer_set(result, &obact->id);
402
403                 return 1;
404         }
405         else if (CTX_data_equals(member, "vertex_paint_object")) {
406                 if (obact && (obact->mode & OB_MODE_VERTEX_PAINT))
407                         CTX_data_id_pointer_set(result, &obact->id);
408
409                 return 1;
410         }
411         else if (CTX_data_equals(member, "weight_paint_object")) {
412                 if (obact && (obact->mode & OB_MODE_WEIGHT_PAINT))
413                         CTX_data_id_pointer_set(result, &obact->id);
414
415                 return 1;
416         }
417         else if (CTX_data_equals(member, "image_paint_object")) {
418                 if (obact && (obact->mode & OB_MODE_TEXTURE_PAINT))
419                         CTX_data_id_pointer_set(result, &obact->id);
420
421                 return 1;
422         }
423         else if (CTX_data_equals(member, "particle_edit_object")) {
424                 if (obact && (obact->mode & OB_MODE_PARTICLE_EDIT))
425                         CTX_data_id_pointer_set(result, &obact->id);
426
427                 return 1;
428         }
429         else if (CTX_data_equals(member, "sequences")) {
430                 Editing *ed = BKE_sequencer_editing_get(scene, false);
431                 if (ed) {
432                         Sequence *seq;
433                         for (seq = ed->seqbasep->first; seq; seq = seq->next) {
434                                 CTX_data_list_add(result, &scene->id, &RNA_Sequence, seq);
435                         }
436                         CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
437                         return 1;
438                 }
439         }
440         else if (CTX_data_equals(member, "selected_sequences")) {
441                 Editing *ed = BKE_sequencer_editing_get(scene, false);
442                 if (ed) {
443                         Sequence *seq;
444                         for (seq = ed->seqbasep->first; seq; seq = seq->next) {
445                                 if (seq->flag & SELECT) {
446                                         CTX_data_list_add(result, &scene->id, &RNA_Sequence, seq);
447                                 }
448                         }
449                         CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
450                         return 1;
451                 }
452         }
453         else if (CTX_data_equals(member, "selected_editable_sequences")) {
454                 Editing *ed = BKE_sequencer_editing_get(scene, false);
455                 if (ed) {
456                         Sequence *seq;
457                         for (seq = ed->seqbasep->first; seq; seq = seq->next) {
458                                 if (seq->flag & SELECT && !(seq->flag & SEQ_LOCK)) {
459                                         CTX_data_list_add(result, &scene->id, &RNA_Sequence, seq);
460                                 }
461                         }
462                         CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
463                         return 1;
464                 }
465         }
466         else if (CTX_data_equals(member, "gpencil_data")) {
467                 /* FIXME: for some reason, CTX_data_active_object(C) returns NULL when called from these situations
468                  * (as outlined above - see Campbell's #ifdefs). That causes the get_active function to fail when
469                  * called from context. For that reason, we end up using an alternative where we pass everything in!
470                  */
471                 bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, scene, sa, obact);
472
473                 if (gpd) {
474                         CTX_data_id_pointer_set(result, &gpd->id);
475                         return 1;
476                 }
477         }
478         else if (CTX_data_equals(member, "gpencil_data_owner")) {
479                 /* pointer to which data/datablock owns the reference to the Grease Pencil data being used (as gpencil_data)
480                  * XXX: see comment for gpencil_data case...
481                  */
482                 bGPdata **gpd_ptr = NULL;
483                 PointerRNA ptr;
484
485                 /* get pointer to Grease Pencil Data */
486                 gpd_ptr = ED_gpencil_data_get_pointers_direct((ID *)sc, scene, sa, obact, &ptr);
487
488                 if (gpd_ptr) {
489                         CTX_data_pointer_set(result, ptr.id.data, ptr.type, ptr.data);
490                         return 1;
491                 }
492         }
493         else if (CTX_data_equals(member, "active_gpencil_layer")) {
494                 /* XXX: see comment for gpencil_data case... */
495                 bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, scene, sa, obact);
496
497                 if (gpd) {
498                         bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd);
499
500                         if (gpl) {
501                                 CTX_data_pointer_set(result, &gpd->id, &RNA_GPencilLayer, gpl);
502                                 return 1;
503                         }
504                 }
505         }
506         else if (CTX_data_equals(member, "active_gpencil_palette")) {
507                 /* XXX: see comment for gpencil_data case... */
508                 bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, scene, sa, obact);
509
510                 if (gpd) {
511                         bGPDpalette *palette = BKE_gpencil_palette_getactive(gpd);
512
513                         if (palette) {
514                                 CTX_data_pointer_set(result, &gpd->id, &RNA_GPencilPalette, palette);
515                                 return 1;
516                         }
517                 }
518         }
519         else if (CTX_data_equals(member, "active_gpencil_palettecolor")) {
520                 /* XXX: see comment for gpencil_data case... */
521                 bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, scene, sa, obact);
522
523                 if (gpd) {
524                         bGPDpalette *palette = BKE_gpencil_palette_getactive(gpd);
525
526                         if (palette) {
527                                 bGPDpalettecolor *palcolor = BKE_gpencil_palettecolor_getactive(palette);
528                                 if (palcolor) {
529                                         CTX_data_pointer_set(result, &gpd->id, &RNA_GPencilPaletteColor, palcolor);
530                                         return 1;
531                                 }
532                         }
533                 }
534         }
535         else if (CTX_data_equals(member, "active_gpencil_brush")) {
536                 /* XXX: see comment for gpencil_data case... */
537                 bGPDbrush *brush = BKE_gpencil_brush_getactive(scene->toolsettings);
538
539                 if (brush) {
540                         CTX_data_pointer_set(result, &scene->id, &RNA_GPencilBrush, brush);
541                         return 1;
542                 }
543         }
544         else if (CTX_data_equals(member, "active_gpencil_frame")) {
545                 /* XXX: see comment for gpencil_data case... */
546                 bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, scene, sa, obact);
547
548                 if (gpd) {
549                         bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd);
550
551                         if (gpl) {
552                                 CTX_data_pointer_set(result, &gpd->id, &RNA_GPencilLayer, gpl->actframe);
553                                 return 1;
554                         }
555                 }
556         }
557         else if (CTX_data_equals(member, "visible_gpencil_layers")) {
558                 /* XXX: see comment for gpencil_data case... */
559                 bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, scene, sa, obact);
560
561                 if (gpd) {
562                         bGPDlayer *gpl;
563
564                         for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
565                                 if ((gpl->flag & GP_LAYER_HIDE) == 0) {
566                                         CTX_data_list_add(result, &gpd->id, &RNA_GPencilLayer, gpl);
567                                 }
568                         }
569                         CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
570                         return 1;
571                 }
572         }
573         else if (CTX_data_equals(member, "editable_gpencil_layers")) {
574                 /* XXX: see comment for gpencil_data case... */
575                 bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, scene, sa, obact);
576
577                 if (gpd) {
578                         bGPDlayer *gpl;
579
580                         for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
581                                 if (gpencil_layer_is_editable(gpl)) {
582                                         CTX_data_list_add(result, &gpd->id, &RNA_GPencilLayer, gpl);
583                                 }
584                         }
585                         CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
586                         return 1;
587                 }
588         }
589         else if (CTX_data_equals(member, "editable_gpencil_strokes")) {
590                 /* XXX: see comment for gpencil_data case... */
591                 bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, scene, sa, obact);
592
593                 if (gpd) {
594                         bGPDlayer *gpl;
595
596                         for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
597                                 if (gpencil_layer_is_editable(gpl) && (gpl->actframe)) {
598                                         bGPDframe *gpf = gpl->actframe;
599                                         bGPDstroke *gps;
600
601                                         for (gps = gpf->strokes.first; gps; gps = gps->next) {
602                                                 if (ED_gpencil_stroke_can_use_direct(sa, gps)) {
603                                                         /* check if the color is editable */
604                                                         if (ED_gpencil_stroke_color_use(gpl, gps) == false) {
605                                                                 continue;
606                                                         }
607
608                                                         CTX_data_list_add(result, &gpd->id, &RNA_GPencilStroke, gps);
609                                                 }
610                                         }
611                                 }
612                         }
613                         CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
614                         return 1;
615                 }
616         }
617         else if (CTX_data_equals(member, "active_operator")) {
618                 wmOperator *op = NULL;
619
620                 SpaceFile *sfile = CTX_wm_space_file(C);
621                 if (sfile) {
622                         op = sfile->op;
623                 }
624                 else if ((op = UI_context_active_operator_get(C))) {
625                         /* do nothing */
626                 }
627                 else {
628                         /* note, this checks poll, could be a problem, but this also
629                          * happens for the toolbar */
630                         op = WM_operator_last_redo(C);
631                 }
632                 /* TODO, get the operator from popup's */
633
634                 if (op && op->ptr) {
635                         CTX_data_pointer_set(result, NULL, &RNA_Operator, op);
636                         return 1;
637                 }
638         }
639         else if (CTX_data_equals(member, "selected_editable_fcurves")) {
640                 bAnimContext ac;
641
642                 if (ANIM_animdata_get_context(C, &ac) && ELEM(ac.spacetype, SPACE_ACTION, SPACE_IPO)) {
643                         bAnimListElem *ale;
644                         ListBase anim_data = {NULL, NULL};
645
646                         int filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_NODUPLIS | ANIMFILTER_SEL) |
647                                      (ac.spacetype == SPACE_IPO ? ANIMFILTER_CURVE_VISIBLE : ANIMFILTER_LIST_VISIBLE);
648
649                         ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
650
651                         for (ale = anim_data.first; ale; ale = ale->next) {
652                                 if (ale->type == ANIMTYPE_FCURVE)
653                                         CTX_data_list_add(result, ale->id, &RNA_FCurve, ale->data);
654                         }
655
656                         ANIM_animdata_freelist(&anim_data);
657
658                         CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
659                         return 1;
660                 }
661         }
662         else {
663                 return 0; /* not found */
664         }
665
666         return -1; /* found but not available */
667 }
668