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