X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/43427087aa140b594865282adffaa1cfcc045d13..c6e62f74fcac5b62889b59e7ce7a41d0ce884d7b:/src/msw/notebook.cpp diff --git a/src/msw/notebook.cpp b/src/msw/notebook.cpp index 8c8e75e196..43b70d1dbb 100644 --- a/src/msw/notebook.cpp +++ b/src/msw/notebook.cpp @@ -22,16 +22,16 @@ // wxWindows #ifndef WX_PRECOMP - #include + #include "wx/string.h" #endif // WX_PRECOMP -#include -#include -#include -#include -#include +#include "wx/log.h" +#include "wx/imaglist.h" +#include "wx/event.h" +#include "wx/control.h" +#include "wx/notebook.h" -#include +#include "wx/msw/private.h" // Windows standard headers #ifndef __WIN95__ @@ -62,11 +62,27 @@ // hide the ugly cast #define m_hwnd (HWND)GetHWND() +// ---------------------------------------------------------------------------- +// constants +// ---------------------------------------------------------------------------- + +// This is a work-around for missing defines in gcc-2.95 headers +#ifndef TCS_RIGHT + #define TCS_RIGHT 0x0002 +#endif + +#ifndef TCS_VERTICAL + #define TCS_VERTICAL 0x0080 +#endif + +#ifndef TCS_BOTTOM + #define TCS_BOTTOM TCS_RIGHT +#endif + // ---------------------------------------------------------------------------- // event table // ---------------------------------------------------------------------------- -#if !USE_SHARED_LIBRARIES BEGIN_EVENT_TABLE(wxNotebook, wxControl) EVT_NOTEBOOK_PAGE_CHANGED(-1, wxNotebook::OnSelChange) @@ -79,7 +95,6 @@ IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxControl) IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxNotifyEvent) -#endif // ============================================================================ // implementation @@ -144,6 +159,13 @@ bool wxNotebook::Create(wxWindow *parent, tabStyle &= WS_BORDER; if (m_windowStyle & wxNB_FIXEDWIDTH) tabStyle |= TCS_FIXEDWIDTH ; + if (m_windowStyle & wxNB_BOTTOM) + tabStyle |= TCS_RIGHT; + if (m_windowStyle & wxNB_LEFT) + tabStyle |= TCS_VERTICAL; + if (m_windowStyle & wxNB_RIGHT) + tabStyle |= TCS_VERTICAL|TCS_RIGHT; + if ( !MSWCreate(GetId(), GetParent(), WC_TABCONTROL, this, NULL, pos.x, pos.y, size.x, size.y, @@ -188,7 +210,7 @@ int wxNotebook::GetRowCount() const int wxNotebook::SetSelection(int nPage) { - wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, _T("notebook page out of range") ); + wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, wxT("notebook page out of range") ); ChangePage(m_nSelection, nPage); @@ -207,7 +229,7 @@ void wxNotebook::AdvanceSelection(bool bForward) bool wxNotebook::SetPageText(int nPage, const wxString& strText) { - wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, _T("notebook page out of range") ); + wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, wxT("notebook page out of range") ); TC_ITEM tcItem; tcItem.mask = TCIF_TEXT; @@ -218,7 +240,7 @@ bool wxNotebook::SetPageText(int nPage, const wxString& strText) wxString wxNotebook::GetPageText(int nPage) const { - wxCHECK_MSG( IS_VALID_PAGE(nPage), _T(""), _T("notebook page out of range") ); + wxCHECK_MSG( IS_VALID_PAGE(nPage), wxT(""), wxT("notebook page out of range") ); wxChar buf[256]; TC_ITEM tcItem; @@ -235,7 +257,7 @@ wxString wxNotebook::GetPageText(int nPage) const int wxNotebook::GetPageImage(int nPage) const { - wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, _T("notebook page out of range") ); + wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, wxT("notebook page out of range") ); TC_ITEM tcItem; tcItem.mask = TCIF_IMAGE; @@ -245,7 +267,7 @@ int wxNotebook::GetPageImage(int nPage) const bool wxNotebook::SetPageImage(int nPage, int nImage) { - wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, _T("notebook page out of range") ); + wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, wxT("notebook page out of range") ); TC_ITEM tcItem; tcItem.mask = TCIF_IMAGE; @@ -275,7 +297,7 @@ void wxNotebook::SetTabSize(const wxSize& sz) // remove one page from the notebook bool wxNotebook::DeletePage(int nPage) { - wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, _T("notebook page out of range") ); + wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, wxT("notebook page out of range") ); if ( m_nSelection == nPage ) { // advance selection backwards - the page being deleted shouldn't be left @@ -292,6 +314,9 @@ bool wxNotebook::DeletePage(int nPage) // no selection if the notebook became empty m_nSelection = -1; } + else + m_nSelection = TabCtrl_GetCurSel(m_hwnd); + return TRUE; } @@ -299,12 +324,17 @@ bool wxNotebook::DeletePage(int nPage) // remove one page from the notebook, without deleting bool wxNotebook::RemovePage(int nPage) { - wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, _T("notebook page out of range") ); + wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, wxT("notebook page out of range") ); TabCtrl_DeleteItem(m_hwnd, nPage); m_aPages.Remove(nPage); + if ( m_aPages.IsEmpty() ) + m_nSelection = -1; + else + m_nSelection = TabCtrl_GetCurSel(m_hwnd); + return TRUE; } @@ -320,6 +350,8 @@ bool wxNotebook::DeleteAllPages() TabCtrl_DeleteAllItems(m_hwnd); + m_nSelection = -1; + return TRUE; } @@ -361,7 +393,7 @@ bool wxNotebook::InsertPage(int nPage, } if ( TabCtrl_InsertItem(m_hwnd, nPage, &tcItem) == -1 ) { - wxLogError(_T("Can't create the notebook page '%s'."), strText.c_str()); + wxLogError(wxT("Can't create the notebook page '%s'."), strText.c_str()); return FALSE; } @@ -384,6 +416,14 @@ bool wxNotebook::InsertPage(int nPage, // this updates internal flag too - otherwise it will get out of sync pPage->Show(FALSE); + // fit the notebook page to the tab control's display area + RECT rc; + rc.left = rc.top = 0; + GetSize((int *)&rc.right, (int *)&rc.bottom); + TabCtrl_AdjustRect(m_hwnd, FALSE, &rc); + pPage->SetSize(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top); + + // some page should be selected: either this one or the first one if there is // still no selection int selNew = -1; @@ -414,8 +454,6 @@ void wxNotebook::OnSize(wxSizeEvent& event) for ( size_t nPage = 0; nPage < nCount; nPage++ ) { wxNotebookPage *pPage = m_aPages[nPage]; pPage->SetSize(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top); - if ( pPage->GetAutoLayout() ) - pPage->Layout(); } event.Skip(); @@ -429,7 +467,7 @@ void wxNotebook::OnSelChange(wxNotebookEvent& event) int sel = event.GetOldSelection(); if ( sel != -1 ) m_aPages[sel]->Show(FALSE); - + sel = event.GetSelection(); if ( sel != -1 ) { @@ -437,7 +475,7 @@ void wxNotebook::OnSelChange(wxNotebookEvent& event) pPage->Show(TRUE); pPage->SetFocus(); } - + m_nSelection = sel; }