Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /////////////////////////////////////////////////////////////////////////////
- // Name: minimal.cpp
- // Purpose: Minimal wxWidgets sample
- // Author: Julian Smart
- // Modified by: fioresoft.net
- // Created: 04/01/98
- // Copyright: (c) Julian Smart
- // Licence: wxWindows licence
- /////////////////////////////////////////////////////////////////////////////
- // ============================================================================
- // declarations
- // ============================================================================
- // ----------------------------------------------------------------------------
- // headers
- // ----------------------------------------------------------------------------
- // For compilers that support precompilation, includes "wx/wx.h".
- #include "wx/wxprec.h"
- #ifdef __BORLANDC__
- #pragma hdrstop
- #endif
- // for all others, include the necessary headers (this file is usually all you
- // need because it includes almost all "standard" wxWidgets headers)
- #ifndef WX_PRECOMP
- #include "wx/wx.h"
- #endif
- #include "wx/aui/tabmdi.h"
- #include "wx/splitter.h"
- #include "bitmaps/new.xpm"
- #include "bitmaps/open.xpm"
- #include "bitmaps/save.xpm"
- #include "bitmaps/bold.xpm"
- #include "bitmaps/italic.xpm"
- #include "bitmaps/underline.xpm"
- #ifdef wxUSE_TOOLBARS
- #undef wxUSE_TOOLBARS
- #endif
- // ----------------------------------------------------------------------------
- // resources
- // ----------------------------------------------------------------------------
- // the application icon (under Windows it is in resources and even
- // though we could still include the XPM here it would be unused)
- #ifndef wxHAS_IMAGES_IN_RESOURCES
- #include "../sample.xpm"
- #endif
- // ----------------------------------------------------------------------------
- // private classes
- // ----------------------------------------------------------------------------
- // Define a new application type, each program should derive a class from wxApp
- class MyApp : public wxApp
- {
- public:
- // override base class virtuals
- // ----------------------------
- // this one is called on application startup and is a good place for the app
- // initialization (doing it here and not in the ctor allows to have an error
- // return: if OnInit() returns false, the application terminates)
- virtual bool OnInit() wxOVERRIDE;
- };
- class MyChild : public wxAuiMDIChildFrame
- {
- public:
- MyChild(wxAuiMDIParentFrame *parent,const wxString& title) :wxAuiMDIChildFrame(parent, wxID_ANY, title,wxDefaultPosition,
- wxDefaultSize,wxDEFAULT_FRAME_STYLE)
- {
- wxTextCtrl* text = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE);
- }
- };
- // Define a new frame type: this is going to be our main frame
- class MyFrame : public wxAuiMDIParentFrame
- {
- wxSplitterWindow* hsplitter;
- public:
- // ctor(s)
- MyFrame(const wxString& title);
- // event handlers (these functions should _not_ be virtual)
- void OnQuit(wxCommandEvent& event);
- void OnAbout(wxCommandEvent& event);
- void OnNew(wxCommandEvent& event);
- void OnCascade(wxCommandEvent& event);
- void OnTile(wxCommandEvent& event);
- void OnClose(wxCommandEvent& event);
- void OnCloseAll(wxCommandEvent& event);
- void OnFrameClose(wxCloseEvent& event);
- void OnSize(wxSizeEvent& event);
- private:
- // any class wishing to process wxWidgets events must use this macro
- wxDECLARE_EVENT_TABLE();
- };
- // ----------------------------------------------------------------------------
- // constants
- // ----------------------------------------------------------------------------
- // IDs for the controls and the menu commands
- enum
- {
- // menu items
- Minimal_Quit = wxID_EXIT,
- // it is important for the id corresponding to the "About" command to have
- // this standard value as otherwise it won't be handled properly under Mac
- // (where it is special and put into the "Apple" menu)
- Minimal_About = wxID_ABOUT
- };
- // ----------------------------------------------------------------------------
- // event tables and other macros for wxWidgets
- // ----------------------------------------------------------------------------
- // the event tables connect the wxWidgets events with the functions (event
- // handlers) which process them. It can be also done at run-time, but for the
- // simple menu events like this the static method is much simpler.
- wxBEGIN_EVENT_TABLE(MyFrame, wxAuiMDIParentFrame)
- EVT_MENU(Minimal_Quit, MyFrame::OnQuit)
- EVT_MENU(Minimal_About, MyFrame::OnAbout)
- EVT_MENU(wxID_NEW,MyFrame::OnNew)
- EVT_MENU(wxID_MDI_WINDOW_CASCADE,MyFrame::OnCascade)
- EVT_MENU(wxID_MDI_WINDOW_TILE_HORZ,MyFrame::OnTile)
- EVT_MENU(wxID_CLOSE,MyFrame::OnClose)
- EVT_MENU(wxID_CLOSE_ALL,MyFrame::OnCloseAll)
- EVT_CLOSE(MyFrame::OnFrameClose)
- EVT_SIZE(MyFrame::OnSize)
- wxEND_EVENT_TABLE()
- // Create a new application object: this macro will allow wxWidgets to create
- // the application object during program execution (it's better than using a
- // static object for many reasons) and also implements the accessor function
- // wxGetApp() which will return the reference of the right type (i.e. MyApp and
- // not wxApp)
- wxIMPLEMENT_APP(MyApp);
- // ============================================================================
- // implementation
- // ============================================================================
- // ----------------------------------------------------------------------------
- // the application class
- // ----------------------------------------------------------------------------
- // 'Main program' equivalent: the program execution "starts" here
- bool MyApp::OnInit()
- {
- // call the base class initialization method, currently it only parses a
- // few common command-line options but it could be do more in the future
- if ( !wxApp::OnInit() )
- return false;
- // create the main application window
- MyFrame *frame = new MyFrame("Minimal wxWidgets App");
- // and show it (the frames, unlike simple controls, are not shown when
- // created initially)
- frame->Show(true);
- // success: wxApp::OnRun() will be called which will enter the main message
- // loop and the application will run. If we returned false here, the
- // application would exit immediately.
- return true;
- }
- // ----------------------------------------------------------------------------
- // main frame
- // ----------------------------------------------------------------------------
- // frame constructor
- MyFrame::MyFrame(const wxString& title)
- : wxAuiMDIParentFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE),
- hsplitter(nullptr)//,panel(nullptr),edit(nullptr)
- {
- // set the frame icon
- SetIcon(wxICON(sample));
- #if wxUSE_MENUBAR
- // create a menu bar
- wxMenu* fileMenu = new wxMenu;
- // the "About" item should be in the help menu
- wxMenu* helpMenu = new wxMenu;
- helpMenu->Append(Minimal_About, "&About\tF1", "Show about dialog");
- fileMenu->Append(wxID_NEW, wxT("&New"));
- fileMenu->Append(Minimal_Quit, "E&xit\tAlt-X", "Quit this program");
- // now append the freshly created menu to the menu bar...
- wxMenuBar* menuBar = new wxMenuBar();
- menuBar->Append(fileMenu, "&File");
- menuBar->Append(helpMenu, "&Help");
- wxMenu* menu = GetWindowMenu();
- menu->Append(wxID_MDI_WINDOW_TILE_HORZ, wxT("&Tile"));
- menu->Append(wxID_MDI_WINDOW_CASCADE, wxT("&Cascade"));
- // ... and attach this menu bar to the frame
- SetMenuBar(menuBar);
- #else // !wxUSE_MENUBAR
- // If menus are not available add a button to access the about box
- wxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
- wxButton* aboutBtn = new wxButton(this, wxID_ANY, "About...");
- aboutBtn->Bind(wxEVT_BUTTON, &MyFrame::OnAbout, this);
- sizer->Add(aboutBtn, wxSizerFlags().Center());
- SetSizer(sizer);
- #endif // wxUSE_MENUBAR/!wxUSE_MENUBAR
- #if wxUSE_STATUSBAR
- // create a status bar just for fun (by default with 1 pane only)
- CreateStatusBar(2);
- SetStatusText("Welcome to wxWidgets!");
- #endif // wxUSE_STATUSBAR
- #if 0//wxUSE_TOOLBAR
- wxToolBar* tb = CreateToolBar();
- wxBitmap bmpNew(new_xpm);
- wxBitmap bmpOpen(open_xpm);
- wxBitmap bmpSave(save_xpm);
- wxBitmap bmpBold(bold_xpm);
- wxBitmap bmpItalic(italic_xpm);
- wxBitmap bmpUnderline(underline_xpm);
- tb->AddTool(wxID_NEW, wxT("new"), bmpNew, wxT("new file"));
- tb->AddTool(wxID_OPEN, wxT("open"), bmpOpen, wxT("open file"));
- tb->AddTool(wxID_SAVE, wxT("save"), bmpSave, wxT("save file"));
- tb->AddSeparator();
- tb->AddTool(wxID_BOLD, wxT("bold"), bmpBold, wxT("bold"));
- tb->AddTool(wxID_ITALIC, wxT("italic"), bmpItalic, wxT("italic"));
- tb->AddTool(wxID_UNDERLINE, wxT("underline"), bmpUnderline, wxT("underline"));
- SetToolBar(tb);
- tb->Realize();
- #endif
- const wxString choices[] = { "hello","damn","world" };
- hsplitter = new wxSplitterWindow(\
- this,
- -1,
- wxDefaultPosition,
- wxDefaultSize,
- wxSP_LIVE_UPDATE | wxSP_3D | wxSP_NO_XP_THEME);
- wxAuiMDIClientWindow* client = GetClientWindow();
- client->SetParent(hsplitter);
- hsplitter->SplitHorizontally(new wxListBox(hsplitter, wxID_ANY, wxDefaultPosition, wxDefaultSize,3,choices),
- client);
- hsplitter->SetSashGravity(0.5);
- }
- // event handlers
- void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
- {
- // true is to force the frame to close
- Close(true);
- }
- void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
- {
- wxMessageBox(wxString::Format
- (
- "Welcome to %s!\n"
- "\n"
- "This is the minimal wxWidgets sample\n"
- "running under %s.",
- wxVERSION_STRING,
- wxGetOsDescription()
- ),
- "About wxWidgets minimal sample",
- wxOK | wxICON_INFORMATION,
- this);
- }
- void MyFrame::OnNew(wxCommandEvent& event)
- {
- static int i = 0;
- MyChild* p = new MyChild(this, wxString::Format(wxT("child %d"), ++i));
- p->Show(true);
- }
- void MyFrame::OnCascade(wxCommandEvent& event)
- {
- this->Cascade();
- }
- void MyFrame::OnTile(wxCommandEvent& event)
- {
- this->Tile();
- }
- void MyFrame::OnClose(wxCommandEvent& event)
- {
- wxAuiMDIChildFrame* child = GetActiveChild();
- bool res = child->Close();
- wxASSERT(res);
- }
- void MyFrame::OnCloseAll(wxCommandEvent& event)
- {
- wxWindowList &list = this->GetChildren();
- for (wxWindowList::iterator it = list.begin(); it != list.end(); it++) {
- (*it)->Close();
- }
- }
- void MyFrame::OnFrameClose(wxCloseEvent& event)
- {
- wxWindowList& list = this->GetChildren();
- for (wxWindowList::iterator it = list.begin(); it != list.end(); it++) {
- (*it)->Close();
- }
- GetClientWindow()->SetParent(this);
- event.Skip();
- }
- void MyFrame::OnSize(wxSizeEvent& event)
- {
- if (hsplitter) {
- wxRect rc = GetClientRect();
- hsplitter->SetSize(rc);
- }
- event.Skip();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement