]> git.saurik.com Git - wxWidgets.git/blob - user/wxFile/wxFile.cpp
more comments
[wxWidgets.git] / user / wxFile / wxFile.cpp
1 /*
2 * Program: wxFile
3 *
4 * Author: Robert Roebling
5 *
6 * Copyright: (C) 1997, GNU (Robert Roebling)
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #ifdef __GNUG__
24 #pragma implementation "wxFile.h"
25 #endif
26
27 #include "wxFile.h"
28 #include "wx/dnd.h"
29
30 #include "delete.xpm"
31 #include "home.xpm"
32 #include "prev.xpm"
33 #include "fileopen.xpm"
34 #include "exit.xpm"
35 #include "listview.xpm"
36 #include "iconview.xpm"
37 #include "reportview.xpm"
38 #include "treeview.xpm"
39 #include "commanderview.xpm"
40 #include "singleview.xpm"
41 #include "save.xpm"
42 #include "search.xpm"
43 #include "help.xpm"
44
45 //-----------------------------------------------------------------------------
46 // main program
47 //-----------------------------------------------------------------------------
48
49 IMPLEMENT_APP(MyApp)
50
51 //-----------------------------------------------------------------------------
52 // MyFrame
53 //-----------------------------------------------------------------------------
54
55 const ID_FILECTRL = 1000;
56 const ID_DIRCTRL = 1001;
57 const ID_TOOLBAR = 1002;
58
59 const ID_QUIT = 100;
60 const ID_ABOUT = 101;
61
62 const ID_LIST = 200;
63 const ID_REPORT = 201;
64 const ID_ICON = 202;
65
66 const ID_SINGLE = 203;
67 const ID_TREE = 204;
68 const ID_COMMANDER = 205;
69
70 const ID_HOME = 400;
71 const ID_PARENT = 401;
72 const ID_MOUNT = 402;
73 const ID_SEARCH = 403;
74
75 const ID_DELETE = 501;
76 const ID_MD = 502;
77
78
79 IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame )
80
81 BEGIN_EVENT_TABLE(MyFrame,wxFrame)
82 EVT_MENU (ID_ABOUT, MyFrame::OnAbout)
83 EVT_MENU (ID_QUIT, MyFrame::OnCommand)
84 EVT_MENU (ID_HOME, MyFrame::OnCommand)
85 EVT_MENU (ID_PARENT, MyFrame::OnCommand)
86 EVT_MENU (ID_LIST, MyFrame::OnView)
87 EVT_MENU (ID_REPORT, MyFrame::OnView)
88 EVT_MENU (ID_ICON, MyFrame::OnView)
89 EVT_MENU (ID_TREE, MyFrame::OnView)
90 EVT_MENU (ID_SINGLE, MyFrame::OnView)
91 EVT_MENU (ID_COMMANDER, MyFrame::OnView)
92 EVT_LIST_KEY_DOWN (ID_FILECTRL, MyFrame::OnListKeyDown)
93 EVT_LIST_DELETE_ITEM (ID_FILECTRL, MyFrame::OnListDeleteItem)
94 EVT_LIST_END_LABEL_EDIT (ID_FILECTRL, MyFrame::OnListEndLabelEdit)
95 EVT_LIST_BEGIN_DRAG (ID_FILECTRL, MyFrame::OnListDrag)
96 EVT_TREE_KEY_DOWN (ID_DIRCTRL, MyFrame::OnTreeKeyDown)
97 EVT_TREE_SEL_CHANGED (ID_DIRCTRL, MyFrame::OnTreeSelected)
98 END_EVENT_TABLE()
99
100 MyFrame::MyFrame(void) :
101 wxFrame( NULL, -1, "wxFile", wxPoint(20,20), wxSize(470,360) )
102 {
103 wxMenu *file_menu = new wxMenu( "Menu 1" );
104 file_menu->Append( ID_ABOUT, "About..");
105 file_menu->Append( ID_QUIT, "Exit");
106
107 wxMenu *view_menu = new wxMenu( "Menu 2" );
108 view_menu->Append( ID_LIST, "List mode");
109 view_menu->Append( ID_REPORT, "Report mode");
110 view_menu->Append( ID_ICON, "Icon mode");
111
112 wxMenuBar *menu_bar = new wxMenuBar();
113 menu_bar->Append(file_menu, "File" );
114 menu_bar->Append(view_menu, "View" );
115 menu_bar->Show( TRUE );
116
117 SetMenuBar( menu_bar );
118
119 CreateStatusBar( 2 );
120
121 SetStatusText( "Welcome", 0 );
122 SetStatusText( "wxFile v0.2 by Robert Roebling.", 1 );
123
124 wxToolBar *m_tb = CreateToolBar( ID_TOOLBAR );
125 m_tb->SetMargins( 2, 2 );
126
127 m_tb->AddSeparator();
128 m_tb->AddTool( ID_QUIT, wxBitmap( exit_xpm ), wxNullBitmap, FALSE, -1, -1, NULL, "Exit wxFile" );
129 m_tb->AddSeparator();
130 m_tb->AddTool( ID_PARENT, wxBitmap( prev_xpm ), wxNullBitmap, FALSE, -1, -1, NULL, "Go to parent directory" );
131 m_tb->AddTool( ID_HOME, wxBitmap( home_xpm ), wxNullBitmap, FALSE, -1, -1, NULL, "Go to home directory" );
132 m_tb->AddSeparator();
133 m_tb->AddTool( ID_DELETE, wxBitmap( delete_xpm ), wxNullBitmap, FALSE, -1, -1, NULL, "Delete file" );
134 m_tb->AddSeparator();
135 m_tb->AddTool( ID_MD, wxBitmap( fileopen_xpm ), wxNullBitmap, FALSE, -1, -1, NULL, "Create directory" );
136 m_tb->AddSeparator();
137 m_tb->AddTool( ID_LIST, wxBitmap( listview_xpm ), wxNullBitmap, FALSE, -1, -1, NULL, "List view" );
138 m_tb->AddTool( ID_REPORT, wxBitmap( reportview_xpm ), wxNullBitmap, FALSE, -1, -1, NULL, "Report view" );
139 m_tb->AddTool( ID_ICON, wxBitmap( iconview_xpm ), wxNullBitmap, FALSE, -1, -1, NULL, "Icon view" );
140 m_tb->AddSeparator();
141 m_tb->AddTool( ID_TREE, wxBitmap( treeview_xpm ), wxNullBitmap, FALSE, -1, -1, NULL, "Tree view" );
142 m_tb->AddTool( ID_COMMANDER, wxBitmap( commanderview_xpm ), wxNullBitmap, FALSE, -1, -1, NULL, "Commander view" );
143 m_tb->AddTool( ID_SINGLE, wxBitmap( singleview_xpm ), wxNullBitmap, FALSE, -1, -1, NULL, "Single view" );
144 m_tb->AddSeparator();
145 m_tb->AddTool( ID_MOUNT, wxBitmap( search_xpm ), wxNullBitmap, FALSE, -1, -1, NULL, "Mount devices" );
146 m_tb->AddSeparator();
147 m_tb->AddTool( ID_SEARCH, wxBitmap( save_xpm ), wxNullBitmap, FALSE, -1, -1, NULL, "Find file(s)" );
148 m_tb->AddSeparator();
149 m_tb->AddTool( ID_ABOUT, wxBitmap( help_xpm ), wxNullBitmap, FALSE, -1, -1, NULL, "About wxFile" );
150
151 m_tb->Layout();
152
153 m_splitter = new wxSplitterWindow( this, -1, wxPoint(0,0), wxSize(400,300), wxSP_3D );
154
155 m_leftFile = NULL;
156 m_dir = new wxDirCtrl( m_splitter, ID_DIRCTRL, "/", wxPoint(10,45), wxSize(200,330) );
157
158 wxString homepath( "/home" );
159 char buf[300];
160 wxGetHomeDir( buf );
161 homepath = buf;
162 m_rightFile = new wxFileCtrl( m_splitter, ID_FILECTRL, homepath, wxPoint(220,5), wxSize(200,330) );
163
164 m_leftFile = new wxFileCtrl( m_splitter, ID_FILECTRL, homepath, wxPoint(0,5), wxSize(200,330) );
165 m_leftFile->Show( FALSE );
166
167 m_leftFile->m_lastFocus = m_rightFile;
168
169 int x = 0;
170 GetClientSize( &x, NULL );
171
172 m_splitter->SplitVertically( m_dir, m_rightFile, x / 3 );
173 m_splitter->SetMinimumPaneSize( 10 );
174 };
175
176 void MyFrame::OnView( wxCommandEvent &event )
177 {
178 int x = 0;
179 GetClientSize( &x, NULL );
180 switch (event.GetId())
181 {
182 case ID_LIST:
183 m_rightFile->ChangeToListMode();
184 if (m_splitter->IsSplit() && (m_splitter->GetWindow1() == m_leftFile))
185 m_leftFile->ChangeToListMode();
186 break;
187 case ID_REPORT:
188 m_rightFile->ChangeToReportMode();
189 if (m_splitter->IsSplit() && (m_splitter->GetWindow1() == m_leftFile))
190 m_leftFile->ChangeToReportMode();
191 break;
192 case ID_ICON:
193 m_rightFile->ChangeToIconMode();
194 if (m_splitter->IsSplit() && (m_splitter->GetWindow1() == m_leftFile))
195 m_leftFile->ChangeToIconMode();
196 break;
197 case ID_TREE:
198 if (m_splitter->IsSplit())
199 {
200 if (m_splitter->GetWindow1() != m_dir)
201 {
202 m_splitter->Unsplit( m_leftFile );
203 m_dir->Show(TRUE);
204 m_splitter->SplitVertically( m_dir, m_rightFile, x/3 );
205 };
206 }
207 else
208 {
209 m_dir->Show(TRUE);
210 m_splitter->SplitVertically( m_dir, m_rightFile, x/3 );
211 };
212 break;
213 case ID_SINGLE:
214 if (m_splitter->IsSplit()) m_splitter->Unsplit( m_splitter->GetWindow1() );
215 break;
216 case ID_COMMANDER:
217 if (m_splitter->IsSplit())
218 {
219 if (m_splitter->GetWindow1() != m_leftFile)
220 {
221 m_splitter->Unsplit( m_dir );
222 m_leftFile->ChangeToListMode();
223 m_rightFile->ChangeToListMode();
224 m_leftFile->Show(TRUE);
225 m_splitter->SplitVertically( m_leftFile, m_rightFile, x/2 );
226 };
227 }
228 else
229 {
230 m_leftFile->ChangeToListMode();
231 m_rightFile->ChangeToListMode();
232 m_leftFile->Show(TRUE);
233 m_splitter->SplitVertically( m_leftFile, m_rightFile, x/2 );
234 };
235 break;
236 default:
237 break;
238 };
239 };
240
241 void MyFrame::OnCommand( wxCommandEvent &event )
242 {
243 switch (event.GetId())
244 {
245 case ID_QUIT:
246 Close( TRUE );
247 break;
248 case ID_HOME:
249 m_leftFile->m_lastFocus->GoToHomeDir();
250 break;
251 case ID_PARENT:
252 m_leftFile->m_lastFocus->GoToParentDir();
253 break;
254 default:
255 break;
256 };
257 };
258
259 void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) )
260 {
261 wxDialog dialog( this, -1, "About wxFile", wxPoint(100,100), wxSize(540,350), wxDIALOG_MODAL );
262
263 int w = 0;
264 int h = 0;
265 dialog.GetSize( &w, &h );
266
267 int x = 30;
268 int y = 20;
269 int step = 20;
270
271 (void)new wxStaticBox( &dialog, -1, (const char*)NULL, wxPoint(10,10), wxSize(w-20,h-80) );
272
273 (void)new wxStaticText( &dialog, -1, "wxFile v0.1", wxPoint(240,y) );
274 y += 2*step-10;
275
276 (void)new wxStaticText( &dialog, -1, "Written by Robert Roebling, 1998.", wxPoint(x,y) );
277 y += 2*step;
278
279 (void)new wxStaticText( &dialog, -1,
280 "wxFile uses wxGTK, the GTK port of the wxWindows GUI-library.", wxPoint(x,y) );
281 y += step;
282 (void)new wxStaticText( &dialog, -1, "http://www.freiburg.linux.de/~wxxt", wxPoint(x+50,y) );
283 y += step;
284 (void)new wxStaticText( &dialog, -1, "http://web.ukonline.co.uk/julian.smart/wxwin", wxPoint(x+50,y) );
285 y += 2*step;
286
287 (void)new wxStaticText( &dialog, -1, "wxFile Copyright: GPL.", wxPoint(x,y) );
288 y += 2*step;
289 (void)new wxStaticText( &dialog, -1, "For questions concerning wxGTK, you may mail to:", wxPoint(x,y) );
290 y += step;
291 (void)new wxStaticText( &dialog, -1, "roebling@ruf.uni-freiburg.de", wxPoint(x+50,y) );
292
293 (void) new wxButton( &dialog, wxID_OK, "Return", wxPoint(w/2-40,h-50), wxSize(80,30) );
294
295 dialog.ShowModal();
296 };
297
298 void MyFrame::OnListKeyDown( wxListEvent &event )
299 {
300 m_rightFile->m_lastFocus->OnListKeyDown( event );
301 };
302
303 void MyFrame::OnListDeleteItem( wxListEvent &event )
304 {
305 m_rightFile->m_lastFocus->OnListDeleteItem( event );
306 };
307
308 void MyFrame::OnListEndLabelEdit( wxListEvent &event )
309 {
310 m_rightFile->m_lastFocus->OnListEndLabelEdit( event );
311 };
312
313 void MyFrame::OnListDrag( wxListEvent &event )
314 {
315 printf( "OnDrag.\n" );
316 return;
317 };
318
319 void MyFrame::OnTreeSelected( wxTreeEvent &event )
320 {
321 wxDirInfo *info = (wxDirInfo*) event.m_item.m_data;
322 if (info) SetStatusText( info->GetPath() );
323 };
324
325 void MyFrame::OnTreeKeyDown( wxTreeEvent &event )
326 {
327 wxDirInfo *info = (wxDirInfo*) event.m_item.m_data;
328 if (info) m_rightFile->GoToDir( info->GetPath() );
329 };
330
331 //-----------------------------------------------------------------------------
332 // MyApp
333 //-----------------------------------------------------------------------------
334
335 MyApp::MyApp(void) :
336 wxApp( )
337 {
338 };
339
340 bool MyApp::OnInit(void)
341 {
342 wxFrame *frame = new MyFrame();
343 frame->Show( TRUE );
344
345 return TRUE;
346 };
347
348
349
350
351