#endif
#include "wx/defs.h"
+#include "wx/help.h"
#if wxUSE_HELP
// 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.
//
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__
#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
// 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); };
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();
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();
void OnAdvancedHtmlHelp(wxCommandEvent& event);
void OnMSHtmlHelp(wxCommandEvent& event);
- void OnContextHelp(wxHelpEvent& event);
void OnShowContextHelp(wxCommandEvent& event);
void OnShowDialogContextHelp(wxCommandEvent& event);
public:
MyModalDialog(wxWindow *parent);
- void OnContextHelp(wxHelpEvent& event);
-
private:
DECLARE_EVENT_TABLE()
enum
{
// menu items
- HelpDemo_Quit = 1,
+ HelpDemo_Quit = 100,
HelpDemo_Help_Index,
HelpDemo_Help_Classes,
HelpDemo_Help_Functions,
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)
// `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
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);
}
#endif
- // create a simple help provider to make SetHelpText() do something
- wxHelpProvider::Set(new wxSimpleHelpProvider);
-
return TRUE;
}
// 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));
// 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."));
}
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
// ----------------------------------------------------------------------------
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
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);
-}
-
--- /dev/null
+#define doc1 100
+#define doc2 2
+#define doc3 1
+#define doc4 3
+#define IDH_PANEL 300
+#define IDH_TEXT 301
+#define IDH_OK 302
[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
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]
--- /dev/null
+.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.
+
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.
// ----------------------------------------------------------------------------
#include "wx/app.h"
#include "wx/dc.h"
#include "wx/utils.h"
+#include "wx/settings.h"
#include "wx/log.h"
#include <string.h>
#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);
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);
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)
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)
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.
#include "wx/utils.h"
#endif
+#include "wx/settings.h"
#include "wx/ownerdrw.h"
#include "wx/menuitem.h"
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)