]> git.saurik.com Git - wxWidgets.git/commitdiff
implemented wxAUI_NB_WINDOWLIST_BUTTON and wxAUI_NB_SCROLL_BUTTONS in wxAuiNotebook
authorBenjamin Williams <bwilliams@kirix.com>
Thu, 2 Nov 2006 20:27:38 +0000 (20:27 +0000)
committerBenjamin Williams <bwilliams@kirix.com>
Thu, 2 Nov 2006 20:27:38 +0000 (20:27 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42960 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/aui/auibook.h
include/wx/aui/framemanager.h
samples/aui/auidemo.cpp
src/aui/auibook.cpp

index cea4e8a901ad8ce49da56cfe29807a8d11074f02..2bdd0200710de27f5b021090e3e47402390ee265 100644 (file)
@@ -37,7 +37,7 @@ enum wxAuiNotebookOption
     wxAUI_NB_TAB_SPLIT           = 1 << 4,
     wxAUI_NB_TAB_MOVE            = 1 << 5,
     wxAUI_NB_SCROLL_BUTTONS      = 1 << 6,
-    wxAUI_NB_PAGELIST_BUTTON     = 1 << 7,
+    wxAUI_NB_WINDOWLIST_BUTTON   = 1 << 7,
     wxAUI_NB_CLOSE_BUTTON        = 1 << 8,
     wxAUI_NB_CLOSE_ON_ACTIVE_TAB = 1 << 9,
     wxAUI_NB_CLOSE_ON_ALL_TABS   = 1 << 10,
@@ -68,9 +68,11 @@ public:
 
     virtual void DrawBackground(
                          wxDC* dc,
+                         wxWindow* wnd,
                          const wxRect& rect) = 0;
 
     virtual void DrawTab(wxDC* dc,
+                         wxWindow* wnd,
                          const wxRect& in_rect,
                          const wxString& caption,
                          bool active,
@@ -81,21 +83,28 @@ public:
     
     virtual void DrawButton(
                          wxDC* dc,
+                         wxWindow* wnd,
                          const wxRect& in_rect,
                          int bitmap_id,
                          int button_state,
                          int orientation,
                          const wxBitmap& bitmap_override,
                          wxRect* out_rect) = 0;
+    
+    virtual int ShowWindowList(
+                         wxWindow* wnd,
+                         const wxArrayString& items,
+                         int active_idx) = 0;
                  
     virtual wxSize GetTabSize(
                          wxDC* dc,
+                         wxWindow* wnd,
                          const wxString& caption,
                          bool active,
                          int close_button_state,
                          int* x_extent) = 0;
-                         
-    virtual int GetBestTabCtrlSize(wxWindow* wnd) = 0;      
+    
+    virtual int GetBestTabCtrlSize(wxWindow* wnd) = 0;    
 };
 
 
@@ -107,15 +116,18 @@ public:
     wxAuiDefaultTabArt();
     virtual ~wxAuiDefaultTabArt();
     
+    void SetWindow(wxWindow* wnd);
     void SetNormalFont(const wxFont& font);
     void SetSelectedFont(const wxFont& font);
     void SetMeasuringFont(const wxFont& font);
     
     void DrawBackground(
                  wxDC* dc,
+                 wxWindow* wnd,
                  const wxRect& rect);
 
     void DrawTab(wxDC* dc,
+                 wxWindow* wnd,
                  const wxRect& in_rect,
                  const wxString& caption,
                  bool active,
@@ -126,6 +138,7 @@ public:
     
     void DrawButton(
                  wxDC* dc,
+                 wxWindow* wnd,
                  const wxRect& in_rect,
                  int bitmap_id,
                  int button_state,
@@ -133,14 +146,20 @@ public:
                  const wxBitmap& bitmap_override,
                  wxRect* out_rect);
     
+    int ShowWindowList(
+                 wxWindow* wnd,
+                 const wxArrayString& items,
+                 int active_idx);
+
     wxSize GetTabSize(
                  wxDC* dc,
+                 wxWindow* wnd,
                  const wxString& caption,
                  bool active,
                  int close_button_state,
                  int* x_extent);
     
-    int GetBestTabCtrlSize(wxWindow* wnd);
+    int GetBestTabCtrlSize(wxWindow* wnd);    
 
 private:
 
@@ -158,6 +177,8 @@ private:
     wxBitmap m_disabled_left_bmp;
     wxBitmap m_active_right_bmp;
     wxBitmap m_disabled_right_bmp;
+    wxBitmap m_active_windowlist_bmp;
+    wxBitmap m_disabled_windowlist_bmp;
 };
 
 
@@ -274,9 +295,9 @@ public:
     
 protected:
 
-    virtual void Render(wxDC* dc);
+    virtual void Render(wxDC* dc, wxWindow* wnd);
 
-private:
+protected:
 
     wxAuiTabArt* m_art;
     wxAuiNotebookPageArray m_pages;
index 9ae5e5e7365f4c518a3c484e11745a70548fe632..9e611bb4b4947a1db140df645b9c5e34f3fcda77 100644 (file)
@@ -99,10 +99,11 @@ enum wxAuiButtonId
     wxAUI_BUTTON_MINIMIZE = 103,
     wxAUI_BUTTON_PIN = 104,
     wxAUI_BUTTON_OPTIONS = 105,
-    wxAUI_BUTTON_LEFT = 106,
-    wxAUI_BUTTON_RIGHT = 107,
-    wxAUI_BUTTON_UP = 108,
-    wxAUI_BUTTON_DOWN = 109,
+    wxAUI_BUTTON_WINDOWLIST = 106,
+    wxAUI_BUTTON_LEFT = 107,
+    wxAUI_BUTTON_RIGHT = 108,
+    wxAUI_BUTTON_UP = 109,
+    wxAUI_BUTTON_DOWN = 110,
     wxAUI_BUTTON_CUSTOM1 = 201,
     wxAUI_BUTTON_CUSTOM2 = 202,
     wxAUI_BUTTON_CUSTOM3 = 203
index d036cf2e20a04ce553f924df8160ecce47e10710..26f2df5d127a8b7b204326bb3de305247f69a3ff 100644 (file)
@@ -90,6 +90,8 @@ class MyFrame : public wxFrame
         ID_NotebookCloseButtonActive,
         ID_NotebookAllowTabMove,
         ID_NotebookAllowTabSplit,
+        ID_NotebookWindowList,
+        ID_NotebookScrollButtons,
         ID_FirstPerspective = ID_CreatePerspective+1000
     };
 
