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