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