]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/helpchm.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Help system: MS HTML Help implementation
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "helpchm.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
27 #include "wx/filefn.h"
29 #if wxUSE_HELP && wxUSE_MS_HTML_HELP && defined(__WIN95__)
30 #include "wx/msw/helpchm.h"
32 // This is found in the HTML Help Workshop installation,
33 // along with htmlhelp.lib.
39 #include "wx/msw/private.h"
44 static HWND
GetSuitableHWND()
46 if (wxTheApp
->GetTopWindow())
47 return (HWND
) wxTheApp
->GetTopWindow()->GetHWND();
49 return GetDesktopWindow();
52 IMPLEMENT_DYNAMIC_CLASS(wxCHMHelpController
, wxHelpControllerBase
)
54 bool wxCHMHelpController::Initialize(const wxString
& filename
)
56 m_helpFile
= filename
;
60 bool wxCHMHelpController::LoadFile(const wxString
& file
)
67 bool wxCHMHelpController::DisplayContents()
69 if (m_helpFile
.IsEmpty()) return FALSE
;
71 wxString str
= GetValidFilename(m_helpFile
);
73 HtmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_HELP_FINDER
, 0L);
77 // Use topic or HTML filename
78 bool wxCHMHelpController::DisplaySection(const wxString
& section
)
80 if (m_helpFile
.IsEmpty()) return FALSE
;
82 wxString str
= GetValidFilename(m_helpFile
);
84 // Is this an HTML file or a keyword?
85 bool isFilename
= (section
.Find(wxT(".htm")) != -1);
88 HtmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_DISPLAY_TOPIC
, (DWORD
) (const wxChar
*) section
);
90 KeywordSearch(section
);
95 bool wxCHMHelpController::DisplaySection(int section
)
97 if (m_helpFile
.IsEmpty()) return FALSE
;
99 wxString str
= GetValidFilename(m_helpFile
);
101 HtmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_HELP_CONTEXT
, (DWORD
)section
);
105 bool wxCHMHelpController::DisplayContextPopup(int contextId
)
107 if (m_helpFile
.IsEmpty()) return FALSE
;
109 wxString str
= GetValidFilename(m_helpFile
);
111 // TODO: what should this be?
112 //HtmlHelp(GetSuitableHWND(), (const wxChar*) str, HH_HELP_CONTEXT, (DWORD)contextId);
114 popup
.cbStruct
= sizeof(popup
);
115 popup
.hinst
= (HINSTANCE
) wxGetInstance();
116 popup
.idString
= contextId
;
118 GetCursorPos(& popup
.pt
);
119 popup
.clrForeground
= -1;
120 popup
.clrBackground
= -1;
121 popup
.rcMargins
.top
= popup
.rcMargins
.left
= popup
.rcMargins
.right
= popup
.rcMargins
.bottom
= -1;
122 popup
.pszFont
= NULL
;
123 popup
.pszText
= NULL
;
125 HtmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_DISPLAY_TEXT_POPUP
, (DWORD
) & popup
);
129 bool wxCHMHelpController::DisplayTextPopup(const wxString
& text
, const wxPoint
& pos
)
132 popup
.cbStruct
= sizeof(popup
);
133 popup
.hinst
= (HINSTANCE
) wxGetInstance();
135 popup
.pt
.x
= pos
.x
; popup
.pt
.y
= pos
.y
;
136 popup
.clrForeground
= -1;
137 popup
.clrBackground
= -1;
138 popup
.rcMargins
.top
= popup
.rcMargins
.left
= popup
.rcMargins
.right
= popup
.rcMargins
.bottom
= -1;
139 popup
.pszFont
= NULL
;
140 popup
.pszText
= (const wxChar
*) text
;
142 HtmlHelp(GetSuitableHWND(), NULL
, HH_DISPLAY_TEXT_POPUP
, (DWORD
) & popup
);
146 bool wxCHMHelpController::DisplayBlock(long block
)
148 return DisplaySection(block
);
151 bool wxCHMHelpController::KeywordSearch(const wxString
& k
)
153 if (m_helpFile
.IsEmpty()) return FALSE
;
155 wxString str
= GetValidFilename(m_helpFile
);
158 link
.cbStruct
= sizeof(HH_AKLINK
) ;
159 link
.fReserved
= FALSE
;
160 link
.pszKeywords
= k
.c_str() ;
162 link
.pszMsgText
= NULL
;
163 link
.pszMsgTitle
= NULL
;
164 link
.pszWindow
= NULL
;
165 link
.fIndexOnFail
= TRUE
;
167 HtmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_KEYWORD_LOOKUP
, (DWORD
)& link
);
171 bool wxCHMHelpController::Quit()
173 HtmlHelp(GetSuitableHWND(), 0, HH_CLOSE_ALL
, 0L);
177 // Append extension if necessary.
178 wxString
wxCHMHelpController::GetValidFilename(const wxString
& file
) const
180 wxString path
, name
, ext
;
181 wxSplitPath(file
, & path
, & name
, & ext
);
185 fullName
= name
+ wxT(".chm");
186 else if (path
.Last() == wxT('\\'))
187 fullName
= path
+ name
+ wxT(".chm");
189 fullName
= path
+ wxT("\\") + name
+ wxT(".chm");