]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/notebook.cpp
More key event work. Added SetDetectableAutoRepeat.
[wxWidgets.git] / src / msw / notebook.cpp
index 07112916d4027cb94628c5e7972d84ce9118e1b5..eed57498e9bc3df494b873884fe2d8254a0f5c1b 100644 (file)
@@ -2,7 +2,7 @@
 // Name:        msw/notebook.cpp
 // Purpose:     implementation of wxNotebook
 // Author:      Vadim Zeitlin
-// Modified by: 
+// Modified by:
 // Created:     11.06.98
 // RCS-ID:      $Id$
 // Copyright:   (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
@@ -134,10 +134,15 @@ bool wxNotebook::Create(wxWindow *parent,
   m_windowStyle = style | wxTAB_TRAVERSAL;
 
   long tabStyle = WS_CHILD | WS_VISIBLE | WS_TABSTOP | TCS_TABS;
+
+  if (m_windowStyle & wxCLIP_CHILDREN)
+    tabStyle |= WS_CLIPCHILDREN;
   if ( m_windowStyle & wxTC_MULTILINE )
     tabStyle |= TCS_MULTILINE;
   if ( m_windowStyle & wxBORDER )
     tabStyle &= WS_BORDER;
+  if (m_windowStyle & wxNB_FIXEDWIDTH)
+    tabStyle |= TCS_FIXEDWIDTH ;
 
   // create the tab control.
   m_hWnd = (WXHWND)CreateWindowEx
@@ -164,9 +169,9 @@ bool wxNotebook::Create(wxWindow *parent,
                   (WPARAM)::GetStockObject(DEFAULT_GUI_FONT),TRUE);
 
 
-  if ( parent != NULL ) 
+  if ( parent != NULL )
     parent->AddChild(this);
-  
+
   SubclassWin(m_hWnd);
 
   return TRUE;
@@ -262,7 +267,7 @@ bool wxNotebook::SetPageImage(int nPage, int nImage)
 }
 
 void wxNotebook::SetImageList(wxImageList* imageList)
-{ 
+{
   m_pImageList = imageList;
   TabCtrl_SetImageList(m_hwnd, (HIMAGELIST)imageList->GetHIMAGELIST());
 }
@@ -299,8 +304,6 @@ bool wxNotebook::RemovePage(int nPage)
 // remove all pages
 bool wxNotebook::DeleteAllPages()
 {
-  TabCtrl_DeleteAllItems(m_hwnd);
-
   int nPageCount = GetPageCount();
   int nPage;
   for ( nPage = 0; nPage < nPageCount; nPage++ )
@@ -308,6 +311,8 @@ bool wxNotebook::DeleteAllPages()
 
   m_aPages.Clear();
 
+  TabCtrl_DeleteAllItems(m_hwnd);
+
   return TRUE;
 }
 
@@ -332,9 +337,23 @@ bool wxNotebook::InsertPage(int nPage,
 
   // add the tab to the control
   TC_ITEM tcItem;
-  tcItem.mask    = TCIF_TEXT | TCIF_IMAGE;
-  tcItem.pszText = (char *)strText.c_str();
-  tcItem.iImage  = imageId;
+  tcItem.mask    = 0;
+
+  if (imageId != -1)
+  {
+    tcItem.mask |= TCIF_IMAGE;
+    tcItem.iImage  = imageId;
+  }
+  else
+    tcItem.iImage  = 0;
+
+  if (!strText.IsEmpty())
+  {
+    tcItem.mask    |= TCIF_TEXT;
+    tcItem.pszText = (char *)strText.c_str();
+  }
+  else
+    tcItem.pszText = (char *) NULL;
 
   if ( TabCtrl_InsertItem(m_hwnd, nPage, &tcItem) == -1 ) {
     wxLogError("Can't create the notebook page '%s'.", strText.c_str());
@@ -344,7 +363,7 @@ bool wxNotebook::InsertPage(int nPage,
   // save the pointer to the page
   m_aPages.Insert(pPage, nPage);
 
-  // some page must be selected: either this one or the first one if there is 
+  // some page must be selected: either this one or the first one if there is
   // still no selection
   if ( bSelect )
     m_nSelection = nPage;
@@ -364,11 +383,13 @@ bool wxNotebook::InsertPage(int nPage,
 
 void wxNotebook::OnSize(wxSizeEvent& event)
 {
-  // emulate page change (it's esp. important to do it first time because
-  // otherwise our page would stay invisible)
-  int nSel = m_nSelection;
-  m_nSelection = -1;
-  SetSelection(nSel);
+  // make sure the current page is shown and has focus (it's useful because all
+  // pages are created invisible initially)
+  if ( m_nSelection != -1 ) {
+    wxNotebookPage *pPage = m_aPages[m_nSelection];
+    pPage->Show(TRUE);
+    pPage->SetFocus();
+  }
 
   // fit the notebook page to the tab control's display area
   RECT rc;
@@ -443,7 +464,7 @@ void wxNotebook::Command(wxCommandEvent& event)
   wxFAIL_MSG("wxNotebook::Command not implemented");
 }
 
-bool wxNotebook::MSWNotify(WXWPARAM wParam, WXLPARAM lParam, WXLPARAM* result)
+bool wxNotebook::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM* result)
 {
   wxNotebookEvent event(wxEVT_NULL, m_windowId);
 
@@ -458,13 +479,13 @@ bool wxNotebook::MSWNotify(WXWPARAM wParam, WXLPARAM lParam, WXLPARAM* result)
       break;
 
     default:
-      return wxControl::MSWNotify(wParam, lParam, result);
+      return wxControl::MSWOnNotify(idCtrl, lParam, result);
   }
 
   event.SetSelection(TabCtrl_GetCurSel(m_hwnd));
   event.SetOldSelection(m_nSelection);
   event.SetEventObject(this);
-  event.SetInt(LOWORD(wParam)); // ctrl id
+  event.SetInt(idCtrl);
 
   bool processed = GetEventHandler()->ProcessEvent(event);
   *result = !event.IsAllowed();
@@ -523,3 +544,10 @@ void wxNotebook::OnEraseBackground(wxEraseEvent& event)
     Default();
 }
 
+// Windows-only at present. Also, you must use the wxNB_FIXEDWIDTH
+// style.
+void wxNotebook::SetTabSize(const wxSize& sz)
+{
+    ::SendMessage((HWND) GetHWND(), TCM_SETITEMSIZE, 0, MAKELPARAM(sz.x, sz.y));
+}
+