2 * header_script.c nov-2003
4 * Functions to draw the "Script Window" window header
5 * and handle user events sent to it.
9 * ***** BEGIN GPL LICENSE BLOCK *****
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software Foundation,
23 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
26 * All rights reserved.
28 * Contributor(s): Willian P. Germano.
30 * ***** END GPL LICENSE BLOCK *****
41 #include "BLI_blenlib.h"
43 #include "BSE_headerbuttons.h"
46 #include "DNA_screen_types.h"
47 #include "DNA_space_types.h"
49 #include "BIF_interface.h"
50 #include "BIF_resources.h"
51 #include "BIF_screen.h"
52 #include "BIF_space.h"
53 #include "BIF_toolbox.h"
54 #include "BKE_global.h"
55 #include "BKE_library.h"
58 #include "BSE_filesel.h"
60 #ifndef DISABLE_PYTHON
61 #include "BPY_extern.h"
62 #include "BPY_menus.h"
68 #include "BLO_sys_types.h" // for intptr_t support
70 /* ********************** SCRIPT ****************************** */
72 /* action executed after clicking in Scripts menu */
73 #ifndef DISABLE_PYTHON
74 static void do_scripts_submenus(void *int_arg, int event)
76 int menutype = (intptr_t)int_arg;
78 BPY_menu_do_python (menutype, event);
80 //allqueue(REDRAWSCRIPT, 0);
83 static uiBlock *script_scripts_submenus(void *int_menutype)
86 short yco = 20, menuwidth = 120;
88 int i = 0, menutype = (intptr_t)int_menutype;
90 if ((menutype < 0) || (menutype > PYMENU_SCRIPTS_MENU_TOTAL))
93 block= uiNewBlock(&curarea->uiblocks, "scriptsscriptssubmenus", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
94 uiBlockSetButmFunc(block, do_scripts_submenus, int_menutype);
96 for (pym = BPyMenuTable[menutype]; pym; pym = pym->next, i++) {
97 uiDefIconTextBut(block, BUTM, 1, ICON_PYTHON, pym->name, 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, i, pym->tooltip?pym->tooltip:pym->filename);
100 uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
102 uiBlockSetDirection(block, UI_RIGHT);
103 uiTextBoundsBlock(block, 60);
108 static void do_script_scriptsmenu(void *arg, int event)
112 if(curarea->spacetype==SPACE_INFO) {
113 sa= closest_bigger_area();
117 /* these are no defines, easier this way, the codes are in the function below */
119 case 0: /* update menus */
120 if (BPY_path_update()==0) {
121 error("Invalid scripts dir: check console");
126 // allqueue(REDRAWSCRIPT, 0);
130 static uiBlock *script_scriptsmenu(void *arg_unused)
133 short yco = 0, menuwidth = 120;
136 block= uiNewBlock(&curarea->uiblocks, "script_scriptsmenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
137 uiBlockSetButmFunc(block, do_script_scriptsmenu, NULL);
139 for (i = 0; i < PYMENU_SCRIPTS_MENU_TOTAL; i++) {
140 uiDefIconTextBlockBut(block, script_scripts_submenus, (void *)(intptr_t)i, ICON_RIGHTARROW_THIN, BPyMenu_group_itoa(i), 0, yco-=20, menuwidth, 19, "");
143 uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
145 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Update Menus", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "Use when a scripts folder or its contents are modified");
147 if(curarea->headertype==HEADERTOP) {
148 uiBlockSetDirection(block, UI_DOWN);
151 uiBlockSetDirection(block, UI_TOP);
152 uiBlockFlipOrder(block);
155 uiTextBoundsBlock(block, 50);
158 #endif /* DISABLE_PYTHON */
160 void do_script_buttons(unsigned short event)
162 SpaceScript *sc= curarea->spacedata.first;
165 Script *script = sc->script;
167 #ifndef DISABLE_PYTHON
169 if (sc->spacetype != SPACE_SCRIPT) return;
173 if (sc->menunr==-2) {
174 activate_databrowse((ID *)script, ID_SCR, 0, B_SCRIPTBROWSE,
175 &sc->menunr, do_script_buttons);
179 if(sc->menunr < 0) break;
184 idtest= G.main->script.first;
190 idtest= idtest->next;
193 sc->script= (Script *)idtest;
195 allqueue(REDRAWSCRIPT, 0);
196 allqueue(REDRAWHEADERS, 0);
201 BLI_remlink(&curarea->spacedata, sc);
202 BLI_addtail(&curarea->spacedata, sc);
203 sc = curarea->spacedata.first;
204 newspace(curarea, sc->spacetype);
212 void script_buttons(void)
215 SpaceScript *sc= curarea->spacedata.first;
219 if (!sc || sc->spacetype != SPACE_SCRIPT) return;
221 sprintf(naam, "header %d", curarea->headwin);
222 block= uiNewBlock(&curarea->uiblocks, naam, UI_EMBOSS, UI_HELV, curarea->headwin);
224 if(area_is_active_area(curarea)) uiBlockSetCol(block, TH_HEADER);
225 else uiBlockSetCol(block, TH_HEADERDESEL);
227 curarea->butspacetype= SPACE_SCRIPT;
229 uiDefIconTextButC(block, ICONTEXTROW,B_NEWSPACE, ICON_VIEW3D,
230 windowtype_pup(), xco,0,XIC+10,YIC, &(curarea->butspacetype), 1.0,
231 SPACEICONMAX, 0, 0, "Displays Current Window Type. Click for menu"
232 " of available types.");
235 uiBlockSetEmboss(block, UI_EMBOSSN);
236 if(curarea->flag & HEADER_NO_PULLDOWN) {
237 uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, B_FLIPINFOMENU, ICON_DISCLOSURE_TRI_RIGHT,
239 &(curarea->flag), 0, 0, 0, 0, "Enables display of pulldown menus");
241 uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, B_FLIPINFOMENU, ICON_DISCLOSURE_TRI_DOWN,
243 &(curarea->flag), 0, 0, 0, 0, "Hides pulldown menus");
245 uiBlockSetEmboss(block, UI_EMBOSS);
248 #ifndef DISABLE_PYTHON
249 /* pull down menus */
250 if((curarea->flag & HEADER_NO_PULLDOWN)==0) {
251 uiBlockSetEmboss(block, UI_EMBOSSP);
253 xmax= GetButStringLength("Scripts");
254 uiDefPulldownBut(block,script_scriptsmenu, NULL, "Scripts", xco, 0, xmax, 20, "");
258 uiBlockSetEmboss(block, UI_EMBOSS);
260 uiBlockBeginAlign(block);
261 uiDefIconBut(block, BUT, B_SCRIPT2PREV, ICON_GO_LEFT, xco+=XIC, 0, XIC, YIC,
262 0, 0, 0, 0, 0, "Returns to previous window");
266 uiDefIconBut(block, BUT,B_FULL, ICON_SPLITSCREEN, xco+=XIC,0,XIC,YIC, 0, 0,
267 0, 0, 0, "Returns to multiple views window (CTRL+Up arrow)");
269 uiDefIconBut(block, BUT,B_FULL, ICON_FULLSCREEN, xco+=XIC,0,XIC,YIC, 0, 0,
270 0, 0, 0, "Makes current window full screen (CTRL+Down arrow)");
271 uiBlockEndAlign(block);
273 /* STD SCRIPT BUTTONS */
275 xco= std_libbuttons(block, xco, 0, 0, NULL, B_SCRIPTBROWSE, ID_SCRIPT, 0, (ID*)sc->script, 0, &(sc->menunr), 0, 0, 0, 0, 0);
278 curarea->headbutlen= xco+2*XIC;
284 /* ********************** SCRIPT ****************************** */