Beispiel #1
0
int main(int argc,char *argv[])
{
	GtkWidget *frame;
	GtkWidget *wnd;
	GtkWidget *vbox;
	GtkWidget *hbox;
	GtkWidget *item;
	GtkWidget *list;	
	GList *item_list;

	gtk_init (&argc, &argv);
        wnd= gtk_window_new (GTK_WINDOW_TOPLEVEL);
	
        gtk_window_set_title(GTK_WINDOW(wnd),"p18.4 frame");
        gtk_window_set_default_size(GTK_WINDOW(wnd),300,200);
        gtk_container_set_border_width(GTK_CONTAINER(wnd),15);

	vbox=gtk_vbox_new(TRUE,5);
	gtk_container_add(GTK_CONTAINER(wnd),vbox);

	hbox=gtk_hbox_new(TRUE,5);
	gtk_box_pack_start(GTK_BOX(vbox),hbox,TRUE,TRUE,0);

	frame=gtk_frame_new("FRAME 1");
	gtk_box_pack_start(GTK_BOX(hbox),frame,TRUE,TRUE,0);

	frame=gtk_frame_new("FRAME 2");
	gtk_box_pack_start(GTK_BOX(hbox),frame,TRUE,TRUE,0);
	gtk_frame_set_label_align(GTK_FRAME(frame),0.5,0);

	frame=gtk_frame_new(NULL);
	gtk_box_pack_start(GTK_BOX(vbox),frame,TRUE,TRUE,0);
	
	list=gtk_list_new();
	item_list=NULL;
	item=gtk_list_item_new_with_label("list 1, one");
	item_list=g_list_append(item_list,item);
	
        item=gtk_list_item_new_with_label("list 2, two");
        item_list=g_list_append(item_list,item);

        item=gtk_list_item_new_with_label("list 3, three");
        item_list=g_list_append(item_list,item);

        item=gtk_list_item_new_with_label("list 4, four");
        item_list=g_list_append(item_list,item);	
	
	gtk_list_insert_items(GTK_LIST(list),item_list,0);

	gtk_container_add(GTK_CONTAINER(frame),list);

        g_signal_connect(G_OBJECT(wnd),"delete_event",G_CALLBACK(release_resource),NULL);

	gtk_widget_show_all(wnd);

	gtk_main();
	
	return 0;
}
Beispiel #2
0
int wxComboBox::DoInsert(const wxString &item, unsigned int pos)
{
    wxCHECK_MSG( !(GetWindowStyle() & wxCB_SORT), -1,
                    wxT("can't insert into sorted list"));

    wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid combobox") );
    wxCHECK_MSG( IsValidInsert(pos), -1, wxT("invalid index") );

    unsigned int count = GetCount();

    if (pos == count)
        return Append(item);

#ifdef __WXGTK24__
    if (!gtk_check_version(2,4,0))
    {
        GtkComboBox* combobox = GTK_COMBO_BOX( m_widget );
        gtk_combo_box_insert_text( combobox, pos, wxGTK_CONV( item ) );
    }
    else
#endif
    {
        DisableEvents();

        GtkWidget *list = GTK_COMBO(m_widget)->list;
        GtkWidget *list_item = gtk_list_item_new_with_label( wxGTK_CONV( item ) );

        GList *gitem_list = g_list_alloc ();
        gitem_list->data = list_item;
        gtk_list_insert_items( GTK_LIST (list), gitem_list, pos );

        if (GTK_WIDGET_REALIZED(m_widget))
        {
            gtk_widget_realize( list_item );
            gtk_widget_realize( GTK_BIN(list_item)->child );

            ApplyWidgetStyle();
        }

        gtk_widget_show( list_item );

        EnableEvents();
    }

    count = GetCount();

    if ( m_clientDataList.GetCount() < count )
        m_clientDataList.Insert( pos, (wxObject*) NULL );
    if ( m_clientObjectList.GetCount() < count )
        m_clientObjectList.Insert( pos, (wxObject*) NULL );

    InvalidateBestSize();

    return pos;
}
Beispiel #3
0
//__________________________________________________________________
void        _HYPlatformPullDown::_AddMenuItem   (_String& newItem, long index)
{
    if (theMenu) {
        GList * singleItem   = g_list_alloc();
        singleItem->prev = singleItem->next = nil;
        if (newItem.Equal(&menuSeparator)) {
            GtkWidget * itemContents = gtk_separator_menu_item_new ();
            gtk_widget_show (itemContents);
            singleItem->data = gtk_list_item_new();
            gtk_container_add((GtkContainer*)singleItem->data,itemContents);
            gtk_combo_set_item_string (GTK_COMBO (theMenu), GTK_ITEM (singleItem->data), "");
            gtk_widget_set_sensitive((GtkWidget*)singleItem->data,false);
            widgetList.InsertElement ((BaseRef)itemContents,2*index,false,false);
        } else {
            _String inItem = newItem;
            if (newItem.beginswith ("(")) {
                inItem.Trim (1,-1);
            }

            GtkWidget * itemContents = gtk_menu_item_new_with_label (inItem.sData);
            gtk_widget_show (itemContents);
            singleItem->data = gtk_list_item_new();
            gtk_container_add((GtkContainer*)singleItem->data,itemContents);
            gtk_combo_set_item_string (GTK_COMBO (theMenu), GTK_ITEM (singleItem->data), inItem.sData);
            gtk_widget_set_sensitive((GtkWidget*)singleItem->data,inItem.sLength == newItem.sLength);
            widgetList.InsertElement ((BaseRef)itemContents,2*index,false,false);
        }
        widgetList.InsertElement ((BaseRef)singleItem->data,2*index,false,false);
        GdkColor convColor = HYColorToGDKColor(_hyGTKMenuBackground);
        gtk_widget_modify_bg ((GtkWidget*)singleItem->data, GTK_STATE_INSENSITIVE, 
        	&convColor);
        gtk_widget_show ((GtkWidget*)singleItem->data);
        if (index<0) {
            gtk_list_append_items (GTK_LIST (GTK_COMBO (theMenu)->list), singleItem);
        } else {
            gtk_list_insert_items (GTK_LIST (GTK_COMBO (theMenu)->list), singleItem, index);
        }

        /*printf ("\nAdding menu item %s at %d\n", newItem.sData, index);
        for (long k = 0; k<widgetList.lLength; k++)
            printf ("%d %s\n", k, GTK_OBJECT_TYPE_NAME (GTK_WIDGET (widgetList(k))));*/
    }

    if (((_HYPullDown*)this)->MenuItemCount()==1||selection==index) {
        cbSelection = -1;
        _RefreshComboBox();
    }
}
Beispiel #4
0
static void
layer_dialog_lower_callback(GtkWidget *widget, gpointer gdata)
{
  Layer *layer;
  Diagram *dia;
  GtkWidget *selected;
  GList *list = NULL;
  int pos;

  dia = layer_dialog->diagram;

  if ((dia != NULL) && (dia->data->layers->len>1)) {
    assert(GTK_LIST(layer_dialog->layer_list)->selection != NULL);
    selected = GTK_LIST(layer_dialog->layer_list)->selection->data;

    pos = gtk_list_child_position(GTK_LIST(layer_dialog->layer_list), selected);

    if (pos < dia->data->layers->len-1) {
      layer = DIA_LAYER_WIDGET(selected)->layer;
      data_lower_layer(dia->data, layer);
      
      list = g_list_prepend(list, selected);

      g_object_ref(selected);
      
      gtk_list_remove_items(GTK_LIST(layer_dialog->layer_list),
			    list);
      
      gtk_list_insert_items(GTK_LIST(layer_dialog->layer_list),
			    list, pos + 1);

      g_object_unref(selected);

      gtk_list_select_item(GTK_LIST(layer_dialog->layer_list), pos+1);
      
      diagram_add_update_all(dia);
      diagram_flush(dia);

      undo_layer(dia, layer, TYPE_LOWER_LAYER, 0);
      undo_set_transactionpoint(dia->undo);
    }

  }
}
Beispiel #5
0
static void
layer_dialog_new_callback(GtkWidget *widget, gpointer gdata)
{
  Layer *layer;
  Diagram *dia;
  GtkWidget *selected;
  GList *list = NULL;
  GtkWidget *layer_widget;
  int pos;
  static int next_layer_num = 1;

  dia = layer_dialog->diagram;

  if (dia != NULL) {
    gchar* new_layer_name = g_strdup_printf(_("New layer %d"),
					    next_layer_num++);
    layer = new_layer(new_layer_name, dia->data);

    assert(GTK_LIST(layer_dialog->layer_list)->selection != NULL);
    selected = GTK_LIST(layer_dialog->layer_list)->selection->data;
    pos = gtk_list_child_position(GTK_LIST(layer_dialog->layer_list), selected);

    data_add_layer_at(dia->data, layer, dia->data->layers->len - pos);
    
    diagram_add_update_all(dia);
    diagram_flush(dia);

    layer_widget = dia_layer_widget_new(dia, layer);
    gtk_widget_show(layer_widget);

    list = g_list_prepend(list, layer_widget);
    
    gtk_list_insert_items(GTK_LIST(layer_dialog->layer_list), list, pos);

    gtk_list_select_item(GTK_LIST(layer_dialog->layer_list), pos);

    undo_layer(dia, layer, TYPE_ADD_LAYER, dia->data->layers->len - pos);
    undo_set_transactionpoint(dia->undo);
  }
}
Beispiel #6
0
int wxComboBox::DoInsertItems(const wxArrayStringsAdapter& items,
                              unsigned int pos,
                              void **clientData,
                              wxClientDataType type)
{
    wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid combobox") );

    DisableEvents();

    GtkWidget *list = GTK_COMBO(m_widget)->list;

    GtkRcStyle *style = CreateWidgetStyle();

    const unsigned int count = items.GetCount();
    for( unsigned int i = 0; i < count; ++i, ++pos )
    {
        GtkWidget *
            list_item = gtk_list_item_new_with_label( wxGTK_CONV( items[i] ) );

        if ( pos == GetCount() )
        {
            gtk_container_add( GTK_CONTAINER(list), list_item );
        }
        else // insert, not append
        {
            GList *gitem_list = g_list_alloc ();
            gitem_list->data = list_item;
            gtk_list_insert_items( GTK_LIST (list), gitem_list, pos );
        }

        if (GTK_WIDGET_REALIZED(m_widget))
        {
            gtk_widget_realize( list_item );
            gtk_widget_realize( GTK_BIN(list_item)->child );

            if (style)
            {
                gtk_widget_modify_style( GTK_WIDGET( list_item ), style );
                GtkBin *bin = GTK_BIN( list_item );
                GtkWidget *label = GTK_WIDGET( bin->child );
                gtk_widget_modify_style( label, style );
            }

        }

        gtk_widget_show( list_item );

        if ( m_clientDataList.GetCount() < GetCount() )
            m_clientDataList.Insert( pos, NULL );
        if ( m_clientObjectList.GetCount() < GetCount() )
            m_clientObjectList.Insert( pos, NULL );

        AssignNewItemClientData(pos, clientData, i, type);
    }

    if ( style )
        gtk_rc_style_unref( style );

    EnableEvents();

    InvalidateBestSize();

    return pos - 1;
}
Beispiel #7
0
void wxListBox::GtkAddItem( const wxString &item, int pos )
{
    wxCHECK_RET( m_list != NULL, wxT("invalid listbox") );

    GtkWidget *list_item;

    wxString label(item);
#if wxUSE_CHECKLISTBOX
    if (m_hasCheckBoxes)
    {
        label.Prepend(wxCHECKLBOX_STRING);
    }
#endif // wxUSE_CHECKLISTBOX

    list_item = gtk_list_item_new_with_label( wxGTK_CONV( label ) );

    GList *gitem_list = g_list_alloc ();
    gitem_list->data = list_item;

    if (pos == -1)
        gtk_list_append_items( GTK_LIST (m_list), gitem_list );
    else
        gtk_list_insert_items( GTK_LIST (m_list), gitem_list, pos );

    gtk_signal_connect_after( GTK_OBJECT(list_item), "select",
      GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this );

    if (HasFlag(wxLB_MULTIPLE) || HasFlag(wxLB_EXTENDED))
        gtk_signal_connect_after( GTK_OBJECT(list_item), "deselect",
          GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback), (gpointer)this );

    gtk_signal_connect( GTK_OBJECT(list_item),
                        "button_press_event",
                        (GtkSignalFunc)gtk_listbox_button_press_callback,
                        (gpointer) this );

    gtk_signal_connect_after( GTK_OBJECT(list_item),
                        "button_release_event",
                        (GtkSignalFunc)gtk_listbox_button_release_callback,
                        (gpointer) this );

    gtk_signal_connect( GTK_OBJECT(list_item),
                           "key_press_event",
                           (GtkSignalFunc)gtk_listbox_key_press_callback,
                           (gpointer)this );


    gtk_signal_connect( GTK_OBJECT(list_item), "focus_in_event",
            GTK_SIGNAL_FUNC(gtk_listitem_focus_in_callback), (gpointer)this );

    gtk_signal_connect( GTK_OBJECT(list_item), "focus_out_event",
            GTK_SIGNAL_FUNC(gtk_listitem_focus_out_callback), (gpointer)this );

    ConnectWidget( list_item );

    if (GTK_WIDGET_REALIZED(m_widget))
    {
        gtk_widget_show( list_item );

        gtk_widget_realize( list_item );
        gtk_widget_realize( GTK_BIN(list_item)->child );

#if wxUSE_TOOLTIPS
        if (m_tooltip) m_tooltip->Apply( this );
#endif
    }

    // Apply current widget style to the new list_item
    GtkRcStyle *style = CreateWidgetStyle();
    if (style)
    {
        gtk_widget_modify_style( GTK_WIDGET( list_item ), style );
        GtkBin *bin = GTK_BIN( list_item );
        gtk_widget_modify_style( GTK_WIDGET( bin->child ), style );
        gtk_rc_style_unref( style );
    }
}
Beispiel #8
0
/* Inserts items into the list at the position position.
 * The GList items must not be freed after. */
