X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/89b892a2982c7f3bb67837835c2701bd70cdd2bc..678d9f2a42faa84cf934bbb75a5b4414a094012e:/src/msw/tbar95.cpp diff --git a/src/msw/tbar95.cpp b/src/msw/tbar95.cpp index 5466c564ef..6a9fcc6cfa 100644 --- a/src/msw/tbar95.cpp +++ b/src/msw/tbar95.cpp @@ -21,24 +21,26 @@ #endif #ifndef WX_PRECOMP -#include "wx.h" +#include "wx/wx.h" #endif #if wxUSE_BUTTONBAR && wxUSE_TOOLBAR && defined(__WIN95__) -#ifndef __GNUWIN32__ +#if !defined(__GNUWIN32__) && !defined(__SALFORDC__) #include "malloc.h" #endif #include -#ifndef __GNUWIN32__ +#if (defined(__WIN95__) && !defined(__GNUWIN32__)) || defined(__TWIN32__) #include #endif +#ifndef __TWIN32__ #ifdef __GNUWIN32__ #include "wx/msw/gnuwin32/extra.h" #endif +#endif #include "wx/msw/dib.h" #include "wx/tbar95.h" @@ -75,12 +77,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxToolBar95, wxToolBarBase) #endif BEGIN_EVENT_TABLE(wxToolBar95, wxToolBarBase) -#if 0 // it seems like none of these functions does anything anyhow - EVT_SIZE(wxToolBar95::OnSize) - EVT_PAINT(wxToolBar95::OnPaint) - EVT_KILL_FOCUS(wxToolBar95::OnKillFocus) EVT_MOUSE_EVENTS(wxToolBar95::OnMouseEvent) -#endif // 0 EVT_SYS_COLOUR_CHANGED(wxToolBar95::OnSysColourChanged) END_EVENT_TABLE() @@ -102,14 +99,16 @@ bool wxToolBar95::Create(wxWindow *parent, long style, const wxString& name) { + m_hWnd = 0; + m_backgroundColour = wxColour(GetRValue(GetSysColor(COLOR_BTNFACE)), GetGValue(GetSysColor(COLOR_BTNFACE)), GetBValue(GetSysColor(COLOR_BTNFACE))); m_foregroundColour = *wxBLACK ; wxASSERT_MSG( (style & wxTB_VERTICAL) == 0, - "Sorry, wxToolBar95 under Windows 95 only " - "supports horizontal orientation." ); + _T("Sorry, wxToolBar95 under Windows 95 only " + "supports horizontal orientation.") ); m_maxWidth = -1; m_maxHeight = -1; @@ -151,12 +150,20 @@ bool wxToolBar95::Create(wxWindow *parent, msflags |= TBSTYLE_FLAT; } + bool want3D; + WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D) ; + + // Even with extended styles, need to combine with WS_BORDER + // for them to look right. + if ( want3D || wxStyleHasBorder(m_windowStyle) ) + msflags |= WS_BORDER; + // Create the toolbar control. HWND hWndToolbar = CreateWindowEx ( - 0L, // No extended styles. + exStyle, // Extended styles. TOOLBARCLASSNAME, // Class name for the toolbar. - "", // No default text. + _T(""), // No default text. msflags, // Styles x, y, width, height, // Standard toolbar size and position. (HWND) parent->GetHWND(), // Parent window of the toolbar. @@ -165,7 +172,7 @@ bool wxToolBar95::Create(wxWindow *parent, NULL // No class data. ); - wxCHECK_MSG( hWndToolbar, FALSE, "Toolbar creation failed" ); + wxCHECK_MSG( hWndToolbar, FALSE, _T("Toolbar creation failed") ); // Toolbar-specific initialisation ::SendMessage(hWndToolbar, TB_BUTTONSTRUCTSIZE, @@ -247,7 +254,9 @@ bool wxToolBar95::CreateTools() replaceBitmap.nIDNew = (UINT) (HBITMAP) m_hBitmap; replaceBitmap.nButtons = noButtons; if (::SendMessage((HWND) GetHWND(), TB_REPLACEBITMAP, (WPARAM) 0, (LPARAM) &replaceBitmap) == -1) - wxMessageBox("Could not add bitmap to toolbar"); + { + wxFAIL_MSG(_T("Could not add bitmap to toolbar")); + } ::DeleteObject((HBITMAP) oldToolBarBitmap); @@ -266,7 +275,9 @@ bool wxToolBar95::CreateTools() addBitmap.hInst = 0; addBitmap.nID = (UINT)m_hBitmap; if (::SendMessage((HWND) GetHWND(), TB_ADDBITMAP, (WPARAM) noButtons, (LPARAM) &addBitmap) == -1) - wxMessageBox("Could not add bitmap to toolbar"); + { + wxFAIL_MSG(_T("Could not add bitmap to toolbar")); + } } // Now add the buttons. @@ -311,7 +322,7 @@ bool wxToolBar95::CreateTools() long rc = ::SendMessage((HWND) GetHWND(), TB_ADDBUTTONS, (WPARAM)i, (LPARAM)& buttons); - wxCHECK_MSG( rc, FALSE, "failed to add buttons to the toolbar" ); + wxCHECK_MSG( rc, FALSE, _T("failed to add buttons to the toolbar") ); (void)::SendMessage((HWND) GetHWND(), TB_AUTOSIZE, (WPARAM)0, (LPARAM) 0); @@ -338,7 +349,7 @@ bool wxToolBar95::MSWCommand(WXUINT cmd, WXWORD id) return TRUE; } -bool wxToolBar95::MSWNotify(WXWPARAM WXUNUSED(wParam), +bool wxToolBar95::MSWOnNotify(int WXUNUSED(idCtrl), WXLPARAM lParam, WXLPARAM *result) { @@ -362,24 +373,37 @@ bool wxToolBar95::MSWNotify(WXWPARAM WXUNUSED(wParam), wxToolBarTool *tool = (wxToolBarTool *)node->Data(); - if ( tool->m_shortHelpString != "" ) + const wxString& help = tool->m_shortHelpString; + + if ( !help.IsEmpty() ) { if ( hdr->code == TTN_NEEDTEXTA ) { - ttText->lpszText = (char *)(const char *)tool->m_shortHelpString; + ttText->lpszText = (wxChar *)help.c_str(); } #if (_WIN32_IE >= 0x0300) else { // FIXME this is a temp hack only until I understand better what // must be done in both ANSI and Unicode builds - size_t lenAnsi = tool->m_shortHelpString.Len(); - size_t lenUnicode = mbstowcs(NULL, tool->m_shortHelpString, lenAnsi); - wchar_t *pwz = new wchar_t[lenUnicode + 1]; - mbstowcs(pwz, tool->m_shortHelpString, lenAnsi + 1); - memcpy(ttText->szText, pwz, - (sizeof(ttText->szText) - 1)/sizeof(ttText->szText[0])); - ttText->szText[WXSIZEOF(ttText->szText)] = 0; + + size_t lenAnsi = help.Len(); + #ifdef __MWERKS__ + // MetroWerks doesn't like calling mbstowcs with NULL argument + size_t lenUnicode = 2*lenAnsi; + #else + size_t lenUnicode = mbstowcs(NULL, help, lenAnsi); + #endif + + // using the pointer of right type avoids us doing all sorts of + // pointer arithmetics ourselves + wchar_t *dst = (wchar_t *)ttText->szText, + *pwz = new wchar_t[lenUnicode + 1]; + mbstowcs(pwz, help, lenAnsi + 1); + memcpy(dst, pwz, lenUnicode*sizeof(wchar_t)); + + // put the terminating _wide_ NUL + dst[lenUnicode] = 0; delete [] pwz; } @@ -419,14 +443,6 @@ wxSize wxToolBar95::GetMaxSize() const return wxSize(m_maxWidth, m_maxHeight); } -void wxToolBar95::GetSize(int *w, int *h) const -{ - wxWindow::GetSize(w, h); - // For some reason, the returned height is several pixels bigger than that - // displayed! - *h -= 2; -} - // The button size is bigger than the bitmap size wxSize wxToolBar95::GetToolSize() const { @@ -490,7 +506,7 @@ wxToolBarTool *wxToolBar95::AddTool(int index, const wxBitmap& bitmap, const wxB else tool->m_y = m_yMargin; - tool->SetSize(GetDefaultButtonWidth(), GetDefaultButtonHeight()); + tool->SetSize(GetToolSize().x, GetToolSize().y); m_tools.Append((long)index, tool); return tool; @@ -505,14 +521,26 @@ void wxToolBar95::OnSysColourChanged(wxSysColourChangedEvent& event) // Remap the buttons CreateTools(); - Default(); - Refresh(); // Propagate the event to the non-top-level children wxWindow::OnSysColourChanged(event); } +void wxToolBar95::OnMouseEvent(wxMouseEvent& event) +{ + if (event.RightDown()) + { + // For now, we don't have an id. Later we could + // try finding the tool. + OnRightClick((int)-1, event.GetX(), event.GetY()); + } + else + { + event.Skip(); + } +} + // These are the default colors used to map the bitmap colors // to the current system colors