1. ------------------------------------------------------------------------------ 
  2. --                  GtkAda - Ada95 binding for Gtk+/Gnome                   -- 
  3. --                                                                          -- 
  4. --                     Copyright (C) 2010-2014, AdaCore                     -- 
  5. --                                                                          -- 
  6. -- This library is free software;  you can redistribute it and/or modify it -- 
  7. -- under terms of the  GNU General Public License  as published by the Free -- 
  8. -- Software  Foundation;  either version 3,  or (at your  option) any later -- 
  9. -- version. This library is distributed in the hope that it will be useful, -- 
  10. -- but WITHOUT ANY WARRANTY;  without even the implied warranty of MERCHAN- -- 
  11. -- TABILITY or FITNESS FOR A PARTICULAR PURPOSE.                            -- 
  12. --                                                                          -- 
  13. -- As a special exception under Section 7 of GPL version 3, you are granted -- 
  14. -- additional permissions described in the GCC Runtime Library Exception,   -- 
  15. -- version 3.1, as published by the Free Software Foundation.               -- 
  16. --                                                                          -- 
  17. -- You should have received a copy of the GNU General Public License and    -- 
  18. -- a copy of the GCC Runtime Library Exception along with this program;     -- 
  19. -- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    -- 
  20. -- <http://www.gnu.org/licenses/>.                                          -- 
  21. --                                                                          -- 
  22. ------------------------------------------------------------------------------ 
  23.  
  24. --  <description> 
  25. --  This package provides a ready-to-use high level printing object. 
  26. --  Use functionality from Gtk.Print_Operation to manipulate the 
  27. --  printing object, and the functionality in this package to provide 
  28. --  the handlers for the printing operation. 
  29. -- 
  30. --  Typically, to use this high-level printing API: 
  31. --    - derive from the Gtkada_Print_Operation_Record object 
  32. --    - override the Draw_Page operation 
  33. --    - (optional) override any other operation useful to you 
  34. --    - start the print operation by 
  35. --          - first setting the number of pages through Set_N_Pages 
  36. --          - then calling Connect_And_Run. 
  37. --  A dialog will be displayed, letting the user select a printer and options. 
  38. --  When the user finishes the dialog, various signals will be emitted on the 
  39. --  Gtkada_Print_Operation, which will call the operations on your object. 
  40. -- 
  41. --  Note: on UNIX/Linux, Gtk+ is loading at run-time the libraries for printing 
  42. --  support. You will need to point the environment variable GTK_EXE_PREFIX 
  43. --  to the root directory of your Gtk+ install before calling Connect_And_Run. 
  44. --  </description> 
  45. --  <example> 
  46. -- 
  47. --     --  Create a derived type 
  48. -- 
  49. --     type Print_Op_Record is new Gtkada_Print_Operation_Record 
  50. --     with record 
  51. --        My_Data : My_Type; 
  52. --     end record; 
  53. --     type Print_Op_Access is access all Print_Op_Record'Class; 
  54. -- 
  55. --     --  Override Draw_Page 
  56. -- 
  57. --     procedure Draw_Page 
  58. --       (Print_Operation : access Print_Op_Record; 
  59. --        Context         : Gtk_Print_Context; 
  60. --        Page_Num        : Gint) 
  61. --     is 
  62. --        Cr : Cairo_Context; 
  63. --     begin 
  64. --        Cr := Get_Cairo_Context (Context); 
  65. -- 
  66. --        --  Do drawing here 
  67. -- 
  68. --     end Draw_Page; 
  69. -- 
  70. -- 
  71. --     --  Do the printing 
  72. --     declare 
  73. --        Print_Op : Print_Op_Access; 
  74. --        Result   : Gtk_Print_Operation_Result; 
  75. --     begin 
  76. --        --  Initialize 
  77. --        Print_Op := new Print_Op_Record; 
  78. --        Print_Op.My_Data := Some_Data; 
  79. -- 
  80. --        --  Set the number of pages to print 
  81. --        Set_N_Pages (Print_Op, 2); 
  82. -- 
  83. --        --  Launch the printing 
  84. --        Result := Connect_And_Run 
  85. --          (Print_Op, Action_Print_Dialog, Gtk_Window (Get_Toplevel (Frame))); 
  86. --     end; 
  87. -- 
  88. --  </example> 
  89. --  <group>Miscellaneous</group> 
  90.  
  91. with Glib; use Glib; 
  92. with Glib.Error; 
  93.  
  94. with Gtk.Page_Setup;              use Gtk.Page_Setup; 
  95. with Gtk.Print_Context;           use Gtk.Print_Context; 
  96. with Gtk.Print_Operation;         use Gtk.Print_Operation; 
  97. with Gtk.Print_Operation_Preview; use Gtk.Print_Operation_Preview; 
  98. with Gtk.Window;                  use Gtk.Window; 
  99.  
  100. package Gtkada.Printing is 
  101.  
  102.    type Gtkada_Print_Operation_Record is new 
  103.      Gtk_Print_Operation_Record with private; 
  104.    type Gtkada_Print_Operation is access all Gtkada_Print_Operation_Record; 
  105.  
  106.    procedure Gtk_New (Op : out Gtkada_Print_Operation); 
  107.    procedure Initialize (Widget : access Gtkada_Print_Operation_Record'Class); 
  108.    --  Initialize the print operation 
  109.  
  110.    function Connect_And_Run 
  111.      (Op        : access Gtkada_Print_Operation_Record'Class; 
  112.       Action    : Gtk_Print_Operation_Action; 
  113.       Parent    : access Gtk_Window_Record'Class; 
  114.       Error     : Glib.Error.GError := null) 
  115.       return Gtk_Print_Operation_Result; 
  116.    --  Runs the print operation, using the handlers installed in Op. 
  117.    --  See Gtk.Print_Operations.Run. 
  118.  
  119.    ------------------------- 
  120.    -- Printing operations -- 
  121.    ------------------------- 
  122.  
  123.    --  The following primitive operations are called by the printing procedure. 
  124.    --  By default, these operations do nothing. 
  125.    --  It is mandatory to override Draw_Page, the other callbacks are optional. 
  126.  
  127.    procedure Draw_Page 
  128.      (Op          : access Gtkada_Print_Operation_Record; 
  129.       Context     : Gtk_Print_Context; 
  130.       Page_Number : Gint); 
  131.    --  Called for every page that is printed. This handler must render the 
  132.    --  page Page_Number onto the cairo context obtained from Context using 
  133.    --  Gtk.Print_Context.Get_Cairo_Context. 
  134.    -- 
  135.    --  Use Gtk.Print_Operation.Set_Use_Full_Page and 
  136.    --  Gtk.Print_Operation.Set_Unit before starting the print operation to set 
  137.    --  up the transformation of the cairo context according to your needs. 
  138.    -- 
  139.    --  This is the main printing handler. This has to be overriden for the 
  140.    --  printing operation to work. 
  141.  
  142.    procedure Begin_Print 
  143.      (Op      : access Gtkada_Print_Operation_Record; 
  144.       Context : Gtk_Print_Context); 
  145.    --  Called after the user has finished changing print settings in the 
  146.    --  dialog, before the actual rendering starts. 
  147.    -- 
  148.    --  A typical use is to use the parameters from the 
  149.    --  Gtk_Print_Context and paginate the document accordingly, and then 
  150.    --  set the number of pages with Gtk.Print_Operation.Set_N_Pages. 
  151.  
  152.    procedure Done 
  153.      (Op     : access Gtkada_Print_Operation_Record; 
  154.       Result : Gtk_Print_Operation_Result); 
  155.    --  Called when the print operation run has finished doing everything 
  156.    --  required for printing. 
  157.    -- 
  158.    --  Result gives you information about what happened during the run. 
  159.    --  If Result is Result_Error then you can call Get_Error for more 
  160.    --  information. 
  161.    -- 
  162.    --  If you enabled print status tracking then 
  163.    --  Gtk.Print_Operation.Is_Finished may still return False after 
  164.    --  done was emitted. 
  165.  
  166.    procedure End_Print 
  167.      (Op      : access Gtkada_Print_Operation_Record; 
  168.       Context : Gtk_Print_Context); 
  169.    --  Called after all pages have been rendered. 
  170.    -- 
  171.    --  This handler can clean up any resources that have been allocated 
  172.    --  in Begin_Print. 
  173.  
  174.    function Paginate 
  175.      (Op      : access Gtkada_Print_Operation_Record; 
  176.       Context : Gtk_Print_Context) return Boolean; 
  177.    --  Called after the "begin-print" signal, but before the actual rendering 
  178.    --  starts. It keeps getting called until it returns True. 
  179.    -- 
  180.    --  The "paginate" signal is intended to be used for paginating a document 
  181.    --  in small chunks, to avoid blocking the user interface for a long 
  182.    --  time. This function should update the number of pages using 
  183.    --  Gtk.Print_Operation.Set_N_Pages, and return True if the document 
  184.    --  has been completely paginated. 
  185.    -- 
  186.    --  If you don't need to do pagination in chunks, you can simply do 
  187.    --  it all in the "begin-print" handler, and set the number of pages 
  188.    --  from there. 
  189.  
  190.    function Preview 
  191.      (Op          : access Gtkada_Print_Operation_Record; 
  192.       Preview     : Gtk_Print_Operation_Preview; 
  193.       Context     : Gtk_Print_Context; 
  194.       Parent      : Gtk_Window) 
  195.      return Boolean; 
  196.    --  Called when a preview is requested from the native dialog. 
  197.    --  This should return True if the in order to take over control of the 
  198.    --  preview. 
  199.    -- 
  200.    --  The default handler for this signal uses an external viewer 
  201.    --  application to preview. 
  202.    -- 
  203.    --  To implement a custom print preview, the overridden implementation 
  204.    --  should return True 
  205.    --  In order to use the provided Context for the preview implementation, it 
  206.    --  must be given a suitable cairo context with Set_Cairo_Context. 
  207.    -- 
  208.    --  The custom preview implementation can use 
  209.    --  Gtk.Print_Operation_Preview.Is_Selected and 
  210.    --  Gtk.Print_Operation_Preview.Render_Page to find pages which 
  211.    --  are selected for print and render them. The preview must be 
  212.    --  finished by calling Gtk.Print_Operation_Preview.End_Preview 
  213.    --  (typically in response to the user clicking a close button). 
  214.  
  215.    procedure Request_Page_Setup 
  216.      (Op          : access Gtkada_Print_Operation_Record; 
  217.       Context     : Gtk_Print_Context; 
  218.       Page_Number : Gint; 
  219.       Setup       : Gtk_Page_Setup); 
  220.    --  Called once for every page that is printed, to give the application 
  221.    --  a chance to modify the page setup. Any changes done to setup will be 
  222.    --  in force only for printing this page. 
  223.  
  224.    procedure Status_Changed (Op : access Gtkada_Print_Operation_Record); 
  225.    --  Called between the various phases of the print operation. 
  226.    --  See Gtk_Print_Status for the phases that are being discriminated. 
  227.    --  Use Gtk.Print_Operation.Get_Status to find out the current 
  228.    --  status. 
  229.  
  230. private 
  231.  
  232.    type Gtkada_Print_Operation_Record is new Gtk_Print_Operation_Record with 
  233.      null record; 
  234.  
  235. end Gtkada.Printing;