-/////// Non-Windows 95 implementation
+// ----------------------------------------------------------------------------
+// constants
+// ----------------------------------------------------------------------------
+
+#define DEFAULTBITMAPX 16
+#define DEFAULTBITMAPY 15
+#define DEFAULTBUTTONX 24
+#define DEFAULTBUTTONY 22
+#define DEFAULTBARHEIGHT 27
+
+//
+// States (not all of them currently used)
+//
+#define wxTBSTATE_CHECKED 0x01 // radio button is checked
+#define wxTBSTATE_PRESSED 0x02 // button is being depressed (any style)
+#define wxTBSTATE_ENABLED 0x04 // button is enabled
+#define wxTBSTATE_HIDDEN 0x08 // button is hidden
+#define wxTBSTATE_INDETERMINATE 0x10 // button is indeterminate
+
+// ----------------------------------------------------------------------------
+// private classes
+// ----------------------------------------------------------------------------
+
+class WXDLLEXPORT wxToolBarTool : public wxToolBarToolBase
+{
+public:
+ wxToolBarTool(wxToolBar *tbar,
+ int id,
+ const wxBitmap& bitmap1,
+ const wxBitmap& bitmap2,
+ bool toggle,
+ wxObject *clientData,
+ const wxString& shortHelpString,
+ const wxString& longHelpString)
+ : wxToolBarToolBase(tbar, id, bitmap1, bitmap2, toggle,
+ clientData, shortHelpString, longHelpString)
+ {
+ }
-#if !USE_IMAGE_LOADING_IN_MSW
-#error If USE_IMAGE_LOADING_IN_MSW is set to 0, then USE_BUTTONBAR must be set to 0 too.
-#endif
+ wxToolBarTool(wxToolBar *tbar, wxControl *control)
+ : wxToolBarToolBase(tbar, control)
+ {
+ }
+
+ void SetSize(const wxSize& size)
+ {
+ m_width = size.x;
+ m_height = size.y;
+ }
+
+ long GetWidth() const { return m_width; }
+ long GetHeight() const { return m_height; }
+
+ wxCoord m_x;
+ wxCoord m_y;
+ wxCoord m_width;
+ wxCoord m_height;
+};
+
+// ----------------------------------------------------------------------------
+// wxWin macros
+// ----------------------------------------------------------------------------
-wxToolBarMSW::wxToolBarMSW(void)
+// ============================================================================
+// implementation
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// wxToolBarTool
+// ----------------------------------------------------------------------------
+
+wxToolBarToolBase *wxToolBar::CreateTool(int id,
+ const wxBitmap& bitmap1,
+ const wxBitmap& bitmap2,
+ bool toggle,
+ wxObject *clientData,
+ const wxString& shortHelpString,
+ const wxString& longHelpString)
-bool wxToolBarMSW::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
- long style, int orientation,
- int RowsOrColumns, const wxString& name)
+wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control)
+{
+ return new wxToolBarTool(this, control);
+}
+
+// ----------------------------------------------------------------------------
+// wxToolBar
+// ----------------------------------------------------------------------------
+
+void wxToolBar::Init()
- m_tilingDirection = orientation;
- m_rowsOrColumns = RowsOrColumns;
- if ( m_tilingDirection == wxVERTICAL )
- { m_lastX = 3; m_lastY = 7; }
- else
- { m_lastX = 7; m_lastY = 3; }
- m_maxWidth = m_maxHeight = 0;
- m_pressedTool = m_currentTool = -1;
- m_xMargin = 0;
- m_yMargin = 0;
- m_toolPacking = 1;
- m_toolSeparation = 5;
+ m_defaultWidth = DEFAULTBITMAPX;
+ m_defaultHeight = DEFAULTBITMAPY;
+
+ m_xPos =
+ m_yPos = -1;
+
+ m_maxWidth = m_maxHeight = 0;
+ m_pressedTool = m_currentTool = -1;
+ m_toolPacking = 1;
+ m_toolSeparation = 5;
+}
- wxNode *node = m_tools.First();
- while (node)
- {
- wxToolBarTool *tool = (wxToolBarTool *)node->Data();
- if (tool->m_toolStyle != wxTOOL_STYLE_SEPARATOR)
- {
- int state = wxTBSTATE_ENABLED;
- if (!tool->m_enabled)
- state = 0;
- if (tool->m_isToggle && tool->m_toggleState)
- state |= wxTBSTATE_CHECKED;
- DrawTool(dc, tool, state);
- }
- node = node->Next();
- }
- wxOnPaintCount --;
+wxToolBarToolBase *wxToolBar::AddTool(int id,
+ const wxBitmap& bitmap,
+ const wxBitmap& pushedBitmap,
+ bool toggle,
+ wxCoord xPos,
+ wxCoord yPos,
+ wxObject *clientData,
+ const wxString& helpString1,
+ const wxString& helpString2)
+{
+ // rememeber the position for DoInsertTool()
+ m_xPos = xPos;
+ m_yPos = yPos;
+
+ return wxToolBarBase::AddTool(id, bitmap, pushedBitmap, toggle,
+ xPos, yPos, clientData,
+ helpString1, helpString2);
- wxToolBarBase::OnSize(event);
+ wxPaintDC dc(this);
+
+ static int wxOnPaintCount = 0;
+
+ // Prevent reentry of OnPaint which would cause
+ // wxMemoryDC errors.
+ if (wxOnPaintCount > 0)
+ return;
+ wxOnPaintCount++;
+
+ wxToolBarToolsList::Node *node = m_tools.GetFirst();
+ while (node)
+ {
+ wxToolBarToolBase *tool = node->GetData();
+ if ( tool->GetStyle()!= wxTOOL_STYLE_BUTTON )
+ {
+ int state = tool->IsEnabled() ? wxTBSTATE_ENABLED : 0;
+ if ( tool->IsToggled() )
+ state |= wxTBSTATE_CHECKED;
+
+ DrawTool(dc, tool, state);
+ }
+
+ node = node->GetNext();
+ }
+
+ wxOnPaintCount--;
- ::ReleaseCapture();
- int state = wxTBSTATE_ENABLED;
- if (eventCurrentTool->m_toggleState)
- state |= wxTBSTATE_CHECKED;
- DrawTool(dc, eventCurrentTool, state);
- eventCurrentTool = NULL;
+ m_currentTool = -1;
+ if (eventCurrentTool && eventCurrentTool->IsEnabled())
+ {
+ ::ReleaseCapture();
+ int state = wxTBSTATE_ENABLED;
+ if (eventCurrentTool->IsToggled())
+ state |= wxTBSTATE_CHECKED;
+ DrawTool(dc, eventCurrentTool, state);
+ eventCurrentTool = NULL;
+ }
+ OnMouseEnter(-1);
+ return;
- // Might have dragged outside tool
- if (eventCurrentTool != tool)
- {
- int state = wxTBSTATE_ENABLED;
- if (tool->m_toggleState)
- state |= wxTBSTATE_CHECKED;
- DrawTool(dc, tool, state);
- eventCurrentTool = NULL;
- return;
- }
+ if (eventCurrentTool)
+ {
+ // Might have dragged outside tool
+ if (eventCurrentTool != tool)
+ {
+ int state = wxTBSTATE_ENABLED;
+ if (tool->IsToggled())
+ state |= wxTBSTATE_CHECKED;
+ DrawTool(dc, tool, state);
+ eventCurrentTool = NULL;
+ return;
+ }
+ }
+ else
+ {
+ if (tool && event.LeftIsDown() && tool->IsEnabled())
+ {
+ eventCurrentTool = tool;
+ ::SetCapture((HWND) GetHWND());
+ int state = wxTBSTATE_ENABLED|wxTBSTATE_PRESSED;
+ if (tool->IsToggled())
+ state |= wxTBSTATE_CHECKED;
+ DrawTool(dc, tool, state);
+ }
+ }
- }
- if (event.LeftDown() && tool->m_enabled)
- {
- eventCurrentTool = tool;
- ::SetCapture((HWND) GetHWND());
- int state = wxTBSTATE_ENABLED|wxTBSTATE_PRESSED;
- if (tool->m_toggleState)
- state |= wxTBSTATE_CHECKED;
- DrawTool(dc, tool, state);
- }
- else if (event.LeftUp() && tool->m_enabled)
- {
- if (eventCurrentTool)
- ::ReleaseCapture();
- if (eventCurrentTool == tool)
+ else if (event.LeftUp() && tool->IsEnabled())
- tool->m_toggleState = !tool->m_toggleState;
+ if (tool->CanBeToggled())
+ {
+ tool->Toggle();
+ if (!OnLeftClick(tool->GetId(), tool->IsToggled()))
+ {
+ tool->Toggle();
+ }
+ int state = wxTBSTATE_ENABLED;
+ if (tool->IsToggled())
+ state |= wxTBSTATE_CHECKED;
+ DrawTool(dc, tool, state);
+ }
+ else
+ {
+ int state = wxTBSTATE_ENABLED;
+ if (tool->IsToggled())
+ state |= wxTBSTATE_CHECKED;
+ DrawTool(dc, tool, state);
+ OnLeftClick(tool->GetId(), tool->IsToggled());
+ }
- int state = wxTBSTATE_ENABLED;
- if (tool->m_toggleState)
- state |= wxTBSTATE_CHECKED;
- DrawTool(dc, tool, state);
- }
- else
- {
- int state = wxTBSTATE_ENABLED;
- if (tool->m_toggleState)
- state |= wxTBSTATE_CHECKED;
- DrawTool(dc, tool, state);
- OnLeftClick(tool->m_index, tool->m_toggleState);
- }
+ eventCurrentTool = NULL;
+ }
+ else if (event.RightDown() && tool->IsEnabled())
+ {
+ OnRightClick(tool->GetId(), x, y);
- // at first do the enabling/disabling in the base class
- wxToolBarBase::EnableTool(toolIndex,enable);
- // then calculate the state of the tool and draw it
- wxToolBarTool *tool = (wxToolBarTool *)node->Data();
- int state = 0;
- if(tool->m_toggleState) state |= wxTBSTATE_CHECKED;
- if(tool->m_enabled) state |= wxTBSTATE_ENABLED;
- // how can i access the PRESSED state???
- DrawTool(dc, tool,state);
- }
+void wxToolBar::DoToggleTool(wxToolBarToolBase *tool, bool WXUNUSED(toggle))
+{
+ DoRedrawTool(tool);
+}
+
+void wxToolBar::DoSetToggle(wxToolBarToolBase * WXUNUSED(tool),
+ bool WXUNUSED(toggle))
+{
+ // nothing to do
+}
+
+void wxToolBar::DoRedrawTool(wxToolBarToolBase *tool)
+{
+ wxClientDC dc(this);
+
+ DrawTool(dc, tool);
- int state = wxTBSTATE_ENABLED;
- if (!tool->m_enabled)
- state = 0;
- if (tool->m_toggleState)
- state |= wxTBSTATE_CHECKED;
- DrawTool(dc, tool, state);
+ int state = 0;
+ if (tool->IsEnabled())
+ state |= wxTBSTATE_ENABLED;
+ if (tool->IsToggled())
+ state |= wxTBSTATE_CHECKED;
+ // how can i access the PRESSED state???
+
+ DrawTool(dc, tool, state);
-// If pushedBitmap is NULL, a reversed version of bitmap is
-// created and used as the pushed/toggled image.
-// If toggle is TRUE, the button toggles between the two states.
-wxToolBarTool *wxToolBarMSW::AddTool(int index, const wxBitmap& bitmap, const wxBitmap& pushedBitmap,
- bool toggle, long xPos, long yPos, wxObject *clientData, const wxString& helpString1, const wxString& helpString2)
+bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos),
+ wxToolBarToolBase *tool)
- wxToolBarTool *tool = new wxToolBarTool(index, bitmap, *bitmap2, toggle, xPos, yPos, helpString1, helpString2);
-#else
- wxToolBarTool *tool = new wxToolBarTool(index, bitmap, (wxBitmap *)NULL, toggle, xPos, yPos, helpString1, helpString2);
+ wxBitmap bmp;
+ bmp.SetHBITMAP((WXHBITMAP)hbmp);
+ tool->SetBitmap2(bmp);
+ }
- tool->m_deleteSecondBitmap = TRUE;
- tool->SetSize(GetDefaultButtonWidth(), GetDefaultButtonHeight());
-
- // Calculate reasonable max size in case Layout() not called
- if ((tool->m_x + bitmap.GetWidth() + m_xMargin) > m_maxWidth)
- m_maxWidth = (tool->m_x + tool->GetWidth() + m_xMargin);
+ if ( tool->IsButton() )
+ {
+ // Calculate reasonable max size in case Layout() not called
+ if ((tool->m_x + tool->GetBitmap1().GetWidth() + m_xMargin) > m_maxWidth)
+ m_maxWidth = (tool->m_x + tool->GetWidth() + m_xMargin);
- GetSysColors();
- if (!CreateDitherBrush())
- return FALSE;
+ 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
+ wxToolBarToolsList::Node *node = m_tools.GetFirst();
+ while (node)
+ {
+ wxToolBarTool *tool = (wxToolBarTool *)node->GetData();
+ if (tool->GetWidth() > maxToolWidth)
+ maxToolWidth = tool->GetWidth();
+ if (tool->GetHeight() > maxToolHeight)
+ maxToolHeight = tool->GetHeight();
+ node = node->GetNext();
+ }
- m_hbmMono = (WXHBITMAP) CreateBitmap((int)GetDefaultButtonWidth(), (int)GetDefaultButtonHeight(), 1, 1, NULL);
- if (!m_hbmMono)
- return FALSE;
+ node = m_tools.GetFirst();
+ while (node)
+ {
+ wxToolBarTool *tool = (wxToolBarTool *)node->GetData();
+ if (tool->GetStyle() == 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->GetStyle() == 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 ++;
+ }
- m_hbmDefault = (WXHBITMAP) SelectObject((HDC) m_hdcMono, (HBITMAP) m_hbmMono);
- return TRUE;
+ if (m_lastX > m_maxWidth)
+ m_maxWidth = m_lastX;
+ if (m_lastY > m_maxHeight)
+ m_maxHeight = m_lastY;
+
+ node = node->GetNext();
+ }
+
+ if ( GetWindowStyleFlag() & wxTB_HORIZONTAL )
+ {
+ m_maxWidth += maxToolWidth;
+ m_maxHeight += maxToolHeight;
+ }
+ else
+ {
+ m_maxWidth += maxToolWidth;
+ m_maxHeight += maxToolHeight;
+ }
+
+ m_maxWidth += m_xMargin;
+ m_maxHeight += m_yMargin;
+
+ SetSize(m_maxWidth, m_maxHeight);
+
+ return TRUE;
-void wxToolBarMSW::FreeGlobalObjects(void)
+bool wxToolBar::InitGlobalObjects()
+{
+ GetSysColors();
+ if (!CreateDitherBrush())
+ return FALSE;
+
+ m_hdcMono = (WXHDC) CreateCompatibleDC(NULL);
+ if (!m_hdcMono)
+ return FALSE;
+
+ m_hbmMono = (WXHBITMAP) CreateBitmap((int)GetToolSize().x, (int)GetToolSize().y, 1, 1, NULL);
+ if (!m_hbmMono)
+ return FALSE;
+
+ m_hbmDefault = (WXHBITMAP) SelectObject((HDC) m_hdcMono, (HBITMAP) m_hbmMono);
+ return TRUE;
+}
+
+void wxToolBar::FreeGlobalObjects()
BitBlt(hdcGlyphs, 0,0, dx, dy, (HDC) hdc, 0, 0, SRCCOPY);
// initalize whole area with 1's
BitBlt(hdcGlyphs, 0,0, dx, dy, (HDC) hdc, 0, 0, SRCCOPY);
// initalize whole area with 1's
- PatB(hdc, x + 1, y, dx - 2, 1, m_rgbFrame);
- PatB(hdc, x + 1, y + dy - 1, dx - 2, 1, m_rgbFrame);
- PatB(hdc, x, y + 1, 1, dy - 2, m_rgbFrame);
- PatB(hdc, x + dx - 1, y +1, 1, dy - 2, m_rgbFrame);
- PatB(hdc, x + 1, y + 1, 1, dy-2, m_rgbShadow);
- PatB(hdc, x + 1, y + 1, dx-2, 1, m_rgbShadow);
+ PatB(hdc, x + 1, y, dx - 2, 1, m_rgbFrame);
+ PatB(hdc, x + 1, y + dy - 1, dx - 2, 1, m_rgbFrame);
+ PatB(hdc, x, y + 1, 1, dy - 2, m_rgbFrame);
+ PatB(hdc, x + dx - 1, y +1, 1, dy - 2, m_rgbFrame);
+ PatB(hdc, x + 1, y + 1, 1, dy-2, m_rgbShadow);
+ PatB(hdc, x + 1, y + 1, dx-2, 1, m_rgbShadow);
- PatB(hdc, x + 1, y, dx - 2, 1, m_rgbFrame);
- PatB(hdc, x + 1, y + dy - 1, dx - 2, 1, m_rgbFrame);
- PatB(hdc, x, y + 1, 1, dy - 2, m_rgbFrame);
- PatB(hdc, x + dx - 1, y + 1, 1, dy - 2, m_rgbFrame);
- dx -= 2;
- dy -= 2;
- PatB(hdc, x + 1, y + 1, 1, dy - 1, m_rgbHilight);
- PatB(hdc, x + 1, y + 1, dx - 1, 1, m_rgbHilight);
- PatB(hdc, x + dx, y + 1, 1, dy, m_rgbShadow);
- PatB(hdc, x + 1, y + dy, dx, 1, m_rgbShadow);
- PatB(hdc, x + dx - 1, y + 2, 1, dy - 2, m_rgbShadow);
- PatB(hdc, x + 2, y + dy - 1, dx - 2, 1, m_rgbShadow);
+ PatB(hdc, x + 1, y, dx - 2, 1, m_rgbFrame);
+ PatB(hdc, x + 1, y + dy - 1, dx - 2, 1, m_rgbFrame);
+ PatB(hdc, x, y + 1, 1, dy - 2, m_rgbFrame);
+ PatB(hdc, x + dx - 1, y + 1, 1, dy - 2, m_rgbFrame);
+ dx -= 2;
+ dy -= 2;
+ PatB(hdc, x + 1, y + 1, 1, dy - 1, m_rgbHilight);
+ PatB(hdc, x + 1, y + 1, dx - 1, 1, m_rgbHilight);
+ PatB(hdc, x + dx, y + 1, 1, dy, m_rgbShadow);
+ PatB(hdc, x + 1, y + dy, dx, 1, m_rgbShadow);
+ PatB(hdc, x + dx - 1, y + 2, 1, dy - 2, m_rgbShadow);
+ PatB(hdc, x + 2, y + dy - 1, dx - 2, 1, m_rgbShadow);
if (hbrOld) {
// draw hilight color where we have 0's in the mask
BitBlt((HDC) hdc, x + 1, y + 1, dxFace, dyFace, (HDC) m_hdcMono, 0, 0, 0x00B8074A);
if (hbrOld) {
// draw hilight color where we have 0's in the mask
BitBlt((HDC) hdc, x + 1, y + 1, dxFace, dyFace, (HDC) m_hdcMono, 0, 0, 0x00B8074A);
if (hbrOld) {
// draw the shadow color where we have 0's in the mask
BitBlt((HDC) hdc, x, y, dxFace, dyFace, (HDC) m_hdcMono, 0, 0, 0x00B8074A);
if (hbrOld) {
// draw the shadow color where we have 0's in the mask
BitBlt((HDC) hdc, x, y, dxFace, dyFace, (HDC) m_hdcMono, 0, 0, 0x00B8074A);
// set the main image
StretchDIBits(hdcMem, 0, 0, wid, hgt, 0, 0, wid, hgt, lpBits,
// set the main image
StretchDIBits(hdcMem, 0, 0, wid, hgt, 0, 0, wid, hgt, lpBits,