b7e2a3325cb9ac2443019e16359a7572a445560a
[blender-staging.git] / source / blender / editors / space_buttons / buttons_context.c
1 /**
2  * $Id:
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. 
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2009 Blender Foundation.
21  * All rights reserved.
22  *
23  * Contributor(s): Blender Foundation
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 #include <stdlib.h>
29 #include <string.h>
30
31 #include "MEM_guardedalloc.h"
32
33 #include "DNA_armature_types.h"
34 #include "DNA_lamp_types.h"
35 #include "DNA_material_types.h"
36 #include "DNA_modifier_types.h"
37 #include "DNA_object_types.h"
38 #include "DNA_scene_types.h"
39 #include "DNA_screen_types.h"
40 #include "DNA_space_types.h"
41 #include "DNA_particle_types.h"
42 #include "DNA_texture_types.h"
43 #include "DNA_world_types.h"
44
45 #include "BLI_listbase.h"
46
47 #include "BKE_context.h"
48 #include "BKE_material.h"
49 #include "BKE_modifier.h"
50 #include "BKE_particle.h"
51 #include "BKE_screen.h"
52 #include "BKE_utildefines.h"
53 #include "BKE_world.h"
54
55 #include "RNA_access.h"
56
57 #include "ED_armature.h"
58 #include "ED_screen.h"
59
60 #include "UI_interface.h"
61 #include "UI_resources.h"
62
63 #include "buttons_intern.h"     // own include
64
65 typedef struct ButsContextPath {
66         PointerRNA ptr[8];
67         int len;
68         int worldtex;
69 } ButsContextPath;
70
71 static int set_pointer_type(ButsContextPath *path, bContextDataResult *result, StructRNA *type)
72 {
73         PointerRNA *ptr;
74         int a;
75
76         for(a=0; a<path->len; a++) {
77                 ptr= &path->ptr[a];
78
79                 if(RNA_struct_is_a(ptr->type, type)) {
80                         CTX_data_pointer_set(result, ptr->id.data, ptr->type, ptr->data);
81                         return 1;
82                 }
83         }
84
85         return 0;
86 }
87
88 static PointerRNA *get_pointer_type(ButsContextPath *path, StructRNA *type)
89 {
90         PointerRNA *ptr;
91         int a;
92
93         for(a=0; a<path->len; a++) {
94                 ptr= &path->ptr[a];
95
96                 if(RNA_struct_is_a(ptr->type, type))
97                         return ptr;
98         }
99
100         return NULL;
101 }
102
103 /************************* Creating the Path ************************/
104
105 static int buttons_context_path_scene(ButsContextPath *path)
106 {
107         PointerRNA *ptr= &path->ptr[path->len-1];
108
109         /* this one just verifies */
110         return RNA_struct_is_a(ptr->type, &RNA_Scene);
111 }
112
113 static int buttons_context_path_world(ButsContextPath *path)
114 {
115         Scene *scene;
116         PointerRNA *ptr= &path->ptr[path->len-1];
117
118         /* if we already have a (pinned) world, we're done */
119         if(RNA_struct_is_a(ptr->type, &RNA_World)) {
120                 return 1;
121         }
122         /* if we have a scene, use the scene's world */
123         else if(buttons_context_path_scene(path)) {
124                 scene= path->ptr[path->len-1].data;
125
126                 RNA_id_pointer_create(&scene->world->id, &path->ptr[path->len]);
127                 path->len++;
128
129                 return 1;
130         }
131
132         /* no path to a world possible */
133         return 0;
134 }
135
136
137 static int buttons_context_path_object(ButsContextPath *path)
138 {
139         Scene *scene;
140         Object *ob;
141         PointerRNA *ptr= &path->ptr[path->len-1];
142
143         /* if we already have a (pinned) object, we're done */
144         if(RNA_struct_is_a(ptr->type, &RNA_Object)) {
145                 return 1;
146         }
147         /* if we have a scene, use the scene's active object */
148         else if(buttons_context_path_scene(path)) {
149                 scene= path->ptr[path->len-1].data;
150                 ob= (scene->basact)? scene->basact->object: NULL;
151
152                 if(ob) {
153                         RNA_id_pointer_create(&ob->id, &path->ptr[path->len]);
154                         path->len++;
155
156                         return 1;
157                 }
158         }
159
160         /* no path to a object possible */
161         return 0;
162 }
163
164 static int buttons_context_path_data(ButsContextPath *path, int type)
165 {
166         Object *ob;
167         PointerRNA *ptr= &path->ptr[path->len-1];
168
169         /* if we already have a data, we're done */
170         if(RNA_struct_is_a(ptr->type, &RNA_Mesh) && (type == -1 || type == OB_MESH)) return 1;
171         else if(RNA_struct_is_a(ptr->type, &RNA_Curve) && (type == -1 || ELEM3(type, OB_CURVE, OB_SURF, OB_FONT))) return 1;
172         else if(RNA_struct_is_a(ptr->type, &RNA_Armature) && (type == -1 || type == OB_ARMATURE)) return 1;
173         else if(RNA_struct_is_a(ptr->type, &RNA_MetaBall) && (type == -1 || type == OB_MBALL)) return 1;
174         else if(RNA_struct_is_a(ptr->type, &RNA_Lattice) && (type == -1 || type == OB_LATTICE)) return 1;
175         else if(RNA_struct_is_a(ptr->type, &RNA_Camera) && (type == -1 || type == OB_CAMERA)) return 1;
176         else if(RNA_struct_is_a(ptr->type, &RNA_Lamp) && (type == -1 || type == OB_LAMP)) return 1;
177         /* try to get an object in the path, no pinning supported here */
178         else if(buttons_context_path_object(path)) {
179                 ob= path->ptr[path->len-1].data;
180
181                 if(ob && (type == -1 || type == ob->type)) {
182                         RNA_id_pointer_create(ob->data, &path->ptr[path->len]);
183                         path->len++;
184
185                         return 1;
186                 }
187         }
188
189         /* no path to data possible */
190         return 0;
191 }
192
193 static int buttons_context_path_modifier(ButsContextPath *path)
194 {
195         Object *ob;
196
197         if(buttons_context_path_object(path)) {
198                 ob= path->ptr[path->len-1].data;
199
200                 if(ob && ELEM4(ob->type, OB_MESH, OB_CURVE, OB_FONT, OB_SURF))
201                         return 1;
202         }
203
204         return 0;
205 }
206
207 static int buttons_context_path_material(ButsContextPath *path)
208 {
209         Object *ob;
210         PointerRNA *ptr= &path->ptr[path->len-1];
211         Material *ma;
212
213         /* if we already have a (pinned) material, we're done */
214         if(RNA_struct_is_a(ptr->type, &RNA_Material)) {
215                 return 1;
216         }
217         /* if we have an object, use the object material slot */
218         else if(buttons_context_path_object(path)) {
219                 ob= path->ptr[path->len-1].data;
220
221                 if(ob && ob->type && (ob->type<OB_LAMP)) {
222                         ma= give_current_material(ob, ob->actcol);
223                         RNA_id_pointer_create(&ma->id, &path->ptr[path->len]);
224                         path->len++;
225                         return 1;
226                 }
227         }
228
229         /* no path to a material possible */
230         return 0;
231 }
232
233 static Bone *find_active_bone(Bone *bone)
234 {
235         Bone *active;
236
237         for(; bone; bone=bone->next) {
238                 if(bone->flag & BONE_ACTIVE)
239                         return bone;
240
241                 active= find_active_bone(bone->childbase.first);
242                 if(active)
243                         return active;
244         }
245
246         return NULL;
247 }
248
249 static int buttons_context_path_bone(ButsContextPath *path)
250 {
251         bArmature *arm;
252         Bone *bone;
253         EditBone *edbo;
254
255         /* if we have an armature, get the active bone */
256         if(buttons_context_path_data(path, OB_ARMATURE)) {
257                 arm= path->ptr[path->len-1].data;
258
259                 if(arm->edbo) {
260                         for(edbo=arm->edbo->first; edbo; edbo=edbo->next) {
261                                 if(edbo->flag & BONE_ACTIVE) {
262                                         RNA_pointer_create(&arm->id, &RNA_EditBone, edbo, &path->ptr[path->len]);
263                                         path->len++;
264                                         return 1;
265                                 }
266                         }
267                 }
268                 else {
269                         bone= find_active_bone(arm->bonebase.first);
270
271                         if(bone) {
272                                 RNA_pointer_create(&arm->id, &RNA_Bone, bone, &path->ptr[path->len]);
273                                 path->len++;
274                                 return 1;
275                         }
276                 }
277         }
278
279         /* no path to a bone possible */
280         return 0;
281 }
282
283 static int buttons_context_path_particle(ButsContextPath *path)
284 {
285         Object *ob;
286         ParticleSystem *psys;
287
288         /* if we have an object, get the active particle system */
289         if(buttons_context_path_object(path)) {
290                 ob= path->ptr[path->len-1].data;
291
292                 if(ob && ob->type == OB_MESH) {
293                         psys= psys_get_current(ob);
294
295                         RNA_pointer_create(&ob->id, &RNA_ParticleSystem, psys, &path->ptr[path->len]);
296                         path->len++;
297                         return 1;
298                 }
299         }
300
301         /* no path to a particle system possible */
302         return 0;
303 }
304
305 static int buttons_context_path_texture(ButsContextPath *path)
306 {
307         Material *ma;
308         Lamp *la;
309         World *wo;
310         MTex *mtex;
311         Tex *tex;
312         PointerRNA *ptr= &path->ptr[path->len-1];
313
314         /* if we already have a (pinned) texture, we're done */
315         if(RNA_struct_is_a(ptr->type, &RNA_Texture)) {
316                 return 1;
317         }
318         /* try world */
319         else if(path->worldtex && buttons_context_path_world(path)) {
320                 wo= path->ptr[path->len-1].data;
321
322                 if(wo) {
323                         mtex= wo->mtex[(int)wo->texact];
324                         tex= (mtex)? mtex->tex: NULL;
325
326                         RNA_id_pointer_create(&tex->id, &path->ptr[path->len]);
327                         path->len++;
328                         return 1;
329                 }
330         }
331         /* try material */
332         else if(buttons_context_path_material(path)) {
333                 ma= path->ptr[path->len-1].data;
334
335                 if(ma) {
336                         mtex= ma->mtex[(int)ma->texact];
337                         tex= (mtex)? mtex->tex: NULL;
338
339                         RNA_id_pointer_create(&tex->id, &path->ptr[path->len]);
340                         path->len++;
341                         return 1;
342                 }
343         }
344         /* try lamp */
345         else if(buttons_context_path_data(path, OB_LAMP)) {
346                 la= path->ptr[path->len-1].data;
347
348                 if(la) {
349                         mtex= la->mtex[(int)la->texact];
350                         tex= (mtex)? mtex->tex: NULL;
351
352                         RNA_id_pointer_create(&tex->id, &path->ptr[path->len]);
353                         path->len++;
354                         return 1;
355                 }
356         }
357         /* TODO: material nodes, brush */
358
359         /* no path to a particle system possible */
360         return 0;
361 }
362
363 static int buttons_context_path(const bContext *C, ButsContextPath *path, int mainb, int worldtex)
364 {
365         SpaceButs *sbuts= (SpaceButs*)CTX_wm_space_data(C);
366         ID *id;
367         int found;
368
369         memset(path, 0, sizeof(*path));
370         path->worldtex= worldtex;
371
372         /* if some ID datablock is pinned, set the root pointer */
373         if(sbuts->pinid) {
374                 id= sbuts->pinid;
375
376                 RNA_id_pointer_create(id, &path->ptr[0]);
377                 path->len++;
378         }
379
380         /* no pinned root, use scene as root */
381         if(path->len == 0) {
382                 id= (ID*)CTX_data_scene(C);
383                 RNA_id_pointer_create(id, &path->ptr[0]);
384                 path->len++;
385         }
386
387         /* now for each buttons context type, we try to construct a path,
388          * tracing back recursively */
389         switch(mainb) {
390                 case BCONTEXT_SCENE:
391                         found= buttons_context_path_scene(path);
392                         break;
393                 case BCONTEXT_WORLD:
394                         found= buttons_context_path_world(path);
395                         break;
396                 case BCONTEXT_OBJECT:
397                 case BCONTEXT_PHYSICS:
398                 case BCONTEXT_CONSTRAINT:
399                         found= buttons_context_path_object(path);
400                         break;
401                 case BCONTEXT_MODIFIER:
402                         found= buttons_context_path_modifier(path);
403                         break;
404                 case BCONTEXT_DATA:
405                         found= buttons_context_path_data(path, -1);
406                         break;
407                 case BCONTEXT_PARTICLE:
408                         found= buttons_context_path_particle(path);
409                         break;
410                 case BCONTEXT_MATERIAL:
411                         found= buttons_context_path_material(path);
412                         break;
413                 case BCONTEXT_TEXTURE:
414                         found= buttons_context_path_texture(path);
415                         break;
416                 case BCONTEXT_BONE:
417                         found= buttons_context_path_bone(path);
418                         if(!found)
419                                 found= buttons_context_path_data(path, OB_ARMATURE);
420                         break;
421                 default:
422                         found= 0;
423                         break;
424         }
425
426         return found;
427 }
428
429 void buttons_context_compute(const bContext *C, SpaceButs *sbuts)
430 {
431         ButsContextPath *path;
432         PointerRNA *ptr;
433         int a, worldtex, flag= 0;
434
435         if(!sbuts->path)
436                 sbuts->path= MEM_callocN(sizeof(ButsContextPath), "ButsContextPath");
437         
438         path= sbuts->path;
439         worldtex= (sbuts->flag & SB_WORLD_TEX);
440         
441         /* for each context, see if we can compute a valid path to it, if
442          * this is the case, we know we have to display the button */
443         for(a=0; a<BCONTEXT_TOT; a++) {
444                 if(buttons_context_path(C, path, a, worldtex)) {
445                         flag |= (1<<a);
446
447                         /* setting icon for data context */
448                         if(a == BCONTEXT_DATA) {
449                                 ptr= &path->ptr[path->len-1];
450
451                                 if(ptr->type)
452                                         sbuts->dataicon= RNA_struct_ui_icon(ptr->type);
453                                 else
454                                         sbuts->dataicon= ICON_EMPTY_DATA;
455                         }
456                 }
457         }
458
459         /* in case something becomes invalid, change */
460         if((flag & (1 << sbuts->mainb)) == 0) {
461                 if(flag & BCONTEXT_OBJECT) {
462                         sbuts->mainb= BCONTEXT_OBJECT;
463                 }
464                 else {
465                         for(a=0; a<BCONTEXT_TOT; a++) {
466                                 if(flag & (1 << a)) {
467                                         sbuts->mainb= a;
468                                         break;
469                                 }
470                         }
471                 }
472         }
473
474         buttons_context_path(C, path, sbuts->mainb, worldtex);
475
476         if(!(flag & (1 << sbuts->mainb))) {
477                 if(flag & (1 << BCONTEXT_OBJECT))
478                         sbuts->mainb= BCONTEXT_OBJECT;
479                 else
480                         sbuts->mainb= BCONTEXT_SCENE;
481         }
482
483         sbuts->pathflag= flag;
484 }
485
486 /************************* Context Callback ************************/
487
488 int buttons_context(const bContext *C, const char *member, bContextDataResult *result)
489 {
490         SpaceButs *sbuts= (SpaceButs*)CTX_wm_space_data(C);
491         ButsContextPath *path= sbuts?sbuts->path:NULL;
492
493         if(!path)
494                 return 0;
495
496         /* here we handle context, getting data from precomputed path */
497         if(CTX_data_dir(member)) {
498                 static const char *dir[] = {
499                         "world", "object", "meshe", "armature", "lattice", "curve",
500                         "meta_ball", "lamp", "camera", "material", "material_slot",
501                         "texture", "texture_slot", "bone", "edit_bone", "particle_system",
502                         "cloth", "soft_body", "fluid", "collision", NULL};
503
504                 CTX_data_dir_set(result, dir);
505                 return 1;
506         }
507         else if(CTX_data_equals(member, "world")) {
508                 set_pointer_type(path, result, &RNA_World);
509                 return 1;
510         }
511         else if(CTX_data_equals(member, "object")) {
512                 set_pointer_type(path, result, &RNA_Object);
513                 return 1;
514         }
515         else if(CTX_data_equals(member, "mesh")) {
516                 set_pointer_type(path, result, &RNA_Mesh);
517                 return 1;
518         }
519         else if(CTX_data_equals(member, "armature")) {
520                 set_pointer_type(path, result, &RNA_Armature);
521                 return 1;
522         }
523         else if(CTX_data_equals(member, "lattice")) {
524                 set_pointer_type(path, result, &RNA_Lattice);
525                 return 1;
526         }
527         else if(CTX_data_equals(member, "curve")) {
528                 set_pointer_type(path, result, &RNA_Curve);
529                 return 1;
530         }
531         else if(CTX_data_equals(member, "meta_ball")) {
532                 set_pointer_type(path, result, &RNA_MetaBall);
533                 return 1;
534         }
535         else if(CTX_data_equals(member, "lamp")) {
536                 set_pointer_type(path, result, &RNA_Lamp);
537                 return 1;
538         }
539         else if(CTX_data_equals(member, "camera")) {
540                 set_pointer_type(path, result, &RNA_Camera);
541                 return 1;
542         }
543         else if(CTX_data_equals(member, "material")) {
544                 set_pointer_type(path, result, &RNA_Material);
545                 return 1;
546         }
547         else if(CTX_data_equals(member, "texture")) {
548                 set_pointer_type(path, result, &RNA_Texture);
549                 return 1;
550         }
551         else if(CTX_data_equals(member, "material_slot")) {
552                 PointerRNA *ptr= get_pointer_type(path, &RNA_Object);
553
554                 if(ptr) {
555                         Object *ob= ptr->data;
556
557                         if(ob && ob->type && (ob->type<OB_LAMP) && ob->totcol)
558                                 CTX_data_pointer_set(result, &ob->id, &RNA_MaterialSlot, ob->mat+ob->actcol-1);
559                 }
560
561                 return 1;
562         }
563         else if(CTX_data_equals(member, "texture_slot")) {
564                 PointerRNA *ptr;
565
566                 if((ptr=get_pointer_type(path, &RNA_Material))) {
567                         Material *ma= ptr->data;
568
569                         if(ma)
570                                 CTX_data_pointer_set(result, &ma->id, &RNA_MaterialTextureSlot, ma->mtex[(int)ma->texact]);
571                 }
572                 else if((ptr=get_pointer_type(path, &RNA_Lamp))) {
573                         Lamp *la= ptr->data;
574
575                         if(la)
576                                 CTX_data_pointer_set(result, &la->id, &RNA_LampTextureSlot, la->mtex[(int)la->texact]);
577                 }
578                 else if((ptr=get_pointer_type(path, &RNA_World))) {
579                         World *wo= ptr->data;
580
581                         if(wo)
582                                 CTX_data_pointer_set(result, &wo->id, &RNA_WorldTextureSlot, wo->mtex[(int)wo->texact]);
583                 }
584                 else if((ptr=get_pointer_type(path, &RNA_Brush))) { /* how to get this into context? */
585                         Brush *br= ptr->data;
586
587                         if(br)
588                                 CTX_data_pointer_set(result, &br->id, &RNA_TextureSlot, br->mtex[(int)br->texact]);
589                 }
590
591                 return 1;
592         }
593         else if(CTX_data_equals(member, "bone")) {
594                 set_pointer_type(path, result, &RNA_Bone);
595                 return 1;
596         }
597         else if(CTX_data_equals(member, "edit_bone")) {
598                 set_pointer_type(path, result, &RNA_EditBone);
599                 return 1;
600         }
601         else if(CTX_data_equals(member, "particle_system")) {
602                 set_pointer_type(path, result, &RNA_ParticleSystem);
603                 return 1;
604         }
605         else if(CTX_data_equals(member, "cloth")) {
606                 PointerRNA *ptr= get_pointer_type(path, &RNA_Object);
607
608                 if(ptr && ptr->data) {
609                         Object *ob= ptr->data;
610                         ModifierData *md= modifiers_findByType(ob, eModifierType_Cloth);
611                         CTX_data_pointer_set(result, &ob->id, &RNA_ClothModifier, md);
612                         return 1;
613                 }
614         }
615         else if(CTX_data_equals(member, "soft_body")) {
616                 PointerRNA *ptr= get_pointer_type(path, &RNA_Object);
617
618                 if(ptr && ptr->data) {
619                         Object *ob= ptr->data;
620                         ModifierData *md= modifiers_findByType(ob, eModifierType_Softbody);
621                         CTX_data_pointer_set(result, &ob->id, &RNA_SoftBodyModifier, md);
622                         return 1;
623                 }
624         }
625         else if(CTX_data_equals(member, "fluid")) {
626                 PointerRNA *ptr= get_pointer_type(path, &RNA_Object);
627
628                 if(ptr && ptr->data) {
629                         Object *ob= ptr->data;
630                         ModifierData *md= modifiers_findByType(ob, eModifierType_Fluidsim);
631                         CTX_data_pointer_set(result, &ob->id, &RNA_FluidSimulationModifier, md);
632                         return 1;
633                 }
634         }
635         else if(CTX_data_equals(member, "collision")) {
636                 PointerRNA *ptr= get_pointer_type(path, &RNA_Object);
637
638                 if(ptr && ptr->data) {
639                         Object *ob= ptr->data;
640                         ModifierData *md= modifiers_findByType(ob, eModifierType_Collision);
641                         CTX_data_pointer_set(result, &ob->id, &RNA_CollisionModifier, md);
642                         return 1;
643                 }
644         }
645
646         return 0;
647 }
648
649 /************************* Drawing the Path ************************/
650
651 static void pin_cb(bContext *C, void *arg1, void *arg2)
652 {
653         SpaceButs *sbuts= (SpaceButs*)CTX_wm_space_data(C);
654         ButsContextPath *path= sbuts->path;
655         PointerRNA *ptr;
656         int a;
657
658         if(sbuts->flag & SB_PIN_CONTEXT) {
659                 if(path->len) {
660                         for(a=path->len-1; a>=0; a--) {
661                                 ptr= &path->ptr[a];
662
663                                 if(ptr->id.data) {
664                                         sbuts->pinid= ptr->id.data;
665                                         break;
666                                 }
667                         }
668                 }
669         }
670         else
671                 sbuts->pinid= NULL;
672         
673         ED_area_tag_redraw(CTX_wm_area(C));
674 }
675
676 void buttons_context_draw(const bContext *C, uiLayout *layout)
677 {
678         SpaceButs *sbuts= (SpaceButs*)CTX_wm_space_data(C);
679         ButsContextPath *path= sbuts->path;
680         uiLayout *row;
681         uiBlock *block;
682         uiBut *but;
683         PointerRNA *ptr;
684         char namebuf[128], *name;
685         int a, icon;
686
687         if(!path)
688                 return;
689
690         row= uiLayoutRow(layout, 1);
691         uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_LEFT);
692
693         block= uiLayoutGetBlock(row);
694         uiBlockSetEmboss(block, UI_EMBOSSN);
695         but= uiDefIconButBitC(block, ICONTOG, SB_PIN_CONTEXT, 0, ICON_UNPINNED, 0, 0, UI_UNIT_X, UI_UNIT_Y, &sbuts->flag, 0, 0, 0, 0, "Follow context or keep fixed datablock displayed.");
696         uiButSetFunc(but, pin_cb, NULL, NULL);
697
698         for(a=0; a<path->len; a++) {
699                 ptr= &path->ptr[a];
700
701                 if(a != 0)
702                         uiDefIconBut(block, LABEL, 0, VICON_SMALL_TRI_RIGHT, 0, 0, 10, UI_UNIT_Y, NULL, 0, 0, 0, 0, "");
703
704                 if(ptr->data) {
705                         icon= RNA_struct_ui_icon(ptr->type);
706                         name= RNA_struct_name_get_alloc(ptr, namebuf, sizeof(namebuf));
707
708                         if(name) {
709                                 if(sbuts->mainb != BCONTEXT_SCENE && ptr->type == &RNA_Scene)
710                                         uiItemL(row, "", icon); /* save some space */
711                                 else
712                                         uiItemL(row, name, icon);
713
714                                 if(name != namebuf)
715                                         MEM_freeN(name);
716                         }
717                         else
718                                 uiItemL(row, "", icon);
719                 }
720         }
721 }
722
723 static void buttons_panel_context(const bContext *C, Panel *pa)
724 {
725         buttons_context_draw(C, pa->layout);
726 }
727
728 void buttons_context_register(ARegionType *art)
729 {
730         PanelType *pt;
731
732         pt= MEM_callocN(sizeof(PanelType), "spacetype buttons panel context");
733         strcpy(pt->idname, "BUTTONS_PT_context");
734         strcpy(pt->label, "Context");
735         pt->draw= buttons_panel_context;
736         pt->flag= PNL_NO_HEADER;
737         BLI_addtail(&art->paneltypes, pt);
738 }
739