1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gtk.PrintOperationPreviewT;
26 
27 public  import gobject.Signals;
28 public  import gtk.PageSetup;
29 public  import gtk.PrintContext;
30 public  import gtk.c.functions;
31 public  import gtk.c.types;
32 public  import gtkc.gtktypes;
33 public  import std.algorithm;
34 
35 
36 /** */
37 public template PrintOperationPreviewT(TStruct)
38 {
39 	/** Get the main Gtk struct */
40 	public GtkPrintOperationPreview* getPrintOperationPreviewStruct(bool transferOwnership = false)
41 	{
42 		if (transferOwnership)
43 			ownedRef = false;
44 		return cast(GtkPrintOperationPreview*)getStruct();
45 	}
46 
47 
48 	/**
49 	 * Ends a preview.
50 	 *
51 	 * This function must be called to finish a custom print preview.
52 	 *
53 	 * Since: 2.10
54 	 */
55 	public void endPreview()
56 	{
57 		gtk_print_operation_preview_end_preview(getPrintOperationPreviewStruct());
58 	}
59 
60 	/**
61 	 * Returns whether the given page is included in the set of pages that
62 	 * have been selected for printing.
63 	 *
64 	 * Params:
65 	 *     pageNr = a page number
66 	 *
67 	 * Returns: %TRUE if the page has been selected for printing
68 	 *
69 	 * Since: 2.10
70 	 */
71 	public bool isSelected(int pageNr)
72 	{
73 		return gtk_print_operation_preview_is_selected(getPrintOperationPreviewStruct(), pageNr) != 0;
74 	}
75 
76 	/**
77 	 * Renders a page to the preview, using the print context that
78 	 * was passed to the #GtkPrintOperation::preview handler together
79 	 * with @preview.
80 	 *
81 	 * A custom iprint preview should use this function in its ::expose
82 	 * handler to render the currently selected page.
83 	 *
84 	 * Note that this function requires a suitable cairo context to
85 	 * be associated with the print context.
86 	 *
87 	 * Params:
88 	 *     pageNr = the page to render
89 	 *
90 	 * Since: 2.10
91 	 */
92 	public void renderPage(int pageNr)
93 	{
94 		gtk_print_operation_preview_render_page(getPrintOperationPreviewStruct(), pageNr);
95 	}
96 
97 	protected class OnGotPageSizeDelegateWrapper
98 	{
99 		void delegate(PrintContext, PageSetup, PrintOperationPreviewIF) dlg;
100 		gulong handlerId;
101 
102 		this(void delegate(PrintContext, PageSetup, PrintOperationPreviewIF) dlg)
103 		{
104 			this.dlg = dlg;
105 			onGotPageSizeListeners ~= this;
106 		}
107 
108 		void remove(OnGotPageSizeDelegateWrapper source)
109 		{
110 			foreach(index, wrapper; onGotPageSizeListeners)
111 			{
112 				if (wrapper.handlerId == source.handlerId)
113 				{
114 					onGotPageSizeListeners[index] = null;
115 					onGotPageSizeListeners = std.algorithm.remove(onGotPageSizeListeners, index);
116 					break;
117 				}
118 			}
119 		}
120 	}
121 	OnGotPageSizeDelegateWrapper[] onGotPageSizeListeners;
122 
123 	/**
124 	 * The ::got-page-size signal is emitted once for each page
125 	 * that gets rendered to the preview.
126 	 *
127 	 * A handler for this signal should update the @context
128 	 * according to @page_setup and set up a suitable cairo
129 	 * context, using gtk_print_context_set_cairo_context().
130 	 *
131 	 * Params:
132 	 *     context = the current #GtkPrintContext
133 	 *     pageSetup = the #GtkPageSetup for the current page
134 	 */
135 	gulong addOnGotPageSize(void delegate(PrintContext, PageSetup, PrintOperationPreviewIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
136 	{
137 		auto wrapper = new OnGotPageSizeDelegateWrapper(dlg);
138 		wrapper.handlerId = Signals.connectData(
139 			this,
140 			"got-page-size",
141 			cast(GCallback)&callBackGotPageSize,
142 			cast(void*)wrapper,
143 			cast(GClosureNotify)&callBackGotPageSizeDestroy,
144 			connectFlags);
145 		return wrapper.handlerId;
146 	}
147 
148 	extern(C) static void callBackGotPageSize(GtkPrintOperationPreview* printoperationpreviewStruct, GtkPrintContext* context, GtkPageSetup* pageSetup, OnGotPageSizeDelegateWrapper wrapper)
149 	{
150 		wrapper.dlg(ObjectG.getDObject!(PrintContext)(context), ObjectG.getDObject!(PageSetup)(pageSetup), wrapper.outer);
151 	}
152 
153 	extern(C) static void callBackGotPageSizeDestroy(OnGotPageSizeDelegateWrapper wrapper, GClosure* closure)
154 	{
155 		wrapper.remove(wrapper);
156 	}
157 
158 	protected class OnReadyDelegateWrapper
159 	{
160 		void delegate(PrintContext, PrintOperationPreviewIF) dlg;
161 		gulong handlerId;
162 
163 		this(void delegate(PrintContext, PrintOperationPreviewIF) dlg)
164 		{
165 			this.dlg = dlg;
166 			onReadyListeners ~= this;
167 		}
168 
169 		void remove(OnReadyDelegateWrapper source)
170 		{
171 			foreach(index, wrapper; onReadyListeners)
172 			{
173 				if (wrapper.handlerId == source.handlerId)
174 				{
175 					onReadyListeners[index] = null;
176 					onReadyListeners = std.algorithm.remove(onReadyListeners, index);
177 					break;
178 				}
179 			}
180 		}
181 	}
182 	OnReadyDelegateWrapper[] onReadyListeners;
183 
184 	/**
185 	 * The ::ready signal gets emitted once per preview operation,
186 	 * before the first page is rendered.
187 	 *
188 	 * A handler for this signal can be used for setup tasks.
189 	 *
190 	 * Params:
191 	 *     context = the current #GtkPrintContext
192 	 */
193 	gulong addOnReady(void delegate(PrintContext, PrintOperationPreviewIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
194 	{
195 		auto wrapper = new OnReadyDelegateWrapper(dlg);
196 		wrapper.handlerId = Signals.connectData(
197 			this,
198 			"ready",
199 			cast(GCallback)&callBackReady,
200 			cast(void*)wrapper,
201 			cast(GClosureNotify)&callBackReadyDestroy,
202 			connectFlags);
203 		return wrapper.handlerId;
204 	}
205 
206 	extern(C) static void callBackReady(GtkPrintOperationPreview* printoperationpreviewStruct, GtkPrintContext* context, OnReadyDelegateWrapper wrapper)
207 	{
208 		wrapper.dlg(ObjectG.getDObject!(PrintContext)(context), wrapper.outer);
209 	}
210 
211 	extern(C) static void callBackReadyDestroy(OnReadyDelegateWrapper wrapper, GClosure* closure)
212 	{
213 		wrapper.remove(wrapper);
214 	}
215 }