Jan Engelhardt
2014-04-29 16:04:20 UTC
A wxNonOwnedWindow is wrongly positioned when calling Center(OnParent),
as it uses relative positions rather than absolute ones.
wxTopLevelWindow::CenterOnParent does the right thing, but the same
logic must be applied to one base lower, wxNonOwnedWindow.
#include <wx/wx.h>
#include <wx/popupwin.h>
class M : public wxFrame {
public: M(void) : wxFrame(NULL,-1,"") {
auto btn = new wxButton(this,-1,"Make Popup");
btn->Bind(wxEVT_BUTTON, [=](wxCommandEvent &) {
auto mr = GetClientRect();
printf("parent: %dx%d+%d+%d\n",
mr.width, mr.height, mr.x, mr.y);
auto pop = new wxPopupWindow(this);
auto popsizer = new wxBoxSizer(wxVERTICAL);
popsizer->Add(new wxStaticText(pop,-1,"POPUP"));
pop->SetSizer(popsizer);
popsizer->SetSizeHints(pop);
pop->Layout();
pop->Show();
wxRect pr;
//pop->CenterOnParent();
//pr = pop->GetRect();
//printf("pop1: %dx%d+%d+%d\n",
// pr.width, pr.height, pr.x, pr.y);
//CenterOnParent expanded:
mr = pop->GetParent()->GetClientSize();
pr = pop->GetRect();
printf("pop2: %dx%d+%d+%d\n",
pr.width, pr.height, pr.x, pr.y);
pr = pr.CentreIn(mr, wxBOTH);
printf("pop3: %dx%d+%d+%d\n",
pr.width, pr.height, pr.x, pr.y);
pop->SetSize(pr);
});
Layout();
Show();
};
};
class A : public wxApp {
public: bool OnInit(void) { new M; return true; };
};
IMPLEMENT_APP(A);
as it uses relative positions rather than absolute ones.
wxTopLevelWindow::CenterOnParent does the right thing, but the same
logic must be applied to one base lower, wxNonOwnedWindow.
#include <wx/wx.h>
#include <wx/popupwin.h>
class M : public wxFrame {
public: M(void) : wxFrame(NULL,-1,"") {
auto btn = new wxButton(this,-1,"Make Popup");
btn->Bind(wxEVT_BUTTON, [=](wxCommandEvent &) {
auto mr = GetClientRect();
printf("parent: %dx%d+%d+%d\n",
mr.width, mr.height, mr.x, mr.y);
auto pop = new wxPopupWindow(this);
auto popsizer = new wxBoxSizer(wxVERTICAL);
popsizer->Add(new wxStaticText(pop,-1,"POPUP"));
pop->SetSizer(popsizer);
popsizer->SetSizeHints(pop);
pop->Layout();
pop->Show();
wxRect pr;
//pop->CenterOnParent();
//pr = pop->GetRect();
//printf("pop1: %dx%d+%d+%d\n",
// pr.width, pr.height, pr.x, pr.y);
//CenterOnParent expanded:
mr = pop->GetParent()->GetClientSize();
pr = pop->GetRect();
printf("pop2: %dx%d+%d+%d\n",
pr.width, pr.height, pr.x, pr.y);
pr = pr.CentreIn(mr, wxBOTH);
printf("pop3: %dx%d+%d+%d\n",
pr.width, pr.height, pr.x, pr.y);
pop->SetSize(pr);
});
Layout();
Show();
};
};
class A : public wxApp {
public: bool OnInit(void) { new M; return true; };
};
IMPLEMENT_APP(A);
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users