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
This commit is contained in:
Julian Smart
2012-05-20 12:25:22 +00:00
parent c564ca3c97
commit 32423dd824
20 changed files with 1421 additions and 525 deletions

View File

@@ -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);

View File

@@ -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
/**

View File

@@ -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,

View File

@@ -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;

View File

@@ -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; }