PageRenderTime 27ms CodeModel.GetById 16ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/src/wrappers/gtk/library/gtk_paper_size.e

http://github.com/tybor/Liberty
Specman e | 225 lines | 138 code | 42 blank | 45 comment | 6 complexity | d8acfe12cd75a53f0ada2dda3200182f MD5 | raw file
  1indexing
  2	description: "Named paper sizes."
  3	copyright: "[
  4					Copyright (C) 2007 Paolo Redaelli, GTK+ team
  5					
  6					This library is free software; you can redistribute it and/or
  7					modify it under the terms of the GNU Lesser General Public License
  8					as published by the Free Software Foundation; either version 2.1 of
  9					the License, or (at your option) any later version.
 10					
 11					This library is distributed in the hopeOA that it will be useful, but
 12					WITHOUT ANY WARRANTY; without even the implied warranty of
 13					MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 14					Lesser General Public License for more details.
 15
 16					You should have received a copy of the GNU Lesser General Public
 17					License along with this library; if not, write to the Free Software
 18					Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 19					02110-1301 USA
 20			]"
 21
 22	wrapped_version: "2.10.6"
 23
 24class GTK_PAPER_SIZE
 25	-- GtkPaperSize handles paper sizes. It uses the standard called
 26	-- "PWG 5101.1-2002 PWG: Standard for Media Standardized Names" to
 27	-- name the paper sizes (and to get the data for the page
 28	-- sizes). In addition to standard paper sizes, GtkPaperSize allows
 29	-- to construct custom paper sizes with arbitrary dimensions.
 30
 31	-- The GtkPaperSize object stores not only the dimensions (width
 32	-- and height) of a paper size and its name, it also provides
 33	-- default print margins.
 34
 35	-- Printing support has been added in GTK+ 2.10.
 36
 37inherit
 38	C_STRUCT 
 39		undefine free 
 40		redefine copy, is_equal 
 41		end
 42	EIFFEL_OWNED undefine free end
 43
 44insert 
 45	GTK_PAPER_SIZE_EXTERNALS rename gtk_paper_size_free as free end
 46	GTK_UNIT 
 47
 48creation make, from_external_pointer
 49
 50feature {} -- Creation
 51	make (a_paper_name: STRING) is
 52			-- Creates a new GtkPaperSize object by parsing a PWG
 53			-- 5101.1-2002 PWG `a_paper_name'.
 54		require name_not_void: a_paper_name /= Void
 55		do
 56			from_external_pointer(gtk_paper_size_new(a_paper_name.to_external))
 57		end
 58
 59	make_default is 
 60			-- Creates a new GtkPaperSize object for the default paper
 61			-- size.
 62		do
 63			from_external_pointer(gtk_paper_size_new(default_pointer))
 64		end
 65
 66	from_ppd (a_ppd_name, a_ppd_display_name: STRING; a_width, an_height: REAL) is
 67			-- Creates a new GtkPaperSize object by using PPD
 68			-- information.
 69
 70			-- If `a_ppd_name' is not a recognized PPD paper name,
 71			-- `a_ppd_display_name,' `a_width' and `an_height' are used
 72			-- to construct a custom GtkPaperSize object.
 73
 74			-- `a_ppd_name' a PPD paper name
 75
 76			-- `a_ppd_display_name' the corresponding human-readable name
 77
 78			--  `a_width' : the paper width, in points
 79
 80			--   `an_height' : the paper height in points
 81		require 
 82			name_not_void: a_ppd_name /= Void
 83			display_name_not_void: a_ppd_display_name /= Void
 84		do
 85			from_external_pointer (gtk_paper_size_new_from_ppd
 86										  (a_ppd_name.to_external, a_ppd_display_name.to_external,
 87											a_width, an_height))
 88		end
 89
 90	make_custom (a_name, a_display_name: STRING; a_width, an_height: REAL; a_unit: INTEGER) is
 91			-- Creates a new GtkPaperSize object with the given
 92			-- parameters.
 93			
 94			-- `a_name' : the paper name
 95
 96			-- `a_display_name' : the human-readable name
 97
 98			-- `a_width' : the paper width, in units of `a_unit'
 99
