1 /********************************************************************************
2 * *
3 * D i r e c t o r y L i s t C o n t r o l *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1998,2006 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * $Id: dirlist.cpp,v 1.16 2006/01/22 17:58:59 fox Exp $ *
9 ********************************************************************************/
10 #include "fx.h"
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <sys/stat.h>
14 #ifndef WIN32
15 #include <unistd.h>
16 #endif
17
18
19
20
21 /*******************************************************************************/
22
23
24 // Main Window
25 class DirListWindow : public FXMainWindow {
26 FXDECLARE(DirListWindow)
27 protected:
28 FXMenuBar* menubar;
29 FXMenuPane* filemenu;
30 FXMenuPane* helpmenu;
31 FXDirList* contents;
32 FXTextField* text;
33 protected:
DirListWindow()34 DirListWindow(){}
35 public:
36 long onCmdAbout(FXObject*,FXSelector,void*);
37 public:
38 enum{
39 ID_ABOUT=FXMainWindow::ID_LAST,
40 ID_LAST
41 };
42 public:
43 DirListWindow(FXApp* a);
44 virtual void create();
45 virtual ~DirListWindow();
46 };
47
48
49
50 /*******************************************************************************/
51
52 // Map
53 FXDEFMAP(DirListWindow) DirListWindowMap[]={
54 FXMAPFUNC(SEL_COMMAND, DirListWindow::ID_ABOUT, DirListWindow::onCmdAbout),
55 };
56
57
58 // Object implementation
FXIMPLEMENT(DirListWindow,FXMainWindow,DirListWindowMap,ARRAYNUMBER (DirListWindowMap))59 FXIMPLEMENT(DirListWindow,FXMainWindow,DirListWindowMap,ARRAYNUMBER(DirListWindowMap))
60
61
62 // Make some windows
63 DirListWindow::DirListWindow(FXApp* a):FXMainWindow(a,"Directory List",NULL,NULL,DECOR_ALL,0,0,800,600){
64
65 // Make menu bar
66 menubar=new FXMenuBar(this,LAYOUT_FILL_X);
67 filemenu=new FXMenuPane(this);
68 new FXMenuCommand(filemenu,"&Quit\tCtl-Q",NULL,getApp(),FXApp::ID_QUIT);
69 new FXMenuTitle(menubar,"&File",NULL,filemenu);
70 helpmenu=new FXMenuPane(this);
71 new FXMenuCommand(helpmenu,"&About FOX...",NULL,this,ID_ABOUT,0);
72 new FXMenuTitle(menubar,"&Help",NULL,helpmenu,LAYOUT_RIGHT);
73
74 // Text field at bottom
75 text=new FXTextField(this,10,NULL,0,LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X|FRAME_SUNKEN|FRAME_THICK);
76
77 // Make contents
78 contents=new FXDirList(this,NULL,0,HSCROLLING_OFF|TREELIST_SHOWS_LINES|TREELIST_SHOWS_BOXES|TREELIST_BROWSESELECT|FRAME_SUNKEN|FRAME_THICK|LAYOUT_FILL_X|LAYOUT_FILL_Y,0,0,0,0);
79
80 text->setTarget(contents);
81 text->setSelector(FXWindow::ID_SETVALUE);
82 }
83
84
~DirListWindow()85 DirListWindow::~DirListWindow(){
86 delete filemenu;
87 delete helpmenu;
88 }
89
90
91 // About
onCmdAbout(FXObject *,FXSelector,void *)92 long DirListWindow::onCmdAbout(FXObject*,FXSelector,void*){
93 FXMessageBox::information(this,MBOX_OK,"About FOX","FOX is a really, really cool C++ library!");
94 return 1;
95 }
96
97
98 // Start
create()99 void DirListWindow::create(){
100 FXMainWindow::create();
101 show(PLACEMENT_SCREEN);
102 }
103
104
105 /*******************************************************************************/
106
107
108 // Start the whole thing
main(int argc,char * argv[])109 int main(int argc,char *argv[]){
110
111 // Make application
112 FXApp application("DirList","FoxTest");
113
114 // Open display
115 application.init(argc,argv);
116
117 // Make window
118 new DirListWindow(&application);
119
120 // Create app
121 application.create();
122
123 // Run
124 return application.run();
125 }
126
127
128