more fixes, printing works quite fine now
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@922 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
a7e594b239
commit
b926666447
@ -66,8 +66,8 @@ MyFrame::MyFrame(void) :
|
||||
wxMenu *file_menu = new wxMenu;
|
||||
file_menu->Append( ID_CLEAR, "Clear");
|
||||
file_menu->Append( ID_ADD_SAMPLE, "Example");
|
||||
file_menu->Append( ID_EDIT, "Edit");
|
||||
file_menu->Append( ID_WXLAYOUT_DEBUG, "Debug");
|
||||
// file_menu->Append( ID_EDIT, "Edit");
|
||||
// file_menu->Append( ID_WXLAYOUT_DEBUG, "Debug");
|
||||
|
||||
file_menu->Append(ID_PRINT, "&Print...", "Print");
|
||||
file_menu->Append(ID_PRINT_SETUP, "Print &Setup...","Setup printer properties");
|
||||
@ -82,10 +82,10 @@ MyFrame::MyFrame(void) :
|
||||
#endif
|
||||
file_menu->AppendSeparator();
|
||||
|
||||
file_menu->Append( ID_DPRINT, "Direct Print");
|
||||
// file_menu->Append( ID_DPRINT, "Direct Print");
|
||||
file_menu->Append( ID_TEXT, "Export Text");
|
||||
file_menu->Append( ID_HTML, "Export HTML");
|
||||
file_menu->Append( ID_TEST, "Test");
|
||||
// file_menu->Append( ID_TEST, "Test");
|
||||
file_menu->Append( ID_QUIT, "Exit");
|
||||
|
||||
wxMenuBar *menu_bar = new wxMenuBar();
|
||||
@ -247,15 +247,6 @@ void MyFrame::OnCommand( wxCommandEvent &event )
|
||||
case ID_CLICK:
|
||||
cerr << "Received click event." << endl;
|
||||
break;
|
||||
case ID_TEST:
|
||||
{
|
||||
Clear();
|
||||
m_lwin->GetLayoutList().LineBreak();
|
||||
m_lwin->GetLayoutList().Insert("abc");
|
||||
m_lwin->GetLayoutList().LineBreak();
|
||||
m_lwin->GetLayoutList().Insert("def");
|
||||
break;
|
||||
}
|
||||
case ID_HTML:
|
||||
{
|
||||
wxLayoutExportObject *export;
|
||||
@ -299,7 +290,7 @@ void MyFrame::OnPrint(wxCommandEvent& WXUNUSED(event))
|
||||
wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
|
||||
#endif
|
||||
wxPrinter printer;
|
||||
wxLayoutPrintout printout( m_lwin->GetLayoutList(),"My printout");
|
||||
wxLayoutPrintout printout( m_lwin->GetLayoutList(),"Printout from wxLayout");
|
||||
if (! printer.Print(this, &printout, TRUE))
|
||||
wxMessageBox(
|
||||
"There was a problem printing.\nPerhaps your current printer is not set correctly?",
|
||||
|
@ -48,6 +48,9 @@
|
||||
|
||||
#define BASELINESTRETCH 12
|
||||
|
||||
// This should never really get created
|
||||
#define WXLLIST_TEMPFILE "__wxllist.tmp"
|
||||
|
||||
#ifdef WXLAYOUT_DEBUG
|
||||
static const char *g_aTypeStrings[] =
|
||||
{
|
||||
@ -508,7 +511,6 @@ wxLayoutList::CalculateCursor(wxDC &dc)
|
||||
void
|
||||
wxLayoutList::DrawCursor(wxDC &dc, bool erase)
|
||||
{
|
||||
|
||||
if(erase)
|
||||
{
|
||||
//dc.SetBrush(*wxWHITE_BRUSH);
|
||||
@ -526,7 +528,7 @@ wxLayoutList::DrawCursor(wxDC &dc, bool erase)
|
||||
Layout(dc);
|
||||
}
|
||||
// Save background:
|
||||
wxBitmap bm(m_CursorSize.x,m_CursorSize.y);
|
||||
wxBitmap bm(m_CursorSize.x+1,m_CursorSize.y+1);
|
||||
m_CursorMemDC.SelectObject(bm);
|
||||
m_CursorMemDC.Blit(0, 0, m_CursorSize.x, m_CursorSize.y,
|
||||
&dc, m_CursorCoords.x,
|
||||
@ -1109,12 +1111,13 @@ bool wxLayoutPrintout::OnPrintPage(int page)
|
||||
wxDC *dc = GetDC();
|
||||
if (dc)
|
||||
{
|
||||
DrawHeader(*dc,wxPoint(m_Margins.left,m_Margins.top/2),wxPoint(m_Margins.right,m_Margins.top),page);
|
||||
int top, bottom;
|
||||
top = (page - 1)*m_PageHeight;
|
||||
bottom = top + m_PageHeight;
|
||||
top = (page - 1)*m_PrintoutHeight;
|
||||
bottom = top + m_PrintoutHeight;
|
||||
// SetDeviceOrigin() doesn't work here, so we need to manually
|
||||
// translate all coordinates.
|
||||
wxPoint translate(0,-top);
|
||||
wxPoint translate(m_Margins.left,-top+m_Margins.top);
|
||||
m_llist->Draw(*dc,top,bottom,wxLayoutObjectList::iterator(NULL),translate);
|
||||
return true;
|
||||
}
|
||||
@ -1140,24 +1143,33 @@ wxLayoutPrintout::OnPreparePrinting(void)
|
||||
void wxLayoutPrintout::GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo)
|
||||
{
|
||||
// ugly hack to get number of pages
|
||||
wxPostScriptDC psdc("tmp.ps",false);
|
||||
#ifdef __WXMSW__
|
||||
wxPrinterDC psdc(WXLLIST_TEMPFILE,false);
|
||||
#else
|
||||
wxPostScriptDC psdc(WXLLIST_TEMPFILE,false);
|
||||
#endif
|
||||
psdc.GetSize(&m_PageWidth, &m_PageHeight); // that's all we need it for
|
||||
|
||||
m_Margins.top = m_PageHeight / 10; // 10%
|
||||
m_Margins.bottom = m_PageHeight - m_PageHeight / 10; // 90%
|
||||
// We do 5% margins on top and bottom, and a 5% high header line.
|
||||
m_Margins.top = m_PageHeight / 10 ; // 10%, half of it header
|
||||
m_Margins.bottom = m_PageHeight - m_PageHeight / 20; // 95%
|
||||
// On the sides we reserve 10% each for the margins.
|
||||
m_Margins.left = m_PageWidth / 10;
|
||||
m_Margins.right = m_PageWidth - m_PageWidth / 10;
|
||||
|
||||
m_PageHeight = m_Margins.bottom - m_Margins.top - m_Margins.bottom;
|
||||
m_PageWidth = m_Margins.right - m_Margins.left - m_Margins.right;
|
||||
// This is the length of the printable area.
|
||||
m_PrintoutHeight = m_PageHeight - (int) (m_PageHeight * 0.15);
|
||||
|
||||
m_NumOfPages = (int)( m_llist->GetSize().y / (float)(m_PageHeight) + 0.5);
|
||||
//FIXME this is wrong but not used at the moment
|
||||
m_PageWidth = m_Margins.right - m_Margins.left;
|
||||
|
||||
m_NumOfPages = (int)( m_llist->GetSize().y / (float)(m_PrintoutHeight) + 0.5);
|
||||
*minPage = 1;
|
||||
*maxPage = m_NumOfPages-1;
|
||||
*maxPage = m_NumOfPages;
|
||||
|
||||
*selPageFrom = 1;
|
||||
*selPageTo = m_NumOfPages-1;
|
||||
|
||||
*selPageTo = m_NumOfPages;
|
||||
wxRemoveFile(WXLLIST_TEMPFILE);
|
||||
}
|
||||
|
||||
bool wxLayoutPrintout::HasPage(int pageNum)
|
||||
@ -1166,6 +1178,44 @@ bool wxLayoutPrintout::HasPage(int pageNum)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
wxLayoutPrintout::DrawHeader(wxDC &dc,
|
||||
wxPoint topleft, wxPoint bottomright,
|
||||
int pageno)
|
||||
{
|
||||
// make backups of all essential parameters
|
||||
wxBrush *brush = dc.GetBrush();
|
||||
wxPen *pen = dc.GetPen();
|
||||
wxFont *font = dc.GetFont(),
|
||||
*myfont;;
|
||||
|
||||
dc.SetBrush(*wxWHITE_BRUSH);
|
||||
dc.SetPen(wxPen(*wxBLACK,0,wxSOLID));
|
||||
dc.DrawRoundedRectangle(topleft.x,
|
||||
topleft.y,bottomright.x-topleft.x,
|
||||
bottomright.y-topleft.y);
|
||||
dc.SetBrush(*wxBLACK_BRUSH);
|
||||
myfont = new wxFont((WXLO_DEFAULTFONTSIZE*12)/10,wxSWISS,wxNORMAL,wxBOLD,false,"Helvetica");
|
||||
dc.SetFont(*myfont);
|
||||
|
||||
wxString page;
|
||||
page = "9999/9999 "; // many pages...
|
||||
long w,h;
|
||||
dc.GetTextExtent(page,&w,&h);
|
||||
page.Printf("%d/%d", pageno, (int) m_NumOfPages);
|
||||
dc.DrawText(page,bottomright.x-w,topleft.y+h/2);
|
||||
dc.GetTextExtent("XXXX", &w,&h);
|
||||
dc.DrawText(m_title, topleft.x+w,topleft.y+h/2);
|
||||
|
||||
// restore settings
|
||||
dc.SetPen(*pen);
|
||||
dc.SetBrush(*brush);
|
||||
dc.SetFont(*font);
|
||||
|
||||
delete myfont;
|
||||
}
|
||||
|
||||
|
||||
wxLayoutPrintout *
|
||||
wxLayoutList::MakePrintout(wxString const &name)
|
||||
{
|
||||
|
@ -44,6 +44,8 @@
|
||||
# define Str(str) str
|
||||
#endif
|
||||
|
||||
#define WXLO_DEFAULTFONTSIZE 12
|
||||
|
||||
/// Types of currently supported layout objects.
|
||||
enum wxLayoutObjectType
|
||||
{ WXLO_TYPE_INVALID = 0, WXLO_TYPE_TEXT, WXLO_TYPE_CMD, WXLO_TYPE_ICON, WXLO_TYPE_LINEBREAK };
|
||||
@ -355,7 +357,7 @@ public:
|
||||
void Delete(CoordType count = 1);
|
||||
void Insert(String const &text);
|
||||
void Insert(wxLayoutObjectBase *obj);
|
||||
void Clear(int family = wxROMAN, int size=12, int style=wxNORMAL, int weight=wxNORMAL,
|
||||
void Clear(int family = wxROMAN, int size=WXLO_DEFAULTFONTSIZE, int style=wxNORMAL, int weight=wxNORMAL,
|
||||
int underline=0, char const *fg="black", char const *bg="white");
|
||||
|
||||
/// return a pointer to the default settings (dangerous, why?) FIXME:
|
||||
@ -432,18 +434,25 @@ private:
|
||||
class wxLayoutPrintout: public wxPrintout
|
||||
{
|
||||
public:
|
||||
wxLayoutPrintout(wxLayoutList &llist, wxString const & title = "My printout")
|
||||
wxLayoutPrintout(wxLayoutList &llist, wxString const & title =
|
||||
"wxLayout Printout")
|
||||
:wxPrintout(title)
|
||||
{ m_llist = &llist; }
|
||||
{ m_llist = &llist; m_title = title;}
|
||||
bool OnPrintPage(int page);
|
||||
bool HasPage(int page);
|
||||
bool OnBeginDocument(int startPage, int endPage);
|
||||
void GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int
|
||||
*selPageTo);
|
||||
void OnPreparePrinting(void);
|
||||
protected:
|
||||
virtual void DrawHeader(wxDC &dc, wxPoint topleft, wxPoint bottomright, int pageno);
|
||||
|
||||
private:
|
||||
wxLayoutList *m_llist;
|
||||
wxString m_title;
|
||||
int m_PageHeight, m_PageWidth;
|
||||
// how much we actually print per page
|
||||
int m_PrintoutHeight;
|
||||
wxLayoutMargins m_Margins;
|
||||
int m_NumOfPages;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user