📄 textctrl.h
字号:
void DoDrawLineWrapMarks(wxDC& dc, const wxRect& rectUpdate);
// line/row geometry calculations
// ------------------------------
// get the extent (width) of the text
wxCoord GetTextWidth(const wxString& text) const;
// get the logical text width (accounting for scrolling)
wxCoord GetTotalWidth() const;
// get total number of rows (different from number of lines if the lines
// can be wrapped)
wxTextCoord GetRowCount() const;
// find the number of rows in this line (only if WrapLines())
wxTextCoord GetRowsPerLine(wxTextCoord line) const;
// get the starting row of the given line
wxTextCoord GetFirstRowOfLine(wxTextCoord line) const;
// get the row following this line
wxTextCoord GetRowAfterLine(wxTextCoord line) const;
// refresh functions
// -----------------
// the text area is the part of the window in which the text can be
// displayed, i.e. part of it inside the margins and the real text area is
// the area in which the text *is* currently displayed: for example, in the
// multiline control case the text area can have extra space at the bottom
// which is not tall enough for another line and which is then not included
// into the real text area
wxRect GetRealTextArea() const;
// refresh the text in the given (in logical coords) rect
void RefreshTextRect(const wxRect& rect, bool textOnly = TRUE);
// refresh the line wrap marks for the given range of lines (inclusive)
void RefreshLineWrapMarks(wxTextCoord rowFirst, wxTextCoord rowLast);
// refresh the text in the given range (in logical coords) of this line, if
// width is 0, refresh to the end of line
void RefreshPixelRange(wxTextCoord line, wxCoord start, wxCoord width);
// refresh the text in the given range (in text coords) in this line
void RefreshColRange(wxTextCoord line, wxTextPos start, size_t count);
// refresh the text from in the given line range (inclusive)
void RefreshLineRange(wxTextCoord lineFirst, wxTextCoord lineLast);
// refresh the text in the given range which can span multiple lines
// (this method accepts arguments in any order)
void RefreshTextRange(wxTextPos start, wxTextPos end);
// get the text to show: either the text itself or the text replaced with
// starts for wxTE_PASSWORD control
wxString GetTextToShow(const wxString& text) const;
// find the row in this line where the given position (counted from the
// start of line) is
wxTextCoord GetRowInLine(wxTextCoord line,
wxTextCoord col,
wxTextCoord *colRowStart = NULL) const;
// find the number of characters of a line before it wraps
// (and optionally also the real width of the line)
size_t GetPartOfWrappedLine(const wxChar* text,
wxCoord *widthReal = NULL) const;
// get the start and end of the selection for this line: if the line is
// outside the selection, both will be -1 and FALSE will be returned
bool GetSelectedPartOfLine(wxTextCoord line,
wxTextPos *start, wxTextPos *end) const;
// update the text rect: the zone inside our client rect (its coords are
// client coords) which contains the text
void UpdateTextRect();
// calculate the last visible position
void UpdateLastVisible();
// move caret to the given position unconditionally
// (SetInsertionPoint() does nothing if the position didn't change)
void DoSetInsertionPoint(wxTextPos pos);
// move caret to the new position without updating the display (for
// internal use only)
void MoveInsertionPoint(wxTextPos pos);
// set the caret to its initial (default) position
void InitInsertionPoint();
// get the width of the longest line in pixels
wxCoord GetMaxWidth() const;
// force recalculation of the max line width
void RecalcMaxWidth();
// update the max width after the given line was modified
void UpdateMaxWidth(wxTextCoord line);
// hit testing
// -----------
// HitTest2() is more efficient than 2 consecutive HitTest()s with the same
// line (i.e. y) and it also returns the offset of the starting position in
// pixels
//
// as the last hack, this function accepts either logical or device (by
// default) coords depending on devCoords flag
wxTextCtrlHitTestResult HitTest2(wxCoord y,
wxCoord x1,
wxCoord x2,
wxTextCoord *row,
wxTextCoord *colStart,
wxTextCoord *colEnd,
wxTextCoord *colRowStart,
bool devCoords = TRUE) const;
// HitTest() version which takes the logical text coordinates and not the
// device ones
wxTextCtrlHitTestResult HitTestLogical(const wxPoint& pos,
wxTextCoord *col,
wxTextCoord *row) const;
// get the line and the row in this line corresponding to the given row,
// return TRUE if ok and FALSE if row is out of range
//
// NB: this function can only be called for controls which wrap lines
bool GetLineAndRow(wxTextCoord row,
wxTextCoord *line,
wxTextCoord *rowInLine) const;
// get the height of one line (the same for all lines)
wxCoord GetLineHeight() const
{
// this one should be already precalculated
wxASSERT_MSG( m_heightLine != -1, _T("should have line height") );
return m_heightLine;
}
// get the average char width
wxCoord GetAverageWidth() const { return m_widthAvg; }
// recalc the line height and char width (to call when the font changes)
void RecalcFontMetrics();
// vertical scrolling helpers
// --------------------------
// all these functions are for multi line controls only
// get the number of visible lines
size_t GetLinesPerPage() const;
// return the position above the cursor or INVALID_POS_VALUE
wxTextPos GetPositionAbove();
// return the position below the cursor or INVALID_POS_VALUE
wxTextPos GetPositionBelow();
// event handlers
// --------------
void OnIdle(wxIdleEvent& event);
void OnChar(wxKeyEvent& event);
void OnSize(wxSizeEvent& event);
// overrdie wxScrollHelper method to prevent (auto)scrolling beyond the end
// of line
virtual bool SendAutoScrollEvents(wxScrollWinEvent& event) const;
// return the struct containing control-type dependent data
struct wxTextSingleLineData& SData() { return *m_data.sdata; }
struct wxTextMultiLineData& MData() { return *m_data.mdata; }
struct wxTextWrappedData& WData() { return *m_data.wdata; }
const wxTextSingleLineData& SData() const { return *m_data.sdata; }
const wxTextMultiLineData& MData() const { return *m_data.mdata; }
const wxTextWrappedData& WData() const { return *m_data.wdata; }
// clipboard operations (unlike the versions without Do prefix, they have a
// return code)
bool DoCut();
bool DoPaste();
private:
// all these methods are for multiline text controls only
// update the scrollbars (only called from OnIdle)
void UpdateScrollbars();
// get read only access to the lines of multiline control
inline const wxArrayString& GetLines() const;
inline size_t GetLineCount() const;
// replace a line (returns TRUE if the number of rows in thel ine changed)
bool ReplaceLine(wxTextCoord line, const wxString& text);
// remove a line
void RemoveLine(wxTextCoord line);
// insert a line at this position
void InsertLine(wxTextCoord line, const wxString& text);
// calculate geometry of this line
void LayoutLine(wxTextCoord line, class wxWrappedLineData& lineData) const;
// calculate geometry of all lines until the given one
void LayoutLines(wxTextCoord lineLast) const;
// the initially specified control size
wxSize m_sizeInitial;
// the global control text
wxString m_value;
// current position
wxTextPos m_curPos;
wxTextCoord m_curCol,
m_curRow;
// last position (only used by GetLastPosition())
wxTextPos m_posLast;
// selection
wxTextPos m_selAnchor,
m_selStart,
m_selEnd;
// flags
bool m_isModified:1,
m_isEditable:1,
m_hasCaret:1;
// the rectangle (in client coordinates) to draw text inside
wxRect m_rectText;
// the height of one line (cached value of GetCharHeight)
wxCoord m_heightLine;
// and the average char width (cached value of GetCharWidth)
wxCoord m_widthAvg;
// we have some data which depends on the kind of control (single or multi
// line)
union
{
wxTextSingleLineData *sdata;
wxTextMultiLineData *mdata;
wxTextWrappedData *wdata;
void *data;
} m_data;
// the object to which we delegate our undo/redo implementation
wxTextCtrlCommandProcessor *m_cmdProcessor;
DECLARE_EVENT_TABLE()
DECLARE_DYNAMIC_CLASS(wxTextCtrl)
};
// ----------------------------------------------------------------------------
// wxStdTextCtrlInputHandler: this control handles only the mouse/kbd actions
// common to Win32 and GTK, platform-specific things are implemented elsewhere
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxStdTextCtrlInputHandler : public wxStdInputHandler
{
public:
wxStdTextCtrlInputHandler(wxInputHandler *inphand);
virtual bool HandleKey(wxInputConsumer *consumer,
const wxKeyEvent& event,
bool pressed);
virtual bool HandleMouse(wxInputConsumer *consumer,
const wxMouseEvent& event);
virtual bool HandleMouseMove(wxInputConsumer *consumer,
const wxMouseEvent& event);
virtual bool HandleFocus(wxInputConsumer *consumer, const wxFocusEvent& event);
protected:
// get the position of the mouse click
static wxTextPos HitTest(const wxTextCtrl *text, const wxPoint& pos);
// capture data
wxTextCtrl *m_winCapture;
};
#endif // _WX_UNIV_TEXTCTRL_H_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -