文件打包管理器UI设计

UI采用wxWidgets库进行设计,使用了wxAuiManager进行界面管理,分层浮动布局。详细见代码注释:

一、头文件定义

/////////////////////////////////////////////////////////////////////////////// // Name: UI.h // Purpose: 文件打包管理器布局 // Author: 陈相礼 // Modified by: // Created: 2009-7-29 // RCS-ID: // Copyright: (C) Copyright 2009, TSong Corporation, All Rights Reserved. // Licence: /////////////////////////////////////////////////////////////////////////////// // -- application 类 -- class MyApp : public wxApp { public: virtual bool OnInit(); }; // pre-declared and used in class MyFrame class wxSizeReportCtrl; // -- frame -- class MyFrame : public wxFrame { enum { LIST_CTRL, ID_CustomizeToolbar, ID_DropDownToolbarItem, MENU_ID_NEW, MENU_ID_OPEN, MENU_ID_ROPEN, MENU_ID_CLOSE, MENU_ID_HISTORY, MENU_ID_INFO, MENU_ID_EXIT, MENU_ID_TOOL, MENU_ID_PREVIEW, MENU_ID_BIGICON, MENU_ID_SMALLICON, MENU_ID_LISTICON, MENU_ID_DETAILICON, MENU_ID_OPENFILE, MENU_ID_OPENMODE, MENU_ID_UNZIP, MENU_ID_RENAME, MENU_ID_DELETE, MENU_ID_ATTRIBUTE, MENU_ID_NEWFOLDER, MENU_ID_ADDFILE, MENU_ID_ADDFOLDER, MENU_ID_SELECTLISTFILE, MENU_ID_UNZIPALL, MENU_ID_REZIP, MENU_ID_FILETYPEOPTION, MENU_ID_LANGUAGE, MENU_ID_ENGLISH, MENU_ID_CHINESE, MENU_ID_RUSSIAN, MENU_ID_SETDEFAULT, MENU_ID_SETTING, MENU_ID_ABOUT, MENU_ID_TEST, }; public: MyFrame(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_FRAME_STYLE | wxSUNKEN_BORDER); ~MyFrame(); wxAuiDockArt* GetDockArt(); void DoUpdate(); private: wxTextCtrl* CreateTextCtrl(const wxString& text = wxEmptyString); wxTreeCtrl* CreateTreeCtrl( wxString StrPath, wxTreeItemId faItem ); wxPoint GetStartPosition(); wxListCtrl* CreateListCtrl(wxWindow* parent = NULL, long style = wxLC_LIST); wxAuiNotebook* CreateNotebook(); private: void OnEraseBackground(wxEraseEvent& evt); void OnSize(wxSizeEvent& evt); void OnHide(wxCommandEvent& evt); void OnShow(wxCommandEvent& evt); void OnOpen(wxCommandEvent& evt); void OnAddFile(wxCommandEvent& evt); void OnAddFolder(wxCommandEvent& evt); void OnDropDownToolbarItem(wxAuiToolBarEvent& evt); void OnRestorePerspective(wxCommandEvent& evt); void OnSettings(wxCommandEvent& evt); void OnCustomizeToolbar(wxCommandEvent& evt); void OnExit(wxCommandEvent& evt); void OnAbout(wxCommandEvent& evt); void ShowContextMenu(const wxPoint& pos); void OnContextMenu(wxContextMenuEvent& event); void OnChangeListStyle(wxCommandEvent& evt); private: wxAuiManager m_mgr; // Aui管理器 wxAuiNotebook* ctrl; wxTreeCtrl* tree; // 树形控件,测试 wxListCtrl* m_listCtrl; // 列表框控件,测试 wxImageList *m_imageListNormal;// 列表框图标 wxImageList *m_imageListSmall; // 同上 wxArrayString m_perspectives; long m_notebook_style; // 样式 bool flag_tool, flag_preview;// 查看菜单中用于控制显示工具栏和预览窗口之用 DECLARE_EVENT_TABLE() }; // 界面显示设置对话框 class SettingsPanel : public wxPanel { enum { ID_PaneBorderSize = wxID_HIGHEST+1, ID_SashSize, ID_CaptionSize, ID_BackgroundColor, ID_SashColor, ID_InactiveCaptionColor, ID_InactiveCaptionGradientColor, ID_InactiveCaptionTextColor, ID_ActiveCaptionColor, ID_ActiveCaptionGradientColor, ID_ActiveCaptionTextColor, ID_BorderColor, ID_GripperColor }; public: SettingsPanel(wxWindow* parent, MyFrame* frame) : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize), m_frame(frame) { wxBoxSizer* s1 = new wxBoxSizer(wxHORIZONTAL); m_border_size = new wxSpinCtrl(this, ID_PaneBorderSize, wxString::Format(wxT("%d"), frame->GetDockArt()->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE)), wxDefaultPosition, wxSize(50,20), wxSP_ARROW_KEYS, 0, 100, frame->GetDockArt()->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE)); s1->Add(1, 1, 1, wxEXPAND); s1->Add(new wxStaticText(this, wxID_ANY, wxT("面板边缘尺寸:"))); s1->Add(m_border_size); s1->Add(1, 1, 1, wxEXPAND); s1->SetItemMinSize((size_t)1, 180, 20); wxBoxSizer* s2 = new wxBoxSizer(wxHORIZONTAL); m_sash_size = new wxSpinCtrl(this, ID_SashSize, wxString::Format(wxT("%d"), frame->GetDockArt()->GetMetric(wxAUI_DOCKART_SASH_SIZE)), wxDefaultPosition, wxSize(50,20), wxSP_ARROW_KEYS, 0, 100, frame->GetDockArt()->GetMetric(wxAUI_DOCKART_SASH_SIZE)); s2->Add(1, 1, 1, wxEXPAND); s2->Add(new wxStaticText(this, wxID_ANY, wxT("窗框大小:"))); s2->Add(m_sash_size); s2->Add(1, 1, 1, wxEXPAND); s2->SetItemMinSize((size_t)1, 180, 20); wxBoxSizer* s3 = new wxBoxSizer(wxHORIZONTAL); m_caption_size = new wxSpinCtrl(this, ID_CaptionSize, wxString::Format(wxT("%d"), frame->GetDockArt()->GetMetric(wxAUI_DOCKART_CAPTION_SIZE)), wxDefaultPosition, wxSize(50,20), wxSP_ARROW_KEYS, 0, 100, frame->GetDockArt()->GetMetric(wxAUI_DOCKART_CAPTION_SIZE)); s3->Add(1, 1, 1, wxEXPAND); s3->Add(new wxStaticText(this, wxID_ANY, wxT("标题大小:"))); s3->Add(m_caption_size); s3->Add(1, 1, 1, wxEXPAND); s3->SetItemMinSize((size_t)1, 180, 20); wxBitmap b = CreateColorBitmap(*wxBLACK); wxBoxSizer* s4 = new wxBoxSizer(wxHORIZONTAL); m_background_color = new wxBitmapButton(this, ID_BackgroundColor, b, wxDefaultPosition, wxSize(50,25)); s4->Add(1, 1, 1, wxEXPAND); s4->Add(new wxStaticText(this, wxID_ANY, wxT("背景颜色:"))); s4->Add(m_background_color); s4->Add(1, 1, 1, wxEXPAND); s4->SetItemMinSize((size_t)1, 180, 20); wxBoxSizer* s5 = new wxBoxSizer(wxHORIZONTAL); m_sash_color = new wxBitmapButton(this, ID_SashColor, b, wxDefaultPosition, wxSize(50,25)); s5->Add(1, 1, 1, wxEXPAND); s5->Add(new wxStaticText(this, wxID_ANY, wxT("边框颜色:"))); s5->Add(m_sash_color); s5->Add(1, 1, 1, wxEXPAND); s5->SetItemMinSize((size_t)1, 180, 20); wxBoxSizer* s6 = new wxBoxSizer(wxHORIZONTAL); m_inactive_caption_color = new wxBitmapButton(this, ID_InactiveCaptionColor, b, wxDefaultPosition, wxSize(50,25)); s6->Add(1, 1, 1, wxEXPAND); s6->Add(new wxStaticText(this, wxID_ANY, wxT("正常标题颜色:"))); s6->Add(m_inactive_caption_color); s6->Add(1, 1, 1, wxEXPAND); s6->SetItemMinSize((size_t)1, 180, 20); wxBoxSizer* s7 = new wxBoxSizer(wxHORIZONTAL); m_inactive_caption_gradient_color = new wxBitmapButton(this, ID_InactiveCaptionGradientColor, b, wxDefaultPosition, wxSize(50,25)); s7->Add(1, 1, 1, wxEXPAND); s7->Add(new wxStaticText(this, wxID_ANY, wxT("正常标题渐变色:"))); s7->Add(m_inactive_caption_gradient_color); s7->Add(1, 1, 1, wxEXPAND); s7->SetItemMinSize((size_t)1, 180, 20); wxBoxSizer* s8 = new wxBoxSizer(wxHORIZONTAL); m_inactive_caption_text_color = new wxBitmapButton(this, ID_InactiveCaptionTextColor, b, wxDefaultPosition, wxSize(50,25)); s8->Add(1, 1, 1, wxEXPAND); s8->Add(new wxStaticText(this, wxID_ANY, wxT("正常标题文本色:"))); s8->Add(m_inactive_caption_text_color); s8->Add(1, 1, 1, wxEXPAND); s8->SetItemMinSize((size_t)1, 180, 20); wxBoxSizer* s9 = new wxBoxSizer(wxHORIZONTAL); m_active_caption_color = new wxBitmapButton(this, ID_ActiveCaptionColor, b, wxDefaultPosition, wxSize(50,25)); s9->Add(1, 1, 1, wxEXPAND); s9->Add(new wxStaticText(this, wxID_ANY, wxT("活动标题颜色:"))); s9->Add(m_active_caption_color); s9->Add(1, 1, 1, wxEXPAND); s9->SetItemMinSize((size_t)1, 180, 20); wxBoxSizer* s10 = new wxBoxSizer(wxHORIZONTAL); m_active_caption_gradient_color = new wxBitmapButton(this, ID_ActiveCaptionGradientColor, b, wxDefaultPosition, wxSize(50,25)); s10->Add(1, 1, 1, wxEXPAND); s10->Add(new wxStaticText(this, wxID_ANY, wxT("活动标题渐变色:"))); s10->Add(m_active_caption_gradient_color); s10->Add(1, 1, 1, wxEXPAND); s10->SetItemMinSize((size_t)1, 180, 20); wxBoxSizer* s11 = new wxBoxSizer(wxHORIZONTAL); m_active_caption_text_color = new wxBitmapButton(this, ID_ActiveCaptionTextColor, b, wxDefaultPosition, wxSize(50,25)); s11->Add(1, 1, 1, wxEXPAND); s11->Add(new wxStaticText(this, wxID_ANY, wxT("活动标题文本色:"))); s11->Add(m_active_caption_text_color); s11->Add(1, 1, 1, wxEXPAND); s11->SetItemMinSize((size_t)1, 180, 20); wxBoxSizer* s12 = new wxBoxSizer(wxHORIZONTAL); m_border_color = new wxBitmapButton(this, ID_BorderColor, b, wxDefaultPosition, wxSize(50,25)); s12->Add(1, 1, 1, wxEXPAND); s12->Add(new wxStaticText(this, wxID_ANY, wxT("边框颜色:"))); s12->Add(m_border_color); s12->Add(1, 1, 1, wxEXPAND); s12->SetItemMinSize((size_t)1, 180, 20); wxBoxSizer* s13 = new wxBoxSizer(wxHORIZONTAL); m_gripper_color = new wxBitmapButton(this, ID_GripperColor, b, wxDefaultPosition, wxSize(50,25)); s13->Add(1, 1, 1, wxEXPAND); s13->Add(new wxStaticText(this, wxID_ANY, wxT("夹子颜色:"))); s13->Add(m_gripper_color); s13->Add(1, 1, 1, wxEXPAND); s13->SetItemMinSize((size_t)1, 180, 20); wxGridSizer* grid_sizer = new wxGridSizer(2); grid_sizer->SetHGap(5); grid_sizer->Add(s1); grid_sizer->Add(s4); grid_sizer->Add(s2); grid_sizer->Add(s5); grid_sizer->Add(s3); grid_sizer->Add(s13); grid_sizer->Add(1,1); grid_sizer->Add(s12); grid_sizer->Add(s6); grid_sizer->Add(s9); grid_sizer->Add(s7); grid_sizer->Add(s10); grid_sizer->Add(s8); grid_sizer->Add(s11); wxBoxSizer* cont_sizer = new wxBoxSizer(wxVERTICAL); cont_sizer->Add(grid_sizer, 1, wxEXPAND | wxALL, 5); SetSizer(cont_sizer); GetSizer()->SetSizeHints(this); UpdateColors(); } private: wxBitmap CreateColorBitmap(const wxColour& c) { wxImage image; image.Create(25,14); for (int x = 0; x < 25; ++x) for (int y = 0; y < 14; ++y) { wxColour pixcol = c; if (x == 0 || x == 24 || y == 0 || y == 13) pixcol = *wxBLACK; image.SetRGB(x, y, pixcol.Red(), pixcol.Green(), pixcol.Blue()); } return wxBitmap(image); } void UpdateColors() { wxColour bk = m_frame->GetDockArt()->GetColor(wxAUI_DOCKART_BACKGROUND_COLOUR); m_background_color->SetBitmapLabel(CreateColorBitmap(bk)); wxColour cap = m_frame->GetDockArt()->GetColor(wxAUI_DOCKART_INACTIVE_CAPTION_COLOUR); m_inactive_caption_color->SetBitmapLabel(CreateColorBitmap(cap)); wxColour capgrad = m_frame->GetDockArt()->GetColor(wxAUI_DOCKART_INACTIVE_CAPTION_GRADIENT_COLOUR); m_inactive_caption_gradient_color->SetBitmapLabel(CreateColorBitmap(capgrad)); wxColour captxt = m_frame->GetDockArt()->GetColor(wxAUI_DOCKART_INACTIVE_CAPTION_TEXT_COLOUR); m_inactive_caption_text_color->SetBitmapLabel(CreateColorBitmap(captxt)); wxColour acap = m_frame->GetDockArt()->GetColor(wxAUI_DOCKART_ACTIVE_CAPTION_COLOUR); m_active_caption_color->SetBitmapLabel(CreateColorBitmap(acap)); wxColour acapgrad = m_frame->GetDockArt()->GetColor(wxAUI_DOCKART_ACTIVE_CAPTION_GRADIENT_COLOUR); m_active_caption_gradient_color->SetBitmapLabel(CreateColorBitmap(acapgrad)); wxColour acaptxt = m_frame->GetDockArt()->GetColor(wxAUI_DOCKART_ACTIVE_CAPTION_TEXT_COLOUR); m_active_caption_text_color->SetBitmapLabel(CreateColorBitmap(acaptxt)); wxColour sash = m_frame->GetDockArt()->GetColor(wxAUI_DOCKART_SASH_COLOUR); m_sash_color->SetBitmapLabel(CreateColorBitmap(sash)); wxColour border = m_frame->GetDockArt()->GetColor(wxAUI_DOCKART_BORDER_COLOUR); m_border_color->SetBitmapLabel(CreateColorBitmap(border)); wxColour gripper = m_frame->GetDockArt()->GetColor(wxAUI_DOCKART_GRIPPER_COLOUR); m_gripper_color->SetBitmapLabel(CreateColorBitmap(gripper)); } void OnPaneBorderSize(wxSpinEvent& event) { m_frame->GetDockArt()->SetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE, event.GetPosition()); m_frame->DoUpdate(); } void OnSashSize(wxSpinEvent& event) { m_frame->GetDockArt()->SetMetric(wxAUI_DOCKART_SASH_SIZE, event.GetPosition()); m_frame->DoUpdate(); } void OnCaptionSize(wxSpinEvent& event) { m_frame->GetDockArt()->SetMetric(wxAUI_DOCKART_CAPTION_SIZE, event.GetPosition()); m_frame->DoUpdate(); } void OnSetColor(wxCommandEvent& event) { wxColourDialog dlg(m_frame); dlg.SetTitle(_("Color Picker")); if (dlg.ShowModal() != wxID_OK) return; int var = 0; switch (event.GetId()) { case ID_BackgroundColor: var = wxAUI_DOCKART_BACKGROUND_COLOUR; break; case ID_SashColor: var = wxAUI_DOCKART_SASH_COLOUR; break; case ID_InactiveCaptionColor: var = wxAUI_DOCKART_INACTIVE_CAPTION_COLOUR; break; case ID_InactiveCaptionGradientColor: var = wxAUI_DOCKART_INACTIVE_CAPTION_GRADIENT_COLOUR; break; case ID_InactiveCaptionTextColor: var = wxAUI_DOCKART_INACTIVE_CAPTION_TEXT_COLOUR; break; case ID_ActiveCaptionColor: var = wxAUI_DOCKART_ACTIVE_CAPTION_COLOUR; break; case ID_ActiveCaptionGradientColor: var = wxAUI_DOCKART_ACTIVE_CAPTION_GRADIENT_COLOUR; break; case ID_ActiveCaptionTextColor: var = wxAUI_DOCKART_ACTIVE_CAPTION_TEXT_COLOUR; break; case ID_BorderColor: var = wxAUI_DOCKART_BORDER_COLOUR; break; case ID_GripperColor: var = wxAUI_DOCKART_GRIPPER_COLOUR; break; default: return; } m_frame->GetDockArt()->SetColor(var, dlg.GetColourData().GetColour()); m_frame->DoUpdate(); UpdateColors(); } private: MyFrame* m_frame; wxSpinCtrl* m_border_size; wxSpinCtrl* m_sash_size; wxSpinCtrl* m_caption_size; wxBitmapButton* m_inactive_caption_text_color; wxBitmapButton* m_inactive_caption_gradient_color; wxBitmapButton* m_inactive_caption_color; wxBitmapButton* m_active_caption_text_color; wxBitmapButton* m_active_caption_gradient_color; wxBitmapButton* m_active_caption_color; wxBitmapButton* m_sash_color; wxBitmapButton* m_background_color; wxBitmapButton* m_border_color; wxBitmapButton* m_gripper_color; DECLARE_EVENT_TABLE() };

 

