]>
git.saurik.com Git - wxWidgets.git/blob - src/html/helpctrl.cpp
d093b99b731a83eca918c0f59848032f41b36238
   1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     wxHtmlHelpController 
   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". 
  13 #include "wx/wxprec.h" 
  26 #include "wx/busyinfo.h" 
  27 #include "wx/html/helpctrl.h" 
  28 #include "wx/html/helpwnd.h" 
  29 #include "wx/html/helpfrm.h" 
  30 #include "wx/html/helpdlg.h" 
  33     #include "wx/tipwin.h" 
  37 #include "wx/html/forcelnk.h" 
  38 FORCE_LINK(wxhtml_chm_support
) 
  41 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpController
, wxHelpControllerBase
) 
  43 wxHtmlHelpController::wxHtmlHelpController(int style
, wxWindow
* parentWindow
): 
  44     wxHelpControllerBase(parentWindow
) 
  51     m_ConfigRoot 
= wxEmptyString
; 
  52 #endif // wxUSE_CONFIG 
  53     m_titleFormat 
= _("Help: %s"); 
  57 wxHtmlHelpController::~wxHtmlHelpController() 
  61         WriteCustomization(m_Config
, m_ConfigRoot
); 
  62 #endif // wxUSE_CONFIG 
  68 void wxHtmlHelpController::DestroyHelpWindow() 
  70     if (m_FrameStyle 
& wxHF_EMBEDDED
) 
  73     // Find top-most parent window 
  75     wxWindow
* parent 
= FindTopLevelWindow(); 
  78         wxDialog
* dialog 
= wxDynamicCast(parent
, wxDialog
); 
  79         if (dialog 
&& dialog
->IsModal()) 
  81             dialog
->EndModal(wxID_OK
); 
  90 void wxHtmlHelpController::OnCloseFrame(wxCloseEvent
& evt
) 
  94         WriteCustomization(m_Config
, m_ConfigRoot
); 
  95 #endif // wxUSE_CONFIG 
 102         m_helpWindow
->SetController(NULL
); 
 108 void wxHtmlHelpController::SetTitleFormat(const wxString
& title
) 
 110     m_titleFormat 
= title
; 
 111     wxHtmlHelpFrame
* frame 
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpFrame
); 
 112     wxHtmlHelpDialog
* dialog 
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpDialog
); 
 115         frame
->SetTitleFormat(title
); 
 118         dialog
->SetTitleFormat(title
); 
 121 // Find the top-most parent window 
 122 wxWindow
* wxHtmlHelpController::FindTopLevelWindow() 
 124     return wxGetTopLevelParent(m_helpWindow
); 
 127 bool wxHtmlHelpController::AddBook(const wxFileName
& book_file
, bool show_wait_msg
) 
 129     return AddBook(wxFileSystem::FileNameToURL(book_file
), show_wait_msg
); 
 132 bool wxHtmlHelpController::AddBook(const wxString
& book
, bool show_wait_msg
) 
 136     wxBusyInfo
* busy 
= NULL
; 
 140         info
.Printf(_("Adding book %s"), book
.c_str()); 
 141         busy 
= new wxBusyInfo(info
); 
 144     bool retval 
= m_helpData
.AddBook(book
); 
 149     wxUnusedVar(show_wait_msg
); 
 152         m_helpWindow
->RefreshLists(); 
 156 wxHtmlHelpFrame
* wxHtmlHelpController::CreateHelpFrame(wxHtmlHelpData 
*data
) 
 158     wxHtmlHelpFrame
* frame 
= new wxHtmlHelpFrame(data
); 
 159     frame
->SetController(this); 
 160     frame
