/src/wrappers/gtk/library/gtk_image.e

http://github.com/tybor/Liberty · Specman e · 189 lines · 124 code · 32 blank · 33 comment · 8 complexity · 456732faead5d443f61001e50127259f MD5 · raw file

  1. indexing
  2. description: "GtkImage: A widget displaying an image"
  3. copyright: "[
  4. Copyright (C) 2006 Nicolas Fafchamps <nicolas.fafchamps@gmail.com> and others
  5. Copyright (C) 2006 eiffel-libraries team, GTK+ team
  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. This library is distributed in the hope that it will be useful, but
  11. WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. Lesser General Public License for more details.
  14. You should have received a copy of the GNU Lesser General Public
  15. License along with this library; if not, write to the Free Software
  16. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. 02110-1301 USA
  18. ]"
  19. date: "$Date:$"
  20. revision "$Revision:$"
  21. class GTK_IMAGE
  22. inherit GTK_MISC
  23. insert
  24. GTK_IMAGE_EXTERNALS
  25. GTK_IMAGE_TYPE
  26. GTK_ICON_SIZE
  27. creation
  28. make, from_file, from_external_pointer, from_pixbuf, from_pixmap, from_stock
  29. feature {} -- Initialization
  30. make is
  31. -- Create an empty gtk_image widget.
  32. require gtk_initialized: gtk.is_initialized
  33. do
  34. from_external_pointer (gtk_image_new)
  35. end
  36. from_file (filename: STRING) is
  37. -- Create a `gtk_image' displaying the file `filename'.
  38. -- If the file isn't found or can't be loaded, the
  39. -- resulting `gtk_image' will display a "broken image" icon.
  40. require
  41. gtk_initialized: gtk.is_initialized
  42. filename_not_void: filename/=Void
  43. do
  44. from_external_pointer (gtk_image_new_from_file (filename.to_external))
  45. end
  46. from_pixbuf (pic: GDK_PIXBUF) is
  47. -- Creates a new GtkImage displaying `pic'.
  48. require
  49. gtk_initialized: gtk.is_initialized
  50. pixbuf_not_void: pic /= Void
  51. do
  52. from_external_pointer (gtk_image_new_from_pixbuf (pic.handle))
  53. end
  54. from_pixmap (a_pixmap: GDK_PIXMAP; a_mask: GDK_BITMAP) is
  55. -- Creates a GtkImage widget displaying pixmap with a mask.
  56. -- A GDK_PIXMAP is a server-side image buffer in the pixel
  57. -- format of the current display.
  58. require gtk_initialized: gtk.is_initialized
  59. local
  60. pixmap_ptr, mask_ptr: POINTER
  61. do
  62. if a_pixmap /= Void then pixmap_ptr := a_pixmap.handle end
  63. if a_mask /= Void then mask_ptr := a_mask.handle end
  64. from_external_pointer (gtk_image_new_from_pixmap (pixmap_ptr, mask_ptr))
  65. end
  66. from_stock (a_stock_item: STRING; a_size: INTEGER) is
  67. require
  68. gtk.is_initialized
  69. a_stock_item /= Void
  70. is_valid_gtk_icon_size (a_size)
  71. do
  72. from_external_pointer (gtk_image_new_from_stock (a_stock_item.to_external, a_size))
  73. end
  74. -- Todo : Write gdk_visual, gdk_pixmap, ...
  75. -- Todo : gtk_icon_stock (?), gtk_icon_size (?), I am looking how to good implement.
  76. -- Todo : GtkWidget* gtk_image_new_from_icon_set ()
  77. -- Todo : GtkWidget* gtk_image_new_from_image ()
  78. -- Todo : GtkWidget* gtk_image_new_from_animation ()
  79. -- Todo : GtkWidget* gtk_image_new_from_icon_name ()
  80. feature -- Access
  81. storage_type: INTEGER is
  82. do
  83. Result := gtk_image_get_storage_type (handle)
  84. ensure
  85. is_valid_gtk_image_type (Result)
  86. end
  87. pixbuf: GDK_PIXBUF is
  88. require
  89. storage_type = gtk_image_pixbuf or storage_type = gtk_image_empty
  90. local
  91. pixbuf_ptr: POINTER
  92. factory: G_OBJECT_EXPANDED_FACTORY [GDK_PIXBUF]
  93. do
  94. pixbuf_ptr := gtk_image_get_pixbuf (handle)
  95. if pixbuf_ptr.is_not_null then
  96. Result := factory.wrapper (pixbuf_ptr)
  97. if Result = Void then
  98. -- We use from_external_pointer here because we *need* to
  99. -- increase the pixbuf's refcount
  100. create Result.from_external_pointer (pixbuf_ptr)
  101. end
  102. end
  103. end
  104. feature -- Element change
  105. set_file (filename: STRING) is
  106. -- Set the `gtk_image' displaying the file `filename'.
  107. -- If the file isn't found or can't be loaded, the
  108. -- resulting gtk_image will display a "broken image" icon.
  109. require
  110. valid_filename: filename /= Void
  111. do
  112. gtk_image_set_from_file (handle,filename.to_external)
  113. end
  114. set_from_pixbuf (a_pixbuf: GDK_PIXBUF) is
  115. -- See `from_pixbuf' for details.
  116. require
  117. valid_pixbuf: a_pixbuf /= Void
  118. do
  119. gtk_image_set_from_pixbuf (handle, a_pixbuf.handle)
  120. end
  121. set_from_pixmap (a_pixmap: GDK_PIXMAP; a_mask: GDK_BITMAP) is
  122. -- See `from_pixmap' for details.
  123. local
  124. pixmap_ptr, mask_ptr: POINTER
  125. do
  126. if a_pixmap /= Void then pixmap_ptr := a_pixmap.handle end
  127. if a_mask /= Void then mask_ptr := a_mask.handle end
  128. gtk_image_set_from_pixmap (handle, pixmap_ptr, mask_ptr)
  129. end
  130. feature -- Status setting
  131. set_pixel_size (a_pixel_size : INTEGER) is
  132. -- Sets the pixel size to use.
  133. do
  134. gtk_image_set_pixel_size (handle,a_pixel_size)
  135. end
  136. -- Todo : Write gdk_visual, gdk_pixmap, ...
  137. -- Todo : gtk_icon_stock (?), gtk_icon_size (?), I am looking how to good implement.
  138. -- Todo : void gtk_image_set_from_file ()
  139. -- Todo : void gtk_image_set_from_icon_set ()
  140. -- Todo : void gtk_image_set_from_image ()
  141. -- Todo : void gtk_image_set_from_pixbuf ()
  142. -- Todo : void gtk_image_set_from_pixmap ()
  143. -- Todo : void gtk_image_set_from_stock ()
  144. -- Todo : void gtk_image_set_from_animation ()
  145. -- Todo : void gtk_image_set_from_icon_name ()
  146. feature -- Status report
  147. pixel_size : INTEGER is
  148. -- Pixel size used.
  149. do
  150. Result := gtk_image_get_pixel_size (handle)
  151. end
  152. feature
  153. struct_size: INTEGER is
  154. external "C inline use <gtk/gtk.h>"
  155. alias "sizeof(GtkImage)"
  156. end
  157. end