=== Custom Transform Orientation ===
[blender.git] / source / blender / src / headerbuttons.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL/BL DUAL 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. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA        02111-1307, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  */
32
33 #include <stdlib.h>
34 #include <string.h>
35 #include <math.h>
36
37 #include <sys/types.h>
38
39 #ifdef HAVE_CONFIG_H
40 #include <config.h>
41 #endif
42
43 #include "MEM_guardedalloc.h"
44
45 #include "BMF_Api.h"
46 #include "BIF_language.h"
47 #ifdef INTERNATIONAL
48 #include "FTF_Api.h"
49 #endif
50
51 #include "BLI_blenlib.h"
52 #include "BLI_arithb.h"
53 #include "BLI_storage_types.h"
54
55 #include "IMB_imbuf_types.h"
56 #include "IMB_imbuf.h"
57
58 #include "DNA_ID.h"
59 #include "DNA_action_types.h"
60 #include "DNA_armature_types.h"
61 #include "DNA_brush_types.h"
62 #include "DNA_camera_types.h"
63 #include "DNA_curve_types.h"
64 #include "DNA_group_types.h"
65 #include "DNA_image_types.h"
66 #include "DNA_ipo_types.h"
67 #include "DNA_key_types.h"
68 #include "DNA_lamp_types.h"
69 #include "DNA_lattice_types.h"
70 #include "DNA_material_types.h"
71 #include "DNA_mesh_types.h"
72 #include "DNA_meta_types.h"
73 #include "DNA_object_types.h"
74 #include "DNA_oops_types.h"
75 #include "DNA_packedFile_types.h"
76 #include "DNA_scene_types.h"
77 #include "DNA_screen_types.h"
78 #include "DNA_sequence_types.h"
79 #include "DNA_sound_types.h"
80 #include "DNA_space_types.h"
81 #include "DNA_texture_types.h"
82 #include "DNA_text_types.h"
83 #include "DNA_userdef_types.h"
84 #include "DNA_view2d_types.h"
85 #include "DNA_view3d_types.h"
86 #include "DNA_world_types.h"
87 #include "DNA_constraint_types.h"
88
89 #include "BKE_utildefines.h"
90
91 #include "BKE_action.h"
92 #include "BKE_armature.h"
93 #include "BKE_blender.h"
94 #include "BKE_brush.h"
95 #include "BKE_constraint.h"
96 #include "BKE_curve.h"
97 #include "BKE_depsgraph.h"
98 #include "BKE_exotic.h"
99 #include "BKE_global.h"
100 #include "BKE_image.h"
101 #include "BKE_ipo.h"
102 #include "BKE_key.h"
103 #include "BKE_lattice.h"
104 #include "BKE_library.h"
105 #include "BKE_main.h"
106 #include "BKE_material.h"
107 #include "BKE_mball.h"
108 #include "BKE_mesh.h"
109 #include "BKE_node.h"
110 #include "BKE_object.h"
111 #include "BKE_packedFile.h"
112 #include "BKE_sca.h"
113 #include "BKE_scene.h"
114 #include "BKE_texture.h"
115 #include "BKE_text.h"
116 #include "BKE_world.h"
117
118 #include "BLO_readfile.h"
119 #include "BLO_writefile.h"
120
121 #include "BIF_drawimage.h"
122 #include "BIF_drawoops.h"
123 #include "BIF_drawscene.h"
124 #include "BIF_drawtext.h"
125 #include "BIF_editaction.h"
126 #include "BIF_editarmature.h"
127 #include "BIF_editfont.h"
128 #include "BIF_editlattice.h"
129 #include "BIF_editconstraint.h"
130 #include "BIF_editmesh.h"
131 #include "BIF_editmesh.h"
132 #include "BIF_editsima.h"
133 #include "BIF_editsound.h"
134 #include "BIF_gl.h"
135 #include "BIF_imasel.h"
136 #include "BIF_interface.h"
137 #include "BIF_mainqueue.h"
138 #include "BIF_mywindow.h"
139 #include "BIF_poseobject.h"
140 #include "BIF_renderwin.h"
141 #include "BIF_resources.h"
142 #include "BIF_screen.h"
143 #include "BIF_space.h"
144 #include "BIF_toets.h"
145 #include "BIF_toolbox.h"
146 #include "BIF_usiblender.h"
147 #include "BIF_previewrender.h"
148 #include "BIF_writeimage.h"
149 #include "BIF_butspace.h"
150
151 #include "BPI_script.h"
152
153 #include "BSE_edit.h"
154 #include "BSE_filesel.h"
155 #include "BSE_headerbuttons.h"
156 #include "BSE_node.h"
157 #include "BSE_view.h"
158 #include "BSE_sequence.h"
159 #include "BSE_editipo.h"
160 #include "BSE_drawipo.h"
161
162 #include "BDR_drawmesh.h"
163 #include "BDR_vpaint.h"
164 #include "BDR_editface.h"
165 #include "BDR_editobject.h"
166 #include "BDR_editcurve.h"
167 #include "BDR_editmball.h"
168 #include "BDR_sculptmode.h"
169
170 #include "BPY_extern.h"
171 #include "BPY_menus.h"
172
173 #include "mydevice.h"
174 #include "blendef.h"
175 #include "interface.h"
176 #include "nla.h"        /* __NLA : To be removed later */
177 #include "butspace.h"  // test_idbutton
178
179 #include "BIF_poseobject.h"
180
181 #include "SYS_System.h"
182
183  /* WATCH IT:  always give all headerbuttons for same window the same name
184         *                       event B_REDR is a standard redraw
185         *
186         */
187
188 char *windowtype_pup(void)
189 {
190         return(
191         "Window type:%t" //14
192         "|3D View %x1" //30
193
194         "|%l" // 33
195
196         "|Ipo Curve Editor %x2" //54
197         "|Action Editor %x12" //73
198         "|NLA Editor %x13" //94
199
200         "|%l" //97
201
202         "|UV/Image Editor %x6" //117
203
204         "|Video Sequence Editor %x8" //143
205         "|Timeline %x15" //163
206         "|Audio Window %x11" //163
207         "|Text Editor %x9" //179
208
209         "|%l" //192
210
211
212         "|User Preferences %x7" //213
213         "|Outliner %x3" //232
214         "|Buttons Window %x4" //251
215         "|Node Editor %x16"
216         "|%l" //254
217
218         "|Image Browser %x10" //273
219         "|File Browser %x5" //290
220
221         "|%l" //293
222
223         "|Scripts Window %x14"//313
224         );
225 }
226
227 int GetButStringLength(char *str) {
228         int rt;
229
230         rt= BIF_GetStringWidth(G.font, str, (U.transopts & USER_TR_BUTTONS));
231
232         return rt + 15;
233 }
234
235 /* ********************** GLOBAL ****************************** */
236
237 int std_libbuttons(uiBlock *block, short xco, short yco,
238                                                         int pin, short *pinpoin, int browse, short id_code, short special, ID *id,
239                                                         ID *parid, short *menupoin, int users, int lib,
240                                                         int del, int autobut, int keepbut)
241 {
242         ListBase *lb;
243         uiBut *but;
244         int len, oldcol, add_addbutton=0;
245         char *str=NULL, str1[10];
246
247         uiBlockBeginAlign(block);
248         oldcol= uiBlockGetCol(block);
249
250         if(id && pin) {
251                 uiDefIconButS(block, ICONTOG, pin, ICON_PIN_DEHLT, xco,yco,XIC,YIC, pinpoin, 0, 0, 0, 0, "Keeps this view displaying the current data regardless of what object is selected");
252                 xco+= XIC;
253         }
254         /* browse menu */
255         if(browse) {
256                 char *extrastr= NULL;
257                 
258                 if(ELEM4(id_code, ID_MA, ID_TE, ID_BR, ID_PA)) add_addbutton= 1;
259                         
260                 lb= wich_libbase(G.main, id_code);
261                 
262                 if(id && id->us>1) uiBlockSetCol(block, TH_BUT_SETTING1);
263
264                 if (pin && *pinpoin) {
265                         uiBlockSetCol(block, TH_BUT_SETTING2);
266                 }
267                 
268                 if (ELEM8( id_code, ID_SCE, ID_SCR, ID_MA, ID_TE, ID_WO, ID_IP, ID_AC, ID_BR) || id_code == ID_PA) extrastr= "ADD NEW %x 32767";
269                 else if (id_code==ID_TXT) extrastr= "OPEN NEW %x 32766 |ADD NEW %x 32767";
270                 else if (id_code==ID_SO) extrastr= "OPEN NEW %x 32766";
271
272                 uiSetButLock(G.scene->id.lib!=0, ERROR_LIBDATA_MESSAGE);
273                 if( id_code==ID_SCE || id_code==ID_SCR ) uiClearButLock();
274                 
275                 if(curarea->spacetype==SPACE_BUTS)
276                         uiSetButLock(id_code!=ID_SCR && G.obedit!=0 && G.buts->mainb==CONTEXT_EDITING, "Cannot perform in EditMode");
277                 
278                 if(parid) uiSetButLock(parid->lib!=0, ERROR_LIBDATA_MESSAGE);
279
280                 if (lb) {
281                         if( id_code==ID_IP)
282                                 IPOnames_to_pupstring(&str, NULL, extrastr, lb, id, menupoin, G.sipo->blocktype);
283                         else if(browse!=B_SIMABROWSE && id_code==ID_IM )
284                                 IMAnames_to_pupstring(&str, NULL, extrastr, lb, id, menupoin);
285                         else
286                                 IDnames_to_pupstring(&str, NULL, extrastr, lb, id, menupoin);
287                 }
288                 
289                 uiDefButS(block, MENU, browse, str, xco,yco,XIC,YIC, menupoin, 0, 0, 0, 0, "Browses existing choices or adds NEW");
290                 xco+= XIC;
291                 
292                 uiClearButLock();
293         
294                 MEM_freeN(str);
295         }
296
297         uiBlockSetCol(block, oldcol);
298
299         if(id) {        /* text button with name */
300         
301                 /* name */
302                 if(id->us>1) uiBlockSetCol(block, TH_BUT_SETTING1);
303                 /* Pinned data ? */
304                 if (pin && *pinpoin) {
305                         uiBlockSetCol(block, TH_BUT_SETTING2);
306                 }
307                 /* Redalert overrides pin color */
308                 if(id->us<=0) uiBlockSetCol(block, TH_REDALERT);
309
310                 uiSetButLock(id->lib!=0, ERROR_LIBDATA_MESSAGE);
311                 
312                 if(GS(id->name)==ID_SCE) strcpy(str1, "SCE:");
313                 else if(GS(id->name)==ID_SCE) strcpy(str1, "SCR:");
314                 else if(GS(id->name)==ID_MA) {
315                         if( ((Material *)id)->use_nodes )
316                                 strcpy(str1, "NT:");
317                         else
318                                 strcpy(str1, "MA:");
319                 }
320                 else {
321                         str1[0]= id->name[0];
322                         str1[1]= id->name[1];
323                         str1[2]= ':';
324                         str1[3]= 0;
325                 }
326                 
327                 if( GS(id->name)==ID_IP) len= 110;
328                 else if((yco) && (GS(id->name)==ID_AC)) len= 100; // comes from button panel (poselib)
329                 else if(yco) len= 140;  // comes from button panel
330                 else len= 120;
331                 
332                 but= uiDefBut(block, TEX, B_IDNAME, str1,xco, yco, (short)len, YIC, id->name+2, 0.0, 21.0, 0, 0, "Displays current Datablock name. Click to change.");
333                 uiButSetFunc(but, test_idbutton_cb, id->name, NULL);
334
335                 uiClearButLock();
336
337                 xco+= len;
338                 
339                 if(id->lib) {
340                         
341                         if(id->flag & LIB_INDIRECT) uiDefIconBut(block, BUT, 0, ICON_DATALIB,xco,yco,XIC,YIC, 0, 0, 0, 0, 0, "Indirect Library Datablock. Cannot change.");
342                         else uiDefIconBut(block, BUT, lib, ICON_PARLIB, xco,yco,XIC,YIC, 0, 0, 0, 0, 0, 
343                                                           lib?"Direct linked Library Datablock. Click to make local.":"Direct linked Library Datablock, cannot make local."
344                                                           );
345                         
346                         xco+= XIC;
347                 }
348                 
349                 
350                 if(users && id->us>1) {
351                         uiSetButLock (pin && *pinpoin, "Can't make pinned data single-user");
352                         
353                         sprintf(str1, "%d", id->us);
354                         if(id->us<10) {
355                                 
356                                 uiDefBut(block, BUT, users, str1, xco,yco,XIC,YIC, 0, 0, 0, 0, 0, "Displays number of users of this data. Click to make a single-user copy.");
357                                 xco+= XIC;
358                         }
359                         else {
360                                 uiDefBut(block, BUT, users, str1, xco, yco, XIC+10, YIC, 0, 0, 0, 0, 0, "Displays number of users of this data. Click to make a single-user copy.");
361                                 xco+= XIC+10;
362                         }
363                         
364                         uiClearButLock();
365                         
366                 }
367                 
368                 if(del) {
369
370                         uiSetButLock (pin && *pinpoin, "Can't unlink pinned data");
371                         if(parid && parid->lib);
372                         else {
373                                 uiDefIconBut(block, BUT, del, ICON_X, xco,yco,XIC,YIC, 0, 0, 0, 0, 0, "Deletes link to this Datablock");
374                                 xco+= XIC;
375                         }
376
377                         uiClearButLock();
378                 }
379
380                 if(autobut) {
381                         if(parid && parid->lib);
382                         else {
383                                 uiDefIconBut(block, BUT, autobut, ICON_AUTO,xco,yco,XIC,YIC, 0, 0, 0, 0, 0, "Generates an automatic name");
384                                 xco+= XIC;
385                         }
386                         
387                         
388                 }
389                 if(keepbut) {
390                         uiDefBut(block, BUT, keepbut, "F", xco,yco,XIC,YIC, 0, 0, 0, 0, 0, "Saves this datablock even if it has no users");  
391                         xco+= XIC;
392                 }
393         }
394         else if(add_addbutton) {        /* "add new" button */
395                 uiBlockSetCol(block, oldcol);
396                 uiDefButS(block, TOG, browse, "Add New" ,xco, yco, 110, YIC, menupoin, (float)*menupoin, 32767.0, 0, 0, "Add new data block");
397                 xco+= 110;
398         }
399         //xco+=XIC;
400         
401         uiBlockSetCol(block, oldcol);
402         uiBlockEndAlign(block);
403
404         return xco;
405 }
406
407
408 /* results in fully updated anim system */
409 static void do_update_for_newframe(int mute, int events)
410 {
411         extern void audiostream_scrub(unsigned int frame);      /* seqaudio.c */
412         
413         if(events) {
414                 allqueue(REDRAWALL, 0);
415         }
416         
417         /* this function applies the changes too */
418         scene_update_for_newframe(G.scene, screen_view3d_layers()); /* BKE_scene.h */
419
420         if ( (CFRA>1) && (!mute) && (G.scene->audio.flag & AUDIO_SCRUB)) 
421                 audiostream_scrub( CFRA );
422         
423         /* 3d window, preview */
424         BIF_view3d_previewrender_signal(curarea, PR_DBASE|PR_DISPRECT);
425
426         /* all movie/sequence images */
427         BIF_image_update_frame();
428         
429         /* composite */
430         if(G.scene->use_nodes && G.scene->nodetree)
431                 ntreeCompositTagAnimated(G.scene->nodetree);
432 }
433
434 void update_for_newframe(void)
435 {
436         do_update_for_newframe(0, 1);
437 }
438
439 void update_for_newframe_muted(void)
440 {
441         do_update_for_newframe(1, 1);
442 }
443
444 /* used by new animated UI playback */
445 void update_for_newframe_nodraw(int nosound)
446 {
447         do_update_for_newframe(nosound, 0);
448 }
449
450
451 static void show_splash(void)
452 {
453         extern char datatoc_splash_jpg[];
454         extern int datatoc_splash_jpg_size;
455         char *string = NULL;
456
457 #ifdef NAN_BUILDINFO
458         char buffer[1024];
459         extern char * build_date;
460         extern char * build_time;
461         extern char * build_rev;
462         extern char * build_platform;
463         extern char * build_type;
464
465         string = &buffer[0];
466         sprintf(string,"Built on %s %s, Rev-%s    Version %s %s", build_date, build_time, build_rev, build_platform, build_type);
467 #endif
468
469         splash((void *)datatoc_splash_jpg, datatoc_splash_jpg_size, string);
470 }
471
472
473 /* Functions for user preferences fileselect windows */
474
475 /* yafray: export dir select */
476 static void filesel_u_yfexportdir(char *name)
477 {
478         char dir[FILE_MAXDIR], file[FILE_MAXFILE];
479
480         BLI_cleanup_dir(G.sce, name);
481         BLI_split_dirfile(name, dir, file);
482
483         strcpy(U.yfexportdir, dir);
484         allqueue(REDRAWALL, 0);
485 }
486
487 static void filesel_u_fontdir(char *name)
488 {
489         char dir[FILE_MAXDIR], file[FILE_MAXFILE];
490         
491         BLI_cleanup_dir(G.sce, name);
492         BLI_split_dirfile(name, dir, file);
493
494         strcpy(U.fontdir, dir);
495         allqueue(REDRAWALL, 0);
496 }
497
498 static void filesel_u_textudir(char *name)
499 {
500         char dir[FILE_MAXDIR], file[FILE_MAXFILE];
501
502         BLI_cleanup_dir(G.sce, name);
503         BLI_split_dirfile(name, dir, file);
504
505         strcpy(U.textudir, dir);
506         allqueue(REDRAWALL, 0);
507 }
508
509 static void filesel_u_plugtexdir(char *name)
510 {
511         char dir[FILE_MAXDIR], file[FILE_MAXFILE];
512
513         BLI_cleanup_dir(G.sce, name);
514         BLI_split_dirfile(name, dir, file);
515
516         strcpy(U.plugtexdir, dir);
517         allqueue(REDRAWALL, 0);
518 }
519
520 static void filesel_u_plugseqdir(char *name)
521 {
522         char dir[FILE_MAXDIR], file[FILE_MAXFILE];
523
524         BLI_cleanup_dir(G.sce, name);
525         BLI_split_dirfile(name, dir, file);
526
527         strcpy(U.plugseqdir, dir);
528         allqueue(REDRAWALL, 0);
529 }
530
531 static void filesel_u_renderdir(char *name)
532 {
533         char dir[FILE_MAXDIR], file[FILE_MAXFILE];
534
535         BLI_cleanup_dir(G.sce, name);
536         BLI_split_dirfile(name, dir, file);
537
538         strcpy(U.renderdir, dir);
539         allqueue(REDRAWALL, 0);
540 }
541
542 static void filesel_u_pythondir(char *name)
543 {
544         char dir[FILE_MAXDIR], file[FILE_MAXFILE];
545
546         BLI_cleanup_dir(G.sce, name);
547         BLI_split_dirfile(name, dir, file);
548
549         strcpy(U.pythondir, dir);
550         allqueue(REDRAWALL, 0);
551 }
552
553 static void filesel_u_sounddir(char *name)
554 {
555         char dir[FILE_MAXDIR], file[FILE_MAXFILE];
556
557         BLI_cleanup_dir(G.sce, name);
558         BLI_split_dirfile(name, dir, file);
559
560         strcpy(U.sounddir, dir);
561         allqueue(REDRAWALL, 0);
562 }
563
564 static void filesel_u_tempdir(char *name)
565 {
566         char dir[FILE_MAXDIR], file[FILE_MAXFILE];
567
568         BLI_cleanup_dir(G.sce, name);
569         BLI_split_dirfile(name, dir, file);
570
571         strcpy(U.tempdir, dir);
572         allqueue(REDRAWALL, 0);
573 }
574
575 /* END Functions for user preferences fileselect windows */
576
577
578 void do_global_buttons(unsigned short event)
579 {
580         ListBase *lb;
581         Object *ob;
582         Material *ma;
583         MTex *mtex;
584         Ipo *ipo;
585         Lamp *la;
586         World *wrld;
587         bAction *act;
588         ID *id, *idtest, *from=NULL;
589         ScrArea *sa;
590         Brush *br;
591         int nr= 1;
592         
593 #ifdef INTERNATIONAL
594         char buf[FILE_MAX];
595 #endif
596
597         ob= OBACT;
598
599         id= NULL;       /* id at null for texbrowse */
600
601
602         switch(event) {
603         
604         case B_NEWFRAME:
605                 scrarea_queue_winredraw(curarea);
606                 scrarea_queue_headredraw(curarea);
607
608                 update_for_newframe();
609                 break;          
610         case B_REDR:
611                 scrarea_queue_winredraw(curarea);
612                 scrarea_queue_headredraw(curarea);
613                 break;
614         case B_REDRCURW3D:
615                 allqueue(REDRAWVIEW3D, 0);
616                 scrarea_queue_winredraw(curarea);
617                 scrarea_queue_headredraw(curarea);
618                 break;
619         case B_EDITBROWSE:
620                 if(ob==NULL) return;
621                 if(ob->id.lib) return;
622                 id= ob->data;
623                 if(id==NULL) return;
624
625                 if(G.buts->menunr== -2) {
626                         activate_databrowse((ID *)G.buts->lockpoin, GS(id->name), 0, B_EDITBROWSE, &G.buts->menunr, do_global_buttons);
627                         return;
628                 }
629                 if(G.buts->menunr < 0) return;
630                 
631                 lb= wich_libbase(G.main, GS(id->name));
632                 idtest= lb->first;
633                 while(idtest) {
634                         if(nr==G.buts->menunr) {
635                                 if(idtest!=id) {
636                                         id->us--;
637                                         id_us_plus(idtest);
638                                         
639                                         ob->data= idtest;
640                                         
641                                         test_object_materials(idtest);
642                                         
643                                         if( GS(idtest->name)==ID_CU ) {
644                                                 test_curve_type(ob);
645                                         }
646                                         else if( ob->type==OB_ARMATURE) {
647                                                 armature_rebuild_pose(ob, ob->data);
648                                         }
649                                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
650                                         
651                                         allqueue(REDRAWBUTSEDIT, 0);
652                                         allqueue(REDRAWVIEW3D, 0);
653                                         allqueue(REDRAWACTION,0);
654                                         allqueue(REDRAWIPO, 0);
655                                         allqueue(REDRAWNLA,0);
656                                 }
657                                 break;
658                         }
659                         nr++;
660                         idtest= idtest->next;
661                 }
662
663                 break;
664         case B_MESHBROWSE:
665                 if(ob==0) return;
666                 if(ob->id.lib) return;
667                 
668                 id= ob->data;
669                 if(id==0) id= G.main->mesh.first;
670                 if(id==0) return;
671                 
672                 if(G.buts->menunr== -2) {
673                         activate_databrowse((ID *)G.buts->lockpoin, GS(id->name), 0, B_MESHBROWSE, &G.buts->menunr, do_global_buttons);
674                         return;
675                 }
676                 if(G.buts->menunr < 0) return;
677                 
678
679                 idtest= G.main->mesh.first;
680                 while(idtest) {
681                         if(nr==G.buts->menunr) {
682                                 set_mesh(ob, (Mesh *)idtest);
683                                 
684                                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
685                                         
686                                 BIF_undo_push("Browse Mesh");
687                                 allqueue(REDRAWBUTSEDIT, 0);
688                                 allqueue(REDRAWVIEW3D, 0);
689                                 allqueue(REDRAWACTION,0);
690                                 allqueue(REDRAWIPO, 0);
691
692                                 break;
693                         }
694                         nr++;
695                         idtest= idtest->next;
696                 }
697
698                 break;
699         case B_MATBROWSE:
700         {
701                 void *lockpoin= NULL;
702                 short *menunr= 0;
703                 
704                 /* this is called now from Node editor too, buttons might not exist */
705                 if(curarea->spacetype==SPACE_NODE) {
706                         SpaceNode *snode= curarea->spacedata.first;
707                         menunr= &snode->menunr;
708                         lockpoin= snode->id;
709                 }
710                 else if(G.buts) {
711                         menunr= &G.buts->menunr;
712                         lockpoin= G.buts->lockpoin;
713                 }
714                 else return;
715                 
716                 if(*menunr== -2) {
717                         if(G.qual & LR_CTRLKEY) {
718                                 activate_databrowse_imasel((ID *)lockpoin, ID_MA, 0, B_MATBROWSE, menunr, do_global_buttons);
719                         }
720                         else {
721                                 activate_databrowse((ID *)lockpoin, ID_MA, 0, B_MATBROWSE, menunr, do_global_buttons);
722                         }
723                         return;
724                 }
725                 
726                 if(*menunr < 0) return;
727                 
728                 if(0) { /* future pin */
729                         
730                 }
731                 else {
732                         
733                         ma= give_current_material(ob, ob->actcol);
734                         nr= 1;
735                         
736                         id= (ID *)ma;
737                         
738                         idtest= G.main->mat.first;
739                         while(idtest) {
740                                 if(nr== *menunr) {
741                                         break;
742                                 }
743                                 nr++;
744                                 idtest= idtest->next;
745                         }
746                         if(idtest==0) { /* new mat */
747                                 if(id)  idtest= (ID *)copy_material((Material *)id);
748                                 else {
749                                         idtest= (ID *)add_material("Material");
750                                 }
751                                 idtest->us--;
752                         }
753                         if(idtest!=id) {
754                                 assign_material(ob, (Material *)idtest, ob->actcol);
755                                 
756                                 BIF_undo_push("Browse Material");
757                                 allqueue(REDRAWBUTSSHADING, 0);
758                                 allqueue(REDRAWIPO, 0);
759                                 allqueue(REDRAWNODE, 0);
760                                 BIF_preview_changed(ID_MA);
761                         }
762                         
763                 }
764         }
765                 break;
766         case B_MATDELETE:
767                 if(0) { /* future pin */
768                         
769                 }
770                 else {
771                         ma= give_current_material(ob, ob->actcol);
772                         if(ma) {
773                                 assign_material(ob, 0, ob->actcol);
774                                 BIF_undo_push("Unlink Material");
775                                 allqueue(REDRAWBUTSSHADING, 0);
776                                 allqueue(REDRAWIPO, 0);
777                                 allqueue(REDRAWOOPS, 0);
778                                 allqueue(REDRAWVIEW3D, 0);
779                                 BIF_preview_changed(ID_MA);
780                         }
781                 }
782                 break;
783         case B_TEXDELETE:
784                 if(G.buts->pin) {
785                         
786                 }
787                 else {
788                         if(G.buts->texfrom==0) {        /* from mat */
789                                 ma= give_current_material(ob, ob->actcol);
790                                 ma= editnode_get_active_material(ma);
791                                 if(ma) {
792                                         mtex= ma->mtex[ ma->texact ];
793                                         if(mtex) {
794                                                 if(mtex->tex) mtex->tex->id.us--;
795                                                 MEM_freeN(mtex);
796                                                 ma->mtex[ ma->texact ]= NULL;
797                                                 allqueue(REDRAWBUTSSHADING, 0);
798                                                 allqueue(REDRAWIPO, 0);
799                                                 BIF_preview_changed(ID_MA);
800                                         }
801                                 }
802                         }
803                         else if(G.buts->texfrom==1) { /* from world */
804                                 wrld= G.scene->world;
805                                 if(wrld) {
806                                         mtex= wrld->mtex[ wrld->texact ];
807                                         if(mtex) {
808                                                 if(mtex->tex) mtex->tex->id.us--;
809                                                 MEM_freeN(mtex);
810                                                 wrld->mtex[ wrld->texact ]= NULL;
811                                                 allqueue(REDRAWBUTSSHADING, 0);
812                                                 allqueue(REDRAWIPO, 0);
813                                                 BIF_preview_changed(ID_WO);
814                                         }
815                                 }
816                         }
817                         else if(G.buts->texfrom==2) {   /* from lamp */
818                                 la= ob->data;
819                                 if(la && ob->type==OB_LAMP) { /* to be sure */
820                                         mtex= la->mtex[ la->texact ];
821                                         if(mtex) {
822                                                 if(mtex->tex) mtex->tex->id.us--;
823                                                 MEM_freeN(mtex);
824                                                 la->mtex[ la->texact ]= NULL;
825                                                 allqueue(REDRAWBUTSSHADING, 0);
826                                                 allqueue(REDRAWIPO, 0);
827                                                 BIF_preview_changed(ID_LA);
828                                         }
829                                 }
830                         }
831                         else {  /* from brush */
832                                 br= G.scene->toolsettings->imapaint.brush;
833                                 if(G.f & G_SCULPTMODE) {
834                                         sculptmode_rem_tex(NULL, NULL);
835                                         allqueue(REDRAWBUTSSHADING, 0);
836                                 } else if(br) {
837                                         mtex= br->mtex[ br->texact ];
838                                         if(mtex) {
839                                                 if(mtex->tex) mtex->tex->id.us--;
840                                                 MEM_freeN(mtex);
841                                                 br->mtex[ br->texact ]= NULL;
842                                                 allqueue(REDRAWBUTSSHADING, 0);
843                                                 allqueue(REDRAWIMAGE, 0);
844                                                 allqueue(REDRAWIPO, 0);
845                                                 /*BIF_preview_changed(ID_BR);*/
846                                         }
847                                 }
848                         }
849                         BIF_undo_push("Unlink Texture");
850                 }
851                 break;
852         case B_EXTEXBROWSE: 
853         case B_TEXBROWSE:
854
855                 if(G.buts->texnr== -2) {
856                         
857                         id= G.buts->lockpoin;
858                         if(event==B_EXTEXBROWSE) {
859                                 id= NULL;
860                                 ma= give_current_material(ob, ob->actcol);
861                                 ma= editnode_get_active_material(ma);
862                                 if(ma) {
863                                         mtex= ma->mtex[ ma->texact ];
864                                         if(mtex) id= (ID *)mtex->tex;
865                                 }
866                         }
867                         if(G.qual & LR_CTRLKEY) {
868                                 activate_databrowse_imasel(id, ID_TE, 0, B_TEXBROWSE, &G.buts->texnr, do_global_buttons);
869                         }
870                         else {
871                                 activate_databrowse(id, ID_TE, 0, B_TEXBROWSE, &G.buts->texnr, do_global_buttons);
872                         }
873                         return;
874                 }
875                 if(G.buts->texnr < 0) break;
876                 
877                 if(G.buts->pin) {
878                         
879                 }
880                 else {
881                         id= NULL;
882                         
883                         ma= give_current_material(ob, ob->actcol);
884                         ma= editnode_get_active_material(ma);
885                         if(ma) {
886                                 mtex= ma->mtex[ ma->texact ];
887                                 if(mtex) id= (ID *)mtex->tex;
888                         }
889
890                         idtest= G.main->tex.first;
891                         while(idtest) {
892                                 if(nr==G.buts->texnr) {
893                                         break;
894                                 }
895                                 nr++;
896                                 idtest= idtest->next;
897                         }
898                         if(idtest==0) { /* new tex */
899                                 if(id)  idtest= (ID *)copy_texture((Tex *)id);
900                                 else idtest= (ID *)add_texture("Tex");
901                                 idtest->us--;
902                         }
903                         if(idtest!=id && ma) {
904                                 
905                                 if( ma->mtex[ma->texact]==0) ma->mtex[ma->texact]= add_mtex();
906                                 
907                                 ma->mtex[ ma->texact ]->tex= (Tex *)idtest;
908                                 id_us_plus(idtest);
909                                 if(id) id->us--;
910                                 
911                                 BIF_undo_push("Browse Texture");
912                                 allqueue(REDRAWBUTSSHADING, 0);
913                                 allqueue(REDRAWIPO, 0);
914                                 allqueue(REDRAWOOPS, 0);
915                                 BIF_preview_changed(ID_MA);
916                         }
917                 }
918                 break;
919         case B_ACTIONDELETE:
920                 act=ob->action;
921                 
922                 if (act)
923                         act->id.us--;
924                 ob->action=NULL;
925                 if(ob->pose) {          // clear flag, also used for draw colors
926                         bPoseChannel *pchan;
927                         for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next)
928                                 pchan->flag= 0;
929                 }
930                 BIF_undo_push("Unlink Action");
931                 
932                 allqueue(REDRAWVIEW3D, 0);
933                 allqueue(REDRAWACTION, 0);
934                 allqueue(REDRAWNLA, 0);
935                 allqueue(REDRAWIPO, 0);
936                 allqueue(REDRAWBUTSEDIT, 0);
937                 break;
938         case B_ACTIONBROWSE:
939                 if (!ob)
940                         break;
941                 act=ob->action;
942                 id= (ID *)act;
943                 
944                 if (G.saction->actnr== -2){
945                                 activate_databrowse((ID *)G.saction->action, ID_AC,  0, B_ACTIONBROWSE, &G.saction->actnr, do_global_buttons);
946                         return;
947                 }
948                 
949                 if(G.saction->actnr < 0) break;
950                 
951                 /*      See if we have selected a valid action */
952                 for (idtest= G.main->action.first; idtest; idtest= idtest->next) {
953                                 if(nr==G.saction->actnr) {
954                                         break;
955                                 }
956                                 nr++;
957                         
958                 }
959
960                 if(G.saction->pin) {
961                         if (idtest == NULL) {
962                                 /* assign new/copy of pinned action only - messy as it doesn't assign to any obj's */
963                                 if (G.saction->action)
964                                         G.saction->action= (bAction *)copy_action(G.saction->action);
965                                 else
966                                         G.saction->action= (bAction *)add_empty_action("PinnedAction");
967                         }
968                         else {
969                                 G.saction->action= (bAction *)idtest;
970                         }
971                         allqueue(REDRAWACTION, 0);
972                 }
973                 else {
974
975                         /* Store current action */
976                         if (!idtest) {
977                                 /* 'Add New' option: 
978                                  *      - make a copy of an exisiting action
979                                  *      - or make a new empty action if no existing action
980                                  */
981                                 if (act) {
982                                         idtest= (ID *)copy_action(act);
983                                 } 
984                                 else { 
985                                         if (ID_OB==ob->type) {
986                                                 /* for empties */
987                                                 idtest=(ID *)add_empty_action("ObAction");
988                                         } 
989                                         else if (ELEM(ob->type, OB_MESH, OB_LATTICE) && ob_get_key(ob)) {
990                                                 /* shapekey - like if B_IPO_ACTION_KEY is triggered */
991                                                 bActionChannel *achan;
992                                                 Key *key= ob_get_key(ob);
993                                                 
994                                                 ob->ipoflag |= OB_ACTION_KEY;
995                                                 
996                                                 act = add_empty_action("ShapeAction");
997                                                 idtest=(ID *)act;
998                                                 
999                                                 achan= verify_action_channel(act, "Shape");
1000                                                 achan->flag = (ACHAN_HILIGHTED|ACHAN_SELECTED|ACHAN_EXPANDED|ACHAN_SHOWIPO);
1001                                                 
1002                                                 if(achan->ipo==NULL && key->ipo) {
1003                                                         achan->ipo= key->ipo;
1004                                                         key->ipo= NULL;
1005                                                         
1006                                                         allqueue(REDRAWVIEW3D, 0);
1007                                                         allqueue(REDRAWIPO, 0);
1008                                                         allqueue(REDRAWOOPS, 0);
1009                                                 }
1010                                         }
1011                                         else {
1012                                                 /* a plain action */
1013                                                 idtest=(ID *)add_empty_action("Action");
1014                                         }
1015                                 }
1016                                 idtest->us--;
1017                         }
1018                         
1019                         
1020                         if(idtest!=id && ob) {
1021                                 act= (bAction *)idtest;
1022                                 
1023                                 ob->action= act;
1024                                 id_us_plus(idtest);
1025                                 
1026                                 if(id) id->us--;
1027                                 
1028                                 // Update everything
1029                                 BIF_undo_push("Browse Action");
1030                                 do_global_buttons (B_NEWFRAME);
1031                                 allqueue(REDRAWVIEW3D, 0);
1032                                 allqueue(REDRAWNLA, 0);
1033                                 allqueue(REDRAWACTION, 0);
1034                                 allqueue(REDRAWHEADERS, 0); 
1035                                 allqueue(REDRAWBUTSEDIT, 0);
1036                         }
1037                 }
1038                 
1039                 break;
1040         case B_IPOBROWSE:
1041
1042                 ipo= G.sipo->ipo;
1043                 from= G.sipo->from;
1044                 id= (ID *)ipo;
1045                 if(from==NULL) return;
1046
1047                 if(G.sipo->menunr== -2) {
1048                         activate_databrowse((ID *)G.sipo->ipo, ID_IP, G.sipo->blocktype, B_IPOBROWSE, &G.sipo->menunr, do_global_buttons);
1049                         return;
1050                 }
1051
1052                 if(G.sipo->menunr < 0) break;
1053
1054                 idtest= G.main->ipo.first;
1055                 while(idtest) {
1056                         if( ((Ipo *)idtest)->blocktype == G.sipo->blocktype) {
1057                                 if(nr==G.sipo->menunr) {
1058                                         break;
1059                                 }
1060                                 nr++;
1061                         }
1062                         idtest= idtest->next;
1063                 }
1064
1065                 if(G.sipo->pin) {
1066                         if(idtest) {
1067                                 G.sipo->ipo= (Ipo *)idtest;
1068                                 allspace(REMAKEIPO, 0);         // in fact it should only do this one, but there is no function for it
1069                         }
1070                 }
1071                 else {
1072                         // assign the ipo to ...
1073
1074                         if(idtest==0) {
1075                                 if(ipo) idtest= (ID *)copy_ipo(ipo);
1076                                 else {
1077                                         nr= G.sipo->blocktype;
1078                                         if(nr==ID_OB) idtest= (ID *)add_ipo("ObIpo", ID_OB);
1079                                         else if(nr==ID_CO) idtest= (ID *)add_ipo("CoIpo", ID_CO);
1080                                         else if(nr==ID_PO) idtest= (ID *)add_ipo("ActIpo", nr);
1081                                         else if(nr==ID_MA) idtest= (ID *)add_ipo("MatIpo", nr);
1082                                         else if(nr==ID_TE) idtest= (ID *)add_ipo("TexIpo", nr);
1083                                         else if(nr==ID_SEQ) idtest= (ID *)add_ipo("MatSeq", nr);
1084                                         else if(nr==ID_CU) idtest= (ID *)add_ipo("CuIpo", nr);
1085                                         else if(nr==ID_KE) idtest= (ID *)add_ipo("KeyIpo", nr);
1086                                         else if(nr==ID_WO) idtest= (ID *)add_ipo("WoIpo", nr);
1087                                         else if(nr==ID_LA) idtest= (ID *)add_ipo("LaIpo", nr);
1088                                         else if(nr==ID_CA) idtest= (ID *)add_ipo("CaIpo", nr);
1089                                         else if(nr==ID_SO) idtest= (ID *)add_ipo("SndIpo", nr);
1090                                         else if(nr==ID_FLUIDSIM) idtest= (ID *)add_ipo("FluidsimIpo", nr);
1091                                         else if(nr==ID_PA) idtest= (ID *)add_ipo("PaIpo", nr);
1092                                         else error("Warn bugtracker!");
1093                                 }
1094                                 idtest->us--;
1095                         }
1096                         if(idtest!=id && from) {
1097                                 spaceipo_assign_ipo(G.sipo, (Ipo *)idtest);
1098                                                                         
1099                                 BIF_undo_push("Browse Ipo");
1100                         }
1101                 }
1102                 break;
1103         case B_IPODELETE:
1104                 ipo= G.sipo->ipo;
1105                 from= G.sipo->from;
1106                 
1107                 spaceipo_assign_ipo(G.sipo, NULL);
1108                 
1109                 editipo_changed(G.sipo, 1); /* doredraw */
1110                 
1111                 BIF_undo_push("Unlink Ipo");
1112                 
1113                 break;
1114         case B_WORLDBROWSE:
1115
1116                 if(G.buts->menunr==-2) {
1117                         activate_databrowse((ID *)G.scene->world, ID_WO, 0, B_WORLDBROWSE, &G.buts->menunr, do_global_buttons);
1118                         break;
1119                 }
1120
1121                 if(G.buts->menunr < 0) break;
1122                 /* no lock */
1123                         
1124                 wrld= G.scene->world;
1125                 nr= 1;
1126                 
1127                 id= (ID *)wrld;
1128                 
1129                 idtest= G.main->world.first;
1130                 while(idtest) {
1131                         if(nr==G.buts->menunr) {
1132                                 break;
1133                         }
1134                         nr++;
1135                         idtest= idtest->next;
1136                 }
1137                 if(idtest==0) { /* new world */
1138                         if(id) idtest= (ID *)copy_world((World *)id);
1139                         else idtest= (ID *)add_world("World");
1140                         idtest->us--;
1141                 }
1142                 if(idtest!=id) {
1143                         G.scene->world= (World *)idtest;
1144                         id_us_plus(idtest);
1145                         if(id) id->us--;
1146                         
1147                         BIF_undo_push("Browse World");
1148                         allqueue(REDRAWBUTSSHADING, 0);
1149                         allqueue(REDRAWIPO, 0);
1150                         allqueue(REDRAWOOPS, 0);
1151                         BIF_preview_changed(ID_WO);
1152                 }
1153                 break;
1154         case B_WORLDDELETE:
1155                 if(G.scene->world) {
1156                         G.scene->world->id.us--;
1157                         G.scene->world= NULL;
1158
1159                         BIF_undo_push("Unlink World");
1160                         allqueue(REDRAWBUTSSHADING, 0);
1161                         allqueue(REDRAWIPO, 0);
1162                 }
1163                 
1164                 break;
1165         case B_WTEXBROWSE:
1166
1167                 if(G.buts->texnr== -2) {
1168                         id= NULL;
1169                         wrld= G.scene->world;
1170                         if(wrld) {
1171                                 mtex= wrld->mtex[ wrld->texact ];
1172                                 if(mtex) id= (ID *)mtex->tex;
1173                         }
1174
1175                         activate_databrowse((ID *)id, ID_TE, 0, B_WTEXBROWSE, &G.buts->texnr, do_global_buttons);
1176                         return;
1177                 }
1178                 if(G.buts->texnr < 0) break;
1179
1180                 if(G.buts->pin) {
1181                         
1182                 }
1183                 else {
1184                         id= NULL;
1185                         
1186                         wrld= G.scene->world;
1187                         if(wrld) {
1188                                 mtex= wrld->mtex[ wrld->texact ];
1189                                 if(mtex) id= (ID *)mtex->tex;
1190                         }
1191
1192                         idtest= G.main->tex.first;
1193                         while(idtest) {
1194                                 if(nr==G.buts->texnr) {
1195                                         break;
1196                                 }
1197                                 nr++;
1198                                 idtest= idtest->next;
1199                         }
1200                         if(idtest==0) { /* new tex */
1201                                 if(id)  idtest= (ID *)copy_texture((Tex *)id);
1202                                 else idtest= (ID *)add_texture("Tex");
1203                                 idtest->us--;
1204                         }
1205                         if(idtest!=id && wrld) {
1206                                 
1207                                 if( wrld->mtex[wrld->texact]==0) {
1208                                         wrld->mtex[wrld->texact]= add_mtex();
1209                                         wrld->mtex[wrld->texact]->texco= TEXCO_VIEW;
1210                                 }
1211                                 wrld->mtex[ wrld->texact ]->tex= (Tex *)idtest;
1212                                 id_us_plus(idtest);
1213                                 if(id) id->us--;
1214                                 
1215                                 BIF_undo_push("Texture browse");
1216                                 allqueue(REDRAWBUTSSHADING, 0);
1217                                 allqueue(REDRAWIPO, 0);
1218                                 allqueue(REDRAWOOPS, 0);
1219                                 BIF_preview_changed(ID_WO);
1220                         }
1221                 }
1222                 break;
1223         case B_LAMPBROWSE:
1224                 /* no lock */
1225                 if(ob==0) return;
1226                 if(ob->type!=OB_LAMP) return;
1227
1228                 if(G.buts->menunr== -2) {
1229                         activate_databrowse((ID *)G.buts->lockpoin, ID_LA, 0, B_LAMPBROWSE, &G.buts->menunr, do_global_buttons);
1230                         return;
1231                 }
1232                 if(G.buts->menunr < 0) break;
1233                 
1234                 la= ob->data;
1235                 nr= 1;
1236                 id= (ID *)la;
1237                 
1238                 idtest= G.main->lamp.first;
1239                 while(idtest) {
1240                         if(nr==G.buts->menunr) {
1241                                 break;
1242                         }
1243                         nr++;
1244                         idtest= idtest->next;
1245                 }
1246                 if(idtest==0) { /* no new lamp */
1247                         return;
1248                 }
1249                 if(idtest!=id) {
1250                         ob->data= (Lamp *)idtest;
1251                         id_us_plus(idtest);
1252                         if(id) id->us--;
1253                         
1254                         BIF_undo_push("Lamp browse");
1255                         allqueue(REDRAWBUTSSHADING, 0);
1256                         allqueue(REDRAWVIEW3D, 0);
1257                         allqueue(REDRAWIPO, 0);
1258                         allqueue(REDRAWOOPS, 0);
1259                         BIF_preview_changed(ID_LA);
1260                 }
1261                 break;
1262         
1263         case B_LTEXBROWSE:
1264
1265                 if(ob==0) return;
1266                 if(ob->type!=OB_LAMP) return;
1267
1268                 if(G.buts->texnr== -2) {
1269                         id= NULL;
1270                         la= ob->data;
1271                         mtex= la->mtex[ la->texact ];
1272                         if(mtex) id= (ID *)mtex->tex;
1273
1274                         activate_databrowse(id, ID_TE, 0, B_LTEXBROWSE, &G.buts->texnr, do_global_buttons);
1275                         return;
1276                 }
1277                 if(G.buts->texnr < 0) break;
1278
1279                 if(G.buts->pin) {
1280                         
1281                 }
1282                 else {
1283                         id= NULL;
1284                         
1285                         la= ob->data;
1286                         mtex= la->mtex[ la->texact ];
1287                         if(mtex) id= (ID *)mtex->tex;
1288
1289                         idtest= G.main->tex.first;
1290                         while(idtest) {
1291                                 if(nr==G.buts->texnr) {
1292                                         break;
1293                                 }
1294                                 nr++;
1295                                 idtest= idtest->next;
1296                         }
1297                         if(idtest==0) { /* new tex */
1298                                 if(id)  idtest= (ID *)copy_texture((Tex *)id);
1299                                 else idtest= (ID *)add_texture("Tex");
1300                                 idtest->us--;
1301                         }
1302                         if(idtest!=id && la) {
1303                                 
1304                                 if( la->mtex[la->texact]==0) {
1305                                         la->mtex[la->texact]= add_mtex();
1306                                         la->mtex[la->texact]->texco= TEXCO_GLOB;
1307                                 }
1308                                 la->mtex[ la->texact ]->tex= (Tex *)idtest;
1309                                 id_us_plus(idtest);
1310                                 if(id) id->us--;
1311                                 
1312                                 BIF_undo_push("Texture Browse");
1313                                 allqueue(REDRAWBUTSSHADING, 0);
1314                                 allqueue(REDRAWIPO, 0);
1315                                 allqueue(REDRAWOOPS, 0);
1316                                 BIF_preview_changed(ID_LA);
1317                         }
1318                 }
1319                 break;
1320
1321         case B_IMAGEDELETE:
1322                 if(G.sima->image && (G.sima->image->type == IMA_TYPE_R_RESULT || G.sima->image->type == IMA_TYPE_COMPOSITE)) {
1323                         /* Run if G.sima is render, remove the render and display the meshes image if it exists */
1324                         G.sima->image= NULL;
1325                         what_image(G.sima);
1326                         allqueue(REDRAWIMAGE, 0);
1327                 } else {
1328                         /* Run on non render images, unlink normally */
1329                         image_changed(G.sima, NULL);
1330                         BIF_undo_push("Unlink Image");
1331                         allqueue(REDRAWIMAGE, 0);
1332                 }
1333                 break;
1334         
1335         case B_AUTOMATNAME:
1336                 /* this is called now from Node editor too, buttons might not exist */
1337                 if(curarea->spacetype==SPACE_NODE) {
1338                         SpaceNode *snode= curarea->spacedata.first;
1339                         automatname((Material *)snode->id);
1340                 }
1341                 else if(G.buts) {
1342                         automatname(G.buts->lockpoin);
1343                 }
1344                 else return;
1345
1346                 BIF_undo_push("Auto name");
1347                 allqueue(REDRAWBUTSSHADING, 0);
1348                 allqueue(REDRAWNODE, 0);
1349                 allqueue(REDRAWOOPS, 0);
1350                 break;          
1351         case B_AUTOTEXNAME:
1352                 if(G.buts->mainb==CONTEXT_SHADING) {
1353                         if(G.buts->tab[CONTEXT_SHADING]==TAB_SHADING_TEX) {
1354                                 autotexname(G.buts->lockpoin);
1355                         }
1356                         else if(G.buts->tab[CONTEXT_SHADING]==TAB_SHADING_MAT) {
1357                                 ma= G.buts->lockpoin;
1358                                 if(ma->mtex[ ma->texact]) autotexname(ma->mtex[ma->texact]->tex);
1359                         }
1360                         else if(G.buts->tab[CONTEXT_SHADING]==TAB_SHADING_WORLD) {
1361                                 wrld= G.buts->lockpoin;
1362                                 if(wrld->mtex[ wrld->texact]) autotexname(wrld->mtex[wrld->texact]->tex);
1363                         }
1364                         else if(G.buts->tab[CONTEXT_SHADING]==TAB_SHADING_LAMP) {
1365                                 la= G.buts->lockpoin;
1366                                 if(la->mtex[ la->texact]) autotexname(la->mtex[la->texact]->tex);
1367                         }
1368                         BIF_undo_push("Auto name");
1369                         allqueue(REDRAWBUTSSHADING, 0);
1370                         allqueue(REDRAWOOPS, 0);
1371                         allqueue(REDRAWIMAGE, 0);
1372                 }
1373                 else if(G.buts->mainb==CONTEXT_EDITING) {
1374                         SculptData *sd= &G.scene->sculptdata;
1375                         if(sd && sd->texact != -1) {
1376                                 if(sd->mtex[sd->texact]) autotexname(sd->mtex[sd->texact]->tex);
1377
1378                                 BIF_undo_push("Auto name");
1379                                 allqueue(REDRAWBUTSEDIT, 0);
1380                                 allqueue(REDRAWOOPS, 0);
1381                         }
1382                 }
1383                 break;
1384
1385         case B_RESETAUTOSAVE:
1386                 reset_autosave();
1387                 allqueue(REDRAWINFO, 0);
1388                 break;
1389         case B_SOUNDTOGGLE:
1390                 SYS_WriteCommandLineInt(SYS_GetSystem(), "noaudio", (U.gameflags & USER_DISABLE_SOUND));
1391                 break;
1392         case B_SHOWSPLASH:
1393                                 show_splash();
1394                 break;
1395         case B_MIPMAPCHANGED:
1396                 set_mipmap(!(U.gameflags & USER_DISABLE_MIPMAP));
1397                 allqueue(REDRAWVIEW3D, 0);
1398                 break;
1399         case B_GLRESLIMITCHANGED:
1400                 free_all_realtime_images(); /* force reloading with new res limit */
1401                 allqueue(REDRAWVIEW3D, 0);
1402                 break;
1403         case B_NEWSPACE:
1404                 newspace(curarea, curarea->butspacetype);
1405                 break;
1406         case B_LOADTEMP:        /* is button from space.c */
1407                 BIF_read_autosavefile();
1408                 break;
1409
1410         case B_USERPREF:
1411                 allqueue(REDRAWINFO, 0);
1412                 break;
1413
1414         case B_DRAWINFO:        /* is button from space.c  *info* */
1415                 allqueue(REDRAWVIEW3D, 0);
1416                 break;
1417
1418         case B_PLAINMENUS:     /* is button from space.c  *info* */
1419                 reset_toolbox();
1420                 break;
1421
1422         case B_FLIPINFOMENU:    /* is button from space.c  *info* */
1423                 scrarea_queue_headredraw(curarea);
1424                 break;
1425
1426 #if 0
1427 //#ifdef _WIN32 // FULLSCREEN
1428         case B_FLIPFULLSCREEN:
1429                 if(U.uiflag & USER_FLIPFULLSCREEN)
1430                         U.uiflag &= ~USER_FLIPFULLSCREEN;
1431                 else
1432                         U.uiflag |= USER_FLIPFULLSCREEN;
1433                 mainwindow_toggle_fullscreen((U.uiflag & USER_FLIPFULLSCREEN));
1434                 break;
1435 #endif
1436
1437         /* Fileselect windows for user preferences file paths */
1438
1439         /* yafray: xml export dir. select */
1440         case B_YAFRAYDIRFILESEL:        /* space.c */
1441                 if(curarea->spacetype==SPACE_INFO) {
1442                         sa= closest_bigger_area();
1443                         areawinset(sa->win);
1444                 }
1445
1446                 activate_fileselect(FILE_SPECIAL, "SELECT YFEXPORT PATH", U.yfexportdir, filesel_u_yfexportdir);
1447                 break;
1448
1449         case B_FONTDIRFILESEL:  /* is button from space.c  *info* */
1450                 if(curarea->spacetype==SPACE_INFO) {
1451                         sa= closest_bigger_area();
1452                         areawinset(sa->win);
1453                 }
1454
1455                 activate_fileselect(FILE_SPECIAL, "SELECT FONT PATH", U.fontdir, filesel_u_fontdir);
1456                 break;
1457
1458         case B_TEXTUDIRFILESEL:         /* is button from space.c  *info* */
1459                 if(curarea->spacetype==SPACE_INFO) {
1460                         sa= closest_bigger_area();
1461                         areawinset(sa->win);
1462                 }
1463
1464                 activate_fileselect(FILE_SPECIAL, "SELECT TEXTURE PATH", U.textudir, filesel_u_textudir);
1465                 break;
1466         
1467         case B_PLUGTEXDIRFILESEL:               /* is button form space.c  *info* */
1468                 if(curarea->spacetype==SPACE_INFO) {
1469                         sa= closest_bigger_area();
1470                         areawinset(sa->win);
1471                 }
1472
1473                 activate_fileselect(FILE_SPECIAL, "SELECT TEX PLUGIN PATH", U.plugtexdir, filesel_u_plugtexdir);
1474                 break;
1475         
1476         case B_PLUGSEQDIRFILESEL:               /* is button from space.c  *info* */
1477                 if(curarea->spacetype==SPACE_INFO) {
1478                         sa= closest_bigger_area();
1479                         areawinset(sa->win);
1480                 }
1481
1482                 activate_fileselect(FILE_SPECIAL, "SELECT SEQ PLUGIN PATH", U.plugseqdir, filesel_u_plugseqdir);
1483                 break;
1484         
1485         case B_RENDERDIRFILESEL:        /* is button from space.c  *info* */
1486                 if(curarea->spacetype==SPACE_INFO) {
1487                         sa= closest_bigger_area();
1488                         areawinset(sa->win);
1489                 }
1490
1491                 activate_fileselect(FILE_SPECIAL, "SELECT RENDER PATH", U.renderdir, filesel_u_renderdir);
1492                 break;
1493
1494         case B_PYMENUEVAL: /* is button from space.c *info* */
1495                 waitcursor( 1 ); /* can take some time */
1496                 BPyMenu_RemoveAllEntries(); /* free old data */
1497                 if (BPyMenu_Init(1) == -1) { /* re-eval scripts registration in menus */
1498                         waitcursor( 0 );
1499                         error("Invalid scripts dir: check console");
1500                 }
1501                 waitcursor( 0 );
1502                 break;
1503         case B_PYTHONDIRFILESEL:        /* is button from space.c  *info* */
1504                 if(curarea->spacetype==SPACE_INFO) {
1505                         sa= closest_bigger_area();
1506                         areawinset(sa->win);
1507                 }
1508
1509                 activate_fileselect(FILE_SPECIAL, "SELECT SCRIPT PATH", U.pythondir, filesel_u_pythondir);
1510                 break;
1511
1512         case B_SOUNDDIRFILESEL:         /* is button from space.c  *info* */
1513                 if(curarea->spacetype==SPACE_INFO) {
1514                         sa= closest_bigger_area();
1515                         areawinset(sa->win);
1516                 }
1517
1518                 activate_fileselect(FILE_SPECIAL, "SELECT SOUND PATH", U.sounddir, filesel_u_sounddir);
1519                 break;
1520
1521         case B_TEMPDIRFILESEL:  /* is button from space.c  *info* */
1522                 if(curarea->spacetype==SPACE_INFO) {
1523                         sa= closest_bigger_area();
1524                         areawinset(sa->win);
1525                 }
1526
1527                 activate_fileselect(FILE_SPECIAL, "SELECT TEMP FILE PATH", U.tempdir, filesel_u_tempdir);
1528                 break;
1529
1530         /* END Fileselect windows for user preferences file paths */
1531
1532 #ifdef INTERNATIONAL
1533         case B_LOADUIFONT:      /* is button from space.c  *info* */
1534                 if(curarea->spacetype==SPACE_INFO) {
1535                         sa= closest_bigger_area();
1536                         areawinset(sa->win);
1537                 }
1538                 BLI_make_file_string("/", buf, U.fontdir, U.fontname);
1539                 activate_fileselect(FILE_SPECIAL, "LOAD UI FONT", buf, set_interface_font);
1540                 break;
1541
1542         case B_SETLANGUAGE:             /* is button from space.c  *info* */
1543                 lang_setlanguage();
1544                 allqueue(REDRAWALL, 0);
1545                 break;
1546
1547         case B_SETFONTSIZE:             /* is button from space.c  *info* */
1548                 refresh_interface_font();
1549                 FTF_SetSize(U.fontsize); 
1550                 allqueue(REDRAWALL, 0);
1551                 break;
1552                 
1553         case B_SETTRANSBUTS:    /* is button from space.c  *info* */
1554                 allqueue(REDRAWALL, 0);
1555                 break;
1556
1557         case B_RESTOREFONT:             /* is button from space.c  *info* */
1558                 U.fontsize= 0;
1559                 start_interface_font();
1560                 allqueue(REDRAWALL, 0);
1561                 break;
1562                 
1563         case B_USETEXTUREFONT:          /* is button from space.c  *info* */
1564                 refresh_interface_font();
1565                 allqueue(REDRAWALL, 0);
1566                 break;
1567
1568         case B_DOLANGUIFONT:    /* is button from space.c  *info* */
1569                 if(U.transopts & USER_DOTRANSLATE)
1570                         start_interface_font();
1571                 else
1572                         G.ui_international = FALSE;
1573                 allqueue(REDRAWALL, 0);
1574                 break;
1575 #endif
1576                 
1577         case B_FULL:
1578                 if(curarea->spacetype!=SPACE_INFO) {
1579                         area_fullscreen();
1580                 }
1581                 break;  
1582
1583         case B_IDNAME:
1584                         /* changing a metaballs name, sadly enough,
1585                          * can require it to be updated because its
1586                          * basis might have changed... -zr
1587                          */
1588                 if (ob && ob->type==OB_MBALL) {
1589                         DAG_scene_sort(G.scene);
1590                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1591                 }
1592                 /* redraw because name has changed: new pup */
1593                 scrarea_queue_headredraw(curarea);
1594                 allqueue(REDRAWINFO, 1);
1595                 allqueue(REDRAWOOPS, 1);
1596                 allqueue(REDRAWACTION, 1);
1597                 allqueue(REDRAWNLA, 1);
1598                 /* name scene also in set PUPmenu */
1599                 allqueue(REDRAWBUTSALL, 0);
1600                 allqueue(REDRAWIMAGE, 0);
1601                 allqueue(REDRAWHEADERS, 0);
1602                 break;
1603         
1604         case B_KEEPDATA:
1605                 /* keep datablock. similar to pressing FKEY in a fileselect window
1606                  * maybe we can move that stuff to a seperate function? -- sg
1607                  */
1608                 if (curarea->spacetype==SPACE_BUTS) {
1609                         id= (ID *)G.buts->lockpoin;
1610                 } else if(curarea->spacetype==SPACE_IPO) {
1611                         id = (ID *)G.sipo->ipo;
1612                 } else if(curarea->spacetype==SPACE_NODE) {
1613                         id = ((SpaceNode *)curarea->spacedata.first)->id;
1614                 } /* similar for other spacetypes ? */
1615                 if (id) {
1616                         if( id->flag & LIB_FAKEUSER) {
1617                                 id->flag -= LIB_FAKEUSER;
1618                                 id->us--;
1619                         } else {
1620                                 id->flag |= LIB_FAKEUSER;
1621                                 id->us++;
1622                         }
1623                 }
1624                 allqueue(REDRAWHEADERS, 0);
1625
1626                 break;
1627
1628         }
1629 }
1630
1631
1632 void do_global_buttons2(short event)
1633 {
1634         Base *base;
1635         Object *ob;
1636         Material *ma;
1637         MTex *mtex;
1638         Mesh *me;
1639         Curve *cu;
1640         MetaBall *mb;
1641         Ipo *ipo;
1642         Lamp *la;
1643         Lattice *lt;
1644         World *wrld;
1645         ID *idfrom; 
1646         bAction *act;
1647         Brush *br;
1648
1649         /* general:  Single User is allowed when from==LOCAL 
1650          *                       Make Local is allowed when (from==LOCAL && id==LIB)
1651          */
1652                 
1653         if(event<B_LOCAL_ALONE) return;
1654
1655         ob= OBACT;
1656
1657         switch(event) {
1658                 
1659         case B_LAMPALONE:
1660                 if(ob && ob->id.lib==0) {
1661                         la= ob->data;
1662                         if(la->id.us>1) {
1663                                 if(okee("Single user")) {
1664                                         ob->data= copy_lamp(la);
1665                                         la->id.us--;
1666                                 }
1667                         }
1668                 }
1669                 break;
1670         case B_LAMPLOCAL:
1671                 if(ob && ob->id.lib==0) {
1672                         la= ob->data;
1673                         if(la->id.lib) {
1674                                 if(okee("Make local")) {
1675                                         make_local_lamp(la);
1676                                 }
1677                         }
1678                 }
1679                 break;
1680         
1681         case B_ARMLOCAL:
1682                 if (ob&&ob->id.lib==0){
1683                         bArmature *arm=ob->data;
1684                         if (arm->id.lib){
1685                                 if(okee("Make local")) {
1686                                         make_local_armature(arm);
1687                                 }
1688                         }
1689                 }
1690                 break;
1691         case B_ARMALONE:
1692                 if(ob && ob->id.lib==0) {
1693                         bArmature *arm=ob->data;
1694                         if(arm->id.us>1) {
1695                                 if(okee("Single user")) {
1696                                         ob->data= copy_armature(arm);
1697                                         armature_rebuild_pose(ob, ob->data);
1698                                         arm->id.us--;
1699                                 }
1700                         }
1701                 }
1702                 break;
1703         case B_ACTLOCAL:
1704                 if(ob && ob->id.lib==0) {
1705                         act= ob->action;
1706                         if(act->id.lib) {
1707                                 if(okee("Make local")) {
1708                                         make_local_action(act);
1709                                         allqueue(REDRAWACTION, 0);
1710                                         allqueue(REDRAWBUTSEDIT, 0);
1711                                 }
1712                         }
1713                 }
1714                 break;
1715         case B_ACTALONE:
1716                 if(ob && ob->id.lib==0) {
1717                         act= ob->action;
1718                         
1719                         if(act->id.us>1) {
1720                                 if(okee("Single user")) {
1721                                         ob->action=copy_action(act);
1722                                         act->id.us--;
1723                                         allqueue(REDRAWACTION, 0);
1724                                         allqueue(REDRAWBUTSEDIT, 0);
1725                                 }
1726                         }
1727                 }
1728                 break;
1729
1730         case B_CAMERAALONE:
1731                 if(ob && ob->id.lib==0) {
1732                         Camera *ca= ob->data;
1733                         if(ca->id.us>1) {
1734                                 if(okee("Single user")) {
1735                                         ob->data= copy_camera(ca);
1736                                         ca->id.us--;
1737                                 }
1738                         }
1739                 }
1740                 break;
1741         case B_CAMERALOCAL:
1742                 if(ob && ob->id.lib==0) {
1743                         Camera *ca= ob->data;
1744                         if(ca->id.lib) {
1745                                 if(okee("Make local")) {
1746                                         make_local_camera(ca);
1747                                 }
1748                         }
1749                 }
1750                 break;
1751         case B_WORLDALONE:
1752                 wrld= G.scene->world;
1753                 if(wrld->id.us>1) {
1754                         if(okee("Single user")) {
1755                                 G.scene->world= copy_world(wrld);
1756                                 wrld->id.us--;
1757                         }
1758                 }
1759                 break;
1760         case B_WORLDLOCAL:
1761                 wrld= G.scene->world;
1762                 if(wrld && wrld->id.lib) {
1763                         if(okee("Make local")) {
1764                                 make_local_world(wrld);
1765                         }
1766                 }
1767                 break;
1768
1769         case B_LATTALONE:
1770                 if(ob && ob->id.lib==0) {
1771                         lt= ob->data;
1772                         if(lt->id.us>1) {
1773                                 if(okee("Single user")) {
1774                                         ob->data= copy_lattice(lt);
1775                                         lt->id.us--;
1776                                 }
1777                         }
1778                 }
1779                 break;
1780         case B_LATTLOCAL:
1781                 if(ob && ob->id.lib==0) {
1782                         lt= ob->data;
1783                         if(lt->id.lib) {
1784                                 if(okee("Make local")) {
1785                                         make_local_lattice(lt);
1786                                 }
1787                         }
1788                 }
1789                 break;
1790         
1791         case B_MATALONE:
1792                 if(ob==0) return;
1793                 ma= give_current_material(ob, ob->actcol);
1794                 idfrom= material_from(ob, ob->actcol);
1795                 if(idfrom && idfrom->lib==0) {
1796                         if(ma->id.us>1) {
1797                                 if(okee("Single user")) {
1798                                         ma= copy_material(ma);
1799                                         ma->id.us= 0;
1800                                         assign_material(ob, ma, ob->actcol);
1801                                 }
1802                         }
1803                 }
1804                 break;
1805         case B_MATLOCAL:
1806                 if(ob==0) return;
1807                 idfrom= material_from(ob, ob->actcol);
1808                 if(idfrom->lib==0) {
1809                         ma= give_current_material(ob, ob->actcol);
1810                         if(ma && ma->id.lib) {
1811                                 if(okee("Make local")) {
1812                                         make_local_material(ma);
1813                                 }
1814                         }
1815                 }
1816                 break;
1817
1818         case B_MESHLOCAL:
1819                 if(ob && ob->id.lib==0) {
1820                         me= ob->data;
1821                         if(me && me->id.lib) {
1822                                 if(okee("Make local")) {
1823                                         make_local_mesh(me);
1824                                         make_local_key( me->key );
1825
1826                                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);                           
1827                                 }
1828                         }
1829                 }
1830                 break;
1831
1832         case B_MBALLALONE:
1833                 if(ob && ob->id.lib==0) {
1834                         mb= ob->data;
1835                         if(mb->id.us>1) {
1836                                 if(okee("Single user")) {
1837                                         ob->data= copy_mball(mb);
1838                                         mb->id.us--;
1839                                         if(ob==G.obedit) allqueue(REDRAWVIEW3D, 0);
1840                                 }
1841                         }
1842                 }
1843                 break;
1844         case B_MBALLLOCAL:
1845                 if(ob && ob->id.lib==0) {
1846                         mb= ob->data;
1847                         if(mb->id.lib) {
1848                                 if(okee("Make local")) {
1849                                         make_local_mball(mb);
1850                                 }
1851                         }
1852                 }
1853                 break;
1854
1855         case B_CURVEALONE:
1856                 if(ob && ob->id.lib==0) {
1857                         cu= ob->data;
1858                         if(cu->id.us>1) {
1859                                 if(okee("Single user")) {
1860                                         ob->data= copy_curve(cu);
1861                                         cu->id.us--;
1862                                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1863                                         if(ob==G.obedit) allqueue(REDRAWVIEW3D, 0);
1864                                 }
1865                         }
1866                 }
1867                 break;
1868         case B_CURVELOCAL:
1869                 if(ob && ob->id.lib==0) {
1870                         cu= ob->data;
1871                         if(cu->id.lib) {
1872                                 if(okee("Make local")) {
1873                                         make_local_curve(cu);
1874                                         make_local_key( cu->key );
1875                                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1876                                 }
1877                         }
1878                 }
1879                 break;
1880                 
1881         case B_TEXALONE:
1882                 if(G.buts->texfrom==0) {        /* from mat */
1883                         if(ob==0) return;
1884                         ma= give_current_material(ob, ob->actcol);
1885                         ma= editnode_get_active_material(ma);
1886                         if(ma && ma->id.lib==0) {
1887                                 mtex= ma->mtex[ ma->texact ];
1888                                 if(mtex->tex && mtex->tex->id.us>1) {
1889                                         if(okee("Single user")) {
1890                                                 mtex->tex->id.us--;
1891                                                 mtex->tex= copy_texture(mtex->tex);
1892                                         }
1893                                 }
1894                         }
1895                 }
1896                 else if(G.buts->texfrom==1) { /* from world */
1897                         wrld= G.scene->world;
1898                         if(wrld->id.lib==0) {
1899                                 mtex= wrld->mtex[ wrld->texact ];
1900                                 if(mtex->tex && mtex->tex->id.us>1) {
1901                                         if(okee("Single user")) {
1902                                                 mtex->tex->id.us--;
1903                                                 mtex->tex= copy_texture(mtex->tex);
1904                                         }
1905                                 }
1906                         }
1907                 }
1908                 else if(G.buts->texfrom==2) { /* from lamp */
1909                         if(ob==0 || ob->type!=OB_LAMP) return;
1910                         la= ob->data;
1911                         if(la->id.lib==0) {
1912                                 mtex= la->mtex[ la->texact ];
1913                                 if(mtex->tex && mtex->tex->id.us>1) {
1914                                         if(okee("Single user")) {
1915                                                 mtex->tex->id.us--;
1916                                                 mtex->tex= copy_texture(mtex->tex);
1917                                         }
1918                                 }
1919                         }
1920                 }
1921                 else if(G.buts->texfrom==3) { /* from brush */
1922                         br= G.scene->toolsettings->imapaint.brush;
1923                         if(br==0) return;
1924                         if(br->id.lib==0) {
1925                                 mtex= br->mtex[ br->texact ];
1926                                 if(mtex->tex && mtex->tex->id.us>1) {
1927                                         if(okee("Single user")) {
1928                                                 mtex->tex->id.us--;
1929                                                 mtex->tex= copy_texture(mtex->tex);
1930                                                 allqueue(REDRAWIMAGE, 0);
1931                                         }
1932                                 }
1933                         }
1934                 }
1935                 break;
1936         case B_TEXLOCAL:
1937                 if(G.buts->texfrom==0) {        /* from mat */
1938                         if(ob==0) return;
1939                         ma= give_current_material(ob, ob->actcol);
1940                         ma= editnode_get_active_material(ma);
1941                         if(ma && ma->id.lib==0) {
1942                                 mtex= ma->mtex[ ma->texact ];
1943                                 if(mtex->tex && mtex->tex->id.lib) {
1944                                         if(okee("Make local")) {
1945                                                 make_local_texture(mtex->tex);
1946                                         }
1947                                 }
1948                         }
1949                 }
1950                 else if(G.buts->texfrom==1) { /* from world */
1951                         wrld= G.scene->world;
1952                         if(wrld->id.lib==0) {
1953                                 mtex= wrld->mtex[ wrld->texact ];
1954                                 if(mtex->tex && mtex->tex->id.lib) {
1955                                         if(okee("Make local")) {
1956                                                 make_local_texture(mtex->tex);
1957                                         }
1958                                 }
1959                         }
1960                 }
1961                 else if(G.buts->texfrom==2) { /* from lamp */
1962                         if(ob==0 || ob->type!=OB_LAMP) return;
1963                         la= ob->data;
1964                         if(la->id.lib==0) {
1965                                 mtex= la->mtex[ la->texact ];
1966                                 if(mtex->tex && mtex->tex->id.lib) {
1967                                         if(okee("Make local")) {
1968                                                 make_local_texture(mtex->tex);
1969                                         }
1970                                 }
1971                         }
1972                 }
1973                 else if(G.buts->texfrom==3) { /* from brush */
1974                         br= G.scene->toolsettings->imapaint.brush;
1975                         if(br==0) return;
1976                         if(br->id.lib==0) {
1977                                 mtex= br->mtex[ br->texact ];
1978                                 if(mtex->tex && mtex->tex->id.lib) {
1979                                         if(okee("Make local")) {
1980                                                 make_local_texture(mtex->tex);
1981                                                 allqueue(REDRAWIMAGE, 0);
1982                                         }
1983                                 }
1984                         }
1985                 }
1986                 break;
1987         
1988         case B_IPOALONE:
1989                 ipo= G.sipo->ipo;
1990                 idfrom= G.sipo->from;
1991                 
1992                 if(idfrom && idfrom->lib==NULL) {
1993                         if(ipo->id.us>1) {
1994                                 if(okee("Single user")) {
1995                                         ipo= copy_ipo(ipo);
1996                                         ipo->id.us= 0;  /* assign_ipo adds users, copy_ipo sets to 1 */
1997                                         spaceipo_assign_ipo(G.sipo, ipo);
1998                                         allqueue(REDRAWIPO, 0);
1999                                 }
2000                         }
2001                 }
2002                 break;
2003         case B_IPOLOCAL:
2004                 ipo= G.sipo->ipo;
2005                 idfrom= G.sipo->from;
2006                 
2007                 if(idfrom && idfrom->lib==0) {
2008                         if(ipo->id.lib) {
2009                                 if(okee("Make local")) {
2010                                         make_local_ipo(ipo);
2011                                         allqueue(REDRAWIPO, 0);
2012                                 }
2013                         }
2014                 }
2015                 break;
2016
2017         case B_OBALONE:
2018                 if(G.scene->id.lib==0) {
2019                         if(ob->id.us>1) {
2020                                 if(okee("Single user")) {
2021                                         base= FIRSTBASE;
2022                                         while(base) {
2023                                                 if(base->object==ob) {
2024                                                         base->object= copy_object(ob);
2025                                                         ob->id.us--;
2026                                                         allqueue(REDRAWVIEW3D, 0);
2027                                                         break;
2028                                                 }
2029                                                 base= base->next;
2030                                         }
2031                                 }
2032                         }
2033                 }
2034                 break;
2035         case B_OBLOCAL:
2036                 if(G.scene->id.lib==0) {
2037                         if(ob->id.lib) {
2038                                 if(okee("Make local")) {
2039                                         make_local_object(ob);
2040                                         allqueue(REDRAWVIEW3D, 0);
2041                                 }
2042                         }
2043                 }
2044                 break;
2045         case B_MESHALONE:
2046                 if(ob && ob->id.lib==0) {
2047                         
2048                         me= ob->data;
2049                         
2050                         if(me && me->id.us>1) {
2051                                 if(okee("Single user")) {
2052                                         Mesh *men= copy_mesh(me);
2053                                         men->id.us= 0;
2054                                         
2055                                         set_mesh(ob, men);
2056                                         
2057                                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2058                                         
2059                                         if(ob==G.obedit) allqueue(REDRAWVIEW3D, 0);
2060                                 }
2061                         }
2062                 }
2063                 break;
2064         }
2065         
2066         BIF_undo_push("Make single user or local");
2067         allqueue(REDRAWBUTSALL, 0);
2068         allqueue(REDRAWOOPS, 0);
2069 }
2070
2071 /* ******************** GENERAL ********************** */
2072
2073 void do_headerbuttons(short event)
2074 {
2075
2076         if(event<=50) do_global_buttons2(event);
2077         else if(event<=100) do_global_buttons(event);
2078         else if(event<200) do_view3d_buttons(event);
2079         else if(event<250) do_ipo_buttons(event);
2080         else if(event<300) do_oops_buttons(event);
2081         else if(event<350) do_info_buttons(event);
2082         else if(event<400) do_image_buttons(event);
2083         else if(event<450) do_buts_buttons(event);
2084         else if(event<500) do_imasel_buttons(event);
2085         else if(event<525) do_text_buttons(event);
2086         else if(event<550) do_script_buttons(event);
2087         else if(event<600) do_file_buttons(event);
2088         else if(event<650) do_seq_buttons(event);
2089         else if(event<700) do_sound_buttons(event);
2090         else if(event<750) do_action_buttons(event);
2091         else if(event<800) do_time_buttons(curarea, event);
2092         else if(event<850) do_nla_buttons(event);
2093         else if(event<900) do_node_buttons(curarea, event);
2094         else if(event>=REDRAWVIEW3D) allqueue(event, 0);
2095 }
2096