added copying selection to clipboard; fixes to selection making

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@20858 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2003-06-02 20:14:31 +00:00
parent bb178b2971
commit 61233023a0
2 changed files with 74 additions and 17 deletions

View File

@@ -41,13 +41,8 @@ public:
m_fromCell(NULL), m_toCell(NULL) {} m_fromCell(NULL), m_toCell(NULL) {}
void Set(const wxPoint& fromPos, wxHtmlCell *fromCell, void Set(const wxPoint& fromPos, wxHtmlCell *fromCell,
const wxPoint& toPos, wxHtmlCell *toCell) const wxPoint& toPos, wxHtmlCell *toCell);
{ void Set(wxHtmlCell *fromCell, wxHtmlCell *toCell);
m_fromCell = fromCell;
m_toCell = toCell;
m_fromPos = fromPos;
m_toPos = toPos;
}
const wxHtmlCell *GetFromCell() const { return m_fromCell; } const wxHtmlCell *GetFromCell() const { return m_fromCell; }
const wxHtmlCell *GetToCell() const { return m_toCell; } const wxHtmlCell *GetToCell() const { return m_toCell; }
@@ -107,6 +102,8 @@ enum
}; };
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// wxHtmlCell // wxHtmlCell
// Internal data structure. It represents fragments of parsed // Internal data structure. It represents fragments of parsed
@@ -136,11 +133,14 @@ public:
// returns the link associated with this cell. The position is position // returns the link associated with this cell. The position is position
// within the cell so it varies from 0 to m_Width, from 0 to m_Height // within the cell so it varies from 0 to m_Width, from 0 to m_Height
virtual wxHtmlLinkInfo* GetLink(int WXUNUSED(x) = 0, int WXUNUSED(y) = 0) const virtual wxHtmlLinkInfo* GetLink(int WXUNUSED(x) = 0,
int WXUNUSED(y) = 0) const
{ return m_Link; } { return m_Link; }
// members access methods // return next cell among parent's cells
wxHtmlCell *GetNext() const {return m_Next;} wxHtmlCell *GetNext() const {return m_Next;}
// returns first child cell (if there are any, i.e. if this is container):
virtual wxHtmlCell* GetFirstChild() const { return NULL; }
// members writing methods // members writing methods
virtual void SetPos(int x, int y) {m_PosX = x, m_PosY = y;} virtual void SetPos(int x, int y) {m_PosX = x, m_PosY = y;}
@@ -229,6 +229,20 @@ public:
virtual wxHtmlCell *GetLastTerminal() const virtual wxHtmlCell *GetLastTerminal() const
{ return wxConstCast(this, wxHtmlCell); } { return wxConstCast(this, wxHtmlCell); }
// Returns cell's depth, i.e. how far under the root cell it is
// (if it is the root, depth is 0)
unsigned GetDepth() const;
// Returns true if the cell appears before 'cell' in natural order of
// cells (= as they are read). If cell A is (grand)parent of cell B,
// then both A.IsBefore(B) and B.IsBefore(A) always return true.
bool IsBefore(wxHtmlCell *cell) const;
// Converts the cell into text representation. If sel != NULL then
// only part of the cell inside the selection is converted.
virtual wxString ConvertToText(wxHtmlSelection *WXUNUSED(sel)) const
{ return wxEmptyString; }
protected: protected:
wxHtmlCell *m_Next; wxHtmlCell *m_Next;
// pointer to the next cell // pointer to the next cell
@@ -252,15 +266,15 @@ protected:
//-------------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Inherited cells: // Inherited cells:
//-------------------------------------------------------------------------------- // ----------------------------------------------------------------------------
//-------------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxHtmlWordCell // wxHtmlWordCell
// Single word in input stream. // Single word in input stream.
//-------------------------------------------------------------------------------- // ----------------------------------------------------------------------------
class WXDLLEXPORT wxHtmlWordCell : public wxHtmlCell class WXDLLEXPORT wxHtmlWordCell : public wxHtmlCell
{ {
@@ -268,6 +282,7 @@ public:
wxHtmlWordCell(const wxString& word, wxDC& dc); wxHtmlWordCell(const wxString& word, wxDC& dc);
void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2, void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2,
wxHtmlRenderingState& state); wxHtmlRenderingState& state);
wxString ConvertToText(wxHtmlSelection *sel) const;
protected: protected:
wxString m_Word; wxString m_Word;
@@ -329,8 +344,10 @@ public:
virtual void OnMouseClick(wxWindow *parent, int x, int y, const wxMouseEvent& event); virtual void OnMouseClick(wxWindow *parent, int x, int y, const wxMouseEvent& event);
virtual void GetHorizontalConstraints(int *left, int *right) const; virtual void GetHorizontalConstraints(int *left, int *right) const;
// returns pointer to the first cell in container or NULL virtual wxHtmlCell* GetFirstChild() const { return m_Cells; }
wxHtmlCell* GetFirstCell() const {return m_Cells;} #if WXWIN_COMPATIBILITY_2_4
wxDEPRECATED( wxHtmlCell* GetFirstCell() const );
#endif
// see comment in wxHtmlCell about this method // see comment in wxHtmlCell about this method
virtual bool IsTerminalCell() const { return FALSE; } virtual bool IsTerminalCell() const { return FALSE; }
@@ -374,14 +391,18 @@ protected:
DECLARE_NO_COPY_CLASS(wxHtmlContainerCell) DECLARE_NO_COPY_CLASS(wxHtmlContainerCell)
}; };
#if WXWIN_COMPATIBILITY_2_4
inline wxHtmlCell* wxHtmlContainerCell::GetFirstCell() const
{ return GetFirstChild(); }
#endif
//-------------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// wxHtmlColourCell // wxHtmlColourCell
// Color changer. // Color changer.
//-------------------------------------------------------------------------------- // ---------------------------------------------------------------------------
class WXDLLEXPORT wxHtmlColourCell : public wxHtmlCell class WXDLLEXPORT wxHtmlColourCell : public wxHtmlCell
{ {
@@ -490,6 +511,26 @@ private:
// ----------------------------------------------------------------------------
// wxHtmlTerminalCellsInterator
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxHtmlTerminalCellsInterator
{
public:
wxHtmlTerminalCellsInterator(const wxHtmlCell *from, const wxHtmlCell *to)
: m_to(to), m_pos(from) {}
operator bool() const { return m_pos; }
const wxHtmlCell* operator++();
const wxHtmlCell* operator->() const { return m_pos; }
const wxHtmlCell* operator*() const { return m_pos; }
private:
const wxHtmlCell *m_to, *m_pos;
};
#endif // wxUSE_HTML #endif // wxUSE_HTML

View File

@@ -213,6 +213,10 @@ protected:
void OnMouseDown(wxMouseEvent& event); void OnMouseDown(wxMouseEvent& event);
void OnMouseUp(wxMouseEvent& event); void OnMouseUp(wxMouseEvent& event);
void OnIdle(wxIdleEvent& event); void OnIdle(wxIdleEvent& event);
#if wxUSE_CLIPBOARD
void OnKeyUp(wxKeyEvent& event);
void OnCopy(wxCommandEvent& event);
#endif
// Returns new filter (will be stored into m_DefaultFilter variable) // Returns new filter (will be stored into m_DefaultFilter variable)
virtual wxHtmlFilter *GetDefaultFilter() {return new wxHtmlFilterPlainText;} virtual wxHtmlFilter *GetDefaultFilter() {return new wxHtmlFilterPlainText;}
@@ -224,6 +228,18 @@ protected:
// and wxHW_NO_SELECTION not used) // and wxHW_NO_SELECTION not used)
bool IsSelectionEnabled() const; bool IsSelectionEnabled() const;
// Convert selection to text:
wxString SelectionToText();
enum ClipboardType
{
Primary,
Secondary
};
// Copies selection to clipboard:
void CopySelection(ClipboardType t = Secondary);
protected: protected:
// This is pointer to the first cell in parsed data. // This is pointer to the first cell in parsed data.
// (Note: the first cell is usually top one = all other cells are sub-cells of this one) // (Note: the first cell is usually top one = all other cells are sub-cells of this one)