// Modified by:
// Created: 04/01/98
// RCS-ID: $Id$
-// Copyright: (c) Julian Smart and Markus Holzem
-// Licence: wxWindows license
+// Copyright: (c) Julian Smart
+// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// ===========================================================================
// headers
// ---------------------------------------------------------------------------
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "radiobox.h"
#endif
#pragma hdrstop
#endif
+#if wxUSE_RADIOBOX
+
#ifndef WX_PRECOMP
#include "wx/bitmap.h"
#include "wx/brush.h"
#include "wx/msw/private.h"
#if wxUSE_TOOLTIPS
- #ifndef __GNUWIN32_OLD__
+ #if !defined(__GNUWIN32_OLD__) || defined(__CYGWIN10__)
#include <commctrl.h>
#endif
#include "wx/tooltip.h"
#endif // wxUSE_TOOLTIPS
+// TODO: wxCONSTRUCTOR
+#if 0 // wxUSE_EXTENDED_RTTI
+WX_DEFINE_FLAGS( wxRadioBoxStyle )
+
+wxBEGIN_FLAGS( wxRadioBoxStyle )
+ // new style border flags, we put them first to
+ // use them for streaming out
+ wxFLAGS_MEMBER(wxBORDER_SIMPLE)
+ wxFLAGS_MEMBER(wxBORDER_SUNKEN)
+ wxFLAGS_MEMBER(wxBORDER_DOUBLE)
+ wxFLAGS_MEMBER(wxBORDER_RAISED)
+ wxFLAGS_MEMBER(wxBORDER_STATIC)
+ wxFLAGS_MEMBER(wxBORDER_NONE)
+
+ // old style border flags
+ wxFLAGS_MEMBER(wxSIMPLE_BORDER)
+ wxFLAGS_MEMBER(wxSUNKEN_BORDER)
+ wxFLAGS_MEMBER(wxDOUBLE_BORDER)
+ wxFLAGS_MEMBER(wxRAISED_BORDER)
+ wxFLAGS_MEMBER(wxSTATIC_BORDER)
+ wxFLAGS_MEMBER(wxBORDER)
+
+ // standard window styles
+ wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
+ wxFLAGS_MEMBER(wxCLIP_CHILDREN)
+ wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
+ wxFLAGS_MEMBER(wxWANTS_CHARS)
+ wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
+ wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
+ wxFLAGS_MEMBER(wxVSCROLL)
+ wxFLAGS_MEMBER(wxHSCROLL)
+
+ wxFLAGS_MEMBER(wxRA_SPECIFY_COLS)
+ wxFLAGS_MEMBER(wxRA_HORIZONTAL)
+ wxFLAGS_MEMBER(wxRA_SPECIFY_ROWS)
+ wxFLAGS_MEMBER(wxRA_VERTICAL)
+
+wxEND_FLAGS( wxRadioBoxStyle )
+
+IMPLEMENT_DYNAMIC_CLASS_XTI(wxRadioBox, wxControl,"wx/radiobox.h")
+
+wxBEGIN_PROPERTIES_TABLE(wxRadioBox)
+ wxEVENT_PROPERTY( Select , wxEVT_COMMAND_RADIOBOX_SELECTED , wxCommandEvent )
+ wxPROPERTY_FLAGS( WindowStyle , wxRadioBoxStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
+wxEND_PROPERTIES_TABLE()
+
+#else
IMPLEMENT_DYNAMIC_CLASS(wxRadioBox, wxControl)
+#endif
+
+/*
+ selection
+ content
+ label
+ dimension
+ item
+*/
// there are two possible ways to create the radio buttons: either as children
// of the radiobox or as siblings of it - allow playing with both variants for
// wxRadioBox
// ---------------------------------------------------------------------------
+int wxRadioBox::GetCount() const
+{
+ return m_noItems;
+}
+
+int wxRadioBox::GetColumnCount() const
+{
+ return GetNumHor();
+}
+
+int wxRadioBox::GetRowCount() const
+{
+ return GetNumVer();
+}
+
// returns the number of rows
int wxRadioBox::GetNumVer() const
{
return FALSE;
}
-#if WXWIN_COMPATIBILITY
-wxRadioBox::wxRadioBox(wxWindow *parent, wxFunction func, const char *title,
- int x, int y, int width, int height,
- int n, char **choices,
- int majorDim, long style, const char *name)
-{
- wxString *choices2 = new wxString[n];
- for ( int i = 0; i < n; i ++) choices2[i] = choices[i];
- Create(parent, -1, title, wxPoint(x, y), wxSize(width, height), n, choices2, majorDim, style,
- wxDefaultValidator, name);
- Callback(func);
- delete choices2;
-}
-
-#endif // WXWIN_COMPATIBILITY
-
// Radio box item
wxRadioBox::wxRadioBox()
{
// Create a dummy radio control to end the group.
(void)::CreateWindow(_T("BUTTON"),
- _T(""),
+ wxEmptyString,
WS_GROUP | BS_AUTORADIOBUTTON | WS_CHILD,
0, 0, 0, 0, hwndParent,
(HMENU)NewControlId(), wxGetInstance(), NULL);
return TRUE;
}
+bool wxRadioBox::Create(wxWindow *parent,
+ wxWindowID id,
+ const wxString& title,
+ const wxPoint& pos,
+ const wxSize& size,
+ const wxArrayString& choices,
+ int majorDim,
+ long style,
+ const wxValidator& val,
+ const wxString& name)
+{
+ wxCArrayString chs(choices);
+ return Create(parent, id, title, pos, size, chs.GetCount(),
+ chs.GetStrings(), majorDim, style, val, name);
+}
+
wxRadioBox::~wxRadioBox()
{
m_isBeingDeleted = TRUE;
}
-wxString wxRadioBox::GetLabel(int item) const
-{
- wxCHECK_MSG( item >= 0 && item < m_noItems, wxT(""), wxT("invalid radiobox index") );
-
- return wxGetWindowText(m_radioButtons[item]);
-}
-
-void wxRadioBox::SetLabel(int item, const wxString& label)
+void wxRadioBox::SetString(int item, const wxString& label)
{
wxCHECK_RET( item >= 0 && item < m_noItems, wxT("invalid radiobox index") );
SetWindowText((HWND)m_radioButtons[item], label.c_str());
}
-void wxRadioBox::SetLabel(int WXUNUSED(item), wxBitmap *WXUNUSED(bitmap))
-{
- /*
- m_radioWidth[item] = bitmap->GetWidth() + FB_MARGIN;
- m_radioHeight[item] = bitmap->GetHeight() + FB_MARGIN;
- */
- wxFAIL_MSG(wxT("not implemented"));
-}
-
-int wxRadioBox::FindString(const wxString& s) const
-{
- for (int i = 0; i < m_noItems; i++)
- {
- if ( s == wxGetWindowText(m_radioButtons[i]) )
- return i;
- }
-
- return wxNOT_FOUND;
-}
-
void wxRadioBox::SetSelection(int N)
{
wxCHECK_RET( (N >= 0) && (N < m_noItems), wxT("invalid radiobox index") );
::SendMessage((HWND) m_radioButtons[m_selectedButton], BM_SETCHECK, 0, 0L);
::SendMessage((HWND)m_radioButtons[N], BM_SETCHECK, 1, 0L);
- ::SetFocus((HWND)m_radioButtons[N]);
m_selectedButton = N;
}
}
// Find string for position
-wxString wxRadioBox::GetString(int N) const
+wxString wxRadioBox::GetString(int item) const
{
- return wxGetWindowText(m_radioButtons[N]);
+ wxCHECK_MSG( item >= 0 && item < m_noItems, wxEmptyString,
+ wxT("invalid radiobox index") );
+
+ return wxGetWindowText(m_radioButtons[item]);
}
// ----------------------------------------------------------------------------
int extraHeight = cy1;
+ /* We'll assume the adjustments below are OK for Win 3.1 too
#if defined(CTL3D) && !CTL3D
// Requires a bigger group box in plain Windows
extraHeight *= 3;
extraHeight /= 2;
#endif
-
+ */
+
int height = GetNumVer() * sizeBtn.y + cy1/2 + extraHeight;
int width = GetNumHor() * (sizeBtn.x + cx1) + cx1;
+ // Add extra space under the label, if it exists.
+ if (!wxControl::GetLabel().IsEmpty())
+ height += cy1/2;
+
// and also wide enough for its label
int widthLabel;
GetTextExtent(GetTitle(), &widthLabel, NULL);
x_offset += cx1;
y_offset += cy1;
-#if defined(CTL3D) && (!CTL3D)
- y_offset += (int)(cy1/2); // Fudge factor since buttons overlapped label
- // JACS 2/12/93. CTL3D draws group label quite high.
-#endif
+ // Add extra space under the label, if it exists.
+ if (!wxControl::GetLabel().IsEmpty())
+ y_offset += cy1/2;
int startX = x_offset;
int startY = y_offset;
{
if (m_noItems > 0)
{
- if (m_selectedButton == -1)
- ::SetFocus((HWND) m_radioButtons[0]);
- else
- ::SetFocus((HWND) m_radioButtons[m_selectedButton]);
+ ::SetFocus((HWND)m_radioButtons[m_selectedButton == -1
+ ? 0
+ : m_selectedButton]);
}
}
::ShowWindow((HWND)m_radioButtons[item], show ? SW_SHOW : SW_HIDE);
}
-// For single selection items only
-wxString wxRadioBox::GetStringSelection() const
-{
- wxString result;
- int sel = GetSelection();
- if (sel > -1)
- result = GetString(sel);
-
- return result;
-}
-
-bool wxRadioBox::SetStringSelection(const wxString& s)
-{
- int sel = FindString (s);
- if (sel > -1)
- {
- SetSelection (sel);
- return TRUE;
- }
- else
- return FALSE;
-}
-
bool wxRadioBox::ContainsHWND(WXHWND hWnd) const
{
- int i;
- for (i = 0; i < Number(); i++)
+ size_t count = GetCount();
+ for ( size_t i = 0; i < count; i++ )
{
- if (GetRadioButtons()[i] == hWnd)
+ if ( GetRadioButtons()[i] == hWnd )
return TRUE;
}
void wxRadioBox::Command(wxCommandEvent & event)
{
SetSelection (event.m_commandInt);
+ SetFocus();
ProcessCommand (event);
}
// radiobox pointer in GWL_USERDATA for radio buttons must be updated too!
void wxRadioBox::SubclassRadioButton(WXHWND hWndBtn)
{
- // No GWL_USERDATA in Win16, so omit this subclassing.
-#ifdef __WIN32__
HWND hwndBtn = (HWND)hWndBtn;
if ( !s_wndprocRadioBtn )
- s_wndprocRadioBtn = (WXFARPROC)::GetWindowLong(hwndBtn, GWL_WNDPROC);
+ s_wndprocRadioBtn = (WXFARPROC)wxGetWindowProc(hwndBtn);
- ::SetWindowLong(hwndBtn, GWL_WNDPROC, (long)wxRadioBtnWndProc);
- ::SetWindowLong(hwndBtn, GWL_USERDATA, (long)this);
-#endif // __WIN32__
+ wxSetWindowProc(hwndBtn, wxRadioBtnWndProc);
+ wxSetWindowUserData(hwndBtn, this);
}
void wxRadioBox::SendNotificationEvent()
// our window proc
// ----------------------------------------------------------------------------
-long wxRadioBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
+WXLRESULT wxRadioBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
{
switch ( nMsg )
{
wxBrush *brush = wxTheBrushList->FindOrCreateBrush(colBack, wxSOLID);
- return (WXHBRUSH)brush->GetResourceHandle();
+ return (WXLRESULT)brush->GetResourceHandle();
}
#endif // Win32
+ // VZ: this code breaks radiobox redrawing under Windows XP, don't use
+ // it. If you need to get messages from the static controls,
+ // create them as a child of another (non static) window
+#if 0
// This is required for the radiobox to be sensitive to mouse input,
// e.g. for Dialog Editor.
case WM_NCHITTEST:
return (long)HTCLIENT;
}
break;
+#endif // 0
}
return wxControl::MSWWindowProc(nMsg, wParam, lParam);
}
WXHBRUSH wxRadioBox::OnCtlColor(WXHDC pDC, WXHWND WXUNUSED(pWnd), WXUINT WXUNUSED(nCtlColor),
+#if wxUSE_CTL3D
+ WXUINT message,
+ WXWPARAM wParam,
+ WXLPARAM lParam
+#else
WXUINT WXUNUSED(message),
WXWPARAM WXUNUSED(wParam),
- WXLPARAM WXUNUSED(lParam))
+ WXLPARAM WXUNUSED(lParam)
+#endif
+ )
{
#if wxUSE_CTL3D
if ( m_useCtl3D )
#endif // wxUSE_CTL3D
HDC hdc = (HDC)pDC;
- if (GetParent()->GetTransparentBackground())
- SetBkMode(hdc, TRANSPARENT);
- else
- SetBkMode(hdc, OPAQUE);
-
wxColour colBack = GetBackgroundColour();
if (!IsEnabled())
- colBack = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE);
+ colBack = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
::SetBkColor(hdc, wxColourToRGB(colBack));
::SetTextColor(hdc, wxColourToRGB(GetForegroundColour()));
case WM_NOTIFY:
{
NMHDR* hdr = (NMHDR *)lParam;
- if ( (int)hdr->code == TTN_NEEDTEXT )
+ if ( hdr->code == TTN_NEEDTEXT )
{
- wxRadioBox *radiobox = (wxRadioBox *)
- ::GetWindowLong(hwnd, GWL_USERDATA);
+ wxRadioBox *
+ radiobox = (wxRadioBox *)wxGetWindowUserData(hwnd);
wxCHECK_MSG( radiobox, 0,
wxT("radio button without radio box?") );
case WM_KEYDOWN:
{
- wxRadioBox *radiobox = (wxRadioBox *)
- ::GetWindowLong(hwnd, GWL_USERDATA);
+ wxRadioBox *radiobox = (wxRadioBox *)wxGetWindowUserData(hwnd);
wxCHECK_MSG( radiobox, 0, wxT("radio button without radio box?") );
bool processed = TRUE;
- bool horz = (radiobox->GetWindowStyle() & wxRA_SPECIFY_COLS) != 0;
- int num = radiobox->Number(),
- rows = radiobox->GetNumVer(),
- cols = radiobox->GetNumHor();
-
- int selOld = radiobox->GetSelection();
- int selNew = selOld;
-
- // wrapping will be handled below for the cases when we
- // add/substract more than 1 but here otherwise as it's simpler
+ wxDirection dir;
switch ( wParam )
{
case VK_UP:
- if ( horz )
- selNew -= cols;
- else
- {
- if ( selNew )
- selNew--;
- else
- selNew = num - 1;
- }
+ dir = wxUP;
break;
case VK_LEFT:
- if ( horz )
- {
- if ( selNew )
- selNew--;
- else
- selNew = num - 1;
- }
- else
- selNew -= rows;
+ dir = wxLEFT;
break;
case VK_DOWN:
- if ( horz )
- selNew += cols;
- else
- {
- if ( ++selNew == num )
- selNew = 0;
- }
+ dir = wxDOWN;
break;
case VK_RIGHT:
- if ( horz )
- {
- if ( ++selNew == num )
- selNew = 0;
- }
- else
- selNew += rows;
+ dir = wxRIGHT;
break;
default:
processed = FALSE;
+
+ // just to suppress the compiler warning
+ dir = wxALL;
}
if ( processed )
{
- // ensure that selNew is in range [0..num)
- if ( selNew >= num )
- {
- selNew -= num;
-
- int dim = horz ? cols : rows;
- selNew += dim - 1;
- selNew %= dim;
- }
- else if ( selNew < 0 )
- {
- selNew += num;
-
- int dim = horz ? cols : rows;
- if ( selNew % dim == 0 )
- {
- selNew -= dim - 1;
- }
- else
- {
- selNew++;
- }
- }
+ int selOld = radiobox->GetSelection();
+ int selNew = radiobox->GetNextItem
+ (
+ selOld,
+ dir,
+ radiobox->GetWindowStyle()
+ );
if ( selNew != selOld )
{
radiobox->SetSelection(selNew);
+ radiobox->SetFocus();
// emulate the button click
radiobox->SendNotificationEvent();
}
break;
+ case WM_SETFOCUS:
+ case WM_KILLFOCUS:
+ {
+ wxRadioBox *radiobox = (wxRadioBox *)wxGetWindowUserData(hwnd);
+
+ wxCHECK_MSG( radiobox, 0, wxT("radio button without radio box?") );
+
+ // if we don't do this, no focus events are generated for the
+ // radiobox and, besides, we need to notify the parent about
+ // the focus change, otherwise the focus handling logic in
+ // wxControlContainer doesn't work
+ if ( message == WM_SETFOCUS )
+ radiobox->HandleSetFocus((WXHWND)wParam);
+ else
+ radiobox->HandleKillFocus((WXHWND)wParam);
+ }
+ break;
+
#ifdef __WIN32__
case WM_HELP:
- {
- wxRadioBox *radiobox = (wxRadioBox *)
- ::GetWindowLong(hwnd, GWL_USERDATA);
+ {
+ wxRadioBox *radiobox = (wxRadioBox *)wxGetWindowUserData(hwnd);
- wxCHECK_MSG( radiobox, 0, wxT("radio button without radio box?") );
+ wxCHECK_MSG( radiobox, 0, wxT("radio button without radio box?") );
- bool processed = TRUE;
+ bool processed = TRUE;
- HELPINFO* info = (HELPINFO*) lParam;
- // Don't yet process menu help events, just windows
- if (info->iContextType == HELPINFO_WINDOW)
- {
- wxWindow* subjectOfHelp = radiobox;
- bool eventProcessed = FALSE;
- while (subjectOfHelp && !eventProcessed)
+ // HELPINFO doesn't seem to be supported on WinCE.
+#ifndef __WXWINCE__
+ HELPINFO* info = (HELPINFO*) lParam;
+ // Don't yet process menu help events, just windows
+ if (info->iContextType == HELPINFO_WINDOW)
+#endif
{
- wxHelpEvent helpEvent(wxEVT_HELP, subjectOfHelp->GetId(), wxPoint(info->MousePos.x, info->MousePos.y) ) ; // info->iCtrlId);
- helpEvent.SetEventObject(radiobox);
- eventProcessed = radiobox->GetEventHandler()->ProcessEvent(helpEvent);
+ wxWindow* subjectOfHelp = radiobox;
+ bool eventProcessed = FALSE;
+ while (subjectOfHelp && !eventProcessed)
+ {
+ wxHelpEvent helpEvent(wxEVT_HELP, subjectOfHelp->GetId(),
+#ifdef __WXWINCE__
+ wxPoint(0, 0)
+#else
+ wxPoint(info->MousePos.x, info->MousePos.y)
+#endif
+ ) ; // info->iCtrlId);
+ helpEvent.SetEventObject(radiobox);
+ eventProcessed = radiobox->GetEventHandler()->ProcessEvent(helpEvent);
- // Go up the window hierarchy until the event is handled (or not)
- subjectOfHelp = subjectOfHelp->GetParent();
+ // Go up the window hierarchy until the event is handled (or not)
+ subjectOfHelp = subjectOfHelp->GetParent();
+ }
+ processed = eventProcessed;
}
- processed = eventProcessed;
- }
- else if (info->iContextType == HELPINFO_MENUITEM)
- {
- wxHelpEvent helpEvent(wxEVT_HELP, info->iCtrlId) ;
- helpEvent.SetEventObject(radiobox);
- processed = radiobox->GetEventHandler()->ProcessEvent(helpEvent);
- }
- else processed = FALSE;
-
- if (processed)
- return 0;
-
- break;
- }
+#ifndef __WXWINCE__
+ else if (info->iContextType == HELPINFO_MENUITEM)
+ {
+ wxHelpEvent helpEvent(wxEVT_HELP, info->iCtrlId) ;
+ helpEvent.SetEventObject(radiobox);
+ processed = radiobox->GetEventHandler()->ProcessEvent(helpEvent);
+ }
+ else
+ processed = FALSE;
#endif
+ if (processed)
+ return 0;
+
+ break;
+ }
+#endif // __WIN32__
}
return ::CallWindowProc(CASTWNDPROC s_wndprocRadioBtn, hwnd, message, wParam, lParam);
#endif // __WIN32__
+#endif // wxUSE_RADIOBOX