]> git.saurik.com Git - wxWidgets.git/blobdiff - src/html/helpwnd.cpp
added length to wx(Scoped)CharBuffer to improve handling of embedded NULs
[wxWidgets.git] / src / html / helpwnd.cpp
index 0d71ff3a0ab14addf73e404d957048c5ca26ae4f..8f5d31464209079570e8664934c2a68adeac7f86 100644 (file)
@@ -19,7 +19,7 @@
 
 #if wxUSE_WXHTML_HELP
 
-#ifndef WXPRECOMP
+#ifndef WX_PRECOMP
     #include "wx/object.h"
     #include "wx/dynarray.h"
     #include "wx/intl.h"
@@ -40,7 +40,7 @@
     #include "wx/toolbar.h"
     #include "wx/choicdlg.h"
     #include "wx/filedlg.h"
-#endif // WXPRECOMP
+#endif // WX_PRECOMP
 
 #include "wx/html/helpfrm.h"
 #include "wx/html/helpdlg.h"
@@ -107,45 +107,49 @@ class wxHtmlHelpHashData : public wxObject
 
 class wxHtmlHelpHtmlWindow : public wxHtmlWindow
 {
-    public:
-        wxHtmlHelpHtmlWindow(wxHtmlHelpWindow *win, wxWindow *parent)
-            : wxHtmlWindow(parent), m_Window(win)
-        {
-            SetStandardFonts();
-        }
+public:
+    wxHtmlHelpHtmlWindow(wxHtmlHelpWindow *win, wxWindow *parent, wxWindowID id = wxID_ANY,
+                         const wxPoint& pos = wxDefaultPosition, const wxSize& sz = wxDefaultSize, long style = wxHW_DEFAULT_STYLE)
+        : wxHtmlWindow(parent, id, pos, sz, style), m_Window(win)
+    {
+        SetStandardFonts();
+    }
 
-        void OnLinkClicked(wxHtmlLinkEvent& ev)
-        {
-            const wxMouseEvent *e = ev.GetLinkInfo().GetEvent();
-            if (e == NULL || e->LeftUp())
-                m_Window->NotifyPageChanged();
-        }
+    void OnLink(wxHtmlLinkEvent& ev)
+    {
+        const wxMouseEvent *e = ev.GetLinkInfo().GetEvent();
+        if (e == NULL || e->LeftUp())
+            m_Window->NotifyPageChanged();
 
-        // Returns full location with anchor (helper)
-        static wxString GetOpenedPageWithAnchor(wxHtmlWindow *win)
-        {
-            if(!win)
-                return wxEmptyString;
+        // skip the event so that normal processing (i.e. following the link)
+        // is done:
+        ev.Skip();
+    }
 
-            wxString an = win->GetOpenedAnchor();
-            wxString pg = win->GetOpenedPage();
-            if(!an.empty())
-            {
-                pg << wxT("#");
-                pg << an;
-            }
-            return pg;
+    // Returns full location with anchor (helper)
+    static wxString GetOpenedPageWithAnchor(wxHtmlWindow *win)
+    {
+        if(!win)
+            return wxEmptyString;
+
+        wxString an = win->GetOpenedAnchor();
+        wxString pg = win->GetOpenedPage();
+        if(!an.empty())
+        {
+            pg << wxT("#") << an;
         }
+        return pg;
+    }
 
-    private:
-        wxHtmlHelpWindow *m_Window;
+private:
+    wxHtmlHelpWindow *m_Window;
 
-    DECLARE_NO_COPY_CLASS(wxHtmlHelpHtmlWindow)
+    wxDECLARE_NO_COPY_CLASS(wxHtmlHelpHtmlWindow);
     DECLARE_EVENT_TABLE()
 };
 
 BEGIN_EVENT_TABLE(wxHtmlHelpHtmlWindow, wxHtmlWindow)
-    EVT_HTML_LINK_CLICKED(wxID_ANY, wxHtmlHelpHtmlWindow::OnLinkClicked)
+    EVT_HTML_LINK_CLICKED(wxID_ANY, wxHtmlHelpHtmlWindow::OnLink)
 END_EVENT_TABLE()
 
 
@@ -293,7 +297,7 @@ void wxHtmlHelpWindow::Init(wxHtmlHelpData* data)
     m_PagesHash = NULL;
     m_UpdateContents = true;
     m_toolBar = NULL;
-    m_helpController = (wxHtmlHelpController*) NULL;
+    m_helpController = NULL;
 }
 
 // Create: builds the GUI components.
@@ -311,17 +315,6 @@ bool wxHtmlHelpWindow::Create(wxWindow* parent, wxWindowID id,
 {
     m_hfStyle = helpStyle;
 
-    wxImageList *ContentsImageList = new wxImageList(16, 16);
-    ContentsImageList->Add(wxArtProvider::GetIcon(wxART_HELP_BOOK,
-                                                  wxART_HELP_BROWSER,
-                                                  wxSize(16, 16)));
-    ContentsImageList->Add(wxArtProvider::GetIcon(wxART_HELP_FOLDER,
-                                                  wxART_HELP_BROWSER,
-                                                  wxSize(16, 16)));
-    ContentsImageList->Add(wxArtProvider::GetIcon(wxART_HELP_PAGE,
-                                                  wxART_HELP_BROWSER,
-                                                  wxSize(16, 16)));
-
     // Do the config in two steps. We read the HtmlWindow customization after we
     // create the window.
     if (m_Config)
@@ -349,6 +342,7 @@ bool wxHtmlHelpWindow::Create(wxWindow* parent, wxWindowID id,
                                            wxTB_DOCKABLE | wxTB_NODIVIDER |
                                            (helpStyle & wxHF_FLAT_TOOLBAR ? wxTB_FLAT : 0));
         toolBar->SetMargins( 2, 2 );
+        toolBar->SetToolBitmapSize( wxSize(22,22) );
         AddToolbarButtons(toolBar, helpStyle);
         toolBar->Realize();
         topWindowSizer->Add(toolBar, 0, wxEXPAND);
@@ -358,6 +352,14 @@ bool wxHtmlHelpWindow::Create(wxWindow* parent, wxWindowID id,
 
     wxSizer *navigSizer = NULL;
 
+#ifdef __WXMSW__
+    wxBorder htmlWindowBorder = GetDefaultBorder();
+    if (htmlWindowBorder == wxBORDER_SUNKEN)
+        htmlWindowBorder = wxBORDER_SIMPLE;
+#else
+    wxBorder htmlWindowBorder = wxBORDER_SIMPLE;
+#endif
+
     if (helpStyle & (wxHF_CONTENTS | wxHF_INDEX | wxHF_SEARCH))
     {
         // traditional help controller; splitter window with html page on the
@@ -366,10 +368,13 @@ bool wxHtmlHelpWindow::Create(wxWindow* parent, wxWindowID id,
 
         topWindowSizer->Add(m_Splitter, 1, wxEXPAND);
 
-        m_HtmlWin = new wxHtmlHelpHtmlWindow(this, m_Splitter);
+        m_HtmlWin = new wxHtmlHelpHtmlWindow(this, m_Splitter, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHW_DEFAULT_STYLE|htmlWindowBorder);
         m_NavigPan = new wxPanel(m_Splitter, wxID_ANY);
         m_NavigNotebook = new wxNotebook(m_NavigPan, wxID_HTML_NOTEBOOK,
                                          wxDefaultPosition, wxDefaultSize);
+#ifdef __WXMAC__
+        m_NavigNotebook->SetWindowVariant(wxWINDOW_VARIANT_SMALL);
+#endif
 
         navigSizer = new wxBoxSizer(wxVERTICAL);
         navigSizer->Add(m_NavigNotebook, 1, wxEXPAND);
@@ -379,7 +384,7 @@ bool wxHtmlHelpWindow::Create(wxWindow* parent, wxWindowID id,
     else
     {
         // only html window, no notebook with index,contents etc
-        m_HtmlWin = new wxHtmlWindow(this);
+        m_HtmlWin = new wxHtmlWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHW_DEFAULT_STYLE|htmlWindowBorder);
         topWindowSizer->Add(m_HtmlWin, 1, wxEXPAND);
     }
 
@@ -390,6 +395,9 @@ bool wxHtmlHelpWindow::Create(wxWindow* parent, wxWindowID id,
     if ( helpStyle & wxHF_CONTENTS )
     {
         wxWindow *dummy = new wxPanel(m_NavigNotebook, wxID_HTML_INDEXPAGE);
+#ifdef __WXMAC__
+        dummy->SetWindowVariant(wxWINDOW_VARIANT_NORMAL);
+#endif
         wxSizer *topsizer = new wxBoxSizer(wxVERTICAL);
 
         topsizer->Add(0, 10);
@@ -430,7 +438,7 @@ bool wxHtmlHelpWindow::Create(wxWindow* parent, wxWindowID id,
 
         m_ContentsBox = new wxTreeCtrl(dummy, wxID_HTML_TREECTRL,
                                        wxDefaultPosition, wxDefaultSize,
-#ifdef __WXGTK20__
+#if defined(__WXGTK20__) || defined(__WXMAC__)
                                        wxSUNKEN_BORDER |
                                        wxTR_HAS_BUTTONS | wxTR_HIDE_ROOT |
                                        wxTR_NO_LINES
@@ -441,6 +449,17 @@ bool wxHtmlHelpWindow::Create(wxWindow* parent, wxWindowID id,
 #endif
                                        );
 
+        wxImageList *ContentsImageList = new wxImageList(16, 16);
+        ContentsImageList->Add(wxArtProvider::GetIcon(wxART_HELP_BOOK,
+                                                      wxART_HELP_BROWSER,
+                                                      wxSize(16, 16)));
+        ContentsImageList->Add(wxArtProvider::GetIcon(wxART_HELP_FOLDER,
+                                                      wxART_HELP_BROWSER,
+                                                      wxSize(16, 16)));
+        ContentsImageList->Add(wxArtProvider::GetIcon(wxART_HELP_PAGE,
+                                                      wxART_HELP_BROWSER,
+                                                      wxSize(16, 16)));
+
         m_ContentsBox->AssignImageList(ContentsImageList);
 
         topsizer->Add(m_ContentsBox, 1,
@@ -455,6 +474,9 @@ bool wxHtmlHelpWindow::Create(wxWindow* parent, wxWindowID id,
     if ( helpStyle & wxHF_INDEX )
     {
         wxWindow *dummy = new wxPanel(m_NavigNotebook, wxID_HTML_INDEXPAGE);
+#ifdef __WXMAC__
+        dummy->SetWindowVariant(wxWINDOW_VARIANT_NORMAL);
+#endif
         wxSizer *topsizer = new wxBoxSizer(wxVERTICAL);
 
         dummy->SetSizer(topsizer);
@@ -495,6 +517,9 @@ bool wxHtmlHelpWindow::Create(wxWindow* parent, wxWindowID id,
     if ( helpStyle & wxHF_SEARCH )
     {
         wxWindow *dummy = new wxPanel(m_NavigNotebook, wxID_HTML_INDEXPAGE);
+#ifdef __WXMAC__
+        dummy->SetWindowVariant(wxWINDOW_VARIANT_NORMAL);
+#endif
         wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
 
         dummy->SetSizer(sizer);
@@ -509,7 +534,7 @@ bool wxHtmlHelpWindow::Create(wxWindow* parent, wxWindowID id,
         m_SearchWholeWords = new wxCheckBox(dummy, wxID_ANY, _("Whole words only"));
         m_SearchButton = new wxButton(dummy, wxID_HTML_SEARCHBUTTON, _("Search"));
 #if wxUSE_TOOLTIPS
-        m_SearchButton->SetToolTip(_("Search contents of help book(s) for all occurences of the text you typed above"));
+        m_SearchButton->SetToolTip(_("Search contents of help book(s) for all occurrences of the text you typed above"));
 #endif //wxUSE_TOOLTIPS
         m_SearchList = new wxListBox(dummy, wxID_HTML_SEARCHLIST,
                                      wxDefaultPosition, wxDefaultSize,
@@ -539,9 +564,12 @@ bool wxHtmlHelpWindow::Create(wxWindow* parent, wxWindowID id,
     // showtime
     if ( m_NavigPan && m_Splitter )
     {
+        // The panel will have its own min size which the splitter
+        // should respect
+        //if (m_NavigPan)
+        //    m_Splitter->SetMinimumPaneSize(m_NavigPan->GetBestSize().x);
+        //else
         m_Splitter->SetMinimumPaneSize(20);
-        if ( m_Cfg.navig_on )
-            m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
 
         if ( m_Cfg.navig_on )
         {
@@ -558,7 +586,7 @@ bool wxHtmlHelpWindow::Create(wxWindow* parent, wxWindowID id,
     // Reduce flicker by updating the splitter pane sizes before the
     // frame is shown
     wxSizeEvent sizeEvent(GetSize(), GetId());
-    ProcessEvent(sizeEvent);
+    GetEventHandler()->ProcessEvent(sizeEvent);
 
     if (m_Splitter)
         m_Splitter->UpdateSize();
@@ -568,6 +596,9 @@ bool wxHtmlHelpWindow::Create(wxWindow* parent, wxWindowID id,
 
 wxHtmlHelpWindow::~wxHtmlHelpWindow()
 {
+    if ( m_helpController )
+        m_helpController->SetHelpWindow(NULL);
+
     delete m_mergedIndex;
 
     // PopEventHandler(); // wxhtmlhelpcontroller (not any more!)
@@ -624,48 +655,28 @@ void wxHtmlHelpWindow::AddToolbarButtons(wxToolBar *toolBar, int style)
                   wxT("One or more HTML help frame toolbar bitmap could not be loaded.")) ;
 
 
-    toolBar->AddTool(wxID_HTML_PANEL, wpanelBitmap, wxNullBitmap,
-                       false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL,
-                       _("Show/hide navigation panel"));
-
+    toolBar->AddTool(wxID_HTML_PANEL, wxEmptyString, wpanelBitmap, _("Show/hide navigation panel"));
     toolBar->AddSeparator();
-    toolBar->AddTool(wxID_HTML_BACK, wbackBitmap, wxNullBitmap,
-                       false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL,
-                       _("Go back"));
-    toolBar->AddTool(wxID_HTML_FORWARD, wforwardBitmap, wxNullBitmap,
-                       false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL,
-                       _("Go forward"));
+    toolBar->AddTool(wxID_HTML_BACK, wxEmptyString, wbackBitmap, _("Go back"));
+    toolBar->AddTool(wxID_HTML_FORWARD, wxEmptyString, wforwardBitmap, _("Go forward"));
     toolBar->AddSeparator();
-
-    toolBar->AddTool(wxID_HTML_UPNODE, wupnodeBitmap, wxNullBitmap,
-                       false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL,
-                       _("Go one level up in document hierarchy"));
-    toolBar->AddTool(wxID_HTML_UP, wupBitmap, wxNullBitmap,
-                       false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL,
-                       _("Previous page"));
-    toolBar->AddTool(wxID_HTML_DOWN, wdownBitmap, wxNullBitmap,
-                       false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL,
-                       _("Next page"));
+    toolBar->AddTool(wxID_HTML_UPNODE, wxEmptyString, wupnodeBitmap, _("Go one level up in document hierarchy"));
+    toolBar->AddTool(wxID_HTML_UP, wxEmptyString, wupBitmap, _("Previous page"));
+    toolBar->AddTool(wxID_HTML_DOWN, wxEmptyString, wdownBitmap, _("Next page"));
 
     if ((style & wxHF_PRINT) || (style & wxHF_OPEN_FILES))
         toolBar->AddSeparator();
 
     if (style & wxHF_OPEN_FILES)
-        toolBar->AddTool(wxID_HTML_OPENFILE, wopenBitmap, wxNullBitmap,
-                           false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL,
-                           _("Open HTML document"));
+        toolBar->AddTool(wxID_HTML_OPENFILE, wxEmptyString, wopenBitmap, _("Open HTML document"));
 
 #if wxUSE_PRINTING_ARCHITECTURE
     if (style & wxHF_PRINT)
-        toolBar->AddTool(wxID_HTML_PRINT, wprintBitmap, wxNullBitmap,
-                           false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL,
-                           _("Print this page"));
+        toolBar->AddTool(wxID_HTML_PRINT, wxEmptyString, wprintBitmap, _("Print this page"));
 #endif
 
     toolBar->AddSeparator();
-    toolBar->AddTool(wxID_HTML_OPTIONS, woptionsBitmap, wxNullBitmap,
-                       false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL,
-                       _("Display options dialog"));
+    toolBar->AddTool(wxID_HTML_OPTIONS, wxEmptyString, woptionsBitmap, _("Display options dialog"));
 
     // Allow application to add custom buttons
     wxHtmlHelpFrame* parentFrame = wxDynamicCast(GetParent(), wxHtmlHelpFrame);
@@ -803,6 +814,8 @@ void wxHtmlHelpWindow::DisplayIndexItem(const wxHtmlHelpMergedIndexItem *it)
 bool wxHtmlHelpWindow::KeywordSearch(const wxString& keyword,
                                     wxHelpSearchMode mode)
 {
+    wxCHECK_MSG( !keyword.empty(), false, "must have a non empty keyword" );
+
     if (mode == wxHELP_SEARCH_ALL)
     {
         if ( !(m_SearchList &&
@@ -1196,16 +1209,19 @@ public:
                       wxSize(200, wxDefaultCoord),
                       0, NULL, wxCB_DROPDOWN | wxCB_READONLY));
 
-        sizer->Add(FontSize = new wxSpinCtrl(this, wxID_ANY));
-        FontSize->SetRange(2, 100);
+        sizer->Add(FontSize = new wxSpinCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition,
+                      wxDefaultSize, wxSP_ARROW_KEYS, 2, 100, 2, _T("wxSpinCtrl")));
 
         topsizer->Add(sizer, 0, wxLEFT|wxRIGHT|wxTOP, 10);
 
         topsizer->Add(new wxStaticText(this, wxID_ANY, _("Preview:")),
                         0, wxLEFT | wxTOP, 10);
+
+        topsizer->AddSpacer(5);
+
         topsizer->Add(TestWin = new wxHtmlWindow(this, wxID_ANY, wxDefaultPosition, wxSize(20, 150),
-                                                 wxHW_SCROLLBAR_AUTO | wxSUNKEN_BORDER),
-                        1, wxEXPAND | wxLEFT|wxTOP|wxRIGHT, 10);
+                                                 wxHW_SCROLLBAR_AUTO|wxBORDER_THEME),
+                        1, wxEXPAND | wxLEFT | wxRIGHT, 10);
 
         wxBoxSizer *sizer2 = new wxBoxSizer(wxHORIZONTAL);
         wxButton *ok;
@@ -1263,7 +1279,7 @@ public:
     }
 
     DECLARE_EVENT_TABLE()
-    DECLARE_NO_COPY_CLASS(wxHtmlHelpWindowOptionsDialog)
+    wxDECLARE_NO_COPY_CLASS(wxHtmlHelpWindowOptionsDialog);
 };
 
 BEGIN_EVENT_TABLE(wxHtmlHelpWindowOptionsDialog, wxDialog)