]> git.saurik.com Git - wxWidgets.git/commitdiff
Added wxHelpControllerHelpProvider, added DisplayContextPopup, DisplayTextPopup
authorJulian Smart <julian@anthemion.co.uk>
Tue, 12 Sep 2000 14:53:39 +0000 (14:53 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Tue, 12 Sep 2000 14:53:39 +0000 (14:53 +0000)
to wxHelpControllerBase and wxCHMHelpController; updated sample

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8339 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

15 files changed:
include/wx/cshelp.h
include/wx/defs.h
include/wx/helpbase.h
include/wx/msw/helpchm.h
include/wx/msw/helpwin.h
samples/help/demo.cpp
samples/help/doc.chm
samples/help/doc.h [new file with mode: 0644]
samples/help/doc.hhp
samples/help/popups.txt [new file with mode: 0644]
src/common/cshelp.cpp
src/common/gdicmn.cpp
src/msw/helpchm.cpp
src/msw/helpwin.cpp
src/msw/ownerdrw.cpp

index 836e76e195fcc4153d5137d167cceeabe9113360..3b8cae26cce0c6f91f604d500152b4029b1ad2ea 100644 (file)
@@ -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__
 
index e466657e8960d3f6342e7da505a690f2afa0c6f8..7c36877cf51d56d65f9e5ab1631bd7cd1f2ab1c8 100644 (file)
@@ -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
index c35b3b0cb125427f9bc607798007d3c4c0278034..17443e79ac56135a40ec2ea21d6989091f018090 100644 (file)
@@ -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); };
index d6db1b92c7f4412144a29004fa25a0e28c02354c..4a172009be9a464ed4aaeb1aa3e0933a7b882772 100644 (file)
@@ -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();
 
index c3260a6e3833d0d061cedac6047a6436677ea35c..3de4b65a7347744fdfcce18500dfd92fb5c6c5af 100644 (file)
@@ -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();
 
index 266f3a3da33968120e500396169f78fca8424ce7..d1bc2f6f7ab345977fbf522861381f7d9c205141 100644 (file)
@@ -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);
-}
-
index 77ff9c01ebe621591a54592ad3b0ace5855d1b17..6a197291c668db56c8cf61382c462ee1a29a3408 100644 (file)
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 (file)
index 0000000..62fe2f8
--- /dev/null
@@ -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
index ef2d0ac23677d0583fc3cfff3e5e3f65ad1e8442..b0098fc48c2cf2d81534c063ca5bbbc0eb5b8c23 100644 (file)
@@ -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 (file)
index 0000000..0c6d69a
--- /dev/null
@@ -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.
+
index 7917ac2c6fc0e7a187a350f61a7c23243c253985..f1e8b26f4e2068702a117b83fb89fe22ddef1a27 100644 (file)
@@ -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.
 // ----------------------------------------------------------------------------
index 4e35df6256aef91de8f62dfdce132dc50c971454..e7dc5831e0f45f2bbaa6891f99a63b4d0c8fa98a 100644 (file)
@@ -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 <string.h>
@@ -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);
index 2fa6dd4495676aa9a2bb65e8ac0a564a47dc1432..71356d4f6ffe23501a2718b139305b36ddc43f31 100644 (file)
@@ -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);
index 74d9160f7fd2e583a8e7fb460ffe006b2b260ab1..a507852e1e5ebcc66de5fff9179e1e46f7a0d85e 100644 (file)
@@ -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.
index 8ea7c54e0f0fd5805a91dd95932abed06398aaa6..f0f1223260634a4c685e8766623bf2cf12a4f7ea 100644 (file)
@@ -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)