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