@@ -574,6 +576,8 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
     EVT_MENU(ID_NotebookCloseButtonActive, MyFrame::OnNotebookFlag)
     EVT_MENU(ID_NotebookAllowTabMove, MyFrame::OnNotebookFlag)
     EVT_MENU(ID_NotebookAllowTabSplit, MyFrame::OnNotebookFlag)
+    EVT_MENU(ID_NotebookScrollButtons, MyFrame::OnNotebookFlag)
+    EVT_MENU(ID_NotebookWindowList, MyFrame::OnNotebookFlag)
     EVT_MENU(ID_NoGradient, MyFrame::OnGradient)
     EVT_MENU(ID_VerticalGradient, MyFrame::OnGradient)
     EVT_MENU(ID_HorizontalGradient, MyFrame::OnGradient)
@@ -592,6 +596,8 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
     EVT_UPDATE_UI(ID_NotebookCloseButtonActive, MyFrame::OnUpdateUI)
     EVT_UPDATE_UI(ID_NotebookAllowTabMove, MyFrame::OnUpdateUI)
     EVT_UPDATE_UI(ID_NotebookAllowTabSplit, MyFrame::OnUpdateUI)
+    EVT_UPDATE_UI(ID_NotebookScrollButtons, MyFrame::OnUpdateUI)
+    EVT_UPDATE_UI(ID_NotebookWindowList, MyFrame::OnUpdateUI)
     EVT_UPDATE_UI(ID_AllowFloating, MyFrame::OnUpdateUI)
     EVT_UPDATE_UI(ID_TransparentHint, MyFrame::OnUpdateUI)
     EVT_UPDATE_UI(ID_VenetianBlindsHint, MyFrame::OnUpdateUI)