二、资源文件

pro_icon ICON "res//pro_icon.ico" #include <wx/msw/wx.rc> icon1 ICON "bitmaps/toolbrai.ico" icon2 ICON "bitmaps/toolchar.ico" icon3 ICON "bitmaps/toolchec.ico" icon4 ICON "bitmaps/tooldata.ico" icon5 ICON "bitmaps/toolgame.ico" icon6 ICON "bitmaps/toolnote.ico" icon7 ICON "bitmaps/tooltime.ico" icon8 ICON "bitmaps/tooltodo.ico" icon9 ICON "bitmaps/toolword.ico" iconsmall ICON "bitmaps/small1.ico"

 

三、界面实现部分

/////////////////////////////////////////////////////////////////////////////// // Name: UI.cpp // Purpose: 文件打包管理器布局 // Author: 陈相礼 // Modified by: // Created: 2009-7-29 // RCS-ID: // Copyright: (C) Copyright 2009, TSong Corporation, All Rights Reserved. // Licence: /////////////////////////////////////////////////////////////////////////////// #include "wx/wxprec.h" #include "wx/app.h" #include "wx/grid.h" #include "wx/treectrl.h" #include "wx/spinctrl.h" #include "wx/artprov.h" #include "wx/clipbrd.h" #include "wx/image.h" #include "wx/colordlg.h" #include "wx/wxhtml.h" #include "wx/imaglist.h" #include "wx/dataobj.h" #include "wx/dcclient.h" #include "wx/bmpbuttn.h" #include "wx/menu.h" #include "wx/toolbar.h" #include "wx/statusbr.h" #include "wx/msgdlg.h" #include "wx/textdlg.h" #include "wx/filefn.h" #include "wx/dir.h" #include "wx/arrstr.h" #include "wx/filename.h" #include "wx/listctrl.h" #include "wx/srchctrl.h" #include "wx/aui/aui.h" #include "wx/filedlg.h" #include "UI.h" ////////////////////////////////////////////////////////////////////////// // SettingsPanel类事件映射表 BEGIN_EVENT_TABLE(SettingsPanel, wxPanel) EVT_SPINCTRL(ID_PaneBorderSize, SettingsPanel::OnPaneBorderSize) EVT_SPINCTRL(ID_SashSize, SettingsPanel::OnSashSize) EVT_SPINCTRL(ID_CaptionSize, SettingsPanel::OnCaptionSize) EVT_BUTTON(ID_BackgroundColor, SettingsPanel::OnSetColor) EVT_BUTTON(ID_SashColor, SettingsPanel::OnSetColor) EVT_BUTTON(ID_InactiveCaptionColor, SettingsPanel::OnSetColor) EVT_BUTTON(ID_InactiveCaptionGradientColor, SettingsPanel::OnSetColor) EVT_BUTTON(ID_InactiveCaptionTextColor, SettingsPanel::OnSetColor) EVT_BUTTON(ID_ActiveCaptionColor, SettingsPanel::OnSetColor) EVT_BUTTON(ID_ActiveCaptionGradientColor, SettingsPanel::OnSetColor) EVT_BUTTON(ID_ActiveCaptionTextColor, SettingsPanel::OnSetColor) EVT_BUTTON(ID_BorderColor, SettingsPanel::OnSetColor) EVT_BUTTON(ID_GripperColor, SettingsPanel::OnSetColor) END_EVENT_TABLE() ////////////////////////////////////////////////////////////////////////// // MyFrame类事件映射表 BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_SIZE(MyFrame::OnSize) EVT_ERASE_BACKGROUND(MyFrame::OnEraseBackground) EVT_MENU(MENU_ID_SETTING, MyFrame::OnSettings) EVT_MENU(MENU_ID_TEST, MyFrame::OnHide) EVT_MENU(MENU_ID_TOOL, MyFrame::OnShow) EVT_MENU(MENU_ID_PREVIEW, MyFrame::OnShow) EVT_MENU(MENU_ID_OPEN, MyFrame::OnOpen) EVT_MENU(MENU_ID_ADDFILE, MyFrame::OnAddFile) EVT_MENU(MENU_ID_ADDFOLDER, MyFrame::OnAddFolder) EVT_MENU(MENU_ID_EXIT, MyFrame::OnExit) EVT_MENU(MENU_ID_ABOUT, MyFrame::OnAbout) EVT_MENU(ID_CustomizeToolbar, MyFrame::OnCustomizeToolbar) EVT_MENU_RANGE(MyFrame::MENU_ID_SETDEFAULT, MyFrame::MENU_ID_SETDEFAULT+1000, MyFrame::OnRestorePerspective) EVT_AUITOOLBAR_TOOL_DROPDOWN(ID_DropDownToolbarItem, MyFrame::OnDropDownToolbarItem) EVT_MENU(MENU_ID_BIGICON, MyFrame::OnChangeListStyle) EVT_MENU(MENU_ID_SMALLICON, MyFrame::OnChangeListStyle) EVT_MENU(MENU_ID_LISTICON, MyFrame::OnChangeListStyle) EVT_MENU(MENU_ID_DETAILICON, MyFrame::OnChangeListStyle) EVT_CONTEXT_MENU(MyFrame::OnContextMenu) END_EVENT_TABLE() DECLARE_APP(MyApp) ////////////////////////////////////////////////////////////////////////// // 程序入口点 IMPLEMENT_APP(MyApp) // 定义列表框图片个数等 static const int NUM_ITEMS = 30; static const int NUM_ICONS = 9; // 程序从这里开始执行 bool MyApp::OnInit() { wxFrame* frame = new MyFrame(NULL, wxID_ANY, wxT("文件打包管理器 - [V1.0]"), wxDefaultPosition, wxSize(800, 600)); SetTopWindow(frame); frame->Show(); return true; } ////////////////////////////////////////////////////////////////////////// // 初始化,对整个UI界面进行布局 MyFrame::MyFrame(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style) : wxFrame(parent, id, title, pos, size, style) { // 告诉 wxAuiManager 要管理的框架 m_mgr.SetManagedWindow(this); // 设置 frame 图标 SetIcon( wxIcon( wxT( "pro_icon" ) ) ); // 设置列表框控件图标列表 m_imageListNormal = new wxImageList(32, 32, true); m_imageListSmall = new wxImageList(16, 16, true); m_imageListNormal->Add( wxIcon(_T("icon1"), wxBITMAP_TYPE_ICO_RESOURCE) ); m_imageListNormal->Add( wxIcon(_T("icon2"), wxBITMAP_TYPE_ICO_RESOURCE) ); m_imageListNormal->Add( wxIcon(_T("icon3"), wxBITMAP_TYPE_ICO_RESOURCE) ); m_imageListNormal->Add( wxIcon(_T("icon4"), wxBITMAP_TYPE_ICO_RESOURCE) ); m_imageListNormal->Add( wxIcon(_T("icon5"), wxBITMAP_TYPE_ICO_RESOURCE) ); m_imageListNormal->Add( wxIcon(_T("icon6"), wxBITMAP_TYPE_ICO_RESOURCE) ); m_imageListNormal->Add( wxIcon(_T("icon7"), wxBITMAP_TYPE_ICO_RESOURCE) ); m_imageListNormal->Add( wxIcon(_T("icon8"), wxBITMAP_TYPE_ICO_RESOURCE) ); m_imageListNormal->Add( wxIcon(_T("icon9"), wxBITMAP_TYPE_ICO_RESOURCE) ); m_imageListSmall->Add( wxIcon(_T("pro_icon"), wxBITMAP_TYPE_ICO_RESOURCE) ); // 设定默认 notebook 样式 m_notebook_style = wxAUI_NB_DEFAULT_STYLE | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER; // 创建菜单 wxMenuBar* mb = new wxMenuBar; wxMenu* file_menu = new wxMenu; file_menu->Append(MENU_ID_NEW, _("新建(&N)/tCtrl+N")); file_menu->Append(MENU_ID_OPEN, _("打开(&O)/tCtrl+O")); file_menu->Append(MENU_ID_ROPEN, _("重新打开(&R)")); file_menu->Append(MENU_ID_CLOSE, _("关闭(&C)")); file_menu->Append(MENU_ID_HISTORY, _("历史记录(&H)")); file_menu->AppendSeparator(); file_menu->Append(MENU_ID_INFO, _("信息(&I)")); file_menu->AppendSeparator(); file_menu->Append(MENU_ID_EXIT, _("退出(&X)/tAlt+Q")); wxMenu* view_menu = new wxMenu; view_menu->AppendCheckItem(MENU_ID_TOOL, _("工具栏(&T)")); view_menu->AppendCheckItem(MENU_ID_PREVIEW, _("预览(&P)")); view_menu->AppendSeparator(); view_menu->AppendRadioItem(MENU_ID_BIGICON, _("大图标(&G)")); view_menu->AppendRadioItem(MENU_ID_SMALLICON, _("小图标(&M)")); view_menu->AppendRadioItem(MENU_ID_LISTICON, _("列表(&L)")); view_menu->AppendRadioItem(MENU_ID_DETAILICON, _("详细资料(&D)")); wxMenu* operate_menu = new wxMenu; operate_menu->Append(MENU_ID_OPENFILE, _("打开(&O)")); operate_menu->Append(MENU_ID_OPENMODE, _("打开方式...(&W)")); operate_menu->AppendSeparator(); operate_menu->Append(MENU_ID_UNZIP, _("解压缩(&E)/tCtrl+E")); operate_menu->Append(MENU_ID_RENAME, _("重命名(&R)/tF2")); operate_menu->Append(MENU_ID_DELETE, _("删除(&D)/tDelete")); operate_menu->AppendSeparator(); operate_menu->Append(MENU_ID_ATTRIBUTE, _("属性(&A)/tAlt+Enter")); operate_menu->Append(MENU_ID_NEWFOLDER, _("新建文件夹(&N)")); operate_menu->Append(MENU_ID_ADDFILE, _("添加文件(&A)")); operate_menu->Append(MENU_ID_ADDFOLDER, _("添加文件夹(&T)")); operate_menu->AppendSeparator(); operate_menu->Append(MENU_ID_SELECTLISTFILE, _("选择列表文件(&L)")); operate_menu->Append(MENU_ID_UNZIPALL, _("全部解压(&X)")); operate_menu->Append(MENU_ID_REZIP, _("重新压缩(&C)")); wxMenu* options_menu = new wxMenu; options_menu->Append(MENU_ID_FILETYPEOPTION, _("文件类型选项(&O)/tF6")); wxMenu* language_menu = new wxMenu; language_menu->AppendRadioItem(MENU_ID_ENGLISH, _("&English")); language_menu->AppendRadioItem(MENU_ID_CHINESE, _("&Chinese")); language_menu->AppendRadioItem(MENU_ID_RUSSIAN, _("&Russian")); options_menu->Append(MENU_ID_LANGUAGE, _("语言"), language_menu); options_menu->AppendSeparator(); options_menu->Append(MENU_ID_SETDEFAULT, _("重置界面(&R)")); options_menu->Append(MENU_ID_SETTING, _("界面设置...(&S)")); wxMenu* help_menu = new wxMenu; help_menu->Append(MENU_ID_ABOUT, _("关于...(&A)")); help_menu->Append(MENU_ID_TEST, _("测试之用...(&T)")); mb->Append(file_menu, _("文件(&F)")); mb->Append(view_menu, _("查看(&V)")); mb->Append(operate_menu, _("操作(&O)")); mb->Append(options_menu, _("选项(&P)")); mb->Append(help_menu, _("帮助(&H)")); SetMenuBar(mb); // 创建状态栏并加载显示 CreateStatusBar(); GetStatusBar()->SetStatusText(_("就绪...")); // 设置窗体本身最小大小 SetMinSize(wxSize(400,300)); // 界面上添加Aui元素 wxAuiToolBarItemArray prepend_items; wxAuiToolBarItemArray append_items; wxAuiToolBarItem item; item.SetKind(wxITEM_SEPARATOR); append_items.Add(item); item.SetKind(wxITEM_NORMAL); item.SetId(ID_CustomizeToolbar); item.SetLabel(_("自定义工具栏...")); append_items.Add(item); // 创建aui工具栏 wxAuiToolBar* common_toolbar = new wxAuiToolBar(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_OVERFLOW | wxAUI_TB_TEXT | wxAUI_TB_HORZ_TEXT); common_toolbar->SetToolBitmapSize(wxSize(16,16)); wxBitmap common_toolbar_bmp1 = wxArtProvider::GetBitmap(wxART_NEW, wxART_OTHER, wxSize(16,16)); common_toolbar->AddTool(ID_DropDownToolbarItem, wxT("新建"), common_toolbar_bmp1); wxBitmap common_toolbar_bmp2 = wxArtProvider::GetBitmap(wxART_FOLDER_OPEN, wxART_OTHER, wxSize(16,16)); common_toolbar->AddTool(MENU_ID_OPEN, wxT("打开"), common_toolbar_bmp2); common_toolbar->AddSeparator(); wxBitmap common_toolbar_bmp3 = wxArtProvider::GetBitmap(wxART_INFORMATION, wxART_OTHER, wxSize(16,16)); common_toolbar->AddTool(MENU_ID_INFO, wxT("信息"), common_toolbar_bmp3); common_toolbar->AddSeparator(); wxBitmap common_toolbar_bmp4 = wxArtProvider::GetBitmap(wxART_QUESTION, wxART_OTHER, wxSize(16,16)); common_toolbar->AddTool(MENU_ID_ABOUT, wxT("?"), common_toolbar_bmp4); common_toolbar->AddSeparator(); wxBitmap common_toolbar_bmp5 = wxArtProvider::GetBitmap(wxART_MISSING_IMAGE, wxART_OTHER, wxSize(16,16)); common_toolbar->AddTool(MENU_ID_UNZIP, wxT("解压缩"), common_toolbar_bmp5); wxBitmap common_toolbar_bmp6 = wxArtProvider::GetBitmap(wxART_CROSS_MARK, wxART_OTHER, wxSize(16,16)); common_toolbar->AddTool(MENU_ID_DELETE, wxT("删除"), common_toolbar_bmp6); common_toolbar->AddSeparator(); wxBitmap common_toolbar_bmp7 = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16)); common_toolbar->AddTool(MENU_ID_ADDFILE, wxT("添加文件"), common_toolbar_bmp7); wxBitmap common_toolbar_bmp8 = wxArtProvider::GetBitmap(wxART_NEW_DIR, wxART_OTHER, wxSize(16,16)); common_toolbar->AddTool(MENU_ID_ADDFOLDER, wxT("添加文件夹"), common_toolbar_bmp8); common_toolbar->AddSeparator(); wxBitmap common_toolbar_bmp9 = wxArtProvider::GetBitmap(wxART_REMOVABLE, wxART_OTHER, wxSize(16,16)); common_toolbar->AddTool(MENU_ID_BIGICON, wxT("大图标"), common_toolbar_bmp9); wxBitmap common_toolbar_bmp10 = wxArtProvider::GetBitmap(wxART_TIP, wxART_OTHER, wxSize(16,16)); common_toolbar->AddTool(MENU_ID_SMALLICON, wxT("小图标"), common_toolbar_bmp10); wxBitmap common_toolbar_bmp11 = wxArtProvider::GetBitmap(wxART_LIST_VIEW, wxART_OTHER, wxSize(16,16)); common_toolbar->AddTool(MENU_ID_LISTICON, wxT("列表"), common_toolbar_bmp11); wxBitmap common_toolbar_bmp12 = wxArtProvider::GetBitmap(wxART_REPORT_VIEW, wxART_OTHER, wxSize(16,16)); common_toolbar->AddTool(MENU_ID_DETAILICON, wxT("详细资料"), common_toolbar_bmp12); common_toolbar->AddSeparator(); common_toolbar->SetToolDropDown(ID_DropDownToolbarItem, true); common_toolbar->SetCustomOverflowItems(prepend_items, append_items); common_toolbar->Realize(); ////////////////////////////////////////////////////////////////////////// // 在管理器中添加面板 // 添加左边目录树 m_mgr.AddPane(CreateTreeCtrl( wxT( "成绩表" ), NULL ), wxAuiPaneInfo(). Name(wxT("dir_tree")).Caption(wxT("PKG目录列表")). Left().Layer(1).Position(1). CloseButton(false).MaximizeButton(false)); // 添加文件预览框 m_mgr.AddPane(CreateTextCtrl(wxT("")), wxAuiPaneInfo(). Name(wxT("file_content")).Caption(wxT("内容预览...")). Bottom().Layer(1).Position(1)); // 添加设置对话框 m_mgr.AddPane(new SettingsPanel(this,this), wxAuiPaneInfo(). Name(wxT("settings")).Caption(wxT("界面显示设置")). Dockable(false).Float().Hide()); // 创建一些中心panes m_mgr.AddPane(CreateNotebook(), wxAuiPaneInfo().Name(wxT("notebook_content")). CenterPane().PaneBorder(false)); // 添加常用工具栏到窗体顶部 m_mgr.AddPane(common_toolbar, wxAuiPaneInfo(). Name(wxT("common_toolbar")).Caption(wxT("常用工具栏")). ToolbarPane().Top().Row(2). LeftDockable(false).RightDockable(false)); // 添加一个搜索工具条 m_mgr.AddPane(new wxSearchCtrl(this, -1, wxEmptyString, wxDefaultPosition, wxSize(150, -1), wxTE_PROCESS_ENTER ), wxAuiPaneInfo(). Name(wxT("search_toolbar")).Caption(wxT("查找工具栏")). ToolbarPane().Top().Row(2).Position(1). LeftDockable(false).RightDockable(false)); // 选择性的隐藏部分栏目 wxString perspective_all = m_mgr.SavePerspective(); int i, count; wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes(); // 隐藏所有非工具栏 for (i = 0, count = (int )all_panes.GetCount(); i < count; ++i) if (!all_panes.Item(i).IsToolbar()) all_panes.Item(i).Hide(); m_mgr.GetPane(wxT("common_toolbar")).Hide(); m_mgr.GetPane(wxT("search_toolbar")).Hide(); // 打开目录树和内容显示 m_mgr.GetPane(wxT("dir_tree")).Show().Left().Layer(0).Row(0).Position(0); m_mgr.GetPane(wxT("notebook_content")).Show(); wxString perspective_default = m_mgr.SavePerspective(); m_perspectives.Add(perspective_default); m_perspectives.Add(perspective_all); // 查看菜单,工具栏和预览标志 flag_tool = true; flag_preview = true; // 提交wxAuiManager的所有更新 m_mgr.Update(); } MyFrame::~MyFrame() { m_mgr.UnInit(); delete m_imageListNormal; delete m_imageListSmall; } wxAuiDockArt* MyFrame::GetDockArt() { return m_mgr.GetArtProvider(); } void MyFrame::DoUpdate() { m_mgr.Update(); } void MyFrame::OnEraseBackground(wxEraseEvent& event) { event.Skip(); } void MyFrame::OnSize(wxSizeEvent& event) { event.Skip(); } void MyFrame::OnSettings(wxCommandEvent& WXUNUSED(evt)) { // 显示浮动的设置面板 wxAuiPaneInfo& floating_pane = m_mgr.GetPane(wxT("settings")).Float().Show(); if (floating_pane.floating_pos == wxDefaultPosition) floating_pane.FloatingPosition(GetStartPosition()); m_mgr.Update(); } ////////////////////////////////////////////////////////////////////////// // 添加工具栏自定义对话框 void MyFrame::OnCustomizeToolbar(wxCommandEvent& WXUNUSED(evt)) { wxMessageBox(_("此处处理自定义工具栏事件.")); } ////////////////////////////////////////////////////////////////////////// // 查看,显示工具栏或者预览编辑框 void MyFrame::OnShow(wxCommandEvent& evt) { wxString perspective_all = m_mgr.SavePerspective(); wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes(); switch (evt.GetId()) { case MENU_ID_TOOL: if (flag_tool) { m_mgr.GetPane(wxT("common_toolbar")).Show(); m_mgr.GetPane(wxT("search_toolbar")).Show(); flag_tool = false; } else { m_mgr.GetPane(wxT("common_toolbar")).Hide(); m_mgr.GetPane(wxT("search_toolbar")).Hide(); flag_tool = true; } break; case MENU_ID_PREVIEW: if (flag_preview) { m_mgr.GetPane(wxT("file_content")).Show(); flag_preview = false; } else { m_mgr.GetPane(wxT("file_content")).Hide(); flag_preview = true; } break; } wxString perspective_default = m_mgr.SavePerspective(); m_perspectives.Add(perspective_default); m_perspectives.Add(perspective_all); // 提交wxAuiManager的所有更新 m_mgr.Update(); } ////////////////////////////////////////////////////////////////////////// // 隐藏所有栏目,测试用 void MyFrame::OnHide(wxCommandEvent& evt) { wxString perspective_all = m_mgr.SavePerspective(); int i, count; wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes(); for (i = 0, count = (int )all_panes.GetCount(); i < count; ++i) all_panes.Item(i).Hide(); wxString perspective_default = m_mgr.SavePerspective(); m_perspectives.Add(perspective_default); m_perspectives.Add(perspective_all); // 提交wxAuiManager的所有更新 m_mgr.Update(); } ////////////////////////////////////////////////////////////////////////// // 重置界面 void MyFrame::OnRestorePerspective(wxCommandEvent& evt) { m_mgr.LoadPerspective(m_perspectives.Item(evt.GetId() - MENU_ID_SETDEFAULT)); } wxPoint MyFrame::GetStartPosition() { static int x = 0; x += 20; wxPoint pt = ClientToScreen(wxPoint(0,0)); return wxPoint(pt.x + x, pt.y + x); } ////////////////////////////////////////////////////////////////////////// // 下拉式工具栏 void MyFrame::OnDropDownToolbarItem(wxAuiToolBarEvent& evt) { if (evt.IsDropDownClicked()) { wxAuiToolBar* tb = static_cast<wxAuiToolBar*>(evt.GetEventObject()); tb->SetToolSticky(evt.GetId(), true); // 创建工具栏下拉菜单 wxMenu menuPopup; wxBitmap bmp1 = wxArtProvider::GetBitmap(wxART_ADD_BOOKMARK, wxART_OTHER, wxSize(16,16)); wxMenuItem* m1 = new wxMenuItem(&menuPopup, 101, _("PKG文件")); m1->SetBitmap(bmp1); menuPopup.Append(m1); wxBitmap bmp2 = wxArtProvider::GetBitmap(wxART_NEW_DIR, wxART_OTHER, wxSize(16,16)); wxMenuItem* m2 = new wxMenuItem(&menuPopup, 101, _("文件夹")); m2->SetBitmap(bmp2); menuPopup.Append(m2); wxBitmap bmp3 = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16)); wxMenuItem* m3 = new wxMenuItem(&menuPopup, 101, _("文件")); m3->SetBitmap(bmp3); menuPopup.Append(m3); wxBitmap bmp4 = wxArtProvider::GetBitmap(wxART_QUESTION, wxART_OTHER, wxSize(16,16)); wxMenuItem* m4 = new wxMenuItem(&menuPopup, 101, _("其他")); m4->SetBitmap(bmp4); menuPopup.Append(m4); // 将菜单同按钮连在一起 wxRect rect = tb->GetToolRect(evt.GetId()); wxPoint pt = tb->ClientToScreen(rect.GetBottomLeft()); pt = ScreenToClient(pt); PopupMenu(&menuPopup, pt); // 确保按钮是不可动的 tb->SetToolSticky(evt.GetId(), false); } } ////////////////////////////////////////////////////////////////////////// // 程序退出 void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event)) { Close(true); } ////////////////////////////////////////////////////////////////////////// // 关于 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) { wxMessageBox(_("文件打包管理器/n对PKG资源包进行综合管理./n(c) Copyright 2009-2010, R.L Studio"), _("关于本程序"), wxOK, this); } ////////////////////////////////////////////////////////////////////////// // 创建文件内容显示文本框 wxTextCtrl* MyFrame::CreateTextCtrl(const wxString& ctrl_text) { static int n = 0; wxString text; if (ctrl_text.Length() > 0) text = ctrl_text; else text.Printf(wxT("没有文件显示..."), ++n); return new wxTextCtrl(this,wxID_ANY, text, wxPoint(0,0), wxSize(150,90), wxNO_BORDER | wxTE_MULTILINE); } ////////////////////////////////////////////////////////////////////////// // 创建树形目录控件 wxTreeCtrl* MyFrame::CreateTreeCtrl( wxString StrPath, wxTreeItemId faItem ) { tree = new wxTreeCtrl(this, wxID_ANY, wxPoint(0,0), wxSize(160,250), wxTR_DEFAULT_STYLE | wxNO_BORDER); wxImageList* imglist = new wxImageList(16, 16, true, 2); imglist->Add(wxArtProvider::GetBitmap(wxART_FOLDER, wxART_OTHER, wxSize(16,16))); imglist->Add(wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16))); tree->AssignImageList(imglist); wxTreeItemId root = tree->AddRoot(wxT("成绩表"), 0);// 添加根节点 wxDir OneFile( wxT( "./成绩表" ) ); wxString FName, DirName; bool BeWorking; wxTreeItemId NewItem; DirName = StrPath + wxT( "//*.*" ); if ( !OneFile.IsOpened() ) { // return; } wxString filename; wxFileName *ffilename; BeWorking = OneFile.GetFirst( &filename ); while ( BeWorking ) { wxString fullname = OneFile.GetName() + wxT( "//" ) + filename; ffilename = new wxFileName( fullname, wxEmptyString ); if ( ffilename->IsDir() ) { NewItem = tree->AppendItem(root, filename, 0); } BeWorking = OneFile.GetNext(&filename); } tree->Expand(root); return tree; } ////////////////////////////////////////////////////////////////////////// // 创建文件目录列表框 wxListCtrl* MyFrame::CreateListCtrl( wxWindow* parent, long style ) { if (!parent) parent = this; switch ( style ) { case wxLC_ICON: m_listCtrl = new wxListCtrl(parent, wxID_ANY, wxDefaultPosition, wxSize(400,300), wxLC_ICON); m_listCtrl->SetImageList(m_imageListNormal, wxIMAGE_LIST_NORMAL); m_listCtrl->SetImageList(m_imageListSmall, wxIMAGE_LIST_SMALL); for ( int i = 0; i < NUM_ICONS; i++ ) { int image = false ? 0 : i; m_listCtrl->InsertItem(i, wxString::Format(_T("文件 %d"), i), image); } break; case wxLC_SMALL_ICON: m_listCtrl = new wxListCtrl(parent, wxID_ANY, wxDefaultPosition, wxSize(400,300),wxLC_SMALL_ICON); m_listCtrl->SetImageList(m_imageListNormal, wxIMAGE_LIST_NORMAL); m_listCtrl->SetImageList(m_imageListSmall, wxIMAGE_LIST_SMALL); for ( int i = 0; i < NUM_ICONS; i++ ) { int image = true ? 0 : i; m_listCtrl->InsertItem(i, wxString::Format(_T("文件 %d"), i),image); } break; case wxLC_LIST: m_listCtrl = new wxListCtrl(parent, wxID_ANY, wxDefaultPosition, wxSize(400,300),wxLC_LIST); m_listCtrl->SetImageList(m_imageListNormal, wxIMAGE_LIST_NORMAL); m_listCtrl->SetImageList(m_imageListSmall, wxIMAGE_LIST_SMALL); for ( int i = 0; i < NUM_ITEMS; i++ ) { int image = true ? 0 : i; m_listCtrl->InsertItem(i, wxString::Format(_T("文件 %d"), i),image); } break; case wxLC_REPORT: m_listCtrl = new wxListCtrl(parent, wxID_ANY, wxDefaultPosition, wxSize(400,300),wxLC_REPORT); m_listCtrl->SetImageList(m_imageListSmall, wxIMAGE_LIST_SMALL); wxListItem itemCol; itemCol.SetText(_T("文件名")); itemCol.SetImage(-1); m_listCtrl->InsertColumn(0, itemCol); itemCol.SetText(_T("文件大小")); itemCol.SetAlign(wxLIST_FORMAT_CENTRE); m_listCtrl->InsertColumn(1, itemCol); itemCol.SetText(_T("属性")); itemCol.SetAlign(wxLIST_FORMAT_RIGHT); m_listCtrl->InsertColumn(2, itemCol); // 临时隐藏,加快速度 m_listCtrl->Hide(); for ( int i = 0; i < NUM_ITEMS; i++ ) { wxString buf; buf.Printf(_T("这是第 %d 项"), i); long tmp = m_listCtrl->InsertItem(i, buf, 0); m_listCtrl->SetItemData(tmp, i); buf.Printf(_T("第 1 列, 第 %d 项"), i); m_listCtrl->SetItem(tmp, 1, buf); buf.Printf(_T("第 2 列, 第 %d 项"), i); m_listCtrl->SetItem(tmp, 2, buf); } m_listCtrl->SetColumnWidth( 0, wxLIST_AUTOSIZE ); m_listCtrl->SetColumnWidth( 1, wxLIST_AUTOSIZE ); m_listCtrl->SetColumnWidth( 2, wxLIST_AUTOSIZE ); m_listCtrl->Show(); break; //default: // break; } return m_listCtrl; } ////////////////////////////////////////////////////////////////////////// // 创建AuiNotebook面板,用以加载wxListCtrl wxAuiNotebook* MyFrame::CreateNotebook() { wxSize client_size = GetClientSize(); ctrl = new wxAuiNotebook(this, wxID_ANY, wxPoint(client_size.x, client_size.y), wxSize(430,200), m_notebook_style & wxAUI_NB_CLOSE_BUTTON ); wxBitmap page_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16)); ctrl->AddPage(CreateListCtrl(ctrl,wxLC_SMALL_ICON), wxT("PKG目录文件列表") , false, page_bmp); return ctrl; } ////////////////////////////////////////////////////////////////////////// // 控制列表框显示样式改变 void MyFrame::OnChangeListStyle(wxCommandEvent& evt) { wxSize client_size = GetClientSize(); delete ctrl; ctrl = new wxAuiNotebook(this, wxID_ANY, wxPoint(client_size.x, client_size.y), wxSize(430,200), m_notebook_style & wxAUI_NB_CLOSE_BUTTON ); wxBitmap page_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16)); switch (evt.GetId()) { case MENU_ID_BIGICON: ctrl->AddPage(CreateListCtrl(ctrl, wxLC_ICON), wxT("PKG目录文件列表") , false, page_bmp); break; case MENU_ID_SMALLICON: ctrl->AddPage(CreateListCtrl(ctrl, wxLC_SMALL_ICON), wxT("PKG目录文件列表") , false, page_bmp); break; case MENU_ID_LISTICON: ctrl->AddPage(CreateListCtrl(ctrl, wxLC_LIST), wxT("PKG目录文件列表") , false, page_bmp); break; case MENU_ID_DETAILICON: ctrl->AddPage(CreateListCtrl(ctrl, wxLC_REPORT), wxT("PKG目录文件列表") , false, page_bmp); break; default: break; } m_mgr.AddPane(ctrl, wxAuiPaneInfo().Name(wxT("notebook1_content")).CenterPane().PaneBorder(false)); m_mgr.GetPane(wxT("notebook1_content")).Show(); } ////////////////////////////////////////////////////////////////////////// // 窗体上显示右键菜单 void MyFrame::OnContextMenu(wxContextMenuEvent& event) { wxPoint point = event.GetPosition(); // If from keyboard if (point.x == -1 && point.y == -1) { wxSize size = GetSize(); point.x = size.x / 2; point.y = size.y / 2; } else { point = ScreenToClient(point); } ShowContextMenu(point); } ////////////////////////////////////////////////////////////////////////// // 计算右键菜单显示坐标位置 void MyFrame::ShowContextMenu(const wxPoint& pos) { wxMenu menu; menu.Append(MENU_ID_ABOUT, _T("&About")); menu.AppendSeparator(); menu.Append(MENU_ID_EXIT, _T("E&xit")); PopupMenu(&menu, pos.x, pos.y); } ////////////////////////////////////////////////////////////////////////// // 打开文件 void MyFrame::OnOpen(wxCommandEvent& evt) { wxString caption = wxT( "打开PKG文件" ); wxString wildcard = wxT( "PKG 文件(*.pkg)|*.pkg|所有文件(*.*)|*.*" ); wxString defaultDir = wxT("./"); wxString defaultFilename = wxEmptyString; wxFileDialog dialog( this, caption, defaultDir, defaultFilename, wildcard, wxOPEN | wxFD_FILE_MUST_EXIST); if ( dialog.ShowModal() == wxID_OK ) { wxString path = dialog.GetPath(); wxMessageBox(path); int filterIndex = dialog.GetFilterIndex(); } } ////////////////////////////////////////////////////////////////////////// // 添加文件,可以多选添加所有文件 void MyFrame::OnAddFile(wxCommandEvent& evt) { wxString caption = wxT( "添加文件" ); wxString wildcard = wxT( "所有文件(*.*)|*.*" ); wxString defaultDir = wxT("./"); wxString defaultFilename = wxEmptyString; wxFileDialog dialog( this, caption, defaultDir, defaultFilename, wildcard, wxOPEN | wxMULTIPLE | wxFD_FILE_MUST_EXIST); if ( dialog.ShowModal() == wxID_OK ) { wxArrayString paths; dialog.GetPaths(paths); size_t count = paths.GetCount(); for ( int i = 0; i < (int )count ; i++ ) { wxMessageBox(paths.Item( i )); } int filterIndex = dialog.GetFilterIndex(); } } ////////////////////////////////////////////////////////////////////////// // 通过选择文件夹递归的向pkg文件中添加文件 void MyFrame::OnAddFolder(wxCommandEvent& evt) { wxString defaultPath = wxT("./"); wxDirDialog dialog( this, wxT("请在下面选择或者输入您要添加文件夹:"), defaultPath, wxDD_DIR_MUST_EXIST); if ( dialog.ShowModal() == wxID_OK ) { wxString path = dialog.GetPath(); wxMessageBox(path); } }

 

四、效果图

 

文件打包管理器UI设计_第1张图片

你可能感兴趣的:(UI,File,button,border,menu,wildcard)