]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/helpwxht.cpp
   1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     A help controller using the wxHTML classes 
   4 // Author:      Karsten Ballueder 
   8 // Copyright:   (c) Karsten Ballueder 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  13 #   pragma implementation "helpwxht.h" 
  16 #include "wx/wxprec.h" 
  22 #if wxUSE_HTML && wxUSE_STREAMS 
  25     #include "wx/string.h" 
  29     #include "wx/layout.h" 
  30     #include "wx/combobox.h" 
  31     #include "wx/button.h" 
  34 #include "wx/helpbase.h" 
  35 #include "wx/generic/helpwxht.h" 
  36 #include "wx/html/htmlwin.h" 
  44 #if !defined(__WINDOWS__) && !defined(__OS2__) 
  48 IMPLEMENT_CLASS(wxHelpControllerHtml
, wxHTMLHelpControllerBase
) 
  51    This class implements help via wxHTML. 
  52    It requires the name of a directory containing the documentation 
  53    and a file mapping numerical Section numbers to relative URLS. 
  56 class wxForceHtmlFilter 
: public wxHtmlFilter
 
  59    virtual wxString 
ReadFile(const wxFSFile
& file
) const 
  61          wxInputStream 
*s 
= file
.GetStream(); 
  65          if (s 
== NULL
) return wxEmptyString
; 
  66          src 
= new char[s 
-> GetSize()+1]; 
  67          src
[s 
-> GetSize()] = 0; 
  68          s 
-> Read(src
, s 
-> GetSize()); 
  74     virtual bool CanRead(const wxFSFile
& file
) const 
  76          wxString filename 
= file
.GetLocation(); 
  77          if(filename
.Length() >= 5 && 
  79                filename
.Right(4).MakeUpper() == ".HTM" || 
  80                filename
.Right(5).MakeUpper() == ".HTML")) 
  87 #define FRAME_WIDTH  500 
  88 #define FRAME_HEIGHT 400 
  89 #define LAYOUT_X_MARGIN 2 
  90 #define LAYOUT_Y_MARGIN 2 
  92 #define BUTTON_WIDTH  70 
  93 #define MAX_COMBO_ENTRIES   25 
  95 class wxHelpFrame 
: public wxFrame
 
  98    wxHelpFrame(wxWindow 
*parent
, int id
, const wxString 
&title
, 
  99                const wxPoint 
&pos
, const wxSize 
&size
, 
 100                wxHelpControllerHtml 
*controller
); 
 102    void OnClose(wxCloseEvent 
&ev
); 
 103    void OnButton(wxCommandEvent 
&ev
); 
 104    bool LoadPage(const wxString 
&url
) { return m_htmlwin
->LoadPage(url
); } 
 106    wxHelpControllerHtml 
*m_controller
; 
 107    wxHtmlWindow         
*m_htmlwin
; 
 108    wxHtmlFilter         
*m_filter
; 
 110    long m_IdBack
, m_IdFwd
, m_IdContents
, m_IdCombo
, m_IdSearch
; 
 111    DECLARE_EVENT_TABLE() 
 114 BEGIN_EVENT_TABLE(wxHelpFrame
, wxFrame
) 
 115    EVT_CLOSE(wxHelpFrame::OnClose
) 
 116    EVT_BUTTON(-1, wxHelpFrame::OnButton
) 
 121 wxHelpFrame::OnButton(wxCommandEvent 
&ev
) 
 126       m_htmlwin
->HistoryBack(); 
 127    else if(id 
== m_IdFwd
) 
 128       m_htmlwin
->HistoryForward(); 
 129    else if(id 
== m_IdContents
) 
 130       m_controller
->DisplayContents(); 
 131    else if(id 
== m_IdSearch
) 
 133       wxString str 
= m_combo
->GetValue(); 
 134       if(m_combo
->FindString(str
) == -1 && m_combo
->Number() < MAX_COMBO_ENTRIES
) 
 135          m_combo
->Append(str
); 
 136       m_controller
->KeywordSearch(str
); 
 140 wxHelpFrame::wxHelpFrame(wxWindow 
*parent
, int id
, 
 141                          const wxString 
&title
, 
 142                          const wxPoint 
&pos
, const wxSize 
&size
, 
 143                          wxHelpControllerHtml 
*controller
) 
 144    : wxFrame(parent
, id
, title
, pos
, size
) 
 147    m_controller 
= controller
; 
 148    m_htmlwin 
