]> git.saurik.com Git - wxWidgets.git/blob - src/generic/helpwxht.cpp
item with no image no longer crash when hit
[wxWidgets.git] / src / generic / helpwxht.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: helpext.cpp
3 // Purpose: an external help controller for wxWindows
4 // Author: Karsten Ballueder
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Karsten Ballueder
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 # pragma implementation "helpwxht.h"
14 #endif
15
16 #include "wx/wxprec.h"
17
18 #ifdef __BORLANDC__
19 # pragma hdrstop
20 #endif
21
22 #if wxUSE_HTML
23
24 #ifndef WX_PRECOMP
25 # include "wx/string.h"
26 # include "wx/utils.h"
27 # include "wx/list.h"
28 # include "wx/intl.h"
29 # include "wx/layout.h"
30 #endif
31
32 #include "wx/helpbase.h"
33 #include "wx/generic/helpwxht.h"
34 #include "wx/html/htmlwin.h"
35
36 #include <stdio.h>
37 #include <ctype.h>
38 #include <sys/stat.h>
39
40 #ifndef __WINDOWS__
41 # include <unistd.h>
42 #endif
43
44 IMPLEMENT_CLASS(wxHelpControllerHtml, wxHTMLHelpControllerBase)
45
46 /**
47 This class implements help via an external browser.
48 It requires the name of a directory containing the documentation
49 and a file mapping numerical Section numbers to relative URLS.
50 */
51
52 #define FRAME_WIDTH 400
53 #define FRAME_HEIGHT 400
54 #define LAYOUT_X_MARGIN 2
55 #define LAYOUT_Y_MARGIN 2
56 #define OFFSET 10
57
58 class wxHelpFrame : public wxFrame
59 {
60 public:
61 wxHelpFrame(wxWindow *parent, int id, const wxString &title,
62 const wxPoint &pos, const wxSize &size,
63 wxHelpControllerHtml *controller);
64 ~wxHelpFrame();
65 void OnClose(wxCloseEvent &ev);
66 bool LoadPage(const wxString &url) { return m_htmlwin->LoadPage(url); }
67 private:
68 wxHelpControllerHtml *m_controller;
69 wxHtmlWindow *m_htmlwin;
70 DECLARE_EVENT_TABLE()
71 };
72
73 BEGIN_EVENT_TABLE(wxHelpFrame, wxFrame)
74 EVT_CLOSE(wxHelpFrame::OnClose)
75 END_EVENT_TABLE()
76
77 wxHelpFrame::wxHelpFrame(wxWindow *parent, int id,
78 const wxString &title,
79 const wxPoint &pos, const wxSize &size,
80 wxHelpControllerHtml *controller)
81 : wxFrame(parent, id, title, pos, size)
82 {
83
84 m_controller = controller;
85 m_htmlwin = new wxHtmlWindow(this,-1,wxDefaultPosition,wxSize(FRAME_WIDTH,
86 FRAME_HEIGHT));
87
88 wxLayoutConstraints *c;
89
90 c = new wxLayoutConstraints;
91 c->left.SameAs(this, wxLeft, 2*LAYOUT_X_MARGIN);
92 c->right.SameAs(this, wxRight, 2*LAYOUT_X_MARGIN);
93 c->top.SameAs(this, wxTop, 2*LAYOUT_Y_MARGIN);
94 c->bottom.SameAs(this, wxBottom, 2*LAYOUT_Y_MARGIN);
95 m_htmlwin->SetConstraints(c);
96 SetAutoLayout(TRUE);
97 Show(TRUE);
98 }
99
100 wxHelpFrame::~wxHelpFrame()
101 {
102 }
103
104 void
105 wxHelpFrame::OnClose(wxCloseEvent &ev)
106 {
107 wxASSERT(m_controller);
108 m_controller->m_Frame = NULL;
109 bool newFrame;
110 int x,y;
111 GetPosition(&x,&y);
112
113 m_controller->GetFrameParameters(NULL, NULL, &newFrame);
114 m_controller->SetFrameParameters(GetTitle(), GetSize(),
115 wxPoint(x,y),
116 newFrame);
117 Destroy();
118 }
119
120 wxHelpControllerHtml::wxHelpControllerHtml(void)
121 {
122 m_Frame = NULL;
123 m_offset = 0;
124
125 SetFrameParameters(_("Help"),
126 wxSize(FRAME_WIDTH, FRAME_HEIGHT),
127 wxDefaultPosition);
128 }
129
130 wxHelpControllerHtml::~wxHelpControllerHtml(void)
131 {
132 if(m_Frame && ! m_NewFrameEachTime)
133 m_Frame->Close();
134 }
135
136
137 #ifdef __WXMSW__
138 # define SEP '\\'
139 #else
140 # define SEP '/'
141 #endif
142
143 bool
144 wxHelpControllerHtml::DisplayHelp(wxString const &relativeURL)
145 {
146 wxBusyCursor b; // display a busy cursor
147
148 wxString url;
149 url << m_MapFile << SEP<< relativeURL;
150 if(! m_Frame || m_NewFrameEachTime)
151 {
152 m_Frame = new wxHelpFrame(NULL, -1, m_FrameTitle,
153 m_FramePosition+wxPoint(m_offset,m_offset),
154 m_FrameSize,
155 this);
156 if(m_NewFrameEachTime)
157 {
158 m_offset += OFFSET;
159 if(m_offset > 200)
160 m_offset = 0;
161 }
162
163 }
164 return m_Frame->LoadPage(url);
165 }
166
167
168 void
169 wxHelpControllerHtml::SetFrameParameters(const wxString &title,
170 const wxSize &size,
171 const wxPoint &pos,
172 bool newFrame)
173 {
174 m_FrameTitle = title;
175 m_FrameSize = size;
176 m_FramePosition = pos;
177 m_NewFrameEachTime = newFrame;
178 }
179
180 void
181 wxHelpControllerHtml::GetFrameParameters(wxSize *size = NULL,
182 wxPoint *pos = NULL,
183 bool *newframe = NULL)
184 {
185 if(size) *size = m_FrameSize;
186 if(pos) *pos = m_FramePosition;
187 if(newframe) *newframe = m_NewFrameEachTime;
188 }
189
190 #endif // wxUSE_HTML