Local Image View for UV/Editmode
[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 error("Warn bugtracker!");
1071                                 }
1072                                 idtest->us--;
1073                         }
1074                         if(idtest!=id && from) {
1075                                 spaceipo_assign_ipo(G.sipo, (Ipo *)idtest);
1076                                                                         
1077                                 BIF_undo_push("Browse Ipo");
1078                         }
1079                 }
1080                 break;
1081         case B_IPODELETE:
1082                 ipo= G.sipo->ipo;
1083                 from= G.sipo->from;
1084                 
1085                 spaceipo_assign_ipo(G.sipo, NULL);
1086                 
1087                 editipo_changed(G.sipo, 1); /* doredraw */
1088                 
1089                 BIF_undo_push("Unlink Ipo");
1090                 
1091                 break;
1092         case B_WORLDBROWSE:
1093
1094                 if(G.buts->menunr==-2) {
1095                         activate_databrowse((ID *)G.scene->world, ID_WO, 0, B_WORLDBROWSE, &G.buts->menunr, do_global_buttons);
1096                         break;
1097                 }
1098
1099                 if(G.buts->menunr < 0) break;
1100                 /* no lock */
1101                         
1102                 wrld= G.scene->world;
1103                 nr= 1;
1104                 
1105                 id= (ID *)wrld;
1106                 
1107                 idtest= G.main->world.first;
1108                 while(idtest) {
1109                         if(nr==G.buts->menunr) {
1110                                 break;
1111                         }
1112                         nr++;
1113                         idtest= idtest->next;
1114                 }
1115                 if(idtest==0) { /* new world */
1116                         if(id) idtest= (ID *)copy_world((World *)id);
1117                         else idtest= (ID *)add_world("World");
1118                         idtest->us--;
1119                 }
1120                 if(idtest!=id) {
1121                         G.scene->world= (World *)idtest;
1122                         id_us_plus(idtest);
1123                         if(id) id->us--;
1124                         
1125                         BIF_undo_push("Browse World");
1126                         allqueue(REDRAWBUTSSHADING, 0);
1127                         allqueue(REDRAWIPO, 0);
1128                         allqueue(REDRAWOOPS, 0);
1129                         BIF_preview_changed(ID_WO);
1130                 }
1131                 break;
1132         case B_WORLDDELETE:
1133                 if(G.scene->world) {
1134                         G.scene->world->id.us--;
1135                         G.scene->world= NULL;
1136
1137                         BIF_undo_push("Unlink World");
1138                         allqueue(REDRAWBUTSSHADING, 0);
1139                         allqueue(REDRAWIPO, 0);
1140                 }
1141                 
1142                 break;
1143         case B_WTEXBROWSE:
1144
1145                 if(G.buts->texnr== -2) {
1146                         id= NULL;
1147                         wrld= G.scene->world;
1148                         if(wrld) {
1149                                 mtex= wrld->mtex[ wrld->texact ];
1150                                 if(mtex) id= (ID *)mtex->tex;
1151                         }
1152
1153                         activate_databrowse((ID *)id, ID_TE, 0, B_WTEXBROWSE, &G.buts->texnr, do_global_buttons);
1154                         return;
1155                 }
1156                 if(G.buts->texnr < 0) break;
1157
1158                 if(G.buts->pin) {
1159                         
1160                 }
1161                 else {
1162                         id= NULL;
1163                         
1164                         wrld= G.scene->world;
1165                         if(wrld) {
1166                                 mtex= wrld->mtex[ wrld->texact ];
1167                                 if(mtex) id= (ID *)mtex->tex;
1168                         }
1169
1170                         idtest= G.main->tex.first;
1171                         while(idtest) {
1172                                 if(nr==G.buts->texnr) {
1173                                         break;
1174                                 }
1175                                 nr++;
1176                                 idtest= idtest->next;
1177                         }
1178                         if(idtest==0) { /* new tex */
1179                                 if(id)  idtest= (ID *)copy_texture((Tex *)id);
1180                                 else idtest= (ID *)add_texture("Tex");
1181                                 idtest->us--;
1182                         }
1183                         if(idtest!=id && wrld) {
1184                                 
1185                                 if( wrld->mtex[wrld->texact]==0) {
1186                                         wrld->mtex[wrld->texact]= add_mtex();
1187                                         wrld->mtex[wrld->texact]->texco= TEXCO_VIEW;
1188                                 }
1189                                 wrld->mtex[ wrld->texact ]->tex= (Tex *)idtest;
1190                                 id_us_plus(idtest);
1191                                 if(id) id->us--;
1192                                 
1193                                 BIF_undo_push("Texture browse");
1194                                 allqueue(REDRAWBUTSSHADING, 0);
1195                                 allqueue(REDRAWIPO, 0);
1196                                 allqueue(REDRAWOOPS, 0);
1197                                 BIF_preview_changed(ID_WO);
1198                         }
1199                 }
1200                 break;
1201         case B_LAMPBROWSE:
1202                 /* no lock */
1203                 if(ob==0) return;
1204                 if(ob->type!=OB_LAMP) return;
1205
1206                 if(G.buts->menunr== -2) {
1207                         activate_databrowse((ID *)G.buts->lockpoin, ID_LA, 0, B_LAMPBROWSE, &G.buts->menunr, do_global_buttons);
1208                         return;
1209                 }
1210                 if(G.buts->menunr < 0) break;
1211                 
1212                 la= ob->data;
1213                 nr= 1;
1214                 id= (ID *)la;
1215                 
1216                 idtest= G.main->lamp.first;
1217                 while(idtest) {
1218                         if(nr==G.buts->menunr) {
1219                                 break;
1220                         }
1221                         nr++;
1222                         idtest= idtest->next;
1223                 }
1224                 if(idtest==0) { /* no new lamp */
1225                         return;
1226                 }
1227                 if(idtest!=id) {
1228                         ob->data= (Lamp *)idtest;
1229                         id_us_plus(idtest);
1230                         if(id) id->us--;
1231                         
1232                         BIF_undo_push("Lamp browse");
1233                         allqueue(REDRAWBUTSSHADING, 0);
1234                         allqueue(REDRAWVIEW3D, 0);
1235                         allqueue(REDRAWIPO, 0);
1236                         allqueue(REDRAWOOPS, 0);
1237                         BIF_preview_changed(ID_LA);
1238                 }
1239                 break;
1240         
1241         case B_LTEXBROWSE:
1242
1243                 if(ob==0) return;
1244                 if(ob->type!=OB_LAMP) return;
1245
1246                 if(G.buts->texnr== -2) {
1247                         id= NULL;
1248                         la= ob->data;
1249                         mtex= la->mtex[ la->texact ];
1250                         if(mtex) id= (ID *)mtex->tex;
1251
1252                         activate_databrowse(id, ID_TE, 0, B_LTEXBROWSE, &G.buts->texnr, do_global_buttons);
1253                         return;
1254                 }
1255                 if(G.buts->texnr < 0) break;
1256
1257                 if(G.buts->pin) {
1258                         
1259                 }
1260                 else {
1261                         id= NULL;
1262                         
1263                         la= ob->data;
1264                         mtex= la->mtex[ la->texact ];
1265                         if(mtex) id= (ID *)mtex->tex;
1266
1267                         idtest= G.main->tex.first;
1268                         while(idtest) {
1269                                 if(nr==G.buts->texnr) {
1270                                         break;
1271                                 }
1272                                 nr++;
1273                                 idtest= idtest->next;
1274                         }
1275                         if(idtest==0) { /* new tex */
1276                                 if(id)  idtest= (ID *)copy_texture((Tex *)id);
1277                                 else idtest= (ID *)add_texture("Tex");
1278                                 idtest->us--;
1279                         }
1280                         if(idtest!=id && la) {
1281                                 
1282                                 if( la->mtex[la->texact]==0) {
1283                                         la->mtex[la->texact]= add_mtex();
1284                                         la->mtex[la->texact]->texco= TEXCO_GLOB;
1285                                 }
1286                                 la->mtex[ la->texact ]->tex= (Tex *)idtest;
1287                                 id_us_plus(idtest);
1288                                 if(id) id->us--;
1289                                 
1290                                 BIF_undo_push("Texture Browse");
1291                                 allqueue(REDRAWBUTSSHADING, 0);
1292                                 allqueue(REDRAWIPO, 0);
1293                                 allqueue(REDRAWOOPS, 0);
1294                                 BIF_preview_changed(ID_LA);
1295                         }
1296                 }
1297                 break;
1298
1299         case B_IMAGEDELETE:
1300                 if(G.sima->image && (G.sima->image->type == IMA_TYPE_R_RESULT || G.sima->image->type == IMA_TYPE_COMPOSITE)) {
1301                         /* Run if G.sima is render, remove the render and display the meshes image if it exists */
1302                         G.sima->image= NULL;
1303                         what_image(G.sima);
1304                         allqueue(REDRAWIMAGE, 0);
1305                 } else {
1306                         /* Run on non render images, unlink normally */
1307                         image_changed(G.sima, NULL);
1308                         BIF_undo_push("Unlink Image");
1309                         allqueue(REDRAWIMAGE, 0);
1310                 }
1311                 break;
1312         
1313         case B_AUTOMATNAME:
1314                 /* this is called now from Node editor too, buttons might not exist */
1315                 if(curarea->spacetype==SPACE_NODE) {
1316                         SpaceNode *snode= curarea->spacedata.first;
1317                         automatname((Material *)snode->id);
1318                 }
1319                 else if(G.buts) {
1320                         automatname(G.buts->lockpoin);
1321                 }
1322                 else return;
1323
1324                 BIF_undo_push("Auto name");
1325                 allqueue(REDRAWBUTSSHADING, 0);
1326                 allqueue(REDRAWNODE, 0);
1327                 allqueue(REDRAWOOPS, 0);
1328                 break;          
1329         case B_AUTOTEXNAME:
1330                 if(G.buts->mainb==CONTEXT_SHADING) {
1331                         if(G.buts->tab[CONTEXT_SHADING]==TAB_SHADING_TEX) {
1332                                 autotexname(G.buts->lockpoin);
1333                         }
1334                         else if(G.buts->tab[CONTEXT_SHADING]==TAB_SHADING_MAT) {
1335                                 ma= G.buts->lockpoin;
1336                                 if(ma->mtex[ ma->texact]) autotexname(ma->mtex[ma->texact]->tex);
1337                         }
1338                         else if(G.buts->tab[CONTEXT_SHADING]==TAB_SHADING_WORLD) {
1339                                 wrld= G.buts->lockpoin;
1340                                 if(wrld->mtex[ wrld->texact]) autotexname(wrld->mtex[wrld->texact]->tex);
1341                         }
1342                         else if(G.buts->tab[CONTEXT_SHADING]==TAB_SHADING_LAMP) {
1343                                 la= G.buts->lockpoin;
1344                                 if(la->mtex[ la->texact]) autotexname(la->mtex[la->texact]->tex);
1345                         }
1346                         BIF_undo_push("Auto name");
1347                         allqueue(REDRAWBUTSSHADING, 0);
1348                         allqueue(REDRAWOOPS, 0);
1349                         allqueue(REDRAWIMAGE, 0);
1350                 }
1351                 else if(G.buts->mainb==CONTEXT_EDITING) {
1352                         SculptData *sd= &G.scene->sculptdata;
1353                         if(sd && sd->texact != -1) {
1354                                 if(sd->mtex[sd->texact]) autotexname(sd->mtex[sd->texact]->tex);
1355
1356                                 BIF_undo_push("Auto name");
1357                                 allqueue(REDRAWBUTSEDIT, 0);
1358                                 allqueue(REDRAWOOPS, 0);
1359                         }
1360                 }
1361                 break;
1362
1363         case B_RESETAUTOSAVE:
1364                 reset_autosave();
1365                 allqueue(REDRAWINFO, 0);
1366                 break;
1367         case B_SOUNDTOGGLE:
1368                 SYS_WriteCommandLineInt(SYS_GetSystem(), "noaudio", (U.gameflags & USER_DISABLE_SOUND));
1369                 break;
1370         case B_SHOWSPLASH:
1371                                 show_splash();
1372                 break;
1373         case B_MIPMAPCHANGED:
1374                 set_mipmap(!(U.gameflags & USER_DISABLE_MIPMAP));
1375                 allqueue(REDRAWVIEW3D, 0);
1376                 break;
1377         case B_GLRESLIMITCHANGED:
1378                 free_all_realtime_images(); /* force reloading with new res limit */
1379                 allqueue(REDRAWVIEW3D, 0);
1380                 break;
1381         case B_NEWSPACE:
1382                 newspace(curarea, curarea->butspacetype);
1383                 break;
1384         case B_LOADTEMP:        /* is button from space.c */
1385                 BIF_read_autosavefile();
1386                 break;
1387
1388         case B_USERPREF:
1389                 allqueue(REDRAWINFO, 0);
1390                 break;
1391
1392         case B_DRAWINFO:        /* is button from space.c  *info* */
1393                 allqueue(REDRAWVIEW3D, 0);
1394                 break;
1395
1396         case B_PLAINMENUS:     /* is button from space.c  *info* */
1397                 reset_toolbox();
1398                 break;
1399
1400         case B_FLIPINFOMENU:    /* is button from space.c  *info* */
1401                 scrarea_queue_headredraw(curarea);
1402                 break;
1403
1404 #if 0
1405 //#ifdef _WIN32 // FULLSCREEN
1406         case B_FLIPFULLSCREEN:
1407                 if(U.uiflag & USER_FLIPFULLSCREEN)
1408                         U.uiflag &= ~USER_FLIPFULLSCREEN;
1409                 else
1410                         U.uiflag |= USER_FLIPFULLSCREEN;
1411                 mainwindow_toggle_fullscreen((U.uiflag & USER_FLIPFULLSCREEN));
1412                 break;
1413 #endif
1414
1415         /* Fileselect windows for user preferences file paths */
1416
1417         /* yafray: xml export dir. select */
1418         case B_YAFRAYDIRFILESEL:        /* space.c */
1419                 if(curarea->spacetype==SPACE_INFO) {
1420                         sa= closest_bigger_area();
1421                         areawinset(sa->win);
1422                 }
1423
1424                 activate_fileselect(FILE_SPECIAL, "SELECT YFEXPORT PATH", U.yfexportdir, filesel_u_yfexportdir);
1425                 break;
1426
1427         case B_FONTDIRFILESEL:  /* is button from space.c  *info* */
1428                 if(curarea->spacetype==SPACE_INFO) {
1429                         sa= closest_bigger_area();
1430                         areawinset(sa->win);
1431                 }
1432
1433                 activate_fileselect(FILE_SPECIAL, "SELECT FONT PATH", U.fontdir, filesel_u_fontdir);
1434                 break;
1435
1436         case B_TEXTUDIRFILESEL:         /* is button from space.c  *info* */
1437                 if(curarea->spacetype==SPACE_INFO) {
1438                         sa= closest_bigger_area();
1439                         areawinset(sa->win);
1440                 }
1441
1442                 activate_fileselect(FILE_SPECIAL, "SELECT TEXTURE PATH", U.textudir, filesel_u_textudir);
1443                 break;
1444         
1445         case B_PLUGTEXDIRFILESEL:               /* is button form space.c  *info* */
1446                 if(curarea->spacetype==SPACE_INFO) {
1447                         sa= closest_bigger_area();
1448                         areawinset(sa->win);
1449                 }
1450
1451                 activate_fileselect(FILE_SPECIAL, "SELECT TEX PLUGIN PATH", U.plugtexdir, filesel_u_plugtexdir);
1452                 break;
1453         
1454         case B_PLUGSEQDIRFILESEL:               /* is button from space.c  *info* */
1455                 if(curarea->spacetype==SPACE_INFO) {
1456                         sa= closest_bigger_area();
1457                         areawinset(sa->win);
1458                 }
1459
1460                 activate_fileselect(FILE_SPECIAL, "SELECT SEQ PLUGIN PATH", U.plugseqdir, filesel_u_plugseqdir);
1461                 break;
1462         
1463         case B_RENDERDIRFILESEL:        /* is button from space.c  *info* */
1464                 if(curarea->spacetype==SPACE_INFO) {
1465                         sa= closest_bigger_area();
1466                         areawinset(sa->win);
1467                 }
1468
1469                 activate_fileselect(FILE_SPECIAL, "SELECT RENDER PATH", U.renderdir, filesel_u_renderdir);
1470                 break;
1471
1472         case B_PYMENUEVAL: /* is button from space.c *info* */
1473                 waitcursor( 1 ); /* can take some time */
1474                 BPyMenu_RemoveAllEntries(); /* free old data */
1475                 if (BPyMenu_Init(1) == -1) { /* re-eval scripts registration in menus */
1476                         waitcursor( 0 );
1477                         error("Invalid scripts dir: check console");
1478                 }
1479                 waitcursor( 0 );
1480                 break;
1481         case B_PYTHONDIRFILESEL:        /* is button from space.c  *info* */
1482                 if(curarea->spacetype==SPACE_INFO) {
1483                         sa= closest_bigger_area();
1484                         areawinset(sa->win);
1485                 }
1486
1487                 activate_fileselect(FILE_SPECIAL, "SELECT SCRIPT PATH", U.pythondir, filesel_u_pythondir);
1488                 break;
1489
1490         case B_SOUNDDIRFILESEL:         /* is button from space.c  *info* */
1491                 if(curarea->spacetype==SPACE_INFO) {
1492                         sa= closest_bigger_area();
1493                         areawinset(sa->win);
1494                 }
1495
1496                 activate_fileselect(FILE_SPECIAL, "SELECT SOUND PATH", U.sounddir, filesel_u_sounddir);
1497                 break;
1498
1499         case B_TEMPDIRFILESEL:  /* is button from space.c  *info* */
1500                 if(curarea->spacetype==SPACE_INFO) {
1501                         sa= closest_bigger_area();
1502                         areawinset(sa->win);
1503                 }
1504
1505                 activate_fileselect(FILE_SPECIAL, "SELECT TEMP FILE PATH", U.tempdir, filesel_u_tempdir);
1506                 break;
1507
1508         /* END Fileselect windows for user preferences file paths */
1509
1510 #ifdef INTERNATIONAL
1511         case B_LOADUIFONT:      /* is button from space.c  *info* */
1512                 if(curarea->spacetype==SPACE_INFO) {
1513                         sa= closest_bigger_area();
1514                         areawinset(sa->win);
1515                 }
1516                 BLI_make_file_string("/", buf, U.fontdir, U.fontname);
1517                 activate_fileselect(FILE_SPECIAL, "LOAD UI FONT", buf, set_interface_font);
1518                 break;
1519
1520         case B_SETLANGUAGE:             /* is button from space.c  *info* */
1521                 lang_setlanguage();
1522                 allqueue(REDRAWALL, 0);
1523                 break;
1524
1525         case B_SETFONTSIZE:             /* is button from space.c  *info* */
1526                 refresh_interface_font();
1527                 FTF_SetSize(U.fontsize); 
1528                 allqueue(REDRAWALL, 0);
1529                 break;
1530                 
1531         case B_SETTRANSBUTS:    /* is button from space.c  *info* */
1532                 allqueue(REDRAWALL, 0);
1533                 break;
1534
1535         case B_RESTOREFONT:             /* is button from space.c  *info* */
1536                 U.fontsize= 0;
1537                 start_interface_font();
1538                 allqueue(REDRAWALL, 0);
1539                 break;
1540                 
1541         case B_USETEXTUREFONT:          /* is button from space.c  *info* */
1542                 refresh_interface_font();
1543                 allqueue(REDRAWALL, 0);
1544                 break;
1545
1546         case B_DOLANGUIFONT:    /* is button from space.c  *info* */
1547                 if(U.transopts & USER_DOTRANSLATE)
1548                         start_interface_font();
1549                 else
1550                         G.ui_international = FALSE;
1551                 allqueue(REDRAWALL, 0);
1552                 break;
1553 #endif
1554                 
1555         case B_FULL:
1556                 if(curarea->spacetype!=SPACE_INFO) {
1557                         area_fullscreen();
1558                 }
1559                 break;  
1560
1561         case B_IDNAME:
1562                         /* changing a metaballs name, sadly enough,
1563                          * can require it to be updated because its
1564                          * basis might have changed... -zr
1565                          */
1566                 if (ob && ob->type==OB_MBALL) {
1567                         DAG_scene_sort(G.scene);
1568                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1569                 }
1570                 /* redraw because name has changed: new pup */
1571                 scrarea_queue_headredraw(curarea);
1572                 allqueue(REDRAWINFO, 1);
1573                 allqueue(REDRAWOOPS, 1);
1574                 allqueue(REDRAWACTION, 1);
1575                 allqueue(REDRAWNLA, 1);
1576                 /* name scene also in set PUPmenu */
1577                 allqueue(REDRAWBUTSALL, 0);
1578                 allqueue(REDRAWIMAGE, 0);
1579                 allqueue(REDRAWHEADERS, 0);
1580                 break;
1581         
1582         case B_KEEPDATA:
1583                 /* keep datablock. similar to pressing FKEY in a fileselect window
1584                  * maybe we can move that stuff to a seperate function? -- sg
1585                  */
1586                 if (curarea->spacetype==SPACE_BUTS) {
1587                         id= (ID *)G.buts->lockpoin;
1588                 } else if(curarea->spacetype==SPACE_IPO) {
1589                         id = (ID *)G.sipo->ipo;
1590                 } else if(curarea->spacetype==SPACE_NODE) {
1591                         id = ((SpaceNode *)curarea->spacedata.first)->id;
1592                 } /* similar for other spacetypes ? */
1593                 if (id) {
1594                         if( id->flag & LIB_FAKEUSER) {
1595                                 id->flag -= LIB_FAKEUSER;
1596                                 id->us--;
1597                         } else {
1598                                 id->flag |= LIB_FAKEUSER;
1599                                 id->us++;
1600                         }
1601                 }
1602                 allqueue(REDRAWHEADERS, 0);
1603
1604                 break;
1605
1606         }
1607 }
1608
1609
1610 void do_global_buttons2(short event)
1611 {
1612         Base *base;
1613         Object *ob;
1614         Material *ma;
1615         MTex *mtex;
1616         Mesh *me;
1617         Curve *cu;
1618         MetaBall *mb;
1619         Ipo *ipo;
1620         Lamp *la;
1621         Lattice *lt;
1622         World *wrld;
1623         ID *idfrom; 
1624         bAction *act;
1625         Brush *br;
1626
1627         /* general:  Single User is allowed when from==LOCAL 
1628          *                       Make Local is allowed when (from==LOCAL && id==LIB)
1629          */
1630                 
1631         if(event<B_LOCAL_ALONE) return;
1632
1633         ob= OBACT;
1634
1635         switch(event) {
1636                 
1637         case B_LAMPALONE:
1638                 if(ob && ob->id.lib==0) {
1639                         la= ob->data;
1640                         if(la->id.us>1) {
1641                                 if(okee("Single user")) {
1642                                         ob->data= copy_lamp(la);
1643                                         la->id.us--;
1644                                 }
1645                         }
1646                 }
1647                 break;
1648         case B_LAMPLOCAL:
1649                 if(ob && ob->id.lib==0) {
1650                         la= ob->data;
1651                         if(la->id.lib) {
1652                                 if(okee("Make local")) {
1653                                         make_local_lamp(la);
1654                                 }
1655                         }
1656                 }
1657                 break;
1658         
1659         case B_ARMLOCAL:
1660                 if (ob&&ob->id.lib==0){
1661                         bArmature *arm=ob->data;
1662                         if (arm->id.lib){
1663                                 if(okee("Make local")) {
1664                                         make_local_armature(arm);
1665                                 }
1666                         }
1667                 }
1668                 break;
1669         case B_ARMALONE:
1670                 if(ob && ob->id.lib==0) {
1671                         bArmature *arm=ob->data;
1672                         if(arm->id.us>1) {
1673                                 if(okee("Single user")) {
1674                                         ob->data= copy_armature(arm);
1675                                         armature_rebuild_pose(ob, ob->data);
1676                                         arm->id.us--;
1677                                 }
1678                         }
1679                 }
1680                 break;
1681         case B_ACTLOCAL:
1682                 if(ob && ob->id.lib==0) {
1683                         act= ob->action;
1684                         if(act->id.lib) {
1685                                 if(okee("Make local")) {
1686                                         make_local_action(act);
1687                                         allqueue(REDRAWACTION,0);
1688                                 }
1689                         }
1690                 }
1691                 break;
1692         case B_ACTALONE:
1693                 if(ob && ob->id.lib==0) {
1694                         act= ob->action;
1695                 
1696                         if(act->id.us>1) {
1697                                 if(okee("Single user")) {
1698                                         ob->action=copy_action(act);
1699                                         act->id.us--;
1700                                         allqueue(REDRAWACTION, 0);
1701                                 }
1702                         }
1703                 }
1704                 break;
1705
1706         case B_CAMERAALONE:
1707                 if(ob && ob->id.lib==0) {
1708                         Camera *ca= ob->data;
1709                         if(ca->id.us>1) {
1710                                 if(okee("Single user")) {
1711                                         ob->data= copy_camera(ca);
1712                                         ca->id.us--;
1713                                 }
1714                         }
1715                 }
1716                 break;
1717         case B_CAMERALOCAL:
1718                 if(ob && ob->id.lib==0) {
1719                         Camera *ca= ob->data;
1720                         if(ca->id.lib) {
1721                                 if(okee("Make local")) {
1722                                         make_local_camera(ca);
1723                                 }
1724                         }
1725                 }
1726                 break;
1727         case B_WORLDALONE:
1728                 wrld= G.scene->world;
1729                 if(wrld->id.us>1) {
1730                         if(okee("Single user")) {
1731                                 G.scene->world= copy_world(wrld);
1732                                 wrld->id.us--;
1733                         }
1734                 }
1735                 break;
1736         case B_WORLDLOCAL:
1737                 wrld= G.scene->world;
1738                 if(wrld && wrld->id.lib) {
1739                         if(okee("Make local")) {
1740                                 make_local_world(wrld);
1741                         }
1742                 }
1743                 break;
1744
1745         case B_LATTALONE:
1746                 if(ob && ob->id.lib==0) {
1747                         lt= ob->data;
1748                         if(lt->id.us>1) {
1749                                 if(okee("Single user")) {
1750                                         ob->data= copy_lattice(lt);
1751                                         lt->id.us--;
1752                                 }
1753                         }
1754                 }
1755                 break;
1756         case B_LATTLOCAL:
1757                 if(ob && ob->id.lib==0) {
1758                         lt= ob->data;
1759                         if(lt->id.lib) {
1760                                 if(okee("Make local")) {
1761                                         make_local_lattice(lt);
1762                                 }
1763                         }
1764                 }
1765                 break;
1766         
1767         case B_MATALONE:
1768                 if(ob==0) return;
1769                 ma= give_current_material(ob, ob->actcol);
1770                 idfrom= material_from(ob, ob->actcol);
1771                 if(idfrom && idfrom->lib==0) {
1772                         if(ma->id.us>1) {
1773                                 if(okee("Single user")) {
1774                                         ma= copy_material(ma);
1775                                         ma->id.us= 0;
1776                                         assign_material(ob, ma, ob->actcol);
1777                                 }
1778                         }
1779                 }
1780                 break;
1781         case B_MATLOCAL:
1782                 if(ob==0) return;
1783                 idfrom= material_from(ob, ob->actcol);
1784                 if(idfrom->lib==0) {
1785                         ma= give_current_material(ob, ob->actcol);
1786                         if(ma && ma->id.lib) {
1787                                 if(okee("Make local")) {
1788                                         make_local_material(ma);
1789                                 }
1790                         }
1791                 }
1792                 break;
1793
1794         case B_MESHLOCAL:
1795                 if(ob && ob->id.lib==0) {
1796                         me= ob->data;
1797                         if(me && me->id.lib) {
1798                                 if(okee("Make local")) {
1799                                         make_local_mesh(me);
1800                                         make_local_key( me->key );
1801
1802                                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);                           
1803                                 }
1804                         }
1805                 }
1806                 break;
1807
1808         case B_MBALLALONE:
1809                 if(ob && ob->id.lib==0) {
1810                         mb= ob->data;
1811                         if(mb->id.us>1) {
1812                                 if(okee("Single user")) {
1813                                         ob->data= copy_mball(mb);
1814                                         mb->id.us--;
1815                                         if(ob==G.obedit) allqueue(REDRAWVIEW3D, 0);
1816                                 }
1817                         }
1818                 }
1819                 break;
1820         case B_MBALLLOCAL:
1821                 if(ob && ob->id.lib==0) {
1822                         mb= ob->data;
1823                         if(mb->id.lib) {
1824                                 if(okee("Make local")) {
1825                                         make_local_mball(mb);
1826                                 }
1827                         }
1828                 }
1829                 break;
1830
1831         case B_CURVEALONE:
1832                 if(ob && ob->id.lib==0) {
1833                         cu= ob->data;
1834                         if(cu->id.us>1) {
1835                                 if(okee("Single user")) {
1836                                         ob->data= copy_curve(cu);
1837                                         cu->id.us--;
1838                                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1839                                         if(ob==G.obedit) allqueue(REDRAWVIEW3D, 0);
1840                                 }
1841                         }
1842                 }
1843                 break;
1844         case B_CURVELOCAL:
1845                 if(ob && ob->id.lib==0) {
1846                         cu= ob->data;
1847                         if(cu->id.lib) {
1848                                 if(okee("Make local")) {
1849                                         make_local_curve(cu);
1850                                         make_local_key( cu->key );
1851                                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1852                                 }
1853                         }
1854                 }
1855                 break;
1856                 
1857         case B_TEXALONE:
1858                 if(G.buts->texfrom==0) {        /* from mat */
1859                         if(ob==0) return;
1860                         ma= give_current_material(ob, ob->actcol);
1861                         ma= editnode_get_active_material(ma);
1862                         if(ma && ma->id.lib==0) {
1863                                 mtex= ma->mtex[ ma->texact ];
1864                                 if(mtex->tex && mtex->tex->id.us>1) {
1865                                         if(okee("Single user")) {
1866                                                 mtex->tex->id.us--;
1867                                                 mtex->tex= copy_texture(mtex->tex);
1868                                         }
1869                                 }
1870                         }
1871                 }
1872                 else if(G.buts->texfrom==1) { /* from world */
1873                         wrld= G.scene->world;
1874                         if(wrld->id.lib==0) {
1875                                 mtex= wrld->mtex[ wrld->texact ];
1876                                 if(mtex->tex && mtex->tex->id.us>1) {
1877                                         if(okee("Single user")) {
1878                                                 mtex->tex->id.us--;
1879                                                 mtex->tex= copy_texture(mtex->tex);
1880                                         }
1881                                 }
1882                         }
1883                 }
1884                 else if(G.buts->texfrom==2) { /* from lamp */
1885                         if(ob==0 || ob->type!=OB_LAMP) return;
1886                         la= ob->data;
1887                         if(la->id.lib==0) {
1888                                 mtex= la->mtex[ la->texact ];
1889                                 if(mtex->tex && mtex->tex->id.us>1) {
1890                                         if(okee("Single user")) {
1891                                                 mtex->tex->id.us--;
1892                                                 mtex->tex= copy_texture(mtex->tex);
1893                                         }
1894                                 }
1895                         }
1896                 }
1897                 else if(G.buts->texfrom==3) { /* from brush */
1898                         br= G.scene->toolsettings->imapaint.brush;
1899                         if(br==0) return;
1900                         if(br->id.lib==0) {
1901                                 mtex= br->mtex[ br->texact ];
1902                                 if(mtex->tex && mtex->tex->id.us>1) {
1903                                         if(okee("Single user")) {
1904                                                 mtex->tex->id.us--;
1905                                                 mtex->tex= copy_texture(mtex->tex);
1906                                                 allqueue(REDRAWIMAGE, 0);
1907                                         }
1908                                 }
1909                         }
1910                 }
1911                 break;
1912         case B_TEXLOCAL:
1913                 if(G.buts->texfrom==0) {        /* from mat */
1914                         if(ob==0) return;
1915                         ma= give_current_material(ob, ob->actcol);
1916                         ma= editnode_get_active_material(ma);
1917                         if(ma && ma->id.lib==0) {
1918                                 mtex= ma->mtex[ ma->texact ];
1919                                 if(mtex->tex && mtex->tex->id.lib) {
1920                                         if(okee("Make local")) {
1921                                                 make_local_texture(mtex->tex);
1922                                         }
1923                                 }
1924                         }
1925                 }
1926                 else if(G.buts->texfrom==1) { /* from world */
1927                         wrld= G.scene->world;
1928                         if(wrld->id.lib==0) {
1929                                 mtex= wrld->mtex[ wrld->texact ];
1930                                 if(mtex->tex && mtex->tex->id.lib) {
1931                                         if(okee("Make local")) {
1932                                                 make_local_texture(mtex->tex);
1933                                         }
1934                                 }
1935                         }
1936                 }
1937                 else if(G.buts->texfrom==2) { /* from lamp */
1938                         if(ob==0 || ob->type!=OB_LAMP) return;
1939                         la= ob->data;
1940                         if(la->id.lib==0) {
1941                                 mtex= la->mtex[ la->texact ];
1942                                 if(mtex->tex && mtex->tex->id.lib) {
1943                                         if(okee("Make local")) {
1944                                                 make_local_texture(mtex->tex);
1945                                         }
1946                                 }
1947                         }
1948                 }
1949                 else if(G.buts->texfrom==3) { /* from brush */
1950                         br= G.scene->toolsettings->imapaint.brush;
1951                         if(br==0) return;
1952                         if(br->id.lib==0) {
1953                                 mtex= br->mtex[ br->texact ];
1954                                 if(mtex->tex && mtex->tex->id.lib) {
1955                                         if(okee("Make local")) {
1956                                                 make_local_texture(mtex->tex);
1957                                                 allqueue(REDRAWIMAGE, 0);
1958                                         }
1959                                 }
1960                         }
1961                 }
1962                 break;
1963         
1964         case B_IPOALONE:
1965                 ipo= G.sipo->ipo;
1966                 idfrom= G.sipo->from;
1967                 
1968                 if(idfrom && idfrom->lib==NULL) {
1969                         if(ipo->id.us>1) {
1970                                 if(okee("Single user")) {
1971                                         ipo= copy_ipo(ipo);
1972                                         ipo->id.us= 0;  /* assign_ipo adds users, copy_ipo sets to 1 */
1973                                         spaceipo_assign_ipo(G.sipo, ipo);
1974                                         allqueue(REDRAWIPO, 0);
1975                                 }
1976                         }
1977                 }
1978                 break;
1979         case B_IPOLOCAL:
1980                 ipo= G.sipo->ipo;
1981                 idfrom= G.sipo->from;
1982                 
1983                 if(idfrom && idfrom->lib==0) {
1984                         if(ipo->id.lib) {
1985                                 if(okee("Make local")) {
1986                                         make_local_ipo(ipo);
1987                                         allqueue(REDRAWIPO, 0);
1988                                 }
1989                         }
1990                 }
1991                 break;
1992
1993         case B_OBALONE:
1994                 if(G.scene->id.lib==0) {
1995                         if(ob->id.us>1) {
1996                                 if(okee("Single user")) {
1997                                         base= FIRSTBASE;
1998                                         while(base) {
1999                                                 if(base->object==ob) {
2000                                                         base->object= copy_object(ob);
2001                                                         ob->id.us--;
2002                                                         allqueue(REDRAWVIEW3D, 0);
2003                                                         break;
2004                                                 }
2005                                                 base= base->next;
2006                                         }
2007                                 }
2008                         }
2009                 }
2010                 break;
2011         case B_OBLOCAL:
2012                 if(G.scene->id.lib==0) {
2013                         if(ob->id.lib) {
2014                                 if(okee("Make local")) {
2015                                         make_local_object(ob);
2016                                         allqueue(REDRAWVIEW3D, 0);
2017                                 }
2018                         }
2019                 }
2020                 break;
2021         case B_MESHALONE:
2022                 if(ob && ob->id.lib==0) {
2023                         
2024                         me= ob->data;
2025                         
2026                         if(me && me->id.us>1) {
2027                                 if(okee("Single user")) {
2028                                         Mesh *men= copy_mesh(me);
2029                                         men->id.us= 0;
2030                                         
2031                                         set_mesh(ob, men);
2032                                         
2033                                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2034                                         
2035                                         if(ob==G.obedit) allqueue(REDRAWVIEW3D, 0);
2036                                 }
2037                         }
2038                 }
2039                 break;
2040         }
2041         
2042         BIF_undo_push("Make single user or local");
2043         allqueue(REDRAWBUTSALL, 0);
2044         allqueue(REDRAWOOPS, 0);
2045 }
2046
2047 /* ******************** GENERAL ********************** */
2048
2049 void do_headerbuttons(short event)
2050 {
2051
2052         if(event<=50) do_global_buttons2(event);
2053         else if(event<=100) do_global_buttons(event);
2054         else if(event<200) do_view3d_buttons(event);
2055         else if(event<250) do_ipo_buttons(event);
2056         else if(event<300) do_oops_buttons(event);
2057         else if(event<350) do_info_buttons(event);
2058         else if(event<400) do_image_buttons(event);
2059         else if(event<450) do_buts_buttons(event);
2060         else if(event<500) do_imasel_buttons(event);
2061         else if(event<525) do_text_buttons(event);
2062         else if(event<550) do_script_buttons(event);
2063         else if(event<600) do_file_buttons(event);
2064         else if(event<650) do_seq_buttons(event);
2065         else if(event<700) do_sound_buttons(event);
2066         else if(event<750) do_action_buttons(event);
2067         else if(event<800) do_time_buttons(curarea, event);
2068         else if(event<850) do_nla_buttons(event);
2069         else if(event<900) do_node_buttons(curarea, event);
2070         else if(event>=REDRAWVIEW3D) allqueue(event, 0);
2071 }
2072