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