X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/debe6624c1e9d4bf3243381153d1e173c849bcd8..e66474166b164b9e11f9881e79d531bc5182ea31:/src/msw/tbarmsw.cpp diff --git a/src/msw/tbarmsw.cpp b/src/msw/tbarmsw.cpp index 7e7402fa1a..3ca04af78b 100644 --- a/src/msw/tbarmsw.cpp +++ b/src/msw/tbarmsw.cpp @@ -21,27 +21,38 @@ #endif #ifndef WX_PRECOMP -#include "wx.h" +#include "wx/wx.h" #endif -#if USE_BUTTONBAR && USE_TOOLBAR +#if wxUSE_BUTTONBAR && wxUSE_TOOLBAR -#ifndef __GNUWIN32__ +#if !defined(__GNUWIN32__) && !defined(__SALFORDC__) #include "malloc.h" #endif +#if !defined(__MWERKS__) && !defined(__SALFORDC__) #include +#endif + #include #include "wx/tbarmsw.h" +#include "wx/event.h" #include "wx/app.h" +#include "wx/bitmap.h" #include "wx/msw/private.h" #include "wx/msw/dib.h" +#define DEFAULTBITMAPX 16 +#define DEFAULTBITMAPY 15 +#define DEFAULTBUTTONX 24 +#define DEFAULTBUTTONY 22 +#define DEFAULTBARHEIGHT 27 + /////// Non-Windows 95 implementation -#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. +#if !wxUSE_IMAGE_LOADING_IN_MSW +#error If wxUSE_IMAGE_LOADING_IN_MSW is set to 0, then wxUSE_BUTTONBAR must be set to 0 too. #endif #if !USE_SHARED_LIBRARY @@ -69,15 +80,12 @@ wxToolBarMSW::wxToolBarMSW(void) } bool wxToolBarMSW::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, - long style, int orientation, - int RowsOrColumns, const wxString& name) + long style, const wxString& name) { if ( ! wxWindow::Create(parent, id, pos, size, style, name) ) return FALSE; - m_tilingDirection = orientation; - m_rowsOrColumns = RowsOrColumns; - if ( m_tilingDirection == wxVERTICAL ) + if ( style & wxTB_HORIZONTAL ) { m_lastX = 3; m_lastY = 7; } else { m_lastX = 7; m_lastY = 3; } @@ -112,7 +120,7 @@ wxToolBarMSW::~wxToolBarMSW(void) FreeGlobalObjects(); } -void wxToolBarMSW::SetDefaultSize(const wxSize& size) +void wxToolBarMSW::SetToolBitmapSize(const wxSize& size) { m_defaultWidth = size.x; m_defaultHeight = size.y; FreeGlobalObjects(); @@ -120,7 +128,7 @@ void wxToolBarMSW::SetDefaultSize(const wxSize& size) } // The button size is bigger than the bitmap size -wxSize wxToolBarMSW::GetDefaultButtonSize(void) const +wxSize wxToolBarMSW::GetToolSize(void) const { return wxSize(m_defaultWidth + 8, m_defaultHeight + 7); } @@ -336,16 +344,15 @@ wxToolBarTool *wxToolBarMSW::AddTool(int index, const wxBitmap& bitmap, const wx // TODO: use the mapping code from wxToolBar95 to get it right in this class #if !defined(__WIN32__) && !defined(__WIN386__) - wxBitmap *bitmap2 = NULL; + wxBitmap bitmap2; if (toggle) { - bitmap2 = new wxBitmap; - bitmap2->SetHBITMAP( (WXHBITMAP) CreateMappedBitmap(wxGetInstance(), (HBITMAP) ((wxBitmap& )bitmap).GetHBITMAP())); + bitmap2.SetHBITMAP( (WXHBITMAP) CreateMappedBitmap((WXHINSTANCE)wxGetInstance(), (WXHBITMAP) ((wxBitmap& )bitmap).GetHBITMAP())); } - wxToolBarTool *tool = new wxToolBarTool(index, bitmap, *bitmap2, toggle, xPos, yPos, helpString1, helpString2); + 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); + wxToolBarTool *tool = new wxToolBarTool(index, bitmap, wxNullBitmap, toggle, xPos, yPos, helpString1, helpString2); #endif tool->m_clientData = clientData; @@ -361,7 +368,7 @@ wxToolBarTool *wxToolBarMSW::AddTool(int index, const wxBitmap& bitmap, const wx tool->m_y = m_yMargin; tool->m_deleteSecondBitmap = TRUE; - tool->SetSize(GetDefaultButtonWidth(), GetDefaultButtonHeight()); + tool->SetSize(GetToolSize().x, GetToolSize().y); // Calculate reasonable max size in case Layout() not called if ((tool->m_x + bitmap.GetWidth() + m_xMargin) > m_maxWidth) @@ -374,6 +381,107 @@ wxToolBarTool *wxToolBarMSW::AddTool(int index, const wxBitmap& bitmap, const wx return tool; } +void wxToolBarMSW::LayoutTools() +{ + 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; + m_maxHeight += maxToolHeight; + } + else + { + m_maxWidth += maxToolWidth; + m_maxHeight += maxToolHeight; + } + + m_maxWidth += m_xMargin; + m_maxHeight += m_yMargin; + + SetSize(m_maxWidth, m_maxHeight); +} + + bool wxToolBarMSW::InitGlobalObjects(void) { GetSysColors(); @@ -384,7 +492,7 @@ bool wxToolBarMSW::InitGlobalObjects(void) if (!m_hdcMono) return FALSE; - m_hbmMono = (WXHBITMAP) CreateBitmap((int)GetDefaultButtonWidth(), (int)GetDefaultButtonHeight(), 1, 1, NULL); + m_hbmMono = (WXHBITMAP) CreateBitmap((int)GetToolSize().x, (int)GetToolSize().y, 1, 1, NULL); if (!m_hbmMono) return FALSE; @@ -439,7 +547,7 @@ void wxToolBarMSW::CreateMask(WXHDC hdc, int xoffset, int yoffset, int dx, int d // krj - create a new bitmap and copy the image from hdc. //HBITMAP bitmapOld = SelectObject(hdcGlyphs, hBitmap); HBITMAP hBitmap = CreateCompatibleBitmap((HDC) hdc, dx, dy); - HBITMAP bitmapOld = SelectObject(hdcGlyphs, hBitmap); + HBITMAP bitmapOld = (HBITMAP) SelectObject(hdcGlyphs, hBitmap); BitBlt(hdcGlyphs, 0,0, dx, dy, (HDC) hdc, 0, 0, SRCCOPY); // initalize whole area with 1's @@ -448,12 +556,12 @@ void wxToolBarMSW::CreateMask(WXHDC hdc, int xoffset, int yoffset, int dx, int d // create mask based on color bitmap // convert this to 1's SetBkColor(hdcGlyphs, m_rgbFace); - BitBlt((HDC) m_hdcMono, xoffset, yoffset, (int)GetDefaultWidth(), (int)GetDefaultHeight(), + BitBlt((HDC) m_hdcMono, xoffset, yoffset, (int)GetToolBitmapSize().x, (int)GetToolBitmapSize().y, hdcGlyphs, 0, 0, SRCCOPY); // convert this to 1's SetBkColor(hdcGlyphs, m_rgbHilight); // OR in the new 1's - BitBlt((HDC) m_hdcMono, xoffset, yoffset, (int)GetDefaultWidth(), (int)GetDefaultHeight(), + BitBlt((HDC) m_hdcMono, xoffset, yoffset, (int)GetToolBitmapSize().x, (int)GetToolBitmapSize().y, hdcGlyphs, 0, 0, SRCPAINT); SelectObject(hdcGlyphs, bitmapOld); @@ -528,17 +636,17 @@ void wxToolBarMSW::DrawButton(WXHDC hdc, int x, int y, int dx, int dy, wxToolBar #if !defined(__WIN32__) && !defined(__WIN386__) HBITMAP bitmapOld; if (tool->m_bitmap2.Ok()) - bitmapOld = SelectObject(hdcGlyphs, (HBITMAP) tool->m_bitmap2.GetHBITMAP()); + bitmapOld = (HBITMAP) SelectObject(hdcGlyphs, (HBITMAP) tool->m_bitmap2.GetHBITMAP()); else - bitmapOld = SelectObject(hdcGlyphs, (HBITMAP) tool->m_bitmap1.GetHBITMAP()); + bitmapOld = (HBITMAP) SelectObject(hdcGlyphs, (HBITMAP) tool->m_bitmap1.GetHBITMAP()); #else - HBITMAP bitmapOld = SelectObject(hdcGlyphs, (HBITMAP) tool->m_bitmap1.GetHBITMAP()); + HBITMAP bitmapOld = (HBITMAP) SelectObject(hdcGlyphs, (HBITMAP) tool->m_bitmap1.GetHBITMAP()); #endif // calculate offset of face from (x,y). y is always from the top, // so the offset is easy. x needs to be centered in face. yOffset = 1; - xCenterOffset = (dxFace - (int)GetDefaultWidth())/2; + xCenterOffset = (dxFace - (int)GetToolBitmapSize().x)/2; if (state & (wxTBSTATE_PRESSED | wxTBSTATE_CHECKED)) { // pressed state moves down and to the right @@ -549,7 +657,7 @@ void wxToolBarMSW::DrawButton(WXHDC hdc, int x, int y, int dx, int dy, wxToolBar // now put on the face if (state & wxTBSTATE_ENABLED) { // regular version - BitBlt((HDC) hdc, x+xCenterOffset, y + yOffset, (int)GetDefaultWidth(), (int)GetDefaultHeight(), + BitBlt((HDC) hdc, x+xCenterOffset, y + yOffset, (int)GetToolBitmapSize().x, (int)GetToolBitmapSize().y, hdcGlyphs, 0, 0, SRCCOPY); } else { // disabled version (or indeterminate) @@ -564,7 +672,7 @@ void wxToolBarMSW::DrawButton(WXHDC hdc, int x, int y, int dx, int dy, wxToolBar if (!(state & wxTBSTATE_INDETERMINATE)) { hbr = CreateSolidBrush(m_rgbHilight); if (hbr) { - hbrOld = SelectObject((HDC) hdc, hbr); + hbrOld = (HBRUSH) SelectObject((HDC) hdc, hbr); 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); @@ -577,7 +685,7 @@ void wxToolBarMSW::DrawButton(WXHDC hdc, int x, int y, int dx, int dy, wxToolBar // gray out glyph hbr = CreateSolidBrush(m_rgbShadow); if (hbr) { - hbrOld = SelectObject((HDC) hdc, hbr); + hbrOld = (HBRUSH) SelectObject((HDC) hdc, hbr); 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); @@ -593,7 +701,7 @@ void wxToolBarMSW::DrawButton(WXHDC hdc, int x, int y, int dx, int dy, wxToolBar if (state & (wxTBSTATE_CHECKED | wxTBSTATE_INDETERMINATE)) { - hbrOld = SelectObject((HDC) hdc, (HBRUSH) m_hbrDither); + hbrOld = (HBRUSH) SelectObject((HDC) hdc, (HBRUSH) m_hbrDither); if (hbrOld) { if (!bMaskCreated) @@ -817,7 +925,7 @@ WXHBITMAP wxToolBarMSW::CreateMappedBitmap(WXHINSTANCE WXUNUSED(hInstance), void // hbm = CreateDiscardableBitmap(hdc, i, hgt); hbm = CreateCompatibleBitmap(hdc, i, hgt); if (hbm) { - hbmOld = SelectObject(hdcMem, hbm); + hbmOld = (HBITMAP) SelectObject(hdcMem, hbm); // set the main image StretchDIBits(hdcMem, 0, 0, wid, hgt, 0, 0, wid, hgt, lpBits,