1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269 | //
// This file is part of the aMule Project.
//
// Copyright (c) 2004-2011 Angel Vidal ( kry@amule.org )
// Copyright (c) 2004-2011 aMule Team ( admin@amule.org / http://www.amule.org )
//
// Any parts of this program derived from the xMule, lMule or eMule project,
// or contributed by third-party developers are copyrighted by their
// respective authors.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
//
#include <wx/menu.h>
#include <wx/intl.h>
#include "MuleNotebook.h" // Interface declarations
#include <common/MenuIDs.h>
DEFINE_LOCAL_EVENT_TYPE(wxEVT_COMMAND_MULENOTEBOOK_PAGE_CLOSING)<--- There is an unknown macro here somewhere. Configuration is required. If DEFINE_LOCAL_EVENT_TYPE is a macro then please configure it.
DEFINE_LOCAL_EVENT_TYPE(wxEVT_COMMAND_MULENOTEBOOK_ALL_PAGES_CLOSED)
BEGIN_EVENT_TABLE(CMuleNotebook, wxNotebook)
EVT_RIGHT_DOWN(CMuleNotebook::OnRMButton)
EVT_MENU(MP_CLOSE_TAB, CMuleNotebook::OnPopupClose)
EVT_MENU(MP_CLOSE_ALL_TABS, CMuleNotebook::OnPopupCloseAll)
EVT_MENU(MP_CLOSE_OTHER_TABS, CMuleNotebook::OnPopupCloseOthers)
// Madcat - tab closing engine
EVT_LEFT_DOWN(CMuleNotebook::OnMouseButton)
EVT_LEFT_UP(CMuleNotebook::OnMouseButton)
EVT_MIDDLE_DOWN(CMuleNotebook::OnMouseButton)
EVT_MIDDLE_UP(CMuleNotebook::OnMouseButton)
EVT_MOTION(CMuleNotebook::OnMouseMotion)
END_EVENT_TABLE()
CMuleNotebook::CMuleNotebook( wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name )
: wxNotebook(parent, id, pos, size, style, name)
{
m_popup_enable = true;
m_popup_widget = NULL;
}
CMuleNotebook::~CMuleNotebook()
{
// Ensure that all notifications gets sent
DeleteAllPages();
}
bool CMuleNotebook::DeletePage(int nPage)
{
wxCHECK_MSG((nPage >= 0) && (nPage < (int)GetPageCount()), false,
wxT("Trying to delete invalid page-index in CMuleNotebook::DeletePage"));
// Send out close event
wxNotebookEvent evt( wxEVT_COMMAND_MULENOTEBOOK_PAGE_CLOSING, GetId(), nPage );
evt.SetEventObject(this);
ProcessEvent( evt );
// and finally remove the actual page
bool result = wxNotebook::DeletePage( nPage );
// Ensure a valid selection
if ( GetPageCount() && (int)GetSelection() >= (int)GetPageCount() ) {
SetSelection( GetPageCount() - 1 );
}
// Send a page change event to work around wx problem when newly selected page
// is identical with deleted page (wx sends a page change event during deletion,
// but the control is still the one to be deleted at that moment).
if (GetPageCount()) {
// Select the tab that took the place of the one we just deleted.
size_t page = nPage;
// Except if we deleted the last one - then select the one that is last now.
if (page == GetPageCount()) {
page--;
}
wxNotebookEvent event( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, GetId(), page );
event.SetEventObject(this);
ProcessEvent( event );
} else {
// Send an event when no pages are left open
wxNotebookEvent event( wxEVT_COMMAND_MULENOTEBOOK_ALL_PAGES_CLOSED, GetId() );
event.SetEventObject(this);
ProcessEvent( event );
}
return result;
}
bool CMuleNotebook::DeleteAllPages()
{
Freeze();
bool result = true;
while ( GetPageCount() ) {
result &= DeletePage( 0 );
}
Thaw();
return result;
}
void CMuleNotebook::EnablePopup( bool enable )
{
m_popup_enable = enable;
}
void CMuleNotebook::SetPopupHandler( wxWindow* widget )
{
m_popup_widget = widget;
}
//#warning wxMac does not support selection by right-clicking on tabs!
void CMuleNotebook::OnRMButton(wxMouseEvent& event)
{
// Cases where we shouldn't be showing a popup-menu.
if ( !GetPageCount() || !m_popup_enable ) {
event.Skip();
return;
}
// For some reason, gtk1 does a rather poor job when using the HitTest
wxPoint eventPoint = event.GetPosition();
int tab = HitTest(eventPoint);
if (tab != wxNOT_FOUND) {
SetSelection(tab);
} else {
event.Skip();
return;
}
// Should we send the event to a specific widget?
if ( m_popup_widget ) {
wxMouseEvent evt = event;
// Map the coordinates onto the parent
wxPoint point = evt.GetPosition();
point = ClientToScreen( point );
point = m_popup_widget->ScreenToClient( point );
evt.m_x = point.x;
evt.m_y = point.y;
m_popup_widget->GetEventHandler()->AddPendingEvent( evt );
} else {
wxMenu menu(_("Close"));
menu.Append(MP_CLOSE_TAB, wxString(_("Close tab")));
menu.Append(MP_CLOSE_ALL_TABS, wxString(_("Close all tabs")));
menu.Append(MP_CLOSE_OTHER_TABS, wxString(_("Close other tabs")));
PopupMenu( &menu, event.GetPosition() );
}
}
void CMuleNotebook::OnPopupClose(wxCommandEvent& WXUNUSED(evt))
{
DeletePage( GetSelection() );
}
void CMuleNotebook::OnPopupCloseAll(wxCommandEvent& WXUNUSED(evt))
{
DeleteAllPages();
}
void CMuleNotebook::OnPopupCloseOthers(wxCommandEvent& WXUNUSED(evt))
{
wxNotebookPage* current = GetPage( GetSelection() );
for ( int i = GetPageCount() - 1; i >= 0; i-- ) {
if ( current != GetPage( i ) )
DeletePage( i );
}
}
void CMuleNotebook::OnMouseButton(wxMouseEvent &event)
{
if (GetImageList() == NULL) {
// This Mulenotebook has no images on tabs, so nothing to do.
event.Skip();
return;
}
long xpos, ypos;
event.GetPosition(&xpos, &ypos);
long flags = 0;
int tab = HitTest(wxPoint(xpos,ypos),&flags);
static int tab_down_icon = -1;
static int tab_down_label = -1;
if (event.LeftDown() && (flags == wxNB_HITTEST_ONICON)) {
tab_down_icon = tab;
}
else if (event.MiddleDown() && (flags == wxNB_HITTEST_ONLABEL)) {
tab_down_label = tab;
}
else if (event.LeftDown() || event.MiddleDown()) {
tab_down_icon = -1;
tab_down_label = -1;
}
if (((tab != -1) && (((flags == wxNB_HITTEST_ONICON) && event.LeftUp() && (tab == tab_down_icon)) ||
((flags == wxNB_HITTEST_ONLABEL) && event.MiddleUp() && (tab == tab_down_label))))) {
// User did click on a 'x' or middle click on the label
tab_down_icon = -1;
tab_down_label = -1;
DeletePage(tab);
} else {
// Is not a 'x'. Send this event up.
event.Skip();
}
}
void CMuleNotebook::OnMouseMotion(wxMouseEvent &event)
{
if (GetImageList() == NULL) {
// This Mulenotebook has no images on tabs, so nothing to do.
event.Skip();
return;
}
long flags = 0;
int tab = HitTest(wxPoint(event.m_x,event.m_y),&flags);
// Clear the highlight for all tabs.
for (int i=0;i<(int)GetPageCount();++i) {
SetPageImage(i, 0);
}
if ((tab != -1) && (flags == wxNB_HITTEST_ONICON)) {
// Mouse is over a 'x'
SetPageImage(tab, 1);
} else {
// Is not a 'x'. Send this event up.
event.Skip();
}
}
// File_checked_for_headers
|