]> git.saurik.com Git - wxWidgets.git/blame - src/msw/helpwin.cpp
Added chapter on collection and container classes to contents
[wxWidgets.git] / src / msw / helpwin.cpp
CommitLineData
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$
8// Copyright: (c) Julian Smart and Markus Holzem
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
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
f6bcfd97
BP
27#if wxUSE_HELP
28
29#include "wx/filefn.h"
2bda0e17
KB
30#include "wx/msw/helpwin.h"
31
2bda0e17
KB
32#include <time.h>
33
2049ba38 34#ifdef __WXMSW__
3096bd2f 35#include "wx/msw/private.h"
2bda0e17
KB
36#endif
37
38#include <string.h>
39
f6bcfd97 40static HWND GetSuitableHWND()
2bda0e17 41{
f6bcfd97
BP
42 if (wxTheApp->GetTopWindow())
43 return (HWND) wxTheApp->GetTopWindow()->GetHWND();
44 else
45 return GetDesktopWindow();
2bda0e17
KB
46}
47
f6bcfd97 48IMPLEMENT_DYNAMIC_CLASS(wxWinHelpController, wxHelpControllerBase)
2bda0e17 49
38009d39 50bool wxWinHelpController::Initialize(const wxString& filename)
2bda0e17 51{
f6bcfd97
BP
52 m_helpFile = filename;
53 return TRUE;
2bda0e17
KB
54}
55
56bool wxWinHelpController::LoadFile(const wxString& file)
57{
f6bcfd97
BP
58 if (!file.IsEmpty())
59 m_helpFile = file;
60 return TRUE;
2bda0e17
KB
61}
62
63bool wxWinHelpController::DisplayContents(void)
64{
f6bcfd97
BP
65 if (m_helpFile.IsEmpty()) return FALSE;
66
67 wxString str = GetValidFilename(m_helpFile);
68
2bda0e17 69#if defined(__WIN95__)
f6bcfd97 70 WinHelp(GetSuitableHWND(), (const wxChar*) str, HELP_FINDER, 0L);
2bda0e17 71#else
f6bcfd97 72 WinHelp(GetSuitableHWND(), (const wxChar*) str, HELP_CONTENTS, 0L);
2bda0e17 73#endif
f6bcfd97 74 return TRUE;
2bda0e17
KB
75}
76
77bool wxWinHelpController::DisplaySection(int section)
78{
33b64e6f 79 // Use context number
f6bcfd97
BP
80 if (m_helpFile.IsEmpty()) return FALSE;
81
82 wxString str = GetValidFilename(m_helpFile);
33b64e6f 83
f6bcfd97
BP
84 WinHelp((HWND) wxTheApp->GetTopWindow()->GetHWND(), (const wxChar*) str, HELP_CONTEXT, (DWORD)section);
85 return TRUE;
2bda0e17
KB
86}
87
88bool wxWinHelpController::DisplayBlock(long block)
89{
f6bcfd97
BP
90 DisplaySection(block);
91 return TRUE;
2bda0e17
KB
92}
93
94bool wxWinHelpController::KeywordSearch(const wxString& k)
95{
f6bcfd97
BP
96 if (m_helpFile.IsEmpty()) return FALSE;
97
98 wxString str = GetValidFilename(m_helpFile);
99
100 WinHelp(GetSuitableHWND(), (const wxChar*) str, HELP_PARTIALKEY, (DWORD)(const wxChar*) k);
101 return TRUE;
2bda0e17
KB
102}
103
104// Can't close the help window explicitly in WinHelp
105bool wxWinHelpController::Quit(void)
106{
f6bcfd97 107 WinHelp(GetSuitableHWND(), 0, HELP_QUIT, 0L);
e5fb7191 108 return TRUE;
2bda0e17
KB
109}
110
f6bcfd97
BP
111// Append extension if necessary.
112wxString wxWinHelpController::GetValidFilename(const wxString& file) const
2bda0e17 113{
f6bcfd97
BP
114 wxString path, name, ext;
115 wxSplitPath(file, & path, & name, & ext);
116
117 wxString fullName;
118 if (path.IsEmpty())
119 fullName = name + wxT(".hlp");
120 else if (path.Last() == wxT('\\'))
121 fullName = path + name + wxT(".hlp");
122 else
123 fullName = path + wxT("\\") + name + wxT(".hlp");
124 return fullName;
2bda0e17
KB
125}
126
47d67540 127#endif // wxUSE_HELP