}
void
-wxLayoutObjectText::Draw(wxDC &dc)
+wxLayoutObjectText::Draw(wxDC &dc, wxPoint const &translate)
{
- dc.DrawText(Str(m_Text), m_Position.x, m_Position.y);
+ dc.DrawText(Str(m_Text), m_Position.x + translate.x, m_Position.y+translate.y);
m_IsDirty = false;
}
}
void
-wxLayoutObjectIcon::Draw(wxDC &dc)
+wxLayoutObjectIcon::Draw(wxDC &dc, wxPoint const &translate)
{
- dc.DrawIcon(m_Icon,m_Position.x, m_Position.y);
+ dc.DrawIcon(m_Icon,m_Position.x+translate.x, m_Position.y+translate.y);
}
void
}
void
-wxLayoutObjectCmd::Draw(wxDC &dc)
+wxLayoutObjectCmd::Draw(wxDC &dc, wxPoint const &translate)
{
wxASSERT(m_font);
dc.SetFont(m_font);
{
m_Position = p; // required so we can find the right object for cursor
// this get called, so that recalculation uses right font sizes
- Draw(dc);
+ Draw(dc,wxPoint(0,0));
}
//-------------------------- wxLayoutList
dc.SetBackgroundMode( wxSOLID ); // to enable setting of text background
dc.SetFont( *wxNORMAL_FONT );
if(m_DefaultSetting)
- m_DefaultSetting->Draw(dc);
+ m_DefaultSetting->Draw(dc,wxPoint(0,0));
}
void
-wxLayoutList::Layout(wxDC &dc)
+wxLayoutList::Layout(wxDC &dc, wxLayoutMargins *margins)
{
iterator i;
wxLayoutObjectBase *cursorObject = NULL; // let's find it again
- struct
+ if(margins)
{
- int top, bottom, left, right;
- } margins;
-
- margins.top = 0; margins.left = 0;
- margins.right = -1;
- margins.bottom = -1;
+ position.y = margins->top;
+ position.x = margins->left;
+ }
+ else
+ {
+ position.y = 0;
+ position.x = 0;
+ }
- position.y = margins.top;
- position.x = margins.left;
-
ResetSettings(dc);
i = begin();
// now check whether we have finished handling this line:
if(type == WXLO_TYPE_LINEBREAK && i != tail())
{
- position.x = margins.left;
+ position.x = margins ? margins->left : 0;
position.y += baseLineSkip;
baseLine = m_FontPtSize;
objBaseLine = baseLine; // not all objects set it
void
wxLayoutList::Draw(wxDC &dc,
CoordType fromLine, CoordType toLine,
- iterator start)
+ iterator start,
+ wxPoint const &translate)
{
Layout(dc); // FIXME just for now
ResetSettings(dc);
wxLayoutObjectList::iterator i;
+
if(start == iterator(NULL))
start = begin();
-
- while( i != end() && (**i).GetPosition().y < fromLine)
- i++;
+ else // we need to restore font settings
+ {
+ for( i = begin() ; i != start; i++)
+ if((**i).GetType() == WXLO_TYPE_CMD)
+ (**i).Draw(dc,translate); // apply font settings
+ }
+
+ while( start != end() && (**start).GetPosition().y < fromLine)
+ {
+ if((**start).GetType() == WXLO_TYPE_CMD)
+ (**start).Draw(dc,translate); // apply font settings
+ start++;
+ }
for( i = start ;
i != end() && (toLine == -1 || (**i).GetPosition().y < toLine) ;
i++ )
- (*i)->Draw(dc);
+ (*i)->Draw(dc,translate);
}
/** Erase at least to end of line */
dc.SetBrush(*wxWHITE_BRUSH);
dc.SetPen(wxPen(*wxWHITE,0,wxTRANSPARENT));
dc.DrawRectangle(p.x,p.y,2000,2000); //dc.MaxX(),dc.MaxY());
- Draw(dc,-1,-1,start);
+ Draw(dc,-1,-1,start,wxPoint(0,0));
//dc.DrawRectangle(p.x,p.y,2000,2000); //dc.MaxX(),dc.MaxY());
}
bool wxLayoutPrintout::OnPrintPage(int page)
{
wxDC *dc = GetDC();
- int top, bottom,width,height;
if (dc)
{
- dc->GetSize(&width, &height);
-
- top = (page - 1) * (9*height)/10;
- bottom = top + (9*height)/10;
-
- if( top >= m_llist->GetSize().y)
- return false;
- m_llist->Draw(*dc,top,bottom);
+ int top, bottom;
+ top = (page - 1)*m_PageHeight;
+ bottom = top + m_PageHeight;
+ // SetDeviceOrigin() doesn't work here, so we need to manually
+ // translate all coordinates.
+ wxPoint translate(0,-top);
+ m_llist->Draw(*dc,top,bottom,wxLayoutObjectList::iterator(NULL),translate);
return true;
}
else
bool wxLayoutPrintout::OnBeginDocument(int startPage, int endPage)
{
- if (!wxPrintout::OnBeginDocument(startPage, endPage))
+ if (!wxPrintout::OnBeginDocument(startPage, endPage))
return false;
return true;
{
// ugly hack to get number of pages
wxPostScriptDC psdc("tmp.ps",false);
- int width,height;
- psdc.GetSize(&width, &height); // that's all we need it for
-
-
- // 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?
+ psdc.GetSize(&m_PageWidth, &m_PageHeight); // that's all we need it for
- *minPage = 0;
- *maxPage = (int)( m_llist->GetSize().y / (float)(0.9*height) + 0.5);
+ m_Margins.top = m_PageHeight / 10; // 10%
+ m_Margins.bottom = m_PageHeight - m_PageHeight / 10; // 90%
+ m_Margins.left = m_PageWidth / 10;
+ m_Margins.right = m_PageWidth - m_PageWidth / 10;
- *selPageFrom = 1;
- *selPageTo = *maxPage;
+ m_PageHeight = m_Margins.bottom - m_Margins.top - m_Margins.bottom;
+ m_PageWidth = m_Margins.right - m_Margins.left - m_Margins.right;
- m_maxPage = *maxPage;
+ m_NumOfPages = (int)( m_llist->GetSize().y / (float)(m_PageHeight) + 0.5);
+ *minPage = 1;
+ *maxPage = m_NumOfPages-1;
+
+ *selPageFrom = 1;
+ *selPageTo = m_NumOfPages-1;
}
bool wxLayoutPrintout::HasPage(int pageNum)
{
- if(m_maxPage != -1)
- return pageNum <= m_maxPage;
- return true;
+ return pageNum < m_NumOfPages;
}
/** Draws an object.
@param dc the wxDC to draw on
+ @param translation to be added to coordinates
*/
- virtual void Draw(wxDC & dc) {}
+ virtual void Draw(wxDC & dc, wxPoint const &translate) {}
/** Calculates and returns the size of the object.
@param baseLine pointer where to store the baseline position of
wxLayoutObjectText(const String &txt);
virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_TEXT; }
- virtual void Layout(wxDC &dc, wxPoint position, CoordType baseLine);
- virtual void Draw(wxDC &dc);
+ virtual void Layout(wxDC &dc, wxPoint position, CoordType
+ baseLine);
+
+ virtual void Draw(wxDC &dc, wxPoint const &translate);
/** This returns the height and in baseLine the position of the
text's baseline within it's box. This is needed to properly
align text objects.
virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_ICON; }
virtual void Layout(wxDC &dc, wxPoint position, CoordType baseLine);
- virtual void Draw(wxDC &dc);
+ virtual void Draw(wxDC &dc, wxPoint const &translate);
virtual wxPoint GetSize(CoordType *baseLine = NULL) const;
virtual bool IsDirty(void) const { return m_IsDirty; }
{
public:
virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_CMD; }
- virtual void Draw(wxDC &dc);
+ virtual void Draw(wxDC &dc, wxPoint const &translate);
virtual void Layout(wxDC &dc, wxPoint position, CoordType baseLine);
wxLayoutObjectCmd(int size, int family, int style, int weight,
bool underline,
class wxLayoutPrintout;
+class wxLayoutMargins
+{
+public:
+ wxLayoutMargins() { top = left = 0; bottom = right = -1; }
+ int top;
+ int left;
+ int bottom;
+ int right;
+};
+
/**
This class provides a high level abstraction to the wxFText
classes.
/** Re-layouts the list on a DC.
- @param findObject if true, return the object occupying the
- position specified by coords
- @param coords position where to find the object
- @param pageNo if > 0, print only that page of a document (for
- printing)
- @param reallyDraw set this to false if you don't want to draw but
- just calculate the coordinates
- @param hasDrawn set to true if a page has been printed
- @return if findObject == true, the object or NULL
+ @param dc the dc to layout for
+ @param margins if not NULL, use these top and left margins
*/
- void Layout(wxDC &dc);
+ void Layout(wxDC &dc, wxLayoutMargins *margins = NULL);
/** Draw the list on a given DC.
- @param pageNo if > 0, print only that page of a document (for
- printing)
+ @param dc the dc to layout for
+ @param fromLine the first graphics line from where to draw
+ @param toLine the last line at which to draw
+ @param start if != iterator(NULL) start drawing from here
*/
void Draw(wxDC &dc,
CoordType fromLine = -1,
CoordType toLine = -1,
- iterator start = iterator(NULL));
+ iterator start = iterator(NULL),
+ wxPoint const &translate = wxPoint(0,0));
/** Deletes at least to the end of line and redraws */
void EraseAndDraw(wxDC &dc, iterator start = iterator(NULL));
void Clear(int family = wxROMAN, int size=12, int style=wxNORMAL, int weight=wxNORMAL,
int underline=0, char const *fg="black", char const *bg="white");
- /// return a pointer to the default settings:
+ /// return a pointer to the default settings (dangerous, why?) FIXME:
wxLayoutObjectCmd const *GetDefaults(void) const { return m_DefaultSetting ; }
wxLayoutObjectList::iterator FindCurrentObject(CoordType *offset = NULL);
public:
wxLayoutPrintout(wxLayoutList &llist, wxString const & title = "My printout")
:wxPrintout(title)
- { m_llist = &llist; m_maxPage = 0; }
+ { m_llist = &llist; }
bool OnPrintPage(int page);
bool HasPage(int page);
bool OnBeginDocument(int startPage, int endPage);
void OnPreparePrinting(void);
private:
wxLayoutList *m_llist;
- int m_maxPage;
+ int m_PageHeight, m_PageWidth;
+ wxLayoutMargins m_Margins;
+ int m_NumOfPages;
};
#endif // WXLLIST_H