📄 fl_demo2.cpp
字号:
/////////////////////////////////////////////////////////////////////////////
// Name: No names yet.
// Purpose: Contrib. demo
// Author: Aleksandras Gluchovas
// Modified by: Sebastian Haase (June 21, 2001)
// Created: 04/11/98
// RCS-ID: $Id: fl_demo2.cpp,v 1.11 2005/09/23 12:47:19 MR Exp $
// Copyright: (c) Aleksandras Gluchovas
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
// wxWidgets headers.
#include "wx/treectrl.h"
#include "wx/imaglist.h"
#include "wx/notebook.h"
// fl headers.
#include "wx/fl/controlbar.h"
#include "wx/fl/rowlayoutpl.h"
#include "wx/fl/antiflickpl.h"
#include "wx/fl/bardragpl.h"
#include "wx/fl/cbcustom.h"
#include "wx/fl/rowdragpl.h"
// some extra fl plugins.
#include "wx/fl/barhintspl.h"
#include "wx/fl/hintanimpl.h"
#include "wx/fl/dyntbar.h"
#include "wx/fl/dyntbarhnd.h" // fl-dimension-handler for dynamic toolbar
#include "fl_demo2.h"
/***** Implementation for class MyApp *****/
// Create a new application object
IMPLEMENT_APP (MyApp)
// `Main program' equivalent, creating windows and returning main app frame
bool MyApp::OnInit(void)
{
// Create the main frame window
MyFrame *frame = new MyFrame(NULL, _("wxWidgets 2.0 wxFrameLayout demo"), 50, 50, 650, 540);
// Give it an icon
#ifdef __WINDOWS__
frame->SetIcon(wxIcon(wxT("mondrian")));
#endif
#ifdef __X__
frame->SetIcon(wxIcon(wxT("aiai.xbm")));
#endif
// Make a menubar
wxMenu *file_menu = new wxMenu;
wxMenu *active_menu = new wxMenu;
file_menu->Append( ID_LOAD, _("&Load layouts") );
file_menu->Append( ID_STORE, _("&Store layouts") );
file_menu->AppendSeparator();
file_menu->Append( ID_AUTOSAVE, _("&Auto Save Layouts"), _("save layouts on exit"), wxITEM_CHECK );
file_menu->AppendSeparator();
file_menu->Append(MINIMAL_ABOUT, _("A&bout !"));
file_menu->Append(MINIMAL_QUIT, _("E&xit\tTab"));
//active_menu->Append( ID_SETTINGS, _("&Settings...\tCtrl") );
//active_menu->AppendSeparator();
active_menu->Append( ID_REMOVE, _("&Remove Active") );
active_menu->Append( ID_REMOVEALL, _("Remove &All") );
active_menu->Append( ID_RECREATE, _("Re&create") );
active_menu->AppendSeparator();
active_menu->Append( ID_FIRST, _("Activate f&irst layout \tF1"), _("activate it"), wxITEM_CHECK );
active_menu->Append( ID_SECOND, _("Activate &second layout\tF2"), _("activate it"), wxITEM_CHECK );
active_menu->Append( ID_THIRD, _("Activate &third layout\tF3"), _("activate it"), wxITEM_CHECK );
wxMenuBar *menu_bar = new wxMenuBar;
menu_bar->Append(file_menu, _("&File"));
menu_bar->Append(active_menu, _("Active &Layout"));
#if wxUSE_STATUSBAR
frame->CreateStatusBar(3);
#endif // wxUSE_STATUSBAR
frame->SetMenuBar(menu_bar);
frame->SyncMenuBarItems();
// Show the frame
frame->Show(true);
SetTopWindow(frame);
return true;
}
MyFrame::~MyFrame()
{
// frame-layouts is not a windows (objects), thus should
// be cleaned up manually
for( int i = 0; i != MAX_LAYOUTS; ++i )
{
if ( mLayouts[i] )
delete mLayouts[i];
}
if ( mpNestedLayout )
delete mpNestedLayout;
if ( mpAboutBoxLayout )
delete mpAboutBoxLayout;
}
/***** Implementation for class MyFrame *****/
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU( MINIMAL_QUIT, MyFrame::OnQuit )
EVT_MENU( MINIMAL_ABOUT, MyFrame::OnAbout )
EVT_MENU( ID_LOAD, MyFrame::OnLoad )
EVT_MENU( ID_STORE, MyFrame::OnStore )
EVT_MENU( ID_AUTOSAVE, MyFrame::OnAutoSave )
//EVT_MENU( ID_SETTINGS, MyFrame::OnSettings )
EVT_MENU( ID_REMOVE, MyFrame::OnRemove )
EVT_MENU( ID_REMOVEALL, MyFrame::OnRemoveAll )
EVT_MENU( ID_RECREATE, MyFrame::OnRecreate )
EVT_MENU( ID_FIRST, MyFrame::OnFirst )
EVT_MENU( ID_SECOND, MyFrame::OnSecond )
EVT_MENU( ID_THIRD, MyFrame::OnThird )
EVT_BUTTON( ID_SAY_ITSOK, MyFrame::OnSayItsOk )
EVT_BUTTON( ID_BTN_YES, MyFrame::OnBtnYes )
EVT_BUTTON( ID_BTN_NO, MyFrame::OnBtnNo )
EVT_BUTTON( ID_BTN_ESC, MyFrame::OnBtnEsc )
EVT_CHAR_HOOK( MyFrame::OnChar )
END_EVENT_TABLE()
// My frame constructor
MyFrame::MyFrame(wxFrame *frame, const wxChar *title, int x, int y, int w, int h)
: wxFrame(frame, wxID_ANY, title, wxPoint(x, y), wxSize(w, h)),
mpNestedLayout( NULL ),
mpAboutBoxLayout( NULL ),
mActiveLayoutNo( FIRST_LAYOUT ),
mAutoSave( true ),
mSavedAlready( false ),
mpClntWindow( NULL ),
mImageList( 16,16, false, 2 )
{
int i;
mpInternalFrm = (wxPanel*)this;
mAboutBox.Create( this, wxID_ANY, _T("About box in wxWidgets style..."),
wxDefaultPosition,
wxSize( 385,220),
wxDEFAULT_DIALOG_STYLE | wxTAB_TRAVERSAL );
for( i = 0; i != MAX_LAYOUTS; ++i )
mLayouts[i] = NULL;
// image-list is one of the few objects which
// currently cannot be serialized, create it first
// and use it as initial reference (IR)
wxBitmap bmp1,bmp2;
if ( wxFileExists( wxString(wxT(BMP_DIR)) + wxT("folder_icon.bmp") ) )
bmp1.LoadFile( wxString(wxT(BMP_DIR)) + wxT("folder_icon.bmp"), wxBITMAP_TYPE_BMP );
if ( wxFileExists( wxString(wxT(BMP_DIR)) + wxT("class_icon1.bmp") ) )
bmp2.LoadFile( wxString(wxT(BMP_DIR)) + wxT("class_icon1.bmp"), wxBITMAP_TYPE_BMP );
mImageList.Add( bmp1 );
mImageList.Add( bmp2 );
InitAboutBox();
// create multiple layouts
mpNestedLayout = 0;
mpClntWindow = CreateTxtCtrl(wxT("client window"));
// Create all layouts
for( i = 0; i != MAX_LAYOUTS; ++i )
{
CreateLayout( i );
}
// hide others
for( i = SECOND_LAYOUT; i != MAX_LAYOUTS; ++i )
{
mLayouts[i]->HideBarWindows();
}
// activate first one
mLayouts[FIRST_LAYOUT]->Activate();
mActiveLayoutNo = FIRST_LAYOUT;
}
/*** event handlers ***/
bool MyFrame::OnClose(void)
{
// USEFUL TRICK:: avoids flickering of application's frame
// when closing NN windows on exit:
Show(false);
if ( (mAutoSave && mSavedAlready) || !mAutoSave )
{
}
else
{
wxCommandEvent evt;
OnStore(evt);
}
mAboutBox.Destroy();
Destroy();
return true;
}
void MyFrame::OnLoad( wxCommandEvent& WXUNUSED(event) )
{
wxMessageBox(_("Hey - you found a BIG question-mark !!"));
}
void MyFrame::OnStore( wxCommandEvent& WXUNUSED(event) )
{
wxMessageBox(_("Hey - you found another BIG question-mark !!"));
}
void MyFrame::OnAutoSave( wxCommandEvent& WXUNUSED(event) )
{
mAutoSave = !mAutoSave;
wxCommandEvent evt;
OnStore(evt);
SyncMenuBarItems();
}
void MyFrame::OnRemove( wxCommandEvent& WXUNUSED(event) )
{
RemoveLayout( mActiveLayoutNo );
Refresh();
}
void MyFrame::OnRemoveAll( wxCommandEvent& WXUNUSED(event) )
{
for( int i = 0; i != MAX_LAYOUTS; ++i )
{
RemoveLayout( i );
}
Refresh();
}
void MyFrame::OnRecreate( wxCommandEvent& event )
{
OnRemove( event ); // first destroy active layout
CreateLayout( mActiveLayoutNo );
mLayouts[mActiveLayoutNo]->Activate();
}
void MyFrame::OnFirst( wxCommandEvent& WXUNUSED(event) )
{
ActivateLayout( FIRST_LAYOUT );
}
void MyFrame::OnSecond( wxCommandEvent& WXUNUSED(event) )
{
ActivateLayout( SECOND_LAYOUT );
}
void MyFrame::OnThird( wxCommandEvent& WXUNUSED(event) )
{
ActivateLayout( THIRD_LAYOUT );
}
void MyFrame::OnQuit( wxCommandEvent& WXUNUSED(event) )
{
// USEFUL TRICK:: avoids flickering of application's frame
// when closing NN windows on exit:
Show(false);
if ( (mAutoSave && mSavedAlready) || !mAutoSave )
{
}
else
{
wxCommandEvent evt;
OnStore(evt);
}
Destroy();
}
void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) )
{
wxFont font;
#ifdef __WXMSW__
font.SetFaceName(wxT("MS Sans Serif"));
#else
font.SetFamily( wxSWISS );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -