X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2bda0e173844e8e0f8acf4e8ad8b5c26e5c6fe5d..3d05544e4e71e7ff10984dae5a9b8a07d92f42a6:/src/msw/radiobox.cpp diff --git a/src/msw/radiobox.cpp b/src/msw/radiobox.cpp index c4fe0dc4b8..dd9e9421fa 100644 --- a/src/msw/radiobox.cpp +++ b/src/msw/radiobox.cpp @@ -6,7 +6,7 @@ // Created: 04/01/98 // RCS-ID: $Id$ // Copyright: (c) Julian Smart and Markus Holzem -// Licence: wxWindows license +// Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ @@ -23,6 +23,8 @@ #ifndef WX_PRECOMP #include #include "wx/setup.h" +#include "wx/bitmap.h" +#include "wx/brush.h" #include "wx/radiobox.h" #endif @@ -32,7 +34,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxRadioBox, wxControl) #endif -bool wxRadioBox::MSWCommand(const WXUINT param, const WXWORD id) +bool wxRadioBox::MSWCommand(WXUINT param, WXWORD id) { if (param == BN_CLICKED) { @@ -85,10 +87,10 @@ wxRadioBox::wxRadioBox(void) m_radioHeight = NULL ; } -bool wxRadioBox::Create(wxWindow *parent, const wxWindowID id, const wxString& title, +bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, - const int n, const wxString choices[], - const int majorDim, const long style, + int n, const wxString choices[], + int majorDim, long style, const wxValidator& val, const wxString& name) { m_selectedButton = -1; @@ -98,8 +100,8 @@ bool wxRadioBox::Create(wxWindow *parent, const wxWindowID id, const wxString& t SetValidator(val); parent->AddChild(this); - m_backgroundColour = parent->GetDefaultBackgroundColour() ; - m_foregroundColour = parent->GetDefaultForegroundColour() ; + m_backgroundColour = parent->GetBackgroundColour() ; + m_foregroundColour = parent->GetForegroundColour() ; m_windowStyle = (long&)style; @@ -116,7 +118,8 @@ bool wxRadioBox::Create(wxWindow *parent, const wxWindowID id, const wxString& t m_noRowsOrCols = majorDim; if (majorDim==0) m_majorDim = n ; - m_majorDim = majorDim ; + else // Seemed to make sense to put this 'else' here... (RD) + m_majorDim = majorDim ; long msStyle = GROUP_FLAGS; @@ -124,41 +127,39 @@ bool wxRadioBox::Create(wxWindow *parent, const wxWindowID id, const wxString& t WXDWORD exStyle = Determine3DEffects(0, &want3D) ; // Even with extended styles, need to combine with WS_BORDER // for them to look right. - if (want3D && ((m_windowStyle & wxSIMPLE_BORDER) || (m_windowStyle & wxRAISED_BORDER) || - (m_windowStyle & wxSUNKEN_BORDER) || (m_windowStyle & wxDOUBLE_BORDER))) +/* + if ( want3D || wxStyleHasBorder(m_windowStyle) ) msStyle |= WS_BORDER; +*/ - m_hWnd = (WXHWND) CreateWindowEx((DWORD) exStyle, GROUP_CLASS, (title == "" ? NULL : (const char *)title), - msStyle, - 0,0,0,0, - (HWND) parent->GetHWND(), (HMENU) m_windowId, wxGetInstance(), NULL) ; - HWND the_handle = (HWND) parent->GetHWND() ; + m_hWnd = (WXHWND)::CreateWindowEx + ( + (DWORD)exStyle, + GROUP_CLASS, + title, + msStyle, + 0, 0, 0, 0, + the_handle, + (HMENU)m_windowId, + wxGetInstance(), + NULL + ); + #if CTL3D if (want3D) { - Ctl3dSubclassCtl((HWND) m_hWnd); - m_useCtl3D = TRUE; + Ctl3dSubclassCtl((HWND)m_hWnd); + m_useCtl3D = TRUE; } #endif - SetFont(* parent->GetFont()); + SetFont(parent->GetFont()); - // Subclass again for purposes of dialog editing mode SubclassWin((WXHWND)m_hWnd); -/* Label will be the same as button font now. - if (labelFont) - { - labelFont->RealizeResource(); - if (labelFont->GetResourceHandle()) - SendMessage(ms_handle,WM_SETFONT, - (WPARAM)labelFont->GetResourceHandle(),0L); - } -*/ - // Some radio boxes test consecutive id. (void)NewControlId() ; m_radioButtons = new WXHWND[n]; @@ -181,13 +182,13 @@ bool wxRadioBox::Create(wxWindow *parent, const wxWindowID id, const wxString& t if (want3D) { Ctl3dSubclassCtl((HWND) m_hWnd); - m_useCtl3D = TRUE; + m_useCtl3D = TRUE; } #endif - if (GetFont()) + if (GetFont().Ok()) { SendMessage((HWND)m_radioButtons[i],WM_SETFONT, - (WPARAM)GetFont()->GetResourceHandle(),0L); + (WPARAM)GetFont().GetResourceHandle(),0L); } m_subControls.Append((wxObject *)newId); } @@ -203,10 +204,10 @@ bool wxRadioBox::Create(wxWindow *parent, const wxWindowID id, const wxString& t } #if 0 -bool wxRadioBox::Create(wxWindow *parent, const wxWindowID id, const wxString& title, +bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, - const int n, const wxBitmap *choices[], - const int majorDim, const long style, + int n, const wxBitmap *choices[], + int majorDim, long style, const wxValidator& val, const wxString& name) { m_selectedButton = -1; @@ -217,8 +218,8 @@ bool wxRadioBox::Create(wxWindow *parent, const wxWindowID id, const wxString& t SetValidator(val); parent->AddChild(this); - m_backgroundColour = parent->GetDefaultBackgroundColour() ; - m_foregroundColour = parent->GetDefaultForegroundColour() ; + m_backgroundColour = parent->GetBackgroundColour() ; + m_foregroundColour = parent->GetForegroundColour() ; m_windowStyle = (long&)style; @@ -245,8 +246,7 @@ bool wxRadioBox::Create(wxWindow *parent, const wxWindowID id, const wxString& t WXDWORD exStyle = Determine3DEffects(0, &want3D) ; // Even with extended styles, need to combine with WS_BORDER // for them to look right. - if (want3D && ((m_windowStyle & wxSIMPLE_BORDER) || (m_windowStyle & wxRAISED_BORDER) || - (m_windowStyle & wxSUNKEN_BORDER) || (m_windowStyle & wxDOUBLE_BORDER))) + if ( want3D || wxStyleHasBorder(m_windowStyle) ) msStyle |= WS_BORDER; m_hWnd = (WXHWND) CreateWindowEx((DWORD) exStyle, GROUP_CLASS, (title == "" ? NULL : (const char *)title), @@ -254,26 +254,17 @@ bool wxRadioBox::Create(wxWindow *parent, const wxWindowID id, const wxString& t 0,0,0,0, (HWND) parent->GetHWND(), (HMENU) m_windowId, wxGetInstance(), NULL) ; -/* - if (labelFont) - { - labelFont->RealizeResource(); - if (labelFont->GetResourceHandle()) - SendMessage(ms_handle,WM_SETFONT, - (WPARAM)labelFont->GetResourceHandle(),0L); - } -*/ the_handle = (HWND) parent->GetHWND(); #if CTL3D if (want3D) { Ctl3dSubclassCtl((HWND) m_hWnd); - m_useCtl3D = TRUE; + m_useCtl3D = TRUE; } #endif - SetFont(* parent->GetFont()); + SetFont(parent->GetFont()); // Subclass again for purposes of dialog editing mode SubclassWin((WXHWND)m_hWnd); @@ -302,7 +293,7 @@ bool wxRadioBox::Create(wxWindow *parent, const wxWindowID id, const wxString& t if (want3D) { Ctl3dSubclassCtl((HWND) m_hWnd); - m_useCtl3D = TRUE; + m_useCtl3D = TRUE; } #endif m_subControls.Append((wxObject *)newId); @@ -321,7 +312,7 @@ bool wxRadioBox::Create(wxWindow *parent, const wxWindowID id, const wxString& t wxRadioBox::~wxRadioBox(void) { m_isBeingDeleted = TRUE; - + if (m_radioButtons) { int i; @@ -339,19 +330,19 @@ wxRadioBox::~wxRadioBox(void) } -wxString wxRadioBox::GetLabel(const int item) const +wxString wxRadioBox::GetLabel(int item) const { GetWindowText((HWND)m_radioButtons[item], wxBuffer, 300); return wxString(wxBuffer); } -void wxRadioBox::SetLabel(const int item, const wxString& label) +void wxRadioBox::SetLabel(int item, const wxString& label) { m_radioWidth[item] = m_radioHeight[item] = -1 ; SetWindowText((HWND)m_radioButtons[item], (const char *)label); } -void wxRadioBox::SetLabel(const int item, wxBitmap *bitmap) +void wxRadioBox::SetLabel(int item, wxBitmap *bitmap) { /* m_radioWidth[item] = bitmap->GetWidth() + FB_MARGIN ; @@ -371,7 +362,7 @@ int wxRadioBox::FindString(const wxString& s) const return -1; } -void wxRadioBox::SetSelection(const int N) +void wxRadioBox::SetSelection(int N) { if ((N < 0) || (N >= m_noItems)) return; @@ -391,13 +382,13 @@ int wxRadioBox::GetSelection(void) const } // Find string for position -wxString wxRadioBox::GetString(const int N) const +wxString wxRadioBox::GetString(int N) const { GetWindowText((HWND) m_radioButtons[N], wxBuffer, 1000); return wxString(wxBuffer); } -void wxRadioBox::SetSize(const int x, const int y, const int width, const int height, const int sizeFlags) +void wxRadioBox::SetSize(int x, int y, int width, int height, int sizeFlags) { int currentX, currentY; GetPosition(¤tX, ¤tY); @@ -409,16 +400,16 @@ void wxRadioBox::SetSize(const int x, const int y, const int width, const int he if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) yy = currentY; + AdjustForParentClientOrigin(xx, yy, sizeFlags); + char buf[400]; int y_offset = yy; int x_offset = xx; - float current_width; - - float cyf; + int current_width, cyf; int cx1,cy1 ; - wxGetCharSize(m_hWnd, &cx1, &cy1, GetFont()); + wxGetCharSize(m_hWnd, &cx1, &cy1, & GetFont()); // Attempt to have a look coherent with other platforms: // We compute the biggest toggle dim, then we align all // items according this value. @@ -434,7 +425,7 @@ void wxRadioBox::SetSize(const int x, const int y, const int width, const int he { // It's a labelled toggle GetWindowText((HWND) m_radioButtons[i], buf, 300); - GetTextExtent(buf, ¤t_width, &cyf,NULL,NULL, GetFont()); + GetTextExtent(buf, ¤t_width, &cyf,NULL,NULL, & GetFont()); eachWidth = (int)(current_width + RADIO_SIZE); eachHeight = (int)((3*cyf)/2); } @@ -514,7 +505,7 @@ void wxRadioBox::SetSize(const int x, const int y, const int width, const int he { // It's a labeled item GetWindowText((HWND) m_radioButtons[i], buf, 300); - GetTextExtent(buf, ¤t_width, &cyf,NULL,NULL,GetFont()); + GetTextExtent(buf, ¤t_width, &cyf,NULL,NULL, & GetFont()); // How do we find out radio button bitmap size!! // By adjusting them carefully, manually :-) @@ -577,6 +568,15 @@ void wxRadioBox::GetPosition(int *x, int *y) const { ::ScreenToClient((HWND) parent->GetHWND(), &point); } + // We may be faking the client origin. + // So a window that's really at (0, 30) may appear + // (to wxWin apps) to be at (0, 0). + if (GetParent()) + { + wxPoint pt(GetParent()->GetClientAreaOrigin()); + point.x -= pt.x; + point.y -= pt.y; + } *x = point.x; *y = point.y; @@ -594,17 +594,12 @@ wxString wxRadioBox::GetLabel(void) const void wxRadioBox::SetLabel(const wxString& label) { - if (m_hWnd && label) + if (m_hWnd) SetWindowText((HWND) m_hWnd, label); } void wxRadioBox::SetFocus(void) { -/* - if (m_noItems > 0) - ::SetFocus((HWND) m_radioButtons[0]); -*/ -/* Begin Alberts Patch 26. 5. 1997*/ if (m_noItems > 0) { if (m_selectedButton == -1) @@ -612,11 +607,10 @@ void wxRadioBox::SetFocus(void) else ::SetFocus((HWND) m_radioButtons[m_selectedButton]); } -/* Ende Alberts Patch*/ } -bool wxRadioBox::Show(const bool show) +bool wxRadioBox::Show(bool show) { int cshow; if (show) @@ -632,7 +626,7 @@ bool wxRadioBox::Show(const bool show) } // Enable a specific button -void wxRadioBox::Enable(const int item, const bool enable) +void wxRadioBox::Enable(int item, bool enable) { if (item<0) wxWindow::Enable(enable) ; @@ -641,17 +635,17 @@ void wxRadioBox::Enable(const int item, const bool enable) } // Enable all controls -void wxRadioBox::Enable(const bool enable) +void wxRadioBox::Enable(bool enable) { wxControl::Enable(enable); - + int i; for (i = 0; i < m_noItems; i++) ::EnableWindow((HWND) m_radioButtons[i], enable); } // Show a specific button -void wxRadioBox::Show(const int item, const bool show) +void wxRadioBox::Show(int item, bool show) { if (item<0) wxRadioBox::Show(show) ; @@ -666,8 +660,8 @@ void wxRadioBox::Show(const int item, const bool show) } } -WXHBRUSH wxRadioBox::OnCtlColor(const WXHDC pDC, const WXHWND pWnd, const WXUINT nCtlColor, - WXUINT message, WXWPARAM wParam, WXLPARAM lParam) +WXHBRUSH wxRadioBox::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, + WXUINT message, WXWPARAM wParam, WXLPARAM lParam) { #if CTL3D if ( m_useCtl3D ) @@ -715,43 +709,13 @@ bool wxRadioBox::SetStringSelection (const wxString& s) return FALSE; } -/* -void wxRadioBox::SetLabelFont(wxFont *font) -{ - // Decrement the usage count of the old label font - // (we may be able to free it up) - if (labelFont) - labelFont->ReleaseResource(); - - labelFont = font; - - // Increment usage count - if (font) - font->UseResource(); - - HWND hWnd = GetHWND(); - if (hWnd != 0) - { - if (font) - { - font->RealizeResource(); - - if (font->GetResourceHandle()) - SendMessage(hWnd, WM_SETFONT, - (WPARAM)font->GetResourceHandle(),TRUE); - } - } -} - -*/ - bool wxRadioBox::ContainsHWND(WXHWND hWnd) const { - int i; + int i; for (i = 0; i < Number(); i++) if (GetRadioButtons()[i] == hWnd) return TRUE; - return FALSE; + return FALSE; } void wxRadioBox::Command (wxCommandEvent & event) @@ -760,4 +724,21 @@ void wxRadioBox::Command (wxCommandEvent & event) ProcessCommand (event); } +long wxRadioBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) +{ + if (nMsg == WM_NCHITTEST) + { + int xPos = LOWORD(lParam); // horizontal position of cursor + int yPos = HIWORD(lParam); // vertical position of cursor + + ScreenToClient(&xPos, &yPos); + + // Make sure you can drag by the top of the groupbox, but let + // other (enclosed) controls get mouse events also + if (yPos < 10) + return (long)HTCLIENT; + } + + return wxControl::MSWWindowProc(nMsg, wParam, lParam); +}