- }
-
- wxSize newSize = size;
- if (newSize.x == -1) newSize.x = maxLen+10;
- if (newSize.y == -1) newSize.y = height;
- SetSize( newSize.x, newSize.y );
-
- PostCreation();
-
- SetLabel( title );
-
- Show( TRUE );
-
- return TRUE;
-}
-
-wxRadioBox::~wxRadioBox(void)
-{
- wxNode *node = m_boxes.First();
- while (node)
- {
- GtkWidget *button = GTK_WIDGET( node->Data() );
- gtk_widget_destroy( button );
- node = node->Next();
- }
-}
-
-void wxRadioBox::OnSize( wxSizeEvent &event )
-{
- wxControl::OnSize( event );
-
- int x = m_x+5;
- int y = m_y+15;
-
- wxNode *node = m_boxes.First();
- while (node)
- {
- GtkWidget *button = GTK_WIDGET( node->Data() );
-
- gtk_myfixed_move( GTK_MYFIXED(m_parent->m_wxwindow), button, x, y );
- y += 20;
-
- int w = m_width-10;
- if (w < 15) w = 15;
- gtk_widget_set_usize( button, w, 20 );
-
- node = node->Next();
- }
+
+ m_parent->DoAddChild( this );
+
+ bool wasShown = IsShown();
+ if ( wasShown )
+ Hide(); // prevent PostCreation() from showing us
+
+ SetLabel( title );
+
+ PostCreation(size);
+
+ if ( wasShown )
+ Show();
+
+ return true;
+}
+
+wxRadioBox::~wxRadioBox()
+{
+ wxList::compatibility_iterator node = m_boxes.GetFirst();
+ while (node)
+ {
+ GtkWidget *button = GTK_WIDGET( node->GetData() );
+ gtk_widget_destroy( button );
+ node = node->GetNext();
+ }
+}
+
+void wxRadioBox::DoSetSize( int x, int y, int width, int height, int sizeFlags )
+{
+ wxWindow::DoSetSize( x, y, width, height, sizeFlags );
+
+ LayoutItems(false);
+}
+
+wxSize wxRadioBox::DoGetBestSize() const
+{
+ wxSize size = LayoutItems(true);
+
+ GtkRequisition req;
+ req.width = 2;
+ req.height = 2;
+ (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget) )->size_request ) (m_widget, &req );
+ if (req.width > size.x)
+ size.x = req.width;
+
+ CacheBestSize(size);
+ return size;
+}
+
+wxSize wxRadioBox::LayoutItems(bool justCalc) const
+{
+ wxSize res( 0, 0 );
+
+ // avoid dividing by 0 below
+ wxCHECK_MSG( m_majorDim, res, wxT("dimension of radiobox should not be 0!") );
+
+ int num_per_major = (m_boxes.GetCount() - 1) / m_majorDim +1;
+
+ int x = 7;
+ int y = 15;
+
+ int num_of_cols = 0;
+ int num_of_rows = 0;
+ if (HasFlag(wxRA_SPECIFY_COLS))
+ {
+ num_of_cols = m_majorDim;
+ num_of_rows = num_per_major;
+ }
+ else
+ {
+ num_of_cols = num_per_major;
+ num_of_rows = m_majorDim;
+ }
+
+ int lineheight = GetCharHeight()+2;
+
+ if ( HasFlag(wxRA_SPECIFY_COLS) ||
+ (HasFlag(wxRA_SPECIFY_ROWS) && (num_of_cols > 1)) )
+ {
+ for (int j = 0; j < num_of_cols; j++)
+ {
+ y = 3;
+ y += lineheight;
+
+ int max_len = 0;
+ wxList::compatibility_iterator node = m_boxes.Item( j*num_of_rows );
+ for (int i1 = 0; i1< num_of_rows; i1++)
+ {
+ GtkWidget *button = GTK_WIDGET( node->GetData() );
+
+ GtkRequisition req;
+ req.width = 2;
+ req.height = 2;
+ (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(button) )->size_request )
+ (button, &req );
+
+ if (req.width > max_len) max_len = req.width;
+
+ if ( !justCalc )
+ gtk_pizza_move( GTK_PIZZA(m_parent->m_wxwindow), button, m_x+x, m_y+y );
+ y += req.height;
+
+ node = node->GetNext();
+ if (!node) break;
+ }
+
+ // we don't know the max_len before
+
+ node = m_boxes.Item( j*num_of_rows );
+ for (int i2 = 0; i2< num_of_rows; i2++)
+ {
+ GtkWidget *button = GTK_WIDGET( node->GetData() );
+
+ if ( !justCalc )
+ gtk_pizza_resize( GTK_PIZZA(m_parent->m_wxwindow), button, max_len, lineheight );
+
+ node = node->GetNext();
+ if (!node) break;
+ }
+
+ if (y > res.y) res.y = y;
+
+ x += max_len + 2;
+ }
+
+ res.x = x+4;
+ res.y += 4;
+ }
+ else
+ {
+ int max = 0;
+
+ wxList::compatibility_iterator node = m_boxes.GetFirst();
+ while (node)
+ {
+ GtkWidget *button = GTK_WIDGET( node->GetData() );
+
+ GtkRequisition req;
+ req.width = 2;
+ req.height = 2;
+ (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(button) )->size_request )
+ (button, &req );
+
+ if (req.width > max) max = req.width;
+
+ node = node->GetNext();
+ }
+
+ node = m_boxes.GetFirst();
+ while (node)
+ {
+ GtkWidget *button = GTK_WIDGET( node->GetData() );
+
+ if ( !justCalc )
+ gtk_pizza_set_size( GTK_PIZZA(m_parent->m_wxwindow), button, m_x+x, m_y+y, max, lineheight );
+ x += max;
+
+ node = node->GetNext();
+ }
+ res.x = x+4;
+ res.y = 40;
+ }
+
+ return res;