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