->Create(m_parentWindow
, -1, wxEmptyString
, m_FrameStyle
 
 162         , m_Config
, m_ConfigRoot
 
 163 #endif // wxUSE_CONFIG 
 165     frame
->SetTitleFormat(m_titleFormat
); 
 170 wxHtmlHelpDialog
* wxHtmlHelpController::CreateHelpDialog(wxHtmlHelpData 
*data
) 
 172     wxHtmlHelpDialog
* dialog 
= new wxHtmlHelpDialog(data
); 
 173     dialog
->SetController(this); 
 174     dialog
->SetTitleFormat(m_titleFormat
); 
 175     dialog
->Create(m_parentWindow
, -1, wxEmptyString
, m_FrameStyle
); 
 176     m_helpDialog 
= dialog
; 
 180 wxWindow
* wxHtmlHelpController::CreateHelpWindow() 
 184         if (m_FrameStyle 
& wxHF_EMBEDDED
) 
 187         wxWindow
* topLevelWindow 
= FindTopLevelWindow(); 
 189             topLevelWindow
->Raise(); 
 194     if (m_Config 
== NULL
) 
 196         m_Config 
= wxConfigBase::Get(false); 
 197         if (m_Config 
!= NULL
) 
 198             m_ConfigRoot 
= wxT("wxWindows/wxHtmlHelpController"); 
 200 #endif // wxUSE_CONFIG 
 202     if (m_FrameStyle 
& wxHF_DIALOG
) 
 204         wxHtmlHelpDialog
* dialog 
= CreateHelpDialog(&m_helpData
); 
 205         m_helpWindow 
= dialog
->GetHelpWindow(); 
 207     else if ((m_FrameStyle 
& wxHF_EMBEDDED
) && m_parentWindow
) 
 209         m_helpWindow 
= new wxHtmlHelpWindow(m_parentWindow
, -1, wxDefaultPosition
, wxDefaultSize
, 
 210             wxTAB_TRAVERSAL
|wxNO_BORDER
, m_FrameStyle
, &m_helpData
); 
 214         wxHtmlHelpFrame
* frame 
= CreateHelpFrame(&m_helpData
); 
 215         m_helpWindow 
= frame
->GetHelpWindow(); 
 223 void wxHtmlHelpController::ReadCustomization(wxConfigBase
* cfg
, const wxString
& path
) 
 225     /* should not be called by the user; call UseConfig, and the controller 
 226      * will do the rest */ 
 227     if (m_helpWindow 
&& cfg
) 
 228         m_helpWindow
->ReadCustomization(cfg
, path
); 
 231 void wxHtmlHelpController::WriteCustomization(wxConfigBase
* cfg
, const wxString
& path
) 
 233     /* typically called by the controllers OnCloseFrame handler */ 
 234     if (m_helpWindow 
&& cfg
) 
 235         m_helpWindow
->WriteCustomization(cfg
, path
); 
 238 void wxHtmlHelpController::UseConfig(wxConfigBase 
*config
, const wxString
& rootpath
) 
 241     m_ConfigRoot 
= rootpath
; 
 242     if (m_helpWindow
) m_helpWindow
->UseConfig(config
, rootpath
); 
 243     ReadCustomization(config
, rootpath
); 
 245 #endif // wxUSE_CONFIG 
 247 //// Backward compatibility with wxHelpController API 
 249 bool wxHtmlHelpController::Initialize(const wxString
& file
) 
 251     wxString dir
, filename
, ext
; 
 252     wxFileName::SplitPath(file
, & dir
, & filename
, & ext
); 
 255         dir 
= dir 
+ wxFILE_SEP_PATH
; 
 257     // Try to find a suitable file 
 258     wxString actualFilename 
= dir 
+ filename 
+ wxString(wxT(".zip")); 
 259     if (!wxFileExists(actualFilename
)) 
 261         actualFilename 
= dir 
+ filename 
+ wxString(wxT(".htb")); 
 262         if (!wxFileExists(actualFilename
)) 
 264             actualFilename 
= dir 
+ filename 
+ wxString(wxT(".hhp")); 
 265             if (!wxFileExists(actualFilename
)) 
 268                 actualFilename 
= dir 
+ filename 
+ wxString(wxT(".chm")); 
 269                 if (!wxFileExists(actualFilename
)) 
 275     return AddBook(wxFileName(actualFilename
)); 
 278 bool wxHtmlHelpController::LoadFile(const wxString
& WXUNUSED(file
)) 
 280     // Don't reload the file or we'll have it appear again, presumably. 
 284 bool wxHtmlHelpController::DisplaySection(int sectionNo
) 
 286     return Display(sectionNo
); 
 289 bool wxHtmlHelpController::DisplayTextPopup(const wxString
& text
, const wxPoint
& WXUNUSED(pos
)) 
 292     static wxTipWindow
* s_tipWindow 
= NULL
; 
 296         // Prevent s_tipWindow being nulled in OnIdle, 
 297         // thereby removing the chance for the window to be closed by ShowHelp 
 298         s_tipWindow
->SetTipWindowPtr(NULL
); 
 299         s_tipWindow
->Close(); 
 305         s_tipWindow 
= new wxTipWindow(wxTheApp
->GetTopWindow(), text
, 100, & s_tipWindow
); 
 311 #endif // wxUSE_TIPWINDOW 
 316 void wxHtmlHelpController::SetHelpWindow(wxHtmlHelpWindow
* helpWindow
) 
 318     m_helpWindow 
= helpWindow
; 
 320         helpWindow
->SetController(this); 
 323 void wxHtmlHelpController::SetFrameParameters(const wxString
& title
, 
 326                                    bool WXUNUSED(newFrameEachTime
)) 
 328     SetTitleFormat(title
); 
 329     wxHtmlHelpFrame
* frame 
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpFrame
); 
 330     wxHtmlHelpDialog
