1. ----------------------------------------------------------------------- 
  2. --               GtkAda - Ada95 binding for Gtk+/Gnome               -- 
  3. --                                                                   -- 
  4. --                    Copyright (C) 2010, AdaCore                    -- 
  5. --                                                                   -- 
  6. -- This library is free software; you can redistribute it and/or     -- 
  7. -- modify it under the terms of the GNU General Public               -- 
  8. -- License as published by the Free Software Foundation; either      -- 
  9. -- version 2 of the License, or (at your option) any later version.  -- 
  10. --                                                                   -- 
  11. -- This library is distributed in the hope that it will be useful,   -- 
  12. -- but WITHOUT ANY WARRANTY; without even the implied warranty of    -- 
  13. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -- 
  14. -- General Public License for more details.                          -- 
  15. --                                                                   -- 
  16. -- You should have received a copy of the GNU General Public         -- 
  17. -- License along with this library; if not, write to the             -- 
  18. -- Free Software Foundation, Inc., 59 Temple Place - Suite 330,      -- 
  19. -- Boston, MA 02111-1307, USA.                                       -- 
  20. --                                                                   -- 
  21. -- -- -- -- -- -- -- -- -- -- -- --
  22. ----------------------------------------------------------------------- 
  23.  
  24. --  <description> 
  25. --  Gtk_Print_Operation is the high-level, portable printing API. It looks a 
  26. --  bit different than other GTK+ dialogs such as the Gtk_File_Chooser, since 
  27. --  some platforms don't expose enough infrastructure to implement a good print 
  28. --  dialog. On such platforms, Gtk_Print_Operation uses the native print 
  29. --  dialog. On platforms which do not provide a native print dialog, GTK+ uses 
  30. --  its own, see Gtk_Print_Unix_Dialog. 
  31. -- 
  32. --  The typical way to use the high-level printing API is to create a 
  33. --  Gtk_Print_Operation object with Gtk_New when the user selects to print. 
  34. --  Then you set some properties on it, e.g. the page size, any 
  35. --  Gtk_Print_Settings from previous print operations, the number of pages, 
  36. --  the current page, etc. 
  37. -- 
  38. --  Then you start the print operation by calling Run. It will then show a 
  39. --  dialog, let the user select a printer and options. When the user finished 
  40. --  the dialog various signals will be emitted on the Gtk_Print_Operation, the 
  41. --  main one being draw-page, which you are supposed to catch and render the 
  42. --  page on the provided Gtk_Print_Context using Cairo. 
  43. --  </description> 
  44. --  <c_version>2.16.6</c_version> 
  45.  
  46. with Glib.Error; 
  47. with Glib.Object; 
  48. with Glib.Properties; 
  49. with Gtk.Enums; 
  50. with Gtk.Page_Setup; 
  51. with Gtk.Print_Settings; 
  52. with Gtk.Window; 
  53.  
  54. package Gtk.Print_Operation is 
  55.  
  56.    type Gtk_Print_Operation_Record is 
  57.      new Glib.Object.GObject_Record with private; 
  58.    type Gtk_Print_Operation is access all Gtk_Print_Operation_Record'Class; 
  59.  
  60.    type Gtk_Print_Status is 
  61.      (Status_Initial, 
  62.       Status_Preparing, 
  63.       Status_Generating_Data, 
  64.       Status_Sending_Data, 
  65.       Status_Pending, 
  66.       Status_Pending_Issue, 
  67.       Status_Printing, 
  68.       Status_Finished, 
  69.       Status_Finished_Aborted); 
  70.    pragma Convention (C, Gtk_Print_Status); 
  71.  
  72.    type Gtk_Print_Operation_Result is 
  73.      (Result_Error, 
  74.       Result_Apply, 
  75.       Result_Cancel, 
  76.       Result_In_Progress); 
  77.    pragma Convention (C, Gtk_Print_Operation_Result); 
  78.  
  79.    type Gtk_Print_Operation_Action is 
  80.      (Action_Print_Dialog, 
  81.       Action_Print, 
  82.       Action_Preview, 
  83.       Action_Export); 
  84.    pragma Convention (C, Gtk_Print_Operation_Action); 
  85.  
  86.    type Gtk_Print_Error is 
  87.      (Error_General, 
  88.       Error_Internal_Error, 
  89.       Error_Nomem, 
  90.       Error_Invalid_File); 
  91.    pragma Convention (C, Gtk_Print_Error); 
  92.  
  93.    procedure Gtk_New (Widget : out Gtk_Print_Operation); 
  94.    procedure Initialize (Widget : access Gtk_Print_Operation_Record'Class); 
  95.    --  Creates a new Gtk_Print_Operation. 
  96.  
  97.    function Get_Type return GType; 
  98.  
  99.    function Error_Quark return GQuark; 
  100.    --  Registers an error quark for Gtk_Print_Operation if necessary. 
  101.  
  102.    function Run 
  103.      (Op     : access Gtk_Print_Operation_Record; 
  104.       Action : Gtk_Print_Operation_Action; 
  105.       Parent : access Gtk.Window.Gtk_Window_Record'Class; 
  106.       Error  : Glib.Error.GError := null) 
  107.       return Gtk_Print_Operation_Result; 
  108.    --  Runs the print operation, by first letting the user modify 
  109.    --  print settings in the print dialog, and then by printing the 
  110.    --  document. 
  111.    -- 
  112.    --  Normally that this function does not return until the rendering of all 
  113.    --  pages is complete. You can connect to the status-changed signal on Op 
  114.    --  to obtain some information about the progress of the print operation. 
  115.    --  Furthermore, it may use a recursive mainloop to show the print dialog. 
  116.    -- 
  117.    --  If you call Set_Allow_Async or set the allow-async property the 
  118.    --  operation will run asynchronously if this is supported on the platform. 
  119.    --  The done signal will be emitted with the result of the operation when 
  120.    --  it is done (i.e. when the dialog is canceled, or when the print succeeds 
  121.    --  or fails). 
  122.    -- 
  123.    --     begin 
  124.    --        if Settings /= null then 
  125.    --           Set_Print_Settings (Print, Settings); 
  126.    --        end if; 
  127.    -- 
  128.    --        if Page_Setup /= null then 
  129.    --           Set_Default_Page_Setup (Print, Page_Setup); 
  130.    --        end if; 
  131.    -- 
  132.    --        Connect (Print, "begin-print", Begin_Print'Access, User_Data); 
  133.    --        Connect (Print, "draw-page",   Draw_Page'Access,   User_Data); 
  134.    -- 
  135.    --        Result := Run (Print, Action_Print_Dialog, Parent, Error); 
  136.    -- 
  137.    --        case Result is 
  138.    --           when Result_Error => 
  139.    --              Gtk_New 
  140.    --                (Error_Dialog, 
  141.    --                 Parent, 
  142.    --                 Destroy_With_Parent, 
  143.    --                 Message_Error, 
  144.    --                 Buttons_Close, 
  145.    --                 "Error printing file"); 
  146.    --              Connect 
  147.    --                (Error_Dialog, "response", Gtk_Widget_Destroy'Access); 
  148.    --              Show (Error_Dialog); 
  149.    --              Glib.Error.Error_Free (Error); 
  150.    -- 
  151.    --           when Result_Apply => 
  152.    --              if Settings /= null then 
  153.    --                 Unref (Settings); 
  154.    --              end if; 
  155.    --              Settings := Get_Print_Settings (Print); 
  156.    --              Ref (Settings); 
  157.    -- 
  158.    --           when Result_Cancel =>      null; 
  159.    --           when Result_In_Progress => null; 
  160.    --        end case; 
  161.    -- 
  162.    --  Note that Run can only be called once on a given Gtk_Print_Operation. 
  163.    -- 
  164.    --  Return value: the result of the print operation. A return value of 
  165.    --  Result_Apply indicates that the printing was completed successfully. 
  166.    --  In this case, it is a good idea to obtain the used print settings with 
  167.    --  Get_Print_Settings and store them for reuse with the next print 
  168.    --  operation. A value of Result_In_Progress means the operation is running 
  169.    --  asynchronously, and will emit the done signal when done. 
  170.  
  171.    procedure Cancel (Op : access Gtk_Print_Operation_Record); 
  172.    --  Cancels a running print operation. This function may be called from 
  173.    --  a begin-print, paginate or draw-page signal handler to stop the 
  174.    --  currently running print operation. 
  175.  
  176.    procedure Draw_Page_Finish (Op : access Gtk_Print_Operation_Record); 
  177.    --  Signal that drawing of particular page is complete. 
  178.    -- 
  179.    --  It is called after completion of page drawing (e.g. drawing in another 
  180.    --  thread).  If Set_Defer_Drawing was called before, then this function has 
  181.    --  to be called by application. In another case it is called by the library 
  182.    --  itself. 
  183.  
  184.    procedure Get_Error 
  185.      (Op    : access Gtk_Print_Operation_Record; 
  186.       Error : Glib.Error.GError); 
  187.    --  Call this when the result of a print operation is 
  188.    --  Result_Error, either as returned by Run, or in the done signal handler. 
  189.    --  The returned GError will contain more details on what went wrong. 
  190.  
  191.    function Get_Print_Settings 
  192.      (Op : access Gtk_Print_Operation_Record) 
  193.       return Gtk.Print_Settings.Gtk_Print_Settings; 
  194.    procedure Set_Print_Settings 
  195.      (Op             : access Gtk_Print_Operation_Record; 
  196.       Print_Settings : access 
  197.                        Gtk.Print_Settings.Gtk_Print_Settings_Record'Class); 
  198.    --  Manipulate the print settings for Op. This is typically used to 
  199.    --  re-establish print settings from a previous print operation, see Run. 
  200.    -- 
  201.    --  Note that the Get_Print_Setting's return value is null until either 
  202.    --  Set_Print_Settings or Run have been called. 
  203.  
  204.    function Get_Status 
  205.      (Op : access Gtk_Print_Operation_Record) return Gtk_Print_Status; 
  206.    function Get_Status (Op : access Gtk_Print_Operation_Record) return String; 
  207.    --  Returns the status of the print operation. 
  208.    -- 
  209.    --  A Gtk_Print_Status is suitable for programmatic use. 
  210.    -- 
  211.    --  The String returned is a translated string representation of the 
  212.    --  status of the print operation.  It is suitable for displaying the 
  213.    --  print status in, e.g., a Gtk_Statusbar. 
  214.  
  215.    function Is_Finished 
  216.      (Op : access Gtk_Print_Operation_Record) return Boolean; 
  217.    --  A convenience function to find out whether the print operation 
  218.    --  is finished, either successfully (Status_Finished) or unsuccessfully 
  219.    --  (Status_Finished_Aborted). 
  220.    -- 
  221.    --  Note: when you enable print status tracking the print operation 
  222.    --  can be in a non-finished state even after done has been called, as 
  223.    --  the operation status then tracks the print job status on the printer. 
  224.  
  225.    procedure Set_Allow_Async 
  226.      (Op          : access Gtk_Print_Operation_Record; 
  227.       Allow_Async : Boolean); 
  228.    --  Sets whether Run may return before the print operation is completed. 
  229.    --  Note that some platforms may not allow asynchronous operation. 
  230.  
  231.    procedure Set_Current_Page 
  232.      (Op           : access Gtk_Print_Operation_Record; 
  233.       Current_Page : Gint); 
  234.    --  Sets the current page. 
  235.    -- 
  236.    --  If this is called before Run, the user will be able to select to print 
  237.    --  only the current page. 
  238.    -- 
  239.    --  Note that this only makes sense for pre-paginated documents. 
  240.  
  241.    procedure Set_Custom_Tab_Label 
  242.      (Op    : access Gtk_Print_Operation_Record; 
  243.       Label : String); 
  244.    --  Sets the label for the tab holding custom widgets. 
  245.  
  246.    procedure Set_Defer_Drawing (Op : access Gtk_Print_Operation_Record); 
  247.    --  Sets up the Gtk_Print_Operation to wait for calling of Draw_Page_Finish 
  248.    --  from application. It can be used for drawing page in another thread. 
  249.    -- 
  250.    --  This function must be called in the callback of "draw-page" signal. 
  251.  
  252.    procedure Set_Export_Filename 
  253.      (Op       : access Gtk_Print_Operation_Record; 
  254.       Filename : String); 
  255.    --  Sets up the Gtk_Print_Operation to generate a file instead 
  256.    --  of showing the print dialog. The indended use of this function 
  257.    --  is for implementing "Export to PDF" actions. Currently, PDF 
  258.    --  is the only supported format. 
  259.    -- 
  260.    --  "Print to PDF" support is independent of this and is done 
  261.    --  by letting the user pick the "Print to PDF" item from the list 
  262.    --  of printers in the print dialog. 
  263.  
  264.    procedure Set_Job_Name 
  265.      (Op       : access Gtk_Print_Operation_Record; 
  266.       Job_Name : String); 
  267.    --  Sets the name of the print job. The name is used to identify 
  268.    --  the job (e.g. in monitoring applications like eggcups). 
  269.    -- 
  270.    --  If you don't set a job name, GTK+ picks a default one by 
  271.    --  numbering successive print jobs. 
  272.  
  273.    procedure Set_N_Pages 
  274.      (Op      : access Gtk_Print_Operation_Record; 
  275.       N_Pages : Gint); 
  276.    --  Sets the number of pages in the document. 
  277.    -- 
  278.    --  This MUST be set to a positive number before the rendering starts. 
  279.    --  It may be set in a begin-print signal hander. 
  280.    -- 
  281.    --  Note that the page numbers passed to the request-page-setup and 
  282.    --  draw-page signals are 0-based, i.e. if the user chooses to print all 
  283.    --  pages, the last draw-page signal will be for page N_Pages - 1. 
  284.  
  285.    procedure Set_Show_Progress 
  286.      (Op            : access Gtk_Print_Operation_Record; 
  287.       Show_Progress : Boolean); 
  288.    --  If True, the print operation will show a progress dialog during the 
  289.    --  print operation. 
  290.  
  291.    procedure Set_Track_Print_Status 
  292.      (Op           : access Gtk_Print_Operation_Record; 
  293.       Track_Status : Boolean); 
  294.    --  If True, the print operation will try to continue report on the status 
  295.    --  of the print job in the printer queues and printer. This can allow your 
  296.    --  application to show things like "out of paper" issues, and when the 
  297.    --  print job actually reaches the printer. 
  298.    -- 
  299.    --  This function is often implemented using some form of polling, so it 
  300.    --  should not be enabled unless needed. 
  301.  
  302.    procedure Set_Unit 
  303.      (Op   : access Gtk_Print_Operation_Record; 
  304.       Unit : Gtk.Enums.Gtk_Unit); 
  305.    --  Sets up the transformation for the cairo context obtained from 
  306.    --  Gtk_Print_Context in such a way that distances are measured in 
  307.    --  units of Unit. 
  308.  
  309.    procedure Set_Use_Full_Page 
  310.      (Op        : access Gtk_Print_Operation_Record; 
  311.       Full_Page : Boolean); 
  312.    --  If True, the transformation for the cairo context obtained from 
  313.    --  Gtk_Print_Context puts the origin at the top left corner of the page 
  314.    --  (which may not be the top left corner of the sheet, depending on page 
  315.    --  orientation and the number of pages per sheet). Otherwise, the origin 
  316.    --  is at the top left corner of the imageable area (i.e. inside the 
  317.    --  margins). 
  318.  
  319.    ---------------- 
  320.    -- Page Setup -- 
  321.    ---------------- 
  322.  
  323.    function Get_Default_Page_Setup 
  324.      (Op : access Gtk_Print_Operation_Record) 
  325.       return Gtk.Page_Setup.Gtk_Page_Setup; 
  326.    procedure Set_Default_Page_Setup 
  327.      (Op                 : access Gtk_Print_Operation_Record; 
  328.       Default_Page_Setup : access Gtk.Page_Setup.Gtk_Page_Setup_Record'Class); 
  329.    --  Makes Default_Page_Setup the default page setup for Op. 
  330.    --  Default_Page_Setup may be null. 
  331.    -- 
  332.    --  This page setup will be used by Run, but it can be overridden on a 
  333.    --  per-page basis by connecting to the request-page-setup signal. 
  334.  
  335.    function Run_Page_Setup_Dialog 
  336.      (Parent     : access Gtk.Window.Gtk_Window_Record; 
  337.       Page_Setup : access Gtk.Page_Setup.Gtk_Page_Setup_Record'Class; 
  338.       Settings   : access Gtk.Print_Settings.Gtk_Print_Settings_Record'Class) 
  339.       return Gtk.Page_Setup.Gtk_Page_Setup; 
  340.    --  Runs a page setup dialog, letting the user modify the values from 
  341.    --  Page_Setup. If the user cancels the dialog, the returned Gtk_Page_Setup 
  342.    --  is identical to the passed in Page_Setup, otherwise it contains the 
  343.    --  modifications done in the dialog. 
  344.    -- 
  345.    --  Note that this function may use a recursive mainloop to show the page 
  346.    --  setup dialog. 
  347.  
  348.    ---------------- 
  349.    -- Properties -- 
  350.    ---------------- 
  351.  
  352.    --  <properties> 
  353.    --  Name:  Allow_Async_Property 
  354.    --  Type:  Boolean 
  355.    --  Descr: True if print process may run asynchronous. 
  356.    -- 
  357.    --  Name:  Current_Page_Property 
  358.    --  Type:  Int 
  359.    --  Descr: The current page in the document 
  360.    -- 
  361.    --  Name:  Custom_Tab_Label_Property 
  362.    --  Type:  String 
  363.    --  Descr: Label for the tab containing custom widgets. 
  364.    -- 
  365.    --  Name:  Default_Page_Setup_Property 
  366.    --  Type:  Object 
  367.    --  Descr: The Gtk_Page_Setup used by default 
  368.    -- 
  369.    --  Name:  Export_Filename_Property 
  370.    --  Type:  String 
  371.    --  Descr: Export filename 
  372.    -- 
  373.    --  Name:  Job_Name_Property 
  374.    --  Type:  String 
  375.    --  Descr: A string used for identifying the print job. 
  376.    -- 
  377.    --  Name:  N_Pages_Property 
  378.    --  Type:  Int 
  379.    --  Descr: The number of pages in the document. 
  380.    -- 
  381.    --  Name:  Print_Settings_Property 
  382.    --  Type:  Object 
  383.    --  Descr: The Gtk_Print_Settings used for initializing the dialog 
  384.    -- 
  385.    --  Name:  Show_Progress_Property 
  386.    --  Type:  Boolean 
  387.    --  Descr: True if a progress dialog is shown while printing. 
  388.    -- 
  389.    --  Name:  Status_Property 
  390.    --  Type:  Enum 
  391.    --  Descr: The status of the print operation 
  392.    -- 
  393.    --  Name:  Status_String_Property 
  394.    --  Type:  String 
  395.    --  Descr: A human-readable description of the status 
  396.    -- 
  397.    --  Name:  Track_Print_Status_Property 
  398.    --  Type:  Boolean 
  399.    --  Descr: True if the print operation will continue to report on the 
  400.    --         print job status after the print data has been sent to the 
  401.    --         printer or print server. 
  402.    -- 
  403.    --  Name:  Unit_Property 
  404.    --  Type:  Enum 
  405.    --  Descr: The unit in which distances can be measured in the context 
  406.    -- 
  407.    --  Name:  Use_Full_Page_Property 
  408.    --  Type:  Boolean 
  409.    --  Descr: True if the origin of the context should be at the corner of 
  410.    --         the page and not the corner of the imageable area 
  411.    -- 
  412.    --  </properties> 
  413.  
  414.    Allow_Async_Property        : constant Glib.Properties.Property_Boolean; 
  415.    Current_Page_Property       : constant Glib.Properties.Property_Int; 
  416.    Custom_Tab_Label_Property   : constant Glib.Properties.Property_String; 
  417.    Default_Page_Setup_Property : constant Glib.Properties.Property_Object; 
  418.    Export_Filename_Property    : constant Glib.Properties.Property_String; 
  419.    Job_Name_Property           : constant Glib.Properties.Property_String; 
  420.    N_Pages_Property            : constant Glib.Properties.Property_Int; 
  421.    Print_Settings_Property     : constant Glib.Properties.Property_Object; 
  422.    Show_Progress_Property      : constant Glib.Properties.Property_Boolean; 
  423.    Status_Property             : constant Glib.Properties.Property_Enum; 
  424.    Status_String_Property      : constant Glib.Properties.Property_String; 
  425.    Track_Print_Status_Property : constant Glib.Properties.Property_Boolean; 
  426.    Unit_Property               : constant Glib.Properties.Property_Enum; 
  427.    Use_Full_Page_Property      : constant Glib.Properties.Property_Boolean; 
  428.  
  429. private 
  430.  
  431.    type Gtk_Print_Operation_Record is 
  432.      new Glib.Object.GObject_Record with null record; 
  433.  
  434.    Allow_Async_Property : constant Glib.Properties.Property_Boolean := 
  435.      Glib.Properties.Build ("allow-async"); 
  436.    Current_Page_Property : constant Glib.Properties.Property_Int := 
  437.      Glib.Properties.Build ("current-page"); 
  438.    Custom_Tab_Label_Property : constant Glib.Properties.Property_String := 
  439.      Glib.Properties.Build ("custom-tab-label"); 
  440.    Default_Page_Setup_Property : constant Glib.Properties.Property_Object := 
  441.      Glib.Properties.Build ("default-page-setup"); 
  442.    Export_Filename_Property : constant Glib.Properties.Property_String := 
  443.      Glib.Properties.Build ("export-filename"); 
  444.    Job_Name_Property : constant Glib.Properties.Property_String := 
  445.      Glib.Properties.Build ("job-name"); 
  446.    N_Pages_Property : constant Glib.Properties.Property_Int := 
  447.      Glib.Properties.Build ("n-pages"); 
  448.    Print_Settings_Property : constant Glib.Properties.Property_Object := 
  449.      Glib.Properties.Build ("print-settings"); 
  450.    Show_Progress_Property : constant Glib.Properties.Property_Boolean := 
  451.      Glib.Properties.Build ("show-progress"); 
  452.    Status_Property : constant Glib.Properties.Property_Enum := 
  453.      Glib.Properties.Build ("status"); 
  454.    Status_String_Property : constant Glib.Properties.Property_String := 
  455.      Glib.Properties.Build ("status-string"); 
  456.    Track_Print_Status_Property : constant Glib.Properties.Property_Boolean := 
  457.      Glib.Properties.Build ("track-print-status"); 
  458.    Unit_Property : constant Glib.Properties.Property_Enum := 
  459.      Glib.Properties.Build ("unit"); 
  460.    Use_Full_Page_Property : constant Glib.Properties.Property_Boolean := 
  461.      Glib.Properties.Build ("use-full-page"); 
  462.  
  463.    pragma Import (C, Get_Type, "gtk_print_operation_get_type"); 
  464.    pragma Import (C, Error_Quark, "gtk_print_error_quark"); 
  465.  
  466. end Gtk.Print_Operation;