1
///////////////////////////////////////////////////////////////////////////////
2
// Name: wxFlatNotebook.cpp
3
// Purpose: generic implementation of flat style notebook class.
4
// Author: Eran Ifrah <eran.ifrah@gmail.com>
5
// Modified by: Priyank Bolia <soft@priyank.in>
7
// Modified: 01/01/2006
8
// Copyright: Eran Ifrah (c)
9
// Licence: wxWindows license <http://www.wxwidgets.org/licence3.txt>
10
///////////////////////////////////////////////////////////////////////////////
12
#include <wx/wxFlatNotebook/wxFlatNotebook.h>
13
#include <wx/wxFlatNotebook/renderer.h>
14
#include <wx/wxFlatNotebook/popup_dlg.h>
15
#include <wx/wxFlatNotebook/fnb_customize_dlg.h>
17
#include <wx/tooltip.h>
18
#include <wx/tipwin.h>
19
#include <wx/arrimpl.cpp>
22
# define FNB_LOG_MSG( msg ) { wxString logmsg; logmsg << msg; wxLogMessage( logmsg ); }
24
# define FNB_LOG_MSG( msg ) { wxString logmsg; logmsg << msg; }
27
static bool InsideRect(const wxRect &rect, const wxPoint &pt)
29
#if wxCHECK_VERSION(2, 8, 0)
30
return rect.Contains(pt);
32
return rect.Inside(pt);
38
wxString WhereToString( int where )
40
static std::map<int, wxString> whereMap;
41
static bool first = true;
45
whereMap[wxFNB_TAB] = wxT("wxFNB_TAB");
46
whereMap[wxFNB_X] = wxT("wxFNB_X");
47
whereMap[wxFNB_TAB_X] = wxT("wxFNB_TAB_X");
48
whereMap[wxFNB_LEFT_ARROW] = wxT("wxFNB_LEFT_ARROW");
49
whereMap[wxFNB_RIGHT_ARROW] = wxT("wxFNB_RIGHT_ARROW");
50
whereMap[wxFNB_DROP_DOWN_ARROW] = wxT("wxFNB_DROP_DOWN_ARROW");
51
whereMap[wxFNB_NOWHERE] = wxT("wxFNB_NOWHERE");
54
return whereMap[where];
58
//-------------------------------------------------------------------
59
// Provide user with a nice feedback when tab is being dragged
60
//-------------------------------------------------------------------
61
bool wxFNBDropSource::GiveFeedback(wxDragResult effect)
64
static_cast<wxPageContainer*>( m_win )->DrawDragHint();
68
IMPLEMENT_DYNAMIC_CLASS(wxFlatNotebookEvent, wxNotifyEvent)
69
DEFINE_EVENT_TYPE(wxEVT_COMMAND_FLATNOTEBOOK_PAGE_CHANGED)
70
DEFINE_EVENT_TYPE(wxEVT_COMMAND_FLATNOTEBOOK_PAGE_CHANGING)
71
DEFINE_EVENT_TYPE(wxEVT_COMMAND_FLATNOTEBOOK_PAGE_CLOSING)
72
DEFINE_EVENT_TYPE(wxEVT_COMMAND_FLATNOTEBOOK_CONTEXT_MENU)
73
DEFINE_EVENT_TYPE(wxEVT_COMMAND_FLATNOTEBOOK_PAGE_CLOSED)
75
IMPLEMENT_DYNAMIC_CLASS(wxFlatNotebook, wxPanel)
77
WX_DEFINE_OBJARRAY(wxFlatNotebookImageList);
78
WX_DEFINE_OBJARRAY(wxPageInfoArray)
79
WX_DEFINE_OBJARRAY(wxWindowPtrArray)
81
BEGIN_EVENT_TABLE(wxFlatNotebook, wxPanel)
82
EVT_NAVIGATION_KEY(wxFlatNotebook::OnNavigationKey)
85
wxFlatNotebook::wxFlatNotebook(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name)
88
Create(parent, id, pos, size, style, name);
91
void wxFlatNotebook::CleanUp ()
93
wxFNBRendererMgrST::Free();
96
wxFlatNotebook::~wxFlatNotebook(void)
100
void wxFlatNotebook::Init()
103
m_sendPageChangeEvent = true;
104
m_bForceSelection = false;
108
m_mainSizer = new wxBoxSizer(wxVERTICAL);
109
SetSizer(m_mainSizer);
112
bool wxFlatNotebook::Create(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
113
long style, const wxString& name)
115
style |= wxTAB_TRAVERSAL;
116
wxPanel::Create(parent, id, pos, size, style, name);
118
m_pages = new wxPageContainer(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style);
119
m_pages->m_colorBorder = wxColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW));
121
m_mainSizer = new wxBoxSizer(wxVERTICAL);
122
SetSizer(m_mainSizer);
124
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
126
// Set default page height
129
wxBitmap bmp(10, 10);
130
memDc.SelectObject(bmp);
136
// For GTK it seems that we must do this steps in order
137
// for the tabs will get the proper height on initialization
138
// on MSW, preforming these steps yields wierd results
139
wxFont normalFont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
140
wxFont boldFont = normalFont;
141
boldFont.SetWeight(wxFONTWEIGHT_BOLD);
142
memDc.SetFont( boldFont );
145
wxString stam = wxT("Tp"); // Temp data to get the text height;
146
memDc.GetTextExtent(stam, &width, &height);
148
int tabHeight = height + wxFNB_HEIGHT_SPACER; // We use 8 pixels as padding
150
// On GTK the tabs are should be larger
153
m_pages->SetSizeHints(wxSize(-1, tabHeight));
155
// Add the tab container to the sizer
156
m_mainSizer->Insert(0, m_pages, 0, wxEXPAND);
157
m_mainSizer->Layout();
159
m_pages->m_nFrom = m_nFrom;
160
m_pDropTarget = new wxFNBDropTarget<wxFlatNotebook>(this, &wxFlatNotebook::OnDropTarget);
161
SetDropTarget(m_pDropTarget);
165
bool wxFlatNotebook::SetFont(const wxFont& font)
167
if ( m_pages != NULL )
169
m_pages->m_font = font;
174
wxFont& wxFlatNotebook::GetFont()
176
return m_pages->m_font;
179
void wxFlatNotebook::SetActiveTabTextColour(const wxColour& textColour)
181
m_pages->m_activeTextColor = textColour;
184
wxDragResult wxFlatNotebook::OnDropTarget(wxCoord x, wxCoord y, int nTabPage, wxWindow * wnd_oldContainer)
186
return m_pages->OnDropTarget(x, y, nTabPage, wnd_oldContainer);
189
int wxFlatNotebook::GetPreviousSelection() const
191
return m_pages->GetPreviousSelection();
194
const wxArrayInt &wxFlatNotebook::GetBrowseHistory() const
196
return m_pages->m_history;
199
bool wxFlatNotebook::AddPage(wxWindow* window, const wxString& caption, const bool selected, const int imgindex)
201
return InsertPage(m_windows.GetCount(), window, caption, selected, imgindex);
204
void wxFlatNotebook::SetImageList(wxFlatNotebookImageList * imglist)
206
m_pages->SetImageList(imglist);
209
wxFlatNotebookImageList * wxFlatNotebook::GetImageList()
211
return m_pages->GetImageList();
214
bool wxFlatNotebook::InsertPage(size_t index, wxWindow* page, const wxString& text, bool select, const int imgindex)
220
// reparent the window to us
221
page->Reparent(this);
223
if( !m_pages->IsShown() )
226
index = FNB_MIN((unsigned int)index, (unsigned int)m_windows.GetCount());
228
bool bSelected = select || m_windows.empty();
229
int curSel = m_pages->GetSelection();
231
if(index <= m_windows.GetCount())
233
m_windows.Insert(page, index);
240
if( !m_pages->InsertPage(index, page, text, bSelected, imgindex) )
243
if((int)index <= curSel)
246
m_pages->m_iActivePage = (int)curSel;
247
m_pages->DoSetSelection(curSel);
252
// Check if a new selection was made
257
// Remove the window from the main sizer
258
m_mainSizer->Detach(m_windows[curSel]);
259
m_windows[curSel]->Hide();
261
m_pages->SetSelection(index);
268
m_mainSizer->Layout();
275
void wxFlatNotebook::SetSelection(size_t page)
277
if(page >= m_windows.GetCount())
280
// Support for disabed tabs
281
if(!m_pages->GetEnabled(page) && m_windows.GetCount() > 1 && !m_bForceSelection)
284
if( m_sendPageChangeEvent )
286
// Allow the user to veto the selection
287
int oldSelection = GetSelection();
289
wxFlatNotebookEvent event(wxEVT_COMMAND_FLATNOTEBOOK_PAGE_CHANGING, GetId());
290
event.SetSelection( (int)page );
291
event.SetOldSelection( oldSelection );
292
event.SetEventObject( this );
293
GetEventHandler()->ProcessEvent(event);
295
if( !event.IsAllowed() )
301
int curSel = m_pages->GetSelection();
303
// program allows the page change
307
// Remove the window from the main sizer
308
m_mainSizer->Detach(m_windows[curSel]);
309
m_windows[curSel]->Hide();
312
if(m_windowStyle & wxFNB_BOTTOM)
314
m_mainSizer->Insert(0, m_windows[page], 1, wxEXPAND);
318
// We leave a space of 1 pixel around the window
319
m_mainSizer->Add(m_windows[page], 1, wxEXPAND);
322
m_windows[page]->Show();
323
m_mainSizer->Layout();
326
if( page != (size_t)m_pages->m_iActivePage ){
327
//keep the page history
328
m_pages->PushPageHistory(m_pages->m_iActivePage);
331
m_pages->m_iActivePage = (int)page;
332
m_pages->DoSetSelection(page);
334
if( m_sendPageChangeEvent )
336
// Fire event 'Page Changed'
337
wxFlatNotebookEvent event(wxEVT_COMMAND_FLATNOTEBOOK_PAGE_CHANGED, GetId());
338
event.SetSelection( (int)page );
339
event.SetEventObject( this );
340
GetEventHandler()->ProcessEvent(event);
344
void wxFlatNotebook::DeletePage(size_t page, bool notify)
346
if(page >= m_windows.GetCount())
349
// Fire a closing event
352
wxFlatNotebookEvent event(wxEVT_COMMAND_FLATNOTEBOOK_PAGE_CLOSING, GetId());
353
event.SetSelection((int)page);
354
event.SetEventObject(this);
355
GetEventHandler()->ProcessEvent(event);
358
// The event handler allows it?
359
if (!event.IsAllowed())
365
// Delete the requested page
366
wxWindow *pageRemoved = m_windows[page];
368
// If the page is the current window, remove it from the sizer
370
if((int)page == m_pages->GetSelection())
372
m_mainSizer->Detach(pageRemoved);
375
// Remove it from the array as well
376
m_windows.RemoveAt(page);
378
// Now we can destroy it; in wxWidgets use Destroy instead of delete
379
pageRemoved->Destroy();
383
m_pages->DoDeletePage(page);
386
// Fire a closed event
389
wxFlatNotebookEvent closedEvent(wxEVT_COMMAND_FLATNOTEBOOK_PAGE_CLOSED, GetId());
390
closedEvent.SetSelection((int)page);
391
closedEvent.SetEventObject(this);
392
GetEventHandler()->ProcessEvent(closedEvent);
396
bool wxFlatNotebook::DeleteAllPages()
398
if(m_windows.empty())
403
for(; i<(int)m_windows.GetCount(); i++)
411
// Clear the container of the tabs as well
412
m_pages->DeleteAllPages();
416
wxWindow* wxFlatNotebook::GetCurrentPage() const
418
int sel = m_pages->GetSelection();
422
return m_windows[sel];
425
wxWindow* wxFlatNotebook::GetPage(size_t page) const
427
if(page >= m_windows.GetCount())
430
return m_windows[page];
433
int wxFlatNotebook::GetPageIndex(wxWindow* win) const
435
for (size_t i = 0; i < m_windows.GetCount(); ++i)
437
if (m_windows[i] == win)
443
int wxFlatNotebook::GetSelection() const
445
return m_pages->GetSelection();
448
void wxFlatNotebook::AdvanceSelection(bool bForward)
450
m_pages->AdvanceSelection(bForward);
453
int wxFlatNotebook::GetPageCount() const
455
return (int)m_pages->GetPageCount();
458
void wxFlatNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
460
if ( event.IsWindowChange() )
462
if( HasFlag(wxFNB_SMART_TABS) )
464
if( !m_popupWin && GetPageCount() > 0)
466
m_popupWin = new wxTabNavigatorWindow( this );
467
m_popupWin->ShowModal();
468
m_popupWin->Destroy();
469
SetSelection((size_t)GetSelection());
472
else if( m_popupWin )
474
// a dialog is already opened
475
m_popupWin->OnNavigationKey( event );
482
AdvanceSelection(event.GetDirection());
487
// pass to the parent
490
event.SetCurrentFocus(this);
491
#if wxCHECK_VERSION(2, 9, 0)
492
GetParent()->GetEventHandler()->ProcessEvent(event);
494
GetParent()->ProcessEvent(event);
500
bool wxFlatNotebook::GetPageShapeAngle(int page_index, unsigned int * result)
502
if(page_index < 0 || page_index >= (int)m_pages->m_pagesInfoVec.GetCount()) return false;
503
*result = m_pages->m_pagesInfoVec[page_index].GetTabAngle();
507
void wxFlatNotebook::SetPageShapeAngle(int page_index, unsigned int angle)
509
if(page_index < 0 || page_index >= (int)m_pages->m_pagesInfoVec.GetCount()) return;
510
if(angle > 15) return;
512
m_pages->m_pagesInfoVec[page_index].SetTabAngle(angle);
515
void wxFlatNotebook::SetAllPagesShapeAngle(unsigned int angle)
517
if(angle > 15) return;
518
for(unsigned int i = 0; i < m_pages->m_pagesInfoVec.GetCount(); i++)
520
m_pages->m_pagesInfoVec[i].SetTabAngle(angle);
525
wxSize wxFlatNotebook::GetPageBestSize()
527
return m_pages->GetClientSize();
530
bool wxFlatNotebook::SetPageText(size_t page, const wxString& text)
532
bool bVal = m_pages->SetPageText(page, text);
537
void wxFlatNotebook::SetPadding(const wxSize& padding)
539
m_nPadding = padding.GetWidth();
542
void wxFlatNotebook::SetWindowStyleFlag(long style)
544
wxPanel::SetWindowStyleFlag(style);
548
// For changing the tab position (i.e. placing them top/bottom)
549
// refreshing the tab container is not enough
550
m_sendPageChangeEvent = false;
551
SetSelection(m_pages->m_iActivePage);
552
m_sendPageChangeEvent = true;
556
bool wxFlatNotebook::RemovePage(size_t page, bool notify)
558
if(page >= m_windows.GetCount())
561
// Fire a closing event
564
wxFlatNotebookEvent event(wxEVT_COMMAND_FLATNOTEBOOK_PAGE_CLOSING, GetId());
565
event.SetSelection((int)page);
566
event.SetEventObject(this);
567
GetEventHandler()->ProcessEvent(event);
569
// The event handler allows it?
570
if (!event.IsAllowed())
576
// Remove the requested page
577
wxWindow *pageRemoved = m_windows[page];
579
// If the page is the current window, remove it from the sizer
581
if((int)page == m_pages->GetSelection())
583
m_mainSizer->Detach(pageRemoved);
586
// Remove it from the array as well
587
m_windows.RemoveAt(page);
590
m_pages->DoDeletePage(page);
592
// Fire a closed event
595
wxFlatNotebookEvent closedEvent(wxEVT_COMMAND_FLATNOTEBOOK_PAGE_CLOSED, GetId());
596
closedEvent.SetSelection((int)page);
597
closedEvent.SetEventObject(this);
598
GetEventHandler()->ProcessEvent(closedEvent);
603
void wxFlatNotebook::SetRightClickMenu(wxMenu* menu)
605
m_pages->m_pRightClickMenu = menu;
608
wxString wxFlatNotebook::GetPageText(size_t page)
610
return m_pages->GetPageText(page);
613
void wxFlatNotebook::SetGradientColors(const wxColour& from, const wxColour& to, const wxColour& border)
615
m_pages->m_colorFrom = from;
616
m_pages->m_colorTo = to;
617
m_pages->m_colorBorder = border;
620
void wxFlatNotebook::SetGradientColorFrom(const wxColour& from)
622
m_pages->m_colorFrom = from;
625
void wxFlatNotebook::SetGradientColorTo(const wxColour& to)
627
m_pages->m_colorTo = to;
630
void wxFlatNotebook::SetGradientColorBorder(const wxColour& border)
632
m_pages->m_colorBorder = border;
635
/// Patch ---- Ti-R ---- Enable to show next tab selected if user click
636
void wxFlatNotebook::SetPreviewSelectColor(const wxColour& select)
638
m_pages->m_colorPreview = select;
640
/// Patch ---- Ti-R ---- Set the disable color of the text
641
void wxFlatNotebook::SetDisableTextColour(const wxColour& disable)
643
m_pages->m_disableTextColor = disable;
647
/// Gets first gradient colour
648
const wxColour& wxFlatNotebook::GetGradientColorFrom()
650
return m_pages->m_colorFrom;
653
/// Gets second gradient colour
654
const wxColour& wxFlatNotebook::GetGradientColorTo()
656
return m_pages->m_colorTo;
659
/// Gets the tab border colour
660
const wxColour& wxFlatNotebook::SetGradientColorBorder()
662
return m_pages->m_colorBorder;
665
/// Get the active tab text
666
const wxColour& wxFlatNotebook::GetActiveTabTextColour()
668
return m_pages->m_activeTextColor;
671
void wxFlatNotebook::SetPageImageIndex(size_t page, int imgindex)
673
m_pages->SetPageImageIndex(page, imgindex);
676
int wxFlatNotebook::GetPageImageIndex(size_t page)
678
return m_pages->GetPageImageIndex(page);
681
bool wxFlatNotebook::GetEnabled(size_t page)
683
return m_pages->GetEnabled(page);
686
void wxFlatNotebook::Enable(size_t page, bool enabled)
688
if(page >= m_windows.GetCount())
691
m_windows[page]->Enable(enabled);
692
m_pages->Enable(page, enabled);
695
const wxColour& wxFlatNotebook::GetNonActiveTabTextColour()
697
return m_pages->m_nonActiveTextColor;
700
void wxFlatNotebook::SetNonActiveTabTextColour(const wxColour& color)
702
m_pages->m_nonActiveTextColor = color;
705
void wxFlatNotebook::SetTabAreaColour(const wxColour& color)
707
m_pages->m_tabAreaColor = color;
710
const wxColour& wxFlatNotebook::GetTabAreaColour()
712
return m_pages->m_tabAreaColor;
715
void wxFlatNotebook::SetActiveTabColour(const wxColour& color)
717
m_pages->m_activeTabColor = color;
720
const wxColour& wxFlatNotebook::GetActiveTabColour()
722
return m_pages->m_activeTabColor;
725
long wxFlatNotebook::GetCustomizeOptions() const {
726
return m_pages->GetCustomizeOptions();
729
void wxFlatNotebook::SetCustomizeOptions(long options) {
730
m_pages->SetCustomizeOptions(options);
733
///////////////////////////////////////////////////////////////////////////////////////////
737
///////////////////////////////////////////////////////////////////////////////////////////
739
BEGIN_EVENT_TABLE(wxPageContainer, wxPanel)
740
EVT_PAINT(wxPageContainer::OnPaint)
741
EVT_SIZE(wxPageContainer::OnSize)
742
EVT_LEFT_DOWN(wxPageContainer::OnLeftDown)
743
EVT_LEFT_UP(wxPageContainer::OnLeftUp)
744
EVT_RIGHT_DOWN(wxPageContainer::OnRightDown)
745
EVT_MIDDLE_DOWN(wxPageContainer::OnMiddleDown)
746
EVT_MOTION(wxPageContainer::OnMouseMove)
747
EVT_ERASE_BACKGROUND(wxPageContainer::OnEraseBackground)
748
EVT_LEAVE_WINDOW(wxPageContainer::OnMouseLeave)
749
EVT_ENTER_WINDOW(wxPageContainer::OnMouseEnterWindow)
750
EVT_LEFT_DCLICK(wxPageContainer::OnLeftDClick)
753
wxPageContainer::wxPageContainer(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style)
756
, m_pDropTarget(NULL)
757
, m_nLeftClickZone(wxFNB_NOWHERE)
758
, m_customizeOptions(wxFNB_CUSTOM_ALL)
760
m_pRightClickMenu = NULL;
761
m_nXButtonStatus = wxFNB_BTN_NONE;
762
m_nArrowDownButtonStatus = wxFNB_BTN_NONE;
764
m_nRightButtonStatus = wxFNB_BTN_NONE;
765
m_nLeftButtonStatus = wxFNB_BTN_NONE;
766
m_nTabXButtonStatus = wxFNB_BTN_NONE;
768
/// Patch (m_nTabStatus) ---- Ti-R ---- Enable to show next tab selected if user click
769
m_nTabStatus = wxFNB_BTN_NONE;
771
m_colorTo = wxColour(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION));
772
m_colorFrom = wxColor(*wxWHITE);
773
m_activeTabColor = wxColor(*wxWHITE);
774
m_activeTextColor = wxColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT));
775
m_nonActiveTextColor = wxColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT));
776
m_tabAreaColor = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
777
m_disableTextColor = wxColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW));
779
/// Patch (m_font) ---- Ti-R ---- Enable to change the font
780
m_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
782
/// Patch (m_font) ---- Ti-R ---- Enable to preview the selected tab
783
m_colorPreview = wxColor(193, 210, 238);
785
// Set default page height, this is done according to the system font
787
wxBitmap bmp(10, 10);
788
memDc.SelectObject(bmp);
793
wxFont normalFont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
794
wxFont boldFont = normalFont;
795
boldFont.SetWeight(wxBOLD);
796
memDc.SetFont( boldFont );
799
memDc.GetTextExtent(wxT("Tp"), &width, &height);
800
int tabHeight = height + wxFNB_HEIGHT_SPACER; // We use 10 pixels as padding
802
wxWindow::Create(parent, id, pos, wxSize(size.x, tabHeight), style | wxNO_BORDER | wxNO_FULL_REPAINT_ON_RESIZE);
804
m_pDropTarget = new wxFNBDropTarget<wxPageContainer>(this, &wxPageContainer::OnDropTarget);
805
SetDropTarget(m_pDropTarget);
808
wxPageContainer::~wxPageContainer(void)
810
if(m_pRightClickMenu)
812
delete m_pRightClickMenu;
813
m_pRightClickMenu = NULL;
823
void wxPageContainer::OnPaint(wxPaintEvent & event)
825
wxBufferedPaintDC dc(this);
826
wxFNBRendererPtr render = wxFNBRendererMgrST::Get()->GetRenderer( GetParent()->GetWindowStyleFlag() );
828
render->DrawTabs(this, dc, event);
831
void wxPageContainer::PopPageHistory(int page)
833
int tabIdx(wxNOT_FOUND);
834
int where = m_history.Index(page);
835
while(where != wxNOT_FOUND){
836
tabIdx = m_history.Item(where);
837
m_history.Remove(page);
838
//remove all appearances of this page
839
where = m_history.Index(page);
843
if(tabIdx != wxNOT_FOUND){
844
for(size_t i=0; i<m_history.size(); i++){
845
int &tt = m_history.Item(i);
853
void wxPageContainer::PushPageHistory(int page)
855
if(page == wxNOT_FOUND)
858
int where = m_history.Index(page);
859
if(where != wxNOT_FOUND){
860
m_history.Remove(page);
862
m_history.Insert(page, 0);
865
bool wxPageContainer::AddPage(const wxString& caption, const bool selected, const int imgindex)
869
PushPageHistory(m_iActivePage);
870
m_iActivePage = (int)m_pagesInfoVec.GetCount();
873
/// Create page info and add it to the vector
874
wxPageInfo pageInfo(caption, imgindex);
875
m_pagesInfoVec.Add(pageInfo);
880
bool wxPageContainer::InsertPage(size_t index, wxWindow* /*page*/, const wxString& text, bool select, const int imgindex)
884
PushPageHistory(m_iActivePage);
885
m_iActivePage = (int)index;
887
wxPageInfo pgInfo(text, imgindex);
888
m_pagesInfoVec.Insert(pgInfo, index);
893
void wxPageContainer::OnSize(wxSizeEvent& WXUNUSED(event))
895
// When resizing the control, try to fit to screen as many tabs as we we can
896
long style = GetParent()->GetWindowStyleFlag();
897
wxFNBRendererPtr render = wxFNBRendererMgrST::Get()->GetRenderer(style);
898
std::vector<wxRect> vTabInfo;
901
int page = GetSelection();
902
for(; from<m_nFrom; from++)
905
render->NumberTabsCanFit( this, vTabInfo, from );
906
if(page - from >= static_cast<int>( vTabInfo.size() ))
911
Refresh(); // Call on paint
914
void wxPageContainer::OnMiddleDown(wxMouseEvent& event)
916
// Test if this style is enabled
917
long style = GetParent()->GetWindowStyleFlag();
918
if(!(style & wxFNB_MOUSE_MIDDLE_CLOSES_TABS))
923
int where = HitTest(event.GetPosition(), pgInfo, tabIdx);
928
DeletePage((size_t)tabIdx);
938
void wxPageContainer::OnShowCustomizeDialog(wxCommandEvent &event)
941
wxFNBCustomizeDialog *dlg = new wxFNBCustomizeDialog(this, m_customizeOptions);
946
void wxPageContainer::OnRightDown(wxMouseEvent& event)
948
FNB_LOG_MSG(wxT("OnRightDown") << event.GetPosition().x << wxT(",") << event.GetPosition().y );
951
int where = HitTest(event.GetPosition(), pgInfo, tabIdx);
956
// Incase user right clicked on 'anywhere' and style wxFNB_CUSTOM_DLG is set,
957
// popup the customize dialog
958
long style = GetParent()->GetWindowStyleFlag();
959
if( style & wxFNB_CUSTOM_DLG ){
961
m_customMenu = new wxMenu();
962
wxMenuItem *item = new wxMenuItem(m_customMenu, wxID_ANY, wxT("Properties..."));
963
m_customMenu->Append(item);
964
Connect( item->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( wxPageContainer::OnShowCustomizeDialog ));
966
PopupMenu(m_customMenu);
974
if(!m_pagesInfoVec[tabIdx].GetEnabled())
977
// Set the current tab to be active
979
if(tabIdx != GetSelection())
981
SetSelection((size_t)tabIdx);
984
// If the owner has defined a context menu for the tabs,
985
// popup the right click menu
986
if (m_pRightClickMenu)
987
PopupMenu(m_pRightClickMenu);
990
// send a message to popup a custom menu
991
wxFlatNotebookEvent event(wxEVT_COMMAND_FLATNOTEBOOK_CONTEXT_MENU, GetParent()->GetId());
992
event.SetSelection((int)tabIdx);
993
event.SetOldSelection((int)m_iActivePage);
994
event.SetEventObject(GetParent());
995
GetParent()->GetEventHandler()->ProcessEvent(event);
1006
void wxPageContainer::OnLeftDown(wxMouseEvent& event)
1011
// Reset buttons status
1012
m_nXButtonStatus = wxFNB_BTN_NONE;
1013
m_nLeftButtonStatus = wxFNB_BTN_NONE;
1014
m_nRightButtonStatus = wxFNB_BTN_NONE;
1015
m_nTabXButtonStatus = wxFNB_BTN_NONE;
1016
m_nArrowDownButtonStatus = wxFNB_BTN_NONE;
1017
/// Patch (m_nTabStatus) ---- Ti-R ---- Enable to show next tab selected if user click
1018
m_nTabStatus = wxFNB_BTN_NONE;
1020
m_nLeftClickZone = HitTest(event.GetPosition(), pgInfo, tabIdx);
1021
switch(m_nLeftClickZone)
1023
case wxFNB_DROP_DOWN_ARROW:
1024
m_nArrowDownButtonStatus = wxFNB_BTN_PRESSED;
1027
case wxFNB_LEFT_ARROW:
1028
m_nLeftButtonStatus = wxFNB_BTN_PRESSED;
1031
case wxFNB_RIGHT_ARROW:
1032
m_nRightButtonStatus = wxFNB_BTN_PRESSED;
1036
m_nXButtonStatus = wxFNB_BTN_PRESSED;
1040
m_nTabXButtonStatus = wxFNB_BTN_PRESSED;
1045
if(m_iActivePage != tabIdx)
1047
// Incase the tab is disabled, we dont allow to choose it
1048
if(!m_pagesInfoVec[tabIdx].GetEnabled())
1051
SetSelection(tabIdx);
1058
void wxPageContainer::RotateLeft()
1063
// Make sure that the button was pressed before
1064
if(m_nLeftButtonStatus != wxFNB_BTN_PRESSED)
1067
m_nLeftButtonStatus = wxFNB_BTN_HOVER;
1069
// We scroll left with bulks of 5
1070
int scrollLeft = GetNumTabsCanScrollLeft();
1072
m_nFrom -= scrollLeft;
1080
void wxPageContainer::RotateRight()
1082
if(m_nFrom >= (int)m_pagesInfoVec.GetCount() - 1)
1085
// Make sure that the button was pressed before
1086
if(m_nRightButtonStatus != wxFNB_BTN_PRESSED)
1089
m_nRightButtonStatus = wxFNB_BTN_HOVER;
1091
// Check if the right most tab is visible, if it is
1092
// don't rotate right anymore
1093
if(m_pagesInfoVec[m_pagesInfoVec.GetCount()-1].GetPosition() != wxPoint(-1, -1))
1100
void wxPageContainer::OnLeftUp(wxMouseEvent& event)
1105
// forget the zone that was initially clicked
1106
m_nLeftClickZone = wxFNB_NOWHERE;
1108
int where = HitTest(event.GetPosition(), pgInfo, tabIdx);
1111
case wxFNB_LEFT_ARROW:
1116
case wxFNB_RIGHT_ARROW:
1123
// Make sure that the button was pressed before
1124
if(m_nXButtonStatus != wxFNB_BTN_PRESSED)
1127
m_nXButtonStatus = wxFNB_BTN_HOVER;
1129
DeletePage((size_t)m_iActivePage);
1134
// Make sure that the button was pressed before
1135
if(m_nTabXButtonStatus != wxFNB_BTN_PRESSED)
1138
m_nTabXButtonStatus = wxFNB_BTN_HOVER;
1140
DeletePage((size_t)m_iActivePage);
1143
case wxFNB_DROP_DOWN_ARROW:
1145
// Make sure that the button was pressed before
1146
if(m_nArrowDownButtonStatus != wxFNB_BTN_PRESSED)
1149
m_nArrowDownButtonStatus = wxFNB_BTN_NONE;
1151
// Refresh the button status
1152
wxFNBRendererPtr render = wxFNBRendererMgrST::Get()->GetRenderer( GetParent()->GetWindowStyleFlag() );
1153
wxClientDC dc(this);
1154
render->DrawDropDownArrow(this, dc);
1163
int wxPageContainer::HitTest(const wxPoint& pt, wxPageInfo& pageInfo, int &tabIdx)
1165
wxFNBRendererPtr render = wxFNBRendererMgrST::Get()->GetRenderer( GetParent()->GetWindowStyleFlag() );
1167
wxRect rect = GetClientRect();
1168
int btnLeftPos = render->GetLeftButtonPos(this);
1169
int btnRightPos = render->GetRightButtonPos(this);
1170
int btnXPos =render->GetXPos(this);
1171
long style = GetParent()->GetWindowStyleFlag();
1174
if(m_pagesInfoVec.IsEmpty())
1176
return wxFNB_NOWHERE;
1179
rect = wxRect(btnXPos, 8, 16, 16);
1180
if(InsideRect(rect, pt))
1182
return (style & wxFNB_NO_X_BUTTON) ? wxFNB_NOWHERE : wxFNB_X;
1185
rect = wxRect(btnRightPos, 8, 16, 16);
1186
if( style & wxFNB_DROPDOWN_TABS_LIST )
1188
rect = wxRect(render->GetDropArrowButtonPos( this ), 8, 16, 16);
1189
if(InsideRect(rect, pt))
1190
return wxFNB_DROP_DOWN_ARROW;
1193
if(InsideRect(rect, pt))
1195
return (style & wxFNB_NO_NAV_BUTTONS) ? wxFNB_NOWHERE : wxFNB_RIGHT_ARROW;
1199
rect = wxRect(btnLeftPos, 8, 16, 16);
1200
if(InsideRect(rect, pt))
1202
return (style & wxFNB_NO_NAV_BUTTONS) ? wxFNB_NOWHERE : wxFNB_LEFT_ARROW;
1205
// Test whether a left click was made on a tab
1206
bool bFoundMatch = false;
1207
for(size_t cur=m_nFrom; cur<m_pagesInfoVec.GetCount(); cur++)
1209
wxPageInfo pgInfo = m_pagesInfoVec[cur];
1210
if(pgInfo.GetPosition() == wxPoint(-1, -1))
1213
// check for mouse over tab's x button
1214
if(style & wxFNB_X_ON_TAB && (int)cur == GetSelection())
1216
// 'x' button exists on a tab
1217
if(InsideRect(m_pagesInfoVec[cur].GetXRect(), pt))
1225
if(style & wxFNB_VC8)
1227
if(m_pagesInfoVec[cur].GetRegion().Contains(pt) == wxInRegion)
1229
if(bFoundMatch || (int)cur == GetSelection())
1243
wxRect tabRect = wxRect(pgInfo.GetPosition().x, pgInfo.GetPosition().y,
1244
pgInfo.GetSize().x, pgInfo.GetSize().y);
1246
if(InsideRect(tabRect, pt))
1260
return wxFNB_NOWHERE;
1263
void wxPageContainer::SetSelection(size_t page)
1265
wxFlatNotebook* book = (wxFlatNotebook*)GetParent();
1266
book->SetSelection(page);
1267
DoSetSelection(page);
1270
void wxPageContainer::DoSetSelection(size_t page)
1272
// Make sure that the selection is visible
1273
if(page < m_pagesInfoVec.GetCount())
1275
//! fix for tabfocus
1276
wxWindow* da_page = ((wxFlatNotebook *)m_pParent)->GetPage(page);
1277
if ( da_page!=NULL )
1278
da_page->SetFocus();
1281
if( !IsTabVisible(page) )
1283
FNB_LOG_MSG( wxT("Tab ") << (int)page << wxT(" is not visible"));
1284
FNB_LOG_MSG( wxT("m_nFrom=") << m_nFrom << wxT(", Selection=") << (int)page );
1286
// Try to remove one tab from start and try again
1287
if( !CanFitToScreen(page) )
1289
if( m_nFrom > (int)page )
1290
m_nFrom = (int)page;
1293
while( m_nFrom < (int)page )
1296
if( CanFitToScreen(page) )
1300
FNB_LOG_MSG( wxT("Adjusting m_nFrom to=") << m_nFrom);
1305
FNB_LOG_MSG( wxT("Tab ") << (int)page << wxT(" is visible"));
1307
PushPageHistory((int)page);
1311
void wxPageContainer::DeletePage(size_t page)
1313
wxFlatNotebook* book = (wxFlatNotebook*)GetParent();
1314
book->DeletePage(page);
1318
bool wxPageContainer::IsTabVisible(size_t page)
1320
int iPage = (int)page;
1321
int iLastVisiblePage = GetLastVisibleTab();
1323
return iPage <= iLastVisiblePage && iPage >= m_nFrom;
1326
int wxPageContainer::GetPreviousSelection() const
1328
if(m_history.empty()){
1331
//return the top of the heap
1332
return m_history.Item(0);
1335
void wxPageContainer::DoDeletePage(size_t page)
1337
// Remove the page from the vector
1338
wxFlatNotebook* book = (wxFlatNotebook*)GetParent();
1340
PopPageHistory((int)page);
1342
// same thing with the active page
1343
if (m_iActivePage > (int)page || (int)page >= (int)(m_pagesInfoVec.Count())){
1345
}else if (m_iActivePage == (int)page){
1346
m_iActivePage = GetPreviousSelection();
1347
//PopPageHistory(m_iActivePage);
1350
m_pagesInfoVec.RemoveAt(page);
1352
if(m_iActivePage == wxNOT_FOUND && m_pagesInfoVec.Count() > 0){
1357
book->SetForceSelection(true);
1358
book->SetSelection(m_iActivePage);
1359
book->SetForceSelection(false);
1361
if(m_pagesInfoVec.empty())
1363
// Erase the page container drawings
1364
wxClientDC dc(this);
1369
void wxPageContainer::DeleteAllPages()
1374
m_pagesInfoVec.Clear();
1376
// Erase the page container drawings
1377
wxClientDC dc(this);
1381
void wxPageContainer::OnMouseMove(wxMouseEvent& event)
1383
if (!m_pagesInfoVec.empty() && IsShown())
1385
const int xButtonStatus = m_nXButtonStatus;
1386
const int xTabButtonStatus = m_nTabXButtonStatus;
1387
const int rightButtonStatus = m_nRightButtonStatus;
1388
const int leftButtonStatus = m_nLeftButtonStatus;
1389
const int dropDownButtonStatus = m_nArrowDownButtonStatus;
1390
/// Patch (savePreviewId) ---- Ti-R ---- Enable to show next tab selected if user click
1391
const int savePreviewId = m_nTabPreviewId;
1393
long style = GetParent()->GetWindowStyleFlag();
1395
m_nXButtonStatus = wxFNB_BTN_NONE;
1396
m_nRightButtonStatus = wxFNB_BTN_NONE;
1397
m_nLeftButtonStatus = wxFNB_BTN_NONE;
1398
m_nTabXButtonStatus = wxFNB_BTN_NONE;
1399
m_nArrowDownButtonStatus = wxFNB_BTN_NONE;
1400
/// Patch (m_nTabStatus) ---- Ti-R ---- Enable to show next tab selected if user click
1401
m_nTabStatus = wxFNB_BTN_NONE;
1406
int where = HitTest(event.GetPosition(), pgInfo, tabIdx);
1410
if (event.LeftIsDown())
1412
m_nXButtonStatus = (m_nLeftClickZone==wxFNB_X) ? wxFNB_BTN_PRESSED : wxFNB_BTN_NONE;
1416
m_nXButtonStatus = wxFNB_BTN_HOVER;
1419
case wxFNB_DROP_DOWN_ARROW:
1420
if (event.LeftIsDown())
1422
m_nArrowDownButtonStatus = (m_nLeftClickZone == wxFNB_DROP_DOWN_ARROW) ? wxFNB_BTN_PRESSED : wxFNB_BTN_NONE;
1426
m_nArrowDownButtonStatus = wxFNB_BTN_HOVER;
1430
if (event.LeftIsDown())
1432
m_nTabXButtonStatus = (m_nLeftClickZone==wxFNB_TAB_X) ? wxFNB_BTN_PRESSED : wxFNB_BTN_NONE;
1436
m_nTabXButtonStatus = wxFNB_BTN_HOVER;
1439
case wxFNB_RIGHT_ARROW:
1440
if (event.LeftIsDown())
1442
m_nRightButtonStatus = (m_nLeftClickZone==wxFNB_RIGHT_ARROW) ? wxFNB_BTN_PRESSED : wxFNB_BTN_NONE;
1446
m_nRightButtonStatus = wxFNB_BTN_HOVER;
1450
case wxFNB_LEFT_ARROW:
1451
if (event.LeftIsDown())
1453
m_nLeftButtonStatus = (m_nLeftClickZone==wxFNB_LEFT_ARROW) ? wxFNB_BTN_PRESSED : wxFNB_BTN_NONE;
1457
m_nLeftButtonStatus = wxFNB_BTN_HOVER;
1462
// Call virtual method for showing tooltip
1463
ShowTabTooltip(tabIdx);
1464
if(!GetEnabled((size_t)tabIdx))
1466
// Set the cursor to be 'No-entry'
1467
::wxSetCursor(wxCURSOR_NO_ENTRY);
1470
// Support for drag and drop
1471
if(event.Dragging() && !(style & wxFNB_NODRAG))
1473
wxFNBDragInfo draginfo(this, tabIdx);
1474
wxFNBDragInfoDataObject dataobject(wxDataFormat(wxT("wxFNB")));
1475
dataobject.SetData(sizeof(wxFNBDragInfo), &draginfo);
1476
wxFNBDropSource dragSource(this);
1477
dragSource.SetData(dataobject);
1478
dragSource.DoDragDrop(wxDrag_DefaultMove);
1481
/// Patch ---- Ti-R ---- Enable to show next tab selected if user click
1482
if(style & wxFNB_PREVIEW_SELECT_TAB)
1484
m_nTabStatus = wxFNB_BTN_HOVER;
1485
m_nTabPreviewId = tabIdx;
1490
m_nTabXButtonStatus = wxFNB_BTN_NONE;
1493
/// Patch (bRedrawTab) ---- Ti-R ---- Enable to show next tab selected if user click
1494
if(m_nTabStatus != wxFNB_BTN_HOVER)
1497
const bool bRedrawTab = (m_nTabPreviewId != savePreviewId);
1498
const bool bRedrawX = m_nXButtonStatus != xButtonStatus;
1499
const bool bRedrawDropArrow = m_nArrowDownButtonStatus != dropDownButtonStatus;
1500
const bool bRedrawRight = m_nRightButtonStatus != rightButtonStatus;
1501
const bool bRedrawLeft = m_nLeftButtonStatus != leftButtonStatus;
1502
const bool bRedrawTabX = m_nTabXButtonStatus != xTabButtonStatus;
1504
wxFNBRendererPtr render = wxFNBRendererMgrST::Get()->GetRenderer( GetParent()->GetWindowStyleFlag() );
1506
if (bRedrawTab || bRedrawX || bRedrawRight || bRedrawLeft || bRedrawTabX || bRedrawDropArrow)
1508
wxClientDC dc(this);
1515
render->DrawX(this, dc);
1519
render->DrawLeftArrow(this, dc);
1523
render->DrawRightArrow(this, dc);
1527
render->DrawTabX(this, dc, pgInfo.GetXRect(), tabIdx, m_nTabXButtonStatus);
1529
if (bRedrawDropArrow)
1531
render->DrawDropDownArrow(this, dc);
1538
int wxPageContainer::GetLastVisibleTab()
1544
for(i=m_nFrom; i<(int)m_pagesInfoVec.GetCount(); i++)
1546
if(m_pagesInfoVec[i].GetPosition() == wxPoint(-1, -1))
1552
int wxPageContainer::GetNumTabsCanScrollLeft()
1554
if( m_nFrom - 1 >= 0){
1561
bool wxPageContainer::IsDefaultTabs()
1563
long style = GetParent()->GetWindowStyleFlag();
1564
bool res = (style & wxFNB_VC71) || (style & wxFNB_FANCY_TABS) || (style & wxFNB_VC8);
1568
void wxPageContainer::AdvanceSelection(bool bForward)
1570
int nSel = GetSelection();
1575
int nMax = (int)GetPageCount() - 1;
1577
SetSelection(nSel == nMax ? 0 : nSel + 1);
1579
SetSelection(nSel == 0 ? nMax : nSel - 1);
1583
void wxPageContainer::OnMouseLeave(wxMouseEvent& event)
1585
m_nLeftButtonStatus = wxFNB_BTN_NONE;
1586
m_nXButtonStatus = wxFNB_BTN_NONE;
1587
m_nRightButtonStatus = wxFNB_BTN_NONE;
1588
m_nTabXButtonStatus = wxFNB_BTN_NONE;
1589
m_nArrowDownButtonStatus = wxFNB_BTN_NONE;
1591
/// Patch (m_nTabStatus) ---- Ti-R ---- Refresh on leave to do not keep the preview
1592
if(m_nTabStatus == wxFNB_BTN_HOVER)
1597
m_nTabStatus = wxFNB_BTN_NONE;
1599
long style = GetParent()->GetWindowStyleFlag();
1600
wxFNBRendererPtr render = wxFNBRendererMgrST::Get()->GetRenderer(style);
1602
wxClientDC dc(this);
1603
render->DrawX(this, dc);
1604
render->DrawLeftArrow(this, dc);
1605
render->DrawRightArrow(this, dc);
1606
if(GetSelection() != -1 && IsTabVisible((size_t)GetSelection()))
1608
render->DrawTabX(this, dc, m_pagesInfoVec[GetSelection()].GetXRect(), GetSelection(), m_nTabXButtonStatus);
1614
void wxPageContainer::OnMouseEnterWindow(wxMouseEvent& event)
1616
m_nLeftButtonStatus = wxFNB_BTN_NONE;
1617
m_nXButtonStatus = wxFNB_BTN_NONE;
1618
m_nRightButtonStatus = wxFNB_BTN_NONE;
1619
m_nLeftClickZone = wxFNB_BTN_NONE;
1620
m_nArrowDownButtonStatus = wxFNB_BTN_NONE;
1621
/// Patch (m_nTabStatus) ---- Ti-R ---- Enable to show next tab selected if user click
1622
m_nTabStatus = wxFNB_BTN_NONE;
1627
void wxPageContainer::ShowTabTooltip(int tabIdx)
1629
wxWindow *pWindow = ((wxFlatNotebook *)m_pParent)->GetPage(tabIdx);
1632
wxToolTip *pToolTip = pWindow->GetToolTip();
1633
if(pToolTip && pToolTip->GetWindow() == pWindow)
1634
SetToolTip(pToolTip->GetTip());
1638
void wxPageContainer::SetPageImageIndex(size_t page, int imgindex)
1640
if(page < m_pagesInfoVec.GetCount())
1642
m_pagesInfoVec[page].SetImageIndex(imgindex);
1647
int wxPageContainer::GetPageImageIndex(size_t page)
1649
if(page < m_pagesInfoVec.GetCount())
1651
return m_pagesInfoVec[page].GetImageIndex();
1656
wxDragResult wxPageContainer::OnDropTarget(wxCoord x, wxCoord y, int nTabPage, wxWindow * wnd_oldContainer)
1658
// Disable drag'n'drop for disabled tab
1659
if(!((wxPageContainer *)wnd_oldContainer)->m_pagesInfoVec[nTabPage].GetEnabled())
1660
return wxDragCancel;
1662
wxLogTrace(wxTraceMask(), _("Old Page Index = %i"), nTabPage);
1663
wxPageContainer * oldContainer = (wxPageContainer *)wnd_oldContainer;
1666
int where = HitTest(wxPoint(x, y), pgInfo, nIndex);
1667
wxLogTrace(wxTraceMask(), _("OnDropTarget: index by HitTest = %i"), nIndex);
1668
wxFlatNotebook * oldNotebook = (wxFlatNotebook *)oldContainer->GetParent();
1669
wxFlatNotebook * newNotebook = (wxFlatNotebook *)GetParent();
1671
if(oldNotebook == newNotebook)
1678
MoveTabPage(nTabPage, nIndex);
1689
else if ( GetParent()->GetWindowStyleFlag() & wxFNB_ALLOW_FOREIGN_DND )
1691
#if defined(__WXMSW__) || defined(__WXGTK__)
1694
wxWindow * window = oldNotebook->GetPage(nTabPage);
1697
wxString caption = oldContainer->GetPageText(nTabPage);
1699
// Pass the image to the new container
1700
// incase that the new container (this) does not have image list we dont pass the image
1701
// to the new notebook
1702
int newIndx( wxNOT_FOUND );
1706
int imageindex = oldContainer->GetPageImageIndex(nTabPage);
1707
if( imageindex >= 0 )
1709
wxBitmap bmp( (*oldContainer->GetImageList())[imageindex] );
1710
m_ImageList->Add( bmp );
1711
newIndx = static_cast<int>(m_ImageList->GetCount() - 1);
1715
oldNotebook->RemovePage( nTabPage );
1716
window->Reparent( newNotebook );
1717
newNotebook->InsertPage(nIndex, window, caption, true, newIndx);
1725
void wxPageContainer::MoveTabPage(int nMove, int nMoveTo)
1727
if(nMove == nMoveTo)
1730
else if(nMoveTo < (int)((wxFlatNotebook *)m_pParent)->GetWindows().GetCount())
1733
m_pParent->Freeze();
1734
// Remove the window from the main sizer
1735
int nCurSel = ((wxFlatNotebook *)m_pParent)->GetPages()->GetSelection();
1736
((wxFlatNotebook *)m_pParent)->GetMainSizer()->Detach(((wxFlatNotebook *)m_pParent)->GetWindows().Item(nCurSel));
1737
((wxFlatNotebook *)m_pParent)->GetWindows().Item(nCurSel)->Hide();
1739
wxWindow *pWindow = ((wxFlatNotebook *)m_pParent)->GetWindows().Item(nMove);
1740
((wxFlatNotebook *)m_pParent)->GetWindows().RemoveAt(nMove);
1741
((wxFlatNotebook *)m_pParent)->GetWindows().Insert(pWindow, nMoveTo-1);
1743
wxPageInfo pgInfo = m_pagesInfoVec[nMove];
1745
m_pagesInfoVec.RemoveAt( nMove );
1746
m_pagesInfoVec.Insert(pgInfo, nMoveTo - 1);
1748
// Add the page according to the style
1749
wxBoxSizer* pSizer = ((wxFlatNotebook *)m_pParent)->GetMainSizer();
1750
long style = GetParent()->GetWindowStyleFlag();
1753
if(style & wxFNB_BOTTOM)
1755
pSizer->Insert(0, pWindow, 1, wxEXPAND);
1759
// We leave a space of 1 pixel around the window
1760
pSizer->Add(pWindow, 1, wxEXPAND);
1765
m_iActivePage = nMoveTo-1;
1767
DoSetSelection(m_iActivePage);
1771
bool wxPageContainer::CanFitToScreen(size_t page)
1773
// Incase the from is greater than page,
1774
// we need to reset the m_nFrom, so in order
1775
// to force the caller to do so, we return false
1776
if(m_nFrom > (int)page)
1779
long style = GetParent()->GetWindowStyleFlag();
1780
wxFNBRendererPtr render = wxFNBRendererMgrST::Get()->GetRenderer(style);
1781
std::vector<wxRect> vTabInfo;
1782
render->NumberTabsCanFit( this, vTabInfo );
1784
if(static_cast<int>(page) - m_nFrom >= static_cast<int>( vTabInfo.size() ))
1789
int wxPageContainer::GetNumOfVisibleTabs()
1793
for(; i<(int)m_pagesInfoVec.GetCount(); i++, ++counter)
1795
if(m_pagesInfoVec[i].GetPosition() == wxPoint(-1, -1))
1801
bool wxPageContainer::GetEnabled(size_t page)
1803
if(page >= m_pagesInfoVec.GetCount())
1804
return true; // Seems strange, but this is the default
1805
return m_pagesInfoVec[page].GetEnabled();
1808
void wxPageContainer::Enable(size_t page, bool enabled)
1810
if(page >= m_pagesInfoVec.GetCount())
1812
m_pagesInfoVec[page].Enable(enabled);
1814
/// Patch ---- Ti-R ---- Enable to display correctly the tab
1819
wxColor wxPageContainer::GetSingleLineBorderColor()
1821
if(HasFlag(wxFNB_FANCY_TABS))
1824
/// Patch ---- Ti-R ---- Enable to have the same line color as the selected tab
1825
if(HasFlag(wxFNB_BOTTOM_LINE_COLOR_CHANGE))
1826
return m_activeTabColor;
1831
bool wxPageContainer::HasFlag(int flag)
1833
long style = GetParent()->GetWindowStyleFlag();
1834
bool res = style & flag ? true : false;
1838
void wxPageContainer::ClearFlag(int flag)
1840
long style = GetParent()->GetWindowStyleFlag();
1842
wxWindowBase::SetWindowStyleFlag(style);
1845
bool wxPageContainer::TabHasImage(int tabIdx)
1848
return m_pagesInfoVec[tabIdx].GetImageIndex() != -1;
1852
void wxPageContainer::OnLeftDClick(wxMouseEvent& event)
1856
int where = HitTest(event.GetPosition(), pgInfo, tabIdx);
1859
case wxFNB_RIGHT_ARROW:
1862
case wxFNB_LEFT_ARROW:
1866
if(HasFlag(wxFNB_DCLICK_CLOSES_TABS))
1868
DeletePage((size_t)tabIdx);
1882
void wxPageContainer::PopupTabsMenu()
1886
for(size_t i=0; i<m_pagesInfoVec.GetCount(); i++)
1888
wxPageInfo pi = m_pagesInfoVec[i];
1889
wxMenuItem *item = new wxMenuItem(&popupMenu, static_cast<int>(i), pi.GetCaption(), pi.GetCaption(), wxITEM_NORMAL);
1891
// This code is commented, since there is an alignment problem with wx2.6.3 & Menus
1892
// if( TabHasImage(static_cast<int>(i)) )
1893
// item->SetBitmaps( (*m_ImageList)[pi.GetImageIndex()] );
1895
popupMenu.Append( item );
1898
// connect an event handler to our menu
1899
popupMenu.Connect(wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(wxPageContainer::OnTabMenuSelection), NULL, this);
1900
PopupMenu( &popupMenu );
1903
void wxPageContainer::OnTabMenuSelection(wxCommandEvent &event)
1905
int selection = event.GetId();
1906
static_cast<wxFlatNotebook*>(m_pParent)->SetSelection( (size_t)selection );
1909
// Draw small arrow at the place that the tab will be placed
1910
void wxPageContainer::DrawDragHint()
1912
// get the index of tab that will be replaced with the dragged tab
1915
wxPoint pt = ::wxGetMousePosition();
1916
wxPoint client_pt = ScreenToClient(pt);
1917
HitTest(client_pt, info, tabIdx);
1918
wxFNBRendererMgrST::Get()->GetRenderer( GetParent()->GetWindowStyleFlag() )->DrawDragHint(this, tabIdx);
1921
void wxPageContainer::SetCustomizeOptions(long options)
1923
m_customizeOptions = options;
1926
long wxPageContainer::GetCustomizeOptions() const
1928
return m_customizeOptions;