]>
git.saurik.com Git - wxWidgets.git/blob - user/wxFile/wxFile.cpp
5c93b977dfbef36bae3715139cd4ee3d17f9b800
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) );
159 wxGetHomeDir( &homepath
);
161 m_rightFile
= new wxFileCtrl( m_splitter
, ID_FILECTRL
, homepath
, wxPoint(220,5), wxSize(200,330) );
163 m_leftFile
= new wxFileCtrl( m_splitter
, ID_FILECTRL
, homepath
, wxPoint(0,5), wxSize(200,330) );
164 m_leftFile
->Show( FALSE
);
166 m_leftFile
->m_lastFocus
= m_rightFile
;
169 GetClientSize( &x
, (int *) NULL
);
171 m_splitter
->SplitVertically( m_dir
, m_rightFile
, x
/ 3 );
172 m_splitter
->SetMinimumPaneSize( 10 );
175 void MyFrame::OnView( wxCommandEvent
&event
)
178 GetClientSize( &x
, (int *) NULL
);
179 switch (event
.GetId())
182 m_rightFile
->ChangeToListMode();
183 if (m_splitter
->IsSplit() && (m_splitter
->GetWindow1() == m_leftFile
))
184 m_leftFile
->ChangeToListMode();
187 m_rightFile
->ChangeToReportMode();
188 if (m_splitter
->IsSplit() && (m_splitter
->GetWindow1() == m_leftFile
))
189 m_leftFile
->ChangeToReportMode();
192 m_rightFile
->ChangeToIconMode();
193 if (m_splitter
->IsSplit() && (m_splitter
->GetWindow1() == m_leftFile
))
194 m_leftFile
->ChangeToIconMode();
197 if (m_splitter
->IsSplit())
199 if (m_splitter
->GetWindow1() != m_dir
)
201 m_splitter
->Unsplit( m_leftFile
);
203 m_splitter
->SplitVertically( m_dir
, m_rightFile
, x
/3 );
209 m_splitter
->SplitVertically( m_dir
, m_rightFile
, x
/3 );
213 if (m_splitter
->IsSplit()) m_splitter
->Unsplit( m_splitter
->GetWindow1() );
216 if (m_splitter
->IsSplit())
218 if (m_splitter
->GetWindow1() != m_leftFile
)
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 );
229 m_leftFile
->ChangeToListMode();
230 m_rightFile
->ChangeToListMode();
231 m_leftFile
->Show(TRUE
);
232 m_splitter
->SplitVertically( m_leftFile
, m_rightFile
, x
/2 );
240 void MyFrame::OnCommand( wxCommandEvent
&event
)
242 switch (event
.GetId())
248 m_leftFile
->m_lastFocus
->GoToHomeDir();
251 m_leftFile
->m_lastFocus
->GoToParentDir();
258 void MyFrame::OnAbout( wxCommandEvent
&WXUNUSED(event
) )
260 wxDialog
dialog( this, -1, "About wxFile", wxPoint(100,100), wxSize(540,350), wxDIALOG_MODAL
);
264 dialog
.GetSize( &w
, &h
);
270 (void)new wxStaticBox( &dialog
, -1, (const char*)NULL
, wxPoint(10,10), wxSize(w
-20,h
-80) );
272 (void)new wxStaticText( &dialog
, -1, "wxFile v0.1", wxPoint(240,y
) );
275 (void)new wxStaticText( &dialog
, -1, "Written by Robert Roebling, 1998.", wxPoint(x
,y
) );
278 (void)new wxStaticText( &dialog
, -1,
279 "wxFile uses wxGTK, the GTK port of the wxWindows GUI-library.", wxPoint(x
,y
) );
281 (void)new wxStaticText( &dialog
, -1, "http://www.freiburg.linux.de/~wxxt", wxPoint(x
+50,y
) );
283 (void)new wxStaticText( &dialog
, -1, "http://web.ukonline.co.uk/julian.smart/wxwin", wxPoint(x
+50,y
) );
286 (void)new wxStaticText( &dialog
, -1, "wxFile Copyright: GPL.", wxPoint(x
,y
) );
288 (void)new wxStaticText( &dialog
, -1, "For questions concerning wxGTK, you may mail to:", wxPoint(x
,y
) );
290 (void)new wxStaticText( &dialog
, -1, "roebling@ruf.uni-freiburg.de", wxPoint(x
+50,y
) );
292 (void) new wxButton( &dialog
, wxID_OK
, "Return", wxPoint(w
/2-40,h
-50), wxSize(80,30) );
299 void MyFrame::OnListKeyDown( wxListEvent
&event
)
301 m_rightFile
->m_lastFocus
->OnListKeyDown( event
);
304 void MyFrame::OnListDeleteItem( wxListEvent
&event
)
306 m_rightFile
->m_lastFocus
->OnListDeleteItem( event
);
309 void MyFrame::OnListEndLabelEdit( wxListEvent
&event
)
311 m_rightFile
->m_lastFocus
->OnListEndLabelEdit( event
);
314 void MyFrame::OnListDrag( wxListEvent
&event
)
316 wxFileDataObject data
;
317 data
.AddFile( "/home/karl/test.txt" );
319 wxDropSource
drag( data
, m_leftFile
->m_lastFocus
);
323 void MyFrame::OnTreeSelected( wxTreeEvent
&event
)
325 wxDirInfo
*info
= (wxDirInfo
*) event
.m_item
.m_data
;
326 if (info
) SetStatusText( info
->GetPath() );
329 void MyFrame::OnTreeKeyDown( wxTreeEvent
&event
)
331 wxDirInfo
*info
= (wxDirInfo
*) event
.m_item
.m_data
;
332 if (info
) m_rightFile
->GoToDir( info
->GetPath() );
335 //-----------------------------------------------------------------------------
337 //-----------------------------------------------------------------------------
344 bool MyApp::OnInit(void)
346 wxFrame
*frame
= new MyFrame();