diff --git a/demos/widget-factory/gtk-logo.webm b/demos/widget-factory/gtk-logo.webm new file mode 100644 index 0000000000..7baa0588d6 Binary files /dev/null and b/demos/widget-factory/gtk-logo.webm differ diff --git a/demos/widget-factory/widget-factory.c b/demos/widget-factory/widget-factory.c index 4b728c3a6c..374d06ab27 100644 --- a/demos/widget-factory/widget-factory.c +++ b/demos/widget-factory/widget-factory.c @@ -323,6 +323,97 @@ activate_inspector (GSimpleAction *action, gtk_window_set_interactive_debugging (TRUE); } +static void +print_operation_done (GtkPrintOperation *op, + GtkPrintOperationResult res, + gpointer data) +{ + GError *error = NULL; + + switch (res) + { + case GTK_PRINT_OPERATION_RESULT_ERROR: + gtk_print_operation_get_error (op, &error); + g_print ("Printing failed: %s\n", error->message); + g_clear_error (&error); + break; + case GTK_PRINT_OPERATION_RESULT_APPLY: + break; + case GTK_PRINT_OPERATION_RESULT_CANCEL: + g_print ("Printing was canceled\n"); + break; + case GTK_PRINT_OPERATION_RESULT_IN_PROGRESS: + return; + default: + g_assert_not_reached (); + break; + } + + g_object_unref (op); +} + +static void +print_operation_begin (GtkPrintOperation *op, + GtkPrintContext *context, + gpointer data) +{ + gtk_print_operation_set_n_pages (op, 1); +} + +static void +print_operation_page (GtkPrintOperation *op, + GtkPrintContext *context, + int page, + gpointer data) +{ + cairo_t *cr; + double width; + double aspect_ratio; + GdkSnapshot *snapshot; + GdkPaintable *paintable; + GskRenderNode *node; + + g_print ("Save the trees!\n"); + + cr = gtk_print_context_get_cairo_context (context); + width = gtk_print_context_get_width (context); + + snapshot = gtk_snapshot_new (); + paintable = gtk_widget_paintable_new (GTK_WIDGET (data)); + aspect_ratio = gdk_paintable_get_intrinsic_aspect_ratio (paintable); + gdk_paintable_snapshot (paintable, snapshot, width, width / aspect_ratio); + node = gtk_snapshot_free_to_node (snapshot); + + gsk_render_node_draw (node, cr); + + gsk_render_node_unref (node); + + g_object_unref (paintable); +} + +static void +activate_print (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) +{ + GtkWindow *window = GTK_WINDOW (user_data); + GtkPrintOperation *op; + GtkPrintOperationResult res; + + op = gtk_print_operation_new (); + gtk_print_operation_set_allow_async (op, TRUE); + g_signal_connect (op, "begin-print", G_CALLBACK (print_operation_begin), NULL); + g_signal_connect (op, "draw-page", G_CALLBACK (print_operation_page), window); + g_signal_connect (op, "done", G_CALLBACK (print_operation_done), NULL); + + res = gtk_print_operation_run (op, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, window, NULL); + + if (res == GTK_PRINT_OPERATION_RESULT_IN_PROGRESS) + return; + + print_operation_done (op, res, NULL); +} + static void spin_value_changed (GtkAdjustment *adjustment, GtkWidget *label) { @@ -1714,6 +1805,7 @@ activate (GApplication *app) { "open", activate_open, NULL, NULL, NULL }, { "record", activate_record, NULL, NULL, NULL }, { "lock", activate_lock, NULL, NULL, NULL }, + { "print", activate_print, NULL, NULL, NULL }, }; struct { const gchar *action_and_target; @@ -2077,7 +2169,6 @@ main (int argc, char *argv[]) { "water", NULL, NULL, "true", NULL }, { "dessert", NULL, "s", "'bars'", NULL }, { "pay", NULL, "s", NULL, NULL }, - { "print", activate_action, NULL, NULL, NULL }, { "share", activate_action, NULL, NULL, NULL }, { "labels", activate_action, NULL, NULL, NULL }, { "new", activate_action, NULL, NULL, NULL }, diff --git a/demos/widget-factory/widget-factory.gresource.xml b/demos/widget-factory/widget-factory.gresource.xml index 39d665da06..3a5c2e9c29 100644 --- a/demos/widget-factory/widget-factory.gresource.xml +++ b/demos/widget-factory/widget-factory.gresource.xml @@ -35,4 +35,7 @@ icons/16x16/emotes/face-monkey-symbolic.symbolic.png icons/16x16/apps/preferences-desktop-locale-symbolic.symbolic.png + + gtk-logo.webm + diff --git a/demos/widget-factory/widget-factory.ui b/demos/widget-factory/widget-factory.ui index 9060c816ce..7ed8edf1d8 100644 --- a/demos/widget-factory/widget-factory.ui +++ b/demos/widget-factory/widget-factory.ui @@ -1042,57 +1042,28 @@ Suspendisse feugiat quam quis dolor accumsan cursus. vertical - 1 6 1 - + start - <b>Inset</b> + <b>Video</b> 1 - - - - - - - - <b>Outset</b> - 1 - - - - - - - - - - <b>Groove</b> - 1 - - - - - - - - - - <b>Ridge</b> - 1 + + + center + center + 6 + 6 + 6 + 6 + 0 + 1 + resource:///org/gtk/WidgetFactory4/gtk-logo.webm @@ -2482,6 +2453,7 @@ microphone-sensitivity-medium-symbolic Print + win.print @@ -2754,15 +2726,17 @@ microphone-sensitivity-medium-symbolic 10 - center + fill + 1 Name… name_completion + 1 1 Age… @@ -3307,7 +3281,7 @@ bad things might happen. 1 - app.print + win.print 1 center - + center center