wxHtmlPrintout::GetMaxPage() returns always 1

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Morfio
Experienced Solver
Experienced Solver
Posts: 67
Joined: Thu Jul 07, 2005 4:35 pm

wxHtmlPrintout::GetMaxPage() returns always 1

Post by Morfio » Wed Apr 01, 2015 10:04 am

Hello,

I've got the problem, that in wxWidgets 3.x wxHtmlPrintout::GetMaxPages() always returns one Page, even if the document has more. What am I doing wrong?

Code: Select all

#include <wx/wx.h>
#include <wx/html/htmprint.h>

class MyApp : public wxApp {

	public:
		bool OnInit();

};

class MyFrame : public wxFrame {

	public:
		MyFrame();

};

IMPLEMENT_APP(MyApp)

bool MyApp::OnInit() {
	MyFrame *f = new MyFrame;
	f->Show();
	SetTopWindow(f);
	return true;
}

MyFrame::MyFrame() : wxFrame(NULL, -1, _("Test")) {
	wxHtmlPrintout *p = new wxHtmlPrintout;
	p->SetHtmlText(_(
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"Hello<br />"
		"World<br />"
	));
	p->SetHeader(_("@[email protected]"));

	wxPrintData *d = new wxPrintData;

	wxPrintPreview *s = new wxPrintPreview(p, p, d);

	wxPanel *m = new wxPanel(this);
	wxBoxSizer *b = new wxBoxSizer(wxVERTICAL);

	wxPreviewCanvas *c = new wxPreviewCanvas(s, m);
	s->SetCanvas(c);

	b->Add(c, 1, wxEXPAND);

	m->SetSizer(b);

	printf("Pages: %i\n", s->GetMaxPage());
}

Thank you

Morfio

Morfio
Experienced Solver
Experienced Solver
Posts: 67
Joined: Thu Jul 07, 2005 4:35 pm

Re: wxHtmlPrintout::GetMaxPage() returns always 1

Post by Morfio » Wed Apr 01, 2015 2:11 pm

If I use GetMaxPage() in an event it works perfectly. It seems, that wxPrintout calculates its sizes after first showing the frame.

Post Reply