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 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696
|
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright : (C) 2014 The CodeLite Team
// file name : notebook_ex.cpp
//
// -------------------------------------------------------------------------
// A
// _____ _ _ _ _
// / __ \ | | | | (_) |
// | / \/ ___ __| | ___| | _| |_ ___
// | | / _ \ / _ |/ _ \ | | | __/ _ )
// | \__/\ (_) | (_| | __/ |___| | || __/
// \____/\___/ \__,_|\___\_____/_|\__\___|
//
// F i l e
//
// 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.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
#include "cl_defs.h"
#if !CL_USE_NATIVEBOOK
#include <wx/app.h>
#include "cl_aui_notebook_art.h"
#include "drawingutils.h"
#include <wx/xrc/xmlres.h>
#include "editor_config.h"
#include <wx/choicebk.h>
#include <wx/notebook.h>
#include "notebook_ex_nav_dlg.h"
#include "notebook_ex.h"
#include <wx/button.h>
#include "wx/sizer.h"
#include <wx/log.h>
#include <wx/wupdlock.h>
#include <set>
#ifdef __WXMSW__
# include <wx/button.h>
# include <wx/imaglist.h>
# include <wx/image.h>
#elif defined(__WXGTK__)
# include <wx/imaglist.h>
#endif
const wxEventType wxEVT_COMMAND_BOOK_PAGE_CHANGING = XRCID("notebook_page_changing");
const wxEventType wxEVT_COMMAND_BOOK_PAGE_CHANGED = XRCID("notebook_page_changed");
const wxEventType wxEVT_COMMAND_BOOK_PAGE_CLOSING = XRCID("notebook_page_closing");
const wxEventType wxEVT_COMMAND_BOOK_PAGE_CLOSED = XRCID("notebook_page_closed");
const wxEventType wxEVT_COMMAND_BOOK_PAGE_MIDDLE_CLICKED = XRCID("notebook_page_middle_clicked");
const wxEventType wxEVT_COMMAND_BOOK_PAGE_X_CLICKED = XRCID("notebook_page_x_btn_clicked");
const wxEventType wxEVT_COMMAND_BOOK_BG_DCLICK = XRCID("notebook_page_bg_dclick");
#define SHOW_POPUP_MENU 1234534
#define X_IMG_NONE -1
#define X_IMG_NORMAL 0
#define X_IMG_PRESSED 1
#define X_IMG_DISABLED 2
#define CHECK_OWNERSHIP(e) {\
if(e.GetEventObject() != this) {\
e.Skip();\
return;\
}\
}
Notebook::Notebook(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, long style)
: wxAuiNotebook(parent, id, pos, size, style | wxNO_BORDER | wxAUI_NB_TAB_MOVE | wxAUI_NB_TAB_SPLIT)
, m_popupWin(NULL)
, m_contextMenu(NULL)
, m_style(style)
, m_leftDownTabIdx(npos)
, m_notify (true)
{
Initialize();
m_leftDownPos = wxPoint();
// Connect events
Connect(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, wxAuiNotebookEventHandler(Notebook::OnInternalPageChanged), NULL, this);
Connect(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, wxAuiNotebookEventHandler(Notebook::OnInternalPageChanging), NULL, this);
Connect(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSED, wxAuiNotebookEventHandler(Notebook::OnInternalPageClosed), NULL, this);
Connect(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE, wxAuiNotebookEventHandler(Notebook::OnInternalPageClosing), NULL, this);
Connect(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_DOWN, wxAuiNotebookEventHandler(Notebook::OnTabMiddle), NULL, this);
Connect(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_DOWN, wxAuiNotebookEventHandler(Notebook::OnTabRightDown), NULL, this);
Connect(wxEVT_COMMAND_AUINOTEBOOK_BUTTON, wxAuiNotebookEventHandler(Notebook::OnTabButton), NULL, this);
Connect(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_UP, wxAuiNotebookEventHandler(Notebook::OnTabRightUp), NULL, this);
Connect(wxEVT_COMMAND_AUINOTEBOOK_BG_DCLICK, wxAuiNotebookEventHandler(Notebook::OnBgDclick), NULL, this);
Connect(wxEVT_COMMAND_AUINOTEBOOK_END_DRAG, wxAuiNotebookEventHandler(Notebook::OnEndDrag), NULL, this);
#ifdef __WXMSW__
Connect(wxEVT_SET_FOCUS, wxFocusEventHandler(Notebook::OnFocus), NULL, this);
#endif
Connect(wxEVT_NAVIGATION_KEY, wxNavigationKeyEventHandler(Notebook::OnNavigationKey), NULL, this);
Connect(SHOW_POPUP_MENU, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(Notebook::OnInternalMenu), NULL, this);
// On Linux, we disable the transparent drag since it will lead to crash when used with compiz / KDE4
#if defined (__WXGTK__) && defined (__WXDEBUG__)
m_mgr.SetFlags(wxAUI_MGR_ALLOW_FLOATING|wxAUI_MGR_ALLOW_ACTIVE_PANE|wxAUI_MGR_TRANSPARENT_DRAG|wxAUI_MGR_RECTANGLE_HINT);
#elif defined(__WXGTK__)
m_mgr.SetFlags((m_mgr.GetFlags() | wxAUI_MGR_VENETIAN_BLINDS_HINT) & ~wxAUI_MGR_TRANSPARENT_HINT);
#endif //
// Set the notebook theme
wxAuiTabArt *artProvider;
size_t flags = EditorConfigST::Get()->GetOptions()->GetOptions();
if(flags & OptionsConfig::TabCurved) {
artProvider = new wxAuiSimpleTabArt;
} else {
artProvider = new clAuiGlossyTabArt;
}
SetArtProvider(artProvider);
}
Notebook::~Notebook()
{
Disconnect(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, wxAuiNotebookEventHandler(Notebook::OnInternalPageChanged), NULL, this);
Disconnect(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, wxAuiNotebookEventHandler(Notebook::OnInternalPageChanging), NULL, this);
Disconnect(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSED, wxAuiNotebookEventHandler(Notebook::OnInternalPageClosed), NULL, this);
Disconnect(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE, wxAuiNotebookEventHandler(Notebook::OnInternalPageClosing), NULL, this);
Disconnect(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_DOWN, wxAuiNotebookEventHandler(Notebook::OnTabMiddle), NULL, this);
Disconnect(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_DOWN, wxAuiNotebookEventHandler(Notebook::OnTabRightDown), NULL, this);
Disconnect(wxEVT_COMMAND_AUINOTEBOOK_BG_DCLICK, wxAuiNotebookEventHandler(Notebook::OnBgDclick), NULL, this);
Disconnect(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_UP, wxAuiNotebookEventHandler(Notebook::OnTabRightUp), NULL, this);
Disconnect(wxEVT_COMMAND_AUINOTEBOOK_END_DRAG, wxAuiNotebookEventHandler(Notebook::OnEndDrag), NULL, this);
Disconnect(wxEVT_NAVIGATION_KEY, wxNavigationKeyEventHandler(Notebook::OnNavigationKey), NULL, this);
#ifdef __WXMSW__
Disconnect(wxEVT_SET_FOCUS, wxFocusEventHandler(Notebook::OnFocus), NULL, this);
#endif
Disconnect(SHOW_POPUP_MENU, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(Notebook::OnInternalMenu), NULL, this);
}
bool Notebook::AddPage(wxWindow *win, const wxString &text, bool selected, const wxBitmap& bmp)
{
if(wxAuiNotebook::AddPage(win, text, selected, bmp)) {
win->Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(Notebook::OnKeyDown), NULL, this);
PushPageHistory(win);
return true;
}
return false;
}
bool Notebook::InsertPage(size_t index, wxWindow* win, const wxString& text, bool selected, const wxBitmap &bmp)
{
if(wxAuiNotebook::InsertPage(index, win, text, selected, bmp)) {
win->Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(Notebook::OnKeyDown), NULL, this);
PushPageHistory(win);
return true;
}
return false;
}
void Notebook::Initialize()
{
}
void Notebook::SetSelection(size_t page, bool notify)
{
if (page >= GetPageCount())
return;
m_notify = notify;
wxAuiNotebook::SetSelection(page);
m_notify = true;
PushPageHistory(GetPage(page));
}
wxWindow* Notebook::GetPage(size_t page) const
{
if (page >= GetPageCount())
return NULL;
return wxAuiNotebook::GetPage(page);
}
bool Notebook::RemovePage(size_t page, bool notify)
{
if (notify) {
//send event to noitfy that the page has changed
NotebookEvent event(wxEVT_COMMAND_BOOK_PAGE_CLOSING, GetId());
event.SetSelection( page );
event.SetEventObject( this );
GetEventHandler()->ProcessEvent(event);
if (!event.IsAllowed()) {
return false;
}
}
wxWindow* win = GetPage(page);
win->Disconnect(wxEVT_KEY_DOWN, wxKeyEventHandler(Notebook::OnKeyDown), NULL, this);
bool rc = wxAuiNotebook::RemovePage(page);
if (rc) {
PopPageHistory(win);
}
if (rc && notify) {
//send event to noitfy that the page has been closed
NotebookEvent event(wxEVT_COMMAND_BOOK_PAGE_CLOSED, GetId());
event.SetSelection( page );
event.SetEventObject( this );
GetEventHandler()->AddPendingEvent(event);
}
return rc;
}
bool Notebook::DeletePage(size_t page, bool notify)
{
if (page >= GetPageCount())
return false;
if (notify) {
//send event to noitfy that the page has changed
NotebookEvent event(wxEVT_COMMAND_BOOK_PAGE_CLOSING, GetId());
event.SetSelection( page );
event.SetEventObject( this );
GetEventHandler()->ProcessEvent(event);
if (!event.IsAllowed()) {
return false;
}
}
wxWindow* win = GetPage(page);
win->Disconnect(wxEVT_KEY_DOWN, wxKeyEventHandler(Notebook::OnKeyDown), NULL, this);
bool rc = wxAuiNotebook::DeletePage(page);
if (rc) {
PopPageHistory(win);
}
if (rc && notify) {
//send event to noitfy that the page has been closed
NotebookEvent event(wxEVT_COMMAND_BOOK_PAGE_CLOSED, GetId());
event.SetSelection( page );
event.SetEventObject( this );
GetEventHandler()->ProcessEvent(event);
}
return rc;
}
wxString Notebook::GetPageText(size_t page) const
{
if (page >= GetPageCount())
return wxT("");
return wxAuiNotebook::GetPageText(page);
}
void Notebook::OnNavigationKey(wxNavigationKeyEvent &e)
{
if ( e.IsWindowChange() ) {
if (DoNavigate())
return;
}
e.Skip();
}
const wxArrayPtrVoid& Notebook::GetHistory() const
{
return m_history;
}
void Notebook::SetRightClickMenu(wxMenu* menu)
{
m_contextMenu = menu;
}
wxWindow* Notebook::GetCurrentPage() const
{
size_t selection = GetSelection();
if (selection != Notebook::npos) {
return GetPage(selection);
}
return NULL;
}
size_t Notebook::GetPageIndex(wxWindow *page) const
{
if ( !page )
return Notebook::npos;
for (size_t i=0; i< GetPageCount(); i++) {
if (GetPage(i) == page) {
return i;
}
}
return Notebook::npos;
}
size_t Notebook::GetPageIndex(const wxString& text) const
{
for (size_t i=0; i< GetPageCount(); i++) {
if (GetPageText(i) == text) {
return i;
}
}
return Notebook::npos;
}
// wxAuiNotebook provides an array of its contained pages, accessible with GetPages()
// However it doesn't update this array when the tab-order is altered using D'n'D
// So, if serialise used GetPages(), the user would lose his preferred order of tabs.
// GetEditorsInOrder() works around the problem
void Notebook::GetEditorsInOrder(std::vector<wxWindow*> &editors)
{
editors.clear();
if (GetPageCount() == 0) {
return;
}
std::vector<wxWindow*> all_pages;// Use a vector here: it's more hassle than a set, but retains the order
// wxAuiNotebook stores its wxAuiTabCtrls in an internal class wxTabFrame, defined in the cpp file, and so unavailable
// The only way I can see to acquire them is to FindTab() on every page to find its wxAuiTabCtrl. Yuck!
std::set<wxAuiTabCtrl*> ctrls;
for (size_t pg = 0; pg < GetPageCount(); ++pg) {
wxAuiTabCtrl* ctrl;
int ctrl_idx;
wxWindow* win = GetPage(pg);
if (win && FindTab(win, &ctrl, &ctrl_idx)) {
ctrls.insert(ctrl);
all_pages.push_back(win); // Store in the all-pages vector: we may need it later
}
}
// For every tabctrl that we found, iterate through its tabs using TabHitTest()
// This is the only way to get their current order within the tabcrl, afaict
std::set<wxAuiTabCtrl*>::const_iterator it;
for (it = ctrls.begin(); it != ctrls.end(); ++it) {
wxAuiTabCtrl* ctrl = *it;
// Aim for the centre of the tab ;)
int y = ctrl->GetRect().height / 2;
// 2 is arbitrary, to ensure we're within the first tab but shouldn't overshoot
int x_offset = ctrl->GetArtProvider()->GetIndentSize() + 2;
wxWindow* previouspage = NULL;
// The elegant way to do this would be to add the width of each tab to the cumulative width
// However the value produced by GetArtProvider() is consistently too large,
// so eventually we overshoot a tab (or the whole ctrl!)
// Instead, keep hit-testing every 10 x-pixels until the page changes
do {
wxWindow* page;
int x = 0;
do {
page = NULL;
x += 10; // Another arbitrary value, but it's unlikely that there'll be a tab smaller than this
bool hit = ctrl->TabHitTest(x_offset+x, y, &page);
// If there's space between tabs, we might be hittesting this, returning hit==false
// Therefore ignore misses if we're still within the width of ctrl
if (!hit && x_offset+x >= ctrl->GetRect().width) {
break;
}
} while ((!page) || page == previouspage);
if (!page) {
// We've reached the end of the tabctrl
previouspage = NULL;
break;
}
editors.push_back(page);
// Remove it from the pages-not-yet-found vector
for (size_t p=0; p < all_pages.size(); ++p) {
if (page == *(all_pages.begin()+p)) {
all_pages.erase(all_pages.begin()+p);
break;
}
wxCHECK_RET(p+1 < all_pages.size(), wxT("Trying to erase a page not in the vector"));
}
x_offset += x;
previouspage = page;
} while (x_offset < ctrl->GetRect().width); // Continue until we reach the end of the visible ctrl
}
// If there are pages the hittest missed, they *might* be detached pages, or hitttest failure
// but they're most likely to be scrolled-off-the-screen tabs.
// I'd guess these are more likely to be from the beginning of the tabctrl, so prepend them to the vector
if (!all_pages.empty()) {
editors.insert(editors.begin(), all_pages.begin(), all_pages.end());
}
}
size_t Notebook::GetVisibleEditorIndex()
{
wxAuiTabCtrl* ctrl = GetActiveTabCtrl();
if (ctrl) {
return ctrl->GetIdxFromWindow(GetCurrentPage());
}
return Notebook::npos;
}
bool Notebook::SetPageText(size_t index, const wxString &text)
{
if (index >= GetPageCount())
return false;
return wxAuiNotebook::SetPageText(index, text);
}
bool Notebook::DeleteAllPages(bool notify)
{
bool res = true;
size_t count = GetPageCount();
for (size_t i=0; i<count && res; i++) {
res = this->DeletePage(0, notify);
}
return res;
}
void Notebook::PushPageHistory(wxWindow *page)
{
if (page == NULL)
return;
int where = m_history.Index(page);
//remove old entry of this page and re-insert it as first
if (where != wxNOT_FOUND) {
m_history.Remove(page);
}
m_history.Insert(page, 0);
}
void Notebook::PopPageHistory(wxWindow *page)
{
if( !page )
return;
int where = m_history.Index(page);
while (where != wxNOT_FOUND) {
wxWindow *tab = static_cast<wxWindow *>(m_history.Item(where));
m_history.Remove(tab);
//remove all appearances of this page
where = m_history.Index(page);
}
}
wxWindow* Notebook::GetPreviousSelection()
{
if (m_history.empty()) {
return NULL;
}
//return the top of the heap
return static_cast<wxWindow*>( m_history.Item(0));
}
void Notebook::OnInternalPageChanged(wxAuiNotebookEvent &e)
{
CHECK_OWNERSHIP(e);
DoPageChangedEvent(e);
}
void Notebook::OnInternalPageChanging(wxAuiNotebookEvent &e)
{
CHECK_OWNERSHIP(e);
DoPageChangingEvent(e);
}
void Notebook::DoPageChangedEvent(wxAuiNotebookEvent& e)
{
CHECK_OWNERSHIP(e);
if (!m_notify) {
e.Skip();
return;
}
//send event to noitfy that the page is changing
NotebookEvent event(wxEVT_COMMAND_BOOK_PAGE_CHANGED, GetId());
event.SetSelection ( e.GetSelection() );
event.SetOldSelection( e.GetOldSelection() );
event.SetEventObject ( this );
GetEventHandler()->ProcessEvent(event);
PushPageHistory( GetPage(e.GetSelection()) );
e.Skip();
}
void Notebook::DoPageChangingEvent(wxAuiNotebookEvent& e)
{
CHECK_OWNERSHIP(e);
if (!m_notify) {
e.Skip();
return;
}
//send event to noitfy that the page is changing
NotebookEvent event(wxEVT_COMMAND_BOOK_PAGE_CHANGING, GetId());
event.SetSelection ( e.GetSelection() );
event.SetOldSelection( e.GetOldSelection() );
event.SetEventObject ( this );
GetEventHandler()->ProcessEvent(event);
if ( !event.IsAllowed() ) {
e.Veto();
}
e.Skip();
}
void Notebook::OnKeyDown(wxKeyEvent& e)
{
if(e.m_controlDown) {
switch(e.GetKeyCode()) {
case WXK_TAB:
DoNavigate(); // smart tabbing
return;
case WXK_PAGEDOWN:
AdvanceSelection(false);
return;
case WXK_PAGEUP:
AdvanceSelection(true);
return;
default:
break;
}
}
e.Skip();
}
bool Notebook::DoNavigate()
{
if ( !m_popupWin && GetPageCount() > 1) {
m_popupWin = new NotebookNavDialog( this );
m_popupWin->ShowModal();
wxWindow *page = m_popupWin->GetSelection();
m_popupWin->Destroy();
m_popupWin = NULL;
SetSelection( GetPageIndex(page), true );
return true;
}
return false;
}
void Notebook::OnFocus(wxFocusEvent& e)
{
e.Skip();
}
void Notebook::OnInternalPageClosing(wxAuiNotebookEvent& e)
{
CHECK_OWNERSHIP(e);
e.Skip();
NotebookEvent event(wxEVT_COMMAND_BOOK_PAGE_CLOSING, GetId());
event.SetSelection( (int)GetSelection() );
event.SetEventObject( this );
GetEventHandler()->ProcessEvent(event);
if (!event.IsAllowed()) {
e.Veto();
} else {
// This page is likely to be removed, remove it from the history
PopPageHistory( GetPage( static_cast<size_t>( GetSelection() ) ) );
}
}
void Notebook::OnInternalPageClosed(wxAuiNotebookEvent& e)
{
CHECK_OWNERSHIP(e);
e.Skip();
NotebookEvent event(wxEVT_COMMAND_BOOK_PAGE_CLOSED, GetId());
event.SetSelection( (int) GetSelection() );
event.SetEventObject( this );
GetEventHandler()->AddPendingEvent(event);
}
void Notebook::OnTabMiddle(wxAuiNotebookEvent& e)
{
CHECK_OWNERSHIP(e);
if (e.GetSelection() != wxNOT_FOUND && HasCloseMiddle()) {
//send event to noitfy that the page is changing
NotebookEvent event(wxEVT_COMMAND_BOOK_PAGE_MIDDLE_CLICKED, GetId());
event.SetSelection ( e.GetSelection() );
event.SetOldSelection( wxNOT_FOUND );
event.SetEventObject ( this );
GetEventHandler()->AddPendingEvent(event);
}
}
void Notebook::OnTabRightDown(wxAuiNotebookEvent& e)
{
CHECK_OWNERSHIP(e);
if(m_contextMenu) {
int where = e.GetSelection();
if(where != wxNOT_FOUND && where == static_cast<int>(GetSelection())) {
PopupMenu(m_contextMenu);
} else {
e.Skip();
}
} else {
e.Skip();
}
}
void Notebook::OnInternalMenu(wxCommandEvent& e)
{
if(m_contextMenu) {
PopupMenu(m_contextMenu);
}
}
void Notebook::OnBgDclick(wxAuiNotebookEvent& e)
{
CHECK_OWNERSHIP(e);
NotebookEvent event(wxEVT_COMMAND_BOOK_BG_DCLICK, GetId());
event.SetSelection ( wxNOT_FOUND );
event.SetOldSelection( wxNOT_FOUND );
event.SetEventObject ( this );
GetEventHandler()->AddPendingEvent(event);
}
void Notebook::OnTabRightUp(wxAuiNotebookEvent& e)
{
CHECK_OWNERSHIP(e);
e.Skip();
}
void Notebook::OnTabButton(wxAuiNotebookEvent& e)
{
CHECK_OWNERSHIP(e);
// Notebook button was clicked
NotebookEvent event(wxEVT_COMMAND_BOOK_PAGE_X_CLICKED, GetId());
event.SetSelection ( GetSelection() );
event.SetOldSelection( wxNOT_FOUND );
event.SetEventObject ( this );
GetEventHandler()->AddPendingEvent(event);
}
std::set<wxAuiTabCtrl*> Notebook::GetAllTabControls()
{
// The only way I can see to acquire them is to FindTab() on every page to find its wxAuiTabCtrl. Yuck!
std::set<wxAuiTabCtrl*> ctrls;
for (size_t pg = 0; pg < GetPageCount(); ++pg) {
wxAuiTabCtrl* ctrl;
int ctrl_idx;
wxWindow* win = GetPage(pg);
if (win && FindTab(win, &ctrl, &ctrl_idx)) {
ctrls.insert(ctrl);
}
}
return ctrls;
}
wxArrayString Notebook::GetPagesTextInOrder() const
{
wxArrayString labels;
for(size_t i=0; i<GetPageCount(); ++i) {
labels.Add( GetPageText(i) );
}
return labels;
}
void Notebook::OnEndDrag(wxAuiNotebookEvent& event)
{
event.Skip();
wxPostEvent(wxTheApp, event); // The Workspace View 'Tabs' pane grabs it from wxTheApp
}
#endif // !CL_USE_NATIVEBOOK
|