]> git.saurik.com Git - wxWidgets.git/blob - src/msw/helpwin.cpp
use a linked list instead of array for saved messages to fix problems when Dispatch...
[wxWidgets.git] / src / msw / helpwin.cpp
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$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "helpwin.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/defs.h"
25 #endif
26
27 #if wxUSE_HELP
28
29 #include "wx/filefn.h"
30 #include "wx/msw/helpwin.h"
31
32 #include <time.h>
33
34 #ifdef __WXMSW__
35 #include "wx/msw/private.h"
36 #endif
37
38 #include <string.h>
39
40 static HWND GetSuitableHWND()
41 {
42 if (wxTheApp->GetTopWindow())
43 return (HWND) wxTheApp->GetTopWindow()->GetHWND();
44 else
45 return GetDesktopWindow();
46 }
47
48 IMPLEMENT_DYNAMIC_CLASS(wxWinHelpController, wxHelpControllerBase)
49
50 bool wxWinHelpController::Initialize(const wxString& filename)
51 {
52 m_helpFile = filename;
53 return true;
54 }
55
56 bool wxWinHelpController::LoadFile(const wxString& file)
57 {
58 if (!file.IsEmpty())
59 m_helpFile = file;
60 return true;
61 }
62
63 bool wxWinHelpController::DisplayContents(void)
64 {
65 if (m_helpFile.IsEmpty()) return false;
66
67 wxString str = GetValidFilename(m_helpFile);
68
69 #if defined(__WIN95__)
70 return (WinHelp(GetSuitableHWND(), (const wxChar*) str, HELP_FINDER, 0L) != 0);
71 #else
72 return (WinHelp(GetSuitableHWND(), (const wxChar*) str, HELP_CONTENTS, 0L) != 0);
73 #endif
74 }
75
76 bool wxWinHelpController::DisplaySection(int section)
77 {
78 // Use context number
79 if (m_helpFile.IsEmpty()) return false;
80
81 wxString str = GetValidFilename(m_helpFile);
82
83 return (WinHelp((HWND) wxTheApp->GetTopWindow()->GetHWND(), (const wxChar*) str, HELP_CONTEXT, (DWORD)section) != 0);
84 }
85
86 bool wxWinHelpController::DisplayContextPopup(int contextId)
87 {
88 if (m_helpFile.IsEmpty()) return false;
89
90 wxString str = GetValidFilename(m_helpFile);
91
92 return (WinHelp((HWND) wxTheApp->GetTopWindow()->GetHWND(), (const wxChar*) str, HELP_CONTEXTPOPUP, (DWORD) contextId) != 0);
93 }
94
95 bool wxWinHelpController::DisplayBlock(long block)
96 {
97 DisplaySection(block);
98 return true;
99 }
100
101 bool wxWinHelpController::KeywordSearch(const wxString& k,
102 wxHelpSearchMode WXUNUSED(mode))
103 {
104 if (m_helpFile.IsEmpty()) return false;
105
106 wxString str = GetValidFilename(m_helpFile);
107
108 return (WinHelp(GetSuitableHWND(), (const wxChar*) str, HELP_PARTIALKEY, (DWORD)(const wxChar*) k) != 0);
109 }
110
111 // Can't close the help window explicitly in WinHelp
112 bool wxWinHelpController::Quit(void)
113 {
114 return (WinHelp(GetSuitableHWND(), 0, HELP_QUIT, 0L) != 0);
115 }
116
117 // Append extension if necessary.
118 wxString wxWinHelpController::GetValidFilename(const wxString& file) const
119 {
120 wxString path, name, ext;
121 wxSplitPath(file, & path, & name, & ext);
122
123 wxString fullName;
124 if (path.IsEmpty())
125 fullName = name + wxT(".hlp");
126 else if (path.Last() == wxT('\\'))
127 fullName = path + name + wxT(".hlp");
128 else
129 fullName = path + wxT("\\") + name + wxT(".hlp");
130 return fullName;
131 }
132
133 #endif // wxUSE_HELP