forked from AuroraMiddleware/gtk
Formatting cleanups
While we normally try to avoid whitespace fixes, the gtk-demo code is shown as exemplary, so it should be in good shape, formatting-wise.
This commit is contained in:
parent
c5cd4174c3
commit
1204a850f3
@ -25,8 +25,8 @@ activate_action (GtkAction *action)
|
||||
GtkSettings *settings = gtk_settings_get_default ();
|
||||
|
||||
g_object_set (G_OBJECT (settings),
|
||||
"gtk-application-prefer-dark-theme", value,
|
||||
NULL);
|
||||
"gtk-application-prefer-dark-theme", value,
|
||||
NULL);
|
||||
return;
|
||||
}
|
||||
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
|
||||
@ -69,7 +69,7 @@ activate_radio_action (GtkAction *action, GtkRadioAction *current)
|
||||
|
||||
static void
|
||||
about_cb (GtkAction *action,
|
||||
GtkWidget *window)
|
||||
GtkWidget *window)
|
||||
{
|
||||
GdkPixbuf *pixbuf, *transparent;
|
||||
gchar *filename;
|
||||
@ -102,21 +102,21 @@ about_cb (GtkAction *action,
|
||||
}
|
||||
|
||||
gtk_show_about_dialog (GTK_WINDOW (window),
|
||||
"program-name", "GTK+ Code Demos",
|
||||
"version", g_strdup_printf ("%s,\nRunning against GTK+ %d.%d.%d",
|
||||
PACKAGE_VERSION,
|
||||
gtk_get_major_version (),
|
||||
gtk_get_minor_version (),
|
||||
gtk_get_micro_version ()),
|
||||
"copyright", "(C) 1997-2009 The GTK+ Team",
|
||||
"license-type", GTK_LICENSE_LGPL_2_1,
|
||||
"website", "http://www.gtk.org",
|
||||
"comments", "Program to demonstrate GTK+ functions.",
|
||||
"authors", authors,
|
||||
"documenters", documentors,
|
||||
"logo", transparent,
|
||||
"program-name", "GTK+ Code Demos",
|
||||
"version", g_strdup_printf ("%s,\nRunning against GTK+ %d.%d.%d",
|
||||
PACKAGE_VERSION,
|
||||
gtk_get_major_version (),
|
||||
gtk_get_minor_version (),
|
||||
gtk_get_micro_version ()),
|
||||
"copyright", "(C) 1997-2009 The GTK+ Team",
|
||||
"license-type", GTK_LICENSE_LGPL_2_1,
|
||||
"website", "http://www.gtk.org",
|
||||
"comments", "Program to demonstrate GTK+ functions.",
|
||||
"authors", authors,
|
||||
"documenters", documentors,
|
||||
"logo", transparent,
|
||||
"title", "About GTK+ Code Demos",
|
||||
NULL);
|
||||
NULL);
|
||||
|
||||
g_object_unref (transparent);
|
||||
}
|
||||
@ -249,9 +249,9 @@ static const gchar *ui_info =
|
||||
" <menu action='PreferencesMenu'>"
|
||||
" <menuitem action='DarkTheme'/>"
|
||||
" <menu action='ColorMenu'>"
|
||||
" <menuitem action='Red'/>"
|
||||
" <menuitem action='Green'/>"
|
||||
" <menuitem action='Blue'/>"
|
||||
" <menuitem action='Red'/>"
|
||||
" <menuitem action='Green'/>"
|
||||
" <menuitem action='Blue'/>"
|
||||
" </menu>"
|
||||
" <menu action='ShapeMenu'>"
|
||||
" <menuitem action='Square'/>"
|
||||
@ -317,10 +317,10 @@ register_stock_icons (void)
|
||||
pixbuf = NULL;
|
||||
filename = demo_find_file ("gtk-logo-rgb.gif", NULL);
|
||||
if (filename)
|
||||
{
|
||||
pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
|
||||
g_free (filename);
|
||||
}
|
||||
{
|
||||
pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
|
||||
g_free (filename);
|
||||
}
|
||||
|
||||
/* Register icon to accompany stock item */
|
||||
if (pixbuf != NULL)
|
||||
@ -355,8 +355,8 @@ update_statusbar (GtkTextBuffer *buffer,
|
||||
GtkTextIter iter;
|
||||
|
||||
gtk_statusbar_pop (statusbar, 0); /* clear any previous message,
|
||||
* underflow is allowed
|
||||
*/
|
||||
* underflow is allowed
|
||||
*/
|
||||
|
||||
count = gtk_text_buffer_get_char_count (buffer);
|
||||
|
||||
@ -407,7 +407,7 @@ do_appwindow (GtkWidget *do_widget)
|
||||
|
||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_screen (GTK_WINDOW (window),
|
||||
gtk_widget_get_screen (do_widget));
|
||||
gtk_widget_get_screen (do_widget));
|
||||
gtk_window_set_title (GTK_WINDOW (window), "Application Window");
|
||||
gtk_window_set_icon_name (GTK_WINDOW (window), "document-open");
|
||||
|
||||
@ -425,42 +425,42 @@ do_appwindow (GtkWidget *do_widget)
|
||||
|
||||
action_group = gtk_action_group_new ("AppWindowActions");
|
||||
open_action = g_object_new (tool_menu_action_get_type (),
|
||||
"name", "Open",
|
||||
"label", "_Open",
|
||||
"tooltip", "Open a file",
|
||||
"stock-id", GTK_STOCK_OPEN,
|
||||
NULL);
|
||||
"name", "Open",
|
||||
"label", "_Open",
|
||||
"tooltip", "Open a file",
|
||||
"stock-id", GTK_STOCK_OPEN,
|
||||
NULL);
|
||||
gtk_action_group_add_action (action_group, open_action);
|
||||
g_object_unref (open_action);
|
||||
gtk_action_group_add_actions (action_group,
|
||||
entries, n_entries,
|
||||
window);
|
||||
entries, n_entries,
|
||||
window);
|
||||
gtk_action_group_add_toggle_actions (action_group,
|
||||
toggle_entries, n_toggle_entries,
|
||||
NULL);
|
||||
toggle_entries, n_toggle_entries,
|
||||
NULL);
|
||||
gtk_action_group_add_radio_actions (action_group,
|
||||
color_entries, n_color_entries,
|
||||
COLOR_RED,
|
||||
G_CALLBACK (activate_radio_action),
|
||||
NULL);
|
||||
color_entries, n_color_entries,
|
||||
COLOR_RED,
|
||||
G_CALLBACK (activate_radio_action),
|
||||
NULL);
|
||||
gtk_action_group_add_radio_actions (action_group,
|
||||
shape_entries, n_shape_entries,
|
||||
SHAPE_SQUARE,
|
||||
G_CALLBACK (activate_radio_action),
|
||||
NULL);
|
||||
shape_entries, n_shape_entries,
|
||||
SHAPE_SQUARE,
|
||||
G_CALLBACK (activate_radio_action),
|
||||
NULL);
|
||||
|
||||
merge = gtk_ui_manager_new ();
|
||||
g_object_set_data_full (G_OBJECT (window), "ui-manager", merge,
|
||||
g_object_unref);
|
||||
g_object_unref);
|
||||
gtk_ui_manager_insert_action_group (merge, action_group, 0);
|
||||
gtk_window_add_accel_group (GTK_WINDOW (window),
|
||||
gtk_ui_manager_get_accel_group (merge));
|
||||
gtk_ui_manager_get_accel_group (merge));
|
||||
|
||||
if (!gtk_ui_manager_add_ui_from_string (merge, ui_info, -1, &error))
|
||||
{
|
||||
g_message ("building menus failed: %s", error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
{
|
||||
g_message ("building menus failed: %s", error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
bar = gtk_ui_manager_get_widget (merge, "/MenuBar");
|
||||
gtk_widget_show (bar);
|
||||
@ -552,4 +552,3 @@ do_appwindow (GtkWidget *do_widget)
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ do_builder (GtkWidget *do_widget)
|
||||
static GtkWidget *window = NULL;
|
||||
GError *err = NULL;
|
||||
gchar *filename;
|
||||
|
||||
|
||||
if (!window)
|
||||
{
|
||||
builder = gtk_builder_new ();
|
||||
@ -41,16 +41,16 @@ do_builder (GtkWidget *do_widget)
|
||||
gtk_builder_add_from_file (builder, filename, &err);
|
||||
g_free (filename);
|
||||
if (err)
|
||||
{
|
||||
g_error ("ERROR: %s\n", err->message);
|
||||
return NULL;
|
||||
}
|
||||
{
|
||||
g_error ("ERROR: %s\n", err->message);
|
||||
return NULL;
|
||||
}
|
||||
gtk_builder_connect_signals (builder, NULL);
|
||||
window = GTK_WIDGET (gtk_builder_get_object (builder, "window1"));
|
||||
gtk_window_set_screen (GTK_WINDOW (window),
|
||||
gtk_widget_get_screen (do_widget));
|
||||
gtk_widget_get_screen (do_widget));
|
||||
g_signal_connect (window, "destroy",
|
||||
G_CALLBACK (gtk_widget_destroyed), &window);
|
||||
G_CALLBACK (gtk_widget_destroyed), &window);
|
||||
}
|
||||
|
||||
if (!gtk_widget_get_visible (window))
|
||||
@ -58,7 +58,7 @@ do_builder (GtkWidget *do_widget)
|
||||
gtk_widget_show_all (window);
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
gtk_widget_destroy (window);
|
||||
window = NULL;
|
||||
}
|
||||
|
@ -7,14 +7,14 @@
|
||||
|
||||
static GtkWidget *
|
||||
create_bbox (gint horizontal,
|
||||
char *title,
|
||||
gint spacing,
|
||||
gint layout)
|
||||
char *title,
|
||||
gint spacing,
|
||||
gint layout)
|
||||
{
|
||||
GtkWidget *frame;
|
||||
GtkWidget *bbox;
|
||||
GtkWidget *button;
|
||||
|
||||
|
||||
frame = gtk_frame_new (title);
|
||||
|
||||
if (horizontal)
|
||||
@ -27,13 +27,13 @@ create_bbox (gint horizontal,
|
||||
|
||||
gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), layout);
|
||||
gtk_box_set_spacing (GTK_BOX (bbox), spacing);
|
||||
|
||||
|
||||
button = gtk_button_new_from_stock (GTK_STOCK_OK);
|
||||
gtk_container_add (GTK_CONTAINER (bbox), button);
|
||||
|
||||
|
||||
button = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
|
||||
gtk_container_add (GTK_CONTAINER (bbox), button);
|
||||
|
||||
|
||||
button = gtk_button_new_from_stock (GTK_STOCK_HELP);
|
||||
gtk_container_add (GTK_CONTAINER (bbox), button);
|
||||
|
||||
@ -49,68 +49,68 @@ do_button_box (GtkWidget *do_widget)
|
||||
GtkWidget *hbox;
|
||||
GtkWidget *frame_horz;
|
||||
GtkWidget *frame_vert;
|
||||
|
||||
|
||||
if (!window)
|
||||
{
|
||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_screen (GTK_WINDOW (window),
|
||||
gtk_widget_get_screen (do_widget));
|
||||
gtk_widget_get_screen (do_widget));
|
||||
gtk_window_set_title (GTK_WINDOW (window), "Button Boxes");
|
||||
|
||||
|
||||
g_signal_connect (window, "destroy",
|
||||
G_CALLBACK (gtk_widget_destroyed),
|
||||
&window);
|
||||
|
||||
G_CALLBACK (gtk_widget_destroyed),
|
||||
&window);
|
||||
|
||||
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
|
||||
|
||||
main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
||||
gtk_container_add (GTK_CONTAINER (window), main_vbox);
|
||||
|
||||
|
||||
frame_horz = gtk_frame_new ("Horizontal Button Boxes");
|
||||
gtk_box_pack_start (GTK_BOX (main_vbox), frame_horz, TRUE, TRUE, 10);
|
||||
|
||||
|
||||
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (vbox), 10);
|
||||
gtk_container_add (GTK_CONTAINER (frame_horz), vbox);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (vbox),
|
||||
create_bbox (TRUE, "Spread", 40, GTK_BUTTONBOX_SPREAD),
|
||||
TRUE, TRUE, 0);
|
||||
gtk_box_pack_start (GTK_BOX (vbox),
|
||||
create_bbox (TRUE, "Spread", 40, GTK_BUTTONBOX_SPREAD),
|
||||
TRUE, TRUE, 0);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (vbox),
|
||||
create_bbox (TRUE, "Edge", 40, GTK_BUTTONBOX_EDGE),
|
||||
TRUE, TRUE, 5);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (vbox),
|
||||
create_bbox (TRUE, "Start", 40, GTK_BUTTONBOX_START),
|
||||
TRUE, TRUE, 5);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (vbox),
|
||||
create_bbox (TRUE, "End", 40, GTK_BUTTONBOX_END),
|
||||
TRUE, TRUE, 5);
|
||||
gtk_box_pack_start (GTK_BOX (vbox),
|
||||
create_bbox (TRUE, "Edge", 40, GTK_BUTTONBOX_EDGE),
|
||||
TRUE, TRUE, 5);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (vbox),
|
||||
create_bbox (TRUE, "Start", 40, GTK_BUTTONBOX_START),
|
||||
TRUE, TRUE, 5);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (vbox),
|
||||
create_bbox (TRUE, "End", 40, GTK_BUTTONBOX_END),
|
||||
TRUE, TRUE, 5);
|
||||
|
||||
frame_vert = gtk_frame_new ("Vertical Button Boxes");
|
||||
gtk_box_pack_start (GTK_BOX (main_vbox), frame_vert, TRUE, TRUE, 10);
|
||||
|
||||
|
||||
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (hbox), 10);
|
||||
gtk_container_add (GTK_CONTAINER (frame_vert), hbox);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (hbox),
|
||||
create_bbox (FALSE, "Spread", 30, GTK_BUTTONBOX_SPREAD),
|
||||
TRUE, TRUE, 0);
|
||||
gtk_box_pack_start (GTK_BOX (hbox),
|
||||
create_bbox (FALSE, "Spread", 30, GTK_BUTTONBOX_SPREAD),
|
||||
TRUE, TRUE, 0);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (hbox),
|
||||
create_bbox (FALSE, "Edge", 30, GTK_BUTTONBOX_EDGE),
|
||||
TRUE, TRUE, 5);
|
||||
gtk_box_pack_start (GTK_BOX (hbox),
|
||||
create_bbox (FALSE, "Edge", 30, GTK_BUTTONBOX_EDGE),
|
||||
TRUE, TRUE, 5);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (hbox),
|
||||
create_bbox (FALSE, "Start", 30, GTK_BUTTONBOX_START),
|
||||
TRUE, TRUE, 5);
|
||||
gtk_box_pack_start (GTK_BOX (hbox),
|
||||
create_bbox (FALSE, "Start", 30, GTK_BUTTONBOX_START),
|
||||
TRUE, TRUE, 5);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (hbox),
|
||||
create_bbox (FALSE, "End", 30, GTK_BUTTONBOX_END),
|
||||
TRUE, TRUE, 5);
|
||||
gtk_box_pack_start (GTK_BOX (hbox),
|
||||
create_bbox (FALSE, "End", 30, GTK_BUTTONBOX_END),
|
||||
TRUE, TRUE, 5);
|
||||
}
|
||||
|
||||
if (!gtk_widget_get_visible (window))
|
||||
@ -118,7 +118,7 @@ do_button_box (GtkWidget *do_widget)
|
||||
gtk_widget_show_all (window);
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
gtk_widget_destroy (window);
|
||||
window = NULL;
|
||||
}
|
||||
|
@ -95,8 +95,8 @@ find_toplevel_at_pointer (GdkDisplay *display)
|
||||
|
||||
static gboolean
|
||||
button_release_event_cb (GtkWidget *widget,
|
||||
GdkEventButton *event,
|
||||
gboolean *clicked)
|
||||
GdkEventButton *event,
|
||||
gboolean *clicked)
|
||||
{
|
||||
*clicked = TRUE;
|
||||
return TRUE;
|
||||
@ -108,7 +108,7 @@ button_release_event_cb (GtkWidget *widget,
|
||||
*/
|
||||
static GtkWidget *
|
||||
query_for_toplevel (GdkScreen *screen,
|
||||
const char *prompt)
|
||||
const char *prompt)
|
||||
{
|
||||
GdkDisplay *display = gdk_screen_get_display (screen);
|
||||
GtkWidget *popup, *label, *frame;
|
||||
@ -132,31 +132,31 @@ query_for_toplevel (GdkScreen *screen,
|
||||
cursor = gdk_cursor_new_for_display (display, GDK_CROSSHAIR);
|
||||
|
||||
if (gdk_pointer_grab (gtk_widget_get_window (popup), FALSE,
|
||||
GDK_BUTTON_RELEASE_MASK,
|
||||
NULL,
|
||||
cursor,
|
||||
GDK_CURRENT_TIME) == GDK_GRAB_SUCCESS)
|
||||
GDK_BUTTON_RELEASE_MASK,
|
||||
NULL,
|
||||
cursor,
|
||||
GDK_CURRENT_TIME) == GDK_GRAB_SUCCESS)
|
||||
{
|
||||
gboolean clicked = FALSE;
|
||||
|
||||
g_signal_connect (popup, "button-release-event",
|
||||
G_CALLBACK (button_release_event_cb), &clicked);
|
||||
G_CALLBACK (button_release_event_cb), &clicked);
|
||||
|
||||
/* Process events until clicked is set by button_release_event_cb.
|
||||
* We pass in may_block=TRUE since we want to wait if there
|
||||
* are no events currently.
|
||||
*/
|
||||
while (!clicked)
|
||||
g_main_context_iteration (NULL, TRUE);
|
||||
g_main_context_iteration (NULL, TRUE);
|
||||
|
||||
toplevel = find_toplevel_at_pointer (gdk_screen_get_display (screen));
|
||||
if (toplevel == popup)
|
||||
toplevel = NULL;
|
||||
toplevel = NULL;
|
||||
}
|
||||
|
||||
g_object_unref (cursor);
|
||||
gtk_widget_destroy (popup);
|
||||
gdk_flush (); /* Really release the grab */
|
||||
gdk_flush (); /* Really release the grab */
|
||||
|
||||
return toplevel;
|
||||
}
|
||||
@ -171,8 +171,8 @@ query_change_display (ChangeDisplayInfo *info)
|
||||
GtkWidget *toplevel;
|
||||
|
||||
toplevel = query_for_toplevel (screen,
|
||||
"Please select the toplevel\n"
|
||||
"to move to the new screen");
|
||||
"Please select the toplevel\n"
|
||||
"to move to the new screen");
|
||||
|
||||
if (toplevel)
|
||||
gtk_window_set_screen (GTK_WINDOW (toplevel), info->current_screen);
|
||||
@ -193,19 +193,19 @@ fill_screens (ChangeDisplayInfo *info)
|
||||
gint i;
|
||||
|
||||
for (i = 0; i < n_screens; i++)
|
||||
{
|
||||
GdkScreen *screen = gdk_display_get_screen (info->current_display, i);
|
||||
GtkTreeIter iter;
|
||||
{
|
||||
GdkScreen *screen = gdk_display_get_screen (info->current_display, i);
|
||||
GtkTreeIter iter;
|
||||
|
||||
gtk_list_store_append (GTK_LIST_STORE (info->screen_model), &iter);
|
||||
gtk_list_store_set (GTK_LIST_STORE (info->screen_model), &iter,
|
||||
SCREEN_COLUMN_NUMBER, i,
|
||||
SCREEN_COLUMN_SCREEN, screen,
|
||||
-1);
|
||||
gtk_list_store_append (GTK_LIST_STORE (info->screen_model), &iter);
|
||||
gtk_list_store_set (GTK_LIST_STORE (info->screen_model), &iter,
|
||||
SCREEN_COLUMN_NUMBER, i,
|
||||
SCREEN_COLUMN_SCREEN, screen,
|
||||
-1);
|
||||
|
||||
if (i == 0)
|
||||
gtk_tree_selection_select_iter (info->screen_selection, &iter);
|
||||
}
|
||||
if (i == 0)
|
||||
gtk_tree_selection_select_iter (info->screen_selection, &iter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -215,8 +215,8 @@ fill_screens (ChangeDisplayInfo *info)
|
||||
*/
|
||||
static void
|
||||
response_cb (GtkDialog *dialog,
|
||||
gint response_id,
|
||||
ChangeDisplayInfo *info)
|
||||
gint response_id,
|
||||
ChangeDisplayInfo *info)
|
||||
{
|
||||
if (response_id == GTK_RESPONSE_OK)
|
||||
query_change_display (info);
|
||||
@ -230,7 +230,7 @@ response_cb (GtkDialog *dialog,
|
||||
*/
|
||||
static void
|
||||
open_display_cb (GtkWidget *button,
|
||||
ChangeDisplayInfo *info)
|
||||
ChangeDisplayInfo *info)
|
||||
{
|
||||
GtkWidget *content_area;
|
||||
GtkWidget *dialog;
|
||||
@ -240,11 +240,11 @@ open_display_cb (GtkWidget *button,
|
||||
GdkDisplay *result = NULL;
|
||||
|
||||
dialog = gtk_dialog_new_with_buttons ("Open Display",
|
||||
GTK_WINDOW (info->window),
|
||||
GTK_DIALOG_MODAL,
|
||||
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
||||
GTK_STOCK_OK, GTK_RESPONSE_OK,
|
||||
NULL);
|
||||
GTK_WINDOW (info->window),
|
||||
GTK_DIALOG_MODAL,
|
||||
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
||||
GTK_STOCK_OK, GTK_RESPONSE_OK,
|
||||
NULL);
|
||||
|
||||
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
|
||||
display_entry = gtk_entry_new ();
|
||||
@ -264,25 +264,25 @@ open_display_cb (GtkWidget *button,
|
||||
{
|
||||
gint response_id = gtk_dialog_run (GTK_DIALOG (dialog));
|
||||
if (response_id != GTK_RESPONSE_OK)
|
||||
break;
|
||||
break;
|
||||
|
||||
new_screen_name = gtk_editable_get_chars (GTK_EDITABLE (display_entry),
|
||||
0, -1);
|
||||
0, -1);
|
||||
|
||||
if (strcmp (new_screen_name, "") != 0)
|
||||
{
|
||||
result = gdk_display_open (new_screen_name);
|
||||
if (!result)
|
||||
{
|
||||
gchar *error_msg =
|
||||
g_strdup_printf ("Can't open display :\n\t%s\nplease try another one\n",
|
||||
new_screen_name);
|
||||
gtk_label_set_text (GTK_LABEL (dialog_label), error_msg);
|
||||
g_free (error_msg);
|
||||
}
|
||||
{
|
||||
result = gdk_display_open (new_screen_name);
|
||||
if (!result)
|
||||
{
|
||||
gchar *error_msg =
|
||||
g_strdup_printf ("Can't open display :\n\t%s\nplease try another one\n",
|
||||
new_screen_name);
|
||||
gtk_label_set_text (GTK_LABEL (dialog_label), error_msg);
|
||||
g_free (error_msg);
|
||||
}
|
||||
|
||||
g_free (new_screen_name);
|
||||
}
|
||||
g_free (new_screen_name);
|
||||
}
|
||||
}
|
||||
|
||||
gtk_widget_destroy (dialog);
|
||||
@ -293,7 +293,7 @@ open_display_cb (GtkWidget *button,
|
||||
*/
|
||||
static void
|
||||
close_display_cb (GtkWidget *button,
|
||||
ChangeDisplayInfo *info)
|
||||
ChangeDisplayInfo *info)
|
||||
{
|
||||
if (info->current_display)
|
||||
gdk_display_close (info->current_display);
|
||||
@ -305,7 +305,7 @@ close_display_cb (GtkWidget *button,
|
||||
*/
|
||||
static void
|
||||
display_changed_cb (GtkTreeSelection *selection,
|
||||
ChangeDisplayInfo *info)
|
||||
ChangeDisplayInfo *info)
|
||||
{
|
||||
GtkTreeModel *model;
|
||||
GtkTreeIter iter;
|
||||
@ -314,8 +314,8 @@ display_changed_cb (GtkTreeSelection *selection,
|
||||
g_object_unref (info->current_display);
|
||||
if (gtk_tree_selection_get_selected (selection, &model, &iter))
|
||||
gtk_tree_model_get (model, &iter,
|
||||
DISPLAY_COLUMN_DISPLAY, &info->current_display,
|
||||
-1);
|
||||
DISPLAY_COLUMN_DISPLAY, &info->current_display,
|
||||
-1);
|
||||
else
|
||||
info->current_display = NULL;
|
||||
|
||||
@ -327,7 +327,7 @@ display_changed_cb (GtkTreeSelection *selection,
|
||||
*/
|
||||
static void
|
||||
screen_changed_cb (GtkTreeSelection *selection,
|
||||
ChangeDisplayInfo *info)
|
||||
ChangeDisplayInfo *info)
|
||||
{
|
||||
GtkTreeModel *model;
|
||||
GtkTreeIter iter;
|
||||
@ -336,8 +336,8 @@ screen_changed_cb (GtkTreeSelection *selection,
|
||||
g_object_unref (info->current_screen);
|
||||
if (gtk_tree_selection_get_selected (selection, &model, &iter))
|
||||
gtk_tree_model_get (model, &iter,
|
||||
SCREEN_COLUMN_SCREEN, &info->current_screen,
|
||||
-1);
|
||||
SCREEN_COLUMN_SCREEN, &info->current_screen,
|
||||
-1);
|
||||
else
|
||||
info->current_screen = NULL;
|
||||
}
|
||||
@ -349,10 +349,10 @@ screen_changed_cb (GtkTreeSelection *selection,
|
||||
*/
|
||||
static void
|
||||
create_frame (ChangeDisplayInfo *info,
|
||||
const char *title,
|
||||
GtkWidget **frame,
|
||||
GtkWidget **tree_view,
|
||||
GtkWidget **button_vbox)
|
||||
const char *title,
|
||||
GtkWidget **frame,
|
||||
GtkWidget **tree_view,
|
||||
GtkWidget **button_vbox)
|
||||
{
|
||||
GtkTreeSelection *selection;
|
||||
GtkWidget *scrollwin;
|
||||
@ -366,9 +366,9 @@ create_frame (ChangeDisplayInfo *info,
|
||||
|
||||
scrollwin = gtk_scrolled_window_new (NULL, NULL);
|
||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollwin),
|
||||
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
|
||||
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
|
||||
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrollwin),
|
||||
GTK_SHADOW_IN);
|
||||
GTK_SHADOW_IN);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), scrollwin, TRUE, TRUE, 0);
|
||||
|
||||
*tree_view = gtk_tree_view_new ();
|
||||
@ -426,20 +426,20 @@ create_display_frame (ChangeDisplayInfo *info)
|
||||
gtk_box_pack_start (GTK_BOX (button_vbox), button, FALSE, FALSE, 0);
|
||||
|
||||
info->display_model = (GtkTreeModel *)gtk_list_store_new (DISPLAY_NUM_COLUMNS,
|
||||
G_TYPE_STRING,
|
||||
GDK_TYPE_DISPLAY);
|
||||
G_TYPE_STRING,
|
||||
GDK_TYPE_DISPLAY);
|
||||
|
||||
gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), info->display_model);
|
||||
|
||||
column = gtk_tree_view_column_new_with_attributes ("Name",
|
||||
gtk_cell_renderer_text_new (),
|
||||
"text", DISPLAY_COLUMN_NAME,
|
||||
NULL);
|
||||
gtk_cell_renderer_text_new (),
|
||||
"text", DISPLAY_COLUMN_NAME,
|
||||
NULL);
|
||||
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
|
||||
|
||||
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
|
||||
g_signal_connect (selection, "changed",
|
||||
G_CALLBACK (display_changed_cb), info);
|
||||
G_CALLBACK (display_changed_cb), info);
|
||||
|
||||
return frame;
|
||||
}
|
||||
@ -457,20 +457,20 @@ create_screen_frame (ChangeDisplayInfo *info)
|
||||
create_frame (info, "Screen", &frame, &tree_view, &button_vbox);
|
||||
|
||||
info->screen_model = (GtkTreeModel *)gtk_list_store_new (SCREEN_NUM_COLUMNS,
|
||||
G_TYPE_INT,
|
||||
GDK_TYPE_SCREEN);
|
||||
G_TYPE_INT,
|
||||
GDK_TYPE_SCREEN);
|
||||
|
||||
gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), info->screen_model);
|
||||
|
||||
column = gtk_tree_view_column_new_with_attributes ("Number",
|
||||
gtk_cell_renderer_text_new (),
|
||||
"text", SCREEN_COLUMN_NUMBER,
|
||||
NULL);
|
||||
gtk_cell_renderer_text_new (),
|
||||
"text", SCREEN_COLUMN_NUMBER,
|
||||
NULL);
|
||||
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
|
||||
|
||||
info->screen_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
|
||||
g_signal_connect (info->screen_selection, "changed",
|
||||
G_CALLBACK (screen_changed_cb), info);
|
||||
G_CALLBACK (screen_changed_cb), info);
|
||||
|
||||
return frame;
|
||||
}
|
||||
@ -480,8 +480,8 @@ create_screen_frame (ChangeDisplayInfo *info)
|
||||
*/
|
||||
static void
|
||||
display_closed_cb (GdkDisplay *display,
|
||||
gboolean is_error,
|
||||
ChangeDisplayInfo *info)
|
||||
gboolean is_error,
|
||||
ChangeDisplayInfo *info)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
gboolean valid;
|
||||
@ -493,13 +493,13 @@ display_closed_cb (GdkDisplay *display,
|
||||
GdkDisplay *tmp_display;
|
||||
|
||||
gtk_tree_model_get (info->display_model, &iter,
|
||||
DISPLAY_COLUMN_DISPLAY, &tmp_display,
|
||||
-1);
|
||||
DISPLAY_COLUMN_DISPLAY, &tmp_display,
|
||||
-1);
|
||||
if (tmp_display == display)
|
||||
{
|
||||
gtk_list_store_remove (GTK_LIST_STORE (info->display_model), &iter);
|
||||
break;
|
||||
}
|
||||
{
|
||||
gtk_list_store_remove (GTK_LIST_STORE (info->display_model), &iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -509,27 +509,27 @@ display_closed_cb (GdkDisplay *display,
|
||||
*/
|
||||
static void
|
||||
add_display (ChangeDisplayInfo *info,
|
||||
GdkDisplay *display)
|
||||
GdkDisplay *display)
|
||||
{
|
||||
const gchar *name = gdk_display_get_name (display);
|
||||
GtkTreeIter iter;
|
||||
|
||||
gtk_list_store_append (GTK_LIST_STORE (info->display_model), &iter);
|
||||
gtk_list_store_set (GTK_LIST_STORE (info->display_model), &iter,
|
||||
DISPLAY_COLUMN_NAME, name,
|
||||
DISPLAY_COLUMN_DISPLAY, display,
|
||||
-1);
|
||||
DISPLAY_COLUMN_NAME, name,
|
||||
DISPLAY_COLUMN_DISPLAY, display,
|
||||
-1);
|
||||
|
||||
g_signal_connect (display, "closed",
|
||||
G_CALLBACK (display_closed_cb), info);
|
||||
G_CALLBACK (display_closed_cb), info);
|
||||
}
|
||||
|
||||
/* Called when a new display is opened
|
||||
*/
|
||||
static void
|
||||
display_opened_cb (GdkDisplayManager *manager,
|
||||
GdkDisplay *display,
|
||||
ChangeDisplayInfo *info)
|
||||
GdkDisplay *display,
|
||||
ChangeDisplayInfo *info)
|
||||
{
|
||||
add_display (info, display);
|
||||
}
|
||||
@ -551,7 +551,7 @@ initialize_displays (ChangeDisplayInfo *info)
|
||||
g_slist_free (tmp_list);
|
||||
|
||||
g_signal_connect (manager, "display-opened",
|
||||
G_CALLBACK (display_opened_cb), info);
|
||||
G_CALLBACK (display_opened_cb), info);
|
||||
}
|
||||
|
||||
/* Cleans up when the toplevel is destroyed; we remove the
|
||||
@ -566,13 +566,13 @@ destroy_info (ChangeDisplayInfo *info)
|
||||
GSList *tmp_list;
|
||||
|
||||
g_signal_handlers_disconnect_by_func (manager,
|
||||
display_opened_cb,
|
||||
info);
|
||||
display_opened_cb,
|
||||
info);
|
||||
|
||||
for (tmp_list = displays; tmp_list; tmp_list = tmp_list->next)
|
||||
g_signal_handlers_disconnect_by_func (tmp_list->data,
|
||||
display_closed_cb,
|
||||
info);
|
||||
display_closed_cb,
|
||||
info);
|
||||
|
||||
g_slist_free (tmp_list);
|
||||
|
||||
@ -590,7 +590,7 @@ destroy_info (ChangeDisplayInfo *info)
|
||||
|
||||
static void
|
||||
destroy_cb (GObject *object,
|
||||
ChangeDisplayInfo **info)
|
||||
ChangeDisplayInfo **info)
|
||||
{
|
||||
destroy_info (*info);
|
||||
*info = NULL;
|
||||
@ -613,18 +613,18 @@ do_changedisplay (GtkWidget *do_widget)
|
||||
info = g_new0 (ChangeDisplayInfo, 1);
|
||||
|
||||
info->window = gtk_dialog_new_with_buttons ("Change Screen or display",
|
||||
GTK_WINDOW (do_widget),
|
||||
0,
|
||||
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
|
||||
"Change", GTK_RESPONSE_OK,
|
||||
NULL);
|
||||
GTK_WINDOW (do_widget),
|
||||
0,
|
||||
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
|
||||
"Change", GTK_RESPONSE_OK,
|
||||
NULL);
|
||||
|
||||
gtk_window_set_default_size (GTK_WINDOW (info->window), 300, 400);
|
||||
|
||||
g_signal_connect (info->window, "response",
|
||||
G_CALLBACK (response_cb), info);
|
||||
G_CALLBACK (response_cb), info);
|
||||
g_signal_connect (info->window, "destroy",
|
||||
G_CALLBACK (destroy_cb), &info);
|
||||
G_CALLBACK (destroy_cb), &info);
|
||||
|
||||
content_area = gtk_dialog_get_content_area (GTK_DIALOG (info->window));
|
||||
|
||||
|
@ -1,15 +1,15 @@
|
||||
/* Combo boxes
|
||||
/* Combo boxes
|
||||
*
|
||||
* The ComboBox widget allows to select one option out of a list.
|
||||
* The ComboBoxEntry additionally allows the user to enter a value
|
||||
* that is not in the list of options.
|
||||
* that is not in the list of options.
|
||||
*
|
||||
* How the options are displayed is controlled by cell renderers.
|
||||
*/
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
enum
|
||||
enum
|
||||
{
|
||||
PIXBUF_COL,
|
||||
TEXT_COL
|
||||
@ -20,16 +20,16 @@ strip_underscore (const gchar *text)
|
||||
{
|
||||
gchar *p, *q;
|
||||
gchar *result;
|
||||
|
||||
|
||||
result = g_strdup (text);
|
||||
p = q = result;
|
||||
while (*p)
|
||||
while (*p)
|
||||
{
|
||||
if (*p != '_')
|
||||
{
|
||||
*q = *p;
|
||||
q++;
|
||||
}
|
||||
{
|
||||
*q = *p;
|
||||
q++;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
*q = '\0';
|
||||
@ -46,7 +46,7 @@ create_stock_icon_store (void)
|
||||
GTK_STOCK_NEW,
|
||||
GTK_STOCK_CLEAR,
|
||||
NULL,
|
||||
GTK_STOCK_OPEN
|
||||
GTK_STOCK_OPEN
|
||||
};
|
||||
|
||||
GtkStockItem item;
|
||||
@ -58,50 +58,50 @@ create_stock_icon_store (void)
|
||||
gint i;
|
||||
|
||||
cellview = gtk_cell_view_new ();
|
||||
|
||||
|
||||
store = gtk_list_store_new (2, GDK_TYPE_PIXBUF, G_TYPE_STRING);
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (stock_id); i++)
|
||||
{
|
||||
if (stock_id[i])
|
||||
{
|
||||
pixbuf = gtk_widget_render_icon_pixbuf (cellview, stock_id[i],
|
||||
GTK_ICON_SIZE_BUTTON);
|
||||
gtk_stock_lookup (stock_id[i], &item);
|
||||
label = strip_underscore (item.label);
|
||||
gtk_list_store_append (store, &iter);
|
||||
gtk_list_store_set (store, &iter,
|
||||
PIXBUF_COL, pixbuf,
|
||||
TEXT_COL, label,
|
||||
-1);
|
||||
g_object_unref (pixbuf);
|
||||
g_free (label);
|
||||
}
|
||||
{
|
||||
pixbuf = gtk_widget_render_icon_pixbuf (cellview, stock_id[i],
|
||||
GTK_ICON_SIZE_BUTTON);
|
||||
gtk_stock_lookup (stock_id[i], &item);
|
||||
label = strip_underscore (item.label);
|
||||
gtk_list_store_append (store, &iter);
|
||||
gtk_list_store_set (store, &iter,
|
||||
PIXBUF_COL, pixbuf,
|
||||
TEXT_COL, label,
|
||||
-1);
|
||||
g_object_unref (pixbuf);
|
||||
g_free (label);
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_list_store_append (store, &iter);
|
||||
gtk_list_store_set (store, &iter,
|
||||
PIXBUF_COL, NULL,
|
||||
TEXT_COL, "separator",
|
||||
-1);
|
||||
}
|
||||
{
|
||||
gtk_list_store_append (store, &iter);
|
||||
gtk_list_store_set (store, &iter,
|
||||
PIXBUF_COL, NULL,
|
||||
TEXT_COL, "separator",
|
||||
-1);
|
||||
}
|
||||
}
|
||||
|
||||
gtk_widget_destroy (cellview);
|
||||
|
||||
|
||||
return GTK_TREE_MODEL (store);
|
||||
}
|
||||
|
||||
/* A GtkCellLayoutDataFunc that demonstrates how one can control
|
||||
* sensitivity of rows. This particular function does nothing
|
||||
* sensitivity of rows. This particular function does nothing
|
||||
* useful and just makes the second row insensitive.
|
||||
*/
|
||||
static void
|
||||
set_sensitive (GtkCellLayout *cell_layout,
|
||||
GtkCellRenderer *cell,
|
||||
GtkTreeModel *tree_model,
|
||||
GtkTreeIter *iter,
|
||||
gpointer data)
|
||||
GtkCellRenderer *cell,
|
||||
GtkTreeModel *tree_model,
|
||||
GtkTreeIter *iter,
|
||||
gpointer data)
|
||||
{
|
||||
GtkTreePath *path;
|
||||
gint *indices;
|
||||
@ -116,13 +116,13 @@ set_sensitive (GtkCellLayout *cell_layout,
|
||||
}
|
||||
|
||||
/* A GtkTreeViewRowSeparatorFunc that demonstrates how rows can be
|
||||
* rendered as separators. This particular function does nothing
|
||||
* rendered as separators. This particular function does nothing
|
||||
* useful and just turns the fourth row into a separator.
|
||||
*/
|
||||
static gboolean
|
||||
is_separator (GtkTreeModel *model,
|
||||
GtkTreeIter *iter,
|
||||
gpointer data)
|
||||
GtkTreeIter *iter,
|
||||
gpointer data)
|
||||
{
|
||||
GtkTreePath *path;
|
||||
gboolean result;
|
||||
@ -141,11 +141,11 @@ create_capital_store (void)
|
||||
gchar *group;
|
||||
gchar *capital;
|
||||
} capitals[] = {
|
||||
{ "A - B", NULL },
|
||||
{ "A - B", NULL },
|
||||
{ NULL, "Albany" },
|
||||
{ NULL, "Annapolis" },
|
||||
{ NULL, "Atlanta" },
|
||||
{ NULL, "Augusta" },
|
||||
{ NULL, "Augusta" },
|
||||
{ NULL, "Austin" },
|
||||
{ NULL, "Baton Rouge" },
|
||||
{ NULL, "Bismarck" },
|
||||
@ -199,36 +199,36 @@ create_capital_store (void)
|
||||
{ NULL, "Trenton" },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
|
||||
GtkTreeIter iter, iter2;
|
||||
GtkTreeStore *store;
|
||||
gint i;
|
||||
|
||||
store = gtk_tree_store_new (1, G_TYPE_STRING);
|
||||
|
||||
|
||||
for (i = 0; capitals[i].group || capitals[i].capital; i++)
|
||||
{
|
||||
if (capitals[i].group)
|
||||
{
|
||||
gtk_tree_store_append (store, &iter, NULL);
|
||||
gtk_tree_store_set (store, &iter, 0, capitals[i].group, -1);
|
||||
}
|
||||
{
|
||||
gtk_tree_store_append (store, &iter, NULL);
|
||||
gtk_tree_store_set (store, &iter, 0, capitals[i].group, -1);
|
||||
}
|
||||
else if (capitals[i].capital)
|
||||
{
|
||||
gtk_tree_store_append (store, &iter2, &iter);
|
||||
gtk_tree_store_set (store, &iter2, 0, capitals[i].capital, -1);
|
||||
}
|
||||
{
|
||||
gtk_tree_store_append (store, &iter2, &iter);
|
||||
gtk_tree_store_set (store, &iter2, 0, capitals[i].capital, -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return GTK_TREE_MODEL (store);
|
||||
}
|
||||
|
||||
static void
|
||||
is_capital_sensitive (GtkCellLayout *cell_layout,
|
||||
GtkCellRenderer *cell,
|
||||
GtkTreeModel *tree_model,
|
||||
GtkTreeIter *iter,
|
||||
gpointer data)
|
||||
GtkCellRenderer *cell,
|
||||
GtkTreeModel *tree_model,
|
||||
GtkTreeIter *iter,
|
||||
gpointer data)
|
||||
{
|
||||
gboolean sensitive;
|
||||
|
||||
@ -274,8 +274,8 @@ struct _MaskEntryClass
|
||||
static void mask_entry_editable_init (GtkEditableInterface *iface);
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (MaskEntry, mask_entry, GTK_TYPE_ENTRY,
|
||||
G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
|
||||
mask_entry_editable_init));
|
||||
G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
|
||||
mask_entry_editable_init));
|
||||
|
||||
|
||||
static void
|
||||
@ -286,10 +286,10 @@ mask_entry_set_background (MaskEntry *entry)
|
||||
if (entry->mask)
|
||||
{
|
||||
if (!g_regex_match_simple (entry->mask, gtk_entry_get_text (GTK_ENTRY (entry)), 0, 0))
|
||||
{
|
||||
gtk_widget_override_color (GTK_WIDGET (entry), 0, &error_color);
|
||||
return;
|
||||
}
|
||||
{
|
||||
gtk_widget_override_color (GTK_WIDGET (entry), 0, &error_color);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
gtk_widget_override_color (GTK_WIDGET (entry), 0, NULL);
|
||||
@ -338,58 +338,58 @@ do_combobox (GtkWidget *do_widget)
|
||||
gtk_window_set_screen (GTK_WINDOW (window),
|
||||
gtk_widget_get_screen (do_widget));
|
||||
gtk_window_set_title (GTK_WINDOW (window), "Combo boxes");
|
||||
|
||||
|
||||
g_signal_connect (window, "destroy",
|
||||
G_CALLBACK (gtk_widget_destroyed),
|
||||
&window);
|
||||
|
||||
|
||||
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
|
||||
|
||||
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
|
||||
gtk_container_add (GTK_CONTAINER (window), vbox);
|
||||
|
||||
/* A combobox demonstrating cell renderers, separators and
|
||||
* insensitive rows
|
||||
* insensitive rows
|
||||
*/
|
||||
frame = gtk_frame_new ("Some stock icons");
|
||||
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
|
||||
|
||||
|
||||
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (box), 5);
|
||||
gtk_container_add (GTK_CONTAINER (frame), box);
|
||||
|
||||
|
||||
model = create_stock_icon_store ();
|
||||
combo = gtk_combo_box_new_with_model (model);
|
||||
g_object_unref (model);
|
||||
gtk_container_add (GTK_CONTAINER (box), combo);
|
||||
|
||||
|
||||
renderer = gtk_cell_renderer_pixbuf_new ();
|
||||
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, FALSE);
|
||||
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), renderer,
|
||||
"pixbuf", PIXBUF_COL,
|
||||
NULL);
|
||||
"pixbuf", PIXBUF_COL,
|
||||
NULL);
|
||||
|
||||
gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo),
|
||||
renderer,
|
||||
set_sensitive,
|
||||
NULL, NULL);
|
||||
|
||||
renderer,
|
||||
set_sensitive,
|
||||
NULL, NULL);
|
||||
|
||||
renderer = gtk_cell_renderer_text_new ();
|
||||
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, TRUE);
|
||||
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), renderer,
|
||||
"text", TEXT_COL,
|
||||
NULL);
|
||||
"text", TEXT_COL,
|
||||
NULL);
|
||||
|
||||
gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo),
|
||||
renderer,
|
||||
set_sensitive,
|
||||
NULL, NULL);
|
||||
renderer,
|
||||
set_sensitive,
|
||||
NULL, NULL);
|
||||
|
||||
gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combo),
|
||||
is_separator, NULL, NULL);
|
||||
|
||||
gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combo),
|
||||
is_separator, NULL, NULL);
|
||||
|
||||
gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
|
||||
|
||||
|
||||
/* A combobox demonstrating trees.
|
||||
*/
|
||||
frame = gtk_frame_new ("Where are we ?");
|
||||
@ -398,7 +398,7 @@ do_combobox (GtkWidget *do_widget)
|
||||
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (box), 5);
|
||||
gtk_container_add (GTK_CONTAINER (frame), box);
|
||||
|
||||
|
||||
model = create_capital_store ();
|
||||
combo = gtk_combo_box_new_with_model (model);
|
||||
g_object_unref (model);
|
||||
@ -407,12 +407,12 @@ do_combobox (GtkWidget *do_widget)
|
||||
renderer = gtk_cell_renderer_text_new ();
|
||||
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, TRUE);
|
||||
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), renderer,
|
||||
"text", 0,
|
||||
NULL);
|
||||
"text", 0,
|
||||
NULL);
|
||||
gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo),
|
||||
renderer,
|
||||
is_capital_sensitive,
|
||||
NULL, NULL);
|
||||
renderer,
|
||||
is_capital_sensitive,
|
||||
NULL, NULL);
|
||||
|
||||
path = gtk_tree_path_new_from_indices (0, 8, -1);
|
||||
gtk_tree_model_get_iter (model, &iter, path);
|
||||
@ -423,18 +423,18 @@ do_combobox (GtkWidget *do_widget)
|
||||
*/
|
||||
frame = gtk_frame_new ("Editable");
|
||||
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
|
||||
|
||||
|
||||
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (box), 5);
|
||||
gtk_container_add (GTK_CONTAINER (frame), box);
|
||||
|
||||
|
||||
combo = gtk_combo_box_text_new_with_entry ();
|
||||
fill_combo_entry (combo);
|
||||
gtk_container_add (GTK_CONTAINER (box), combo);
|
||||
|
||||
|
||||
entry = g_object_new (TYPE_MASK_ENTRY, NULL);
|
||||
MASK_ENTRY (entry)->mask = "^([0-9]*|One|Two|2\302\275|Three)$";
|
||||
|
||||
|
||||
gtk_container_remove (GTK_CONTAINER (combo), gtk_bin_get_child (GTK_BIN (combo)));
|
||||
gtk_container_add (GTK_CONTAINER (combo), entry);
|
||||
|
||||
@ -464,7 +464,7 @@ do_combobox (GtkWidget *do_widget)
|
||||
gtk_widget_show_all (window);
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
gtk_widget_destroy (window);
|
||||
window = NULL;
|
||||
}
|
||||
|
@ -11,17 +11,17 @@ static GtkWidget *entry2 = NULL;
|
||||
|
||||
static void
|
||||
message_dialog_clicked (GtkButton *button,
|
||||
gpointer user_data)
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
static gint i = 1;
|
||||
|
||||
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
|
||||
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_MESSAGE_INFO,
|
||||
GTK_BUTTONS_OK,
|
||||
"This message box has been popped up the following\n"
|
||||
"number of times:");
|
||||
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_MESSAGE_INFO,
|
||||
GTK_BUTTONS_OK,
|
||||
"This message box has been popped up the following\n"
|
||||
"number of times:");
|
||||
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
|
||||
"%d", i);
|
||||
gtk_dialog_run (GTK_DIALOG (dialog));
|
||||
@ -31,7 +31,7 @@ message_dialog_clicked (GtkButton *button,
|
||||
|
||||
static void
|
||||
interactive_dialog_clicked (GtkButton *button,
|
||||
gpointer user_data)
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkWidget *content_area;
|
||||
GtkWidget *dialog;
|
||||
@ -44,13 +44,13 @@ interactive_dialog_clicked (GtkButton *button,
|
||||
gint response;
|
||||
|
||||
dialog = gtk_dialog_new_with_buttons ("Interactive Dialog",
|
||||
GTK_WINDOW (window),
|
||||
GTK_DIALOG_MODAL| GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_STOCK_OK,
|
||||
GTK_RESPONSE_OK,
|
||||
GTK_WINDOW (window),
|
||||
GTK_DIALOG_MODAL| GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_STOCK_OK,
|
||||
GTK_RESPONSE_OK,
|
||||
"_Non-stock Button",
|
||||
GTK_RESPONSE_CANCEL,
|
||||
NULL);
|
||||
NULL);
|
||||
|
||||
content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
|
||||
|
||||
@ -102,12 +102,12 @@ do_dialog (GtkWidget *do_widget)
|
||||
GtkWidget *button;
|
||||
GtkWidget *table;
|
||||
GtkWidget *label;
|
||||
|
||||
|
||||
if (!window)
|
||||
{
|
||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_screen (GTK_WINDOW (window),
|
||||
gtk_widget_get_screen (do_widget));
|
||||
gtk_widget_get_screen (do_widget));
|
||||
gtk_window_set_title (GTK_WINDOW (window), "Dialogs");
|
||||
|
||||
g_signal_connect (window, "destroy", G_CALLBACK (gtk_widget_destroyed), &window);
|
||||
@ -125,7 +125,7 @@ do_dialog (GtkWidget *do_widget)
|
||||
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
||||
button = gtk_button_new_with_mnemonic ("_Message Dialog");
|
||||
g_signal_connect (button, "clicked",
|
||||
G_CALLBACK (message_dialog_clicked), NULL);
|
||||
G_CALLBACK (message_dialog_clicked), NULL);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (vbox), gtk_separator_new (GTK_ORIENTATION_HORIZONTAL),
|
||||
@ -138,7 +138,7 @@ do_dialog (GtkWidget *do_widget)
|
||||
|
||||
button = gtk_button_new_with_mnemonic ("_Interactive Dialog");
|
||||
g_signal_connect (button, "clicked",
|
||||
G_CALLBACK (interactive_dialog_clicked), NULL);
|
||||
G_CALLBACK (interactive_dialog_clicked), NULL);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), vbox2, FALSE, FALSE, 0);
|
||||
gtk_box_pack_start (GTK_BOX (vbox2), button, FALSE, FALSE, 0);
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
* GtkCellRenderer::editing-started signal to do custom setup of the
|
||||
* editable widget.
|
||||
*
|
||||
* The cell renderers used in this demo are GtkCellRendererText,
|
||||
* The cell renderers used in this demo are GtkCellRendererText,
|
||||
* GtkCellRendererCombo and GtkCellRendererProgress.
|
||||
*/
|
||||
|
||||
@ -205,7 +205,7 @@ editing_started (GtkCellRenderer *cell,
|
||||
const gchar *path,
|
||||
gpointer data)
|
||||
{
|
||||
gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (editable),
|
||||
gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (editable),
|
||||
separator_row, NULL, NULL);
|
||||
}
|
||||
|
||||
@ -259,7 +259,7 @@ cell_edited (GtkCellRendererText *cell,
|
||||
}
|
||||
|
||||
static void
|
||||
add_columns (GtkTreeView *treeview,
|
||||
add_columns (GtkTreeView *treeview,
|
||||
GtkTreeModel *items_model,
|
||||
GtkTreeModel *numbers_model)
|
||||
{
|
||||
@ -306,8 +306,6 @@ add_columns (GtkTreeView *treeview,
|
||||
-1, "Yummy", renderer,
|
||||
"value", COLUMN_ITEM_YUMMY,
|
||||
NULL);
|
||||
|
||||
|
||||
}
|
||||
|
||||
GtkWidget *
|
||||
|
@ -20,17 +20,17 @@ do_entry_buffer (GtkWidget *do_widget)
|
||||
if (!window)
|
||||
{
|
||||
window = gtk_dialog_new_with_buttons ("GtkEntryBuffer",
|
||||
GTK_WINDOW (do_widget),
|
||||
0,
|
||||
GTK_STOCK_CLOSE,
|
||||
GTK_RESPONSE_NONE,
|
||||
NULL);
|
||||
GTK_WINDOW (do_widget),
|
||||
0,
|
||||
GTK_STOCK_CLOSE,
|
||||
GTK_RESPONSE_NONE,
|
||||
NULL);
|
||||
gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
|
||||
|
||||
g_signal_connect (window, "response",
|
||||
G_CALLBACK (gtk_widget_destroy), NULL);
|
||||
G_CALLBACK (gtk_widget_destroy), NULL);
|
||||
g_signal_connect (window, "destroy",
|
||||
G_CALLBACK (gtk_widget_destroyed), &window);
|
||||
G_CALLBACK (gtk_widget_destroyed), &window);
|
||||
|
||||
content_area = gtk_dialog_get_content_area (GTK_DIALOG (window));
|
||||
|
||||
@ -64,5 +64,3 @@ do_entry_buffer (GtkWidget *do_widget)
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
|
||||
|
@ -15,7 +15,7 @@ create_completion_model (void)
|
||||
{
|
||||
GtkListStore *store;
|
||||
GtkTreeIter iter;
|
||||
|
||||
|
||||
store = gtk_list_store_new (1, G_TYPE_STRING);
|
||||
|
||||
/* Append one word */
|
||||
@ -29,7 +29,7 @@ create_completion_model (void)
|
||||
/* And another word */
|
||||
gtk_list_store_append (store, &iter);
|
||||
gtk_list_store_set (store, &iter, 0, "totally", -1);
|
||||
|
||||
|
||||
return GTK_TREE_MODEL (store);
|
||||
}
|
||||
|
||||
@ -43,51 +43,51 @@ do_entry_completion (GtkWidget *do_widget)
|
||||
GtkWidget *entry;
|
||||
GtkEntryCompletion *completion;
|
||||
GtkTreeModel *completion_model;
|
||||
|
||||
|
||||
if (!window)
|
||||
{
|
||||
window = gtk_dialog_new_with_buttons ("GtkEntryCompletion",
|
||||
GTK_WINDOW (do_widget),
|
||||
0,
|
||||
GTK_STOCK_CLOSE,
|
||||
GTK_RESPONSE_NONE,
|
||||
NULL);
|
||||
gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
|
||||
{
|
||||
window = gtk_dialog_new_with_buttons ("GtkEntryCompletion",
|
||||
GTK_WINDOW (do_widget),
|
||||
0,
|
||||
GTK_STOCK_CLOSE,
|
||||
GTK_RESPONSE_NONE,
|
||||
NULL);
|
||||
gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
|
||||
|
||||
g_signal_connect (window, "response",
|
||||
G_CALLBACK (gtk_widget_destroy), NULL);
|
||||
g_signal_connect (window, "destroy",
|
||||
G_CALLBACK (gtk_widget_destroyed), &window);
|
||||
g_signal_connect (window, "response",
|
||||
G_CALLBACK (gtk_widget_destroy), NULL);
|
||||
g_signal_connect (window, "destroy",
|
||||
G_CALLBACK (gtk_widget_destroyed), &window);
|
||||
|
||||
content_area = gtk_dialog_get_content_area (GTK_DIALOG (window));
|
||||
content_area = gtk_dialog_get_content_area (GTK_DIALOG (window));
|
||||
|
||||
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
|
||||
gtk_box_pack_start (GTK_BOX (content_area), vbox, TRUE, TRUE, 0);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
|
||||
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
|
||||
gtk_box_pack_start (GTK_BOX (content_area), vbox, TRUE, TRUE, 0);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
|
||||
|
||||
label = gtk_label_new (NULL);
|
||||
gtk_label_set_markup (GTK_LABEL (label), "Completion demo, try writing <b>total</b> or <b>gnome</b> for example.");
|
||||
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
|
||||
label = gtk_label_new (NULL);
|
||||
gtk_label_set_markup (GTK_LABEL (label), "Completion demo, try writing <b>total</b> or <b>gnome</b> for example.");
|
||||
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
|
||||
|
||||
/* Create our entry */
|
||||
entry = gtk_entry_new ();
|
||||
gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0);
|
||||
/* Create our entry */
|
||||
entry = gtk_entry_new ();
|
||||
gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0);
|
||||
|
||||
/* Create the completion object */
|
||||
completion = gtk_entry_completion_new ();
|
||||
/* Create the completion object */
|
||||
completion = gtk_entry_completion_new ();
|
||||
|
||||
/* Assign the completion to the entry */
|
||||
gtk_entry_set_completion (GTK_ENTRY (entry), completion);
|
||||
g_object_unref (completion);
|
||||
|
||||
/* Create a tree model and use it as the completion model */
|
||||
completion_model = create_completion_model ();
|
||||
gtk_entry_completion_set_model (completion, completion_model);
|
||||
g_object_unref (completion_model);
|
||||
|
||||
/* Use model column 0 as the text column */
|
||||
gtk_entry_completion_set_text_column (completion, 0);
|
||||
}
|
||||
/* Assign the completion to the entry */
|
||||
gtk_entry_set_completion (GTK_ENTRY (entry), completion);
|
||||
g_object_unref (completion);
|
||||
|
||||
/* Create a tree model and use it as the completion model */
|
||||
completion_model = create_completion_model ();
|
||||
gtk_entry_completion_set_model (completion, completion_model);
|
||||
g_object_unref (completion_model);
|
||||
|
||||
/* Use model column 0 as the text column */
|
||||
gtk_entry_completion_set_text_column (completion, 0);
|
||||
}
|
||||
|
||||
if (!gtk_widget_get_visible (window))
|
||||
gtk_widget_show_all (window);
|
||||
@ -96,5 +96,3 @@ do_entry_completion (GtkWidget *do_widget)
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
|
||||
|
@ -17,21 +17,21 @@ do_expander (GtkWidget *do_widget)
|
||||
GtkWidget *vbox;
|
||||
GtkWidget *label;
|
||||
GtkWidget *expander;
|
||||
|
||||
|
||||
if (!window)
|
||||
{
|
||||
window = gtk_dialog_new_with_buttons ("GtkExpander",
|
||||
GTK_WINDOW (do_widget),
|
||||
0,
|
||||
GTK_STOCK_CLOSE,
|
||||
GTK_RESPONSE_NONE,
|
||||
NULL);
|
||||
GTK_WINDOW (do_widget),
|
||||
0,
|
||||
GTK_STOCK_CLOSE,
|
||||
GTK_RESPONSE_NONE,
|
||||
NULL);
|
||||
gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
|
||||
|
||||
g_signal_connect (window, "response",
|
||||
G_CALLBACK (gtk_widget_destroy), NULL);
|
||||
G_CALLBACK (gtk_widget_destroy), NULL);
|
||||
g_signal_connect (window, "destroy",
|
||||
G_CALLBACK (gtk_widget_destroyed), &window);
|
||||
G_CALLBACK (gtk_widget_destroyed), &window);
|
||||
|
||||
content_area = gtk_dialog_get_content_area (GTK_DIALOG (window));
|
||||
|
||||
@ -57,5 +57,3 @@ do_expander (GtkWidget *do_widget)
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
/* Text Widget/Hypertext
|
||||
*
|
||||
* Usually, tags modify the appearance of text in the view, e.g. making it
|
||||
* bold or colored or underlined. But tags are not restricted to appearance.
|
||||
* They can also affect the behavior of mouse and key presses, as this demo
|
||||
* Usually, tags modify the appearance of text in the view, e.g. making it
|
||||
* bold or colored or underlined. But tags are not restricted to appearance.
|
||||
* They can also affect the behavior of mouse and key presses, as this demo
|
||||
* shows.
|
||||
*/
|
||||
|
||||
@ -12,19 +12,19 @@
|
||||
/* Inserts a piece of text into the buffer, giving it the usual
|
||||
* appearance of a hyperlink in a web browser: blue and underlined.
|
||||
* Additionally, attaches some data on the tag, to make it recognizable
|
||||
* as a link.
|
||||
* as a link.
|
||||
*/
|
||||
static void
|
||||
insert_link (GtkTextBuffer *buffer,
|
||||
GtkTextIter *iter,
|
||||
gchar *text,
|
||||
static void
|
||||
insert_link (GtkTextBuffer *buffer,
|
||||
GtkTextIter *iter,
|
||||
gchar *text,
|
||||
gint page)
|
||||
{
|
||||
GtkTextTag *tag;
|
||||
|
||||
tag = gtk_text_buffer_create_tag (buffer, NULL,
|
||||
"foreground", "blue",
|
||||
"underline", PANGO_UNDERLINE_SINGLE,
|
||||
|
||||
tag = gtk_text_buffer_create_tag (buffer, NULL,
|
||||
"foreground", "blue",
|
||||
"underline", PANGO_UNDERLINE_SINGLE,
|
||||
NULL);
|
||||
g_object_set_data (G_OBJECT (tag), "page", GINT_TO_POINTER (page));
|
||||
gtk_text_buffer_insert_with_tags (buffer, iter, text, -1, tag, NULL);
|
||||
@ -34,7 +34,7 @@ insert_link (GtkTextBuffer *buffer,
|
||||
* hypertext app, this method would parse a file to identify the links.
|
||||
*/
|
||||
static void
|
||||
show_page (GtkTextBuffer *buffer,
|
||||
show_page (GtkTextBuffer *buffer,
|
||||
gint page)
|
||||
{
|
||||
GtkTextIter iter;
|
||||
@ -51,7 +51,7 @@ show_page (GtkTextBuffer *buffer,
|
||||
}
|
||||
else if (page == 2)
|
||||
{
|
||||
gtk_text_buffer_insert (buffer, &iter,
|
||||
gtk_text_buffer_insert (buffer, &iter,
|
||||
"A tag is an attribute that can be applied to some range of text. "
|
||||
"For example, a tag might be called \"bold\" and make the text inside "
|
||||
"the tag bold. However, the tag concept is more general than that; "
|
||||
@ -60,27 +60,27 @@ show_page (GtkTextBuffer *buffer,
|
||||
"user can't edit it, or countless other things.\n", -1);
|
||||
insert_link (buffer, &iter, "Go back", 1);
|
||||
}
|
||||
else if (page == 3)
|
||||
else if (page == 3)
|
||||
{
|
||||
GtkTextTag *tag;
|
||||
|
||||
tag = gtk_text_buffer_create_tag (buffer, NULL,
|
||||
"weight", PANGO_WEIGHT_BOLD,
|
||||
|
||||
tag = gtk_text_buffer_create_tag (buffer, NULL,
|
||||
"weight", PANGO_WEIGHT_BOLD,
|
||||
NULL);
|
||||
gtk_text_buffer_insert_with_tags (buffer, &iter, "hypertext:\n", -1, tag, NULL);
|
||||
gtk_text_buffer_insert (buffer, &iter,
|
||||
gtk_text_buffer_insert (buffer, &iter,
|
||||
"machine-readable text that is not sequential but is organized "
|
||||
"so that related items of information are connected.\n", -1);
|
||||
insert_link (buffer, &iter, "Go back", 1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Looks at all tags covering the position of iter in the text view,
|
||||
/* Looks at all tags covering the position of iter in the text view,
|
||||
* and if one of them is a link, follow it by showing the page identified
|
||||
* by the data attached to it.
|
||||
*/
|
||||
static void
|
||||
follow_if_link (GtkWidget *text_view,
|
||||
follow_if_link (GtkWidget *text_view,
|
||||
GtkTextIter *iter)
|
||||
{
|
||||
GSList *tags = NULL, *tagp = NULL;
|
||||
@ -98,7 +98,7 @@ follow_if_link (GtkWidget *text_view,
|
||||
}
|
||||
}
|
||||
|
||||
if (tags)
|
||||
if (tags)
|
||||
g_slist_free (tags);
|
||||
}
|
||||
|
||||
@ -113,10 +113,10 @@ key_press_event (GtkWidget *text_view,
|
||||
|
||||
switch (event->keyval)
|
||||
{
|
||||
case GDK_KEY_Return:
|
||||
case GDK_KEY_Return:
|
||||
case GDK_KEY_KP_Enter:
|
||||
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
|
||||
gtk_text_buffer_get_iter_at_mark (buffer, &iter,
|
||||
gtk_text_buffer_get_iter_at_mark (buffer, &iter,
|
||||
gtk_text_buffer_get_insert (buffer));
|
||||
follow_if_link (text_view, &iter);
|
||||
break;
|
||||
@ -154,7 +154,7 @@ event_after (GtkWidget *text_view,
|
||||
if (gtk_text_iter_get_offset (&start) != gtk_text_iter_get_offset (&end))
|
||||
return FALSE;
|
||||
|
||||
gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
|
||||
gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
|
||||
GTK_TEXT_WINDOW_WIDGET,
|
||||
event->x, event->y, &x, &y);
|
||||
|
||||
@ -169,7 +169,7 @@ static gboolean hovering_over_link = FALSE;
|
||||
static GdkCursor *hand_cursor = NULL;
|
||||
static GdkCursor *regular_cursor = NULL;
|
||||
|
||||
/* Looks at all tags covering the position (x, y) in the text view,
|
||||
/* Looks at all tags covering the position (x, y) in the text view,
|
||||
* and if one of them is a link, change the cursor to the "hands" cursor
|
||||
* typically used by web browsers.
|
||||
*/
|
||||
@ -183,14 +183,14 @@ set_cursor_if_appropriate (GtkTextView *text_view,
|
||||
gboolean hovering = FALSE;
|
||||
|
||||
gtk_text_view_get_iter_at_location (text_view, &iter, x, y);
|
||||
|
||||
|
||||
tags = gtk_text_iter_get_tags (&iter);
|
||||
for (tagp = tags; tagp != NULL; tagp = tagp->next)
|
||||
{
|
||||
GtkTextTag *tag = tagp->data;
|
||||
gint page = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tag), "page"));
|
||||
|
||||
if (page != 0)
|
||||
if (page != 0)
|
||||
{
|
||||
hovering = TRUE;
|
||||
break;
|
||||
@ -207,11 +207,11 @@ set_cursor_if_appropriate (GtkTextView *text_view,
|
||||
gdk_window_set_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), regular_cursor);
|
||||
}
|
||||
|
||||
if (tags)
|
||||
if (tags)
|
||||
g_slist_free (tags);
|
||||
}
|
||||
|
||||
/* Update the cursor image if the pointer moved.
|
||||
/* Update the cursor image if the pointer moved.
|
||||
*/
|
||||
static gboolean
|
||||
motion_notify_event (GtkWidget *text_view,
|
||||
@ -219,7 +219,7 @@ motion_notify_event (GtkWidget *text_view,
|
||||
{
|
||||
gint x, y;
|
||||
|
||||
gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
|
||||
gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
|
||||
GTK_TEXT_WINDOW_WIDGET,
|
||||
event->x, event->y, &x, &y);
|
||||
|
||||
@ -242,7 +242,7 @@ visibility_notify_event (GtkWidget *text_view,
|
||||
gdk_window_get_pointer (gtk_widget_get_window (text_view),
|
||||
&wx, &wy, NULL);
|
||||
|
||||
gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
|
||||
gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
|
||||
GTK_TEXT_WINDOW_WIDGET,
|
||||
wx, wy, &bx, &by);
|
||||
|
||||
@ -264,13 +264,13 @@ do_hypertext (GtkWidget *do_widget)
|
||||
|
||||
hand_cursor = gdk_cursor_new (GDK_HAND2);
|
||||
regular_cursor = gdk_cursor_new (GDK_XTERM);
|
||||
|
||||
|
||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_screen (GTK_WINDOW (window),
|
||||
gtk_widget_get_screen (do_widget));
|
||||
gtk_window_set_default_size (GTK_WINDOW (window),
|
||||
450, 450);
|
||||
|
||||
|
||||
g_signal_connect (window, "destroy",
|
||||
G_CALLBACK (gtk_widget_destroyed), &window);
|
||||
|
||||
@ -279,17 +279,17 @@ do_hypertext (GtkWidget *do_widget)
|
||||
|
||||
view = gtk_text_view_new ();
|
||||
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), GTK_WRAP_WORD);
|
||||
g_signal_connect (view, "key-press-event",
|
||||
g_signal_connect (view, "key-press-event",
|
||||
G_CALLBACK (key_press_event), NULL);
|
||||
g_signal_connect (view, "event-after",
|
||||
g_signal_connect (view, "event-after",
|
||||
G_CALLBACK (event_after), NULL);
|
||||
g_signal_connect (view, "motion-notify-event",
|
||||
g_signal_connect (view, "motion-notify-event",
|
||||
G_CALLBACK (motion_notify_event), NULL);
|
||||
g_signal_connect (view, "visibility-notify-event",
|
||||
g_signal_connect (view, "visibility-notify-event",
|
||||
G_CALLBACK (visibility_notify_event), NULL);
|
||||
|
||||
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
|
||||
|
||||
|
||||
sw = gtk_scrolled_window_new (NULL, NULL);
|
||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
|
||||
GTK_POLICY_AUTOMATIC,
|
||||
@ -314,4 +314,3 @@ do_hypertext (GtkWidget *do_widget)
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
|
@ -85,23 +85,23 @@ fill_store (GtkListStore *store)
|
||||
|
||||
/* We ignore hidden files that start with a '.' */
|
||||
if (name[0] != '.')
|
||||
{
|
||||
path = g_build_filename (parent, name, NULL);
|
||||
{
|
||||
path = g_build_filename (parent, name, NULL);
|
||||
|
||||
is_dir = g_file_test (path, G_FILE_TEST_IS_DIR);
|
||||
is_dir = g_file_test (path, G_FILE_TEST_IS_DIR);
|
||||
|
||||
display_name = g_filename_to_utf8 (name, -1, NULL, NULL, NULL);
|
||||
display_name = g_filename_to_utf8 (name, -1, NULL, NULL, NULL);
|
||||
|
||||
gtk_list_store_append (store, &iter);
|
||||
gtk_list_store_set (store, &iter,
|
||||
COL_PATH, path,
|
||||
COL_DISPLAY_NAME, display_name,
|
||||
COL_IS_DIRECTORY, is_dir,
|
||||
COL_PIXBUF, is_dir ? folder_pixbuf : file_pixbuf,
|
||||
-1);
|
||||
g_free (path);
|
||||
g_free (display_name);
|
||||
}
|
||||
gtk_list_store_append (store, &iter);
|
||||
gtk_list_store_set (store, &iter,
|
||||
COL_PATH, path,
|
||||
COL_DISPLAY_NAME, display_name,
|
||||
COL_IS_DIRECTORY, is_dir,
|
||||
COL_PIXBUF, is_dir ? folder_pixbuf : file_pixbuf,
|
||||
-1);
|
||||
g_free (path);
|
||||
g_free (display_name);
|
||||
}
|
||||
|
||||
name = g_dir_read_name (dir);
|
||||
}
|
||||
@ -110,9 +110,9 @@ fill_store (GtkListStore *store)
|
||||
|
||||
static gint
|
||||
sort_func (GtkTreeModel *model,
|
||||
GtkTreeIter *a,
|
||||
GtkTreeIter *b,
|
||||
gpointer user_data)
|
||||
GtkTreeIter *a,
|
||||
GtkTreeIter *b,
|
||||
gpointer user_data)
|
||||
{
|
||||
gboolean is_dir_a, is_dir_b;
|
||||
gchar *name_a, *name_b;
|
||||
@ -124,14 +124,14 @@ sort_func (GtkTreeModel *model,
|
||||
|
||||
|
||||
gtk_tree_model_get (model, a,
|
||||
COL_IS_DIRECTORY, &is_dir_a,
|
||||
COL_DISPLAY_NAME, &name_a,
|
||||
-1);
|
||||
COL_IS_DIRECTORY, &is_dir_a,
|
||||
COL_DISPLAY_NAME, &name_a,
|
||||
-1);
|
||||
|
||||
gtk_tree_model_get (model, b,
|
||||
COL_IS_DIRECTORY, &is_dir_b,
|
||||
COL_DISPLAY_NAME, &name_b,
|
||||
-1);
|
||||
COL_IS_DIRECTORY, &is_dir_b,
|
||||
COL_DISPLAY_NAME, &name_b,
|
||||
-1);
|
||||
|
||||
if (!is_dir_a && is_dir_b)
|
||||
ret = 1;
|
||||
@ -154,26 +154,26 @@ create_store (void)
|
||||
GtkListStore *store;
|
||||
|
||||
store = gtk_list_store_new (NUM_COLS,
|
||||
G_TYPE_STRING,
|
||||
G_TYPE_STRING,
|
||||
GDK_TYPE_PIXBUF,
|
||||
G_TYPE_BOOLEAN);
|
||||
G_TYPE_STRING,
|
||||
G_TYPE_STRING,
|
||||
GDK_TYPE_PIXBUF,
|
||||
G_TYPE_BOOLEAN);
|
||||
|
||||
/* Set sort column and function */
|
||||
gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (store),
|
||||
sort_func,
|
||||
NULL, NULL);
|
||||
sort_func,
|
||||
NULL, NULL);
|
||||
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
|
||||
GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID,
|
||||
GTK_SORT_ASCENDING);
|
||||
GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID,
|
||||
GTK_SORT_ASCENDING);
|
||||
|
||||
return store;
|
||||
}
|
||||
|
||||
static void
|
||||
item_activated (GtkIconView *icon_view,
|
||||
GtkTreePath *tree_path,
|
||||
gpointer user_data)
|
||||
GtkTreePath *tree_path,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkListStore *store;
|
||||
gchar *path;
|
||||
@ -183,11 +183,11 @@ item_activated (GtkIconView *icon_view,
|
||||
store = GTK_LIST_STORE (user_data);
|
||||
|
||||
gtk_tree_model_get_iter (GTK_TREE_MODEL (store),
|
||||
&iter, tree_path);
|
||||
&iter, tree_path);
|
||||
gtk_tree_model_get (GTK_TREE_MODEL (store), &iter,
|
||||
COL_PATH, &path,
|
||||
COL_IS_DIRECTORY, &is_dir,
|
||||
-1);
|
||||
COL_PATH, &path,
|
||||
COL_IS_DIRECTORY, &is_dir,
|
||||
-1);
|
||||
|
||||
if (!is_dir)
|
||||
{
|
||||
@ -207,7 +207,7 @@ item_activated (GtkIconView *icon_view,
|
||||
|
||||
static void
|
||||
up_clicked (GtkToolItem *item,
|
||||
gpointer user_data)
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkListStore *store;
|
||||
gchar *dir_name;
|
||||
@ -223,12 +223,12 @@ up_clicked (GtkToolItem *item,
|
||||
|
||||
/* Maybe de-sensitize the up button */
|
||||
gtk_widget_set_sensitive (GTK_WIDGET (up_button),
|
||||
strcmp (parent, "/") != 0);
|
||||
strcmp (parent, "/") != 0);
|
||||
}
|
||||
|
||||
static void
|
||||
home_clicked (GtkToolItem *item,
|
||||
gpointer user_data)
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkListStore *store;
|
||||
|
||||
@ -241,7 +241,7 @@ home_clicked (GtkToolItem *item,
|
||||
|
||||
/* Sensitize the up button */
|
||||
gtk_widget_set_sensitive (GTK_WIDGET (up_button),
|
||||
TRUE);
|
||||
TRUE);
|
||||
}
|
||||
|
||||
static void close_window(void)
|
||||
@ -267,96 +267,96 @@ do_iconview (GtkWidget *do_widget)
|
||||
gtk_window_set_default_size (GTK_WINDOW (window), 650, 400);
|
||||
|
||||
gtk_window_set_screen (GTK_WINDOW (window),
|
||||
gtk_widget_get_screen (do_widget));
|
||||
gtk_widget_get_screen (do_widget));
|
||||
gtk_window_set_title (GTK_WINDOW (window), "GtkIconView demo");
|
||||
|
||||
g_signal_connect (window, "destroy",
|
||||
G_CALLBACK (close_window), NULL);
|
||||
G_CALLBACK (close_window), NULL);
|
||||
|
||||
error = NULL;
|
||||
if (!load_pixbufs (&error))
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
|
||||
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
|
||||
GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_MESSAGE_ERROR,
|
||||
GTK_BUTTONS_CLOSE,
|
||||
"Failed to load an image: %s",
|
||||
error->message);
|
||||
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
|
||||
GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_MESSAGE_ERROR,
|
||||
GTK_BUTTONS_CLOSE,
|
||||
"Failed to load an image: %s",
|
||||
error->message);
|
||||
|
||||
g_error_free (error);
|
||||
g_error_free (error);
|
||||
|
||||
g_signal_connect (dialog, "response",
|
||||
G_CALLBACK (gtk_widget_destroy), NULL);
|
||||
g_signal_connect (dialog, "response",
|
||||
G_CALLBACK (gtk_widget_destroy), NULL);
|
||||
|
||||
gtk_widget_show (dialog);
|
||||
}
|
||||
gtk_widget_show (dialog);
|
||||
}
|
||||
else
|
||||
{
|
||||
GtkWidget *sw;
|
||||
GtkWidget *icon_view;
|
||||
GtkListStore *store;
|
||||
GtkWidget *vbox;
|
||||
GtkWidget *tool_bar;
|
||||
GtkToolItem *home_button;
|
||||
{
|
||||
GtkWidget *sw;
|
||||
GtkWidget *icon_view;
|
||||
GtkListStore *store;
|
||||
GtkWidget *vbox;
|
||||
GtkWidget *tool_bar;
|
||||
GtkToolItem *home_button;
|
||||
|
||||
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
||||
gtk_container_add (GTK_CONTAINER (window), vbox);
|
||||
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
||||
gtk_container_add (GTK_CONTAINER (window), vbox);
|
||||
|
||||
tool_bar = gtk_toolbar_new ();
|
||||
gtk_box_pack_start (GTK_BOX (vbox), tool_bar, FALSE, FALSE, 0);
|
||||
tool_bar = gtk_toolbar_new ();
|
||||
gtk_box_pack_start (GTK_BOX (vbox), tool_bar, FALSE, FALSE, 0);
|
||||
|
||||
up_button = gtk_tool_button_new_from_stock (GTK_STOCK_GO_UP);
|
||||
gtk_tool_item_set_is_important (up_button, TRUE);
|
||||
gtk_widget_set_sensitive (GTK_WIDGET (up_button), FALSE);
|
||||
gtk_toolbar_insert (GTK_TOOLBAR (tool_bar), up_button, -1);
|
||||
up_button = gtk_tool_button_new_from_stock (GTK_STOCK_GO_UP);
|
||||
gtk_tool_item_set_is_important (up_button, TRUE);
|
||||
gtk_widget_set_sensitive (GTK_WIDGET (up_button), FALSE);
|
||||
gtk_toolbar_insert (GTK_TOOLBAR (tool_bar), up_button, -1);
|
||||
|
||||
home_button = gtk_tool_button_new_from_stock (GTK_STOCK_HOME);
|
||||
gtk_tool_item_set_is_important (home_button, TRUE);
|
||||
gtk_toolbar_insert (GTK_TOOLBAR (tool_bar), home_button, -1);
|
||||
home_button = gtk_tool_button_new_from_stock (GTK_STOCK_HOME);
|
||||
gtk_tool_item_set_is_important (home_button, TRUE);
|
||||
gtk_toolbar_insert (GTK_TOOLBAR (tool_bar), home_button, -1);
|
||||
|
||||
|
||||
sw = gtk_scrolled_window_new (NULL, NULL);
|
||||
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
|
||||
GTK_SHADOW_ETCHED_IN);
|
||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
|
||||
GTK_POLICY_AUTOMATIC,
|
||||
GTK_POLICY_AUTOMATIC);
|
||||
sw = gtk_scrolled_window_new (NULL, NULL);
|
||||
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
|
||||
GTK_SHADOW_ETCHED_IN);
|
||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
|
||||
GTK_POLICY_AUTOMATIC,
|
||||
GTK_POLICY_AUTOMATIC);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0);
|
||||
|
||||
/* Create the store and fill it with the contents of '/' */
|
||||
parent = g_strdup ("/");
|
||||
store = create_store ();
|
||||
fill_store (store);
|
||||
/* Create the store and fill it with the contents of '/' */
|
||||
parent = g_strdup ("/");
|
||||
store = create_store ();
|
||||
fill_store (store);
|
||||
|
||||
icon_view = gtk_icon_view_new_with_model (GTK_TREE_MODEL (store));
|
||||
gtk_icon_view_set_selection_mode (GTK_ICON_VIEW (icon_view),
|
||||
GTK_SELECTION_MULTIPLE);
|
||||
g_object_unref (store);
|
||||
icon_view = gtk_icon_view_new_with_model (GTK_TREE_MODEL (store));
|
||||
gtk_icon_view_set_selection_mode (GTK_ICON_VIEW (icon_view),
|
||||
GTK_SELECTION_MULTIPLE);
|
||||
g_object_unref (store);
|
||||
|
||||
/* Connect to the "clicked" signal of the "Up" tool button */
|
||||
g_signal_connect (up_button, "clicked",
|
||||
G_CALLBACK (up_clicked), store);
|
||||
/* Connect to the "clicked" signal of the "Up" tool button */
|
||||
g_signal_connect (up_button, "clicked",
|
||||
G_CALLBACK (up_clicked), store);
|
||||
|
||||
/* Connect to the "clicked" signal of the "Home" tool button */
|
||||
g_signal_connect (home_button, "clicked",
|
||||
G_CALLBACK (home_clicked), store);
|
||||
/* Connect to the "clicked" signal of the "Home" tool button */
|
||||
g_signal_connect (home_button, "clicked",
|
||||
G_CALLBACK (home_clicked), store);
|
||||
|
||||
/* We now set which model columns that correspond to the text
|
||||
* and pixbuf of each item
|
||||
*/
|
||||
gtk_icon_view_set_text_column (GTK_ICON_VIEW (icon_view), COL_DISPLAY_NAME);
|
||||
gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW (icon_view), COL_PIXBUF);
|
||||
/* We now set which model columns that correspond to the text
|
||||
* and pixbuf of each item
|
||||
*/
|
||||
gtk_icon_view_set_text_column (GTK_ICON_VIEW (icon_view), COL_DISPLAY_NAME);
|
||||
gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW (icon_view), COL_PIXBUF);
|
||||
|
||||
/* Connect to the "item-activated" signal */
|
||||
g_signal_connect (icon_view, "item-activated",
|
||||
G_CALLBACK (item_activated), store);
|
||||
gtk_container_add (GTK_CONTAINER (sw), icon_view);
|
||||
/* Connect to the "item-activated" signal */
|
||||
g_signal_connect (icon_view, "item-activated",
|
||||
G_CALLBACK (item_activated), store);
|
||||
gtk_container_add (GTK_CONTAINER (sw), icon_view);
|
||||
|
||||
gtk_widget_grab_focus (icon_view);
|
||||
}
|
||||
gtk_widget_grab_focus (icon_view);
|
||||
}
|
||||
}
|
||||
|
||||
if (!gtk_widget_get_visible (window))
|
||||
@ -369,4 +369,3 @@ do_iconview (GtkWidget *do_widget)
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
|
@ -47,10 +47,10 @@ create_store (void)
|
||||
|
||||
static void
|
||||
set_cell_color (GtkCellLayout *cell_layout,
|
||||
GtkCellRenderer *cell,
|
||||
GtkTreeModel *tree_model,
|
||||
GtkTreeIter *iter,
|
||||
gpointer data)
|
||||
GtkCellRenderer *cell,
|
||||
GtkTreeModel *tree_model,
|
||||
GtkTreeIter *iter,
|
||||
gpointer data)
|
||||
{
|
||||
gchar *text;
|
||||
GdkColor color;
|
||||
@ -76,9 +76,9 @@ set_cell_color (GtkCellLayout *cell_layout,
|
||||
|
||||
static void
|
||||
edited (GtkCellRendererText *cell,
|
||||
gchar *path_string,
|
||||
gchar *text,
|
||||
gpointer data)
|
||||
gchar *path_string,
|
||||
gchar *text,
|
||||
gpointer data)
|
||||
{
|
||||
GtkTreeModel *model;
|
||||
GtkTreeIter iter;
|
||||
@ -89,7 +89,7 @@ edited (GtkCellRendererText *cell,
|
||||
|
||||
gtk_tree_model_get_iter (model, &iter, path);
|
||||
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
|
||||
COL_TEXT, text, -1);
|
||||
COL_TEXT, text, -1);
|
||||
|
||||
gtk_tree_path_free (path);
|
||||
}
|
||||
@ -106,11 +106,11 @@ do_iconview_edit (GtkWidget *do_widget)
|
||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
|
||||
gtk_window_set_screen (GTK_WINDOW (window),
|
||||
gtk_widget_get_screen (do_widget));
|
||||
gtk_widget_get_screen (do_widget));
|
||||
gtk_window_set_title (GTK_WINDOW (window), "Editing and Drag-and-Drop");
|
||||
|
||||
g_signal_connect (window, "destroy",
|
||||
G_CALLBACK (gtk_widget_destroyed), &window);
|
||||
G_CALLBACK (gtk_widget_destroyed), &window);
|
||||
|
||||
store = create_store ();
|
||||
fill_store (store);
|
||||
@ -119,29 +119,29 @@ do_iconview_edit (GtkWidget *do_widget)
|
||||
g_object_unref (store);
|
||||
|
||||
gtk_icon_view_set_selection_mode (GTK_ICON_VIEW (icon_view),
|
||||
GTK_SELECTION_SINGLE);
|
||||
GTK_SELECTION_SINGLE);
|
||||
gtk_icon_view_set_item_orientation (GTK_ICON_VIEW (icon_view),
|
||||
GTK_ORIENTATION_HORIZONTAL);
|
||||
GTK_ORIENTATION_HORIZONTAL);
|
||||
gtk_icon_view_set_columns (GTK_ICON_VIEW (icon_view), 2);
|
||||
gtk_icon_view_set_reorderable (GTK_ICON_VIEW (icon_view), TRUE);
|
||||
|
||||
renderer = gtk_cell_renderer_pixbuf_new ();
|
||||
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view),
|
||||
renderer, TRUE);
|
||||
renderer, TRUE);
|
||||
gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (icon_view),
|
||||
renderer,
|
||||
set_cell_color,
|
||||
NULL, NULL);
|
||||
renderer,
|
||||
set_cell_color,
|
||||
NULL, NULL);
|
||||
|
||||
renderer = gtk_cell_renderer_text_new ();
|
||||
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view),
|
||||
renderer, TRUE);
|
||||
renderer, TRUE);
|
||||
g_object_set (renderer, "editable", TRUE, NULL);
|
||||
g_signal_connect (renderer, "edited", G_CALLBACK (edited), icon_view);
|
||||
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
|
||||
renderer,
|
||||
"text", COL_TEXT,
|
||||
NULL);
|
||||
renderer,
|
||||
"text", COL_TEXT,
|
||||
NULL);
|
||||
|
||||
gtk_container_add (GTK_CONTAINER (window), icon_view);
|
||||
}
|
||||
@ -156,4 +156,3 @@ do_iconview_edit (GtkWidget *do_widget)
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ static FILE* image_stream = NULL;
|
||||
|
||||
static void
|
||||
progressive_prepared_callback (GdkPixbufLoader *loader,
|
||||
gpointer data)
|
||||
gpointer data)
|
||||
{
|
||||
GdkPixbuf *pixbuf;
|
||||
GtkWidget *image;
|
||||
@ -44,11 +44,11 @@ progressive_prepared_callback (GdkPixbufLoader *loader,
|
||||
|
||||
static void
|
||||
progressive_updated_callback (GdkPixbufLoader *loader,
|
||||
gint x,
|
||||
gint y,
|
||||
gint width,
|
||||
gint height,
|
||||
gpointer data)
|
||||
gint x,
|
||||
gint y,
|
||||
gint width,
|
||||
gint height,
|
||||
gpointer data)
|
||||
{
|
||||
GtkWidget *image;
|
||||
|
||||
@ -86,97 +86,97 @@ progressive_timeout (gpointer data)
|
||||
bytes_read = fread (buf, 1, 256, image_stream);
|
||||
|
||||
if (ferror (image_stream))
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
|
||||
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
|
||||
GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_MESSAGE_ERROR,
|
||||
GTK_BUTTONS_CLOSE,
|
||||
"Failure reading image file 'alphatest.png': %s",
|
||||
g_strerror (errno));
|
||||
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
|
||||
GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_MESSAGE_ERROR,
|
||||
GTK_BUTTONS_CLOSE,
|
||||
"Failure reading image file 'alphatest.png': %s",
|
||||
g_strerror (errno));
|
||||
|
||||
g_signal_connect (dialog, "response",
|
||||
G_CALLBACK (gtk_widget_destroy), NULL);
|
||||
g_signal_connect (dialog, "response",
|
||||
G_CALLBACK (gtk_widget_destroy), NULL);
|
||||
|
||||
fclose (image_stream);
|
||||
image_stream = NULL;
|
||||
fclose (image_stream);
|
||||
image_stream = NULL;
|
||||
|
||||
gtk_widget_show (dialog);
|
||||
gtk_widget_show (dialog);
|
||||
|
||||
load_timeout = 0;
|
||||
load_timeout = 0;
|
||||
|
||||
return FALSE; /* uninstall the timeout */
|
||||
}
|
||||
return FALSE; /* uninstall the timeout */
|
||||
}
|
||||
|
||||
if (!gdk_pixbuf_loader_write (pixbuf_loader,
|
||||
buf, bytes_read,
|
||||
&error))
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
buf, bytes_read,
|
||||
&error))
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
|
||||
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
|
||||
GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_MESSAGE_ERROR,
|
||||
GTK_BUTTONS_CLOSE,
|
||||
"Failed to load image: %s",
|
||||
error->message);
|
||||
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
|
||||
GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_MESSAGE_ERROR,
|
||||
GTK_BUTTONS_CLOSE,
|
||||
"Failed to load image: %s",
|
||||
error->message);
|
||||
|
||||
g_error_free (error);
|
||||
g_error_free (error);
|
||||
|
||||
g_signal_connect (dialog, "response",
|
||||
G_CALLBACK (gtk_widget_destroy), NULL);
|
||||
g_signal_connect (dialog, "response",
|
||||
G_CALLBACK (gtk_widget_destroy), NULL);
|
||||
|
||||
fclose (image_stream);
|
||||
image_stream = NULL;
|
||||
fclose (image_stream);
|
||||
image_stream = NULL;
|
||||
|
||||
gtk_widget_show (dialog);
|
||||
gtk_widget_show (dialog);
|
||||
|
||||
load_timeout = 0;
|
||||
load_timeout = 0;
|
||||
|
||||
return FALSE; /* uninstall the timeout */
|
||||
}
|
||||
return FALSE; /* uninstall the timeout */
|
||||
}
|
||||
|
||||
if (feof (image_stream))
|
||||
{
|
||||
fclose (image_stream);
|
||||
image_stream = NULL;
|
||||
{
|
||||
fclose (image_stream);
|
||||
image_stream = NULL;
|
||||
|
||||
/* Errors can happen on close, e.g. if the image
|
||||
* file was truncated we'll know on close that
|
||||
* it was incomplete.
|
||||
*/
|
||||
error = NULL;
|
||||
if (!gdk_pixbuf_loader_close (pixbuf_loader,
|
||||
&error))
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
/* Errors can happen on close, e.g. if the image
|
||||
* file was truncated we'll know on close that
|
||||
* it was incomplete.
|
||||
*/
|
||||
error = NULL;
|
||||
if (!gdk_pixbuf_loader_close (pixbuf_loader,
|
||||
&error))
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
|
||||
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
|
||||
GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_MESSAGE_ERROR,
|
||||
GTK_BUTTONS_CLOSE,
|
||||
"Failed to load image: %s",
|
||||
error->message);
|
||||
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
|
||||
GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_MESSAGE_ERROR,
|
||||
GTK_BUTTONS_CLOSE,
|
||||
"Failed to load image: %s",
|
||||
error->message);
|
||||
|
||||
g_error_free (error);
|
||||
g_error_free (error);
|
||||
|
||||
g_signal_connect (dialog, "response",
|
||||
G_CALLBACK (gtk_widget_destroy), NULL);
|
||||
g_signal_connect (dialog, "response",
|
||||
G_CALLBACK (gtk_widget_destroy), NULL);
|
||||
|
||||
gtk_widget_show (dialog);
|
||||
gtk_widget_show (dialog);
|
||||
|
||||
g_object_unref (pixbuf_loader);
|
||||
pixbuf_loader = NULL;
|
||||
g_object_unref (pixbuf_loader);
|
||||
pixbuf_loader = NULL;
|
||||
|
||||
load_timeout = 0;
|
||||
load_timeout = 0;
|
||||
|
||||
return FALSE; /* uninstall the timeout */
|
||||
}
|
||||
return FALSE; /* uninstall the timeout */
|
||||
}
|
||||
|
||||
g_object_unref (pixbuf_loader);
|
||||
pixbuf_loader = NULL;
|
||||
}
|
||||
g_object_unref (pixbuf_loader);
|
||||
pixbuf_loader = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -190,55 +190,55 @@ progressive_timeout (gpointer data)
|
||||
*/
|
||||
filename = demo_find_file ("alphatest.png", &error);
|
||||
if (error)
|
||||
{
|
||||
error_message = g_strdup (error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
{
|
||||
error_message = g_strdup (error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
else
|
||||
{
|
||||
image_stream = g_fopen (filename, "rb");
|
||||
g_free (filename);
|
||||
{
|
||||
image_stream = g_fopen (filename, "rb");
|
||||
g_free (filename);
|
||||
|
||||
if (!image_stream)
|
||||
error_message = g_strdup_printf ("Unable to open image file 'alphatest.png': %s",
|
||||
g_strerror (errno));
|
||||
}
|
||||
if (!image_stream)
|
||||
error_message = g_strdup_printf ("Unable to open image file 'alphatest.png': %s",
|
||||
g_strerror (errno));
|
||||
}
|
||||
|
||||
if (image_stream == NULL)
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
|
||||
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
|
||||
GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_MESSAGE_ERROR,
|
||||
GTK_BUTTONS_CLOSE,
|
||||
"%s", error_message);
|
||||
g_free (error_message);
|
||||
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
|
||||
GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_MESSAGE_ERROR,
|
||||
GTK_BUTTONS_CLOSE,
|
||||
"%s", error_message);
|
||||
g_free (error_message);
|
||||
|
||||
g_signal_connect (dialog, "response",
|
||||
G_CALLBACK (gtk_widget_destroy), NULL);
|
||||
g_signal_connect (dialog, "response",
|
||||
G_CALLBACK (gtk_widget_destroy), NULL);
|
||||
|
||||
gtk_widget_show (dialog);
|
||||
gtk_widget_show (dialog);
|
||||
|
||||
load_timeout = 0;
|
||||
load_timeout = 0;
|
||||
|
||||
return FALSE; /* uninstall the timeout */
|
||||
}
|
||||
return FALSE; /* uninstall the timeout */
|
||||
}
|
||||
|
||||
if (pixbuf_loader)
|
||||
{
|
||||
gdk_pixbuf_loader_close (pixbuf_loader, NULL);
|
||||
g_object_unref (pixbuf_loader);
|
||||
pixbuf_loader = NULL;
|
||||
}
|
||||
{
|
||||
gdk_pixbuf_loader_close (pixbuf_loader, NULL);
|
||||
g_object_unref (pixbuf_loader);
|
||||
pixbuf_loader = NULL;
|
||||
}
|
||||
|
||||
pixbuf_loader = gdk_pixbuf_loader_new ();
|
||||
|
||||
g_signal_connect (pixbuf_loader, "area-prepared",
|
||||
G_CALLBACK (progressive_prepared_callback), image);
|
||||
G_CALLBACK (progressive_prepared_callback), image);
|
||||
|
||||
g_signal_connect (pixbuf_loader, "area-updated",
|
||||
G_CALLBACK (progressive_updated_callback), image);
|
||||
G_CALLBACK (progressive_updated_callback), image);
|
||||
}
|
||||
|
||||
/* leave timeout installed */
|
||||
@ -256,13 +256,13 @@ start_progressive_loading (GtkWidget *image)
|
||||
* pauses in the reading process.
|
||||
*/
|
||||
load_timeout = gdk_threads_add_timeout (150,
|
||||
progressive_timeout,
|
||||
image);
|
||||
progressive_timeout,
|
||||
image);
|
||||
}
|
||||
|
||||
static void
|
||||
cleanup_callback (GObject *object,
|
||||
gpointer data)
|
||||
gpointer data)
|
||||
{
|
||||
if (load_timeout)
|
||||
{
|
||||
@ -324,13 +324,13 @@ do_images (GtkWidget *do_widget)
|
||||
{
|
||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_screen (GTK_WINDOW (window),
|
||||
gtk_widget_get_screen (do_widget));
|
||||
gtk_widget_get_screen (do_widget));
|
||||
gtk_window_set_title (GTK_WINDOW (window), "Images");
|
||||
|
||||
g_signal_connect (window, "destroy",
|
||||
G_CALLBACK (gtk_widget_destroyed), &window);
|
||||
G_CALLBACK (gtk_widget_destroyed), &window);
|
||||
g_signal_connect (window, "destroy",
|
||||
G_CALLBACK (cleanup_callback), NULL);
|
||||
G_CALLBACK (cleanup_callback), NULL);
|
||||
|
||||
gtk_container_set_border_width (GTK_CONTAINER (window), 8);
|
||||
|
||||
@ -340,7 +340,7 @@ do_images (GtkWidget *do_widget)
|
||||
|
||||
label = gtk_label_new (NULL);
|
||||
gtk_label_set_markup (GTK_LABEL (label),
|
||||
"<u>Image loaded from a file</u>");
|
||||
"<u>Image loaded from a file</u>");
|
||||
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
|
||||
|
||||
frame = gtk_frame_new (NULL);
|
||||
@ -356,34 +356,34 @@ do_images (GtkWidget *do_widget)
|
||||
pixbuf = NULL;
|
||||
filename = demo_find_file ("gtk-logo-rgb.gif", &error);
|
||||
if (filename)
|
||||
{
|
||||
pixbuf = gdk_pixbuf_new_from_file (filename, &error);
|
||||
g_free (filename);
|
||||
}
|
||||
{
|
||||
pixbuf = gdk_pixbuf_new_from_file (filename, &error);
|
||||
g_free (filename);
|
||||
}
|
||||
|
||||
if (error)
|
||||
{
|
||||
/* This code shows off error handling. You can just use
|
||||
* gtk_image_new_from_file() instead if you don't want to report
|
||||
* errors to the user. If the file doesn't load when using
|
||||
* gtk_image_new_from_file(), a "missing image" icon will
|
||||
* be displayed instead.
|
||||
*/
|
||||
GtkWidget *dialog;
|
||||
{
|
||||
/* This code shows off error handling. You can just use
|
||||
* gtk_image_new_from_file() instead if you don't want to report
|
||||
* errors to the user. If the file doesn't load when using
|
||||
* gtk_image_new_from_file(), a "missing image" icon will
|
||||
* be displayed instead.
|
||||
*/
|
||||
GtkWidget *dialog;
|
||||
|
||||
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
|
||||
GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_MESSAGE_ERROR,
|
||||
GTK_BUTTONS_CLOSE,
|
||||
"Unable to open image file 'gtk-logo-rgb.gif': %s",
|
||||
error->message);
|
||||
g_error_free (error);
|
||||
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
|
||||
GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_MESSAGE_ERROR,
|
||||
GTK_BUTTONS_CLOSE,
|
||||
"Unable to open image file 'gtk-logo-rgb.gif': %s",
|
||||
error->message);
|
||||
g_error_free (error);
|
||||
|
||||
g_signal_connect (dialog, "response",
|
||||
G_CALLBACK (gtk_widget_destroy), NULL);
|
||||
g_signal_connect (dialog, "response",
|
||||
G_CALLBACK (gtk_widget_destroy), NULL);
|
||||
|
||||
gtk_widget_show (dialog);
|
||||
}
|
||||
gtk_widget_show (dialog);
|
||||
}
|
||||
|
||||
image = gtk_image_new_from_pixbuf (pixbuf);
|
||||
|
||||
@ -394,7 +394,7 @@ do_images (GtkWidget *do_widget)
|
||||
|
||||
label = gtk_label_new (NULL);
|
||||
gtk_label_set_markup (GTK_LABEL (label),
|
||||
"<u>Animation loaded from a file</u>");
|
||||
"<u>Animation loaded from a file</u>");
|
||||
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
|
||||
|
||||
frame = gtk_frame_new (NULL);
|
||||
@ -413,7 +413,7 @@ do_images (GtkWidget *do_widget)
|
||||
|
||||
label = gtk_label_new (NULL);
|
||||
gtk_label_set_markup (GTK_LABEL (label),
|
||||
"<u>Symbolic themed icon</u>");
|
||||
"<u>Symbolic themed icon</u>");
|
||||
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
|
||||
|
||||
frame = gtk_frame_new (NULL);
|
||||
@ -432,7 +432,7 @@ do_images (GtkWidget *do_widget)
|
||||
|
||||
label = gtk_label_new (NULL);
|
||||
gtk_label_set_markup (GTK_LABEL (label),
|
||||
"<u>Progressive image loading</u>");
|
||||
"<u>Progressive image loading</u>");
|
||||
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
|
||||
|
||||
frame = gtk_frame_new (NULL);
|
||||
|
@ -15,10 +15,10 @@ on_bar_response (GtkInfoBar *info_bar,
|
||||
GtkWidget *dialog;
|
||||
|
||||
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
|
||||
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_MESSAGE_INFO,
|
||||
GTK_BUTTONS_OK,
|
||||
"You clicked a button on an info bar");
|
||||
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_MESSAGE_INFO,
|
||||
GTK_BUTTONS_OK,
|
||||
"You clicked a button on an info bar");
|
||||
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
|
||||
"Your response has id %d", response_id);
|
||||
gtk_dialog_run (GTK_DIALOG (dialog));
|
||||
|
@ -54,11 +54,11 @@ do_links (GtkWidget *do_widget)
|
||||
{
|
||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_screen (GTK_WINDOW (window),
|
||||
gtk_widget_get_screen (do_widget));
|
||||
gtk_widget_get_screen (do_widget));
|
||||
gtk_window_set_title (GTK_WINDOW (window), "Links");
|
||||
gtk_container_set_border_width (GTK_CONTAINER (window), 12);
|
||||
g_signal_connect (window, "destroy",
|
||||
G_CALLBACK (gtk_widget_destroyed), &window);
|
||||
G_CALLBACK (gtk_widget_destroyed), &window);
|
||||
|
||||
label = gtk_label_new ("Some <a href=\"http://en.wikipedia.org/wiki/Text\""
|
||||
"title=\"plain text\">text</a> may be marked up\n"
|
||||
|
@ -43,7 +43,7 @@ get_democodedir (void)
|
||||
{
|
||||
result = g_win32_get_package_installation_directory_of_module (NULL);
|
||||
if (result == NULL)
|
||||
result = "unknown-location";
|
||||
result = "unknown-location";
|
||||
|
||||
result = g_strconcat (result, "\\share\\gtk-3.0\\demo", NULL);
|
||||
}
|
||||
@ -59,19 +59,19 @@ get_democodedir (void)
|
||||
* demo_find_file:
|
||||
* @base: base filename
|
||||
* @err: location to store error, or %NULL.
|
||||
*
|
||||
*
|
||||
* Looks for @base first in the current directory, then in the
|
||||
* location GTK+ where it will be installed on make install,
|
||||
* returns the first file found.
|
||||
*
|
||||
*
|
||||
* Return value: the filename, if found or %NULL
|
||||
**/
|
||||
*/
|
||||
gchar *
|
||||
demo_find_file (const char *base,
|
||||
GError **err)
|
||||
GError **err)
|
||||
{
|
||||
g_return_val_if_fail (err == NULL || *err == NULL, NULL);
|
||||
|
||||
|
||||
if (g_file_test ("gtk-logo-rgb.gif", G_FILE_TEST_EXISTS) &&
|
||||
g_file_test (base, G_FILE_TEST_EXISTS))
|
||||
return g_strdup (base);
|
||||
@ -79,12 +79,12 @@ demo_find_file (const char *base,
|
||||
{
|
||||
char *filename = g_build_filename (DEMOCODEDIR, base, NULL);
|
||||
if (!g_file_test (filename, G_FILE_TEST_EXISTS))
|
||||
{
|
||||
g_set_error (err, G_FILE_ERROR, G_FILE_ERROR_NOENT,
|
||||
"Cannot find demo data file \"%s\"", base);
|
||||
g_free (filename);
|
||||
return NULL;
|
||||
}
|
||||
{
|
||||
g_set_error (err, G_FILE_ERROR, G_FILE_ERROR_NOENT,
|
||||
"Cannot find demo data file \"%s\"", base);
|
||||
g_free (filename);
|
||||
return NULL;
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
}
|
||||
@ -98,12 +98,12 @@ window_closed_cb (GtkWidget *window, gpointer data)
|
||||
|
||||
gtk_tree_model_get_iter (cbdata->model, &iter, cbdata->path);
|
||||
gtk_tree_model_get (GTK_TREE_MODEL (cbdata->model), &iter,
|
||||
STYLE_COLUMN, &style,
|
||||
-1);
|
||||
STYLE_COLUMN, &style,
|
||||
-1);
|
||||
if (style == PANGO_STYLE_ITALIC)
|
||||
gtk_tree_store_set (GTK_TREE_STORE (cbdata->model), &iter,
|
||||
STYLE_COLUMN, PANGO_STYLE_NORMAL,
|
||||
-1);
|
||||
STYLE_COLUMN, PANGO_STYLE_NORMAL,
|
||||
-1);
|
||||
|
||||
gtk_tree_path_free (cbdata->path);
|
||||
g_free (cbdata);
|
||||
@ -113,17 +113,17 @@ gboolean
|
||||
read_line (FILE *stream, GString *str)
|
||||
{
|
||||
int n_read = 0;
|
||||
|
||||
|
||||
#ifdef HAVE_FLOCKFILE
|
||||
flockfile (stream);
|
||||
#endif
|
||||
|
||||
g_string_truncate (str, 0);
|
||||
|
||||
|
||||
while (1)
|
||||
{
|
||||
int c;
|
||||
|
||||
|
||||
#ifdef HAVE_FLOCKFILE
|
||||
c = getc_unlocked (stream);
|
||||
#else
|
||||
@ -131,31 +131,31 @@ read_line (FILE *stream, GString *str)
|
||||
#endif
|
||||
|
||||
if (c == EOF)
|
||||
goto done;
|
||||
goto done;
|
||||
else
|
||||
n_read++;
|
||||
n_read++;
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case '\r':
|
||||
case '\n':
|
||||
{
|
||||
{
|
||||
case '\r':
|
||||
case '\n':
|
||||
{
|
||||
#ifdef HAVE_FLOCKFILE
|
||||
int next_c = getc_unlocked (stream);
|
||||
int next_c = getc_unlocked (stream);
|
||||
#else
|
||||
int next_c = getc (stream);
|
||||
int next_c = getc (stream);
|
||||
#endif
|
||||
|
||||
if (!(next_c == EOF ||
|
||||
(c == '\r' && next_c == '\n') ||
|
||||
(c == '\n' && next_c == '\r')))
|
||||
ungetc (next_c, stream);
|
||||
|
||||
goto done;
|
||||
}
|
||||
default:
|
||||
g_string_append_c (str, c);
|
||||
}
|
||||
|
||||
if (!(next_c == EOF ||
|
||||
(c == '\r' && next_c == '\n') ||
|
||||
(c == '\n' && next_c == '\r')))
|
||||
ungetc (next_c, stream);
|
||||
|
||||
goto done;
|
||||
}
|
||||
default:
|
||||
g_string_append_c (str, c);
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
@ -333,10 +333,10 @@ static gchar *control[] =
|
||||
};
|
||||
void
|
||||
parse_chars (gchar *text,
|
||||
gchar **end_ptr,
|
||||
gint *state,
|
||||
gchar **tag,
|
||||
gboolean start)
|
||||
gchar **end_ptr,
|
||||
gint *state,
|
||||
gchar **tag,
|
||||
gboolean start)
|
||||
{
|
||||
gint i;
|
||||
gchar *next_token;
|
||||
@ -346,11 +346,11 @@ parse_chars (gchar *text,
|
||||
{
|
||||
*end_ptr = strstr (text, "*/");
|
||||
if (*end_ptr)
|
||||
{
|
||||
*end_ptr += 2;
|
||||
*state = STATE_NORMAL;
|
||||
*tag = "comment";
|
||||
}
|
||||
{
|
||||
*end_ptr += 2;
|
||||
*state = STATE_NORMAL;
|
||||
*tag = "comment";
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -362,9 +362,9 @@ parse_chars (gchar *text,
|
||||
{
|
||||
*end_ptr = strstr (text, "*/");
|
||||
if (*end_ptr)
|
||||
*end_ptr += 2;
|
||||
*end_ptr += 2;
|
||||
else
|
||||
*state = STATE_IN_COMMENT;
|
||||
*state = STATE_IN_COMMENT;
|
||||
*tag = "comment";
|
||||
return;
|
||||
}
|
||||
@ -381,29 +381,29 @@ parse_chars (gchar *text,
|
||||
if (start && * text != '\t' && *text != ' ' && *text != '{' && *text != '}')
|
||||
{
|
||||
if (strstr (text, "("))
|
||||
{
|
||||
*end_ptr = strstr (text, "(");
|
||||
*tag = "function";
|
||||
return;
|
||||
}
|
||||
{
|
||||
*end_ptr = strstr (text, "(");
|
||||
*tag = "function";
|
||||
return;
|
||||
}
|
||||
}
|
||||
/* check for types */
|
||||
for (i = 0; types[i] != NULL; i++)
|
||||
if (!strncmp (text, types[i], strlen (types[i])) ||
|
||||
(start && types[i][0] == ' ' && !strncmp (text, types[i] + 1, strlen (types[i]) - 1)))
|
||||
{
|
||||
*end_ptr = text + strlen (types[i]);
|
||||
*tag = "type";
|
||||
return;
|
||||
*end_ptr = text + strlen (types[i]);
|
||||
*tag = "type";
|
||||
return;
|
||||
}
|
||||
|
||||
/* check for control */
|
||||
for (i = 0; control[i] != NULL; i++)
|
||||
if (!strncmp (text, control[i], strlen (control[i])))
|
||||
{
|
||||
*end_ptr = text + strlen (control[i]);
|
||||
*tag = "control";
|
||||
return;
|
||||
*end_ptr = text + strlen (control[i]);
|
||||
*tag = "control";
|
||||
return;
|
||||
}
|
||||
|
||||
/* check for string */
|
||||
@ -414,18 +414,18 @@ parse_chars (gchar *text,
|
||||
*end_ptr = text + 1;
|
||||
*tag = "string";
|
||||
while (**end_ptr != '\000')
|
||||
{
|
||||
if (**end_ptr == '\"' && !maybe_escape)
|
||||
{
|
||||
*end_ptr += 1;
|
||||
return;
|
||||
}
|
||||
if (**end_ptr == '\\')
|
||||
maybe_escape = TRUE;
|
||||
else
|
||||
maybe_escape = FALSE;
|
||||
*end_ptr += 1;
|
||||
}
|
||||
{
|
||||
if (**end_ptr == '\"' && !maybe_escape)
|
||||
{
|
||||
*end_ptr += 1;
|
||||
return;
|
||||
}
|
||||
if (**end_ptr == '\\')
|
||||
maybe_escape = TRUE;
|
||||
else
|
||||
maybe_escape = FALSE;
|
||||
*end_ptr += 1;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -434,36 +434,36 @@ parse_chars (gchar *text,
|
||||
{
|
||||
next_token = strstr (text, tokens[i]);
|
||||
if (next_token)
|
||||
{
|
||||
if (*end_ptr)
|
||||
*end_ptr = (*end_ptr<next_token)?*end_ptr:next_token;
|
||||
else
|
||||
*end_ptr = next_token;
|
||||
}
|
||||
{
|
||||
if (*end_ptr)
|
||||
*end_ptr = (*end_ptr<next_token)?*end_ptr:next_token;
|
||||
else
|
||||
*end_ptr = next_token;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; types[i] != NULL; i++)
|
||||
{
|
||||
next_token = strstr (text, types[i]);
|
||||
if (next_token)
|
||||
{
|
||||
if (*end_ptr)
|
||||
*end_ptr = (*end_ptr<next_token)?*end_ptr:next_token;
|
||||
else
|
||||
*end_ptr = next_token;
|
||||
}
|
||||
{
|
||||
if (*end_ptr)
|
||||
*end_ptr = (*end_ptr<next_token)?*end_ptr:next_token;
|
||||
else
|
||||
*end_ptr = next_token;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; control[i] != NULL; i++)
|
||||
{
|
||||
next_token = strstr (text, control[i]);
|
||||
if (next_token)
|
||||
{
|
||||
if (*end_ptr)
|
||||
*end_ptr = (*end_ptr<next_token)?*end_ptr:next_token;
|
||||
else
|
||||
*end_ptr = next_token;
|
||||
}
|
||||
{
|
||||
if (*end_ptr)
|
||||
*end_ptr = (*end_ptr<next_token)?*end_ptr:next_token;
|
||||
else
|
||||
*end_ptr = next_token;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -488,25 +488,25 @@ fontify (void)
|
||||
start_ptr = text = gtk_text_iter_get_text (&start_iter, &next_iter);
|
||||
|
||||
do
|
||||
{
|
||||
parse_chars (start_ptr, &end_ptr, &state, &tag, start);
|
||||
{
|
||||
parse_chars (start_ptr, &end_ptr, &state, &tag, start);
|
||||
|
||||
start = FALSE;
|
||||
if (end_ptr)
|
||||
{
|
||||
tmp_iter = start_iter;
|
||||
gtk_text_iter_forward_chars (&tmp_iter, end_ptr - start_ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp_iter = next_iter;
|
||||
}
|
||||
if (tag)
|
||||
gtk_text_buffer_apply_tag_by_name (source_buffer, tag, &start_iter, &tmp_iter);
|
||||
start = FALSE;
|
||||
if (end_ptr)
|
||||
{
|
||||
tmp_iter = start_iter;
|
||||
gtk_text_iter_forward_chars (&tmp_iter, end_ptr - start_ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp_iter = next_iter;
|
||||
}
|
||||
if (tag)
|
||||
gtk_text_buffer_apply_tag_by_name (source_buffer, tag, &start_iter, &tmp_iter);
|
||||
|
||||
start_iter = tmp_iter;
|
||||
start_ptr = end_ptr;
|
||||
}
|
||||
start_iter = tmp_iter;
|
||||
start_ptr = end_ptr;
|
||||
}
|
||||
while (end_ptr);
|
||||
|
||||
g_free (text);
|
||||
@ -533,7 +533,7 @@ load_file (const gchar *filename)
|
||||
|
||||
g_free (current_file);
|
||||
current_file = g_strdup (filename);
|
||||
|
||||
|
||||
gtk_text_buffer_get_bounds (info_buffer, &start, &end);
|
||||
gtk_text_buffer_delete (info_buffer, &start, &end);
|
||||
|
||||
@ -564,101 +564,101 @@ load_file (const gchar *filename)
|
||||
gchar *p = buffer->str;
|
||||
gchar *q;
|
||||
gchar *r;
|
||||
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case 0:
|
||||
/* Reading title */
|
||||
while (*p == '/' || *p == '*' || g_ascii_isspace (*p))
|
||||
p++;
|
||||
r = p;
|
||||
while (*r != '/' && strlen (r))
|
||||
r++;
|
||||
if (strlen (r) > 0)
|
||||
p = r + 1;
|
||||
q = p + strlen (p);
|
||||
while (q > p && g_ascii_isspace (*(q - 1)))
|
||||
q--;
|
||||
{
|
||||
case 0:
|
||||
/* Reading title */
|
||||
while (*p == '/' || *p == '*' || g_ascii_isspace (*p))
|
||||
p++;
|
||||
r = p;
|
||||
while (*r != '/' && strlen (r))
|
||||
r++;
|
||||
if (strlen (r) > 0)
|
||||
p = r + 1;
|
||||
q = p + strlen (p);
|
||||
while (q > p && g_ascii_isspace (*(q - 1)))
|
||||
q--;
|
||||
|
||||
if (q > p)
|
||||
{
|
||||
int len_chars = g_utf8_pointer_to_offset (p, q);
|
||||
if (q > p)
|
||||
{
|
||||
int len_chars = g_utf8_pointer_to_offset (p, q);
|
||||
|
||||
end = start;
|
||||
end = start;
|
||||
|
||||
g_assert (strlen (p) >= q - p);
|
||||
gtk_text_buffer_insert (info_buffer, &end, p, q - p);
|
||||
start = end;
|
||||
g_assert (strlen (p) >= q - p);
|
||||
gtk_text_buffer_insert (info_buffer, &end, p, q - p);
|
||||
start = end;
|
||||
|
||||
gtk_text_iter_backward_chars (&start, len_chars);
|
||||
gtk_text_buffer_apply_tag_by_name (info_buffer, "title", &start, &end);
|
||||
gtk_text_iter_backward_chars (&start, len_chars);
|
||||
gtk_text_buffer_apply_tag_by_name (info_buffer, "title", &start, &end);
|
||||
|
||||
start = end;
|
||||
|
||||
state++;
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
/* Reading body of info section */
|
||||
while (g_ascii_isspace (*p))
|
||||
p++;
|
||||
if (*p == '*' && *(p + 1) == '/')
|
||||
{
|
||||
gtk_text_buffer_get_iter_at_offset (source_buffer, &start, 0);
|
||||
state++;
|
||||
}
|
||||
else
|
||||
{
|
||||
int len;
|
||||
|
||||
while (*p == '*' || g_ascii_isspace (*p))
|
||||
p++;
|
||||
start = end;
|
||||
|
||||
len = strlen (p);
|
||||
while (g_ascii_isspace (*(p + len - 1)))
|
||||
len--;
|
||||
|
||||
if (len > 0)
|
||||
{
|
||||
if (in_para)
|
||||
gtk_text_buffer_insert (info_buffer, &start, " ", 1);
|
||||
state++;
|
||||
}
|
||||
break;
|
||||
|
||||
g_assert (strlen (p) >= len);
|
||||
gtk_text_buffer_insert (info_buffer, &start, p, len);
|
||||
in_para = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_text_buffer_insert (info_buffer, &start, "\n", 1);
|
||||
in_para = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
/* Reading body of info section */
|
||||
while (g_ascii_isspace (*p))
|
||||
p++;
|
||||
if (*p == '*' && *(p + 1) == '/')
|
||||
{
|
||||
gtk_text_buffer_get_iter_at_offset (source_buffer, &start, 0);
|
||||
state++;
|
||||
}
|
||||
else
|
||||
{
|
||||
int len;
|
||||
|
||||
case 2:
|
||||
/* Skipping blank lines */
|
||||
while (g_ascii_isspace (*p))
|
||||
p++;
|
||||
if (*p)
|
||||
{
|
||||
p = buffer->str;
|
||||
state++;
|
||||
/* Fall through */
|
||||
}
|
||||
else
|
||||
break;
|
||||
|
||||
case 3:
|
||||
/* Reading program body */
|
||||
gtk_text_buffer_insert (source_buffer, &start, p, -1);
|
||||
gtk_text_buffer_insert (source_buffer, &start, "\n", 1);
|
||||
break;
|
||||
}
|
||||
while (*p == '*' || g_ascii_isspace (*p))
|
||||
p++;
|
||||
|
||||
len = strlen (p);
|
||||
while (g_ascii_isspace (*(p + len - 1)))
|
||||
len--;
|
||||
|
||||
if (len > 0)
|
||||
{
|
||||
if (in_para)
|
||||
gtk_text_buffer_insert (info_buffer, &start, " ", 1);
|
||||
|
||||
g_assert (strlen (p) >= len);
|
||||
gtk_text_buffer_insert (info_buffer, &start, p, len);
|
||||
in_para = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_text_buffer_insert (info_buffer, &start, "\n", 1);
|
||||
in_para = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
/* Skipping blank lines */
|
||||
while (g_ascii_isspace (*p))
|
||||
p++;
|
||||
if (*p)
|
||||
{
|
||||
p = buffer->str;
|
||||
state++;
|
||||
/* Fall through */
|
||||
}
|
||||
else
|
||||
break;
|
||||
|
||||
case 3:
|
||||
/* Reading program body */
|
||||
gtk_text_buffer_insert (source_buffer, &start, p, -1);
|
||||
gtk_text_buffer_insert (source_buffer, &start, "\n", 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
fclose (file);
|
||||
|
||||
|
||||
fontify ();
|
||||
|
||||
g_string_free (buffer, TRUE);
|
||||
@ -667,7 +667,7 @@ load_file (const gchar *filename)
|
||||
void
|
||||
row_activated_cb (GtkTreeView *tree_view,
|
||||
GtkTreePath *path,
|
||||
GtkTreeViewColumn *column)
|
||||
GtkTreeViewColumn *column)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
PangoStyle style;
|
||||
@ -676,39 +676,39 @@ row_activated_cb (GtkTreeView *tree_view,
|
||||
GtkTreeModel *model;
|
||||
|
||||
model = gtk_tree_view_get_model (tree_view);
|
||||
|
||||
|
||||
gtk_tree_model_get_iter (model, &iter, path);
|
||||
gtk_tree_model_get (GTK_TREE_MODEL (model),
|
||||
&iter,
|
||||
FUNC_COLUMN, &func,
|
||||
STYLE_COLUMN, &style,
|
||||
-1);
|
||||
&iter,
|
||||
FUNC_COLUMN, &func,
|
||||
STYLE_COLUMN, &style,
|
||||
-1);
|
||||
|
||||
if (func)
|
||||
{
|
||||
gtk_tree_store_set (GTK_TREE_STORE (model),
|
||||
&iter,
|
||||
STYLE_COLUMN, (style == PANGO_STYLE_ITALIC ? PANGO_STYLE_NORMAL : PANGO_STYLE_ITALIC),
|
||||
-1);
|
||||
&iter,
|
||||
STYLE_COLUMN, (style == PANGO_STYLE_ITALIC ? PANGO_STYLE_NORMAL : PANGO_STYLE_ITALIC),
|
||||
-1);
|
||||
window = (func) (gtk_widget_get_toplevel (GTK_WIDGET (tree_view)));
|
||||
|
||||
|
||||
if (window != NULL)
|
||||
{
|
||||
CallbackData *cbdata;
|
||||
|
||||
cbdata = g_new (CallbackData, 1);
|
||||
cbdata->model = model;
|
||||
cbdata->path = gtk_tree_path_copy (path);
|
||||
|
||||
g_signal_connect (window, "destroy",
|
||||
G_CALLBACK (window_closed_cb), cbdata);
|
||||
}
|
||||
{
|
||||
CallbackData *cbdata;
|
||||
|
||||
cbdata = g_new (CallbackData, 1);
|
||||
cbdata->model = model;
|
||||
cbdata->path = gtk_tree_path_copy (path);
|
||||
|
||||
g_signal_connect (window, "destroy",
|
||||
G_CALLBACK (window_closed_cb), cbdata);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
selection_cb (GtkTreeSelection *selection,
|
||||
GtkTreeModel *model)
|
||||
GtkTreeModel *model)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
GValue value = {0, };
|
||||
@ -717,8 +717,8 @@ selection_cb (GtkTreeSelection *selection,
|
||||
return;
|
||||
|
||||
gtk_tree_model_get_value (model, &iter,
|
||||
FILENAME_COLUMN,
|
||||
&value);
|
||||
FILENAME_COLUMN,
|
||||
&value);
|
||||
if (g_value_get_string (&value))
|
||||
load_file (g_value_get_string (&value));
|
||||
g_value_unset (&value);
|
||||
@ -726,7 +726,7 @@ selection_cb (GtkTreeSelection *selection,
|
||||
|
||||
static GtkWidget *
|
||||
create_text (GtkTextBuffer **buffer,
|
||||
gboolean is_source)
|
||||
gboolean is_source)
|
||||
{
|
||||
GtkWidget *scrolled_window;
|
||||
GtkWidget *text_view;
|
||||
@ -734,20 +734,20 @@ create_text (GtkTextBuffer **buffer,
|
||||
|
||||
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
|
||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
|
||||
GTK_POLICY_AUTOMATIC,
|
||||
GTK_POLICY_AUTOMATIC);
|
||||
GTK_POLICY_AUTOMATIC,
|
||||
GTK_POLICY_AUTOMATIC);
|
||||
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
|
||||
GTK_SHADOW_IN);
|
||||
|
||||
GTK_SHADOW_IN);
|
||||
|
||||
text_view = gtk_text_view_new ();
|
||||
|
||||
|
||||
*buffer = gtk_text_buffer_new (NULL);
|
||||
gtk_text_view_set_buffer (GTK_TEXT_VIEW (text_view), *buffer);
|
||||
gtk_text_view_set_editable (GTK_TEXT_VIEW (text_view), FALSE);
|
||||
gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (text_view), FALSE);
|
||||
|
||||
gtk_container_add (GTK_CONTAINER (scrolled_window), text_view);
|
||||
|
||||
|
||||
if (is_source)
|
||||
{
|
||||
font_desc = pango_font_description_from_string ("monospace");
|
||||
@ -767,7 +767,7 @@ create_text (GtkTextBuffer **buffer,
|
||||
gtk_text_view_set_pixels_below_lines (GTK_TEXT_VIEW (text_view),
|
||||
2);
|
||||
}
|
||||
|
||||
|
||||
return scrolled_window;
|
||||
}
|
||||
|
||||
@ -790,7 +790,7 @@ create_tree (void)
|
||||
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
|
||||
|
||||
gtk_tree_selection_set_mode (GTK_TREE_SELECTION (selection),
|
||||
GTK_SELECTION_BROWSE);
|
||||
GTK_SELECTION_BROWSE);
|
||||
gtk_widget_set_size_request (tree_view, 200, -1);
|
||||
|
||||
/* this code only supports 1 level of children. If we
|
||||
@ -803,46 +803,46 @@ create_tree (void)
|
||||
gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
|
||||
|
||||
gtk_tree_store_set (GTK_TREE_STORE (model),
|
||||
&iter,
|
||||
TITLE_COLUMN, d->title,
|
||||
FILENAME_COLUMN, d->filename,
|
||||
FUNC_COLUMN, d->func,
|
||||
STYLE_COLUMN, PANGO_STYLE_NORMAL,
|
||||
-1);
|
||||
&iter,
|
||||
TITLE_COLUMN, d->title,
|
||||
FILENAME_COLUMN, d->filename,
|
||||
FUNC_COLUMN, d->func,
|
||||
STYLE_COLUMN, PANGO_STYLE_NORMAL,
|
||||
-1);
|
||||
|
||||
d++;
|
||||
|
||||
if (!children)
|
||||
continue;
|
||||
|
||||
while (children->title)
|
||||
{
|
||||
GtkTreeIter child_iter;
|
||||
continue;
|
||||
|
||||
gtk_tree_store_append (GTK_TREE_STORE (model), &child_iter, &iter);
|
||||
|
||||
gtk_tree_store_set (GTK_TREE_STORE (model),
|
||||
&child_iter,
|
||||
TITLE_COLUMN, children->title,
|
||||
FILENAME_COLUMN, children->filename,
|
||||
FUNC_COLUMN, children->func,
|
||||
STYLE_COLUMN, PANGO_STYLE_NORMAL,
|
||||
-1);
|
||||
|
||||
children++;
|
||||
}
|
||||
while (children->title)
|
||||
{
|
||||
GtkTreeIter child_iter;
|
||||
|
||||
gtk_tree_store_append (GTK_TREE_STORE (model), &child_iter, &iter);
|
||||
|
||||
gtk_tree_store_set (GTK_TREE_STORE (model),
|
||||
&child_iter,
|
||||
TITLE_COLUMN, children->title,
|
||||
FILENAME_COLUMN, children->filename,
|
||||
FUNC_COLUMN, children->func,
|
||||
STYLE_COLUMN, PANGO_STYLE_NORMAL,
|
||||
-1);
|
||||
|
||||
children++;
|
||||
}
|
||||
}
|
||||
|
||||
cell = gtk_cell_renderer_text_new ();
|
||||
|
||||
column = gtk_tree_view_column_new_with_attributes ("Widget (double click for demo)",
|
||||
cell,
|
||||
"text", TITLE_COLUMN,
|
||||
"style", STYLE_COLUMN,
|
||||
NULL);
|
||||
|
||||
cell,
|
||||
"text", TITLE_COLUMN,
|
||||
"style", STYLE_COLUMN,
|
||||
NULL);
|
||||
|
||||
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view),
|
||||
GTK_TREE_VIEW_COLUMN (column));
|
||||
GTK_TREE_VIEW_COLUMN (column));
|
||||
|
||||
gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model), &iter);
|
||||
gtk_tree_selection_select_iter (GTK_TREE_SELECTION (selection), &iter);
|
||||
@ -852,11 +852,11 @@ create_tree (void)
|
||||
|
||||
gtk_tree_view_collapse_all (GTK_TREE_VIEW (tree_view));
|
||||
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_view), FALSE);
|
||||
|
||||
|
||||
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
|
||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
|
||||
GTK_POLICY_NEVER,
|
||||
GTK_POLICY_AUTOMATIC);
|
||||
GTK_POLICY_NEVER,
|
||||
GTK_POLICY_AUTOMATIC);
|
||||
gtk_container_add (GTK_CONTAINER (scrolled_window), tree_view);
|
||||
|
||||
label = gtk_label_new ("Widget (double click for demo)");
|
||||
@ -895,21 +895,21 @@ setup_default_icon (void)
|
||||
if (err)
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
|
||||
|
||||
dialog = gtk_message_dialog_new (NULL, 0,
|
||||
GTK_MESSAGE_ERROR,
|
||||
GTK_BUTTONS_CLOSE,
|
||||
"Failed to read icon file: %s",
|
||||
err->message);
|
||||
GTK_MESSAGE_ERROR,
|
||||
GTK_BUTTONS_CLOSE,
|
||||
"Failed to read icon file: %s",
|
||||
err->message);
|
||||
g_error_free (err);
|
||||
|
||||
g_signal_connect (dialog, "response",
|
||||
G_CALLBACK (gtk_widget_destroy), NULL);
|
||||
G_CALLBACK (gtk_widget_destroy), NULL);
|
||||
}
|
||||
|
||||
if (pixbuf)
|
||||
{
|
||||
GList *list;
|
||||
GList *list;
|
||||
GdkPixbuf *transparent;
|
||||
|
||||
/* The gtk-logo-rgb icon has a white background, make it transparent */
|
||||
@ -943,15 +943,15 @@ main (int argc, char **argv)
|
||||
g_setenv ("GTK_IM_MODULE_FILE", "../../modules/input/immodules.cache", TRUE);
|
||||
}
|
||||
/* -- End of hack -- */
|
||||
|
||||
|
||||
gtk_init (&argc, &argv);
|
||||
|
||||
setup_default_icon ();
|
||||
|
||||
|
||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_title (GTK_WINDOW (window), "GTK+ Code Demos");
|
||||
g_signal_connect_after (window, "destroy",
|
||||
G_CALLBACK (gtk_main_quit), NULL);
|
||||
G_CALLBACK (gtk_main_quit), NULL);
|
||||
|
||||
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
||||
gtk_container_add (GTK_CONTAINER (window), hbox);
|
||||
@ -963,8 +963,8 @@ main (int argc, char **argv)
|
||||
gtk_box_pack_start (GTK_BOX (hbox), notebook, TRUE, TRUE, 0);
|
||||
|
||||
gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
|
||||
create_text (&info_buffer, FALSE),
|
||||
gtk_label_new_with_mnemonic ("_Info"));
|
||||
create_text (&info_buffer, FALSE),
|
||||
gtk_label_new_with_mnemonic ("_Info"));
|
||||
|
||||
gtk_text_buffer_create_tag (info_buffer, "title",
|
||||
"font", "Sans 18",
|
||||
@ -972,8 +972,8 @@ main (int argc, char **argv)
|
||||
g_object_unref (info_buffer);
|
||||
|
||||
gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
|
||||
create_text (&source_buffer, TRUE),
|
||||
gtk_label_new_with_mnemonic ("_Source"));
|
||||
create_text (&source_buffer, TRUE),
|
||||
gtk_label_new_with_mnemonic ("_Source"));
|
||||
|
||||
|
||||
gtk_text_buffer_create_tag (source_buffer, "comment",
|
||||
@ -998,13 +998,12 @@ main (int argc, char **argv)
|
||||
"foreground", "DarkGoldenrod4",
|
||||
NULL);
|
||||
g_object_unref (source_buffer);
|
||||
|
||||
|
||||
gtk_window_set_default_size (GTK_WINDOW (window), 600, 400);
|
||||
gtk_widget_show_all (window);
|
||||
|
||||
|
||||
load_file (testgtk_demos[0].filename);
|
||||
|
||||
|
||||
gtk_main ();
|
||||
|
||||
return 0;
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
static GtkWidget *
|
||||
create_menu (gint depth,
|
||||
gboolean tearoff)
|
||||
gboolean tearoff)
|
||||
{
|
||||
GtkWidget *menu;
|
||||
GtkWidget *menuitem;
|
||||
@ -61,7 +61,7 @@ create_menu (gint depth,
|
||||
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
|
||||
gtk_widget_show (menuitem);
|
||||
if (i == 3)
|
||||
gtk_widget_set_sensitive (menuitem, FALSE);
|
||||
gtk_widget_set_sensitive (menuitem, FALSE);
|
||||
|
||||
gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), create_menu (depth - 1, TRUE));
|
||||
}
|
||||
@ -106,10 +106,10 @@ do_menus (GtkWidget *do_widget)
|
||||
|
||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_screen (GTK_WINDOW (window),
|
||||
gtk_widget_get_screen (do_widget));
|
||||
gtk_widget_get_screen (do_widget));
|
||||
gtk_window_set_title (GTK_WINDOW (window), "Menus");
|
||||
g_signal_connect (window, "destroy",
|
||||
G_CALLBACK(gtk_widget_destroyed), &window);
|
||||
G_CALLBACK(gtk_widget_destroyed), &window);
|
||||
|
||||
accel_group = gtk_accel_group_new ();
|
||||
gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
|
||||
@ -152,13 +152,13 @@ do_menus (GtkWidget *do_widget)
|
||||
|
||||
button = gtk_button_new_with_label ("Flip");
|
||||
g_signal_connect (button, "clicked",
|
||||
G_CALLBACK (change_orientation), menubar);
|
||||
G_CALLBACK (change_orientation), menubar);
|
||||
gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
|
||||
gtk_widget_show (button);
|
||||
|
||||
button = gtk_button_new_with_label ("Close");
|
||||
g_signal_connect_swapped (button, "clicked",
|
||||
G_CALLBACK(gtk_widget_destroy), window);
|
||||
G_CALLBACK(gtk_widget_destroy), window);
|
||||
gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
|
||||
gtk_widget_set_can_default (button, TRUE);
|
||||
gtk_widget_grab_default (button);
|
||||
|
@ -613,4 +613,3 @@ do_offscreen_window (GtkWidget *do_widget)
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
|
@ -524,4 +524,3 @@ do_offscreen_window2 (GtkWidget *do_widget)
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ do_overlay (GtkWidget *do_widget)
|
||||
gtk_widget_get_screen (do_widget));
|
||||
gtk_window_set_default_size (GTK_WINDOW (window),
|
||||
450, 450);
|
||||
|
||||
|
||||
g_signal_connect (window, "destroy",
|
||||
G_CALLBACK (gtk_widget_destroyed), &window);
|
||||
|
||||
|
@ -158,7 +158,7 @@ do_panes (GtkWidget *do_widget)
|
||||
gtk_frame_set_shadow_type (GTK_FRAME(frame), GTK_SHADOW_IN);
|
||||
gtk_widget_set_size_request (frame, 60, 60);
|
||||
gtk_paned_add1 (GTK_PANED (hpaned), frame);
|
||||
|
||||
|
||||
button = gtk_button_new_with_mnemonic ("_Hi there");
|
||||
gtk_container_add (GTK_CONTAINER(frame), button);
|
||||
|
||||
|
@ -71,7 +71,7 @@ load_pixbufs (GError **error)
|
||||
|
||||
background = gdk_pixbuf_new_from_file (filename, error);
|
||||
g_free (filename);
|
||||
|
||||
|
||||
if (!background)
|
||||
return FALSE; /* Note that "error" was filled with a GError */
|
||||
|
||||
@ -83,10 +83,10 @@ load_pixbufs (GError **error)
|
||||
filename = demo_find_file (image_names[i], error);
|
||||
if (!filename)
|
||||
return FALSE; /* Note that "error" was filled with a GError */
|
||||
|
||||
|
||||
images[i] = gdk_pixbuf_new_from_file (filename, error);
|
||||
g_free (filename);
|
||||
|
||||
|
||||
if (!images[i])
|
||||
return FALSE; /* Note that "error" was filled with a GError */
|
||||
}
|
||||
|
@ -26,8 +26,8 @@ typedef struct
|
||||
|
||||
static void
|
||||
begin_print (GtkPrintOperation *operation,
|
||||
GtkPrintContext *context,
|
||||
gpointer user_data)
|
||||
GtkPrintContext *context,
|
||||
gpointer user_data)
|
||||
{
|
||||
PrintData *data = (PrintData *)user_data;
|
||||
char *contents;
|
||||
@ -55,9 +55,9 @@ begin_print (GtkPrintOperation *operation,
|
||||
|
||||
static void
|
||||
draw_page (GtkPrintOperation *operation,
|
||||
GtkPrintContext *context,
|
||||
gint page_nr,
|
||||
gpointer user_data)
|
||||
GtkPrintContext *context,
|
||||
gint page_nr,
|
||||
gpointer user_data)
|
||||
{
|
||||
PrintData *data = (PrintData *)user_data;
|
||||
cairo_t *cr;
|
||||
@ -132,8 +132,8 @@ draw_page (GtkPrintOperation *operation,
|
||||
|
||||
static void
|
||||
end_print (GtkPrintOperation *operation,
|
||||
GtkPrintContext *context,
|
||||
gpointer user_data)
|
||||
GtkPrintContext *context,
|
||||
gpointer user_data)
|
||||
{
|
||||
PrintData *data = (PrintData *)user_data;
|
||||
|
||||
@ -159,11 +159,11 @@ do_printing (GtkWidget *do_widget)
|
||||
data->font_size = 12.0;
|
||||
|
||||
g_signal_connect (G_OBJECT (operation), "begin-print",
|
||||
G_CALLBACK (begin_print), data);
|
||||
G_CALLBACK (begin_print), data);
|
||||
g_signal_connect (G_OBJECT (operation), "draw-page",
|
||||
G_CALLBACK (draw_page), data);
|
||||
G_CALLBACK (draw_page), data);
|
||||
g_signal_connect (G_OBJECT (operation), "end-print",
|
||||
G_CALLBACK (end_print), data);
|
||||
G_CALLBACK (end_print), data);
|
||||
|
||||
gtk_print_operation_set_use_full_page (operation, FALSE);
|
||||
gtk_print_operation_set_unit (operation, GTK_UNIT_POINTS);
|
||||
@ -195,14 +195,14 @@ do_printing (GtkWidget *do_widget)
|
||||
GtkWidget *dialog;
|
||||
|
||||
dialog = gtk_message_dialog_new (GTK_WINDOW (do_widget),
|
||||
GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_MESSAGE_ERROR,
|
||||
GTK_BUTTONS_CLOSE,
|
||||
"%s", error->message);
|
||||
GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_MESSAGE_ERROR,
|
||||
GTK_BUTTONS_CLOSE,
|
||||
"%s", error->message);
|
||||
g_error_free (error);
|
||||
|
||||
g_signal_connect (dialog, "response",
|
||||
G_CALLBACK (gtk_widget_destroy), NULL);
|
||||
G_CALLBACK (gtk_widget_destroy), NULL);
|
||||
|
||||
gtk_widget_show (dialog);
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ create_fancy_attr_list_for_layout (PangoLayout *layout)
|
||||
for (p = text; (p = strstr (p, HEART)); p += strlen (HEART))
|
||||
{
|
||||
PangoAttribute *attr;
|
||||
|
||||
|
||||
attr = pango_attr_shape_new_with_data (&ink_rect,
|
||||
&logical_rect,
|
||||
GUINT_TO_POINTER (g_utf8_get_char (p)),
|
||||
@ -152,7 +152,7 @@ rotated_text_draw (GtkWidget *widget,
|
||||
|
||||
/* Inform Pango to re-layout the text with the new transformation matrix */
|
||||
pango_cairo_update_layout (cr, layout);
|
||||
|
||||
|
||||
pango_layout_get_pixel_size (layout, &width, &height);
|
||||
cairo_move_to (cr, - width / 2, - RADIUS * .9);
|
||||
pango_cairo_show_layout (cr, layout);
|
||||
@ -166,7 +166,7 @@ rotated_text_draw (GtkWidget *widget,
|
||||
g_object_unref (layout);
|
||||
g_object_unref (context);
|
||||
cairo_pattern_destroy (pattern);
|
||||
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -2,9 +2,9 @@
|
||||
*
|
||||
* GtkSizeGroup provides a mechanism for grouping a number of
|
||||
* widgets together so they all request the same amount of space.
|
||||
* This is typically useful when you want a column of widgets to
|
||||
* This is typically useful when you want a column of widgets to
|
||||
* have the same size, but you can't use a GtkTable widget.
|
||||
*
|
||||
*
|
||||
* Note that size groups only affect the amount of space requested,
|
||||
* not the size that the widgets finally receive. If you want the
|
||||
* widgets in a GtkSizeGroup to actually be the same size, you need
|
||||
@ -26,7 +26,7 @@ create_combo_box (const char **strings)
|
||||
const char **str;
|
||||
|
||||
combo_box = gtk_combo_box_text_new ();
|
||||
|
||||
|
||||
for (str = strings; *str; str++)
|
||||
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo_box), *str);
|
||||
|
||||
@ -37,10 +37,10 @@ create_combo_box (const char **strings)
|
||||
|
||||
static void
|
||||
add_row (GtkGrid *table,
|
||||
int row,
|
||||
GtkSizeGroup *size_group,
|
||||
const char *label_text,
|
||||
const char **options)
|
||||
int row,
|
||||
GtkSizeGroup *size_group,
|
||||
const char *label_text,
|
||||
const char **options)
|
||||
{
|
||||
GtkWidget *combo_box;
|
||||
GtkWidget *label;
|
||||
@ -59,7 +59,7 @@ add_row (GtkGrid *table,
|
||||
|
||||
static void
|
||||
toggle_grouping (GtkToggleButton *check_button,
|
||||
GtkSizeGroup *size_group)
|
||||
GtkSizeGroup *size_group)
|
||||
{
|
||||
GtkSizeGroupMode new_mode;
|
||||
|
||||
@ -71,7 +71,7 @@ toggle_grouping (GtkToggleButton *check_button,
|
||||
new_mode = GTK_SIZE_GROUP_HORIZONTAL;
|
||||
else
|
||||
new_mode = GTK_SIZE_GROUP_NONE;
|
||||
|
||||
|
||||
gtk_size_group_set_mode (size_group, new_mode);
|
||||
}
|
||||
|
||||
@ -88,29 +88,29 @@ do_sizegroup (GtkWidget *do_widget)
|
||||
static const char *color_options[] = {
|
||||
"Red", "Green", "Blue", NULL
|
||||
};
|
||||
|
||||
|
||||
static const char *dash_options[] = {
|
||||
"Solid", "Dashed", "Dotted", NULL
|
||||
};
|
||||
|
||||
|
||||
static const char *end_options[] = {
|
||||
"Square", "Round", "Arrow", NULL
|
||||
};
|
||||
|
||||
|
||||
if (!window)
|
||||
{
|
||||
window = gtk_dialog_new_with_buttons ("GtkSizeGroup",
|
||||
GTK_WINDOW (do_widget),
|
||||
0,
|
||||
GTK_STOCK_CLOSE,
|
||||
GTK_RESPONSE_NONE,
|
||||
NULL);
|
||||
GTK_WINDOW (do_widget),
|
||||
0,
|
||||
GTK_STOCK_CLOSE,
|
||||
GTK_RESPONSE_NONE,
|
||||
NULL);
|
||||
gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
|
||||
|
||||
|
||||
g_signal_connect (window, "response",
|
||||
G_CALLBACK (gtk_widget_destroy), NULL);
|
||||
G_CALLBACK (gtk_widget_destroy), NULL);
|
||||
g_signal_connect (window, "destroy",
|
||||
G_CALLBACK (gtk_widget_destroyed), &window);
|
||||
G_CALLBACK (gtk_widget_destroyed), &window);
|
||||
|
||||
content_area = gtk_dialog_get_content_area (GTK_DIALOG (window));
|
||||
|
||||
@ -119,9 +119,8 @@ do_sizegroup (GtkWidget *do_widget)
|
||||
gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
|
||||
|
||||
size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
|
||||
|
||||
/* Create one frame holding color options
|
||||
*/
|
||||
|
||||
/* Create one frame holding color options */
|
||||
frame = gtk_frame_new ("Color Options");
|
||||
gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0);
|
||||
|
||||
@ -134,8 +133,7 @@ do_sizegroup (GtkWidget *do_widget)
|
||||
add_row (GTK_GRID (table), 0, size_group, "_Foreground", color_options);
|
||||
add_row (GTK_GRID (table), 1, size_group, "_Background", color_options);
|
||||
|
||||
/* And another frame holding line style options
|
||||
*/
|
||||
/* And another frame holding line style options */
|
||||
frame = gtk_frame_new ("Line Options");
|
||||
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
|
||||
|
||||
@ -154,7 +152,7 @@ do_sizegroup (GtkWidget *do_widget)
|
||||
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button), TRUE);
|
||||
g_signal_connect (check_button, "toggled",
|
||||
G_CALLBACK (toggle_grouping), size_group);
|
||||
G_CALLBACK (toggle_grouping), size_group);
|
||||
}
|
||||
|
||||
if (!gtk_widget_get_visible (window))
|
||||
|
@ -93,5 +93,3 @@ do_spinner (GtkWidget *do_widget)
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
|
||||
|
@ -35,7 +35,7 @@ stock_item_info_free (StockItemInfo *info)
|
||||
g_free (info->accel_str);
|
||||
if (info->small_icon)
|
||||
g_object_unref (info->small_icon);
|
||||
|
||||
|
||||
g_free (info);
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ stock_item_info_copy (StockItemInfo *src)
|
||||
info->id = g_strdup (src->id);
|
||||
info->macro = g_strdup (src->macro);
|
||||
info->accel_str = g_strdup (src->accel_str);
|
||||
|
||||
|
||||
info->item = src->item;
|
||||
|
||||
info->small_icon = src->small_icon;
|
||||
@ -82,9 +82,9 @@ id_to_macro (const gchar *id)
|
||||
/* gtk-foo-bar -> GTK_STOCK_FOO_BAR */
|
||||
|
||||
macro = g_string_new (NULL);
|
||||
|
||||
|
||||
cp = id;
|
||||
|
||||
|
||||
if (strncmp (cp, "gtk-", 4) == 0)
|
||||
{
|
||||
g_string_append (macro, "GTK_STOCK_");
|
||||
@ -94,11 +94,11 @@ id_to_macro (const gchar *id)
|
||||
while (*cp)
|
||||
{
|
||||
if (*cp == '-')
|
||||
g_string_append_c (macro, '_');
|
||||
g_string_append_c (macro, '_');
|
||||
else if (g_ascii_islower (*cp))
|
||||
g_string_append_c (macro, g_ascii_toupper (*cp));
|
||||
g_string_append_c (macro, g_ascii_toupper (*cp));
|
||||
else
|
||||
g_string_append_c (macro, *cp);
|
||||
g_string_append_c (macro, *cp);
|
||||
|
||||
cp++;
|
||||
}
|
||||
@ -112,7 +112,7 @@ create_model (void)
|
||||
GtkListStore *store;
|
||||
GSList *ids;
|
||||
GSList *tmp_list;
|
||||
|
||||
|
||||
store = gtk_list_store_new (2, STOCK_ITEM_INFO_TYPE, G_TYPE_STRING);
|
||||
|
||||
ids = gtk_stock_list_ids ();
|
||||
@ -124,9 +124,9 @@ create_model (void)
|
||||
GtkStockItem item;
|
||||
GtkTreeIter iter;
|
||||
GtkIconSet *icon_set;
|
||||
|
||||
|
||||
info.id = tmp_list->data;
|
||||
|
||||
|
||||
if (gtk_stock_lookup (info.id, &item))
|
||||
{
|
||||
info.item = item;
|
||||
@ -165,19 +165,19 @@ create_model (void)
|
||||
++i;
|
||||
}
|
||||
g_free (sizes);
|
||||
|
||||
info.small_icon = gtk_widget_render_icon_pixbuf (window,
|
||||
|
||||
info.small_icon = gtk_widget_render_icon_pixbuf (window,
|
||||
info.id,
|
||||
size);
|
||||
|
||||
|
||||
if (size != GTK_ICON_SIZE_MENU)
|
||||
{
|
||||
/* Make the result the proper size for our thumbnail */
|
||||
gint w, h;
|
||||
GdkPixbuf *scaled;
|
||||
|
||||
|
||||
gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &w, &h);
|
||||
|
||||
|
||||
scaled = gdk_pixbuf_scale_simple (info.small_icon,
|
||||
w, h,
|
||||
GDK_INTERP_BILINEAR);
|
||||
@ -200,7 +200,7 @@ create_model (void)
|
||||
}
|
||||
|
||||
info.macro = id_to_macro (info.id);
|
||||
|
||||
|
||||
gtk_list_store_append (store, &iter);
|
||||
gtk_list_store_set (store, &iter, 0, &info, 1, info.id, -1);
|
||||
|
||||
@ -208,10 +208,10 @@ create_model (void)
|
||||
g_free (info.accel_str);
|
||||
if (info.small_icon)
|
||||
g_object_unref (info.small_icon);
|
||||
|
||||
|
||||
tmp_list = g_slist_next (tmp_list);
|
||||
}
|
||||
|
||||
|
||||
g_slist_foreach (ids, (GFunc)g_free, NULL);
|
||||
g_slist_free (ids);
|
||||
|
||||
@ -235,16 +235,16 @@ get_largest_size (const char *id)
|
||||
for (i = 0; i < n_sizes; i++)
|
||||
{
|
||||
gint width, height;
|
||||
|
||||
|
||||
gtk_icon_size_lookup (sizes[i], &width, &height);
|
||||
|
||||
if (width * height > best_pixels)
|
||||
{
|
||||
best_size = sizes[i];
|
||||
best_pixels = width * height;
|
||||
}
|
||||
{
|
||||
best_size = sizes[i];
|
||||
best_pixels = width * height;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
g_free (sizes);
|
||||
|
||||
return best_size;
|
||||
@ -257,7 +257,7 @@ selection_changed (GtkTreeSelection *selection)
|
||||
StockItemDisplay *display;
|
||||
GtkTreeModel *model;
|
||||
GtkTreeIter iter;
|
||||
|
||||
|
||||
treeview = gtk_tree_selection_get_tree_view (selection);
|
||||
display = g_object_get_data (G_OBJECT (treeview), "stock-display");
|
||||
|
||||
@ -265,7 +265,7 @@ selection_changed (GtkTreeSelection *selection)
|
||||
{
|
||||
StockItemInfo *info;
|
||||
gchar *str;
|
||||
|
||||
|
||||
gtk_tree_model_get (model, &iter,
|
||||
0, &info,
|
||||
-1);
|
||||
@ -313,21 +313,21 @@ selection_changed (GtkTreeSelection *selection)
|
||||
|
||||
static void
|
||||
macro_set_func_text (GtkTreeViewColumn *tree_column,
|
||||
GtkCellRenderer *cell,
|
||||
GtkTreeModel *model,
|
||||
GtkTreeIter *iter,
|
||||
gpointer data)
|
||||
GtkCellRenderer *cell,
|
||||
GtkTreeModel *model,
|
||||
GtkTreeIter *iter,
|
||||
gpointer data)
|
||||
{
|
||||
StockItemInfo *info;
|
||||
|
||||
|
||||
gtk_tree_model_get (model, iter,
|
||||
0, &info,
|
||||
-1);
|
||||
|
||||
|
||||
g_object_set (GTK_CELL_RENDERER (cell),
|
||||
"text", info->macro,
|
||||
NULL);
|
||||
|
||||
|
||||
stock_item_info_free (info);
|
||||
}
|
||||
|
||||
@ -339,15 +339,15 @@ id_set_func (GtkTreeViewColumn *tree_column,
|
||||
gpointer data)
|
||||
{
|
||||
StockItemInfo *info;
|
||||
|
||||
|
||||
gtk_tree_model_get (model, iter,
|
||||
0, &info,
|
||||
-1);
|
||||
|
||||
|
||||
g_object_set (GTK_CELL_RENDERER (cell),
|
||||
"text", info->id,
|
||||
NULL);
|
||||
|
||||
|
||||
stock_item_info_free (info);
|
||||
}
|
||||
|
||||
@ -359,15 +359,15 @@ accel_set_func (GtkTreeViewColumn *tree_column,
|
||||
gpointer data)
|
||||
{
|
||||
StockItemInfo *info;
|
||||
|
||||
|
||||
gtk_tree_model_get (model, iter,
|
||||
0, &info,
|
||||
-1);
|
||||
|
||||
|
||||
g_object_set (GTK_CELL_RENDERER (cell),
|
||||
"text", info->accel_str,
|
||||
NULL);
|
||||
|
||||
|
||||
stock_item_info_free (info);
|
||||
}
|
||||
|
||||
@ -379,15 +379,15 @@ label_set_func (GtkTreeViewColumn *tree_column,
|
||||
gpointer data)
|
||||
{
|
||||
StockItemInfo *info;
|
||||
|
||||
|
||||
gtk_tree_model_get (model, iter,
|
||||
0, &info,
|
||||
-1);
|
||||
|
||||
|
||||
g_object_set (GTK_CELL_RENDERER (cell),
|
||||
"text", info->item.label,
|
||||
NULL);
|
||||
|
||||
|
||||
stock_item_info_free (info);
|
||||
}
|
||||
|
||||
@ -409,7 +409,7 @@ do_stock_browser (GtkWidget *do_widget)
|
||||
|
||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_screen (GTK_WINDOW (window),
|
||||
gtk_widget_get_screen (do_widget));
|
||||
gtk_widget_get_screen (do_widget));
|
||||
gtk_window_set_title (GTK_WINDOW (window), "Stock Icons and Items");
|
||||
gtk_window_set_default_size (GTK_WINDOW (window), -1, 500);
|
||||
|
||||
@ -426,31 +426,31 @@ do_stock_browser (GtkWidget *do_widget)
|
||||
gtk_box_pack_start (GTK_BOX (hbox), sw, FALSE, FALSE, 0);
|
||||
|
||||
model = create_model ();
|
||||
|
||||
|
||||
treeview = gtk_tree_view_new_with_model (model);
|
||||
|
||||
g_object_unref (model);
|
||||
|
||||
gtk_container_add (GTK_CONTAINER (sw), treeview);
|
||||
|
||||
|
||||
column = gtk_tree_view_column_new ();
|
||||
gtk_tree_view_column_set_title (column, "Macro");
|
||||
|
||||
cell_renderer = gtk_cell_renderer_pixbuf_new ();
|
||||
gtk_tree_view_column_pack_start (column,
|
||||
cell_renderer,
|
||||
FALSE);
|
||||
cell_renderer,
|
||||
FALSE);
|
||||
gtk_tree_view_column_set_attributes (column, cell_renderer,
|
||||
"stock_id", 1, NULL);
|
||||
"stock_id", 1, NULL);
|
||||
cell_renderer = gtk_cell_renderer_text_new ();
|
||||
gtk_tree_view_column_pack_start (column,
|
||||
cell_renderer,
|
||||
TRUE);
|
||||
cell_renderer,
|
||||
TRUE);
|
||||
gtk_tree_view_column_set_cell_data_func (column, cell_renderer,
|
||||
macro_set_func_text, NULL, NULL);
|
||||
macro_set_func_text, NULL, NULL);
|
||||
|
||||
gtk_tree_view_append_column (GTK_TREE_VIEW (treeview),
|
||||
column);
|
||||
column);
|
||||
|
||||
cell_renderer = gtk_cell_renderer_text_new ();
|
||||
gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (treeview),
|
||||
@ -492,7 +492,7 @@ do_stock_browser (GtkWidget *do_widget)
|
||||
"stock-display",
|
||||
display,
|
||||
g_free); /* free display with treeview */
|
||||
|
||||
|
||||
display->type_label = gtk_label_new (NULL);
|
||||
display->macro_label = gtk_label_new (NULL);
|
||||
display->id_label = gtk_label_new (NULL);
|
||||
@ -504,7 +504,7 @@ do_stock_browser (GtkWidget *do_widget)
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (vbox), display->icon_image,
|
||||
FALSE, FALSE, 0);
|
||||
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (vbox), display->label_accel_label,
|
||||
FALSE, FALSE, 0);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), display->macro_label,
|
||||
@ -514,11 +514,11 @@ do_stock_browser (GtkWidget *do_widget)
|
||||
|
||||
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
|
||||
gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
|
||||
|
||||
|
||||
g_signal_connect (selection,
|
||||
"changed",
|
||||
G_CALLBACK (selection_changed),
|
||||
NULL);
|
||||
"changed",
|
||||
G_CALLBACK (selection_changed),
|
||||
NULL);
|
||||
}
|
||||
|
||||
if (!gtk_widget_get_visible (window))
|
||||
@ -526,7 +526,7 @@ do_stock_browser (GtkWidget *do_widget)
|
||||
gtk_widget_show_all (window);
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
gtk_widget_destroy (window);
|
||||
window = NULL;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* Text Widget/Automatic scrolling
|
||||
*
|
||||
* This example demonstrates how to use the gravity of
|
||||
* This example demonstrates how to use the gravity of
|
||||
* GtkTextMarks to keep a text view scrolled to the bottom
|
||||
* while appending text.
|
||||
*/
|
||||
@ -20,14 +20,14 @@ scroll_to_end (GtkTextView *textview)
|
||||
static int count;
|
||||
|
||||
buffer = gtk_text_view_get_buffer (textview);
|
||||
|
||||
/* Get "end" mark. It's located at the end of buffer because
|
||||
|
||||
/* Get "end" mark. It's located at the end of buffer because
|
||||
* of right gravity
|
||||
*/
|
||||
mark = gtk_text_buffer_get_mark (buffer, "end");
|
||||
gtk_text_buffer_get_iter_at_mark (buffer, &iter, mark);
|
||||
|
||||
/* and insert some text at its position, the iter will be
|
||||
/* and insert some text at its position, the iter will be
|
||||
* revalidated after insertion to point to the end of inserted text
|
||||
*/
|
||||
spaces = g_strnfill (count++, ' ');
|
||||
@ -43,7 +43,7 @@ scroll_to_end (GtkTextView *textview)
|
||||
*/
|
||||
gtk_text_view_scroll_mark_onscreen (textview, mark);
|
||||
|
||||
/* Emulate typewriter behavior, shift to the left if we
|
||||
/* Emulate typewriter behavior, shift to the left if we
|
||||
* are far enough to the right.
|
||||
*/
|
||||
if (count > 150)
|
||||
@ -64,7 +64,7 @@ scroll_to_bottom (GtkTextView *textview)
|
||||
static int count;
|
||||
|
||||
buffer = gtk_text_view_get_buffer (textview);
|
||||
|
||||
|
||||
/* Get end iterator */
|
||||
gtk_text_buffer_get_end_iter (buffer, &iter);
|
||||
|
||||
@ -80,17 +80,17 @@ scroll_to_bottom (GtkTextView *textview)
|
||||
-1);
|
||||
g_free (spaces);
|
||||
|
||||
/* Move the iterator to the beginning of line, so we don't scroll
|
||||
* in horizontal direction
|
||||
/* Move the iterator to the beginning of line, so we don't scroll
|
||||
* in horizontal direction
|
||||
*/
|
||||
gtk_text_iter_set_line_offset (&iter, 0);
|
||||
|
||||
|
||||
/* and place the mark at iter. the mark will stay there after we
|
||||
* insert some text at the end because it has right gravity.
|
||||
*/
|
||||
mark = gtk_text_buffer_get_mark (buffer, "scroll");
|
||||
gtk_text_buffer_move_mark (buffer, mark, &iter);
|
||||
|
||||
|
||||
/* Scroll the mark onscreen.
|
||||
*/
|
||||
gtk_text_view_scroll_mark_onscreen (textview, mark);
|
||||
@ -114,30 +114,30 @@ setup_scroll (GtkTextView *textview,
|
||||
gtk_text_buffer_get_end_iter (buffer, &iter);
|
||||
|
||||
if (to_end)
|
||||
{
|
||||
/* If we want to scroll to the end, including horizontal scrolling,
|
||||
* then we just create a mark with right gravity at the end of the
|
||||
* buffer. It will stay at the end unless explicitely moved with
|
||||
* gtk_text_buffer_move_mark.
|
||||
*/
|
||||
gtk_text_buffer_create_mark (buffer, "end", &iter, FALSE);
|
||||
|
||||
/* Add scrolling timeout. */
|
||||
return g_timeout_add (50, (GSourceFunc) scroll_to_end, textview);
|
||||
}
|
||||
{
|
||||
/* If we want to scroll to the end, including horizontal scrolling,
|
||||
* then we just create a mark with right gravity at the end of the
|
||||
* buffer. It will stay at the end unless explicitely moved with
|
||||
* gtk_text_buffer_move_mark.
|
||||
*/
|
||||
gtk_text_buffer_create_mark (buffer, "end", &iter, FALSE);
|
||||
|
||||
/* Add scrolling timeout. */
|
||||
return g_timeout_add (50, (GSourceFunc) scroll_to_end, textview);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* If we want to scroll to the bottom, but not scroll horizontally,
|
||||
* then an end mark won't do the job. Just create a mark so we can
|
||||
* use it with gtk_text_view_scroll_mark_onscreen, we'll position it
|
||||
* explicitely when needed. Use left gravity so the mark stays where
|
||||
* we put it after inserting new text.
|
||||
*/
|
||||
gtk_text_buffer_create_mark (buffer, "scroll", &iter, TRUE);
|
||||
|
||||
/* Add scrolling timeout. */
|
||||
return g_timeout_add (100, (GSourceFunc) scroll_to_bottom, textview);
|
||||
}
|
||||
{
|
||||
/* If we want to scroll to the bottom, but not scroll horizontally,
|
||||
* then an end mark won't do the job. Just create a mark so we can
|
||||
* use it with gtk_text_view_scroll_mark_onscreen, we'll position it
|
||||
* explicitely when needed. Use left gravity so the mark stays where
|
||||
* we put it after inserting new text.
|
||||
*/
|
||||
gtk_text_buffer_create_mark (buffer, "scroll", &iter, TRUE);
|
||||
|
||||
/* Add scrolling timeout. */
|
||||
return g_timeout_add (100, (GSourceFunc) scroll_to_bottom, textview);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
@ -163,7 +163,7 @@ create_text_view (GtkWidget *hbox,
|
||||
timeout = setup_scroll (GTK_TEXT_VIEW (textview), to_end);
|
||||
|
||||
/* Remove the timeout in destroy handler, so we don't try to
|
||||
* scroll destroyed widget.
|
||||
* scroll destroyed widget.
|
||||
*/
|
||||
g_signal_connect (textview, "destroy",
|
||||
G_CALLBACK (remove_timeout),
|
||||
@ -181,9 +181,9 @@ do_textscroll (GtkWidget *do_widget)
|
||||
|
||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
g_signal_connect (window, "destroy",
|
||||
G_CALLBACK (gtk_widget_destroyed), &window);
|
||||
G_CALLBACK (gtk_widget_destroyed), &window);
|
||||
gtk_window_set_default_size (GTK_WINDOW (window), 600, 400);
|
||||
|
||||
|
||||
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
|
||||
gtk_box_set_homogeneous (GTK_BOX (hbox), TRUE);
|
||||
gtk_container_add (GTK_CONTAINER (window), hbox);
|
||||
@ -193,9 +193,9 @@ do_textscroll (GtkWidget *do_widget)
|
||||
}
|
||||
|
||||
if (!gtk_widget_get_visible (window))
|
||||
gtk_widget_show_all (window);
|
||||
gtk_widget_show_all (window);
|
||||
else
|
||||
gtk_widget_destroy (window);
|
||||
gtk_widget_destroy (window);
|
||||
|
||||
return window;
|
||||
}
|
||||
|
@ -632,4 +632,3 @@ easter_egg_callback (GtkWidget *button,
|
||||
|
||||
gtk_widget_show_all (window);
|
||||
}
|
||||
|
||||
|
@ -170,14 +170,14 @@ create_model (void)
|
||||
|
||||
/* create tree store */
|
||||
model = gtk_tree_store_new (NUM_COLUMNS,
|
||||
G_TYPE_STRING,
|
||||
G_TYPE_BOOLEAN,
|
||||
G_TYPE_BOOLEAN,
|
||||
G_TYPE_BOOLEAN,
|
||||
G_TYPE_BOOLEAN,
|
||||
G_TYPE_BOOLEAN,
|
||||
G_TYPE_BOOLEAN,
|
||||
G_TYPE_BOOLEAN);
|
||||
G_TYPE_STRING,
|
||||
G_TYPE_BOOLEAN,
|
||||
G_TYPE_BOOLEAN,
|
||||
G_TYPE_BOOLEAN,
|
||||
G_TYPE_BOOLEAN,
|
||||
G_TYPE_BOOLEAN,
|
||||
G_TYPE_BOOLEAN,
|
||||
G_TYPE_BOOLEAN);
|
||||
|
||||
/* add data to the tree store */
|
||||
while (month->label)
|
||||
@ -186,35 +186,35 @@ create_model (void)
|
||||
|
||||
gtk_tree_store_append (model, &iter, NULL);
|
||||
gtk_tree_store_set (model, &iter,
|
||||
HOLIDAY_NAME_COLUMN, month->label,
|
||||
ALEX_COLUMN, FALSE,
|
||||
HAVOC_COLUMN, FALSE,
|
||||
TIM_COLUMN, FALSE,
|
||||
OWEN_COLUMN, FALSE,
|
||||
DAVE_COLUMN, FALSE,
|
||||
VISIBLE_COLUMN, FALSE,
|
||||
WORLD_COLUMN, FALSE,
|
||||
-1);
|
||||
HOLIDAY_NAME_COLUMN, month->label,
|
||||
ALEX_COLUMN, FALSE,
|
||||
HAVOC_COLUMN, FALSE,
|
||||
TIM_COLUMN, FALSE,
|
||||
OWEN_COLUMN, FALSE,
|
||||
DAVE_COLUMN, FALSE,
|
||||
VISIBLE_COLUMN, FALSE,
|
||||
WORLD_COLUMN, FALSE,
|
||||
-1);
|
||||
|
||||
/* add children */
|
||||
while (holiday->label)
|
||||
{
|
||||
GtkTreeIter child_iter;
|
||||
{
|
||||
GtkTreeIter child_iter;
|
||||
|
||||
gtk_tree_store_append (model, &child_iter, &iter);
|
||||
gtk_tree_store_set (model, &child_iter,
|
||||
HOLIDAY_NAME_COLUMN, holiday->label,
|
||||
ALEX_COLUMN, holiday->alex,
|
||||
HAVOC_COLUMN, holiday->havoc,
|
||||
TIM_COLUMN, holiday->tim,
|
||||
OWEN_COLUMN, holiday->owen,
|
||||
DAVE_COLUMN, holiday->dave,
|
||||
VISIBLE_COLUMN, TRUE,
|
||||
WORLD_COLUMN, holiday->world_holiday,
|
||||
-1);
|
||||
gtk_tree_store_append (model, &child_iter, &iter);
|
||||
gtk_tree_store_set (model, &child_iter,
|
||||
HOLIDAY_NAME_COLUMN, holiday->label,
|
||||
ALEX_COLUMN, holiday->alex,
|
||||
HAVOC_COLUMN, holiday->havoc,
|
||||
TIM_COLUMN, holiday->tim,
|
||||
OWEN_COLUMN, holiday->owen,
|
||||
DAVE_COLUMN, holiday->dave,
|
||||
VISIBLE_COLUMN, TRUE,
|
||||
WORLD_COLUMN, holiday->world_holiday,
|
||||
-1);
|
||||
|
||||
holiday++;
|
||||
}
|
||||
holiday++;
|
||||
}
|
||||
|
||||
month++;
|
||||
}
|
||||
@ -224,8 +224,8 @@ create_model (void)
|
||||
|
||||
static void
|
||||
item_toggled (GtkCellRendererToggle *cell,
|
||||
gchar *path_str,
|
||||
gpointer data)
|
||||
gchar *path_str,
|
||||
gpointer data)
|
||||
{
|
||||
GtkTreeModel *model = (GtkTreeModel *)data;
|
||||
GtkTreePath *path = gtk_tree_path_new_from_string (path_str);
|
||||
@ -245,7 +245,7 @@ item_toggled (GtkCellRendererToggle *cell,
|
||||
|
||||
/* set new value */
|
||||
gtk_tree_store_set (GTK_TREE_STORE (model), &iter, column,
|
||||
toggle_item, -1);
|
||||
toggle_item, -1);
|
||||
|
||||
/* clean up */
|
||||
gtk_tree_path_free (path);
|
||||
@ -264,10 +264,10 @@ add_columns (GtkTreeView *treeview)
|
||||
g_object_set (renderer, "xalign", 0.0, NULL);
|
||||
|
||||
col_offset = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
|
||||
-1, "Holiday",
|
||||
renderer, "text",
|
||||
HOLIDAY_NAME_COLUMN,
|
||||
NULL);
|
||||
-1, "Holiday",
|
||||
renderer, "text",
|
||||
HOLIDAY_NAME_COLUMN,
|
||||
NULL);
|
||||
column = gtk_tree_view_get_column (GTK_TREE_VIEW (treeview), col_offset - 1);
|
||||
gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
|
||||
|
||||
@ -279,18 +279,18 @@ add_columns (GtkTreeView *treeview)
|
||||
g_signal_connect (renderer, "toggled", G_CALLBACK (item_toggled), model);
|
||||
|
||||
col_offset = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
|
||||
-1, "Alex",
|
||||
renderer,
|
||||
"active",
|
||||
ALEX_COLUMN,
|
||||
"visible",
|
||||
VISIBLE_COLUMN,
|
||||
"activatable",
|
||||
WORLD_COLUMN, NULL);
|
||||
-1, "Alex",
|
||||
renderer,
|
||||
"active",
|
||||
ALEX_COLUMN,
|
||||
"visible",
|
||||
VISIBLE_COLUMN,
|
||||
"activatable",
|
||||
WORLD_COLUMN, NULL);
|
||||
|
||||
column = gtk_tree_view_get_column (GTK_TREE_VIEW (treeview), col_offset - 1);
|
||||
gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column),
|
||||
GTK_TREE_VIEW_COLUMN_FIXED);
|
||||
GTK_TREE_VIEW_COLUMN_FIXED);
|
||||
gtk_tree_view_column_set_fixed_width (GTK_TREE_VIEW_COLUMN (column), 50);
|
||||
gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
|
||||
|
||||
@ -302,17 +302,17 @@ add_columns (GtkTreeView *treeview)
|
||||
g_signal_connect (renderer, "toggled", G_CALLBACK (item_toggled), model);
|
||||
|
||||
col_offset = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
|
||||
-1, "Havoc",
|
||||
renderer,
|
||||
"active",
|
||||
HAVOC_COLUMN,
|
||||
"visible",
|
||||
VISIBLE_COLUMN,
|
||||
NULL);
|
||||
-1, "Havoc",
|
||||
renderer,
|
||||
"active",
|
||||
HAVOC_COLUMN,
|
||||
"visible",
|
||||
VISIBLE_COLUMN,
|
||||
NULL);
|
||||
|
||||
column = gtk_tree_view_get_column (GTK_TREE_VIEW (treeview), col_offset - 1);
|
||||
gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column),
|
||||
GTK_TREE_VIEW_COLUMN_FIXED);
|
||||
GTK_TREE_VIEW_COLUMN_FIXED);
|
||||
gtk_tree_view_column_set_fixed_width (GTK_TREE_VIEW_COLUMN (column), 50);
|
||||
gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
|
||||
|
||||
@ -324,18 +324,18 @@ add_columns (GtkTreeView *treeview)
|
||||
g_signal_connect (renderer, "toggled", G_CALLBACK (item_toggled), model);
|
||||
|
||||
col_offset = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
|
||||
-1, "Tim",
|
||||
renderer,
|
||||
"active",
|
||||
TIM_COLUMN,
|
||||
"visible",
|
||||
VISIBLE_COLUMN,
|
||||
"activatable",
|
||||
WORLD_COLUMN, NULL);
|
||||
-1, "Tim",
|
||||
renderer,
|
||||
"active",
|
||||
TIM_COLUMN,
|
||||
"visible",
|
||||
VISIBLE_COLUMN,
|
||||
"activatable",
|
||||
WORLD_COLUMN, NULL);
|
||||
|
||||
column = gtk_tree_view_get_column (GTK_TREE_VIEW (treeview), col_offset - 1);
|
||||
gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column),
|
||||
GTK_TREE_VIEW_COLUMN_FIXED);
|
||||
GTK_TREE_VIEW_COLUMN_FIXED);
|
||||
gtk_tree_view_column_set_fixed_width (GTK_TREE_VIEW_COLUMN (column), 50);
|
||||
gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
|
||||
|
||||
@ -347,17 +347,17 @@ add_columns (GtkTreeView *treeview)
|
||||
g_signal_connect (renderer, "toggled", G_CALLBACK (item_toggled), model);
|
||||
|
||||
col_offset = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
|
||||
-1, "Owen",
|
||||
renderer,
|
||||
"active",
|
||||
OWEN_COLUMN,
|
||||
"visible",
|
||||
VISIBLE_COLUMN,
|
||||
NULL);
|
||||
-1, "Owen",
|
||||
renderer,
|
||||
"active",
|
||||
OWEN_COLUMN,
|
||||
"visible",
|
||||
VISIBLE_COLUMN,
|
||||
NULL);
|
||||
|
||||
column = gtk_tree_view_get_column (GTK_TREE_VIEW (treeview), col_offset - 1);
|
||||
gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column),
|
||||
GTK_TREE_VIEW_COLUMN_FIXED);
|
||||
GTK_TREE_VIEW_COLUMN_FIXED);
|
||||
gtk_tree_view_column_set_fixed_width (GTK_TREE_VIEW_COLUMN (column), 50);
|
||||
gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
|
||||
|
||||
@ -369,17 +369,17 @@ add_columns (GtkTreeView *treeview)
|
||||
g_signal_connect (renderer, "toggled", G_CALLBACK (item_toggled), model);
|
||||
|
||||
col_offset = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
|
||||
-1, "Dave",
|
||||
renderer,
|
||||
"active",
|
||||
DAVE_COLUMN,
|
||||
"visible",
|
||||
VISIBLE_COLUMN,
|
||||
NULL);
|
||||
-1, "Dave",
|
||||
renderer,
|
||||
"active",
|
||||
DAVE_COLUMN,
|
||||
"visible",
|
||||
VISIBLE_COLUMN,
|
||||
NULL);
|
||||
|
||||
column = gtk_tree_view_get_column (GTK_TREE_VIEW (treeview), col_offset - 1);
|
||||
gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column),
|
||||
GTK_TREE_VIEW_COLUMN_FIXED);
|
||||
GTK_TREE_VIEW_COLUMN_FIXED);
|
||||
gtk_tree_view_column_set_fixed_width (GTK_TREE_VIEW_COLUMN (column), 50);
|
||||
gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
|
||||
}
|
||||
@ -397,25 +397,25 @@ do_tree_store (GtkWidget *do_widget)
|
||||
/* create window, etc */
|
||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_screen (GTK_WINDOW (window),
|
||||
gtk_widget_get_screen (do_widget));
|
||||
gtk_widget_get_screen (do_widget));
|
||||
gtk_window_set_title (GTK_WINDOW (window), "Card planning sheet");
|
||||
g_signal_connect (window, "destroy",
|
||||
G_CALLBACK (gtk_widget_destroyed), &window);
|
||||
G_CALLBACK (gtk_widget_destroyed), &window);
|
||||
|
||||
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (vbox), 8);
|
||||
gtk_container_add (GTK_CONTAINER (window), vbox);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (vbox),
|
||||
gtk_label_new ("Jonathan's Holiday Card Planning Sheet"),
|
||||
FALSE, FALSE, 0);
|
||||
gtk_label_new ("Jonathan's Holiday Card Planning Sheet"),
|
||||
FALSE, FALSE, 0);
|
||||
|
||||
sw = gtk_scrolled_window_new (NULL, NULL);
|
||||
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
|
||||
GTK_SHADOW_ETCHED_IN);
|
||||
GTK_SHADOW_ETCHED_IN);
|
||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
|
||||
GTK_POLICY_AUTOMATIC,
|
||||
GTK_POLICY_AUTOMATIC);
|
||||
GTK_POLICY_AUTOMATIC,
|
||||
GTK_POLICY_AUTOMATIC);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0);
|
||||
|
||||
/* create model */
|
||||
@ -426,7 +426,7 @@ do_tree_store (GtkWidget *do_widget)
|
||||
g_object_unref (model);
|
||||
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (treeview), TRUE);
|
||||
gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)),
|
||||
GTK_SELECTION_MULTIPLE);
|
||||
GTK_SELECTION_MULTIPLE);
|
||||
|
||||
add_columns (GTK_TREE_VIEW (treeview));
|
||||
|
||||
@ -434,7 +434,7 @@ do_tree_store (GtkWidget *do_widget)
|
||||
|
||||
/* expand all rows after the treeview widget has been realized */
|
||||
g_signal_connect (treeview, "realize",
|
||||
G_CALLBACK (gtk_tree_view_expand_all), NULL);
|
||||
G_CALLBACK (gtk_tree_view_expand_all), NULL);
|
||||
gtk_window_set_default_size (GTK_WINDOW (window), 650, 400);
|
||||
}
|
||||
|
||||
|
@ -15,8 +15,8 @@ activate_action (GtkAction *action)
|
||||
static void
|
||||
activate_radio_action (GtkAction *action, GtkRadioAction *current)
|
||||
{
|
||||
g_message ("Radio action \"%s\" selected",
|
||||
gtk_action_get_name (GTK_ACTION (current)));
|
||||
g_message ("Radio action \"%s\" selected",
|
||||
gtk_action_get_name (GTK_ACTION (current)));
|
||||
}
|
||||
|
||||
static GtkActionEntry entries[] = {
|
||||
@ -27,30 +27,30 @@ static GtkActionEntry entries[] = {
|
||||
{ "HelpMenu", NULL, "_Help" }, /* name, stock id, label */
|
||||
{ "New", GTK_STOCK_NEW, /* name, stock id */
|
||||
"_New", "<control>N", /* label, accelerator */
|
||||
"Create a new file", /* tooltip */
|
||||
G_CALLBACK (activate_action) },
|
||||
"Create a new file", /* tooltip */
|
||||
G_CALLBACK (activate_action) },
|
||||
{ "Open", GTK_STOCK_OPEN, /* name, stock id */
|
||||
"_Open","<control>O", /* label, accelerator */
|
||||
"_Open","<control>O", /* label, accelerator */
|
||||
"Open a file", /* tooltip */
|
||||
G_CALLBACK (activate_action) },
|
||||
G_CALLBACK (activate_action) },
|
||||
{ "Save", GTK_STOCK_SAVE, /* name, stock id */
|
||||
"_Save","<control>S", /* label, accelerator */
|
||||
"_Save","<control>S", /* label, accelerator */
|
||||
"Save current file", /* tooltip */
|
||||
G_CALLBACK (activate_action) },
|
||||
{ "SaveAs", GTK_STOCK_SAVE, /* name, stock id */
|
||||
"Save _As...", NULL, /* label, accelerator */
|
||||
"Save _As...", NULL, /* label, accelerator */
|
||||
"Save to a file", /* tooltip */
|
||||
G_CALLBACK (activate_action) },
|
||||
{ "Quit", GTK_STOCK_QUIT, /* name, stock id */
|
||||
"_Quit", "<control>Q", /* label, accelerator */
|
||||
"_Quit", "<control>Q", /* label, accelerator */
|
||||
"Quit", /* tooltip */
|
||||
G_CALLBACK (activate_action) },
|
||||
{ "About", NULL, /* name, stock id */
|
||||
"_About", "<control>A", /* label, accelerator */
|
||||
"About", /* tooltip */
|
||||
"_About", "<control>A", /* label, accelerator */
|
||||
"About", /* tooltip */
|
||||
G_CALLBACK (activate_action) },
|
||||
{ "Logo", "demo-gtk-logo", /* name, stock id */
|
||||
NULL, NULL, /* label, accelerator */
|
||||
NULL, NULL, /* label, accelerator */
|
||||
"GTK+", /* tooltip */
|
||||
G_CALLBACK (activate_action) },
|
||||
};
|
||||
@ -59,9 +59,9 @@ static guint n_entries = G_N_ELEMENTS (entries);
|
||||
|
||||
static GtkToggleActionEntry toggle_entries[] = {
|
||||
{ "Bold", GTK_STOCK_BOLD, /* name, stock id */
|
||||
"_Bold", "<control>B", /* label, accelerator */
|
||||
"_Bold", "<control>B", /* label, accelerator */
|
||||
"Bold", /* tooltip */
|
||||
G_CALLBACK (activate_action),
|
||||
G_CALLBACK (activate_action),
|
||||
TRUE }, /* is_active */
|
||||
};
|
||||
static guint n_toggle_entries = G_N_ELEMENTS (toggle_entries);
|
||||
@ -74,13 +74,13 @@ enum {
|
||||
|
||||
static GtkRadioActionEntry color_entries[] = {
|
||||
{ "Red", NULL, /* name, stock id */
|
||||
"_Red", "<control>R", /* label, accelerator */
|
||||
"_Red", "<control>R", /* label, accelerator */
|
||||
"Blood", COLOR_RED }, /* tooltip, value */
|
||||
{ "Green", NULL, /* name, stock id */
|
||||
"_Green", "<control>G", /* label, accelerator */
|
||||
"_Green", "<control>G", /* label, accelerator */
|
||||
"Grass", COLOR_GREEN }, /* tooltip, value */
|
||||
{ "Blue", NULL, /* name, stock id */
|
||||
"_Blue", "<control>B", /* label, accelerator */
|
||||
"_Blue", "<control>B", /* label, accelerator */
|
||||
"Sky", COLOR_BLUE }, /* tooltip, value */
|
||||
};
|
||||
static guint n_color_entries = G_N_ELEMENTS (color_entries);
|
||||
@ -93,18 +93,18 @@ enum {
|
||||
|
||||
static GtkRadioActionEntry shape_entries[] = {
|
||||
{ "Square", NULL, /* name, stock id */
|
||||
"_Square", "<control>S", /* label, accelerator */
|
||||
"_Square", "<control>S", /* label, accelerator */
|
||||
"Square", SHAPE_SQUARE }, /* tooltip, value */
|
||||
{ "Rectangle", NULL, /* name, stock id */
|
||||
"_Rectangle", "<control>R", /* label, accelerator */
|
||||
"_Rectangle", "<control>R", /* label, accelerator */
|
||||
"Rectangle", SHAPE_RECTANGLE }, /* tooltip, value */
|
||||
{ "Oval", NULL, /* name, stock id */
|
||||
"_Oval", "<control>O", /* label, accelerator */
|
||||
"Egg", SHAPE_OVAL }, /* tooltip, value */
|
||||
"_Oval", "<control>O", /* label, accelerator */
|
||||
"Egg", SHAPE_OVAL }, /* tooltip, value */
|
||||
};
|
||||
static guint n_shape_entries = G_N_ELEMENTS (shape_entries);
|
||||
|
||||
static const gchar *ui_info =
|
||||
static const gchar *ui_info =
|
||||
"<ui>"
|
||||
" <menubar name='MenuBar'>"
|
||||
" <menu action='FileMenu'>"
|
||||
@ -117,9 +117,9 @@ static const gchar *ui_info =
|
||||
" </menu>"
|
||||
" <menu action='PreferencesMenu'>"
|
||||
" <menu action='ColorMenu'>"
|
||||
" <menuitem action='Red'/>"
|
||||
" <menuitem action='Green'/>"
|
||||
" <menuitem action='Blue'/>"
|
||||
" <menuitem action='Red'/>"
|
||||
" <menuitem action='Green'/>"
|
||||
" <menuitem action='Blue'/>"
|
||||
" </menu>"
|
||||
" <menu action='ShapeMenu'>"
|
||||
" <menuitem action='Square'/>"
|
||||
@ -144,7 +144,7 @@ GtkWidget *
|
||||
do_ui_manager (GtkWidget *do_widget)
|
||||
{
|
||||
static GtkWidget *window = NULL;
|
||||
|
||||
|
||||
if (!window)
|
||||
{
|
||||
GtkWidget *box1;
|
||||
@ -158,50 +158,49 @@ do_ui_manager (GtkWidget *do_widget)
|
||||
|
||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_screen (GTK_WINDOW (window),
|
||||
gtk_widget_get_screen (do_widget));
|
||||
|
||||
gtk_widget_get_screen (do_widget));
|
||||
|
||||
g_signal_connect (window, "destroy",
|
||||
G_CALLBACK (gtk_widget_destroyed), &window);
|
||||
G_CALLBACK (gtk_widget_destroyed), &window);
|
||||
g_signal_connect (window, "delete-event",
|
||||
G_CALLBACK (gtk_true), NULL);
|
||||
G_CALLBACK (gtk_true), NULL);
|
||||
|
||||
actions = gtk_action_group_new ("Actions");
|
||||
gtk_action_group_add_actions (actions, entries, n_entries, NULL);
|
||||
gtk_action_group_add_toggle_actions (actions,
|
||||
toggle_entries, n_toggle_entries,
|
||||
NULL);
|
||||
gtk_action_group_add_radio_actions (actions,
|
||||
color_entries, n_color_entries,
|
||||
COLOR_RED,
|
||||
G_CALLBACK (activate_radio_action),
|
||||
NULL);
|
||||
gtk_action_group_add_radio_actions (actions,
|
||||
shape_entries, n_shape_entries,
|
||||
SHAPE_OVAL,
|
||||
G_CALLBACK (activate_radio_action),
|
||||
NULL);
|
||||
gtk_action_group_add_toggle_actions (actions,
|
||||
toggle_entries, n_toggle_entries,
|
||||
NULL);
|
||||
gtk_action_group_add_radio_actions (actions,
|
||||
color_entries, n_color_entries,
|
||||
COLOR_RED,
|
||||
G_CALLBACK (activate_radio_action),
|
||||
NULL);
|
||||
gtk_action_group_add_radio_actions (actions,
|
||||
shape_entries, n_shape_entries,
|
||||
SHAPE_OVAL,
|
||||
G_CALLBACK (activate_radio_action),
|
||||
NULL);
|
||||
|
||||
ui = gtk_ui_manager_new ();
|
||||
gtk_ui_manager_insert_action_group (ui, actions, 0);
|
||||
g_object_unref (actions);
|
||||
gtk_window_add_accel_group (GTK_WINDOW (window),
|
||||
gtk_ui_manager_get_accel_group (ui));
|
||||
gtk_window_add_accel_group (GTK_WINDOW (window),
|
||||
gtk_ui_manager_get_accel_group (ui));
|
||||
gtk_window_set_title (GTK_WINDOW (window), "UI Manager");
|
||||
gtk_container_set_border_width (GTK_CONTAINER (window), 0);
|
||||
|
||||
|
||||
if (!gtk_ui_manager_add_ui_from_string (ui, ui_info, -1, &error))
|
||||
{
|
||||
g_message ("building menus failed: %s", error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
{
|
||||
g_message ("building menus failed: %s", error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
box1 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
||||
gtk_container_add (GTK_CONTAINER (window), box1);
|
||||
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (box1),
|
||||
gtk_ui_manager_get_widget (ui, "/MenuBar"),
|
||||
FALSE, FALSE, 0);
|
||||
gtk_ui_manager_get_widget (ui, "/MenuBar"),
|
||||
FALSE, FALSE, 0);
|
||||
|
||||
label = gtk_label_new ("Type\n<alt>\nto start");
|
||||
gtk_widget_set_size_request (label, 200, 200);
|
||||
@ -209,18 +208,16 @@ do_ui_manager (GtkWidget *do_widget)
|
||||
gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
|
||||
gtk_box_pack_start (GTK_BOX (box1), label, TRUE, TRUE, 0);
|
||||
|
||||
|
||||
separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
|
||||
gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
|
||||
|
||||
|
||||
box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
|
||||
gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
|
||||
|
||||
button = gtk_button_new_with_label ("close");
|
||||
g_signal_connect_swapped (button, "clicked",
|
||||
G_CALLBACK (gtk_widget_destroy), window);
|
||||
G_CALLBACK (gtk_widget_destroy), window);
|
||||
gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
|
||||
gtk_widget_set_can_default (button, TRUE);
|
||||
gtk_widget_grab_default (button);
|
||||
|
Loading…
Reference in New Issue
Block a user