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