📄 gtk-high-level-printing-api.html
字号:
GtkPrintOperation implements <a class="link" href="gtk-High-level-Printing-API.html#GtkPrintOperationPreview">GtkPrintOperationPreview</a>.</p></div><div class="refsect1" lang="en"><a name="id4128772"></a><h2>Known Implementations</h2><p>GtkPrintOperationPreview is implemented by <a class="link" href="gtk-High-level-Printing-API.html#GtkPrintOperation">GtkPrintOperation</a>.</p></div><div class="refsect1" lang="en"><a name="id4128795"></a><h2>Properties</h2><pre class="synopsis"> "<a class="link" href="gtk-High-level-Printing-API.html#GtkPrintOperation--allow-async">allow-async</a>" <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gboolean">gboolean</a> : Read / Write "<a class="link" href="gtk-High-level-Printing-API.html#GtkPrintOperation--current-page">current-page</a>" <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gint">gint</a> : Read / Write "<a class="link" href="gtk-High-level-Printing-API.html#GtkPrintOperation--custom-tab-label">custom-tab-label</a>" <ahref="/usr/share/gtk-doc/html/gobject/gobject-Standard-Parameter-and-Value-Types.html#gchararray">gchararray</a> : Read / Write "<a class="link" href="gtk-High-level-Printing-API.html#GtkPrintOperation--default-page-setup">default-page-setup</a>" <a class="link" href="GtkPageSetup.html" title="GtkPageSetup">GtkPageSetup</a> : Read / Write "<a class="link" href="gtk-High-level-Printing-API.html#GtkPrintOperation--export-filename">export-filename</a>" <ahref="/usr/share/gtk-doc/html/gobject/gobject-Standard-Parameter-and-Value-Types.html#gchararray">gchararray</a> : Read / Write "<a class="link" href="gtk-High-level-Printing-API.html#GtkPrintOperation--job-name">job-name</a>" <ahref="/usr/share/gtk-doc/html/gobject/gobject-Standard-Parameter-and-Value-Types.html#gchararray">gchararray</a> : Read / Write "<a class="link" href="gtk-High-level-Printing-API.html#GtkPrintOperation--n-pages">n-pages</a>" <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gint">gint</a> : Read / Write "<a class="link" href="gtk-High-level-Printing-API.html#GtkPrintOperation--print-settings">print-settings</a>" <a class="link" href="GtkPrintSettings.html" title="GtkPrintSettings">GtkPrintSettings</a> : Read / Write "<a class="link" href="gtk-High-level-Printing-API.html#GtkPrintOperation--show-progress">show-progress</a>" <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gboolean">gboolean</a> : Read / Write "<a class="link" href="gtk-High-level-Printing-API.html#GtkPrintOperation--status">status</a>" <a class="link" href="gtk-High-level-Printing-API.html#GtkPrintStatus">GtkPrintStatus</a> : Read "<a class="link" href="gtk-High-level-Printing-API.html#GtkPrintOperation--status-string">status-string</a>" <ahref="/usr/share/gtk-doc/html/gobject/gobject-Standard-Parameter-and-Value-Types.html#gchararray">gchararray</a> : Read "<a class="link" href="gtk-High-level-Printing-API.html#GtkPrintOperation--track-print-status">track-print-status</a>" <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gboolean">gboolean</a> : Read / Write "<a class="link" href="gtk-High-level-Printing-API.html#GtkPrintOperation--unit">unit</a>" <a class="link" href="gtk-GtkPaperSize.html#GtkUnit">GtkUnit</a> : Read / Write "<a class="link" href="gtk-High-level-Printing-API.html#GtkPrintOperation--use-full-page">use-full-page</a>" <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gboolean">gboolean</a> : Read / Write</pre></div><div class="refsect1" lang="en"><a name="id4129057"></a><h2>Signals</h2><pre class="synopsis"> "<a class="link" href="gtk-High-level-Printing-API.html#GtkPrintOperation-begin-print">begin-print</a>" : Run Last "<a class="link" href="gtk-High-level-Printing-API.html#GtkPrintOperation-create-custom-widget">create-custom-widget</a>" : Run Last "<a class="link" href="gtk-High-level-Printing-API.html#GtkPrintOperation-custom-widget-apply">custom-widget-apply</a>" : Run Last "<a class="link" href="gtk-High-level-Printing-API.html#GtkPrintOperation-done">done</a>" : Run Last "<a class="link" href="gtk-High-level-Printing-API.html#GtkPrintOperation-draw-page">draw-page</a>" : Run Last "<a class="link" href="gtk-High-level-Printing-API.html#GtkPrintOperation-end-print">end-print</a>" : Run Last "<a class="link" href="gtk-High-level-Printing-API.html#GtkPrintOperation-paginate">paginate</a>" : Run Last "<a class="link" href="gtk-High-level-Printing-API.html#GtkPrintOperation-preview">preview</a>" : Run Last "<a class="link" href="gtk-High-level-Printing-API.html#GtkPrintOperation-request-page-setup">request-page-setup</a>" : Run Last "<a class="link" href="gtk-High-level-Printing-API.html#GtkPrintOperation-status-changed">status-changed</a>" : Run Last</pre></div><div class="refsect1" lang="en"><a name="id4129182"></a><h2>Description</h2><p>GtkPrintOperation is the high-level, portable printing API. It looks a bit different than other GTK+ dialogs such as the <a class="link" href="GtkFileChooser.html" title="GtkFileChooser"><span class="type">GtkFileChooser</span></a>, since some platforms don't expose enough infrastructure to implementa good print dialog. On such platforms, GtkPrintOperation uses the native print dialog. On platforms which do not provide a native print dialog, GTK+ uses its own, see <a class="link" href="GtkPrintUnixDialog.html" title="GtkPrintUnixDialog"><span class="type">GtkPrintUnixDialog</span></a>.</p><p>The typical way to use the high-level printing API is to create a <a class="link" href="gtk-High-level-Printing-API.html#GtkPrintOperation"><span class="type">GtkPrintOperation</span></a> object with <a class="link" href="gtk-High-level-Printing-API.html#gtk-print-operation-new"><code class="function">gtk_print_operation_new()</code></a> when the user selects to print. Then you set some properties on it, e.g. the page size, any <a class="link" href="GtkPrintSettings.html" title="GtkPrintSettings"><span class="type">GtkPrintSettings</span></a> from previous print operations, the number of pages, the current page, etc. </p><p>Then you start the print operation by calling <a class="link" href="gtk-High-level-Printing-API.html#gtk-print-operation-run"><code class="function">gtk_print_operation_run()</code></a>.It will then show a dialog, let the user select a printer and options. When the user finished the dialog various signals will be emitted on the <a class="link" href="gtk-High-level-Printing-API.html#GtkPrintOperation"><span class="type">GtkPrintOperation</span></a>, the main one being ::draw-page, which you are supposed to catch and render the page on the provided <a class="link" href="GtkPrintContext.html" title="GtkPrintContext"><span class="type">GtkPrintContext</span></a> using Cairo.</p><div class="example"><a name="id4129289"></a><p class="title"><b>Example 39. The high-level printing API</b></p><div class="example-contents"><pre class="programlisting">static GtkPrintSettings *settings = NULL;static voiddo_print (void){ GtkPrintOperation *print; GtkPrintOperationResult res; print = gtk_print_operation_new (); if (settings != NULL) gtk_print_operation_set_print_settings (print, settings); g_signal_connect (print, "begin_print", G_CALLBACK (begin_print), NULL); g_signal_connect (print, "draw_page", G_CALLBACK (draw_page), NULL); res = gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW (main_window), NULL); if (res == GTK_PRINT_OPERATION_RESULT_APPLY) { if (settings != NULL) g_object_unref (settings); settings = g_object_ref (gtk_print_operation_get_print_settings (print)); } g_object_unref (print);}</pre></div></div><br class="example-break"><p>By default GtkPrintOperation uses an external application to doprint preview. To implement a custom print preview, an application must connect to the preview signal. The functions <code class="function">gtk_print_operation_print_preview_render_page()</code>, <a class="link" href="gtk-High-level-Printing-API.html#gtk-print-operation-preview-end-preview"><code class="function">gtk_print_operation_preview_end_preview()</code></a> and <a class="link" href="gtk-High-level-Printing-API.html#gtk-print-operation-preview-is-selected"><code class="function">gtk_print_operation_preview_is_selected()</code></a> are useful when implementing a print preview.</p><p>Printing support was added in GTK+ 2.10.</p></div><div class="refsect1" lang="en"><a name="id4129365"></a><h2>Details</h2><div class="refsect2" lang="en"><a name="id4129376"></a><h3><a name="GtkPrintOperation-struct"></a>GtkPrintOperation</h3><a class="indexterm" name="id4129389"></a><pre class="programlisting">typedef struct _GtkPrintOperation GtkPrintOperation;</pre><p></p></div><hr><div class="refsect2" lang="en"><a name="id4129405"></a><h3><a name="GtkPrintStatus"></a>enum GtkPrintStatus</h3><a class="indexterm" name="id4129417"></a><pre class="programlisting">typedef enum { GTK_PRINT_STATUS_INITIAL, GTK_PRINT_STATUS_PREPARING, GTK_PRINT_STATUS_GENERATING_DATA, GTK_PRINT_STATUS_SENDING_DATA, GTK_PRINT_STATUS_PENDING, GTK_PRINT_STATUS_PENDING_ISSUE, GTK_PRINT_STATUS_PRINTING, GTK_PRINT_STATUS_FINISHED, GTK_PRINT_STATUS_FINISHED_ABORTED} GtkPrintStatus;</pre><p>The status gives a rough indication of the completionof a running print operation.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><a name="GTK-PRINT-STATUS-INITIAL:CAPS"></a><code class="literal">GTK_PRINT_STATUS_INITIAL</code></span></p></td><td>The printing has not started yet; this status is set initially, and while the print dialog is shown.</td></tr><tr><td><p><span class="term"><a name="GTK-PRINT-STATUS-PREPARING:CAPS"></a><code class="literal">GTK_PRINT_STATUS_PREPARING</code></span></p></td><td>This status is set while the begin-print signal is emitted and during pagination.</td></tr><tr><td><p><span class="term"><a name="GTK-PRINT-STATUS-GENERATING-DATA:CAPS"></a><code class="literal">GTK_PRINT_STATUS_GENERATING_DATA</code></span></p></td><td>This status is set while the pages are being rendered.</td></tr><tr><td><p><span class="term"><a name="GTK-PRINT-STATUS-SENDING-DATA:CAPS"></a><code class="literal">GTK_PRINT_STATUS_SENDING_DATA</code></span></p></td><td>The print job is being sent off to the printer.</td></tr><tr><td><p><span class="term"><a name="GTK-PRINT-STATUS-PENDING:CAPS"></a><code class="literal">GTK_PRINT_STATUS_PENDING</code></span></p></td><td>The print job has been sent to the printer, but is not printed for some reason, e.g. the printer may be stopped.</td></tr><tr><td><p><span class="term"><a name="GTK-PRINT-STATUS-PENDING-ISSUE:CAPS"></a><code class="literal">GTK_PRINT_STATUS_PENDING_ISSUE</code></span></p></td><td>Some problem has occurred during printing, e.g. a paper jam.</td></tr><tr><td><p><span class="term"><a name="GTK-PRINT-STATUS-PRINTING:CAPS"></a><code class="literal">GTK_PRINT_STATUS_PRINTING</code></span></p></td><td>The printer is processing the print job.</td></tr><tr><td><p><span class="term"><a name="GTK-PRINT-STATUS-FINISHED:CAPS"></a><code class="literal">GTK_PRINT_STATUS_FINISHED</code></span></p></td><td>The printing has been completed successfully.</td></tr><tr><td><p><span class="term"><a name="GTK-PRINT-STATUS-FINISHED-ABORTED:CAPS"></a><code class="literal">GTK_PRINT_STATUS_FINISHED_ABORTED</code></span></p></td><td>The printing has been aborted.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id4129660"></a><h3><a name="GtkPrintOperationAction"></a>enum GtkPrintOperationAction</h3><a class="indexterm" name="id4129674"></a><pre class="programlisting">typedef enum { GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_PRINT_OPERATION_ACTION_PRINT, GTK_PRINT_OPERATION_ACTION_PREVIEW, GTK_PRINT_OPERATION_ACTION_EXPORT} GtkPrintOperationAction;</pre><p>The <em class="parameter"><code>action</code></em> parameter to <a class="link" href="gtk-High-level-Printing-API.html#gtk-print-operation-run"><code class="function">gtk_print_operation_run()</code></a>determines what action the print operation should perform.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><a name="GTK-PRINT-OPERATION-ACTION-PRINT-DIALOG:CAPS"></a><code class="literal">GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG</code></span></p></td><td>Show the print dialog.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -