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