]>
Commit | Line | Data |
---|---|---|
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_SIZE (MyFrame::OnSize) | |
83 | EVT_MENU (ID_ABOUT, MyFrame::OnAbout) | |
84 | EVT_TOOL (ID_ABOUT, MyFrame::OnAbout) | |
85 | EVT_MENU (ID_QUIT, MyFrame::OnCommand) | |
86 | EVT_TOOL (ID_QUIT, MyFrame::OnCommand) | |
87 | EVT_MENU (ID_HOME, MyFrame::OnCommand) | |
88 | EVT_TOOL (ID_HOME, MyFrame::OnCommand) | |
89 | EVT_MENU (ID_PARENT, MyFrame::OnCommand) | |
90 | EVT_TOOL (ID_PARENT, MyFrame::OnCommand) | |
91 | EVT_MENU (ID_LIST, MyFrame::OnView) | |
92 | EVT_MENU (ID_REPORT, MyFrame::OnView) | |
93 | EVT_MENU (ID_ICON, MyFrame::OnView) | |
94 | EVT_TOOL (ID_LIST, MyFrame::OnView) | |
95 | EVT_TOOL (ID_REPORT, MyFrame::OnView) | |
96 | EVT_TOOL (ID_ICON, MyFrame::OnView) | |
97 | EVT_TOOL (ID_TREE, MyFrame::OnView) | |
98 | EVT_TOOL (ID_SINGLE, MyFrame::OnView) | |
99 | EVT_TOOL (ID_COMMANDER, MyFrame::OnView) | |
100 | EVT_LIST_KEY_DOWN (ID_FILECTRL, MyFrame::OnListKeyDown) | |
101 | EVT_LIST_DELETE_ITEM (ID_FILECTRL, MyFrame::OnListDeleteItem) | |
102 | EVT_LIST_END_LABEL_EDIT (ID_FILECTRL, MyFrame::OnListEndLabelEdit) | |
103 | EVT_LIST_BEGIN_DRAG (ID_FILECTRL, MyFrame::OnListDrag) | |
104 | EVT_TREE_KEY_DOWN (ID_DIRCTRL, MyFrame::OnTreeKeyDown) | |
105 | EVT_TREE_SEL_CHANGED (ID_DIRCTRL, MyFrame::OnTreeSelected) | |
106 | END_EVENT_TABLE() | |
107 | ||
108 | MyFrame::MyFrame(void) : | |
109 | wxFrame( NULL, -1, "wxFile", wxPoint(20,20), wxSize(470,360) ) | |
110 | { | |
111 | wxMenu *file_menu = new wxMenu( "Menu 1" ); | |
112 | file_menu->Append( ID_ABOUT, "About.."); | |
113 | file_menu->Append( ID_QUIT, "Exit"); | |
114 | ||
115 | wxMenu *view_menu = new wxMenu( "Menu 2" ); | |
116 | view_menu->Append( ID_LIST, "List mode"); | |
117 | view_menu->Append( ID_REPORT, "Report mode"); | |
118 | view_menu->Append( ID_ICON, "Icon mode"); | |
119 | ||
120 | wxMenuBar *menu_bar = new wxMenuBar(); | |
121 | menu_bar->Append(file_menu, "File" ); | |
122 | menu_bar->Append(view_menu, "View" ); | |
123 | menu_bar->Show( TRUE ); | |
124 | ||
125 | SetMenuBar( menu_bar ); | |
126 | ||
127 | CreateStatusBar( 2 ); | |
128 | ||
129 | SetStatusText( "Welcome", 0 ); | |
130 | SetStatusText( "wxFile v0.2 by Robert Roebling.", 1 ); | |
131 | ||
132 | m_tb = new wxToolBarGTK( this, ID_TOOLBAR, wxPoint(2,60), wxSize(300-4,26) ); | |
133 | m_tb->SetMargins( 2, 2 ); | |
134 | ||
135 | wxBitmap *bm; | |
136 | m_tb->AddSeparator(); | |
137 | ||
138 | bm = new wxBitmap( exit_xpm ); | |
139 | m_tb->AddTool( ID_QUIT, *bm, wxNullBitmap, FALSE, -1, -1, NULL, "Exit wxFile" ); | |
140 | m_tb->AddSeparator(); | |
141 | ||
142 | bm = new wxBitmap( prev_xpm ); | |
143 | m_tb->AddTool( ID_PARENT, *bm, wxNullBitmap, FALSE, -1, -1, NULL, "Go to parent directory" ); | |
144 | bm = new wxBitmap( home_xpm ); | |
145 | m_tb->AddTool( ID_HOME, *bm, wxNullBitmap, FALSE, -1, -1, NULL, "Go to home directory" ); | |
146 | m_tb->AddSeparator(); | |
147 | ||
148 | bm = new wxBitmap( delete_xpm ); | |
149 | m_tb->AddTool( ID_DELETE, *bm, wxNullBitmap, FALSE, -1, -1, NULL, "Delete file" ); | |
150 | m_tb->AddSeparator(); | |
151 | ||
152 | bm = new wxBitmap( fileopen_xpm ); | |
153 | m_tb->AddTool( ID_MD, *bm, wxNullBitmap, FALSE, -1, -1, NULL, "Create directory" ); | |
154 | m_tb->AddSeparator(); | |
155 | ||
156 | bm = new wxBitmap( listview_xpm ); | |
157 | m_tb->AddTool( ID_LIST, *bm, wxNullBitmap, FALSE, -1, -1, NULL, "List view" ); | |
158 | bm = new wxBitmap( reportview_xpm ); | |
159 | m_tb->AddTool( ID_REPORT, *bm, wxNullBitmap, FALSE, -1, -1, NULL, "Report view" ); | |
160 | bm = new wxBitmap( iconview_xpm ); | |
161 | m_tb->AddTool( ID_ICON, *bm, wxNullBitmap, FALSE, -1, -1, NULL, "Icon view" ); | |
162 | m_tb->AddSeparator(); | |
163 | ||
164 | bm = new wxBitmap( treeview_xpm ); | |
165 | m_tb->AddTool( ID_TREE, *bm, wxNullBitmap, FALSE, -1, -1, NULL, "Tree view" ); | |
166 | bm = new wxBitmap( commanderview_xpm ); | |
167 | m_tb->AddTool( ID_COMMANDER, *bm, wxNullBitmap, FALSE, -1, -1, NULL, "Commander view" ); | |
168 | bm = new wxBitmap( singleview_xpm ); | |
169 | m_tb->AddTool( ID_SINGLE, *bm, wxNullBitmap, FALSE, -1, -1, NULL, "Single view" ); | |
170 | m_tb->AddSeparator(); | |
171 | ||
172 | bm = new wxBitmap( search_xpm ); | |
173 | m_tb->AddTool( ID_MOUNT, *bm, wxNullBitmap, FALSE, -1, -1, NULL, "Mount devices" ); | |
174 | m_tb->AddSeparator(); | |
175 | ||
176 | bm = new wxBitmap( save_xpm ); | |
177 | m_tb->AddTool( ID_SEARCH, *bm, wxNullBitmap, FALSE, -1, -1, NULL, "Find file(s)" ); | |
178 | m_tb->AddSeparator(); | |
179 | ||
180 | bm = new wxBitmap( help_xpm ); | |
181 | m_tb->AddTool( ID_ABOUT, *bm, wxNullBitmap, FALSE, -1, -1, NULL, "About wxFile" ); | |
182 | ||
183 | m_tb->Layout(); | |
184 | ||
185 | m_splitter = new wxSplitterWindow( this, -1, wxPoint(0,0), wxSize(400,300), wxSP_3D ); | |
186 | ||
187 | m_leftFile = NULL; | |
188 | m_dir = new wxDirCtrl( m_splitter, ID_DIRCTRL, "/", wxPoint(10,45), wxSize(200,330) ); | |
189 | ||
190 | wxString homepath( "/home" ); | |
191 | char buf[300]; | |
192 | wxGetHomeDir( buf ); | |
193 | homepath = buf; | |
194 | m_rightFile = new wxFileCtrl( m_splitter, ID_FILECTRL, homepath, wxPoint(220,5), wxSize(200,330) ); | |
195 | ||
196 | m_leftFile = new wxFileCtrl( m_splitter, ID_FILECTRL, homepath, wxPoint(0,5), wxSize(200,330) ); | |
197 | m_leftFile->Show( FALSE ); | |
198 | ||
199 | m_leftFile->m_lastFocus = m_rightFile; | |
200 | ||
201 | int x = 0; | |
202 | GetClientSize( &x, NULL ); | |
203 | ||
204 | m_splitter->SplitVertically( m_dir, m_rightFile, x / 3 ); | |
205 | m_splitter->SetMinimumPaneSize( 10 ); | |
206 | }; | |
207 | ||
208 | void MyFrame::OnSize( wxSizeEvent &WXUNUSED(event) ) | |
209 | { | |
210 | int x = 0; | |
211 | int y = 0; | |
212 | GetClientSize( &x, &y ); | |
213 | ||
214 | m_tb->SetSize( 1, 0, x-2, 30 ); | |
215 | m_splitter->SetSize( 0, 31, x, y-31 ); | |
216 | }; | |
217 | ||
218 | void MyFrame::OnView( wxCommandEvent &event ) | |
219 | { | |
220 | int x = 0; | |
221 | GetClientSize( &x, NULL ); | |
222 | switch (event.GetId()) | |
223 | { | |
224 | case ID_LIST: | |
225 | m_rightFile->ChangeToListMode(); | |
226 | if (m_splitter->IsSplit() && (m_splitter->GetWindow1() == m_leftFile)) | |
227 | m_leftFile->ChangeToListMode(); | |
228 | break; | |
229 | case ID_REPORT: | |
230 | m_rightFile->ChangeToReportMode(); | |
231 | if (m_splitter->IsSplit() && (m_splitter->GetWindow1() == m_leftFile)) | |
232 | m_leftFile->ChangeToReportMode(); | |
233 | break; | |
234 | case ID_ICON: | |
235 | m_rightFile->ChangeToIconMode(); | |
236 | if (m_splitter->IsSplit() && (m_splitter->GetWindow1() == m_leftFile)) | |
237 | m_leftFile->ChangeToIconMode(); | |
238 | break; | |
239 | case ID_TREE: | |
240 | if (m_splitter->IsSplit()) | |
241 | { | |
242 | if (m_splitter->GetWindow1() != m_dir) | |
243 | { | |
244 | m_splitter->Unsplit( m_leftFile ); | |
245 | m_dir->Show(TRUE); | |
246 | m_splitter->SplitVertically( m_dir, m_rightFile, x/3 ); | |
247 | }; | |
248 | } | |
249 | else | |
250 | { | |
251 | m_dir->Show(TRUE); | |
252 | m_splitter->SplitVertically( m_dir, m_rightFile, x/3 ); | |
253 | }; | |
254 | break; | |
255 | case ID_SINGLE: | |
256 | if (m_splitter->IsSplit()) m_splitter->Unsplit( m_splitter->GetWindow1() ); | |
257 | break; | |
258 | case ID_COMMANDER: | |
259 | if (m_splitter->IsSplit()) | |
260 | { | |
261 | if (m_splitter->GetWindow1() != m_leftFile) | |
262 | { | |
263 | m_splitter->Unsplit( m_dir ); | |
264 | m_leftFile->ChangeToListMode(); | |
265 | m_rightFile->ChangeToListMode(); | |
266 | m_leftFile->Show(TRUE); | |
267 | m_splitter->SplitVertically( m_leftFile, m_rightFile, x/2 ); | |
268 | }; | |
269 | } | |
270 | else | |
271 | { | |
272 | m_leftFile->ChangeToListMode(); | |
273 | m_rightFile->ChangeToListMode(); | |
274 | m_leftFile->Show(TRUE); | |
275 | m_splitter->SplitVertically( m_leftFile, m_rightFile, x/2 ); | |
276 | }; | |
277 | break; | |
278 | default: | |
279 | break; | |
280 | }; | |
281 | }; | |
282 | ||
283 | void MyFrame::OnCommand( wxCommandEvent &event ) | |
284 | { | |
285 | switch (event.GetId()) | |
286 | { | |
287 | case ID_QUIT: | |
288 | Close( TRUE ); | |
289 | break; | |
290 | case ID_HOME: | |
291 | m_leftFile->m_lastFocus->GoToHomeDir(); | |
292 | break; | |
293 | case ID_PARENT: | |
294 | m_leftFile->m_lastFocus->GoToParentDir(); | |
295 | break; | |
296 | default: | |
297 | break; | |
298 | }; | |
299 | }; | |
300 | ||
301 | void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) ) | |
302 | { | |
303 | wxDialog dialog( this, -1, "About wxFile", wxPoint(100,100), wxSize(540,350), wxDIALOG_MODAL ); | |
304 | ||
305 | int w = 0; | |
306 | int h = 0; | |
307 | dialog.GetSize( &w, &h ); | |
308 | ||
309 | int x = 30; | |
310 | int y = 20; | |
311 | int step = 20; | |
312 | ||
313 | (void)new wxStaticBox( &dialog, -1, (const char*)NULL, wxPoint(10,10), wxSize(w-20,h-80) ); | |
314 | ||
315 | (void)new wxStaticText( &dialog, -1, "wxFile v0.1", wxPoint(240,y) ); | |
316 | y += 2*step-10; | |
317 | ||
318 | (void)new wxStaticText( &dialog, -1, "Written by Robert Roebling, 1998.", wxPoint(x,y) ); | |
319 | y += 2*step; | |
320 | ||
321 | (void)new wxStaticText( &dialog, -1, | |
322 | "wxFile uses wxGTK, the GTK port of the wxWindows GUI-library.", wxPoint(x,y) ); | |
323 | y += step; | |
324 | (void)new wxStaticText( &dialog, -1, "http://www.freiburg.linux.de/~wxxt", wxPoint(x+50,y) ); | |
325 | y += step; | |
326 | (void)new wxStaticText( &dialog, -1, "http://web.ukonline.co.uk/julian.smart/wxwin", wxPoint(x+50,y) ); | |
327 | y += 2*step; | |
328 | ||
329 | (void)new wxStaticText( &dialog, -1, "wxFile Copyright: GPL.", wxPoint(x,y) ); | |
330 | y += 2*step; | |
331 | (void)new wxStaticText( &dialog, -1, "For questions concerning wxGTK, you may mail to:", wxPoint(x,y) ); | |
332 | y += step; | |
333 | (void)new wxStaticText( &dialog, -1, "roebling@ruf.uni-freiburg.de", wxPoint(x+50,y) ); | |
334 | ||
335 | (void) new wxButton( &dialog, wxID_OK, "Return", wxPoint(w/2-40,h-50), wxSize(80,30) ); | |
336 | ||
337 | dialog.ShowModal(); | |
338 | }; | |
339 | ||
340 | void MyFrame::OnListKeyDown( wxListEvent &event ) | |
341 | { | |
342 | m_rightFile->m_lastFocus->OnListKeyDown( event ); | |
343 | }; | |
344 | ||
345 | void MyFrame::OnListDeleteItem( wxListEvent &event ) | |
346 | { | |
347 | m_rightFile->m_lastFocus->OnListDeleteItem( event ); | |
348 | }; | |
349 | ||
350 | void MyFrame::OnListEndLabelEdit( wxListEvent &event ) | |
351 | { | |
352 | m_rightFile->m_lastFocus->OnListEndLabelEdit( event ); | |
353 | }; | |
354 | ||
355 | void MyFrame::OnListDrag( wxListEvent &event ) | |
356 | { | |
357 | printf( "OnDrag.\n" ); | |
358 | return; | |
359 | }; | |
360 | ||
361 | void MyFrame::OnTreeSelected( wxTreeEvent &event ) | |
362 | { | |
363 | wxDirInfo *info = (wxDirInfo*) event.m_item.m_data; | |
364 | SetStatusText( info->GetPath() ); | |
365 | }; | |
366 | ||
367 | void MyFrame::OnTreeKeyDown( wxTreeEvent &event ) | |
368 | { | |
369 | wxDirInfo *info = (wxDirInfo*) event.m_item.m_data; | |
370 | m_rightFile->GoToDir( info->GetPath() ); | |
371 | }; | |
372 | ||
373 | //----------------------------------------------------------------------------- | |
374 | // MyApp | |
375 | //----------------------------------------------------------------------------- | |
376 | ||
377 | MyApp::MyApp(void) : | |
378 | wxApp( ) | |
379 | { | |
380 | }; | |
381 | ||
382 | bool MyApp::OnInit(void) | |
383 | { | |
384 | wxFrame *frame = new MyFrame(); | |
385 | frame->Show( TRUE ); | |
386 | ||
387 | return TRUE; | |
388 | }; | |
389 | ||
390 | ||
391 | ||
392 | ||
393 |