for (int i = 0; i < n; i++)
{
- GtkAppendHelper(menu, choices[i]);
+ GtkAddHelper(menu, i, choices[i]);
}
gtk_option_menu_set_menu( GTK_OPTION_MENU(m_widget), menu );
GtkWidget *menu = gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) );
- return GtkAppendHelper(menu, item);
+ return GtkAddHelper(menu, GetCount(), item);
+}
+
+int wxChoice::DoInsert( const wxString &item, int pos )
+{
+ wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid choice control") );
+ wxCHECK_MSG( (pos>=0) && (pos<=GetCount()), -1, wxT("invalid index"));
+
+ if (pos == GetCount())
+ return DoAppend(item);
+
+ GtkWidget *menu = gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) );
+
+ return GtkAddHelper(menu, pos, item);
}
void wxChoice::DoSetItemClientData( int n, void* clientData )
{
wxCHECK_RET( m_widget != NULL, wxT("invalid choice control") );
- wxNode *node = m_clientList.Nth( n );
+ wxNode *node = m_clientList.Item( n );
wxCHECK_RET( node, wxT("invalid index in wxChoice::DoSetItemClientData") );
node->SetData( (wxObject*) clientData );
{
wxCHECK_MSG( m_widget != NULL, NULL, wxT("invalid choice control") );
- wxNode *node = m_clientList.Nth( n );
+ wxNode *node = m_clientList.Item( n );
wxCHECK_MSG( node, NULL, wxT("invalid index in wxChoice::DoGetItemClientData") );
- return node->Data();
+ return node->GetData();
}
void wxChoice::DoSetItemClientObject( int n, wxClientData* clientData )
{
wxCHECK_RET( m_widget != NULL, wxT("invalid choice control") );
- wxNode *node = m_clientList.Nth( n );
+ wxNode *node = m_clientList.Item( n );
wxCHECK_RET( node, wxT("invalid index in wxChoice::DoSetItemClientObject") );
- wxClientData *cd = (wxClientData*) node->Data();
- delete cd;
+ // wxItemContainer already deletes data for us
node->SetData( (wxObject*) clientData );
}
{
wxCHECK_MSG( m_widget != NULL, (wxClientData*) NULL, wxT("invalid choice control") );
- wxNode *node = m_clientList.Nth( n );
+ wxNode *node = m_clientList.Item( n );
wxCHECK_MSG( node, (wxClientData *)NULL,
wxT("invalid index in wxChoice::DoGetItemClientObject") );
- return (wxClientData*) node->Data();
+ return (wxClientData*) node->GetData();
}
void wxChoice::Clear()
// destroy the data (due to Robert's idea of using wxList<wxObject>
// and not wxList<wxClientData> we can't just say
// m_clientList.DeleteContents(TRUE) - this would crash!
- wxNode *node = m_clientList.First();
+ wxNode *node = m_clientList.GetFirst();
while ( node )
{
- delete (wxClientData *)node->Data();
- node = node->Next();
+ delete (wxClientData *)node->GetData();
+ node = node->GetNext();
}
}
m_clientList.Clear();
wxASSERT_MSG( label != NULL , wxT("wxChoice: invalid label") );
- wxString tmp( wxGTK_CONV_BACK( label->label ) );
+#ifdef __WXGTK20__
+ wxString tmp( wxGTK_CONV_BACK( gtk_label_get_text( label) ) );
+#else
+ wxString tmp( label->label );
+#endif
if (string == tmp)
return count;
int wxChoice::GetSelection() const
{
wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid choice") );
+
+#ifdef __WXGTK20__
+ return gtk_option_menu_get_history( GTK_OPTION_MENU(m_widget) );
+
+#else
GtkMenuShell *menu_shell = GTK_MENU_SHELL( gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) ) );
int count = 0;
+
GList *child = menu_shell->children;
while (child)
{
}
return -1;
+#endif
}
void wxChoice::SetString( int WXUNUSED(n), const wxString& WXUNUSED(string) )
wxASSERT_MSG( label != NULL , wxT("wxChoice: invalid label") );
- return wxString( wxGTK_CONV_BACK(label->label) );
+#ifdef __WXGTK20__
+ return wxString( wxGTK_CONV_BACK( gtk_label_get_text( label) ) );
+#else
+ return wxString( label->label );
+#endif
}
child = child->next;
count++;
}
}
-size_t wxChoice::GtkAppendHelper(GtkWidget *menu, const wxString& item)
+int wxChoice::GtkAddHelper(GtkWidget *menu, int pos, const wxString& item)
{
+ wxCHECK_MSG((pos>=0) && (pos<=(int)m_clientList.GetCount()), -1, wxT("invalid index"));
+
GtkWidget *menu_item = gtk_menu_item_new_with_label( wxGTK_CONV( item ) );
size_t index;
}
else
{
+ // don't call wxChoice::GetCount() from here because it doesn't work
+ // if we're called from ctor (and GtkMenuShell is still NULL)
+
// normal control, just append
+ if (pos == (int)m_clientList.GetCount())
+ {
gtk_menu_append( GTK_MENU(menu), menu_item );
-
m_clientList.Append( (wxObject*) NULL );
-
- // don't call wxChoice::GetCount() from here because it doesn't work
- // if we're called from ctor (and GtkMenuShell is still NULL)
index = m_clientList.GetCount() - 1;
+ }
+ else
+ {
+ gtk_menu_insert( GTK_MENU(menu), menu_item, pos );
+ m_clientList.Insert( pos, (wxObject*) NULL );
+ index = pos;
+ }
}
if (GTK_WIDGET_REALIZED(m_widget))
ret.x = 0;
if ( m_widget )
{
- GdkFont *font = m_font.GetInternalFont();
-
- wxCoord width;
+ int width;
size_t count = GetCount();
for ( size_t n = 0; n < count; n++ )
{
- // FIXME GTK 2.0
- width = (wxCoord)gdk_string_width(font, wxGTK_CONV( GetString(n) ) );
+ GetTextExtent( GetString(n), &width, NULL, NULL, NULL, &m_font );
if ( width > ret.x )
ret.x = width;
}
if ( ret.x < 80 )
ret.x = 80;
- ret.y = 16 + gdk_char_height(GET_STYLE_FONT( m_widget->style ), 'H' );
+ ret.y = 16 + GetCharHeight();
return ret;
}