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