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 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; m_IsDirty = false;
} }
@@ -142,9 +142,9 @@ wxLayoutObjectIcon::wxLayoutObjectIcon(wxIcon *icon)
} }
void 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
@@ -203,7 +203,7 @@ wxLayoutObjectCmd::GetStyle(void) const
} }
void void
wxLayoutObjectCmd::Draw(wxDC &dc) wxLayoutObjectCmd::Draw(wxDC &dc, wxPoint const &translate)
{ {
wxASSERT(m_font); wxASSERT(m_font);
dc.SetFont(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 m_Position = p; // required so we can find the right object for cursor
// this get called, so that recalculation uses right font sizes // this get called, so that recalculation uses right font sizes
Draw(dc); Draw(dc,wxPoint(0,0));
} }
//-------------------------- wxLayoutList //-------------------------- wxLayoutList
@@ -299,11 +299,11 @@ wxLayoutList::ResetSettings(wxDC &dc)
dc.SetBackgroundMode( wxSOLID ); // to enable setting of text background dc.SetBackgroundMode( wxSOLID ); // to enable setting of text background
dc.SetFont( *wxNORMAL_FONT ); dc.SetFont( *wxNORMAL_FONT );
if(m_DefaultSetting) if(m_DefaultSetting)
m_DefaultSetting->Draw(dc); m_DefaultSetting->Draw(dc,wxPoint(0,0));
} }
void void
wxLayoutList::Layout(wxDC &dc) wxLayoutList::Layout(wxDC &dc, wxLayoutMargins *margins)
{ {
iterator i; iterator i;
@@ -323,18 +323,17 @@ wxLayoutList::Layout(wxDC &dc)
wxLayoutObjectBase *cursorObject = NULL; // let's find it again wxLayoutObjectBase *cursorObject = NULL; // let's find it again
struct if(margins)
{ {
int top, bottom, left, right; position.y = margins->top;
} margins; position.x = margins->left;
}
margins.top = 0; margins.left = 0; else
margins.right = -1; {
margins.bottom = -1; position.y = 0;
position.x = 0;
}
position.y = margins.top;
position.x = margins.left;
ResetSettings(dc); ResetSettings(dc);
i = begin(); i = begin();
@@ -380,7 +379,7 @@ wxLayoutList::Layout(wxDC &dc)
// now check whether we have finished handling this line: // now check whether we have finished handling this line:
if(type == WXLO_TYPE_LINEBREAK && i != tail()) if(type == WXLO_TYPE_LINEBREAK && i != tail())
{ {
position.x = margins.left; position.x = margins ? margins->left : 0;
position.y += baseLineSkip; position.y += baseLineSkip;
baseLine = m_FontPtSize; baseLine = m_FontPtSize;
objBaseLine = baseLine; // not all objects set it objBaseLine = baseLine; // not all objects set it
@@ -407,22 +406,34 @@ wxLayoutList::Layout(wxDC &dc)
void void
wxLayoutList::Draw(wxDC &dc, wxLayoutList::Draw(wxDC &dc,
CoordType fromLine, CoordType toLine, CoordType fromLine, CoordType toLine,
iterator start) iterator start,
wxPoint const &translate)
{ {
Layout(dc); // FIXME just for now Layout(dc); // FIXME just for now
ResetSettings(dc); ResetSettings(dc);
wxLayoutObjectList::iterator i; wxLayoutObjectList::iterator i;
if(start == iterator(NULL)) if(start == iterator(NULL))
start = begin(); start = begin();
else // we need to restore font settings
while( i != end() && (**i).GetPosition().y < fromLine) {
i++; 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 ; for( i = start ;
i != end() && (toLine == -1 || (**i).GetPosition().y < toLine) ; i != end() && (toLine == -1 || (**i).GetPosition().y < toLine) ;
i++ ) i++ )
(*i)->Draw(dc); (*i)->Draw(dc,translate);
} }
/** Erase at least to end of line */ /** Erase at least to end of line */
@@ -446,7 +457,7 @@ wxLayoutList::EraseAndDraw(wxDC &dc, iterator start)
dc.SetBrush(*wxWHITE_BRUSH); dc.SetBrush(*wxWHITE_BRUSH);
dc.SetPen(wxPen(*wxWHITE,0,wxTRANSPARENT)); dc.SetPen(wxPen(*wxWHITE,0,wxTRANSPARENT));
dc.DrawRectangle(p.x,p.y,2000,2000); //dc.MaxX(),dc.MaxY()); 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()); //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) bool wxLayoutPrintout::OnPrintPage(int page)
{ {
wxDC *dc = GetDC(); wxDC *dc = GetDC();
int top, bottom,width,height;
if (dc) if (dc)
{ {
dc->GetSize(&width, &height); int top, bottom;
top = (page - 1)*m_PageHeight;
top = (page - 1) * (9*height)/10; bottom = top + m_PageHeight;
bottom = top + (9*height)/10; // SetDeviceOrigin() doesn't work here, so we need to manually
// translate all coordinates.
if( top >= m_llist->GetSize().y) wxPoint translate(0,-top);
return false; m_llist->Draw(*dc,top,bottom,wxLayoutObjectList::iterator(NULL),translate);
m_llist->Draw(*dc,top,bottom);
return true; return true;
} }
else else
@@ -1115,7 +1124,7 @@ bool wxLayoutPrintout::OnPrintPage(int page)
bool wxLayoutPrintout::OnBeginDocument(int startPage, int endPage) bool wxLayoutPrintout::OnBeginDocument(int startPage, int endPage)
{ {
if (!wxPrintout::OnBeginDocument(startPage, endPage)) if (!wxPrintout::OnBeginDocument(startPage, endPage))
return false; return false;
return true; return true;
@@ -1132,28 +1141,28 @@ void wxLayoutPrintout::GetPageInfo(int *minPage, int *maxPage, int *selPageFrom,
{ {
// ugly hack to get number of pages // ugly hack to get number of pages
wxPostScriptDC psdc("tmp.ps",false); wxPostScriptDC psdc("tmp.ps",false);
int width,height; psdc.GetSize(&m_PageWidth, &m_PageHeight); // that's all we need it for
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?
*minPage = 0; m_Margins.top = m_PageHeight / 10; // 10%
*maxPage = (int)( m_llist->GetSize().y / (float)(0.9*height) + 0.5); 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; *selPageFrom = 1;
*selPageTo = *maxPage; *selPageTo = m_NumOfPages-1;
m_maxPage = *maxPage;
} }
bool wxLayoutPrintout::HasPage(int pageNum) bool wxLayoutPrintout::HasPage(int pageNum)
{ {
if(m_maxPage != -1) return pageNum < m_NumOfPages;
return pageNum <= m_maxPage;
return true;
} }

View File

@@ -83,8 +83,9 @@ public:
/** Draws an object. /** Draws an object.
@param dc the wxDC to draw on @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. /** Calculates and returns the size of the object.
@param baseLine pointer where to store the baseline position of @param baseLine pointer where to store the baseline position of
@@ -140,8 +141,10 @@ public:
wxLayoutObjectText(const String &txt); wxLayoutObjectText(const String &txt);
virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_TEXT; } virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_TEXT; }
virtual void Layout(wxDC &dc, wxPoint position, CoordType baseLine); virtual void Layout(wxDC &dc, wxPoint position, CoordType
virtual void Draw(wxDC &dc); baseLine);
virtual void Draw(wxDC &dc, wxPoint const &translate);
/** This returns the height and in baseLine the position of the /** This returns the height and in baseLine the position of the
text's baseline within it's box. This is needed to properly text's baseline within it's box. This is needed to properly
align text objects. align text objects.
@@ -180,7 +183,7 @@ public:
virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_ICON; } virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_ICON; }
virtual void Layout(wxDC &dc, wxPoint position, CoordType baseLine); 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 wxPoint GetSize(CoordType *baseLine = NULL) const;
virtual bool IsDirty(void) const { return m_IsDirty; } virtual bool IsDirty(void) const { return m_IsDirty; }
@@ -205,7 +208,7 @@ class wxLayoutObjectCmd : public wxLayoutObjectBase
{ {
public: public:
virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_CMD; } 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); virtual void Layout(wxDC &dc, wxPoint position, CoordType baseLine);
wxLayoutObjectCmd(int size, int family, int style, int weight, wxLayoutObjectCmd(int size, int family, int style, int weight,
bool underline, bool underline,
@@ -234,6 +237,16 @@ public:
class wxLayoutPrintout; 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 This class provides a high level abstraction to the wxFText
classes. classes.
@@ -280,26 +293,22 @@ public:
/** Re-layouts the list on a DC. /** Re-layouts the list on a DC.
@param findObject if true, return the object occupying the @param dc the dc to layout for
position specified by coords @param margins if not NULL, use these top and left margins
@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
*/ */
void Layout(wxDC &dc); void Layout(wxDC &dc, wxLayoutMargins *margins = NULL);
/** Draw the list on a given DC. /** Draw the list on a given DC.
@param pageNo if > 0, print only that page of a document (for @param dc the dc to layout for
printing) @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, void Draw(wxDC &dc,
CoordType fromLine = -1, CoordType fromLine = -1,
CoordType toLine = -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 */ /** Deletes at least to the end of line and redraws */
void EraseAndDraw(wxDC &dc, iterator start = iterator(NULL)); 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, 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"); 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 ; } wxLayoutObjectCmd const *GetDefaults(void) const { return m_DefaultSetting ; }
wxLayoutObjectList::iterator FindCurrentObject(CoordType *offset = NULL); wxLayoutObjectList::iterator FindCurrentObject(CoordType *offset = NULL);
@@ -425,7 +434,7 @@ class wxLayoutPrintout: public wxPrintout
public: public:
wxLayoutPrintout(wxLayoutList &llist, wxString const & title = "My printout") wxLayoutPrintout(wxLayoutList &llist, wxString const & title = "My printout")
:wxPrintout(title) :wxPrintout(title)
{ m_llist = &llist; m_maxPage = 0; } { m_llist = &llist; }
bool OnPrintPage(int page); bool OnPrintPage(int page);
bool HasPage(int page); bool HasPage(int page);
bool OnBeginDocument(int startPage, int endPage); bool OnBeginDocument(int startPage, int endPage);
@@ -434,7 +443,9 @@ class wxLayoutPrintout: public wxPrintout
void OnPreparePrinting(void); void OnPreparePrinting(void);
private: private:
wxLayoutList *m_llist; wxLayoutList *m_llist;
int m_maxPage; int m_PageHeight, m_PageWidth;
wxLayoutMargins m_Margins;
int m_NumOfPages;
}; };
#endif // WXLLIST_H #endif // WXLLIST_H