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