]>
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 | ||
3db52265 | 36 | static HWND GetSuitableHWND(wxWinHelpController* controller) |
2bda0e17 | 37 | { |
3db52265 JS |
38 | if (controller->GetParentWindow()) |
39 | return (HWND) controller->GetParentWindow()->GetHWND(); | |
40 | else if (wxTheApp->GetTopWindow()) | |
f6bcfd97 BP |
41 | return (HWND) wxTheApp->GetTopWindow()->GetHWND(); |
42 | else | |
43 | return GetDesktopWindow(); | |
2bda0e17 KB |
44 | } |
45 | ||
f6bcfd97 | 46 | IMPLEMENT_DYNAMIC_CLASS(wxWinHelpController, wxHelpControllerBase) |
2bda0e17 | 47 | |
38009d39 | 48 | bool wxWinHelpController::Initialize(const wxString& filename) |
2bda0e17 | 49 | { |
f6bcfd97 | 50 | m_helpFile = filename; |
59af881e | 51 | return true; |
2bda0e17 KB |
52 | } |
53 | ||
54 | bool wxWinHelpController::LoadFile(const wxString& file) | |
55 | { | |
f6bcfd97 BP |
56 | if (!file.IsEmpty()) |
57 | m_helpFile = file; | |
59af881e | 58 | return true; |
2bda0e17 KB |
59 | } |
60 | ||
61 | bool wxWinHelpController::DisplayContents(void) | |
62 | { | |
59af881e WS |
63 | if (m_helpFile.IsEmpty()) return false; |
64 | ||
f6bcfd97 | 65 | wxString str = GetValidFilename(m_helpFile); |
59af881e | 66 | |
2bda0e17 | 67 | #if defined(__WIN95__) |
3db52265 | 68 | return (WinHelp(GetSuitableHWND(this), (const wxChar*) str, HELP_FINDER, 0L) != 0); |
2bda0e17 | 69 | #else |
3db52265 | 70 | return (WinHelp(GetSuitableHWND(this), (const wxChar*) str, HELP_CONTENTS, 0L) != 0); |
2bda0e17 | 71 | #endif |
2bda0e17 KB |
72 | } |
73 | ||
74 | bool wxWinHelpController::DisplaySection(int section) | |
75 | { | |
33b64e6f | 76 | // Use context number |
59af881e WS |
77 | if (m_helpFile.IsEmpty()) return false; |
78 | ||
f6bcfd97 | 79 | wxString str = GetValidFilename(m_helpFile); |
33b64e6f | 80 | |
3db52265 | 81 | return (WinHelp(GetSuitableHWND(this), (const wxChar*) str, HELP_CONTEXT, (DWORD)section) != 0); |
5100cabf JS |
82 | } |
83 | ||
84 | bool wxWinHelpController::DisplayContextPopup(int contextId) | |
85 | { | |
59af881e WS |
86 | if (m_helpFile.IsEmpty()) return false; |
87 | ||
5100cabf JS |
88 | wxString str = GetValidFilename(m_helpFile); |
89 | ||
3db52265 | 90 | return (WinHelp(GetSuitableHWND(this), (const wxChar*) str, HELP_CONTEXTPOPUP, (DWORD) contextId) != 0); |
2bda0e17 KB |
91 | } |
92 | ||
93 | bool wxWinHelpController::DisplayBlock(long block) | |
94 | { | |
f6bcfd97 | 95 | DisplaySection(block); |
59af881e | 96 | return true; |
2bda0e17 KB |
97 | } |
98 | ||
69b5cec2 VS |
99 | bool wxWinHelpController::KeywordSearch(const wxString& k, |
100 | wxHelpSearchMode WXUNUSED(mode)) | |
2bda0e17 | 101 | { |
59af881e WS |
102 | if (m_helpFile.IsEmpty()) return false; |
103 | ||
f6bcfd97 | 104 | wxString str = GetValidFilename(m_helpFile); |
59af881e | 105 | |
3db52265 | 106 | return (WinHelp(GetSuitableHWND(this), (const wxChar*) str, HELP_PARTIALKEY, (DWORD)(const wxChar*) k) != 0); |
2bda0e17 KB |
107 | } |
108 | ||
109 | // Can't close the help window explicitly in WinHelp | |
110 | bool wxWinHelpController::Quit(void) | |
111 | { | |
3db52265 | 112 | return (WinHelp(GetSuitableHWND(this), 0, HELP_QUIT, 0L) != 0); |
2bda0e17 KB |
113 | } |
114 | ||
f6bcfd97 BP |
115 | // Append extension if necessary. |
116 | wxString wxWinHelpController::GetValidFilename(const wxString& file) const | |
2bda0e17 | 117 | { |
f6bcfd97 BP |
118 | wxString path, name, ext; |
119 | wxSplitPath(file, & path, & name, & ext); | |
120 | ||
121 | wxString fullName; | |
122 | if (path.IsEmpty()) | |
123 | fullName = name + wxT(".hlp"); | |
124 | else if (path.Last() == wxT('\\')) | |
125 | fullName = path + name + wxT(".hlp"); | |
126 | else | |
127 | fullName = path + wxT("\\") + name + wxT(".hlp"); | |
128 | return fullName; | |
2bda0e17 KB |
129 | } |
130 | ||
47d67540 | 131 | #endif // wxUSE_HELP |