1 // 2 // This file is part of the aMule Project. 3 // 4 // Copyright (c) 2004-2011 Angel Vidal ( kry@amule.org ) 5 // Copyright (c) 2004-2011 aMule Team ( admin@amule.org / http://www.amule.org ) 6 // 7 // Any parts of this program derived from the xMule, lMule or eMule project, 8 // or contributed by third-party developers are copyrighted by their 9 // respective authors. 10 // 11 // This program is free software; you can redistribute it and/or modify 12 // it under the terms of the GNU General Public License as published by 13 // the Free Software Foundation; either version 2 of the License, or 14 // (at your option) any later version. 15 // 16 // This program is distributed in the hope that it will be useful, 17 // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 // GNU General Public License for more details. 20 // 21 // You should have received a copy of the GNU General Public License 22 // along with this program; if not, write to the Free Software 23 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 24 // 25 26 #ifndef MULENOTEBOOK_H 27 #define MULENOTEBOOK_H 28 29 #include <wx/notebook.h> 30 31 #define MULE_NEEDS_DELETEPAGE_WORKAROUND wxCHECK_VERSION(3,0,2) 32 33 34 DECLARE_LOCAL_EVENT_TYPE(wxEVT_COMMAND_MULENOTEBOOK_PAGE_CLOSING, -1) 35 DECLARE_LOCAL_EVENT_TYPE(wxEVT_COMMAND_MULENOTEBOOK_ALL_PAGES_CLOSED, -1) 36 37 #if MULE_NEEDS_DELETEPAGE_WORKAROUND 38 DECLARE_LOCAL_EVENT_TYPE(wxEVT_COMMAND_MULENOTEBOOK_DELETE_PAGE, -1) 39 40 #define EVT_MULENOTEBOOK_DELETE_PAGE(id, fn) \ 41 DECLARE_EVENT_TABLE_ENTRY( \ 42 wxEVT_COMMAND_MULENOTEBOOK_DELETE_PAGE, \ 43 id, \ 44 -1, \ 45 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \ 46 NULL \ 47 ), 48 #endif // MULE_NEEDS_DELETEPAGE_WORKAROUND 49 50 #define EVT_MULENOTEBOOK_PAGE_CLOSING(id, fn) \ 51 DECLARE_EVENT_TABLE_ENTRY( \ 52 wxEVT_COMMAND_MULENOTEBOOK_PAGE_CLOSING, \ 53 id, \ 54 -1, \ 55 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \ 56 NULL \ 57 ), 58 #define EVT_MULENOTEBOOK_ALL_PAGES_CLOSED(id, fn) \ 59 DECLARE_EVENT_TABLE_ENTRY( \ 60 wxEVT_COMMAND_MULENOTEBOOK_ALL_PAGES_CLOSED, \ 61 id, \ 62 -1, \ 63 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \ 64 NULL \ 65 ), 66 67 68 class wxWindow; 69 70 71 /** 72 * This is an NoteBook control which adds additional features above what is 73 * provided by the wxNoteBook widget. Currently it includes: 74 * - Use of images on the tabs for closing the pages. 75 * - A popup-menu for closing one or more pages. 76 * - Events triggered when pages are closed. 77 */ 78 class CMuleNotebook : public wxNotebook 79 { 80 public: 81 /** 82 * Constructor. 83 * 84 * @see wxNotebook::wxNotebook 85 */ 86 CMuleNotebook( wxWindow *parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = wxT("notebook") ); 87 88 /** 89 * Destructor. 90 */ 91 virtual ~CMuleNotebook(); 92 93 /** 94 * Deletes the page and triggers an event. 95 * 96 * @param nPage The page to be removed. 97 */ 98 virtual bool DeletePage(int nPage); 99 100 /** 101 * Deletes and triggers and event for every page. 102 */ 103 virtual bool DeleteAllPages(); 104 105 106 /** 107 * Enables or disables the displaying of a popup-menu. 108 * 109 * @param enabled The new setting. 110 */ 111 void EnablePopup( bool enable ); 112 113 /** 114 * Sets an external widget to handle the popup-event. 115 * 116 * @param widget The widget which would recieve the event or NULL to disable. 117 * 118 * Setting the handler to a non-NULL pointer means that upon right-clicks, a 119 * right click event will be sent to that widget, so that it can create a 120 * popup-menu. The coordinates will be fixed to fit onto the specified widget, 121 * so no mapping is needed. 122 */ 123 void SetPopupHandler( wxWindow* widget ); 124 125 #if MULE_NEEDS_DELETEPAGE_WORKAROUND 126 private: 127 // Internal handler. Workaround for wxWidgets Tab-Crash bug. 128 void OnDeletePage(wxBookCtrlEvent& evt); 129 #endif // MULE_NEEDS_DELETEPAGE_WORKAROUND 130 131 protected: 132 /** 133 * Event handler for left or middle mouse button to press or release (for closing pages) 134 */ 135 void OnMouseButton(wxMouseEvent &event); 136 137 /** 138 * Event handler for mouse motion (for highlighting the 'x') 139 */ 140 void OnMouseMotion(wxMouseEvent &event); 141 142 /** 143 * Event-handler for right-clicks that takes care of displaying the popup-menu. 144 */ 145 void OnRMButton(wxMouseEvent& event); 146 147 /** 148 * Event-handler fo the Close item on the popup-menu. 149 */ 150 void OnPopupClose(wxCommandEvent& evt); 151 152 /** 153 * Event-handler fo the CloseAll item on the popup-menu. 154 */ 155 void OnPopupCloseAll(wxCommandEvent& evt); 156 157 /** 158 * Event-handler fo the CloseOthers item on the popup-menu. 159 */ 160 void OnPopupCloseOthers(wxCommandEvent& evt); 161 162 //! Keeps track of the popup-menu being enabled or not. 163 bool m_popup_enable; 164 165 //! The pointer to the widget which would recieve right-click events or NULL. 166 wxWindow* m_popup_widget; 167 168 DECLARE_EVENT_TABLE() 169 }; 170 171 #ifdef __WINDOWS__ 172 #define MULE_NOTEBOOK_TAB_HEIGHT 26 173 #else 174 #define MULE_NOTEBOOK_TAB_HEIGHT 40 175 #endif 176 177 #endif 178 // File_checked_for_headers 179