]>
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 ID_FILECTRL
= 1000;
56 const ID_DIRCTRL
= 1001;
57 const ID_TOOLBAR
= 1002;
63 const ID_REPORT
= 201;
66 const ID_SINGLE
= 203;
68 const ID_COMMANDER
= 205;
71 const ID_PARENT
= 401;
73 const ID_SEARCH
= 403;
75 const ID_DELETE
= 501;
79 IMPLEMENT_DYNAMIC_CLASS( MyFrame
, wxFrame
)
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
)
108 MyFrame::MyFrame(void) :
109 wxFrame( NULL
, -1, "wxFile", wxPoint(20,20), wxSize(470,360) )
111 wxMenu
*file_menu
= new wxMenu( "Menu 1" );
112 file_menu
->Append( ID_ABOUT
, "About..");
113 file_menu
->Append( ID_QUIT
, "Exit");
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");
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
);
125 SetMenuBar( menu_bar
);
127 CreateStatusBar( 2 );
129 SetStatusText( "Welcome", 0 );
130 SetStatusText( "wxFile v0.2 by Robert Roebling.", 1 );
132 m_tb
= new wxToolBarGTK( this, ID_TOOLBAR
, wxPoint(2,60), wxSize(300-4,26) );
133 m_tb
->SetMargins( 2, 2 );
136 m_tb
->AddSeparator();
138 bm
= new wxBitmap( exit_xpm
);
139 m_tb
->AddTool( ID_QUIT
, *bm
, wxNullBitmap
, FALSE
, -1, -1, NULL
, "Exit wxFile" );
140 m_tb
->AddSeparator();
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();
148 bm
= new wxBitmap( delete_xpm
);
149 m_tb
->AddTool( ID_DELETE
, *bm
, wxNullBitmap
, FALSE
, -1, -1, NULL
, "Delete file" );
150 m_tb
->AddSeparator();
152 bm
= new wxBitmap( fileopen_xpm
);
153 m_tb
->AddTool( ID_MD
, *bm
, wxNullBitmap
, FALSE
, -1, -1, NULL
, "Create directory" );
154 m_tb
->AddSeparator();
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();
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();
172 bm
= new wxBitmap( search_xpm
);
173 m_tb
->AddTool( ID_MOUNT
, *bm
, wxNullBitmap
, FALSE
, -1, -1, NULL
, "Mount devices" );
174 m_tb
->AddSeparator();
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();
180 bm
= new wxBitmap( help_xpm
);
181 m_tb
->AddTool( ID_ABOUT
, *bm
, wxNullBitmap
, FALSE
, -1, -1, NULL
, "About wxFile" );
185 m_splitter
= new wxSplitterWindow( this, -1, wxPoint(0,0), wxSize(400,300), wxSP_3D
);
188 m_dir
= new wxDirCtrl( m_splitter
, ID_DIRCTRL
, "/", wxPoint(10,45), wxSize(200,330) );
190 wxString
homepath( "/home" );
194 m_rightFile
= new wxFileCtrl( m_splitter
, ID_FILECTRL
, homepath
, wxPoint(220,5), wxSize(200,330) );
196 m_leftFile
= new wxFileCtrl( m_splitter
, ID_FILECTRL
, homepath
, wxPoint(0,5), wxSize(200,330) );
197 m_leftFile
->Show( FALSE
);
199 m_leftFile
->m_lastFocus
= m_rightFile
;
202 GetClientSize( &x
, NULL
);
204 m_splitter
->SplitVertically( m_dir
, m_rightFile
, x
/ 3 );
205 m_splitter
->SetMinimumPaneSize( 10 );
208 void MyFrame::OnSize( wxSizeEvent
&WXUNUSED(event
) )
212 GetClientSize( &x
, &y
);
214 m_tb
->SetSize( 1, 0, x
-2, 30 );
215 m_splitter
->SetSize( 0, 31, x
, y
-31 );
218 void MyFrame::OnView( wxCommandEvent
&event
)
221 GetClientSize( &x
, NULL
);
222 switch (event
.GetId())
225 m_rightFile
->ChangeToListMode();
226 if (m_splitter
->IsSplit() && (m_splitter
->GetWindow1() == m_leftFile
))
227 m_leftFile
->ChangeToListMode();
230 m_rightFile
->ChangeToReportMode();
231 if (m_splitter
->IsSplit() && (m_splitter
->GetWindow1() == m_leftFile
))
232 m_leftFile
->ChangeToReportMode();
235 m_rightFile
->ChangeToIconMode();
236 if (m_splitter
->IsSplit() && (m_splitter
->GetWindow1() == m_leftFile
))
237 m_leftFile
->ChangeToIconMode();
240 if (m_splitter
->IsSplit())
242 if (m_splitter
->GetWindow1() != m_dir
)
244 m_splitter
->Unsplit( m_leftFile
);
246 m_splitter
->SplitVertically( m_dir
, m_rightFile
, x
/3 );
252 m_splitter
->SplitVertically( m_dir
, m_rightFile
, x
/3 );
256 if (m_splitter
->IsSplit()) m_splitter
->Unsplit( m_splitter
->GetWindow1() );
259 if (m_splitter
->IsSplit())
261 if (m_splitter
->GetWindow1() != m_leftFile
)
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 );
272 m_leftFile
->ChangeToListMode();
273 m_rightFile
->ChangeToListMode();
274 m_leftFile
->Show(TRUE
);
275 m_splitter
->SplitVertically( m_leftFile
, m_rightFile
, x
/2 );
283 void MyFrame::OnCommand( wxCommandEvent
&event
)
285 switch (event
.GetId())
291 m_leftFile
->m_lastFocus
->GoToHomeDir();
294 m_leftFile
->m_lastFocus
->GoToParentDir();
301 void MyFrame::OnAbout( wxCommandEvent
&WXUNUSED(event
) )
303 wxDialog
dialog( this, -1, "About wxFile", wxPoint(100,100), wxSize(540,350), wxDIALOG_MODAL
);
307 dialog
.GetSize( &w
, &h
);
313 (void)new wxStaticBox( &dialog
, -1, (const char*)NULL
, wxPoint(10,10), wxSize(w
-20,h
-80) );
315 (void)new wxStaticText( &dialog
, -1, "wxFile v0.1", wxPoint(240,y
) );
318 (void)new wxStaticText( &dialog
, -1, "Written by Robert Roebling, 1998.", wxPoint(x
,y
) );
321 (void)new wxStaticText( &dialog
, -1,
322 "wxFile uses wxGTK, the GTK port of the wxWindows GUI-library.", wxPoint(x
,y
) );
324 (void)new wxStaticText( &dialog
, -1, "http://www.freiburg.linux.de/~wxxt", wxPoint(x
+50,y
) );
326 (void)new wxStaticText( &dialog
, -1, "http://web.ukonline.co.uk/julian.smart/wxwin", wxPoint(x
+50,y
) );
329 (void)new wxStaticText( &dialog
, -1, "wxFile Copyright: GPL.", wxPoint(x
,y
) );
331 (void)new wxStaticText( &dialog
, -1, "For questions concerning wxGTK, you may mail to:", wxPoint(x
,y
) );
333 (void)new wxStaticText( &dialog
, -1, "roebling@ruf.uni-freiburg.de", wxPoint(x
+50,y
) );
335 (void) new wxButton( &dialog
, wxID_OK
, "Return", wxPoint(w
/2-40,h
-50), wxSize(80,30) );
340 void MyFrame::OnListKeyDown( wxListEvent
&event
)
342 m_rightFile
->m_lastFocus
->OnListKeyDown( event
);
345 void MyFrame::OnListDeleteItem( wxListEvent
&event
)
347 m_rightFile
->m_lastFocus
->OnListDeleteItem( event
);
350 void MyFrame::OnListEndLabelEdit( wxListEvent
&event
)
352 m_rightFile
->m_lastFocus
->OnListEndLabelEdit( event
);
355 void MyFrame::OnListDrag( wxListEvent
&event
)
357 printf( "OnDrag.\n" );
361 void MyFrame::OnTreeSelected( wxTreeEvent
&event
)
363 wxDirInfo
*info
= (wxDirInfo
*) event
.m_item
.m_data
;
364 SetStatusText( info
->GetPath() );
367 void MyFrame::OnTreeKeyDown( wxTreeEvent
&event
)
369 wxDirInfo
*info
= (wxDirInfo
*) event
.m_item
.m_data
;
370 m_rightFile
->GoToDir( info
->GetPath() );
373 //-----------------------------------------------------------------------------
375 //-----------------------------------------------------------------------------
382 bool MyApp::OnInit(void)
384 wxFrame
*frame
= new MyFrame();