From 32423dd8248d13625e8eedd10298601e5313a393 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Sun, 20 May 2012 12:25:22 +0000 Subject: [PATCH] Added pixel size capability to wxTextAttr and wxRichTextCtrl. Fixed composite object positioning in centred and right-aligned paragraphs. Added field example to sample, and enabled pixel font size selection. Added custom text and dimension scaling. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71505 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 2 + include/wx/richtext/richtextbuffer.h | 97 ++- include/wx/richtext/richtextctrl.h | 25 + include/wx/richtext/richtextfontpage.h | 24 +- include/wx/richtext/richtextformatdlg.h | 28 +- include/wx/richtext/richtextstyles.h | 10 +- include/wx/textctrl.h | 22 +- interface/wx/richtext/richtextbuffer.h | 89 ++- interface/wx/richtext/richtextctrl.h | 25 + interface/wx/richtext/richtextformatdlg.h | 19 + interface/wx/textctrl.h | 40 +- samples/richtext/richtext.cpp | 171 ++++- src/common/textcmn.cpp | 186 ++++-- src/richtext/richtextbuffer.cpp | 318 +++++++--- src/richtext/richtextctrl.cpp | 22 +- src/richtext/richtextdialogs.pjd | 723 ++++++++++++++-------- src/richtext/richtextfontpage.cpp | 217 +++++-- src/richtext/richtextformatdlg.cpp | 1 + src/richtext/richtextstyles.cpp | 6 +- src/richtext/richtextxml.cpp | 21 +- 20 files changed, 1471 insertions(+), 575 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 0a83eb5c63..dda32f3a95 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -548,6 +548,8 @@ All (GUI): - Added wxAcceleratorEntry::ToRawString() (Armel Asselin). - Added wxDataViewEvent::SetDragFlags() and GetDropEffect() (Friedrich). - Added support for fields and virtual attributes to wxRichTextCtrl. +- Added custom text and dimension scaling to wxRichTextCtrl. +- Added pixel font size capability to wxTextAttr and wxRichTextCtrl. GTK: diff --git a/include/wx/richtext/richtextbuffer.h b/include/wx/richtext/richtextbuffer.h index b9c7dfdc8a..1a644eac9a 100644 --- a/include/wx/richtext/richtextbuffer.h +++ b/include/wx/richtext/richtextbuffer.h @@ -281,7 +281,7 @@ enum wxRichTextHitTestFlags // A special flag telling the buffer to keep the first paragraph style // as-is, when deleting a paragraph marker. In future we might pass a // flag to InsertFragment and DeleteRange to indicate the appropriate mode. -#define wxTEXT_ATTR_KEEP_FIRST_PARA_STYLE 0x10000000 +#define wxTEXT_ATTR_KEEP_FIRST_PARA_STYLE 0x20000000 /** Default superscript/subscript font multiplication factor. @@ -370,9 +370,12 @@ public: void Reset() { m_value = 0; m_flags = 0; } /** - Partial equality test. + Partial equality test. If @a weakTest is @true, attributes of this object do not + have to be present if those attributes of @a dim are present. If @a weakTest is + @false, the function will fail if an attribute is present in @a dim but not + in this object. */ - bool EqPartial(const wxTextAttrDimension& dim) const; + bool EqPartial(const wxTextAttrDimension& dim, bool weakTest = true) const; /** Apply the dimension, but not those identical to @a compareWith if present. */ @@ -497,10 +500,13 @@ public: bool operator==(const wxTextAttrDimensions& dims) const { return m_left == dims.m_left && m_top == dims.m_top && m_right == dims.m_right && m_bottom == dims.m_bottom; } /** - Partial equality test. + Partial equality test. If @a weakTest is @true, attributes of this object do not + have to be present if those attributes of @a dim sare present. If @a weakTest is + @false, the function will fail if an attribute is present in @a dims but not + in this object. */ - bool EqPartial(const wxTextAttrDimensions& dims) const; + bool EqPartial(const wxTextAttrDimensions& dims, bool weakTest = true) const; /** Apply to 'this', but not if the same as @a compareWith. @@ -588,9 +594,12 @@ public: bool operator==(const wxTextAttrSize& size) const { return m_width == size.m_width && m_height == size.m_height ; } /** - Partial equality test. + Partial equality test. If @a weakTest is @true, attributes of this object do not + have to be present if those attributes of @a size are present. If @a weakTest is + @false, the function will fail if an attribute is present in @a size but not + in this object. */ - bool EqPartial(const wxTextAttrSize& dims) const; + bool EqPartial(const wxTextAttrSize& size, bool weakTest = true) const; /** Apply to this object, but not if the same as @a compareWith. @@ -813,9 +822,12 @@ public: void Reset() { m_borderStyle = 0; m_borderColour = 0; m_flags = 0; m_borderWidth.Reset(); } /** - Partial equality test. + Partial equality test. If @a weakTest is @true, attributes of this object do not + have to be present if those attributes of @a border are present. If @a weakTest is + @false, the function will fail if an attribute is present in @a border but not + in this object. */ - bool EqPartial(const wxTextAttrBorder& border) const; + bool EqPartial(const wxTextAttrBorder& border, bool weakTest = true) const; /** Applies the border to this object, but not if the same as @a compareWith. @@ -989,9 +1001,12 @@ public: void Reset() { m_left.Reset(); m_right.Reset(); m_top.Reset(); m_bottom.Reset(); } /** - Partial equality test. + Partial equality test. If @a weakTest is @true, attributes of this object do not + have to be present if those attributes of @a borders are present. If @a weakTest is + @false, the function will fail if an attribute is present in @a borders but not + in this object. */ - bool EqPartial(const wxTextAttrBorders& borders) const; + bool EqPartial(const wxTextAttrBorders& borders, bool weakTest = true) const; /** Applies border to this object, but not if the same as @a compareWith. @@ -1087,10 +1102,13 @@ public: bool operator== (const wxTextBoxAttr& attr) const; /** - Partial equality test, ignoring unset attributes. + Partial equality test, ignoring unset attributes. 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 wxTextBoxAttr& attr) const; + bool EqPartial(const wxTextBoxAttr& attr, bool weakTest = true) const; /** Merges the given attributes. If @a compareWith is non-NULL, then it will be used @@ -1489,9 +1507,12 @@ public: bool operator==(const wxRichTextAttr& attr) const; /** - Partial equality test taking comparison object into account. + 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 wxRichTextAttr& attr) const; + bool EqPartial(const wxRichTextAttr& attr, bool weakTest = true) const; /** Merges the given attributes. If @a compareWith @@ -1752,8 +1773,15 @@ public: */ bool operator != (const wxRichTextFontTable& table) const { return !(*this == table); } + /** + Set the font scale factor. + */ + void SetFontScale(double fontScale); + protected: + double m_fontScale; + DECLARE_DYNAMIC_CLASS(wxRichTextFontTable) }; @@ -3545,7 +3573,7 @@ public: Update the field; delegated to the associated field type. This would typically expand the field to its value, if this is a dynamically changing and/or composite field. */ - virtual bool UpdateField(); + virtual bool UpdateField(wxRichTextBuffer* buffer); virtual wxRichTextObject* Clone() const { return new wxRichTextField(*this); } @@ -3628,7 +3656,7 @@ public: Update the field. This would typically expand the field to its value, if this is a dynamically changing and/or composite field. */ - virtual bool UpdateField(wxRichTextField* WXUNUSED(obj)) { return false; } + virtual bool UpdateField(wxRichTextBuffer* WXUNUSED(buffer), wxRichTextField* WXUNUSED(obj)) { return false; } /** Returns @true if this object is top-level, i.e. contains its own paragraphs, such as a text box. @@ -4704,6 +4732,31 @@ public: */ void SetFontTable(const wxRichTextFontTable& table) { m_fontTable = table; } + /** + Sets the scale factor for displaying fonts, for example for more comfortable + editing. + */ + void SetFontScale(double fontScale); + + /** + Returns the scale factor for displaying fonts, for example for more comfortable + editing. + */ + double GetFontScale() const { return m_fontScale; } + + /** + Sets the scale factor for displaying certain dimensions such as indentation and + inter-paragraph spacing. This can be useful when editing in a small control + where you still want legible text, but a minimum of wasted white space. + */ + void SetDimensionScale(double dimScale); + + /** + Returns the scale factor for displaying certain dimensions such as indentation + and inter-paragraph spacing. + */ + double GetDimensionScale() const { return m_dimensionScale; } + // Operations /** @@ -5374,6 +5427,12 @@ protected: /// Scaling factor in use: needed to calculate correct dimensions when printing double m_scale; + + /// Font scale for adjusting the text size when editing + double m_fontScale; + + /// Dimension scale for reducing redundant whitespace when editing + double m_dimensionScale; }; /** @@ -6332,10 +6391,6 @@ inline bool wxRichTextHasStyle(int flags, int style) WXDLLIMPEXP_RICHTEXT bool wxTextAttrEq(const wxRichTextAttr& attr1, const wxRichTextAttr& attr2); WXDLLIMPEXP_RICHTEXT bool wxTextAttrEq(const wxRichTextAttr& attr1, const wxRichTextAttr& attr2); -/// Compare two attribute objects, but take into account the flags -/// specifying attributes of interest. -WXDLLIMPEXP_RICHTEXT bool wxTextAttrEqPartial(const wxRichTextAttr& attr1, const wxRichTextAttr& attr2); - /// Apply one style to another WXDLLIMPEXP_RICHTEXT bool wxRichTextApplyStyle(wxRichTextAttr& destStyle, const wxRichTextAttr& style, wxRichTextAttr* compareWith = NULL); diff --git a/include/wx/richtext/richtextctrl.h b/include/wx/richtext/richtextctrl.h index 2ced2cdb7b..d4f8adbf58 100644 --- a/include/wx/richtext/richtextctrl.h +++ b/include/wx/richtext/richtextctrl.h @@ -1701,6 +1701,31 @@ public: */ virtual bool GetVerticalScrollbarEnabled() const { return m_verticalScrollbarEnabled; } + /** + Sets the scale factor for displaying fonts, for example for more comfortable + editing. + */ + void SetFontScale(double fontScale, bool refresh = false); + + /** + Returns the scale factor for displaying fonts, for example for more comfortable + editing. + */ + double GetFontScale() const { return GetBuffer().GetFontScale(); } + + /** + Sets the scale factor for displaying certain dimensions such as indentation and + inter-paragraph spacing. This can be useful when editing in a small control + where you still want legible text, but a minimum of wasted white space. + */ + void SetDimensionScale(double dimScale, bool refresh = false); + + /** + Returns the scale factor for displaying certain dimensions such as indentation + and inter-paragraph spacing. + */ + double GetDimensionScale() const { return GetBuffer().GetDimensionScale(); } + // Command handlers /** diff --git a/include/wx/richtext/richtextfontpage.h b/include/wx/richtext/richtextfontpage.h index 4a0d851626..7573391cce 100644 --- a/include/wx/richtext/richtextfontpage.h +++ b/include/wx/richtext/richtextfontpage.h @@ -19,6 +19,7 @@ #include "wx/richtext/richtextdialogpage.h" ////@begin includes +#include "wx/spinbutt.h" ////@end includes /*! @@ -26,6 +27,8 @@ */ ////@begin forward declarations +class wxSpinButton; +class wxBoxSizer; class wxRichTextFontListBox; class wxRichTextColourSwatchCtrl; class wxRichTextFontPreviewCtrl; @@ -82,12 +85,24 @@ public: ////@begin wxRichTextFontPage event handler declarations + /// wxEVT_IDLE event handler for ID_RICHTEXTFONTPAGE + void OnIdle( wxIdleEvent& event ); + /// wxEVT_COMMAND_TEXT_UPDATED event handler for ID_RICHTEXTFONTPAGE_FACETEXTCTRL void OnFaceTextCtrlUpdated( wxCommandEvent& event ); /// wxEVT_COMMAND_TEXT_UPDATED event handler for ID_RICHTEXTFONTPAGE_SIZETEXTCTRL void OnSizeTextCtrlUpdated( wxCommandEvent& event ); + /// wxEVT_SCROLL_LINEUP event handler for ID_RICHTEXTFONTPAGE_SPINBUTTONS + void OnRichtextfontpageSpinbuttonsUp( wxSpinEvent& event ); + + /// wxEVT_SCROLL_LINEDOWN event handler for ID_RICHTEXTFONTPAGE_SPINBUTTONS + void OnRichtextfontpageSpinbuttonsDown( wxSpinEvent& event ); + + /// wxEVT_COMMAND_CHOICE_SELECTED event handler for ID_RICHTEXTFONTPAGE_SIZE_UNITS + void OnRichtextfontpageSizeUnitsSelected( wxCommandEvent& event ); + /// wxEVT_COMMAND_LISTBOX_SELECTED event handler for ID_RICHTEXTFONTPAGE_SIZELISTBOX void OnSizeListBoxSelected( wxCommandEvent& event ); @@ -128,8 +143,11 @@ public: ////@begin wxRichTextFontPage member variables wxTextCtrl* m_faceTextCtrl; - wxRichTextFontListBox* m_faceListBox; wxTextCtrl* m_sizeTextCtrl; + wxSpinButton* m_fontSizeSpinButtons; + wxChoice* m_sizeUnitsCtrl; + wxBoxSizer* m_fontListBoxParent; + wxRichTextFontListBox* m_faceListBox; wxListBox* m_sizeListBox; wxComboBox* m_styleCtrl; wxComboBox* m_weightCtrl; @@ -147,8 +165,10 @@ public: enum { ID_RICHTEXTFONTPAGE = 10000, ID_RICHTEXTFONTPAGE_FACETEXTCTRL = 10001, - ID_RICHTEXTFONTPAGE_FACELISTBOX = 10002, ID_RICHTEXTFONTPAGE_SIZETEXTCTRL = 10005, + ID_RICHTEXTFONTPAGE_SPINBUTTONS = 10018, + ID_RICHTEXTFONTPAGE_SIZE_UNITS = 10017, + ID_RICHTEXTFONTPAGE_FACELISTBOX = 10002, ID_RICHTEXTFONTPAGE_SIZELISTBOX = 10006, ID_RICHTEXTFONTPAGE_STYLECTRL = 10007, ID_RICHTEXTFONTPAGE_WEIGHTCTRL = 10004, diff --git a/include/wx/richtext/richtextformatdlg.h b/include/wx/richtext/richtextformatdlg.h index 53abf8ac7d..ec785a5b00 100644 --- a/include/wx/richtext/richtextformatdlg.h +++ b/include/wx/richtext/richtextformatdlg.h @@ -126,6 +126,8 @@ DECLARE_CLASS(wxRichTextFormattingDialog) DECLARE_HELP_PROVISION() public: + enum { Option_AllowPixelFontSize = 0x0001 }; + wxRichTextFormattingDialog() { Init(); } wxRichTextFormattingDialog(long flags, wxWindow* parent, const wxString& title = wxGetTranslation(wxT("Formatting")), wxWindowID id = wxID_ANY, @@ -164,7 +166,7 @@ public: /// Apply attributes to the given range virtual bool ApplyStyle(wxRichTextCtrl* ctrl, const wxRichTextRange& range, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO|wxRICHTEXT_SETSTYLE_OPTIMIZE); - + /// Apply attributes to the object being edited, if any virtual bool ApplyStyle(wxRichTextCtrl* ctrl, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO); @@ -172,12 +174,18 @@ public: const wxRichTextAttr& GetAttributes() const { return m_attributes; } wxRichTextAttr& GetAttributes() { return m_attributes; } void SetAttributes(const wxRichTextAttr& attr) { m_attributes = attr; } -#if 0 - /// Gets and sets the attributes that the user wants to reset - const wxRichTextAttr& GetResetAttributes() const { return m_resetAttributes; } - wxRichTextAttr& GetResetAttributes() { return m_resetAttributes; } - void SetResetAttributes(const wxRichTextAttr& attr) { m_resetAttributes = attr; } -#endif + + /// Sets the dialog options, determining what the interface presents to the user. + /// Currently the only option is Option_AllowPixelFontSize. + void SetOptions(int options) { m_options = options; } + + /// Gets the dialog options, determining what the interface presents to the user. + /// Currently the only option is Option_AllowPixelFontSize. + int GetOptions() const { return m_options; } + + /// Returns @true if the given option is present. + bool HasOption(int option) const { return (m_options & option) != 0; } + /// If editing the attributes for a particular object, such as an image, /// set the object so the code can initialize attributes such as size correctly. wxRichTextObject* GetObject() const { return m_object; } @@ -222,24 +230,24 @@ public: /// Get the dimension from the value and units controls static void GetDimensionValue(wxTextAttrDimension& dim, wxTextCtrl* valueCtrl, wxComboBox* unitsCtrl, wxCheckBox* checkBox); - + /// Convert CM to MM static bool ConvertFromString(const wxString& string, int& ret, int scale); /// Map book control page index to our page id void AddPageId(int id) { m_pageIds.Add(id); } - + /// Find a page by class wxWindow* FindPage(wxClassInfo* info) const; protected: wxRichTextAttr m_attributes; - //wxRichTextAttr m_resetAttributes; wxRichTextStyleDefinition* m_styleDefinition; wxRichTextStyleSheet* m_styleSheet; wxRichTextObject* m_object; wxArrayInt m_pageIds; // mapping of book control indexes to page ids + int m_options; // UI options static wxRichTextFormattingDialogFactory* ms_FormattingDialogFactory; static bool sm_showToolTips; diff --git a/include/wx/richtext/richtextstyles.h b/include/wx/richtext/richtextstyles.h index 75efa9b1b0..107cc65cc0 100644 --- a/include/wx/richtext/richtextstyles.h +++ b/include/wx/richtext/richtextstyles.h @@ -102,7 +102,7 @@ public: virtual wxRichTextAttr GetStyleMergedWithBase(const wxRichTextStyleSheet* sheet) const; /** - Sets the definition's properties. + Returns the definition's properties. */ wxRichTextProperties& GetProperties() { return m_properties; } @@ -112,7 +112,7 @@ public: const wxRichTextProperties& GetProperties() const { return m_properties; } /** - Returns the definition's properties. + Sets the definition's properties. */ void SetProperties(const wxRichTextProperties& props) { m_properties = props; } @@ -419,17 +419,17 @@ public: const wxString& GetDescription() const { return m_description; } /** - Sets the definition's properties. + Returns the sheet's properties. */ wxRichTextProperties& GetProperties() { return m_properties; } /** - Returns the definition's properties. + Returns the sheet's properties. */ const wxRichTextProperties& GetProperties() const { return m_properties; } /** - Returns the definition's properties. + Sets the sheet's properties. */ void SetProperties(const wxRichTextProperties& props) { m_properties = props; } diff --git a/include/wx/textctrl.h b/include/wx/textctrl.h index 0239ce3ca3..f8a344d01e 100644 --- a/include/wx/textctrl.h +++ b/include/wx/textctrl.h @@ -166,13 +166,16 @@ enum wxTextAttrFlags 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_STRIKETHROUGH | wxTEXT_ATTR_FONT_ENCODING | wxTEXT_ATTR_FONT_FAMILY ), @@ -298,8 +301,11 @@ public: // Equality test bool operator== (const wxTextAttr& attr) const; - // Partial equality test - bool EqPartial(const wxTextAttr& attr) 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); @@ -312,7 +318,9 @@ 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 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; } @@ -322,7 +330,7 @@ public: 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; } @@ -389,6 +397,8 @@ public: 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); } @@ -431,7 +441,7 @@ public: // 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); - + // merges the attributes of the base and the overlay objects and returns // the result; the parameter attributes take precedence // diff --git a/interface/wx/richtext/richtextbuffer.h b/interface/wx/richtext/richtextbuffer.h index 41cc9abc49..4f821125f8 100644 --- a/interface/wx/richtext/richtextbuffer.h +++ b/interface/wx/richtext/richtextbuffer.h @@ -251,9 +251,12 @@ public: void Reset() { m_value = 0; m_flags = 0; } /** - Partial equality test. + Partial equality test. If @a weakTest is @true, attributes of this object do not + have to be present if those attributes of @a dim are present. If @a weakTest is + @false, the function will fail if an attribute is present in @a dim but not + in this object. */ - bool EqPartial(const wxTextAttrDimension& dim) const; + bool EqPartial(const wxTextAttrDimension& dim, bool weakTest = true) const; /** Apply the dimension, but not those identical to @a compareWith if present. */ @@ -378,10 +381,13 @@ public: bool operator==(const wxTextAttrDimensions& dims) const { return m_left == dims.m_left && m_top == dims.m_top && m_right == dims.m_right && m_bottom == dims.m_bottom; } /** - Partial equality test. + Partial equality test. If @a weakTest is @true, attributes of this object do not + have to be present if those attributes of @a dim sare present. If @a weakTest is + @false, the function will fail if an attribute is present in @a dims but not + in this object. */ - bool EqPartial(const wxTextAttrDimensions& dims) const; + bool EqPartial(const wxTextAttrDimensions& dims, bool weakTest = true) const; /** Apply to 'this', but not if the same as @a compareWith. @@ -469,9 +475,12 @@ public: bool operator==(const wxTextAttrSize& size) const { return m_width == size.m_width && m_height == size.m_height ; } /** - Partial equality test. + Partial equality test. If @a weakTest is @true, attributes of this object do not + have to be present if those attributes of @a size are present. If @a weakTest is + @false, the function will fail if an attribute is present in @a size but not + in this object. */ - bool EqPartial(const wxTextAttrSize& dims) const; + bool EqPartial(const wxTextAttrSize& size, bool weakTest = true) const; /** Apply to this object, but not if the same as @a compareWith. @@ -694,9 +703,12 @@ public: void Reset() { m_borderStyle = 0; m_borderColour = 0; m_flags = 0; m_borderWidth.Reset(); } /** - Partial equality test. + Partial equality test. If @a weakTest is @true, attributes of this object do not + have to be present if those attributes of @a border are present. If @a weakTest is + @false, the function will fail if an attribute is present in @a border but not + in this object. */ - bool EqPartial(const wxTextAttrBorder& border) const; + bool EqPartial(const wxTextAttrBorder& border, bool weakTest = true) const; /** Applies the border to this object, but not if the same as @a compareWith. @@ -870,9 +882,12 @@ public: void Reset() { m_left.Reset(); m_right.Reset(); m_top.Reset(); m_bottom.Reset(); } /** - Partial equality test. + Partial equality test. If @a weakTest is @true, attributes of this object do not + have to be present if those attributes of @a borders are present. If @a weakTest is + @false, the function will fail if an attribute is present in @a borders but not + in this object. */ - bool EqPartial(const wxTextAttrBorders& borders) const; + bool EqPartial(const wxTextAttrBorders& borders, bool weakTest = true) const; /** Applies border to this object, but not if the same as @a compareWith. @@ -968,10 +983,13 @@ public: bool operator== (const wxTextBoxAttr& attr) const; /** - Partial equality test, ignoring unset attributes. + Partial equality test, ignoring unset attributes. 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 wxTextBoxAttr& attr) const; + bool EqPartial(const wxTextBoxAttr& attr, bool weakTest = true) const; /** Merges the given attributes. If @a compareWith is non-NULL, then it will be used @@ -1370,9 +1388,12 @@ public: bool operator==(const wxRichTextAttr& attr) const; /** - Partial equality test taking comparison object into account. + 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 wxRichTextAttr& attr) const; + bool EqPartial(const wxRichTextAttr& attr, bool weakTest = true) const; /** Merges the given attributes. If @a compareWith @@ -1633,8 +1654,15 @@ public: */ bool operator != (const wxRichTextFontTable& table) const { return !(*this == table); } + /** + Set the font scale factor. + */ + void SetFontScale(double fontScale); + protected: + double m_fontScale; + DECLARE_DYNAMIC_CLASS(wxRichTextFontTable) }; @@ -3423,7 +3451,7 @@ public: Update the field; delegated to the associated field type. This would typically expand the field to its value, if this is a dynamically changing and/or composite field. */ - virtual bool UpdateField(); + virtual bool UpdateField(wxRichTextBuffer* buffer); virtual wxRichTextObject* Clone() const { return new wxRichTextField(*this); } @@ -3506,7 +3534,7 @@ public: Update the field. This would typically expand the field to its value, if this is a dynamically changing and/or composite field. */ - virtual bool UpdateField(wxRichTextField* WXUNUSED(obj)) { return false; } + virtual bool UpdateField(wxRichTextBuffer* buffer, wxRichTextField* obj) { return false; } /** Returns @true if this object is top-level, i.e. contains its own paragraphs, such as a text box. @@ -4576,6 +4604,31 @@ public: */ void SetFontTable(const wxRichTextFontTable& table) { m_fontTable = table; } + /** + Sets the scale factor for displaying fonts, for example for more comfortable + editing. + */ + void SetFontScale(double fontScale); + + /** + Returns the scale factor for displaying fonts, for example for more comfortable + editing. + */ + double GetFontScale() const { return m_fontScale; } + + /** + Sets the scale factor for displaying certain dimensions such as indentation and + inter-paragraph spacing. This can be useful when editing in a small control + where you still want legible text, but a minimum of wasted white space. + */ + void SetDimensionScale(double dimScale); + + /** + Returns the scale factor for displaying certain dimensions such as indentation + and inter-paragraph spacing. + */ + double GetDimensionScale() const { return m_dimensionScale; } + // Operations /** @@ -6203,10 +6256,6 @@ inline bool wxRichTextHasStyle(int flags, int style) WXDLLIMPEXP_RICHTEXT bool wxTextAttrEq(const wxRichTextAttr& attr1, const wxRichTextAttr& attr2); WXDLLIMPEXP_RICHTEXT bool wxTextAttrEq(const wxRichTextAttr& attr1, const wxRichTextAttr& attr2); -/// Compare two attribute objects, but take into account the flags -/// specifying attributes of interest. -WXDLLIMPEXP_RICHTEXT bool wxTextAttrEqPartial(const wxRichTextAttr& attr1, const wxRichTextAttr& attr2); - /// Apply one style to another WXDLLIMPEXP_RICHTEXT bool wxRichTextApplyStyle(wxRichTextAttr& destStyle, const wxRichTextAttr& style, wxRichTextAttr* compareWith = NULL); diff --git a/interface/wx/richtext/richtextctrl.h b/interface/wx/richtext/richtextctrl.h index cceb0c85f3..b020e081d9 100644 --- a/interface/wx/richtext/richtextctrl.h +++ b/interface/wx/richtext/richtextctrl.h @@ -1660,6 +1660,31 @@ public: */ virtual bool GetVerticalScrollbarEnabled() const; + /** + Sets the scale factor for displaying fonts, for example for more comfortable + editing. + */ + void SetFontScale(double fontScale, bool refresh = false); + + /** + Returns the scale factor for displaying fonts, for example for more comfortable + editing. + */ + double GetFontScale() const { return GetBuffer().GetFontScale(); } + + /** + Sets the scale factor for displaying certain dimensions such as indentation and + inter-paragraph spacing. This can be useful when editing in a small control + where you still want legible text, but a minimum of wasted white space. + */ + void SetDimensionScale(double dimScale, bool refresh = false); + + /** + Returns the scale factor for displaying certain dimensions such as indentation + and inter-paragraph spacing. + */ + double GetDimensionScale() const { return GetBuffer().GetDimensionScale(); } + // Command handlers /** diff --git a/interface/wx/richtext/richtextformatdlg.h b/interface/wx/richtext/richtextformatdlg.h index 1dc4282236..21bf1539b0 100644 --- a/interface/wx/richtext/richtextformatdlg.h +++ b/interface/wx/richtext/richtextformatdlg.h @@ -123,6 +123,8 @@ public: class wxRichTextFormattingDialog : public wxPropertySheetDialog { public: + enum { Option_AllowPixelFontSize = 0x0001 }; + /** Default ctor. */ @@ -227,6 +229,23 @@ public: */ void SetAttributes(const wxTextAttr& attr); + /** + Sets the dialog options, determining what the interface presents to the user. + Currently the only option is Option_AllowPixelFontSize. + */ + void SetOptions(int options) { m_options = options; } + + /** + Gets the dialog options, determining what the interface presents to the user. + Currently the only option is Option_AllowPixelFontSize. + */ + int GetOptions() const { return m_options; } + + /** + Returns @true if the given option is present. + */ + bool HasOption(int option) const { return (m_options & option) != 0; } + /** Sets the formatting factory object to be used for customization and page creation. diff --git a/interface/wx/textctrl.h b/interface/wx/textctrl.h index 048cf6564a..146201e99a 100644 --- a/interface/wx/textctrl.h +++ b/interface/wx/textctrl.h @@ -87,19 +87,23 @@ enum wxTextAttrFlags 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 ), /** Defined as the combination of all @c wxTEXT_ATTR_FONT_* values above. */ 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, @@ -290,6 +294,14 @@ public: const wxTextAttr& overlay); + /** + 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 wxTextAttrEx& attr, bool weakTest = true) const; + /** @name GetXXX functions */ @@ -567,10 +579,20 @@ public: bool HasFontItalic() const; /** - Returns @true if the attribute object specifies a font point size. + Returns @true if the attribute object specifies a font point or pixel size. */ bool HasFontSize() const; + /** + Returns @true if the attribute object specifies a font point size. + */ + bool HasFontPointSize() const; + + /** + Returns @true if the attribute object specifies a font pixel size. + */ + bool HasFontPixelSize() const; + /** Returns @true if the attribute object specifies either underlining or no underlining. @@ -738,7 +760,7 @@ public: Sets the attributes for the given font. Note that wxTextAttr does not store an actual wxFont object. */ - void SetFont(const wxFont& font, int flags = wxTEXT_ATTR_FONT); + void SetFont(const wxFont& font, int flags = (wxTEXT_ATTR_FONT & ~wxTEXT_ATTR_FONT_PIXEL_SIZE)); /** Sets the font encoding. @@ -760,6 +782,16 @@ public: */ void SetFontSize(int pointSize); + /** + Sets the font size in points. + */ + void SetFontPointSize(int pointSize); + + /** + Sets the font size in pixels. + */ + void SetFontPixelSize(int pixelSize); + /** Sets the font style (normal, italic or slanted). */ diff --git a/samples/richtext/richtext.cpp b/samples/richtext/richtext.cpp index d50ec7b575..f101c86e5b 100644 --- a/samples/richtext/richtext.cpp +++ b/samples/richtext/richtext.cpp @@ -82,6 +82,61 @@ #include "wx/richtext/richtextprint.h" #include "wx/richtext/richtextimagedlg.h" +// A custom field type +class wxRichTextFieldTypePropertiesTest: public wxRichTextFieldTypeStandard +{ +public: + wxRichTextFieldTypePropertiesTest(const wxString& name, const wxString& label, int displayStyle = wxRICHTEXT_FIELD_STYLE_RECTANGLE): + wxRichTextFieldTypeStandard(name, label, displayStyle) + { + } + wxRichTextFieldTypePropertiesTest(const wxString& name, const wxBitmap& bitmap, int displayStyle = wxRICHTEXT_FIELD_STYLE_RECTANGLE): + wxRichTextFieldTypeStandard(name, bitmap, displayStyle) + { + } + + virtual bool CanEditProperties(wxRichTextField* WXUNUSED(obj)) const { return true; } + virtual bool EditProperties(wxRichTextField* WXUNUSED(obj), wxWindow* WXUNUSED(parent), wxRichTextBuffer* WXUNUSED(buffer)) + { + wxString label = GetLabel(); + wxMessageBox(wxString::Format(wxT("Editing %s"), label.c_str())); + return true; + } + + virtual wxString GetPropertiesMenuLabel(wxRichTextField* WXUNUSED(obj)) const + { + return GetLabel(); + } +}; + +// A custom composite field type +class wxRichTextFieldTypeCompositeTest: public wxRichTextFieldTypePropertiesTest +{ +public: + wxRichTextFieldTypeCompositeTest(const wxString& name, const wxString& label): + wxRichTextFieldTypePropertiesTest(name, label, wxRICHTEXT_FIELD_STYLE_COMPOSITE) + { + } + + virtual bool UpdateField(wxRichTextBuffer* buffer, wxRichTextField* obj) + { + if (buffer) + { + wxRichTextAttr attr(buffer->GetAttributes()); + attr.GetTextBoxAttr().Reset(); + attr.SetParagraphSpacingAfter(0); + attr.SetLineSpacing(10); + obj->SetAttributes(attr); + } + obj->GetChildren().Clear(); + wxRichTextParagraph* para = new wxRichTextParagraph; + wxRichTextPlainText* text = new wxRichTextPlainText(GetLabel()); + para->AppendChild(text); + obj->AppendChild(para); + return true; + } +}; + // ---------------------------------------------------------------------------- // resources // ---------------------------------------------------------------------------- @@ -237,6 +292,9 @@ public: void OnPageSetup(wxCommandEvent& event); void OnInsertImage(wxCommandEvent& event); + + void OnSetFontScale(wxCommandEvent& event); + void OnSetDimensionScale(wxCommandEvent& event); protected: // Forward command events to the current rich text control, if any @@ -302,6 +360,9 @@ enum ID_FORMAT_DEMOTE_LIST, ID_FORMAT_CLEAR_LIST, + ID_SET_FONT_SCALE, + ID_SET_DIMENSION_SCALE, + ID_VIEW_HTML, ID_SWITCH_STYLE_SHEETS, ID_MANAGE_STYLES, @@ -396,6 +457,9 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_TEXT_URL(wxID_ANY, MyFrame::OnURL) EVT_RICHTEXT_STYLESHEET_REPLACING(wxID_ANY, MyFrame::OnStyleSheetReplacing) + + EVT_MENU(ID_SET_FONT_SCALE, MyFrame::OnSetFontScale) + EVT_MENU(ID_SET_DIMENSION_SCALE, MyFrame::OnSetDimensionScale) END_EVENT_TABLE() // Create a new application object: this macro will allow wxWidgets to create @@ -437,6 +501,25 @@ bool MyApp::OnInit() wxRichTextBuffer::AddHandler(new wxRichTextXMLHandler); wxRichTextBuffer::AddHandler(new wxRichTextHTMLHandler); + // Add field types + + wxRichTextBuffer::AddFieldType(new wxRichTextFieldTypePropertiesTest(wxT("rectangle"), wxT("RECTANGLE"), wxRichTextFieldTypeStandard::wxRICHTEXT_FIELD_STYLE_RECTANGLE)); + + wxRichTextFieldTypeStandard* s1 = new wxRichTextFieldTypeStandard(wxT("begin-section"), wxT("SECTION"), wxRichTextFieldTypeStandard::wxRICHTEXT_FIELD_STYLE_START_TAG); + s1->SetBackgroundColour(*wxBLUE); + + wxRichTextFieldTypeStandard* s2 = new wxRichTextFieldTypeStandard(wxT("end-section"), wxT("SECTION"), wxRichTextFieldTypeStandard::wxRICHTEXT_FIELD_STYLE_END_TAG); + s2->SetBackgroundColour(*wxBLUE); + + wxRichTextFieldTypeStandard* s3 = new wxRichTextFieldTypeStandard(wxT("bitmap"), wxBitmap(paste_xpm), wxRichTextFieldTypeStandard::wxRICHTEXT_FIELD_STYLE_NO_BORDER); + + wxRichTextBuffer::AddFieldType(s1); + wxRichTextBuffer::AddFieldType(s2); + wxRichTextBuffer::AddFieldType(s3); + + wxRichTextFieldTypeCompositeTest* s4 = new wxRichTextFieldTypeCompositeTest(wxT("composite"), wxT("This is a field value")); + wxRichTextBuffer::AddFieldType(s4); + // Add image handlers #if wxUSE_LIBPNG wxImage::AddHandler( new wxPNGHandler ); @@ -673,11 +756,9 @@ MyFrame::MyFrame(const wxString& title, wxWindowID id, const wxPoint& pos, editMenu->AppendSeparator(); editMenu->Append(wxID_SELECTALL, _("Select A&ll\tCtrl+A")); -#if 0 editMenu->AppendSeparator(); - editMenu->Append(wxID_FIND, _("&Find...\tCtrl+F")); - editMenu->Append(stID_FIND_REPLACE, _("&Replace...\tCtrl+R")); -#endif + editMenu->Append(ID_SET_FONT_SCALE, _("Set &Text Scale...")); + editMenu->Append(ID_SET_DIMENSION_SCALE, _("Set &Dimension Scale...")); wxMenu* formatMenu = new wxMenu; formatMenu->AppendCheckItem(ID_FORMAT_BOLD, _("&Bold\tCtrl+B")); @@ -802,10 +883,14 @@ MyFrame::MyFrame(const wxString& title, wxWindowID id, const wxPoint& pos, wxFont italicFont = wxFont(12, wxROMAN, wxITALIC, wxNORMAL); m_richTextCtrl = new MyRichTextCtrl(splitter, ID_RICHTEXT_CTRL, wxEmptyString, wxDefaultPosition, wxSize(200, 200), wxVSCROLL|wxHSCROLL|wxWANTS_CHARS); + wxASSERT(!m_richTextCtrl->GetBuffer().GetAttributes().HasFontPixelSize()); + wxFont font(12, wxROMAN, wxNORMAL, wxNORMAL); m_richTextCtrl->SetFont(font); + wxASSERT(!m_richTextCtrl->GetBuffer().GetAttributes().HasFontPixelSize()); + m_richTextCtrl->SetMargins(10, 10); m_richTextCtrl->SetStyleSheet(wxGetApp().GetStyleSheet()); @@ -874,6 +959,13 @@ void MyFrame::WriteInitialText() r.EndAlignment(); +#if 0 + r.BeginAlignment(wxTEXT_ALIGNMENT_CENTRE); + r.WriteText(wxString(wxT("This is a simple test for a floating left image test. The zebra image should be placed at the left side of the current buffer and all the text should flow around it at the right side. This is a simple test for a floating left image test. The zebra image should be placed at the left side of the current buffer and all the text should flow around it at the right side. This is a simple test for a floating left image test. The zebra image should be placed at the left side of the current buffer and all the text should flow around it at the right side."))); + r.Newline(); + r.EndAlignment(); +#endif + r.BeginAlignment(wxTEXT_ALIGNMENT_LEFT); wxRichTextAttr imageAttr; imageAttr.GetTextBoxAttr().SetFloatMode(wxTEXT_BOX_ATTR_FLOAT_LEFT); @@ -1042,8 +1134,8 @@ void MyFrame::WriteInitialText() r.WriteText(wxT("Note: this sample content was generated programmatically from within the MyFrame constructor in the demo. The images were loaded from inline XPMs. Enjoy wxRichTextCtrl!\n")); r.EndParagraphSpacing(); -#if 1 +#if 1 { // Add a text box @@ -1105,6 +1197,23 @@ void MyFrame::WriteInitialText() } #endif + r.Newline(); + + wxRichTextProperties properties; + r.WriteText(wxT("This is a rectangle field: ")); + r.WriteField(wxT("rectangle"), properties); + r.WriteText(wxT(" and a begin section field: ")); + r.WriteField(wxT("begin-section"), properties); + r.WriteText(wxT("This is text between the two tags.")); + r.WriteField(wxT("end-section"), properties); + r.WriteText(wxT(" Now a bitmap. ")); + r.WriteField(wxT("bitmap"), properties); + r.WriteText(wxT(" Before we go, here's a composite field: ***")); + wxRichTextField* field = r.WriteField(wxT("composite"), properties); + field->UpdateField(& r.GetBuffer()); // Creates the composite value (sort of a text box) + r.WriteText(wxT("*** End of composite field.")); + + r.Newline(); r.EndSuppressUndo(); // Add some locked content first - needs Undo to be enabled @@ -1357,39 +1466,13 @@ void MyFrame::OnFont(wxCommandEvent& WXUNUSED(event)) int pages = wxRICHTEXT_FORMAT_FONT; wxRichTextFormattingDialog formatDlg(pages, this); + formatDlg.SetOptions(wxRichTextFormattingDialog::Option_AllowPixelFontSize); formatDlg.GetStyle(m_richTextCtrl, range); if (formatDlg.ShowModal() == wxID_OK) { formatDlg.ApplyStyle(m_richTextCtrl, range, wxRICHTEXT_SETSTYLE_WITH_UNDO|wxRICHTEXT_SETSTYLE_OPTIMIZE|wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY); } - - // Old method using wxFontDialog -#if 0 - if (!m_richTextCtrl->HasSelection()) - return; - - wxRichTextRange range = m_richTextCtrl->GetSelectionRange(); - wxFontData fontData; - - wxRichTextAttr attr; - attr.SetFlags(wxTEXT_ATTR_FONT); - - if (m_richTextCtrl->GetStyle(m_richTextCtrl->GetInsertionPoint(), attr)) - fontData.SetInitialFont(attr.GetFont()); - - wxFontDialog dialog(this, fontData); - if (dialog.ShowModal() == wxID_OK) - { - fontData = dialog.GetFontData(); - attr.SetFlags(wxTEXT_ATTR_FONT); - attr.SetFont(fontData.GetChosenFont()); - if (attr.GetFont().IsOk()) - { - m_richTextCtrl->SetStyle(range, attr); - } - } -#endif } void MyFrame::OnImage(wxCommandEvent& WXUNUSED(event)) @@ -1892,6 +1975,30 @@ void MyFrame::OnPageSetup(wxCommandEvent& WXUNUSED(event)) // wxGetApp().GetPrinting()->PageSetup(); } +void MyFrame::OnSetFontScale(wxCommandEvent& WXUNUSED(event)) +{ + wxString value = wxString::Format(wxT("%g"), m_richTextCtrl->GetFontScale()); + wxString text = wxGetTextFromUser(wxT("Enter a text scale factor:"), wxT("Text Scale Factor"), value, wxGetTopLevelParent(this)); + if (!text.IsEmpty() && value != text) + { + double scale = 1.0; + wxSscanf(text, wxT("%lf"), & scale); + m_richTextCtrl->SetFontScale(scale, true); + } +} + +void MyFrame::OnSetDimensionScale(wxCommandEvent& WXUNUSED(event)) +{ + wxString value = wxString::Format(wxT("%g"), m_richTextCtrl->GetDimensionScale()); + wxString text = wxGetTextFromUser(wxT("Enter a dimension scale factor:"), wxT("Dimension Scale Factor"), value, wxGetTopLevelParent(this)); + if (!text.IsEmpty() && value != text) + { + double scale = 1.0; + wxSscanf(text, wxT("%lf"), & scale); + m_richTextCtrl->SetDimensionScale(scale, true); + } +} + void MyRichTextCtrl::PrepareContent(wxRichTextParagraphLayoutBox& container) { if (IsLocked()) diff --git a/src/common/textcmn.cpp b/src/common/textcmn.cpp index ed3e07f505..541f996a32 100644 --- a/src/common/textcmn.cpp +++ b/src/common/textcmn.cpp @@ -267,117 +267,138 @@ bool wxTextAttr::operator== (const wxTextAttr& attr) const } // Partial equality test. Only returns false if an attribute doesn't match. -bool wxTextAttr::EqPartial(const wxTextAttr& attr) const +bool wxTextAttr::EqPartial(const wxTextAttr& attr, bool weakTest) const { int flags = attr.GetFlags(); - - if ((flags & wxTEXT_ATTR_TEXT_COLOUR) && GetTextColour() != attr.GetTextColour()) + + if (!weakTest && + ((!HasTextColour() && attr.HasTextColour()) || + (!HasBackgroundColour() && attr.HasBackgroundColour()) || + (!HasFontFaceName() && attr.HasFontFaceName()) || + (!HasFontSize() && attr.HasFontSize()) || + (!HasFontWeight() && attr.HasFontWeight()) || + (!HasFontItalic() && attr.HasFontItalic()) || + (!HasFontUnderlined() && attr.HasFontUnderlined()) || + (!HasFontStrikethrough() && attr.HasFontStrikethrough()) || + (!HasFontEncoding() && attr.HasFontEncoding()) || + (!HasFontFamily() && attr.HasFontFamily()) || + (!HasURL() && attr.HasURL()) || + (!HasAlignment() && attr.HasAlignment()) || + (!HasLeftIndent() && attr.HasLeftIndent()) || + (!HasParagraphSpacingAfter() && attr.HasParagraphSpacingAfter()) || + (!HasParagraphSpacingBefore() && attr.HasParagraphSpacingBefore()) || + (!HasLineSpacing() && attr.HasLineSpacing()) || + (!HasCharacterStyleName() && attr.HasCharacterStyleName()) || + (!HasParagraphStyleName() && attr.HasParagraphStyleName()) || + (!HasListStyleName() && attr.HasListStyleName()) || + (!HasBulletStyle() && attr.HasBulletStyle()) || + (!HasBulletNumber() && attr.HasBulletNumber()) || + (!HasBulletText() && attr.HasBulletText()) || + (!HasBulletName() && attr.HasBulletName()) || + (!HasTabs() && attr.HasTabs()) || + (!HasTextEffects() && attr.HasTextEffects()) || + (!HasOutlineLevel() && attr.HasOutlineLevel()))) + { + return false; + } + + if (HasTextColour() && attr.HasTextColour() && GetTextColour() != attr.GetTextColour()) + return false; + + if (HasBackgroundColour() && attr.HasBackgroundColour() && GetBackgroundColour() != attr.GetBackgroundColour()) + return false; + + if (HasFontFaceName() && attr.HasFontFaceName() && GetFontFaceName() != attr.GetFontFaceName()) return false; - if ((flags & wxTEXT_ATTR_BACKGROUND_COLOUR) && GetBackgroundColour() != attr.GetBackgroundColour()) + // This checks whether the two objects have the same font size dimension (px versus pt) + if (HasFontSize() && attr.HasFontSize() && (flags & wxTEXT_ATTR_FONT) != (GetFlags() & wxTEXT_ATTR_FONT)) return false; - if ((flags & wxTEXT_ATTR_FONT_FACE) && - GetFontFaceName() != attr.GetFontFaceName()) + if (HasFontPointSize() && attr.HasFontPointSize() && GetFontSize() != attr.GetFontSize()) return false; - if ((flags & wxTEXT_ATTR_FONT_SIZE) && - GetFontSize() != attr.GetFontSize()) + if (HasFontPixelSize() && attr.HasFontPixelSize() && GetFontSize() != attr.GetFontSize()) return false; - if ((flags & wxTEXT_ATTR_FONT_WEIGHT) && - GetFontWeight() != attr.GetFontWeight()) + if (HasFontWeight() && attr.HasFontWeight() && GetFontWeight() != attr.GetFontWeight()) return false; - if ((flags & wxTEXT_ATTR_FONT_ITALIC) && - GetFontStyle() != attr.GetFontStyle()) + if (HasFontItalic() && attr.HasFontItalic() && GetFontStyle() != attr.GetFontStyle()) return false; - if ((flags & wxTEXT_ATTR_FONT_UNDERLINE) && - GetFontUnderlined() != attr.GetFontUnderlined()) + if (HasFontUnderlined() && attr.HasFontUnderlined() && GetFontUnderlined() != attr.GetFontUnderlined()) return false; - if ((flags & wxTEXT_ATTR_FONT_ENCODING) && - GetFontEncoding() != attr.GetFontEncoding()) + if (HasFontStrikethrough() && attr.HasFontStrikethrough() && GetFontStrikethrough() != attr.GetFontStrikethrough()) return false; - if ((flags & wxTEXT_ATTR_FONT_FAMILY) && - GetFontFamily() != attr.GetFontFamily()) + if (HasFontEncoding() && attr.HasFontEncoding() && GetFontEncoding() != attr.GetFontEncoding()) return false; - if ((flags & wxTEXT_ATTR_URL) && GetURL() != attr.GetURL()) + if (HasFontFamily() && attr.HasFontFamily() && GetFontFamily() != attr.GetFontFamily()) return false; - if ((flags & wxTEXT_ATTR_ALIGNMENT) && GetAlignment() != attr.GetAlignment()) + if (HasURL() && attr.HasURL() && GetURL() != attr.GetURL()) return false; - if ((flags & wxTEXT_ATTR_LEFT_INDENT) && + if (HasAlignment() && attr.HasAlignment() && GetAlignment() != attr.GetAlignment()) + return false; + + if (HasLeftIndent() && attr.HasLeftIndent() && ((GetLeftIndent() != attr.GetLeftIndent()) || (GetLeftSubIndent() != attr.GetLeftSubIndent()))) return false; - if ((flags & wxTEXT_ATTR_RIGHT_INDENT) && - (GetRightIndent() != attr.GetRightIndent())) + if (HasRightIndent() && attr.HasRightIndent() && (GetRightIndent() != attr.GetRightIndent())) return false; - if ((flags & wxTEXT_ATTR_PARA_SPACING_AFTER) && + if (HasParagraphSpacingAfter() && attr.HasParagraphSpacingAfter() && (GetParagraphSpacingAfter() != attr.GetParagraphSpacingAfter())) return false; - if ((flags & wxTEXT_ATTR_PARA_SPACING_BEFORE) && + if (HasParagraphSpacingBefore() && attr.HasParagraphSpacingBefore() && (GetParagraphSpacingBefore() != attr.GetParagraphSpacingBefore())) return false; - if ((flags & wxTEXT_ATTR_LINE_SPACING) && - (GetLineSpacing() != attr.GetLineSpacing())) + if (HasLineSpacing() && attr.HasLineSpacing() && (GetLineSpacing() != attr.GetLineSpacing())) return false; - if ((flags & wxTEXT_ATTR_CHARACTER_STYLE_NAME) && - (GetCharacterStyleName() != attr.GetCharacterStyleName())) + if (HasCharacterStyleName() && attr.HasCharacterStyleName() && (GetCharacterStyleName() != attr.GetCharacterStyleName())) return false; - if ((flags & wxTEXT_ATTR_PARAGRAPH_STYLE_NAME) && - (GetParagraphStyleName() != attr.GetParagraphStyleName())) + if (HasParagraphStyleName() && attr.HasParagraphStyleName() && (GetParagraphStyleName() != attr.GetParagraphStyleName())) return false; - if ((flags & wxTEXT_ATTR_LIST_STYLE_NAME) && - (GetListStyleName() != attr.GetListStyleName())) + if (HasListStyleName() && attr.HasListStyleName() && (GetListStyleName() != attr.GetListStyleName())) return false; - if ((flags & wxTEXT_ATTR_BULLET_STYLE) && - (GetBulletStyle() != attr.GetBulletStyle())) + if (HasBulletStyle() && attr.HasBulletStyle() && (GetBulletStyle() != attr.GetBulletStyle())) return false; - if ((flags & wxTEXT_ATTR_BULLET_NUMBER) && - (GetBulletNumber() != attr.GetBulletNumber())) + if (HasBulletNumber() && attr.HasBulletNumber() && (GetBulletNumber() != attr.GetBulletNumber())) return false; - if ((flags & wxTEXT_ATTR_BULLET_TEXT) && + if (HasBulletText() && attr.HasBulletText() && (GetBulletText() != attr.GetBulletText()) && (GetBulletFont() != attr.GetBulletFont())) return false; - if ((flags & wxTEXT_ATTR_BULLET_NAME) && - (GetBulletName() != attr.GetBulletName())) + if (HasBulletName() && attr.HasBulletName() && (GetBulletName() != attr.GetBulletName())) return false; - if ((flags & wxTEXT_ATTR_TABS) && - !TabsEq(GetTabs(), attr.GetTabs())) + if (HasTabs() && attr.HasTabs() && !TabsEq(GetTabs(), attr.GetTabs())) return false; - if ((flags & wxTEXT_ATTR_PAGE_BREAK) && - (HasPageBreak() != attr.HasPageBreak())) + if ((HasPageBreak() != attr.HasPageBreak())) return false; - if (flags & wxTEXT_ATTR_EFFECTS) + if (HasTextEffects() && attr.HasTextEffects()) { - if (HasTextEffects() != attr.HasTextEffects()) - return false; if (!BitlistsEqPartial(GetTextEffects(), attr.GetTextEffects(), attr.GetTextEffectFlags())) return false; } - if ((flags & wxTEXT_ATTR_OUTLINE_LEVEL) && - (GetOutlineLevel() != attr.GetOutlineLevel())) + if (HasOutlineLevel() && attr.HasOutlineLevel() && (GetOutlineLevel() != attr.GetOutlineLevel())) return false; return true; @@ -393,11 +414,11 @@ wxFont wxTextAttr::GetFont() const if (HasFontSize()) fontSize = GetFontSize(); - int fontStyle = wxNORMAL; + wxFontStyle fontStyle = wxFONTSTYLE_NORMAL; if (HasFontItalic()) fontStyle = GetFontStyle(); - int fontWeight = wxNORMAL; + wxFontWeight fontWeight = wxFONTWEIGHT_NORMAL; if (HasFontWeight()) fontWeight = GetFontWeight(); @@ -406,7 +427,7 @@ wxFont wxTextAttr::GetFont() const underlined = GetFontUnderlined(); bool strikethrough = false; - if ( HasFontStrikethrough() ) + if (HasFontStrikethrough()) strikethrough = GetFontStrikethrough(); wxString fontFaceName; @@ -421,10 +442,20 @@ wxFont wxTextAttr::GetFont() const if (HasFontFamily()) fontFamily = GetFontFamily(); - wxFont font(fontSize, fontFamily, fontStyle, fontWeight, underlined, fontFaceName, encoding); - if ( strikethrough ) - font.SetStrikethrough( true ); - return font; + if (HasFontPixelSize()) + { + wxFont font(wxSize(0, fontSize), fontFamily, fontStyle, fontWeight, underlined, fontFaceName, encoding); + if (strikethrough) + font.SetStrikethrough(true); + return font; + } + else + { + wxFont font(fontSize, fontFamily, fontStyle, fontWeight, underlined, fontFaceName, encoding); + if (strikethrough) + font.SetStrikethrough(true); + return font; + } } // Get attributes from font. @@ -433,8 +464,30 @@ bool wxTextAttr::GetFontAttributes(const wxFont& font, int flags) if (!font.IsOk()) return false; - if (flags & wxTEXT_ATTR_FONT_SIZE) + // If we pass both pixel and point size attributes, this is an indication + // to choose the most appropriate units. + if ((flags & wxTEXT_ATTR_FONT) == wxTEXT_ATTR_FONT) + { + if (font.IsUsingSizeInPixels()) + { + m_fontSize = font.GetPixelSize().y; + flags &= ~wxTEXT_ATTR_FONT_POINT_SIZE; + } + else + { + m_fontSize = font.GetPointSize(); + flags &= ~wxTEXT_ATTR_FONT_PIXEL_SIZE; + } + } + else if (flags & wxTEXT_ATTR_FONT_POINT_SIZE) + { m_fontSize = font.GetPointSize(); + flags &= ~wxTEXT_ATTR_FONT_PIXEL_SIZE; + } + else if (flags & wxTEXT_ATTR_FONT_PIXEL_SIZE) + { + m_fontSize = font.GetPixelSize().y; + } if (flags & wxTEXT_ATTR_FONT_ITALIC) m_fontStyle = font.GetStyle(); @@ -493,10 +546,15 @@ bool wxTextAttr::Apply(const wxTextAttr& style, const wxTextAttr* compareWith) destStyle.SetFontWeight(style.GetFontWeight()); } - if (style.HasFontSize()) + if (style.HasFontPointSize()) + { + if (!(compareWith && compareWith->HasFontPointSize() && compareWith->GetFontSize() == style.GetFontSize())) + destStyle.SetFontPointSize(style.GetFontSize()); + } + else if (style.HasFontPixelSize()) { - if (!(compareWith && compareWith->HasFontSize() && compareWith->GetFontSize() == style.GetFontSize())) - destStyle.SetFontSize(style.GetFontSize()); + if (!(compareWith && compareWith->HasFontPixelSize() && compareWith->GetFontSize() == style.GetFontSize())) + destStyle.SetFontPixelSize(style.GetFontSize()); } if (style.HasFontItalic()) @@ -949,14 +1007,14 @@ bool wxTextCtrlBase::EmulateKeyPress(const wxKeyEvent& event) #ifndef __WIN32__ wxChar ch = 0; int keycode = event.GetKeyCode(); - + long from, to; GetSelection(&from,&to); long insert = GetInsertionPoint(); long last = GetLastPosition(); - - // catch arrow left and right - + + // catch arrow left and right + switch ( keycode ) { case WXK_LEFT: diff --git a/src/richtext/richtextbuffer.cpp b/src/richtext/richtextbuffer.cpp index 349fc01ccb..fb1bdc5472 100644 --- a/src/richtext/richtextbuffer.cpp +++ b/src/richtext/richtextbuffer.cpp @@ -465,21 +465,6 @@ int wxRichTextFloatCollector::HitTest(wxDC& dc, wxRichTextDrawingContext& contex // Helpers for efficiency inline void wxCheckSetFont(wxDC& dc, const wxFont& font) { - // JACS: did I do this some time ago when testing? Should we re-enable it? -#if 0 - const wxFont& font1 = dc.GetFont(); - if (font1.IsOk() && font.IsOk()) - { - if (font1.GetPointSize() == font.GetPointSize() && - font1.GetFamily() == font.GetFamily() && - font1.GetStyle() == font.GetStyle() && - font1.GetWeight() == font.GetWeight() && - font1.GetUnderlined() == font.GetUnderlined() && - font1.GetFamily() == font.GetFamily() && - font1.GetFaceName() == font.GetFaceName()) - return; - } -#endif dc.SetFont(font); } @@ -630,7 +615,7 @@ int wxRichTextObject::ConvertTenthsMMToPixels(wxDC& dc, int units) const // Unscale double scale = 1.0; if (GetBuffer()) - scale = GetBuffer()->GetScale(); + scale = GetBuffer()->GetScale() / GetBuffer()->GetDimensionScale(); int p = ConvertTenthsMMToPixels(dc.GetPPI().x, units, scale); return p; @@ -2052,6 +2037,12 @@ bool wxRichTextParagraphLayoutBox::Layout(wxDC& dc, wxRichTextDrawingContext& co maxWidth = wxMax(maxWidth, w); maxMaxWidth = wxMax(maxMaxWidth, w); } + else + { + // TODO: Make sure the layout box's position reflects + // the position of the children, but without + // breaking layout of a box within a paragraph. + } // TODO: (also in para layout) should set the // object's size to an absolute one if specified, @@ -2372,6 +2363,7 @@ wxRichTextRange wxRichTextParagraphLayoutBox::AddParagraph(const wxString& text, wxRichTextAttr* cStyle = & defaultCharStyle; wxRichTextParagraph* para = new wxRichTextParagraph(text, this, pStyle, cStyle); + para->GetAttributes().GetTextBoxAttr().Reset(); AppendChild(para); @@ -2413,6 +2405,7 @@ wxRichTextRange wxRichTextParagraphLayoutBox::AddParagraphs(const wxString& text size_t len = text.length(); wxString line; wxRichTextParagraph* para = new wxRichTextParagraph(wxEmptyString, this, pStyle, cStyle); + para->GetAttributes().GetTextBoxAttr().Reset(); AppendChild(para); @@ -2430,6 +2423,7 @@ wxRichTextRange wxRichTextParagraphLayoutBox::AddParagraphs(const wxString& text plainText->SetText(line); para = new wxRichTextParagraph(wxEmptyString, this, pStyle, cStyle); + para->GetAttributes().GetTextBoxAttr().Reset(); AppendChild(para); @@ -2479,6 +2473,7 @@ wxRichTextRange wxRichTextParagraphLayoutBox::AddImage(const wxImage& image, wxR wxRichTextAttr* cStyle = & defaultCharStyle; wxRichTextParagraph* para = new wxRichTextParagraph(this, pStyle); + para->GetAttributes().GetTextBoxAttr().Reset(); AppendChild(para); para->AppendChild(new wxRichTextImage(image, this, cStyle)); @@ -3342,6 +3337,7 @@ bool wxRichTextParagraphLayoutBox::DoGetStyle(long position, wxRichTextAttr& sty { // Start with the base style style = GetAttributes(); + style.GetTextBoxAttr().Reset(); // Apply the paragraph style wxRichTextApplyStyle(style, obj->GetAttributes()); @@ -3487,7 +3483,7 @@ bool wxRichTextParagraphLayoutBox::HasCharacterAttributes(const wxRichTextRange& foundCount ++; wxRichTextAttr textAttr = para->GetCombinedAttributes(child->GetAttributes()); - if (wxTextAttrEqPartial(textAttr, style)) + if (textAttr.EqPartial(style, false /* strong test - attributes must be valid in both objects */)) matchingCount ++; } @@ -3530,7 +3526,7 @@ bool wxRichTextParagraphLayoutBox::HasParagraphAttributes(const wxRichTextRange& wxRichTextApplyStyle(textAttr, para->GetAttributes()); foundCount ++; - if (wxTextAttrEqPartial(textAttr, style)) + if (textAttr.EqPartial(style, false /* strong test */)) matchingCount ++; } } @@ -4795,7 +4791,8 @@ bool wxRichTextParagraph::Layout(wxDC& dc, wxRichTextDrawingContext& context, co if (child->IsTopLevel()) { // We can move it to the correct position at this point - child->Move(GetPosition() + wxPoint(currentWidth, currentPosition.y)); + // TODO: probably need to add margin + child->Move(GetPosition() + wxPoint(currentWidth + (wxMax(leftIndent, leftIndent + leftSubIndent)), currentPosition.y)); } // Cases: @@ -5052,6 +5049,7 @@ void wxRichTextParagraph::ApplyParagraphStyle(wxRichTextLine* line, const wxRich return; wxPoint pos = line->GetPosition(); + wxPoint originalPos = pos; wxSize size = line->GetSize(); // centering, right-justification @@ -5067,6 +5065,22 @@ void wxRichTextParagraph::ApplyParagraphStyle(wxRichTextLine* line, const wxRich pos.x = pos.x + rect.GetWidth() - size.x - rightIndent; line->SetPosition(pos); } + + if (pos != originalPos) + { + wxPoint inc = pos - originalPos; + + wxRichTextObjectList::compatibility_iterator node = m_children.GetFirst(); + + while (node) + { + wxRichTextObject* child = node->GetData(); + if (child->IsTopLevel() && !child->GetRange().IsOutside(line->GetAbsoluteRange())) + child->Move(child->GetPosition() + inc); + + node = node->GetNext(); + } + } } /// Insert text at the given position @@ -6256,19 +6270,40 @@ bool wxRichTextPlainText::Draw(wxDC& dc, wxRichTextDrawingContext& context, cons { if ( textAttr.HasTextEffects() && (textAttr.GetTextEffects() & wxTEXT_ATTR_EFFECT_SUPERSCRIPT) ) { - double size = static_cast(textFont.GetPointSize()) / wxSCRIPT_MUL_FACTOR; - textFont.SetPointSize( static_cast(size) ); - x = rect.x; - y = rect.y; + if (textFont.IsUsingSizeInPixels()) + { + double size = static_cast(textFont.GetPixelSize().y) / wxSCRIPT_MUL_FACTOR; + textFont.SetPixelSize(wxSize(0, static_cast(size)) ); + x = rect.x; + y = rect.y; + } + else + { + double size = static_cast(textFont.GetPointSize()) / wxSCRIPT_MUL_FACTOR; + textFont.SetPointSize( static_cast(size) ); + x = rect.x; + y = rect.y; + } wxCheckSetFont(dc, textFont); } else if ( textAttr.HasTextEffects() && (textAttr.GetTextEffects() & wxTEXT_ATTR_EFFECT_SUBSCRIPT) ) { - double size = static_cast(textFont.GetPointSize()) / wxSCRIPT_MUL_FACTOR; - textFont.SetPointSize( static_cast(size) ); - x = rect.x; - int sub_height = static_cast( static_cast(charHeight) / wxSCRIPT_MUL_FACTOR); - y = rect.y + (rect.height - sub_height + (descent - m_descent)); + if (textFont.IsUsingSizeInPixels()) + { + double size = static_cast(textFont.GetPixelSize().y) / wxSCRIPT_MUL_FACTOR; + textFont.SetPixelSize(wxSize(0, static_cast(size))); + x = rect.x; + int sub_height = static_cast( static_cast(charHeight) / wxSCRIPT_MUL_FACTOR); + y = rect.y + (rect.height - sub_height + (descent - m_descent)); + } + else + { + double size = static_cast(textFont.GetPointSize()) / wxSCRIPT_MUL_FACTOR; + textFont.SetPointSize( static_cast(size) ); + x = rect.x; + int sub_height = static_cast( static_cast(charHeight) / wxSCRIPT_MUL_FACTOR); + y = rect.y + (rect.height - sub_height + (descent - m_descent)); + } wxCheckSetFont(dc, textFont); } else @@ -6558,8 +6593,16 @@ bool wxRichTextPlainText::GetRangeSize(const wxRichTextRange& range, wxSize& siz || (textAttr.GetTextEffects() & wxTEXT_ATTR_EFFECT_SUBSCRIPT) ) ) { wxFont textFont = font; - double size = static_cast(textFont.GetPointSize()) / wxSCRIPT_MUL_FACTOR; - textFont.SetPointSize( static_cast(size) ); + if (textFont.IsUsingSizeInPixels()) + { + double size = static_cast(textFont.GetPixelSize().y) / wxSCRIPT_MUL_FACTOR; + textFont.SetPixelSize(wxSize(0, static_cast(size))); + } + else + { + double size = static_cast(textFont.GetPointSize()) / wxSCRIPT_MUL_FACTOR; + textFont.SetPointSize(static_cast(size)); + } wxCheckSetFont(dc, textFont); bScript = true; } @@ -6852,6 +6895,8 @@ void wxRichTextBuffer::Init() m_suppressUndo = 0; m_handlerFlags = 0; m_scale = 1.0; + m_dimensionScale = 1.0; + m_fontScale = 1.0; SetMargins(4); } @@ -6887,6 +6932,8 @@ void wxRichTextBuffer::Copy(const wxRichTextBuffer& obj) m_batchedCommand = NULL; m_suppressUndo = obj.m_suppressUndo; m_invalidRange = obj.m_invalidRange; + m_dimensionScale = obj.m_dimensionScale; + m_fontScale = obj.m_fontScale; } /// Push style sheet to top of stack @@ -7007,6 +7054,8 @@ bool wxRichTextParagraphLayoutBox::InsertNewlineWithUndo(wxRichTextBuffer* buffe } wxRichTextAttr attr(buffer->GetDefaultStyle()); + // Don't include box attributes such as margins + attr.GetTextBoxAttr().Reset(); wxRichTextParagraph* newPara = new wxRichTextParagraph(wxEmptyString, this, & attr); action->GetNewParagraphs().AppendChild(newPara); @@ -7034,13 +7083,13 @@ bool wxRichTextParagraphLayoutBox::InsertNewlineWithUndo(wxRichTextBuffer* buffe action->SetPosition(pos); - // Use the default character style // Use the default character style if (!buffer->GetDefaultStyle().IsDefault() && newPara->GetChildren().GetFirst()) { // Check whether the default style merely reflects the paragraph/basic style, // in which case don't apply it. wxRichTextAttr defaultStyle(buffer->GetDefaultStyle()); + defaultStyle.GetTextBoxAttr().Reset(); wxRichTextAttr toApply; if (para) { @@ -7090,6 +7139,9 @@ bool wxRichTextParagraphLayoutBox::InsertImageWithUndo(wxRichTextBuffer* buffer, wxRichTextAttr attr(buffer->GetDefaultStyle()); + // Don't include box attributes such as margins + attr.GetTextBoxAttr().Reset(); + wxRichTextParagraph* newPara = new wxRichTextParagraph(this, & attr); if (p) newPara->SetAttributes(*p); @@ -7134,6 +7186,9 @@ wxRichTextObject* wxRichTextParagraphLayoutBox::InsertObjectWithUndo(wxRichTextB wxRichTextAttr attr(buffer->GetDefaultStyle()); + // Don't include box attributes such as margins + attr.GetTextBoxAttr().Reset(); + wxRichTextParagraph* newPara = new wxRichTextParagraph(this, & attr); if (p) newPara->SetAttributes(*p); @@ -7173,6 +7228,9 @@ wxRichTextField* wxRichTextParagraphLayoutBox::InsertFieldWithUndo(wxRichTextBuf wxRichTextAttr attr(buffer->GetDefaultStyle()); + // Don't include box attributes such as margins + attr.GetTextBoxAttr().Reset(); + wxRichTextParagraph* newPara = new wxRichTextParagraph(this, & attr); if (p) newPara->SetAttributes(*p); @@ -7392,9 +7450,10 @@ bool wxRichTextBuffer::EndSuppressUndo() bool wxRichTextBuffer::BeginStyle(const wxRichTextAttr& style) { wxRichTextAttr newStyle(GetDefaultStyle()); + newStyle.GetTextBoxAttr().Reset(); // Save the old default style - m_attributeStack.Append((wxObject*) new wxRichTextAttr(GetDefaultStyle())); + m_attributeStack.Append((wxObject*) new wxRichTextAttr(newStyle)); wxRichTextApplyStyle(newStyle, style); newStyle.SetFlags(style.GetFlags()|newStyle.GetFlags()); @@ -8142,6 +8201,17 @@ int wxRichTextBuffer::HitTest(wxDC& dc, wxRichTextDrawingContext& context, const } } +void wxRichTextBuffer::SetFontScale(double fontScale) +{ + m_fontScale = fontScale; + m_fontTable.SetFontScale(fontScale); +} + +void wxRichTextBuffer::SetDimensionScale(double dimScale) +{ + m_dimensionScale = dimScale; +} + bool wxRichTextStdRenderer::DrawStandardBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxRichTextAttr& bulletAttr, const wxRect& rect) { if (bulletAttr.GetTextColour().IsOk()) @@ -8230,7 +8300,10 @@ bool wxRichTextStdRenderer::DrawTextBullet(wxRichTextParagraph* paragraph, wxDC& if ((attr.GetBulletStyle() & wxTEXT_ATTR_BULLET_STYLE_SYMBOL) && !attr.GetBulletFont().IsEmpty() && attr.HasFont()) { wxRichTextAttr fontAttr; - fontAttr.SetFontSize(attr.GetFontSize()); + if (attr.HasFontPixelSize()) + fontAttr.SetFontPixelSize(attr.GetFontSize()); + else + fontAttr.SetFontPointSize(attr.GetFontSize()); fontAttr.SetFontStyle(attr.GetFontStyle()); fontAttr.SetFontWeight(attr.GetFontWeight()); fontAttr.SetFontUnderlined(attr.GetFontUnderlined()); @@ -8401,7 +8474,7 @@ void wxRichTextField::Copy(const wxRichTextField& obj) { wxRichTextParagraphLayoutBox::Copy(obj); - UpdateField(); + UpdateField(GetBuffer()); } // Edit properties via a GUI @@ -8432,11 +8505,11 @@ wxString wxRichTextField::GetPropertiesMenuLabel() const return wxEmptyString; } -bool wxRichTextField::UpdateField() +bool wxRichTextField::UpdateField(wxRichTextBuffer* buffer) { wxRichTextFieldType* fieldType = wxRichTextBuffer::FindFieldType(GetFieldType()); if (fieldType) - return fieldType->UpdateField((wxRichTextField*) this); + return fieldType->UpdateField(buffer, (wxRichTextField*) this); return false; } @@ -10874,12 +10947,6 @@ bool wxTextAttrEq(const wxRichTextAttr& attr1, const wxRichTextAttr& attr2) return (attr1 == attr2); } -// Partial equality test taking flags into account -bool wxTextAttrEqPartial(const wxRichTextAttr& attr1, const wxRichTextAttr& attr2) -{ - return attr1.EqPartial(attr2); -} - /// Compare tabs bool wxRichTextTabsEq(const wxArrayInt& tabs1, const wxArrayInt& tabs2) { @@ -11494,22 +11561,48 @@ class wxRichTextFontTableData: public wxObjectRefData public: wxRichTextFontTableData() {} - wxFont FindFont(const wxRichTextAttr& fontSpec); + wxFont FindFont(const wxRichTextAttr& fontSpec, double fontScale); wxRichTextFontTableHashMap m_hashMap; }; -wxFont wxRichTextFontTableData::FindFont(const wxRichTextAttr& fontSpec) +wxFont wxRichTextFontTableData::FindFont(const wxRichTextAttr& fontSpec, double fontScale) { wxString facename(fontSpec.GetFontFaceName()); - wxString spec(wxString::Format(wxT("%d-%d-%d-%d-%s-%d"), fontSpec.GetFontSize(), fontSpec.GetFontStyle(), fontSpec.GetFontWeight(), (int) fontSpec.GetFontUnderlined(), facename.c_str(), (int) fontSpec.GetFontEncoding())); - wxRichTextFontTableHashMap::iterator entry = m_hashMap.find(spec); + int fontSize = fontSpec.GetFontSize(); + if (fontScale != 1.0) + fontSize = (int) ((double(fontSize) * fontScale) + 0.5); + + wxString units; + if (fontSpec.HasFontPixelSize() && !fontSpec.HasFontPointSize()) + units = wxT("px"); + else + units = wxT("pt"); + wxString spec = wxString::Format(wxT("%d-%s-%d-%d-%d-%d-%s-%d"), + fontSize, units.c_str(), fontSpec.GetFontStyle(), fontSpec.GetFontWeight(), (int) fontSpec.GetFontUnderlined(), (int) fontSpec.GetFontStrikethrough(), + facename.c_str(), (int) fontSpec.GetFontEncoding()); + + wxRichTextFontTableHashMap::iterator entry = m_hashMap.find(spec); if ( entry == m_hashMap.end() ) { - wxFont font(fontSpec.GetFontSize(), wxDEFAULT, fontSpec.GetFontStyle(), fontSpec.GetFontWeight(), fontSpec.GetFontUnderlined(), facename.c_str()); - m_hashMap[spec] = font; - return font; + if (fontSpec.HasFontPixelSize() && !fontSpec.HasFontPointSize()) + { + wxFont font(wxSize(0, fontSize), wxDEFAULT, fontSpec.GetFontStyle(), fontSpec.GetFontWeight(), fontSpec.GetFontUnderlined(), facename.c_str()); + if (fontSpec.HasFontStrikethrough() && fontSpec.GetFontStrikethrough()) + font.SetStrikethrough(true); + m_hashMap[spec] = font; + return font; + } + else + { + wxFont font(fontSize, wxDEFAULT, fontSpec.GetFontStyle(), fontSpec.GetFontWeight(), fontSpec.GetFontUnderlined(), facename.c_str()); + if (fontSpec.HasFontStrikethrough() && fontSpec.GetFontStrikethrough()) + font.SetStrikethrough(true); + + m_hashMap[spec] = font; + return font; + } } else { @@ -11522,6 +11615,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxRichTextFontTable, wxObject) wxRichTextFontTable::wxRichTextFontTable() { m_refData = new wxRichTextFontTableData; + m_fontScale = 1.0; } wxRichTextFontTable::wxRichTextFontTable(const wxRichTextFontTable& table) @@ -11543,13 +11637,14 @@ bool wxRichTextFontTable::operator == (const wxRichTextFontTable& table) const void wxRichTextFontTable::operator= (const wxRichTextFontTable& table) { Ref(table); + m_fontScale = table.m_fontScale; } wxFont wxRichTextFontTable::FindFont(const wxRichTextAttr& fontSpec) { wxRichTextFontTableData* data = (wxRichTextFontTableData*) m_refData; if (data) - return data->FindFont(fontSpec); + return data->FindFont(fontSpec, m_fontScale); else return wxFont(); } @@ -11561,6 +11656,13 @@ void wxRichTextFontTable::Clear() data->m_hashMap.clear(); } +void wxRichTextFontTable::SetFontScale(double fontScale) +{ + if (fontScale != m_fontScale) + Clear(); + m_fontScale = fontScale; +} + // wxTextBoxAttr void wxTextBoxAttr::Reset() @@ -11610,8 +11712,17 @@ bool wxTextBoxAttr::operator== (const wxTextBoxAttr& attr) const } // Partial equality test -bool wxTextBoxAttr::EqPartial(const wxTextBoxAttr& attr) const +bool wxTextBoxAttr::EqPartial(const wxTextBoxAttr& attr, bool weakTest) const { + if (!weakTest && + ((!HasFloatMode() && attr.HasFloatMode()) || + (!HasClearMode() && attr.HasClearMode()) || + (!HasCollapseBorders() && attr.HasCollapseBorders()) || + (!HasVerticalAlignment() && attr.HasVerticalAlignment()) || + (!HasBoxStyleName() && attr.HasBoxStyleName()))) + { + return false; + } if (attr.HasFloatMode() && HasFloatMode() && (GetFloatMode() != attr.GetFloatMode())) return false; @@ -11629,36 +11740,36 @@ bool wxTextBoxAttr::EqPartial(const wxTextBoxAttr& attr) const // Position - if (!m_position.EqPartial(attr.m_position)) + if (!m_position.EqPartial(attr.m_position, weakTest)) return false; // Size - if (!m_size.EqPartial(attr.m_size)) + if (!m_size.EqPartial(attr.m_size, weakTest)) return false; - if (!m_minSize.EqPartial(attr.m_minSize)) + if (!m_minSize.EqPartial(attr.m_minSize, weakTest)) return false; - if (!m_maxSize.EqPartial(attr.m_maxSize)) + if (!m_maxSize.EqPartial(attr.m_maxSize, weakTest)) return false; // Margins - if (!m_margins.EqPartial(attr.m_margins)) + if (!m_margins.EqPartial(attr.m_margins, weakTest)) return false; // Padding - if (!m_padding.EqPartial(attr.m_padding)) + if (!m_padding.EqPartial(attr.m_padding, weakTest)) return false; // Border - if (!GetBorder().EqPartial(attr.GetBorder())) + if (!GetBorder().EqPartial(attr.GetBorder(), weakTest)) return false; // Outline - if (!GetOutline().EqPartial(attr.GetOutline())) + if (!GetOutline().EqPartial(attr.GetOutline(), weakTest)) return false; return true; @@ -11883,13 +11994,13 @@ bool wxRichTextAttr::operator==(const wxRichTextAttr& attr) const return (m_textBoxAttr == attr.m_textBoxAttr); } -// Partial equality test taking comparison object into account -bool wxRichTextAttr::EqPartial(const wxRichTextAttr& attr) const +// Partial equality test +bool wxRichTextAttr::EqPartial(const wxRichTextAttr& attr, bool weakTest) const { - if (!(wxTextAttr::EqPartial(attr))) + if (!(wxTextAttr::EqPartial(attr, weakTest))) return false; - return m_textBoxAttr.EqPartial(attr.m_textBoxAttr); + return m_textBoxAttr.EqPartial(attr.m_textBoxAttr, weakTest); } // Merges the given attributes. If compareWith @@ -11920,15 +12031,23 @@ void wxRichTextAttr::CollectCommonAttributes(const wxRichTextAttr& attr, wxRichT } // Partial equality test -bool wxTextAttrBorder::EqPartial(const wxTextAttrBorder& border) const +bool wxTextAttrBorder::EqPartial(const wxTextAttrBorder& border, bool weakTest) const { - if (border.HasStyle() && !HasStyle() && (border.GetStyle() != GetStyle())) + if (!weakTest && + ((!HasStyle() && border.HasStyle()) || + (!HasColour() && border.HasColour()) || + (!HasWidth() && border.HasWidth()))) + { + return false; + } + + if (border.HasStyle() && HasStyle() && (border.GetStyle() != GetStyle())) return false; - if (border.HasColour() && !HasColour() && (border.GetColourLong() != GetColourLong())) + if (border.HasColour() && HasColour() && (border.GetColourLong() != GetColourLong())) return false; - if (border.HasWidth() && !HasWidth() && !(border.GetWidth() == GetWidth())) + if (border.HasWidth() && HasWidth() && !(border.GetWidth() == GetWidth())) return false; return true; @@ -12015,10 +12134,10 @@ void wxTextAttrBorder::CollectCommonAttributes(const wxTextAttrBorder& attr, wxT } // Partial equality test -bool wxTextAttrBorders::EqPartial(const wxTextAttrBorders& borders) const +bool wxTextAttrBorders::EqPartial(const wxTextAttrBorders& borders, bool weakTest) const { - return m_left.EqPartial(borders.m_left) && m_right.EqPartial(borders.m_right) && - m_top.EqPartial(borders.m_top) && m_bottom.EqPartial(borders.m_bottom); + return m_left.EqPartial(borders.m_left, weakTest) && m_right.EqPartial(borders.m_right, weakTest) && + m_top.EqPartial(borders.m_top, weakTest) && m_bottom.EqPartial(borders.m_bottom, weakTest); } // Apply border to 'this', but not if the same as compareWith @@ -12087,8 +12206,11 @@ void wxTextAttrBorders::SetWidth(const wxTextAttrDimension& width) } // Partial equality test -bool wxTextAttrDimension::EqPartial(const wxTextAttrDimension& dim) const +bool wxTextAttrDimension::EqPartial(const wxTextAttrDimension& dim, bool weakTest) const { + if (!weakTest && !IsValid() && dim.IsValid()) + return false; + if (dim.IsValid() && IsValid() && !((*this) == dim)) return false; else @@ -12185,18 +12307,18 @@ int wxTextAttrDimensionConverter::GetTenthsMM(const wxTextAttrDimension& dim) co } // Partial equality test -bool wxTextAttrDimensions::EqPartial(const wxTextAttrDimensions& dims) const +bool wxTextAttrDimensions::EqPartial(const wxTextAttrDimensions& dims, bool weakTest) const { - if (!m_left.EqPartial(dims.m_left)) + if (!m_left.EqPartial(dims.m_left, weakTest)) return false; - if (!m_right.EqPartial(dims.m_right)) + if (!m_right.EqPartial(dims.m_right, weakTest)) return false; - if (!m_top.EqPartial(dims.m_top)) + if (!m_top.EqPartial(dims.m_top, weakTest)) return false; - if (!m_bottom.EqPartial(dims.m_bottom)) + if (!m_bottom.EqPartial(dims.m_bottom, weakTest)) return false; return true; @@ -12239,12 +12361,12 @@ void wxTextAttrDimensions::CollectCommonAttributes(const wxTextAttrDimensions& a } // Partial equality test -bool wxTextAttrSize::EqPartial(const wxTextAttrSize& size) const +bool wxTextAttrSize::EqPartial(const wxTextAttrSize& size, bool weakTest) const { - if (!m_width.EqPartial(size.m_width)) + if (!m_width.EqPartial(size.m_width, weakTest)) return false; - if (!m_height.EqPartial(size.m_height)) + if (!m_height.EqPartial(size.m_height, weakTest)) return false; return true; @@ -12289,21 +12411,36 @@ void wxTextAttrCollectCommonAttributes(wxTextAttr& currentStyle, const wxTextAtt if (attr.HasFont()) { - if (attr.HasFontSize() && !wxHasStyle(forbiddenFlags, wxTEXT_ATTR_FONT_SIZE)) + if (attr.HasFontPointSize() && !wxHasStyle(forbiddenFlags, wxTEXT_ATTR_FONT_POINT_SIZE)) { - if (currentStyle.HasFontSize()) + if (currentStyle.HasFontPointSize()) { if (currentStyle.GetFontSize() != attr.GetFontSize()) { // Clash of attr - mark as such - clashingAttr.AddFlag(wxTEXT_ATTR_FONT_SIZE); - currentStyle.RemoveFlag(wxTEXT_ATTR_FONT_SIZE); + clashingAttr.AddFlag(wxTEXT_ATTR_FONT_POINT_SIZE); + currentStyle.RemoveFlag(wxTEXT_ATTR_FONT_POINT_SIZE); } } else currentStyle.SetFontSize(attr.GetFontSize()); } + if (attr.HasFontPixelSize() && !wxHasStyle(forbiddenFlags, wxTEXT_ATTR_FONT_PIXEL_SIZE)) + { + if (currentStyle.HasFontPixelSize()) + { + if (currentStyle.GetFontSize() != attr.GetFontSize()) + { + // Clash of attr - mark as such + clashingAttr.AddFlag(wxTEXT_ATTR_FONT_PIXEL_SIZE); + currentStyle.RemoveFlag(wxTEXT_ATTR_FONT_PIXEL_SIZE); + } + } + else + currentStyle.SetFontPixelSize(attr.GetFontSize()); + } + if (attr.HasFontItalic() && !wxHasStyle(forbiddenFlags, wxTEXT_ATTR_FONT_ITALIC)) { if (currentStyle.HasFontItalic()) @@ -12381,6 +12518,21 @@ void wxTextAttrCollectCommonAttributes(wxTextAttr& currentStyle, const wxTextAtt else currentStyle.SetFontUnderlined(attr.GetFontUnderlined()); } + + if (attr.HasFontStrikethrough() && !wxHasStyle(forbiddenFlags, wxTEXT_ATTR_FONT_STRIKETHROUGH)) + { + if (currentStyle.HasFontStrikethrough()) + { + if (currentStyle.GetFontStrikethrough() != attr.GetFontStrikethrough()) + { + // Clash of attr - mark as such + clashingAttr.AddFlag(wxTEXT_ATTR_FONT_STRIKETHROUGH); + currentStyle.RemoveFlag(wxTEXT_ATTR_FONT_STRIKETHROUGH); + } + } + else + currentStyle.SetFontStrikethrough(attr.GetFontStrikethrough()); + } } if (attr.HasTextColour() && !wxHasStyle(forbiddenFlags, wxTEXT_ATTR_TEXT_COLOUR)) diff --git a/src/richtext/richtextctrl.cpp b/src/richtext/richtextctrl.cpp index 30e9fa2ce4..e4ab3de176 100644 --- a/src/richtext/richtextctrl.cpp +++ b/src/richtext/richtextctrl.cpp @@ -264,7 +264,6 @@ bool wxRichTextCtrl::Create( wxWindow* parent, wxWindowID id, const wxString& va attributes.SetLineSpacing(10); attributes.SetParagraphSpacingAfter(10); attributes.SetParagraphSpacingBefore(0); - SetBasicStyle(attributes); int margin = 5; @@ -2931,6 +2930,7 @@ void wxRichTextCtrl::DoWriteText(const wxString& value, int flags) wxString valueUnix = wxTextFile::Translate(value, wxTextFileType_Unix); GetFocusObject()->InsertTextWithUndo(& GetBuffer(), m_caretPosition+1, valueUnix, this, wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE); + GetBuffer().Defragment(); if ( flags & SetValue_SendEvent ) wxTextCtrl::SendTextUpdatedEvent(this); @@ -4580,6 +4580,26 @@ void wxRichTextCtrl::EnableVerticalScrollbar(bool enable) SetupScrollbars(); } +void wxRichTextCtrl::SetFontScale(double fontScale, bool refresh) +{ + GetBuffer().SetFontScale(fontScale); + if (refresh) + { + GetBuffer().Invalidate(wxRICHTEXT_ALL); + Refresh(); + } +} + +void wxRichTextCtrl::SetDimensionScale(double dimScale, bool refresh) +{ + GetBuffer().SetDimensionScale(dimScale); + if (refresh) + { + GetBuffer().Invalidate(wxRICHTEXT_ALL); + Refresh(); + } +} + #if wxRICHTEXT_USE_OWN_CARET // ---------------------------------------------------------------------------- diff --git a/src/richtext/richtextdialogs.pjd b/src/richtext/richtextdialogs.pjd index 0323f23475..96c154f3d0 100644 --- a/src/richtext/richtextdialogs.pjd +++ b/src/richtext/richtextdialogs.pjd @@ -234,6 +234,7 @@ "Standard" 0 0 + "wxEVT_IDLE|OnIdle|NONE||wxRichTextFontPage" "ID_RICHTEXTFONTPAGE" 10000 "wxRichTextFontPage" @@ -307,14 +308,6 @@ "wbBoxSizerProxy" "Vertical" "" - "Centre" - "Centre" - 0 - 5 - 1 - 1 - 1 - 1 0 0 0 @@ -549,29 +542,56 @@ "" "" + + + "wxBoxSizer V" + "dialog-control-document" + "" + "sizer" + 0 + 1 + 0 + 0 + "2/10/2006" + "wbBoxSizerProxy" + "Vertical" + "" + "Centre" + "Expand" + 0 + 5 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + "<Any platform>" - "wxRichTextFontListBox: ID_RICHTEXTFONTPAGE_FACELISTBOX" + "wxStaticText: wxID_STATIC" "dialog-control-document" "" - "foreign" + "statictext" 0 1 0 0 "2/10/2006" - "wbForeignCtrlProxy" - "ID_RICHTEXTFONTPAGE_FACELISTBOX" - 10002 + "wbStaticTextProxy" + "wxID_STATIC" + 5105 "" - "wxRichTextFontListBox" - "wxWindow" + "wxStaticText" + "wxStaticText" 1 0 "" "" - "m_faceListBox" - 1 - "Lists the available fonts." + "" + "&Size:" + -1 + "" "" "" "" @@ -586,6 +606,10 @@ "" "" "" + 0 + 0 + 0 + 0 0 0 0 @@ -596,286 +620,435 @@ 0 0 0 - 0 - 0 - 0 - 0 "" -1 -1 - 200 - 100 - "Expand" + -1 + -1 + "Left" "Centre" - 1 + 0 5 1 1 1 - 1 + 0 0 0 - 1 + 0 "" "" - "" + + + "wxBoxSizer H" + "dialog-control-document" + "" + "sizer" + 0 + 1 + 0 + 0 + "wbBoxSizerProxy" + "Horizontal" + "" + "Expand" + "Centre" + 0 + 5 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + "<Any platform>" + + "wxTextCtrl: ID_RICHTEXTFONTPAGE_SIZETEXTCTRL" + "dialog-control-document" + "" + "textctrl" + 0 + 1 + 0 + 0 + "wbTextCtrlProxy" + "wxEVT_COMMAND_TEXT_UPDATED|OnSizeTextCtrlUpdated" + "ID_RICHTEXTFONTPAGE_SIZETEXTCTRL" + 10005 + "" + "wxTextCtrl" + "wxTextCtrl" + 1 + 0 + "" + "" + "m_sizeTextCtrl" + "" + 0 + "Type a size in points." + "" + "" + "" + "" + 0 + 1 + "<Any platform>" + "" + "" + "" + "" + "" + "" + "" + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + "" + -1 + -1 + 50 + -1 + "Expand" + "Centre" + 0 + 5 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + "" + "" + + + "wxSpinButton: ID_RICHTEXTFONTPAGE_SPINBUTTONS" + "dialog-control-document" + "" + "spinctrl" + 0 + 1 + 0 + 0 + "wbSpinButtonProxy" + "wxEVT_SCROLL_LINEUP|OnRichtextfontpageSpinbuttonsUp|NONE||wxRichTextFontPage" + "wxEVT_SCROLL_LINEDOWN|OnRichtextfontpageSpinbuttonsDown|NONE||wxRichTextFontPage" + "ID_RICHTEXTFONTPAGE_SPINBUTTONS" + 10018 + "" + "wxSpinButton" + "wxSpinButton" + 1 + 0 + "" + "" + "m_fontSizeSpinButtons" + 0 + 100 + 0 + "" + "" + "" + "" + "" + 0 + 1 + "<Any platform>" + "" + "" + "" + "" + "" + "" + "" + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + "" + -1 + -1 + -1 + 20 + "Centre" + "Centre" + 0 + 5 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + "" + "" + + + "wxChoice: ID_RICHTEXTFONTPAGE_SIZE_UNITS" + "dialog-control-document" + "" + "choice" + 0 + 1 + 0 + 0 + "wbChoiceProxy" + "wxEVT_COMMAND_CHOICE_SELECTED|OnRichtextfontpageSizeUnitsSelected|NONE||wxRichTextFontPage" + "ID_RICHTEXTFONTPAGE_SIZE_UNITS" + 10017 + "" + "wxChoice" + "wxChoice" + 1 + 0 + "" + "" + "m_sizeUnitsCtrl" + "pt|px" + "pt" + "The font size units, points or pixels." + "" + "" + "" + "" + 0 + 1 + "<Any platform>" + "" + "" + "" + "" + "" + "" + "" + 0 + 0 + 0 + "" + -1 + -1 + -1 + -1 + "Expand" + "Centre" + 0 + 5 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + "" + "" + + + + "wxBoxSizer H" + "dialog-control-document" + "" + "sizer" + 0 + 1 + 0 + 0 + "wbBoxSizerProxy" + "Horizontal" + "m_fontListBoxParent" + "Expand" + "Centre" + 0 + 5 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + "<Any platform>" - "wxBoxSizer V" + "wxRichTextFontListBox: ID_RICHTEXTFONTPAGE_FACELISTBOX" "dialog-control-document" "" - "sizer" + "foreign" 0 1 0 0 - "2/10/2006" - "wbBoxSizerProxy" - "Vertical" - "" + "wbForeignCtrlProxy" + "ID_RICHTEXTFONTPAGE_FACELISTBOX" + 10002 + "" + "wxRichTextFontListBox" + "wxWindow" + 1 + 0 + "" + "" + "m_faceListBox" + 1 + "Lists the available fonts." + "" + "" + "" + "" + 0 + 1 + "<Any platform>" + "" + "" + "" + "" + "" + "" + "" + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + "" + -1 + -1 + 200 + 100 + "Expand" + "Centre" + 1 + 5 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + "" + "" + "" + + + "wxListBox: ID_RICHTEXTFONTPAGE_SIZELISTBOX" + "dialog-control-document" + "" + "listbox" + 0 + 1 + 0 + 0 + "wbListBoxProxy" + "wxEVT_COMMAND_LISTBOX_SELECTED|OnSizeListBoxSelected" + "ID_RICHTEXTFONTPAGE_SIZELISTBOX" + 10006 + "" + "wxListBox" + "wxListBox" + 1 + 0 + "" + "" + "m_sizeListBox" + "" + "" + "Lists font sizes in points." + "" + "" + "" + "" + 0 + 1 + "<Any platform>" + "" + "" + "" + "" + "" + "" + "" + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + "" + -1 + -1 + 50 + -1 "Centre" "Expand" 0 5 - 0 - 0 - 0 - 0 + 1 + 1 + 1 + 1 0 0 - 0 - "<Any platform>" - - "wxStaticText: wxID_STATIC" - "dialog-control-document" - "" - "statictext" - 0 - 1 - 0 - 0 - "2/10/2006" - "wbStaticTextProxy" - "wxID_STATIC" - 5105 - "" - "wxStaticText" - "wxStaticText" - 1 - 0 - "" - "" - "" - "&Size:" - -1 - "" - "" - "" - "" - "" - 0 - 1 - "<Any platform>" - "" - "" - "" - "" - "" - "" - "" - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - "" - -1 - -1 - -1 - -1 - "Left" - "Centre" - 0 - 5 - 1 - 1 - 1 - 0 - 0 - 0 - 0 - "" - "" - - - "wxTextCtrl: ID_RICHTEXTFONTPAGE_SIZETEXTCTRL" - "dialog-control-document" - "" - "textctrl" - 0 - 1 - 0 - 0 - "2/10/2006" - "wbTextCtrlProxy" - "wxEVT_COMMAND_TEXT_UPDATED|OnSizeTextCtrlUpdated" - "ID_RICHTEXTFONTPAGE_SIZETEXTCTRL" - 10005 - "" - "wxTextCtrl" - "wxTextCtrl" - 1 - 0 - "" - "" - "m_sizeTextCtrl" - "" - 0 - "Type a size in points." - "" - "" - "" - "" - 0 - 1 - "<Any platform>" - "" - "" - "" - "" - "" - "" - "" - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - "" - -1 - -1 - 50 - -1 - "Expand" - "Centre" - 0 - 5 - 1 - 1 - 1 - 0 - 0 - 0 - 0 - "" - "" - - - "wxListBox: ID_RICHTEXTFONTPAGE_SIZELISTBOX" - "dialog-control-document" - "" - "listbox" - 0 - 1 - 0 - 0 - "2/10/2006" - "wbListBoxProxy" - "wxEVT_COMMAND_LISTBOX_SELECTED|OnSizeListBoxSelected" - "ID_RICHTEXTFONTPAGE_SIZELISTBOX" - 10006 - "" - "wxListBox" - "wxListBox" - 1 - 0 - "" - "" - "m_sizeListBox" - "" - "" - "Lists font sizes in points." - "" - "" - "" - "" - 0 - 1 - "<Any platform>" - "" - "" - "" - "" - "" - "" - "" - 1 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - "" - -1 - -1 - 50 - -1 - "Centre" - "Centre" - 1 - 5 - 1 - 1 - 1 - 1 - 0 - 0 - 1 - "" - "" - + 1 + "" + "" @@ -14643,6 +14816,14 @@ "wbBoxSizerProxy" "Vertical" "" + "Centre" + "Centre" + 0 + 5 + 1 + 1 + 1 + 1 0 0 0 diff --git a/src/richtext/richtextfontpage.cpp b/src/richtext/richtextfontpage.cpp index d0461d723f..89c9f1e023 100644 --- a/src/richtext/richtextfontpage.cpp +++ b/src/richtext/richtextfontpage.cpp @@ -27,10 +27,17 @@ BEGIN_EVENT_TABLE( wxRichTextFontPage, wxRichTextDialogPage ) EVT_BUTTON( ID_RICHTEXTFONTPAGE_BGCOLOURCTRL, wxRichTextFontPage::OnColourClicked ) ////@begin wxRichTextFontPage event table entries + EVT_IDLE( wxRichTextFontPage::OnIdle ) + EVT_TEXT( ID_RICHTEXTFONTPAGE_FACETEXTCTRL, wxRichTextFontPage::OnFaceTextCtrlUpdated ) EVT_TEXT( ID_RICHTEXTFONTPAGE_SIZETEXTCTRL, wxRichTextFontPage::OnSizeTextCtrlUpdated ) + EVT_SPIN_UP( ID_RICHTEXTFONTPAGE_SPINBUTTONS, wxRichTextFontPage::OnRichtextfontpageSpinbuttonsUp ) + EVT_SPIN_DOWN( ID_RICHTEXTFONTPAGE_SPINBUTTONS, wxRichTextFontPage::OnRichtextfontpageSpinbuttonsDown ) + + EVT_CHOICE( ID_RICHTEXTFONTPAGE_SIZE_UNITS, wxRichTextFontPage::OnRichtextfontpageSizeUnitsSelected ) + EVT_LISTBOX( ID_RICHTEXTFONTPAGE_SIZELISTBOX, wxRichTextFontPage::OnSizeListBoxSelected ) EVT_COMBOBOX( ID_RICHTEXTFONTPAGE_STYLECTRL, wxRichTextFontPage::OnStyleCtrlSelected ) @@ -83,8 +90,11 @@ void wxRichTextFontPage::Init() ////@begin wxRichTextFontPage member initialisation m_faceTextCtrl = NULL; - m_faceListBox = NULL; m_sizeTextCtrl = NULL; + m_fontSizeSpinButtons = NULL; + m_sizeUnitsCtrl = NULL; + m_fontListBoxParent = NULL; + m_faceListBox = NULL; m_sizeListBox = NULL; m_styleCtrl = NULL; m_weightCtrl = NULL; @@ -150,131 +160,152 @@ void wxRichTextFontPage::CreateControls() m_faceTextCtrl->SetToolTip(_("Type a font name.")); itemBoxSizer5->Add(m_faceTextCtrl, 0, wxGROW|wxLEFT|wxRIGHT|wxTOP, 5); - m_faceListBox = new wxRichTextFontListBox( itemRichTextDialogPage1, ID_RICHTEXTFONTPAGE_FACELISTBOX, wxDefaultPosition, wxSize(200, 100), 0 ); - m_faceListBox->SetHelpText(_("Lists the available fonts.")); - if (wxRichTextFontPage::ShowToolTips()) - m_faceListBox->SetToolTip(_("Lists the available fonts.")); - itemBoxSizer5->Add(m_faceListBox, 1, wxGROW|wxALL|wxFIXED_MINSIZE, 5); + wxBoxSizer* itemBoxSizer8 = new wxBoxSizer(wxVERTICAL); + itemBoxSizer4->Add(itemBoxSizer8, 0, wxGROW, 5); - wxBoxSizer* itemBoxSizer9 = new wxBoxSizer(wxVERTICAL); - itemBoxSizer4->Add(itemBoxSizer9, 0, wxGROW, 5); + wxStaticText* itemStaticText9 = new wxStaticText( itemRichTextDialogPage1, wxID_STATIC, _("&Size:"), wxDefaultPosition, wxDefaultSize, 0 ); + itemBoxSizer8->Add(itemStaticText9, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5); - wxStaticText* itemStaticText10 = new wxStaticText( itemRichTextDialogPage1, wxID_STATIC, _("&Size:"), wxDefaultPosition, wxDefaultSize, 0 ); - itemBoxSizer9->Add(itemStaticText10, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5); + wxBoxSizer* itemBoxSizer10 = new wxBoxSizer(wxHORIZONTAL); + itemBoxSizer8->Add(itemBoxSizer10, 0, wxGROW, 5); m_sizeTextCtrl = new wxTextCtrl( itemRichTextDialogPage1, ID_RICHTEXTFONTPAGE_SIZETEXTCTRL, wxEmptyString, wxDefaultPosition, wxSize(50, -1), 0 ); m_sizeTextCtrl->SetHelpText(_("Type a size in points.")); if (wxRichTextFontPage::ShowToolTips()) m_sizeTextCtrl->SetToolTip(_("Type a size in points.")); - itemBoxSizer9->Add(m_sizeTextCtrl, 0, wxGROW|wxLEFT|wxRIGHT|wxTOP, 5); + itemBoxSizer10->Add(m_sizeTextCtrl, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxTOP, 5); + + m_fontSizeSpinButtons = new wxSpinButton( itemRichTextDialogPage1, ID_RICHTEXTFONTPAGE_SPINBUTTONS, wxDefaultPosition, wxSize(-1, 20), wxSP_VERTICAL ); + m_fontSizeSpinButtons->SetRange(0, 100); + m_fontSizeSpinButtons->SetValue(0); + itemBoxSizer10->Add(m_fontSizeSpinButtons, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxTOP, 5); + + wxArrayString m_sizeUnitsCtrlStrings; + m_sizeUnitsCtrlStrings.Add(_("pt")); + m_sizeUnitsCtrlStrings.Add(_("px")); + m_sizeUnitsCtrl = new wxChoice( itemRichTextDialogPage1, ID_RICHTEXTFONTPAGE_SIZE_UNITS, wxDefaultPosition, wxDefaultSize, m_sizeUnitsCtrlStrings, 0 ); + m_sizeUnitsCtrl->SetStringSelection(_("pt")); + m_sizeUnitsCtrl->SetHelpText(_("The font size units, points or pixels.")); + if (wxRichTextFontPage::ShowToolTips()) + m_sizeUnitsCtrl->SetToolTip(_("The font size units, points or pixels.")); + itemBoxSizer10->Add(m_sizeUnitsCtrl, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxTOP, 5); + + m_fontListBoxParent = new wxBoxSizer(wxHORIZONTAL); + itemBoxSizer3->Add(m_fontListBoxParent, 0, wxGROW, 5); + + m_faceListBox = new wxRichTextFontListBox( itemRichTextDialogPage1, ID_RICHTEXTFONTPAGE_FACELISTBOX, wxDefaultPosition, wxSize(200, 100), 0 ); + m_faceListBox->SetHelpText(_("Lists the available fonts.")); + if (wxRichTextFontPage::ShowToolTips()) + m_faceListBox->SetToolTip(_("Lists the available fonts.")); + m_fontListBoxParent->Add(m_faceListBox, 1, wxALIGN_CENTER_VERTICAL|wxALL|wxFIXED_MINSIZE, 5); wxArrayString m_sizeListBoxStrings; m_sizeListBox = new wxListBox( itemRichTextDialogPage1, ID_RICHTEXTFONTPAGE_SIZELISTBOX, wxDefaultPosition, wxSize(50, -1), m_sizeListBoxStrings, wxLB_SINGLE ); m_sizeListBox->SetHelpText(_("Lists font sizes in points.")); if (wxRichTextFontPage::ShowToolTips()) m_sizeListBox->SetToolTip(_("Lists font sizes in points.")); - itemBoxSizer9->Add(m_sizeListBox, 1, wxALIGN_CENTER_HORIZONTAL|wxALL|wxFIXED_MINSIZE, 5); + m_fontListBoxParent->Add(m_sizeListBox, 0, wxGROW|wxALL|wxFIXED_MINSIZE, 5); - wxBoxSizer* itemBoxSizer13 = new wxBoxSizer(wxHORIZONTAL); - itemBoxSizer3->Add(itemBoxSizer13, 0, wxGROW, 5); + wxBoxSizer* itemBoxSizer17 = new wxBoxSizer(wxHORIZONTAL); + itemBoxSizer3->Add(itemBoxSizer17, 0, wxGROW, 5); - wxBoxSizer* itemBoxSizer14 = new wxBoxSizer(wxVERTICAL); - itemBoxSizer13->Add(itemBoxSizer14, 0, wxGROW, 5); + wxBoxSizer* itemBoxSizer18 = new wxBoxSizer(wxVERTICAL); + itemBoxSizer17->Add(itemBoxSizer18, 0, wxGROW, 5); - wxStaticText* itemStaticText15 = new wxStaticText( itemRichTextDialogPage1, wxID_STATIC, _("Font st&yle:"), wxDefaultPosition, wxDefaultSize, 0 ); - itemBoxSizer14->Add(itemStaticText15, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5); + wxStaticText* itemStaticText19 = new wxStaticText( itemRichTextDialogPage1, wxID_STATIC, _("Font st&yle:"), wxDefaultPosition, wxDefaultSize, 0 ); + itemBoxSizer18->Add(itemStaticText19, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5); wxArrayString m_styleCtrlStrings; m_styleCtrl = new wxComboBox( itemRichTextDialogPage1, ID_RICHTEXTFONTPAGE_STYLECTRL, wxEmptyString, wxDefaultPosition, wxSize(110, -1), m_styleCtrlStrings, wxCB_READONLY ); m_styleCtrl->SetHelpText(_("Select regular or italic style.")); if (wxRichTextFontPage::ShowToolTips()) m_styleCtrl->SetToolTip(_("Select regular or italic style.")); - itemBoxSizer14->Add(m_styleCtrl, 0, wxGROW|wxALL, 5); + itemBoxSizer18->Add(m_styleCtrl, 0, wxGROW|wxALL, 5); - wxBoxSizer* itemBoxSizer17 = new wxBoxSizer(wxVERTICAL); - itemBoxSizer13->Add(itemBoxSizer17, 0, wxGROW, 5); + wxBoxSizer* itemBoxSizer21 = new wxBoxSizer(wxVERTICAL); + itemBoxSizer17->Add(itemBoxSizer21, 0, wxGROW, 5); - wxStaticText* itemStaticText18 = new wxStaticText( itemRichTextDialogPage1, wxID_STATIC, _("Font &weight:"), wxDefaultPosition, wxDefaultSize, 0 ); - itemBoxSizer17->Add(itemStaticText18, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5); + wxStaticText* itemStaticText22 = new wxStaticText( itemRichTextDialogPage1, wxID_STATIC, _("Font &weight:"), wxDefaultPosition, wxDefaultSize, 0 ); + itemBoxSizer21->Add(itemStaticText22, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5); wxArrayString m_weightCtrlStrings; m_weightCtrl = new wxComboBox( itemRichTextDialogPage1, ID_RICHTEXTFONTPAGE_WEIGHTCTRL, wxEmptyString, wxDefaultPosition, wxSize(110, -1), m_weightCtrlStrings, wxCB_READONLY ); m_weightCtrl->SetHelpText(_("Select regular or bold.")); if (wxRichTextFontPage::ShowToolTips()) m_weightCtrl->SetToolTip(_("Select regular or bold.")); - itemBoxSizer17->Add(m_weightCtrl, 0, wxGROW|wxALL, 5); + itemBoxSizer21->Add(m_weightCtrl, 0, wxGROW|wxALL, 5); - wxBoxSizer* itemBoxSizer20 = new wxBoxSizer(wxVERTICAL); - itemBoxSizer13->Add(itemBoxSizer20, 0, wxGROW, 5); + wxBoxSizer* itemBoxSizer24 = new wxBoxSizer(wxVERTICAL); + itemBoxSizer17->Add(itemBoxSizer24, 0, wxGROW, 5); - wxStaticText* itemStaticText21 = new wxStaticText( itemRichTextDialogPage1, wxID_STATIC, _("&Underlining:"), wxDefaultPosition, wxDefaultSize, 0 ); - itemBoxSizer20->Add(itemStaticText21, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5); + wxStaticText* itemStaticText25 = new wxStaticText( itemRichTextDialogPage1, wxID_STATIC, _("&Underlining:"), wxDefaultPosition, wxDefaultSize, 0 ); + itemBoxSizer24->Add(itemStaticText25, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5); wxArrayString m_underliningCtrlStrings; m_underliningCtrl = new wxComboBox( itemRichTextDialogPage1, ID_RICHTEXTFONTPAGE_UNDERLINING_CTRL, wxEmptyString, wxDefaultPosition, wxSize(110, -1), m_underliningCtrlStrings, wxCB_READONLY ); m_underliningCtrl->SetHelpText(_("Select underlining or no underlining.")); if (wxRichTextFontPage::ShowToolTips()) m_underliningCtrl->SetToolTip(_("Select underlining or no underlining.")); - itemBoxSizer20->Add(m_underliningCtrl, 0, wxGROW|wxALL, 5); + itemBoxSizer24->Add(m_underliningCtrl, 0, wxGROW|wxALL, 5); - itemBoxSizer13->Add(0, 0, 1, wxALIGN_CENTER_VERTICAL|wxBOTTOM, 5); + itemBoxSizer17->Add(0, 0, 1, wxALIGN_CENTER_VERTICAL|wxBOTTOM, 5); - wxBoxSizer* itemBoxSizer24 = new wxBoxSizer(wxVERTICAL); - itemBoxSizer13->Add(itemBoxSizer24, 0, wxGROW, 5); + wxBoxSizer* itemBoxSizer28 = new wxBoxSizer(wxVERTICAL); + itemBoxSizer17->Add(itemBoxSizer28, 0, wxGROW, 5); m_textColourLabel = new wxCheckBox( itemRichTextDialogPage1, ID_RICHTEXTFONTPAGE_COLOURCTRL_LABEL, _("&Colour:"), wxDefaultPosition, wxDefaultSize, 0 ); m_textColourLabel->SetValue(false); - itemBoxSizer24->Add(m_textColourLabel, 0, wxALIGN_CENTER_HORIZONTAL|wxLEFT|wxRIGHT|wxTOP, 5); + itemBoxSizer28->Add(m_textColourLabel, 0, wxALIGN_CENTER_HORIZONTAL|wxLEFT|wxRIGHT|wxTOP, 5); m_colourCtrl = new wxRichTextColourSwatchCtrl( itemRichTextDialogPage1, ID_RICHTEXTFONTPAGE_COLOURCTRL, wxDefaultPosition, wxSize(40, 20), 0 ); m_colourCtrl->SetHelpText(_("Click to change the text colour.")); if (wxRichTextFontPage::ShowToolTips()) m_colourCtrl->SetToolTip(_("Click to change the text colour.")); - itemBoxSizer24->Add(m_colourCtrl, 0, wxGROW|wxALL, 5); + itemBoxSizer28->Add(m_colourCtrl, 0, wxGROW|wxALL, 5); - wxBoxSizer* itemBoxSizer27 = new wxBoxSizer(wxVERTICAL); - itemBoxSizer13->Add(itemBoxSizer27, 0, wxGROW, 5); + wxBoxSizer* itemBoxSizer31 = new wxBoxSizer(wxVERTICAL); + itemBoxSizer17->Add(itemBoxSizer31, 0, wxGROW, 5); m_bgColourLabel = new wxCheckBox( itemRichTextDialogPage1, ID_RICHTEXTFONTPAGE_BGCOLOURCTRL_LABEL, _("&Bg colour:"), wxDefaultPosition, wxDefaultSize, 0 ); m_bgColourLabel->SetValue(false); - itemBoxSizer27->Add(m_bgColourLabel, 0, wxALIGN_CENTER_HORIZONTAL|wxLEFT|wxRIGHT|wxTOP, 5); + itemBoxSizer31->Add(m_bgColourLabel, 0, wxALIGN_CENTER_HORIZONTAL|wxLEFT|wxRIGHT|wxTOP, 5); m_bgColourCtrl = new wxRichTextColourSwatchCtrl( itemRichTextDialogPage1, ID_RICHTEXTFONTPAGE_BGCOLOURCTRL, wxDefaultPosition, wxSize(40, 20), 0 ); m_bgColourCtrl->SetHelpText(_("Click to change the text background colour.")); if (wxRichTextFontPage::ShowToolTips()) m_bgColourCtrl->SetToolTip(_("Click to change the text background colour.")); - itemBoxSizer27->Add(m_bgColourCtrl, 0, wxGROW|wxALL, 5); + itemBoxSizer31->Add(m_bgColourCtrl, 0, wxGROW|wxALL, 5); - wxBoxSizer* itemBoxSizer30 = new wxBoxSizer(wxHORIZONTAL); - itemBoxSizer3->Add(itemBoxSizer30, 0, wxGROW, 5); + wxBoxSizer* itemBoxSizer34 = new wxBoxSizer(wxHORIZONTAL); + itemBoxSizer3->Add(itemBoxSizer34, 0, wxGROW, 5); m_strikethroughCtrl = new wxCheckBox( itemRichTextDialogPage1, ID_RICHTEXTFONTPAGE_STRIKETHROUGHCTRL, _("&Strikethrough"), wxDefaultPosition, wxDefaultSize, wxCHK_3STATE|wxCHK_ALLOW_3RD_STATE_FOR_USER ); m_strikethroughCtrl->SetValue(false); m_strikethroughCtrl->SetHelpText(_("Check to show a line through the text.")); if (wxRichTextFontPage::ShowToolTips()) m_strikethroughCtrl->SetToolTip(_("Check to show a line through the text.")); - itemBoxSizer30->Add(m_strikethroughCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); + itemBoxSizer34->Add(m_strikethroughCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); m_capitalsCtrl = new wxCheckBox( itemRichTextDialogPage1, ID_RICHTEXTFONTPAGE_CAPSCTRL, _("Ca&pitals"), wxDefaultPosition, wxDefaultSize, wxCHK_3STATE|wxCHK_ALLOW_3RD_STATE_FOR_USER ); m_capitalsCtrl->SetValue(false); m_capitalsCtrl->SetHelpText(_("Check to show the text in capitals.")); if (wxRichTextFontPage::ShowToolTips()) m_capitalsCtrl->SetToolTip(_("Check to show the text in capitals.")); - itemBoxSizer30->Add(m_capitalsCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); + itemBoxSizer34->Add(m_capitalsCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); m_superscriptCtrl = new wxCheckBox( itemRichTextDialogPage1, ID_RICHTEXTFONTPAGE_SUPERSCRIPT, _("Supe&rscript"), wxDefaultPosition, wxDefaultSize, wxCHK_3STATE|wxCHK_ALLOW_3RD_STATE_FOR_USER ); m_superscriptCtrl->SetValue(false); m_superscriptCtrl->SetHelpText(_("Check to show the text in superscript.")); if (wxRichTextFontPage::ShowToolTips()) m_superscriptCtrl->SetToolTip(_("Check to show the text in superscript.")); - itemBoxSizer30->Add(m_superscriptCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); + itemBoxSizer34->Add(m_superscriptCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); m_subscriptCtrl = new wxCheckBox( itemRichTextDialogPage1, ID_RICHTEXTFONTPAGE_SUBSCRIPT, _("Subscrip&t"), wxDefaultPosition, wxDefaultSize, wxCHK_3STATE|wxCHK_ALLOW_3RD_STATE_FOR_USER ); m_subscriptCtrl->SetValue(false); m_subscriptCtrl->SetHelpText(_("Check to show the text in subscript.")); if (wxRichTextFontPage::ShowToolTips()) m_subscriptCtrl->SetToolTip(_("Check to show the text in subscript.")); - itemBoxSizer30->Add(m_subscriptCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); + itemBoxSizer34->Add(m_subscriptCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); itemBoxSizer3->Add(5, 5, 0, wxALIGN_CENTER_HORIZONTAL, 5); @@ -332,7 +363,10 @@ bool wxRichTextFontPage::TransferDataFromWindow() int sz = wxAtoi(strSize); if (sz > 0) { - attr->SetFontSize(sz); + if (m_sizeUnitsCtrl->GetSelection() == 0) + attr->SetFontPointSize(sz); + else + attr->SetFontPixelSize(sz); } } else @@ -462,13 +496,21 @@ bool wxRichTextFontPage::TransferDataToWindow() m_faceListBox->SetFaceNameSelection(wxEmptyString); } - if (attr->HasFontSize()) + if (attr->HasFontPointSize()) { wxString strSize = wxString::Format(wxT("%d"), attr->GetFontSize()); m_sizeTextCtrl->SetValue(strSize); + m_sizeUnitsCtrl->SetSelection(0); if (m_sizeListBox->FindString(strSize) != wxNOT_FOUND) m_sizeListBox->SetStringSelection(strSize); } + else if (attr->HasFontPixelSize()) + { + wxString strSize = wxString::Format(wxT("%d"), attr->GetFontSize()); + m_sizeTextCtrl->SetValue(strSize); + m_sizeUnitsCtrl->SetSelection(1); + m_sizeListBox->SetSelection(wxNOT_FOUND); + } else { m_sizeTextCtrl->SetValue(wxEmptyString); @@ -642,7 +684,12 @@ void wxRichTextFontPage::UpdatePreview() { int sz = wxAtoi(strSize); if (sz > 0) - attr.SetFontSize(sz); + { + if (m_sizeUnitsCtrl->GetSelection() == 1) + attr.SetFontPixelSize(sz); + else + attr.SetFontPointSize(sz); + } } if (m_styleCtrl->GetSelection() != wxNOT_FOUND && m_styleCtrl->GetSelection() != 0) @@ -938,3 +985,79 @@ void wxRichTextFontPage::OnRichtextfontpageSubscriptClick( wxCommandEvent& WXUNU UpdatePreview(); } + +/*! + * wxEVT_COMMAND_CHOICE_SELECTED event handler for ID_RICHTEXTFONTPAGE_SIZE_UNITS + */ + +void wxRichTextFontPage::OnRichtextfontpageSizeUnitsSelected( wxCommandEvent& WXUNUSED(event) ) +{ + if (m_dontUpdate) + return; + + UpdatePreview(); +} + +/*! + * wxEVT_COMMAND_SPINCTRL_UPDATED event handler for ID_RICHTEXTFONTPAGE_SPINBUTTONS + */ + +void wxRichTextFontPage::OnRichtextfontpageSpinbuttonsUp( wxSpinEvent& WXUNUSED(event) ) +{ + wxString text = m_sizeTextCtrl->GetValue(); + if (!text.IsEmpty()) + { + int size = wxAtoi(text); + if (size > 0) + { + size ++; + m_sizeTextCtrl->SetValue(wxString::Format(wxT("%d"), size)); + UpdatePreview(); + } + } +} + +/*! + * wxEVT_SCROLL_LINEDOWN event handler for ID_RICHTEXTFONTPAGE_SPINBUTTONS + */ + +void wxRichTextFontPage::OnRichtextfontpageSpinbuttonsDown( wxSpinEvent& WXUNUSED(event) ) +{ + wxString text = m_sizeTextCtrl->GetValue(); + if (!text.IsEmpty()) + { + int size = wxAtoi(text); + if (size > 0) + { + size --; + m_sizeTextCtrl->SetValue(wxString::Format(wxT("%d"), size)); + UpdatePreview(); + } + } +} + +/*! + * wxEVT_IDLE event handler for ID_RICHTEXTFONTPAGE + */ + +void wxRichTextFontPage::OnIdle( wxIdleEvent& WXUNUSED(event) ) +{ + if (!m_sizeUnitsCtrl) + return; + + if (m_sizeUnitsCtrl->GetSelection() == 1 && m_sizeListBox->IsShown()) + { + m_fontListBoxParent->Show(m_sizeListBox, false); + Layout(); + } + else if (m_sizeUnitsCtrl->GetSelection() == 0 && !m_sizeListBox->IsShown()) + { + m_fontListBoxParent->Show(m_sizeListBox, true); + Layout(); + } + if (!wxRichTextFormattingDialog::GetDialog(this)->HasOption(wxRichTextFormattingDialog::Option_AllowPixelFontSize) && + m_sizeUnitsCtrl->IsEnabled()) + { + m_sizeUnitsCtrl->Disable(); + } +} diff --git a/src/richtext/richtextformatdlg.cpp b/src/richtext/richtextformatdlg.cpp index fb255fd7fa..62e92b9ff3 100644 --- a/src/richtext/richtextformatdlg.cpp +++ b/src/richtext/richtextformatdlg.cpp @@ -97,6 +97,7 @@ void wxRichTextFormattingDialog::Init() m_styleDefinition = NULL; m_styleSheet = NULL; m_object = NULL; + m_options = 0; } wxRichTextFormattingDialog::~wxRichTextFormattingDialog() diff --git a/src/richtext/richtextstyles.cpp b/src/richtext/richtextstyles.cpp index 77e1d2abac..47939315e4 100644 --- a/src/richtext/richtextstyles.cpp +++ b/src/richtext/richtextstyles.cpp @@ -775,7 +775,7 @@ wxString wxRichTextStyleListBox::CreateHTML(wxRichTextStyleDefinition* def) cons name.Find(wxT("default")) != wxNOT_FOUND || name.Find(defaultTranslated) != wxNOT_FOUND) { wxRichTextAttr attr2(d->GetStyleMergedWithBase(GetStyleSheet())); - if (attr2.HasFontSize()) + if (attr2.HasFontPointSize()) { stdFontSize = attr2.GetFontSize(); break; @@ -796,7 +796,7 @@ wxString wxRichTextStyleListBox::CreateHTML(wxRichTextStyleDefinition* def) cons if (d) { wxRichTextAttr attr2(d->GetStyleMergedWithBase(GetStyleSheet())); - if (attr2.HasFontSize()) + if (attr2.HasFontPointSize()) { if (attr2.GetFontSize() <= (int) maxSize) sizes[attr2.GetFontSize()] ++; @@ -816,7 +816,7 @@ wxString wxRichTextStyleListBox::CreateHTML(wxRichTextStyleDefinition* def) cons if (stdFontSize == 0) stdFontSize = 12; - int thisFontSize = ((attr.GetFlags() & wxTEXT_ATTR_FONT_SIZE) != 0) ? attr.GetFontSize() : stdFontSize; + int thisFontSize = attr.HasFontPointSize() ? attr.GetFontSize() : stdFontSize; if (thisFontSize < stdFontSize) size --; diff --git a/src/richtext/richtextxml.cpp b/src/richtext/richtextxml.cpp index fa3ee081c3..4157ec5505 100644 --- a/src/richtext/richtextxml.cpp +++ b/src/richtext/richtextxml.cpp @@ -1092,8 +1092,10 @@ wxString wxRichTextXMLHandler::AddAttributes(const wxRichTextAttr& attr, bool is if (attr.HasBackgroundColour() && attr.GetBackgroundColour().IsOk()) AddAttribute(str, wxT("bgcolor"), attr.GetBackgroundColour()); - if (attr.HasFontSize()) - AddAttribute(str, wxT("fontsize"), attr.GetFontSize()); + if (attr.HasFontPointSize()) + AddAttribute(str, wxT("fontpointsize"), attr.GetFontSize()); + else if (attr.HasFontPixelSize()) + AddAttribute(str, wxT("fontpixelsize"), attr.GetFontSize()); if (attr.HasFontFamily()) AddAttribute(str, wxT("fontfamily"), attr.GetFontFamily()); @@ -1395,8 +1397,10 @@ bool wxRichTextXMLHandler::AddAttributes(wxXmlNode* node, wxRichTextAttr& attr, if (attr.HasBackgroundColour() && attr.GetBackgroundColour().IsOk()) node->AddAttribute(wxT("bgcolor"), MakeString(attr.GetBackgroundColour())); - if (attr.HasFontSize()) - node->AddAttribute(wxT("fontsize"), MakeString(attr.GetFontSize())); + if (attr.HasFontPointSize()) + node->AddAttribute(wxT("fontpointsize"), MakeString(attr.GetFontSize())); + else if (attr.HasFontPixelSize()) + node->AddAttribute(wxT("fontpixelsize"), MakeString(attr.GetFontSize())); if (attr.HasFontFamily()) node->AddAttribute(wxT("fontfamily"), MakeString(attr.GetFontFamily())); if (attr.HasFontItalic()) @@ -1683,10 +1687,15 @@ bool wxRichTextXMLHandler::ImportStyle(wxRichTextAttr& attr, wxXmlNode* node, bo if (!value.empty()) attr.SetFontStyle((wxFontStyle)wxAtoi(value)); } - else if (name == wxT("fontsize")) + else if (name == wxT("fontsize") || name == wxT("fontpointsize")) { if (!value.empty()) - attr.SetFontSize(wxAtoi(value)); + attr.SetFontPointSize(wxAtoi(value)); + } + else if (name == wxT("fontpixelsize")) + { + if (!value.empty()) + attr.SetFontPixelSize(wxAtoi(value)); } else if (name == wxT("fontweight")) { -- 2.45.2