From 1807a1f3cf63a4f0ae277ef8e8d059a0d089c807 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Tue, 10 Oct 2006 17:01:36 +0000 Subject: [PATCH] Return type change Added support for help button to formatting dialog git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41899 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/richtext/richtextctrl.h | 2 +- include/wx/richtext/richtextformatdlg.h | 7 +++++++ src/richtext/richtextctrl.cpp | 23 +++++++++++++---------- src/richtext/richtextformatdlg.cpp | 14 ++++++++++++++ 4 files changed, 35 insertions(+), 11 deletions(-) diff --git a/include/wx/richtext/richtextctrl.h b/include/wx/richtext/richtextctrl.h index acfc86d..1e0e289 100644 --- a/include/wx/richtext/richtextctrl.h +++ b/include/wx/richtext/richtextctrl.h @@ -528,7 +528,7 @@ public: virtual bool ApplyAlignmentToSelection(wxTextAttrAlignment alignment); /// Apply a named style to the selection - virtual void ApplyStyle(wxRichTextStyleDefinition* def); + virtual bool ApplyStyle(wxRichTextStyleDefinition* def); /// Set style sheet, if any. void SetStyleSheet(wxRichTextStyleSheet* styleSheet) { GetBuffer().SetStyleSheet(styleSheet); } diff --git a/include/wx/richtext/richtextformatdlg.h b/include/wx/richtext/richtextformatdlg.h index a5645b3..fc23fd3 100644 --- a/include/wx/richtext/richtextformatdlg.h +++ b/include/wx/richtext/richtextformatdlg.h @@ -148,6 +148,9 @@ public: /// up to date void OnTabChanged(wxBookCtrlEvent& event); + /// Respond to help command + void OnHelp(wxCommandEvent& event); + /// Set/get image list void SetImageList(wxImageList* imageList) { m_imageList = imageList; } wxImageList* GetImageList() const { return m_imageList; } @@ -165,12 +168,16 @@ public: /// Helper for pages to get the style static wxRichTextStyleDefinition* GetDialogStyleDefinition(wxWindow* win); + /// Map book control page index to our page id + void AddPageId(int id) { m_pageIds.Add(id); } + protected: wxImageList* m_imageList; wxTextAttrEx m_attributes; wxRichTextStyleDefinition* m_styleDefinition; wxRichTextStyleSheet* m_styleSheet; + wxArrayInt m_pageIds; // mapping of book control indexes to page ids static wxRichTextFormattingDialogFactory* ms_FormattingDialogFactory; diff --git a/src/richtext/richtextctrl.cpp b/src/richtext/richtextctrl.cpp index f480f23..4c36644 100644 --- a/src/richtext/richtextctrl.cpp +++ b/src/richtext/richtextctrl.cpp @@ -630,7 +630,7 @@ void wxRichTextCtrl::OnChar(wxKeyEvent& event) event.Skip(); return; } - + default: { if (event.CmdDown() || event.AltDown()) @@ -1721,14 +1721,14 @@ bool wxRichTextCtrl::SelectWord(long position) { if (position < 0 || position > GetBuffer().GetRange().GetEnd()) return false; - + wxRichTextParagraph* para = GetBuffer().GetParagraphAtPosition(position); if (!para) return false; long positionStart = position; long positionEnd = position; - + for (positionStart = position; positionStart >= para->GetRange().GetStart(); positionStart --) { wxString text = GetBuffer().GetTextForRange(wxRichTextRange(positionStart, positionStart)); @@ -1740,7 +1740,7 @@ bool wxRichTextCtrl::SelectWord(long position) } if (positionStart < para->GetRange().GetStart()) positionStart = para->GetRange().GetStart(); - + for (positionEnd = position; positionEnd < para->GetRange().GetEnd(); positionEnd ++) { wxString text = GetBuffer().GetTextForRange(wxRichTextRange(positionEnd, positionEnd)); @@ -1752,13 +1752,13 @@ bool wxRichTextCtrl::SelectWord(long position) } if (positionEnd >= para->GetRange().GetEnd()) positionEnd = para->GetRange().GetEnd(); - + SetSelection(positionStart, positionEnd+1); if (positionStart >= 0) { MoveCaret(positionStart-1, true); - SetDefaultStyleToCursorStyle(); + SetDefaultStyleToCursorStyle(); } return true; @@ -2738,19 +2738,19 @@ bool wxRichTextCtrl::ApplyAlignmentToSelection(wxTextAttrAlignment alignment) } /// Apply a named style to the selection -void wxRichTextCtrl::ApplyStyle(wxRichTextStyleDefinition* def) +bool wxRichTextCtrl::ApplyStyle(wxRichTextStyleDefinition* def) { // Flags are defined within each definition, so only certain // attributes are applied. wxRichTextAttr attr(def->GetStyle()); - + int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO|wxRICHTEXT_SETSTYLE_OPTIMIZE; // Make sure the attr has the style name if (def->IsKindOf(CLASSINFO(wxRichTextParagraphStyleDefinition))) { attr.SetParagraphStyleName(def->GetName()); - + // If applying a paragraph style, we only want the paragraph nodes to adopt these // attributes, and not the leaf nodes. This will allow the context (e.g. text) // to change its style independently. @@ -2760,9 +2760,12 @@ void wxRichTextCtrl::ApplyStyle(wxRichTextStyleDefinition* def) attr.SetCharacterStyleName(def->GetName()); if (HasSelection()) - SetStyleEx(GetSelectionRange(), attr, flags); + return SetStyleEx(GetSelectionRange(), attr, flags); else + { SetAndShowDefaultStyle(attr); + return true; + } } /// Apply the style sheet to the buffer, for example if the styles have changed. diff --git a/src/richtext/richtextformatdlg.cpp b/src/richtext/richtextformatdlg.cpp index d65dedb..c7c392d 100644 --- a/src/richtext/richtextformatdlg.cpp +++ b/src/richtext/richtextformatdlg.cpp @@ -192,6 +192,18 @@ void wxRichTextFormattingDialog::OnTabChanged(wxBookCtrlEvent& event) } } +/// Respond to help command +void wxRichTextFormattingDialog::OnHelp(wxCommandEvent& event) +{ + int selPage = GetBookCtrl()->GetSelection(); + if (selPage != wxNOT_FOUND) + { + int pageId = m_pageIds[selPage]; + if (!GetFormattingDialogFactory()->ShowHelp(pageId, this)) + event.Skip(); + } +} + void wxRichTextFormattingDialog::SetFormattingDialogFactory(wxRichTextFormattingDialogFactory* factory) { if (ms_FormattingDialogFactory) @@ -225,6 +237,8 @@ bool wxRichTextFormattingDialogFactory::CreatePages(long pages, wxRichTextFormat int imageIndex = GetPageImage(pageId); dialog->GetBookCtrl()->AddPage(panel, title, !selected, imageIndex); selected = true; + + dialog->AddPageId(pageId); } } } -- 2.7.4