From 5b2acc3a4f02058e76cdcbfad5d57a0988bbb138 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Sun, 17 Sep 2006 11:51:08 +0000 Subject: [PATCH] [ 1550698 ] Bottom aligned toolbar git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41268 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/toolbar.tex | 1 + include/wx/toolbar.h | 5 +++- samples/toolbar/toolbar.cpp | 50 +++++++++++++++++++++++++++++++++--- src/gtk/frame.cpp | 13 ++++++++++ src/mac/carbon/frame.cpp | 6 +++++ src/msw/frame.cpp | 51 +++++++++++++++++++++++++++++-------- src/msw/tbar95.cpp | 3 +++ src/os2/frame.cpp | 9 +++++++ 8 files changed, 122 insertions(+), 16 deletions(-) diff --git a/docs/latex/wx/toolbar.tex b/docs/latex/wx/toolbar.tex index 3ed722010c..ea95dbe2e8 100644 --- a/docs/latex/wx/toolbar.tex +++ b/docs/latex/wx/toolbar.tex @@ -72,6 +72,7 @@ use this option under Windows XP with true colour: 2 only). This style must be used with wxTB\_TEXT.} \twocolitem{\windowstyle{wxTB\_HORZ\_TEXT}}{Combination of wxTB\_HORZ\_LAYOUT and wxTB\_TEXT.} \twocolitem{\windowstyle{wxTB\_NO\_TOOLTIPS}}{Don't show the short help tooltips for the tools when the mouse hovers over them.} +\twocolitem{\windowstyle{wxTB\_BOTTOM}}{Align the toolbar at the bottom of parent window.} \end{twocollist} See also \helpref{window styles overview}{windowstyles}. Note that the Win32 diff --git a/include/wx/toolbar.h b/include/wx/toolbar.h index b7b8cc3f29..398ebf8a01 100644 --- a/include/wx/toolbar.h +++ b/include/wx/toolbar.h @@ -52,7 +52,10 @@ enum wxTB_HORZ_TEXT = wxTB_HORZ_LAYOUT | wxTB_TEXT, // don't show the toolbar short help tooltips - wxTB_NO_TOOLTIPS = 0x1000 + wxTB_NO_TOOLTIPS = 0x1000, + + // lay out toolbar at the bottom of the window + wxTB_BOTTOM = 0x2000 }; #if wxUSE_TOOLBAR diff --git a/samples/toolbar/toolbar.cpp b/samples/toolbar/toolbar.cpp index e8edd69298..bff716023d 100644 --- a/samples/toolbar/toolbar.cpp +++ b/samples/toolbar/toolbar.cpp @@ -97,6 +97,7 @@ public: void OnToggleAnotherToolbar(wxCommandEvent& event); void OnToggleHorizontalText(wxCommandEvent& WXUNUSED(event)); + void OnBottomToolbar(wxCommandEvent& WXUNUSED(event)); void OnToggleToolbarSize(wxCommandEvent& event); void OnToggleToolbarOrient(wxCommandEvent& event); void OnToggleToolbarRows(wxCommandEvent& event); @@ -133,6 +134,7 @@ private: bool m_smallToolbar, m_horzToolbar, + m_bottomToolbar, m_horzText, m_useCustomDisabled, m_showTooltips; @@ -181,12 +183,13 @@ enum IDM_TOOLBAR_SHOW_ICONS, IDM_TOOLBAR_SHOW_BOTH, IDM_TOOLBAR_CUSTOM_PATH, - + IDM_TOOLBAR_BOTTOM_ORIENTATION, IDM_TOOLBAR_OTHER_1, IDM_TOOLBAR_OTHER_2, IDM_TOOLBAR_OTHER_3, - ID_COMBO = 1000 + ID_COMBO = 1000, + ID_SPIN = 1001 }; // ---------------------------------------------------------------------------- @@ -206,6 +209,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR, MyFrame::OnToggleAnotherToolbar) EVT_MENU(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT, MyFrame::OnToggleHorizontalText) + EVT_MENU(IDM_TOOLBAR_BOTTOM_ORIENTATION, MyFrame::OnBottomToolbar) EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARSIZE, MyFrame::OnToggleToolbarSize) EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARORIENT, MyFrame::OnToggleToolbarOrient) EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARROWS, MyFrame::OnToggleToolbarRows) @@ -290,7 +294,10 @@ void MyFrame::RecreateToolbar() SetToolBar(NULL); - style &= ~(wxTB_HORIZONTAL | wxTB_VERTICAL | wxTB_HORZ_LAYOUT); + style &= ~(wxTB_HORIZONTAL | wxTB_VERTICAL | wxTB_BOTTOM | wxTB_HORZ_LAYOUT); + if( m_bottomToolbar ) + style |= wxTB_BOTTOM; + else style |= m_horzToolbar ? wxTB_HORIZONTAL : wxTB_VERTICAL; if ( m_showTooltips ) @@ -369,6 +376,9 @@ void MyFrame::RecreateToolbar() combo->Append(_T("in a")); combo->Append(_T("toolbar")); toolBar->AddControl(combo); + + //wxSpinCtrl *spin = new wxSpinCtrl( toolBar, ID_SPIN, wxT("0"), wxDefaultPosition, wxSize(80,wxDefaultCoord), 0, 100, 0 ); + //toolBar->AddControl( spin ); } #endif // toolbars which don't support controls @@ -440,6 +450,7 @@ MyFrame::MyFrame(wxFrame* parent, m_smallToolbar = true; m_horzToolbar = true; + m_bottomToolbar = false; m_horzText = false; m_useCustomDisabled = false; m_showTooltips = true; @@ -490,6 +501,9 @@ MyFrame::MyFrame(wxFrame* parent, _T("Switch between using system-generated and custom disabled images")); + tbarMenu->AppendCheckItem(IDM_TOOLBAR_BOTTOM_ORIENTATION, + _T("Set toolbar at the bottom of the window"), + _T("Set toolbar at the bottom of the window")); tbarMenu->AppendSeparator(); tbarMenu->Append(IDM_TOOLBAR_ENABLEPRINT, _T("&Enable print button\tCtrl-E")); @@ -530,9 +544,22 @@ MyFrame::MyFrame(wxFrame* parent, // Create the toolbar RecreateToolbar(); - m_textWindow = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxPoint(0, 0), wxDefaultSize, wxTE_MULTILINE); + m_textWindow = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE); } +#if USE_GENERIC_TBAR + +wxToolBar* MyFrame::OnCreateToolBar(long style, + wxWindowID id, + const wxString& name) +{ + return (wxToolBar *)new wxToolBarSimple(this, id, + wxDefaultPosition, wxDefaultSize, + style, name); +} + +#endif // USE_GENERIC_TBAR + void MyFrame::LayoutChildren() { wxSize size = GetClientSize(); @@ -652,7 +679,12 @@ void MyFrame::OnToggleCustomDisabled(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnToggleToolbarOrient(wxCommandEvent& WXUNUSED(event)) { + if( m_bottomToolbar ) + m_bottomToolbar = false; m_horzToolbar = !m_horzToolbar; + wxMenuBar *menuBar = GetMenuBar(); + if( menuBar->IsChecked( IDM_TOOLBAR_BOTTOM_ORIENTATION ) ) + menuBar->Check( IDM_TOOLBAR_BOTTOM_ORIENTATION, false ); RecreateToolbar(); } @@ -818,3 +850,13 @@ void MyFrame::OnToggleRadioBtn(wxCommandEvent& event) event.GetId() - IDM_TOOLBAR_TOGGLERADIOBTN1, true); } } +void MyFrame::OnBottomToolbar(wxCommandEvent& event ) +{ + m_bottomToolbar = !m_bottomToolbar; + wxMenuBar *menuBar = GetMenuBar(); + if( menuBar->IsChecked( IDM_TOOLBAR_TOGGLETOOLBARORIENT ) ) + menuBar->Check( IDM_TOOLBAR_TOGGLETOOLBARORIENT, false ); + if( !m_horzToolbar ) + m_horzToolbar = true; + RecreateToolbar(); +} diff --git a/src/gtk/frame.cpp b/src/gtk/frame.cpp index 9d26447c67..b6c8bc5e42 100644 --- a/src/gtk/frame.cpp +++ b/src/gtk/frame.cpp @@ -421,6 +421,19 @@ void wxFrame::GtkOnSize() client_area_x_offset += ww; } + else if( m_frameToolBar->GetWindowStyle() & wxTB_BOTTOM ) + { + xx = m_miniEdge; + yy = GetClientSize().y; +#if wxUSE_MENUS_NATIVE + yy += m_menuBarHeight; +#endif // wxUSE_MENU_NATIVE + m_frameToolBar->m_x = xx; + m_frameToolBar->m_y = yy; + ww = m_width - 2*m_miniEdge; + hh = m_toolBarDetached ? wxPLACE_HOLDER + : m_frameToolBar->m_height; + } else { ww = m_width - 2*m_miniEdge; diff --git a/src/mac/carbon/frame.cpp b/src/mac/carbon/frame.cpp index b630e653f4..b327bfa9bf 100644 --- a/src/mac/carbon/frame.cpp +++ b/src/mac/carbon/frame.cpp @@ -366,6 +366,12 @@ void wxFrame::PositionToolBar() // have the original client size. GetToolBar()->SetSize(tx , ty , tw, ch , wxSIZE_NO_ADJUSTMENTS ); } + else if (GetToolBar->GetWindowStyleFlag() & wxTB_BOTTOM) + { + tx = 0; + ty = statusY - th; + GetToolBar->SetSize(tx, ty, cw, th, wxSIZE_NO_ADJUSTMENTS ); + } else { #if !wxMAC_USE_NATIVE_TOOLBAR diff --git a/src/msw/frame.cpp b/src/msw/frame.cpp index c31faeb708..9ede74a5ac 100644 --- a/src/msw/frame.cpp +++ b/src/msw/frame.cpp @@ -248,7 +248,16 @@ void wxFrame::DoGetClientSize(int *x, int *y) const if ( y ) *y -= pt.y; - +#if wxUSE_TOOLBAR + if( y ) + { + wxToolBar *toolbar = GetToolBar(); + if( toolbar && toolbar->HasFlag( wxTB_BOTTOM ) ) + { + *y -= toolbar->GetClientSize().y; + } + } +#endif #if wxUSE_STATUSBAR // adjust client area height to take the status bar into account if ( y ) @@ -315,6 +324,11 @@ void wxFrame::PositionStatusBar() int w, h; GetClientSize(&w, &h); +#if wxUSE_TOOLBAR + wxToolBar *toolbar = GetToolBar(); + if( toolbar && toolbar->HasFlag( wxTB_BOTTOM ) ) + h += toolbar->GetClientRect().height; +#endif int sw, sh; m_frameStatusBar->GetSize(&sw, &sh); @@ -560,6 +574,7 @@ wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& nam void wxFrame::PositionToolBar() { + int x = 0, y = 0; wxToolBar *toolbar = GetToolBar(); if ( toolbar && toolbar->IsShown() ) { @@ -581,9 +596,19 @@ void wxFrame::PositionToolBar() height -= statbar->GetClientSize().y; } #endif // wxUSE_STATUSBAR - - int x = 0; - int y = 0; + int tx, ty, tw, th; + toolbar->GetPosition( &tx, &ty ); + toolbar->GetSize( &tw, &th ); + if( ( toolbar->GetWindowStyleFlag() & wxTB_HORIZONTAL ) || ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL ) ) + { + x = 0; + y = 0; + } + else if( toolbar->GetWindowStyleFlag() & wxTB_BOTTOM ) + { + x = 0; + y = height - th; + } #if defined(WINCE_WITH_COMMANDBAR) // We're using a commandbar - so we have to allow for it. if (GetMenuBar() && GetMenuBar()->GetCommandBar()) @@ -593,17 +618,21 @@ void wxFrame::PositionToolBar() y = rect.bottom - rect.top; } #endif - - int tx, ty; - int tw, th; - toolbar->GetPosition(&tx, &ty); - toolbar->GetSize(&tw, &th); - + if( ( toolbar->GetWindowStyleFlag() & wxTB_HORIZONTAL ) || ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL ) ) + { // Adjust if (ty < 0 && (-ty == th)) ty = 0; if (tx < 0 && (-tx == tw)) tx = 0; + } + else if( toolbar->GetWindowStyleFlag() & wxTB_BOTTOM ) + { + if( ty < 0 && ( -ty == th ) ) + ty = height - th; + if( tx < 0 && ( -tx == tw ) ) + tx = 0; + } int desiredW = tw; int desiredH = th; @@ -1055,7 +1084,7 @@ wxPoint wxFrame::GetClientAreaOrigin() const { pt.x += w; } - else + else if( !( toolbar->GetWindowStyleFlag() & wxTB_BOTTOM ) ) { pt.y += h; } diff --git a/src/msw/tbar95.cpp b/src/msw/tbar95.cpp index 1e93c69901..9b9436d81f 100644 --- a/src/msw/tbar95.cpp +++ b/src/msw/tbar95.cpp @@ -402,6 +402,9 @@ WXDWORD wxToolBar::MSWGetStyle(long style, WXDWORD *exstyle) const if ( style & wxTB_VERTICAL ) msStyle |= CCS_VERT; + if( style & wxTB_BOTTOM ) + msStyle |= CCS_BOTTOM; + return msStyle; } diff --git a/src/os2/frame.cpp b/src/os2/frame.cpp index 7555185986..b885819f93 100644 --- a/src/os2/frame.cpp +++ b/src/os2/frame.cpp @@ -704,6 +704,15 @@ void wxFrame::PositionToolBar() ,vTHeight ); } + else if (pToolBar->GetWindowStyleFlag() & wxTB_BOTTOM ) + { + vWidth = (wxCoord)(vRect.xRight - vRect.xLeft); + pToolBar->SetSize( vRect.xLeft - vFRect.xLeft + ,vRect.yBottom - vTHeight // assuming the vRect contains the client coordinates + ,vWidth + ,vHeight + ); + } else { wxCoord vSwidth = 0; -- 2.45.2