Partially functioning selections.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2376 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -24,7 +24,6 @@
|
||||
|
||||
#ifdef M_BASEDIR
|
||||
# include "gui/wxllist.h"
|
||||
# include "gui/wxMDialogs.h"
|
||||
#else
|
||||
# include "wxllist.h"
|
||||
#endif
|
||||
@@ -109,6 +108,23 @@ bool Contains(const wxRect &r, const wxPoint &p)
|
||||
{
|
||||
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);
|
||||
}
|
||||
//@}
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
@@ -147,9 +163,33 @@ wxLayoutObjectText::GetSize(CoordType *top, CoordType *bottom) const
|
||||
}
|
||||
|
||||
void
|
||||
wxLayoutObjectText::Draw(wxDC &dc, wxPoint const &coords)
|
||||
wxLayoutObjectText::Draw(wxDC &dc, wxPoint const &coords,
|
||||
CoordType begin, CoordType end)
|
||||
{
|
||||
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
|
||||
@@ -222,8 +262,12 @@ wxLayoutObjectIcon::wxLayoutObjectIcon(wxBitmap *icon)
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -296,7 +340,8 @@ wxLayoutObjectCmd::GetStyle(wxLayoutStyleInfo *si) const
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -637,10 +682,35 @@ wxLayoutLine::Draw(wxDC &dc,
|
||||
|
||||
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++)
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1486,6 +1556,14 @@ wxLayoutList::EndSelection(void)
|
||||
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
|
||||
@@ -1501,6 +1579,44 @@ wxLayoutList::IsSelected(const wxPoint &cursor)
|
||||
&& 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
|
||||
@@ -1530,16 +1646,10 @@ wxLayoutPrintout::wxLayoutPrintout(wxLayoutList *llist,
|
||||
{
|
||||
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
|
||||
@@ -1594,12 +1704,6 @@ wxLayoutPrintout::ScaleDC(wxDC *dc)
|
||||
|
||||
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);
|
||||
@@ -1650,12 +1754,6 @@ void wxLayoutPrintout::GetPageInfo(int *minPage, int *maxPage, int *selPageFrom,
|
||||
*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)
|
||||
|
@@ -111,8 +111,13 @@ public:
|
||||
/** 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
|
||||
@@ -187,7 +192,9 @@ public:
|
||||
|
||||
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
|
||||
@@ -244,7 +251,9 @@ public:
|
||||
|
||||
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
|
||||
@@ -288,7 +297,9 @@ class wxLayoutObjectCmd : public wxLayoutObject
|
||||
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);
|
||||
@@ -435,11 +446,11 @@ public:
|
||||
/** 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 */
|
||||
@@ -820,6 +831,17 @@ public:
|
||||
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
|
||||
@@ -938,10 +960,6 @@ private:
|
||||
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
|
||||
};
|
||||
|
||||
|
||||
|
@@ -148,6 +148,27 @@ wxString wxLayoutExportCmdAsHTML(wxLayoutObjectCmd const & cmd,
|
||||
|
||||
|
||||
|
||||
wxLayoutExportStatus::wxLayoutExportStatus(wxLayoutList *list,
|
||||
wxPoint fromPos,
|
||||
wxPoint toPos)
|
||||
{
|
||||
list->GetDefaults()->GetStyle(&m_si);
|
||||
m_line = list->GetFirstLine();
|
||||
m_iterator = m_line->GetFirstObject();
|
||||
m_fromPos = fromPos;
|
||||
m_toPos = toPos;
|
||||
|
||||
if(m_fromPos != wxLayoutExportNoPosition)
|
||||
{
|
||||
while(m_line && (*m_line)->GetLineNumber() != m_fromPos.y)
|
||||
m_line->GetNextLine();
|
||||
wxASSERT(m_line);
|
||||
m_iterator = (**i).FindObject(fromPos.x);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#define WXLO_IS_TEXT(type) \
|
||||
( type == WXLO_TYPE_TEXT \
|
||||
|| (type == WXLO_TYPE_CMD \
|
||||
@@ -155,6 +176,8 @@ wxString wxLayoutExportCmdAsHTML(wxLayoutObjectCmd const & cmd,
|
||||
|
||||
|
||||
|
||||
extern const wxPoint wxLayoutExportNoPosition = wxPoint(-1,-1);
|
||||
|
||||
wxLayoutExportObject *wxLayoutExport(wxLayoutExportStatus *status,
|
||||
int mode, int flags)
|
||||
{
|
||||
@@ -197,7 +220,6 @@ wxLayoutExportObject *wxLayoutExport(wxLayoutExportStatus *status,
|
||||
|
||||
wxString *str = new wxString();
|
||||
// text must be concatenated
|
||||
int testf = WXLO_EXPORT_WITH_CRLF;
|
||||
for(;;)
|
||||
{
|
||||
while(status->m_iterator == NULLIT)
|
||||
|
@@ -52,21 +52,21 @@ struct wxLayoutExportObject
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
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,
|
||||
@@ -74,7 +74,8 @@ 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,
|
||||
@@ -83,8 +84,8 @@ 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
|
||||
|
Reference in New Issue
Block a user