* dialog 
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpDialog
); 
 332         frame
->SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
); 
 334         dialog
->SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
); 
 337 wxFrame
* wxHtmlHelpController::GetFrameParameters(wxSize 
*size
, 
 339                                    bool *newFrameEachTime
) 
 341     if (newFrameEachTime
) 
 342         (* newFrameEachTime
) = false; 
 344     wxHtmlHelpFrame
* frame 
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpFrame
); 
 345     wxHtmlHelpDialog
* dialog 
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpDialog
); 
 349             (* size
) = frame
->GetSize(); 
 351             (* pos
) = frame
->GetPosition(); 
 357             (* size
) = dialog
->GetSize(); 
 359             (* pos
) = dialog
->GetPosition(); 
 365 bool wxHtmlHelpController::Quit() 
 371 // Make the help controller's frame 'modal' if 
 373 void wxHtmlHelpController::MakeModalIfNeeded() 
 375     if ((m_FrameStyle 
& wxHF_EMBEDDED
) == 0) 
 377         wxHtmlHelpFrame
* frame 
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpFrame
); 
 378         wxHtmlHelpDialog
* dialog 
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpDialog
); 
 380             frame
->AddGrabIfNeeded(); 
 381         else if (dialog 
&& (m_FrameStyle 
& wxHF_MODAL
)) 
 388 bool wxHtmlHelpController::Display(const wxString
& x
) 
 391     bool success 
= m_helpWindow
->Display(x
); 
 396 bool wxHtmlHelpController::Display(int id
) 
 399     bool success 
= m_helpWindow
->Display(id
); 
 404 bool wxHtmlHelpController::DisplayContents() 
 407     bool success 
= m_helpWindow
->DisplayContents(); 
 412 bool wxHtmlHelpController::DisplayIndex() 
 415     bool success 
= m_helpWindow
->DisplayIndex(); 
 420 bool wxHtmlHelpController::KeywordSearch(const wxString
& keyword
, 
 421                                          wxHelpSearchMode mode
) 
 424     bool success 
= m_helpWindow
->KeywordSearch(keyword
, mode
); 
 431  * A convenience class, to use like this: 
 433  * wxHtmlModalHelp help(parent, helpFile, topic); 
 436 wxHtmlModalHelp::wxHtmlModalHelp(wxWindow
* parent
, const wxString
& helpFile
, const wxString
& topic
, int style
) 
 438     // Force some mandatory styles 
 439     style 
|= wxHF_DIALOG 
| wxHF_MODAL
; 
 441     wxHtmlHelpController 
controller(style
, parent
); 
 442     controller
.Initialize(helpFile
); 
 445         controller
.DisplayContents(); 
 447         controller
.DisplaySection(topic
); 
 450 #endif // wxUSE_WXHTML_HELP