#include "wxllist.h"
#include "iostream"
+#include <wx/dc.h>
+#include <wx/postscrp.h>
+#include <wx/print.h>
+
#define BASELINESTRETCH 12
#define VAR(x) cerr << #x"=" << x << endl;
#ifdef WXLAYOUT_DEBUG
static const char *_t[] = { "invalid", "text", "cmd", "icon",
- "linebreak"};
+ "linebreak"};
void
wxLayoutObjectBase::Debug(void)
void
wxLayoutObjectText::Draw(wxDC &dc, wxPoint position, CoordType baseLine,
- bool draw)
+ bool draw)
{
long descent = 0l;
dc.GetTextExtent(Str(m_Text),&m_Width, &m_Height, &descent);
void
wxLayoutObjectIcon::Draw(wxDC &dc, wxPoint position, CoordType baseLine,
- bool draw)
+ bool draw)
{
position.y += baseLine - m_Icon->GetHeight();
if(draw)
wxLayoutObjectCmd::wxLayoutObjectCmd(int size, int family, int style, int
- weight, bool underline,
- wxColour const *fg, wxColour const *bg)
+ weight, bool underline,
+ wxColour const *fg, wxColour const *bg)
{
m_font = new wxFont(size,family,style,weight,underline);
void
wxLayoutObjectCmd::Draw(wxDC &dc, wxPoint position, CoordType lineHeight,
- bool draw)
+ bool draw)
{
wxASSERT(m_font);
// this get called even when draw==false, so that recalculation
Insert(
new wxLayoutObjectCmd(m_FontPtSize,m_FontFamily,m_FontStyle,m_FontWeight,m_FontUnderline,
- m_ColourFG, m_ColourBG));
+ m_ColourFG, m_ColourBG));
}
void
// used temporarily
wxLayoutObjectText *tobj = NULL;
+
+
+ // this is needed for printing to a printer:
+ // only interesting for printer/PS output
+ int pageWidth, pageHeight; //GetSize() still needs int at the moment
+ struct
+ {
+ int top, bottom, left, right;
+ } margins;
+
+ if(
+#ifdef __WXMSW__
+ dc.IsKindOf(CLASSINFO(wxPrinterDC)) ||
+#endif
+ dc.IsKindOf(CLASSINFO(wxPostScriptDC)))
+ {
+ VAR(wxThePrintSetupData);
+
+ 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;
+ }
+ else
+ {
+ margins.top = 0; margins.left = 0;
+ margins.right = -1;
+ margins.bottom = -1;
+ }
+ position.y = margins.right;
+ position.x = margins.left;
VAR(findObject); VAR(findCoords.x); VAR(findCoords.y);
// if the cursorobject is a cmd, we need to find the first
else
{
if(type == WXLO_TYPE_LINEBREAK)
- dc.DrawLine(0, position.y+baseLineSkip, 0, position.y+2*baseLineSkip);
+ dc.DrawLine(0, position.y+baseLineSkip, 0, position.y+2*baseLineSkip);
else
{
if(size.x == 0)
}
if(! draw) // finished calculating sizes
- { // do this line again, this time drawing it
+ {
+ // 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)
+ {
+ dc.EndPage();
+ position_HeadOfLine.y = margins.top;
+ dc.StartPage();
+ }
+ // do this line again, this time drawing it
position = position_HeadOfLine;
draw = true;
i = headOfLine;
// is it a linebreak?
if(type == WXLO_TYPE_LINEBREAK || i == tail())
{
- position.x = 0;
+ position.x = margins.left;
position.y += baseLineSkip;
baseLine = m_FontPtSize;
objBaseLine = baseLine; // not all objects set it
}
i++;
}
+ dc.EndDoc();
m_MaxY = position.y;
return foundObject;
}