]> git.saurik.com Git - wxWidgets.git/blob - src/msw/helpwin.cpp
don't reset the selection after event was vetoed if there is no old selection
[wxWidgets.git] / src / msw / helpwin.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/helpwin.cpp
3 // Purpose: Help system: WinHelp implementation
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
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 #if wxUSE_HELP
20
21 #ifndef WX_PRECOMP
22 #endif
23
24 #include "wx/filefn.h"
25 #include "wx/msw/helpwin.h"
26
27 #include <time.h>
28
29 #ifdef __WXMSW__
30 #include "wx/msw/private.h"
31 #endif
32
33 #include <string.h>
34
35 static HWND GetSuitableHWND(wxWinHelpController* controller)
36 {
37 if (controller->GetParentWindow())
38 return (HWND) controller->GetParentWindow()->GetHWND();
39 else if (wxTheApp->GetTopWindow())
40 return (HWND) wxTheApp->GetTopWindow()->GetHWND();
41 else
42 return GetDesktopWindow();
43 }
44
45 IMPLEMENT_DYNAMIC_CLASS(wxWinHelpController, wxHelpControllerBase)
46
47 bool wxWinHelpController::Initialize(const wxString& filename)
48 {
49 m_helpFile = filename;
50 return true;
51 }
52
53 bool wxWinHelpController::LoadFile(const wxString& file)
54 {
55 if (!file.empty())
56 m_helpFile = file;
57 return true;
58 }
59
60 bool wxWinHelpController::DisplayContents(void)
61 {
62 if (m_helpFile.empty()) return false;
63
64 wxString str = GetValidFilename(m_helpFile);
65
66 return (WinHelp(GetSuitableHWND(this), (const wxChar*) str, HELP_FINDER, 0L) != 0);
67 }
68
69 bool wxWinHelpController::DisplaySection(int section)
70 {
71 // Use context number
72 if (m_helpFile.empty()) return false;
73
74 wxString str = GetValidFilename(m_helpFile);
75
76 return (WinHelp(GetSuitableHWND(this), (const wxChar*) str, HELP_CONTEXT, (DWORD)section) != 0);
77 }
78
79 bool wxWinHelpController::DisplayContextPopup(int contextId)
80 {
81 if (m_helpFile.empty()) return false;
82
83 wxString str = GetValidFilename(m_helpFile);
84
85 return (WinHelp(GetSuitableHWND(this), (const wxChar*) str, HELP_CONTEXTPOPUP, (DWORD) contextId) != 0);
86 }
87
88 bool wxWinHelpController::DisplayBlock(long block)
89 {
90 DisplaySection(block);
91 return true;
92 }
93
94 bool wxWinHelpController::KeywordSearch(const wxString& k,
95 wxHelpSearchMode WXUNUSED(mode))
96 {
97 if (m_helpFile.empty()) return false;
98
99 wxString str = GetValidFilename(m_helpFile);
100
101 return (WinHelp(GetSuitableHWND(this), (const wxChar*) str, HELP_PARTIALKEY, (DWORD)(const wxChar*) k) != 0);
102 }
103
104 // Can't close the help window explicitly in WinHelp
105 bool wxWinHelpController::Quit(void)
106 {
107 return (WinHelp(GetSuitableHWND(this), 0, HELP_QUIT, 0L) != 0);
108 }
109
110 // Append extension if necessary.
111 wxString wxWinHelpController::GetValidFilename(const wxString& file) const
112 {
113 wxString path, name, ext;
114 wxSplitPath(file, & path, & name, & ext);
115
116 wxString fullName;
117 if (path.empty())
118 fullName = name + wxT(".hlp");
119 else if (path.Last() == wxT('\\'))
120 fullName = path + name + wxT(".hlp");
121 else
122 fullName = path + wxT("\\") + name + wxT(".hlp");
123 return fullName;
124 }
125
126 #endif // wxUSE_HELP