]>
git.saurik.com Git - wxWidgets.git/blob - src/html/helpfrm.cpp
   1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/html/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 
   8 // Copyright:   (c) Harm van der Heijden and Vaclav Slavik 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 // For compilers that support precompilation, includes "wx.h" 
  14 #include "wx/wxprec.h" 
  23     #include "wx/object.h" 
  24     #include "wx/dynarray.h" 
  28         #include "wx/stream.h" 
  33     #include "wx/bmpbuttn.h" 
  34     #include "wx/statbox.h" 
  35     #include "wx/radiobox.h" 
  37     #include "wx/settings.h" 
  38     #include "wx/msgdlg.h" 
  39     #include "wx/textctrl.h" 
  40     #include "wx/toolbar.h" 
  41     #include "wx/choicdlg.h" 
  42     #include "wx/filedlg.h" 
  45 #include "wx/html/helpfrm.h" 
  46 #include "wx/html/helpctrl.h" 
  47 #include "wx/notebook.h" 
  48 #include "wx/imaglist.h" 
  49 #include "wx/treectrl.h" 
  50 #include "wx/tokenzr.h" 
  51 #include "wx/wfstream.h" 
  52 #include "wx/html/htmlwin.h" 
  53 #include "wx/busyinfo.h" 
  54 #include "wx/progdlg.h" 
  55 #include "wx/fontenum.h" 
  56 #include "wx/artprov.h" 
  57 #include "wx/spinctrl.h" 
  59 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpFrame
, wxFrame
) 
  61 BEGIN_EVENT_TABLE(wxHtmlHelpFrame
, wxFrame
) 
  62     EVT_ACTIVATE(wxHtmlHelpFrame::OnActivate
) 
  63     EVT_CLOSE(wxHtmlHelpFrame::OnCloseWindow
) 
  65     EVT_MENU(wxID_CLOSE
, wxHtmlHelpFrame::OnClose
) 
  66     EVT_MENU(wxID_ABOUT
, wxHtmlHelpFrame::OnAbout
) 
  67     EVT_MENU(wxID_HELP_CONTENTS
, wxHtmlHelpFrame::OnAbout
) 
  71 wxHtmlHelpFrame::wxHtmlHelpFrame(wxWindow
* parent
, wxWindowID id
, const wxString
& title
, 
  72                                  int style
, wxHtmlHelpData
* data
, 
  73                                  wxConfigBase 
*config
, const wxString
& rootpath
) 
  76     Create(parent
, id
, title
, style
, config
, rootpath
); 
  79 void wxHtmlHelpFrame::Init(wxHtmlHelpData
* data
) 
  81     // Simply pass the pointer on to the help window 
  84     m_helpController 
= NULL
; 
  87 void wxHtmlHelpFrame::SetController(wxHtmlHelpController
* controller
) 
  89     m_helpController 
= controller
; 
  91         m_HtmlHelpWin
->SetController(controller
); 
  94 // Create: builds the GUI components. 
  95 bool wxHtmlHelpFrame::Create(wxWindow
* parent
, wxWindowID id
, 
  96                              const wxString
& WXUNUSED(title
), int style
, 
  97                              wxConfigBase 
*config
, const wxString
& rootpath
) 
  99     m_HtmlHelpWin 
= new wxHtmlHelpWindow(m_Data
); 
 100     m_HtmlHelpWin
->SetController(m_helpController
); 
 102         m_HtmlHelpWin
->UseConfig(config
, rootpath
); 
 104     wxFrame::Create(parent
, id
, _("Help"), 
 105                     wxPoint(m_HtmlHelpWin
->GetCfgData().x
, m_HtmlHelpWin
->GetCfgData().y
), 
 106                     wxSize(m_HtmlHelpWin
->GetCfgData().w
, m_HtmlHelpWin
->GetCfgData().h
), 
 107                     wxDEFAULT_FRAME_STYLE
, wxT("wxHtmlHelp")); 
 111     m_HtmlHelpWin
->Create(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, 
 112         wxTAB_TRAVERSAL
|wxNO_BORDER
, style
); 
 114     GetPosition(& (m_HtmlHelpWin
->GetCfgData().x
), & (m_HtmlHelpWin
->GetCfgData()).y
); 
 116     SetIcons(wxArtProvider::GetIconBundle(wxART_HELP
, wxART_FRAME_ICON
)); 
 118     // On the Mac, each modeless frame must have a menubar. 
 119     // TODO: add more menu items, and perhaps add a style to show 
 120     // the menubar: compulsory on the Mac, optional elsewhere. 
 122     wxMenuBar
