]>
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 // We also have to specify the popups file (default is cshelp.txt).
112 // str += wxT("::/cshelp.txt");
115 popup
.cbStruct
= sizeof(popup
);
116 popup
.hinst
= (HINSTANCE
) wxGetInstance();
117 popup
.idString
= contextId
;
119 GetCursorPos(& popup
.pt
);
120 popup
.clrForeground
= -1;
121 popup
.clrBackground
= -1;
122 popup
.rcMargins
.top
= popup
.rcMargins
.left
= popup
.rcMargins
.right
= popup
.rcMargins
.bottom
= -1;
123 popup
.pszFont
= NULL
;
124 popup
.pszText
= NULL
;
126 HtmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_DISPLAY_TEXT_POPUP
, (DWORD
) & popup
);
130 bool wxCHMHelpController::DisplayTextPopup(const wxString
& text
, const wxPoint
& pos
)
133 popup
.cbStruct
= sizeof(popup
);
134 popup
.hinst
= (HINSTANCE
) wxGetInstance();
136 popup
.pt
.x
= pos
.x
; popup
.pt
.y
= pos
.y
;
137 popup
.clrForeground
= -1;
138 popup
.clrBackground
= -1;
139 popup
.rcMargins
.top
= popup
.rcMargins
.left
= popup
.rcMargins
.right
= popup
.rcMargins
.bottom
= -1;
140 popup
.pszFont
= NULL
;
141 popup
.pszText
= (const wxChar
*) text
;
143 HtmlHelp(GetSuitableHWND(), NULL
, HH_DISPLAY_TEXT_POPUP
, (DWORD
) & popup
);
147 bool wxCHMHelpController::DisplayBlock(long block
)
149 return DisplaySection(block
);
152 bool wxCHMHelpController::KeywordSearch(const wxString
& k
)
154 if (m_helpFile
.IsEmpty()) return FALSE
;
156 wxString str
= GetValidFilename(m_helpFile
);
159 link
.cbStruct
= sizeof(HH_AKLINK
) ;
160 link
.fReserved
= FALSE
;
161 link
.pszKeywords
= k
.c_str() ;
163 link
.pszMsgText
= NULL
;
164 link
.pszMsgTitle
= NULL
;
165 link
.pszWindow
= NULL
;
166 link
.fIndexOnFail
= TRUE
;
168 HtmlHelp(GetSuitableHWND(), (const wxChar
*) str
, HH_KEYWORD_LOOKUP
, (DWORD
)& link
);
172 bool wxCHMHelpController::Quit()
174 HtmlHelp(GetSuitableHWND(), 0, HH_CLOSE_ALL
, 0L);
178 // Append extension if necessary.
179 wxString
wxCHMHelpController::GetValidFilename(const wxString
& file
) const
181 wxString path
, name
, ext
;
182 wxSplitPath(file
, & path
, & name
, & ext
);
186 fullName
= name
+ wxT(".chm");
187 else if (path
.Last() == wxT('\\'))
188 fullName
= path
+ name
+ wxT(".chm");
190 fullName
= path
+ wxT("\\") + name
+ wxT(".chm");