int
clip_GTK_LISTINSERTITEMS(ClipMachine * ClipMachineMemory)
{
   C_widget *clst = _fetch_cw_arg(ClipMachineMemory);

   ClipVar  *cv = _clip_spar(ClipMachineMemory, 2);

   gint      position = _clip_parni(ClipMachineMemory, 3);

   GList    *items = NULL;

   CHECKCWID(clst, GTK_IS_LIST);
   CHECKARG4(2, ARRAY_type_of_ClipVarType, CHARACTER_type_of_ClipVarType, MAP_type_of_ClipVarType, NUMERIC_type_of_ClipVarType);
   CHECKOPT(3, NUMERIC_type_of_ClipVarType);
   if (_clip_parinfo(ClipMachineMemory, 3) == UNDEF_type_of_ClipVarType)
      position = 1;
   switch (cv->ClipType_t_of_ClipVar.ClipVartype_type_of_ClipType)
    {
    case CHARACTER_type_of_ClipVarType:
       items =
	g_list_append(items,
		      gtk_list_item_new_with_label(cv->ClipStrVar_s_of_ClipVar.ClipBuf_str_of_ClipStrVar.buf_of_ClipBuf));
       break;

    case MAP_type_of_ClipVarType:
    case NUMERIC_type_of_ClipVarType:
       {
	  C_widget *citem = _fetch_cwidget(ClipMachineMemory, cv);

	  CHECKCWID(citem, GTK_IS_WIDGET);
	  if (GTK_IS_LIST_ITEM(citem->widget))
	     items = g_list_append(items, citem->widget);
	  else
	   {
	      GtkWidget *item = gtk_list_item_new();

	      gtk_container_add(GTK_CONTAINER(item), citem->widget);
	      items = g_list_append(items, item);
	   }
	  break;
       }

    case ARRAY_type_of_ClipVarType:
       {
	  C_widget *citem;

	  GtkWidget *item;

	  int       i;

	  for (i = 0; i < cv->ClipArrVar_a_of_ClipVar.count_of_ClipArrVar; i++)
	   {
	      switch (cv->ClipArrVar_a_of_ClipVar.ClipVar_items_of_ClipArrVar[i].ClipType_t_of_ClipVar.
		      ClipVartype_type_of_ClipType)
	       {
	       case CHARACTER_type_of_ClipVarType:
		  items =
		   g_list_append(items,
				 gtk_list_item_new_with_label(cv->ClipArrVar_a_of_ClipVar.
							      ClipVar_items_of_ClipArrVar[i].ClipStrVar_s_of_ClipVar.
							      ClipBuf_str_of_ClipStrVar.buf_of_ClipBuf));
		  break;
	       case MAP_type_of_ClipVarType:
	       case NUMERIC_type_of_ClipVarType:
		  citem = _fetch_cwidget(ClipMachineMemory, &cv->ClipArrVar_a_of_ClipVar.ClipVar_items_of_ClipArrVar[i]);
		  CHECKCWID(citem, GTK_IS_WIDGET);
		  if (GTK_IS_LIST_ITEM(citem->widget))
		     items = g_list_append(items, citem->widget);
		  else
		   {
		      item = gtk_list_item_new();
		      gtk_container_add(GTK_CONTAINER(item), citem->widget);
		      items = g_list_append(items, item);
		   }
		  break;
	       default:
		  break;
	       }
	   }

       }
    default:
       break;
    }
   gtk_list_insert_items(GTK_LIST(clst->widget), items, position - 1);
   return 0;
 err:
   return 1;
}