1 module webkit2.PrintCustomWidget;
2 
3 private import glib.ConstructionException;
4 private import glib.Str;
5 private import gobject.ObjectG;
6 private import gobject.Signals;
7 private import gtk.PageSetup;
8 private import gtk.PrintSettings;
9 private import gtk.Widget;
10 private import std.algorithm;
11 private import webkit2.c.functions;
12 public  import webkit2.c.types;
13 
14 
15 /**
16  * A WebKitPrintCustomWidget allows to embed a custom widget in the print
17  * dialog by connecting to the #WebKitPrintOperation::create-custom-widget
18  * signal, creating a new WebKitPrintCustomWidget with
19  * webkit_print_custom_widget_new() and returning it from there. You can later
20  * use webkit_print_operation_run_dialog() to display the dialog.
21  *
22  * Since: 2.16
23  */
24 public class PrintCustomWidget : ObjectG
25 {
26 	/** the main Gtk struct */
27 	protected WebKitPrintCustomWidget* webKitPrintCustomWidget;
28 
29 	/** Get the main Gtk struct */
30 	public WebKitPrintCustomWidget* getPrintCustomWidgetStruct(bool transferOwnership = false)
31 	{
32 		if (transferOwnership)
33 			ownedRef = false;
34 		return webKitPrintCustomWidget;
35 	}
36 
37 	/** the main Gtk struct as a void* */
38 	protected override void* getStruct()
39 	{
40 		return cast(void*)webKitPrintCustomWidget;
41 	}
42 
43 	/**
44 	 * Sets our main struct and passes it to the parent class.
45 	 */
46 	public this (WebKitPrintCustomWidget* webKitPrintCustomWidget, bool ownedRef = false)
47 	{
48 		this.webKitPrintCustomWidget = webKitPrintCustomWidget;
49 		super(cast(GObject*)webKitPrintCustomWidget, ownedRef);
50 	}
51 
52 
53 	/** */
54 	public static GType getType()
55 	{
56 		return webkit_print_custom_widget_get_type();
57 	}
58 
59 	/**
60 	 * Create a new #WebKitPrintCustomWidget with given @widget and @title. The @widget
61 	 * ownership is taken and it is destroyed together with the dialog even if this
62 	 * object could still be alive at that point. You typically want to pass a container
63 	 * widget with multiple widgets in it.
64 	 *
65 	 * Params:
66 	 *     widget = a #GtkWidget
67 	 *     title = a @widget's title
68 	 *
69 	 * Returns: a new #WebKitPrintOperation.
70 	 *
71 	 * Since: 2.16
72 	 *
73 	 * Throws: ConstructionException GTK+ fails to create the object.
74 	 */
75 	public this(Widget widget, string title)
76 	{
77 		auto __p = webkit_print_custom_widget_new((widget is null) ? null : widget.getWidgetStruct(), Str.toStringz(title));
78 
79 		if(__p is null)
80 		{
81 			throw new ConstructionException("null returned by new");
82 		}
83 
84 		this(cast(WebKitPrintCustomWidget*) __p, true);
85 	}
86 
87 	/**
88 	 * Return the value of #WebKitPrintCustomWidget:title property for the given
89 	 * @print_custom_widget object.
90 	 *
91 	 * Returns: Title of the @print_custom_widget.
92 	 *
93 	 * Since: 2.16
94 	 */
95 	public string getTitle()
96 	{
97 		return Str.toString(webkit_print_custom_widget_get_title(webKitPrintCustomWidget));
98 	}
99 
100 	/**
101 	 * Return the value of #WebKitPrintCustomWidget:widget property for the given
102 	 * @print_custom_widget object. The returned value will always be valid if called
103 	 * from #WebKitPrintCustomWidget::apply or #WebKitPrintCustomWidget::update
104 	 * callbacks, but it will be %NULL if called after the
105 	 * #WebKitPrintCustomWidget::apply signal is emitted.
106 	 *
107 	 * Returns: a #GtkWidget.
108 	 *
109 	 * Since: 2.16
110 	 */
111 	public Widget getWidget()
112 	{
113 		auto __p = webkit_print_custom_widget_get_widget(webKitPrintCustomWidget);
114 
115 		if(__p is null)
116 		{
117 			return null;
118 		}
119 
120 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) __p);
121 	}
122 
123 	/**
124 	 * Emitted right before the printing will start. You should read the information
125 	 * from the widget and update the content based on it if necessary. The widget
126 	 * is not guaranteed to be valid at a later time.
127 	 *
128 	 * Since: 2.16
129 	 */
130 	gulong addOnApply(void delegate(PrintCustomWidget) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
131 	{
132 		return Signals.connect(this, "apply", dlg, connectFlags ^ ConnectFlags.SWAPPED);
133 	}
134 
135 	/**
136 	 * Emitted after change of selected printer in the dialog. The actual page setup
137 	 * and print settings are available and the custom widget can actualize itself
138 	 * according to their values.
139 	 *
140 	 * Params:
141 	 *     pageSetup = actual page setup
142 	 *     printSettings = actual print settings
143 	 *
144 	 * Since: 2.16
145 	 */
146 	gulong addOnUpdate(void delegate(PageSetup, PrintSettings, PrintCustomWidget) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
147 	{
148 		return Signals.connect(this, "update", dlg, connectFlags ^ ConnectFlags.SWAPPED);
149 	}
150 }