100			-- `an_height' : the paper height, in units of `a_unit'
101
102			--  `a_unit' : the unit for `a_width' and `an_height'
103		require 
104			name_not_void: a_name /= Void
105			display_name_not_void: a_display_name /= Void
106			valid_unit: is_valid_gtk_unit (a_unit)
107		do
108			from_external_pointer(gtk_paper_size_new_custom
109										 (a_name.to_external, a_display_name.to_external,
110										  a_width, an_height, a_unit))
111		end	
112	
113feature -- Copying
114	copy (another: GTK_PAPER_SIZE) is
115			--   Copies an existing GtkPaperSize.
116		do
117			from_external_pointer(gtk_paper_size_copy(another.handle))
118		end	
119
120feature -- Queries
121	is_equal (another: GTK_PAPER_SIZE): BOOLEAN is
122			-- Do Current and `another' represent the same paper size?
123		do
124			Result:=gtk_paper_size_is_equal(handle, another.handle).to_boolean
125		end
126
127	name: CONST_STRING is
128			-- the name of the GtkPaperSize.
129		do
130			if stored_name=Void then 
131				create stored_name.from_external (gtk_paper_size_get_name(handle))
132			end
133			Result:=stored_name
134		end
135
136	display_name: CONST_STRING is
137			-- the human-readable name of the GtkPaperSize.
138		do
139			if stored_display_name=Void then
140				create stored_display_name.from_external (gtk_paper_size_get_display_name(handle))
141			end
142			Result:=stored_display_name
143		end
144	
145	ppd_name:CONST_STRING is
146			-- the PPD name of the GtkPaperSize, which may be Void.
147		local ptr: POINTER
148		do
149			if not ppd_name_retrieved then
150				ptr:=gtk_paper_size_get_ppd_name(handle)
151				if ptr.is_not_null then
152					create stored_ppd_name.from_external(ptr)
153				end
154				ppd_name_retrieved:=True
155			end
156			Result:=stored_ppd_name
157		end
158
159	unit: INTEGER 
160			-- the unit measure for all the further queries
161	
162	width: REAL is
163			-- the paper width of the GtkPaperSize
164		do
165			Result:=gtk_paper_size_get_width(handle, unit)
166		end
167
168	height: REAL is
169			--  the paper height of the GtkPaperSize
170		do
171			Result:=gtk_paper_size_get_height(handle, unit)
172		end
173	
174	is_custom: BOOLEAN is
175			-- Is size not a standard paper size?
176		do
177			Result:=gtk_paper_size_is_custom(handle).to_boolean
178		end
179
180	default_top_margin: REAL is
181			-- The default top margin for the GtkPaperSize.
182		do
183			Result:=gtk_paper_size_get_default_top_margin(handle,unit)
184		end
185
186	default_bottom_margin: REAL is
187			--  the default bottom margin for the GtkPaperSize.
188		do
189			Result:=gtk_paper_size_get_default_bottom_margin(handle,unit)
190		end
191
192	default_left_margin: REAL is
193			-- the default left margin for the GtkPaperSize.
194		do
195			Result:=gtk_paper_size_get_default_left_margin(handle, unit)
196		end
197
198	default_right_margin: REAL is
199			-- the default right margin for the GtkPaperSize.
200		do
201			Result:=gtk_paper_size_get_default_right_margin(handle,unit)
202		end
203
204feature -- Setters
205	set_unit (a_unit: INTEGER) is
206			-- Set the unit measure for all the further queries
207		do
208			unit:=a_unit
209		ensure set: unit = a_unit
210		end
211	
212	set_size (a_width, an_height: REAL; a_unit: INTEGER) is
213			-- Changes the dimensions of a size to `a_width' x `an_height', 
214			-- expressed in `a_unit'.
215		require valid_unit: is_valid_gtk_unit(a_unit)
216		do
217			gtk_paper_size_set_size(handle, a_width, an_height, a_unit)
218		end
219
220feature {} -- Implementation
221	stored_name, stored_display_name, stored_ppd_name: CONST_STRING
222	ppd_name_retrieved: BOOLEAN
223	
224end -- class GTK_PAPER_SIZE
225