]> git.saurik.com Git - wxWidgets.git/blob - user/wxFile/wxFile.cpp
Removed wxProp source files
[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 int ID_FILECTRL = 1000;
56 const int ID_DIRCTRL = 1001;
57 const int ID_TOOLBAR = 1002;
58
59 const int ID_QUIT = 100;
60 const int ID_ABOUT = 101;
61
62 const int ID_LIST = 200;
63 const int ID_REPORT = 201;
64 const int ID_ICON = 202;
65
66 const int ID_SINGLE = 203;
67 const int ID_TREE = 204;
68 const int ID_COMMANDER = 205;
69
70 const int ID_HOME = 400;
71 const int ID_PARENT = 401;
72 const int ID_MOUNT = 402;
73 const int ID_SEARCH = 403;
74
75 const int ID_DELETE = 501;
76 const int 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( (wxFrame *) NULL, -1, (char *) "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();
125 m_tb->SetMargins( 2, 2 );
126
127 m_tb->AddSeparator();
128 m_tb->AddTool( ID_QUIT, wxBitmap( exit_xpm ), wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "Exit wxFile" );
129 m_tb->AddSeparator();
130 m_tb->AddTool( ID_PARENT, wxBitmap( prev_xpm ), wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "Go to parent directory" );
131 m_tb->AddTool( ID_HOME, wxBitmap( home_xpm ), wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "Go to home directory" );
132 m_tb->AddSeparator();
133 m_tb->AddTool( ID_DELETE, wxBitmap( delete_xpm ), wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "Delete file" );
134 m_tb->AddSeparator();
135 m_tb->AddTool( ID_MD, wxBitmap( fileopen_xpm ), wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "Create directory" );
136 m_tb->AddSeparator();
137 m_tb->AddTool( ID_LIST, wxBitmap( listview_xpm ), wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "List view" );
138 m_tb->AddTool( ID_REPORT, wxBitmap( reportview_xpm ), wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "Report view" );
139 m_tb->AddTool( ID_ICON, wxBitmap( iconview_xpm ), wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "Icon view" );
140 m_tb->AddSeparator();
141 m_tb->AddTool( ID_TREE, wxBitmap( treeview_xpm ), wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "Tree view" );
142 m_tb->AddTool( ID_COMMANDER, wxBitmap( commanderview_xpm ), wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "Commander view" );
143 m_tb->AddTool( ID_SINGLE, wxBitmap( singleview_xpm ), wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "Single view" );
144 m_tb->AddSeparator();
145 m_tb->AddTool( ID_MOUNT, wxBitmap( search_xpm ), wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "Mount devices" );
146 m_tb->AddSeparator();
147 m_tb->AddTool( ID_SEARCH, wxBitmap( save_xpm ), wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "Find file(s)" );
148 m_tb->AddSeparator();
149 m_tb->AddTool( ID_ABOUT, wxBitmap( help_xpm ), wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "About wxFile" );
150
151 m_tb->Realize();
152
153 m_splitter = new wxSplitterWindow( this, -1, wxPoint(0,0), wxSize(400,300), wxSP_3D );
154
155 m_leftFile = (wxFileCtrl *) NULL;
156 m_dir = new wxDirCtrl( m_splitter, ID_DIRCTRL, "/", wxPoint(10,45), wxSize(200,330) );
157
158 wxString homepath;
159 wxGetHomeDir( &homepath );
160
161 m_rightFile = new wxFileCtrl( m_splitter, ID_FILECTRL, homepath, wxPoint(220,5), wxSize(200,330) );
162
163 m_leftFile = new wxFileCtrl( m_splitter, ID_FILECTRL, homepath, wxPoint(0,5), wxSize(200,330) );
164 m_leftFile->Show( FALSE );
165
166 m_leftFile->m_lastFocus = m_rightFile;
167
168 int x = 0;
169 GetClientSize( &x, (int *) NULL );
170
171 m_splitter->SplitVertically( m_dir, m_rightFile, x / 3 );
172 m_splitter->SetMinimumPaneSize( 10 );
173 };
174
175 void MyFrame::OnView( wxCommandEvent &event )
176 {
177 int x = 0;
178 GetClientSize( &x, (int *) NULL );
179 switch (event.GetId())
180 {
181 case ID_LIST:
182 m_rightFile->ChangeToListMode();
183 if (m_splitter->IsSplit() && (m_splitter->GetWindow1() == m_leftFile))
184 m_leftFile->ChangeToListMode();
185 break;
186 case ID_REPORT:
187 m_rightFile->ChangeToReportMode();
188 if (m_splitter->IsSplit() && (m_splitter->GetWindow1() == m_leftFile))
189 m_leftFile->ChangeToReportMode();
190 break;
191 case ID_ICON:
192 m_rightFile->ChangeToIconMode();
193 if (m_splitter->IsSplit() && (m_splitter->GetWindow1() == m_leftFile))
194 m_leftFile->ChangeToIconMode();
195 break;
196 case ID_TREE:
197 if (m_splitter->IsSplit())
198 {
199 if (m_splitter->GetWindow1() != m_dir)
200 {
201 m_splitter->Unsplit( m_leftFile );
202 m_dir->Show(TRUE);
203 m_splitter->SplitVertically( m_dir, m_rightFile, x/3 );
204 };
205 }
206 else
207 {
208 m_dir->Show(TRUE);
209 m_splitter->SplitVertically( m_dir, m_rightFile, x/3 );
210 };
211 break;
212 case ID_SINGLE:
213 if (m_splitter->IsSplit()) m_splitter->Unsplit( m_splitter->GetWindow1() );
214 break;
215 case ID_COMMANDER:
216 if (m_splitter->IsSplit())
217 {
218 if (m_splitter->GetWindow1() != m_leftFile)
219 {
220 m_splitter->Unsplit( m_dir );
221 m_leftFile->ChangeToListMode();
222 m_rightFile->ChangeToListMode();
223 m_leftFile->Show(TRUE);
224 m_splitter->SplitVertically( m_leftFile, m_rightFile, x/2 );
225 };
226 }
227 else
228 {
229 m_leftFile->ChangeToListMode();
230 m_rightFile->ChangeToListMode();
231 m_leftFile->Show(TRUE);
232 m_splitter->SplitVertically( m_leftFile, m_rightFile, x/2 );
233 };
234 break;
235 default:
236 break;
237 };
238 };
239
240 void MyFrame::OnCommand( wxCommandEvent &event )
241 {
242 switch (event.GetId())
243 {
244 case ID_QUIT:
245 Close( TRUE );
246 break;
247 case ID_HOME:
248 m_leftFile->m_lastFocus->GoToHomeDir();
249 break;
250 case ID_PARENT:
251 m_leftFile->m_lastFocus->GoToParentDir();
252 break;
253 default:
254 break;
255 };
256 };
257
258 void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) )
259 {
260 wxDialog dialog( this, -1, "About wxFile", wxPoint(100,100), wxSize(540,350), wxDIALOG_MODAL );
261
262 int w = 0;
263 int h = 0;
264 dialog.GetSize( &w, &h );
265
266 int x = 30;
267 int y = 20;
268 int step = 20;
269
270 (void)new wxStaticBox( &dialog, -1, (const char*)NULL, wxPoint(10,10), wxSize(w-20,h-80) );
271
272 (void)new wxStaticText( &dialog, -1, "wxFile v0.1", wxPoint(240,y) );
273 y += 2*step-10;
274
275 (void)new wxStaticText( &dialog, -1, "Written by Robert Roebling, 1998.", wxPoint(x,y) );
276 y += 2*step;
277
278 (void)new wxStaticText( &dialog, -1,
279 "wxFile uses wxGTK, the GTK port of the wxWindows GUI-library.", wxPoint(x,y) );
280 y += step;
281 (void)new wxStaticText( &dialog, -1, "http://www.freiburg.linux.de/~wxxt", wxPoint(x+50,y) );
282 y += step;
283 (void)new wxStaticText( &dialog, -1, "http://web.ukonline.co.uk/julian.smart/wxwin", wxPoint(x+50,y) );
284 y += 2*step;
285
286 (void)new wxStaticText( &dialog, -1, "wxFile Copyright: GPL.", wxPoint(x,y) );
287 y += 2*step;
288 (void)new wxStaticText( &dialog, -1, "For questions concerning wxGTK, you may mail to:", wxPoint(x,y) );
289 y += step;
290 (void)new wxStaticText( &dialog, -1, "roebling@ruf.uni-freiburg.de", wxPoint(x+50,y) );
291
292 (void) new wxButton( &dialog, wxID_OK, "Return", wxPoint(w/2-40,h-50), wxSize(80,30) );
293
294 dialog.Fit();
295
296 dialog.ShowModal();
297 };
298
299 void MyFrame::OnListKeyDown( wxListEvent &event )
300 {
301 m_rightFile->m_lastFocus->OnListKeyDown( event );
302 };
303
304 void MyFrame::OnListDeleteItem( wxListEvent &event )
305 {
306 m_rightFile->m_lastFocus->OnListDeleteItem( event );
307 };
308
309 void MyFrame::OnListEndLabelEdit( wxListEvent &event )
310 {
311 m_rightFile->m_lastFocus->OnListEndLabelEdit( event );
312 };
313
314 void MyFrame::OnListDrag( wxListEvent &event )
315 {
316 wxFileDataObject data;
317 data.AddFile( "/home/karl/test.txt" );
318
319 wxDropSource drag( data, m_leftFile->m_lastFocus );
320 drag.DoDragDrop();
321 };
322
323 void MyFrame::OnTreeSelected( wxTreeEvent &event )
324 {
325 wxDirInfo *info = (wxDirInfo*) event.m_item.m_data;
326 if (info) SetStatusText( info->GetPath() );
327 };
328
329 void MyFrame::OnTreeKeyDown( wxTreeEvent &event )
330 {
331 wxDirInfo *info = (wxDirInfo*) event.m_item.m_data;
332 if (info) m_rightFile->GoToDir( info->GetPath() );
333 };
334
335 //-----------------------------------------------------------------------------
336 // MyApp
337 //-----------------------------------------------------------------------------
338
339 MyApp::MyApp(void) :
340 wxApp( )
341 {
342 };
343
344 bool MyApp::OnInit(void)
345 {
346 wxFrame *frame = new MyFrame();
347 frame->Show( TRUE );
348
349 return TRUE;
350 };
351
352
353
354
355