#include "wx/control.h"
#endif
-#if wxUSE_TOOLBAR && wxUSE_TOOLBAR_NATIVE && (!defined(_WIN32_WCE) || (_WIN32_WCE >= 400 && !defined(WIN32_PLATFORM_PSPC) && !defined(WIN32_PLATFORM_WFSP)))
+#if wxUSE_TOOLBAR && wxUSE_TOOLBAR_NATIVE && (!defined(_WIN32_WCE) || (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__)))
#include "wx/toolbar.h"
#include "wx/sysopt.h"
#include "wx/msw/private.h"
+#if wxUSE_UXTHEME
+#include "wx/msw/uxtheme.h"
+#endif
+
// include <commctrl.h> "properly"
#include "wx/msw/wrapcctl.h"
IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl)
/*
- TOOLBAR PROPERTIES
- tool
- bitmap
- bitmap2
- tooltip
- longhelp
- radio (bool)
- toggle (bool)
- separator
- style ( wxNO_BORDER | wxTB_HORIZONTAL)
- bitmapsize
- margins
- packing
- separation
-
- dontattachtoframe
+ TOOLBAR PROPERTIES
+ tool
+ bitmap
+ bitmap2
+ tooltip
+ longhelp
+ radio (bool)
+ toggle (bool)
+ separator
+ style ( wxNO_BORDER | wxTB_HORIZONTAL)
+ bitmapsize
+ margins
+ packing
+ separation
+
+ dontattachtoframe
*/
BEGIN_EVENT_TABLE(wxToolBar, wxToolBarBase)
{
// common initialisation
if ( !CreateControl(parent, id, pos, size, style, wxDefaultValidator, name) )
- return FALSE;
+ return false;
// MSW-specific initialisation
if ( !MSWCreateToolbar(pos, size) )
- return FALSE;
+ return false;
wxSetCCUnicodeFormat(GetHwnd());
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR));
SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
- return TRUE;
+ // workaround for flat toolbar on Windows XP classic style
+#if wxUSE_UXTHEME
+ if ( style & wxTB_FLAT )
+ {
+ wxUxThemeEngine *p = wxUxThemeEngine::Get();
+ if ( !p || !p->IsThemeActive() )
+ {
+ DWORD dwToolbarStyle;
+
+ dwToolbarStyle = (DWORD)::SendMessage(GetHwnd(), TB_GETSTYLE, 0, 0L );
+
+ if ((dwToolbarStyle & TBSTYLE_FLAT) == 0)
+ {
+ dwToolbarStyle |= TBSTYLE_FLAT;
+ ::SendMessage(GetHwnd(), TB_SETSTYLE, 0, (LPARAM)dwToolbarStyle );
+ }
+ }
+ }
+#endif
+
+ return true;
}
bool wxToolBar::MSWCreateToolbar(const wxPoint& pos, const wxSize& size)
{
if ( !MSWCreateControl(TOOLBARCLASSNAME, wxEmptyString, pos, size) )
- return FALSE;
+ return false;
// toolbar-specific post initialisation
::SendMessage(GetHwnd(), TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
- return TRUE;
+ return true;
}
void wxToolBar::Recreate()
// Realize() later
tool->Attach(this);
- return TRUE;
+ InvalidateBestSize();
+ return true;
}
bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool)
{
wxLogLastError(wxT("TB_DELETEBUTTON"));
- return FALSE;
+ return false;
}
}
int x;
wxControl *control = tool2->GetControl();
control->GetPosition(&x, NULL);
- control->Move(x - width, -1);
+ control->Move(x - width, wxDefaultCoord);
}
}
- return TRUE;
+ InvalidateBestSize();
+ return true;
}
bool wxToolBar::Realize()
if ( nTools == 0 )
{
// nothing to do
- return TRUE;
+ return true;
}
const bool isVertical = HasFlag(wxTB_VERTICAL);
+ bool doRemap, doRemapBg, doTransparent;
+ if (wxSystemOptions::GetOptionInt(wxT("msw.remap")) == 2)
+ {
+ doRemapBg = doRemap = false;
+ doTransparent = true;
+ }
+ else
+ { doRemap = !wxSystemOptions::HasOption(wxT("msw.remap"))
+ || wxSystemOptions::GetOptionInt(wxT("msw.remap")) == 1;
+ doRemapBg = !doRemap;
+ doTransparent = false;
+ }
+
// delete all old buttons, if any
for ( size_t pos = 0; pos < m_nButtons; pos++ )
{
wxMemoryDC dcAllButtons;
wxBitmap bitmap(totalBitmapWidth, totalBitmapHeight);
dcAllButtons.SelectObject(bitmap);
+ if (doTransparent)
+ dcAllButtons.SetBackground(*wxTRANSPARENT_BRUSH);
+ else
dcAllButtons.SetBackground(*wxLIGHT_GREY_BRUSH);
dcAllButtons.Clear();
{
wxLogLastError(_T("CreateCompatibleBitmap"));
- return FALSE;
+ return false;
}
m_hBitmap = (WXHBITMAP)hBitmap;
MemoryHDC memoryDC2;
#endif // USE_BITMAP_MASKS/!USE_BITMAP_MASKS
- if (wxSystemOptions::HasOption(wxT("msw.remap")) && wxSystemOptions::GetOptionInt(wxT("msw.remap")) == 0)
+ if (doRemapBg)
{
#if USE_BITMAP_MASKS
dcAllButtons.SelectObject(wxNullBitmap);
int yOffset = wxMax(0, (m_defaultHeight - bmp.GetHeight())/2);
#if USE_BITMAP_MASKS
// notice the last parameter: do use mask
- dcAllButtons.DrawBitmap(bmp, x+xOffset, yOffset, TRUE);
+ dcAllButtons.DrawBitmap(bmp, x+xOffset, yOffset, true);
#else // !USE_BITMAP_MASKS
SelectInHDC hdcSelector2(memoryDC2, GetHbitmapOf(bmp));
if ( !BitBlt(memoryDC,
bitmap.SetHBITMAP(0);
#endif // USE_BITMAP_MASKS/!USE_BITMAP_MASKS
- if (!wxSystemOptions::HasOption(wxT("msw.remap")) || wxSystemOptions::GetOptionInt(wxT("msw.remap")) == 1)
+ if (doRemap)
{
// Map to system colours
hBitmap = (HBITMAP)MapBitmap((WXHBITMAP) hBitmap,
totalBitmapWidth, totalBitmapHeight);
}
- bool addBitmap = TRUE;
+ bool addBitmap = true;
if ( oldToolBarBitmap )
{
::DeleteObject(oldToolBarBitmap);
// already done
- addBitmap = FALSE;
+ addBitmap = false;
}
else
#endif // TB_REPLACEBITMAP
// we can't replace the old bitmap, so we will add another one
// (awfully inefficient, but what else to do?) and shift the bitmap
// indices accordingly
- addBitmap = TRUE;
+ addBitmap = true;
bitmapId = m_nButtons;
}
// this array will hold the indices of all controls in the toolbar
wxArrayInt controlIds;
- bool lastWasRadio = FALSE;
+ bool lastWasRadio = false;
int i = 0;
for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
{
wxZeroMemory(button);
- bool isRadio = FALSE;
+ bool isRadio = false;
switch ( tool->GetStyle() )
{
case wxTOOL_STYLE_CONTROL:
// radio items
button.fsState |= TBSTATE_CHECKED;
- tool->Toggle(TRUE);
+ tool->Toggle(true);
}
- isRadio = TRUE;
+ isRadio = true;
break;
case wxITEM_CHECK:
// note that we use TB_GETITEMRECT and not TB_GETRECT because the
// latter only appeared in v4.70 of comctl32.dll
RECT r;
- if ( !SendMessage(GetHwnd(), TB_GETITEMRECT,
- index, (LPARAM)(LPRECT)&r) )
+ if ( !::SendMessage(GetHwnd(), TB_GETITEMRECT,
+ index, (LPARAM)(LPRECT)&r) )
{
wxLogLastError(wxT("TB_GETITEMRECT"));
}
wxSize size = control->GetSize();
// the position of the leftmost controls corner
- int left = -1;
+ int left = wxDefaultCoord;
// TB_SETBUTTONINFO message is only supported by comctl32.dll 4.71+
#ifdef TB_SETBUTTONINFO
tbbi.cbSize = sizeof(tbbi);
tbbi.dwMask = TBIF_SIZE;
tbbi.cx = size.x;
- if ( !SendMessage(GetHwnd(), TB_SETBUTTONINFO,
- tool->GetId(), (LPARAM)&tbbi) )
+ if ( !::SendMessage(GetHwnd(), TB_SETBUTTONINFO,
+ tool->GetId(), (LPARAM)&tbbi) )
{
// the id is probably invalid?
wxLogLastError(wxT("TB_SETBUTTONINFO"));
size_t nSeparators = size.x / widthSep;
for ( size_t nSep = 0; nSep < nSeparators; nSep++ )
{
- if ( !SendMessage(GetHwnd(), TB_INSERTBUTTON,
- index, (LPARAM)&tbb) )
+ if ( !::SendMessage(GetHwnd(), TB_INSERTBUTTON,
+ index, (LPARAM)&tbb) )
{
wxLogLastError(wxT("TB_INSERTBUTTON"));
}
((wxToolBarTool *)tool)->SetSeparatorsCount(nSeparators);
// adjust the controls width to exactly cover the separators
- control->SetSize((nSeparators + 1)*widthSep, -1);
+ control->SetSize((nSeparators + 1)*widthSep, wxDefaultCoord);
}
// position the control itself correctly vertically
if ( diff < 0 )
{
// the control is too high, resize to fit
- control->SetSize(-1, height - 2);
+ control->SetSize(wxDefaultCoord, height - 2);
diff = 2;
}
}
else // horizontal toolbar
{
- if ( left == -1 )
+ if ( left == wxDefaultCoord )
left = r.left;
top = r.top;
}
}
- return TRUE;
+ InvalidateBestSize();
+ return true;
}
// ----------------------------------------------------------------------------
{
wxToolBarToolBase *tool = FindById((int)id);
if ( !tool )
- return FALSE;
+ return false;
bool toggled = false; // just to suppress warnings
// ignore the event when a radio button is released, as this doesn't seem to
// happen at all, and is handled otherwise
if ( tool->GetKind() == wxITEM_RADIO && !toggled )
- return TRUE;
+ return true;
tool->Toggle(toggled);
UnToggleRadioGroup(tool);
::SendMessage(GetHwnd(), TB_CHECKBUTTON, id, MAKELONG(toggled, 0));
}
- return TRUE;
+ return true;
}
bool wxToolBar::MSWOnNotify(int WXUNUSED(idCtrl),
// in an ANSI application - this seems to be a bug in comctl32.dll v5
UINT code = hdr->code;
if ( (code != (UINT) TTN_NEEDTEXTA) && (code != (UINT) TTN_NEEDTEXTW) )
- return FALSE;
+ return false;
HWND toolTipWnd = (HWND)::SendMessage((HWND)GetHWND(), TB_GETTOOLTIPS, 0, 0);
if ( toolTipWnd != hdr->hwndFrom )
- return FALSE;
+ return false;
LPTOOLTIPTEXT ttText = (LPTOOLTIPTEXT)lParam;
int id = (int)ttText->hdr.idFrom;
wxToolBarToolBase *tool = FindById(id);
if ( !tool )
- return FALSE;
+ return false;
return HandleTooltipNotify(code, lParam, tool->GetShortHelp());
#else
- return FALSE;
+ return false;
#endif
}
void wxToolBar::UpdateSize()
{
// the toolbar size changed
- SendMessage(GetHwnd(), TB_AUTOSIZE, 0, 0);
+ ::SendMessage(GetHwnd(), TB_AUTOSIZE, 0, 0);
// we must also refresh the frame after the toolbar size (possibly) changed
wxFrame *frame = wxDynamicCast(GetParent(), wxFrame);
}
// message processed
- return TRUE;
+ return true;
}
- return FALSE;
+ return false;
}
bool wxToolBar::HandlePaint(WXWPARAM wParam, WXLPARAM lParam)
if ( !node )
{
// no controls, nothing to erase
- return FALSE;
+ return false;
}
// prepare the DC on which we'll be drawing
dc.SetPen(*wxTRANSPARENT_PEN);
RECT r;
- if ( !GetUpdateRect(GetHwnd(), &r, FALSE) )
+ if ( !::GetUpdateRect(GetHwnd(), &r, FALSE) )
{
// nothing to redraw anyhow
- return FALSE;
+ return false;
}
wxRect rectUpdate;
{
// yes, do erase it!
dc.DrawRectangle(rectItem);
-
+
// Necessary in case we use a no-paint-on-size
// style in the parent: the controls can disappear
- control->Refresh(FALSE);
+ control->Refresh(false);
}
}
}
}
- return TRUE;
+ return true;
}
void wxToolBar::HandleMouseMove(WXWPARAM WXUNUSED(wParam), WXLPARAM lParam)