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
32DECLARE_LOCAL_EVENT_TYPE(wxEVT_COMMAND_MULENOTEBOOK_PAGE_CLOSING, -1)
33DECLARE_LOCAL_EVENT_TYPE(wxEVT_COMMAND_MULENOTEBOOK_ALL_PAGES_CLOSED, -1)
34
35#define EVT_MULENOTEBOOK_PAGE_CLOSING(id, fn)						\
36	DECLARE_EVENT_TABLE_ENTRY(							\
37		wxEVT_COMMAND_MULENOTEBOOK_PAGE_CLOSING,					\
38		id,									\
39		-1,									\
40		(wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn,  \
41		NULL                                                                    \
42	),
43#define EVT_MULENOTEBOOK_ALL_PAGES_CLOSED(id, fn)					\
44	DECLARE_EVENT_TABLE_ENTRY(							\
45		wxEVT_COMMAND_MULENOTEBOOK_ALL_PAGES_CLOSED,				\
46		id,									\
47		-1,									\
48		(wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn,  \
49		NULL                                                                    \
50	),
51
52
53class wxWindow;
54
55
56/**
57 * This is an NoteBook control which adds additional features above what is
58 * provided by the wxNoteBook widget. Currently it includes:
59 *  - Use of images on the tabs for closing the pages.
60 *  - A popup-menu for closing one or more pages.
61 *  - Events triggered when pages are closed.
62 */
63class CMuleNotebook : public wxNotebook
64{
65public:
66	/**
67	 * Constructor.
68	 *
69	 * @see wxNotebook::wxNotebook
70	 */
71	CMuleNotebook( wxWindow *parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = wxT("notebook") );
72
73	/**
74	 * Destructor.
75	 */
76	virtual ~CMuleNotebook();
77
78	/**
79	 * Deletes the page and triggers an event.
80	 *
81	 * @param nPage The page to be removed.
82	 */
83	virtual bool DeletePage(int nPage);
84
85	/**
86	 * Deletes and triggers and event for every page.
87	 */
88	virtual bool DeleteAllPages();
89
90
91	/**
92	 * Enables or disables the displaying of a popup-menu.
93	 *
94	 * @param enabled The new setting.
95	 */
96	void EnablePopup( bool enable );
97
98	/**
99	 * Sets an external widget to handle the popup-event.
100	 *
101	 * @param widget The widget which would recieve the event or NULL to disable.
102	 *
103	 * Setting the handler to a non-NULL pointer means that upon right-clicks, a
104	 * right click event will be sent to that widget, so that it can create a
105	 * popup-menu. The coordinates will be fixed to fit onto the specified widget,
106	 * so no mapping is needed.
107	 */
108	void SetPopupHandler( wxWindow* widget );
109
110protected:
111	/**
112	 * Event handler for left mouse button release (for closing pages)
113	 */
114	void OnMouseLeftRelease(wxMouseEvent &event);
115
116	/**
117	 * Event handler for mouse motion (for highlighting the 'x')
118	 */
119	void OnMouseMotion(wxMouseEvent &event);
120
121	/**
122	 * Event-handler for right-clicks that takes care of displaying the popup-menu.
123	 */
124	void OnRMButton(wxMouseEvent& event);
125
126	/**
127	 * Event-handler fo the Close item on the popup-menu.
128	 */
129	void OnPopupClose(wxCommandEvent& evt);
130
131	/**
132	 * Event-handler fo the CloseAll item on the popup-menu.
133	 */
134	void OnPopupCloseAll(wxCommandEvent& evt);
135
136	/**
137	 * Event-handler fo the CloseOthers item on the popup-menu.
138	 */
139	void OnPopupCloseOthers(wxCommandEvent& evt);
140
141	//! Keeps track of the popup-menu being enabled or not.
142	bool		m_popup_enable;
143
144	//! The pointer to the widget which would recieve right-click events or NULL.
145	wxWindow*	m_popup_widget;
146
147	DECLARE_EVENT_TABLE()
148};
149
150#ifdef __WXMSW__
151	#define MULE_NOTEBOOK_TAB_HEIGHT 26
152#else
153	#define MULE_NOTEBOOK_TAB_HEIGHT 40
154#endif
155
156#endif
157// File_checked_for_headers
158