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