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