@@ -672,6 +678,8 @@ MyFrame::MyFrame(wxWindow* parent,
     notebook_menu->AppendSeparator();
     notebook_menu->AppendCheckItem(ID_NotebookAllowTabMove, _("Allow Tab Move"));
     notebook_menu->AppendCheckItem(ID_NotebookAllowTabSplit, _("Allow Notebook Split"));
+    notebook_menu->AppendCheckItem(ID_NotebookScrollButtons, _("Scroll Buttons Visible"));
+    notebook_menu->AppendCheckItem(ID_NotebookWindowList, _("Window List Button Visible"));
 
     m_perspectives_menu = new wxMenu;
     m_perspectives_menu->Append(ID_CreatePerspective, _("Create Perspective"));
@@ -1034,11 +1042,18 @@ void MyFrame::OnNotebookFlag(wxCommandEvent& event)
     {
         m_notebook_style ^= wxAUI_NB_TAB_MOVE;
     }
-    
-    if (id == ID_NotebookAllowTabSplit)
+     else if (id == ID_NotebookAllowTabSplit)
     {
         m_notebook_style ^= wxAUI_NB_TAB_SPLIT;
     }
+     else if (id == ID_NotebookWindowList)
+    {
+        m_notebook_style ^= wxAUI_NB_WINDOWLIST_BUTTON;
+    }
+     else if (id == ID_NotebookScrollButtons)
+    {
+        m_notebook_style ^= wxAUI_NB_SCROLL_BUTTONS;
+    }
         
         
         
@@ -1119,6 +1134,12 @@ void MyFrame::OnUpdateUI(wxUpdateUIEvent& event)
         case ID_NotebookAllowTabMove:
             event.Check((m_notebook_style & wxAUI_NB_TAB_MOVE) != 0);
             break;
+        case ID_NotebookScrollButtons:
+            event.Check((m_notebook_style & wxAUI_NB_SCROLL_BUTTONS) != 0);
+            break;
+        case ID_NotebookWindowList:
+            event.Check((m_notebook_style & wxAUI_NB_WINDOWLIST_BUTTON) != 0);
+            break;
     }
 }
 
index 0df4995c4fc167b2b9f2c7305b47695516ef1abb..30d2129b827efa2823556cbd9c0ac87dc514d5aa 100644 (file)
@@ -152,6 +152,12 @@ wxAuiDefaultTabArt::wxAuiDefaultTabArt()
        0x1f, 0xfe, 0x1f, 0xfc, 0x1f, 0xfe, 0x1f, 0xff, 0x9f, 0xff, 0xdf, 0xff,
        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
    
+    static unsigned char list_bits[] = {
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0x0f, 0xf8, 0xff, 0xff, 0x0f, 0xf8, 0x1f, 0xfc, 0x3f, 0xfe, 0x7f, 0xff,
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
+   
+   
     m_active_close_bmp = BitmapFromBits(close_bits, 16, 16, *wxBLACK);
     m_disabled_close_bmp = BitmapFromBits(close_bits, 16, 16, wxColour(128,128,128));
     
@@ -160,6 +166,10 @@ wxAuiDefaultTabArt::wxAuiDefaultTabArt()
     
     m_active_right_bmp = BitmapFromBits(right_bits, 16, 16, *wxBLACK);
     m_disabled_right_bmp = BitmapFromBits(right_bits, 16, 16, wxColour(128,128,128));
+    
+    m_active_windowlist_bmp = BitmapFromBits(list_bits, 16, 16, *wxBLACK);
+    m_disabled_windowlist_bmp = BitmapFromBits(list_bits, 16, 16, wxColour(128,128,128));
+    
 }
 
 wxAuiDefaultTabArt::~wxAuiDefaultTabArt()
