1{%MainUnit Gtk2Extra.pp} 2{ $Id$ } 3{ 4 ***************************************************************************** 5 This file is part of the Lazarus Component Library (LCL) 6 7 See the file COPYING.modifiedLGPL.txt, included in this distribution, 8 for details about the license. 9 ***************************************************************************** 10} 11 12uses 13 dynlibs, 14 {$ifdef HasX} 15 xlib, x, 16 {$endif} 17 glib2, gdk2, gtk2, gtk2ext, 18 {$IF FPC_FULLVERSION<20600} 19 gdk2pixbuf, 20 {$ENDIF} 21 {$ifdef HasGdk2X} 22 gdk2x, 23 {$endif} 24 Pango; 25 26const 27 { This is equired when people don't have -dev/-devel packages on linux. 28 I'm not sure how Darwin is handled tho } 29 {$ifdef windows} 30 GLibNames: array[1..1] of string = (gliblib); 31 {$else} 32 {$ifdef darwin} // Mac/Darwin 33 GLibNames: array[1..1] of string = (gliblib); // TODO: I don't know this one! 34 {$else} // BSD, Solaris, Linux 35 GLibNames: array[1..2] of string = (gliblib, gliblib + '.0'); 36 {$endif} 37 {$endif} 38 39const 40 gdkdll = gdklib; 41 // additional response codes for gtk2 42 GTK_RESPONSE_LCL_ALL = GTK_RESPONSE_APPLY; 43 GTK_RESPONSE_LCL_YESTOALL = GTK_RESPONSE_ACCEPT; 44 GTK_RESPONSE_LCL_RETRY = -12; 45 GTK_RESPONSE_LCL_IGNORE = -13; 46 GTK_RESPONSE_LCL_NOTOALL = -14; 47 48{$IF FPC_FULLVERSION<20600} 49// missing declarations in fpc 2.2 50const 51 GTK_CELL_RENDERER_FOCUSED = 1 shl 4; 52{$ENDIF} 53 54{$IFNDEF MSWINDOWS} // this is required for compilation under windows 55{$if defined(HasX)} // This is required for compilation under Mac OS X 56var 57 gdk_display: PDisplay; external gdklib name 'gdk_display'; 58 59function gdk_window_xwindow(win : PGdkDrawable): TXID; cdecl; external gdklib name 'gdk_x11_drawable_get_xid'; 60function gdk_x11_image_get_ximage(image:PGdkImage):PXImage;cdecl;external gdklib name 'gdk_x11_image_get_ximage'; 61{$endif} 62{$ENDIF} 63 64procedure laz_gdk_gc_set_dashes(gc:PGdkGC; dash_offset:gint; 65 dashlist:Pgint8; n:gint); cdecl; external gdkdll name 'gdk_gc_set_dashes'; 66// - - - - - - - - - pango extras - - - - - - - - - 67 68 69function pango_unichar_direction(ch : gunichar) : TPangoDirection; cdecl; external pangolib; 70 71// pango 1.4 72function pango_find_base_dir(text : Pgchar; aLength : gint) : TPangoDirection; cdecl; external pangolib; 73 74type 75 PPPangoAttrList = ^PPangoAttrList; 76// pango 1.16 77 PPangoGravity = ^TPangoGravity; 78 TPangoGravity = ( 79 PANGO_GRAVITY_SOUTH, 80 PANGO_GRAVITY_EAST, 81 PANGO_GRAVITY_NORTH, 82 PANGO_GRAVITY_WEST, 83 PANGO_GRAVITY_AUTO 84 ); 85 86{$IF FPC_FULLVERSION<20600} 87// ----------------- this pango symbols can be removed after fpc 2.2.4 88// pango 1.6 89 PPangoMatrix = ^TPangoMatrix; 90 TPangoMatrix = record 91 xx: double; 92 xy: double; 93 yx: double; 94 yy: double; 95 x0: double; 96 y0: double; 97 end; 98 99// pango 1.8 100 101 TPangoRenderer = pointer; 102 PPangoRenderer = ^TPangoRenderer; 103 TPangoRenderPart = ( 104 PANGO_RENDER_PART_FOREGROUND, 105 PANGO_RENDER_PART_BACKGROUND, 106 PANGO_RENDER_PART_UNDERLINE, 107 PANGO_RENDER_PART_STRIKETHROUGH 108 ); 109 110procedure pango_renderer_draw_layout(renderer: PPangoRenderer; layout: PPangoLayout; x, y: Integer); cdecl; external pangolib; 111procedure pango_matrix_translate(matrix: PPangoMatrix; tx, ty: double); cdecl; external pangolib; 112procedure pango_matrix_rotate(matrix: PPangoMatrix; degrees: double); cdecl; external pangolib; 113{$ENDIF} 114 115// ------------------end of symbold to remove -------------------------- 116 117function pango_context_get_gravity(Context: PPangoContext): TPangoGravity; cdecl; external pangolib; 118procedure pango_context_set_base_gravity(Context: PPangoContext; gravity: TPangoGravity); cdecl; external pangolib; 119 120function pango_context_get_matrix(Context: PPangoContext): PPangoMatrix; cdecl; external pangolib; 121procedure pango_context_set_matrix(context: PPangoContext; const matrix: PPangoMatrix); cdecl; external pangolib; 122 123function pango_font_description_get_gravity(desc: PPangoFontDescription): TPangoGravity; cdecl; external pangolib; 124procedure pango_font_description_set_gravity(desc: PPangoFontDescription; gravity: TPangoGravity); cdecl; external pangolib; 125 126function pango_attr_gravity_new(gravity: TPangoGravity): PPangoAttribute; cdecl; external pangolib; 127 128function pango_version_check(required_major, required_minor, required_micro: integer): PChar; cdecl; external pangolib; 129 130procedure pango_extents_to_pixels(inclusive: PPangoRectangle; nearest: PPangoRectangle); cdecl; external pangolib; 131 132{$IF FPC_FULLVERSION<20501} 133function pango_font_family_is_monospace(family:PPangoFontFamily):gboolean; cdecl; external pangolib; 134{$ENDIF} 135 136 137// - - - - - - - - - gtk extras - - - - - - - - - 138 139// ----------------- this gtk symbols can be removed after fpc 2.2.4 140 141{$IF FPC_FULLVERSION<20600} 142// gtk 2.2 143function gtk_tree_path_new_from_indices(first_index: gint): PGtkTreePath; cdecl; varargs; external gtklib name 'gtk_tree_path_new_from_indices'; 144 145// gtk 2.4 146procedure gtk_toolbar_insert(toolbar: PGtkToolBar; item: PGtkToolItem; pos: gint); cdecl; external gtklib name 'gtk_toolbar_insert'; 147procedure gtk_event_box_set_visible_window(event_box: PGtkEventBox; visible_window: gboolean); cdecl; external gtklib name 'gtk_event_box_set_visible_window'; 148procedure gtk_event_box_set_above_child(event_box: PGtkEventBox; visible_window: gboolean); cdecl; external gtklib name 'gtk_event_box_set_above_child'; 149procedure gtk_draw_insertion_cursor(widget:PGtkWidget; drawable:PGdkDrawable; area:PGdkRectangle; location:PGdkRectangle; is_primary:gboolean; 150 direction:TGtkTextDirection; draw_arrow:gboolean); cdecl; external gtklib; 151{$ENDIF} 152 153// gtk 2.6 154type 155 PGtkCellView = ^TGtkCellView; 156 TGtkCellView = record 157 parent_instance: TGtkWidget; 158 159 // private 160 model: PGtkTreeModel; 161 displayed_row: PGtkTreeRowReference; 162 cell_list: PGList; 163 spacing: gint; 164 background: TGdkColor; 165 background_set: gboolean; 166 end; 167function GTK_TYPE_CELL_VIEW : GType; 168function GTK_CELL_VIEW(obj: pointer) : PGtkCellView; 169//function GTK_CELL_VIEW_CLASS(klass: pointer) : PGtkCellViewClass; 170function GTK_IS_CELL_VIEW(obj: pointer) : boolean; 171function GTK_IS_CELL_VIEW_CLASS(klass: pointer) : boolean; 172//function GTK_CELL_VIEW_GET_CLASS(obj: pointer) : PGtkCellViewClass; 173function gtk_cell_view_get_type:TGtkType; cdecl; external gtklib; 174function gtk_cell_view_get_model(cell_view: PGtkCellView): PGtkTreeModel; 175function gtk_cell_view_get_displayed_row(cell_view: PGtkCellView): PGtkTreePath; cdecl; external gtklib name 'gtk_cell_view_get_displayed_row'; 176procedure gtk_file_chooser_set_show_hidden(chooser: PGtkFileChooser; show_hidden: gboolean); cdecl; external gtklib name 'gtk_file_chooser_set_show_hidden'; 177// ------------------end of symbold to remove -------------------------- 178 179procedure gtk_im_context_get_preedit_string_laz(context:PGtkIMContext; str:PPgchar; attrs:PPPangoAttrList; cursor_pos:Pgint); cdecl; external gtklib name 'gtk_im_context_get_preedit_string'; 180 181// - - - - - - - - - gdk extras - - - - - - - - - 182 183{$ifdef GTK_2_8} 184// gdk 2.8 185procedure gdk_display_warp_pointer(display: PGdkDisplay; screen: PGdkScreen; x, y: gint); cdecl; external gdklib; 186function gdk_screen_get_rgba_colormap(screen: PGdkScreen): PGdkColormap; cdecl; external gdklib; 187procedure gdk_window_move_region(window: PGdkWindow ; region: PGdkRegion; dx, dy: gint);cdecl; external gdklib; 188 189type 190 _PGtkIconViewPrivate = ^_GtkIconViewPrivate; {private struct of GtkIconView, used to fix #22778} 191 _GtkIconViewPrivate = record 192 Width: Gint; 193 Height: Gint; 194 Selection_Mode: PGtkSelectionMode; 195 196 bin_window: PGdkWindow; 197 children: PGList; 198 Model: PGtkTreeModel; 199 Items: PGList; 200 201 hadjustment: PGtkAdjustment; 202 vadjustment: PGtkAdjustment; 203 204 layout_idle_id: guint; 205 206 doing_rubberband: gboolean; 207 rubberband_x1: gint; 208 rubberband_y1: gint; 209 rubberband_x2: gint; 210 rubberband_y2: gint; 211 scroll_timeout_id: guint; 212 scroll_value_diff: gint; 213 event_last_x: gint; 214 event_last_y: gint; 215 anchor_item: Pointer; // PGtkIconViewItem; 216 cursor_item: Pointer; // PGtkIconViewItem; 217 edited_item: Pointer; // PGtkIconViewItem; 218 editable_item: Pointer; // PGtkCellEditable; 219 last_single_clicked: Pointer; // PGtkIconViewItem; 220 221 cell_list: PGList; 222 n_cells: guint; 223 cursor_cell: gint; 224 225 226 orientation: TGtkOrientation; 227 228 columns: gint; 229 item_width: gint; 230 spacing: gint; 231 row_spacing: gint; 232 column_spacing: gint; 233 margin: gint; 234 item_padding: gint; 235 text_column: gint; 236 markup_column: gint; 237 pixbuf_column: gint; 238 pixbuf_cell: gint; 239 text_cell: gint; 240 tooltip_column: gint; 241 242 // * Drag-and-drop. */ 243 start_button_mask: TGdkModifierType; 244 pressed_button: gint; 245 press_start_x: gint; 246 press_start_y: gint; 247 248 source_actions: TGdkDragAction; 249 dest_actions: TGdkDragAction; 250 251 dest_item: PGtkTreeRowReference; 252 dest_pos: guint; // TGtkIconViewDropPosition; 253 254 // * scroll to */ 255 scroll_to_path: PGtkTreeRowReference; 256 scroll_to_row_align: gfloat; 257 scroll_to_col_align: gfloat; 258 scroll_to_use_align: guint; 259 260 source_set: guint; 261 dest_set: guint; 262 reorderable: guint; 263 empty_view_drop: guint; 264 265 ctrl_pressed: guint; 266 shift_pressed: guint; 267 268 draw_focus: guint; 269 end; 270 271 TGtkPackDirection = longint; 272 273const 274 GTK_PACK_DIRECTION_LTR = 0; 275 GTK_PACK_DIRECTION_RTL = 1; 276 GTK_PACK_DIRECTION_TTB = 2; 277 GTK_PACK_DIRECTION_BTT = 3; 278 279procedure gtk_menu_bar_set_pack_direction(menubar : PGtkMenuBar; pack_dir : TGtkPackDirection); cdecl; external gtklib; 280procedure gtk_menu_bar_set_child_pack_direction(menubar : PGtkMenuBar; pack_dir : TGtkPackDirection); cdecl; external gtklib; 281{$IF FPC_FULLVERSION<20600} 282procedure gtk_file_chooser_set_do_overwrite_confirmation(chooser:PGtkFileChooser; do_overwrite_confirmation:gboolean); cdecl; external gtklib; 283{$ENDIF} 284procedure gtk_icon_view_scroll_to_path(icon_view: PGtkIconView; path: PGtkTreePath; use_align: gboolean; row_align: gfloat; col_align: gfloat); cdecl; external gtklib; 285function gtk_icon_view_get_cursor(icon_view: PGtkIconView; var path: PGtkTreePath; var cell: PGtkCellRenderer): gboolean; cdecl; external gtklib; 286procedure gtk_icon_view_set_cursor(icon_view: PGtkIconView; path: PGtkTreePath; cell: PGtkCellRenderer; start_editing: gboolean); cdecl; external gtklib; 287function gtk_tree_view_get_visible_range(tree_view: PGtkTreeView; out start_path, endpath: PGtkTreePath): gboolean; cdecl; external gtklib; 288function gtk_icon_view_get_visible_range(tree_view: PGtkTreeView; out start_path, endpath: PGtkTreePath): gboolean; cdecl; external gtklib; 289function gtk_icon_view_get_item_at_pos(icon_view: PGtkIconView; x: gint; y: gint; var path: PGtkTreePath; var cell: PGtkCellRenderer): gboolean; cdecl; external gtklib; 290 291procedure gtk_tree_view_column_queue_resize(tree_column: PGtkTreeViewColumn); cdecl; external gtklib; 292 293{$endif} 294const 295 GDK_WINDOW_OFFSCREEN_lcl = 6; // ToDo: move to fpc 296{$ifdef GTK_2_10} 297function gdk_screen_is_composited(screen: PGdkScreen): gboolean; cdecl; external gdklib; 298{$endif} 299 300type 301 TGtkTreeViewGridLines = cardinal; 302 303const 304 GTK_TREE_VIEW_GRID_LINES_NONE = 0; 305 GTK_TREE_VIEW_GRID_LINES_HORIZONTAL = 1; 306 GTK_TREE_VIEW_GRID_LINES_VERTICAL = 2; 307 GTK_TREE_VIEW_GRID_LINES_BOTH = 3; 308 309var 310 gtk_window_set_opacity: procedure(window: PGtkWindow; opacity: gdouble); cdecl; 311 g_object_ref_sink: function(anObject: PGObject): gpointer; cdecl; 312 gdk_window_get_cursor: function(window: PGdkWindow): PGdkCursor; cdecl; 313 // since 2.20 314 gdk_screen_get_primary_monitor: function(screen: PGdkScreen): gint; cdecl; 315 316 // since 2.10 317 gtk_tree_view_set_grid_lines: procedure(tree_view: PGtkTreeView; grid_lines: TGtkTreeViewGridLines); cdecl; 318 gtk_tree_view_get_grid_lines: function(tree_view: PGtkTreeView): TGtkTreeViewGridLines; cdecl; 319 gtk_window_get_group: function(window:PGtkWindow): PGtkWindowGroup; cdecl; 320 // since 2.14 321 gtk_adjustment_configure: procedure(Adjustment: PGtkAdjustment; AValue: GDouble; ALower: GDouble; AUpper: GDouble; 322 AStepIncrement: GDouble; APageIncrement: GDouble; APageSize: GDouble); cdecl; 323 324