|
Packit |
1470ea |
|
|
Packit |
1470ea |
<page xmlns="http://projectmallard.org/1.0/" xmlns:its="http://www.w3.org/2005/11/its" xmlns:xi="http://www.w3.org/2001/XInclude" type="guide" style="task" id="toolbar.c" xml:lang="fr">
|
|
Packit |
1470ea |
<info>
|
|
Packit |
1470ea |
<title type="text">Toolbar (C)</title>
|
|
Packit |
1470ea |
<link type="guide" xref="c#menu-combo-toolbar"/>
|
|
Packit |
1470ea |
<link type="seealso" xref="menubar.c"/>
|
|
Packit |
1470ea |
<link type="seealso" xref="grid.c"/>
|
|
Packit |
1470ea |
<revision version="0.1" date="2012-08-19" status="draft"/>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<credit type="author copyright">
|
|
Packit |
1470ea |
<name>Monica Kochofar</name>
|
|
Packit |
1470ea |
<email its:translate="no">monicakochofar@gmail.com</email>
|
|
Packit |
1470ea |
<years>2012</years>
|
|
Packit |
1470ea |
</credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<desc>Une barre de boutons</desc>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Luc Rebert,</mal:name>
|
|
Packit |
1470ea |
<mal:email>traduc@rebert.name</mal:email>
|
|
Packit |
1470ea |
<mal:years>2011</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Alain Lojewski,</mal:name>
|
|
Packit |
1470ea |
<mal:email>allomervan@gmail.com</mal:email>
|
|
Packit |
1470ea |
<mal:years>2011-2012</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Luc Pionchon</mal:name>
|
|
Packit |
1470ea |
<mal:email>pionchon.luc@gmail.com</mal:email>
|
|
Packit |
1470ea |
<mal:years>2011</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Bruno Brouard</mal:name>
|
|
Packit |
1470ea |
<mal:email>annoa.b@gmail.com</mal:email>
|
|
Packit |
1470ea |
<mal:years>2011-12</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Luis Menina</mal:name>
|
|
Packit |
1470ea |
<mal:email>liberforce@freeside.fr</mal:email>
|
|
Packit |
1470ea |
<mal:years>2014</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
</info>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<title>Barre d'outils</title>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<media type="image" mime="image/png" src="media/toolbar.png"/>
|
|
Packit |
1470ea |
La barre d'outils peut contenir soit du texte, soit des icônes de la collection. Dans cet exemple, nous utilisons les icônes de la collection. Cet exemple possède la fonction plein écran.
|
|
Packit |
1470ea |
This example uses SimpleActions (window and app). App actions can easily be added to the app menu.
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
#include <gtk/gtk.h>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Declare these two Toolbuttons, as they will be used in both the fullscreen
|
|
Packit |
1470ea |
* action callback as well as the activate function.
|
|
Packit |
1470ea |
*/
|
|
Packit |
1470ea |
GtkToolItem *fullscreen_button;
|
|
Packit |
1470ea |
GtkToolItem *leavefullscreen_button;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Callback function for the undo action */
|
|
Packit |
1470ea |
static void
|
|
Packit |
1470ea |
undo_callback (GSimpleAction *simple,
|
|
Packit |
1470ea |
GVariant *parameter,
|
|
Packit |
1470ea |
gpointer user_data)
|
|
Packit |
1470ea |
{
|
|
Packit |
1470ea |
g_print ("You clicked \"Undo\".\n");
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Callback function for the fullscreen action */
|
|
Packit |
1470ea |
static void
|
|
Packit |
1470ea |
fullscreen_callback (GSimpleAction *simple,
|
|
Packit |
1470ea |
GVariant *parameter,
|
|
Packit |
1470ea |
gpointer user_data)
|
|
Packit |
1470ea |
{
|
|
Packit |
1470ea |
GdkWindow *window = gtk_widget_get_window (GTK_WIDGET (user_data));
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
GdkWindowState current_state = gdk_window_get_state (window);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* If the window is currently in fullscreen mode */
|
|
Packit |
1470ea |
if ( (current_state & GDK_WINDOW_STATE_FULLSCREEN) != 0)
|
|
Packit |
1470ea |
{
|
|
Packit |
1470ea |
/* Minimize the window and change to the fullscreen button */
|
|
Packit |
1470ea |
gdk_window_unfullscreen (window);
|
|
Packit |
1470ea |
gtk_widget_hide (GTK_WIDGET(leavefullscreen_button));
|
|
Packit |
1470ea |
gtk_widget_show (GTK_WIDGET(fullscreen_button));
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
else
|
|
Packit |
1470ea |
{
|
|
Packit |
1470ea |
/* Maximize the window, and change to the unfullscreen button */
|
|
Packit |
1470ea |
gdk_window_fullscreen (window);
|
|
Packit |
1470ea |
gtk_widget_hide (GTK_WIDGET (fullscreen_button));
|
|
Packit |
1470ea |
gtk_widget_show (GTK_WIDGET (leavefullscreen_button));
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
static void
|
|
Packit |
1470ea |
activate (GtkApplication *app,
|
|
Packit |
1470ea |
gpointer user_data)
|
|
Packit |
1470ea |
{
|
|
Packit |
1470ea |
/* Initialize variables */
|
|
Packit |
1470ea |
GtkWidget *window;
|
|
Packit |
1470ea |
GtkWidget *grid;
|
|
Packit |
1470ea |
GtkWidget *toolbar;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
GtkToolItem *new_button;
|
|
Packit |
1470ea |
GtkToolItem *open_button;
|
|
Packit |
1470ea |
GtkToolItem *undo_button;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
GtkStyleContext *style_context;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
GSimpleAction *undo_action;
|
|
Packit |
1470ea |
GSimpleAction *fullscreen_action;
|
|
Packit |
1470ea |
GSimpleAction *leavefullscreen_action;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Create a window with a title and a default size */
|
|
Packit |
1470ea |
window = gtk_application_window_new (app);
|
|
Packit |
1470ea |
gtk_window_set_title (GTK_WINDOW (window), "Toolbar Example");
|
|
Packit |
1470ea |
gtk_window_set_default_size (GTK_WINDOW (window), 400, 200);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Here we begin to create the toolbar */
|
|
Packit |
1470ea |
toolbar = gtk_toolbar_new ();
|
|
Packit |
1470ea |
/* Set the toolbar to be the primary toolbar of the application */
|
|
Packit |
1470ea |
style_context = gtk_widget_get_style_context (toolbar);
|
|
Packit |
1470ea |
gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_PRIMARY_TOOLBAR);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Create a button for the "new" action, with a stock image */
|
|
Packit |
1470ea |
new_button = gtk_tool_button_new_from_stock (GTK_STOCK_NEW);
|
|
Packit |
1470ea |
/* Show the "new" button's label */
|
|
Packit |
1470ea |
gtk_tool_item_set_is_important (new_button, TRUE);
|
|
Packit |
1470ea |
/* Insert the button in the desired position within the toolbar */
|
|
Packit |
1470ea |
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), new_button, 0);
|
|
Packit |
1470ea |
/* Show the button */
|
|
Packit |
1470ea |
gtk_widget_show (GTK_WIDGET (new_button));
|
|
Packit |
1470ea |
/* Set the action name for the "new" action. We use "app.new" to
|
|
Packit |
1470ea |
* indicate that the action controls the application.
|
|
Packit |
1470ea |
*/
|
|
Packit |
1470ea |
gtk_actionable_set_action_name (GTK_ACTIONABLE (new_button), "app.new");
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Repeat the same steps for the "open" action */
|
|
Packit |
1470ea |
open_button = gtk_tool_button_new_from_stock (GTK_STOCK_OPEN);
|
|
Packit |
1470ea |
gtk_tool_item_set_is_important (open_button, TRUE);
|
|
Packit |
1470ea |
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), open_button, 1);
|
|
Packit |
1470ea |
gtk_widget_show (GTK_WIDGET (open_button));
|
|
Packit |
1470ea |
gtk_actionable_set_action_name (GTK_ACTIONABLE (open_button), "app.open");
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Repeat the same steps for the "undo" action */
|
|
Packit |
1470ea |
undo_button = gtk_tool_button_new_from_stock (GTK_STOCK_UNDO);
|
|
Packit |
1470ea |
gtk_tool_item_set_is_important (undo_button, TRUE);
|
|
Packit |
1470ea |
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), undo_button, 2);
|
|
Packit |
1470ea |
gtk_widget_show (GTK_WIDGET (undo_button));
|
|
Packit |
1470ea |
/* In this case, we use "win.undo" to indicate that
|
|
Packit |
1470ea |
* the action controls only the window
|
|
Packit |
1470ea |
*/
|
|
Packit |
1470ea |
gtk_actionable_set_action_name (GTK_ACTIONABLE (undo_button), "win.undo");
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Repeat the same steps for the "fullscreen" action */
|
|
Packit |
1470ea |
fullscreen_button = gtk_tool_button_new_from_stock (GTK_STOCK_FULLSCREEN);
|
|
Packit |
1470ea |
gtk_tool_item_set_is_important (fullscreen_button, TRUE);
|
|
Packit |
1470ea |
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), fullscreen_button, 3);
|
|
Packit |
1470ea |
gtk_widget_show (GTK_WIDGET (fullscreen_button));
|
|
Packit |
1470ea |
gtk_actionable_set_action_name (GTK_ACTIONABLE (fullscreen_button),
|
|
Packit |
1470ea |
"win.fullscreen");
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/*Repeat the same steps for the "leavefullscreen" action */
|
|
Packit |
1470ea |
leavefullscreen_button = gtk_tool_button_new_from_stock (GTK_STOCK_LEAVE_FULLSCREEN);
|
|
Packit |
1470ea |
gtk_tool_item_set_is_important (leavefullscreen_button, TRUE);
|
|
Packit |
1470ea |
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), leavefullscreen_button, 3);
|
|
Packit |
1470ea |
/* The only difference here is that we don't show the leavefullscreen button,
|
|
Packit |
1470ea |
* as it will later replace the fullscreen button.
|
|
Packit |
1470ea |
*/
|
|
Packit |
1470ea |
gtk_actionable_set_action_name (GTK_ACTIONABLE (leavefullscreen_button),
|
|
Packit |
1470ea |
"win.leavefullscreen");
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Once we've created the bare-bones of the toolbar, we make
|
|
Packit |
1470ea |
* sure it has enough horizontal space.
|
|
Packit |
1470ea |
*/
|
|
Packit |
1470ea |
gtk_widget_set_hexpand (toolbar, TRUE);
|
|
Packit |
1470ea |
gtk_widget_show (toolbar);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Attach the toolbar to the grid and add it to the overall window */
|
|
Packit |
1470ea |
grid = gtk_grid_new ();
|
|
Packit |
1470ea |
gtk_grid_attach (GTK_GRID (grid), toolbar, 0, 0, 1, 1);
|
|
Packit |
1470ea |
gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (grid));
|
|
Packit |
1470ea |
gtk_widget_show (GTK_WIDGET (grid));
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Use the action names to create the actions that control the window, and
|
|
Packit |
1470ea |
* connect them to the appropriate callbackfunctions.
|
|
Packit |
1470ea |
*/
|
|
Packit |
1470ea |
undo_action = g_simple_action_new ("undo", NULL);
|
|
Packit |
1470ea |
g_signal_connect (undo_action, "activate", G_CALLBACK (undo_callback),
|
|
Packit |
1470ea |
GTK_WINDOW (window));
|
|
Packit |
1470ea |
g_action_map_add_action (G_ACTION_MAP (window), G_ACTION (undo_action));
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
fullscreen_action = g_simple_action_new ("fullscreen", NULL);
|
|
Packit |
1470ea |
g_signal_connect (fullscreen_action, "activate", G_CALLBACK (fullscreen_callback),
|
|
Packit |
1470ea |
GTK_WINDOW (window));
|
|
Packit |
1470ea |
g_action_map_add_action (G_ACTION_MAP (window), G_ACTION (fullscreen_action));
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
leavefullscreen_action = g_simple_action_new ("leavefullscreen", NULL);
|
|
Packit |
1470ea |
g_signal_connect (leavefullscreen_action, "activate", G_CALLBACK (fullscreen_callback),
|
|
Packit |
1470ea |
GTK_WINDOW (window));
|
|
Packit |
1470ea |
g_action_map_add_action (G_ACTION_MAP (window), G_ACTION (leavefullscreen_action));
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
gtk_widget_show (window);
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Callback function for the new action */
|
|
Packit |
1470ea |
static void
|
|
Packit |
1470ea |
new_callback (GSimpleAction *simple,
|
|
Packit |
1470ea |
GVariant *parameter,
|
|
Packit |
1470ea |
gpointer user_data)
|
|
Packit |
1470ea |
{
|
|
Packit |
1470ea |
g_print ("You clicked \"New\".\n");
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Callback function for the open action */
|
|
Packit |
1470ea |
static void
|
|
Packit |
1470ea |
open_callback (GSimpleAction *simple,
|
|
Packit |
1470ea |
GVariant *parameter,
|
|
Packit |
1470ea |
gpointer user_data)
|
|
Packit |
1470ea |
{
|
|
Packit |
1470ea |
g_print ("You clicked \"Open\".\n");
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* In this function, we create the actions in which control the window, and
|
|
Packit |
1470ea |
* connect their signals to the appropriate callback function.
|
|
Packit |
1470ea |
*/
|
|
Packit |
1470ea |
static void
|
|
Packit |
1470ea |
startup (GApplication *app,
|
|
Packit |
1470ea |
gpointer user_data)
|
|
Packit |
1470ea |
{
|
|
Packit |
1470ea |
GSimpleAction *new_action;
|
|
Packit |
1470ea |
GSimpleAction *open_action;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
new_action = g_simple_action_new ("new", NULL);
|
|
Packit |
1470ea |
g_signal_connect (new_action, "activate", G_CALLBACK (new_callback), app);
|
|
Packit |
1470ea |
g_action_map_add_action (G_ACTION_MAP (app), G_ACTION (new_action));
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
open_action = g_simple_action_new ("open", NULL);
|
|
Packit |
1470ea |
g_signal_connect (open_action, "activate", G_CALLBACK (open_callback), app);
|
|
Packit |
1470ea |
g_action_map_add_action (G_ACTION_MAP (app), G_ACTION (open_action));
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Startup function for the application */
|
|
Packit |
1470ea |
int
|
|
Packit |
1470ea |
main (int argc, char **argv)
|
|
Packit |
1470ea |
{
|
|
Packit |
1470ea |
GtkApplication *app;
|
|
Packit |
1470ea |
int status;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
|
|
Packit |
1470ea |
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
|
|
Packit |
1470ea |
g_signal_connect (app, "startup", G_CALLBACK (startup), NULL);
|
|
Packit |
1470ea |
status = g_application_run (G_APPLICATION (app), argc, argv);
|
|
Packit |
1470ea |
g_object_unref (app);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
return status;
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
Dans cet exemple, les éléments suivants sont utilisés :
|
|
Packit |
1470ea |
<list>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/stable/GtkToolbar.html">GtkToolbar</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/stable/GtkToolButton.html">GtkToolbutton</link> </item>
|
|
Packit |
1470ea |
</list>
|
|
Packit |
1470ea |
</page>
|