]>
Commit | Line | Data |
---|---|---|
2bda0e17 KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: helpwin.cpp | |
3 | // Purpose: Help system: WinHelp implementation | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
6c9a19aa | 8 | // Copyright: (c) Julian Smart |
59af881e | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
2bda0e17 KB |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifdef __BORLANDC__ | |
16 | #pragma hdrstop | |
17 | #endif | |
18 | ||
19 | #ifndef WX_PRECOMP | |
20 | #include "wx/defs.h" | |
21 | #endif | |
22 | ||
f6bcfd97 BP |
23 | #if wxUSE_HELP |
24 | ||
25 | #include "wx/filefn.h" | |
2bda0e17 KB |
26 | #include "wx/msw/helpwin.h" |
27 | ||
2bda0e17 KB |
28 | #include <time.h> |
29 | ||
2049ba38 | 30 | #ifdef __WXMSW__ |
3096bd2f | 31 | #include "wx/msw/private.h" |
2bda0e17 KB |
32 | #endif |
33 | ||
34 | #include <string.h> | |
35 | ||
f6bcfd97 | 36 | static HWND GetSuitableHWND() |
2bda0e17 | 37 | { |
f6bcfd97 BP |
38 | if (wxTheApp->GetTopWindow()) |
39 | return (HWND) wxTheApp->GetTopWindow()->GetHWND(); | |
40 | else | |
41 | return GetDesktopWindow(); | |
2bda0e17 KB |
42 | } |
43 | ||
f6bcfd97 | 44 | IMPLEMENT_DYNAMIC_CLASS(wxWinHelpController, wxHelpControllerBase) |
2bda0e17 | 45 | |
38009d39 | 46 | bool wxWinHelpController::Initialize(const wxString& filename) |
2bda0e17 | 47 | { |
f6bcfd97 | 48 | m_helpFile = filename; |
59af881e | 49 | return true; |
2bda0e17 KB |
50 | } |
51 | ||
52 | bool wxWinHelpController::LoadFile(const wxString& file) | |
53 | { | |
f6bcfd97 BP |
54 | if (!file.IsEmpty()) |
55 | m_helpFile = file; | |
59af881e | 56 | return true; |
2bda0e17 KB |
57 | } |
58 | ||
59 | bool wxWinHelpController::DisplayContents(void) | |
60 | { | |
59af881e WS |
61 | if (m_helpFile.IsEmpty()) return false; |
62 | ||
f6bcfd97 | 63 | wxString str = GetValidFilename(m_helpFile); |
59af881e | 64 | |
2bda0e17 | 65 | #if defined(__WIN95__) |
5100cabf | 66 | return (WinHelp(GetSuitableHWND(), (const wxChar*) str, HELP_FINDER, 0L) != 0); |
2bda0e17 | 67 | #else |
5100cabf | 68 | return (WinHelp(GetSuitableHWND(), (const wxChar*) str, HELP_CONTENTS, 0L) != 0); |
2bda0e17 | 69 | #endif |
2bda0e17 KB |
70 | } |
71 | ||
72 | bool wxWinHelpController::DisplaySection(int section) | |
73 | { | |
33b64e6f | 74 | // Use context number |
59af881e WS |
75 | if (m_helpFile.IsEmpty()) return false; |
76 | ||
f6bcfd97 | 77 | wxString str = GetValidFilename(m_helpFile); |
33b64e6f | 78 | |
5100cabf JS |
79 | return (WinHelp((HWND) wxTheApp->GetTopWindow()->GetHWND(), (const wxChar*) str, HELP_CONTEXT, (DWORD)section) != 0); |
80 | } | |
81 | ||
82 | bool wxWinHelpController::DisplayContextPopup(int contextId) | |
83 | { | |
59af881e WS |
84 | if (m_helpFile.IsEmpty()) return false; |
85 | ||
5100cabf JS |
86 | wxString str = GetValidFilename(m_helpFile); |
87 | ||
88 | return (WinHelp((HWND) wxTheApp->GetTopWindow()->GetHWND(), (const wxChar*) str, HELP_CONTEXTPOPUP, (DWORD) contextId) != 0); | |
2bda0e17 KB |
89 | } |
90 | ||
91 | bool wxWinHelpController::DisplayBlock(long block) | |
92 | { | |
f6bcfd97 | 93 | DisplaySection(block); |
59af881e | 94 | return true; |
2bda0e17 KB |
95 | } |
96 | ||
69b5cec2 VS |
97 | bool wxWinHelpController::KeywordSearch(const wxString& k, |
98 | wxHelpSearchMode WXUNUSED(mode)) | |
2bda0e17 | 99 | { |
59af881e WS |
100 | if (m_helpFile.IsEmpty()) return false; |
101 | ||
f6bcfd97 | 102 | wxString str = GetValidFilename(m_helpFile); |
59af881e | 103 | |
5100cabf | 104 | return (WinHelp(GetSuitableHWND(), (const wxChar*) str, HELP_PARTIALKEY, (DWORD)(const wxChar*) k) != 0); |
2bda0e17 KB |
105 | } |
106 | ||
107 | // Can't close the help window explicitly in WinHelp | |
108 | bool wxWinHelpController::Quit(void) | |
109 | { | |
5100cabf | 110 | return (WinHelp(GetSuitableHWND(), 0, HELP_QUIT, 0L) != 0); |
2bda0e17 KB |
111 | } |
112 | ||
f6bcfd97 BP |
113 | // Append extension if necessary. |
114 | wxString wxWinHelpController::GetValidFilename(const wxString& file) const | |
2bda0e17 | 115 | { |
f6bcfd97 BP |
116 | wxString path, name, ext; |
117 | wxSplitPath(file, & path, & name, & ext); | |
118 | ||
119 | wxString fullName; | |
120 | if (path.IsEmpty()) | |
121 | fullName = name + wxT(".hlp"); | |
122 | else if (path.Last() == wxT('\\')) | |
123 | fullName = path + name + wxT(".hlp"); | |
124 | else | |
125 | fullName = path + wxT("\\") + name + wxT(".hlp"); | |
126 | return fullName; | |
2bda0e17 KB |
127 | } |
128 | ||
47d67540 | 129 | #endif // wxUSE_HELP |