added a fullscreen button in the top header (windows only)
[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                 mainwindow_toggle_fullscreen((U.uiflag & FLIPFULLSCREEN));
1413                 break;
1414 #endif
1415
1416         /* Fileselect windows for user preferences file paths */
1417
1418         case B_FONTDIRFILESEL:  /* is button from space.c  *info* */
1419                 if(curarea->spacetype==SPACE_INFO) {
1420                         sa= closest_bigger_area();
1421                         areawinset(sa->win);
1422                 }
1423
1424                 activate_fileselect(FILE_SPECIAL, "SELECT FONT PATH", U.fontdir, filesel_u_fontdir);
1425                 break;
1426
1427         case B_TEXTUDIRFILESEL:         /* is button from space.c  *info* */
1428                 if(curarea->spacetype==SPACE_INFO) {
1429                         sa= closest_bigger_area();
1430                         areawinset(sa->win);
1431                 }
1432
1433                 activate_fileselect(FILE_SPECIAL, "SELECT TEXTURE PATH", U.textudir, filesel_u_textudir);
1434                 break;
1435         
1436         case B_PLUGTEXDIRFILESEL:       /* is button form space.c  *info* */
1437                 if(curarea->spacetype==SPACE_INFO) {
1438                         sa= closest_bigger_area();
1439                         areawinset(sa->win);
1440                 }
1441
1442                 activate_fileselect(FILE_SPECIAL, "SELECT TEX PLUGIN PATH", U.plugtexdir, filesel_u_plugtexdir);
1443                 break;
1444         
1445         case B_PLUGSEQDIRFILESEL:       /* is button from space.c  *info* */
1446                 if(curarea->spacetype==SPACE_INFO) {
1447                         sa= closest_bigger_area();
1448                         areawinset(sa->win);
1449                 }
1450
1451                 activate_fileselect(FILE_SPECIAL, "SELECT SEQ PLUGIN PATH", U.plugseqdir, filesel_u_plugseqdir);
1452                 break;
1453         
1454         case B_RENDERDIRFILESEL:        /* is button from space.c  *info* */
1455                 if(curarea->spacetype==SPACE_INFO) {
1456                         sa= closest_bigger_area();
1457                         areawinset(sa->win);
1458                 }
1459
1460                 activate_fileselect(FILE_SPECIAL, "SELECT RENDER PATH", U.renderdir, filesel_u_renderdir);
1461                 break;
1462         
1463         case B_PYTHONDIRFILESEL:        /* is button from space.c  *info* */
1464                 if(curarea->spacetype==SPACE_INFO) {
1465                         sa= closest_bigger_area();
1466                         areawinset(sa->win);
1467                 }
1468
1469                 activate_fileselect(FILE_SPECIAL, "SELECT SCRIPT PATH", U.pythondir, filesel_u_pythondir);
1470                 break;
1471
1472         case B_SOUNDDIRFILESEL:         /* is button from space.c  *info* */
1473                 if(curarea->spacetype==SPACE_INFO) {
1474                         sa= closest_bigger_area();
1475                         areawinset(sa->win);
1476                 }
1477
1478                 activate_fileselect(FILE_SPECIAL, "SELECT SOUND PATH", U.sounddir, filesel_u_sounddir);
1479                 break;
1480
1481         case B_TEMPDIRFILESEL:  /* is button from space.c  *info* */
1482                 if(curarea->spacetype==SPACE_INFO) {
1483                         sa= closest_bigger_area();
1484                         areawinset(sa->win);
1485                 }
1486
1487                 activate_fileselect(FILE_SPECIAL, "SELECT TEMP FILE PATH", U.tempdir, filesel_u_tempdir);
1488                 break;
1489
1490         /* END Fileselect windows for user preferences file paths */
1491
1492
1493 #ifdef INTERNATIONAL
1494         case B_LOADUIFONT:      /* is button from space.c  *info* */
1495                 if(curarea->spacetype==SPACE_INFO) {
1496                         sa= closest_bigger_area();
1497                         areawinset(sa->win);
1498                 }
1499                 BLI_make_file_string("/", buf, U.fontdir, U.fontname);
1500                 activate_fileselect(FILE_SPECIAL, "LOAD UI FONT", buf, set_interface_font);
1501                 break;
1502
1503         case B_SETLANGUAGE:     /* is button from space.c  *info* */
1504                 lang_setlanguage();
1505                 allqueue(REDRAWALL, 0);
1506                 break;
1507
1508         case B_SETFONTSIZE:     /* is button from space.c  *info* */
1509                 FTF_SetSize(U.fontsize);
1510                 allqueue(REDRAWALL, 0);
1511                 break;
1512                 
1513         case B_SETTRANSBUTS:    /* is button from space.c  *info* */
1514                 allqueue(REDRAWALL, 0);
1515                 break;
1516
1517         case B_DOLANGUIFONT:    /* is button from space.c  *info* */
1518                 if(U.transopts & TR_ALL)
1519                         set_ML_interface_font();
1520                 else
1521                         G.ui_international = FALSE;
1522                 allqueue(REDRAWALL, 0);
1523                 break;
1524
1525 #endif
1526                 
1527         case B_FULL:
1528                 if(curarea->spacetype!=SPACE_INFO) {
1529                         area_fullscreen();
1530                 }
1531                 break;  
1532
1533         case B_IDNAME:
1534                         /* changing a metaballs name, sadly enough,
1535                          * can require it to be updated because its
1536                          * basis might have changed... -zr
1537                          */
1538                 if (OBACT && OBACT->type==OB_MBALL)
1539                         makeDispList(OBACT);
1540                         
1541                 /* redraw because name has changed: new pup */
1542                 scrarea_queue_headredraw(curarea);
1543                 allqueue(REDRAWBUTSHEAD, 0);
1544                 allqueue(REDRAWINFO, 1);
1545                 allqueue(REDRAWOOPS, 1);
1546                 /* name scene also in set PUPmenu */
1547                 if ELEM(curarea->spacetype, SPACE_BUTS, SPACE_INFO) allqueue(REDRAWBUTSALL, 0);
1548
1549                 allqueue(REDRAWHEADERS, 0);
1550
1551                 break;
1552         
1553         case B_KEEPDATA:
1554                 /* keep datablock. similar to pressing FKEY in a fileselect window
1555                  * maybe we can move that stuff to a seperate function? -- sg
1556                  */
1557                 if (curarea->spacetype==SPACE_BUTS) {
1558                         id= (ID *)G.buts->lockpoin;
1559                 } else if(curarea->spacetype==SPACE_IPO) {
1560                         id = (ID *)G.sipo->ipo;
1561                 } /* similar for other spacetypes ? */
1562                 if (id) {
1563                         if( id->flag & LIB_FAKEUSER) {
1564                                 id->flag -= LIB_FAKEUSER;
1565                                 id->us--;
1566                         } else {
1567                                 id->flag |= LIB_FAKEUSER;
1568                                 id->us++;
1569                         }
1570                 }
1571                 allqueue(REDRAWHEADERS, 0);
1572
1573                 break;
1574         }
1575 }
1576
1577
1578 void do_global_buttons2(short event)
1579 {
1580         Base *base;
1581         Object *ob;
1582         Material *ma;
1583         MTex *mtex;
1584         Mesh *me;
1585         Curve *cu;
1586         MetaBall *mb;
1587         Ipo *ipo;
1588         Lamp *la;
1589         Lattice *lt;
1590         World *wrld;
1591         ID *idfrom;     
1592         bAction *act;
1593
1594         /* general:  Single User is allowed when from==LOCAL 
1595          *                       Make Local is allowed when (from==LOCAL && id==LIB)
1596          */
1597         
1598         ob= OBACT;
1599         
1600         switch(event) {
1601                 
1602         case B_LAMPALONE:
1603                 if(ob && ob->id.lib==0) {
1604                         la= ob->data;
1605                         if(la->id.us>1) {
1606                                 if(okee("Single user")) {
1607                                         ob->data= copy_lamp(la);
1608                                         la->id.us--;
1609                                 }
1610                         }
1611                 }
1612                 break;
1613         case B_LAMPLOCAL:
1614                 if(ob && ob->id.lib==0) {
1615                         la= ob->data;
1616                         if(la->id.lib) {
1617                                 if(okee("Make local")) {
1618                                         make_local_lamp(la);
1619                                 }
1620                         }
1621                 }
1622                 break;
1623         
1624         case B_ARMLOCAL:
1625                 if (ob&&ob->id.lib==0){
1626                         bArmature *arm=ob->data;
1627                         if (arm->id.lib){
1628                                 if(okee("Make local")) {
1629                                         make_local_armature(arm);
1630                                 }
1631                         }
1632                 }
1633                 break;
1634         case B_ARMALONE:
1635                 if(ob && ob->id.lib==0) {
1636                         bArmature *arm=ob->data;
1637                         if(arm->id.us>1) {
1638                                 if(okee("Single user")) {
1639                                         ob->data= copy_armature(arm);
1640                                         arm->id.us--;
1641                                 }
1642                         }
1643                 }
1644                 break;
1645         case B_ACTLOCAL:
1646                 if(ob && ob->id.lib==0) {
1647                         act= ob->action;
1648                         if(act->id.lib) {
1649                                 if(okee("Make local")) {
1650                                         make_local_action(act);
1651                                         allqueue(REDRAWACTION,0);
1652                                 }
1653                         }
1654                 }
1655                 break;
1656         case B_ACTALONE:
1657                 if (ob)
1658                         act= ob->action;
1659                 
1660                 if(ob && ob->id.lib==0) {
1661                         if(act->id.us>1) {
1662                                 if(okee("Single user")) {
1663                                         ob->action=copy_action(act);
1664                                         ob->activecon=NULL;
1665                                         act->id.us--;
1666                                         allqueue(REDRAWACTION, 0);
1667                                 }
1668                         }
1669                 }
1670                 break;
1671
1672         case B_CAMERAALONE:
1673                 if(ob && ob->id.lib==0) {
1674                         Camera *ca= ob->data;
1675                         if(ca->id.us>1) {
1676                                 if(okee("Single user")) {
1677                                         ob->data= copy_camera(ca);
1678                                         ca->id.us--;
1679                                 }
1680                         }
1681                 }
1682                 break;
1683         case B_CAMERALOCAL:
1684                 if(ob && ob->id.lib==0) {
1685                         Camera *ca= ob->data;
1686                         if(ca->id.lib) {
1687                                 if(okee("Make local")) {
1688                                         make_local_camera(ca);
1689                                 }
1690                         }
1691                 }
1692                 break;
1693         case B_WORLDALONE:
1694                 wrld= G.scene->world;
1695                 if(wrld->id.us>1) {
1696                         if(okee("Single user")) {
1697                                 G.scene->world= copy_world(wrld);
1698                                 wrld->id.us--;
1699                         }
1700                 }
1701                 break;
1702         case B_WORLDLOCAL:
1703                 wrld= G.scene->world;
1704                 if(wrld && wrld->id.lib) {
1705                         if(okee("Make local")) {
1706                                 make_local_world(wrld);
1707                         }
1708                 }
1709                 break;
1710
1711         case B_LATTALONE:
1712                 if(ob && ob->id.lib==0) {
1713                         lt= ob->data;
1714                         if(lt->id.us>1) {
1715                                 if(okee("Single user")) {
1716                                         ob->data= copy_lattice(lt);
1717                                         lt->id.us--;
1718                                 }
1719                         }
1720                 }
1721                 break;
1722         case B_LATTLOCAL:
1723                 if(ob && ob->id.lib==0) {
1724                         lt= ob->data;
1725                         if(lt->id.lib) {
1726                                 if(okee("Make local")) {
1727                                         make_local_lattice(lt);
1728                                 }
1729                         }
1730                 }
1731                 break;
1732         
1733         case B_MATALONE:
1734                 if(ob==0) return;
1735                 ma= give_current_material(ob, ob->actcol);
1736                 idfrom= material_from(ob, ob->actcol);
1737                 if(idfrom && idfrom->lib==0) {
1738                         if(ma->id.us>1) {
1739                                 if(okee("Single user")) {
1740                                         ma= copy_material(ma);
1741                                         ma->id.us= 0;
1742                                         assign_material(ob, ma, ob->actcol);
1743                                 }
1744                         }
1745                 }
1746                 break;
1747         case B_MATLOCAL:
1748                 if(ob==0) return;
1749                 idfrom= material_from(ob, ob->actcol);
1750                 if(idfrom->lib==0) {
1751                         ma= give_current_material(ob, ob->actcol);
1752                         if(ma && ma->id.lib) {
1753                                 if(okee("Make local")) {
1754                                         make_local_material(ma);
1755                                 }
1756                         }
1757                 }
1758                 break;
1759
1760         case B_MESHLOCAL:
1761                 if(ob && ob->id.lib==0) {
1762                         me= ob->data;
1763                         if(me && me->id.lib) {
1764                                 if(okee("Make local")) {
1765                                         make_local_mesh(me);
1766                                         make_local_key( me->key );
1767                                 }
1768                         }
1769                 }
1770                 break;
1771
1772         case B_MBALLALONE:
1773                 if(ob && ob->id.lib==0) {
1774                         mb= ob->data;
1775                         if(mb->id.us>1) {
1776                                 if(okee("Single user")) {
1777                                         ob->data= copy_mball(mb);
1778                                         mb->id.us--;
1779                                         if(ob==G.obedit) allqueue(REDRAWVIEW3D, 0);
1780                                 }
1781                         }
1782                 }
1783                 break;
1784         case B_MBALLLOCAL:
1785                 if(ob && ob->id.lib==0) {
1786                         mb= ob->data;
1787                         if(mb->id.lib) {
1788                                 if(okee("Make local")) {
1789                                         make_local_mball(mb);
1790                                 }
1791                         }
1792                 }
1793                 break;
1794
1795         case B_CURVEALONE:
1796                 if(ob && ob->id.lib==0) {
1797                         cu= ob->data;
1798                         if(cu->id.us>1) {
1799                                 if(okee("Single user")) {
1800                                         ob->data= copy_curve(cu);
1801                                         cu->id.us--;
1802                                         makeDispList(ob);
1803                                         if(ob==G.obedit) allqueue(REDRAWVIEW3D, 0);
1804                                 }
1805                         }
1806                 }
1807                 break;
1808         case B_CURVELOCAL:
1809                 if(ob && ob->id.lib==0) {
1810                         cu= ob->data;
1811                         if(cu->id.lib) {
1812                                 if(okee("Make local")) {
1813                                         make_local_curve(cu);
1814                                         make_local_key( cu->key );
1815                                         makeDispList(ob);
1816                                 }
1817                         }
1818                 }
1819                 break;
1820                 
1821         case B_TEXALONE:
1822                 if(G.buts->texfrom==0) {        /* from mat */
1823                         if(ob==0) return;
1824                         ma= give_current_material(ob, ob->actcol);
1825                         if(ma && ma->id.lib==0) {
1826                                 mtex= ma->mtex[ ma->texact ];
1827                                 if(mtex->tex && mtex->tex->id.us>1) {
1828                                         if(okee("Single user")) {
1829                                                 mtex->tex->id.us--;
1830                                                 mtex->tex= copy_texture(mtex->tex);
1831                                         }
1832                                 }
1833                         }
1834                 }
1835                 else if(G.buts->texfrom==1) {   /* from world */
1836                         wrld= G.scene->world;
1837                         if(wrld->id.lib==0) {
1838                                 mtex= wrld->mtex[ wrld->texact ];
1839                                 if(mtex->tex && mtex->tex->id.us>1) {
1840                                         if(okee("Single user")) {
1841                                                 mtex->tex->id.us--;
1842                                                 mtex->tex= copy_texture(mtex->tex);
1843                                         }
1844                                 }
1845                         }
1846                 }
1847                 else if(G.buts->texfrom==2) {   /* from lamp */
1848                         if(ob==0 || ob->type!=OB_LAMP) return;
1849                         la= ob->data;
1850                         if(la->id.lib==0) {
1851                                 mtex= la->mtex[ la->texact ];
1852                                 if(mtex->tex && mtex->tex->id.us>1) {
1853                                         if(okee("Single user")) {
1854                                                 mtex->tex->id.us--;
1855                                                 mtex->tex= copy_texture(mtex->tex);
1856                                         }
1857                                 }
1858                         }
1859                 }
1860                 break;
1861         case B_TEXLOCAL:
1862                 if(G.buts->texfrom==0) {        /* from mat */
1863                         if(ob==0) return;
1864                         ma= give_current_material(ob, ob->actcol);
1865                         if(ma && ma->id.lib==0) {
1866                                 mtex= ma->mtex[ ma->texact ];
1867                                 if(mtex->tex && mtex->tex->id.lib) {
1868                                         if(okee("Make local")) {
1869                                                 make_local_texture(mtex->tex);
1870                                         }
1871                                 }
1872                         }
1873                 }
1874                 else if(G.buts->texfrom==1) {   /* from world */
1875                         wrld= G.scene->world;
1876                         if(wrld->id.lib==0) {
1877                                 mtex= wrld->mtex[ wrld->texact ];
1878                                 if(mtex->tex && mtex->tex->id.lib) {
1879                                         if(okee("Make local")) {
1880                                                 make_local_texture(mtex->tex);
1881                                         }
1882                                 }
1883                         }
1884                 }
1885                 else if(G.buts->texfrom==2) {   /* from lamp */
1886                         if(ob==0 || ob->type!=OB_LAMP) return;
1887                         la= ob->data;
1888                         if(la->id.lib==0) {
1889                                 mtex= la->mtex[ la->texact ];
1890                                 if(mtex->tex && mtex->tex->id.lib) {
1891                                         if(okee("Make local")) {
1892                                                 make_local_texture(mtex->tex);
1893                                         }
1894                                 }
1895                         }
1896                 }
1897                 break;
1898         
1899         case B_IPOALONE:
1900                 ipo= get_ipo_to_edit(&idfrom);
1901                 
1902                 if(idfrom && idfrom->lib==0) {
1903                         if(ipo->id.us>1) {
1904                                 if(okee("Single user")) {
1905                                         if(ipo->blocktype==ID_OB) ((Object *)idfrom)->ipo= copy_ipo(ipo);
1906                                         else if(ipo->blocktype==ID_MA) ((Material *)idfrom)->ipo= copy_ipo(ipo);
1907                                         else if(ipo->blocktype==ID_SEQ) ((Sequence *)idfrom)->ipo= copy_ipo(ipo);
1908                                         else if(ipo->blocktype==ID_CU) ((Curve *)idfrom)->ipo= copy_ipo(ipo);
1909                                         else if(ipo->blocktype==ID_KE) ((Key *)idfrom)->ipo= copy_ipo(ipo);
1910                                         else if(ipo->blocktype==ID_LA) ((Lamp *)idfrom)->ipo= copy_ipo(ipo);
1911                                         else if(ipo->blocktype==ID_WO) ((World *)idfrom)->ipo= copy_ipo(ipo);
1912                                         else if(ipo->blocktype==ID_CA) ((Camera *)idfrom)->ipo= copy_ipo(ipo);
1913                                         else if(ipo->blocktype==ID_SO) ((bSound *)idfrom)->ipo= copy_ipo(ipo);
1914                                         else if(ipo->blocktype==ID_AC) get_hilighted_action_channel((bAction *)idfrom)->ipo= copy_ipo(ipo);
1915                                         else if(ipo->blocktype==IPO_CO) ((Object *)idfrom)->activecon->ipo= copy_ipo(ipo);
1916                                         else error("Warn ton!");
1917                                         
1918                                         ipo->id.us--;
1919                                         allqueue(REDRAWIPO, 0);
1920                                 }
1921                         }
1922                 }
1923                 break;
1924         case B_IPOLOCAL:
1925                 ipo= get_ipo_to_edit(&idfrom);
1926                 
1927                 if(idfrom && idfrom->lib==0) {
1928                         if(ipo->id.lib) {
1929                                 if(okee("Make local")) {
1930                                         make_local_ipo(ipo);
1931                                         allqueue(REDRAWIPO, 0);
1932                                 }
1933                         }
1934                 }
1935                 break;
1936
1937         case B_OBALONE:
1938                 if(G.scene->id.lib==0) {
1939                         if(ob->id.us>1) {
1940                                 if(okee("Single user")) {
1941                                         base= FIRSTBASE;
1942                                         while(base) {
1943                                                 if(base->object==ob) {
1944                                                         base->object= copy_object(ob);
1945                                                         ob->id.us--;
1946                                                         allqueue(REDRAWVIEW3D, 0);
1947                                                         break;
1948                                                 }
1949                                                 base= base->next;
1950                                         }
1951                                 }
1952                         }
1953                 }
1954                 break;
1955         case B_OBLOCAL:
1956                 if(G.scene->id.lib==0) {
1957                         if(ob->id.lib) {
1958                                 if(okee("Make local")) {
1959                                         make_local_object(ob);
1960                                         allqueue(REDRAWVIEW3D, 0);
1961                                 }
1962                         }
1963                 }
1964                 break;
1965         case B_MESHALONE:
1966                 if(ob && ob->id.lib==0) {
1967                         
1968                         me= ob->data;
1969                         
1970                         if(me && me->id.us>1) {
1971                                 if(okee("Single user")) {
1972                                         Mesh *men= copy_mesh(me);
1973                                         men->id.us= 0;
1974                                         
1975                                         set_mesh(ob, men);
1976                                         
1977                                         if(ob==G.obedit) allqueue(REDRAWVIEW3D, 0);
1978                                 }
1979                         }
1980                 }
1981                 break;
1982         }
1983         
1984         allqueue(REDRAWBUTSALL, 0);
1985         allqueue(REDRAWOOPS, 0);
1986 }
1987
1988 /* ********************** EMPTY ****************************** */
1989 /* ********************** INFO ****************************** */
1990
1991 int buttons_do_unpack()
1992 {
1993         int how;
1994         char menu[2048];
1995         char line[128];
1996         int ret_value = RET_OK, count = 0;
1997
1998         count = countPackedFiles();
1999
2000         if (count) {
2001                 if (count == 1) {
2002                         sprintf(menu, "Unpack 1 file%%t");
2003                 } else {
2004                         sprintf(menu, "Unpack %d files%%t", count);
2005                 }
2006                 
2007                 sprintf(line, "|Use files in current directory (create when necessary)%%x%d", PF_USE_LOCAL);
2008                 strcat(menu, line);
2009         
2010                 sprintf(line, "|Write files to current directory (overwrite existing files)%%x%d", PF_WRITE_LOCAL);
2011                 strcat(menu, line);
2012         
2013                 sprintf(line, "|%%l|Use files in original location (create when necessary)%%x%d", PF_USE_ORIGINAL);
2014                 strcat(menu, line);
2015         
2016                 sprintf(line, "|Write files to original location (overwrite existing files)%%x%d", PF_WRITE_ORIGINAL);
2017                 strcat(menu, line);
2018         
2019                 sprintf(line, "|%%l|Disable AutoPack, keep all packed files %%x%d", PF_KEEP);
2020                 strcat(menu, line);
2021         
2022                 sprintf(line, "|Ask for each file %%x%d", PF_ASK);
2023                 strcat(menu, line);
2024                 
2025                 how = pupmenu(menu);
2026                 
2027                 if(how != -1) {
2028                         if (how != PF_KEEP) {
2029                                 unpackAll(how);
2030                         }
2031                         G.fileflags &= ~G_AUTOPACK;
2032                 } else {
2033                         ret_value = RET_CANCEL;
2034                 }
2035         } else {
2036                 pupmenu("No packed files. Autopack disabled");
2037         }
2038         
2039         return (ret_value);
2040 }
2041
2042 /* here, because of all creator stuff */
2043
2044 Scene *copy_scene(Scene *sce, int level)
2045 {
2046         /* level 0: al objects shared
2047          * level 1: al object-data shared
2048          * level 2: full copy
2049          */
2050         Scene *scen;
2051         Base *base, *obase;
2052
2053
2054         /* level 0 */
2055         scen= copy_libblock(sce);
2056         duplicatelist(&(scen->base), &(sce->base));
2057         
2058         clear_id_newpoins();
2059         
2060         id_us_plus((ID *)scen->world);
2061         id_us_plus((ID *)scen->set);
2062         
2063         scen->ed= 0;
2064         scen->radio= 0;
2065         
2066         obase= sce->base.first;
2067         base= scen->base.first;
2068         while(base) {
2069                 base->object->id.us++;
2070                 if(obase==sce->basact) scen->basact= base;
2071                 
2072                 obase= obase->next;
2073                 base= base->next;
2074         }
2075         
2076         if(level==0) return scen;
2077         
2078         /* level 1 */
2079         G.scene= scen;
2080         single_object_users(0);
2081
2082         /*  camera */
2083         ID_NEW(G.scene->camera);
2084                 
2085         /* level 2 */
2086         if(level>=2) {
2087                 if(scen->world) {
2088                         scen->world->id.us--;
2089                         scen->world= copy_world(scen->world);
2090                 }
2091                 single_obdata_users(0);
2092                 single_mat_users_expand();
2093                 single_tex_users_expand();
2094         }
2095
2096         clear_id_newpoins();
2097
2098         BPY_copy_scriptlink(&sce->scriptlink);
2099
2100
2101
2102         // make a private copy of the avicodecdata
2103
2104         if (sce->r.avicodecdata) {
2105
2106                 scen->r.avicodecdata = MEM_dupallocN(sce->r.avicodecdata);
2107
2108                 scen->r.avicodecdata->lpFormat = MEM_dupallocN(scen->r.avicodecdata->lpFormat);
2109
2110                 scen->r.avicodecdata->lpParms = MEM_dupallocN(scen->r.avicodecdata->lpParms);
2111
2112         }
2113
2114         return scen;
2115 }
2116
2117 void do_info_buttons(unsigned short event)
2118 {
2119         bScreen *sc, *oldscreen;
2120         Scene *sce, *sce1;
2121         ScrArea *sa;
2122         int nr;
2123         
2124         switch(event) {
2125         
2126         case B_INFOSCR:         /* menu select screen */
2127
2128                 if( G.curscreen->screennr== -2) {
2129                         if(curarea->winy <50) {
2130                                 sa= closest_bigger_area();
2131                                 areawinset(sa->win);
2132                         }
2133                         activate_databrowse((ID *)G.curscreen, ID_SCR, 0, B_INFOSCR, &G.curscreen->screennr, do_info_buttons);
2134                         return;
2135                 }
2136                 if( G.curscreen->screennr < 0) return;
2137                 
2138                 sc= G.main->screen.first;
2139                 nr= 1;
2140                 while(sc) {
2141                         if(nr==G.curscreen->screennr) {
2142                                 if(is_allowed_to_change_screen(sc)) setscreen(sc);
2143                                 else error("Unable to perform function in EditMode");
2144                                 break;
2145                         }
2146                         nr++;
2147                         sc= sc->id.next;
2148                 }
2149                 /* last item: NEW SCREEN */
2150                 if(sc==0) {
2151                         duplicate_screen();
2152                 }
2153                 break;
2154         case B_INFODELSCR:
2155                 /* do this event only with buttons, so it can never be called with full-window */
2156
2157                 if(G.curscreen->id.prev) sc= G.curscreen->id.prev;
2158                 else if(G.curscreen->id.next) sc= G.curscreen->id.next;
2159                 else return;
2160                 if(okee("Delete current screen")) {
2161                         /* find new G.curscreen */
2162                         
2163                         oldscreen= G.curscreen;
2164                         setscreen(sc);          /* this test if sc has a full */
2165                         unlink_screen(oldscreen);
2166                         free_libblock(&G.main->screen, oldscreen);
2167                 }
2168                 scrarea_queue_headredraw(curarea);
2169
2170                 break;
2171         case B_INFOSCE:         /* menu select scene */
2172                 
2173                 if( G.obedit) {
2174                         error("Unable to perform function in EditMode");
2175                         return;
2176                 }
2177                 if( G.curscreen->scenenr== -2) {
2178                         if(curarea->winy <50) {
2179                                 sa= closest_bigger_area();
2180                                 areawinset(sa->win);
2181                         }
2182                         activate_databrowse((ID *)G.scene, ID_SCE, 0, B_INFOSCE, &G.curscreen->scenenr, do_info_buttons);
2183                         return;
2184                 }
2185                 if( G.curscreen->scenenr < 0) return;
2186
2187                 sce= G.main->scene.first;
2188                 nr= 1;
2189                 while(sce) {
2190                         if(nr==G.curscreen->scenenr) {
2191                                 if(sce!=G.scene) set_scene(sce);
2192                                 break;
2193                         }
2194                         nr++;
2195                         sce= sce->id.next;
2196                 }
2197                 /* last item: NEW SCENE */
2198                 if(sce==0) {
2199                         nr= pupmenu("Add scene%t|Empty|Link Objects|Link ObData|Full Copy");
2200                         if(nr<= 0) return;
2201                         if(nr==1) {
2202                                 sce= add_scene(G.scene->id.name+2);
2203                                 sce->r= G.scene->r;
2204                         }
2205                         else sce= copy_scene(G.scene, nr-2);
2206                         
2207                         set_scene(sce);
2208                 }
2209                 BIF_preview_changed(G.buts);
2210
2211                 break;
2212         case B_INFODELSCE:
2213                 
2214                 if(G.scene->id.prev) sce= G.scene->id.prev;
2215                 else if(G.scene->id.next) sce= G.scene->id.next;
2216                 else return;
2217                 if(okee("Delete current scene")) {
2218                         
2219                         /* check all sets */
2220                         sce1= G.main->scene.first;
2221                         while(sce1) {
2222                                 if(sce1->set == G.scene) sce1->set= 0;
2223                                 sce1= sce1->id.next;
2224                         }
2225                         
2226                         /* check all sequences */
2227                         clear_scene_in_allseqs(G.scene);
2228                         
2229                         /* al screens */
2230                         sc= G.main->screen.first;
2231                         while(sc) {
2232                                 if(sc->scene == G.scene) sc->scene= sce;
2233                                 sc= sc->id.next;
2234                         }
2235                         free_libblock(&G.main->scene, G.scene);
2236                         set_scene(sce);
2237                 }
2238         
2239                 break;
2240         case B_FILEMENU:
2241                 tbox_setmain(9);
2242                 toolbox();
2243                 break;
2244         }
2245 }
2246
2247 /* strubi shamelessly abused the status line as a progress bar... 
2248    feel free to kill him after release */
2249
2250 static int      g_progress_bar = 0;
2251 static char *g_progress_info = 0;
2252 static float g_done;
2253
2254 int start_progress_bar(void)
2255 {
2256         g_progress_bar = 1;
2257         return 1;               // we never fail (yet)
2258 }
2259
2260 void end_progress_bar(void)
2261 {
2262         g_progress_bar = 0;
2263 }
2264
2265 static void update_progress_bar(float done, char *info)
2266 {
2267         g_done = done;
2268         g_progress_info = info;
2269 }
2270
2271 /** Progress bar
2272         'done': a value between 0.0 and 1.0, showing progress
2273         'info': a info text what is currently being done
2274
2275         Make sure that the progress bar is always called with:
2276         done = 0.0 first
2277                 and
2278         done = 1.0 last -- or alternatively use:
2279
2280         start_progressbar();
2281         do_stuff_and_callback_progress_bar();
2282         end_progressbar();
2283 */
2284 int progress_bar(float done, char *busy_info)
2285 {
2286         ScrArea *sa;
2287         short val; 
2288
2289         /* User break (ESC) */
2290         while (qtest()) {
2291                 if (extern_qread(&val) == ESCKEY) 
2292                         return 0;
2293         }
2294         if (done == 0.0) {
2295                 start_progress_bar();
2296         } else if (done > 0.99) {
2297                 end_progress_bar();
2298         }
2299
2300         sa= G.curscreen->areabase.first;
2301         while(sa) {
2302                 if (sa->spacetype == SPACE_INFO) {
2303                         update_progress_bar(done, busy_info);
2304
2305                         curarea = sa;
2306
2307                         scrarea_do_headdraw(curarea);
2308                         areawinset(curarea->win);
2309                         sa->head_swap= WIN_BACK_OK;
2310                         screen_swapbuffers();
2311                 }
2312                 sa = sa->next;
2313         }
2314         return 1;
2315 }
2316
2317
2318 static void check_packAll()
2319 {
2320         // first check for dirty images
2321         Image *ima;
2322
2323         ima = G.main->image.first;
2324         while (ima) {
2325                 if (ima->ibuf && (ima->ibuf->userflags &= IB_BITMAPDIRTY)) {
2326                         break;
2327                 }
2328                 ima= ima->id.next;
2329         }
2330         
2331         if (ima == 0 || okee("Some images are painted on. These changes will be lost. Continue ?")) {
2332                 packAll();
2333                 G.fileflags |= G_AUTOPACK;
2334         }
2335 }
2336
2337
2338 int write_runtime(char *str, char *exename)
2339 {
2340         char *freestr= NULL;
2341         char *ext = 0;
2342
2343 #ifdef _WIN32
2344         ext = ".exe";
2345 #endif
2346
2347 #ifdef __APPLE__
2348         ext = ".app";
2349 #endif
2350         if (ext && (!BLI_testextensie(str, ext))) {
2351                 freestr= MEM_mallocN(strlen(str) + strlen(ext) + 1, "write_runtime_check");
2352                 strcpy(freestr, str);
2353                 strcat(freestr, ext);
2354                 str= freestr;
2355         }
2356
2357         if (!BLI_exists(str) || saveover(str))
2358                 BLO_write_runtime(str, exename);
2359
2360         if (freestr)
2361                 MEM_freeN(freestr);
2362         
2363         return 0;
2364 }
2365
2366 static void write_runtime_check_dynamic(char *str) 
2367 {
2368         write_runtime(str, "blenderdynplayer.exe");
2369 }
2370
2371 static void write_runtime_check(char *str) 
2372 {
2373         char player[128];
2374
2375         strcpy(player, "blenderplayer");
2376
2377 #ifdef _WIN32
2378         strcat(player, ".exe");
2379 #endif
2380
2381 #ifdef __APPLE__
2382         strcat(player, ".app");
2383 #endif
2384
2385         write_runtime(str, player);
2386 }
2387 /* end keyed functions */
2388
2389
2390 static void do_info_filemenu(void *arg, int event)
2391 {
2392         ScrArea *sa;
2393         char dir[FILE_MAXDIR];
2394         
2395         if(curarea->spacetype==SPACE_INFO) {
2396                 sa= closest_bigger_area();
2397                 areawinset(sa->win);
2398         }
2399
2400         /* these are no defines, easier this way, the codes are in the function below */
2401         switch(event) {
2402         case 0:
2403                 if (okee("ERASE ALL")) {
2404                         if (!BIF_read_homefile())
2405                                 error("No file ~/.B.blend");
2406                 }
2407                 break;
2408         case 1:
2409                 activate_fileselect(FILE_BLENDER, "LOAD FILE", G.sce, BIF_read_file);
2410                 break;
2411         case 2:
2412                 {
2413                         char *s= MEM_mallocN(strlen(G.sce) + 11 + 1, "okee_reload");
2414                         strcpy(s, "Open file: ");
2415                         strcat(s, G.sce);
2416                         if (okee(s))
2417                                 BIF_read_file(G.sce);
2418                         MEM_freeN(s);
2419                 }
2420                 break;
2421         case 3:
2422                 activate_fileselect(FILE_LOADLIB, "LOAD LIBRARY", G.lib, 0);
2423                 break;
2424         case 4:
2425                 strcpy(dir, G.sce);
2426                 untitled(dir);
2427                 activate_fileselect(FILE_BLENDER, "SAVE FILE", dir, BIF_write_file);
2428                 break;
2429         case 5:
2430                 strcpy(dir, G.sce);
2431                 if (untitled(dir)) {
2432                         activate_fileselect(FILE_BLENDER, "SAVE FILE", dir, BIF_write_file);
2433                 } else {
2434                         BIF_write_file(dir);
2435                         free_filesel_spec(dir);
2436                 }
2437                 break;
2438         case 6:
2439                 mainqenter(F3KEY, 1);
2440                 break;
2441         case 7:
2442                 write_vrml_fs();
2443                 break;
2444         case 8:
2445                 write_dxf_fs();
2446                 break;
2447         case 9:
2448                 write_videoscape_fs();
2449                 break;
2450 /*
2451         case 20:
2452                 strcpy(dir, G.sce);
2453                 activate_fileselect(FILE_SPECIAL, "INSTALL LICENSE KEY", dir, loadKeyboard);
2454                 break;
2455         case 21:
2456                 SHOW_LICENSE_KEY();
2457                 break;
2458 */
2459         case 22:
2460                 activate_fileselect(FILE_SPECIAL, "WRITE RUNTIME", "", write_runtime_check);
2461                 break;
2462         case 23:
2463                 activate_fileselect(FILE_SPECIAL, "WRITE DYNAMIC RUNTIME", "", write_runtime_check_dynamic);
2464                 break;
2465         case 30:
2466                 // import menu, no handling
2467                 break;
2468
2469 #ifdef EXPERIMENTAL_MENUS
2470         case 10:
2471                 check_packAll();
2472                 break;
2473         case 11:
2474                 unpackAll(PF_WRITE_LOCAL);
2475                 G.fileflags &= ~G_AUTOPACK;
2476                 break;
2477         case 12:
2478                 if (buttons_do_unpack() != RET_CANCEL) {
2479                         /* Clear autopack bit only if user selected one of the unpack options */
2480                         G.fileflags &= ~G_AUTOPACK;
2481                 }
2482                 break;
2483         case 13:
2484 #else /* EXPERIMENTAL_MENUS */
2485         case 10:
2486 #endif /* EXPERIMENTAL_MENUS */
2487                 exit_usiblender();
2488                 break;          
2489         }
2490         allqueue(REDRAWINFO, 0);
2491 }
2492
2493 void do_info_file_optionsmenu(void *arg, int event)
2494 {
2495         G.fileflags ^= (1 << event);
2496
2497         // allqueue(REDRAWINFO, 0);
2498 }
2499
2500
2501 static uiBlock *info_file_optionsmenu(void *arg_unused)
2502 {
2503         uiBlock *block;
2504         short yco= 0, xco = 20;
2505
2506         block= uiNewBlock(&curarea->uiblocks, "runtime_options", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
2507         uiBlockSetButmFunc(block, do_info_file_optionsmenu, NULL);
2508         uiBlockSetXOfs(block,-40);  // offset to parent button
2509
2510         /* flags are case-values */
2511         uiDefBut(block, BUTM, 1, "Compress File",       xco, yco-=20, 100, 19, NULL, 0.0, 0.0, 0, G_FILE_COMPRESS_BIT, "Use file compression");
2512 /*
2513         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");
2514         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");
2515 */
2516         uiTextBoundsBlock(block, 50);
2517
2518         /* Toggle buttons */
2519         
2520         yco= 0;
2521         xco -= 20;
2522         uiBlockSetEmboss(block, UI_EMBOSSW);
2523         uiBlockSetButmFunc(block, NULL, NULL);
2524         /* flags are defines */
2525         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, "");
2526 /*
2527         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, "");
2528         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, "");
2529 */
2530         uiBlockSetDirection(block, UI_RIGHT);
2531                 
2532         return block;
2533 }
2534
2535 static uiBlock *info_runtime_optionsmenu(void *arg_unused)
2536 {
2537         uiBlock *block;
2538         short yco= 0, xco = 20;
2539
2540         block= uiNewBlock(&curarea->uiblocks, "add_surfacemenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
2541         uiBlockSetXOfs(block, -40);  // offset to parent button
2542
2543         uiBlockSetEmboss(block, UI_EMBOSSW);
2544
2545         uiDefBut(block, LABEL, 0, "Size options:",              xco, yco-=20, 114, 19, 0, 0.0, 0.0, 0, 0, "");
2546         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");
2547         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");
2548
2549         uiDefBut(block, SEPR, 0, "",            xco, yco-=4, 114, 4, NULL, 0.0, 0.0, 0, 0, "");
2550
2551         uiDefBut(block, LABEL, 0, "Fullscreen options:",                xco, yco-=20, 114, 19, 0, 0.0, 0.0, 0, 0, "");
2552         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");
2553         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");
2554         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");
2555
2556         uiDefBut(block, SEPR, 0, "",            xco, yco-=4, 114, 4, NULL, 0.0, 0.0, 0, 0, "");
2557
2558         /* stereo settings */
2559         /* can't use any definition from the game engine here so hardcode it. Change it here when it changes there!
2560          * RAS_IRasterizer has definitions:
2561          * RAS_STEREO_NOSTEREO     1
2562          * RAS_STEREO_QUADBUFFERED 2
2563          * RAS_STEREO_ABOVEBELOW   3
2564          * RAS_STEREO_INTERLACED   4   future
2565          */
2566         uiDefBut(block, LABEL, 0, "Stereo options", xco, yco-=20, 114, 19, 0, 0.0, 0.0, 0, 0, "");
2567         uiDefButS(block, ROW, 0, "no stereo", xco+19, yco-=20, 95, 19, &(G.scene->r.stereomode), 6.0, 1.0, 0, 0, "Disables stereo");
2568         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");
2569         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");
2570 #if 0
2571         // future
2572         uiDefButS(block, ROW, 0, "syncdoubling", xco+19, yco, 95, 19, &(G.scene->r.stereomode), 5.0, 4.0, 0, 0, "Enables interlaced stereo method");
2573 #endif
2574
2575         uiBlockSetDirection(block, UI_RIGHT);
2576         uiTextBoundsBlock(block, 50);
2577                 
2578         return block;
2579 }
2580
2581 static uiBlock *info_file_importmenu(void *arg_unused)
2582 {
2583         uiBlock *block;
2584         short yco= 0, xco = 20;
2585
2586         block= uiNewBlock(&curarea->uiblocks, "importmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
2587         uiBlockSetXOfs(block, -40);  // offset to parent button
2588
2589         uiBlockSetEmboss(block, UI_EMBOSSW);
2590
2591         /* flags are defines */
2592         uiDefBut(block, LABEL, 0, "VRML 2.0 options", xco, yco, 125, 19,   NULL, 0.0, 0.0, 0, 0, "");
2593         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");
2594         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)");
2595         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");
2596
2597         uiBlockSetDirection(block, UI_RIGHT);
2598         uiTextBoundsBlock(block, 50);
2599                 
2600         return block;
2601 }
2602
2603 static uiBlock *info_filemenu(void *arg_unused)
2604 {
2605         uiBlock *block;
2606         short xco=0;
2607
2608         block= uiNewBlock(&curarea->uiblocks, "filemenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
2609         uiBlockSetButmFunc(block, do_info_filemenu, NULL);
2610         
2611         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)");
2612         uiDefBut(block, BUTM, 1, "Open|F1",                                     0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, "Open a new file");
2613         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");
2614         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");
2615         uiDefBlockBut(block, info_file_importmenu, NULL, "Import Settings|>>", 0, xco-=20, 160, 19, "");
2616
2617         uiDefBut(block, SEPR, 0, "",                                            0, xco-=6, 160, 6, NULL, 0.0, 0.0, 0, 0, "");
2618         uiDefBut(block, BUTM, 1, "Save As|F2",                          0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 4, "Save to a new file");
2619         uiDefBut(block, BUTM, 1, "Save|Ctrl W",                         0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 5, "Save to the current file");
2620
2621         uiDefBlockBut(block, info_file_optionsmenu, NULL, "File options|>>", 0, xco-=20, 160, 19, "Click to open the File Options menu");
2622
2623         uiDefBut(block, SEPR, 0, "",                                            0, xco-=6, 160, 6, NULL, 0.0, 0.0, 0, 0, "");
2624
2625         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");
2626 #ifdef _WIN32
2627         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)");
2628 #endif
2629         uiDefBlockBut(block, info_runtime_optionsmenu, NULL, "Runtime options|>>", 0, xco-=20, 160, 19, "Click to open the File Options menu");
2630
2631         uiDefBut(block, SEPR, 0, "",                                            0, xco-=6, 160, 6, NULL, 0.0, 0.0, 0, 0, "");
2632         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");
2633         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");
2634         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");
2635         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");
2636
2637
2638         /*
2639         if (LICENSE_KEY_VALID) {
2640                 uiDefBut(block, SEPR, 0, "",                                            0, xco-=6, 160, 6, NULL, 0.0, 0.0, 1, 0, "");
2641                 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");
2642                 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");
2643         } else if (I_AM_PUBLISHER) {
2644                 uiDefBut(block, SEPR, 0, "",                                            0, xco-=6, 160, 6, NULL, 0.0, 0.0, 1, 0, "");
2645                 uiDefBut(block, BUTM, 1, "Install License Key", 0, xco-=20,     140, 19, NULL, 0.0, 0.0, 1, 20, "Install your Blender License Key");
2646                 uiDefIconBut(block, BUTM, 1, ICON_PUBLISHER,                     141,xco,       19,  19, NULL, 0.0, 0.0, 1, 20, "Install your Blender License Key");
2647         }
2648         */
2649
2650
2651         uiDefBut(block, SEPR, 0, "",                                            0, xco-=6, 160, 6, NULL, 0.0, 0.0, 1, 0, "");
2652
2653 #ifdef EXPERIMENTAL_MENUS
2654         uiDefBut(block, BUTM, 1, "Pack Data",                                           0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 10, "");
2655         uiDefBut(block, BUTM, 1, "Unpack Data to current dir",          0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 11, "");
2656         uiDefBut(block, BUTM, 1, "Advanced Unpack",                                     0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 12, "");
2657         uiDefBut(block, SEPR, 0, "",                                            0, xco-=6, 160, 6, NULL, 0.0, 0.0, 1, 0, "");
2658         uiDefBut(block, BUTM, 1, "Quit | Q",                            0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 13, "Quit Blender immediately");
2659 #else /* EXPERIMENTAL_MENUS */
2660         uiDefBut(block, BUTM, 1, "Quit | Q",                            0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 10, "Quit Blender immediately");
2661 #endif /* EXPERIMENTAL_MENUS */
2662         uiBlockSetDirection(block, UI_DOWN);
2663
2664         uiTextBoundsBlock(block, 80);
2665
2666         return block;
2667 }
2668
2669 static void do_info_editmenu(void *arg, int event)
2670 {
2671         switch(event) {
2672                 
2673         case 0:
2674                 /* (De)Select All */
2675                 if(select_area(SPACE_VIEW3D)) mainqenter(AKEY, 1);
2676                 break;
2677                 /* Border Select */
2678         case 1:
2679                 if(select_area(SPACE_VIEW3D)) mainqenter(BKEY, 1);
2680                 break;
2681         case 2:
2682                 /* Circle Select */
2683                 /*if(select_area(SPACE_VIEW3D)) {
2684                         ;
2685                 }*/
2686                 break;
2687         case 3:
2688                 /* Duplicate */
2689                 if(select_area(SPACE_VIEW3D)) {
2690                         duplicate_context_selected();
2691                 }
2692                 break;
2693         case 4:
2694                 /* Delete */
2695                 if(select_area(SPACE_VIEW3D)) {
2696                         delete_context_selected();
2697                 }
2698                 break;
2699         case 5:
2700                 /* Edit Mode */
2701                 if(select_area(SPACE_VIEW3D)) {
2702                         blenderqread(TABKEY, 1);
2703                 }
2704                 break;
2705         case 6:
2706                 /* Grabber */
2707                 if(select_area(SPACE_VIEW3D)) {
2708                         transform('g');
2709                 }
2710                 break;
2711         case 7:
2712                 /* Rotate */
2713                 if(select_area(SPACE_VIEW3D)) {
2714                         transform('r');
2715                 }
2716                 break;
2717         case 8:
2718                 /* Scale */
2719                 if(select_area(SPACE_VIEW3D)) {
2720                         transform('s');
2721                 }
2722                 break;
2723         case 9:
2724                 /* Shear */
2725                 if (!G.obedit) {
2726                         enter_editmode();
2727                         /* ### put these into a deselectall_gen() */
2728                         if(G.obedit->type==OB_MESH) deselectall_mesh();
2729                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) deselectall_nurb();
2730                         else if(G.obedit->type==OB_MBALL) deselectall_mball();
2731                         else if(G.obedit->type==OB_LATTICE) deselectall_Latt();
2732                         /* ### */
2733                 }       
2734                 if(select_area(SPACE_VIEW3D)) {
2735                         transform('S');
2736                 }
2737                 break;
2738         case 10:
2739                 /* Warp/Bend */
2740                 if (!G.obedit) {
2741                         enter_editmode();
2742                         /* ### put these into a deselectall_gen() */
2743                         if(G.obedit->type==OB_MESH) deselectall_mesh();
2744                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) deselectall_nurb();
2745                         else if(G.obedit->type==OB_MBALL) deselectall_mball();
2746                         else if(G.obedit->type==OB_LATTICE) deselectall_Latt();
2747                         /* ### */
2748                 }       
2749                 if(select_area(SPACE_VIEW3D)) {
2750                         transform('w');
2751                 }
2752                 break;
2753         case 11:
2754                 /* Snap */
2755                 if(select_area(SPACE_VIEW3D)) {
2756                         snapmenu();
2757                 }
2758                 break;
2759         }
2760         allqueue(REDRAWINFO, 0);
2761 }
2762
2763
2764 static uiBlock *info_editmenu(void *arg_unused)
2765 {
2766 /*      static short tog=0; */
2767         uiBlock *block;
2768         short xco= 0;
2769         
2770         block= uiNewBlock(&curarea->uiblocks, "editmenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
2771         uiBlockSetButmFunc(block, do_info_editmenu, NULL);
2772
2773         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");
2774         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)");
2775
2776         /* uiDefBut(block, BUTM, 1, "Circle Select",            0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 2, "Select objects in a circular area"); */
2777         uiDefBut(block, SEPR, 0, "",                                    0, xco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
2778         uiDefBut(block, BUTM, 1, "Duplicate|Shift D",   0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 3, "Duplicate the selected object(s)");
2779         uiDefBut(block, BUTM, 1, "Delete|X",                    0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 4, "Delete the selected object(s)");
2780         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");
2781         uiDefBut(block, SEPR, 0, "",                                    0, xco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
2782         uiDefBut(block, BUTM, 1, "Grabber|G",                   0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 6, "Move the selected object(s)");
2783         uiDefBut(block, BUTM, 1, "Rotate|R",                    0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 7, "Rotate the selected object(s)");
2784         uiDefBut(block, BUTM, 1, "Scale|S",                             0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 8, "Scale the selected object(s)");
2785         uiDefBut(block, SEPR, 0, "",                                    0, xco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
2786         uiDefBut(block, BUTM, 1, "Shear|Ctrl S",                0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 9, "Shear the selected object(s)");
2787         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");
2788         uiDefBut(block, BUTM, 1, "Snap Menu|Shift S",   0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 11, "Activate the snap menu");
2789         
2790         uiBlockSetDirection(block, UI_DOWN);
2791         uiTextBoundsBlock(block, 80);
2792                 
2793         return block;
2794 }
2795
2796 static void do_info_add_meshmenu(void *arg, int event)
2797 {
2798
2799         switch(event) {         
2800 #ifdef EXPERIMENTAL_MENUS
2801         /* Maarten's proposal for a new Add Mesh menu */
2802                 case 0:
2803                         /* Line */
2804                         //add_primitiveMesh(4);
2805                         break;
2806                 case 1:
2807                         /* Circle */
2808                         if(select_area(SPACE_VIEW3D)) {
2809                                 add_primitiveMesh(4);
2810                         }
2811                         break;
2812                 case 2:
2813                         /* Plane */
2814                         add_primitiveMesh(0);
2815                         break;
2816                 case 3:
2817                         /* Cube */
2818                         add_primitiveMesh(1);
2819                         break;
2820                 case 4:
2821                         /* UVsphere */
2822                         add_primitiveMesh(11);
2823                         break;
2824                 case 5:
2825                         /* IcoSphere */
2826                         add_primitiveMesh(12);
2827                         break;
2828                 case 6:
2829                         /* Cylinder */
2830                         add_primitiveMesh(5);
2831                         break;
2832                 case 7:
2833                         /* Tube */
2834                         add_primitiveMesh(6);
2835                         break;
2836                 case 8:
2837                         /* Cone */
2838                         add_primitiveMesh(7);
2839                         break;
2840                 case 9:
2841                         /* Grid */
2842                         add_primitiveMesh(10);
2843                         break;
2844 #else /* EXPERIMENTAL_MENUS*/ 
2845                 case 0:
2846                         /* Plane */
2847                         add_primitiveMesh(0);
2848                         break;
2849                 case 1:
2850                         /* Cube */
2851                         add_primitiveMesh(1);
2852                         break;
2853                 case 2:
2854                         /* Circle */
2855                         add_primitiveMesh(4);
2856                         break;
2857                 case 3:
2858                         /* UVsphere */
2859                         add_primitiveMesh(11);
2860                         break;
2861                 case 4:
2862                         /* IcoSphere */
2863                         add_primitiveMesh(12);
2864                         break;
2865                 case 5:
2866                         /* Cylinder */
2867                         add_primitiveMesh(5);
2868                         break;
2869                 case 6:
2870                         /* Tube */
2871                         add_primitiveMesh(6);
2872                         break;
2873                 case 7:
2874                         /* Cone */
2875                         add_primitiveMesh(7);
2876                         break;
2877                 case 8:
2878                         /* Grid */
2879                         add_primitiveMesh(10);
2880                         break;
2881 #endif /* EXPERIMENTAL_MENUS */
2882                 default:
2883                         break;
2884         }
2885         allqueue(REDRAWINFO, 0);
2886 }
2887
2888 static uiBlock *info_add_meshmenu(void *arg_unused)
2889 {
2890 /*      static short tog=0; */
2891         uiBlock *block;
2892         short xco= 0;
2893         
2894         block= uiNewBlock(&curarea->uiblocks, "add_meshmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
2895         uiBlockSetButmFunc(block, do_info_add_meshmenu, NULL);
2896
2897 #ifdef EXPERIMENTAL_MENUS
2898         /* Maarten's proposal for a new Add Mesh menu */
2899         uiDefBut(block, BUTM, 1, "Line|",                                       0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "Add a Mesh Line");
2900         uiDefBut(block, BUTM, 1, "Circle|",                                     0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, "Add a Mesh Circle");
2901         uiDefBut(block, SEPR, 0, "",                                            0, xco-=6,  160, 6,  NULL, 0.0, 0.0, 0, 0, "");
2902         uiDefBut(block, BUTM, 1, "Plane|",                                      0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 2, "Add a Mesh Plane");
2903         uiDefBut(block, BUTM, 1, "Cube|",                                       0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 3, "Add a Mesh Cube");
2904         uiDefBut(block, BUTM, 1, "UVsphere",                            0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 4, "Add a Mesh Sphere");
2905         uiDefBut(block, BUTM, 1, "IcoSphere|",                          0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 5, "Add a Mesh Isocohedron Sphere");
2906         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");
2907         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");
2908         uiDefBut(block, BUTM, 1, "Cone|",                                       0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 8, "Add a Mesh Cone");
2909         uiDefBut(block, BUTM, 1, "Grid|",                                       0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 9, "Add a Mesh Grid");
2910 #else /* EXPERIMENTAL_MENUS */
2911         uiDefBut(block, BUTM, 1, "Plane|",                              0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "Add a Mesh Plane");
2912         uiDefBut(block, BUTM, 1, "Cube|",                               0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, "Add a Mesh Cube");
2913         uiDefBut(block, BUTM, 1, "Circle|",                             0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 2, "Add a Mesh Circle");
2914         uiDefBut(block, BUTM, 1, "UVsphere",                    0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 3, "Add a Mesh Sphere");
2915         uiDefBut(block, BUTM, 1, "IcoSphere|",                  0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 4, "Add a Mesh Isocohedron Sphere");
2916         uiDefBut(block, BUTM, 1, "Cylinder|",                   0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 5, "Add a Mesh Cylinder");
2917         uiDefBut(block, BUTM, 1, "Tube|",                               0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 6, "Add a Mesh Tube");
2918         uiDefBut(block, BUTM, 1, "Cone|",                               0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 7, "Add a Mesh Cone");
2919         uiDefBut(block, SEPR, 0, "",                                    0, xco-=6,  160, 6,  NULL, 0.0, 0.0, 0, 0, "");
2920         uiDefBut(block, BUTM, 1, "Grid|",                               0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 8, "Add a Mesh Grid");
2921 #endif /* EXPERIMENTAL_MENUS */
2922
2923         uiBlockSetDirection(block, UI_RIGHT);
2924         uiTextBoundsBlock(block, 50);
2925                 
2926         return block;
2927 }
2928
2929 static void do_info_add_curvemenu(void *arg, int event)
2930 {
2931
2932         switch(event) {         
2933                 case 0:
2934                         /* Bezier Curve */
2935                         add_primitiveCurve(10);
2936                         break;
2937                 case 1:
2938                         /* Bezier Circle */
2939                         add_primitiveCurve(11);
2940                         break;
2941                 case 2:
2942                         /* NURB Curve */
2943                         add_primitiveCurve(40);
2944                         break;
2945                 case 3:
2946                         /* NURB Circle */
2947                         add_primitiveCurve(41);
2948                         break;
2949                 case 4:
2950                         /* Path */
2951                         add_primitiveCurve(46);
2952                         break;
2953                 default:
2954                         break;
2955         }
2956         allqueue(REDRAWINFO, 0);
2957 }
2958
2959 static uiBlock *info_add_curvemenu(void *arg_unused)
2960 {
2961 /*      static short tog=0; */
2962         uiBlock *block;
2963         short xco= 0;
2964         
2965         block= uiNewBlock(&curarea->uiblocks, "add_curvemenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
2966         uiBlockSetButmFunc(block, do_info_add_curvemenu, NULL);
2967
2968         uiDefBut(block, BUTM, 1, "Bezier Curve|",       0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "Add a Bezier curve");
2969         uiDefBut(block, BUTM, 1, "Bezier Circle|",      0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, "Add a Bezier circle");
2970         uiDefBut(block, BUTM, 1, "NURBS Curve|",                0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 2, "Add a NURB curve");
2971         uiDefBut(block, BUTM, 1, "NURBS Circle",                0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 3, "Add a NURB circle");
2972         uiDefBut(block, BUTM, 1, "Path|",                       0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 4, "Add a path");
2973         
2974         uiBlockSetDirection(block, UI_RIGHT);
2975         uiTextBoundsBlock(block, 50);
2976                 
2977         return block;
2978 }
2979
2980
2981 static void do_info_add_surfacemenu(void *arg, int event)
2982 {
2983
2984         switch(event) {         
2985                 case 0:
2986                         /* Curve */
2987                         add_primitiveNurb(0);
2988                         break;
2989                 case 1:
2990                         /* Circle */
2991                         add_primitiveNurb(1);
2992                         break;
2993                 case 2:
2994                         /* Surface */
2995                         add_primitiveNurb(2);
2996                         break;
2997                 case 3:
2998                         /* Tube */
2999                         add_primitiveNurb(3);
3000                         break;
3001                 case 4:
3002                         /* Sphere */
3003                         add_primitiveNurb(4);
3004                         break;
3005                 case 5:
3006                         /* Donut */
3007                         add_primitiveNurb(5);
3008                         break;
3009                 default:
3010                         break;
3011         }
3012         allqueue(REDRAWINFO, 0);
3013 }
3014
3015 static uiBlock *info_add_surfacemenu(void *arg_unused)
3016 {
3017 /*      static short tog=0; */
3018         uiBlock *block;
3019         short xco= 0;
3020         
3021         block= uiNewBlock(&curarea->uiblocks, "add_surfacemenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
3022         uiBlockSetButmFunc(block, do_info_add_surfacemenu, NULL);
3023