Merge with -r 22620:23107.
[blender.git] / source / blender / editors / interface / interface_templates.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  * Contributor(s): Blender Foundation 2009.
21  *
22  * ***** END GPL LICENSE BLOCK *****
23  */
24
25 #include <stdlib.h>
26 #include <string.h>
27
28 #include "MEM_guardedalloc.h"
29
30 #include "DNA_scene_types.h"
31 #include "DNA_screen_types.h"
32
33 #include "BLI_string.h"
34
35 #include "BKE_context.h"
36 #include "BKE_icons.h"
37 #include "BKE_global.h"
38 #include "BKE_library.h"
39 #include "BKE_utildefines.h"
40
41 #include "ED_screen.h"
42 #include "ED_previewrender.h"
43
44 #include "RNA_access.h"
45
46 #include "WM_api.h"
47 #include "WM_types.h"
48
49 #include "UI_interface.h"
50 #include "UI_resources.h"
51 #include "interface_intern.h"
52
53 void ui_template_fix_linking()
54 {
55 }
56
57 /********************** Header Template *************************/
58
59 void uiTemplateHeader(uiLayout *layout, bContext *C, int menus)
60 {
61         uiBlock *block;
62         
63         block= uiLayoutFreeBlock(layout);
64         if(menus) ED_area_header_standardbuttons(C, block, 0);
65         else ED_area_header_switchbutton(C, block, 0);
66 }
67
68 /********************** Search Callbacks *************************/
69
70 typedef struct TemplateID {
71         PointerRNA ptr;
72         PropertyRNA *prop;
73
74         ListBase *idlb;
75 } TemplateID;
76
77 /* Search browse menu, assign  */
78 static void id_search_call_cb(struct bContext *C, void *arg_template, void *item)
79 {
80         TemplateID *template= (TemplateID*)arg_template;
81
82         /* ID */
83         if(item) {
84                 PointerRNA idptr;
85
86                 RNA_id_pointer_create(item, &idptr);
87                 RNA_property_pointer_set(&template->ptr, template->prop, idptr);
88                 RNA_property_update(C, &template->ptr, template->prop);
89         }
90 }
91
92 /* ID Search browse menu, do the search */
93 static void id_search_cb(const struct bContext *C, void *arg_template, char *str, uiSearchItems *items)
94 {
95         TemplateID *template= (TemplateID*)arg_template;
96         Scene *scene= CTX_data_scene(C);
97         ListBase *lb= template->idlb;
98         ID *id;
99         int iconid;
100
101         /* ID listbase */
102         for(id= lb->first; id; id= id->next) {
103                 if(BLI_strcasestr(id->name+2, str)) {
104                         iconid= ui_id_icon_get(scene, id);
105
106                         if(!uiSearchItemAdd(items, id->name+2, id, iconid))
107                                 break;
108                 }
109         }
110 }
111
112 /* ID Search browse menu, open */
113 static uiBlock *search_menu(bContext *C, ARegion *ar, void *arg_litem)
114 {
115         static char search[256];
116         static TemplateID template;
117         PointerRNA idptr;
118         wmEvent event;
119         wmWindow *win= CTX_wm_window(C);
120         uiBlock *block;
121         uiBut *but;
122         
123         /* clear initial search string, then all items show */
124         search[0]= 0;
125         /* arg_litem is malloced, can be freed by parent button */
126         template= *((TemplateID*)arg_litem);
127         
128         /* get active id for showing first item */
129         idptr= RNA_property_pointer_get(&template.ptr, template.prop);
130
131         block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
132         uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_RET_1);
133         
134         /* fake button, it holds space for search items */
135         uiDefBut(block, LABEL, 0, "", 10, 15, 150, uiSearchBoxhHeight(), NULL, 0, 0, 0, 0, NULL);
136         
137         but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, 256, 10, 0, 150, 19, "");
138         uiButSetSearchFunc(but, id_search_cb, &template, id_search_call_cb, idptr.data);
139         
140         uiBoundsBlock(block, 6);
141         uiBlockSetDirection(block, UI_DOWN);    
142         uiEndBlock(C, block);
143         
144         event= *(win->eventstate);      /* XXX huh huh? make api call */
145         event.type= EVT_BUT_OPEN;
146         event.val= KM_PRESS;
147         event.customdata= but;
148         event.customdatafree= FALSE;
149         wm_event_add(win, &event);
150         
151         return block;
152 }
153
154 /************************ ID Template ***************************/
155
156 static void template_id_cb(bContext *C, void *arg_litem, void *arg_event)
157 {
158         TemplateID *template= (TemplateID*)arg_litem;
159         PointerRNA idptr= RNA_property_pointer_get(&template->ptr, template->prop);
160         ID *id= idptr.data, *newid;
161         int event= GET_INT_FROM_POINTER(arg_event);
162         
163         switch(event) {
164                 case UI_ID_BROWSE:
165                 case UI_ID_PIN:
166                         printf("warning, id event %d shouldnt come here\n", event);
167                         break;
168                 case UI_ID_OPEN:
169                 case UI_ID_ADD_NEW:
170                         if(template->idlb->last) {
171                                 RNA_id_pointer_create(template->idlb->last, &idptr);
172                                 RNA_property_pointer_set(&template->ptr, template->prop, idptr);
173                                 RNA_property_update(C, &template->ptr, template->prop);
174                         }
175                         break;
176                 case UI_ID_DELETE:
177                         memset(&idptr, 0, sizeof(idptr));
178                         RNA_property_pointer_set(&template->ptr, template->prop, idptr);
179                         RNA_property_update(C, &template->ptr, template->prop);
180                         break;
181                 case UI_ID_FAKE_USER:
182                         if(id) {
183                                 if(id->flag & LIB_FAKEUSER) id->us++;
184                                 else id->us--;
185                         }
186                         else return;
187                         break;
188                 case UI_ID_LOCAL:
189                         if(id) {
190                                 if(id_make_local(id, 0)) {
191                                         /* reassign to get get proper updates/notifiers */
192                                         idptr= RNA_property_pointer_get(&template->ptr, template->prop);
193                                         RNA_property_pointer_set(&template->ptr, template->prop, idptr);
194                                         RNA_property_update(C, &template->ptr, template->prop);
195                                 }
196                         }
197                         break;
198                 case UI_ID_ALONE:
199                         if(id) {
200                                 /* make copy */
201                                 if(id_copy(id, &newid, 0) && newid) {
202                                         /* us is 1 by convention, but RNA_property_pointer_set
203                                            will also incremement it, so set it to zero */
204                                         newid->us= 0;
205
206                                         /* assign copy */
207                                         RNA_id_pointer_create(newid, &idptr);
208                                         RNA_property_pointer_set(&template->ptr, template->prop, idptr);
209                                         RNA_property_update(C, &template->ptr, template->prop);
210                                 }
211                         }
212                         break;
213 #if 0
214                 case UI_ID_AUTO_NAME:
215                         break;
216 #endif
217         }
218 }
219
220 static void template_ID(bContext *C, uiBlock *block, TemplateID *template, StructRNA *type, int flag, char *newop, char *openop, char *unlinkop)
221 {
222         uiBut *but;
223         PointerRNA idptr;
224         ListBase *lb;
225         ID *id, *idfrom;
226
227         idptr= RNA_property_pointer_get(&template->ptr, template->prop);
228         id= idptr.data;
229         idfrom= template->ptr.id.data;
230         lb= template->idlb;
231
232         uiBlockBeginAlign(block);
233
234         if(idptr.type)
235                 type= idptr.type;
236
237         if(flag & UI_ID_BROWSE) {
238                 but= uiDefBlockButN(block, search_menu, MEM_dupallocN(template), "", 0, 0, UI_UNIT_X*1.6, UI_UNIT_Y, "Browse ID data");
239                 if(type) {
240                         but->icon= RNA_struct_ui_icon(type);
241                         but->flag|= UI_HAS_ICON;
242                         but->flag|= UI_ICON_LEFT;
243                 }
244
245                 if((idfrom && idfrom->lib))
246                         uiButSetFlag(but, UI_BUT_DISABLED);
247         }
248
249         /* text button with name */
250         if(id) {
251                 char name[64];
252
253                 //text_idbutton(id, name);
254                 name[0]= '\0';
255                 but= uiDefButR(block, TEX, 0, name, 0, 0, UI_UNIT_X*6, UI_UNIT_Y, &idptr, "name", -1, 0, 0, -1, -1, NULL);
256                 uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_RENAME));
257
258                 if(id->lib) {
259                         if(id->flag & LIB_INDIRECT) {
260                                 but= uiDefIconBut(block, BUT, 0, ICON_LIBRARY_DATA_INDIRECT, 0,0,UI_UNIT_X,UI_UNIT_Y, 0, 0, 0, 0, 0,
261                                         "Indirect library datablock, cannot change.");
262                                 uiButSetFlag(but, UI_BUT_DISABLED);
263                         }
264                         else {
265                                 but= uiDefIconBut(block, BUT, 0, ICON_LIBRARY_DATA_DIRECT, 0,0,UI_UNIT_X,UI_UNIT_Y, 0, 0, 0, 0, 0,
266                                         "Direct linked library datablock, click to make local.");
267                                 if(!id_make_local(id, 1 /* test */) || (idfrom && idfrom->lib))
268                                         uiButSetFlag(but, UI_BUT_DISABLED);
269                         }
270
271                         uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_LOCAL));
272                 }
273
274                 if(id->us > 1) {
275                         char str[32];
276
277                         sprintf(str, "%d", id->us);
278
279                         if(id->us<10)
280                                 but= uiDefBut(block, BUT, 0, str, 0,0,UI_UNIT_X,UI_UNIT_Y, 0, 0, 0, 0, 0, "Displays number of users of this data. Click to make a single-user copy.");
281                         else
282                                 but= uiDefBut(block, BUT, 0, str, 0,0,UI_UNIT_X+10,UI_UNIT_Y, 0, 0, 0, 0, 0, "Displays number of users of this data. Click to make a single-user copy.");
283
284                         uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_ALONE));
285                         if(!id_copy(id, NULL, 1 /* test only */) || (idfrom && idfrom->lib))
286                                 uiButSetFlag(but, UI_BUT_DISABLED);
287                 }
288         }
289         
290         if(flag & UI_ID_ADD_NEW) {
291                 int w= id?UI_UNIT_X: (flag & UI_ID_OPEN)? UI_UNIT_X*3: UI_UNIT_X*6;
292                 
293                 if(newop) {
294                         but= uiDefIconTextButO(block, BUT, newop, WM_OP_INVOKE_REGION_WIN, ICON_ZOOMIN, (id)? "": "New", 0, 0, w, UI_UNIT_Y, NULL);
295                         uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_ADD_NEW));
296                 }
297                 else {
298                         but= uiDefIconTextBut(block, BUT, 0, ICON_ZOOMIN, (id)? "": "New", 0, 0, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, NULL);
299                         uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_ADD_NEW));
300                 }
301
302                 if((idfrom && idfrom->lib))
303                         uiButSetFlag(but, UI_BUT_DISABLED);
304         }
305
306         if(flag & UI_ID_OPEN) {
307                 int w= id?UI_UNIT_X: (flag & UI_ID_ADD_NEW)? UI_UNIT_X*3: UI_UNIT_X*6;
308                 
309                 if(openop) {
310                         but= uiDefIconTextButO(block, BUT, openop, WM_OP_INVOKE_REGION_WIN, ICON_FILESEL, (id)? "": "Open", 0, 0, w, UI_UNIT_Y, NULL);
311                         uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_OPEN));
312                 }
313                 else {
314                         but= uiDefIconTextBut(block, BUT, 0, ICON_FILESEL, (id)? "": "Open", 0, 0, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, NULL);
315                         uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_OPEN));
316                 }
317
318                 if((idfrom && idfrom->lib))
319                         uiButSetFlag(but, UI_BUT_DISABLED);
320         }
321         
322         /* delete button */
323         if(id && (flag & UI_ID_DELETE)) {
324                 if(unlinkop) {
325                         but= uiDefIconButO(block, BUT, unlinkop, WM_OP_INVOKE_REGION_WIN, ICON_X, 0, 0, UI_UNIT_X, UI_UNIT_Y, NULL);
326                 }
327                 else {
328                         but= uiDefIconBut(block, BUT, 0, ICON_X, 0, 0, UI_UNIT_X, UI_UNIT_Y, NULL, 0, 0, 0, 0, NULL);
329                         uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_DELETE));
330                 }
331
332                 if((idfrom && idfrom->lib))
333                         uiButSetFlag(but, UI_BUT_DISABLED);
334         }
335         
336         uiBlockEndAlign(block);
337 }
338
339 void uiTemplateID(uiLayout *layout, bContext *C, PointerRNA *ptr, char *propname, char *newop, char *openop, char *unlinkop)
340 {
341         TemplateID *template;
342         uiBlock *block;
343         PropertyRNA *prop;
344         StructRNA *type;
345         int flag;
346
347         if(!ptr->data)
348                 return;
349
350         prop= RNA_struct_find_property(ptr, propname);
351
352         if(!prop || RNA_property_type(prop) != PROP_POINTER) {
353                 printf("uiTemplateID: pointer property not found: %s\n", propname);
354                 return;
355         }
356
357         template= MEM_callocN(sizeof(TemplateID), "TemplateID");
358         template->ptr= *ptr;
359         template->prop= prop;
360
361         flag= UI_ID_BROWSE|UI_ID_RENAME|UI_ID_DELETE;
362
363         if(newop)
364                 flag |= UI_ID_ADD_NEW;
365         if(openop)
366                 flag |= UI_ID_OPEN;
367
368         type= RNA_property_pointer_type(ptr, prop);
369         template->idlb= wich_libbase(CTX_data_main(C), RNA_type_to_ID_code(type));
370
371         if(template->idlb) {
372                 uiLayoutRow(layout, 1);
373                 block= uiLayoutGetBlock(layout);
374                 template_ID(C, block, template, type, flag, newop, openop, unlinkop);
375         }
376
377         MEM_freeN(template);
378 }
379
380 /************************ Modifier Template *************************/
381
382 #define ERROR_LIBDATA_MESSAGE "Can't edit external libdata"
383
384 #include <string.h>
385
386 #include "DNA_object_force.h"
387 #include "DNA_object_types.h"
388 #include "DNA_modifier_types.h"
389 #include "DNA_scene_types.h"
390
391 #include "BKE_depsgraph.h"
392 #include "BKE_DerivedMesh.h"
393 #include "BKE_global.h"
394 #include "BKE_modifier.h"
395 #include "BKE_object.h"
396 #include "BKE_particle.h"
397 #include "BKE_report.h"
398
399 #include "UI_resources.h"
400 #include "ED_util.h"
401
402 #include "BLI_arithb.h"
403 #include "BLI_listbase.h"
404
405 #include "ED_object.h"
406
407 static void modifiers_setOnCage(bContext *C, void *ob_v, void *md_v)
408 {
409         Object *ob = ob_v;
410         ModifierData *md;
411         
412         int i, cageIndex = modifiers_getCageIndex(ob, NULL );
413
414         for(i = 0, md=ob->modifiers.first; md; ++i, md=md->next) {
415                 if(md == md_v) {
416                         if(i >= cageIndex)
417                                 md->mode ^= eModifierMode_OnCage;
418                         break;
419                 }
420         }
421
422         WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob);
423         DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
424 }
425
426 static void modifiers_convertToReal(bContext *C, void *ob_v, void *md_v)
427 {
428         Object *ob = ob_v;
429         ModifierData *md = md_v;
430         ModifierData *nmd = modifier_new(md->type);
431
432         modifier_copyData(md, nmd);
433         nmd->mode &= ~eModifierMode_Virtual;
434
435         BLI_addhead(&ob->modifiers, nmd);
436
437         ob->partype = PAROBJECT;
438
439         WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob);
440         DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
441
442         ED_undo_push(C, "Modifier convert to real");
443 }
444
445 static int modifier_can_delete(ModifierData *md)
446 {
447         // fluid particle modifier can't be deleted here
448         if(md->type == eModifierType_ParticleSystem)
449                 if(((ParticleSystemModifierData *)md)->psys->part->type == PART_FLUID)
450                         return 0;
451
452         return 1;
453 }
454
455 static uiLayout *draw_modifier(uiLayout *layout, Object *ob, ModifierData *md, int index, int cageIndex, int lastCageIndex)
456 {
457         ModifierTypeInfo *mti = modifierType_getInfo(md->type);
458         PointerRNA ptr;
459         uiBut *but;
460         uiBlock *block;
461         uiLayout *column, *row, *result= NULL;
462         int isVirtual = md->mode & eModifierMode_Virtual;
463         // XXX short color = md->error?TH_REDALERT:TH_BUT_NEUTRAL;
464         char str[128];
465
466         /* create RNA pointer */
467         RNA_pointer_create(&ob->id, &RNA_Modifier, md, &ptr);
468
469         column= uiLayoutColumn(layout, 1);
470         uiLayoutSetContextPointer(column, "modifier", &ptr);
471
472         /* rounded header */
473         /* XXX uiBlockSetCol(block, color); */
474                 /* roundbox 4 free variables: corner-rounding, nop, roundbox type, shade */
475
476         row= uiLayoutRow(uiLayoutBox(column), 0);
477         uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_EXPAND);
478
479         block= uiLayoutGetBlock(row);
480
481         //uiDefBut(block, ROUNDBOX, 0, "", x-10, y-4, width, 25, NULL, 7.0, 0.0, 
482         //               (!isVirtual && (md->mode & eModifierMode_Expanded))?3:15, 20, ""); 
483         /* XXX uiBlockSetCol(block, TH_AUTO); */
484         
485         /* open/close icon */
486         if(!isVirtual) {
487                 uiBlockSetEmboss(block, UI_EMBOSSN);
488                 uiDefIconButBitI(block, ICONTOG, eModifierMode_Expanded, 0, ICON_TRIA_RIGHT, 0, 0, UI_UNIT_X, UI_UNIT_Y, &md->mode, 0.0, 0.0, 0.0, 0.0, "Collapse/Expand Modifier");
489         }
490         
491         /* modifier-type icon */
492         uiItemL(row, "", RNA_struct_ui_icon(ptr.type));
493         
494         uiBlockSetEmboss(block, UI_EMBOSS);
495         
496         if(isVirtual) {
497                 /* virtual modifier */
498                 sprintf(str, "%s parent deform", md->name);
499                 uiDefBut(block, LABEL, 0, str, 0, 0, 185, UI_UNIT_Y, NULL, 0.0, 0.0, 0.0, 0.0, "Modifier name"); 
500
501                 but = uiDefBut(block, BUT, 0, "Make Real", 0, 0, 80, 16, NULL, 0.0, 0.0, 0.0, 0.0, "Convert virtual modifier to a real modifier");
502                 uiButSetFunc(but, modifiers_convertToReal, ob, md);
503         }
504         else {
505                 /* real modifier */
506                 uiBlockBeginAlign(block);
507                 uiItemR(row, "", 0, &ptr, "name", 0);
508
509                 /* Softbody not allowed in this situation, enforce! */
510                 if(((md->type!=eModifierType_Softbody && md->type!=eModifierType_Collision) || !(ob->pd && ob->pd->deflect)) && (md->type!=eModifierType_Surface)) {
511                         uiItemR(row, "", ICON_SCENE, &ptr, "render", 0);
512                         uiItemR(row, "", ICON_RESTRICT_VIEW_OFF, &ptr, "realtime", 0);
513
514                         if(mti->flags & eModifierTypeFlag_SupportsEditmode)
515                                 uiItemR(row, "", ICON_EDITMODE_HLT, &ptr, "editmode", 0);
516                 }
517                 
518
519                 /* XXX uiBlockSetEmboss(block, UI_EMBOSSR); */
520
521                 if(ob->type==OB_MESH && modifier_couldBeCage(md) && index<=lastCageIndex) {
522
523                         /* XXX uiBlockSetCol(block, color); */
524                         but = uiDefIconBut(block, BUT, 0, ICON_MESH_DATA, 0, 0, 16, 20, NULL, 0.0, 0.0, 0.0, 0.0, "Apply modifier to editing cage during Editmode");
525                         uiButSetFunc(but, modifiers_setOnCage, ob, md);
526                         uiBlockEndAlign(block);
527                         /* XXX uiBlockSetCol(block, TH_AUTO); */
528                 }
529         }
530
531         /* up/down/delete */
532         if(!isVirtual) {
533                 /* XXX uiBlockSetCol(block, TH_BUT_ACTION); */
534                 uiBlockBeginAlign(block);
535                 uiItemO(row, "", VICON_MOVE_UP, "OBJECT_OT_modifier_move_up");
536                 uiItemO(row, "", VICON_MOVE_DOWN, "OBJECT_OT_modifier_move_down");
537                 uiBlockEndAlign(block);
538                 
539                 uiBlockSetEmboss(block, UI_EMBOSSN);
540
541                 if(modifier_can_delete(md))
542                         uiItemO(row, "", VICON_X, "OBJECT_OT_modifier_remove");
543
544                 /* XXX uiBlockSetCol(block, TH_AUTO); */
545         }
546
547         uiBlockSetEmboss(block, UI_EMBOSS);
548
549         if(!isVirtual && (md->mode & eModifierMode_Expanded)) {
550                 /* apply/convert/copy */
551                 uiLayout *box;
552
553                 box= uiLayoutBox(column);
554                 row= uiLayoutRow(box, 1);
555
556                 if(!isVirtual && (md->type!=eModifierType_Collision) && (md->type!=eModifierType_Surface)) {
557                         /* only here obdata, the rest of modifiers is ob level */
558                         uiBlockSetButLock(block, object_data_is_libdata(ob), ERROR_LIBDATA_MESSAGE);
559
560                         if(md->type==eModifierType_ParticleSystem) {
561                         ParticleSystem *psys= ((ParticleSystemModifierData *)md)->psys;
562
563                         if(!(ob->mode & OB_MODE_PARTICLE_EDIT))
564                                         if(ELEM3(psys->part->ren_as, PART_DRAW_PATH, PART_DRAW_GR, PART_DRAW_OB) && psys->pathcache)
565                                                 uiItemO(row, "Convert", 0, "OBJECT_OT_modifier_convert");
566                         }
567                         else
568                                 uiItemO(row, "Apply", 0, "OBJECT_OT_modifier_apply");
569                         
570                         uiBlockClearButLock(block);
571                         uiBlockSetButLock(block, ob && ob->id.lib, ERROR_LIBDATA_MESSAGE);
572
573                         if(!ELEM4(md->type, eModifierType_Fluidsim, eModifierType_Softbody, eModifierType_ParticleSystem, eModifierType_Cloth))
574                                 uiItemO(row, "Copy", 0, "OBJECT_OT_modifier_copy");
575                 }
576
577                 result= uiLayoutColumn(box, 0);
578                 block= uiLayoutFreeBlock(box);
579         }
580
581         if(md->error) {
582                 row = uiLayoutRow(uiLayoutBox(column), 0);
583
584                 /* XXX uiBlockSetCol(block, color); */
585                 uiItemL(row, md->error, ICON_ERROR);
586                 /* XXX uiBlockSetCol(block, TH_AUTO); */
587         }
588
589         return result;
590 }
591
592 uiLayout *uiTemplateModifier(uiLayout *layout, PointerRNA *ptr)
593 {
594         Object *ob;
595         ModifierData *md, *vmd;
596         int i, lastCageIndex, cageIndex;
597
598         /* verify we have valid data */
599         if(!RNA_struct_is_a(ptr->type, &RNA_Modifier)) {
600                 printf("uiTemplateModifier: expected modifier on object.\n");
601                 return NULL;
602         }
603
604         ob= ptr->id.data;
605         md= ptr->data;
606
607         if(!ob || !(GS(ob->id.name) == ID_OB)) {
608                 printf("uiTemplateModifier: expected modifier on object.\n");
609                 return NULL;
610         }
611         
612         uiBlockSetButLock(uiLayoutGetBlock(layout), (ob && ob->id.lib), ERROR_LIBDATA_MESSAGE);
613         
614         /* find modifier and draw it */
615         cageIndex = modifiers_getCageIndex(ob, &lastCageIndex);
616
617         // XXX virtual modifiers are not accesible for python
618         vmd = modifiers_getVirtualModifierList(ob);
619
620         for(i=0; vmd; i++, vmd=vmd->next) {
621                 if(md == vmd)
622                         return draw_modifier(layout, ob, md, i, cageIndex, lastCageIndex);
623                 else if(vmd->mode & eModifierMode_Virtual)
624                         i--;
625         }
626
627         return NULL;
628 }
629
630 /************************ Constraint Template *************************/
631
632 #include "DNA_action_types.h"
633 #include "DNA_constraint_types.h"
634
635 #include "BKE_action.h"
636 #include "BKE_constraint.h"
637
638 #define REDRAWIPO                                       1
639 #define REDRAWNLA                                       2
640 #define REDRAWBUTSOBJECT                        3               
641 #define REDRAWACTION                            4
642 #define B_CONSTRAINT_TEST                       5
643 #define B_CONSTRAINT_CHANGETARGET       6
644 #define B_CONSTRAINT_INF                        7
645 #define REMAKEIPO                                       8
646 #define B_DIFF                                          9
647
648 void do_constraint_panels(bContext *C, void *arg, int event)
649 {
650         Scene *scene= CTX_data_scene(C);
651         Object *ob= CTX_data_active_object(C);
652         
653         switch(event) {
654         case B_CONSTRAINT_TEST:
655                 // XXX allqueue(REDRAWVIEW3D, 0);
656                 // XXX allqueue(REDRAWBUTSOBJECT, 0);
657                 // XXX allqueue(REDRAWBUTSEDIT, 0);
658                 break;  // no handling
659         case B_CONSTRAINT_INF:
660                 /* influence; do not execute actions for 1 dag_flush */
661                 if (ob->pose)
662                         ob->pose->flag |= (POSE_LOCKED|POSE_DO_UNLOCK);
663                 break;
664         case B_CONSTRAINT_CHANGETARGET:
665                 if (ob->pose) ob->pose->flag |= POSE_RECALC;    // checks & sorts pose channels
666                 DAG_scene_sort(scene);
667                 break;
668         default:
669                 break;
670         }
671
672         object_test_constraints(ob);
673         
674         if(ob->pose) update_pose_constraint_flags(ob->pose);
675         
676         if(ob->type==OB_ARMATURE) DAG_id_flush_update(&ob->id, OB_RECALC_DATA|OB_RECALC_OB);
677         else DAG_id_flush_update(&ob->id, OB_RECALC_OB);
678         
679         // XXX allqueue(REDRAWVIEW3D, 0);
680         // XXX allqueue(REDRAWBUTSOBJECT, 0);
681         // XXX allqueue(REDRAWBUTSEDIT, 0);
682 }
683
684 static void constraint_active_func(bContext *C, void *ob_v, void *con_v)
685 {
686         ED_object_constraint_set_active(ob_v, con_v);
687 }
688
689 static void verify_constraint_name_func (bContext *C, void *con_v, void *name_v)
690 {
691         Object *ob= CTX_data_active_object(C);
692         bConstraint *con= con_v;
693         char oldname[32];       
694         
695         if (!con)
696                 return;
697         
698         /* put on the stack */
699         BLI_strncpy(oldname, (char *)name_v, 32);
700         
701         ED_object_constraint_rename(ob, con, oldname);
702         ED_object_constraint_set_active(ob, con);
703         // XXX allqueue(REDRAWACTION, 0); 
704 }
705
706 /* some commonly used macros in the constraints drawing code */
707 #define is_armature_target(target) (target && target->type==OB_ARMATURE)
708 #define is_armature_owner(ob) ((ob->type == OB_ARMATURE) && (ob->mode & OB_MODE_POSE))
709 #define is_geom_target(target) (target && (ELEM(target->type, OB_MESH, OB_LATTICE)) )
710
711 /* Helper function for draw constraint - draws constraint space stuff 
712  * This function should not be called if no menus are required 
713  * owner/target: -1 = don't draw menu; 0= not posemode, 1 = posemode 
714  */
715 static void draw_constraint_spaceselect (uiBlock *block, bConstraint *con, short xco, short yco, short owner, short target)
716 {
717         short tarx, ownx, iconx;
718         short bwidth;
719         short iconwidth = 20;
720         
721         /* calculate sizes and placement of menus */
722         if (owner == -1) {
723                 bwidth = 125;
724                 tarx = 120;
725                 ownx = 0;
726         }
727         else if (target == -1) {
728                 bwidth = 125;
729                 tarx = 0;
730                 ownx = 120;
731         }
732         else {
733                 bwidth = 100;
734                 tarx = 85;
735                 iconx = tarx + bwidth + 5;
736                 ownx = tarx + bwidth + iconwidth + 10;
737         }
738         
739         
740         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Convert:", xco, yco, 80,18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
741
742         /* Target-Space */
743         if (target == 1) {
744                 uiDefButC(block, MENU, B_CONSTRAINT_TEST, "Target Space %t|World Space %x0|Pose Space %x2|Local with Parent %x3|Local Space %x1", 
745                                                                                                 tarx, yco, bwidth, 18, &con->tarspace, 0, 0, 0, 0, "Choose space that target is evaluated in"); 
746         }
747         else if (target == 0) {
748                 uiDefButC(block, MENU, B_CONSTRAINT_TEST, "Target Space %t|World Space %x0|Local (Without Parent) Space %x1", 
749                                                                                 tarx, yco, bwidth, 18, &con->tarspace, 0, 0, 0, 0, "Choose space that target is evaluated in"); 
750         }
751         
752         if ((target != -1) && (owner != -1))
753                 uiDefIconBut(block, LABEL, 0, ICON_ARROW_LEFTRIGHT,
754                         iconx, yco, 20, 20, NULL, 0.0, 0.0, 0.0, 0.0, "");
755         
756         /* Owner-Space */
757         if (owner == 1) {
758                 uiDefButC(block, MENU, B_CONSTRAINT_TEST, "Owner Space %t|World Space %x0|Pose Space %x2|Local with Parent %x3|Local Space %x1", 
759                                                                                                 ownx, yco, bwidth, 18, &con->ownspace, 0, 0, 0, 0, "Choose space that owner is evaluated in");  
760         }
761         else if (owner == 0) {
762                 uiDefButC(block, MENU, B_CONSTRAINT_TEST, "Owner Space %t|World Space %x0|Local (Without Parent) Space %x1", 
763                                                                                 ownx, yco, bwidth, 18, &con->ownspace, 0, 0, 0, 0, "Choose space that owner is evaluated in");  
764         }
765 }
766
767 /* draw panel showing settings for a constraint */
768 static uiLayout *draw_constraint(uiLayout *layout, Object *ob, bConstraint *con)
769 {
770         bPoseChannel *pchan= get_active_posechannel(ob);
771         bConstraintTypeInfo *cti;
772         uiBlock *block;
773         uiLayout *result= NULL, *col, *box, *row, *subrow;
774         uiBut *but;
775         PointerRNA ptr;
776         char typestr[32];
777         short width = 265;
778         short proxy_protected, xco=0, yco=0;
779         int rb_col;
780
781         /* get constraint typeinfo */
782         cti= constraint_get_typeinfo(con);
783         if (cti == NULL) {
784                 /* exception for 'Null' constraint - it doesn't have constraint typeinfo! */
785                 if (con->type == CONSTRAINT_TYPE_NULL)
786                         strcpy(typestr, "Null");
787                 else
788                         strcpy(typestr, "Unknown");
789         }
790         else
791                 strcpy(typestr, cti->name);
792                 
793         /* determine whether constraint is proxy protected or not */
794         if (proxylocked_constraints_owner(ob, pchan))
795                 proxy_protected= (con->flag & CONSTRAINT_PROXY_LOCAL)==0;
796         else
797                 proxy_protected= 0;
798
799         /* unless button has own callback, it adds this callback to button */
800         block= uiLayoutGetBlock(layout);
801         uiBlockSetHandleFunc(block, do_constraint_panels, NULL);
802         uiBlockSetFunc(block, constraint_active_func, ob, con);
803
804         RNA_pointer_create(&ob->id, &RNA_Constraint, con, &ptr);
805
806         col= uiLayoutColumn(layout, 1);
807         uiLayoutSetContextPointer(col, "constraint", &ptr);
808
809         box= uiLayoutBox(col);
810         row= uiLayoutRow(box, 0);
811
812         block= uiLayoutGetBlock(box);
813
814         subrow= uiLayoutRow(row, 0);
815         uiLayoutSetAlignment(subrow, UI_LAYOUT_ALIGN_LEFT);
816
817         /* Draw constraint header */
818         uiBlockSetEmboss(block, UI_EMBOSSN);
819         
820         /* rounded header */
821         rb_col= (con->flag & CONSTRAINT_ACTIVE)?50:20;
822         
823         /* open/close */
824         uiDefIconButBitS(block, ICONTOG, CONSTRAINT_EXPAND, B_CONSTRAINT_TEST, ICON_TRIA_RIGHT, xco-10, yco, 20, 20, &con->flag, 0.0, 0.0, 0.0, 0.0, "Collapse/Expand Constraint");
825         
826         /* name */      
827         uiBlockSetEmboss(block, UI_EMBOSS);
828         
829         /* XXX if (con->flag & CONSTRAINT_DISABLE)
830                 uiBlockSetCol(block, TH_REDALERT);*/
831         
832         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, typestr, xco+10, yco, 100, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
833         
834         if(proxy_protected == 0) {
835                 but = uiDefBut(block, TEX, B_CONSTRAINT_TEST, "", xco+120, yco, 85, 18, con->name, 0.0, 29.0, 0.0, 0.0, "Constraint name"); 
836                 uiButSetFunc(but, verify_constraint_name_func, con, con->name);
837         }
838         else
839                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, con->name, xco+120, yco-1, 135, 19, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
840
841         // XXX uiBlockSetCol(block, TH_AUTO);   
842
843         subrow= uiLayoutRow(row, 0);
844         uiLayoutSetAlignment(subrow, UI_LAYOUT_ALIGN_RIGHT);
845         
846         /* proxy-protected constraints cannot be edited, so hide up/down + close buttons */
847         if (proxy_protected) {
848                 uiBlockSetEmboss(block, UI_EMBOSSN);
849                 
850                 /* draw a ghost icon (for proxy) and also a lock beside it, to show that constraint is "proxy locked" */
851                 uiDefIconBut(block, BUT, B_CONSTRAINT_TEST, ICON_GHOST, xco+244, yco, 19, 19, NULL, 0.0, 0.0, 0.0, 0.0, "Proxy Protected");
852                 uiDefIconBut(block, BUT, B_CONSTRAINT_TEST, ICON_LOCKED, xco+262, yco, 19, 19, NULL, 0.0, 0.0, 0.0, 0.0, "Proxy Protected");
853                 
854                 uiBlockSetEmboss(block, UI_EMBOSS);
855         }
856         else {
857                 short prev_proxylock, show_upbut, show_downbut;
858                 
859                 /* Up/Down buttons: 
860                  *      Proxy-constraints are not allowed to occur after local (non-proxy) constraints
861                  *      as that poses problems when restoring them, so disable the "up" button where
862                  *      it may cause this situation. 
863                  *
864                  *      Up/Down buttons should only be shown (or not greyed - todo) if they serve some purpose. 
865                  */
866                 if (proxylocked_constraints_owner(ob, pchan)) {
867                         if (con->prev) {
868                                 prev_proxylock= (con->prev->flag & CONSTRAINT_PROXY_LOCAL) ? 0 : 1;
869                         }
870                         else
871                                 prev_proxylock= 0;
872                 }
873                 else
874                         prev_proxylock= 0;
875                         
876                 show_upbut= ((prev_proxylock == 0) && (con->prev));
877                 show_downbut= (con->next) ? 1 : 0;
878                 
879                 if (show_upbut || show_downbut) {
880                         uiBlockBeginAlign(block);
881                                 uiBlockSetEmboss(block, UI_EMBOSS);
882                                 
883                                 if (show_upbut)
884                                         uiDefIconButO(block, BUT, "CONSTRAINT_OT_move_up", WM_OP_INVOKE_DEFAULT, VICON_MOVE_UP, xco+width-50, yco, 16, 18, "Move constraint up in constraint stack");
885                                 
886                                 if (show_downbut)
887                                         uiDefIconButO(block, BUT, "CONSTRAINT_OT_move_down", WM_OP_INVOKE_DEFAULT, VICON_MOVE_DOWN, xco+width-50+18, yco, 16, 18, "Move constraint down in constraint stack");
888                         uiBlockEndAlign(block);
889                 }
890                 
891                 
892                 /* Close 'button' - emboss calls here disable drawing of 'button' behind X */
893                 uiBlockSetEmboss(block, UI_EMBOSSN);
894                         uiDefIconButO(block, BUT, "CONSTRAINT_OT_delete", WM_OP_INVOKE_DEFAULT, ICON_X, xco+262, yco, 19, 19, "Delete constraint");
895                 uiBlockSetEmboss(block, UI_EMBOSS);
896         }
897         
898         /* Set but-locks for protected settings (magic numbers are used here!) */
899         if (proxy_protected)
900                 uiBlockSetButLock(block, 1, "Cannot edit Proxy-Protected Constraint");
901         
902         /* Draw constraint data */
903         if ((con->flag & CONSTRAINT_EXPAND) == 0) {
904                 (yco) -= 21;
905         }
906         else {
907                 box= uiLayoutBox(col);
908                 block= uiLayoutFreeBlock(box);
909
910                 switch (con->type) {
911 #ifndef DISABLE_PYTHON
912                 case CONSTRAINT_TYPE_PYTHON:
913                         {
914                                 bPythonConstraint *data = con->data;
915                                 bConstraintTarget *ct;
916                                 // uiBut *but2;
917                                 int tarnum, theight;
918                                 // static int pyconindex=0;
919                                 // char *menustr;
920                                 
921                                 theight = (data->tarnum)? (data->tarnum * 38) : (38);
922                                 
923                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Script:", xco+60, yco-24, 55, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
924                                 
925                                 /* do the scripts menu */
926                                 /* XXX menustr = buildmenu_pyconstraints(data->text, &pyconindex);
927                                 but2 = uiDefButI(block, MENU, B_CONSTRAINT_TEST, menustr,
928                                       xco+120, yco-24, 150, 20, &pyconindex,
929                                       0, 0, 0, 0, "Set the Script Constraint to use");
930                                 uiButSetFunc(but2, validate_pyconstraint_cb, data, &pyconindex);
931                                 MEM_freeN(menustr);      */
932                                 
933                                 /* draw target(s) */
934                                 if (data->flag & PYCON_USETARGETS) {
935                                         /* Draw target parameters */ 
936                                         for (ct=data->targets.first, tarnum=1; ct; ct=ct->next, tarnum++) {
937                                                 char tarstr[32];
938                                                 short yoffset= ((tarnum-1) * 38);
939         
940                                                 /* target label */
941                                                 sprintf(tarstr, "Target %d:", tarnum);
942                                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, tarstr, xco+45, yco-(48+yoffset), 100, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
943                                                 
944                                                 /* target space-selector - per target */
945                                                 if (is_armature_target(ct->tar)) {
946                                                         uiDefButS(block, MENU, B_CONSTRAINT_TEST, "Target Space %t|World Space %x0|Pose Space %x3|Local with Parent %x4|Local Space %x1", 
947                                                                                                                         xco+10, yco-(66+yoffset), 100, 18, &ct->space, 0, 0, 0, 0, "Choose space that target is evaluated in"); 
948                                                 }
949                                                 else {
950                                                         uiDefButS(block, MENU, B_CONSTRAINT_TEST, "Target Space %t|World Space %x0|Local (Without Parent) Space %x1", 
951                                                                                                                         xco+10, yco-(66+yoffset), 100, 18, &ct->space, 0, 0, 0, 0, "Choose space that target is evaluated in"); 
952                                                 }
953                                                 
954                                                 uiBlockBeginAlign(block);
955                                                         /* target object */
956                                                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", xco+120, yco-(48+yoffset), 150, 18, &ct->tar, "Target Object"); 
957                                                         
958                                                         /* subtarget */
959                                                         if (is_armature_target(ct->tar)) {
960                                                                 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", xco+120, yco-(66+yoffset),150,18, &ct->subtarget, 0, 24, 0, 0, "Subtarget Bone");
961                                                                 uiButSetCompleteFunc(but, autocomplete_bone, (void *)ct->tar);
962                                                         }
963                                                         else if (is_geom_target(ct->tar)) {
964                                                                 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "VG:", xco+120, yco-(66+yoffset),150,18, &ct->subtarget, 0, 24, 0, 0, "Name of Vertex Group defining 'target' points");
965                                                                 uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)ct->tar);
966                                                         }
967                                                         else {
968                                                                 strcpy(ct->subtarget, "");
969                                                         }
970                                                 uiBlockEndAlign(block);
971                                         }
972                                 }
973                                 else {
974                                         /* Draw indication that no target needed */
975                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", xco+60, yco-48, 55, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
976                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Not Applicable", xco+120, yco-48, 150, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
977                                 }
978                                 
979                                 /* settings */
980                                 uiBlockBeginAlign(block);
981                                         but=uiDefBut(block, BUT, B_CONSTRAINT_TEST, "Options", xco, yco-(52+theight), (width/2),18, NULL, 0, 24, 0, 0, "Change some of the constraint's settings.");
982                                         // XXX uiButSetFunc(but, BPY_pyconstraint_settings, data, NULL);
983                                         
984                                         but=uiDefBut(block, BUT, B_CONSTRAINT_TEST, "Refresh", xco+((width/2)+10), yco-(52+theight), (width/2),18, NULL, 0, 24, 0, 0, "Force constraint to refresh it's settings");
985                                 uiBlockEndAlign(block);
986                                 
987                                 /* constraint space settings */
988                                 draw_constraint_spaceselect(block, con, xco, yco-(73+theight), is_armature_owner(ob), -1);
989                         }
990                         break;
991 #endif 
992
993                 case CONSTRAINT_TYPE_NULL:
994                         {
995                                 uiItemL(box, "", 0);
996                         }
997                         break;
998                 default:
999                         result= box;
1000                         break;
1001                 }
1002         }
1003         
1004         /* clear any locks set up for proxies/lib-linking */
1005         uiBlockClearButLock(block);
1006
1007         return result;
1008 }
1009
1010 uiLayout *uiTemplateConstraint(uiLayout *layout, PointerRNA *ptr)
1011 {
1012         Object *ob;
1013         bConstraint *con;
1014
1015         /* verify we have valid data */
1016         if(!RNA_struct_is_a(ptr->type, &RNA_Constraint)) {
1017                 printf("uiTemplateConstraint: expected constraint on object.\n");
1018                 return NULL;
1019         }
1020
1021         ob= ptr->id.data;
1022         con= ptr->data;
1023
1024         if(!ob || !(GS(ob->id.name) == ID_OB)) {
1025                 printf("uiTemplateConstraint: expected constraint on object.\n");
1026                 return NULL;
1027         }
1028         
1029         uiBlockSetButLock(uiLayoutGetBlock(layout), (ob && ob->id.lib), ERROR_LIBDATA_MESSAGE);
1030
1031         /* hrms, the temporal constraint should not draw! */
1032         if(con->type==CONSTRAINT_TYPE_KINEMATIC) {
1033                 bKinematicConstraint *data= con->data;
1034                 if(data->flag & CONSTRAINT_IK_TEMP)
1035                         return NULL;
1036         }
1037
1038         return draw_constraint(layout, ob, con);
1039 }
1040
1041 /************************* Group Template ***************************/
1042
1043 #if 0
1044 static void do_add_groupmenu(void *arg, int event)
1045 {
1046         Object *ob= OBACT;
1047         
1048         if(ob) {
1049                 
1050                 if(event== -1) {
1051                         Group *group= add_group( "Group" );
1052                         add_to_group(group, ob);
1053                 }
1054                 else
1055                         add_to_group(BLI_findlink(&G.main->group, event), ob);
1056                         
1057                 ob->flag |= OB_FROMGROUP;
1058                 BASACT->flag |= OB_FROMGROUP;
1059                 allqueue(REDRAWBUTSOBJECT, 0);
1060                 allqueue(REDRAWVIEW3D, 0);
1061         }               
1062 }
1063
1064 static uiBlock *add_groupmenu(void *arg_unused)
1065 {
1066         uiBlock *block;
1067         Group *group;
1068         short xco=0, yco= 0, index=0;
1069         char str[32];
1070         
1071         block= uiNewBlock(&curarea->uiblocks, "add_constraintmenu", UI_EMBOSSP, UI_HELV, curarea->win);
1072         uiBlockSetButmFunc(block, do_add_groupmenu, NULL);
1073
1074         uiDefBut(block, BUTM, B_NOP, "ADD NEW",         0, 20, 160, 19, NULL, 0.0, 0.0, 1, -1, "");
1075         for(group= G.main->group.first; group; group= group->id.next, index++) {
1076                 
1077                 /*if(group->id.lib) strcpy(str, "L  ");*/ /* we cant allow adding objects inside linked groups, it wont be saved anyway */
1078                 if(group->id.lib==0) {
1079                         strcpy(str, "   ");
1080                         strcat(str, group->id.name+2);
1081                         uiDefBut(block, BUTM, B_NOP, str,       xco*160, -20*yco, 160, 19, NULL, 0.0, 0.0, 1, index, "");
1082                         
1083                         yco++;
1084                         if(yco>24) {
1085                                 yco= 0;
1086                                 xco++;
1087                         }
1088                 }
1089         }
1090         
1091         uiTextBoundsBlock(block, 50);
1092         uiBlockSetDirection(block, UI_DOWN);    
1093         
1094         return block;
1095 }
1096
1097 static void group_ob_rem(void *gr_v, void *ob_v)
1098 {
1099         Object *ob= OBACT;
1100         
1101         if(rem_from_group(gr_v, ob) && find_group(ob, NULL)==NULL) {
1102                 ob->flag &= ~OB_FROMGROUP;
1103                 BASACT->flag &= ~OB_FROMGROUP;
1104         }
1105         allqueue(REDRAWBUTSOBJECT, 0);
1106         allqueue(REDRAWVIEW3D, 0);
1107
1108 }
1109
1110 static void group_local(void *gr_v, void *unused)
1111 {
1112         Group *group= gr_v;
1113         
1114         group->id.lib= NULL;
1115         
1116         allqueue(REDRAWBUTSOBJECT, 0);
1117         allqueue(REDRAWVIEW3D, 0);
1118         
1119 }
1120
1121 uiLayout *uiTemplateGroup(uiLayout *layout, Object *ob, Group *group)
1122 {
1123         uiSetButLock(1, NULL);
1124         uiDefBlockBut(block, add_groupmenu, NULL, "Add to Group", 10,150,150,20, "Add Object to a new Group");
1125
1126         /* all groups */
1127         if(group->id.lib) {
1128                 uiLayoutRow()
1129                 uiBlockBeginAlign(block);
1130                 uiSetButLock(GET_INT_FROM_POINTER(group->id.lib), ERROR_LIBDATA_MESSAGE); /* We cant actually use this button */
1131                 uiDefBut(block, TEX, B_IDNAME, "GR:",   10, 120-yco, 100, 20, group->id.name+2, 0.0, 21.0, 0, 0, "Displays Group name. Click to change.");
1132                 uiClearButLock();
1133                 
1134                 but= uiDefIconBut(block, BUT, B_NOP, ICON_PARLIB, 110, 120-yco, 20, 20, NULL, 0.0, 0.0, 0.0, 0.0, "Make Group local");
1135                 uiButSetFunc(but, group_local, group, NULL);
1136                 uiBlockEndAlign(block);
1137         } else {
1138                 but = uiDefBut(block, TEX, B_IDNAME, "GR:",     10, 120-yco, 120, 20, group->id.name+2, 0.0, 21.0, 0, 0, "Displays Group name. Click to change.");
1139                 uiButSetFunc(but, test_idbutton_cb, group->id.name, NULL);
1140         }
1141         
1142         xco = 290;
1143         if(group->id.lib==0) { /* cant remove objects from linked groups */
1144                 but = uiDefIconBut(block, BUT, B_NOP, VICON_X, xco, 120-yco, 20, 20, NULL, 0.0, 0.0, 0.0, 0.0, "Remove Group membership");
1145                 uiButSetFunc(but, group_ob_rem, group, ob);
1146         }
1147 }
1148 #endif
1149
1150 /************************* Preview Template ***************************/
1151
1152 #include "DNA_lamp_types.h"
1153 #include "DNA_material_types.h"
1154 #include "DNA_world_types.h"
1155
1156 #define B_MATPRV 1
1157
1158 static void do_preview_buttons(bContext *C, void *arg, int event)
1159 {
1160         switch(event) {
1161                 case B_MATPRV:
1162                         WM_event_add_notifier(C, NC_MATERIAL|ND_SHADING, arg);
1163                         break;
1164         }
1165 }
1166
1167 void uiTemplatePreview(uiLayout *layout, ID *id, ID *parent, MTex *slot)
1168 {
1169         uiLayout *row, *col;
1170         uiBlock *block;
1171         Material *ma= NULL;
1172         ID *pid, *pparent;
1173         short *pr_texture= NULL;
1174
1175         if(id && !ELEM4(GS(id->name), ID_MA, ID_TE, ID_WO, ID_LA)) {
1176                 printf("uiTemplatePreview: expected ID of type material, texture, lamp or world.\n");
1177                 return;
1178         }
1179
1180         /* decide what to render */
1181         pid= id;
1182         pparent= NULL;
1183
1184         if(id && (GS(id->name) == ID_TE)) {
1185                 if(parent && (GS(parent->name) == ID_MA))
1186                         pr_texture= &((Material*)parent)->pr_texture;
1187                 else if(parent && (GS(parent->name) == ID_WO))
1188                         pr_texture= &((World*)parent)->pr_texture;
1189                 else if(parent && (GS(parent->name) == ID_LA))
1190                         pr_texture= &((Lamp*)parent)->pr_texture;
1191
1192                 if(pr_texture) {
1193                         if(*pr_texture == TEX_PR_OTHER)
1194                                 pid= parent;
1195                         else if(*pr_texture == TEX_PR_BOTH)
1196                                 pparent= parent;
1197                 }
1198         }
1199
1200         /* layout */
1201         block= uiLayoutGetBlock(layout);
1202         row= uiLayoutRow(layout, 0);
1203         col= uiLayoutColumn(row, 0);
1204         uiLayoutSetKeepAspect(col, 1);
1205         
1206         /* add preview */
1207         uiDefBut(block, BUT_EXTRA, 0, "", 0, 0, UI_UNIT_X*6, UI_UNIT_Y*6, pid, 0.0, 0.0, 0, 0, "");
1208         uiBlockSetDrawExtraFunc(block, ED_preview_draw, pparent, slot);
1209         uiBlockSetHandleFunc(block, do_preview_buttons, NULL);
1210         
1211         /* add buttons */
1212         if(pid) {
1213                 if(GS(pid->name) == ID_MA || (pparent && GS(pparent->name) == ID_MA)) {
1214                         if(GS(pid->name) == ID_MA) ma= (Material*)pid;
1215                         else ma= (Material*)pparent;
1216
1217                         uiLayoutColumn(row, 1);
1218
1219                         uiDefIconButC(block, ROW, B_MATPRV, ICON_MATPLANE,  0, 0,UI_UNIT_X*1.5,UI_UNIT_Y, &(ma->pr_type), 10, MA_FLAT, 0, 0, "Preview type: Flat XY plane");
1220                         uiDefIconButC(block, ROW, B_MATPRV, ICON_MATSPHERE, 0, 0,UI_UNIT_X*1.5,UI_UNIT_Y, &(ma->pr_type), 10, MA_SPHERE, 0, 0, "Preview type: Sphere");
1221                         uiDefIconButC(block, ROW, B_MATPRV, ICON_MATCUBE,   0, 0,UI_UNIT_X*1.5,UI_UNIT_Y, &(ma->pr_type), 10, MA_CUBE, 0, 0, "Preview type: Cube");
1222                         uiDefIconButC(block, ROW, B_MATPRV, ICON_MONKEY,    0, 0,UI_UNIT_X*1.5,UI_UNIT_Y, &(ma->pr_type), 10, MA_MONKEY, 0, 0, "Preview type: Monkey");
1223                         uiDefIconButC(block, ROW, B_MATPRV, ICON_HAIR,      0, 0,UI_UNIT_X*1.5,UI_UNIT_Y, &(ma->pr_type), 10, MA_HAIR, 0, 0, "Preview type: Hair strands");
1224                         uiDefIconButC(block, ROW, B_MATPRV, ICON_MAT_SPHERE_SKY, 0, 0,UI_UNIT_X*1.5,UI_UNIT_Y, &(ma->pr_type), 10, MA_SPHERE_A, 0, 0, "Preview type: Large sphere with sky");
1225                 }
1226
1227                 if(pr_texture) {
1228                         uiLayoutRow(layout, 1);
1229
1230                         uiDefButS(block, ROW, B_MATPRV, "Texture",  0, 0,UI_UNIT_X*10,UI_UNIT_Y, pr_texture, 10, TEX_PR_TEXTURE, 0, 0, "");
1231                         if(GS(parent->name) == ID_MA)
1232                                 uiDefButS(block, ROW, B_MATPRV, "Material",  0, 0,UI_UNIT_X*10,UI_UNIT_Y, pr_texture, 10, TEX_PR_OTHER, 0, 0, "");
1233                         else if(GS(parent->name) == ID_LA)
1234                                 uiDefButS(block, ROW, B_MATPRV, "Lamp",  0, 0,UI_UNIT_X*10,UI_UNIT_Y, pr_texture, 10, TEX_PR_OTHER, 0, 0, "");
1235                         else if(GS(parent->name) == ID_WO)
1236                                 uiDefButS(block, ROW, B_MATPRV, "World",  0, 0,UI_UNIT_X*10,UI_UNIT_Y, pr_texture, 10, TEX_PR_OTHER, 0, 0, "");
1237                         uiDefButS(block, ROW, B_MATPRV, "Both",  0, 0,UI_UNIT_X*10,UI_UNIT_Y, pr_texture, 10, TEX_PR_BOTH, 0, 0, "");
1238                 }
1239         }
1240 }
1241
1242 /********************** ColorRamp Template **************************/
1243
1244 void uiTemplateColorRamp(uiLayout *layout, ColorBand *coba, int expand)
1245 {
1246         uiBlock *block;
1247         rctf rect;
1248
1249         if(coba) {
1250                 rect.xmin= 0; rect.xmax= 200;
1251                 rect.ymin= 0; rect.ymax= 190;
1252                 
1253                 block= uiLayoutFreeBlock(layout);
1254                 colorband_buttons(block, coba, &rect, !expand);
1255         }
1256 }
1257
1258 /********************* CurveMapping Template ************************/
1259
1260 #include "DNA_color_types.h"
1261
1262 void uiTemplateCurveMapping(uiLayout *layout, CurveMapping *cumap, int type, int compact)
1263 {
1264         rctf rect;
1265
1266         if(cumap) {
1267                 if(compact) {
1268                         rect.xmin= 0; rect.xmax= 150;
1269                         rect.ymin= 0; rect.ymax= 140;
1270                 }
1271                 else {
1272                         rect.xmin= 0; rect.xmax= 200;
1273                         rect.ymin= 0; rect.ymax= 190;
1274                 }
1275                 
1276                 curvemap_layout(layout, cumap, type, 0, 0, &rect);
1277         }
1278 }
1279
1280 /********************* TriColor (ThemeWireColorSet) Template ************************/
1281
1282 void uiTemplateTriColorSet(uiLayout *layout, PointerRNA *ptr, char *propname)
1283 {
1284         uiLayout *row;
1285         PropertyRNA *prop;
1286         PointerRNA csPtr;
1287         
1288         if (!ptr->data)
1289                 return;
1290         
1291         prop= RNA_struct_find_property(ptr, propname);
1292         if (!prop) {
1293                 printf("uiTemplateTriColorSet: property not found: %s\n", propname);
1294                 return;
1295         }
1296         
1297         /* we lay out the data in a row as 3 color swatches */
1298         row= uiLayoutRow(layout, 1);
1299         
1300         /* nselected, selected, active color swatches */
1301         csPtr= RNA_property_pointer_get(ptr, prop);
1302         
1303         uiItemR(row, "", 0, &csPtr, "normal", 0);
1304         uiItemR(row, "", 0, &csPtr, "selected", 0);
1305         uiItemR(row, "", 0, &csPtr, "active", 0);
1306 }
1307
1308 /********************* Layer Buttons Template ************************/
1309
1310 // TODO:
1311 //      - option for showing extra info like whether layer has contents?
1312 //      - for now, grouping of layers is determined by dividing up the length of 
1313 //        the array of layer bitflags
1314
1315 void uiTemplateLayers(uiLayout *layout, PointerRNA *ptr, char *propname)
1316 {
1317         uiLayout *uRow, *uSplit, *uCol;
1318         PropertyRNA *prop;
1319         int groups, cols, layers;
1320         int group, col, layer, row;
1321         
1322         if (!ptr->data)
1323                 return;
1324         
1325         prop= RNA_struct_find_property(ptr, propname);
1326         if (!prop) {
1327                 printf("uiTemplateLayer: layers property not found: %s\n", propname);
1328                 return;
1329         }
1330         
1331         /* the number of layers determines the way we group them 
1332          *      - we want 2 rows only (for now)
1333          *      - the number of columns (cols) is the total number of buttons per row
1334          *        the 'remainder' is added to this, as it will be ok to have first row slightly wider if need be
1335          *      - for now, only split into groups if if group will have at least 5 items
1336          */
1337         layers= RNA_property_array_length(ptr, prop);
1338         cols= (layers / 2) + (layers % 2);
1339         groups= ((cols / 2) < 5) ? (1) : (cols / 2);
1340         
1341         /* layers are laid out going across rows, with the columns being divided into groups */
1342         if (groups > 1)
1343                 uSplit= uiLayoutSplit(layout, (1.0f/(float)groups));
1344         else    
1345                 uSplit= layout;
1346         
1347         for (group= 0; group < groups; group++) {
1348                 uCol= uiLayoutColumn(uSplit, 1);
1349                 
1350                 for (row= 0; row < 2; row++) {
1351                         uRow= uiLayoutRow(uCol, 1);
1352                         layer= groups*cols*row + cols*group;
1353                         
1354                         /* add layers as toggle buts */
1355                         for (col= 0; (col < cols) && (layer < layers); col++, layer++) {
1356                                 int icon=0; // XXX - add some way of setting this...
1357                                 uiItemFullR(uRow, "", icon, ptr, prop, layer, 0, UI_ITEM_R_TOGGLE);
1358                         }
1359                 }
1360         }
1361 }
1362
1363
1364 /************************* List Template **************************/
1365
1366 #if 0
1367 static void list_item_add(ListBase *lb, ListBase *itemlb, uiLayout *layout, PointerRNA *data)
1368 {
1369         CollectionPointerLink *link;
1370         uiListItem *item;
1371
1372         /* add to list to store in box */
1373         item= MEM_callocN(sizeof(uiListItem), "uiListItem");
1374         item->layout= layout;
1375         item->data= *data;
1376         BLI_addtail(itemlb, item);
1377
1378         /* add to list to return from function */
1379         link= MEM_callocN(sizeof(CollectionPointerLink), "uiTemplateList return");
1380         RNA_pointer_create(NULL, &RNA_UIListItem, item, &link->ptr);
1381         BLI_addtail(lb, link);
1382 }
1383 #endif
1384
1385 ListBase uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, char *propname, PointerRNA *activeptr, char *activepropname, int rows, int listtype)
1386 {
1387         //Scene *scene= CTX_data_scene(C);
1388         PropertyRNA *prop= NULL, *activeprop;
1389         PropertyType type, activetype;
1390         StructRNA *ptype;
1391         uiLayout *box, *row, *col, *subrow;
1392         uiBlock *block;
1393         uiBut *but;
1394         Panel *pa;
1395         ListBase lb, *itemlb;
1396         char *name, str[32];
1397         int icon=0, i= 0, activei= 0, len= 0, items, found, min, max;
1398
1399         lb.first= lb.last= NULL;
1400         
1401         /* validate arguments */
1402         block= uiLayoutGetBlock(layout);
1403         pa= block->panel;
1404
1405         if(!pa) {
1406                 printf("uiTemplateList: only works inside a panel.\n");
1407                 return lb;
1408         }
1409
1410         if(!activeptr->data)
1411                 return lb;
1412         
1413         if(ptr->data) {
1414                 prop= RNA_struct_find_property(ptr, propname);
1415                 if(!prop) {
1416                         printf("uiTemplateList: property not found: %s\n", propname);
1417                         return lb;
1418                 }
1419         }
1420
1421         activeprop= RNA_struct_find_property(activeptr, activepropname);
1422         if(!activeprop) {
1423                 printf("uiTemplateList: property not found: %s\n", activepropname);
1424                 return lb;
1425         }
1426
1427         if(prop) {
1428                 type= RNA_property_type(prop);
1429                 if(type != PROP_COLLECTION) {
1430                         printf("uiTemplateList: expected collection property.\n");
1431                         return lb;
1432                 }
1433         }
1434
1435         activetype= RNA_property_type(activeprop);
1436         if(activetype != PROP_INT) {
1437                 printf("uiTemplateList: expected integer property.\n");
1438                 return lb;
1439         }
1440
1441         /* get icon */
1442         if(ptr->data && prop) {
1443                 ptype= RNA_property_pointer_type(ptr, prop);
1444                 icon= RNA_struct_ui_icon(ptype);
1445         }
1446
1447         /* get active data */
1448         activei= RNA_property_int_get(activeptr, activeprop);
1449
1450         if(listtype == 'i') {
1451                 box= uiLayoutListBox(layout);
1452                 col= uiLayoutColumn(box, 1);
1453                 row= uiLayoutRow(col, 0);
1454
1455                 itemlb= uiLayoutBoxGetList(box);
1456
1457                 if(ptr->data && prop) {
1458                         /* create list items */
1459                         RNA_PROP_BEGIN(ptr, itemptr, prop) {
1460                                 /* create button */
1461                                 if(i == 9)
1462                                         row= uiLayoutRow(col, 0);
1463
1464                                 if(RNA_struct_is_a(itemptr.type, &RNA_TextureSlot)) {
1465 #if 0
1466                                         MTex *mtex= itemptr.data;
1467
1468                                         if(mtex && mtex->tex)
1469                                                 icon= ui_id_icon_get(scene, &mtex->tex->id);
1470 #endif
1471                                 }
1472
1473                                 uiDefIconButR(block, LISTROW, 0, icon, 0,0,UI_UNIT_X*10,UI_UNIT_Y, activeptr, activepropname, 0, 0, i, 0, 0, "");
1474
1475                                 //list_item_add(&lb, itemlb, uiLayoutRow(row, 1), &itemptr);
1476
1477                                 i++;
1478                         }
1479                         RNA_PROP_END;
1480                 }
1481         }
1482         else if(listtype == 'c') {
1483                 /* compact layout */
1484                 found= 0;
1485
1486                 row= uiLayoutRow(layout, 1);
1487
1488                 if(ptr->data && prop) {
1489                         /* create list items */
1490                         RNA_PROP_BEGIN(ptr, itemptr, prop) {
1491                                 found= (activei == i);
1492
1493                                 if(found) {
1494                                         /* create button */
1495                                         name= RNA_struct_name_get_alloc(&itemptr, NULL, 0);
1496                                         uiItemL(row, (name)? name: "", icon);
1497
1498                                         if(name)
1499                                                 MEM_freeN(name);
1500
1501                                         /* add to list to return */
1502                                         //list_item_add(&lb, itemlb, uiLayoutRow(row, 1), &itemptr);
1503                                 }
1504
1505                                 i++;
1506                         }
1507                         RNA_PROP_END;
1508                 }
1509
1510                 /* if not found, add in dummy button */
1511                 if(i == 0)
1512                         uiItemL(row, "", 0);
1513
1514                 /* next/prev button */
1515                 sprintf(str, "%d :", i);
1516                 but= uiDefIconTextButR(block, NUM, 0, 0, str, 0,0,UI_UNIT_X*5,UI_UNIT_Y, activeptr, activepropname, 0, 0, 0, 0, 0, "");
1517                 if(i == 0)
1518                         uiButSetFlag(but, UI_BUT_DISABLED);
1519         }
1520         else {
1521                 /* default rows */
1522                 if(rows == 0)
1523                         rows= 5;
1524
1525                 /* layout */
1526                 box= uiLayoutListBox(layout);
1527                 row= uiLayoutRow(box, 0);
1528                 col = uiLayoutColumn(row, 1);
1529
1530                 /* init numbers */
1531                 RNA_property_int_range(activeptr, activeprop, &min, &max);
1532
1533                 if(prop)
1534                         len= RNA_property_collection_length(ptr, prop);
1535                 items= CLAMPIS(len, rows, 5);
1536
1537                 pa->list_scroll= MIN2(pa->list_scroll, len-items);
1538                 pa->list_scroll= MAX2(pa->list_scroll, 0);
1539
1540                 itemlb= uiLayoutBoxGetList(box);
1541
1542                 if(ptr->data && prop) {
1543                         /* create list items */
1544                         RNA_PROP_BEGIN(ptr, itemptr, prop) {
1545                                 if(i >= pa->list_scroll && i<pa->list_scroll+items) {
1546                                         name= RNA_struct_name_get_alloc(&itemptr, NULL, 0);
1547
1548                                         subrow= uiLayoutRow(col, 0);
1549
1550                                         /* create button */
1551                                         if(!icon || icon == ICON_DOT)
1552                                                 but= uiDefButR(block, LISTROW, 0, (name)? name: "", 0,0,UI_UNIT_X*10,UI_UNIT_Y, activeptr, activepropname, 0, 0, i, 0, 0, "");
1553                                         else
1554                                                 but= uiDefIconTextButR(block, LISTROW, 0, icon, (name)? name: "", 0,0,UI_UNIT_X*10,UI_UNIT_Y, activeptr, activepropname, 0, 0, i, 0, 0, "");
1555                                         uiButSetFlag(but, UI_ICON_LEFT|UI_TEXT_LEFT);
1556
1557                                         /* XXX hardcoded */
1558                                         if(itemptr.type == &RNA_MeshTextureFaceLayer || itemptr.type == &RNA_MeshColorLayer) {
1559                                                 uiBlockSetEmboss(block, UI_EMBOSSN);
1560                                                 uiDefIconButR(block, TOG, 0, ICON_SCENE, 0, 0, UI_UNIT_X, UI_UNIT_Y, &itemptr, "active_render", 0, 0, 0, 0, 0, NULL);
1561                                                 uiBlockSetEmboss(block, UI_EMBOSS);
1562                                         }
1563
1564                                         if(name)
1565                                                 MEM_freeN(name);
1566
1567                                         /* add to list to return */
1568                                         //list_item_add(&lb, itemlb, subrow, &itemptr);
1569                                 }
1570
1571                                 i++;
1572                         }
1573                         RNA_PROP_END;
1574                 }
1575
1576                 /* add dummy buttons to fill space */
1577                 while(i < pa->list_scroll+items) {
1578                         if(i >= pa->list_scroll)
1579                                 uiItemL(col, "", 0);
1580                         i++;
1581                 }
1582
1583                 /* add scrollbar */
1584                 if(len > items) {
1585                         col= uiLayoutColumn(row, 0);
1586                         uiDefButI(block, SCROLL, 0, "", 0,0,UI_UNIT_X*0.75,UI_UNIT_Y*items, &pa->list_scroll, 0, len-items, items, 0, "");
1587                 }
1588         }
1589
1590         /* return items in list */
1591         return lb;
1592 }
1593
1594 /************************* Operator Search Template **************************/
1595
1596 static void operator_call_cb(struct bContext *C, void *arg1, void *arg2)
1597 {
1598         wmOperatorType *ot= arg2;
1599         
1600         if(ot)
1601                 WM_operator_name_call(C, ot->idname, WM_OP_INVOKE_DEFAULT, NULL);
1602 }
1603
1604 static void operator_search_cb(const struct bContext *C, void *arg, char *str, uiSearchItems *items)
1605 {
1606         wmOperatorType *ot = WM_operatortype_first();
1607         
1608         for(; ot; ot= ot->next) {
1609                 
1610                 if(BLI_strcasestr(ot->name, str)) {
1611                         if(ot->poll==NULL || ot->poll((bContext *)C)) {
1612                                 char name[256];
1613                                 int len= strlen(ot->name);
1614                                 
1615                                 /* display name for menu, can hold hotkey */
1616                                 BLI_strncpy(name, ot->name, 256);
1617                                 
1618                                 /* check for hotkey */
1619                                 if(len < 256-6) {
1620                                         if(WM_key_event_operator_string(C, ot->idname, WM_OP_EXEC_DEFAULT, NULL, &name[len+1], 256-len-1))
1621                                                 name[len]= '|';
1622                                 }
1623                                 
1624                                 if(0==uiSearchItemAdd(items, name, ot, 0))
1625                                         break;
1626                         }
1627                 }
1628         }
1629 }
1630
1631 void uiTemplateOperatorSearch(uiLayout *layout)
1632 {
1633         uiBlock *block;
1634         uiBut *but;
1635         static char search[256]= "";
1636                 
1637         block= uiLayoutGetBlock(layout);
1638         uiBlockSetCurLayout(block, layout);
1639
1640         but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, sizeof(search), 0, 0, UI_UNIT_X*6, UI_UNIT_Y, "");
1641         uiButSetSearchFunc(but, operator_search_cb, NULL, operator_call_cb, NULL);
1642 }
1643
1644 /************************* Running Jobs Template **************************/
1645
1646 #define B_STOPRENDER    1
1647 #define B_STOPCAST              2
1648 #define B_STOPANIM              3
1649
1650 static void do_running_jobs(bContext *C, void *arg, int event)
1651 {
1652         switch(event) {
1653                 case B_STOPRENDER:
1654                         G.afbreek= 1;
1655                         break;
1656                 case B_STOPCAST:
1657                         WM_jobs_stop(CTX_wm_manager(C), CTX_wm_screen(C));
1658                         break;
1659                 case B_STOPANIM:
1660                         WM_operator_name_call(C, "SCREEN_OT_animation_play", WM_OP_INVOKE_SCREEN, NULL);
1661                         break;
1662         }
1663 }
1664
1665 void uiTemplateRunningJobs(uiLayout *layout, bContext *C)
1666 {
1667         bScreen *screen= CTX_wm_screen(C);
1668         Scene *scene= CTX_data_scene(C);
1669         wmWindowManager *wm= CTX_wm_manager(C);
1670         uiBlock *block;
1671
1672         block= uiLayoutGetBlock(layout);
1673         uiBlockSetCurLayout(block, layout);
1674
1675         uiBlockSetHandleFunc(block, do_running_jobs, NULL);
1676
1677         if(WM_jobs_test(wm, scene))
1678                 uiDefIconTextBut(block, BUT, B_STOPRENDER, ICON_REC, "Render", 0,0,75,UI_UNIT_Y, NULL, 0.0f, 0.0f, 0, 0, "Stop rendering");
1679         if(WM_jobs_test(wm, screen))
1680                 uiDefIconTextBut(block, BUT, B_STOPCAST, ICON_REC, "Capture", 0,0,85,UI_UNIT_Y, NULL, 0.0f, 0.0f, 0, 0, "Stop screencast");
1681         if(screen->animtimer)
1682                 uiDefIconTextBut(block, BUT, B_STOPANIM, ICON_REC, "Anim Player", 0,0,85,UI_UNIT_Y, NULL, 0.0f, 0.0f, 0, 0, "Stop animation playback");
1683 }
1684
1685 /************************* Image Template **************************/
1686
1687 #include "ED_image.h"
1688
1689 void uiTemplateTextureImage(uiLayout *layout, bContext *C, Tex *tex)
1690 {
1691         uiBlock *block;
1692
1693         if(tex) {
1694                 block= uiLayoutFreeBlock(layout);
1695                 ED_image_uiblock_panel(C, block, &tex->ima, &tex->iuser, 0, 0);
1696         }
1697 }
1698