📄 wxflatnotebook.cpp
字号:
}/// Gets first gradient colourconst wxColour& wxFlatNotebook::GetGradientColorFrom(){ return m_pages->m_colorFrom;}/// Gets second gradient colourconst wxColour& wxFlatNotebook::GetGradientColorTo(){ return m_pages->m_colorTo;}/// Gets the tab border colourconst wxColour& wxFlatNotebook::SetGradientColorBorder(){ return m_pages->m_colorBorder;}/// Get the active tab textconst wxColour& wxFlatNotebook::GetActiveTabTextColour(){ return m_pages->m_activeTextColor;}void wxFlatNotebook::SetPageImageIndex(size_t page, int imgindex){ m_pages->SetPageImageIndex(page, imgindex);}int wxFlatNotebook::GetPageImageIndex(size_t page){ return m_pages->GetPageImageIndex(page);}bool wxFlatNotebook::GetEnabled(size_t page){ return m_pages->GetEnabled(page);}void wxFlatNotebook::Enable(size_t page, bool enabled){ if(page >= m_windows.GetCount()) return; m_windows[page]->Enable(enabled); m_pages->Enable(page, enabled);}const wxColour& wxFlatNotebook::GetNonActiveTabTextColour(){ return m_pages->m_nonActiveTextColor;}void wxFlatNotebook::SetNonActiveTabTextColour(const wxColour& color){ m_pages->m_nonActiveTextColor = color;}void wxFlatNotebook::SetTabAreaColour(const wxColour& color){ m_pages->m_tabAreaColor = color;}const wxColour& wxFlatNotebook::GetTabAreaColour(){ return m_pages->m_tabAreaColor;}void wxFlatNotebook::SetActiveTabColour(const wxColour& color){ m_pages->m_activeTabColor = color;}const wxColour& wxFlatNotebook::GetActiveTabColour(){ return m_pages->m_activeTabColor;}/////////////////////////////////////////////////////////////////////////////////////////////// wxPageContainer/////////////////////////////////////////////////////////////////////////////////////////////BEGIN_EVENT_TABLE(wxPageContainer, wxPanel)EVT_PAINT(wxPageContainer::OnPaint)EVT_SIZE(wxPageContainer::OnSize)EVT_LEFT_DOWN(wxPageContainer::OnLeftDown)EVT_LEFT_UP(wxPageContainer::OnLeftUp)EVT_RIGHT_DOWN(wxPageContainer::OnRightDown)EVT_MIDDLE_DOWN(wxPageContainer::OnMiddleDown)EVT_MOTION(wxPageContainer::OnMouseMove)EVT_ERASE_BACKGROUND(wxPageContainer::OnEraseBackground)EVT_LEAVE_WINDOW(wxPageContainer::OnMouseLeave)EVT_ENTER_WINDOW(wxPageContainer::OnMouseEnterWindow)EVT_LEFT_DCLICK(wxPageContainer::OnLeftDClick)END_EVENT_TABLE()wxPageContainer::wxPageContainer(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style): m_ImageList(NULL), m_iActivePage(-1), m_pDropTarget(NULL), m_nLeftClickZone(wxFNB_NOWHERE), m_iPreviousActivePage(-1){ m_pRightClickMenu = NULL; m_nXButtonStatus = wxFNB_BTN_NONE; m_nArrowDownButtonStatus = wxFNB_BTN_NONE; m_pParent = parent; m_nRightButtonStatus = wxFNB_BTN_NONE; m_nLeftButtonStatus = wxFNB_BTN_NONE; m_nTabXButtonStatus = wxFNB_BTN_NONE; m_colorTo = wxColour(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION)); m_colorFrom = wxColor(*wxWHITE); m_activeTabColor = wxColor(*wxWHITE); m_activeTextColor = wxColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT)); m_nonActiveTextColor = wxColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW)); m_tabAreaColor = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE); // Set default page height, this is done according to the system font wxMemoryDC memDc; wxBitmap bmp(10, 10); memDc.SelectObject(bmp); int width, height;#ifdef __WXGTK__ wxFont normalFont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); wxFont boldFont = normalFont; boldFont.SetWeight(wxBOLD); memDc.SetFont( boldFont );#endif memDc.GetTextExtent(wxT("Tp"), &width, &height); int tabHeight = height + wxFNB_HEIGHT_SPACER; // We use 10 pixels as padding wxWindow::Create(parent, id, pos, wxSize(size.x, tabHeight), style | wxNO_BORDER | wxNO_FULL_REPAINT_ON_RESIZE); m_pDropTarget = new wxFNBDropTarget<wxPageContainer>(this, &wxPageContainer::OnDropTarget); SetDropTarget(m_pDropTarget);}wxPageContainer::~wxPageContainer(void){ if(m_pRightClickMenu) { delete m_pRightClickMenu; m_pRightClickMenu = NULL; }}void wxPageContainer::OnPaint(wxPaintEvent & event){ wxBufferedPaintDC dc(this); wxFNBRendererPtr render = wxFNBRendererMgrST::Get()->GetRenderer( GetParent()->GetWindowStyleFlag() ); render->DrawTabs(this, dc, event);}bool wxPageContainer::AddPage(const wxString& caption, const bool selected, const int imgindex){ if(selected) { m_iPreviousActivePage = m_iActivePage; m_iActivePage = (int)m_pagesInfoVec.GetCount(); } /// Create page info and add it to the vector wxPageInfo pageInfo(caption, imgindex); m_pagesInfoVec.Add(pageInfo); Refresh(); return true;}bool wxPageContainer::InsertPage(size_t index, wxWindow* /*page*/, const wxString& text, bool select, const int imgindex){ if(select) { m_iPreviousActivePage = m_iActivePage; m_iActivePage = (int)m_pagesInfoVec.GetCount(); } wxPageInfo pgInfo(text, imgindex);// pgInfo.SetPosition(wxPoint(1, 1)); m_pagesInfoVec.Insert(pgInfo, index); Refresh(); return true;}void wxPageContainer::OnSize(wxSizeEvent& WXUNUSED(event)){ // When resizing the control, try to fit to screen as many tabs as we we can long style = GetParent()->GetWindowStyleFlag(); wxFNBRendererPtr render = wxFNBRendererMgrST::Get()->GetRenderer(style); std::vector<wxRect> vTabInfo; int from = 0; int page = GetSelection(); for(; from<m_nFrom; from++) { vTabInfo.clear(); render->NumberTabsCanFit( this, vTabInfo, from ); if(page - from >= static_cast<int>( vTabInfo.size() )) continue; break; } m_nFrom = from; Refresh(); // Call on paint}void wxPageContainer::OnMiddleDown(wxMouseEvent& event){ // Test if this style is enabled long style = GetParent()->GetWindowStyleFlag(); if(!(style & wxFNB_MOUSE_MIDDLE_CLOSES_TABS)) return; wxPageInfo pgInfo; int tabIdx; int where = HitTest(event.GetPosition(), pgInfo, tabIdx); switch(where) { case wxFNB_TAB: { DeletePage((size_t)tabIdx); break; } default: break; } event.Skip();}void wxPageContainer::OnRightDown(wxMouseEvent& event){ wxPageInfo pgInfo; int tabIdx; int where = HitTest(event.GetPosition(), pgInfo, tabIdx); switch(where) { case wxFNB_TAB: case wxFNB_TAB_X: { if(!m_pagesInfoVec[tabIdx].GetEnabled()) break; // Set the current tab to be active SetSelection((size_t)tabIdx); // If the owner has defined a context menu for the tabs, // popup the right click menu if (m_pRightClickMenu) PopupMenu(m_pRightClickMenu); else { // send a message to popup a custom menu wxFlatNotebookEvent event(wxEVT_COMMAND_FLATNOTEBOOK_CONTEXT_MENU, GetParent()->GetId()); event.SetSelection((int)tabIdx); event.SetOldSelection((int)m_iActivePage); event.SetEventObject(GetParent()); GetParent()->GetEventHandler()->ProcessEvent(event); } } break; default: break; } event.Skip();}void wxPageContainer::OnLeftDown(wxMouseEvent& event){ wxPageInfo pgInfo; int tabIdx; // Reset buttons status m_nXButtonStatus = wxFNB_BTN_NONE; m_nLeftButtonStatus = wxFNB_BTN_NONE; m_nRightButtonStatus = wxFNB_BTN_NONE; m_nTabXButtonStatus = wxFNB_BTN_NONE; m_nArrowDownButtonStatus = wxFNB_BTN_NONE; m_nLeftClickZone = HitTest(event.GetPosition(), pgInfo, tabIdx); switch(m_nLeftClickZone) { case wxFNB_DROP_DOWN_ARROW: m_nArrowDownButtonStatus = wxFNB_BTN_PRESSED; Refresh(); break; case wxFNB_LEFT_ARROW: m_nLeftButtonStatus = wxFNB_BTN_PRESSED; Refresh(); break; case wxFNB_RIGHT_ARROW: m_nRightButtonStatus = wxFNB_BTN_PRESSED; Refresh(); break; case wxFNB_X: m_nXButtonStatus = wxFNB_BTN_PRESSED; Refresh(); break; case wxFNB_TAB_X: m_nTabXButtonStatus = wxFNB_BTN_PRESSED; Refresh(); break; case wxFNB_TAB: { if(m_iActivePage != tabIdx) { // Incase the tab is disabled, we dont allow to choose it if(!m_pagesInfoVec[tabIdx].GetEnabled()) break; SetSelection(tabIdx); } break; } }}void wxPageContainer::OnLeftUp(wxMouseEvent& event){ wxPageInfo pgInfo; int tabIdx; // forget the zone that was initially clicked m_nLeftClickZone = wxFNB_NOWHERE; int where = HitTest(event.GetPosition(), pgInfo, tabIdx); switch(where) { case wxFNB_LEFT_ARROW: { if(m_nFrom == 0) break; // Make sure that the button was pressed before if(m_nLeftButtonStatus != wxFNB_BTN_PRESSED) break; m_nLeftButtonStatus = wxFNB_BTN_HOVER; // We scroll left with bulks of 5 int scrollLeft = GetNumTabsCanScrollLeft(); m_nFrom -= scrollLeft; if(m_nFrom < 0) m_nFrom = 0; Refresh(); break; } case wxFNB_RIGHT_ARROW: { if(m_nFrom >= (int)m_pagesInfoVec.GetCount() - 1) break; // Make sure that the button was pressed before if(m_nRightButtonStatus != wxFNB_BTN_PRESSED) break; m_nRightButtonStatus = wxFNB_BTN_HOVER; // Check if the right most tab is visible, if it is // don't rotate right anymore if(m_pagesInfoVec[m_pagesInfoVec.GetCount()-1].GetPosition() != wxPoint(-1, -1)) break; int lastVisibleTab = GetLastVisibleTab(); if(lastVisibleTab < 0) { // Probably the screen is too small for displaying even a single // tab, in this case we do nothing break; } m_nFrom += GetNumOfVisibleTabs(); Refresh(); break; } case wxFNB_X: { // Make sure that the button was pressed before if(m_nXButtonStatus != wxFNB_BTN_PRESSED) break; m_nXButtonStatus = wxFNB_BTN_HOVER; DeletePage((size_t)m_iActivePage); break; } case wxFNB_TAB_X: { // Make sure that the button was pressed before if(m_nTabXButtonStatus != wxFNB_BTN_PRESSED) break; m_nTabXButtonStatus = wxFNB_BTN_HOVER; DeletePage((size_t)m_iActivePage); break; } case wxFNB_DROP_DOWN_ARROW: { // Make sure that the button was pressed before if(m_nArrowDownButtonStatus != wxFNB_BTN_PRESSED) break; m_nArrowDownButtonStatus = wxFNB_BTN_NONE; // Refresh the button status wxFNBRendererPtr render = wxFNBRendererMgrST::Get()->GetRenderer( GetParent()->GetWindowStyleFlag() ); wxClientDC dc(this); render->DrawDropDownArrow(this, dc); PopupTabsMenu(); break; } }}int wxPageContainer::HitTest(const wxPoint& pt, wxPageInfo& pageInfo, int &tabIdx){ wxFNBRendererPtr render = wxFNBRendererMgrST::Get()->GetRenderer( GetParent()->GetWindowStyleFlag() ); wxRect rect = GetClientRect(); int btnLeftPos = render->GetLeftButtonPos(this); int btnRightPos = render->GetRightButtonPos(this); int btnXPos =render->GetXPos(this); long style = GetParent()->GetWindowStyleFlag(); tabIdx = -1; if(m_pagesInfoVec.IsEmpty()) { return wxFNB_NOWHERE; } rect = wxRect(btnXPos, 8, 16, 16); if(rect.Contains(pt)) { return (style & wxFNB_NO_X_BUTTON) ? wxFNB_NOWHERE : wxFNB_X; } rect = wxRect(btnRightPos, 8, 16, 16); if( style & wxFNB_DROPDOWN_TABS_LIST ) { rect = wxRect(render->GetDropArrowButtonPos( this ), 8, 16, 16); if( rect.Contains(pt) ) return wxFNB_DROP_DOWN_ARROW; } if(rect.Contains(pt)) { return (style & wxFNB_NO_NAV_BUTTONS) ? wxFNB_NOWHERE : wxFNB_RIGHT_ARROW; } rect = wxRect(btnLeftPos, 8, 16, 16); if(rect.Contains(pt)) { return (style & wxFNB_NO_NAV_BUTTONS) ? wxFNB_NOWHERE : wxFNB_LEFT_ARROW; } // Test whether a left click was made on a tab bool bFoundMatch = false; for(size_t cur=m_nFrom; cur<m_pagesInfoVec.GetCount(); cur++) { wxPageInfo pgInfo = m_pagesInfoVec[cur]; if(pgInfo.GetPosition() == wxPoint(-1, -1)) continue; // check for mouse over tab's x button if(style & wxFNB_X_ON_TAB && (int)cur == GetSelection()) { // 'x' button exists on a tab if(m_pagesInfoVec[cur].GetXRect().Contains(pt)) { pageInfo = pgInfo; tabIdx = (int)cur; return wxFNB_TAB_X; } } if(style & wxFNB_VC8) { if(m_pagesInfoVec[cur].GetRegion().Contains(pt) == wxInRegion) { if(bFoundMatch || (int)cur == GetSelection()) { pageInfo = pgInfo; tabIdx = (int)cur; return wxFNB_TAB; } pageInfo = pgInfo; tabIdx = (int)cur; bFoundMatch = true; } } else { wxRect tabRect = wxRect(pgInfo.GetPosition().x, pgInfo.GetPosition().y, pgInfo.GetSize().x, pgInfo.GetSize().y); if(tabRect.Contains(pt)) { // We have a match pageInfo = pgInfo; tabIdx = (int)cur; return wxFNB_TAB; } } } if(bFoundMatch) return wxFNB_TAB; // Default return wxFNB_NOWHERE;}void wxPageContainer::SetSelection(size_t page){ wxFlatNotebook* book = (wxFlatNotebook*)GetParent(); book->SetSelection(page); DoSetSelection(page);}void wxPageContainer::DoSetSelection(size_t page){ // Make sure that the selection is visible if(page < m_pagesInfoVec.GetCount()) { //! fix for tabfocus wxWindow* da_page = ((wxFlatNotebook *)m_pParent)->GetPage(page); if ( da_page!=NULL ) da_page->SetFocus(); } if( !IsTabVisible(page) ) { FNB_LOG_MSG( wxT("Tab ") << (int)page << wxT(" is not visible")); FNB_LOG_MSG( wxT("m_nFrom=") << m_nFrom << wxT(", Selection=") << (int)page ); // Try to remove one tab from start and try again if( !CanFitToScreen(page) ) { if( m_nFrom > (int)page ) m_nFrom = (int)page; else { while( m_nFrom < (int)page ) { m_nFrom++; if( CanFitToScreen(page) ) break; } } FNB_LOG_MSG( wxT("Adjusting m_nFrom to=") << m_nFrom); } } else { FNB_LOG_MSG( wxT("Tab ") << (int)page << wxT(" is visible")); } Refresh();}void wxPageContainer::DeletePage(size_t page){ wxFlatNotebook* book = (wxFlatNotebook*)GetParent(); book->DeletePage(page); book->Refresh();}bool wxPageContainer::IsTabVisible(size_t page){ int iPage = (int)page;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -