// MyFrame
//-----------------------------------------------------------------------------
- enum ids{ ID_EDIT = 1, ID_ADD_SAMPLE, ID_CLEAR, ID_PRINT, ID_DPRINT,
+ enum ids{ ID_EDIT = 1, ID_ADD_SAMPLE, ID_CLEAR, ID_PRINT,
+ ID_PRINT_SETUP, ID_PAGE_SETUP, ID_PREVIEW, ID_PRINT_PS,
+ ID_PRINT_SETUP_PS, ID_PAGE_SETUP_PS,ID_PREVIEW_PS,
+ ID_DPRINT,
ID_WXLAYOUT_DEBUG, ID_QUIT, ID_CLICK, ID_HTML, ID_TEXT, ID_TEST };
IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame )
BEGIN_EVENT_TABLE(MyFrame,wxFrame)
- EVT_MENU (-1, MyFrame::OnCommand)
- EVT_COMMAND (-1,-1, MyFrame::OnCommand)
- EVT_CHAR ( wxLayoutWindow::OnChar )
+ EVT_MENU(ID_PRINT, MyFrame::OnPrint)
+ EVT_MENU(ID_PREVIEW, MyFrame::OnPrintPreview)
+ EVT_MENU(ID_PRINT_SETUP, MyFrame::OnPrintSetup)
+ EVT_MENU(ID_PAGE_SETUP, MyFrame::OnPageSetup)
+ EVT_MENU(ID_PRINT_PS, MyFrame::OnPrintPS)
+ EVT_MENU(ID_PREVIEW_PS, MyFrame::OnPrintPreviewPS)
+ EVT_MENU(ID_PRINT_SETUP_PS, MyFrame::OnPrintSetupPS)
+ EVT_MENU(ID_PAGE_SETUP_PS, MyFrame::OnPageSetupPS)
+ EVT_MENU (-1, MyFrame::OnCommand)
+ EVT_COMMAND (-1,-1, MyFrame::OnCommand)
+ EVT_CHAR ( wxLayoutWindow::OnChar )
END_EVENT_TABLE()
+
+
+
+
+
+int orientation = wxPORTRAIT;
+
+
+
+
+
+
MyFrame::MyFrame(void) :
wxFrame( NULL, -1, "wxLayout", wxPoint(20,20), wxSize(600,360) )
{
file_menu->Append( ID_ADD_SAMPLE, "Example");
file_menu->Append( ID_EDIT, "Edit");
file_menu->Append( ID_WXLAYOUT_DEBUG, "Debug");
- file_menu->Append( ID_PRINT, "Print");
+
+ file_menu->Append(ID_PRINT, "&Print...", "Print");
+ file_menu->Append(ID_PRINT_SETUP, "Print &Setup...","Setup printer properties");
+ file_menu->Append(ID_PAGE_SETUP, "Page Set&up...", "Page setup");
+ file_menu->Append(ID_PREVIEW, "Print Pre&view", "Preview");
+#ifdef __WXMSW__
+ file_menu->AppendSeparator();
+ file_menu->Append(ID_PRINT_PS, "Print PostScript...", "Print (PostScript)");
+ file_menu->Append(ID_PRINT_SETUP_PS, "Print Setup PostScript...", "Setup printer properties (PostScript)");
+ file_menu->Append(ID_PAGE_SETUP_PS, "Page Setup PostScript...", "Page setup (PostScript)");
+ file_menu->Append(ID_PREVIEW_PS, "Print Preview PostScript", "Preview (PostScript)");
+#endif
+ file_menu->AppendSeparator();
+
file_menu->Append( ID_DPRINT, "Direct Print");
file_menu->Append( ID_TEXT, "Export Text");
file_menu->Append( ID_HTML, "Export HTML");
}
};
+void MyFrame::OnPrint(wxCommandEvent& WXUNUSED(event))
+{
+#ifdef __WXMSW__
+ wxGetApp().SetPrintMode(wxPRINT_WINDOWS);
+#else
+ wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
+#endif
+ wxPrinter printer;
+ wxLayoutPrintout printout( m_lwin->GetLayoutList(),"My printout");
+ if (!printer.Print(this, &printout, TRUE))
+ wxMessageBox("There was a problem printing.\nPerhaps your current printer is not set correctly?", "Printing", wxOK);
+}
+
+void MyFrame::OnPrintPS(wxCommandEvent& WXUNUSED(event))
+{
+ wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
+
+ wxPostScriptPrinter printer;
+ wxLayoutPrintout printout( m_lwin->GetLayoutList(),"My printout");
+ printer.Print(this, &printout, TRUE);
+}
+
+void MyFrame::OnPrintPreview(wxCommandEvent& WXUNUSED(event))
+{
+#ifdef __WXMSW__
+ wxGetApp().SetPrintMode(wxPRINT_WINDOWS);
+#else
+ wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
+#endif
+ wxPrintData printData;
+ printData.SetOrientation(orientation);
+
+ // Pass two printout objects: for preview, and possible printing.
+ wxPrintPreview *preview = new wxPrintPreview(new wxLayoutPrintout( m_lwin->GetLayoutList()), new wxLayoutPrintout( m_lwin->GetLayoutList()), & printData);
+ if (!preview->Ok())
+ {
+ delete preview;
+ wxMessageBox("There was a problem previewing.\nPerhaps your current printer is not set correctly?", "Previewing", wxOK);
+ return;
+ }
+
+ wxPreviewFrame *frame = new wxPreviewFrame(preview, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
+ frame->Centre(wxBOTH);
+ frame->Initialize();
+ frame->Show(TRUE);
+}
+
+void MyFrame::OnPrintPreviewPS(wxCommandEvent& WXUNUSED(event))
+{
+ wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
+
+ wxPrintData printData;
+ printData.SetOrientation(orientation);
+
+ // Pass two printout objects: for preview, and possible printing.
+ wxPrintPreview *preview = new wxPrintPreview(new wxLayoutPrintout( m_lwin->GetLayoutList()), new wxLayoutPrintout( m_lwin->GetLayoutList()), & printData);
+ wxPreviewFrame *frame = new wxPreviewFrame(preview, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
+ frame->Centre(wxBOTH);
+ frame->Initialize();
+ frame->Show(TRUE);
+}
+
+void MyFrame::OnPrintSetup(wxCommandEvent& WXUNUSED(event))
+{
+#ifdef __WXMSW__
+ wxGetApp().SetPrintMode(wxPRINT_WINDOWS);
+#else
+ wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
+#endif
+ wxPrintData data;
+ data.SetOrientation(orientation);
+
+#ifdef __WXMSW__
+ wxPrintDialog printerDialog(this, & data);
+#else
+ wxGenericPrintDialog printerDialog(this, & data);
+#endif
+ printerDialog.GetPrintData().SetSetupDialog(TRUE);
+ printerDialog.ShowModal();
+
+ orientation = printerDialog.GetPrintData().GetOrientation();
+}
+
+void MyFrame::OnPageSetup(wxCommandEvent& WXUNUSED(event))
+{
+#ifdef __WXMSW__
+ wxGetApp().SetPrintMode(wxPRINT_WINDOWS);
+#else
+ wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
+#endif
+ wxPageSetupData data;
+ data.SetOrientation(orientation);
+
+#ifdef __WXMSW__
+ wxPageSetupDialog pageSetupDialog(this, & data);
+#else
+ wxGenericPageSetupDialog pageSetupDialog(this, & data);
+#endif
+ pageSetupDialog.ShowModal();
+
+ data = pageSetupDialog.GetPageSetupData();
+ orientation = data.GetOrientation();
+}
+
+void MyFrame::OnPrintSetupPS(wxCommandEvent& WXUNUSED(event))
+{
+ wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
+
+ wxPrintData data;
+ data.SetOrientation(orientation);
+
+ wxGenericPrintDialog printerDialog(this, & data);
+ printerDialog.GetPrintData().SetSetupDialog(TRUE);
+ printerDialog.ShowModal();
+
+ orientation = printerDialog.GetPrintData().GetOrientation();
+}
+
+void MyFrame::OnPageSetupPS(wxCommandEvent& WXUNUSED(event))
+{
+ wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
+
+ wxPageSetupData data;
+ data.SetOrientation(orientation);
+
+ wxGenericPageSetupDialog pageSetupDialog(this, & data);
+ pageSetupDialog.ShowModal();
+
+ orientation = pageSetupDialog.GetPageSetupData().GetOrientation();
+}
+
//-----------------------------------------------------------------------------
// MyApp
};
# define wxLayoutDebug wxLogDebug
-# define WXL_VAR(x) wxLogDebug(#x " = ", x)
+# define WXL_VAR(x) cerr << #x " = " << x ;
# define WXL_DBG_POINT(p) wxLogDebug(#p ": (%d, %d)", p.x, p.y)
# define WXL_TRACE(f) wxLogDebug(#f ": ")
# define TypeString(t) g_aTypeStrings[t]
void
wxLayoutList::SetFont(int family, int size, int style, int weight,
int underline, char const *fg, char const *bg)
+
{
wxColour const
* cfg = NULL,
wxLayoutList::GetSize(CoordType *max_x, CoordType *max_y,
CoordType *lineHeight)
{
- wxASSERT(max_x); wxASSERT(max_y); wxASSERT(lineHeight);
- *max_x = m_MaxX;
- *max_y = m_MaxY;
- *lineHeight = m_LineHeight;
+
+ if(max_x) *max_x = m_MaxX;
+ if(max_y) *max_y = m_MaxY;
+ if(lineHeight) *lineHeight = m_LineHeight;
}
wxLayoutObjectBase *
-wxLayoutList::Draw(wxDC &dc, bool findObject, wxPoint const &findCoords)
+wxLayoutList::Draw(wxDC &dc, bool findObject, wxPoint const
+ &findCoords, int pageNo, bool reallyDraw)
{
wxLayoutObjectList::iterator i;
int top, bottom, left, right;
} margins;
- if(
-#ifdef __WXMSW__
- dc.IsKindOf(CLASSINFO(wxPrinterDC)) ||
-#endif
- dc.IsKindOf(CLASSINFO(wxPostScriptDC)))
+ int currentPage = 1;
+
+ if(pageNo > 0)
{
dc.GetSize(&pageWidth, &pageHeight);
- dc.StartDoc(_("Printing..."));
- dc.StartPage();
- margins.top = (1*pageHeight)/10; // 10%
- margins.bottom = (9*pageHeight)/10; // 90%
- margins.left = (1*pageWidth)/10;
- margins.right = (9*pageWidth)/10;
+ WXL_VAR(pageHeight);
+ margins.top = 0; //(1*pageHeight)/10; // 10%
+ margins.bottom = pageHeight;// (9*pageHeight)/10; // 90%
+ margins.left = 0; //(1*pageWidth)/10;
+ margins.right = pageWidth; //(9*pageWidth)/10;
}
else
{
margins.right = -1;
margins.bottom = -1;
}
- position.y = margins.right;
+ position.y = margins.top;
position.x = margins.left;
// if the cursorobject is a cmd, we need to find the first
type = (*i)->GetType();
// to initialise sizes of objects, we need to call Draw
- (*i)->Draw(dc, position, baseLine, draw);
-
+ if(draw && (pageNo == -1 || pageNo == currentPage))
+ {
+ (*i)->Draw(dc, position, baseLine, draw);
+#ifdef WXLAYOUT_DEBUG
+ if(i == begin())
+ wxLogDebug("first position = (%d,%d)",(int) position.x, (int)position.y);
+#endif
+ }
// update coordinates for next object:
size = (*i)->GetSize(&objBaseLine);
if(findObject && draw) // we need to look for an object
{
// if the this line needs to go onto a new page, we need
// to change pages before drawing it:
- if(margins.bottom != -1 && position.y > margins.bottom)
+ if(pageNo > 0 && position.y > margins.bottom)
{
- dc.EndPage();
+ currentPage++;
position_HeadOfLine.y = margins.top;
- dc.StartPage();
}
- // do this line again, this time drawing it
- position = position_HeadOfLine;
- draw = true;
- i = headOfLine;
- continue;
+ if(reallyDraw && (pageNo == -1 || pageNo == currentPage))
+ {
+ // do this line again, this time drawing it
+ position = position_HeadOfLine;
+ draw = true;
+ i = headOfLine;
+ continue;
+ }
}
else // we have drawn a line, so continue calculating next one
draw = false;
}
i++;
}
- dc.EndDoc();
// draw the cursor
if(m_Editable)
{
m_FontWeight,m_FontUnderline,
m_ColourFG, m_ColourBG);
}
+
+
+
+/******************** printing stuff ********************/
+
+bool wxLayoutPrintout::OnPrintPage(int page)
+{
+ wxDC *dc = GetDC();
+ if (dc)
+ {
+ m_llist->Draw(*dc,false,wxPoint(0,0),page);
+ return TRUE;
+ }
+ else
+ return FALSE;
+}
+
+bool wxLayoutPrintout::OnBeginDocument(int startPage, int endPage)
+{
+ if (!wxPrintout::OnBeginDocument(startPage, endPage))
+ return FALSE;
+
+ return TRUE;
+}
+
+void wxLayoutPrintout::GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo)
+{
+
+ // This code doesn't work, because we don't have a DC yet.
+ // How on earth are we supposed to calculate the number of pages then?
+
+ *minPage = 1;
+ *maxPage = 32000;
+
+ *selPageFrom = 1;
+ *selPageTo = 1;
+
+#if 0
+ CoordType height;
+ int pageWidth, pageHeight;
+
+ wxDC *dc = GetDC();
+ wxASSERT(dc);
+
+ dc->GetSize(&pageWidth, &pageHeight);
+// don't draw but just recalculate sizes:
+ m_llist->Draw(*dc,false,wxPoint(0,0),-1,false);
+ m_llist->GetSize(NULL,&height,NULL);
+
+ *minPage = 1;
+ *maxPage = height/pageHeight+1;
+
+ *selPageFrom = 1;
+ *selPageTo = *maxPage;
+ m_maxPage = *maxPage;
+#endif
+
+}
+
+bool wxLayoutPrintout::HasPage(int pageNum)
+{
+ return true;
+// return m_maxPage >= pageNum;
+}
+
+
+wxLayoutPrintout *
+wxLayoutList::MakePrintout(wxString const &name)
+{
+ return new wxLayoutPrintout(*this,name);
+}
#include "kbList.h"
#include "wx/wx.h"
+#include "wx/print.h"
+#include "wx/printdlg.h"
+#include "wx/generic/printps.h"
+#include "wx/generic/prntdlgg.h"
// skip the following defines if embedded in M application
#ifdef M_BASEDIR
};
+class wxLayoutPrintout;
+
/**
This class provides a high level abstraction to the wxFText
classes.
@param findObject if true, return the object occupying the
position specified by coords
@param coords position where to find the object
+ @pageNo if > 0, print only that page of a document (for
+ printing)
+ @reallyDraw set this to false if you don't want to draw but just calculate the coordinates
@return if findObject == true, the object or NULL
*/
wxLayoutObjectBase *Draw(wxDC &dc, bool findObject = false,
- wxPoint const &coords = wxPoint(0,0));
+ wxPoint const &coords = wxPoint(0,0),
+ int pageNo = -1, bool reallyDraw = true);
#ifdef WXLAYOUT_DEBUG
void Debug(void);
void GetSize(CoordType *max_x, CoordType *max_y,
CoordType *lineHeight);
+
/**@name Functionality for editing */
//@{
/// set list editable or read only
// only used to decide whether we are before or after linebreak
CoordType GetLineLength(wxLayoutObjectList::iterator i,
CoordType offs = 0);
+ wxLayoutPrintout *MakePrintout(wxString const &name);
+
//@}
protected:
/// font parameters:
};
+class wxLayoutPrintout: public wxPrintout
+{
+ public:
+ wxLayoutPrintout(wxLayoutList &llist, wxString const & title = "My printout"):wxPrintout(title)
+ { m_llist = &llist; m_maxPage = 0; }
+ bool OnPrintPage(int page);
+ bool HasPage(int page);
+ bool OnBeginDocument(int startPage, int endPage);
+ void GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int
+ *selPageTo);
+private:
+ wxLayoutList *m_llist;
+ int m_maxPage;
+};
+
#endif // WXLLIST_H