2.5
[blender-staging.git] / source / blender / editors / space_file / file_header.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL 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. 
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2008 Blender Foundation.
21  * All rights reserved.
22  *
23  * 
24  * Contributor(s): Blender Foundation
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 #include <string.h>
30 #include <stdio.h>
31
32 #include "DNA_space_types.h"
33 #include "DNA_scene_types.h"
34 #include "DNA_screen_types.h"
35 #include "DNA_windowmanager_types.h"
36
37 #include "MEM_guardedalloc.h"
38
39 #include "BLI_blenlib.h"
40
41 #include "BKE_global.h"
42 #include "BKE_screen.h"
43
44 #include "ED_screen.h"
45 #include "ED_util.h"
46
47 #include "WM_api.h"
48 #include "WM_types.h"
49
50 #include "BIF_gl.h"
51 #include "BIF_glutil.h"
52
53 #include "UI_interface.h"
54 #include "UI_resources.h"
55 #include "UI_view2d.h"
56
57
58 /* ************************ header area region *********************** */
59
60 static void do_viewmenu(bContext *C, void *arg, int event)
61 {
62         
63 }
64
65 static uiBlock *dummy_viewmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
66 {
67         ScrArea *curarea= C->area;
68         uiBlock *block;
69         short yco= 0, menuwidth=120;
70         
71         block= uiBeginBlock(C, handle->region, "dummy_viewmenu", UI_EMBOSSP, UI_HELV);
72         uiBlockSetButmFunc(block, do_viewmenu, NULL);
73         
74         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Nothing yet", 0, yco-=20, 
75                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
76         
77         if(curarea->headertype==HEADERTOP) {
78                 uiBlockSetDirection(block, UI_DOWN);
79         }
80         else {
81                 uiBlockSetDirection(block, UI_TOP);
82                 uiBlockFlipOrder(block);
83         }
84         
85         uiTextBoundsBlock(block, 50);
86         uiEndBlock(C, block);
87         
88         return block;
89 }
90
91 #define B_NEWSPACE              100
92
93 static void do_file_buttons(bContext *C, void *arg, int event)
94 {
95         switch(event) {
96                 case B_NEWSPACE:
97                         ED_newspace(C->area, C->area->butspacetype);
98                         WM_event_add_notifier(C, WM_NOTE_SCREEN_CHANGED, 0, NULL);
99                         break;
100                 }
101 }
102
103
104 void file_header_buttons(const bContext *C, ARegion *ar)
105 {
106         ScrArea *sa= C->area;
107         uiBlock *block;
108         short xco, yco= 3;
109         
110         block= uiBeginBlock(C, ar, "header buttons", UI_EMBOSS, UI_HELV);
111         uiBlockSetHandleFunc(block, do_file_buttons, NULL);
112         
113         if(ED_screen_area_active(C)) uiBlockSetCol(block, TH_HEADER);
114         else uiBlockSetCol(block, TH_HEADERDESEL);
115
116         xco = 8;
117         
118         uiDefIconTextButC(block, ICONTEXTROW,B_NEWSPACE, ICON_VIEW3D, 
119                                           windowtype_pup(), xco, yco, XIC+10, YIC, 
120                                           &(C->area->butspacetype), 1.0, SPACEICONMAX, 0, 0, 
121                                           "Displays Current Window Type. "
122                                           "Click for menu of available types.");
123         
124         xco += XIC + 14;
125         
126         uiBlockSetEmboss(block, UI_EMBOSSN);
127         if (sa->flag & HEADER_NO_PULLDOWN) {
128                 uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, 0, 
129                                                  ICON_DISCLOSURE_TRI_RIGHT,
130                                                  xco,yco,XIC,YIC-2,
131                                                  &(sa->flag), 0, 0, 0, 0, 
132                                                  "Show pulldown menus");
133         }
134         else {
135                 uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, 0, 
136                                                  ICON_DISCLOSURE_TRI_DOWN,
137                                                  xco,yco,XIC,YIC-2,
138                                                  &(sa->flag), 0, 0, 0, 0, 
139                                                  "Hide pulldown menus");
140         }
141         uiBlockSetEmboss(block, UI_EMBOSS);
142         xco+=XIC;
143         
144         if((sa->flag & HEADER_NO_PULLDOWN)==0) {
145                 int xmax;
146                 
147                 /* pull down menus */
148                 uiBlockSetEmboss(block, UI_EMBOSSP);
149                 
150                 xmax= GetButStringLength("View");
151                 uiDefPulldownBut(block, dummy_viewmenu, C->area, 
152                                                  "View", xco, yco-2, xmax-3, 24, "");
153                 xco+=XIC+xmax;
154         }
155         
156         uiBlockSetEmboss(block, UI_EMBOSS);
157
158         /* always as last  */
159         sa->headbutlen= xco+XIC+80; // +80 because the last button is not an icon
160         
161         uiEndBlock(C, block);
162         uiDrawBlock(block);
163 }
164
165