bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, int n, const wxString choices[], int majorDim, long style, const wxValidator& val, const wxString& name) { // common initialization if ( !wxStaticBox::Create(parent, id, title, pos, size, style, name) ) return false; // the code elsewhere in this file supposes that either wxRA_SPECIFY_COLS // or wxRA_SPECIFY_ROWS is set, ensure that this is indeed the case if ( !(style & (wxRA_SPECIFY_ROWS | wxRA_SPECIFY_COLS)) ) style |= wxRA_SPECIFY_COLS; #if wxUSE_VALIDATORS SetValidator(val); #else wxUnusedVar(val); #endif // wxUSE_VALIDATORS/!wxUSE_VALIDATORS // We need an extra one to keep track of the 'dummy' item we // create to end the radio group, so it will be destroyed and // it's id will be released. But we want it separate from the // other buttons since the wxSubwindows will operate on it as // well and we just want to ignore it until destroying it. // For instance, we don't want the bounding box of the radio // buttons to include the dummy button m_radioButtons = new wxSubwindows(n); m_radioWidth = new int[n]; m_radioHeight = new int[n]; for ( int i = 0; i < n; i++ ) { m_radioWidth[i] = m_radioHeight[i] = wxDefaultCoord; long styleBtn = BS_AUTORADIOBUTTON | WS_TABSTOP | WS_CHILD | WS_VISIBLE; if ( i == 0 ) styleBtn |= WS_GROUP; wxWindowIDRef subid = NewControlId(); HWND hwndBtn = ::CreateWindow(wxT("BUTTON"), choices[i].t_str(), styleBtn, 0, 0, 0, 0, // will be set in SetSize() GetHwndOf(parent), (HMENU)wxUIntToPtr(subid.GetValue()), wxGetInstance(), NULL); if ( !hwndBtn ) { wxLogLastError(wxT("CreateWindow(radio btn)")); return false; } // Keep track of the subwindow m_radioButtons->Set(i, hwndBtn, subid); SubclassRadioButton((WXHWND)hwndBtn); // Also, make it a subcontrol of this control m_subControls.Add(subid); } // Create a dummy radio control to end the group. m_dummyId = NewControlId(); m_dummyHwnd = (WXHWND)::CreateWindow(wxT("BUTTON"), wxEmptyString, WS_GROUP | BS_AUTORADIOBUTTON | WS_CHILD, 0, 0, 0, 0, GetHwndOf(parent), (HMENU)wxUIntToPtr(m_dummyId.GetValue()), wxGetInstance(), NULL); m_radioButtons->SetFont(GetFont()); SetMajorDim(majorDim == 0 ? n : majorDim, style); // Select the first radio button if we have any buttons at all. if ( n > 0 ) SetSelection(0); SetSize(pos.x, pos.y, size.x, size.y); // Now that we have items determine what is the best size and set it. SetInitialSize(size); // And update all the buttons positions to match it. const wxSize actualSize = GetSize(); PositionAllButtons(pos.x, pos.y, actualSize.x, actualSize.y); // The base wxStaticBox class never accepts focus, but we do because giving // focus to a wxRadioBox actually gives it to one of its buttons, which are // not visible at wx level and hence are not taken into account by the // logic in wxControlContainer code. m_container.EnableSelfFocus(); return true; }
bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, int n, const wxString choices[], int majorDim, long style, const wxValidator& val, const wxString& name) { // common initialization if ( !wxStaticBox::Create(parent, id, title, pos, size, style, name) ) return false; // the code elsewhere in this file supposes that either wxRA_SPECIFY_COLS // or wxRA_SPECIFY_ROWS is set, ensure that this is indeed the case if ( !(style & (wxRA_SPECIFY_ROWS | wxRA_SPECIFY_COLS)) ) style |= wxRA_SPECIFY_COLS; #if wxUSE_VALIDATORS SetValidator(val); #else wxUnusedVar(val); #endif // wxUSE_VALIDATORS/!wxUSE_VALIDATORS // We need an extra one to keep track of the 'dummy' item we // create to end the radio group, so it will be destroyed and // it's id will be released. But we want it separate from the // other buttons since the wxSubwindows will operate on it as // well and we just want to ignore it until destroying it. // For instance, we don't want the bounding box of the radio // buttons to include the dummy button m_radioButtons = new wxSubwindows(n); m_radioWidth = new int[n]; m_radioHeight = new int[n]; for ( int i = 0; i < n; i++ ) { m_radioWidth[i] = m_radioHeight[i] = wxDefaultCoord; long styleBtn = BS_AUTORADIOBUTTON | WS_TABSTOP | WS_CHILD | WS_VISIBLE; if ( i == 0 ) styleBtn |= WS_GROUP; wxWindowIDRef subid = NewControlId(); HWND hwndBtn = ::CreateWindow(wxT("BUTTON"), choices[i].wx_str(), styleBtn, 0, 0, 0, 0, // will be set in SetSize() GetHwndOf(parent), (HMENU)wxUIntToPtr(subid.GetValue()), wxGetInstance(), NULL); if ( !hwndBtn ) { wxLogLastError(wxT("CreateWindow(radio btn)")); return false; } // Keep track of the subwindow m_radioButtons->Set(i, hwndBtn, subid); SubclassRadioButton((WXHWND)hwndBtn); // Also, make it a subcontrol of this control m_subControls.Add(subid); } // Create a dummy radio control to end the group. m_dummyId = NewControlId(); m_dummyHwnd = (WXHWND)::CreateWindow(wxT("BUTTON"), wxEmptyString, WS_GROUP | BS_AUTORADIOBUTTON | WS_CHILD, 0, 0, 0, 0, GetHwndOf(parent), (HMENU)wxUIntToPtr(m_dummyId.GetValue()), wxGetInstance(), NULL); m_radioButtons->SetFont(GetFont()); #ifdef __WXWINCE__ // Set the z-order correctly SetWindowPos(GetHwnd(), HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); #endif SetMajorDim(majorDim == 0 ? n : majorDim, style); SetSelection(0); SetSize(pos.x, pos.y, size.x, size.y); // Now that we have items determine what is the best size and set it. SetInitialSize(size); return true; }
bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, int n, const wxString choices[], int majorDim, long style, const wxValidator& val, const wxString& name) { // initialize members m_majorDim = majorDim == 0 ? n : majorDim; // common initialization if ( !wxStaticBox::Create(parent, id, title, pos, size, style, name) ) return false; #if wxUSE_VALIDATORS SetValidator(val); #else wxUnusedVar(val); #endif // wxUSE_VALIDATORS/!wxUSE_VALIDATORS m_radioButtons = new wxSubwindows(n); m_radioWidth = new int[n]; m_radioHeight = new int[n]; for ( int i = 0; i < n; i++ ) { m_radioWidth[i] = m_radioHeight[i] = wxDefaultCoord; long styleBtn = BS_AUTORADIOBUTTON | WS_TABSTOP | WS_CHILD | WS_VISIBLE; if ( i == 0 ) styleBtn |= WS_GROUP; long newId = NewControlId(); HWND hwndBtn = ::CreateWindow(_T("BUTTON"), choices[i], styleBtn, 0, 0, 0, 0, // will be set in SetSize() GetHwnd(), (HMENU)newId, wxGetInstance(), NULL); if ( !hwndBtn ) { wxLogLastError(wxT("CreateWindow(radio btn)")); return false; } (*m_radioButtons)[i] = hwndBtn; SubclassRadioButton((WXHWND)hwndBtn); m_subControls.Add(newId); } // Create a dummy radio control to end the group. (void)::CreateWindow(_T("BUTTON"), wxEmptyString, WS_GROUP | BS_AUTORADIOBUTTON | WS_CHILD, 0, 0, 0, 0, GetHwnd(), (HMENU)NewControlId(), wxGetInstance(), NULL); m_radioButtons->SetFont(GetFont()); #ifdef __WXWINCE__ // Set the z-order correctly SetWindowPos(GetHwnd(), HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); #endif SetSelection(0); SetSize(pos.x, pos.y, size.x, size.y); // Now that we have items determine what is the best size and set it. SetBestSize(size); return true; }
bool wxRadioBox::Create( wxWindow* pParent, wxWindowID vId, const wxString& rsTitle, const wxPoint& rPos, const wxSize& rSize, int nNum, const wxString asChoices[], int nMajorDim, long lStyle, const wxValidator& rVal, const wxString& rsName ) { wxColour vColour(*wxBLACK); LONG lColor; HWND hWndParent = GetHwndOf(pParent); m_backgroundColour = pParent->GetBackgroundColour(); m_nSelectedButton = -1; m_nNoItems = 0; // // Common initialization // if (!CreateControl( pParent ,vId ,rPos ,rSize ,lStyle ,rVal ,rsName )) return false; if (!OS2CreateControl( wxT("STATIC") ,SS_GROUPBOX ,rPos ,rSize ,rsTitle )) return false; wxAssociateWinWithHandle(m_hWnd, this); // // Now we can set m_nNoItems and let SetMajorDim set m_numCols/m_numRows // m_nNoItems = (unsigned int)nNum; SetMajorDim(nMajorDim == 0 ? nNum : nMajorDim, lStyle); m_ahRadioButtons = new WXHWND[nNum]; m_pnRadioWidth = new int[nNum]; m_pnRadioHeight = new int[nNum]; for (int i = 0; i < nNum; i++) { m_pnRadioWidth[i] = m_pnRadioHeight[i] = -1; long lStyleBtn = BS_AUTORADIOBUTTON | WS_VISIBLE; int nNewId = NewControlId(); if (i == 0) lStyleBtn |= WS_GROUP | WS_TABSTOP; wxString sLabel = ::wxPMTextToLabel(asChoices[i]); HWND hWndBtn = (WXHWND)::WinCreateWindow ( hWndParent, WC_BUTTON, sLabel.c_str(), lStyleBtn, 0, 0, 0, 0, hWndParent, HWND_BOTTOM, (HMENU)nNewId, NULL, NULL ); if (!hWndBtn) { return false; } lColor = (LONG)vColour.GetPixel(); ::WinSetPresParam( hWndBtn ,PP_FOREGROUNDCOLOR ,sizeof(LONG) ,(PVOID)&lColor ); lColor = (LONG)m_backgroundColour.GetPixel(); ::WinSetPresParam( hWndBtn ,PP_BACKGROUNDCOLOR ,sizeof(LONG) ,(PVOID)&lColor ); m_ahRadioButtons[i] = (WXHWND)hWndBtn; SubclassRadioButton((WXHWND)hWndBtn); wxAssociateWinWithHandle(hWndBtn, this); wxOS2SetFont( hWndBtn ,*wxSMALL_FONT ); ::WinSetWindowULong(hWndBtn, QWL_USER, (ULONG)this); m_aSubControls.Add(nNewId); } // // Create a dummy control to end the group. // (void)::WinCreateWindow ( hWndParent, WC_BUTTON, "", WS_GROUP, 0, 0, 0, 0, hWndParent, HWND_TOP, (HMENU)NewControlId(), NULL, NULL ); fnWndProcRadioBox = (WXFARPROC)::WinSubclassWindow( GetHwnd() ,(PFNWP)wxRadioBoxWndProc ); ::WinSetWindowULong(GetHwnd(), QWL_USER, (ULONG)this); lColor = (LONG)vColour.GetPixel(); ::WinSetPresParam( m_hWnd ,PP_FOREGROUNDCOLOR ,sizeof(LONG) ,(PVOID)&lColor ); lColor = (LONG)m_backgroundColour.GetPixel(); ::WinSetPresParam( m_hWnd ,PP_BACKGROUNDCOLOR ,sizeof(LONG) ,(PVOID)&lColor ); SetXComp(0); SetYComp(0); SetSelection(0); SetSize( rPos.x ,rPos.y ,rSize.x ,rSize.y ); return true; } // end of wxRadioBox::Create