]> git.saurik.com Git - wxWidgets.git/blob - src/html/helpfrm.cpp
don't draw focus rect for custom drawn items when the list control doesn't have focus
[wxWidgets.git] / src / html / helpfrm.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: helpfrm.cpp
3 // Purpose: wxHtmlHelpFrame
4 // Notes: Based on htmlhelp.cpp, implementing a monolithic
5 // HTML Help controller class, by Vaclav Slavik
6 // Author: Harm van der Heijden and Vaclav Slavik
7 // RCS-ID: $Id$
8 // Copyright: (c) Harm van der Heijden and Vaclav Slavik
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h"
13
14 #include "wx/wxprec.h"
15
16 #ifdef __BORLANDC__
17 #pragma hdrstop
18 #endif
19
20 #if wxUSE_WXHTML_HELP
21
22 #ifndef WXPRECOMP
23 #include "wx/intl.h"
24 #include "wx/log.h"
25
26 #include "wx/object.h"
27 #include "wx/sizer.h"
28
29 #include "wx/bmpbuttn.h"
30 #include "wx/statbox.h"
31 #include "wx/radiobox.h"
32 #endif // WXPRECOMP
33
34 #ifdef __WXMAC__
35 #include "wx/menu.h"
36 #include "wx/msgdlg.h"
37 #endif
38
39 #include "wx/html/helpfrm.h"
40 #include "wx/html/helpctrl.h"
41 #include "wx/textctrl.h"
42 #include "wx/notebook.h"
43 #include "wx/imaglist.h"
44 #include "wx/treectrl.h"
45 #include "wx/tokenzr.h"
46 #include "wx/wfstream.h"
47 #include "wx/html/htmlwin.h"
48 #include "wx/busyinfo.h"
49 #include "wx/progdlg.h"
50 #include "wx/toolbar.h"
51 #include "wx/fontenum.h"
52 #include "wx/stream.h"
53 #include "wx/filedlg.h"
54 #include "wx/artprov.h"
55 #include "wx/spinctrl.h"
56 #include "wx/dynarray.h"
57 #include "wx/choicdlg.h"
58 #include "wx/settings.h"
59
60 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpFrame, wxFrame)
61
62 BEGIN_EVENT_TABLE(wxHtmlHelpFrame, wxFrame)
63 EVT_ACTIVATE(wxHtmlHelpFrame::OnActivate)
64 EVT_CLOSE(wxHtmlHelpFrame::OnCloseWindow)
65 #ifdef __WXMAC__
66 EVT_MENU(wxID_CLOSE, wxHtmlHelpFrame::OnClose)
67 EVT_MENU(wxID_ABOUT, wxHtmlHelpFrame::OnAbout)
68 EVT_MENU(wxID_HELP_CONTENTS, wxHtmlHelpFrame::OnAbout)
69 #endif
70 END_EVENT_TABLE()
71
72 wxHtmlHelpFrame::wxHtmlHelpFrame(wxWindow* parent, wxWindowID id, const wxString& title,
73 int style, wxHtmlHelpData* data)
74 {
75 Init(data);
76 Create(parent, id, title, style);
77 }
78
79 void wxHtmlHelpFrame::Init(wxHtmlHelpData* data)
80 {
81 // Simply pass the pointer on to the help window
82 m_Data = data;
83 m_HtmlHelpWin = NULL;
84 m_helpController = (wxHtmlHelpController*) NULL;
85 }
86
87 // Create: builds the GUI components.
88 bool wxHtmlHelpFrame::Create(wxWindow* parent, wxWindowID id,
89 const wxString& WXUNUSED(title), int style)
90 {
91 m_HtmlHelpWin = new wxHtmlHelpWindow(m_Data);
92
93 wxFrame::Create(parent, id, _("Help"),
94 wxPoint(m_HtmlHelpWin->GetCfgData().x, m_HtmlHelpWin->GetCfgData().y),
95 wxSize(m_HtmlHelpWin->GetCfgData().w, m_HtmlHelpWin->GetCfgData().h),
96 wxDEFAULT_FRAME_STYLE, wxT("wxHtmlHelp"));
97 #if wxUSE_STATUSBAR
98 CreateStatusBar();
99 #endif
100 m_HtmlHelpWin->Create(this, -1, wxDefaultPosition, wxDefaultSize,
101 wxTAB_TRAVERSAL|wxNO_BORDER, style);
102
103 GetPosition(& (m_HtmlHelpWin->GetCfgData().x), & (m_HtmlHelpWin->GetCfgData()).y);
104
105 SetIcon(wxArtProvider::GetIcon(wxART_HELP, wxART_HELP_BROWSER));
106
107 // On the Mac, each modeless frame must have a menubar.
108 // TODO: add more menu items, and perhaps add a style to show
109 // the menubar: compulsory on the Mac, optional elsewhere.
110 #ifdef __WXMAC__
111 wxMenuBar* menuBar = new wxMenuBar;
112
113 wxMenu* fileMenu = new wxMenu;
114 fileMenu->Append(wxID_HTML_OPENFILE, _("&Open..."));
115 fileMenu->AppendSeparator();
116 fileMenu->Append(wxID_CLOSE, _("&Close"));
117
118 wxMenu* helpMenu = new wxMenu;
119 helpMenu->Append(wxID_ABOUT, _("&About..."));
120 // Ensures we don't get an empty help menu
121 helpMenu->Append(wxID_HELP_CONTENTS, _("&About..."));
122
123 menuBar->Append(fileMenu,_("&File"));
124 menuBar->Append(helpMenu,_("&Help"));
125 SetMenuBar(menuBar);
126 #endif
127
128 m_HtmlHelpWin->GetHtmlWindow()->SetRelatedFrame(this, m_TitleFormat);
129 #if wxUSE_STATUSBAR
130 m_HtmlHelpWin->GetHtmlWindow()->SetRelatedStatusBar(0);
131 #endif
132 return true;
133 }
134
135 wxHtmlHelpFrame::~wxHtmlHelpFrame()
136 {
137 }
138
139 void wxHtmlHelpFrame::SetTitleFormat(const wxString& format)
140 {
141 if (GetHelpWindow() && GetHelpWindow()->GetHtmlWindow())
142 GetHelpWindow()->GetHtmlWindow()->SetRelatedFrame(this, format);
143 m_TitleFormat = format;
144 }
145
146 /*
147 EVENT HANDLING :
148 */
149
150
151 void wxHtmlHelpFrame::OnActivate(wxActivateEvent& event)
152 {
153 // This saves one mouse click when using the
154 // wxHTML for context sensitive help systems
155 #ifndef __WXGTK__
156 // NB: wxActivateEvent is a bit broken in wxGTK
157 // and is sometimes sent when it should not be
158 if (event.GetActive() && m_HtmlHelpWin)
159 m_HtmlHelpWin->GetHtmlWindow()->SetFocus();
160 #endif
161
162 event.Skip();
163 }
164
165 void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent& evt)
166 {
167 if (!IsIconized())
168 {
169 GetSize(& (m_HtmlHelpWin->GetCfgData().w), &(m_HtmlHelpWin->GetCfgData().h));
170 GetPosition(& (m_HtmlHelpWin->GetCfgData().x), & (m_HtmlHelpWin->GetCfgData().y));
171 }
172
173 #ifdef __WXGTK__
174 if (IsGrabbed())
175 {
176 RemoveGrab();
177 }
178 #endif
179
180 if (m_HtmlHelpWin->GetSplitterWindow() && m_HtmlHelpWin->GetCfgData().navig_on)
181 m_HtmlHelpWin->GetCfgData().sashpos = m_HtmlHelpWin->GetSplitterWindow()->GetSashPosition();
182
183 if (m_helpController && m_helpController->IsKindOf(CLASSINFO(wxHtmlHelpController)))
184 {
185 ((wxHtmlHelpController*) m_helpController)->OnCloseFrame(evt);
186 }
187
188 evt.Skip();
189 }
190
191 // Make the help controller's frame 'modal' if
192 // needed
193 void wxHtmlHelpFrame::AddGrabIfNeeded()
194 {
195 // So far, wxGTK only
196 #ifdef __WXGTK__
197 bool needGrab = FALSE;
198
199 // Check if there are any modal windows present,
200 // in which case we need to add a grab.
201 for ( wxWindowList::iterator it = wxTopLevelWindows.begin();
202 it != wxTopLevelWindows.end();
203 ++it )
204 {
205 wxWindow *win = *it;
206 wxDialog *dialog = wxDynamicCast(win, wxDialog);
207
208 if (dialog && dialog->IsModal())
209 needGrab = TRUE;
210 }
211
212 if (needGrab)
213 AddGrab();
214 #endif // __WXGTK__
215 }
216
217 // For compatibility
218 void wxHtmlHelpFrame::UseConfig(wxConfigBase *config, const wxString& rootPath)
219 {
220 if (m_HtmlHelpWin)
221 m_HtmlHelpWin->UseConfig(config, rootPath);
222 }
223
224 #ifdef __WXMAC__
225 void wxHtmlHelpFrame::OnClose(wxCommandEvent& event)
226 {
227 Close(true);
228 }
229
230 void wxHtmlHelpFrame::OnAbout(wxCommandEvent& event)
231 {
232 wxMessageBox(wxT("wxWidgets HTML Help Viewer (c) 1998-2006, Vaclav Slavik et al"), wxT("HelpView"),
233 wxICON_INFORMATION|wxOK, this);
234 }
235 #endif
236
237 #endif // wxUSE_WXHTML_HELP