]> git.saurik.com Git - wxWidgets.git/blob - src/msw/helpwin.cpp
fix wxExecute() return code checks and removed not working code to open URLs in new...
[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 // 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
23 #if wxUSE_HELP
24
25 #include "wx/filefn.h"
26 #include "wx/msw/helpwin.h"
27
28 #include <time.h>
29
30 #ifdef __WXMSW__
31 #include "wx/msw/private.h"
32 #endif
33
34 #include <string.h>
35
36 static HWND GetSuitableHWND()
37 {
38 if (wxTheApp->GetTopWindow())
39 return (HWND) wxTheApp->GetTopWindow()->GetHWND();
40 else
41 return GetDesktopWindow();
42 }
43
44 IMPLEMENT_DYNAMIC_CLASS(wxWinHelpController, wxHelpControllerBase)
45
46 bool wxWinHelpController::Initialize(const wxString& filename)
47 {
48 m_helpFile = filename;
49 return true;
50 }
51
52 bool wxWinHelpController::LoadFile(const wxString& file)
53 {
54 if (!file.IsEmpty())
55 m_helpFile = file;
56 return true;
57 }
58
59 bool wxWinHelpController::DisplayContents(void)
60 {
61 if (m_helpFile.IsEmpty()) return false;
62
63 wxString str = GetValidFilename(m_helpFile);
64
65 #if defined(__WIN95__)
66 return (WinHelp(GetSuitableHWND(), (const wxChar*) str, HELP_FINDER, 0L) != 0);
67 #else
68 return (WinHelp(GetSuitableHWND(), (const wxChar*) str, HELP_CONTENTS, 0L) != 0);
69 #endif
70 }
71
72 bool wxWinHelpController::DisplaySection(int section)
73 {
74 // Use context number
75 if (m_helpFile.IsEmpty()) return false;
76
77 wxString str = GetValidFilename(m_helpFile);
78
79 return (WinHelp((HWND) wxTheApp->GetTopWindow()->GetHWND(), (const wxChar*) str, HELP_CONTEXT, (DWORD)section) != 0);
80 }
81
82 bool wxWinHelpController::DisplayContextPopup(int contextId)
83 {
84 if (m_helpFile.IsEmpty()) return false;
85
86 wxString str = GetValidFilename(m_helpFile);
87
88 return (WinHelp((HWND) wxTheApp->GetTopWindow()->GetHWND(), (const wxChar*) str, HELP_CONTEXTPOPUP, (DWORD) contextId) != 0);
89 }
90
91 bool wxWinHelpController::DisplayBlock(long block)
92 {
93 DisplaySection(block);
94 return true;
95 }
96
97 bool wxWinHelpController::KeywordSearch(const wxString& k,
98 wxHelpSearchMode WXUNUSED(mode))
99 {
100 if (m_helpFile.IsEmpty()) return false;
101
102 wxString str = GetValidFilename(m_helpFile);
103
104 return (WinHelp(GetSuitableHWND(), (const wxChar*) str, HELP_PARTIALKEY, (DWORD)(const wxChar*) k) != 0);
105 }
106
107 // Can't close the help window explicitly in WinHelp
108 bool wxWinHelpController::Quit(void)
109 {
110 return (WinHelp(GetSuitableHWND(), 0, HELP_QUIT, 0L) != 0);
111 }
112
113 // Append extension if necessary.
114 wxString wxWinHelpController::GetValidFilename(const wxString& file) const
115 {
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;
127 }
128
129 #endif // wxUSE_HELP