bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& label, const wxPoint& pos, const wxSize& size, int n, const wxString choices[], int majorDim, long style, const wxValidator& val, const wxString& name ) { DontCreatePeer(); if ( !wxControl::Create( parent, id, pos, size, style, val, name ) ) return false; // during construction we must keep this at 0, otherwise GetBestSize fails m_noItems = 0; m_noRowsOrCols = majorDim; m_radioButtonCycle = NULL; SetMajorDim( majorDim == 0 ? n : majorDim, style ); m_labelOrig = m_label = label; SetPeer(wxWidgetImpl::CreateGroupBox( this, parent, id, label, pos, size, style, GetExtraStyle() )); #if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ for (int i = 0; i < n; i++) { wxRadioButton *radBtn = new wxRadioButton( this, wxID_ANY, GetLabelText(choices[i]), wxPoint( 5, 20 * i + 10 ), wxDefaultSize, i == 0 ? wxRB_GROUP : 0 ); if ( i == 0 ) m_radioButtonCycle = radBtn; // m_radioButtonCycle = radBtn->AddInCycle( m_radioButtonCycle ); } // as all radiobuttons have been set-up, set the correct dimensions m_noItems = (unsigned int)n; SetMajorDim( majorDim == 0 ? n : majorDim, style ); SetSelection( 0 ); InvalidateBestSize(); SetInitialSize( size ); MacPostControlCreate( pos, size ); return true; }
bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& label, const wxPoint& pos, const wxSize& size, int n, const wxString choices[], int majorDim, long style, const wxValidator& val, const wxString& name ) { m_macIsUserPane = false ; if ( !wxControl::Create( parent, id, pos, size, style, val, name ) ) return false; int i; m_noItems = (unsigned int)n; m_noRowsOrCols = majorDim; m_radioButtonCycle = NULL; SetMajorDim( majorDim == 0 ? n : majorDim, style ); m_labelOrig = m_label = label; m_peer = wxWidgetImpl::CreateGroupBox( this, parent, id, label, pos, size, style, GetExtraStyle() ); for (i = 0; i < n; i++) { wxRadioButton *radBtn = new wxRadioButton( this, wxID_ANY, GetLabelText(choices[i]), wxPoint( 5, 20 * i + 10 ), wxDefaultSize, i == 0 ? wxRB_GROUP : 0 ); if ( i == 0 ) m_radioButtonCycle = radBtn; // m_radioButtonCycle = radBtn->AddInCycle( m_radioButtonCycle ); } SetSelection( 0 ); MacPostControlCreate( pos, 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& wxVALIDATOR_PARAM(val), const wxString& name) { if ( !(style & (wxRA_SPECIFY_ROWS | wxRA_SPECIFY_COLS)) ) style |= wxRA_SPECIFY_COLS; if ( !wxStaticBox::Create(parent, id, title, pos, size, style, name) ) return false; #if wxUSE_VALIDATORS SetValidator(val); #endif // wxUSE_VALIDATORS Append(n, choices); // majorDim default value is 0 which means make one row/column SetMajorDim(majorDim == 0 ? n : majorDim, style); if ( size == wxDefaultSize ) { SetClientSize(DoGetBestClientSize()); } // Need to move the radiobox in order to move the radio buttons wxPoint actualPos = GetPosition(); wxSize actualSize = GetSize(); DoMoveWindow(actualPos.x, actualPos.y, actualSize.x, actualSize.y); // radiobox should already have selection so select at least one item SetSelection(0); 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].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) { // initialize members SetMajorDim(majorDim == 0 ? n : majorDim, style); if ( GetMajorDim() == 0 || n == 0 ) return false; // subtype of the native palmOS radio: checkbox or push button? const bool use_checkbox = style & wxRA_USE_CHECKBOX; const bool use_cols = style & wxRA_SPECIFY_COLS; // get default size and position for the initial placement m_size = size; m_pos = pos; int minor = n / GetMajorDim(); if(n % GetMajorDim() > 0) minor++; if(m_size.x==wxDefaultCoord) m_size.x=36*(use_cols?GetMajorDim():minor); if(m_size.y==wxDefaultCoord) m_size.y=12*(use_cols?minor:GetMajorDim()); if(m_pos.x==wxDefaultCoord) m_pos.x=0; if(m_pos.y==wxDefaultCoord) m_pos.y=0; m_label = title; if(!wxControl::Create(parent, id, m_pos, m_size, style, val, name)) return false; int i = 0; for ( unsigned int j = 0; j < minor; j++ ) { for ( unsigned int k = 0; k < GetMajorDim(); k++ ) { if(i<n) { wxPoint start, end; start.x = (use_cols ? (k*m_size.x)/GetMajorDim() : (j*m_size.x)/minor); start.y = (use_cols ? (j*m_size.y)/minor : (k*m_size.y)/GetMajorDim()); end.x = (use_cols ? ((k+1)*m_size.x)/GetMajorDim() : ((j+1)*m_size.x)/minor); end.y = (use_cols ? ((j+1)*m_size.y)/minor : ((k+1)*m_size.y)/GetMajorDim()); wxRadioButton* rb = new wxRadioButton(); rb->SetGroup( id ); rb->Create( this, wxID_ANY, choices[i], start, wxSize(end.x-start.x-1,end.y-start.y-1), ( n == 0 ? wxRB_GROUP : 0 ) | use_checkbox ? wxRB_USE_CHECKBOX : 0 ); m_radios.Put(i,rb); i++; } } } }
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& validator, const wxString &name ) { if (!PreCreation( parent, pos, size ) || !CreateBase( parent, id, pos, size, style, validator, name )) { wxFAIL_MSG( wxT("wxRadioBox creation failed") ); return false; } m_widget = GTKCreateFrame(title); g_object_ref(m_widget); wxControl::SetLabel(title); if ( HasFlag(wxNO_BORDER) ) { // If we don't do this here, the wxNO_BORDER style is ignored in Show() gtk_frame_set_shadow_type(GTK_FRAME(m_widget), GTK_SHADOW_NONE); } // majorDim may be 0 if all trailing parameters were omitted, so don't // assert here but just use the correct value for it SetMajorDim(majorDim == 0 ? n : majorDim, style); unsigned int num_of_cols = GetColumnCount(); unsigned int num_of_rows = GetRowCount(); GtkRadioButton *rbtn = NULL; GtkWidget *table = gtk_table_new( num_of_rows, num_of_cols, FALSE ); gtk_table_set_col_spacings( GTK_TABLE(table), 1 ); gtk_table_set_row_spacings( GTK_TABLE(table), 1 ); gtk_widget_show( table ); gtk_container_add( GTK_CONTAINER(m_widget), table ); wxString label; GSList *radio_button_group = NULL; for (unsigned int i = 0; i < (unsigned int)n; i++) { if ( i != 0 ) radio_button_group = gtk_radio_button_get_group( GTK_RADIO_BUTTON(rbtn) ); label.Empty(); for ( wxString::const_iterator pc = choices[i].begin(); pc != choices[i].end(); ++pc ) { if ( *pc != wxT('&') ) label += *pc; } rbtn = GTK_RADIO_BUTTON( gtk_radio_button_new_with_label( radio_button_group, wxGTK_CONV( label ) ) ); gtk_widget_show( GTK_WIDGET(rbtn) ); g_signal_connect (rbtn, "key_press_event", G_CALLBACK (gtk_radiobox_keypress_callback), this); m_buttonsInfo.Append( new wxGTKRadioButtonInfo( rbtn, wxRect() ) ); if (HasFlag(wxRA_SPECIFY_COLS)) { int left = i%num_of_cols; int right = (i%num_of_cols) + 1; int top = i/num_of_cols; int bottom = (i/num_of_cols)+1; gtk_table_attach( GTK_TABLE(table), GTK_WIDGET(rbtn), left, right, top, bottom, GTK_FILL, GTK_FILL, 1, 1 ); } else { int left = i/num_of_rows; int right = (i/num_of_rows) + 1; int top = i%num_of_rows; int bottom = (i%num_of_rows)+1; gtk_table_attach( GTK_TABLE(table), GTK_WIDGET(rbtn), left, right, top, bottom, GTK_FILL, GTK_FILL, 1, 1 ); } ConnectWidget( GTK_WIDGET(rbtn) ); if (!i) gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(rbtn), TRUE ); g_signal_connect (rbtn, "clicked", G_CALLBACK (gtk_radiobutton_clicked_callback), this); g_signal_connect (rbtn, "focus_in_event", G_CALLBACK (gtk_radiobutton_focus_in), this); g_signal_connect (rbtn, "focus_out_event", G_CALLBACK (gtk_radiobutton_focus_out), this); g_signal_connect (rbtn, "size_allocate", G_CALLBACK (gtk_radiobutton_size_allocate), this); } m_parent->DoAddChild( this ); PostCreation(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) { // 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* 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
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& validator, const wxString &name ) { if (!PreCreation( parent, pos, size ) || !CreateBase( parent, id, pos, size, style, validator, name )) { wxFAIL_MSG( wxT("wxRadioBox creation failed") ); return false; } m_widget = gtk_frame_new(NULL); SetLabel(title); // majorDim may be 0 if all trailing parameters were omitted, so don't // assert here but just use the correct value for it SetMajorDim(majorDim == 0 ? n : majorDim, style); unsigned int num_of_cols = GetColumnCount(); unsigned int num_of_rows = GetRowCount(); GtkRadioButton *m_radio = (GtkRadioButton*) NULL; GtkWidget *table = gtk_table_new( num_of_rows, num_of_cols, FALSE ); gtk_table_set_col_spacings( GTK_TABLE(table), 1 ); gtk_table_set_row_spacings( GTK_TABLE(table), 1 ); gtk_widget_show( table ); gtk_container_add( GTK_CONTAINER(m_widget), table ); wxString label; GSList *radio_button_group = (GSList *) NULL; for (int i = 0; i < n; i++) { if ( i != 0 ) radio_button_group = gtk_radio_button_group( GTK_RADIO_BUTTON(m_radio) ); label.Empty(); for ( const wxChar *pc = choices[i]; *pc; pc++ ) { if ( *pc != wxT('&') ) label += *pc; } m_radio = GTK_RADIO_BUTTON( gtk_radio_button_new_with_label( radio_button_group, wxGTK_CONV( label ) ) ); gtk_widget_show( GTK_WIDGET(m_radio) ); gtk_signal_connect( GTK_OBJECT(m_radio), "key_press_event", GTK_SIGNAL_FUNC(gtk_radiobox_keypress_callback), (gpointer)this ); m_boxes.Append( (wxObject*) m_radio ); if (HasFlag(wxRA_SPECIFY_COLS)) { int left = i%num_of_cols; int right = (i%num_of_cols) + 1; int top = i/num_of_cols; int bottom = (i/num_of_cols)+1; gtk_table_attach( GTK_TABLE(table), GTK_WIDGET(m_radio), left, right, top, bottom, GTK_FILL, GTK_FILL, 1, 1 ); } else { int left = i/num_of_rows; int right = (i/num_of_rows) + 1; int top = i%num_of_rows; int bottom = (i%num_of_rows)+1; gtk_table_attach( GTK_TABLE(table), GTK_WIDGET(m_radio), left, right, top, bottom, GTK_FILL, GTK_FILL, 1, 1 ); } ConnectWidget( GTK_WIDGET(m_radio) ); if (!i) gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_radio), TRUE ); gtk_signal_connect( GTK_OBJECT(m_radio), "clicked", GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this ); gtk_signal_connect( GTK_OBJECT(m_radio), "focus_in_event", GTK_SIGNAL_FUNC(gtk_radiobutton_focus_in), (gpointer)this ); gtk_signal_connect( GTK_OBJECT(m_radio), "focus_out_event", GTK_SIGNAL_FUNC(gtk_radiobutton_focus_out), (gpointer)this ); } m_parent->DoAddChild( this ); PostCreation(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) { // 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 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() GetHwndOf(parent), (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, GetHwndOf(parent), (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 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& wxVALIDATOR_PARAM(val), const wxString& name) { // for compatibility with the other ports which don't handle (yet?) // wxRA_LEFTTORIGHT and wxRA_TOPTOBOTTOM flags, we add them ourselves if // not specified if ( !(style & (wxRA_LEFTTORIGHT | wxRA_TOPTOBOTTOM)) ) { // horizontal radiobox use left to right layout if ( style & wxRA_HORIZONTAL ) { style |= wxRA_LEFTTORIGHT; } else if ( style & wxRA_VERTICAL ) { style |= wxRA_TOPTOBOTTOM; } else { wxFAIL_MSG( _T("you must specify wxRA_XXX style!") ); // use default style = wxRA_HORIZONTAL | wxRA_LEFTTORIGHT; } } if ( !wxStaticBox::Create(parent, id, title, pos, size, style, name) ) return false; #if wxUSE_VALIDATORS SetValidator(val); #endif // wxUSE_VALIDATORS Append(n, choices); // majorDim default value is 0 which means make one row/column SetMajorDim(majorDim == 0 ? n : majorDim); if ( size == wxDefaultSize ) { SetClientSize(DoGetBestClientSize()); } // Need to move the radiobox in order to move the radio buttons wxPoint actualPos = GetPosition(); wxSize actualSize = GetSize(); DoMoveWindow(actualPos.x, actualPos.y, actualSize.x, actualSize.y); // radiobox should already have selection so select at least one item SetSelection(0); 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) { if( !CreateControl( parent, id, pos, size, style, val, name ) ) return false; PreCreation(); m_noItems = (unsigned int)n; m_noRowsOrCols = majorDim; SetMajorDim(majorDim == 0 ? n : majorDim, style); Widget parentWidget = (Widget) parent->GetClientWidget(); Display* dpy = XtDisplay(parentWidget); m_mainWidget = XtVaCreateWidget ("radioboxframe", xmFrameWidgetClass, parentWidget, XmNresizeHeight, True, XmNresizeWidth, True, NULL); wxString label1(GetLabelText(title)); if (!label1.empty()) { wxXmString text(label1); m_labelWidget = (WXWidget) XtVaCreateManagedWidget( label1.mb_str(), #if wxUSE_GADGETS style & wxCOLOURED ? xmLabelWidgetClass : xmLabelGadgetClass, (Widget)m_mainWidget, #else xmLabelWidgetClass, (Widget)m_mainWidget, #endif wxFont::GetFontTag(), m_font.GetFontTypeC(dpy), XmNlabelString, text(), // XmNframeChildType is not in Motif 1.2, nor in Lesstif, // if it was compiled with 1.2 compatibility // TODO: check this still looks OK for Motif 1.2. #if (XmVersion > 1200) XmNframeChildType, XmFRAME_TITLE_CHILD, #else XmNchildType, XmFRAME_TITLE_CHILD, #endif XmNchildVerticalAlignment, XmALIGNMENT_CENTER, NULL); } Arg args[3]; XtSetArg (args[0], XmNorientation, ((style & wxHORIZONTAL) == wxHORIZONTAL ? XmHORIZONTAL : XmVERTICAL)); XtSetArg (args[1], XmNnumColumns, GetMajorDim()); XtSetArg (args[2], XmNadjustLast, False); Widget radioBoxWidget = XmCreateRadioBox ((Widget)m_mainWidget, wxMOTIF_STR("radioBoxWidget"), args, 3); m_radioButtons.reserve(n); m_radioButtonLabels.reserve(n); int i; for (i = 0; i < n; i++) { wxString str(GetLabelText(choices[i])); m_radioButtonLabels.push_back(str); Widget radioItem = XtVaCreateManagedWidget ( str.mb_str(), #if wxUSE_GADGETS xmToggleButtonGadgetClass, radioBoxWidget, #else xmToggleButtonWidgetClass, radioBoxWidget, #endif wxFont::GetFontTag(), m_font.GetFontTypeC(dpy), NULL); m_radioButtons.push_back((WXWidget)radioItem); XtAddCallback (radioItem, XmNvalueChangedCallback, (XtCallbackProc) wxRadioBoxCallback, (XtPointer) this); } SetSelection (0); XtRealizeWidget((Widget)m_mainWidget); XtManageChild (radioBoxWidget); XtManageChild ((Widget)m_mainWidget); PostCreation(); AttachWidget (parent, m_mainWidget, NULL, pos.x, pos.y, size.x, size.y); return true; }