= new wxHtmlWindow(this,-1,wxDefaultPosition
,wxSize(FRAME_WIDTH
, 
 151    m_IdBack 
= wxWindow::NewControlId(); 
 152    m_IdFwd 
= wxWindow::NewControlId(); 
 153    m_IdContents 
= wxWindow::NewControlId(); 
 154    m_IdCombo 
= wxWindow::NewControlId(); 
 155    m_IdSearch 
= wxWindow::NewControlId(); 
 157    wxButton 
*btn_back 
= new wxButton(this, m_IdBack
, _("Back")); 
 158    wxButton 
*btn_fwd 
= new wxButton(this, m_IdFwd
, _("Forward")); 
 159    wxButton 
*btn_contents 
= new wxButton(this, m_IdContents
, _("Contents")); 
 160    m_combo 
= new wxComboBox(this, m_IdCombo
); 
 161    wxButton 
*btn_search 
= new wxButton(this, m_IdSearch
, _("Search")); 
 163    m_filter 
= new wxForceHtmlFilter
; 
 165    wxLayoutConstraints 
*c
; 
 167    c 
= new wxLayoutConstraints
; 
 168    c
->left
.SameAs(this, wxLeft
, 2*LAYOUT_X_MARGIN
); 
 169    c
->width
.Absolute(BUTTON_WIDTH
); 
 170    c
->top
.SameAs(this, wxTop
, 2*LAYOUT_Y_MARGIN
); 
 172    btn_back
->SetConstraints(c
); 
 174    c 
= new wxLayoutConstraints
; 
 175    c
->left
.SameAs(btn_back
, wxRight
, 2*LAYOUT_X_MARGIN
); 
 176    c
->width
.Absolute(BUTTON_WIDTH
); 
 177    c
->top
.SameAs(this, wxTop
, 2*LAYOUT_Y_MARGIN
); 
 179    btn_fwd
->SetConstraints(c
); 
 181    c 
= new wxLayoutConstraints
; 
 182    c
->left
.SameAs(btn_fwd
, wxRight
, 2*LAYOUT_X_MARGIN
); 
 183    c
->width
.Absolute(BUTTON_WIDTH
); 
 184    c
->top
.SameAs(this, wxTop
, 2*LAYOUT_Y_MARGIN
); 
 186    btn_contents
->SetConstraints(c
); 
 188    c 
= new wxLayoutConstraints
; 
 189    c
->left
.SameAs(btn_contents
, wxRight
, 2*LAYOUT_X_MARGIN
); 
 190    c
->width
.Absolute(3*BUTTON_WIDTH
); 
 191    c
->top
.SameAs(this, wxTop
, 2*LAYOUT_Y_MARGIN
); 
 193    m_combo
->SetConstraints(c
); 
 195    c 
= new wxLayoutConstraints
; 
 196    c
->left
.SameAs(m_combo
, wxRight
, 2*LAYOUT_X_MARGIN
); 
 197    c
->width
.Absolute(BUTTON_WIDTH
); 
 198    c
->top
.SameAs(this, wxTop
, 2*LAYOUT_Y_MARGIN
); 
 200    btn_search
->SetConstraints(c
); 
 203    c 
= new wxLayoutConstraints
; 
 204    c
->left
.SameAs(this, wxLeft
, 2*LAYOUT_X_MARGIN
); 
 205    c
->right
.SameAs(this, wxRight
, 2*LAYOUT_X_MARGIN
); 
 206    c
->top
.SameAs(btn_back
, wxBottom
, 2*LAYOUT_Y_MARGIN
); 
 207    c
->bottom
.SameAs(this, wxBottom
, 2*LAYOUT_Y_MARGIN
); 
 208    m_htmlwin
->SetConstraints(c
); 
 212    m_htmlwin
->SetRelatedFrame(this, title
); 
 213    m_htmlwin
->SetRelatedStatusBar(0); 
 214    m_htmlwin
->AddFilter(m_filter
); 
 217    // Motif needs a nudge to get it to resize properly 
 219    wxSizeEvent 
event(size
, GetId()); 
 220    GetEventHandler()->ProcessEvent(event
); 
 226 wxHelpFrame::~wxHelpFrame() 
 231 wxHelpFrame::OnClose(wxCloseEvent 
&WXUNUSED(ev
)) 
 233    wxASSERT(m_controller
); 
 234    m_controller
->m_Frame 
= NULL
; 
 239    m_controller
->GetFrameParameters(NULL
, NULL
, &newFrame
); 
 240    m_controller
->SetFrameParameters(GetTitle(), GetSize(), 
 246 wxHelpControllerHtml::wxHelpControllerHtml(void) 
 251    SetFrameParameters(_("Help: %s"), 
 252                       wxSize(FRAME_WIDTH
, FRAME_HEIGHT
), 
 256 wxHelpControllerHtml::~wxHelpControllerHtml(void) 
 258    if(m_Frame 
&& ! m_NewFrameEachTime
) 
 270 wxHelpControllerHtml::DisplayHelp(const wxString 
&relativeURL
) 
 272    wxBusyCursor b
; // display a busy cursor 
 275    url 
<< m_MapFile 
<< SEP
<< relativeURL
; 
 276    if(! m_Frame 
|| m_NewFrameEachTime
) 
 278       m_Frame 
= new wxHelpFrame(NULL
, -1, m_FrameTitle
, 
 279                                 m_FramePosition
+wxPoint(m_offset
,m_offset
), 
 282       if(m_NewFrameEachTime
) 
 291    return m_Frame
->LoadPage(url
); 
 296 wxHelpControllerHtml::SetFrameParameters(const wxString 
&title
, 
 301    m_FrameTitle 
= title
; 
 303    m_FramePosition 
= pos
; 
 304    m_NewFrameEachTime 
= newFrame
; 
 308 wxHelpControllerHtml::GetFrameParameters(wxSize 
*size
, 
 312    if(size
) *size 
= m_FrameSize
; 
 313    if(pos
) *pos 
= m_FramePosition
; 
 314    if(newframe
) *newframe 
= m_NewFrameEachTime
;