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