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