Printing moreless works now.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@912 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Karsten Ballüder 1998-10-25 11:08:43 +00:00
parent db828ab4cb
commit 07071479f2
2 changed files with 90 additions and 70 deletions

View File

@ -97,9 +97,9 @@ wxLayoutObjectText::GetSize(CoordType *baseLine) const
}
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;
}
@ -142,9 +142,9 @@ wxLayoutObjectIcon::wxLayoutObjectIcon(wxIcon *icon)
}
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
@ -203,7 +203,7 @@ wxLayoutObjectCmd::GetStyle(void) const
}
void
wxLayoutObjectCmd::Draw(wxDC &dc)
wxLayoutObjectCmd::Draw(wxDC &dc, wxPoint const &translate)
{
wxASSERT(m_font);
dc.SetFont(m_font);
@ -217,7 +217,7 @@ wxLayoutObjectCmd::Layout(wxDC &dc, wxPoint p, CoordType baseline)
{
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
@ -299,11 +299,11 @@ wxLayoutList::ResetSettings(wxDC &dc)
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;
@ -323,18 +323,17 @@ wxLayoutList::Layout(wxDC &dc)
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();
@ -380,7 +379,7 @@ wxLayoutList::Layout(wxDC &dc)
// 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
@ -407,22 +406,34 @@ wxLayoutList::Layout(wxDC &dc)
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 */
@ -446,7 +457,7 @@ wxLayoutList::EraseAndDraw(wxDC &dc, iterator start)
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());
}
@ -1096,17 +1107,15 @@ wxLayoutList::Find(wxPoint coords) const
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
@ -1115,7 +1124,7 @@ bool wxLayoutPrintout::OnPrintPage(int page)
bool wxLayoutPrintout::OnBeginDocument(int startPage, int endPage)
{
if (!wxPrintout::OnBeginDocument(startPage, endPage))
if (!wxPrintout::OnBeginDocument(startPage, endPage))
return false;
return true;
@ -1132,28 +1141,28 @@ void wxLayoutPrintout::GetPageInfo(int *minPage, int *maxPage, int *selPageFrom,
{
// 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;
m_PageHeight = m_Margins.bottom - m_Margins.top - m_Margins.bottom;
m_PageWidth = m_Margins.right - m_Margins.left - m_Margins.right;
m_NumOfPages = (int)( m_llist->GetSize().y / (float)(m_PageHeight) + 0.5);
*minPage = 1;
*maxPage = m_NumOfPages-1;
*selPageFrom = 1;
*selPageTo = *maxPage;
m_maxPage = *maxPage;
*selPageTo = m_NumOfPages-1;
}
bool wxLayoutPrintout::HasPage(int pageNum)
{
if(m_maxPage != -1)
return pageNum <= m_maxPage;
return true;
return pageNum < m_NumOfPages;
}

View File

@ -83,8 +83,9 @@ public:
/** 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
@ -140,8 +141,10 @@ public:
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.
@ -180,7 +183,7 @@ public:
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; }
@ -205,7 +208,7 @@ class wxLayoutObjectCmd : public wxLayoutObjectBase
{
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,
@ -234,6 +237,16 @@ public:
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.
@ -280,26 +293,22 @@ public:
/** 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));
@ -349,7 +358,7 @@ public:
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);
@ -425,7 +434,7 @@ class wxLayoutPrintout: public wxPrintout
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);
@ -434,7 +443,9 @@ class wxLayoutPrintout: public wxPrintout
void OnPreparePrinting(void);
private:
wxLayoutList *m_llist;
int m_maxPage;
int m_PageHeight, m_PageWidth;
wxLayoutMargins m_Margins;
int m_NumOfPages;
};
#endif // WXLLIST_H