X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/10b959e3729a77b95ab15614d1bdce74da327d8b..fc9ef629ac8733c4f0b844356782cca80ae09c4b:/src/common/tbarsmpl.cpp diff --git a/src/common/tbarsmpl.cpp b/src/common/tbarsmpl.cpp index b14e1ee2b5..e973cfdedb 100644 --- a/src/common/tbarsmpl.cpp +++ b/src/common/tbarsmpl.cpp @@ -21,10 +21,10 @@ #endif #ifndef WX_PRECOMP -#include "wx.h" +#include "wx/wx.h" #endif -#if USE_TOOLBAR +#if wxUSE_TOOLBAR #include "wx/tbarsmpl.h" @@ -39,18 +39,15 @@ BEGIN_EVENT_TABLE(wxToolBarSimple, wxToolBarBase) END_EVENT_TABLE() #endif -// TODO: eliminate these; use system colours -static wxPen * white_pen = NULL, - * dark_grey_pen = NULL, - * black_pen = NULL, - * thick_black_pen; - wxToolBarSimple::wxToolBarSimple(void) { + m_currentRowsOrColumns = 0; + m_lastX = 0; + m_lastY = 0; } -bool wxToolBarSimple::Create(wxWindow *parent, const wxWindowID id, const wxPoint& pos, const wxSize& size, const long style, - const int direction, const int RowsOrColumns, const wxString& name ) +bool wxToolBarSimple::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, + const wxString& name ) { if ( ! wxWindow::Create(parent, id, pos, size, style, name) ) return FALSE; @@ -58,39 +55,18 @@ bool wxToolBarSimple::Create(wxWindow *parent, const wxWindowID id, const wxPoin // Set it to grey (or other 3D face colour) wxSystemSettings settings; SetBackgroundColour(settings.GetSystemColour(wxSYS_COLOUR_3DFACE)); - SetDefaultBackgroundColour(settings.GetSystemColour(wxSYS_COLOUR_3DFACE)); - if ( white_pen == 0 ) - { - white_pen = new wxPen; - white_pen->SetColour( "WHITE" ); - } - if ( dark_grey_pen == 0 ) - { - dark_grey_pen = new wxPen; - dark_grey_pen->SetColour( 85,85,85 ); - } - if ( black_pen == 0 ) - { - black_pen = new wxPen; - black_pen->SetColour( "BLACK" ); - } - if ( thick_black_pen == 0 ) - { - thick_black_pen = new wxPen("BLACK", 3, wxSOLID); - } - m_tilingDirection = direction; - m_rowsOrColumns = RowsOrColumns; - if ( m_tilingDirection == wxVERTICAL ) - { m_lastX = 3; m_lastY = 7; } - else + if ( GetWindowStyleFlag() & wxTB_VERTICAL ) { m_lastX = 7; m_lastY = 3; } + else + { m_lastX = 3; m_lastY = 7; } m_maxWidth = m_maxHeight = 0; m_pressedTool = m_currentTool = -1; m_xMargin = 0; m_yMargin = 0; m_toolPacking = 1; m_toolSeparation = 5; + SetCursor(*wxSTANDARD_CURSOR); return TRUE; } @@ -99,7 +75,7 @@ wxToolBarSimple::~wxToolBarSimple () { } -void wxToolBarSimple::OnPaint (wxPaintEvent& event) +void wxToolBarSimple::OnPaint (wxPaintEvent& WXUNUSED(event)) { wxPaintDC dc(this); PrepareDC(dc); @@ -119,18 +95,6 @@ void wxToolBarSimple::OnPaint (wxPaintEvent& event) DrawTool(dc, mem_dc, tool); } -/* Old code which drew a line beneath the toolbar - not generally - * wanted. - int w, h; - GetClientSize( &w, &h ); - wxPen * old_pen = dc.GetPen(); - dc.SetPen( *white_pen ); - dc.DrawLine(0,0,w,0); - dc.SetPen( *black_pen ); - dc.DrawLine(0,(h-1),w,(h-1)); - dc.SetPen( *old_pen ); -*/ - count--; } @@ -139,7 +103,7 @@ void wxToolBarSimple::OnSize ( wxSizeEvent& event ) wxToolBarBase::OnSize(event); } -void wxToolBarSimple::OnKillFocus (wxFocusEvent& event) +void wxToolBarSimple::OnKillFocus (wxFocusEvent& WXUNUSED(event)) { OnMouseEnter(m_pressedTool = m_currentTool = -1); } @@ -150,6 +114,15 @@ void wxToolBarSimple::OnMouseEvent ( wxMouseEvent & event ) event.Position(&x, &y); wxToolBarTool *tool = FindToolForPosition(x, y); + if (event.LeftDown()) + { + CaptureMouse(); + } + if (event.LeftUp()) + { + ReleaseMouse(); + } + if (!tool) { if (m_currentTool > -1) @@ -168,16 +141,17 @@ void wxToolBarSimple::OnMouseEvent ( wxMouseEvent & event ) { // If the left button is kept down and moved over buttons, // press those buttons. - if (event.LeftIsDown() && tool->m_enabled) { - SpringUpButton(m_currentTool); - tool->m_toggleState = !tool->m_toggleState; - wxMemoryDC *dc2 = new wxMemoryDC; - wxClientDC dc(this); - DrawTool(dc, *dc2, tool); - delete dc2; + if (event.LeftIsDown() && tool->m_enabled) + { + SpringUpButton(m_currentTool); + tool->m_toggleState = !tool->m_toggleState; + wxMemoryDC *dc2 = new wxMemoryDC; + wxClientDC dc(this); + DrawTool(dc, *dc2, tool); + delete dc2; } - OnMouseEnter(tool->m_index); - m_currentTool = tool->m_index; + m_currentTool = tool->m_index; + OnMouseEnter(tool->m_index); } return; } @@ -185,33 +159,44 @@ void wxToolBarSimple::OnMouseEvent ( wxMouseEvent & event ) // Left button pressed. if (event.LeftDown() && tool->m_enabled) { - tool->m_toggleState = !tool->m_toggleState; + if (tool->m_isToggle) + { + tool->m_toggleState = !tool->m_toggleState; + } + wxMemoryDC *dc2 = new wxMemoryDC; wxClientDC dc(this); DrawTool(dc, *dc2, tool); delete dc2; + } else if (event.RightDown()) { OnRightClick(tool->m_index, x, y); } + // Left Button Released. Only this action confirms selection. // If the button is enabled and it is not a toggle tool and it is // in the pressed state, then raise the button and call OnLeftClick. // if (event.LeftUp() && tool->m_enabled && - (tool->m_toggleState || tool->m_isToggle)){ - if (!tool->m_isToggle) - tool->m_toggleState = FALSE; - // Pass the OnLeftClick event to tool - if (!OnLeftClick(tool->m_index, tool->m_toggleState) && tool->m_isToggle) - // If it was a toggle, and OnLeftClick says No Toggle allowed, - // then change it back - tool->m_toggleState = !tool->m_toggleState; + (tool->m_toggleState || tool->m_isToggle)) + { + if (!tool->m_isToggle) + tool->m_toggleState = FALSE; + + // Pass the OnLeftClick event to tool + if (!OnLeftClick(tool->m_index, tool->m_toggleState) && tool->m_isToggle) + { + // If it was a toggle, and OnLeftClick says No Toggle allowed, + // then change it back + tool->m_toggleState = !tool->m_toggleState; + } + wxClientDC dc(this); - wxMemoryDC *dc2 = new wxMemoryDC; - DrawTool(dc, *dc2, tool); - delete dc2; + wxMemoryDC *dc2 = new wxMemoryDC; + DrawTool(dc, *dc2, tool); + delete dc2; } } @@ -219,12 +204,18 @@ void wxToolBarSimple::DrawTool(wxDC& dc, wxMemoryDC& memDC, wxToolBarTool *tool) { PrepareDC(dc); + wxPen dark_grey_pen(wxColour( 85,85,85 ), 1, wxSOLID); + wxPen white_pen("WHITE", 1, wxSOLID); + wxPen black_pen("BLACK", 1, wxSOLID); + wxBitmap *bitmap = tool->m_toggleState ? (& tool->m_bitmap2) : (& tool->m_bitmap1); if (bitmap && bitmap->Ok()) { - if (bitmap->GetColourMap()) - memDC.SetPalette(*bitmap->GetColourMap()); +#ifndef __WXGTK__ + if (bitmap->GetPalette()) + memDC.SetPalette(*bitmap->GetPalette()); +#endif int ax = (int)tool->m_x, ay = (int)tool->m_y, @@ -236,14 +227,14 @@ void wxToolBarSimple::DrawTool(wxDC& dc, wxMemoryDC& memDC, wxToolBarTool *tool) { dc.SetClippingRegion(ax, ay, (bx-ax+1), (by-ay+1)); dc.Blit((ax+1), (ay+1), (bx-ax-2), (by-ay-2), &memDC, 0, 0); - wxPen * old_pen = dc.GetPen(); - dc.SetPen( *white_pen ); + wxPen * old_pen = & dc.GetPen(); + dc.SetPen( white_pen ); dc.DrawLine(ax,(by-1),ax,ay); dc.DrawLine(ax,ay,(bx-1),ay); - dc.SetPen( *dark_grey_pen ); + dc.SetPen( dark_grey_pen ); dc.DrawLine((bx-1),(ay+1),(bx-1),(by-1)); dc.DrawLine((bx-1),(by-1),(ax+1),(by-1)); - dc.SetPen( *black_pen ); + dc.SetPen( black_pen ); dc.DrawLine(bx,ay,bx,by); dc.DrawLine(bx,by,ax,by); dc.SetPen( *old_pen ); @@ -257,17 +248,19 @@ void wxToolBarSimple::DrawTool(wxDC& dc, wxMemoryDC& memDC, wxToolBarTool *tool) &memDC, 0, 0); } memDC.SelectObject(wxNullBitmap); +#ifndef __WXGTK__ memDC.SetPalette(wxNullPalette); +#endif } // No second bitmap, so draw a thick line around bitmap, or invert if mono else if (tool->m_toggleState) { bool drawBorder = FALSE; - #ifdef __X__ // X doesn't invert properly on colour +#ifdef __X__ // X doesn't invert properly on colour drawBorder = wxColourDisplay(); - #else // Inversion works fine under Windows +#else // Inversion works fine under Windows drawBorder = FALSE; - #endif +#endif if (!drawBorder) { @@ -288,14 +281,14 @@ void wxToolBarSimple::DrawTool(wxDC& dc, wxMemoryDC& memDC, wxToolBarTool *tool) memDC.SelectObject(tool->m_bitmap1); dc.SetClippingRegion(ax, ay, (bx-ax+1), (by-ay+1)); dc.Blit((ax+2), (ay+2), (bx-ax-2), (by-ay-2), &memDC, 0, 0); - wxPen * old_pen = dc.GetPen(); - dc.SetPen( *black_pen ); + wxPen * old_pen = & dc.GetPen(); + dc.SetPen( black_pen ); dc.DrawLine(ax,(by-1),ax,ay); dc.DrawLine(ax,ay,(bx-1),ay); - dc.SetPen( *dark_grey_pen ); + dc.SetPen( dark_grey_pen ); dc.DrawLine((ax+1),(by-2),(ax+1),(ay+1)); dc.DrawLine((ax+1),(ay+1),(bx-2),(ay+1)); - dc.SetPen( *white_pen ); + dc.SetPen( white_pen ); dc.DrawLine(bx,ay,bx,by); dc.DrawLine(bx,by,ax,by); dc.SetPen( *old_pen ); @@ -308,12 +301,13 @@ void wxToolBarSimple::DrawTool(wxDC& dc, wxMemoryDC& memDC, wxToolBarTool *tool) long y = tool->m_y; long w = tool->m_bitmap1.GetWidth(); long h = tool->m_bitmap1.GetHeight(); + wxPen thick_black_pen("BLACK", 3, wxSOLID); memDC.SelectObject(tool->m_bitmap1); dc.SetClippingRegion(tool->m_x, tool->m_y, w, h); dc.Blit(tool->m_x, tool->m_y, w, h, &memDC, 0, 0); - dc.SetPen(*thick_black_pen); + dc.SetPen(thick_black_pen); dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.DrawRectangle(x, y, w-1, h-1); dc.DestroyClippingRegion(); @@ -323,9 +317,10 @@ void wxToolBarSimple::DrawTool(wxDC& dc, wxMemoryDC& memDC, wxToolBarTool *tool) } } -void wxToolBarSimple::ToggleTool(const int index, const bool toggle) +void wxToolBarSimple::ToggleTool(int index, bool toggle) { - wxNode *node = m_tools.Find((long)index); + wxNode *node = (wxNode*) NULL; + node = m_tools.Find((long)index); if (node) { wxToolBarTool *tool = (wxToolBarTool *)node->Data(); @@ -348,9 +343,10 @@ void wxToolBarSimple::ToggleTool(const int index, const bool toggle) // the tool we're leaving was a 'sprung push button' and if so, // spring it back to the up state. // -void wxToolBarSimple::SpringUpButton(const int index) +void wxToolBarSimple::SpringUpButton(int index) { - wxNode *node=m_tools.Find((long)index); + wxNode *node = (wxNode*) NULL; + node=m_tools.Find((long)index); if (node) { wxToolBarTool *tool = (wxToolBarTool *)node->Data(); if (tool && !tool->m_isToggle && tool->m_toggleState){ @@ -368,4 +364,97 @@ void wxToolBarSimple::SpringUpButton(const int index) } } +void wxToolBarSimple::Layout(void) +{ + m_currentRowsOrColumns = 0; + m_lastX = m_xMargin; + m_lastY = m_yMargin; + int maxToolWidth = 0; + int maxToolHeight = 0; + m_maxWidth = 0; + m_maxHeight = 0; + + // Find the maximum tool width and height + wxNode *node = m_tools.First(); + while (node) + { + wxToolBarTool *tool = (wxToolBarTool *)node->Data(); + if (tool->GetWidth() > maxToolWidth) + maxToolWidth = (int)tool->GetWidth(); + if (tool->GetHeight() > maxToolHeight) + maxToolHeight = (int)tool->GetHeight(); + node = node->Next(); + } + + int separatorSize = m_toolSeparation; + + node = m_tools.First(); + while (node) + { + wxToolBarTool *tool = (wxToolBarTool *)node->Data(); + if (tool->m_toolStyle == wxTOOL_STYLE_SEPARATOR) + { + if ( GetWindowStyleFlag() & wxTB_HORIZONTAL ) + { + if (m_currentRowsOrColumns >= m_maxCols) + m_lastY += separatorSize; + else + m_lastX += separatorSize; + } + else + { + if (m_currentRowsOrColumns >= m_maxRows) + m_lastX += separatorSize; + else + m_lastY += separatorSize; + } + } + else if (tool->m_toolStyle == wxTOOL_STYLE_BUTTON) + { + if ( GetWindowStyleFlag() & wxTB_HORIZONTAL ) + { + if (m_currentRowsOrColumns >= m_maxCols) + { + m_currentRowsOrColumns = 0; + m_lastX = m_xMargin; + m_lastY += maxToolHeight + m_toolPacking; + } + tool->m_x = (long) (m_lastX + (maxToolWidth - tool->GetWidth())/2.0); + tool->m_y = (long) (m_lastY + (maxToolHeight - tool->GetHeight())/2.0); + + m_lastX += maxToolWidth + m_toolPacking; + } + else + { + if (m_currentRowsOrColumns >= m_maxRows) + { + m_currentRowsOrColumns = 0; + m_lastX += (maxToolWidth + m_toolPacking); + m_lastY = m_yMargin; + } + tool->m_x = (long) (m_lastX + (maxToolWidth - tool->GetWidth())/2.0); + tool->m_y = (long) (m_lastY + (maxToolHeight - tool->GetHeight())/2.0); + + m_lastY += maxToolHeight + m_toolPacking; + } + m_currentRowsOrColumns ++; + } + + if (m_lastX > m_maxWidth) + m_maxWidth = m_lastX; + if (m_lastY > m_maxHeight) + m_maxHeight = m_lastY; + + node = node->Next(); + } + if ( GetWindowStyleFlag() & wxTB_HORIZONTAL ) + m_maxWidth += maxToolWidth; + else + m_maxHeight += maxToolHeight; + + m_maxWidth += m_xMargin; + m_maxHeight += m_yMargin; +} + + #endif