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 gtkc.gdktypes;
31 public  import gtkc.gtk;
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()
41 	{
42 		return cast(GtkPrintOperationPreview*)getStruct();
43 	}
44 
45 
46 	/**
47 	 * Ends a preview.
48 	 *
49 	 * This function must be called to finish a custom print preview.
50 	 *
51 	 * Since: 2.10
52 	 */
53 	public void endPreview()
54 	{
55 		gtk_print_operation_preview_end_preview(getPrintOperationPreviewStruct());
56 	}
57 
58 	/**
59 	 * Returns whether the given page is included in the set of pages that
60 	 * have been selected for printing.
61 	 *
62 	 * Params:
63 	 *     pageNr = a page number
64 	 *
65 	 * Return: %TRUE if the page has been selected for printing
66 	 *
67 	 * Since: 2.10
68 	 */
69 	public bool isSelected(int pageNr)
70 	{
71 		return gtk_print_operation_preview_is_selected(getPrintOperationPreviewStruct(), pageNr) != 0;
72 	}
73 
74 	/**
75 	 * Renders a page to the preview, using the print context that
76 	 * was passed to the #GtkPrintOperation::preview handler together
77 	 * with @preview.
78 	 *
79 	 * A custom iprint preview should use this function in its ::expose
80 	 * handler to render the currently selected page.
81 	 *
82 	 * Note that this function requires a suitable cairo context to
83 	 * be associated with the print context.
84 	 *
85 	 * Params:
86 	 *     pageNr = the page to render
87 	 *
88 	 * Since: 2.10
89 	 */
90 	public void renderPage(int pageNr)
91 	{
92 		gtk_print_operation_preview_render_page(getPrintOperationPreviewStruct(), pageNr);
93 	}
94 
95 	protected class OnGotPageSizeDelegateWrapper
96 	{
97 		void delegate(PrintContext, PageSetup, PrintOperationPreviewIF) dlg;
98 		gulong handlerId;
99 		ConnectFlags flags;
100 		this(void delegate(PrintContext, PageSetup, PrintOperationPreviewIF) dlg, gulong handlerId, ConnectFlags flags)
101 		{
102 			this.dlg = dlg;
103 			this.handlerId = handlerId;
104 			this.flags = flags;
105 		}
106 	}
107 	protected OnGotPageSizeDelegateWrapper[] onGotPageSizeListeners;
108 
109 	/**
110 	 * The ::got-page-size signal is emitted once for each page
111 	 * that gets rendered to the preview.
112 	 *
113 	 * A handler for this signal should update the @context
114 	 * according to @page_setup and set up a suitable cairo
115 	 * context, using gtk_print_context_set_cairo_context().
116 	 *
117 	 * Params:
118 	 *     context = the current #GtkPrintContext
119 	 *     pageSetup = the #GtkPageSetup for the current page
120 	 */
121 	gulong addOnGotPageSize(void delegate(PrintContext, PageSetup, PrintOperationPreviewIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
122 	{
123 		onGotPageSizeListeners ~= new OnGotPageSizeDelegateWrapper(dlg, 0, connectFlags);
124 		onGotPageSizeListeners[onGotPageSizeListeners.length - 1].handlerId = Signals.connectData(
125 			this,
126 			"got-page-size",
127 			cast(GCallback)&callBackGotPageSize,
128 			cast(void*)onGotPageSizeListeners[onGotPageSizeListeners.length - 1],
129 			cast(GClosureNotify)&callBackGotPageSizeDestroy,
130 			connectFlags);
131 		return onGotPageSizeListeners[onGotPageSizeListeners.length - 1].handlerId;
132 	}
133 	
134 	extern(C) static void callBackGotPageSize(GtkPrintOperationPreview* printoperationpreviewStruct, GtkPrintContext* context, GtkPageSetup* pageSetup,OnGotPageSizeDelegateWrapper wrapper)
135 	{
136 		wrapper.dlg(ObjectG.getDObject!(PrintContext)(context), ObjectG.getDObject!(PageSetup)(pageSetup), wrapper.outer);
137 	}
138 	
139 	extern(C) static void callBackGotPageSizeDestroy(OnGotPageSizeDelegateWrapper wrapper, GClosure* closure)
140 	{
141 		wrapper.outer.internalRemoveOnGotPageSize(wrapper);
142 	}
143 
144 	protected void internalRemoveOnGotPageSize(OnGotPageSizeDelegateWrapper source)
145 	{
146 		foreach(index, wrapper; onGotPageSizeListeners)
147 		{
148 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
149 			{
150 				onGotPageSizeListeners[index] = null;
151 				onGotPageSizeListeners = std.algorithm.remove(onGotPageSizeListeners, index);
152 				break;
153 			}
154 		}
155 	}
156 	
157 
158 	protected class OnReadyDelegateWrapper
159 	{
160 		void delegate(PrintContext, PrintOperationPreviewIF) dlg;
161 		gulong handlerId;
162 		ConnectFlags flags;
163 		this(void delegate(PrintContext, PrintOperationPreviewIF) dlg, gulong handlerId, ConnectFlags flags)
164 		{
165 			this.dlg = dlg;
166 			this.handlerId = handlerId;
167 			this.flags = flags;
168 		}
169 	}
170 	protected OnReadyDelegateWrapper[] onReadyListeners;
171 
172 	/**
173 	 * The ::ready signal gets emitted once per preview operation,
174 	 * before the first page is rendered.
175 	 *
176 	 * A handler for this signal can be used for setup tasks.
177 	 *
178 	 * Params:
179 	 *     context = the current #GtkPrintContext
180 	 */
181 	gulong addOnReady(void delegate(PrintContext, PrintOperationPreviewIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
182 	{
183 		onReadyListeners ~= new OnReadyDelegateWrapper(dlg, 0, connectFlags);
184 		onReadyListeners[onReadyListeners.length - 1].handlerId = Signals.connectData(
185 			this,
186 			"ready",
187 			cast(GCallback)&callBackReady,
188 			cast(void*)onReadyListeners[onReadyListeners.length - 1],
189 			cast(GClosureNotify)&callBackReadyDestroy,
190 			connectFlags);
191 		return onReadyListeners[onReadyListeners.length - 1].handlerId;
192 	}
193 	
194 	extern(C) static void callBackReady(GtkPrintOperationPreview* printoperationpreviewStruct, GtkPrintContext* context,OnReadyDelegateWrapper wrapper)
195 	{
196 		wrapper.dlg(ObjectG.getDObject!(PrintContext)(context), wrapper.outer);
197 	}
198 	
199 	extern(C) static void callBackReadyDestroy(OnReadyDelegateWrapper wrapper, GClosure* closure)
200 	{
201 		wrapper.outer.internalRemoveOnReady(wrapper);
202 	}
203 
204 	protected void internalRemoveOnReady(OnReadyDelegateWrapper source)
205 	{
206 		foreach(index, wrapper; onReadyListeners)
207 		{
208 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
209 			{
210 				onReadyListeners[index] = null;
211 				onReadyListeners = std.algorithm.remove(onReadyListeners, index);
212 				break;
213 			}
214 		}
215 	}
216 	
217 }