]> git.saurik.com Git - wxWidgets.git/blame - user/wxFile/wxFile.cpp
wxLogWindoe changed again: now takes a parent frame in ctor
[wxWidgets.git] / user / wxFile / wxFile.cpp
CommitLineData
c801d85f
KB
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
49IMPLEMENT_APP(MyApp)
50
51//-----------------------------------------------------------------------------
52// MyFrame
53//-----------------------------------------------------------------------------
54
55const ID_FILECTRL = 1000;
56const ID_DIRCTRL = 1001;
57const ID_TOOLBAR = 1002;
58
59const ID_QUIT = 100;
60const ID_ABOUT = 101;
61
62const ID_LIST = 200;
63const ID_REPORT = 201;
64const ID_ICON = 202;
65
66const ID_SINGLE = 203;
67const ID_TREE = 204;
68const ID_COMMANDER = 205;
69
70const ID_HOME = 400;
71const ID_PARENT = 401;
72const ID_MOUNT = 402;
73const ID_SEARCH = 403;
74
75const ID_DELETE = 501;
76const ID_MD = 502;
77
78
79IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame )
80
81BEGIN_EVENT_TABLE(MyFrame,wxFrame)
c801d85f 82 EVT_MENU (ID_ABOUT, MyFrame::OnAbout)
c801d85f 83 EVT_MENU (ID_QUIT, MyFrame::OnCommand)
c801d85f 84 EVT_MENU (ID_HOME, MyFrame::OnCommand)
c801d85f 85 EVT_MENU (ID_PARENT, MyFrame::OnCommand)
c801d85f
KB
86 EVT_MENU (ID_LIST, MyFrame::OnView)
87 EVT_MENU (ID_REPORT, MyFrame::OnView)
88 EVT_MENU (ID_ICON, MyFrame::OnView)
46dc76ba
RR
89 EVT_MENU (ID_TREE, MyFrame::OnView)
90 EVT_MENU (ID_SINGLE, MyFrame::OnView)
91 EVT_MENU (ID_COMMANDER, MyFrame::OnView)
c801d85f
KB
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)
98END_EVENT_TABLE()
99
100MyFrame::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
b204641e 124 wxToolBar *m_tb = CreateToolBar();
c801d85f
KB
125 m_tb->SetMargins( 2, 2 );
126
c801d85f 127 m_tb->AddSeparator();
46dc76ba 128 m_tb->AddTool( ID_QUIT, wxBitmap( exit_xpm ), wxNullBitmap, FALSE, -1, -1, NULL, "Exit wxFile" );
c801d85f 129 m_tb->AddSeparator();
46dc76ba
RR
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" );
c801d85f 132 m_tb->AddSeparator();
46dc76ba 133 m_tb->AddTool( ID_DELETE, wxBitmap( delete_xpm ), wxNullBitmap, FALSE, -1, -1, NULL, "Delete file" );
c801d85f 134 m_tb->AddSeparator();
46dc76ba 135 m_tb->AddTool( ID_MD, wxBitmap( fileopen_xpm ), wxNullBitmap, FALSE, -1, -1, NULL, "Create directory" );
c801d85f 136 m_tb->AddSeparator();
46dc76ba
RR
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" );
c801d85f 140 m_tb->AddSeparator();
46dc76ba
RR
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" );
c801d85f 144 m_tb->AddSeparator();
46dc76ba 145 m_tb->AddTool( ID_MOUNT, wxBitmap( search_xpm ), wxNullBitmap, FALSE, -1, -1, NULL, "Mount devices" );
c801d85f 146 m_tb->AddSeparator();
46dc76ba 147 m_tb->AddTool( ID_SEARCH, wxBitmap( save_xpm ), wxNullBitmap, FALSE, -1, -1, NULL, "Find file(s)" );
c801d85f 148 m_tb->AddSeparator();
46dc76ba 149 m_tb->AddTool( ID_ABOUT, wxBitmap( help_xpm ), wxNullBitmap, FALSE, -1, -1, NULL, "About wxFile" );
c801d85f 150
b204641e 151 m_tb->Realize();
c801d85f
KB
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
c801d85f
KB
176void 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
241void 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
259void 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
47908e25
RR
295 dialog.Fit();
296
c801d85f
KB
297 dialog.ShowModal();
298};
299
300void MyFrame::OnListKeyDown( wxListEvent &event )
301{
302 m_rightFile->m_lastFocus->OnListKeyDown( event );
303};
304
305void MyFrame::OnListDeleteItem( wxListEvent &event )
306{
307 m_rightFile->m_lastFocus->OnListDeleteItem( event );
308};
309
310void MyFrame::OnListEndLabelEdit( wxListEvent &event )
311{
312 m_rightFile->m_lastFocus->OnListEndLabelEdit( event );
313};
314
315void MyFrame::OnListDrag( wxListEvent &event )
316{
e3e65dac
RR
317 wxFileDataObject data;
318 data.AddFile( "/home/karl/test.txt" );
319
320 wxDropSource drag( data, m_leftFile->m_lastFocus );
321 drag.DoDragDrop();
c801d85f
KB
322};
323
324void MyFrame::OnTreeSelected( wxTreeEvent &event )
325{
326 wxDirInfo *info = (wxDirInfo*) event.m_item.m_data;
4c681997 327 if (info) SetStatusText( info->GetPath() );
c801d85f
KB
328};
329
330void MyFrame::OnTreeKeyDown( wxTreeEvent &event )
331{
332 wxDirInfo *info = (wxDirInfo*) event.m_item.m_data;
4c681997 333 if (info) m_rightFile->GoToDir( info->GetPath() );
c801d85f
KB
334};
335
336//-----------------------------------------------------------------------------
337// MyApp
338//-----------------------------------------------------------------------------
339
340MyApp::MyApp(void) :
341 wxApp( )
342{
343};
344
345bool MyApp::OnInit(void)
346{
347 wxFrame *frame = new MyFrame();
348 frame->Show( TRUE );
349
350 return TRUE;
351};
352
353
354
355
356