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