* menuBar 
= new wxMenuBar
; 
 124     wxMenu
* fileMenu 
= new wxMenu
; 
 125     fileMenu
->Append(wxID_HTML_OPENFILE
, _("&Open...")); 
 126     fileMenu
->AppendSeparator(); 
 127     fileMenu
->Append(wxID_CLOSE
, _("&Close")); 
 129     wxMenu
* helpMenu 
= new wxMenu
; 
 130     helpMenu
->Append(wxID_ABOUT
, _("&About...")); 
 131     // Ensures we don't get an empty help menu 
 132     helpMenu
->Append(wxID_HELP_CONTENTS
, _("&About...")); 
 134     menuBar
->Append(fileMenu
,_("&File")); 
 135     menuBar
->Append(helpMenu
,_("&Help")); 
 139     m_HtmlHelpWin
->GetHtmlWindow()->SetRelatedFrame(this, m_TitleFormat
); 
 141     m_HtmlHelpWin
->GetHtmlWindow()->SetRelatedStatusBar(0); 
 146 wxHtmlHelpFrame::~wxHtmlHelpFrame() 
 150 void wxHtmlHelpFrame::SetTitleFormat(const wxString
& format
) 
 152     if (GetHelpWindow() && GetHelpWindow()->GetHtmlWindow()) 
 153         GetHelpWindow()->GetHtmlWindow()->SetRelatedFrame(this, format
); 
 154     m_TitleFormat 
= format
; 
 162 void wxHtmlHelpFrame::OnActivate(wxActivateEvent
& event
) 
 164     // This saves one mouse click when using the 
 165     // wxHTML for context sensitive help systems 
 167     // NB: wxActivateEvent is a bit broken in wxGTK 
 168     //     and is sometimes sent when it should not be 
 169     if (event
.GetActive() && m_HtmlHelpWin
) 
 170         m_HtmlHelpWin
->GetHtmlWindow()->SetFocus(); 
 176 void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent
& evt
) 
 180         GetSize(& (m_HtmlHelpWin
->GetCfgData().w
), &(m_HtmlHelpWin
->GetCfgData().h
)); 
 181         GetPosition(& (m_HtmlHelpWin
->GetCfgData().x
), & (m_HtmlHelpWin
->GetCfgData().y
)); 
 191     if (m_HtmlHelpWin
->GetSplitterWindow() && m_HtmlHelpWin
->GetCfgData().navig_on
) 
 192         m_HtmlHelpWin
->GetCfgData().sashpos 
= m_HtmlHelpWin
->GetSplitterWindow()->GetSashPosition(); 
 194     if (m_helpController 
&& m_helpController
->IsKindOf(CLASSINFO(wxHtmlHelpController
))) 
 196         ((wxHtmlHelpController
*) m_helpController
)->OnCloseFrame(evt
); 
 202 // Make the help controller's frame 'modal' if 
 204 void wxHtmlHelpFrame::AddGrabIfNeeded() 
 206     // So far, wxGTK only 
 208     bool needGrab 
= false; 
 210     // Check if there are any modal windows present, 
 211     // in which case we need to add a grab. 
 212     for ( wxWindowList::iterator it 
= wxTopLevelWindows
.begin(); 
 213           it 
!= wxTopLevelWindows
.end(); 
 217         wxDialog 
*dialog 
= wxDynamicCast(win
, wxDialog
); 
 219         if (dialog 
&& dialog
->IsModal()) 
 229 void wxHtmlHelpFrame::UseConfig(wxConfigBase 
*config
, const wxString
& rootPath
) 
 232         m_HtmlHelpWin
->UseConfig(config
, rootPath
); 
 236 void wxHtmlHelpFrame::OnClose(wxCommandEvent
& WXUNUSED(event
)) 
 241 void wxHtmlHelpFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
)) 
 243     wxMessageBox(wxT("wxWidgets HTML Help Viewer (c) 1998-2006, Vaclav Slavik et al"), wxT("HelpView"), 
 244         wxICON_INFORMATION
|wxOK
, this); 
 248 #endif // wxUSE_WXHTML_HELP