git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@29175
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
class WXDLLEXPORT wxChoice;
class WXDLLEXPORT wxChoice;
-// ----------------------------------------------------------------------------
-// constants
-// ----------------------------------------------------------------------------
-
-// wxChoicebook styles
-enum
-{
- // default alignment: top everywhere
- wxCHB_DEFAULT = 0,
-
- // put the choice control to the left/right/top/bottom of the page area
- wxCHB_TOP = 0x1,
- wxCHB_BOTTOM = 0x2,
- wxCHB_LEFT = 0x4,
- wxCHB_RIGHT = 0x8,
-
- // the mask which can be used to extract the alignment from the style
- wxCHB_ALIGN_MASK = 0xf
-};
-
// ----------------------------------------------------------------------------
// wxChoicebook
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// wxChoicebook
// ----------------------------------------------------------------------------
protected:
virtual wxWindow *DoRemovePage(size_t page);
protected:
virtual wxWindow *DoRemovePage(size_t page);
-private:
- // common part of all constructors
- void Init();
-
// get the size which the choice control should have
wxSize GetChoiceSize() const;
// get the size which the choice control should have
wxSize GetChoiceSize() const;
void OnSize(wxSizeEvent& event);
void OnChoiceSelected(wxCommandEvent& event);
void OnSize(wxSizeEvent& event);
void OnChoiceSelected(wxCommandEvent& event);
// the choice control we use for showing the pages index
wxChoice *m_choice;
// the currently selected page or wxNOT_FOUND if none
int m_selection;
// the choice control we use for showing the pages index
wxChoice *m_choice;
// the currently selected page or wxNOT_FOUND if none
int m_selection;
+private:
+ // common part of all constructors
+ void Init();
DECLARE_EVENT_TABLE()
DECLARE_DYNAMIC_CLASS_NO_COPY(wxChoicebook)
DECLARE_EVENT_TABLE()
DECLARE_DYNAMIC_CLASS_NO_COPY(wxChoicebook)
DECLARE_EVENT_TABLE_ENTRY( \
wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED, \
id, \
DECLARE_EVENT_TABLE_ENTRY( \
wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED, \
id, \
(wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxChoicebookEventFunction, &fn ), \
NULL \
),
#define EVT_CHOICEBOOK_PAGE_CHANGING(id, fn) \
DECLARE_EVENT_TABLE_ENTRY( \
(wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxChoicebookEventFunction, &fn ), \
NULL \
),
#define EVT_CHOICEBOOK_PAGE_CHANGING(id, fn) \
DECLARE_EVENT_TABLE_ENTRY( \
- wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING, \
+ wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING, \
(wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxChoicebookEventFunction, &fn ), \
NULL \
),
(wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxChoicebookEventFunction, &fn ), \
NULL \
),
#define wxNB_RIGHT 0x0040
#define wxNB_BOTTOM 0x0080
#define wxNB_MULTILINE 0x0100
#define wxNB_RIGHT 0x0040
#define wxNB_BOTTOM 0x0080
#define wxNB_MULTILINE 0x0100
+#define wxNB_DEFAULT wxNB_TOP
+
+/*
+ * wxListbook flags
+ */
+#define wxLB_DEFAULT 0x0
+#define wxLB_TOP 0x1
+#define wxLB_BOTTOM 0x2
+#define wxLB_LEFT 0x4
+#define wxLB_RIGHT 0x8
+#define wxLB_ALIGN_MASK 0xf
+
+/*
+ * wxChoicebook flags
+ */
+#define wxCHB_DEFAULT 0x0
+#define wxCHB_TOP 0x1
+#define wxCHB_BOTTOM 0x2
+#define wxCHB_LEFT 0x4
+#define wxCHB_RIGHT 0x8
+#define wxCHB_ALIGN_MASK 0xf
class WXDLLEXPORT wxStaticLine;
#endif // wxUSE_LINE_IN_LISTBOOK
class WXDLLEXPORT wxStaticLine;
#endif // wxUSE_LINE_IN_LISTBOOK
-// ----------------------------------------------------------------------------
-// constants
-// ----------------------------------------------------------------------------
-
-// wxListbook styles
-enum
-{
- // default alignment: left everywhere except Mac where it is top
- wxLB_DEFAULT = 0,
-
- // put the list control to the left/right/top/bottom of the page area
- wxLB_TOP = 0x1,
- wxLB_BOTTOM = 0x2,
- wxLB_LEFT = 0x4,
- wxLB_RIGHT = 0x8,
-
- // the mask which can be used to extract the alignment from the style
- wxLB_ALIGN_MASK = 0xf
-};
-
// ----------------------------------------------------------------------------
// wxListbook
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// wxListbook
// ----------------------------------------------------------------------------
{
public:
wxListbookEvent(wxEventType commandType = wxEVT_NULL, int id = 0,
{
public:
wxListbookEvent(wxEventType commandType = wxEVT_NULL, int id = 0,
- int nSel = -1, int nOldSel = -1)
+ int nSel = wxNOT_FOUND, int nOldSel = wxNOT_FOUND)
: wxBookCtrlEvent(commandType, id, nSel, nOldSel)
{
}
: wxBookCtrlEvent(commandType, id, nSel, nOldSel)
{
}
DECLARE_EVENT_TABLE_ENTRY( \
wxEVT_COMMAND_LISTBOOK_PAGE_CHANGED, \
id, \
DECLARE_EVENT_TABLE_ENTRY( \
wxEVT_COMMAND_LISTBOOK_PAGE_CHANGED, \
id, \
(wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxListbookEventFunction, &fn ), \
NULL \
),
(wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxListbookEventFunction, &fn ), \
NULL \
),
DECLARE_EVENT_TABLE_ENTRY( \
wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING, \
id, \
DECLARE_EVENT_TABLE_ENTRY( \
wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING, \
id, \
(wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxListbookEventFunction, &fn ), \
NULL \
),
(wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxListbookEventFunction, &fn ), \
NULL \
),
m_choice->Move(posChoice.x, posChoice.y);
m_choice->SetSize(sizeChoice.x, sizeChoice.y);
m_choice->Move(posChoice.x, posChoice.y);
m_choice->SetSize(sizeChoice.x, sizeChoice.y);
- // we should always have some selection if possible
- if ( m_selection == wxNOT_FOUND && GetPageCount() )
- {
- SetSelection(0);
- }
-
+ // resize the currently shown page
if ( m_selection != wxNOT_FOUND )
{
wxWindow *page = m_pages[m_selection];
wxCHECK_RET( page, _T("NULL page in wxChoicebook?") );
if ( m_selection != wxNOT_FOUND )
{
wxWindow *page = m_pages[m_selection];
wxCHECK_RET( page, _T("NULL page in wxChoicebook?") );
page->SetSize(GetPageRect());
page->SetSize(GetPageRect());
- if ( !page->IsShown() )
- {
- page->Show();
- }
wxCHECK_MSG( n < GetPageCount(), wxNOT_FOUND,
_T("invalid page index in wxChoicebook::SetSelection()") );
wxCHECK_MSG( n < GetPageCount(), wxNOT_FOUND,
_T("invalid page index in wxChoicebook::SetSelection()") );
- int selOld = m_selection;
+ const int selOld = m_selection;
if ( (int)n != m_selection )
{
if ( (int)n != m_selection )
{
- m_choice->Select(n);
-
- // change m_selection only now, otherwise OnChoiceSelected() would ignore
- // the selection change event
-
if ( m_selection != wxNOT_FOUND )
m_pages[m_selection]->Hide();
if ( m_selection != wxNOT_FOUND )
m_pages[m_selection]->Hide();
- wxWindow *page = m_pages[m_selection = n];
+ wxWindow *page = m_pages[n];
page->SetSize(GetPageRect());
page->Show();
page->SetSize(GetPageRect());
page->Show();
+
+ // change m_selection only now to ignore the selection change event
+ m_selection = n;
+ m_choice->Select(n);
// ----------------------------------------------------------------------------
// adding/removing the pages
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// adding/removing the pages
// ----------------------------------------------------------------------------
m_choice->Insert(text, n);
m_choice->Insert(text, n);
+ // we should always have some selection if possible
+ if ( bSelect || (m_selection == wxNOT_FOUND) )
}
else // don't select this page
{
}
else // don't select this page
{
wxWindow *wxChoicebook::DoRemovePage(size_t page)
{
wxWindow *wxChoicebook::DoRemovePage(size_t page)
{
+ const int page_count = GetPageCount();
wxWindow *win = wxBookCtrl::DoRemovePage(page);
wxWindow *win = wxBookCtrl::DoRemovePage(page);
if ( win )
{
m_choice->Delete(page);
if ( win )
{
m_choice->Delete(page);
+
+ if (m_selection >= (int)page)
+ {
+ // force new sel valid if possible
+ int sel = m_selection - 1;
+ if (page_count == 1)
+ sel = wxNOT_FOUND;
+ else if ((page_count == 2) || (sel == -1))
+ sel = 0;
+
+ // force sel invalid if deleting current page - don't try to hide it
+ m_selection = (m_selection == (int)page) ? wxNOT_FOUND : m_selection - 1;
+
+ if ((sel != wxNOT_FOUND) && (sel != m_selection))
+ SetSelection(sel);
+ }
void wxChoicebook::OnChoiceSelected(wxCommandEvent& eventChoice)
{
const int selNew = eventChoice.GetSelection();
void wxChoicebook::OnChoiceSelected(wxCommandEvent& eventChoice)
{
const int selNew = eventChoice.GetSelection();
+ const int selOld = m_selection;
if ( selNew == m_selection )
{
if ( selNew == m_selection )
{
eventIng.SetEventObject(this);
eventIng.SetSelection(selNew);
eventIng.SetEventObject(this);
eventIng.SetSelection(selNew);
- eventIng.SetOldSelection(m_selection);
+ eventIng.SetOldSelection(selOld);
if ( GetEventHandler()->ProcessEvent(eventIng) && !eventIng.IsAllowed() )
{
m_choice->Select(m_selection);
if ( GetEventHandler()->ProcessEvent(eventIng) && !eventIng.IsAllowed() )
{
m_choice->Select(m_selection);
}
// change allowed: do change the page and notify the user about it
}
// change allowed: do change the page and notify the user about it
- if ( m_selection != wxNOT_FOUND )
- m_pages[m_selection]->Hide();
- wxWindow *page = m_pages[m_selection = selNew];
- page->SetSize(GetPageRect());
- page->Show();
wxChoicebookEvent eventEd(wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED, GetId());
eventEd.SetEventObject(this);
eventEd.SetSelection(selNew);
wxChoicebookEvent eventEd(wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED, GetId());
eventEd.SetEventObject(this);
eventEd.SetSelection(selNew);
- eventEd.SetOldSelection(m_selection);
+ eventEd.SetOldSelection(selOld);
(void)GetEventHandler()->ProcessEvent(eventEd);
}
(void)GetEventHandler()->ProcessEvent(eventEd);
}
// change m_selection only now to ignore the selection change event
m_selection = n;
// change m_selection only now to ignore the selection change event
m_selection = n;
{
const int page_count = GetPageCount();
wxWindow *win = wxBookCtrl::DoRemovePage(page);
{
const int page_count = GetPageCount();
wxWindow *win = wxBookCtrl::DoRemovePage(page);
if ( win )
{
m_list->DeleteItem(page);
if ( win )
{
m_list->DeleteItem(page);
// force new sel valid if possible
int sel = m_selection - 1;
if (page_count == 1)
// force new sel valid if possible
int sel = m_selection - 1;
if (page_count == 1)
else if ((page_count == 2) || (sel == -1))
sel = 0;
else if ((page_count == 2) || (sel == -1))
sel = 0;
// force sel invalid if deleting current page - don't try to hide it
// force sel invalid if deleting current page - don't try to hide it
- m_selection = (m_selection == (int)page) ? -1 : m_selection - 1;
-
- if ((sel != -1) && (sel != m_selection))
+ m_selection = (m_selection == (int)page) ? wxNOT_FOUND : m_selection - 1;
+
+ if ((sel != wxNOT_FOUND) && (sel != m_selection))