X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9c4cb6116779e9fc7bcb7009ef0aa6047d2f8874..77ba5c12cb3346639944fe7d0b47bb38ad3310e4:/include/wx/textctrl.h diff --git a/include/wx/textctrl.h b/include/wx/textctrl.h index 415639287c..57dfeb79b4 100644 --- a/include/wx/textctrl.h +++ b/include/wx/textctrl.h @@ -1,6 +1,6 @@ /////////////////////////////////////////////////////////////////////////////// // Name: wx/textctrl.h -// Purpose: wxTextCtrlBase class - the interface of wxTextCtrl +// Purpose: wxTextAttr and wxTextCtrlBase class - the interface of wxTextCtrl // Author: Vadim Zeitlin // Modified by: // Created: 13.07.99 @@ -28,7 +28,6 @@ // some compilers don't have standard compliant rdbuf() (and MSVC has it only // in its new iostream library, not in the old one used with iostream.h) #if defined(__WATCOMC__) || \ - defined(__MWERKS__) || \ ((defined(__VISUALC5__) || defined(__VISUALC6__)) && wxUSE_IOSTREAMH) #define wxHAS_TEXT_WINDOW_STREAM 0 #elif wxUSE_STD_IOSTREAM @@ -165,32 +164,43 @@ enum wxTextAttrFlags { wxTEXT_ATTR_TEXT_COLOUR = 0x00000001, wxTEXT_ATTR_BACKGROUND_COLOUR = 0x00000002, + wxTEXT_ATTR_FONT_FACE = 0x00000004, - wxTEXT_ATTR_FONT_SIZE = 0x00000008, + wxTEXT_ATTR_FONT_POINT_SIZE = 0x00000008, + wxTEXT_ATTR_FONT_PIXEL_SIZE = 0x10000000, wxTEXT_ATTR_FONT_WEIGHT = 0x00000010, wxTEXT_ATTR_FONT_ITALIC = 0x00000020, wxTEXT_ATTR_FONT_UNDERLINE = 0x00000040, + wxTEXT_ATTR_FONT_STRIKETHROUGH = 0x08000000, wxTEXT_ATTR_FONT_ENCODING = 0x02000000, wxTEXT_ATTR_FONT_FAMILY = 0x04000000, + wxTEXT_ATTR_FONT_SIZE = \ + ( wxTEXT_ATTR_FONT_POINT_SIZE | wxTEXT_ATTR_FONT_PIXEL_SIZE ), wxTEXT_ATTR_FONT = \ ( wxTEXT_ATTR_FONT_FACE | wxTEXT_ATTR_FONT_SIZE | wxTEXT_ATTR_FONT_WEIGHT | \ - wxTEXT_ATTR_FONT_ITALIC | wxTEXT_ATTR_FONT_UNDERLINE | wxTEXT_ATTR_FONT_ENCODING | wxTEXT_ATTR_FONT_FAMILY ), + wxTEXT_ATTR_FONT_ITALIC | wxTEXT_ATTR_FONT_UNDERLINE | wxTEXT_ATTR_FONT_STRIKETHROUGH | wxTEXT_ATTR_FONT_ENCODING | wxTEXT_ATTR_FONT_FAMILY ), wxTEXT_ATTR_ALIGNMENT = 0x00000080, wxTEXT_ATTR_LEFT_INDENT = 0x00000100, wxTEXT_ATTR_RIGHT_INDENT = 0x00000200, wxTEXT_ATTR_TABS = 0x00000400, - wxTEXT_ATTR_PARA_SPACING_AFTER = 0x00000800, wxTEXT_ATTR_PARA_SPACING_BEFORE = 0x00001000, wxTEXT_ATTR_LINE_SPACING = 0x00002000, wxTEXT_ATTR_CHARACTER_STYLE_NAME = 0x00004000, wxTEXT_ATTR_PARAGRAPH_STYLE_NAME = 0x00008000, wxTEXT_ATTR_LIST_STYLE_NAME = 0x00010000, + wxTEXT_ATTR_BULLET_STYLE = 0x00020000, wxTEXT_ATTR_BULLET_NUMBER = 0x00040000, wxTEXT_ATTR_BULLET_TEXT = 0x00080000, wxTEXT_ATTR_BULLET_NAME = 0x00100000, + + wxTEXT_ATTR_BULLET = \ + ( wxTEXT_ATTR_BULLET_STYLE | wxTEXT_ATTR_BULLET_NUMBER | wxTEXT_ATTR_BULLET_TEXT | \ + wxTEXT_ATTR_BULLET_NAME ), + + wxTEXT_ATTR_URL = 0x00200000, wxTEXT_ATTR_PAGE_BREAK = 0x00400000, wxTEXT_ATTR_EFFECTS = 0x00800000, @@ -207,8 +217,7 @@ enum wxTextAttrFlags wxTEXT_ATTR_PARAGRAPH = \ (wxTEXT_ATTR_ALIGNMENT|wxTEXT_ATTR_LEFT_INDENT|wxTEXT_ATTR_RIGHT_INDENT|wxTEXT_ATTR_TABS|\ wxTEXT_ATTR_PARA_SPACING_BEFORE|wxTEXT_ATTR_PARA_SPACING_AFTER|wxTEXT_ATTR_LINE_SPACING|\ - wxTEXT_ATTR_BULLET_STYLE|wxTEXT_ATTR_BULLET_NUMBER|wxTEXT_ATTR_BULLET_TEXT|wxTEXT_ATTR_BULLET_NAME|\ - wxTEXT_ATTR_PARAGRAPH_STYLE_NAME|wxTEXT_ATTR_LIST_STYLE_NAME|wxTEXT_ATTR_OUTLINE_LEVEL), + wxTEXT_ATTR_BULLET|wxTEXT_ATTR_PARAGRAPH_STYLE_NAME|wxTEXT_ATTR_LIST_STYLE_NAME|wxTEXT_ATTR_OUTLINE_LEVEL|wxTEXT_ATTR_PAGE_BREAK), wxTEXT_ATTR_ALL = (wxTEXT_ATTR_CHARACTER|wxTEXT_ATTR_PARAGRAPH) }; @@ -292,8 +301,11 @@ public: // Equality test bool operator== (const wxTextAttr& attr) const; - // Partial equality test taking flags into account - bool EqPartial(const wxTextAttr& attr, int flags) const; + // Partial equality test. If @a weakTest is @true, attributes of this object do not + // have to be present if those attributes of @a attr are present. If @a weakTest is + // @false, the function will fail if an attribute is present in @a attr but not + // in this object. + bool EqPartial(const wxTextAttr& attr, bool weakTest = true) const; // Get attributes from font. bool GetFontAttributes(const wxFont& font, int flags = wxTEXT_ATTR_FONT); @@ -306,16 +318,19 @@ public: void SetLeftIndent(int indent, int subIndent = 0) { m_leftIndent = indent; m_leftSubIndent = subIndent; m_flags |= wxTEXT_ATTR_LEFT_INDENT; } void SetRightIndent(int indent) { m_rightIndent = indent; m_flags |= wxTEXT_ATTR_RIGHT_INDENT; } - void SetFontSize(int pointSize) { m_fontSize = pointSize; m_flags |= wxTEXT_ATTR_FONT_SIZE; } - void SetFontStyle(int fontStyle) { m_fontStyle = fontStyle; m_flags |= wxTEXT_ATTR_FONT_ITALIC; } - void SetFontWeight(int fontWeight) { m_fontWeight = fontWeight; m_flags |= wxTEXT_ATTR_FONT_WEIGHT; } + void SetFontSize(int pointSize) { m_fontSize = pointSize; m_flags &= ~wxTEXT_ATTR_FONT_SIZE; m_flags |= wxTEXT_ATTR_FONT_POINT_SIZE; } + void SetFontPointSize(int pointSize) { m_fontSize = pointSize; m_flags &= ~wxTEXT_ATTR_FONT_SIZE; m_flags |= wxTEXT_ATTR_FONT_POINT_SIZE; } + void SetFontPixelSize(int pixelSize) { m_fontSize = pixelSize; m_flags &= ~wxTEXT_ATTR_FONT_SIZE; m_flags |= wxTEXT_ATTR_FONT_PIXEL_SIZE; } + void SetFontStyle(wxFontStyle fontStyle) { m_fontStyle = fontStyle; m_flags |= wxTEXT_ATTR_FONT_ITALIC; } + void SetFontWeight(wxFontWeight fontWeight) { m_fontWeight = fontWeight; m_flags |= wxTEXT_ATTR_FONT_WEIGHT; } void SetFontFaceName(const wxString& faceName) { m_fontFaceName = faceName; m_flags |= wxTEXT_ATTR_FONT_FACE; } void SetFontUnderlined(bool underlined) { m_fontUnderlined = underlined; m_flags |= wxTEXT_ATTR_FONT_UNDERLINE; } + void SetFontStrikethrough(bool strikethrough) { m_fontStrikethrough = strikethrough; m_flags |= wxTEXT_ATTR_FONT_STRIKETHROUGH; } void SetFontEncoding(wxFontEncoding encoding) { m_fontEncoding = encoding; m_flags |= wxTEXT_ATTR_FONT_ENCODING; } - void SetFontFamily(int family) { m_fontFamily = family; m_flags |= wxTEXT_ATTR_FONT_FAMILY; } + void SetFontFamily(wxFontFamily family) { m_fontFamily = family; m_flags |= wxTEXT_ATTR_FONT_FAMILY; } // Set font - void SetFont(const wxFont& font, int flags = wxTEXT_ATTR_FONT) { GetFontAttributes(font, flags); } + void SetFont(const wxFont& font, int flags = (wxTEXT_ATTR_FONT & ~wxTEXT_ATTR_FONT_PIXEL_SIZE)) { GetFontAttributes(font, flags); } void SetFlags(long flags) { m_flags = flags; } @@ -346,12 +361,13 @@ public: long GetFlags() const { return m_flags; } int GetFontSize() const { return m_fontSize; } - int GetFontStyle() const { return m_fontStyle; } - int GetFontWeight() const { return m_fontWeight; } + wxFontStyle GetFontStyle() const { return m_fontStyle; } + wxFontWeight GetFontWeight() const { return m_fontWeight; } bool GetFontUnderlined() const { return m_fontUnderlined; } + bool GetFontStrikethrough() const { return m_fontStrikethrough; } const wxString& GetFontFaceName() const { return m_fontFaceName; } wxFontEncoding GetFontEncoding() const { return m_fontEncoding; } - int GetFontFamily() const { return m_fontFamily; } + wxFontFamily GetFontFamily() const { return m_fontFamily; } wxFont GetFont() const; @@ -361,7 +377,6 @@ public: int GetParagraphSpacingAfter() const { return m_paragraphSpacingAfter; } int GetParagraphSpacingBefore() const { return m_paragraphSpacingBefore; } - // TODO: should return the relative wxTextAttr* enumeration values int GetLineSpacing() const { return m_lineSpacing; } int GetBulletStyle() const { return m_bulletStyle; } int GetBulletNumber() const { return m_bulletNumber; } @@ -374,16 +389,19 @@ public: int GetOutlineLevel() const { return m_outlineLevel; } // accessors - bool HasTextColour() const { return m_colText.Ok() && HasFlag(wxTEXT_ATTR_TEXT_COLOUR) ; } - bool HasBackgroundColour() const { return m_colBack.Ok() && HasFlag(wxTEXT_ATTR_BACKGROUND_COLOUR) ; } + bool HasTextColour() const { return m_colText.IsOk() && HasFlag(wxTEXT_ATTR_TEXT_COLOUR) ; } + bool HasBackgroundColour() const { return m_colBack.IsOk() && HasFlag(wxTEXT_ATTR_BACKGROUND_COLOUR) ; } bool HasAlignment() const { return (m_textAlignment != wxTEXT_ALIGNMENT_DEFAULT) && HasFlag(wxTEXT_ATTR_ALIGNMENT) ; } bool HasTabs() const { return HasFlag(wxTEXT_ATTR_TABS) ; } bool HasLeftIndent() const { return HasFlag(wxTEXT_ATTR_LEFT_INDENT); } bool HasRightIndent() const { return HasFlag(wxTEXT_ATTR_RIGHT_INDENT); } bool HasFontWeight() const { return HasFlag(wxTEXT_ATTR_FONT_WEIGHT); } bool HasFontSize() const { return HasFlag(wxTEXT_ATTR_FONT_SIZE); } + bool HasFontPointSize() const { return HasFlag(wxTEXT_ATTR_FONT_POINT_SIZE); } + bool HasFontPixelSize() const { return HasFlag(wxTEXT_ATTR_FONT_PIXEL_SIZE); } bool HasFontItalic() const { return HasFlag(wxTEXT_ATTR_FONT_ITALIC); } bool HasFontUnderlined() const { return HasFlag(wxTEXT_ATTR_FONT_UNDERLINE); } + bool HasFontStrikethrough() const { return HasFlag(wxTEXT_ATTR_FONT_STRIKETHROUGH); } bool HasFontFaceName() const { return HasFlag(wxTEXT_ATTR_FONT_FACE); } bool HasFontEncoding() const { return HasFlag(wxTEXT_ATTR_FONT_ENCODING); } bool HasFontFamily() const { return HasFlag(wxTEXT_ATTR_FONT_FAMILY); } @@ -406,6 +424,8 @@ public: bool HasOutlineLevel() const { return HasFlag(wxTEXT_ATTR_OUTLINE_LEVEL); } bool HasFlag(long flag) const { return (m_flags & flag) != 0; } + void RemoveFlag(long flag) { m_flags &= ~flag; } + void AddFlag(long flag) { m_flags |= flag; } // Is this a character style? bool IsCharacterStyle() const { return HasFlag(wxTEXT_ATTR_CHARACTER); } @@ -417,7 +437,7 @@ public: return GetFlags() == 0; } - // Merges the given attributes. Does not affect 'this'. If compareWith + // Merges the given attributes. If compareWith // is non-NULL, then it will be used to mask out those attributes that are the same in style // and compareWith, for situations where we don't want to explicitly set inherited attributes. bool Apply(const wxTextAttr& style, const wxTextAttr* compareWith = NULL); @@ -489,10 +509,11 @@ private: wxColour m_colText, m_colBack; int m_fontSize; - int m_fontStyle; - int m_fontWeight; - int m_fontFamily; + wxFontStyle m_fontStyle; + wxFontWeight m_fontWeight; + wxFontFamily m_fontFamily; bool m_fontUnderlined; + bool m_fontStrikethrough; wxString m_fontFaceName; // Character style @@ -567,6 +588,11 @@ public: virtual long XYToPosition(long x, long y) const = 0; virtual bool PositionToXY(long pos, long *x, long *y) const = 0; + // translate the given position (which is just an index in the text control) + // to client coordinates + wxPoint PositionToCoords(long pos) const; + + virtual void ShowPosition(long pos) = 0; // find the character at position given in pixels @@ -577,12 +603,21 @@ public: virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, wxTextCoord *col, wxTextCoord *row) const; + virtual wxString GetValue() const = 0; + virtual void SetValue(const wxString& value) = 0; protected: // implementation of loading/saving - virtual bool DoLoadFile(const wxString& file, int fileType) = 0; - virtual bool DoSaveFile(const wxString& file, int fileType) = 0; + virtual bool DoLoadFile(const wxString& file, int fileType); + virtual bool DoSaveFile(const wxString& file, int fileType); + // Return true if the given position is valid, i.e. positive and less than + // the last position. + virtual bool IsValidPosition(long pos) const = 0; + + // Default stub implementation of PositionToCoords() always returns + // wxDefaultPosition. + virtual wxPoint DoPositionToCoords(long pos) const; // the name of the last file loaded with LoadFile() which will be used by // SaveFile() by default @@ -592,7 +627,7 @@ protected: wxTextAttr m_defaultStyle; - DECLARE_NO_COPY_CLASS(wxTextAreaBase) + wxDECLARE_NO_COPY_CLASS(wxTextAreaBase); }; // this class defines wxTextCtrl interface, wxTextCtrlBase actually implements @@ -606,8 +641,24 @@ class WXDLLIMPEXP_CORE wxTextCtrlIface : public wxTextAreaBase, public: wxTextCtrlIface() { } + // wxTextAreaBase overrides + virtual wxString GetValue() const + { + return wxTextEntryBase::GetValue(); + } + virtual void SetValue(const wxString& value) + { + wxTextEntryBase::SetValue(value); + } + +protected: + virtual bool IsValidPosition(long pos) const + { + return pos >= 0 && pos <= GetLastPosition(); + } + private: - DECLARE_NO_COPY_CLASS(wxTextCtrlIface) + wxDECLARE_NO_COPY_CLASS(wxTextCtrlIface); }; // ---------------------------------------------------------------------------- @@ -648,11 +699,6 @@ public: virtual bool EmulateKeyPress(const wxKeyEvent& event); - // generate the wxEVT_COMMAND_TEXT_UPDATED event, like SetValue() does and - // return true if the event was processed - static bool SendTextUpdatedEvent(wxWindow *win); - bool SendTextUpdatedEvent() { return SendTextUpdatedEvent(this); } - // do the window-specific processing after processing the update event virtual void DoUpdateWindowUI(wxUpdateUIEvent& event); @@ -678,17 +724,47 @@ public: virtual bool GetStyle(long position, wxTextAttr& style); virtual bool SetDefaultStyle(const wxTextAttr& style); + // wxTextAreaBase overrides + virtual wxString GetValue() const + { + return wxTextEntry::GetValue(); + } + virtual void SetValue(const wxString& value) + { + wxTextEntry::SetValue(value); + } + + // wxTextEntry overrides + virtual bool SetHint(const wxString& hint); + + // wxWindow overrides + virtual wxVisualAttributes GetDefaultAttributes() const + { + return GetClassDefaultAttributes(GetWindowVariant()); + } + + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL) + { + return GetCompositeControlsDefaultAttributes(variant); + } + protected: // override streambuf method #if wxHAS_TEXT_WINDOW_STREAM int overflow(int i); #endif // wxHAS_TEXT_WINDOW_STREAM - virtual bool DoLoadFile(const wxString& file, int fileType); - virtual bool DoSaveFile(const wxString& file, int fileType); + // Another wxTextAreaBase override. + virtual bool IsValidPosition(long pos) const + { + return pos >= 0 && pos <= GetLastPosition(); + } + // implement the wxTextEntry pure virtual method + virtual wxWindow *GetEditableWindow() { return this; } - DECLARE_NO_COPY_CLASS(wxTextCtrlBase) + wxDECLARE_NO_COPY_CLASS(wxTextCtrlBase); DECLARE_ABSTRACT_CLASS(wxTextCtrlBase) }; @@ -716,8 +792,6 @@ protected: #include "wx/cocoa/textctrl.h" #elif defined(__WXPM__) #include "wx/os2/textctrl.h" -#elif defined(__WXPALMOS__) - #include "wx/palmos/textctrl.h" #endif // ---------------------------------------------------------------------------- @@ -726,10 +800,10 @@ protected: class WXDLLIMPEXP_FWD_CORE wxTextUrlEvent; -wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEvent) -wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_TEXT_ENTER, wxCommandEvent) -wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_TEXT_URL, wxTextUrlEvent) -wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_TEXT_MAXLEN, wxCommandEvent) +wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEvent); +wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_TEXT_ENTER, wxCommandEvent); +wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_TEXT_URL, wxTextUrlEvent); +wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_TEXT_MAXLEN, wxCommandEvent); class WXDLLIMPEXP_CORE wxTextUrlEvent : public wxCommandEvent {