Bugfix #7371
[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(ELEM3(id_code, ID_MA, ID_TE, ID_BR)) 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) 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) len= 140;  // comes from button panel
329                 else len= 120;
330                 
331                 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.");
332                 uiButSetFunc(but, test_idbutton_cb, id->name, NULL);
333
334                 uiClearButLock();
335
336                 xco+= len;
337                 
338                 if(id->lib) {
339                         
340                         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.");
341                         else uiDefIconBut(block, BUT, lib, ICON_PARLIB, xco,yco,XIC,YIC, 0, 0, 0, 0, 0, 
342                                                           lib?"Direct linked Library Datablock. Click to make local.":"Direct linked Library Datablock, cannot make local."
343                                                           );
344                         
345                         xco+= XIC;
346                 }
347                 
348                 
349                 if(users && id->us>1) {
350                         uiSetButLock (pin && *pinpoin, "Can't make pinned data single-user");
351                         
352                         sprintf(str1, "%d", id->us);
353                         if(id->us<10) {
354                                 
355                                 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.");
356                                 xco+= XIC;
357                         }
358                         else {
359                                 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.");
360                                 xco+= XIC+10;
361                         }
362                         
363                         uiClearButLock();
364                         
365                 }
366                 
367                 if(del) {
368
369                         uiSetButLock (pin && *pinpoin, "Can't unlink pinned data");
370                         if(parid && parid->lib);
371                         else {
372                                 uiDefIconBut(block, BUT, del, ICON_X, xco,yco,XIC,YIC, 0, 0, 0, 0, 0, "Deletes link to this Datablock");
373                                 xco+= XIC;
374                         }
375
376                         uiClearButLock();
377                 }
378
379                 if(autobut) {
380                         if(parid && parid->lib);
381                         else {
382                                 uiDefIconBut(block, BUT, autobut, ICON_AUTO,xco,yco,XIC,YIC, 0, 0, 0, 0, 0, "Generates an automatic name");
383                                 xco+= XIC;
384                         }
385                         
386                         
387                 }
388                 if(keepbut) {
389                         uiDefBut(block, BUT, keepbut, "F", xco,yco,XIC,YIC, 0, 0, 0, 0, 0, "Saves this datablock even if it has no users");  
390                         xco+= XIC;
391                 }
392         }
393         else if(add_addbutton) {        /* "add new" button */
394                 uiBlockSetCol(block, oldcol);
395                 uiDefButS(block, TOG, browse, "Add New" ,xco, yco, 110, YIC, menupoin, (float)*menupoin, 32767.0, 0, 0, "Add new data block");
396                 xco+= 110;
397         }
398         //xco+=XIC;
399         
400         uiBlockSetCol(block, oldcol);
401         uiBlockEndAlign(block);
402
403         return xco;
404 }
405
406
407 /* results in fully updated anim system */
408 static void do_update_for_newframe(int mute, int events)
409 {
410         extern void audiostream_scrub(unsigned int frame);      /* seqaudio.c */
411         
412         if(events) {
413                 allqueue(REDRAWALL, 0);
414         }
415         
416         /* this function applies the changes too */
417         scene_update_for_newframe(G.scene, screen_view3d_layers()); /* BKE_scene.h */
418
419         if ( (CFRA>1) && (!mute) && (G.scene->audio.flag & AUDIO_SCRUB)) 
420                 audiostream_scrub( CFRA );
421         
422         /* 3d window, preview */
423         BIF_view3d_previewrender_signal(curarea, PR_DBASE|PR_DISPRECT);
424
425         /* all movie/sequence images */
426         BIF_image_update_frame();
427         
428         /* composite */
429         if(G.scene->use_nodes && G.scene->nodetree)
430                 ntreeCompositTagAnimated(G.scene->nodetree);
431 }
432
433 void update_for_newframe(void)
434 {
435         do_update_for_newframe(0, 1);
436 }
437
438 void update_for_newframe_muted(void)
439 {
440         do_update_for_newframe(1, 1);
441 }
442
443 /* used by new animated UI playback */
444 void update_for_newframe_nodraw(int nosound)
445 {
446         do_update_for_newframe(nosound, 0);
447 }
448
449
450 static void show_splash(void)
451 {
452         extern char datatoc_splash_jpg[];
453         extern int datatoc_splash_jpg_size;
454         char *string = NULL;
455
456 #ifdef NAN_BUILDINFO
457         char buffer[1024];
458         extern char * build_date;
459         extern char * build_time;
460         extern char * build_platform;
461         extern char * build_type;
462
463         string = &buffer[0];
464         sprintf(string,"Built on %s %s     Version %s %s", build_date, build_time, build_platform, build_type);
465 #endif
466
467         splash((void *)datatoc_splash_jpg, datatoc_splash_jpg_size, string);
468 }
469
470
471 /* Functions for user preferences fileselect windows */
472
473 /* yafray: export dir select */
474 static void filesel_u_yfexportdir(char *name)
475 {
476         char dir[FILE_MAXDIR], file[FILE_MAXFILE];
477
478         BLI_cleanup_dir(G.sce, name);
479         BLI_split_dirfile(name, dir, file);
480
481         strcpy(U.yfexportdir, dir);
482         allqueue(REDRAWALL, 0);
483 }
484
485 static void filesel_u_fontdir(char *name)
486 {
487         char dir[FILE_MAXDIR], file[FILE_MAXFILE];
488         
489         BLI_cleanup_dir(G.sce, name);
490         BLI_split_dirfile(name, dir, file);
491
492         strcpy(U.fontdir, dir);
493         allqueue(REDRAWALL, 0);
494 }
495
496 static void filesel_u_textudir(char *name)
497 {
498         char dir[FILE_MAXDIR], file[FILE_MAXFILE];
499
500         BLI_cleanup_dir(G.sce, name);
501         BLI_split_dirfile(name, dir, file);
502
503         strcpy(U.textudir, dir);
504         allqueue(REDRAWALL, 0);
505 }
506
507 static void filesel_u_plugtexdir(char *name)
508 {
509         char dir[FILE_MAXDIR], file[FILE_MAXFILE];
510
511         BLI_cleanup_dir(G.sce, name);
512         BLI_split_dirfile(name, dir, file);
513
514         strcpy(U.plugtexdir, dir);
515         allqueue(REDRAWALL, 0);
516 }
517
518 static void filesel_u_plugseqdir(char *name)
519 {
520         char dir[FILE_MAXDIR], file[FILE_MAXFILE];
521
522         BLI_cleanup_dir(G.sce, name);
523         BLI_split_dirfile(name, dir, file);
524
525         strcpy(U.plugseqdir, dir);
526         allqueue(REDRAWALL, 0);
527 }
528
529 static void filesel_u_renderdir(char *name)
530 {
531         char dir[FILE_MAXDIR], file[FILE_MAXFILE];
532
533         BLI_cleanup_dir(G.sce, name);
534         BLI_split_dirfile(name, dir, file);
535
536         strcpy(U.renderdir, dir);
537         allqueue(REDRAWALL, 0);
538 }
539
540 static void filesel_u_pythondir(char *name)
541 {
542         char dir[FILE_MAXDIR], file[FILE_MAXFILE];
543
544         BLI_cleanup_dir(G.sce, name);
545         BLI_split_dirfile(name, dir, file);
546
547         strcpy(U.pythondir, dir);
548         allqueue(REDRAWALL, 0);
549 }
550
551 static void filesel_u_sounddir(char *name)
552 {
553         char dir[FILE_MAXDIR], file[FILE_MAXFILE];
554
555         BLI_cleanup_dir(G.sce, name);
556         BLI_split_dirfile(name, dir, file);
557
558         strcpy(U.sounddir, dir);
559         allqueue(REDRAWALL, 0);
560 }
561
562 static void filesel_u_tempdir(char *name)
563 {
564         char dir[FILE_MAXDIR], file[FILE_MAXFILE];
565
566         BLI_cleanup_dir(G.sce, name);
567         BLI_split_dirfile(name, dir, file);
568
569         strcpy(U.tempdir, dir);
570         allqueue(REDRAWALL, 0);
571 }
572
573 /* END Functions for user preferences fileselect windows */
574
575
576 void do_global_buttons(unsigned short event)
577 {
578         ListBase *lb;
579         Object *ob;
580         Material *ma;
581         MTex *mtex;
582         Ipo *ipo;
583         Lamp *la;
584         World *wrld;
585         bAction *act;
586         ID *id, *idtest, *from=NULL;
587         ScrArea *sa;
588         Brush *br;
589         int nr= 1;
590         char buf[FILE_MAX];
591
592         ob= OBACT;
593
594         id= NULL;       /* id at null for texbrowse */
595
596
597         switch(event) {
598         
599         case B_NEWFRAME:
600                 scrarea_queue_winredraw(curarea);
601                 scrarea_queue_headredraw(curarea);
602
603                 update_for_newframe();
604                 break;          
605         case B_REDR:
606                 scrarea_queue_winredraw(curarea);
607                 scrarea_queue_headredraw(curarea);
608                 break;
609         case B_REDRCURW3D:
610                 allqueue(REDRAWVIEW3D, 0);
611                 scrarea_queue_winredraw(curarea);
612                 scrarea_queue_headredraw(curarea);
613                 break;
614         case B_EDITBROWSE:
615                 if(ob==NULL) return;
616                 if(ob->id.lib) return;
617                 id= ob->data;
618                 if(id==NULL) return;
619
620                 if(G.buts->menunr== -2) {
621                         activate_databrowse((ID *)G.buts->lockpoin, GS(id->name), 0, B_EDITBROWSE, &G.buts->menunr, do_global_buttons);
622                         return;
623                 }
624                 if(G.buts->menunr < 0) return;
625                 
626                 lb= wich_libbase(G.main, GS(id->name));
627                 idtest= lb->first;
628                 while(idtest) {
629                         if(nr==G.buts->menunr) {
630                                 if(idtest!=id) {
631                                         id->us--;
632                                         id_us_plus(idtest);
633                                         
634                                         ob->data= idtest;
635                                         
636                                         test_object_materials(idtest);
637                                         
638                                         if( GS(idtest->name)==ID_CU ) {
639                                                 test_curve_type(ob);
640                                         }
641                                         else if( ob->type==OB_ARMATURE) {
642                                                 armature_rebuild_pose(ob, ob->data);
643                                         }
644                                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
645                                         
646                                         allqueue(REDRAWBUTSEDIT, 0);
647                                         allqueue(REDRAWVIEW3D, 0);
648                                         allqueue(REDRAWACTION,0);
649                                         allqueue(REDRAWIPO, 0);
650                                         allqueue(REDRAWNLA,0);
651                                 }
652                                 break;
653                         }
654                         nr++;
655                         idtest= idtest->next;
656                 }
657
658                 break;
659         case B_MESHBROWSE:
660                 if(ob==0) return;
661                 if(ob->id.lib) return;
662                 
663                 id= ob->data;
664                 if(id==0) id= G.main->mesh.first;
665                 if(id==0) return;
666                 
667                 if(G.buts->menunr== -2) {
668                         activate_databrowse((ID *)G.buts->lockpoin, GS(id->name), 0, B_MESHBROWSE, &G.buts->menunr, do_global_buttons);
669                         return;
670                 }
671                 if(G.buts->menunr < 0) return;
672                 
673
674                 idtest= G.main->mesh.first;
675                 while(idtest) {
676                         if(nr==G.buts->menunr) {
677                                 set_mesh(ob, (Mesh *)idtest);
678                                 
679                                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
680                                         
681                                 BIF_undo_push("Browse Mesh");
682                                 allqueue(REDRAWBUTSEDIT, 0);
683                                 allqueue(REDRAWVIEW3D, 0);
684                                 allqueue(REDRAWACTION,0);
685                                 allqueue(REDRAWIPO, 0);
686
687                                 break;
688                         }
689                         nr++;
690                         idtest= idtest->next;
691                 }
692
693                 break;
694         case B_MATBROWSE:
695         {
696                 void *lockpoin= NULL;
697                 short *menunr= 0;
698                 
699                 /* this is called now from Node editor too, buttons might not exist */
700                 if(curarea->spacetype==SPACE_NODE) {
701                         SpaceNode *snode= curarea->spacedata.first;
702                         menunr= &snode->menunr;
703                         lockpoin= snode->id;
704                 }
705                 else if(G.buts) {
706                         menunr= &G.buts->menunr;
707                         lockpoin= G.buts->lockpoin;
708                 }
709                 else return;
710                 
711                 if(*menunr== -2) {
712                         if(G.qual & LR_CTRLKEY) {
713                                 activate_databrowse_imasel((ID *)lockpoin, ID_MA, 0, B_MATBROWSE, menunr, do_global_buttons);
714                         }
715                         else {
716                                 activate_databrowse((ID *)lockpoin, ID_MA, 0, B_MATBROWSE, menunr, do_global_buttons);
717                         }
718                         return;
719                 }
720                 
721                 if(*menunr < 0) return;
722                 
723                 if(0) { /* future pin */
724                         
725                 }
726                 else {
727                         
728                         ma= give_current_material(ob, ob->actcol);
729                         nr= 1;
730                         
731                         id= (ID *)ma;
732                         
733                         idtest= G.main->mat.first;
734                         while(idtest) {
735                                 if(nr== *menunr) {
736                                         break;
737                                 }
738                                 nr++;
739                                 idtest= idtest->next;
740                         }
741                         if(idtest==0) { /* new mat */
742                                 if(id)  idtest= (ID *)copy_material((Material *)id);
743                                 else {
744                                         idtest= (ID *)add_material("Material");
745                                 }
746                                 idtest->us--;
747                         }
748                         if(idtest!=id) {
749                                 assign_material(ob, (Material *)idtest, ob->actcol);
750                                 
751                                 BIF_undo_push("Browse Material");
752                                 allqueue(REDRAWBUTSSHADING, 0);
753                                 allqueue(REDRAWIPO, 0);
754                                 allqueue(REDRAWNODE, 0);
755                                 BIF_preview_changed(ID_MA);
756                         }
757                         
758                 }
759         }
760                 break;
761         case B_MATDELETE:
762                 if(0) { /* future pin */
763                         
764                 }
765                 else {
766                         ma= give_current_material(ob, ob->actcol);
767                         if(ma) {
768                                 assign_material(ob, 0, ob->actcol);
769                                 BIF_undo_push("Unlink Material");
770                                 allqueue(REDRAWBUTSSHADING, 0);
771                                 allqueue(REDRAWIPO, 0);
772                                 allqueue(REDRAWOOPS, 0);
773                                 allqueue(REDRAWVIEW3D, 0);
774                                 BIF_preview_changed(ID_MA);
775                         }
776                 }
777                 break;
778         case B_TEXDELETE:
779                 if(G.buts->pin) {
780                         
781                 }
782                 else {
783                         if(G.buts->texfrom==0) {        /* from mat */
784                                 ma= give_current_material(ob, ob->actcol);
785                                 ma= editnode_get_active_material(ma);
786                                 if(ma) {
787                                         mtex= ma->mtex[ ma->texact ];
788                                         if(mtex) {
789                                                 if(mtex->tex) mtex->tex->id.us--;
790                                                 MEM_freeN(mtex);
791                                                 ma->mtex[ ma->texact ]= NULL;
792                                                 allqueue(REDRAWBUTSSHADING, 0);
793                                                 allqueue(REDRAWIPO, 0);
794                                                 BIF_preview_changed(ID_MA);
795                                         }
796                                 }
797                         }
798                         else if(G.buts->texfrom==1) { /* from world */
799                                 wrld= G.scene->world;
800                                 if(wrld) {
801                                         mtex= wrld->mtex[ wrld->texact ];
802                                         if(mtex) {
803                                                 if(mtex->tex) mtex->tex->id.us--;
804                                                 MEM_freeN(mtex);
805                                                 wrld->mtex[ wrld->texact ]= NULL;
806                                                 allqueue(REDRAWBUTSSHADING, 0);
807                                                 allqueue(REDRAWIPO, 0);
808                                                 BIF_preview_changed(ID_WO);
809                                         }
810                                 }
811                         }
812                         else if(G.buts->texfrom==2) {   /* from lamp */
813                                 la= ob->data;
814                                 if(la && ob->type==OB_LAMP) { /* to be sure */
815                                         mtex= la->mtex[ la->texact ];
816                                         if(mtex) {
817                                                 if(mtex->tex) mtex->tex->id.us--;
818                                                 MEM_freeN(mtex);
819                                                 la->mtex[ la->texact ]= NULL;
820                                                 allqueue(REDRAWBUTSSHADING, 0);
821                                                 allqueue(REDRAWIPO, 0);
822                                                 BIF_preview_changed(ID_LA);
823                                         }
824                                 }
825                         }
826                         else {  /* from brush */
827                                 br= G.scene->toolsettings->imapaint.brush;
828                                 if(G.f & G_SCULPTMODE) {
829                                         sculptmode_rem_tex(NULL, NULL);
830                                         allqueue(REDRAWBUTSSHADING, 0);
831                                 } else if(br) {
832                                         mtex= br->mtex[ br->texact ];
833                                         if(mtex) {
834                                                 if(mtex->tex) mtex->tex->id.us--;
835                                                 MEM_freeN(mtex);
836                                                 br->mtex[ br->texact ]= NULL;
837                                                 allqueue(REDRAWBUTSSHADING, 0);
838                                                 allqueue(REDRAWIMAGE, 0);
839                                                 allqueue(REDRAWIPO, 0);
840                                                 /*BIF_preview_changed(ID_BR);*/
841                                         }
842                                 }
843                         }
844                         BIF_undo_push("Unlink Texture");
845                 }
846                 break;
847         case B_EXTEXBROWSE: 
848         case B_TEXBROWSE:
849
850                 if(G.buts->texnr== -2) {
851                         
852                         id= G.buts->lockpoin;
853                         if(event==B_EXTEXBROWSE) {
854                                 id= NULL;
855                                 ma= give_current_material(ob, ob->actcol);
856                                 ma= editnode_get_active_material(ma);
857                                 if(ma) {
858                                         mtex= ma->mtex[ ma->texact ];
859                                         if(mtex) id= (ID *)mtex->tex;
860                                 }
861                         }
862                         
863                         activate_databrowse(id, ID_TE, 0, B_TEXBROWSE, &G.buts->texnr, do_global_buttons);
864                         return;
865                 }
866                 if(G.buts->texnr < 0) break;
867                 
868                 if(G.buts->pin) {
869                         
870                 }
871                 else {
872                         id= NULL;
873                         
874                         ma= give_current_material(ob, ob->actcol);
875                         ma= editnode_get_active_material(ma);
876                         if(ma) {
877                                 mtex= ma->mtex[ ma->texact ];
878                                 if(mtex) id= (ID *)mtex->tex;
879                         }
880
881                         idtest= G.main->tex.first;
882                         while(idtest) {
883                                 if(nr==G.buts->texnr) {
884                                         break;
885                                 }
886                                 nr++;
887                                 idtest= idtest->next;
888                         }
889                         if(idtest==0) { /* new tex */
890                                 if(id)  idtest= (ID *)copy_texture((Tex *)id);
891                                 else idtest= (ID *)add_texture("Tex");
892                                 idtest->us--;
893                         }
894                         if(idtest!=id && ma) {
895                                 
896                                 if( ma->mtex[ma->texact]==0) ma->mtex[ma->texact]= add_mtex();
897                                 
898                                 ma->mtex[ ma->texact ]->tex= (Tex *)idtest;
899                                 id_us_plus(idtest);
900                                 if(id) id->us--;
901                                 
902                                 BIF_undo_push("Browse Texture");
903                                 allqueue(REDRAWBUTSSHADING, 0);
904                                 allqueue(REDRAWIPO, 0);
905                                 allqueue(REDRAWOOPS, 0);
906                                 BIF_preview_changed(ID_MA);
907                         }
908                 }
909                 break;
910         case B_ACTIONDELETE:
911                 act=ob->action;
912                 
913                 if (act)
914                         act->id.us--;
915                 ob->action=NULL;
916                 if(ob->pose) {          // clear flag, also used for draw colors
917                         bPoseChannel *pchan;
918                         for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next)
919                                 pchan->flag= 0;
920                 }
921                 BIF_undo_push("Unlink Action");
922                 
923                 allqueue(REDRAWVIEW3D, 0);
924                 allqueue(REDRAWACTION, 0);
925                 allqueue(REDRAWNLA, 0);
926                 allqueue(REDRAWIPO, 0);
927                 break;
928         case B_ACTIONBROWSE:
929                 if (!ob)
930                         break;
931                 act=ob->action;
932                 id= (ID *)act;
933
934                 if (G.saction->actnr== -2){
935                                 activate_databrowse((ID *)G.saction->action, ID_AC,  0, B_ACTIONBROWSE, &G.saction->actnr, do_global_buttons);
936                         return;
937                 }
938
939                 if(G.saction->actnr < 0) break;
940
941                 /*      See if we have selected a valid action */
942                 for (idtest= G.main->action.first; idtest; idtest= idtest->next) {
943                                 if(nr==G.saction->actnr) {
944                                         break;
945                                 }
946                                 nr++;
947                         
948                 }
949
950                 if(G.saction->pin) {
951                         G.saction->action= (bAction *)idtest;
952                         allqueue(REDRAWACTION, 0);
953                 }
954                 else {
955
956                         /* Store current action */
957                         if (!idtest) {
958                                 /* 'Add New' option: 
959                                  *      - make a copy of an exisiting action
960                                  *      - or make a new empty action if no existing action
961                                  */
962                                 if (act) {
963                                         idtest= (ID *)copy_action(act);
964                                 } 
965                                 else { 
966                                         if (ID_OB==ob->type) {
967                                                 /* for empties */
968                                                 idtest=(ID *)add_empty_action("ObAction");
969                                         } 
970                                         else if (ELEM(ob->type, OB_MESH, OB_LATTICE) && ob_get_key(ob)) {
971                                                 /* shapekey - like if B_IPO_ACTION_KEY is triggered */
972                                                 bActionChannel *achan;
973                                                 Key *key= ob_get_key(ob);
974                                                 
975                                                 ob->ipoflag |= OB_ACTION_KEY;
976                                                 
977                                                 act = add_empty_action("ShapeAction");
978                                                 idtest=(ID *)act;
979                                                 
980                                                 achan= verify_action_channel(act, "Shape");
981                                                 achan->flag = (ACHAN_HILIGHTED|ACHAN_SELECTED|ACHAN_EXPANDED|ACHAN_SHOWIPO);
982                                                 
983                                                 if(achan->ipo==NULL && key->ipo) {
984                                                         achan->ipo= key->ipo;
985                                                         key->ipo= NULL;
986                                                         
987                                                         allqueue(REDRAWVIEW3D, 0);
988                                                         allqueue(REDRAWIPO, 0);
989                                                         allqueue(REDRAWOOPS, 0);
990                                                 }
991                                         }
992                                         else {
993                                                 /* a plain action */
994                                                 idtest=(ID *)add_empty_action("Action");
995                                         }
996                                 }
997                                 idtest->us--;
998                         }
999                         
1000                         
1001                         if(idtest!=id && ob) {
1002                                 act= (bAction *)idtest;
1003                                 
1004                                 ob->action= act;
1005                                 id_us_plus(idtest);
1006                                 
1007                                 if(id) id->us--;
1008                                 
1009                                 // Update everything
1010                                 BIF_undo_push("Browse Action");
1011                                 do_global_buttons (B_NEWFRAME);
1012                                 allqueue(REDRAWVIEW3D, 0);
1013                                 allqueue(REDRAWNLA, 0);
1014                                 allqueue(REDRAWACTION, 0);
1015                                 allqueue(REDRAWHEADERS, 0); 
1016                         }
1017                 }
1018                 
1019                 break;
1020         case B_IPOBROWSE:
1021
1022                 ipo= G.sipo->ipo;
1023                 from= G.sipo->from;
1024                 id= (ID *)ipo;
1025                 if(from==NULL) return;
1026
1027                 if(G.sipo->menunr== -2) {
1028                         activate_databrowse((ID *)G.sipo->ipo, ID_IP, G.sipo->blocktype, B_IPOBROWSE, &G.sipo->menunr, do_global_buttons);
1029                         return;
1030                 }
1031
1032                 if(G.sipo->menunr < 0) break;
1033
1034                 idtest= G.main->ipo.first;
1035                 while(idtest) {
1036                         if( ((Ipo *)idtest)->blocktype == G.sipo->blocktype) {
1037                                 if(nr==G.sipo->menunr) {
1038                                         break;
1039                                 }
1040                                 nr++;
1041                         }
1042                         idtest= idtest->next;
1043                 }
1044
1045                 if(G.sipo->pin) {
1046                         if(idtest) {
1047                                 G.sipo->ipo= (Ipo *)idtest;
1048                                 allspace(REMAKEIPO, 0);         // in fact it should only do this one, but there is no function for it
1049                         }
1050                 }
1051                 else {
1052                         // assign the ipo to ...
1053
1054                         if(idtest==0) {
1055                                 if(ipo) idtest= (ID *)copy_ipo(ipo);
1056                                 else {
1057                                         nr= G.sipo->blocktype;
1058                                         if(nr==ID_OB) idtest= (ID *)add_ipo("ObIpo", ID_OB);
1059                                         else if(nr==ID_CO) idtest= (ID *)add_ipo("CoIpo", ID_CO);
1060                                         else if(nr==ID_PO) idtest= (ID *)add_ipo("ActIpo", nr);
1061                                         else if(nr==ID_MA) idtest= (ID *)add_ipo("MatIpo", nr);
1062                                         else if(nr==ID_TE) idtest= (ID *)add_ipo("TexIpo", nr);
1063                                         else if(nr==ID_SEQ) idtest= (ID *)add_ipo("MatSeq", nr);
1064                                         else if(nr==ID_CU) idtest= (ID *)add_ipo("CuIpo", nr);
1065                                         else if(nr==ID_KE) idtest= (ID *)add_ipo("KeyIpo", nr);
1066                                         else if(nr==ID_WO) idtest= (ID *)add_ipo("WoIpo", nr);
1067                                         else if(nr==ID_LA) idtest= (ID *)add_ipo("LaIpo", nr);
1068                                         else if(nr==ID_CA) idtest= (ID *)add_ipo("CaIpo", nr);
1069                                         else if(nr==ID_SO) idtest= (ID *)add_ipo("SndIpo", nr);
1070                                         else if(nr==ID_FLUIDSIM) idtest= (ID *)add_ipo("FluidsimIpo", nr);
1071                                         else error("Warn bugtracker!");
1072                                 }
1073                                 idtest->us--;
1074                         }
1075                         if(idtest!=id && from) {
1076                                 spaceipo_assign_ipo(G.sipo, (Ipo *)idtest);
1077                                                                         
1078                                 BIF_undo_push("Browse Ipo");
1079                         }
1080                 }
1081                 break;
1082         case B_IPODELETE:
1083                 ipo= G.sipo->ipo;
1084                 from= G.sipo->from;
1085                 
1086                 spaceipo_assign_ipo(G.sipo, NULL);
1087                 
1088                 editipo_changed(G.sipo, 1); /* doredraw */
1089                 
1090                 BIF_undo_push("Unlink Ipo");
1091                 
1092                 break;
1093         case B_WORLDBROWSE:
1094
1095                 if(G.buts->menunr==-2) {
1096                         activate_databrowse((ID *)G.scene->world, ID_WO, 0, B_WORLDBROWSE, &G.buts->menunr, do_global_buttons);
1097                         break;
1098                 }
1099
1100                 if(G.buts->menunr < 0) break;
1101                 /* no lock */
1102                         
1103                 wrld= G.scene->world;
1104                 nr= 1;
1105                 
1106                 id= (ID *)wrld;
1107                 
1108                 idtest= G.main->world.first;
1109                 while(idtest) {
1110                         if(nr==G.buts->menunr) {
1111                                 break;
1112                         }
1113                         nr++;
1114                         idtest= idtest->next;
1115                 }
1116                 if(idtest==0) { /* new world */
1117                         if(id) idtest= (ID *)copy_world((World *)id);
1118                         else idtest= (ID *)add_world("World");
1119                         idtest->us--;
1120                 }
1121                 if(idtest!=id) {
1122                         G.scene->world= (World *)idtest;
1123                         id_us_plus(idtest);
1124                         if(id) id->us--;
1125                         
1126                         BIF_undo_push("Browse World");
1127                         allqueue(REDRAWBUTSSHADING, 0);
1128                         allqueue(REDRAWIPO, 0);
1129                         allqueue(REDRAWOOPS, 0);
1130                         BIF_preview_changed(ID_WO);
1131                 }
1132                 break;
1133         case B_WORLDDELETE:
1134                 if(G.scene->world) {
1135                         G.scene->world->id.us--;
1136                         G.scene->world= NULL;
1137
1138                         BIF_undo_push("Unlink World");
1139                         allqueue(REDRAWBUTSSHADING, 0);
1140                         allqueue(REDRAWIPO, 0);
1141                 }
1142                 
1143                 break;
1144         case B_WTEXBROWSE:
1145
1146                 if(G.buts->texnr== -2) {
1147                         id= NULL;
1148                         wrld= G.scene->world;
1149                         if(wrld) {
1150                                 mtex= wrld->mtex[ wrld->texact ];
1151                                 if(mtex) id= (ID *)mtex->tex;
1152                         }
1153
1154                         activate_databrowse((ID *)id, ID_TE, 0, B_WTEXBROWSE, &G.buts->texnr, do_global_buttons);
1155                         return;
1156                 }
1157                 if(G.buts->texnr < 0) break;
1158
1159                 if(G.buts->pin) {
1160                         
1161                 }
1162                 else {
1163                         id= NULL;
1164                         
1165                         wrld= G.scene->world;
1166                         if(wrld) {
1167                                 mtex= wrld->mtex[ wrld->texact ];
1168                                 if(mtex) id= (ID *)mtex->tex;
1169                         }
1170
1171                         idtest= G.main->tex.first;
1172                         while(idtest) {
1173                                 if(nr==G.buts->texnr) {
1174                                         break;
1175                                 }
1176                                 nr++;
1177                                 idtest= idtest->next;
1178                         }
1179                         if(idtest==0) { /* new tex */
1180                                 if(id)  idtest= (ID *)copy_texture((Tex *)id);
1181                                 else idtest= (ID *)add_texture("Tex");
1182                                 idtest->us--;
1183                         }
1184                         if(idtest!=id && wrld) {
1185                                 
1186                                 if( wrld->mtex[wrld->texact]==0) {
1187                                         wrld->mtex[wrld->texact]= add_mtex();
1188                                         wrld->mtex[wrld->texact]->texco= TEXCO_VIEW;
1189                                 }
1190                                 wrld->mtex[ wrld->texact ]->tex= (Tex *)idtest;
1191                                 id_us_plus(idtest);
1192                                 if(id) id->us--;
1193                                 
1194                                 BIF_undo_push("Texture browse");
1195                                 allqueue(REDRAWBUTSSHADING, 0);
1196                                 allqueue(REDRAWIPO, 0);
1197                                 allqueue(REDRAWOOPS, 0);
1198                                 BIF_preview_changed(ID_WO);
1199                         }
1200                 }
1201                 break;
1202         case B_LAMPBROWSE:
1203                 /* no lock */
1204                 if(ob==0) return;
1205                 if(ob->type!=OB_LAMP) return;
1206
1207                 if(G.buts->menunr== -2) {
1208                         activate_databrowse((ID *)G.buts->lockpoin, ID_LA, 0, B_LAMPBROWSE, &G.buts->menunr, do_global_buttons);
1209                         return;
1210                 }
1211                 if(G.buts->menunr < 0) break;
1212                 
1213                 la= ob->data;
1214                 nr= 1;
1215                 id= (ID *)la;
1216                 
1217                 idtest= G.main->lamp.first;
1218                 while(idtest) {
1219                         if(nr==G.buts->menunr) {
1220                                 break;
1221                         }
1222                         nr++;
1223                         idtest= idtest->next;
1224                 }
1225                 if(idtest==0) { /* no new lamp */
1226                         return;
1227                 }
1228                 if(idtest!=id) {
1229                         ob->data= (Lamp *)idtest;
1230                         id_us_plus(idtest);
1231                         if(id) id->us--;
1232                         
1233                         BIF_undo_push("Lamp browse");
1234                         allqueue(REDRAWBUTSSHADING, 0);
1235                         allqueue(REDRAWVIEW3D, 0);
1236                         allqueue(REDRAWIPO, 0);
1237                         allqueue(REDRAWOOPS, 0);
1238                         BIF_preview_changed(ID_LA);
1239                 }
1240                 break;
1241         
1242         case B_LTEXBROWSE:
1243
1244                 if(ob==0) return;
1245                 if(ob->type!=OB_LAMP) return;
1246
1247                 if(G.buts->texnr== -2) {
1248                         id= NULL;
1249                         la= ob->data;
1250                         mtex= la->mtex[ la->texact ];
1251                         if(mtex) id= (ID *)mtex->tex;
1252
1253                         activate_databrowse(id, ID_TE, 0, B_LTEXBROWSE, &G.buts->texnr, do_global_buttons);
1254                         return;
1255                 }
1256                 if(G.buts->texnr < 0) break;
1257
1258                 if(G.buts->pin) {
1259                         
1260                 }
1261                 else {
1262                         id= NULL;
1263                         
1264                         la= ob->data;
1265                         mtex= la->mtex[ la->texact ];
1266                         if(mtex) id= (ID *)mtex->tex;
1267
1268                         idtest= G.main->tex.first;
1269                         while(idtest) {
1270                                 if(nr==G.buts->texnr) {
1271                                         break;
1272                                 }
1273                                 nr++;
1274                                 idtest= idtest->next;
1275                         }
1276                         if(idtest==0) { /* new tex */
1277                                 if(id)  idtest= (ID *)copy_texture((Tex *)id);
1278                                 else idtest= (ID *)add_texture("Tex");
1279                                 idtest->us--;
1280                         }
1281                         if(idtest!=id && la) {
1282                                 
1283                                 if( la->mtex[la->texact]==0) {
1284                                         la->mtex[la->texact]= add_mtex();
1285                                         la->mtex[la->texact]->texco= TEXCO_GLOB;
1286                                 }
1287                                 la->mtex[ la->texact ]->tex= (Tex *)idtest;
1288                                 id_us_plus(idtest);
1289                                 if(id) id->us--;
1290                                 
1291                                 BIF_undo_push("Texture Browse");
1292                                 allqueue(REDRAWBUTSSHADING, 0);
1293                                 allqueue(REDRAWIPO, 0);
1294                                 allqueue(REDRAWOOPS, 0);
1295                                 BIF_preview_changed(ID_LA);
1296                         }
1297                 }
1298                 break;
1299
1300         case B_IMAGEDELETE:
1301                 if(G.sima->image && (G.sima->image->type == IMA_TYPE_R_RESULT || G.sima->image->type == IMA_TYPE_COMPOSITE)) {
1302                         /* Run if G.sima is render, remove the render and display the meshes image if it exists */
1303                         G.sima->image= NULL;
1304                         what_image(G.sima);
1305                         allqueue(REDRAWIMAGE, 0);
1306                 } else {
1307                         /* Run on non render images, unlink normally */
1308                         image_changed(G.sima, NULL);
1309                         BIF_undo_push("Unlink Image");
1310                         allqueue(REDRAWIMAGE, 0);
1311                 }
1312                 break;
1313         
1314         case B_AUTOMATNAME:
1315                 /* this is called now from Node editor too, buttons might not exist */
1316                 if(curarea->spacetype==SPACE_NODE) {
1317                         SpaceNode *snode= curarea->spacedata.first;
1318                         automatname((Material *)snode->id);
1319                 }
1320                 else if(G.buts) {
1321                         automatname(G.buts->lockpoin);
1322                 }
1323                 else return;
1324
1325                 BIF_undo_push("Auto name");
1326                 allqueue(REDRAWBUTSSHADING, 0);
1327                 allqueue(REDRAWNODE, 0);
1328                 allqueue(REDRAWOOPS, 0);
1329                 break;          
1330         case B_AUTOTEXNAME:
1331                 if(G.buts->mainb==CONTEXT_SHADING) {
1332                         if(G.buts->tab[CONTEXT_SHADING]==TAB_SHADING_TEX) {
1333                                 autotexname(G.buts->lockpoin);
1334                         }
1335                         else if(G.buts->tab[CONTEXT_SHADING]==TAB_SHADING_MAT) {
1336                                 ma= G.buts->lockpoin;
1337                                 if(ma->mtex[ ma->texact]) autotexname(ma->mtex[ma->texact]->tex);
1338                         }
1339                         else if(G.buts->tab[CONTEXT_SHADING]==TAB_SHADING_WORLD) {
1340                                 wrld= G.buts->lockpoin;
1341                                 if(wrld->mtex[ wrld->texact]) autotexname(wrld->mtex[wrld->texact]->tex);
1342                         }
1343                         else if(G.buts->tab[CONTEXT_SHADING]==TAB_SHADING_LAMP) {
1344                                 la= G.buts->lockpoin;
1345                                 if(la->mtex[ la->texact]) autotexname(la->mtex[la->texact]->tex);
1346                         }
1347                         BIF_undo_push("Auto name");
1348                         allqueue(REDRAWBUTSSHADING, 0);
1349                         allqueue(REDRAWOOPS, 0);
1350                         allqueue(REDRAWIMAGE, 0);
1351                 }
1352                 else if(G.buts->mainb==CONTEXT_EDITING) {
1353                         SculptData *sd= &G.scene->sculptdata;
1354                         if(sd && sd->texact != -1) {
1355                                 if(sd->mtex[sd->texact]) autotexname(sd->mtex[sd->texact]->tex);
1356
1357                                 BIF_undo_push("Auto name");
1358                                 allqueue(REDRAWBUTSEDIT, 0);
1359                                 allqueue(REDRAWOOPS, 0);
1360                         }
1361                 }
1362                 break;
1363
1364         case B_RESETAUTOSAVE:
1365                 reset_autosave();
1366                 allqueue(REDRAWINFO, 0);
1367                 break;
1368         case B_SOUNDTOGGLE:
1369                 SYS_WriteCommandLineInt(SYS_GetSystem(), "noaudio", (U.gameflags & USER_DISABLE_SOUND));
1370                 break;
1371         case B_SHOWSPLASH:
1372                                 show_splash();
1373                 break;
1374         case B_MIPMAPCHANGED:
1375                 set_mipmap(!(U.gameflags & USER_DISABLE_MIPMAP));
1376                 allqueue(REDRAWVIEW3D, 0);
1377                 break;
1378         case B_GLRESLIMITCHANGED:
1379                 free_all_realtime_images(); /* force reloading with new res limit */
1380                 allqueue(REDRAWVIEW3D, 0);
1381                 break;
1382         case B_NEWSPACE:
1383                 newspace(curarea, curarea->butspacetype);
1384                 break;
1385         case B_LOADTEMP:        /* is button from space.c */
1386                 BIF_read_autosavefile();
1387                 break;
1388
1389         case B_USERPREF:
1390                 allqueue(REDRAWINFO, 0);
1391                 break;
1392
1393         case B_DRAWINFO:        /* is button from space.c  *info* */
1394                 allqueue(REDRAWVIEW3D, 0);
1395                 break;
1396
1397         case B_PLAINMENUS:     /* is button from space.c  *info* */
1398                 reset_toolbox();
1399                 break;
1400
1401         case B_FLIPINFOMENU:    /* is button from space.c  *info* */
1402                 scrarea_queue_headredraw(curarea);
1403                 break;
1404
1405 #if 0
1406 //#ifdef _WIN32 // FULLSCREEN
1407         case B_FLIPFULLSCREEN:
1408                 if(U.uiflag & USER_FLIPFULLSCREEN)
1409                         U.uiflag &= ~USER_FLIPFULLSCREEN;
1410                 else
1411                         U.uiflag |= USER_FLIPFULLSCREEN;
1412                 mainwindow_toggle_fullscreen((U.uiflag & USER_FLIPFULLSCREEN));
1413                 break;
1414 #endif
1415
1416         /* Fileselect windows for user preferences file paths */
1417
1418         /* yafray: xml export dir. select */
1419         case B_YAFRAYDIRFILESEL:        /* space.c */
1420                 if(curarea->spacetype==SPACE_INFO) {
1421                         sa= closest_bigger_area();
1422                         areawinset(sa->win);
1423                 }
1424
1425                 activate_fileselect(FILE_SPECIAL, "SELECT YFEXPORT PATH", U.yfexportdir, filesel_u_yfexportdir);
1426                 break;
1427
1428         case B_FONTDIRFILESEL:  /* is button from space.c  *info* */
1429                 if(curarea->spacetype==SPACE_INFO) {
1430                         sa= closest_bigger_area();
1431                         areawinset(sa->win);
1432                 }
1433
1434                 activate_fileselect(FILE_SPECIAL, "SELECT FONT PATH", U.fontdir, filesel_u_fontdir);
1435                 break;
1436
1437         case B_TEXTUDIRFILESEL:         /* is button from space.c  *info* */
1438                 if(curarea->spacetype==SPACE_INFO) {
1439                         sa= closest_bigger_area();
1440                         areawinset(sa->win);
1441                 }
1442
1443                 activate_fileselect(FILE_SPECIAL, "SELECT TEXTURE PATH", U.textudir, filesel_u_textudir);
1444                 break;
1445         
1446         case B_PLUGTEXDIRFILESEL:               /* is button form space.c  *info* */
1447                 if(curarea->spacetype==SPACE_INFO) {
1448                         sa= closest_bigger_area();
1449                         areawinset(sa->win);
1450                 }
1451
1452                 activate_fileselect(FILE_SPECIAL, "SELECT TEX PLUGIN PATH", U.plugtexdir, filesel_u_plugtexdir);
1453                 break;
1454         
1455         case B_PLUGSEQDIRFILESEL:               /* is button from space.c  *info* */
1456                 if(curarea->spacetype==SPACE_INFO) {
1457                         sa= closest_bigger_area();
1458                         areawinset(sa->win);
1459                 }
1460
1461                 activate_fileselect(FILE_SPECIAL, "SELECT SEQ PLUGIN PATH", U.plugseqdir, filesel_u_plugseqdir);
1462                 break;
1463         
1464         case B_RENDERDIRFILESEL:        /* is button from space.c  *info* */
1465                 if(curarea->spacetype==SPACE_INFO) {
1466                         sa= closest_bigger_area();
1467                         areawinset(sa->win);
1468                 }
1469
1470                 activate_fileselect(FILE_SPECIAL, "SELECT RENDER PATH", U.renderdir, filesel_u_renderdir);
1471                 break;
1472
1473         case B_PYMENUEVAL: /* is button from space.c *info* */
1474                 waitcursor( 1 ); /* can take some time */
1475                 BPyMenu_RemoveAllEntries(); /* free old data */
1476                 if (BPyMenu_Init(1) == -1) { /* re-eval scripts registration in menus */
1477                         waitcursor( 0 );
1478                         error("Invalid scripts dir: check console");
1479                 }
1480                 waitcursor( 0 );
1481                 break;
1482         case B_PYTHONDIRFILESEL:        /* is button from space.c  *info* */
1483                 if(curarea->spacetype==SPACE_INFO) {
1484                         sa= closest_bigger_area();
1485                         areawinset(sa->win);
1486                 }
1487
1488                 activate_fileselect(FILE_SPECIAL, "SELECT SCRIPT PATH", U.pythondir, filesel_u_pythondir);
1489                 break;
1490
1491         case B_SOUNDDIRFILESEL:         /* is button from space.c  *info* */
1492                 if(curarea->spacetype==SPACE_INFO) {
1493                         sa= closest_bigger_area();
1494                         areawinset(sa->win);
1495                 }
1496
1497                 activate_fileselect(FILE_SPECIAL, "SELECT SOUND PATH", U.sounddir, filesel_u_sounddir);
1498                 break;
1499
1500         case B_TEMPDIRFILESEL:  /* is button from space.c  *info* */
1501                 if(curarea->spacetype==SPACE_INFO) {
1502                         sa= closest_bigger_area();
1503                         areawinset(sa->win);
1504                 }
1505
1506                 activate_fileselect(FILE_SPECIAL, "SELECT TEMP FILE PATH", U.tempdir, filesel_u_tempdir);
1507                 break;
1508
1509         /* END Fileselect windows for user preferences file paths */
1510
1511 #ifdef INTERNATIONAL
1512         case B_LOADUIFONT:      /* is button from space.c  *info* */
1513                 if(curarea->spacetype==SPACE_INFO) {
1514                         sa= closest_bigger_area();
1515                         areawinset(sa->win);
1516                 }
1517                 BLI_make_file_string("/", buf, U.fontdir, U.fontname);
1518                 activate_fileselect(FILE_SPECIAL, "LOAD UI FONT", buf, set_interface_font);
1519                 break;
1520
1521         case B_SETLANGUAGE:             /* is button from space.c  *info* */
1522                 lang_setlanguage();
1523                 allqueue(REDRAWALL, 0);
1524                 break;
1525
1526         case B_SETFONTSIZE:             /* is button from space.c  *info* */
1527                 refresh_interface_font();
1528                 FTF_SetSize(U.fontsize); 
1529                 allqueue(REDRAWALL, 0);
1530                 break;
1531                 
1532         case B_SETTRANSBUTS:    /* is button from space.c  *info* */
1533                 allqueue(REDRAWALL, 0);
1534                 break;
1535
1536         case B_RESTOREFONT:             /* is button from space.c  *info* */
1537                 U.fontsize= 0;
1538                 start_interface_font();
1539                 allqueue(REDRAWALL, 0);
1540                 break;
1541                 
1542         case B_USETEXTUREFONT:          /* is button from space.c  *info* */
1543                 refresh_interface_font();
1544                 allqueue(REDRAWALL, 0);
1545                 break;
1546
1547         case B_DOLANGUIFONT:    /* is button from space.c  *info* */
1548                 if(U.transopts & USER_DOTRANSLATE)
1549                         start_interface_font();
1550                 else
1551                         G.ui_international = FALSE;
1552                 allqueue(REDRAWALL, 0);
1553                 break;
1554 #endif
1555                 
1556         case B_FULL:
1557                 if(curarea->spacetype!=SPACE_INFO) {
1558                         area_fullscreen();
1559                 }
1560                 break;  
1561
1562         case B_IDNAME:
1563                         /* changing a metaballs name, sadly enough,
1564                          * can require it to be updated because its
1565                          * basis might have changed... -zr
1566                          */
1567                 if (ob && ob->type==OB_MBALL) {
1568                         DAG_scene_sort(G.scene);
1569                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1570                 }
1571                 /* redraw because name has changed: new pup */
1572                 scrarea_queue_headredraw(curarea);
1573                 allqueue(REDRAWINFO, 1);
1574                 allqueue(REDRAWOOPS, 1);
1575                 allqueue(REDRAWACTION, 1);
1576                 allqueue(REDRAWNLA, 1);
1577                 /* name scene also in set PUPmenu */
1578                 allqueue(REDRAWBUTSALL, 0);
1579                 allqueue(REDRAWIMAGE, 0);
1580                 allqueue(REDRAWHEADERS, 0);
1581                 break;
1582         
1583         case B_KEEPDATA:
1584                 /* keep datablock. similar to pressing FKEY in a fileselect window
1585                  * maybe we can move that stuff to a seperate function? -- sg
1586                  */
1587                 if (curarea->spacetype==SPACE_BUTS) {
1588                         id= (ID *)G.buts->lockpoin;
1589                 } else if(curarea->spacetype==SPACE_IPO) {
1590                         id = (ID *)G.sipo->ipo;
1591                 } else if(curarea->spacetype==SPACE_NODE) {
1592                         id = ((SpaceNode *)curarea->spacedata.first)->id;
1593                 } /* similar for other spacetypes ? */
1594                 if (id) {
1595                         if( id->flag & LIB_FAKEUSER) {
1596                                 id->flag -= LIB_FAKEUSER;
1597                                 id->us--;
1598                         } else {
1599                                 id->flag |= LIB_FAKEUSER;
1600                                 id->us++;
1601                         }
1602                 }
1603                 allqueue(REDRAWHEADERS, 0);
1604
1605                 break;
1606
1607         }
1608 }
1609
1610
1611 void do_global_buttons2(short event)
1612 {
1613         Base *base;
1614         Object *ob;
1615         Material *ma;
1616         MTex *mtex;
1617         Mesh *me;
1618         Curve *cu;
1619         MetaBall *mb;
1620         Ipo *ipo;
1621         Lamp *la;
1622         Lattice *lt;
1623         World *wrld;
1624         ID *idfrom; 
1625         bAction *act;
1626         Brush *br;
1627
1628         /* general:  Single User is allowed when from==LOCAL 
1629          *                       Make Local is allowed when (from==LOCAL && id==LIB)
1630          */
1631                 
1632         if(event<B_LOCAL_ALONE) return;
1633
1634         ob= OBACT;
1635
1636         switch(event) {
1637                 
1638         case B_LAMPALONE:
1639                 if(ob && ob->id.lib==0) {
1640                         la= ob->data;
1641                         if(la->id.us>1) {
1642                                 if(okee("Single user")) {
1643                                         ob->data= copy_lamp(la);
1644                                         la->id.us--;
1645                                 }
1646                         }
1647                 }
1648                 break;
1649         case B_LAMPLOCAL:
1650                 if(ob && ob->id.lib==0) {
1651                         la= ob->data;
1652                         if(la->id.lib) {
1653                                 if(okee("Make local")) {
1654                                         make_local_lamp(la);
1655                                 }
1656                         }
1657                 }
1658                 break;
1659         
1660         case B_ARMLOCAL:
1661                 if (ob&&ob->id.lib==0){
1662                         bArmature *arm=ob->data;
1663                         if (arm->id.lib){
1664                                 if(okee("Make local")) {
1665                                         make_local_armature(arm);
1666                                 }
1667                         }
1668                 }
1669                 break;
1670         case B_ARMALONE:
1671                 if(ob && ob->id.lib==0) {
1672                         bArmature *arm=ob->data;
1673                         if(arm->id.us>1) {
1674                                 if(okee("Single user")) {
1675                                         ob->data= copy_armature(arm);
1676                                         armature_rebuild_pose(ob, ob->data);
1677                                         arm->id.us--;
1678                                 }
1679                         }
1680                 }
1681                 break;
1682         case B_ACTLOCAL:
1683                 if(ob && ob->id.lib==0) {
1684                         act= ob->action;
1685                         if(act->id.lib) {
1686                                 if(okee("Make local")) {
1687                                         make_local_action(act);
1688                                         allqueue(REDRAWACTION,0);
1689                                 }
1690                         }
1691                 }
1692                 break;
1693         case B_ACTALONE:
1694                 if(ob && ob->id.lib==0) {
1695                         act= ob->action;
1696                 
1697                         if(act->id.us>1) {
1698                                 if(okee("Single user")) {
1699                                         ob->action=copy_action(act);
1700                                         act->id.us--;
1701                                         allqueue(REDRAWACTION, 0);
1702                                 }
1703                         }
1704                 }
1705                 break;
1706
1707         case B_CAMERAALONE:
1708                 if(ob && ob->id.lib==0) {
1709                         Camera *ca= ob->data;
1710                         if(ca->id.us>1) {
1711                                 if(okee("Single user")) {
1712                                         ob->data= copy_camera(ca);
1713                                         ca->id.us--;
1714                                 }
1715                         }
1716                 }
1717                 break;
1718         case B_CAMERALOCAL:
1719                 if(ob && ob->id.lib==0) {
1720                         Camera *ca= ob->data;
1721                         if(ca->id.lib) {
1722                                 if(okee("Make local")) {
1723                                         make_local_camera(ca);
1724                                 }
1725                         }
1726                 }
1727                 break;
1728         case B_WORLDALONE:
1729                 wrld= G.scene->world;
1730                 if(wrld->id.us>1) {
1731                         if(okee("Single user")) {
1732                                 G.scene->world= copy_world(wrld);
1733                                 wrld->id.us--;
1734                         }
1735                 }
1736                 break;
1737         case B_WORLDLOCAL:
1738                 wrld= G.scene->world;
1739                 if(wrld && wrld->id.lib) {
1740                         if(okee("Make local")) {
1741                                 make_local_world(wrld);
1742                         }
1743                 }
1744                 break;
1745
1746         case B_LATTALONE:
1747                 if(ob && ob->id.lib==0) {
1748                         lt= ob->data;
1749                         if(lt->id.us>1) {
1750                                 if(okee("Single user")) {
1751                                         ob->data= copy_lattice(lt);
1752                                         lt->id.us--;
1753                                 }
1754                         }
1755                 }
1756                 break;
1757         case B_LATTLOCAL:
1758                 if(ob && ob->id.lib==0) {
1759                         lt= ob->data;
1760                         if(lt->id.lib) {
1761                                 if(okee("Make local")) {
1762                                         make_local_lattice(lt);
1763                                 }
1764                         }
1765                 }
1766                 break;
1767         
1768         case B_MATALONE:
1769                 if(ob==0) return;
1770                 ma= give_current_material(ob, ob->actcol);
1771                 idfrom= material_from(ob, ob->actcol);
1772                 if(idfrom && idfrom->lib==0) {
1773                         if(ma->id.us>1) {
1774                                 if(okee("Single user")) {
1775                                         ma= copy_material(ma);
1776                                         ma->id.us= 0;
1777                                         assign_material(ob, ma, ob->actcol);
1778                                 }
1779                         }
1780                 }
1781                 break;
1782         case B_MATLOCAL:
1783                 if(ob==0) return;
1784                 idfrom= material_from(ob, ob->actcol);
1785                 if(idfrom->lib==0) {
1786                         ma= give_current_material(ob, ob->actcol);
1787                         if(ma && ma->id.lib) {
1788                                 if(okee("Make local")) {
1789                                         make_local_material(ma);
1790                                 }
1791                         }
1792                 }
1793                 break;
1794
1795         case B_MESHLOCAL:
1796                 if(ob && ob->id.lib==0) {
1797                         me= ob->data;
1798                         if(me && me->id.lib) {
1799                                 if(okee("Make local")) {
1800                                         make_local_mesh(me);
1801                                         make_local_key( me->key );
1802
1803                                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);                           
1804                                 }
1805                         }
1806                 }
1807                 break;
1808
1809         case B_MBALLALONE:
1810                 if(ob && ob->id.lib==0) {
1811                         mb= ob->data;
1812                         if(mb->id.us>1) {
1813                                 if(okee("Single user")) {
1814                                         ob->data= copy_mball(mb);
1815                                         mb->id.us--;
1816                                         if(ob==G.obedit) allqueue(REDRAWVIEW3D, 0);
1817                                 }
1818                         }
1819                 }
1820                 break;
1821         case B_MBALLLOCAL:
1822                 if(ob && ob->id.lib==0) {
1823                         mb= ob->data;
1824                         if(mb->id.lib) {
1825                                 if(okee("Make local")) {
1826                                         make_local_mball(mb);
1827                                 }
1828                         }
1829                 }
1830                 break;
1831
1832         case B_CURVEALONE:
1833                 if(ob && ob->id.lib==0) {
1834                         cu= ob->data;
1835                         if(cu->id.us>1) {
1836                                 if(okee("Single user")) {
1837                                         ob->data= copy_curve(cu);
1838                                         cu->id.us--;
1839                                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1840                                         if(ob==G.obedit) allqueue(REDRAWVIEW3D, 0);
1841                                 }
1842                         }
1843                 }
1844                 break;
1845         case B_CURVELOCAL:
1846                 if(ob && ob->id.lib==0) {
1847                         cu= ob->data;
1848                         if(cu->id.lib) {
1849                                 if(okee("Make local")) {
1850                                         make_local_curve(cu);
1851                                         make_local_key( cu->key );
1852                                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1853                                 }
1854                         }
1855                 }
1856                 break;
1857                 
1858         case B_TEXALONE:
1859                 if(G.buts->texfrom==0) {        /* from mat */
1860                         if(ob==0) return;
1861                         ma= give_current_material(ob, ob->actcol);
1862                         ma= editnode_get_active_material(ma);
1863                         if(ma && ma->id.lib==0) {
1864                                 mtex= ma->mtex[ ma->texact ];
1865                                 if(mtex->tex && mtex->tex->id.us>1) {
1866                                         if(okee("Single user")) {
1867                                                 mtex->tex->id.us--;
1868                                                 mtex->tex= copy_texture(mtex->tex);
1869                                         }
1870                                 }
1871                         }
1872                 }
1873                 else if(G.buts->texfrom==1) { /* from world */
1874                         wrld= G.scene->world;
1875                         if(wrld->id.lib==0) {
1876                                 mtex= wrld->mtex[ wrld->texact ];
1877                                 if(mtex->tex && mtex->tex->id.us>1) {
1878                                         if(okee("Single user")) {
1879                                                 mtex->tex->id.us--;
1880                                                 mtex->tex= copy_texture(mtex->tex);
1881                                         }
1882                                 }
1883                         }
1884                 }
1885                 else if(G.buts->texfrom==2) { /* from lamp */
1886                         if(ob==0 || ob->type!=OB_LAMP) return;
1887                         la= ob->data;
1888                         if(la->id.lib==0) {
1889                                 mtex= la->mtex[ la->texact ];
1890                                 if(mtex->tex && mtex->tex->id.us>1) {
1891                                         if(okee("Single user")) {
1892                                                 mtex->tex->id.us--;
1893                                                 mtex->tex= copy_texture(mtex->tex);
1894                                         }
1895                                 }
1896                         }
1897                 }
1898                 else if(G.buts->texfrom==3) { /* from brush */
1899                         br= G.scene->toolsettings->imapaint.brush;
1900                         if(br==0) return;
1901                         if(br->id.lib==0) {
1902                                 mtex= br->mtex[ br->texact ];
1903                                 if(mtex->tex && mtex->tex->id.us>1) {
1904                                         if(okee("Single user")) {
1905                                                 mtex->tex->id.us--;
1906                                                 mtex->tex= copy_texture(mtex->tex);
1907                                                 allqueue(REDRAWIMAGE, 0);
1908                                         }
1909                                 }
1910                         }
1911                 }
1912                 break;
1913         case B_TEXLOCAL:
1914                 if(G.buts->texfrom==0) {        /* from mat */
1915                         if(ob==0) return;
1916                         ma= give_current_material(ob, ob->actcol);
1917                         ma= editnode_get_active_material(ma);
1918                         if(ma && ma->id.lib==0) {
1919                                 mtex= ma->mtex[ ma->texact ];
1920                                 if(mtex->tex && mtex->tex->id.lib) {
1921                                         if(okee("Make local")) {
1922                                                 make_local_texture(mtex->tex);
1923                                         }
1924                                 }
1925                         }
1926                 }
1927                 else if(G.buts->texfrom==1) { /* from world */
1928                         wrld= G.scene->world;
1929                         if(wrld->id.lib==0) {
1930                                 mtex= wrld->mtex[ wrld->texact ];
1931                                 if(mtex->tex && mtex->tex->id.lib) {
1932                                         if(okee("Make local")) {
1933                                                 make_local_texture(mtex->tex);
1934                                         }
1935                                 }
1936                         }
1937                 }
1938                 else if(G.buts->texfrom==2) { /* from lamp */
1939                         if(ob==0 || ob->type!=OB_LAMP) return;
1940                         la= ob->data;
1941                         if(la->id.lib==0) {
1942                                 mtex= la->mtex[ la->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==3) { /* from brush */
1951                         br= G.scene->toolsettings->imapaint.brush;
1952                         if(br==0) return;
1953                         if(br->id.lib==0) {
1954                                 mtex= br->mtex[ br->texact ];
1955                                 if(mtex->tex && mtex->tex->id.lib) {
1956                                         if(okee("Make local")) {
1957                                                 make_local_texture(mtex->tex);
1958                                                 allqueue(REDRAWIMAGE, 0);
1959                                         }
1960                                 }
1961                         }
1962                 }
1963                 break;
1964         
1965         case B_IPOALONE:
1966                 ipo= G.sipo->ipo;
1967                 idfrom= G.sipo->from;
1968                 
1969                 if(idfrom && idfrom->lib==NULL) {
1970                         if(ipo->id.us>1) {
1971                                 if(okee("Single user")) {
1972                                         ipo= copy_ipo(ipo);
1973                                         ipo->id.us= 0;  /* assign_ipo adds users, copy_ipo sets to 1 */
1974                                         spaceipo_assign_ipo(G.sipo, ipo);
1975                                         allqueue(REDRAWIPO, 0);
1976                                 }
1977                         }
1978                 }
1979                 break;
1980         case B_IPOLOCAL:
1981                 ipo= G.sipo->ipo;
1982                 idfrom= G.sipo->from;
1983                 
1984                 if(idfrom && idfrom->lib==0) {
1985                         if(ipo->id.lib) {
1986                                 if(okee("Make local")) {
1987                                         make_local_ipo(ipo);
1988                                         allqueue(REDRAWIPO, 0);
1989                                 }
1990                         }
1991                 }
1992                 break;
1993
1994         case B_OBALONE:
1995                 if(G.scene->id.lib==0) {
1996                         if(ob->id.us>1) {
1997                                 if(okee("Single user")) {
1998                                         base= FIRSTBASE;
1999                                         while(base) {
2000                                                 if(base->object==ob) {
2001                                                         base->object= copy_object(ob);
2002                                                         ob->id.us--;
2003                                                         allqueue(REDRAWVIEW3D, 0);
2004                                                         break;
2005                                                 }
2006                                                 base= base->next;
2007                                         }
2008                                 }
2009                         }
2010                 }
2011                 break;
2012         case B_OBLOCAL:
2013                 if(G.scene->id.lib==0) {
2014                         if(ob->id.lib) {
2015                                 if(okee("Make local")) {
2016                                         make_local_object(ob);
2017                                         allqueue(REDRAWVIEW3D, 0);
2018                                 }
2019                         }
2020                 }
2021                 break;
2022         case B_MESHALONE:
2023                 if(ob && ob->id.lib==0) {
2024                         
2025                         me= ob->data;
2026                         
2027                         if(me && me->id.us>1) {
2028                                 if(okee("Single user")) {
2029                                         Mesh *men= copy_mesh(me);
2030                                         men->id.us= 0;
2031                                         
2032                                         set_mesh(ob, men);
2033                                         
2034                                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2035                                         
2036                                         if(ob==G.obedit) allqueue(REDRAWVIEW3D, 0);
2037                                 }
2038                         }
2039                 }
2040                 break;
2041         }
2042         
2043         BIF_undo_push("Make single user or local");
2044         allqueue(REDRAWBUTSALL, 0);
2045         allqueue(REDRAWOOPS, 0);
2046 }
2047
2048 /* ******************** GENERAL ********************** */
2049
2050 void do_headerbuttons(short event)
2051 {
2052
2053         if(event<=50) do_global_buttons2(event);
2054         else if(event<=100) do_global_buttons(event);
2055         else if(event<200) do_view3d_buttons(event);
2056         else if(event<250) do_ipo_buttons(event);
2057         else if(event<300) do_oops_buttons(event);
2058         else if(event<350) do_info_buttons(event);
2059         else if(event<400) do_image_buttons(event);
2060         else if(event<450) do_buts_buttons(event);
2061         else if(event<500) do_imasel_buttons(event);
2062         else if(event<525) do_text_buttons(event);
2063         else if(event<550) do_script_buttons(event);
2064         else if(event<600) do_file_buttons(event);
2065         else if(event<650) do_seq_buttons(event);
2066         else if(event<700) do_sound_buttons(event);
2067         else if(event<750) do_action_buttons(event);
2068         else if(event<800) do_time_buttons(curarea, event);
2069         else if(event<850) do_nla_buttons(event);
2070         else if(event<900) do_node_buttons(curarea, event);
2071         else if(event>=REDRAWVIEW3D) allqueue(event, 0);
2072 }
2073