1d3a24c4f3b29255bb7e8891bb3d1cd793250ba2
[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 <string.h>
34 #include <math.h>
35
36 #include <sys/types.h>
37
38 #ifdef HAVE_CONFIG_H
39 #include <config.h>
40 #endif
41
42 #ifdef WIN32
43 #include "BLI_winstuff.h"
44 #endif
45
46 #include "MEM_guardedalloc.h"
47
48 #include "BMF_Api.h"
49 #ifdef INTERNATIONAL
50 #include "FTF_Api.h"
51 #include "BIF_language.h"
52 #endif
53
54 #include "BLI_blenlib.h"
55 #include "BLI_arithb.h"
56 #include "BLI_editVert.h"
57 #include "BLI_storage_types.h"
58
59 #include "IMB_imbuf_types.h"
60 #include "IMB_imbuf.h"
61
62 #include "DNA_ID.h"
63 #include "DNA_action_types.h"
64 #include "DNA_armature_types.h"
65 #include "DNA_camera_types.h"
66 #include "DNA_curve_types.h"
67 #include "DNA_group_types.h"
68 #include "DNA_image_types.h"
69 #include "DNA_ipo_types.h"
70 #include "DNA_key_types.h"
71 #include "DNA_lamp_types.h"
72 #include "DNA_lattice_types.h"
73 #include "DNA_material_types.h"
74 #include "DNA_mesh_types.h"
75 #include "DNA_meta_types.h"
76 #include "DNA_object_types.h"
77 #include "DNA_oops_types.h"
78 #include "DNA_packedFile_types.h"
79 #include "DNA_scene_types.h"
80 #include "DNA_screen_types.h"
81 #include "DNA_sequence_types.h"
82 #include "DNA_sound_types.h"
83 #include "DNA_space_types.h"
84 #include "DNA_texture_types.h"
85 #include "DNA_text_types.h"
86 #include "DNA_userdef_types.h"
87 #include "DNA_view2d_types.h"
88 #include "DNA_view3d_types.h"
89 #include "DNA_world_types.h"
90 #include "DNA_constraint_types.h"
91
92 #include "BKE_utildefines.h"
93
94 #include "BKE_constraint.h"
95 #include "BKE_action.h"
96 #include "BKE_armature.h"
97 #include "BKE_blender.h"
98 #include "BKE_curve.h"
99 #include "BKE_displist.h"
100 #include "BKE_exotic.h"
101 #include "BKE_global.h"
102 #include "BKE_image.h"
103 #include "BKE_ika.h"
104 #include "BKE_ipo.h"
105 #include "BKE_key.h"
106 #include "BKE_lattice.h"
107 #include "BKE_library.h"
108 #include "BKE_main.h"
109 #include "BKE_material.h"
110 #include "BKE_mball.h"
111 #include "BKE_mesh.h"
112 #include "BKE_object.h"
113 #include "BKE_packedFile.h"
114 #include "BKE_sca.h"
115 #include "BKE_scene.h"
116 #include "BKE_texture.h"
117 #include "BKE_text.h"
118 #include "BKE_world.h"
119
120 #include "BLO_readfile.h"
121 #include "BLO_writefile.h"
122
123 #include "BIF_drawimage.h"
124 #include "BIF_drawoops.h"
125 #include "BIF_drawscene.h"
126 #include "BIF_drawtext.h"
127 #include "BIF_editarmature.h"
128 #include "BIF_editfont.h"
129 #include "BIF_editlattice.h"
130 #include "BIF_editconstraint.h"
131 #include "BIF_editmesh.h"
132 #include "BIF_editmesh.h"
133 #include "BIF_editsima.h"
134 #include "BIF_editsound.h"
135 #include "BIF_editsound.h"
136 #include "BIF_gl.h"
137 #include "BIF_imasel.h"
138 #include "BIF_interface.h"
139 #include "BIF_mainqueue.h"
140 #include "BIF_mywindow.h"
141 #include "BIF_poseobject.h"
142 #include "BIF_renderwin.h"
143 #include "BIF_resources.h"
144 #include "BIF_screen.h"
145 #include "BIF_space.h"
146 #include "BIF_toets.h"
147 #include "BIF_toets.h"
148 #include "BIF_toolbox.h"
149 #include "BIF_usiblender.h"
150 #include "BIF_previewrender.h"
151 #include "BIF_writeimage.h"
152
153 #include "BSE_edit.h"
154 #include "BSE_filesel.h"
155 #include "BSE_headerbuttons.h"
156 #include "BSE_view.h"
157 #include "BSE_sequence.h"
158 #include "BSE_editaction.h"
159 #include "BSE_editaction_types.h"
160 #include "BSE_editipo.h"
161 #include "BSE_drawipo.h"
162
163 #include "BDR_drawmesh.h"
164 #include "BDR_vpaint.h"
165 #include "BDR_editface.h"
166 #include "BDR_editobject.h"
167 #include "BDR_editcurve.h"
168 #include "BDR_editmball.h"
169
170 #include "BPY_extern.h" // Blender Python library
171
172 #include "interface.h"
173 #include "mydevice.h"
174 #include "blendef.h"
175 #include "render.h"
176 #include "ipo.h"
177 #include "nla.h"        /* __NLA : To be removed later */
178
179 #include "TPT_DependKludge.h"
180
181 /* local (?) functions */
182 void do_file_buttons(short event);
183 void do_text_buttons(unsigned short event);
184 void load_space_sound(char *str);
185 void load_sound_buttons(char *str);
186 void load_space_image(char *str);
187 void image_replace(Image *old, Image *new);
188 void replace_space_image(char *str);
189 void do_image_buttons(unsigned short event);
190 void do_imasel_buttons(short event);
191 static void check_packAll(void);
192 static void unique_bone_name(Bone *bone, bArmature *arm);
193 static void validate_bonebutton(void *data1, void *data2);
194 static int bonename_exists(Bone *orig, char *name, ListBase *list);
195
196 static  void test_idbutton_cb(void *namev, void *arg2_unused)
197 {
198         char *name= namev;
199         test_idbutton(name+2);
200 }
201
202 #define SPACEICONMAX    13 /* See release/datafiles/blenderbuttons */
203
204 #include "BIF_poseobject.h"
205
206 #include "SYS_System.h"
207
208 static int std_libbuttons(uiBlock *block, 
209                                                   int xco, int pin, short *pinpoin, 
210                                                   int browse, ID *id, ID *parid, 
211                                                   short *menupoin, int users, 
212                                                   int lib, int del, int autobut, int keepbut);
213
214
215 extern char versionstr[]; /* from blender.c */
216 /*  extern                void add_text_fs(char *file);  *//* from text.c, BIF_text.h*/
217
218  /* WATCH IT:  always give all headerbuttons for same window the same name
219   *                     event B_REDR is a standard redraw
220   *
221   */
222
223
224 /*
225  * The next define turns the newest menu structure on.
226  * There are some loose ends here at the moment so leave this undefined for now.
227  */
228 /* #define EXPERIMENTAL_MENUS */
229
230
231 #define XIC 20
232 #define YIC 20
233
234 static int viewmovetemp=0;
235
236 /*  extern void info_buttons(); in BSE_headerbuttons.c */
237
238 extern char videosc_dir[];      /* exotic.c */
239
240 /* *********************************************************************** */
241
242 void write_videoscape_fs()
243 {
244         if(G.obedit) {
245                 error("Can't save Videoscape. Press TAB to leave EditMode");
246         }
247         else {
248                 if(videosc_dir[0]==0) strcpy(videosc_dir, G.sce);
249                 activate_fileselect(FILE_SPECIAL, "SAVE VIDEOSCAPE", videosc_dir, write_videoscape);
250         }
251 }
252
253 void write_vrml_fs()
254 {
255         if(G.obedit) {
256                 error("Can't save VRML. Press TAB to leave EditMode");
257         }
258         else {
259                 if(videosc_dir[0]==0) strcpy(videosc_dir, G.sce);
260         
261                 activate_fileselect(FILE_SPECIAL, "SAVE VRML1", videosc_dir, write_vrml);
262         }
263         
264 }
265
266 void write_dxf_fs()
267 {
268         if(G.obedit) {
269                 error("Can't save DXF. Press TAB to leave EditMode");
270         }
271         else {
272
273                 if(videosc_dir[0]==0) strcpy(videosc_dir, G.sce);
274
275                 activate_fileselect(FILE_SPECIAL, "SAVE DXF", videosc_dir, write_dxf);  
276         }
277 }
278
279 /* ********************** GLOBAL ****************************** */
280
281 static int std_libbuttons(uiBlock *block, int xco, int pin, short *pinpoin, int browse, ID *id, ID *parid, short *menupoin, int users, int lib, int del, int autobut, int keepbut)
282 {
283         ListBase *lb;
284         Object *ob;
285         Ipo *ipo;
286         uiBut *but;
287         int len, idwasnul=0, idtype, oldcol;
288         char *str=NULL, str1[10];
289         
290         oldcol= uiBlockGetCol(block);
291
292         if(id && pin) {
293                 uiDefIconButS(block, ICONTOG, pin, ICON_PIN_DEHLT,      (short)xco,0,XIC,YIC, pinpoin, 0, 0, 0, 0, "Pin this data block; no update according Object selection");
294                 xco+= XIC;
295         }
296         if(browse) {
297                 if(id==0) {
298                         idwasnul= 1;
299                         /* only the browse button */
300                         ob= OBACT;
301                         if(curarea->spacetype==SPACE_IMAGE) {
302                                 id= G.main->image.first;
303                         }
304                         else if(curarea->spacetype==SPACE_SOUND) {
305                                 id= G.main->sound.first;
306                         }
307                         else if(curarea->spacetype==SPACE_ACTION) {
308                                 id= G.main->action.first;
309                         }
310                         else if(curarea->spacetype==SPACE_NLA) {
311                                 id=NULL;
312                         }
313                         else if(curarea->spacetype==SPACE_IPO) {
314                                 id= G.main->ipo.first;
315                                 /* test for ipotype */
316                                 while(id) {
317                                         ipo= (Ipo *)id;
318                                         if(G.sipo->blocktype==ipo->blocktype) break;
319                                         id= id->next;
320                                 }
321                         }
322                         else if(curarea->spacetype==SPACE_BUTS) {
323                                 if(browse==B_WORLDBROWSE) {
324                                         id= G.main->world.first;
325                                 }
326                                 else if(ob && ob->type && (ob->type<OB_LAMP)) {
327                                         if(G.buts->mainb==BUTS_MAT) id= G.main->mat.first;
328                                         else if(G.buts->mainb==BUTS_TEX) id= G.main->tex.first;
329                                 }
330                         }
331                         else if(curarea->spacetype==SPACE_TEXT) {
332                                 id= G.main->text.first;
333                         }
334                 }
335                 if(id) {
336                         char *extrastr= NULL;
337                         
338                         idtype= GS(id->name);
339                         lb= wich_libbase(G.main, GS(id->name));
340                         
341                         if(idwasnul) id= NULL;
342                         else if(id->us>1) uiBlockSetCol(block, BUTDBLUE);
343
344                         if (pin && *pinpoin) {
345                                 uiBlockSetCol(block, BUTDPINK);
346                         }
347                         
348                         if ELEM7( idtype, ID_SCE, ID_SCR, ID_MA, ID_TE, ID_WO, ID_IP, ID_AC) extrastr= "ADD NEW %x 32767";
349                         else if (idtype==ID_TXT) extrastr= "OPEN NEW %x 32766 |ADD NEW %x 32767";
350                         else if (idtype==ID_SO) extrastr= "OPEN NEW %x 32766";
351                         
352                         uiSetButLock(G.scene->id.lib!=0, "Can't edit library data");
353                         if( idtype==ID_SCE || idtype==ID_SCR ) uiClearButLock();
354                         
355                         if(curarea->spacetype==SPACE_BUTS)
356                                 uiSetButLock(idtype!=ID_SCR && G.obedit!=0 && G.buts->mainb==BUTS_EDIT, NULL);
357                         
358                         if(parid) uiSetButLock(parid->lib!=0, "Can't edit library data");
359
360                         if (lb) {
361                                 if( idtype==ID_IP)
362                                         IPOnames_to_pupstring(&str, NULL, extrastr, lb, id, menupoin, G.sipo->blocktype);
363                                 else
364                                         IDnames_to_pupstring(&str, NULL, extrastr, lb, id, menupoin);
365                         }
366                         
367                         uiDefButS(block, MENU, browse, str, (short)xco,0,XIC,YIC, menupoin, 0, 0, 0, 0, "Browse Datablock or Add NEW");
368                         
369                         uiClearButLock();
370                 
371                         MEM_freeN(str);
372                         xco+= XIC;
373                 }
374                 else if(curarea->spacetype==SPACE_BUTS) {
375                         if ELEM3(G.buts->mainb, BUTS_MAT, BUTS_TEX, BUTS_WORLD) {
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                                 uiDefButS(block, MENU, browse, "ADD NEW %x 32767",(short) xco,0,XIC,YIC, menupoin, 0, 0, 0, 0, "Browse Datablock");
379                                 uiClearButLock();
380                         } else if (G.buts->mainb == BUTS_SOUND) {
381                                 uiDefButS(block, MENU, browse, "OPEN NEW %x 32766",(short) xco,0,XIC,YIC, menupoin, 0, 0, 0, 0, "Browse Datablock");
382                         }
383                 }
384                 else if(curarea->spacetype==SPACE_TEXT) {
385                         uiDefButS(block, MENU, browse, "OPEN NEW %x 32766 | ADD NEW %x 32767", (short)xco,0,XIC,YIC, menupoin, 0, 0, 0, 0, "Browse Datablock");
386                 }
387                 else if(curarea->spacetype==SPACE_SOUND) {
388                         uiDefButS(block, MENU, browse, "OPEN NEW %x 32766",(short)xco,0,XIC,YIC, menupoin, 0, 0, 0, 0, "Browse Datablock");
389                 }
390                 else if(curarea->spacetype==SPACE_NLA) {
391                 }
392                 else if(curarea->spacetype==SPACE_ACTION) {
393                         uiSetButLock(G.scene->id.lib!=0, "Can't edit library data");
394                         if(parid) uiSetButLock(parid->lib!=0, "Can't edit library data");
395
396                         uiDefButS(block, MENU, browse, "ADD NEW %x 32767", xco,0,XIC,YIC, menupoin, 0, 0, 0, 0, "Browse Datablock");
397                         uiClearButLock();
398                 }
399                 else if(curarea->spacetype==SPACE_IPO) {
400                         uiSetButLock(G.scene->id.lib!=0, "Can't edit library data");
401                         if(parid) uiSetButLock(parid->lib!=0, "Can't edit library data");
402
403                         uiDefButS(block, MENU, browse, "ADD NEW %x 32767", (short)xco,0,XIC,YIC, menupoin, 0, 0, 0, 0, "Browse Datablock");
404                         uiClearButLock();
405                 }
406         }
407
408
409         uiBlockSetCol(block, oldcol);
410
411         if(id) {
412         
413                 /* name */
414                 if(id->us>1) uiBlockSetCol(block, BUTDBLUE);
415                 /* Pinned data ? */
416                 if (pin && *pinpoin) {
417                         uiBlockSetCol(block, BUTDPINK);
418                 }
419                 /* Redalert overrides pin color */
420                 if(id->us<=0) uiBlockSetCol(block, REDALERT);
421
422                 uiSetButLock(id->lib!=0, "Can't edit library data");
423                 
424                 str1[0]= id->name[0];
425                 str1[1]= id->name[1];
426                 str1[2]= ':';
427                 str1[3]= 0;
428                 if(strcmp(str1, "SC:")==0) strcpy(str1, "SCE:");
429                 else if(strcmp(str1, "SR:")==0) strcpy(str1, "SCR:");
430                 
431                 if( GS(id->name)==ID_IP) len= 110;
432                 else len= 120;
433                 
434                 but= uiDefBut(block, TEX, B_IDNAME, str1,(short)xco, 0, (short)len, YIC, id->name+2, 0.0, 19.0, 0, 0, "Datablock name");
435                 uiButSetFunc(but, test_idbutton_cb, id->name, NULL);
436
437                 uiClearButLock();
438
439                 xco+= len;
440                 
441                 if(id->lib) {
442                         
443                         if(parid && parid->lib) uiDefIconBut(block, BUT, 0, ICON_DATALIB,(short)xco,0,XIC,YIC, 0, 0, 0, 0, 0, "Indirect Library Datablock");
444                         else uiDefIconBut(block, BUT, lib, ICON_PARLIB, (short)xco,0,XIC,YIC, 0, 0, 0, 0, 0, "Library DataBlock, press to make local");
445                         
446                         xco+= XIC;
447                 }
448                 
449                 
450                 if(users && id->us>1) {
451                         uiSetButLock (pin && *pinpoin, "Can't make pinned data single-user");
452                         
453                         sprintf(str1, "%d", id->us);
454                         if(id->us<100) {
455                                 
456                                 uiDefBut(block, BUT, users, str1,       (short)xco,0,XIC,YIC, 0, 0, 0, 0, 0, "Number of users,  press to make single-user");
457                                 xco+= XIC;
458                         }
459                         else {
460                                 uiDefBut(block, BUT, users, str1,       (short)xco, 0, XIC+10, YIC, 0, 0, 0, 0, 0, "Number of users,  press to make single-user");
461                                 xco+= XIC+10;
462                         }
463                         
464                         uiClearButLock();
465                         
466                 }
467                 
468                 if(del) {
469
470                         uiSetButLock (pin && *pinpoin, "Can't unlink pinned data");
471                         if(parid && parid->lib);
472                         else {
473                                 uiDefIconBut(block, BUT, del, ICON_X,   (short)xco,0,XIC,YIC, 0, 0, 0, 0, 0, "Delete link to this Datablock");
474                                 xco+= XIC;
475                         }
476
477                         uiClearButLock();
478                 }
479
480                 if(autobut) {
481                         if(parid && parid->lib);
482                         else {
483                                 uiDefIconBut(block, BUT, autobut, ICON_AUTO,(short)xco,0,XIC,YIC, 0, 0, 0, 0, 0, "Automatic name");
484                                 xco+= XIC;
485                         }
486                         
487                         
488                 }
489                 if(keepbut) {
490                         uiDefBut(block, BUT, keepbut, "F", (short)xco,0,XIC,YIC, 0, 0, 0, 0, 0, "Keep Datablock");      
491                         xco+= XIC;
492                 }
493         }
494         else xco+=XIC;
495         
496         uiBlockSetCol(block, oldcol);
497
498         return xco;
499 }
500
501 void update_for_newframe(void)
502 {
503         allqueue(REDRAWVIEW3D, 0);
504         allqueue(REDRAWACTION,0);
505         allqueue(REDRAWNLA,0);
506         allqueue(REDRAWIPO, 0);
507         allqueue(REDRAWINFO, 1);
508         allqueue(REDRAWSEQ, 1);
509         allqueue(REDRAWSOUND, 1);
510         allqueue(REDRAWBUTSHEAD, 1);
511         allqueue(REDRAWBUTSMAT, 1);
512         allqueue(REDRAWBUTSLAMP, 1);
513
514         /* layers/materials, object ipos are calculted in where_is_object (too) */
515         do_all_ipos();
516         BPY_do_all_scripts(SCRIPT_FRAMECHANGED);
517         do_all_keys();
518         do_all_actions();
519         do_all_ikas();
520
521         test_all_displists();
522 }
523
524 static void show_splash(void)
525 {
526         extern char datatoc_splash_jpg[];
527         extern int datatoc_splash_jpg_size;
528         char *string = NULL;
529
530 #ifdef NAN_BUILDINFO
531         char buffer[1024];
532         extern char * build_date;
533         extern char * build_time;
534         extern char * build_platform;
535         extern char * build_type;
536
537         string = &buffer[0];
538         sprintf(string,"Built on %s %s     Version %s %s", build_date, build_time, build_platform, build_type);
539 #endif
540
541         splash((void *)datatoc_splash_jpg, datatoc_splash_jpg_size, string);
542 }
543
544
545 /* Functions for user preferences fileselect windows */
546
547 void filesel_u_fontdir(char *name)
548 {
549         char dir[FILE_MAXDIR], file[FILE_MAXFILE];
550         BLI_split_dirfile(name, dir, file);
551
552         strcpy(U.fontdir, dir);
553         allqueue(REDRAWALL, 0);
554 }
555
556 void filesel_u_textudir(char *name)
557 {
558         char dir[FILE_MAXDIR], file[FILE_MAXFILE];
559         BLI_split_dirfile(name, dir, file);
560
561         strcpy(U.textudir, dir);
562         allqueue(REDRAWALL, 0);
563 }
564
565 void filesel_u_plugtexdir(char *name)
566 {
567         char dir[FILE_MAXDIR], file[FILE_MAXFILE];
568         BLI_split_dirfile(name, dir, file);
569
570         strcpy(U.plugtexdir, dir);
571         allqueue(REDRAWALL, 0);
572 }
573
574 void filesel_u_plugseqdir(char *name)
575 {
576         char dir[FILE_MAXDIR], file[FILE_MAXFILE];
577         BLI_split_dirfile(name, dir, file);
578
579         strcpy(U.plugseqdir, dir);
580         allqueue(REDRAWALL, 0);
581 }
582
583 void filesel_u_renderdir(char *name)
584 {
585         char dir[FILE_MAXDIR], file[FILE_MAXFILE];
586         BLI_split_dirfile(name, dir, file);
587
588         strcpy(U.renderdir, dir);
589         allqueue(REDRAWALL, 0);
590 }
591
592 void filesel_u_pythondir(char *name)
593 {
594         char dir[FILE_MAXDIR], file[FILE_MAXFILE];
595         BLI_split_dirfile(name, dir, file);
596
597         strcpy(U.pythondir, dir);
598         allqueue(REDRAWALL, 0);
599 }
600
601 void filesel_u_sounddir(char *name)
602 {
603         char dir[FILE_MAXDIR], file[FILE_MAXFILE];
604         BLI_split_dirfile(name, dir, file);
605
606         strcpy(U.sounddir, dir);
607         allqueue(REDRAWALL, 0);
608 }
609
610 void filesel_u_tempdir(char *name)
611 {
612         char dir[FILE_MAXDIR], file[FILE_MAXFILE];
613         BLI_split_dirfile(name, dir, file);
614
615         strcpy(U.tempdir, dir);
616         allqueue(REDRAWALL, 0);
617 }
618
619 /* END Functions for user preferences fileselect windows */
620
621
622 void do_global_buttons(unsigned short event)
623 {
624         ListBase *lb;
625         Object *ob;
626         Material *ma;
627         MTex *mtex;
628         Ipo *ipo;
629         Lamp *la;
630         World *wrld;
631         Sequence *seq;
632         bAction *act;
633         ID *id, *idtest, *from;
634         ScrArea *sa;
635         int nr= 1;
636         char buf[FILE_MAXDIR+FILE_MAXFILE];
637
638         
639         ob= OBACT;
640         
641         id= 0;  /* id at null for texbrowse */
642         
643
644         switch(event) {
645         
646         case B_NEWFRAME:
647                 scrarea_queue_winredraw(curarea);
648                 scrarea_queue_headredraw(curarea);
649
650                 update_for_newframe();
651                 break;          
652         case B_REDR:
653                 scrarea_queue_winredraw(curarea);
654                 scrarea_queue_headredraw(curarea);
655                 break;
656         case B_EDITBROWSE:
657                 if(ob==0) return;
658                 if(ob->id.lib) return;
659                 id= ob->data;
660                 if(id==0) return;
661
662                 if(G.buts->menunr== -2) {
663                         activate_databrowse((ID *)G.buts->lockpoin, GS(id->name), 0, B_EDITBROWSE, &G.buts->menunr, do_global_buttons);
664                         return;
665                 }
666                 if(G.buts->menunr < 0) return;
667                 
668                 lb= wich_libbase(G.main, GS(id->name));
669                 idtest= lb->first;
670                 while(idtest) {
671                         if(nr==G.buts->menunr) {
672                                 if(idtest!=id) {
673                                         id->us--;
674                                         id_us_plus(idtest);
675                                         
676                                         ob->data= idtest;
677                                         
678                                         test_object_materials(idtest);
679                                         
680                                         if( GS(idtest->name)==ID_CU ) {
681                                                 test_curve_type(ob);
682                                                 allqueue(REDRAWBUTSEDIT, 0);
683                                                 makeDispList(ob);
684                                         }
685                                         else if( ob->type==OB_MESH ) {
686                                                 makeDispList(ob);
687                                         }
688                                         
689                                         allqueue(REDRAWBUTSEDIT, 0);
690                                         allqueue(REDRAWVIEW3D, 0);
691                                         allqueue(REDRAWACTION,0);
692                                         allqueue(REDRAWIPO, 0);
693                                         allqueue(REDRAWNLA,0);
694                                 }
695                                 break;
696                         }
697                         nr++;
698                         idtest= idtest->next;
699                 }
700
701                 break;
702         case B_MESHBROWSE:
703                 if(ob==0) return;
704                 if(ob->id.lib) return;
705                 
706                 id= ob->data;
707                 if(id==0) id= G.main->mesh.first;
708                 if(id==0) return;
709                 
710                 if(G.buts->menunr== -2) {
711                         activate_databrowse((ID *)G.buts->lockpoin, GS(id->name), 0, B_MESHBROWSE, &G.buts->menunr, do_global_buttons);
712                         return;
713                 }
714                 if(G.buts->menunr < 0) return;
715                 
716
717                 idtest= G.main->mesh.first;
718                 while(idtest) {
719                         if(nr==G.buts->menunr) {
720                                         
721                                 set_mesh(ob, (Mesh *)idtest);
722                                 
723                                 allqueue(REDRAWBUTSEDIT, 0);
724                                 allqueue(REDRAWVIEW3D, 0);
725                                 allqueue(REDRAWACTION,0);
726                                 allqueue(REDRAWIPO, 0);
727
728                                 break;
729                         }
730                         nr++;
731                         idtest= idtest->next;
732                 }
733
734                 break;
735         case B_MATBROWSE:
736                 if(G.buts->menunr== -2) {
737                         activate_databrowse((ID *)G.buts->lockpoin, ID_MA, 0, B_MATBROWSE, &G.buts->menunr, do_global_buttons);
738                         return;
739                 }
740                 
741                 if(G.buts->menunr < 0) return;
742                 
743                 if(G.buts->pin) {
744                         
745                 }
746                 else {
747                         
748                         ma= give_current_material(ob, ob->actcol);
749                         nr= 1;
750                         
751                         id= (ID *)ma;
752                         
753                         idtest= G.main->mat.first;
754                         while(idtest) {
755                                 if(nr==G.buts->menunr) {
756                                         break;
757                                 }
758                                 nr++;
759                                 idtest= idtest->next;
760                         }
761                         if(idtest==0) { /* new mat */
762                                 if(id)  idtest= (ID *)copy_material((Material *)id);
763                                 else {
764                                         idtest= (ID *)add_material("Material");
765                                 }
766                                 idtest->us--;
767                         }
768                         if(idtest!=id) {
769                                 assign_material(ob, (Material *)idtest, ob->actcol);
770                                 
771                                 allqueue(REDRAWBUTSHEAD, 0);
772                                 allqueue(REDRAWBUTSMAT, 0);
773                                 allqueue(REDRAWIPO, 0);
774                                 BIF_preview_changed(G.buts);
775                         }
776                         
777                 }
778                 break;
779         case B_MATDELETE:
780                 if(G.buts->pin) {
781                         
782                 }
783                 else {
784                         ma= give_current_material(ob, ob->actcol);
785                         if(ma) {
786                                 assign_material(ob, 0, ob->actcol);
787                                 allqueue(REDRAWBUTSHEAD, 0);
788                                 allqueue(REDRAWBUTSMAT, 0);
789                                 allqueue(REDRAWIPO, 0);
790                                 BIF_preview_changed(G.buts);
791                         }
792                 }
793                 break;
794         case B_TEXDELETE:
795                 if(G.buts->pin) {
796                         
797                 }
798                 else {
799                         if(G.buts->texfrom==0) {        /* from mat */
800                                 ma= give_current_material(ob, ob->actcol);
801                                 if(ma) {
802                                         mtex= ma->mtex[ ma->texact ];
803                                         if(mtex) {
804                                                 if(mtex->tex) mtex->tex->id.us--;
805                                                 MEM_freeN(mtex);
806                                                 ma->mtex[ ma->texact ]= 0;
807                                                 allqueue(REDRAWBUTSTEX, 0);
808                                                 allqueue(REDRAWIPO, 0);
809                                                 BIF_preview_changed(G.buts);
810                                         }
811                                 }
812                         }
813                         else if(G.buts->texfrom==1) {   /* from world */
814                                 wrld= G.scene->world;
815                                 if(wrld) {
816                                         mtex= wrld->mtex[ wrld->texact ];
817                                         if(mtex) {
818                                                 if(mtex->tex) mtex->tex->id.us--;
819                                                 MEM_freeN(mtex);
820                                                 wrld->mtex[ wrld->texact ]= 0;
821                                                 allqueue(REDRAWBUTSTEX, 0);
822                                                 allqueue(REDRAWIPO, 0);
823                                                 BIF_preview_changed(G.buts);
824                                         }
825                                 }
826                         }
827                         else {  /* from lamp */
828                                 la= ob->data;
829                                 if(la && ob->type==OB_LAMP) {   /* to be sure */
830                                         mtex= la->mtex[ la->texact ];
831                                         if(mtex) {
832                                                 if(mtex->tex) mtex->tex->id.us--;
833                                                 MEM_freeN(mtex);
834                                                 la->mtex[ la->texact ]= 0;
835                                                 allqueue(REDRAWBUTSTEX, 0);
836                                                 allqueue(REDRAWIPO, 0);
837                                                 BIF_preview_changed(G.buts);
838                                         }
839                                 }
840                         }
841                 }
842                 break;
843         case B_EXTEXBROWSE:     
844         case B_TEXBROWSE:
845
846                 if(G.buts->texnr== -2) {
847                         
848                         id= G.buts->lockpoin;
849                         if(event==B_EXTEXBROWSE) {
850                                 id= 0;
851                                 ma= give_current_material(ob, ob->actcol);
852                                 if(ma) {
853                                         mtex= ma->mtex[ ma->texact ];
854                                         if(mtex) id= (ID *)mtex->tex;
855                                 }
856                         }
857                         
858                         activate_databrowse(id, ID_TE, 0, B_TEXBROWSE, &G.buts->texnr, do_global_buttons);
859                         return;
860                 }
861                 if(G.buts->texnr < 0) break;
862                 
863                 if(G.buts->pin) {
864                         
865                 }
866                 else {
867                         id= 0;
868                         
869                         ma= give_current_material(ob, ob->actcol);
870                         if(ma) {
871                                 mtex= ma->mtex[ ma->texact ];
872                                 if(mtex) id= (ID *)mtex->tex;
873                         }
874
875                         idtest= G.main->tex.first;
876                         while(idtest) {
877                                 if(nr==G.buts->texnr) {
878                                         break;
879                                 }
880                                 nr++;
881                                 idtest= idtest->next;
882                         }
883                         if(idtest==0) { /* new tex */
884                                 if(id)  idtest= (ID *)copy_texture((Tex *)id);
885                                 else idtest= (ID *)add_texture("Tex");
886                                 idtest->us--;
887                         }
888                         if(idtest!=id && ma) {
889                                 
890                                 if( ma->mtex[ma->texact]==0) ma->mtex[ma->texact]= add_mtex();
891                                 
892                                 ma->mtex[ ma->texact ]->tex= (Tex *)idtest;
893                                 id_us_plus(idtest);
894                                 if(id) id->us--;
895                                 
896                                 allqueue(REDRAWBUTSHEAD, 0);
897                                 allqueue(REDRAWBUTSTEX, 0);
898                                 allqueue(REDRAWBUTSMAT, 0);
899                                 allqueue(REDRAWIPO, 0);
900                                 BIF_preview_changed(G.buts);
901                         }
902                 }
903                 break;
904         case B_ACTIONDELETE:
905                 act=ob->action;
906                 
907                 if (act)
908                         act->id.us--;
909                 ob->action=NULL;
910                 allqueue(REDRAWACTION, 0);
911                 allqueue(REDRAWNLA, 0);
912                 allqueue(REDRAWIPO, 0);
913                 break;
914         case B_ACTIONBROWSE:
915                 if (!ob)
916                         break;
917                 act=ob->action;
918                 id= (ID *)act;
919
920                 if (G.saction->actnr== -2){
921                                 activate_databrowse((ID *)G.saction->action, ID_AC,  0, B_ACTIONBROWSE, &G.saction->actnr, do_global_buttons);
922                         return;
923                 }
924
925                 if(G.saction->actnr < 0) break;
926
927                 /*      See if we have selected a valid action */
928                 for (idtest= G.main->action.first; idtest; idtest= idtest->next) {
929                                 if(nr==G.saction->actnr) {
930                                         break;
931                                 }
932                                 nr++;
933                         
934                 }
935
936                 if(G.saction->pin) {
937                         G.saction->action= (bAction *)idtest;
938                         allqueue(REDRAWACTION, 0);
939                 }
940                 else {
941
942                         /* Store current action */
943                         if (!idtest){
944                                 if (act)
945                                         idtest= (ID *)copy_action(act);
946                                 else 
947                                         idtest=(ID *)add_empty_action();
948                                 idtest->us--;
949                         }
950                         
951                         
952                         if(idtest!=id && ob) {
953                                 act= (bAction *)idtest;
954                                 
955                                 ob->action= act;
956                                 ob->activecon=NULL;
957                                 id_us_plus(idtest);
958                                 
959                                 if(id) id->us--;
960                                 
961                                 // Update everything
962                                 do_global_buttons (B_NEWFRAME);
963                                 allqueue(REDRAWVIEW3D, 0);
964                                 allqueue(REDRAWNLA, 0);
965                                 allqueue(REDRAWACTION, 0);
966                                 allqueue(REDRAWHEADERS, 0);     
967                         }
968                 }
969                 
970                 break;
971         case B_IPOBROWSE:
972
973                 ipo= get_ipo_to_edit(&from);
974                 id= (ID *)ipo;
975                 if(from==0) return;
976
977                 if(G.sipo->menunr== -2) {
978                         activate_databrowse((ID *)G.sipo->ipo, ID_IP, GS(from->name), B_IPOBROWSE, &G.sipo->menunr, do_global_buttons);
979                         return;
980                 }
981
982                 if(G.sipo->menunr < 0) break;
983
984                 idtest= G.main->ipo.first;
985                 while(idtest) {
986                         if( ((Ipo *)idtest)->blocktype == G.sipo->blocktype) {
987                                 if(nr==G.sipo->menunr) {
988                                         break;
989                                 }
990                                 nr++;
991                         }
992                         idtest= idtest->next;
993                 }
994
995                 if(G.sipo->pin) {
996                         if(idtest) {
997                                 G.sipo->ipo= (Ipo *)idtest;
998                                 allspace(REMAKEIPO, 0);         // in fact it should only do this one, but there is no function for it
999                         }
1000                 }
1001                 else {
1002                         // assign the ipo to ...
1003
1004                         if(idtest==0) {
1005                                 if(ipo) idtest= (ID *)copy_ipo(ipo);
1006                                 else {
1007                                         nr= GS(from->name);
1008                                         if(nr==ID_OB){
1009                                                 if (G.sipo->blocktype==IPO_CO)
1010                                                         idtest= (ID *)add_ipo("CoIpo", IPO_CO); /* BLEARGH! */
1011                                                 else
1012                                                         idtest= (ID *)add_ipo("ObIpo", nr);
1013                                         }
1014                                         else if(nr==ID_MA) idtest= (ID *)add_ipo("MatIpo", nr);
1015                                         else if(nr==ID_SEQ) idtest= (ID *)add_ipo("MatSeq", nr);
1016                                         else if(nr==ID_CU) idtest= (ID *)add_ipo("CuIpo", nr);
1017                                         else if(nr==ID_KE) idtest= (ID *)add_ipo("KeyIpo", nr);
1018                                         else if(nr==ID_WO) idtest= (ID *)add_ipo("WoIpo", nr);
1019                                         else if(nr==ID_LA) idtest= (ID *)add_ipo("LaIpo", nr);
1020                                         else if(nr==ID_CA) idtest= (ID *)add_ipo("CaIpo", nr);
1021                                         else if(nr==ID_SO) idtest= (ID *)add_ipo("SndIpo", nr);
1022                                         else if(nr==ID_AC) idtest= (ID *)add_ipo("ActIpo", nr);
1023                                         else error("Warn bugs@blender.nl!");
1024                                 }
1025                                 idtest->us--;
1026                         }
1027                         if(idtest!=id && from) {
1028                                 ipo= (Ipo *)idtest;
1029                 
1030                                 if (ipo->blocktype==IPO_CO){
1031                                         ((Object*)from)->activecon->ipo = ipo;
1032                                         id_us_plus(idtest);
1033                                         allqueue(REDRAWVIEW3D, 0);
1034                                         allqueue(REDRAWACTION, 0);
1035                                         allqueue(REDRAWNLA, 0);
1036                                 }
1037                                 else if(ipo->blocktype==ID_OB) {
1038                                         ( (Object *)from)->ipo= ipo;
1039                                         id_us_plus(idtest);
1040                                         allqueue(REDRAWVIEW3D, 0);
1041                                 }
1042                                 else if(ipo->blocktype==ID_AC) {
1043                                         bActionChannel *chan;
1044                                         chan = get_hilighted_action_channel ((bAction*)from);
1045                                         if (!chan){
1046                                                 error ("Create an action channel first");
1047                                                 return;
1048                                         }
1049                                         chan->ipo=ipo;
1050                                         id_us_plus(idtest);
1051                                         allqueue(REDRAWNLA, 0);
1052                                         allqueue(REDRAWACTION, 0);
1053                                 }
1054                                 else if(ipo->blocktype==ID_MA) {
1055                                         ( (Material *)from)->ipo= ipo;
1056                                         id_us_plus(idtest);
1057                                         allqueue(REDRAWBUTSMAT, 0);
1058                                 }
1059                                 else if(ipo->blocktype==ID_SEQ) {
1060                                         seq= (Sequence *)from;
1061                                         if(seq->type & SEQ_EFFECT) {
1062                                                 id_us_plus(idtest);
1063                                                 seq->ipo= ipo;
1064                                         }
1065                                 }
1066                                 else if(ipo->blocktype==ID_CU) {
1067                                         ( (Curve *)from)->ipo= ipo;
1068                                         id_us_plus(idtest);
1069                                         allqueue(REDRAWVIEW3D, 0);
1070                                 }
1071                                 else if(ipo->blocktype==ID_KE) {
1072                                         ( (Key *)from)->ipo= ipo;
1073                                         
1074                                         id_us_plus(idtest);
1075                                         allqueue(REDRAWVIEW3D, 0);
1076                                         
1077                                 }
1078                                 else if(ipo->blocktype==ID_WO) {
1079                                         ( (World *)from)->ipo= ipo;
1080                                         id_us_plus(idtest);
1081                                         allqueue(REDRAWBUTSWORLD, 0);
1082                                 }
1083                                 else if(ipo->blocktype==ID_LA) {
1084                                         ( (Lamp *)from)->ipo= ipo;
1085                                         id_us_plus(idtest);
1086                                         allqueue(REDRAWBUTSLAMP, 0);
1087                                 }
1088                                 else if(ipo->blocktype==ID_CA) {
1089                                         ( (Camera *)from)->ipo= ipo;
1090                                         id_us_plus(idtest);
1091                                         allqueue(REDRAWBUTSEDIT, 0);
1092                                 }
1093                                 else if(ipo->blocktype==ID_SO) {
1094                                         ( (bSound *)from)->ipo= ipo;
1095                                         id_us_plus(idtest);
1096                                         allqueue(REDRAWBUTSEDIT, 0);
1097                                 }
1098                                 else
1099                                         printf("error in browse ipo \n");
1100                                 
1101                                 if(id) id->us--;
1102                                 
1103                                 scrarea_queue_winredraw(curarea);
1104                                 scrarea_queue_headredraw(curarea);
1105                                 allqueue(REDRAWIPO, 0);
1106                         }
1107                 }
1108                 break;
1109         case B_IPODELETE:
1110                 ipo= get_ipo_to_edit(&from);
1111                 if(from==0) return;
1112                 
1113                 ipo->id.us--;
1114                 
1115                 if(ipo->blocktype==ID_OB) ( (Object *)from)->ipo= 0;
1116                 else if(ipo->blocktype==ID_MA) ( (Material *)from)->ipo= 0;
1117                 else if(ipo->blocktype==ID_SEQ) ( (Sequence *)from)->ipo= 0;
1118                 else if(ipo->blocktype==ID_CU) ( (Curve *)from)->ipo= 0;
1119                 else if(ipo->blocktype==ID_KE) ( (Key *)from)->ipo= 0;
1120                 else if(ipo->blocktype==ID_WO) ( (World *)from)->ipo= 0;
1121                 else if(ipo->blocktype==ID_LA) ( (Lamp *)from)->ipo= 0;
1122                 else if(ipo->blocktype==ID_WO) ( (World *)from)->ipo= 0;
1123                 else if(ipo->blocktype==ID_CA) ( (Camera *)from)->ipo= 0;
1124                 else if(ipo->blocktype==ID_SO) ( (bSound *)from)->ipo= 0;
1125                 else if(ipo->blocktype==ID_AC) {
1126                         bAction *act = (bAction*) from;
1127                         bActionChannel *chan = 
1128                                 get_hilighted_action_channel((bAction*)from);
1129                         BLI_freelinkN (&act->chanbase, chan);
1130                 }
1131                 else if(ipo->blocktype==IPO_CO) ((Object *)from)->activecon->ipo= 0;
1132
1133                 else error("Warn bugs@blender.nl!");
1134                 
1135                 editipo_changed(G.sipo, 1);     /* doredraw */
1136                 allqueue(REDRAWIPO, 0);
1137                 allqueue(REDRAWNLA, 0);
1138                 allqueue (REDRAWACTION, 0);
1139                 
1140                 break;
1141         case B_WORLDBROWSE:
1142
1143                 if(G.buts->menunr==-2) {
1144                         activate_databrowse((ID *)G.scene->world, ID_WO, 0, B_WORLDBROWSE, &G.buts->menunr, do_global_buttons);
1145                         break;
1146                 }
1147
1148                 if(G.buts->menunr < 0) break;
1149                 /* no lock */
1150                         
1151                 wrld= G.scene->world;
1152                 nr= 1;
1153                 
1154                 id= (ID *)wrld;
1155                 
1156                 idtest= G.main->world.first;
1157                 while(idtest) {
1158                         if(nr==G.buts->menunr) {
1159                                 break;
1160                         }
1161                         nr++;
1162                         idtest= idtest->next;
1163                 }
1164                 if(idtest==0) { /* new world */
1165                         if(id) idtest= (ID *)copy_world((World *)id);
1166                         else idtest= (ID *)add_world("World");
1167                         idtest->us--;
1168                 }
1169                 if(idtest!=id) {
1170                         G.scene->world= (World *)idtest;
1171                         id_us_plus(idtest);
1172                         if(id) id->us--;
1173                         
1174                         allqueue(REDRAWBUTSHEAD, 0);
1175                         allqueue(REDRAWBUTSWORLD, 0);
1176                         allqueue(REDRAWIPO, 0);
1177                         BIF_preview_changed(G.buts);
1178                 }
1179                 break;
1180         case B_WORLDDELETE:
1181                 if(G.scene->world) {
1182                         G.scene->world->id.us--;
1183                         G.scene->world= 0;
1184                         allqueue(REDRAWBUTSWORLD, 0);
1185                         allqueue(REDRAWIPO, 0);
1186                 }
1187                 
1188                 break;
1189         case B_WTEXBROWSE:
1190
1191                 if(G.buts->texnr== -2) {
1192                         id= 0;
1193                         wrld= G.scene->world;
1194                         if(wrld) {
1195                                 mtex= wrld->mtex[ wrld->texact ];
1196                                 if(mtex) id= (ID *)mtex->tex;
1197                         }
1198
1199                         activate_databrowse((ID *)id, ID_TE, 0, B_WTEXBROWSE, &G.buts->texnr, do_global_buttons);
1200                         return;
1201                 }
1202                 if(G.buts->texnr < 0) break;
1203
1204                 if(G.buts->pin) {
1205                         
1206                 }
1207                 else {
1208                         id= 0;
1209                         
1210                         wrld= G.scene->world;
1211                         if(wrld) {
1212                                 mtex= wrld->mtex[ wrld->texact ];
1213                                 if(mtex) id= (ID *)mtex->tex;
1214                         }
1215
1216                         idtest= G.main->tex.first;
1217                         while(idtest) {
1218                                 if(nr==G.buts->texnr) {
1219                                         break;
1220                                 }
1221                                 nr++;
1222                                 idtest= idtest->next;
1223                         }
1224                         if(idtest==0) { /* new tex */
1225                                 if(id)  idtest= (ID *)copy_texture((Tex *)id);
1226                                 else idtest= (ID *)add_texture("Tex");
1227                                 idtest->us--;
1228                         }
1229                         if(idtest!=id && wrld) {
1230                                 
1231                                 if( wrld->mtex[wrld->texact]==0) {
1232                                         wrld->mtex[wrld->texact]= add_mtex();
1233                                         wrld->mtex[wrld->texact]->texco= TEXCO_VIEW;
1234                                 }
1235                                 wrld->mtex[ wrld->texact ]->tex= (Tex *)idtest;
1236                                 id_us_plus(idtest);
1237                                 if(id) id->us--;
1238                                 
1239                                 allqueue(REDRAWBUTSHEAD, 0);
1240                                 allqueue(REDRAWBUTSTEX, 0);
1241                                 allqueue(REDRAWBUTSWORLD, 0);
1242                                 allqueue(REDRAWIPO, 0);
1243                                 BIF_preview_changed(G.buts);
1244                         }
1245                 }
1246                 break;
1247         case B_LAMPBROWSE:
1248                 /* no lock */
1249                 if(ob==0) return;
1250                 if(ob->type!=OB_LAMP) return;
1251
1252                 if(G.buts->menunr== -2) {
1253                         activate_databrowse((ID *)G.buts->lockpoin, ID_LA, 0, B_LAMPBROWSE, &G.buts->menunr, do_global_buttons);
1254                         return;
1255                 }
1256                 if(G.buts->menunr < 0) break;
1257                 
1258                 la= ob->data;
1259                 nr= 1;
1260                 id= (ID *)la;
1261                 
1262                 idtest= G.main->lamp.first;
1263                 while(idtest) {
1264                         if(nr==G.buts->menunr) {
1265                                 break;
1266                         }
1267                         nr++;
1268                         idtest= idtest->next;
1269                 }
1270                 if(idtest==0) { /* no new lamp */
1271                         return;
1272                 }
1273                 if(idtest!=id) {
1274                         ob->data= (Lamp *)idtest;
1275                         id_us_plus(idtest);
1276                         if(id) id->us--;
1277                         
1278                         allqueue(REDRAWBUTSHEAD, 0);
1279                         allqueue(REDRAWBUTSLAMP, 0);
1280                         allqueue(REDRAWVIEW3D, 0);
1281                         allqueue(REDRAWIPO, 0);
1282                         BIF_preview_changed(G.buts);
1283                 }
1284                 break;
1285         
1286         case B_LTEXBROWSE:
1287
1288                 if(ob==0) return;
1289                 if(ob->type!=OB_LAMP) return;
1290
1291                 if(G.buts->texnr== -2) {
1292                         id= 0;
1293                         la= ob->data;
1294                         mtex= la->mtex[ la->texact ];
1295                         if(mtex) id= (ID *)mtex->tex;
1296
1297                         activate_databrowse(id, ID_TE, 0, B_LTEXBROWSE, &G.buts->texnr, do_global_buttons);
1298                         return;
1299                 }
1300                 if(G.buts->texnr < 0) break;
1301
1302                 if(G.buts->pin) {
1303                         
1304                 }
1305                 else {
1306                         id= 0;
1307                         
1308                         la= ob->data;
1309                         mtex= la->mtex[ la->texact ];
1310                         if(mtex) id= (ID *)mtex->tex;
1311
1312                         idtest= G.main->tex.first;
1313                         while(idtest) {
1314                                 if(nr==G.buts->texnr) {
1315                                         break;
1316                                 }
1317                                 nr++;
1318                                 idtest= idtest->next;
1319                         }
1320                         if(idtest==0) { /* new tex */
1321                                 if(id)  idtest= (ID *)copy_texture((Tex *)id);
1322                                 else idtest= (ID *)add_texture("Tex");
1323                                 idtest->us--;
1324                         }
1325                         if(idtest!=id && la) {
1326                                 
1327                                 if( la->mtex[la->texact]==0) {
1328                                         la->mtex[la->texact]= add_mtex();
1329                                         la->mtex[la->texact]->texco= TEXCO_GLOB;
1330                                 }
1331                                 la->mtex[ la->texact ]->tex= (Tex *)idtest;
1332                                 id_us_plus(idtest);
1333                                 if(id) id->us--;
1334                                 
1335                                 allqueue(REDRAWBUTSHEAD, 0);
1336                                 allqueue(REDRAWBUTSTEX, 0);
1337                                 allqueue(REDRAWBUTSLAMP, 0);
1338                                 allqueue(REDRAWIPO, 0);
1339                                 BIF_preview_changed(G.buts);
1340                         }
1341                 }
1342                 break;
1343         
1344         case B_IMAGEDELETE:
1345                 G.sima->image= 0;
1346                 image_changed(G.sima, 0);
1347                 allqueue(REDRAWIMAGE, 0);
1348                 break;
1349         
1350         case B_AUTOMATNAME:
1351                 automatname(G.buts->lockpoin);
1352                 allqueue(REDRAWBUTSHEAD, 0);
1353                 break;          
1354         case B_AUTOTEXNAME:
1355                 if(G.buts->mainb==BUTS_TEX) {
1356                         autotexname(G.buts->lockpoin);
1357                         allqueue(REDRAWBUTSHEAD, 0);
1358                         allqueue(REDRAWBUTSTEX, 0);
1359                 }
1360                 else if(G.buts->mainb==BUTS_MAT) {
1361                         ma= G.buts->lockpoin;
1362                         if(ma->mtex[ ma->texact]) autotexname(ma->mtex[ma->texact]->tex);
1363                         allqueue(REDRAWBUTSMAT, 0);
1364                 }
1365                 else if(G.buts->mainb==BUTS_WORLD) {
1366                         wrld= G.buts->lockpoin;
1367                         if(wrld->mtex[ wrld->texact]) autotexname(wrld->mtex[wrld->texact]->tex);
1368                         allqueue(REDRAWBUTSWORLD, 0);
1369                 }
1370                 else if(G.buts->mainb==BUTS_LAMP) {
1371                         la= G.buts->lockpoin;
1372                         if(la->mtex[ la->texact]) autotexname(la->mtex[la->texact]->tex);
1373                         allqueue(REDRAWBUTSLAMP, 0);
1374                 }
1375                 break;
1376
1377         case B_RESETAUTOSAVE:
1378                 reset_autosave();
1379                 allqueue(REDRAWINFO, 0);
1380                 break;
1381         case B_SOUNDTOGGLE:
1382                 SYS_WriteCommandLineInt(SYS_GetSystem(), "noaudio", (U.gameflags & USERDEF_DISABLE_SOUND));
1383                 break;
1384         case B_SHOWSPLASH:
1385                 show_splash();
1386                 break;
1387         case B_MIPMAPCHANGED:
1388                 set_mipmap(!(U.gameflags & USERDEF_DISABLE_SOUND));
1389                 allqueue(REDRAWVIEW3D, 0);
1390                 break;
1391         case B_NEWSPACE:
1392                 newspace(curarea, curarea->butspacetype);
1393                 break;
1394         case B_LOADTEMP:        /* is button from space.c */
1395                 BIF_read_autosavefile();
1396                 break;
1397
1398         case B_USERPREF:
1399                 allqueue(REDRAWINFO, 0);
1400 //              BIF_printf("userpref %d\n", U.userpref);
1401                 break;
1402         case B_DRAWINFO:        /* is button from space.c  *info* */
1403                 allqueue(REDRAWVIEW3D, 0);
1404                 break;
1405
1406         case B_FLIPINFOMENU:    /* is button uit space.c  *info* */
1407                 scrarea_queue_headredraw(curarea);
1408                 break;
1409
1410 #ifdef _WIN32   // FULLSCREEN
1411         case B_FLIPFULLSCREEN:
1412                 if(U.uiflag & FLIPFULLSCREEN)
1413                         U.uiflag &= ~FLIPFULLSCREEN;
1414                 else
1415                         U.uiflag |= FLIPFULLSCREEN;
1416                 mainwindow_toggle_fullscreen((U.uiflag & FLIPFULLSCREEN));
1417                 break;
1418 #endif
1419
1420         /* Fileselect windows for user preferences file paths */
1421
1422         case B_FONTDIRFILESEL:  /* is button from space.c  *info* */
1423                 if(curarea->spacetype==SPACE_INFO) {
1424                         sa= closest_bigger_area();
1425                         areawinset(sa->win);
1426                 }
1427
1428                 activate_fileselect(FILE_SPECIAL, "SELECT FONT PATH", U.fontdir, filesel_u_fontdir);
1429                 break;
1430
1431         case B_TEXTUDIRFILESEL:         /* is button from space.c  *info* */
1432                 if(curarea->spacetype==SPACE_INFO) {
1433                         sa= closest_bigger_area();
1434                         areawinset(sa->win);
1435                 }
1436
1437                 activate_fileselect(FILE_SPECIAL, "SELECT TEXTURE PATH", U.textudir, filesel_u_textudir);
1438                 break;
1439         
1440         case B_PLUGTEXDIRFILESEL:       /* is button form space.c  *info* */
1441                 if(curarea->spacetype==SPACE_INFO) {
1442                         sa= closest_bigger_area();
1443                         areawinset(sa->win);
1444                 }
1445
1446                 activate_fileselect(FILE_SPECIAL, "SELECT TEX PLUGIN PATH", U.plugtexdir, filesel_u_plugtexdir);
1447                 break;
1448         
1449         case B_PLUGSEQDIRFILESEL:       /* is button from space.c  *info* */
1450                 if(curarea->spacetype==SPACE_INFO) {
1451                         sa= closest_bigger_area();
1452                         areawinset(sa->win);
1453                 }
1454
1455                 activate_fileselect(FILE_SPECIAL, "SELECT SEQ PLUGIN PATH", U.plugseqdir, filesel_u_plugseqdir);
1456                 break;
1457         
1458         case B_RENDERDIRFILESEL:        /* is button from space.c  *info* */
1459                 if(curarea->spacetype==SPACE_INFO) {
1460                         sa= closest_bigger_area();
1461                         areawinset(sa->win);
1462                 }
1463
1464                 activate_fileselect(FILE_SPECIAL, "SELECT RENDER PATH", U.renderdir, filesel_u_renderdir);
1465                 break;
1466         
1467         case B_PYTHONDIRFILESEL:        /* is button from space.c  *info* */
1468                 if(curarea->spacetype==SPACE_INFO) {
1469                         sa= closest_bigger_area();
1470                         areawinset(sa->win);
1471                 }
1472
1473                 activate_fileselect(FILE_SPECIAL, "SELECT SCRIPT PATH", U.pythondir, filesel_u_pythondir);
1474                 break;
1475
1476         case B_SOUNDDIRFILESEL:         /* is button from space.c  *info* */
1477                 if(curarea->spacetype==SPACE_INFO) {
1478                         sa= closest_bigger_area();
1479                         areawinset(sa->win);
1480                 }
1481
1482                 activate_fileselect(FILE_SPECIAL, "SELECT SOUND PATH", U.sounddir, filesel_u_sounddir);
1483                 break;
1484
1485         case B_TEMPDIRFILESEL:  /* is button from space.c  *info* */
1486                 if(curarea->spacetype==SPACE_INFO) {
1487                         sa= closest_bigger_area();
1488                         areawinset(sa->win);
1489                 }
1490
1491                 activate_fileselect(FILE_SPECIAL, "SELECT TEMP FILE PATH", U.tempdir, filesel_u_tempdir);
1492                 break;
1493
1494         /* END Fileselect windows for user preferences file paths */
1495
1496
1497 #ifdef INTERNATIONAL
1498         case B_LOADUIFONT:      /* is button from space.c  *info* */
1499                 if(curarea->spacetype==SPACE_INFO) {
1500                         sa= closest_bigger_area();
1501                         areawinset(sa->win);
1502                 }
1503                 BLI_make_file_string("/", buf, U.fontdir, U.fontname);
1504                 activate_fileselect(FILE_SPECIAL, "LOAD UI FONT", buf, set_interface_font);
1505                 break;
1506
1507         case B_SETLANGUAGE:     /* is button from space.c  *info* */
1508                 lang_setlanguage();
1509                 allqueue(REDRAWALL, 0);
1510                 break;
1511
1512         case B_SETFONTSIZE:     /* is button from space.c  *info* */
1513                 FTF_SetSize(U.fontsize);
1514                 allqueue(REDRAWALL, 0);
1515                 break;
1516                 
1517         case B_SETTRANSBUTS:    /* is button from space.c  *info* */
1518                 allqueue(REDRAWALL, 0);
1519                 break;
1520
1521         case B_DOLANGUIFONT:    /* is button from space.c  *info* */
1522                 if(U.transopts & TR_ALL)
1523                         start_interface_font();
1524                 else
1525                         G.ui_international = FALSE;
1526                 allqueue(REDRAWALL, 0);
1527                 break;
1528 #endif
1529                 
1530         case B_FULL:
1531                 if(curarea->spacetype!=SPACE_INFO) {
1532                         area_fullscreen();
1533                 }
1534                 break;  
1535
1536         case B_IDNAME:
1537                         /* changing a metaballs name, sadly enough,
1538                          * can require it to be updated because its
1539                          * basis might have changed... -zr
1540                          */
1541                 if (OBACT && OBACT->type==OB_MBALL)
1542                         makeDispList(OBACT);
1543                         
1544                 /* redraw because name has changed: new pup */
1545                 scrarea_queue_headredraw(curarea);
1546                 allqueue(REDRAWBUTSHEAD, 0);
1547                 allqueue(REDRAWINFO, 1);
1548                 allqueue(REDRAWOOPS, 1);
1549                 /* name scene also in set PUPmenu */
1550                 if ELEM(curarea->spacetype, SPACE_BUTS, SPACE_INFO) allqueue(REDRAWBUTSALL, 0);
1551
1552                 allqueue(REDRAWHEADERS, 0);
1553
1554                 break;
1555         
1556         case B_KEEPDATA:
1557                 /* keep datablock. similar to pressing FKEY in a fileselect window
1558                  * maybe we can move that stuff to a seperate function? -- sg
1559                  */
1560                 if (curarea->spacetype==SPACE_BUTS) {
1561                         id= (ID *)G.buts->lockpoin;
1562                 } else if(curarea->spacetype==SPACE_IPO) {
1563                         id = (ID *)G.sipo->ipo;
1564                 } /* similar for other spacetypes ? */
1565                 if (id) {
1566                         if( id->flag & LIB_FAKEUSER) {
1567                                 id->flag -= LIB_FAKEUSER;
1568                                 id->us--;
1569                         } else {
1570                                 id->flag |= LIB_FAKEUSER;
1571                                 id->us++;
1572                         }
1573                 }
1574                 allqueue(REDRAWHEADERS, 0);
1575
1576                 break;
1577         }
1578 }
1579
1580
1581 void do_global_buttons2(short event)
1582 {
1583         Base *base;
1584         Object *ob;
1585         Material *ma;
1586         MTex *mtex;
1587         Mesh *me;
1588         Curve *cu;
1589         MetaBall *mb;
1590         Ipo *ipo;
1591         Lamp *la;
1592         Lattice *lt;
1593         World *wrld;
1594         ID *idfrom;     
1595         bAction *act;
1596
1597         /* general:  Single User is allowed when from==LOCAL 
1598          *                       Make Local is allowed when (from==LOCAL && id==LIB)
1599          */
1600         
1601         ob= OBACT;
1602         
1603         switch(event) {
1604                 
1605         case B_LAMPALONE:
1606                 if(ob && ob->id.lib==0) {
1607                         la= ob->data;
1608                         if(la->id.us>1) {
1609                                 if(okee("Single user")) {
1610                                         ob->data= copy_lamp(la);
1611                                         la->id.us--;
1612                                 }
1613                         }
1614                 }
1615                 break;
1616         case B_LAMPLOCAL:
1617                 if(ob && ob->id.lib==0) {
1618                         la= ob->data;
1619                         if(la->id.lib) {
1620                                 if(okee("Make local")) {
1621                                         make_local_lamp(la);
1622                                 }
1623                         }
1624                 }
1625                 break;
1626         
1627         case B_ARMLOCAL:
1628                 if (ob&&ob->id.lib==0){
1629                         bArmature *arm=ob->data;
1630                         if (arm->id.lib){
1631                                 if(okee("Make local")) {
1632                                         make_local_armature(arm);
1633                                 }
1634                         }
1635                 }
1636                 break;
1637         case B_ARMALONE:
1638                 if(ob && ob->id.lib==0) {
1639                         bArmature *arm=ob->data;
1640                         if(arm->id.us>1) {
1641                                 if(okee("Single user")) {
1642                                         ob->data= copy_armature(arm);
1643                                         arm->id.us--;
1644                                 }
1645                         }
1646                 }
1647                 break;
1648         case B_ACTLOCAL:
1649                 if(ob && ob->id.lib==0) {
1650                         act= ob->action;
1651                         if(act->id.lib) {
1652                                 if(okee("Make local")) {
1653                                         make_local_action(act);
1654                                         allqueue(REDRAWACTION,0);
1655                                 }
1656                         }
1657                 }
1658                 break;
1659         case B_ACTALONE:
1660                 if (ob)
1661                         act= ob->action;
1662                 
1663                 if(ob && ob->id.lib==0) {
1664                         if(act->id.us>1) {
1665                                 if(okee("Single user")) {
1666                                         ob->action=copy_action(act);
1667                                         ob->activecon=NULL;
1668                                         act->id.us--;
1669                                         allqueue(REDRAWACTION, 0);
1670                                 }
1671                         }
1672                 }
1673                 break;
1674
1675         case B_CAMERAALONE:
1676                 if(ob && ob->id.lib==0) {
1677                         Camera *ca= ob->data;
1678                         if(ca->id.us>1) {
1679                                 if(okee("Single user")) {
1680                                         ob->data= copy_camera(ca);
1681                                         ca->id.us--;
1682                                 }
1683                         }
1684                 }
1685                 break;
1686         case B_CAMERALOCAL:
1687                 if(ob && ob->id.lib==0) {
1688                         Camera *ca= ob->data;
1689                         if(ca->id.lib) {
1690                                 if(okee("Make local")) {
1691                                         make_local_camera(ca);
1692                                 }
1693                         }
1694                 }
1695                 break;
1696         case B_WORLDALONE:
1697                 wrld= G.scene->world;
1698                 if(wrld->id.us>1) {
1699                         if(okee("Single user")) {
1700                                 G.scene->world= copy_world(wrld);
1701                                 wrld->id.us--;
1702                         }
1703                 }
1704                 break;
1705         case B_WORLDLOCAL:
1706                 wrld= G.scene->world;
1707                 if(wrld && wrld->id.lib) {
1708                         if(okee("Make local")) {
1709                                 make_local_world(wrld);
1710                         }
1711                 }
1712                 break;
1713
1714         case B_LATTALONE:
1715                 if(ob && ob->id.lib==0) {
1716                         lt= ob->data;
1717                         if(lt->id.us>1) {
1718                                 if(okee("Single user")) {
1719                                         ob->data= copy_lattice(lt);
1720                                         lt->id.us--;
1721                                 }
1722                         }
1723                 }
1724                 break;
1725         case B_LATTLOCAL:
1726                 if(ob && ob->id.lib==0) {
1727                         lt= ob->data;
1728                         if(lt->id.lib) {
1729                                 if(okee("Make local")) {
1730                                         make_local_lattice(lt);
1731                                 }
1732                         }
1733                 }
1734                 break;
1735         
1736         case B_MATALONE:
1737                 if(ob==0) return;
1738                 ma= give_current_material(ob, ob->actcol);
1739                 idfrom= material_from(ob, ob->actcol);
1740                 if(idfrom && idfrom->lib==0) {
1741                         if(ma->id.us>1) {
1742                                 if(okee("Single user")) {
1743                                         ma= copy_material(ma);
1744                                         ma->id.us= 0;
1745                                         assign_material(ob, ma, ob->actcol);
1746                                 }
1747                         }
1748                 }
1749                 break;
1750         case B_MATLOCAL:
1751                 if(ob==0) return;
1752                 idfrom= material_from(ob, ob->actcol);
1753                 if(idfrom->lib==0) {
1754                         ma= give_current_material(ob, ob->actcol);
1755                         if(ma && ma->id.lib) {
1756                                 if(okee("Make local")) {
1757                                         make_local_material(ma);
1758                                 }
1759                         }
1760                 }
1761                 break;
1762
1763         case B_MESHLOCAL:
1764                 if(ob && ob->id.lib==0) {
1765                         me= ob->data;
1766                         if(me && me->id.lib) {
1767                                 if(okee("Make local")) {
1768                                         make_local_mesh(me);
1769                                         make_local_key( me->key );
1770                                 }
1771                         }
1772                 }
1773                 break;
1774
1775         case B_MBALLALONE:
1776                 if(ob && ob->id.lib==0) {
1777                         mb= ob->data;
1778                         if(mb->id.us>1) {
1779                                 if(okee("Single user")) {
1780                                         ob->data= copy_mball(mb);
1781                                         mb->id.us--;
1782                                         if(ob==G.obedit) allqueue(REDRAWVIEW3D, 0);
1783                                 }
1784                         }
1785                 }
1786                 break;
1787         case B_MBALLLOCAL:
1788                 if(ob && ob->id.lib==0) {
1789                         mb= ob->data;
1790                         if(mb->id.lib) {
1791                                 if(okee("Make local")) {
1792                                         make_local_mball(mb);
1793                                 }
1794                         }
1795                 }
1796                 break;
1797
1798         case B_CURVEALONE:
1799                 if(ob && ob->id.lib==0) {
1800                         cu= ob->data;
1801                         if(cu->id.us>1) {
1802                                 if(okee("Single user")) {
1803                                         ob->data= copy_curve(cu);
1804                                         cu->id.us--;
1805                                         makeDispList(ob);
1806                                         if(ob==G.obedit) allqueue(REDRAWVIEW3D, 0);
1807                                 }
1808                         }
1809                 }
1810                 break;
1811         case B_CURVELOCAL:
1812                 if(ob && ob->id.lib==0) {
1813                         cu= ob->data;
1814                         if(cu->id.lib) {
1815                                 if(okee("Make local")) {
1816                                         make_local_curve(cu);
1817                                         make_local_key( cu->key );
1818                                         makeDispList(ob);
1819                                 }
1820                         }
1821                 }
1822                 break;
1823                 
1824         case B_TEXALONE:
1825                 if(G.buts->texfrom==0) {        /* from mat */
1826                         if(ob==0) return;
1827                         ma= give_current_material(ob, ob->actcol);
1828                         if(ma && ma->id.lib==0) {
1829                                 mtex= ma->mtex[ ma->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                 else if(G.buts->texfrom==1) {   /* from world */
1839                         wrld= G.scene->world;
1840                         if(wrld->id.lib==0) {
1841                                 mtex= wrld->mtex[ wrld->texact ];
1842                                 if(mtex->tex && mtex->tex->id.us>1) {
1843                                         if(okee("Single user")) {
1844                                                 mtex->tex->id.us--;
1845                                                 mtex->tex= copy_texture(mtex->tex);
1846                                         }
1847                                 }
1848                         }
1849                 }
1850                 else if(G.buts->texfrom==2) {   /* from lamp */
1851                         if(ob==0 || ob->type!=OB_LAMP) return;
1852                         la= ob->data;
1853                         if(la->id.lib==0) {
1854                                 mtex= la->mtex[ la->texact ];
1855                                 if(mtex->tex && mtex->tex->id.us>1) {
1856                                         if(okee("Single user")) {
1857                                                 mtex->tex->id.us--;
1858                                                 mtex->tex= copy_texture(mtex->tex);
1859                                         }
1860                                 }
1861                         }
1862                 }
1863                 break;
1864         case B_TEXLOCAL:
1865                 if(G.buts->texfrom==0) {        /* from mat */
1866                         if(ob==0) return;
1867                         ma= give_current_material(ob, ob->actcol);
1868                         if(ma && ma->id.lib==0) {
1869                                 mtex= ma->mtex[ ma->texact ];
1870                                 if(mtex->tex && mtex->tex->id.lib) {
1871                                         if(okee("Make local")) {
1872                                                 make_local_texture(mtex->tex);
1873                                         }
1874                                 }
1875                         }
1876                 }
1877                 else if(G.buts->texfrom==1) {   /* from world */
1878                         wrld= G.scene->world;
1879                         if(wrld->id.lib==0) {
1880                                 mtex= wrld->mtex[ wrld->texact ];
1881                                 if(mtex->tex && mtex->tex->id.lib) {
1882                                         if(okee("Make local")) {
1883                                                 make_local_texture(mtex->tex);
1884                                         }
1885                                 }
1886                         }
1887                 }
1888                 else if(G.buts->texfrom==2) {   /* from lamp */
1889                         if(ob==0 || ob->type!=OB_LAMP) return;
1890                         la= ob->data;
1891                         if(la->id.lib==0) {
1892                                 mtex= la->mtex[ la->texact ];
1893                                 if(mtex->tex && mtex->tex->id.lib) {
1894                                         if(okee("Make local")) {
1895                                                 make_local_texture(mtex->tex);
1896                                         }
1897                                 }
1898                         }
1899                 }
1900                 break;
1901         
1902         case B_IPOALONE:
1903                 ipo= get_ipo_to_edit(&idfrom);
1904                 
1905                 if(idfrom && idfrom->lib==0) {
1906                         if(ipo->id.us>1) {
1907                                 if(okee("Single user")) {
1908                                         if(ipo->blocktype==ID_OB) ((Object *)idfrom)->ipo= copy_ipo(ipo);
1909                                         else if(ipo->blocktype==ID_MA) ((Material *)idfrom)->ipo= copy_ipo(ipo);
1910                                         else if(ipo->blocktype==ID_SEQ) ((Sequence *)idfrom)->ipo= copy_ipo(ipo);
1911                                         else if(ipo->blocktype==ID_CU) ((Curve *)idfrom)->ipo= copy_ipo(ipo);
1912                                         else if(ipo->blocktype==ID_KE) ((Key *)idfrom)->ipo= copy_ipo(ipo);
1913                                         else if(ipo->blocktype==ID_LA) ((Lamp *)idfrom)->ipo= copy_ipo(ipo);
1914                                         else if(ipo->blocktype==ID_WO) ((World *)idfrom)->ipo= copy_ipo(ipo);
1915                                         else if(ipo->blocktype==ID_CA) ((Camera *)idfrom)->ipo= copy_ipo(ipo);
1916                                         else if(ipo->blocktype==ID_SO) ((bSound *)idfrom)->ipo= copy_ipo(ipo);
1917                                         else if(ipo->blocktype==ID_AC) get_hilighted_action_channel((bAction *)idfrom)->ipo= copy_ipo(ipo);
1918                                         else if(ipo->blocktype==IPO_CO) ((Object *)idfrom)->activecon->ipo= copy_ipo(ipo);
1919                                         else error("Warn ton!");
1920                                         
1921                                         ipo->id.us--;
1922                                         allqueue(REDRAWIPO, 0);
1923                                 }
1924                         }
1925                 }
1926                 break;
1927         case B_IPOLOCAL:
1928                 ipo= get_ipo_to_edit(&idfrom);
1929                 
1930                 if(idfrom && idfrom->lib==0) {
1931                         if(ipo->id.lib) {
1932                                 if(okee("Make local")) {
1933                                         make_local_ipo(ipo);
1934                                         allqueue(REDRAWIPO, 0);
1935                                 }
1936                         }
1937                 }
1938                 break;
1939
1940         case B_OBALONE:
1941                 if(G.scene->id.lib==0) {
1942                         if(ob->id.us>1) {
1943                                 if(okee("Single user")) {
1944                                         base= FIRSTBASE;
1945                                         while(base) {
1946                                                 if(base->object==ob) {
1947                                                         base->object= copy_object(ob);
1948                                                         ob->id.us--;
1949                                                         allqueue(REDRAWVIEW3D, 0);
1950                                                         break;
1951                                                 }
1952                                                 base= base->next;
1953                                         }
1954                                 }
1955                         }
1956                 }
1957                 break;
1958         case B_OBLOCAL:
1959                 if(G.scene->id.lib==0) {
1960                         if(ob->id.lib) {
1961                                 if(okee("Make local")) {
1962                                         make_local_object(ob);
1963                                         allqueue(REDRAWVIEW3D, 0);
1964                                 }
1965                         }
1966                 }
1967                 break;
1968         case B_MESHALONE:
1969                 if(ob && ob->id.lib==0) {
1970                         
1971                         me= ob->data;
1972                         
1973                         if(me && me->id.us>1) {
1974                                 if(okee("Single user")) {
1975                                         Mesh *men= copy_mesh(me);
1976                                         men->id.us= 0;
1977                                         
1978                                         set_mesh(ob, men);
1979                                         
1980                                         if(ob==G.obedit) allqueue(REDRAWVIEW3D, 0);
1981                                 }
1982                         }
1983                 }
1984                 break;
1985         }
1986         
1987         allqueue(REDRAWBUTSALL, 0);
1988         allqueue(REDRAWOOPS, 0);
1989 }
1990
1991 /* ********************** EMPTY ****************************** */
1992 /* ********************** INFO ****************************** */
1993
1994 int buttons_do_unpack()
1995 {
1996         int how;
1997         char menu[2048];
1998         char line[128];
1999         int ret_value = RET_OK, count = 0;
2000
2001         count = countPackedFiles();
2002
2003         if (count) {
2004                 if (count == 1) {
2005                         sprintf(menu, "Unpack 1 file%%t");
2006                 } else {
2007                         sprintf(menu, "Unpack %d files%%t", count);
2008                 }
2009                 
2010                 sprintf(line, "|Use files in current directory (create when necessary)%%x%d", PF_USE_LOCAL);
2011                 strcat(menu, line);
2012         
2013                 sprintf(line, "|Write files to current directory (overwrite existing files)%%x%d", PF_WRITE_LOCAL);
2014                 strcat(menu, line);
2015         
2016                 sprintf(line, "|%%l|Use files in original location (create when necessary)%%x%d", PF_USE_ORIGINAL);
2017                 strcat(menu, line);
2018         
2019                 sprintf(line, "|Write files to original location (overwrite existing files)%%x%d", PF_WRITE_ORIGINAL);
2020                 strcat(menu, line);
2021         
2022                 sprintf(line, "|%%l|Disable AutoPack, keep all packed files %%x%d", PF_KEEP);
2023                 strcat(menu, line);
2024         
2025                 sprintf(line, "|Ask for each file %%x%d", PF_ASK);
2026                 strcat(menu, line);
2027                 
2028                 how = pupmenu(menu);
2029                 
2030                 if(how != -1) {
2031                         if (how != PF_KEEP) {
2032                                 unpackAll(how);
2033                         }
2034                         G.fileflags &= ~G_AUTOPACK;
2035                 } else {
2036                         ret_value = RET_CANCEL;
2037                 }
2038         } else {
2039                 pupmenu("No packed files. Autopack disabled");
2040         }
2041         
2042         return (ret_value);
2043 }
2044
2045 /* here, because of all creator stuff */
2046
2047 Scene *copy_scene(Scene *sce, int level)
2048 {
2049         /* level 0: al objects shared
2050          * level 1: al object-data shared
2051          * level 2: full copy
2052          */
2053         Scene *scen;
2054         Base *base, *obase;
2055
2056
2057         /* level 0 */
2058         scen= copy_libblock(sce);
2059         duplicatelist(&(scen->base), &(sce->base));
2060         
2061         clear_id_newpoins();
2062         
2063         id_us_plus((ID *)scen->world);
2064         id_us_plus((ID *)scen->set);
2065         
2066         scen->ed= 0;
2067         scen->radio= 0;
2068         
2069         obase= sce->base.first;
2070         base= scen->base.first;
2071         while(base) {
2072                 base->object->id.us++;
2073                 if(obase==sce->basact) scen->basact= base;
2074                 
2075                 obase= obase->next;
2076                 base= base->next;
2077         }
2078         
2079         if(level==0) return scen;
2080         
2081         /* level 1 */
2082         G.scene= scen;
2083         single_object_users(0);
2084
2085         /*  camera */
2086         ID_NEW(G.scene->camera);
2087                 
2088         /* level 2 */
2089         if(level>=2) {
2090                 if(scen->world) {
2091                         scen->world->id.us--;
2092                         scen->world= copy_world(scen->world);
2093                 }
2094                 single_obdata_users(0);
2095                 single_mat_users_expand();
2096                 single_tex_users_expand();
2097         }
2098
2099         clear_id_newpoins();
2100
2101         BPY_copy_scriptlink(&sce->scriptlink);
2102
2103
2104
2105         // make a private copy of the avicodecdata
2106
2107         if (sce->r.avicodecdata) {
2108
2109                 scen->r.avicodecdata = MEM_dupallocN(sce->r.avicodecdata);
2110
2111                 scen->r.avicodecdata->lpFormat = MEM_dupallocN(scen->r.avicodecdata->lpFormat);
2112
2113                 scen->r.avicodecdata->lpParms = MEM_dupallocN(scen->r.avicodecdata->lpParms);
2114         }
2115
2116         return scen;
2117 }
2118
2119 void do_info_buttons(unsigned short event)
2120 {
2121         bScreen *sc, *oldscreen;
2122         Scene *sce, *sce1;
2123         ScrArea *sa;
2124         int nr;
2125         
2126         switch(event) {
2127         
2128         case B_INFOSCR:         /* menu select screen */
2129
2130                 if( G.curscreen->screennr== -2) {
2131                         if(curarea->winy <50) {
2132                                 sa= closest_bigger_area();
2133                                 areawinset(sa->win);
2134                         }
2135                         activate_databrowse((ID *)G.curscreen, ID_SCR, 0, B_INFOSCR, &G.curscreen->screennr, do_info_buttons);
2136                         return;
2137                 }
2138                 if( G.curscreen->screennr < 0) return;
2139                 
2140                 sc= G.main->screen.first;
2141                 nr= 1;
2142                 while(sc) {
2143                         if(nr==G.curscreen->screennr) {
2144                                 if(is_allowed_to_change_screen(sc)) setscreen(sc);
2145                                 else error("Unable to perform function in EditMode");
2146                                 break;
2147                         }
2148                         nr++;
2149                         sc= sc->id.next;
2150                 }
2151                 /* last item: NEW SCREEN */
2152                 if(sc==0) {
2153                         duplicate_screen();
2154                 }
2155                 break;
2156         case B_INFODELSCR:
2157                 /* do this event only with buttons, so it can never be called with full-window */
2158
2159                 if(G.curscreen->id.prev) sc= G.curscreen->id.prev;
2160                 else if(G.curscreen->id.next) sc= G.curscreen->id.next;
2161                 else return;
2162                 if(okee("Delete current screen")) {
2163                         /* find new G.curscreen */
2164                         
2165                         oldscreen= G.curscreen;
2166                         setscreen(sc);          /* this test if sc has a full */
2167                         unlink_screen(oldscreen);
2168                         free_libblock(&G.main->screen, oldscreen);
2169                 }
2170                 scrarea_queue_headredraw(curarea);
2171
2172                 break;
2173         case B_INFOSCE:         /* menu select scene */
2174                 
2175                 if( G.obedit) {
2176                         error("Unable to perform function in EditMode");
2177                         return;
2178                 }
2179                 if( G.curscreen->scenenr== -2) {
2180                         if(curarea->winy <50) {
2181                                 sa= closest_bigger_area();
2182                                 areawinset(sa->win);
2183                         }
2184                         activate_databrowse((ID *)G.scene, ID_SCE, 0, B_INFOSCE, &G.curscreen->scenenr, do_info_buttons);
2185                         return;
2186                 }
2187                 if( G.curscreen->scenenr < 0) return;
2188
2189                 sce= G.main->scene.first;
2190                 nr= 1;
2191                 while(sce) {
2192                         if(nr==G.curscreen->scenenr) {
2193                                 if(sce!=G.scene) set_scene(sce);
2194                                 break;
2195                         }
2196                         nr++;
2197                         sce= sce->id.next;
2198                 }
2199                 /* last item: NEW SCENE */
2200                 if(sce==0) {
2201                         nr= pupmenu("Add scene%t|Empty|Link Objects|Link ObData|Full Copy");
2202                         if(nr<= 0) return;
2203                         if(nr==1) {
2204                                 sce= add_scene(G.scene->id.name+2);
2205                                 sce->r= G.scene->r;
2206 #ifdef _WIN32
2207                                 if (sce->r.avicodecdata) {
2208                                         sce->r.avicodecdata = MEM_dupallocN(G.scene->r.avicodecdata);
2209                                         sce->r.avicodecdata->lpFormat = MEM_dupallocN(G.scene->r.avicodecdata->lpFormat);
2210                                         sce->r.avicodecdata->lpParms = MEM_dupallocN(G.scene->r.avicodecdata->lpParms);
2211                                 }
2212 #endif
2213                         }
2214                         else sce= copy_scene(G.scene, nr-2);
2215                         
2216                         set_scene(sce);
2217                 }
2218                 BIF_preview_changed(G.buts);
2219
2220                 break;
2221         case B_INFODELSCE:
2222                 
2223                 if(G.scene->id.prev) sce= G.scene->id.prev;
2224                 else if(G.scene->id.next) sce= G.scene->id.next;
2225                 else return;
2226                 if(okee("Delete current scene")) {
2227                         
2228                         /* check all sets */
2229                         sce1= G.main->scene.first;
2230                         while(sce1) {
2231                                 if(sce1->set == G.scene) sce1->set= 0;
2232                                 sce1= sce1->id.next;
2233                         }
2234                         
2235                         /* check all sequences */
2236                         clear_scene_in_allseqs(G.scene);
2237                         
2238                         /* al screens */
2239                         sc= G.main->screen.first;
2240                         while(sc) {
2241                                 if(sc->scene == G.scene) sc->scene= sce;
2242                                 sc= sc->id.next;
2243                         }
2244                         free_libblock(&G.main->scene, G.scene);
2245                         set_scene(sce);
2246                 }
2247         
2248                 break;
2249         case B_FILEMENU:
2250                 tbox_setmain(9);
2251                 toolbox();
2252                 break;
2253         }
2254 }
2255
2256 /* strubi shamelessly abused the status line as a progress bar... 
2257    feel free to kill him after release */
2258
2259 static int      g_progress_bar = 0;
2260 static char *g_progress_info = 0;
2261 static float g_done;
2262
2263 int start_progress_bar(void)
2264 {
2265         g_progress_bar = 1;
2266         return 1;               // we never fail (yet)
2267 }
2268
2269 void end_progress_bar(void)
2270 {
2271         g_progress_bar = 0;
2272 }
2273
2274 static void update_progress_bar(float done, char *info)
2275 {
2276         g_done = done;
2277         g_progress_info = info;
2278 }
2279
2280 /** Progress bar
2281         'done': a value between 0.0 and 1.0, showing progress
2282         'info': a info text what is currently being done
2283
2284         Make sure that the progress bar is always called with:
2285         done = 0.0 first
2286                 and
2287         done = 1.0 last -- or alternatively use:
2288
2289         start_progressbar();
2290         do_stuff_and_callback_progress_bar();
2291         end_progressbar();
2292 */
2293 int progress_bar(float done, char *busy_info)
2294 {
2295         ScrArea *sa;
2296         short val; 
2297
2298         /* User break (ESC) */
2299         while (qtest()) {
2300                 if (extern_qread(&val) == ESCKEY) 
2301                         return 0;
2302         }
2303         if (done == 0.0) {
2304                 start_progress_bar();
2305         } else if (done > 0.99) {
2306                 end_progress_bar();
2307         }
2308
2309         sa= G.curscreen->areabase.first;
2310         while(sa) {
2311                 if (sa->spacetype == SPACE_INFO) {
2312                         update_progress_bar(done, busy_info);
2313
2314                         curarea = sa;
2315
2316                         scrarea_do_headdraw(curarea);
2317                         areawinset(curarea->win);
2318                         sa->head_swap= WIN_BACK_OK;
2319                         screen_swapbuffers();
2320                 }
2321                 sa = sa->next;
2322         }
2323         return 1;
2324 }
2325
2326
2327 static void check_packAll()
2328 {
2329         // first check for dirty images
2330         Image *ima;
2331
2332         ima = G.main->image.first;
2333         while (ima) {
2334                 if (ima->ibuf && (ima->ibuf->userflags &= IB_BITMAPDIRTY)) {
2335                         break;
2336                 }
2337                 ima= ima->id.next;
2338         }
2339         
2340         if (ima == 0 || okee("Some images are painted on. These changes will be lost. Continue ?")) {
2341                 packAll();
2342                 G.fileflags |= G_AUTOPACK;
2343         }
2344 }
2345
2346
2347 int write_runtime(char *str, char *exename)
2348 {
2349         char *freestr= NULL;
2350         char *ext = 0;
2351
2352 #ifdef _WIN32
2353         ext = ".exe";
2354 #endif
2355
2356 #ifdef __APPLE__
2357         ext = ".app";
2358 #endif
2359         if (ext && (!BLI_testextensie(str, ext))) {
2360                 freestr= MEM_mallocN(strlen(str) + strlen(ext) + 1, "write_runtime_check");
2361                 strcpy(freestr, str);
2362                 strcat(freestr, ext);
2363                 str= freestr;
2364         }
2365
2366         if (!BLI_exists(str) || saveover(str))
2367                 BLO_write_runtime(str, exename);
2368
2369         if (freestr)
2370                 MEM_freeN(freestr);
2371         
2372         return 0;
2373 }
2374
2375 static void write_runtime_check_dynamic(char *str) 
2376 {
2377         write_runtime(str, "blenderdynplayer.exe");
2378 }
2379
2380 static void write_runtime_check(char *str) 
2381 {
2382         char player[128];
2383
2384         strcpy(player, "blenderplayer");
2385
2386 #ifdef _WIN32
2387         strcat(player, ".exe");
2388 #endif
2389
2390 #ifdef __APPLE__
2391         strcat(player, ".app");
2392 #endif
2393
2394         write_runtime(str, player);
2395 }
2396 /* end keyed functions */
2397
2398
2399 static void do_info_filemenu(void *arg, int event)
2400 {
2401         ScrArea *sa;
2402         char dir[FILE_MAXDIR];
2403         
2404         if(curarea->spacetype==SPACE_INFO) {
2405                 sa= closest_bigger_area();
2406                 areawinset(sa->win);
2407         }
2408
2409         /* these are no defines, easier this way, the codes are in the function below */
2410         switch(event) {
2411         case 0:
2412                 if (okee("ERASE ALL")) {
2413                         if (!BIF_read_homefile())
2414                                 error("No file ~/.B.blend");
2415                 }
2416                 break;
2417         case 1:
2418                 activate_fileselect(FILE_BLENDER, "LOAD FILE", G.sce, BIF_read_file);
2419                 break;
2420         case 2:
2421                 {
2422                         char *s= MEM_mallocN(strlen(G.sce) + 11 + 1, "okee_reload");
2423                         strcpy(s, "Open file: ");
2424                         strcat(s, G.sce);
2425                         if (okee(s))
2426                                 BIF_read_file(G.sce);
2427                         MEM_freeN(s);
2428                 }
2429                 break;
2430         case 3:
2431                 activate_fileselect(FILE_LOADLIB, "LOAD LIBRARY", G.lib, 0);
2432                 break;
2433         case 4:
2434                 strcpy(dir, G.sce);
2435                 untitled(dir);
2436                 activate_fileselect(FILE_BLENDER, "SAVE FILE", dir, BIF_write_file);
2437                 break;
2438         case 5:
2439                 strcpy(dir, G.sce);
2440                 if (untitled(dir)) {
2441                         activate_fileselect(FILE_BLENDER, "SAVE FILE", dir, BIF_write_file);
2442                 } else {
2443                         BIF_write_file(dir);
2444                         free_filesel_spec(dir);
2445                 }
2446                 break;
2447         case 6:
2448                 mainqenter(F3KEY, 1);
2449                 break;
2450         case 7:
2451                 write_vrml_fs();
2452                 break;
2453         case 8:
2454                 write_dxf_fs();
2455                 break;
2456         case 9:
2457                 write_videoscape_fs();
2458                 break;
2459 /*
2460         case 20:
2461                 strcpy(dir, G.sce);
2462                 activate_fileselect(FILE_SPECIAL, "INSTALL LICENSE KEY", dir, loadKeyboard);
2463                 break;
2464         case 21:
2465                 SHOW_LICENSE_KEY();
2466                 break;
2467 */
2468         case 22:
2469                 activate_fileselect(FILE_SPECIAL, "WRITE RUNTIME", "", write_runtime_check);
2470                 break;
2471         case 23:
2472                 activate_fileselect(FILE_SPECIAL, "WRITE DYNAMIC RUNTIME", "", write_runtime_check_dynamic);
2473                 break;
2474         case 30:
2475                 // import menu, no handling
2476                 break;
2477
2478 #ifdef EXPERIMENTAL_MENUS
2479         case 10:
2480                 check_packAll();
2481                 break;
2482         case 11:
2483                 unpackAll(PF_WRITE_LOCAL);
2484                 G.fileflags &= ~G_AUTOPACK;
2485                 break;
2486         case 12:
2487                 if (buttons_do_unpack() != RET_CANCEL) {
2488                         /* Clear autopack bit only if user selected one of the unpack options */
2489                         G.fileflags &= ~G_AUTOPACK;
2490                 }
2491                 break;
2492         case 13:
2493 #else /* EXPERIMENTAL_MENUS */
2494         case 10:
2495 #endif /* EXPERIMENTAL_MENUS */
2496                 exit_usiblender();
2497                 break;          
2498         }
2499         allqueue(REDRAWINFO, 0);
2500 }
2501
2502 void do_info_file_optionsmenu(void *arg, int event)
2503 {
2504         G.fileflags ^= (1 << event);
2505
2506         // allqueue(REDRAWINFO, 0);
2507 }
2508
2509 //#ifdef NEW_WINDOW_TYPE_MENUS
2510
2511 static char *windowtype_pup(void)
2512 {
2513         static char string[1024];
2514
2515         strcpy(string, "Window type:%t"); //14
2516         strcat(string, "|3D Viewport %x1"); //30
2517
2518         strcat(string, "|%l"); // 33
2519
2520         strcat(string, "|Ipo Curve Editor %x2"); //54
2521         strcat(string, "|Action Editor %x12"); //73
2522         strcat(string, "|NLA Editor %x13"); //94
2523
2524         strcat(string, "|%l"); //97
2525
2526         strcat(string, "|UV/Image Editor %x6"); //117
2527
2528         strcat(string, "|Video Sequence Editor %x8"); //143
2529         strcat(string, "|Audio Timeline %x11"); //163
2530         strcat(string, "|Text Editor %x9"); //179
2531
2532         strcat(string, "|%l"); //192
2533
2534
2535         strcat(string, "|User Preferences %x7"); //213
2536         strcat(string, "|OOPS Schematic %x3"); //232
2537         strcat(string, "|Buttons Window %x4"); //251
2538
2539         strcat(string, "|%l"); //254
2540
2541         strcat(string, "|Image Browser %x10");
2542         strcat(string, "|File Browser %x5");
2543
2544         return (string);
2545 }
2546
2547
2548 static uiBlock *info_file_optionsmenu(void *arg_unused)
2549 {
2550         uiBlock *block;
2551         short yco= 0, xco = 20;
2552
2553         block= uiNewBlock(&curarea->uiblocks, "runtime_options", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
2554         uiBlockSetButmFunc(block, do_info_file_optionsmenu, NULL);
2555         uiBlockSetXOfs(block,-40);  // offset to parent button
2556
2557         /* flags are case-values */
2558         uiDefBut(block, BUTM, 1, "Compress File",       xco, yco-=20, 100, 19, NULL, 0.0, 0.0, 0, G_FILE_COMPRESS_BIT, "Use file compression");
2559 /*
2560         uiDefBut(block, BUTM, 1, "Sign File",   xco, yco-=20, 100, 19, NULL, 0.0, 0.0, 0, G_FILE_SIGN_BIT, "Add signature to file");
2561         uiDefBut(block, BUTM, 1, "Lock File",   xco, yco-=20, 100, 19, NULL, 0.0, 0.0, 0, G_FILE_LOCK_BIT, "Protect the file from editing by others");
2562 */
2563         uiTextBoundsBlock(block, 50);
2564
2565         /* Toggle buttons */
2566         
2567         yco= 0;
2568         xco -= 20;
2569         uiBlockSetEmboss(block, UI_EMBOSSW);
2570         uiBlockSetButmFunc(block, NULL, NULL);
2571         /* flags are defines */
2572         uiDefIconButI(block, ICONTOG|BIT|G_FILE_COMPRESS_BIT, 0, ICON_CHECKBOX_DEHLT, xco, yco-=20, 19, 19, &G.fileflags, 0.0, 0.0, 0, 0, "");
2573 /*
2574         uiDefIconButI(block, ICONTOG|BIT|G_FILE_SIGN_BIT, 0, ICON_CHECKBOX_DEHLT, xco, yco-=20, 19, 19, &G.fileflags, 0.0, 0.0, 0, 0, "");
2575         uiDefIconButI(block, ICONTOG|BIT|G_FILE_LOCK_BIT, 0, ICON_CHECKBOX_DEHLT, xco, yco-=20, 19, 19, &G.fileflags, 0.0, 0.0, 0, 0, "");
2576 */
2577         uiBlockSetDirection(block, UI_RIGHT);
2578                 
2579         return block;
2580 }
2581
2582 static uiBlock *info_runtime_optionsmenu(void *arg_unused)
2583 {
2584         uiBlock *block;
2585         short yco= 0, xco = 20;
2586
2587         block= uiNewBlock(&curarea->uiblocks, "add_surfacemenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
2588         uiBlockSetXOfs(block, -40);  // offset to parent button
2589
2590         uiBlockSetEmboss(block, UI_EMBOSSW);
2591
2592         uiDefBut(block, LABEL, 0, "Size options:",              xco, yco-=20, 114, 19, 0, 0.0, 0.0, 0, 0, "");
2593         uiDefButS(block, NUM, 0, "X:",          xco+19, yco-=20, 95, 19,    &G.scene->r.xplay, 10.0, 2000.0, 0, 0, "X screen/window resolution");
2594         uiDefButS(block, NUM, 0, "Y:",          xco+19, yco-=20, 95, 19, &G.scene->r.yplay, 10.0, 2000.0, 0, 0, "Y screen/window resolution");
2595
2596         uiDefBut(block, SEPR, 0, "",            xco, yco-=4, 114, 4, NULL, 0.0, 0.0, 0, 0, "");
2597
2598         uiDefBut(block, LABEL, 0, "Fullscreen options:",                xco, yco-=20, 114, 19, 0, 0.0, 0.0, 0, 0, "");
2599         uiDefButS(block, TOG, 0, "Fullscreen", xco + 19, yco-=20, 95, 19, &G.scene->r.fullscreen, 0.0, 0.0, 0, 0, "Starts player in a new fullscreen display");
2600         uiDefButS(block, NUM, 0, "Freq:",       xco+19, yco-=20, 95, 19, &G.scene->r.freqplay, 10.0, 120.0, 0, 0, "Clock frequency of fullscreen display");
2601         uiDefButS(block, NUM, 0, "Bits:",       xco+19, yco-=20, 95, 19, &G.scene->r.depth, 1.0, 32.0, 0, 0, "Bit depth of full screen disply");
2602
2603         uiDefBut(block, SEPR, 0, "",            xco, yco-=4, 114, 4, NULL, 0.0, 0.0, 0, 0, "");
2604
2605         /* stereo settings */
2606         /* can't use any definition from the game engine here so hardcode it. Change it here when it changes there!
2607          * RAS_IRasterizer has definitions:
2608          * RAS_STEREO_NOSTEREO     1
2609          * RAS_STEREO_QUADBUFFERED 2
2610          * RAS_STEREO_ABOVEBELOW   3
2611          * RAS_STEREO_INTERLACED   4   future
2612          */
2613         uiDefBut(block, LABEL, 0, "Stereo options", xco, yco-=20, 114, 19, 0, 0.0, 0.0, 0, 0, "");
2614         uiDefButS(block, ROW, 0, "no stereo", xco+19, yco-=20, 95, 19, &(G.scene->r.stereomode), 6.0, 1.0, 0, 0, "Disables stereo");
2615         uiDefButS(block, ROW, 0, "h/w pageflip", xco+19, yco-=20, 95, 19, &(G.scene->r.stereomode), 6.0, 2.0, 0, 0, "Enables h/w pageflip stereo method");
2616         uiDefButS(block, ROW, 0, "syncdoubling", xco+19, yco-=20, 95, 19, &(G.scene->r.stereomode), 6.0, 3.0, 0, 0, "Enables syncdoubling stereo method");
2617 #if 0
2618         // future
2619         uiDefButS(block, ROW, 0, "syncdoubling", xco+19, yco, 95, 19, &(G.scene->r.stereomode), 5.0, 4.0, 0, 0, "Enables interlaced stereo method");
2620 #endif
2621
2622         uiBlockSetDirection(block, UI_RIGHT);
2623         uiTextBoundsBlock(block, 50);
2624                 
2625         return block;
2626 }
2627
2628 static uiBlock *info_file_importmenu(void *arg_unused)
2629 {
2630         uiBlock *block;
2631         short yco= 0, xco = 20;
2632
2633         block= uiNewBlock(&curarea->uiblocks, "importmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
2634         uiBlockSetXOfs(block, -40);  // offset to parent button
2635
2636         uiBlockSetEmboss(block, UI_EMBOSSW);
2637
2638         /* flags are defines */
2639         uiDefBut(block, LABEL, 0, "VRML 2.0 options", xco, yco, 125, 19,   NULL, 0.0, 0.0, 0, 0, "");
2640         uiDefButS(block, TOG|BIT|0, 0, "SepLayers", xco, yco-=20, 75, 19,                 &U.vrmlflag, 0.0, 0.0, 0, 0, "Separate Empties, Lamps, etc. into Layers");
2641         uiDefButS(block, TOG|BIT|1, 0, "Scale 1/100", xco, yco-=20, 75, 19,   &U.vrmlflag, 0.0, 0.0, 0, 0, "Scale scene by 1/100 (3DS VRML)");
2642         uiDefButS(block, TOG|BIT|2, 0, "Two Sided", xco, yco-=20, 75, 19,   &U.vrmlflag, 0.0, 0.0, 0, 0, "Import two sided faces");
2643
2644         uiBlockSetDirection(block, UI_RIGHT);
2645         uiTextBoundsBlock(block, 50);
2646                 
2647         return block;
2648 }
2649
2650 static uiBlock *info_filemenu(void *arg_unused)
2651 {
2652         uiBlock *block;
2653         short xco=0;
2654
2655         block= uiNewBlock(&curarea->uiblocks, "filemenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
2656         uiBlockSetButmFunc(block, do_info_filemenu, NULL);
2657         
2658         uiDefBut(block, BUTM, 1, "New|Ctrl X",                          0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "Start a new project (and delete the current)");
2659         uiDefBut(block, BUTM, 1, "Open|F1",                                     0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, "Open a new file");
2660         uiDefBut(block, BUTM, 1, "Reopen Last|Ctrl O",          0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 2, "Revert to the last version saved to file");
2661         uiDefBut(block, BUTM, 1, "Append|Shift F1",                     0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 3, "Append contents of a file to the current project");
2662         uiDefBlockBut(block, info_file_importmenu, NULL, "Import Settings|>>", 0, xco-=20, 160, 19, "");
2663
2664         uiDefBut(block, SEPR, 0, "",                                            0, xco-=6, 160, 6, NULL, 0.0, 0.0, 0, 0, "");
2665         uiDefBut(block, BUTM, 1, "Save As|F2",                          0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 4, "Save to a new file");
2666         uiDefBut(block, BUTM, 1, "Save|Ctrl W",                         0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 5, "Save to the current file");
2667
2668         uiDefBlockBut(block, info_file_optionsmenu, NULL, "File options|>>", 0, xco-=20, 160, 19, "Click to open the File Options menu");
2669
2670         uiDefBut(block, SEPR, 0, "",                                            0, xco-=6, 160, 6, NULL, 0.0, 0.0, 0, 0, "");
2671
2672         uiDefBut(block, BUTM, 1, "Save Runtime",                        0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 22, "Create a runtime executable with the current project");
2673 #ifdef _WIN32
2674         uiDefBut(block, BUTM, 1, "Save dynamic Runtime",                        0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 23, "Create a dynamic runtime executable with the current project (requieres extenal python20.dll)");
2675 #endif
2676         uiDefBlockBut(block, info_runtime_optionsmenu, NULL, "Runtime options|>>", 0, xco-=20, 160, 19, "Click to open the File Options menu");
2677
2678         uiDefBut(block, SEPR, 0, "",                                            0, xco-=6, 160, 6, NULL, 0.0, 0.0, 0, 0, "");
2679         uiDefBut(block, BUTM, 1, "Save Image|F3",                       0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 6, "Save the image in the render buffer to a file");
2680         uiDefBut(block, BUTM, 1, "Save VRML 1.0|Ctrl F2",               0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 7, "Save the current scene to a file in VRML 1.0 format");
2681         uiDefBut(block, BUTM, 1, "Save DXF|Shift F2",           0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 8, "Save the current scene to a file in DXF format");
2682         uiDefBut(block, BUTM, 1, "Save VideoScape|Alt W",       0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 9, "Save the current scene to a file in VideoScape format");
2683
2684
2685         /*
2686         if (LICENSE_KEY_VALID) {
2687                 uiDefBut(block, SEPR, 0, "",                                            0, xco-=6, 160, 6, NULL, 0.0, 0.0, 1, 0, "");
2688                 uiDefBut(block, BUTM, 1, "Show License Key", 0, xco-=20,        140, 19, NULL, 0.0, 0.0, 1, 21, "Show the personal information stored in your Blender License Key");
2689                 uiDefIconBut(block, BUTM, 1, ICON_PUBLISHER,                     141,xco,       19,  19, NULL, 0.0, 0.0, 1, 21, "Show the personal information stored in your Blender License Key");
2690         } else if (I_AM_PUBLISHER) {
2691                 uiDefBut(block, SEPR, 0, "",                                            0, xco-=6, 160, 6, NULL, 0.0, 0.0, 1, 0, "");
2692                 uiDefBut(block, BUTM, 1, "Install License Key", 0, xco-=20,     140, 19, NULL, 0.0, 0.0, 1, 20, "Install your Blender License Key");
2693                 uiDefIconBut(block, BUTM, 1, ICON_PUBLISHER,                     141,xco,       19,  19, NULL, 0.0, 0.0, 1, 20, "Install your Blender License Key");
2694         }
2695         */
2696
2697
2698         uiDefBut(block, SEPR, 0, "",                                            0, xco-=6, 160, 6, NULL, 0.0, 0.0, 1, 0, "");
2699
2700 #ifdef EXPERIMENTAL_MENUS
2701         uiDefBut(block, BUTM, 1, "Pack Data",                                           0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 10, "");
2702         uiDefBut(block, BUTM, 1, "Unpack Data to current dir",          0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 11, "");
2703         uiDefBut(block, BUTM, 1, "Advanced Unpack",                                     0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 12, "");
2704         uiDefBut(block, SEPR, 0, "",                                            0, xco-=6, 160, 6, NULL, 0.0, 0.0, 1, 0, "");
2705         uiDefBut(block, BUTM, 1, "Quit | Q",                            0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 13, "Quit Blender immediately");
2706 #else /* EXPERIMENTAL_MENUS */
2707         uiDefBut(block, BUTM, 1, "Quit | Q",                            0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 10, "Quit Blender immediately");
2708 #endif /* EXPERIMENTAL_MENUS */
2709         uiBlockSetDirection(block, UI_DOWN);
2710
2711         uiTextBoundsBlock(block, 80);
2712
2713         return block;
2714 }
2715
2716 static void do_info_editmenu(void *arg, int event)
2717 {
2718         /* needed to check for valid selected objects */
2719         Base *base=NULL;
2720         Object *ob=NULL;
2721
2722         base= BASACT;
2723         if (base) ob= base->object;
2724
2725         switch(event) {
2726                 
2727         case 0:
2728                 /* (De)Select All */
2729                 if(select_area(SPACE_VIEW3D)) mainqenter(AKEY, 1);
2730                 break;
2731                 /* Border Select */
2732         case 1:
2733                 if(select_area(SPACE_VIEW3D)) mainqenter(BKEY, 1);
2734                 break;
2735         case 2:
2736                 /* Circle Select */
2737                 /*if(select_area(SPACE_VIEW3D)) {
2738                         ;
2739                 }*/
2740                 break;
2741         case 3:
2742                 /* Duplicate */
2743                 if(select_area(SPACE_VIEW3D)) {
2744                         duplicate_context_selected();
2745                 }
2746                 break;
2747         case 4:
2748                 /* Delete */
2749                 if(select_area(SPACE_VIEW3D)) {
2750                         delete_context_selected();
2751                 }
2752                 break;
2753         case 5:
2754                 /* Edit Mode */
2755                 if(select_area(SPACE_VIEW3D)) {
2756                         blenderqread(TABKEY, 1);
2757                 }
2758                 break;
2759         case 6:
2760                 /* Grabber */
2761                 if(select_area(SPACE_VIEW3D)) {
2762                         transform('g');
2763                 }
2764                 break;
2765         case 7:
2766                 /* Rotate */
2767                 if(select_area(SPACE_VIEW3D)) {
2768                         transform('r');
2769                 }
2770                 break;
2771         case 8:
2772                 /* Scale */
2773                 if(select_area(SPACE_VIEW3D)) {
2774                         transform('s');
2775                 }
2776                 break;
2777         case 9:
2778                 /* Shear */
2779                 /* check that a valid object is selected to prevent crash */
2780                 if (!ob) error ("Only selected objects can be sheared");
2781                 else if ((ob->type==OB_LAMP) || (ob->type==OB_EMPTY) || (ob->type==OB_FONT) || (ob->type==OB_CAMERA)) {
2782                         error("Only editable 3D objects can be sheared");
2783                 }
2784                 else if ((base->lay & G.vd->lay)==0) {
2785                         error("Only objects on visible layers can be sheared");
2786                 }
2787                 else {
2788                         if (!G.obedit) {
2789                                 enter_editmode();
2790                                 /* ### put these into a deselectall_gen() */
2791                                 if(G.obedit->type==OB_MESH) deselectall_mesh();
2792                                 else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) deselectall_nurb();
2793                                 else if(G.obedit->type==OB_MBALL) deselectall_mball();
2794                                 else if(G.obedit->type==OB_LATTICE) deselectall_Latt();
2795                                 else if(G.obedit->type==OB_ARMATURE) deselectall_armature();
2796                                 /* ### */
2797                         }
2798                         if(select_area(SPACE_VIEW3D)) {
2799                                 transform('S');
2800                         }
2801                 }
2802                 if(select_area(SPACE_VIEW3D)) {
2803                         transform('S');
2804                 }
2805                 break;
2806         case 10:
2807                 /* Warp/Bend */
2808                 /* check that a valid object is selected to prevent crash */
2809                 if (!ob) error("Only selected objects can be warped");
2810                 else if ((ob->type==OB_LAMP) || (ob->type==OB_EMPTY) || (ob->type==OB_FONT) || (ob->type==OB_CAMERA)) {
2811                         error("Only editable 3D objects can be warped");
2812                 }
2813                 else if ((base->lay & G.vd->lay)==0) {
2814                         error("Only objects on visible layers can be warped");
2815                 }
2816                 else {
2817                         if (!G.obedit) {
2818                                 enter_editmode();
2819                                 /* ### put these into a deselectall_gen() */
2820                                 if(G.obedit->type==OB_MESH) deselectall_mesh();
2821                                 else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) deselectall_nurb();
2822                                 else if(G.obedit->type==OB_MBALL) deselectall_mball();
2823                                 else if(G.obedit->type==OB_LATTICE) deselectall_Latt();
2824                                 else if(G.obedit->type==OB_ARMATURE) deselectall_armature();
2825                                 /* ### */
2826                         }
2827                         if(select_area(SPACE_VIEW3D)) {
2828                                 transform('w');
2829                         }
2830                 }
2831                 break;
2832         case 11:
2833                 /* Snap */
2834                 if(select_area(SPACE_VIEW3D)) {
2835                         snapmenu();
2836                 }
2837                 break;
2838         }
2839         allqueue(REDRAWINFO, 0);
2840 }
2841
2842
2843 static uiBlock *info_editmenu(void *arg_unused)
2844 {
2845 /*      static short tog=0; */
2846         uiBlock *block;
2847         short xco= 0;
2848         
2849         block= uiNewBlock(&curarea->uiblocks, "editmenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
2850         uiBlockSetButmFunc(block, do_info_editmenu, NULL);
2851
2852         uiDefBut(block, BUTM, 1, "(De)Select All|A",    0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 0, "Select all objects in the scene or empty the selection");
2853         uiDefBut(block, BUTM, 1, "Border Select|B",             0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 1, "Select objects in a rectangular area (press B again to activate circle select in edit mode)");
2854
2855         /* uiDefBut(block, BUTM, 1, "Circle Select",            0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 2, "Select objects in a circular area"); */
2856         uiDefBut(block, SEPR, 0, "",                                    0, xco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
2857         uiDefBut(block, BUTM, 1, "Duplicate|Shift D",   0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 3, "Duplicate the selected object(s)");
2858         uiDefBut(block, BUTM, 1, "Delete|X",                    0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 4, "Delete the selected object(s)");
2859         uiDefBut(block, BUTM, 1, "Edit Mode|Tab",               0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 5, "Toggle between object and edit mode");
2860         uiDefBut(block, SEPR, 0, "",                                    0, xco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
2861         uiDefBut(block, BUTM, 1, "Grabber|G",                   0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 6, "Move the selected object(s)");
2862         uiDefBut(block, BUTM, 1, "Rotate|R",                    0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 7, "Rotate the selected object(s)");
2863         uiDefBut(block, BUTM, 1, "Scale|S",                             0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 8, "Scale the selected object(s)");
2864         uiDefBut(block, SEPR, 0, "",                                    0, xco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
2865         uiDefBut(block, BUTM, 1, "Shear|Ctrl S",                0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 9, "Shear the selected object(s)");
2866         uiDefBut(block, BUTM, 1, "Warp/Bend|Shift W",   0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 10, "Warp or bend the selected objects");
2867         uiDefBut(block, BUTM, 1, "Snap Menu|Shift S",   0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 11, "Activate the snap menu");
2868         
2869         uiBlockSetDirection(block, UI_DOWN);
2870         uiTextBoundsBlock(block, 80);
2871                 
2872         return block;
2873 }
2874
2875 static void do_info_add_meshmenu(void *arg, int event)
2876 {
2877
2878         switch(event) {         
2879 #ifdef EXPERIMENTAL_MENUS
2880         /* Maarten's proposal for a new Add Mesh menu */
2881                 case 0:
2882                         /* Line */
2883                         //add_primitiveMesh(4);
2884                         break;
2885                 case 1:
2886                         /* Circle */
2887                         if(select_area(SPACE_VIEW3D)) {
2888                                 add_primitiveMesh(4);
2889                         }
2890                         break;
2891                 case 2:
2892                         /* Plane */
2893                         add_primitiveMesh(0);
2894                         break;
2895                 case 3:
2896                         /* Cube */
2897                         add_primitiveMesh(1);
2898                         break;
2899                 case 4:
2900                         /* UVsphere */
2901                         add_primitiveMesh(11);
2902                         break;
2903                 case 5:
2904                         /* IcoSphere */
2905                         add_primitiveMesh(12);
2906                         break;
2907                 case 6:
2908                         /* Cylinder */
2909                         add_primitiveMesh(5);
2910                         break;
2911                 case 7:
2912                         /* Tube */
2913                         add_primitiveMesh(6);
2914                         break;
2915                 case 8:
2916                         /* Cone */
2917                         add_primitiveMesh(7);
2918                         break;
2919                 case 9:
2920                         /* Grid */
2921                         add_primitiveMesh(10);
2922                         break;
2923 #else /* EXPERIMENTAL_MENUS*/ 
2924                 case 0:
2925                         /* Plane */
2926                         add_primitiveMesh(0);
2927                         break;
2928                 case 1:
2929                         /* Cube */
2930                         add_primitiveMesh(1);
2931                         break;
2932                 case 2:
2933                         /* Circle */
2934                         add_primitiveMesh(4);
2935                         break;
2936                 case 3:
2937                         /* UVsphere */
2938                         add_primitiveMesh(11);
2939                         break;
2940                 case 4:
2941                         /* IcoSphere */
2942                         add_primitiveMesh(12);
2943                         break;
2944                 case 5:
2945                         /* Cylinder */
2946                         add_primitiveMesh(5);
2947                         break;
2948                 case 6:
2949                         /* Tube */
2950                         add_primitiveMesh(6);
2951                         break;
2952                 case 7:
2953                         /* Cone */
2954                         add_primitiveMesh(7);
2955                         break;
2956                 case 8:
2957                         /* Grid */
2958                         add_primitiveMesh(10);
2959                         break;
2960 #endif /* EXPERIMENTAL_MENUS */
2961                 default:
2962                         break;
2963         }
2964         allqueue(REDRAWINFO, 0);
2965 }
2966
2967 static uiBlock *info_add_meshmenu(void *arg_unused)
2968 {
2969 /*      static short tog=0; */
2970         uiBlock *block;
2971         short xco= 0;
2972         
2973         block= uiNewBlock(&curarea->uiblocks, "add_meshmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
2974         uiBlockSetButmFunc(block, do_info_add_meshmenu, NULL);
2975
2976 #ifdef EXPERIMENTAL_MENUS
2977         /* Maarten's proposal for a new Add Mesh menu */
2978         uiDefBut(block, BUTM, 1, "Line|",                                       0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "Add a Mesh Line");
2979         uiDefBut(block, BUTM, 1, "Circle|",                                     0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, "Add a Mesh Circle");
2980         uiDefBut(block, SEPR, 0, "",                                            0, xco-=6,  160, 6,  NULL, 0.0, 0.0, 0, 0, "");
2981         uiDefBut(block, BUTM, 1, "Plane|",                                      0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 2, "Add a Mesh Plane");
2982         uiDefBut(block, BUTM, 1, "Cube|",                                       0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 3, "Add a Mesh Cube");
2983         uiDefBut(block, BUTM, 1, "UVsphere",                            0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 4, "Add a Mesh Sphere");
2984         uiDefBut(block, BUTM, 1, "IcoSphere|",                          0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 5, "Add a Mesh Isocohedron Sphere");
2985         uiDefBut(block, BUTM, 1, "Cylinder With Caps|",         0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 6, "Add a Mesh Cylinder with caps");
2986         uiDefBut(block, BUTM, 1, "Cylinder Without Caps|",      0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 7, "Add a Mesh Cylinder without caps");
2987         uiDefBut(block, BUTM, 1, "Cone|",                                       0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 8, "Add a Mesh Cone");
2988         uiDefBut(block, BUTM, 1, "Grid|",                                       0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 9, "Add a Mesh Grid");
2989 #else /* EXPERIMENTAL_MENUS */
2990         uiDefBut(block, BUTM, 1, "Plane|",                              0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "Add a Mesh Plane");
2991         uiDefBut(block, BUTM, 1, "Cube|",                               0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, "Add a Mesh Cube");
2992         uiDefBut(block, BUTM, 1, "Circle|",                             0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 2, "Add a Mesh Circle");
2993         uiDefBut(block, BUTM, 1, "UVsphere",                    0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 3, "Add a Mesh Sphere");
2994         uiDefBut(block, BUTM, 1, "IcoSphere|",                  0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 4, "Add a Mesh Isocohedron Sphere");
2995         uiDefBut(block, BUTM, 1, "Cylinder|",                   0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 5, "Add a Mesh Cylinder");
2996         uiDefBut(block, BUTM, 1, "Tube|",                               0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 6, "Add a Mesh Tube");
2997         uiDefBut(block, BUTM, 1, "Cone|",                               0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 7, "Add a Mesh Cone");
2998         uiDefBut(block, SEPR, 0, "",                                    0, xco-=6,  160, 6,  NULL, 0.0, 0.0, 0, 0, "");
2999         uiDefBut(block, BUTM, 1, "Grid|",                               0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 8, "Add a Mesh Grid");
3000 #endif /* EXPERIMENTAL_MENUS */
3001
3002         uiBlockSetDirection(block, UI_RIGHT);
3003         uiTextBoundsBlock(block, 50);
3004                 
3005         return block;
3006 }
3007
3008 static void do_info_add_curvemenu(void *arg, int event)
3009 {
3010
3011         switch(event) {         
3012                 case 0:
3013                         /* Bezier Curve */
3014                         add_primitiveCurve(10);
3015                         break;