2
#include "cl_aui_notebook_art.h"
3
#include "drawingutils.h"
4
#include <wx/xrc/xmlres.h>
5
#include <wx/choicebk.h>
6
#include <wx/notebook.h>
7
#include "notebook_ex_nav_dlg.h"
8
#include "notebook_ex.h"
12
#include <wx/wupdlock.h>
15
# include <wx/button.h>
16
# include <wx/imaglist.h>
17
# include <wx/image.h>
18
#elif defined(__WXGTK__)
20
# include <wx/imaglist.h>
23
const wxEventType wxEVT_COMMAND_BOOK_PAGE_CHANGED = XRCID("notebook_page_changing");
24
const wxEventType wxEVT_COMMAND_BOOK_PAGE_CHANGING = XRCID("notebook_page_changed");
25
const wxEventType wxEVT_COMMAND_BOOK_PAGE_CLOSING = XRCID("notebook_page_closing");
26
const wxEventType wxEVT_COMMAND_BOOK_PAGE_CLOSED = XRCID("notebook_page_closed");
27
const wxEventType wxEVT_COMMAND_BOOK_PAGE_MIDDLE_CLICKED = XRCID("notebook_page_middle_clicked");
28
const wxEventType wxEVT_COMMAND_BOOK_PAGE_X_CLICKED = XRCID("notebook_page_x_btn_clicked");
29
const wxEventType wxEVT_COMMAND_BOOK_BG_DCLICK = XRCID("notebook_page_bg_dclick");
31
#define SHOW_POPUP_MENU 1234534
34
#define X_IMG_NORMAL 0
35
#define X_IMG_PRESSED 1
36
#define X_IMG_DISABLED 2
38
Notebook::Notebook(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, long style)
39
: wxAuiNotebook(parent, id, pos, size, style | wxNO_BORDER | wxAUI_NB_TAB_MOVE | wxAUI_NB_TAB_SPLIT)
43
, m_leftDownTabIdx(npos)
48
m_leftDownPos = wxPoint();
51
Connect(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, wxAuiNotebookEventHandler(Notebook::OnInternalPageChanged), NULL, this);
52
Connect(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, wxAuiNotebookEventHandler(Notebook::OnInternalPageChanging), NULL, this);
53
Connect(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSED, wxAuiNotebookEventHandler(Notebook::OnInternalPageClosed), NULL, this);
54
Connect(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE, wxAuiNotebookEventHandler(Notebook::OnInternalPageClosing), NULL, this);
55
Connect(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_DOWN, wxAuiNotebookEventHandler(Notebook::OnTabMiddle), NULL, this);
56
Connect(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_DOWN, wxAuiNotebookEventHandler(Notebook::OnTabRightDown), NULL, this);
57
Connect(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_UP, wxAuiNotebookEventHandler(Notebook::OnTabRightUp), NULL, this);
58
Connect(wxEVT_COMMAND_AUINOTEBOOK_BG_DCLICK, wxAuiNotebookEventHandler(Notebook::OnBgDclick), NULL, this);
61
Connect(wxEVT_SET_FOCUS, wxFocusEventHandler(Notebook::OnFocus), NULL, this);
63
Connect(wxEVT_NAVIGATION_KEY, wxNavigationKeyEventHandler(Notebook::OnNavigationKey), NULL, this);
64
Connect(SHOW_POPUP_MENU, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(Notebook::OnInternalMenu), NULL, this);
66
// On Linux, we disable the transparent drag since it will lead to crash when used with compiz / KDE4
67
#if defined (__WXGTK__) && defined (__WXDEBUG__)
68
m_mgr.SetFlags(wxAUI_MGR_ALLOW_FLOATING|wxAUI_MGR_ALLOW_ACTIVE_PANE|wxAUI_MGR_TRANSPARENT_DRAG|wxAUI_MGR_RECTANGLE_HINT);
70
#elif defined(__WXGTK__)
71
m_mgr.SetFlags((m_mgr.GetFlags() | wxAUI_MGR_VENETIAN_BLINDS_HINT) & ~wxAUI_MGR_TRANSPARENT_HINT);
75
SetArtProvider(new clAuiTabArt());
80
Disconnect(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, wxAuiNotebookEventHandler(Notebook::OnInternalPageChanged), NULL, this);
81
Disconnect(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, wxAuiNotebookEventHandler(Notebook::OnInternalPageChanging), NULL, this);
82
Disconnect(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSED, wxAuiNotebookEventHandler(Notebook::OnInternalPageClosed), NULL, this);
83
Disconnect(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE, wxAuiNotebookEventHandler(Notebook::OnInternalPageClosing), NULL, this);
84
Disconnect(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_DOWN, wxAuiNotebookEventHandler(Notebook::OnTabMiddle), NULL, this);
85
Disconnect(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_DOWN, wxAuiNotebookEventHandler(Notebook::OnTabRightDown), NULL, this);
86
Disconnect(wxEVT_COMMAND_AUINOTEBOOK_BG_DCLICK, wxAuiNotebookEventHandler(Notebook::OnBgDclick), NULL, this);
87
Disconnect(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_UP, wxAuiNotebookEventHandler(Notebook::OnTabRightUp), NULL, this);
89
Disconnect(wxEVT_NAVIGATION_KEY, wxNavigationKeyEventHandler(Notebook::OnNavigationKey), NULL, this);
91
Disconnect(wxEVT_SET_FOCUS, wxFocusEventHandler(Notebook::OnFocus), NULL, this);
93
Disconnect(SHOW_POPUP_MENU, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(Notebook::OnInternalMenu), NULL, this);
96
bool Notebook::AddPage(wxWindow *win, const wxString &text, bool selected, const wxBitmap& bmp)
98
wxWindowUpdateLocker locker(this);
100
if(wxAuiNotebook::InsertPage(GetPageCount(), win, text, selected, bmp)){
101
win->Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(Notebook::OnKeyDown), NULL, this);
102
PushPageHistory(win);
108
bool Notebook::InsertPage(size_t index, wxWindow* win, const wxString& text, bool selected, const wxBitmap &bmp)
111
if(wxAuiNotebook::InsertPage(index, win, text, selected, bmp)){
112
win->Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(Notebook::OnKeyDown), NULL, this);
113
PushPageHistory(win);
120
void Notebook::Initialize()
124
void Notebook::SetSelection(size_t page, bool notify)
126
if (page >= GetPageCount())
130
wxAuiNotebook::SetSelection(page);
133
PushPageHistory(GetPage(page));
136
size_t Notebook::GetSelection()
138
return static_cast<size_t>(wxAuiNotebook::GetSelection());
141
wxWindow* Notebook::GetPage(size_t page)
143
if (page >= GetPageCount())
146
return wxAuiNotebook::GetPage(page);
149
bool Notebook::RemovePage(size_t page, bool notify)
152
//send event to noitfy that the page has changed
153
NotebookEvent event(wxEVT_COMMAND_BOOK_PAGE_CLOSING, GetId());
154
event.SetSelection( page );
155
event.SetEventObject( this );
156
GetEventHandler()->ProcessEvent(event);
158
if (!event.IsAllowed()) {
163
wxWindow* win = GetPage(page);
164
win->Disconnect(wxEVT_KEY_DOWN, wxKeyEventHandler(Notebook::OnKeyDown), NULL, this);
166
bool rc = wxAuiNotebook::RemovePage(page);
172
//send event to noitfy that the page has been closed
173
NotebookEvent event(wxEVT_COMMAND_BOOK_PAGE_CLOSED, GetId());
174
event.SetSelection( page );
175
event.SetEventObject( this );
176
GetEventHandler()->AddPendingEvent(event);
182
bool Notebook::DeletePage(size_t page, bool notify)
184
if (page >= GetPageCount())
188
//send event to noitfy that the page has changed
189
NotebookEvent event(wxEVT_COMMAND_BOOK_PAGE_CLOSING, GetId());
190
event.SetSelection( page );
191
event.SetEventObject( this );
192
GetEventHandler()->ProcessEvent(event);
194
if (!event.IsAllowed()) {
199
wxWindow* win = GetPage(page);
200
win->Disconnect(wxEVT_KEY_DOWN, wxKeyEventHandler(Notebook::OnKeyDown), NULL, this);
202
bool rc = wxAuiNotebook::DeletePage(page);
208
//send event to noitfy that the page has been closed
209
NotebookEvent event(wxEVT_COMMAND_BOOK_PAGE_CLOSED, GetId());
210
event.SetSelection( page );
211
event.SetEventObject( this );
212
GetEventHandler()->ProcessEvent(event);
219
wxString Notebook::GetPageText(size_t page) const
221
if (page >= GetPageCount())
224
return wxAuiNotebook::GetPageText(page);
227
void Notebook::OnNavigationKey(wxNavigationKeyEvent &e)
229
if ( e.IsWindowChange() ) {
236
const wxArrayPtrVoid& Notebook::GetHistory() const
241
void Notebook::SetRightClickMenu(wxMenu* menu)
243
m_contextMenu = menu;
246
wxWindow* Notebook::GetCurrentPage()
248
size_t selection = GetSelection();
249
if (selection != Notebook::npos) {
250
return GetPage(selection);
255
size_t Notebook::GetPageIndex(wxWindow *page)
258
return Notebook::npos;
260
for (size_t i=0; i< GetPageCount(); i++) {
261
if (GetPage(i) == page) {
265
return Notebook::npos;
268
size_t Notebook::GetPageIndex(const wxString& text)
270
for (size_t i=0; i< GetPageCount(); i++) {
272
if (GetPageText(i) == text) {
276
return Notebook::npos;
279
bool Notebook::SetPageText(size_t index, const wxString &text)
281
if (index >= GetPageCount())
283
return wxAuiNotebook::SetPageText(index, text);
286
bool Notebook::DeleteAllPages(bool notify)
289
size_t count = GetPageCount();
290
for (size_t i=0; i<count && res; i++) {
291
res = this->DeletePage(0, notify);
296
void Notebook::PushPageHistory(wxWindow *page)
301
int where = m_history.Index(page);
302
//remove old entry of this page and re-insert it as first
303
if (where != wxNOT_FOUND) {
304
m_history.Remove(page);
306
m_history.Insert(page, 0);
309
void Notebook::PopPageHistory(wxWindow *page)
314
int where = m_history.Index(page);
315
while (where != wxNOT_FOUND) {
316
wxWindow *tab = static_cast<wxWindow *>(m_history.Item(where));
317
m_history.Remove(tab);
319
//remove all appearances of this page
320
where = m_history.Index(page);
324
wxWindow* Notebook::GetPreviousSelection()
326
if (m_history.empty()) {
329
//return the top of the heap
330
return static_cast<wxWindow*>( m_history.Item(0));
333
void Notebook::OnInternalPageChanged(wxAuiNotebookEvent &e)
335
DoPageChangedEvent(e);
338
void Notebook::OnInternalPageChanging(wxAuiNotebookEvent &e)
340
DoPageChangingEvent(e);
343
void Notebook::DoPageChangedEvent(wxAuiNotebookEvent& e)
350
//send event to noitfy that the page is changing
351
NotebookEvent event(wxEVT_COMMAND_BOOK_PAGE_CHANGED, GetId());
352
event.SetSelection ( e.GetSelection() );
353
event.SetOldSelection( e.GetOldSelection() );
354
event.SetEventObject ( this );
355
GetEventHandler()->AddPendingEvent(event);
357
PushPageHistory( GetPage(e.GetSelection()) );
361
void Notebook::DoPageChangingEvent(wxAuiNotebookEvent& e)
368
//send event to noitfy that the page is changing
369
NotebookEvent event(wxEVT_COMMAND_BOOK_PAGE_CHANGING, GetId());
370
event.SetSelection ( e.GetSelection() );
371
event.SetOldSelection( e.GetOldSelection() );
372
event.SetEventObject ( this );
373
GetEventHandler()->ProcessEvent(event);
375
if ( !event.IsAllowed() ) {
381
void Notebook::OnKeyDown(wxKeyEvent& e)
383
if (e.GetKeyCode() == WXK_TAB && e.m_controlDown ) {
392
bool Notebook::DoNavigate()
394
if ( !m_popupWin && GetPageCount() > 1) {
396
m_popupWin = new NotebookNavDialog( this );
397
m_popupWin->ShowModal();
399
wxWindow *page = m_popupWin->GetSelection();
400
m_popupWin->Destroy();
403
SetSelection( GetPageIndex(page), true );
411
void Notebook::OnFocus(wxFocusEvent& e)
413
if( m_style & wxVB_PASS_FOCUS) {
414
wxWindow *w = GetCurrentPage();
422
void Notebook::OnInternalPageClosing(wxAuiNotebookEvent& e)
426
NotebookEvent event(wxEVT_COMMAND_BOOK_PAGE_CLOSING, GetId());
427
event.SetSelection( (int)GetSelection() );
428
event.SetEventObject( this );
429
GetEventHandler()->ProcessEvent(event);
431
if (!event.IsAllowed()) {
435
// This page is likely to be removed, remove it from the history
436
PopPageHistory( GetPage( static_cast<size_t>( GetSelection() ) ) );
440
void Notebook::OnInternalPageClosed(wxAuiNotebookEvent& e)
444
NotebookEvent event(wxEVT_COMMAND_BOOK_PAGE_CLOSED, GetId());
445
event.SetSelection( (int) GetSelection() );
446
event.SetEventObject( this );
447
GetEventHandler()->AddPendingEvent(event);
451
void Notebook::OnTabMiddle(wxAuiNotebookEvent& e)
453
if (e.GetSelection() != wxNOT_FOUND && HasCloseMiddle()) {
454
//send event to noitfy that the page is changing
455
NotebookEvent event(wxEVT_COMMAND_BOOK_PAGE_MIDDLE_CLICKED, GetId());
456
event.SetSelection ( e.GetSelection() );
457
event.SetOldSelection( wxNOT_FOUND );
458
event.SetEventObject ( this );
459
GetEventHandler()->AddPendingEvent(event);
463
void Notebook::OnTabRightDown(wxAuiNotebookEvent& e)
467
int where = e.GetSelection();
468
if(where != wxNOT_FOUND && where == static_cast<int>(GetSelection())) {
470
PopupMenu(m_contextMenu);
484
void Notebook::OnInternalMenu(wxCommandEvent& e)
487
PopupMenu(m_contextMenu);
491
void Notebook::OnBgDclick(wxAuiNotebookEvent& e)
493
NotebookEvent event(wxEVT_COMMAND_BOOK_BG_DCLICK, GetId());
494
event.SetSelection ( wxNOT_FOUND );
495
event.SetOldSelection( wxNOT_FOUND );
496
event.SetEventObject ( this );
497
GetEventHandler()->AddPendingEvent(event);
500
void Notebook::OnTabRightUp(wxAuiNotebookEvent& e)