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