📄 richtextstyles.h
字号:
/// Get/set previous sheet wxRichTextStyleSheet* GetPreviousSheet() const { return m_previousSheet; } void SetPreviousSheet(wxRichTextStyleSheet* sheet) { m_previousSheet = sheet; } /// Sets and gets the name of the style sheet void SetName(const wxString& name) { m_name = name; } const wxString& GetName() const { return m_name; } /// Sets and gets the style description void SetDescription(const wxString& descr) { m_description = descr; } const wxString& GetDescription() const { return m_description; }/// Implementation /// Add a definition to one of the style lists bool AddStyle(wxList& list, wxRichTextStyleDefinition* def); /// Remove a style bool RemoveStyle(wxList& list, wxRichTextStyleDefinition* def, bool deleteStyle); /// Find a definition by name wxRichTextStyleDefinition* FindStyle(const wxList& list, const wxString& name, bool recurse = true) const;protected: wxString m_description; wxString m_name; wxList m_characterStyleDefinitions; wxList m_paragraphStyleDefinitions; wxList m_listStyleDefinitions; wxRichTextStyleSheet* m_previousSheet; wxRichTextStyleSheet* m_nextSheet;};#if wxUSE_HTML/*! * wxRichTextStyleListBox class declaration * A listbox to display styles. */class WXDLLIMPEXP_RICHTEXT wxRichTextStyleListBox: public wxHtmlListBox{ DECLARE_CLASS(wxRichTextStyleListBox) DECLARE_EVENT_TABLE()public: /// Which type of style definition is currently showing? enum wxRichTextStyleType { wxRICHTEXT_STYLE_ALL, wxRICHTEXT_STYLE_PARAGRAPH, wxRICHTEXT_STYLE_CHARACTER, wxRICHTEXT_STYLE_LIST }; wxRichTextStyleListBox() { Init(); } wxRichTextStyleListBox(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0); virtual ~wxRichTextStyleListBox(); void Init() { m_styleSheet = NULL; m_richTextCtrl = NULL; m_applyOnSelection = false; m_styleType = wxRICHTEXT_STYLE_PARAGRAPH; m_autoSetSelection = true; } bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0); /// Creates a suitable HTML fragment for a definition wxString CreateHTML(wxRichTextStyleDefinition* def) const; /// Associates the control with a style sheet void SetStyleSheet(wxRichTextStyleSheet* styleSheet) { m_styleSheet = styleSheet; } wxRichTextStyleSheet* GetStyleSheet() const { return m_styleSheet; } /// Associates the control with a wxRichTextCtrl void SetRichTextCtrl(wxRichTextCtrl* ctrl) { m_richTextCtrl = ctrl; } wxRichTextCtrl* GetRichTextCtrl() const { return m_richTextCtrl; } /// Get style for index wxRichTextStyleDefinition* GetStyle(size_t i) const ; /// Get index for style name int GetIndexForStyle(const wxString& name) const ; /// Set selection for string, returning the index. int SetStyleSelection(const wxString& name); /// Updates the list void UpdateStyles(); /// Apply the style void ApplyStyle(int i); /// Left click void OnLeftDown(wxMouseEvent& event); /// Left double-click void OnLeftDoubleClick(wxMouseEvent& event); /// Auto-select from style under caret in idle time void OnIdle(wxIdleEvent& event); /// Convert units in tends of a millimetre to device units int ConvertTenthsMMToPixels(wxDC& dc, int units) const; /// Can we set the selection based on the editor caret position? /// Need to override this if being used in a combobox popup virtual bool CanAutoSetSelection() { return m_autoSetSelection; } virtual void SetAutoSetSelection(bool autoSet) { m_autoSetSelection = autoSet; } /// Set whether the style should be applied as soon as the item is selected (the default) void SetApplyOnSelection(bool applyOnSel) { m_applyOnSelection = applyOnSel; } bool GetApplyOnSelection() const { return m_applyOnSelection; } /// Set the style type to display void SetStyleType(wxRichTextStyleType styleType) { m_styleType = styleType; UpdateStyles(); } wxRichTextStyleType GetStyleType() const { return m_styleType; } /// Helper for listbox and combo control static wxString GetStyleToShowInIdleTime(wxRichTextCtrl* ctrl, wxRichTextStyleType styleType);protected: /// Returns the HTML for this item virtual wxString OnGetItem(size_t n) const;private: wxRichTextStyleSheet* m_styleSheet; wxRichTextCtrl* m_richTextCtrl; bool m_applyOnSelection; // if true, applies style on selection wxRichTextStyleType m_styleType; // style type to display bool m_autoSetSelection; wxArrayString m_styleNames;};/*! * wxRichTextStyleListCtrl class declaration * This is a container for the list control plus a combobox to switch between * style types. */#define wxRICHTEXTSTYLELIST_HIDE_TYPE_SELECTOR 0x1000class WXDLLIMPEXP_RICHTEXT wxRichTextStyleListCtrl: public wxControl{ DECLARE_CLASS(wxRichTextStyleListCtrl) DECLARE_EVENT_TABLE()public: /// Constructors wxRichTextStyleListCtrl() { Init(); } wxRichTextStyleListCtrl(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0); /// Constructors virtual ~wxRichTextStyleListCtrl(); /// Member initialisation void Init() { m_styleListBox = NULL; m_styleChoice = NULL; m_dontUpdate = false; } /// Creates the windows bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0); /// Updates the style list box void UpdateStyles(); /// Associates the control with a style sheet void SetStyleSheet(wxRichTextStyleSheet* styleSheet); wxRichTextStyleSheet* GetStyleSheet() const; /// Associates the control with a wxRichTextCtrl void SetRichTextCtrl(wxRichTextCtrl* ctrl); wxRichTextCtrl* GetRichTextCtrl() const; /// Set/get the style type to display void SetStyleType(wxRichTextStyleListBox::wxRichTextStyleType styleType); wxRichTextStyleListBox::wxRichTextStyleType GetStyleType() const; /// Get the choice index for style type int StyleTypeToIndex(wxRichTextStyleListBox::wxRichTextStyleType styleType); /// Get the style type for choice index wxRichTextStyleListBox::wxRichTextStyleType StyleIndexToType(int i); /// Get the listbox wxRichTextStyleListBox* GetStyleListBox() const { return m_styleListBox; } /// Get the choice wxChoice* GetStyleChoice() const { return m_styleChoice; } /// React to style type choice void OnChooseType(wxCommandEvent& event); /// Lay out the controls void OnSize(wxSizeEvent& event);private: wxRichTextStyleListBox* m_styleListBox; wxChoice* m_styleChoice; bool m_dontUpdate;};#if wxUSE_COMBOCTRL/*! * Style drop-down for a wxComboCtrl */class wxRichTextStyleComboPopup : public wxRichTextStyleListBox, public wxComboPopup{public: virtual void Init() { m_itemHere = -1; // hot item in list m_value = -1; } virtual bool Create( wxWindow* parent ) { return wxRichTextStyleListBox::Create(parent, wxID_ANY, wxPoint(0,0), wxDefaultSize, wxSIMPLE_BORDER); } virtual wxWindow *GetControl() { return this; } virtual void SetStringValue( const wxString& s ); virtual wxString GetStringValue() const; /// Can we set the selection based on the editor caret position? // virtual bool CanAutoSetSelection() { return ((m_combo == NULL) || !m_combo->IsPopupShown()); } virtual bool CanAutoSetSelection() { return false; } // // Popup event handlers // // Mouse hot-tracking void OnMouseMove(wxMouseEvent& event); // On mouse left, set the value and close the popup void OnMouseClick(wxMouseEvent& WXUNUSED(event));protected: int m_itemHere; // hot item in popup int m_value;private: DECLARE_EVENT_TABLE()};/*! * wxRichTextStyleComboCtrl * A combo for applying styles. */class WXDLLIMPEXP_RICHTEXT wxRichTextStyleComboCtrl: public wxComboCtrl{ DECLARE_CLASS(wxRichTextStyleComboCtrl) DECLARE_EVENT_TABLE()public: wxRichTextStyleComboCtrl() { Init(); } wxRichTextStyleComboCtrl(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxCB_READONLY) { Init(); Create(parent, id, pos, size, style); } virtual ~wxRichTextStyleComboCtrl() {} void Init() { m_stylePopup = NULL; } bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0); /// Updates the list void UpdateStyles() { m_stylePopup->UpdateStyles(); } /// Associates the control with a style sheet void SetStyleSheet(wxRichTextStyleSheet* styleSheet) { m_stylePopup->SetStyleSheet(styleSheet); } wxRichTextStyleSheet* GetStyleSheet() const { return m_stylePopup->GetStyleSheet(); } /// Associates the control with a wxRichTextCtrl void SetRichTextCtrl(wxRichTextCtrl* ctrl) { m_stylePopup->SetRichTextCtrl(ctrl); } wxRichTextCtrl* GetRichTextCtrl() const { return m_stylePopup->GetRichTextCtrl(); } /// Gets the style popup wxRichTextStyleComboPopup* GetStylePopup() const { return m_stylePopup; } /// Auto-select from style under caret in idle time void OnIdle(wxIdleEvent& event);protected: wxRichTextStyleComboPopup* m_stylePopup;};#endif // wxUSE_COMBOCTRL#endif // wxUSE_HTML#endif // wxUSE_RICHTEXT#endif // _WX_RICHTEXTSTYLES_H_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -