#ifdef M_BASEDIR
# include "gui/wxllist.h"
-# include "gui/wxMDialogs.h"
#else
# include "wxllist.h"
#endif
{
return r.x <= p.x && r.y <= p.y && (r.x+r.width) >= p.x && (r.y + r.height) >= p.y;
}
+
+
+/// Starts highlighting the selection
+static
+inline void StartHighlighting(wxDC &dc)
+{
+ dc.SetBrush(*wxBLACK_BRUSH);
+ dc.SetPen(wxPen(*wxBLACK,1,wxSOLID));
+ dc.SetLogicalFunction(wxINVERT);
+}
+
+/// Ends highlighting the selection
+static
+inline void EndHighlighting(wxDC &dc)
+{
+ dc.SetLogicalFunction(wxCOPY);
+}
//@}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
}
void
-wxLayoutObjectText::Draw(wxDC &dc, wxPoint const &coords)
+wxLayoutObjectText::Draw(wxDC &dc, wxPoint const &coords,
+ CoordType begin, CoordType end)
{
- dc.DrawText(m_Text, coords.x, coords.y-m_Top);
+ if(begin == -1)
+ dc.DrawText(m_Text, coords.x, coords.y-m_Top);
+ else
+ {
+ // highlight the bit between begin and len
+ wxString str;
+ CoordType
+ xpos = coords.x,
+ ypos = coords.y-m_Top;
+ long width, height, descent;
+
+ str = m_Text.Mid(0, begin);
+ dc.DrawText(str, xpos, ypos);
+ dc.GetTextExtent(str, &width, &height, &descent);
+ xpos += width;
+ StartHighlighting(dc);
+ str = m_Text.Mid(begin, end-begin);
+ dc.DrawText(str, xpos, ypos);
+ dc.GetTextExtent(str, &width, &height, &descent);
+ xpos += width;
+ dc.SetLogicalFunction(wxCOPY);
+ str = m_Text.Mid(end, m_Text.Length()-end);
+ dc.DrawText(str, xpos, ypos);
+ }
}
CoordType
}
void
-wxLayoutObjectIcon::Draw(wxDC &dc, wxPoint const &coords)
+wxLayoutObjectIcon::Draw(wxDC &dc, wxPoint const &coords,
+ CoordType begin, CoordType /* len */)
{
+ if(begin == 0)
+ StartHighlighting(dc);
+
dc.DrawBitmap(*m_Icon, coords.x, coords.y-m_Icon->GetHeight(),
(m_Icon->GetMask() == NULL) ? FALSE : TRUE);
}
}
void
-wxLayoutObjectCmd::Draw(wxDC &dc, wxPoint const & /* coords */)
+wxLayoutObjectCmd::Draw(wxDC &dc, wxPoint const & /* coords */,
+ CoordType begin, CoordType /* len */)
{
wxASSERT(m_font);
dc.SetFont(*m_font);
pos = pos + GetPosition();
pos.y += m_BaseLine;
-
+
+ CoordType xpos = 0; // cursorpos, lenght of line
+
+ CoordType from, to, tempto;
+ int highlight = llist->IsSelected(this, &from, &to);
+ if(highlight == 1) // we need to draw the whole line inverted!
+ StartHighlighting(dc);
+ else
+ EndHighlighting(dc);
+
for(i = m_ObjectList.begin(); i != NULLIT; i++)
{
- (**i).Draw(dc, pos);
+ if(highlight == -1) // partially highlight line
+ {
+ // parts of the line need highlighting
+ tempto = xpos+(**i).GetLength();
+ if(tempto >= from && tempto <= to)
+ {
+ tempto = to-xpos;
+ if(tempto > (**i).GetLength())
+ tempto = (**i).GetLength();
+ (**i).Draw(dc, pos, from-xpos, to);
+ }
+ else
+ EndHighlighting(dc);
+ }
+ else
+ (**i).Draw(dc, pos);
pos.x += (**i).GetWidth();
+ xpos += (**i).GetLength();
}
}
m_Selection.m_CursorB = m_CursorPos;
m_Selection.m_selecting = false;
m_Selection.m_valid = true;
+
+ // We always want m_CursorA <= m_CursorB!
+ if(! (m_Selection.m_CursorA <= m_Selection.m_CursorB))
+ {
+ wxPoint help = m_Selection.m_CursorB;
+ m_Selection.m_CursorB = m_Selection.m_CursorA;
+ m_Selection.m_CursorA = help;
+ }
}
bool
&& cursor <= m_Selection.m_CursorB;
}
+
+/** Tests whether this layout line is selected and needs
+ highlighting.
+ @param line to test for
+ @return 0 = not selected, 1 = fully selected, -1 = partially
+ selected
+ */
+int
+wxLayoutList::IsSelected(const wxLayoutLine *line, CoordType *from,
+ CoordType *to)
+{
+ wxASSERT(line); wxASSERT(to); wxASSERT(from);
+
+ CoordType y = line->GetLineNumber();
+ if(m_Selection.m_CursorA.y < y && m_Selection.m_CursorB.y > y)
+ return 1;
+ else if(m_Selection.m_CursorA.y == y)
+ {
+ *from = m_Selection.m_CursorA.x;
+ if(m_Selection.m_CursorB.y == y)
+ *to = m_Selection.m_CursorB.x;
+ else
+ *to = line->GetLength();
+ return -1;
+ }
+ else if(m_Selection.m_CursorB.y == y)
+ {
+ *to = m_Selection.m_CursorB.x;
+ if(m_Selection.m_CursorA.y == y)
+ *from = m_Selection.m_CursorA.x;
+ else
+ *from = 0;
+ return -1;
+ }
+ else
+ return 0;
+}
+
#ifdef WXLAYOUT_DEBUG
void
{
m_llist = llist;
m_title = title;
-#ifdef M_BASEDIR
- m_ProgressDialog = NULL;
-#endif
}
wxLayoutPrintout::~wxLayoutPrintout()
{
-#ifdef M_BASEDIR
- if(m_ProgressDialog) delete m_ProgressDialog;
-#endif
}
float
bool wxLayoutPrintout::OnPrintPage(int page)
{
-#ifdef M_BASEDIR
- wxString msg;
- msg.Printf(_("Printing page %d..."), page);
- if(! m_ProgressDialog->Update(page, msg))
- return false;
-#endif
wxDC *dc = GetDC();
ScaleDC(dc);
*selPageFrom = 1;
*selPageTo = m_NumOfPages;
wxRemoveFile(WXLLIST_TEMPFILE);
-
-#ifdef M_BASEDIR
- m_ProgressDialog = new MProgressDialog(
- title, _("Printing..."),m_NumOfPages, NULL, false, true);
-#endif
-
}
bool wxLayoutPrintout::HasPage(int pageNum)
/** Draws an object.
@param dc the wxDC to draw on
@param coords where to draw the baseline of the object.
+ @param begin if !=-1, from which position on to highlight it
+ @param end if begin !=-1, how many positions to highlight it
*/
- virtual void Draw(wxDC & /* dc */, wxPoint const & /* coords */) { }
+ virtual void Draw(wxDC & /* dc */,
+ wxPoint const & /* coords */,
+ CoordType begin = -1,
+ CoordType end = -1) { }
/** Calculates and returns the size of the object.
@param top where to store height above baseline
virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_TEXT; }
virtual void Layout(wxDC &dc);
- virtual void Draw(wxDC &dc, wxPoint const &coords);
+ virtual void Draw(wxDC &dc, wxPoint const &coords,
+ CoordType begin = -1,
+ CoordType end = -1);
/** Calculates and returns the size of the object.
@param top where to store height above baseline
@param bottom where to store height below baseline
virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_ICON; }
virtual void Layout(wxDC &dc);
- virtual void Draw(wxDC &dc, wxPoint const &coords);
+ virtual void Draw(wxDC &dc, wxPoint const &coords,
+ CoordType begin = -1,
+ CoordType end = -1);
/** Calculates and returns the size of the object.
@param top where to store height above baseline
public:
virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_CMD; }
virtual void Layout(wxDC &dc);
- virtual void Draw(wxDC &dc, wxPoint const &coords);
+ virtual void Draw(wxDC &dc, wxPoint const &coords,
+ CoordType begin = -1,
+ CoordType end = -1);
wxLayoutObjectCmd(int size, int family, int style, int weight,
bool underline,
wxColour &fg, wxColour &bg);
/** Return the line number of this line.
@return the line number
*/
- CoordType GetLineNumber(void) const { return m_LineNumber; }
+ inline CoordType GetLineNumber(void) const { return m_LineNumber; }
/** Return the length of the line.
@return line lenght in cursor positions
*/
- CoordType GetLength(void) const { return m_Length; }
+ inline CoordType GetLength(void) const { return m_Length; }
//@}
/**@name Drawing and Layout */
bool IsSelecting(void);
bool IsSelected(const wxPoint &cursor);
+ /** Tests whether this layout line is selected and needs
+ highlighting.
+ @param line to test for
+ @param from set to first cursorpos to be highlighted (for returncode == -1)
+ @param to set to last cursorpos to be highlighted (for returncode == -1)
+ @return 0 = not selected, 1 = fully selected, -1 = partially
+ selected
+
+ */
+ int IsSelected(const wxLayoutLine *line, CoordType *from, CoordType *to);
+
#ifdef WXLAYOUT_DEBUG
void Debug(void);
#endif
int m_NumOfPages;
/// Top left corner where we start printing.
wxPoint m_Offset;
-#ifdef M_BASEDIR
- /// A progress dialog for printing
- MProgressDialog *m_ProgressDialog;
-#endif
};
}
};
+
+extern const wxPoint wxLayoutExportNoPosition;
+
struct wxLayoutExportStatus
{
- wxLayoutExportStatus(wxLayoutList *list)
- {
- list->GetDefaults()->GetStyle(&m_si);
- m_line = list->GetFirstLine();
- m_iterator = m_line->GetFirstObject();
- }
-
+ wxLayoutExportStatus(wxLayoutList *list,
+ wxPoint fromPos = wxLayoutExportNoPosition,
+ wxPoint toPos = wxLayoutExportNoPosition);
wxLayoutLine * m_line;
wxLOiterator m_iterator;
wxLayoutStyleInfo m_si;
+ wxPoint m_fromPos;
+ wxPoint m_toPos;
};
-
#ifdef OS_WIN
/// import text into a wxLayoutList (including linefeeds):
void wxLayoutImportText(wxLayoutList *list, wxString const &str,
wxLayoutExportObject *wxLayoutExport(wxLayoutExportStatus *status,
int mode = WXLO_EXPORT_AS_TEXT,
- int flags = WXLO_EXPORT_WITH_CRLF);
+ int flags =
+ WXLO_EXPORT_WITH_CRLF);
#else
/// import text into a wxLayoutList (including linefeeds):
void wxLayoutImportText(wxLayoutList *list, wxString const &str,
/// export text in a given format
wxLayoutExportObject *wxLayoutExport(wxLayoutExportStatus *status,
int mode = WXLO_EXPORT_AS_TEXT,
- int flags = WXLO_EXPORT_WITH_LF_ONLY
- );
+ int flags =
+ WXLO_EXPORT_WITH_LF_ONLY);
#endif
#endif //WXLPARSER_H