]>
git.saurik.com Git - wxWidgets.git/blob - user/wxFile/wxFile.cpp
4 * Author: Robert Roebling
6 * Copyright: (C) 1997, GNU (Robert Roebling)
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.
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.
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.
24 #pragma implementation "wxFile.h"
33 #include "fileopen.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"
45 //-----------------------------------------------------------------------------
47 //-----------------------------------------------------------------------------
51 //-----------------------------------------------------------------------------
53 //-----------------------------------------------------------------------------
55 const int ID_FILECTRL
= 1000;
56 const int ID_DIRCTRL
= 1001;
57 const int ID_TOOLBAR
= 1002;
59 const int ID_QUIT
= 100;
60 const int ID_ABOUT
= 101;
62 const int ID_LIST
= 200;
63 const int ID_REPORT
= 201;
64 const int ID_ICON
= 202;
66 const int ID_SINGLE
= 203;
67 const int ID_TREE
= 204;
68 const int ID_COMMANDER
= 205;
70 const int ID_HOME
= 400;
71 const int ID_PARENT
= 401;
72 const int ID_MOUNT
= 402;
73 const int ID_SEARCH
= 403;
75 const int ID_DELETE
= 501;
76 const int ID_MD
= 502;
79 IMPLEMENT_DYNAMIC_CLASS( MyFrame
, wxFrame
)
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
)
100 MyFrame::MyFrame(void) :
101 wxFrame( (wxFrame
*) NULL
, -1, (char *) "wxFile", wxPoint(20,20), wxSize(470,360) )
103 wxMenu
*file_menu
= new wxMenu( "Menu 1" );
104 file_menu
->Append( ID_ABOUT
, "About..");
105 file_menu
->Append( ID_QUIT
, "Exit");
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");
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
);
117 SetMenuBar( menu_bar
);
119 CreateStatusBar( 2 );
121 SetStatusText( "Welcome", 0 );
122 SetStatusText( "wxFile v0.2 by Robert Roebling.", 1 );
124 wxToolBar
*m_tb
= CreateToolBar();
125 m_tb
->SetMargins( 2, 2 );
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" );
153 m_splitter
= new wxSplitterWindow( this, -1, wxPoint(0,0), wxSize(400,300), wxSP_3D
);
155 m_leftFile
= (wxFileCtrl
*) NULL
;
156 m_dir
= new wxDirCtrl( m_splitter
, ID_DIRCTRL
, "/", wxPoint(10,45), wxSize(200,330) );
158 wxString
homepath( "/home" );
162 m_rightFile
= new wxFileCtrl( m_splitter
, ID_FILECTRL
, homepath
, wxPoint(220,5), wxSize(200,330) );
164 m_leftFile
= new wxFileCtrl( m_splitter
, ID_FILECTRL
, homepath
, wxPoint(0,5), wxSize(200,330) );
165 m_leftFile
->Show( FALSE
);
167 m_leftFile
->m_lastFocus
= m_rightFile
;
170 GetClientSize( &x
, (int *) NULL
);
172 m_splitter
->SplitVertically( m_dir
, m_rightFile
, x
/ 3 );
173 m_splitter
->SetMinimumPaneSize( 10 );
176 void MyFrame::OnView( wxCommandEvent
&event
)
179 GetClientSize( &x
, (int *) NULL
);
180 switch (event
.GetId())
183 m_rightFile
->ChangeToListMode();
184 if (m_splitter
->IsSplit() && (m_splitter
->GetWindow1() == m_leftFile
))
185 m_leftFile
->ChangeToListMode();
188 m_rightFile
->ChangeToReportMode();
189 if (m_splitter
->IsSplit() && (m_splitter
->GetWindow1() == m_leftFile
))
190 m_leftFile
->ChangeToReportMode();
193 m_rightFile
->ChangeToIconMode();
194 if (m_splitter
->IsSplit() && (m_splitter
->GetWindow1() == m_leftFile
))
195 m_leftFile
->ChangeToIconMode();
198 if (m_splitter
->IsSplit())
200 if (m_splitter
->GetWindow1() != m_dir
)
202 m_splitter
->Unsplit( m_leftFile
);
204 m_splitter
->SplitVertically( m_dir
, m_rightFile
, x
/3 );
210 m_splitter
->SplitVertically( m_dir
, m_rightFile
, x
/3 );
214 if (m_splitter
->IsSplit()) m_splitter
->Unsplit( m_splitter
->GetWindow1() );
217 if (m_splitter
->IsSplit())
219 if (m_splitter
->GetWindow1() != m_leftFile
)
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 );
230 m_leftFile
->ChangeToListMode();
231 m_rightFile
->ChangeToListMode();
232 m_leftFile
->Show(TRUE
);
233 m_splitter
->SplitVertically( m_leftFile
, m_rightFile
, x
/2 );
241 void MyFrame::OnCommand( wxCommandEvent
&event
)
243 switch (event
.GetId())
249 m_leftFile
->m_lastFocus
->GoToHomeDir();
252 m_leftFile
->m_lastFocus
->GoToParentDir();
259 void MyFrame::OnAbout( wxCommandEvent
&WXUNUSED(event
) )
261 wxDialog
dialog( this, -1, "About wxFile", wxPoint(100,100), wxSize(540,350), wxDIALOG_MODAL
);
265 dialog
.GetSize( &w
, &h
);
271 (void)new wxStaticBox( &dialog
, -1, (const char*)NULL
, wxPoint(10,10), wxSize(w
-20,h
-80) );
273 (void)new wxStaticText( &dialog
, -1, "wxFile v0.1", wxPoint(240,y
) );
276 (void)new wxStaticText( &dialog
, -1, "Written by Robert Roebling, 1998.", wxPoint(x
,y
) );
279 (void)new wxStaticText( &dialog
, -1,
280 "wxFile uses wxGTK, the GTK port of the wxWindows GUI-library.", wxPoint(x
,y
) );
282 (void)new wxStaticText( &dialog
, -1, "http://www.freiburg.linux.de/~wxxt", wxPoint(x
+50,y
) );
284 (void)new wxStaticText( &dialog
, -1, "http://web.ukonline.co.uk/julian.smart/wxwin", wxPoint(x
+50,y
) );
287 (void)new wxStaticText( &dialog
, -1, "wxFile Copyright: GPL.", wxPoint(x
,y
) );
289 (void)new wxStaticText( &dialog
, -1, "For questions concerning wxGTK, you may mail to:", wxPoint(x
,y
) );
291 (void)new wxStaticText( &dialog
, -1, "roebling@ruf.uni-freiburg.de", wxPoint(x
+50,y
) );
293 (void) new wxButton( &dialog
, wxID_OK
, "Return", wxPoint(w
/2-40,h
-50), wxSize(80,30) );
300 void MyFrame::OnListKeyDown( wxListEvent
&event
)
302 m_rightFile
->m_lastFocus
->OnListKeyDown( event
);
305 void MyFrame::OnListDeleteItem( wxListEvent
&event
)
307 m_rightFile
->m_lastFocus
->OnListDeleteItem( event
);
310 void MyFrame::OnListEndLabelEdit( wxListEvent
&event
)
312 m_rightFile
->m_lastFocus
->OnListEndLabelEdit( event
);
315 void MyFrame::OnListDrag( wxListEvent
&event
)
317 wxFileDataObject data
;
318 data
.AddFile( "/home/karl/test.txt" );
320 wxDropSource
drag( data
, m_leftFile
->m_lastFocus
);
324 void MyFrame::OnTreeSelected( wxTreeEvent
&event
)
326 wxDirInfo
*info
= (wxDirInfo
*) event
.m_item
.m_data
;
327 if (info
) SetStatusText( info
->GetPath() );
330 void MyFrame::OnTreeKeyDown( wxTreeEvent
&event
)
332 wxDirInfo
*info
= (wxDirInfo
*) event
.m_item
.m_data
;
333 if (info
) m_rightFile
->GoToDir( info
->GetPath() );
336 //-----------------------------------------------------------------------------
338 //-----------------------------------------------------------------------------
345 bool MyApp::OnInit(void)
347 wxFrame
*frame
= new MyFrame();