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