Print options grayed out with GtkPrintOperation

I’m developing an application using the GtkPrintOperation.
I can print OK but the print dialog box does not allow me to change many of the parameters (such as orientation). See this dialog I get using the application


Other applications do dot prohibit me from changing these settings. What is going wrong here?
This occurs on all printers and on “print to file”.
I’ve set up the code almost identically to the examples …

static GtkPrintSettings *settings = NULL;
void
CB_BtnMPrint (GtkButton *wButton, tGlobal *pGlobal)
{
	  GtkPrintOperation *print;
	  GtkPrintOperationResult res;
	  static gboolean bInitial = TRUE;

	  if( bInitial ) {
		  settings = gtk_print_settings_new ();
		  gtk_print_settings_set_orientation ( settings, GTK_PAGE_ORIENTATION_LANDSCAPE );
		  bInitial = FALSE;
	  }

	  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), pGlobal);
	  g_signal_connect (print, "draw_page", G_CALLBACK (draw_page), pGlobal);

	  res = gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
			  GTK_WINDOW(g_hash_table_lookup ( pGlobal->widgetHashTable, (gconstpointer)"WID_hp8753c_main") ), 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);
}

OK, to answer my own question :scream_cat:
After some more investigation I find I need to add …
gtk_print_operation_set_embed_page_setup ( print, TRUE );
I also need to save and restore the page setup in addition to the other settings.

The final code looks like …

static GtkPrintSettings *printSettings = NULL;
static GtkPageSetup *pageSetup = NULL;

void
CB_BtnMPrint (GtkButton *wButton, tGlobal *pGlobal)
{
	  GtkPrintOperation *print;
	  GtkPrintOperationResult res;

	  print = gtk_print_operation_new ();

	  if (printSettings != NULL)
	    gtk_print_operation_set_print_settings (print, printSettings);

	  if (pageSetup != NULL)
		  gtk_print_operation_set_default_page_setup (print, pageSetup);

	  g_signal_connect (print, "begin_print", G_CALLBACK (begin_print), pGlobal);
	  g_signal_connect (print, "draw_page", G_CALLBACK (draw_page), pGlobal);

	  gtk_print_operation_set_embed_page_setup ( print, TRUE );
	  gtk_print_operation_set_use_full_page ( print, FALSE );

	  res = gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
			  GTK_WINDOW(g_hash_table_lookup ( pGlobal->widgetHashTable, (gconstpointer)"WID_hp8753c_main") ), NULL);

	  if (res == GTK_PRINT_OPERATION_RESULT_APPLY)
	    {
	      if (printSettings != NULL)
	        g_object_unref (printSettings);
	      printSettings = g_object_ref (gtk_print_operation_get_print_settings (print));

	      if (pageSetup != NULL)
	        g_object_unref (pageSetup);
	      pageSetup = g_object_ref (gtk_print_operation_get_default_page_setup (print));
	    }

	  g_object_unref (print);
}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.