Skip to content

Instantly share code, notes, and snippets.

@lighth7015
Created February 10, 2020 04:10
Show Gist options
  • Save lighth7015/cbe25741ffe1a12c2fd2984b2daeb5fc to your computer and use it in GitHub Desktop.
Save lighth7015/cbe25741ffe1a12c2fd2984b2daeb5fc to your computer and use it in GitHub Desktop.
MDI Test
#include <wx/artprov.h>
#include <wx/xrc/xmlres.h>
#include <wx/scrolwin.h>
#include <wx/gdicmn.h>
#include <wx/font.h>
#include <wx/colour.h>
#include <wx/settings.h>
#include <wx/string.h>
#include <wx/frame.h>
#include <wx/aui/aui.h>
#include <wx/wx.h>
namespace Controls {
class ChildWindow: public wxPanel {
wxFrame* frame = new wxFrame( this, wxID_ANY, "", { 0, 0 } );
wxPanel* content = new wxPanel( this, wxID_ANY, { 35, 35 }, wxDefaultSize);
const int border = 5, captionHeight = 30;
public:
void OnRedraw(wxPaintEvent & evt) {
//wxPaintDC dc(this);
printf("paint?\n");
}
void OnPaint(wxDC& dc) {
puts("paint?");
}
bool ProcessEvent (wxEvent &event) override {
wxWindow& window = *((wxWindow*)event.GetEventObject());
int height, width;
if (event.GetEventType() == wxEVT_SIZE) {
window.GetSize(&width, &height);
SetSize( width, height);
frame->SetSize( width, height);
content->SetSize( border, captionHeight + border, width - (border * 2), height - (( border + captionHeight ) + border ));
}
else if (event.GetEventType() == wxEVT_CLOSE_WINDOW) {
return wxPanel::ProcessEvent(event);
}
return true;
}
ChildWindow(wxWindow* parent, const char* caption, int width = 360, int height = 91160):
wxPanel(parent, wxID_ANY, wxDefaultPosition, wxSize( 1920, 1080 ))
{
SetBackgroundColour(wxColour(80, 80, 80));
}
~ChildWindow() {
delete frame;
delete content;
}
DECLARE_EVENT_TABLE()
};
BEGIN_EVENT_TABLE(ChildWindow, wxPanel)
EVT_PAINT(ChildWindow::OnRedraw)
END_EVENT_TABLE()
class Frame : public wxFrame {
wxAuiManager layout;
wxScrolledWindow* const workspace
= new wxScrolledWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL );
wxPanel* child = new ChildWindow( workspace, "Child Window" );
public:
bool ProcessEvent (wxEvent &event) override {
wxWindow& window = *((wxWindow*)event.GetEventObject());
int height, width;
if (event.GetEventType() == wxEVT_SIZE) {
window.GetSize(&width, &height);
workspace->SetSize(0, 0, width, height);
}
else if (event.GetEventType() == wxEVT_CLOSE_WINDOW) {
return wxFrame::ProcessEvent(event);
}
return true;
}
Frame(const char* caption): wxFrame(nullptr, wxID_ANY, caption) {
SetClientSize(640, 480);
layout.SetManagedWindow(this);
layout.SetFlags(wxAUI_MGR_ALLOW_ACTIVE_PANE|wxAUI_MGR_ALLOW_FLOATING|wxAUI_MGR_DEFAULT);
workspace->SetScrollRate( 5, 5 );
//child->SetBackgroundColour(wxColour(180, 180, 180));
workspace->SetBackgroundColour(wxColour(180, 180, 180));
child->SetSize(20, 20, 120, 120);
wxAuiPaneInfo layoutInfo(wxAuiPaneInfo()
.Centre()
.CaptionVisible( false )
.MinimizeButton( true )
.PaneBorder( false )
.Dock()
.Resizable()
.FloatingSize( wxDefaultSize )
.CentrePane());
layout.AddPane( workspace, layoutInfo );
layout.Update();
Centre( wxBOTH );
SetBackgroundColour(wxColour(80, 80, 80));
}
~Frame() {
layout.UnInit();
}
};
}
class Application : public wxApp {
wxFrame* container = nullptr;
bool OnInit() override {
if (container == nullptr) {
container = new Controls::Frame("Panel example");
container->Show();
}
return true;
}
};
wxIMPLEMENT_APP(Application);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment