1 /* 2 3 Copyright (C) 2003 - 2013 Razvan Cojocaru <rzvncj@gmail.com> 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 2 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 18 MA 02110-1301, USA. 19 20 */ 21 22 23 #ifndef __CHMHTMLWINDOW_H_ 24 #define __CHMHTMLWINDOW_H_ 25 26 27 #include <wx/html/htmlwin.h> 28 #include <wx/treectrl.h> 29 #include <wx/menu.h> 30 #include <wx/notebook.h> 31 #include <chmfinddialog.h> 32 33 34 35 //! Event IDs. 36 enum { 37 ID_CopySel = 1216, 38 ID_CopyLink, 39 ID_SaveLinkAs, 40 ID_PopupForward, 41 ID_PopupBack, 42 ID_PopupFind, 43 ID_PopupFullScreen, 44 ID_OpenInNewTab, 45 }; 46 47 48 //! Minimize dependencies. Forward declaration. 49 class CHMFrame; 50 51 52 /*! 53 \class wxHtmlWindow 54 \brief wxWidgets HTML widget class. 55 */ 56 57 58 /*! 59 \brief Custom HTML widget class. Needed for sychnronization between 60 the topics tree control and the currently displayed page. 61 */ 62 class CHMHtmlWindow : public wxHtmlWindow { 63 64 public: 65 /*! 66 \brief Initializes the widget. 67 \param parent The parent widget. 68 \param tc Pointer to the tree control we want to synchronize 69 with. 70 \param frame Outer frame. 71 */ 72 CHMHtmlWindow(wxWindow *parent, wxTreeCtrl *tc, CHMFrame* frame); 73 74 //! Destructor. Deletes heap objects allocated in the constructor. 75 ~CHMHtmlWindow(); 76 virtual void OnSetTitle(const wxString& title); 77 //! Override. Looks up the wanted page in the tree and selects it. 78 bool LoadPage(const wxString& location); 79 80 /*! 81 \brief Dictates the behaviour of LoadPage(). If SetSync() 82 has been called with a true parameter, the tree control will 83 be updated by LoadPage(). Otherwise, it will not be updated. 84 \param value Synchronize the tree widget on load? 85 */ SetSync(bool value)86 void SetSync(bool value) { _syncTree = value; } 87 88 /*! 89 Returns true if the tree control's EVT_TREE_SEL_CHANGED 90 event happened as a result of the CHMHtmlWindow calling 91 SelectItem() on it. 92 */ IsCaller()93 bool IsCaller() const { return _found; } 94 95 public: 96 /*! 97 \brief Finds the first occurence of word in the displayed page. 98 \param parent Root of the wxHtmlCell tree where the search should 99 begin. 100 \param word The word we're looking for. If more words separated 101 by spaces are typed in, only the first one is taken into 102 account. 103 \param wholeWords If true, will search for words that match 104 word exactly. 105 \param caseSensitive If true, the search will be performed 106 case sensitive. 107 \return A valid cell if the result was found, NULL otherwise. 108 */ 109 wxHtmlCell* FindFirst(wxHtmlCell* parent, const wxString& word, 110 bool wholeWords, bool caseSensitive); 111 112 /*! 113 \brief Same as FindFirst(), but continues the search from start 114 (start is considered in the search process). 115 */ 116 wxHtmlCell* FindNext(wxHtmlCell *start, 117 const wxString& word, bool wholeWords, 118 bool caseSensitive); 119 120 //! Clears the current selection. 121 void ClearSelection(); 122 123 // Needs to be public, cause I call it from CHMHtmlFrame. 124 //! Called when the user selects 'Find' from the popup menu. 125 void OnFind(wxCommandEvent& event); 126 127 //! Called when the user selects 'Copy' from the popup menu. 128 void OnCopy(wxCommandEvent& event); 129 130 protected: 131 //! Called when the user selects 'Forward' from the popup menu. 132 void OnForward(wxCommandEvent& event); 133 134 //! Called when the user selects 'Back' from the popup menu. 135 void OnBack(wxCommandEvent& event); 136 137 //! Called when the user selects 'Copy link' from the popup menu. 138 void OnCopyLink(wxCommandEvent& event); 139 140 //! Called when the user selects 'Save link as' from the popup menu. 141 void OnSaveLinkAs(wxCommandEvent& event); 142 143 //! Called when the user presses a key 144 void OnChar(wxKeyEvent &event); 145 146 //! Called on widget resize. 147 void OnSize(wxSizeEvent& event); 148 149 //! Called when the user selects 'Save link as' from the popup menu. 150 void OnOpenInNewTab(wxCommandEvent& event); 151 152 //! Called when the 'Toggle fullscreen' is selected from the popup menu. 153 void OnToggleFullScreen(wxCommandEvent& event); 154 155 protected: 156 //! Called when the user right clicks the HTML window. 157 void OnRightClick(wxMouseEvent& event); 158 159 //! Overridden. Called when the user clicks on a link. 160 void OnLinkClicked(const wxHtmlLinkInfo& link); 161 162 private: 163 //! Helper. Recursively looks for the opened page in the tree. 164 void Sync(wxTreeItemId root, const wxString& page); 165 166 //! Helper. Returns the prefix of the currently loaded page. 167 wxString GetPrefix(const wxString& location) const; 168 169 private: 170 wxTreeCtrl *_tcl; 171 bool _syncTree; 172 bool _found; 173 wxMenu *_menu; 174 CHMFrame *_frame; 175 wxString _link; 176 CHMFindDialog* _fdlg; 177 178 private: 179 DECLARE_EVENT_TABLE() 180 }; 181 182 183 184 #endif // __CHMHTMLWINDOW_H_ 185 186 187 /* 188 Local Variables: 189 mode: c++ 190 c-basic-offset: 8 191 tab-width: 8 192 c-indent-comments-syntactically-p: t 193 c-tab-always-indent: t 194 indent-tabs-mode: t 195 End: 196 */ 197 198 // vim:shiftwidth=8:autoindent:tabstop=8:noexpandtab:softtabstop=8 199 200