]> git.saurik.com Git - wxWidgets.git/blame - src/generic/helpwxht.cpp
some updates...
[wxWidgets.git] / src / generic / helpwxht.cpp
CommitLineData
29ea4a29
KB
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
4f84c635
VZ
22#if wxUSE_HTML
23
29ea4a29 24#ifndef WX_PRECOMP
29ea4a29
KB
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
44IMPLEMENT_CLASS(wxHelpControllerHtml, wxHTMLHelpControllerBase)
4f84c635 45
29ea4a29
KB
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
4f84c635 53#define FRAME_HEIGHT 400
29ea4a29
KB
54#define LAYOUT_X_MARGIN 2
55#define LAYOUT_Y_MARGIN 2
56#define OFFSET 10
4f84c635 57
29ea4a29
KB
58class wxHelpFrame : public wxFrame
59{
60public:
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); }
67private:
68 wxHelpControllerHtml *m_controller;
69 wxHtmlWindow *m_htmlwin;
70 DECLARE_EVENT_TABLE()
71};
72
73BEGIN_EVENT_TABLE(wxHelpFrame, wxFrame)
74 EVT_CLOSE(wxHelpFrame::OnClose)
75END_EVENT_TABLE()
76
77wxHelpFrame::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;
4f84c635 85 m_htmlwin = new wxHtmlWindow(this,-1,wxDefaultPosition,wxSize(FRAME_WIDTH,
29ea4a29 86 FRAME_HEIGHT));
4f84c635 87
29ea4a29
KB
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
100wxHelpFrame::~wxHelpFrame()
101{
102}
103
104void
105wxHelpFrame::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
120wxHelpControllerHtml::wxHelpControllerHtml(void)
121{
122 m_Frame = NULL;
123 m_offset = 0;
4f84c635 124
29ea4a29
KB
125 SetFrameParameters(_("Help"),
126 wxSize(FRAME_WIDTH, FRAME_HEIGHT),
127 wxDefaultPosition);
128}
129
130wxHelpControllerHtml::~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
143bool
144wxHelpControllerHtml::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 }
4f84c635 162
29ea4a29
KB
163 }
164 return m_Frame->LoadPage(url);
165}
166
167
168void
169wxHelpControllerHtml::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
180void
181wxHelpControllerHtml::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}
4f84c635
VZ
189
190#endif // wxUSE_HTML