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