GTK gossip: gtkstatusbar

Source: Internet
Author: User
Tags gtk
The sequence column is usually located at the bottom of the sequence window, used to display some sequence information of the current sequence window operation sequence. The sequence column component in GTK is gtkstatusbar, you can use gtk_statusbar_new () to create a table.

Each component or operation in the window can have a corresponding response message. In order to allow other components or operations in the column, use context in gtkstatusbar
ID. You can use gtk_statusbar_get_context_id () and specify a region to obtain the corresponding context ID. For example:

Gtkwidget * statusbar;

Gint contextid;

Statusbar = gtk_statusbar_new ();

Contextid =
Gtk_statusbar_get_context_id (

Gtk_statusbar (statusbar), "editor messages ");



After obtaining the context ID, you can use the following functions to add or remove the Response Message to the gtkstatusbar:

Guint gtk_statusbar_push (gtkstatusbar * statusbar,



Guint context_id,



Const gchar * text );


Void gtk_statusbar_pop (gtkstatusbar * statusbar,



Guint context_id );


Void gtk_statusbar_remove (gtkstatusbar * statusbar,



Guint context_id,



Guint message_id );


The interest of the gtkstatusbar is stored in a stack. The method is later in and out. To add the interest, use gtk_statusbar_push ().
A message_id. You can use the gtk_statusbar_remove () function to specify
While gtk_statusbar_pop () is the top warning message in the heap response of the context ID.

The following program uses
Gtktoolbar


Add

Gtktextview


With the gtkstatusbar, the external keys after the rows are more like a window program text handler:

  • Gtk_statusbar_demo.c
# Include <GTK/GTK. h>

Void itempressed (gtkmenuitem * menuitem, gpointer data ){
G_print ("% s/n", data );
}

Gtkwidget * createfilemenuitem (){
Gtkwidget * rootfileitem;
Gtkwidget * filemenu;
Gtkwidget * openmenuitem;
Gtkwidget * savemenuitem;
Gtkwidget * closemenuitem;

Rootfileitem = gtk_menu_item_new_with_mnemonic ("_ file ");
Filemenu = gtk_menu_new ();
Openmenuitem = gtk_menu_item_new_with_label ("open ");
Savemenuitem = gtk_menu_item_new_with_label ("save ");
Closemenuitem = gtk_menu_item_new_with_label ("close ");

Gtk_menu_shell_append (gtk_menu_shell (filemenu), openmenuitem );
Gtk_menu_shell_append (gtk_menu_shell (filemenu), savemenuitem );
Gtk_menu_shell_append (gtk_menu_shell (filemenu ),
Gtk_separator_menu_item_new ());
Gtk_menu_shell_append (gtk_menu_shell (filemenu), closemenuitem );

Gtk_menu_item_set_submenu (gtk_menu_item (rootfileitem), filemenu );

G_signal_connect (gtk_object (openmenuitem), "Activate ",
G_callback (itempressed), "open ....");
G_signal_connect (gtk_object (savemenuitem), "Activate ",
G_callback (itempressed), "Save ....");
G_signal_connect (gtk_object (closemenuitem), "Activate ",
G_callback (gtk_main_quit), null );

Return rootfileitem;
}

// Create a gtktoolitem that contains the subject, text, and picture.
Gtktoolitem * createquallitem (gchar * stock_id, gchar * Text ){
Gtktoolitem * open;
Gtkwidget * box;
Gtkwidget * label;
Gtkwidget * image;
Gtkwidget * button;

Open = gtk_tool_item_new ();
Gtk_tool_item_set_tooltip_text (open, "open file ..");

Box = gtk_vbox_new (false, 0 );

Image = gtk_image_new_from_stock (stock_id, gtk_icon_size_small_toolbar );
Label = gtk_label_new (text );

Gtk_box_pack_start (gtk_box (box), image, false, false, 0 );
Gtk_box_pack_start (gtk_box (box), label, false, false, 0 );

Button = gtk_button_new ();

Gtk_container_add (gtk_container (button), box );
Gtk_container_add (gtk_container (open), button );

Return open;
}

Int main (INT argc, char * argv []) {
Gtkwidget * window;
Gtkwidget * menubarbox;
Gtkwidget * toolbarbox;
Gtkwidget * vbox;
Gtkwidget * menubar;
Gtkwidget * toolbar;
Gtkwidget * statusbar;
Gint contextid;

Gtk_init (& argc, & argv );

Window = gtk_window_new (gtk_window_toplevel );
Gtk_window_set_title (gtk_window (window), "gtkstatusbar ");
Gtk_window_set_default_size (gtk_window (window), 400,300 );

Menubar = gtk_menu_bar_new ();

Gtk_menu_bar_append (menubar, createfilemenuitem ());
Gtk_menu_bar_append (menubar, gtk_menu_item_new_with_mnemonic ("_ edit "));
Gtk_menu_bar_append (menubar, gtk_menu_item_new_with_mnemonic ("_ Help "));

Vbox = gtk_vbox_new (false, 0 );

Menubarbox = gtk_handle_box_new ();
Gtk_container_add (gtk_container (menubarbox), menubar );
Gtk_box_pack_start (gtk_box (vbox), menubarbox, false, false, 0 );

Toolbar = gtk_toolbar_new ();
Gtk_toolbar_insert (gtk_toolbar (toolbar ),
Createmedilitem (gtk_stock_open, "open"), 0 );
Gtk_toolbar_insert (gtk_toolbar (toolbar ),
Createconlitem (gtk_stock_save, "save"), 1 );

Toolbarbox = gtk_handle_box_new ();
Gtk_container_add (gtk_container (toolbarbox), toolbar );
Gtk_box_pack_start (gtk_box (vbox), toolbarbox, false, false, 0 );

Gtk_box_pack_start (gtk_box (vbox), gtk_text_view_new (), true, true, 0 );

Statusbar = gtk_statusbar_new ();
Contextid = gtk_statusbar_get_context_id (
Gtk_statusbar (statusbar), "editor messages ");
Gtk_statusbar_push (gtk_statusbar (statusbar ),
Contextid, "gtkstatusbar example ");
Gtk_box_pack_start (gtk_box (vbox), statusbar, false, false, 0 );

Gtk_container_add (gtk_container (window), vbox );

G_signal_connect (gtk_object (window), "Destroy ",
G_callback (gtk_main_quit), null );

Gtk_widget_show_all (window );

Gtk_main ();

Return 0;
}


The result is shown as follows:


 



Bloggerads warning
Degrees of attention, energy, and carbon
A little bright, 2011 yuan, new hopes, saving money and secret technology, and now joining the National shopping Festival
More messages ..
Your eyes are so fragile and easily excited!
Don't you give your eyes blank. Have you chosen the bath products? Let's get to know the truth about the product selection!
More messages ..
Impr


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.