+ // fit the notebook page to the tab control's display area: this should be
+ // done before adding it to the notebook or TabCtrl_InsertItem() will
+ // change the notebooks size itself!
+ 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);
+
+
+ // finally do insert it
+ if ( TabCtrl_InsertItem(m_hwnd, nPage, &tcItem) == -1 ) {
+ wxLogError(wxT("Can't create the notebook page '%s'."), strText.c_str());
+
+ return FALSE;
+ }
+
+ // succeeded: save the pointer to the page
+ m_pages.Insert(pPage, nPage);
+
+ // hide the page: unless it is selected, it shouldn't be shown (and if it
+ // is selected it will be shown later)
+ HWND hwnd = GetWinHwnd(pPage);
+ SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_VISIBLE);
+
+ // this updates internal flag too -- otherwise it would get out of sync
+ // with the real state
+ pPage->Show(FALSE);
+
+
+ // now deal with the selection
+ // ---------------------------
+
+ // if the inserted page is before the selected one, we must update the
+ // index of the selected page
+ if ( nPage <= m_nSelection )
+ {
+ // one extra page added
+ m_nSelection++;
+ }
+
+ // some page should be selected: either this one or the first one if there
+ // is still no selection
+ int selNew = -1;
+ if ( bSelect )
+ selNew = nPage;
+ else if ( m_nSelection == -1 )
+ selNew = 0;
+
+ if ( selNew != -1 )
+ SetSelection(selNew);
+
+ return TRUE;