1 /********************************************************************************
2 * *
3 * Test Tab Book *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1997 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * $Id: tabbook.cpp,v 1.23 2006/02/06 03:06:51 fox Exp $ *
9 ********************************************************************************/
10 #include "fx.h"
11
12
13 // Main Window
14 class TabBookWindow : public FXMainWindow {
15 FXDECLARE(TabBookWindow)
16 protected:
17
18 // Member data
19 FXMenuBar* menubar;
20 FXMenuPane* filemenu;
21 FXMenuPane* tabmenu;
22 FXHorizontalFrame* contents;
23 FXTabBook* tabbook;
24 FXTabItem* tab1;
25 FXTabItem* tab2;
26 FXTabItem* tab3;
27 FXTabItem* tab4;
28 FXHorizontalFrame* listframe;
29 FXHorizontalFrame* fileframe;
30 FXHorizontalFrame* dirframe;
31 FXHorizontalFrame* textframe;
32 FXList* simplelist;
33 FXFileList* filelist;
34 FXDirList* dirlist;
35 FXText* text;
36
37 protected:
38
TabBookWindow()39 TabBookWindow(){}
40
41 public:
42
43 // Message handlers
44 long onCmdTabOrient(FXObject*,FXSelector,void*);
45 long onCmdPackUniformWidth(FXObject*,FXSelector,void*);
46 long onCmdPackNonUniformWidth(FXObject*,FXSelector,void*);
47 long onCmdHideShow(FXObject*,FXSelector,void*);
48 long onCmdPanel(FXObject*,FXSelector,void*);
49
50 public:
51
52 // Messages
53 enum{
54 ID_TABS_TOP=FXMainWindow::ID_LAST,
55 ID_TABS_BOTTOM,
56 ID_TABS_LEFT,
57 ID_TABS_RIGHT,
58 ID_HIDESHOW,
59 ID_PANEL,
60 ID_PACK_UNIFORM_WIDTH,
61 ID_PACK_NON_UNIFORM_WIDTH,
62 };
63 public:
64 TabBookWindow(FXApp* a);
65 virtual void create();
66 virtual ~TabBookWindow();
67 };
68
69
70 /*******************************************************************************/
71
72 // Map
73 FXDEFMAP(TabBookWindow) TabBookWindowMap[]={
74 FXMAPFUNCS(SEL_COMMAND,TabBookWindow::ID_TABS_TOP,TabBookWindow::ID_TABS_RIGHT,TabBookWindow::onCmdTabOrient),
75 FXMAPFUNC(SEL_COMMAND,TabBookWindow::ID_HIDESHOW,TabBookWindow::onCmdHideShow),
76 FXMAPFUNC(SEL_COMMAND,TabBookWindow::ID_PANEL,TabBookWindow::onCmdPanel),
77 FXMAPFUNC(SEL_COMMAND,TabBookWindow::ID_PACK_UNIFORM_WIDTH,TabBookWindow::onCmdPackUniformWidth),
78 FXMAPFUNC(SEL_COMMAND,TabBookWindow::ID_PACK_NON_UNIFORM_WIDTH,TabBookWindow::onCmdPackNonUniformWidth),
79 };
80
81
82 // Object implementation
FXIMPLEMENT(TabBookWindow,FXMainWindow,TabBookWindowMap,ARRAYNUMBER (TabBookWindowMap))83 FXIMPLEMENT(TabBookWindow,FXMainWindow,TabBookWindowMap,ARRAYNUMBER(TabBookWindowMap))
84
85
86 /*******************************************************************************/
87
88
89 // Make some windows
90 TabBookWindow::TabBookWindow(FXApp *a):FXMainWindow(a,"Tab Book Test",NULL,NULL,DECOR_ALL,0,0,600,400){
91 FXHorizontalFrame *boxframe;
92
93 // Tooltip
94 new FXToolTip(getApp());
95
96 // Menubar
97 menubar=new FXMenuBar(this,LAYOUT_SIDE_TOP|LAYOUT_FILL_X);
98
99 // Separator
100 new FXHorizontalSeparator(this,LAYOUT_SIDE_TOP|LAYOUT_FILL_X|SEPARATOR_GROOVE);
101
102 // Contents
103 contents=new FXHorizontalFrame(this,LAYOUT_SIDE_TOP|FRAME_NONE|LAYOUT_FILL_X|LAYOUT_FILL_Y|PACK_UNIFORM_WIDTH);
104
105 // Switcher
106 tabbook=new FXTabBook(contents,this,ID_PANEL,PACK_UNIFORM_WIDTH|PACK_UNIFORM_HEIGHT|LAYOUT_FILL_X|LAYOUT_FILL_Y|LAYOUT_RIGHT);
107
108 // First item is a list
109 tab1=new FXTabItem(tabbook,"&Simple List",NULL);
110
111 listframe=new FXHorizontalFrame(tabbook,FRAME_THICK|FRAME_RAISED);
112 boxframe=new FXHorizontalFrame(listframe,FRAME_THICK|FRAME_SUNKEN|LAYOUT_FILL_X|LAYOUT_FILL_Y, 0,0,0,0, 0,0,0,0);
113 simplelist=new FXList(boxframe,NULL,0,LIST_EXTENDEDSELECT|LAYOUT_FILL_X|LAYOUT_FILL_Y);
114 simplelist->appendItem("First Entry");
115 simplelist->appendItem("Second Entry");
116 simplelist->appendItem("Third Entry");
117 simplelist->appendItem("Fourth Entry");
118
119 // Second item is a file list
120 tab2=new FXTabItem(tabbook,"F&ile List",NULL);
121 fileframe=new FXHorizontalFrame(tabbook,FRAME_THICK|FRAME_RAISED);
122 boxframe=new FXHorizontalFrame(fileframe,FRAME_THICK|FRAME_SUNKEN|LAYOUT_FILL_X|LAYOUT_FILL_Y, 0,0,0,0, 0,0,0,0);
123 filelist=new FXFileList(boxframe,NULL,0,ICONLIST_EXTENDEDSELECT|LAYOUT_FILL_X|LAYOUT_FILL_Y);
124
125 // Third item is a directory list
126 tab3=new FXTabItem(tabbook,"T&ree List",NULL);
127 dirframe=new FXHorizontalFrame(tabbook,FRAME_THICK|FRAME_RAISED);
128 boxframe=new FXHorizontalFrame(dirframe,FRAME_THICK|FRAME_SUNKEN|LAYOUT_FILL_X|LAYOUT_FILL_Y, 0,0,0,0, 0,0,0,0);
129 dirlist=new FXDirList(boxframe,NULL,0,DIRLIST_SHOWFILES|TREELIST_SHOWS_LINES|TREELIST_SHOWS_BOXES|LAYOUT_FILL_X|LAYOUT_FILL_Y);
130
131 // Fourth item is text
132 tab4=new FXTabItem(tabbook,"Text",NULL);
133 textframe=new FXHorizontalFrame(tabbook,FRAME_THICK|FRAME_RAISED);
134 boxframe=new FXHorizontalFrame(textframe,FRAME_THICK|FRAME_SUNKEN|LAYOUT_FILL_X|LAYOUT_FILL_Y, 0,0,0,0, 0,0,0,0);
135 text=new FXText(boxframe,NULL,0,LAYOUT_FILL_X|LAYOUT_FILL_Y);
136
137 // File Menu
138 filemenu=new FXMenuPane(this);
139 new FXMenuCommand(filemenu,"&Simple List",NULL,tabbook,FXTabBar::ID_OPEN_FIRST+0);
140 new FXMenuCommand(filemenu,"F&ile List",NULL,tabbook,FXTabBar::ID_OPEN_FIRST+1);
141 new FXMenuCommand(filemenu,"T&ree List",NULL,tabbook,FXTabBar::ID_OPEN_FIRST+2);
142 new FXMenuCommand(filemenu,"&Quit\tCtl-Q",NULL,getApp(),FXApp::ID_QUIT);
143 new FXMenuTitle(menubar,"&File",NULL,filemenu);
144
145 // Tab side
146 tabmenu=new FXMenuPane(this);
147 new FXMenuCommand(tabmenu,"Hide/Show Tab 2",NULL,this,TabBookWindow::ID_HIDESHOW);
148 new FXMenuCommand(tabmenu,"&Top Tabs",NULL,this,TabBookWindow::ID_TABS_TOP);
149 new FXMenuCommand(tabmenu,"&Bottom Tabs",NULL,this,TabBookWindow::ID_TABS_BOTTOM);
150 new FXMenuCommand(tabmenu,"&Left Tabs",NULL,this,TabBookWindow::ID_TABS_LEFT);
151 new FXMenuCommand(tabmenu,"&Right Tabs",NULL,this,TabBookWindow::ID_TABS_RIGHT);
152 new FXMenuCommand(tabmenu,"&Uniform Width Tabs",NULL,this,TabBookWindow::ID_PACK_UNIFORM_WIDTH);
153 new FXMenuCommand(tabmenu,"&Nonuniform Width Tabs",NULL,this,TabBookWindow::ID_PACK_NON_UNIFORM_WIDTH);
154 new FXMenuTitle(menubar,"&Tab Placement",NULL,tabmenu);
155
156 }
157
158
159 // Clean up
~TabBookWindow()160 TabBookWindow::~TabBookWindow(){
161 delete tabmenu;
162 delete filemenu;
163 }
164
165
166 // Switch tab orientations
onCmdTabOrient(FXObject *,FXSelector sel,void *)167 long TabBookWindow::onCmdTabOrient(FXObject*,FXSelector sel,void*){
168 FXuint sid=FXSELID(sel);
169 switch(sid){
170 case ID_TABS_TOP:
171 tabbook->setTabStyle(TABBOOK_TOPTABS);
172 tab1->setTabOrientation(TAB_TOP);
173 tab2->setTabOrientation(TAB_TOP);
174 tab3->setTabOrientation(TAB_TOP);
175 tab4->setTabOrientation(TAB_TOP);
176 break;
177 case ID_TABS_BOTTOM:
178 tabbook->setTabStyle(TABBOOK_BOTTOMTABS);
179 tab1->setTabOrientation(TAB_BOTTOM);
180 tab2->setTabOrientation(TAB_BOTTOM);
181 tab3->setTabOrientation(TAB_BOTTOM);
182 tab4->setTabOrientation(TAB_BOTTOM);
183 break;
184 case ID_TABS_LEFT:
185 tabbook->setTabStyle(TABBOOK_LEFTTABS);
186 tab1->setTabOrientation(TAB_LEFT);
187 tab2->setTabOrientation(TAB_LEFT);
188 tab3->setTabOrientation(TAB_LEFT);
189 tab4->setTabOrientation(TAB_LEFT);
190 break;
191 case ID_TABS_RIGHT:
192 tabbook->setTabStyle(TABBOOK_RIGHTTABS);
193 tab1->setTabOrientation(TAB_RIGHT);
194 tab2->setTabOrientation(TAB_RIGHT);
195 tab3->setTabOrientation(TAB_RIGHT);
196 tab4->setTabOrientation(TAB_RIGHT);
197 break;
198 }
199 return 1;
200 }
201
202 // Calculate tab header widths based on largest tab label string
onCmdPackUniformWidth(FXObject *,FXSelector sel,void *)203 long TabBookWindow::onCmdPackUniformWidth(FXObject*,FXSelector sel,void*){
204 FXuint sid=FXSELID(sel);
205 FXuint packing_hints = tabbook->getPackingHints();
206 packing_hints |= PACK_UNIFORM_WIDTH;
207 tabbook->setPackingHints(packing_hints);
208 return 1;
209 }
210
211 // Calculate tab header width individually for each tab label string
onCmdPackNonUniformWidth(FXObject *,FXSelector sel,void *)212 long TabBookWindow::onCmdPackNonUniformWidth(FXObject*,FXSelector sel,void*){
213 FXuint sid=FXSELID(sel);
214 FXuint packing_hints = tabbook->getPackingHints();
215 packing_hints &= ~PACK_UNIFORM_WIDTH;
216 tabbook->setPackingHints(packing_hints);
217 return 1;
218 }
219
220
221 // Hide of show a panel
onCmdHideShow(FXObject *,FXSelector,void *)222 long TabBookWindow::onCmdHideShow(FXObject*,FXSelector,void*){
223 if(tab2->shown()){
224 tab2->hide();
225 fileframe->hide();
226 }
227 else{
228 tab2->show();
229 fileframe->show();
230 }
231 tab2->recalc();
232 fileframe->recalc();
233 return 1;
234 }
235
236
237 // Active panel switched
onCmdPanel(FXObject *,FXSelector,void * ptr)238 long TabBookWindow::onCmdPanel(FXObject*,FXSelector,void* ptr){
239 FXTRACE((1,"Panel = %d\n",(FXint)(FXival)ptr));
240 return 1;
241 }
242
243
244 // Show up
create()245 void TabBookWindow::create(){
246 FXMainWindow::create();
247 show(PLACEMENT_SCREEN);
248 }
249
250
251 /*******************************************************************************/
252
253
254 // Start the whole thing
main(int argc,char * argv[])255 int main(int argc,char *argv[]){
256
257 // Make application
258 FXApp application("TabBook","FoxTest");
259
260 // Open display; this reads registry
261 application.init(argc,argv);
262
263 // Build a window
264 new TabBookWindow(&application);
265
266 // Create app
267 application.create();
268
269 // Run
270 return application.run();
271 }
272
273