@@ -167,7 +177,8 @@ wxAuiDefaultTabArt::~wxAuiDefaultTabArt()
 }
 
 void wxAuiDefaultTabArt::DrawBackground(wxDC* dc,
-                                     const wxRect& rect)
+                                        wxWindow* WXUNUSED(wnd),
+                                        const wxRect& rect)
 {
     // draw background
     dc->SetBrush(m_bkbrush);
@@ -190,13 +201,14 @@ void wxAuiDefaultTabArt::DrawBackground(wxDC* dc,
 // x_extent - the advance x; where the next tab should start
 
 void wxAuiDefaultTabArt::DrawTab(wxDC* dc,
-                              const wxRect& in_rect,
-                              const wxString& caption_text,
-                              bool active,
-                              int close_button_state,
-                              wxRect* out_tab_rect,
-                              wxRect* out_button_rect,
-                              int* x_extent)
+                                 wxWindow* wnd,
+                                 const wxRect& in_rect,
+                                 const wxString& caption_text,
+                                 bool active,
+                                 int close_button_state,
+                                 wxRect* out_tab_rect,
+                                 wxRect* out_button_rect,
+                                 int* x_extent)
 {
     wxCoord normal_textx, normal_texty;
     wxCoord selected_textx, selected_texty;
@@ -214,7 +226,7 @@ void wxAuiDefaultTabArt::DrawTab(wxDC* dc,
     dc->GetTextExtent(caption, &normal_textx, &normal_texty);
         
     // figure out the size of the tab
-    wxSize tab_size = GetTabSize(dc, caption, active, close_button_state, x_extent);
+    wxSize tab_size = GetTabSize(dc, wnd, caption, active, close_button_state, x_extent);
 
     wxCoord tab_height = tab_size.y;
     wxCoord tab_width = tab_size.x;
@@ -311,10 +323,11 @@ void wxAuiDefaultTabArt::DrawTab(wxDC* dc,
 
 
 wxSize wxAuiDefaultTabArt::GetTabSize(wxDC* dc,
-                                   const wxString& caption,
-                                   bool WXUNUSED(active),
-                                   int close_button_state,
-                                   int* x_extent)
+                                      wxWindow* WXUNUSED(wnd),
+                                      const wxString& caption,
+                                      bool WXUNUSED(active),
+                                      int close_button_state,
+                                      int* x_extent)
 {
     wxCoord measured_textx, measured_texty;
     
@@ -334,13 +347,14 @@ wxSize wxAuiDefaultTabArt::GetTabSize(wxDC* dc,
 
 
 void wxAuiDefaultTabArt::DrawButton(
-                 wxDC* dc,
-                 const wxRect& in_rect,
-                 int bitmap_id,
-                 int button_state,
-                 int orientation,
-                 const wxBitmap& bitmap_override,
-                 wxRect* out_rect)
+                                    wxDC* dc,
+                                    wxWindow* WXUNUSED(wnd),
+                                    const wxRect& in_rect,
+                                    int bitmap_id,
+                                    int button_state,
+                                    int orientation,
+                                    const wxBitmap& bitmap_override,
+                                    wxRect* out_rect)
 {
     wxBitmap bmp;
     wxRect rect;
@@ -371,6 +385,12 @@ void wxAuiDefaultTabArt::DrawButton(
                      else
                     bmp = m_active_right_bmp;
                 break;
+            case wxAUI_BUTTON_WINDOWLIST:
+                if (button_state & wxAUI_BUTTON_STATE_DISABLED)
+                    bmp = m_disabled_windowlist_bmp;
+                     else
+                    bmp = m_active_windowlist_bmp;
+                break;
         }
     }
 
@@ -401,12 +421,90 @@ void wxAuiDefaultTabArt::DrawButton(
 
 
 
+
+// -- GUI helper classes and functions --
+
+class wxAuiCommandCapture : public wxEvtHandler
+{
+public:
+    
+    wxAuiCommandCapture() { m_last_id = 0; }
+    int GetCommandId() const { return m_last_id; }
+
+    bool ProcessEvent(wxEvent& evt)
+    {
+        if (evt.GetEventType() == wxEVT_COMMAND_MENU_SELECTED)
+        {
+            m_last_id = evt.GetId();
+            return true;
+        }
+        
+        if (GetNextHandler())
+            return GetNextHandler()->ProcessEvent(evt);
+
+        return false;
+    }
+    
+private:
+    int m_last_id;
+};
+
+
+
+int wxAuiDefaultTabArt::ShowWindowList(wxWindow* wnd,
+                                       const wxArrayString& items,
+                                       int active_idx)
+{
+       wxMenu menuPopup;
+
+    size_t i, count = items.GetCount();
+    for (i = 0; i < count; ++i)
+    {
+        menuPopup.AppendCheckItem(1000+i, items.Item(i));
+    }
+    
+    if (active_idx != -1)
+    {
+        menuPopup.Check(1000+active_idx, true);
+    }
+    
+    // find out where to put the popup menu of window
+    // items.  Subtract 100 for now to center the menu
+    // a bit, until a better mechanism can be implemented
+    wxPoint pt = ::wxGetMousePosition();
+    pt = wnd->ScreenToClient(pt);
+    if (pt.x < 100)
+        pt.x = 0;
+         else
+        pt.x -= 100;
+    
+    // find out the screen coordinate at the bottom of the tab ctrl
+    wxRect cli_rect = wnd->GetClientRect();
+    pt.y = cli_rect.y + cli_rect.height;
+    
+    wxAuiCommandCapture* cc = new wxAuiCommandCapture;
+    wnd->PushEventHandler(cc);
+    wnd->PopupMenu(&menuPopup, pt);
+    int command = cc->GetCommandId();
+    wnd->PopEventHandler(true);
+    
+    if (command >= 1000)
+        return command-1000;
+        
+    return -1;
+}
+
 int wxAuiDefaultTabArt::GetBestTabCtrlSize(wxWindow* wnd)
 {
     wxClientDC dc(wnd);
     dc.SetFont(m_measuring_font);
     int x_ext = 0;
-    wxSize s = GetTabSize(&dc, wxT("ABCDEFGHIj"), true, wxAUI_BUTTON_STATE_HIDDEN, &x_ext);
+    wxSize s = GetTabSize(&dc,
+                          wnd,
+                          wxT("ABCDEFGHIj"),
+                          true,
+                          wxAUI_BUTTON_STATE_HIDDEN,
+                          &x_ext);
     return s.y+3;
 }
 
@@ -450,7 +548,8 @@ wxAuiTabContainer::wxAuiTabContainer()
     m_art = new wxAuiDefaultTabArt;
     
     AddButton(wxAUI_BUTTON_LEFT, wxLEFT);       
-    AddButton(wxAUI_BUTTON_RIGHT, wxRIGHT);      
+    AddButton(wxAUI_BUTTON_RIGHT, wxRIGHT);
+    AddButton(wxAUI_BUTTON_WINDOWLIST, wxRIGHT);
     AddButton(wxAUI_BUTTON_CLOSE, wxRIGHT);
 }
 
@@ -475,7 +574,23 @@ void wxAuiTabContainer::SetFlags(unsigned int flags)
     m_flags = flags;
     
     // check for new close button settings
+    RemoveButton(wxAUI_BUTTON_LEFT);       
+    RemoveButton(wxAUI_BUTTON_RIGHT);
+    RemoveButton(wxAUI_BUTTON_WINDOWLIST);
     RemoveButton(wxAUI_BUTTON_CLOSE);
+    
+    
+    if (flags & wxAUI_NB_SCROLL_BUTTONS)
+    {
+        AddButton(wxAUI_BUTTON_LEFT, wxLEFT);       
+        AddButton(wxAUI_BUTTON_RIGHT, wxRIGHT);
+    }
+
+    if (flags & wxAUI_NB_WINDOWLIST_BUTTON)
+    {
+        AddButton(wxAUI_BUTTON_WINDOWLIST, wxRIGHT);
+    }
+    
     if (flags & wxAUI_NB_CLOSE_BUTTON)
     {
         AddButton(wxAUI_BUTTON_CLOSE, wxRIGHT);
@@ -705,7 +820,7 @@ void wxAuiTabContainer::SetTabOffset(size_t offset)
 // Render() renders the tab catalog to the specified DC
 // It is a virtual function and can be overridden to
 // provide custom drawing capabilities
-void wxAuiTabContainer::Render(wxDC* raw_dc)
+void wxAuiTabContainer::Render(wxDC* raw_dc, wxWindow* wnd)
 {
     wxMemoryDC dc;
     wxBitmap bmp;
@@ -737,6 +852,7 @@ void wxAuiTabContainer::Render(wxDC* raw_dc)
     
         int x_extent = 0;
         wxSize size = m_art->GetTabSize(&dc,
+                            wnd,
                             page.caption,
                             page.active,
                             close_button ?
@@ -808,7 +924,7 @@ void wxAuiTabContainer::Render(wxDC* raw_dc)
 
 
     // draw background
-    m_art->DrawBackground(&dc, m_rect);
+    m_art->DrawBackground(&dc, wnd, m_rect);
 
     // draw buttons
     int left_buttons_width = 0;
@@ -832,6 +948,7 @@ void wxAuiTabContainer::Render(wxDC* raw_dc)
         button_rect.SetWidth(offset);
 
         m_art->DrawButton(&dc,
+                          wnd,
                           button_rect,
                           button.id,
                           button.cur_state,
@@ -861,6 +978,7 @@ void wxAuiTabContainer::Render(wxDC* raw_dc)
         wxRect button_rect(offset, 1, 1000, m_rect.height);
 
         m_art->DrawButton(&dc,
+                          wnd,
                           button_rect,
                           button.id,
                           button.cur_state,
@@ -934,14 +1052,15 @@ void wxAuiTabContainer::Render(wxDC* raw_dc)
 
         rect.x = offset;
 
-        m_art->DrawTab(&dc, 
-                rect,
-                page.caption,
-                page.active,
-                tab_button.cur_state,
-                &page.rect,
-                &tab_button.rect,
-                &x_extent);
+        m_art->DrawTab(&dc,
+                       wnd,
+                       rect,
+                       page.caption,
+                       page.active,
+                       tab_button.cur_state,
+                       &page.rect,
+                       &tab_button.rect,
+                       &x_extent);
 
         if (page.active)
         {
@@ -969,13 +1088,14 @@ void wxAuiTabContainer::Render(wxDC* raw_dc)
 
         rect.x = active_offset;
         m_art->DrawTab(&dc,
-                rect,
-                page.caption,
-                page.active,
-                tab_button.cur_state,
-                &page.rect,
-                &tab_button.rect,
-                &x_extent);
+                       wnd,
+                       rect,
+                       page.caption,
+                       page.active,
+                       tab_button.cur_state,
+                       &page.rect,
+                       &tab_button.rect,
+                       &x_extent);
     }
 
     dc.DestroyClippingRegion();
@@ -1143,7 +1263,7 @@ void wxAuiTabCtrl::OnPaint(wxPaintEvent&)
     dc.SetFont(GetFont());
 
     if (GetPageCount() > 0)
-        Render(&dc);
+        Render(&dc, this);
 }
 
 void wxAuiTabCtrl::OnEraseBackground(wxEraseEvent& WXUNUSED(evt))
@@ -1320,6 +1440,28 @@ void wxAuiTabCtrl::OnButton(wxAuiNotebookEvent& event)
             Refresh();
             Update();
         }
+    }
+     else if (button == wxAUI_BUTTON_WINDOWLIST)
+    {
+        wxArrayString as;
+        
+        size_t i, page_count = m_pages.GetCount();
+        for (i = 0; i < page_count; ++i)
+        {
+            wxAuiNotebookPage& page = m_pages.Item(i);
+            as.Add(page.caption);
+        }
+
+        int idx = GetArtProvider()->ShowWindowList(this, as, GetActivePage());
+        
+        if (idx != -1)
+        {
+            wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, m_windowId);
+            e.SetSelection(idx);
+            e.SetOldSelection(GetActivePage());
+            e.SetEventObject(this);
+            GetEventHandler()->ProcessEvent(e);
+        }
     }
      else
     {
@@ -1385,7 +1527,8 @@ public:
         for (i = 0; i < page_count; ++i)
         {
             wxAuiNotebookPage& page = pages.Item(i);
-            page.window->SetSize(m_rect.x, m_rect.y+tab_height, m_rect.width, m_rect.height-tab_height);
+            page.window->SetSize(m_rect.x, m_rect.y+tab_height,
+                                 m_rect.width, m_rect.height-tab_height);
 
             if (page.window->IsKindOf(CLASSINFO(wxAuiMDIChildFrame)))
             {