From: Julian Smart Date: Tue, 12 Sep 2000 14:53:39 +0000 (+0000) Subject: Added wxHelpControllerHelpProvider, added DisplayContextPopup, DisplayTextPopup X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/5100cabffa34c38db26884577113d01f21cda446 Added wxHelpControllerHelpProvider, added DisplayContextPopup, DisplayTextPopup to wxHelpControllerBase and wxCHMHelpController; updated sample git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8339 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/cshelp.h b/include/wx/cshelp.h index 836e76e195..3b8cae26cc 100644 --- a/include/wx/cshelp.h +++ b/include/wx/cshelp.h @@ -17,6 +17,7 @@ #endif #include "wx/defs.h" +#include "wx/help.h" #if wxUSE_HELP @@ -83,7 +84,7 @@ private: // classes used to implement context help support // ---------------------------------------------------------------------------- -// wxHelpProvider is an ABC used by the program implementing context help to +// wxHelpProvider is an abstract class used by the program implementing context help to // show the help text (or whatever: it may be HTML page or anything else) for // the given window. // @@ -151,5 +152,30 @@ protected: m_hashIds; }; +// wxHelpControllerHelpProvider is an implementation of wxHelpProvider which supports +// both context identifiers and plain text help strings. If the help text is an integer, +// it is passed to wxHelpController::DisplayContextPopup. Otherwise, it shows the string +// in a tooltip as per wxSimpleHelpProvider. +class WXDLLEXPORT wxHelpControllerHelpProvider : public wxSimpleHelpProvider +{ +public: + // Note that it doesn't own the help controller. The help controller + // should be deleted separately. + wxHelpControllerHelpProvider(wxHelpControllerBase* hc = (wxHelpControllerBase*) NULL); + + // implement wxHelpProvider methods + virtual bool ShowHelp(wxWindowBase *window); + + // Other accessors + void SetHelpController(wxHelpControllerBase* hc) { m_helpController = hc; } + wxHelpControllerBase* GetHelpController() const { return m_helpController; } + +protected: + wxHelpControllerBase* m_helpController; +}; + +// Convenience function for turning context id into wxString +wxString wxContextId(int id); + #endif // _WX_CSHELPH__ diff --git a/include/wx/defs.h b/include/wx/defs.h index e466657e89..7c36877cf5 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -1311,6 +1311,10 @@ enum wxStretch #define wxID_SETUP 5110 #define wxID_RESET 5111 #define wxID_CONTEXT_HELP 5112 +#define wxID_YESTOALL 5113 +#define wxID_NOTOALL 5114 +#define wxID_ABORT 5115 +#define wxID_RETRY 5116 // IDs used by generic file dialog (11 consecutive starting from this value) #define wxID_FILEDLGG 5900 diff --git a/include/wx/helpbase.h b/include/wx/helpbase.h index c35b3b0cb1..17443e79ac 100644 --- a/include/wx/helpbase.h +++ b/include/wx/helpbase.h @@ -47,9 +47,19 @@ public: // If file is "", reloads file given in Initialize virtual bool LoadFile(const wxString& file = "") = 0; + + // Displays the contents virtual bool DisplayContents(void) = 0; + + // Display the given section virtual bool DisplaySection(int sectionNo) = 0; + // Display the section using a context id + virtual bool DisplayContextPopup(int WXUNUSED(contextId)) { return FALSE; }; + + // Display the text in a popup, if possible + virtual bool DisplayTextPopup(const wxString& WXUNUSED(text), const wxPoint& WXUNUSED(pos)) { return FALSE; }; + // By default, uses KeywordSection to display a topic. Implementations // may override this for more specific behaviour. virtual bool DisplaySection(const wxString& section) { return KeywordSearch(section); }; diff --git a/include/wx/msw/helpchm.h b/include/wx/msw/helpchm.h index d6db1b92c7..4a172009be 100644 --- a/include/wx/msw/helpchm.h +++ b/include/wx/msw/helpchm.h @@ -39,6 +39,8 @@ public: virtual bool DisplaySection(int sectionNo); virtual bool DisplaySection(const wxString& section); virtual bool DisplayBlock(long blockNo); + virtual bool DisplayContextPopup(int contextId); + virtual bool DisplayTextPopup(const wxString& text, const wxPoint& pos); virtual bool KeywordSearch(const wxString& k); virtual bool Quit(); diff --git a/include/wx/msw/helpwin.h b/include/wx/msw/helpwin.h index c3260a6e38..3de4b65a73 100644 --- a/include/wx/msw/helpwin.h +++ b/include/wx/msw/helpwin.h @@ -38,6 +38,7 @@ public: virtual bool DisplayContents(); virtual bool DisplaySection(int sectionNo); virtual bool DisplayBlock(long blockNo); + virtual bool DisplayContextPopup(int contextId); virtual bool KeywordSearch(const wxString& k); virtual bool Quit(); diff --git a/samples/help/demo.cpp b/samples/help/demo.cpp index 266f3a3da3..d1bc2f6f7a 100644 --- a/samples/help/demo.cpp +++ b/samples/help/demo.cpp @@ -121,7 +121,6 @@ public: void OnAdvancedHtmlHelp(wxCommandEvent& event); void OnMSHtmlHelp(wxCommandEvent& event); - void OnContextHelp(wxHelpEvent& event); void OnShowContextHelp(wxCommandEvent& event); void OnShowDialogContextHelp(wxCommandEvent& event); @@ -151,8 +150,6 @@ class MyModalDialog : public wxDialog public: MyModalDialog(wxWindow *parent); - void OnContextHelp(wxHelpEvent& event); - private: DECLARE_EVENT_TABLE() @@ -166,7 +163,7 @@ private: enum { // menu items - HelpDemo_Quit = 1, + HelpDemo_Quit = 100, HelpDemo_Help_Index, HelpDemo_Help_Classes, HelpDemo_Help_Functions, @@ -217,8 +214,6 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(HelpDemo_Help_ContextHelp, MyFrame::OnShowContextHelp) EVT_MENU(HelpDemo_Help_DialogContextHelp, MyFrame::OnShowDialogContextHelp) - EVT_HELP(-1, MyFrame::OnContextHelp) - EVT_MENU(HelpDemo_Html_Help_Index, MyFrame::OnHtmlHelp) EVT_MENU(HelpDemo_Html_Help_Classes, MyFrame::OnHtmlHelp) EVT_MENU(HelpDemo_Html_Help_Functions, MyFrame::OnHtmlHelp) @@ -260,6 +255,12 @@ IMPLEMENT_APP(MyApp) // `Main program' equivalent: the program execution "starts" here bool MyApp::OnInit() { + // Create a simple help provider to make SetHelpText() do something. + // Note that this must be set before any SetHelpText() calls are made. + //wxHelpProvider::Set(new wxSimpleHelpProvider); + wxHelpControllerHelpProvider* provider = new wxHelpControllerHelpProvider; + wxHelpProvider::Set(provider); + #if wxUSE_HTML #if wxUSE_GIF // Required for images in the online documentation @@ -277,6 +278,12 @@ bool MyApp::OnInit() MyFrame *frame = new MyFrame("HelpDemo wxWindows App", wxPoint(50, 50), wxSize(450, 340)); +#if wxUSE_MS_HTML_HELP + provider->SetHelpController(& frame->GetMSHtmlHelpController()); +#else + provider->SetHelpController(& frame->GetHelpController()); +#endif + frame->Show(TRUE); SetTopWindow(frame); @@ -321,9 +328,6 @@ bool MyApp::OnInit() } #endif - // create a simple help provider to make SetHelpText() do something - wxHelpProvider::Set(new wxSimpleHelpProvider); - return TRUE; } @@ -341,7 +345,7 @@ int MyApp::OnExit() // frame constructor MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) - : wxFrame((wxFrame *)NULL, -1, title, pos, size) + : wxFrame((wxFrame *)NULL, 300, title, pos, size) { // set the frame icon SetIcon(wxICON(mondrian)); @@ -408,10 +412,13 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) // a panel first - if there were several controls, it would allow us to // navigate between them from the keyboard - wxPanel *panel = new wxPanel(this, -1, wxPoint(0, 0), wxSize(400, 200)); + wxPanel *panel = new wxPanel(this, 301, wxPoint(0, 0), wxSize(400, 200)); + //panel->SetHelpText(_("This panel just holds a static text control.")); + panel->SetHelpText(wxContextId(300)); // and a static control whose parent is the panel - (void)new wxStaticText(panel, -1, "Hello, world!", wxPoint(10, 10)); + wxStaticText* staticText = new wxStaticText(panel, 302, "Hello, world!", wxPoint(10, 10)); + staticText->SetHelpText(_("This static text control isn't doing a lot right now.")); } @@ -441,14 +448,6 @@ void MyFrame::OnShowDialogContextHelp(wxCommandEvent& event) dialog.ShowModal(); } -void MyFrame::OnContextHelp(wxHelpEvent& event) -{ - // In a real app, if we didn't recognise this ID, we should call event.Skip() - wxString msg; - msg.Printf(wxT("We should now display help for window %d"), event.GetId()); - wxMessageBox(msg); -} - void MyFrame::OnHtmlHelp(wxCommandEvent& event) { #if USE_HTML_HELP && USE_OLD_HTML_HELP @@ -607,27 +606,32 @@ void MyFrame::ShowHelp(int commandId, wxHelpControllerBase& helpController) // ---------------------------------------------------------------------------- BEGIN_EVENT_TABLE(MyModalDialog, wxDialog) - EVT_HELP(-1, MyModalDialog::OnContextHelp) END_EVENT_TABLE() MyModalDialog::MyModalDialog(wxWindow *parent) : wxDialog() { + // Add the context-sensitive help button on the caption for MSW +#ifdef __WXMSW__ + SetExtraStyle(wxDIALOG_EX_CONTEXTHELP); +#endif + wxDialog::Create(parent, -1, wxString("Modal dialog")); wxBoxSizer *sizerTop = new wxBoxSizer(wxVERTICAL); wxBoxSizer *sizerRow = new wxBoxSizer(wxHORIZONTAL); wxButton* btnOK = new wxButton(this, wxID_OK, "&OK"); + btnOK->SetHelpText(_("The OK button confirms the dialog choices.")); + wxButton* btnCancel = new wxButton(this, wxID_CANCEL, "&Cancel"); + btnCancel->SetHelpText(_("The Cancel button cancels the dialog.")); + sizerRow->Add(btnOK, 0, wxALIGN_CENTER | wxALL, 5); sizerRow->Add(btnCancel, 0, wxALIGN_CENTER | wxALL, 5); - // Add the context-sensitive help button on the caption for MSW and the - // explicit context-sensitive help button elsewhere -#ifdef __WXMSW__ - SetExtraStyle(wxDIALOG_EX_CONTEXTHELP); -#else + // Add explicit context-sensitive help button for non-MSW +#ifndef __WXMSW__ sizerRow->Add(new wxContextHelpButton(this), 0, wxALIGN_CENTER | wxALL, 5); #endif @@ -649,33 +653,3 @@ MyModalDialog::MyModalDialog(wxWindow *parent) btnOK->SetDefault(); } -void MyModalDialog::OnContextHelp(wxHelpEvent& event) -{ - wxString msg; - switch (event.GetId()) - { - case wxID_OK: - { - msg = _("The OK button confirms the dialog choices."); - break; - } - case wxID_CANCEL: - { - msg = _("The Cancel button cancels the dialog."); - break; - } - case wxID_APPLY: - { - msg = _("This is a text control that does nothing in particular."); - break; - } - case wxID_CONTEXT_HELP: - { - msg = _("If you didn't know what this button is for, why did you press it? :-)"); - break; - } - } - if (!msg.IsEmpty()) - wxMessageBox(msg, _("Help"), wxICON_INFORMATION, this); -} - diff --git a/samples/help/doc.chm b/samples/help/doc.chm index 77ff9c01eb..6a197291c6 100644 Binary files a/samples/help/doc.chm and b/samples/help/doc.chm differ diff --git a/samples/help/doc.h b/samples/help/doc.h new file mode 100644 index 0000000000..62fe2f8ac7 --- /dev/null +++ b/samples/help/doc.h @@ -0,0 +1,7 @@ +#define doc1 100 +#define doc2 2 +#define doc3 1 +#define doc4 3 +#define IDH_PANEL 300 +#define IDH_TEXT 301 +#define IDH_OK 302 diff --git a/samples/help/doc.hhp b/samples/help/doc.hhp index ef2d0ac236..b0098fc48c 100644 --- a/samples/help/doc.hhp +++ b/samples/help/doc.hhp @@ -1,15 +1,18 @@ [OPTIONS] -Compatibility=1.1 -Full-text search=Yes -Contents file=doc.hhc +Compatibility=1.1 or later Compiled file=doc.chm +Contents file=doc.hhc Default Window=docHelp Default topic=doc.htm +Display compile progress=No +Full-text search=Yes Index file=doc.hhk +Language=0x809 English (United Kingdom) Title=Help Demo [WINDOWS] -docHelp=,"doc.hhc","doc.hhk","doc.htm",,,,,,0x2420,,0x380e,,,,,0,,, +docHelp=,"doc.hhc","doc.hhk","doc.htm",,,,,,0x2420,,0x380e,,,,,0,,,0 + [FILES] doc.htm @@ -20,8 +23,11 @@ doc4.htm doc5.htm [MAP] -#define doc1 100 -#define doc3 1 -#define doc2 2 -#define doc4 3 +#include doc.h + +[TEXT POPUPS] +doc.h +popups.txt + +[INFOTYPES] diff --git a/samples/help/popups.txt b/samples/help/popups.txt new file mode 100644 index 0000000000..0c6d69a6da --- /dev/null +++ b/samples/help/popups.txt @@ -0,0 +1,9 @@ +.topic IDH_PANEL +This is the topic for the main panel. + +.topic IDH_TEXT +This is the topic for the text control. + +.topic IDH_OK +This is the topic for the OK button. + diff --git a/src/common/cshelp.cpp b/src/common/cshelp.cpp index 7917ac2c6f..f1e8b26f4e 100644 --- a/src/common/cshelp.cpp +++ b/src/common/cshelp.cpp @@ -312,6 +312,48 @@ bool wxSimpleHelpProvider::ShowHelp(wxWindowBase *window) return FALSE; } +// ---------------------------------------------------------------------------- +// wxHelpControllerHelpProvider +// ---------------------------------------------------------------------------- + +wxHelpControllerHelpProvider::wxHelpControllerHelpProvider(wxHelpControllerBase* hc) +{ + m_helpController = hc; +} + +bool wxHelpControllerHelpProvider::ShowHelp(wxWindowBase *window) +{ + wxString text = GetHelp(window); + if ( !text.empty() ) + { + if (m_helpController) + { + if (text.IsNumber()) + return m_helpController->DisplayContextPopup(wxAtoi(text)); + + // If the help controller is capable of popping up the text... + else if (m_helpController->DisplayTextPopup(text, wxGetMousePosition())) + { + return TRUE; + } + else + // ...else use the default method. + return wxSimpleHelpProvider::ShowHelp(window); + } + else + return wxSimpleHelpProvider::ShowHelp(window); + + } + + return FALSE; +} + +// Convenience function for turning context id into wxString +wxString wxContextId(int id) +{ + return wxString(IntToString(id)); +} + // ---------------------------------------------------------------------------- // wxHelpProviderModule: module responsible for cleaning up help provider. // ---------------------------------------------------------------------------- diff --git a/src/common/gdicmn.cpp b/src/common/gdicmn.cpp index 4e35df6256..e7dc5831e0 100644 --- a/src/common/gdicmn.cpp +++ b/src/common/gdicmn.cpp @@ -36,6 +36,7 @@ #include "wx/app.h" #include "wx/dc.h" #include "wx/utils.h" +#include "wx/settings.h" #include "wx/log.h" #include @@ -360,13 +361,18 @@ void wxInitializeStockObjects () #endif // why under MSW fonts shouldn't have the standard system size? +/* #ifdef __WXMSW__ static const int sizeFont = 10; #else static const int sizeFont = 12; #endif +*/ + +// wxNORMAL_FONT = new wxFont (sizeFont, wxMODERN, wxNORMAL, wxNORMAL); + wxNORMAL_FONT = new wxFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT)); + static const int sizeFont = wxNORMAL_FONT->GetPointSize(); - wxNORMAL_FONT = new wxFont (sizeFont, wxMODERN, wxNORMAL, wxNORMAL); wxSMALL_FONT = new wxFont (sizeFont - 2, wxSWISS, wxNORMAL, wxNORMAL); wxITALIC_FONT = new wxFont (sizeFont, wxROMAN, wxITALIC, wxNORMAL); wxSWISS_FONT = new wxFont (sizeFont, wxSWISS, wxNORMAL, wxNORMAL); diff --git a/src/msw/helpchm.cpp b/src/msw/helpchm.cpp index 2fa6dd4495..71356d4f6f 100644 --- a/src/msw/helpchm.cpp +++ b/src/msw/helpchm.cpp @@ -102,6 +102,47 @@ bool wxCHMHelpController::DisplaySection(int section) return TRUE; } +bool wxCHMHelpController::DisplayContextPopup(int contextId) +{ + if (m_helpFile.IsEmpty()) return FALSE; + + wxString str = GetValidFilename(m_helpFile); + + // TODO: what should this be? + //HtmlHelp(GetSuitableHWND(), (const wxChar*) str, HH_HELP_CONTEXT, (DWORD)contextId); + HH_POPUP popup; + popup.cbStruct = sizeof(popup); + popup.hinst = (HINSTANCE) wxGetInstance(); + popup.idString = contextId ; + + GetCursorPos(& popup.pt); + popup.clrForeground = -1; + popup.clrBackground = -1; + popup.rcMargins.top = popup.rcMargins.left = popup.rcMargins.right = popup.rcMargins.bottom = -1; + popup.pszFont = NULL; + popup.pszText = NULL; + + HtmlHelp(GetSuitableHWND(), (const wxChar*) str, HH_DISPLAY_TEXT_POPUP, (DWORD) & popup); + return TRUE; +} + +bool wxCHMHelpController::DisplayTextPopup(const wxString& text, const wxPoint& pos) +{ + HH_POPUP popup; + popup.cbStruct = sizeof(popup); + popup.hinst = (HINSTANCE) wxGetInstance(); + popup.idString = 0 ; + popup.pt.x = pos.x; popup.pt.y = pos.y; + popup.clrForeground = -1; + popup.clrBackground = -1; + popup.rcMargins.top = popup.rcMargins.left = popup.rcMargins.right = popup.rcMargins.bottom = -1; + popup.pszFont = NULL; + popup.pszText = (const wxChar*) text; + + HtmlHelp(GetSuitableHWND(), NULL, HH_DISPLAY_TEXT_POPUP, (DWORD) & popup); + return TRUE; +} + bool wxCHMHelpController::DisplayBlock(long block) { return DisplaySection(block); diff --git a/src/msw/helpwin.cpp b/src/msw/helpwin.cpp index 74d9160f7f..a507852e1e 100644 --- a/src/msw/helpwin.cpp +++ b/src/msw/helpwin.cpp @@ -67,11 +67,10 @@ bool wxWinHelpController::DisplayContents(void) wxString str = GetValidFilename(m_helpFile); #if defined(__WIN95__) - WinHelp(GetSuitableHWND(), (const wxChar*) str, HELP_FINDER, 0L); + return (WinHelp(GetSuitableHWND(), (const wxChar*) str, HELP_FINDER, 0L) != 0); #else - WinHelp(GetSuitableHWND(), (const wxChar*) str, HELP_CONTENTS, 0L); + return (WinHelp(GetSuitableHWND(), (const wxChar*) str, HELP_CONTENTS, 0L) != 0); #endif - return TRUE; } bool wxWinHelpController::DisplaySection(int section) @@ -81,8 +80,16 @@ bool wxWinHelpController::DisplaySection(int section) wxString str = GetValidFilename(m_helpFile); - WinHelp((HWND) wxTheApp->GetTopWindow()->GetHWND(), (const wxChar*) str, HELP_CONTEXT, (DWORD)section); - return TRUE; + return (WinHelp((HWND) wxTheApp->GetTopWindow()->GetHWND(), (const wxChar*) str, HELP_CONTEXT, (DWORD)section) != 0); +} + +bool wxWinHelpController::DisplayContextPopup(int contextId) +{ + if (m_helpFile.IsEmpty()) return FALSE; + + wxString str = GetValidFilename(m_helpFile); + + return (WinHelp((HWND) wxTheApp->GetTopWindow()->GetHWND(), (const wxChar*) str, HELP_CONTEXTPOPUP, (DWORD) contextId) != 0); } bool wxWinHelpController::DisplayBlock(long block) @@ -97,15 +104,13 @@ bool wxWinHelpController::KeywordSearch(const wxString& k) wxString str = GetValidFilename(m_helpFile); - WinHelp(GetSuitableHWND(), (const wxChar*) str, HELP_PARTIALKEY, (DWORD)(const wxChar*) k); - return TRUE; + return (WinHelp(GetSuitableHWND(), (const wxChar*) str, HELP_PARTIALKEY, (DWORD)(const wxChar*) k) != 0); } // Can't close the help window explicitly in WinHelp bool wxWinHelpController::Quit(void) { - WinHelp(GetSuitableHWND(), 0, HELP_QUIT, 0L); - return TRUE; + return (WinHelp(GetSuitableHWND(), 0, HELP_QUIT, 0L) != 0); } // Append extension if necessary. diff --git a/src/msw/ownerdrw.cpp b/src/msw/ownerdrw.cpp index 8ea7c54e0f..f0f1223260 100644 --- a/src/msw/ownerdrw.cpp +++ b/src/msw/ownerdrw.cpp @@ -31,6 +31,7 @@ #include "wx/utils.h" #endif +#include "wx/settings.h" #include "wx/ownerdrw.h" #include "wx/menuitem.h" @@ -51,6 +52,8 @@ wxOwnerDrawn::wxOwnerDrawn(const wxString& str, m_bOwnerDrawn = FALSE; m_nHeight = 0; m_nMarginWidth = ms_nLastMarginWidth; + if (wxNORMAL_FONT) + m_font = * wxNORMAL_FONT; } #if defined(__WXMSW__) && defined(__WIN32__) && defined(SM_CXMENUCHECK)