1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551
|
{%MainUnit gtkproc.pp}{%MainUnit gtkint.pp}
{ $Id$ }
{
*****************************************************************************
This file is part of the Lazarus Component Library (LCL)
See the file COPYING.modifiedLGPL.txt, included in this distribution,
for details about the license.
*****************************************************************************
}
function G_OBJECT(p: Pointer): PGtkObject;
begin
Result:=PGtkObject(p);
end;
function G_CALLBACK(p: Pointer): TGTKSignalFunc;
begin
Result:=TGTKSignalFunc(p);
end;
function GDK_GET_CURRENT_DESKTOP(): gint;
var
XDisplay: PDisplay;
XScreen: PScreen;
XWindow: TWindow;
AtomType: x.TAtom;
Format: gint;
nitems: gulong;
bytes_after: gulong;
current_desktop: pguint;
begin
Result := -1;
xdisplay := gdk_display;
xscreen := XDefaultScreenOfDisplay(xdisplay);
xwindow := XRootWindowOfScreen(xscreen);
XGetWindowProperty (xdisplay, xwindow,
XInternAtom(xdisplay, '_NET_CURRENT_DESKTOP', false),
0, MaxInt, False, XA_CARDINAL, @atomtype, @format, @nitems,
@bytes_after, gpointer(@current_desktop));
if (atomtype = XA_CARDINAL) and (format = 32) and (nitems > 0) then
Result := current_desktop[0];
if current_desktop <> nil then
XFree (current_desktop);
end;
function GDK_WINDOW_GET_DESKTOP(Window: PGdkWindowPrivate): gint;
var
xdisplay: PDisplay;
xwindow: TWindow;
atomtype: x.TAtom;
format: gint;
nitems: gulong;
bytes_after: gulong;
current_desktop: pguint;
begin
Result := -1;
XWindow := GDK_WINDOW_XWINDOW (Window);
XDisplay := GDK_WINDOW_XDISPLAY (Window);
XGetWindowProperty (xdisplay, xwindow,
XInternAtom(xdisplay, '_NET_WM_DESKTOP', false),
0, MaxInt, False, XA_CARDINAL, @atomtype, @format, @nitems,
@bytes_after, gpointer(@current_desktop));
if (atomtype = XA_CARDINAL) and (format = 32) and (nitems > 0) then
Result := current_desktop[0];
if current_desktop <> nil then
XFree (current_desktop);
end;
function GDK_WINDOW_SET_DESKTOP(Window: PGdkWindowPrivate; Desktop: gint): gint;
var
XDisplay: PDisplay;
XScreen: PScreen;
XRootWindow,
XWindow: TWindow;
XEvent: TXClientMessageEvent;
_NET_WM_DESKTOP: Integer;
begin
Result := -1;
XDisplay := GDK_WINDOW_XDISPLAY (Window);
XScreen := XDefaultScreenOfDisplay(xdisplay);
XRootWindow := XRootWindowOfScreen(xscreen);
XWindow := GDK_WINDOW_XWINDOW (Window);
_NET_WM_DESKTOP := XInternAtom(xdisplay, '_NET_WM_DESKTOP', false);
XEvent._type := ClientMessage;
XEvent.window := XWindow;
XEvent.message_type := _NET_WM_DESKTOP;
XEvent.format := 32;
XEvent.data.l[0] := Desktop;
XSendEvent(XDisplay, XRootWindow, False, SubstructureNotifyMask, PXEvent(@XEvent));
end;
procedure GDK_WINDOW_ACTIVATE(Window: PGdkWindowPrivate);
var
XDisplay: PDisplay;
XScreen: PScreen;
aXRootWindow,
XWindow: x.TWindow;
XEvent: xlib.TXClientMessageEvent;
_NET_ACTIVE_WINDOW: Integer;
begin
if (Window=nil) or (gdk.destroyed(Window^)<>0) then exit;
XDisplay := GDK_WINDOW_XDISPLAY (Window);
if XDisplay=nil then exit;
XScreen := XDefaultScreenOfDisplay(xdisplay);
if XScreen=nil then exit;
aXRootWindow := XRootWindowOfScreen(xscreen);
if aXRootWindow=0 then exit;
XWindow := GDK_WINDOW_XWINDOW (Window);
if XWindow=0 then exit;
_NET_ACTIVE_WINDOW := XInternAtom(xdisplay, '_NET_ACTIVE_WINDOW', false);
XEvent._type := ClientMessage;
XEvent.window := XWindow;
XEvent.message_type := _NET_ACTIVE_WINDOW;
XEvent.format := 32;
XEvent.data.l[0] := 1; //Message is from program
XEvent.data.l[1] := CurrentTime;
XEvent.data.l[2] := 0; // Applications current active window
XSendEvent(XDisplay, aXRootWindow, False, SubstructureNotifyMask, PXEvent(@XEvent));
end;
procedure GDK_WINDOW_MAXIMIZE(Window: PGdkWindowPrivate);
const
_NET_WM_STATE_REMOVE = 0; // remove/unset property
_NET_WM_STATE_ADD = 1; // add/set property
_NET_WM_STATE_TOGGLE = 2; // toggle property
var
XDisplay: PDisplay;
XScreen: PScreen;
aXRootWindow,
XWindow: TWindow;
XEvent: TXClientMessageEvent;
_NET_WM_STATE,
_NET_WM_STATE_MAXIMIZED_VERT,
_NET_WM_STATE_MAXIMIZED_HORZ: Integer;
begin
XDisplay := GDK_WINDOW_XDISPLAY (Window);
XScreen := XDefaultScreenOfDisplay(xdisplay);
aXRootWindow := XRootWindowOfScreen(xscreen);
XWindow := GDK_WINDOW_XWINDOW (Window);
_NET_WM_STATE := XInternAtom(xdisplay, '_NET_WM_STATE', false);
_NET_WM_STATE_MAXIMIZED_VERT := XInternAtom(xdisplay, '_NET_WM_STATE_MAXIMIZED_VERT', false);
_NET_WM_STATE_MAXIMIZED_HORZ := XInternAtom(xdisplay, '_NET_WM_STATE_MAXIMIZED_HORZ', false);
XEvent._type := ClientMessage;
XEvent.window := XWindow;
XEvent.message_type := _NET_WM_STATE;
XEvent.format := 32;
XEvent.data.l[0] := _NET_WM_STATE_ADD;
XEvent.data.l[1] := _NET_WM_STATE_MAXIMIZED_HORZ;
XEvent.data.l[2] := _NET_WM_STATE_MAXIMIZED_VERT;
XSendEvent(XDisplay, aXRootWindow, False, SubstructureNotifyMask, PXEvent(@XEvent));
end;
function GDK_WINDOW_GET_MINIMIZED(Window: PGdkWindowPrivate): gboolean;
const
_NET_WM_STATE_REMOVE = 0; // remove/unset property
_NET_WM_STATE_ADD = 1; // add/set property
_NET_WM_STATE_TOGGLE = 2; // toggle property
var
XDisplay: PDisplay;
XWindow: x.TWindow;
_NET_WM_STATE,
_NET_WM_STATE_HIDDEN: Integer;
atomtype: x.TAtom;
format: gint;
nitems: gulong;
bytes_after: gulong;
state_array: pguint;
X: Integer;
begin
Result := False;
XDisplay := GDK_WINDOW_XDISPLAY(Window);
XWindow := GDK_WINDOW_XWINDOW(Window);
_NET_WM_STATE := XInternAtom(XDisplay, '_NET_WM_STATE', False);
_NET_WM_STATE_HIDDEN := XInternAtom(XDisplay, '_NET_WM_STATE_HIDDEN', False);
XGetWindowProperty(XDisplay, XWindow, _NET_WM_STATE,
0, MaxInt, False, XA_ATOM, @atomtype, @format, @nitems,
@bytes_after, gpointer(@state_array));
if (atomtype = XA_ATOM) and (format = 32) and (nitems > 0) then
begin
// Check to see if the window is already minimized...
for X := 0 to nitems - 1 do
begin
if (state_array[X] = _NET_WM_STATE_HIDDEN) then
begin
XFree(state_array);
Exit(True);
end;
end;
end;
if state_array <> nil then
XFree(state_array);
end;
procedure GDK_WINDOW_MINIMIZE(Window: PGdkWindowPrivate);
var
XDisplay: PDisplay;
XScreen: PScreen;
XWindow: x.TWindow;
begin
if GDK_WINDOW_GET_MINIMIZED(Window) then
Exit;
XDisplay := GDK_WINDOW_XDISPLAY(Window);
XScreen := XDefaultScreenOfDisplay(XDisplay);
XWindow := GDK_WINDOW_XWINDOW(Window);
XIconifyWindow(XDisplay, XWindow, XScreenNumberOfScreen(XScreen));
end;
function GDK_WINDOW_GET_MAXIMIZED(Window: PGdkWindowPrivate): gboolean;
var
xdisplay: PDisplay;
xwindow: TWindow;
atomtype: x.TAtom;
format: gint;
nitems: gulong;
bytes_after: gulong;
state_array: pguint;
_NET_WM_STATE,
_NET_WM_STATE_MAXIMIZED_VERT,
_NET_WM_STATE_MAXIMIZED_HORZ: x.TAtom;
X: Integer;
maximized_horz, maximized_vert: Boolean;
begin
Result := False;
XWindow := GDK_WINDOW_XWINDOW(Window);
XDisplay := GDK_WINDOW_XDISPLAY(Window);
_NET_WM_STATE := XInternAtom(XDisplay, '_NET_WM_STATE', False);
_NET_WM_STATE_MAXIMIZED_VERT := XInternAtom(XDisplay, '_NET_WM_STATE_MAXIMIZED_VERT', False);
_NET_WM_STATE_MAXIMIZED_HORZ := XInternAtom(XDisplay, '_NET_WM_STATE_MAXIMIZED_HORZ', False);
XGetWindowProperty (xdisplay, xwindow,
_NET_WM_STATE,
0, MaxInt, False, XA_ATOM, @atomtype, @format, @nitems,
@bytes_after, gpointer(@state_array));
if (atomtype = XA_ATOM) and (format = 32) and (nitems > 0) then
begin
maximized_horz := False;
maximized_vert := False;
for X := 0 to nitems - 1 do
begin
if (state_array[X] = _NET_WM_STATE_MAXIMIZED_VERT) then maximized_vert := True;
if (state_array[X] = _NET_WM_STATE_MAXIMIZED_HORZ) then maximized_horz := True;
Result := (maximized_horz and maximized_vert);
if Result then Break;
end;
end;
if state_array <> nil then
XFree(state_array);
end;
procedure GDK_WINDOW_SHOW_IN_TASKBAR(Window: PGdkWindowPrivate; Show: Boolean);
// this is a try to hide windows from the taskbar.
// Unpleasantly, some windowmanagers like metacity also hides from the Alt-Tab
// cycle.
// This feature is therefore disabled on default.
{$IFDEF EnableHideFromTaskBar}
var
XDisplay: PDisplay;
XScreen: PScreen;
XRootWindow,
XWindow: TWindow;
XEvent: TXClientMessageEvent;
_NET_WM_STATE,
_NET_WM_STATE_SKIP_TASKBAR: clong;
{$ENDIF}
begin
{$IFDEF EnableHideFromTaskBar}
// GTK1: reshowing does not work, so a modal form will hide the whole application
// GTK
XDisplay := GDK_WINDOW_XDISPLAY (Window);
XScreen := XDefaultScreenOfDisplay(xdisplay);
XRootWindow := XRootWindowOfScreen(xscreen);
XWindow := GDK_WINDOW_XWINDOW (Window);
_NET_WM_STATE := XInternAtom(xdisplay, '_NET_WM_STATE', false);
_NET_WM_STATE_SKIP_TASKBAR := XInternAtom(xdisplay, '_NET_WM_STATE_SKIP_TASKBAR', false);
XEvent._type := ClientMessage;
XEvent.window := XWindow;
XEvent.message_type := _NET_WM_STATE;
XEvent.format := 32;
if Show then
XEvent.data.l[0] := 1
else
XEvent.data.l[0] := 0;// 0=Remove 1=Add 2=Toggle
XEvent.data.l[1] := _NET_WM_STATE_SKIP_TASKBAR;
XSendEvent(XDisplay, XRootWindow, False, SubstructureNotifyMask, @XEvent);
{$ENDIF}
end;
function gtk_class_get_type(aclass : Pointer) : TGtkType;
begin
If (aclass <> nil) then
result := PGtkTypeClass(aclass)^.thetype
else
result := 0;
end;
function gtk_object_get_class(anobject : Pointer) : Pointer;
begin
If (anobject <> nil) then
result := PGtkTypeObject(anobject)^.klass
else
result := nil;
end;
function gtk_window_get_modal(window:PGtkWindow):gboolean;
begin
if assigned(Window) then
result := (Window^.flag0 and bm_modal)<>0
else
result := False;
end;
function gtk_bin_get_child(bin : PGTKBin) : PGTKWidget;
begin
if (bin <> nil) then
result := bin^.Child
else
result := nil;
end;
procedure gtk_menu_item_set_right_justified(menu_item : PGtkMenuItem; right_justified : gboolean);
begin
if right_justified then
menu_item^.flag0:=menu_item^.flag0 or bm_right_justify
else
menu_item^.flag0:=menu_item^.flag0 and (not bm_right_justify);
end;
function gtk_check_menu_item_get_active(menu_item : PGtkCheckMenuItem) : gboolean;
begin
Result:=(menu_item^.flag0 and bm_checkmenuitem_active <> 0);
end;
procedure gtk_menu_append(menu : PGTKWidget; Item : PGtkWidget);
begin
gtk.gtk_menu_append(PGTKMenu(menu), Item);
end;
procedure gtk_menu_insert(menu : PGtkWidget; Item : PGTKWidget; Index : gint);
begin
gtk.gtk_menu_insert(PGTKMenu(menu), Item, Index);
end;
procedure gtk_menu_bar_insert(menubar : PGtkWidget; Item : PGTKWidget; Index : gint);
begin
gtk.gtk_menu_bar_insert(PGtkMenuBar(menubar), Item, Index);
end;
function gtk_image_new :PGTKWidget;
begin
result := gtk.gtk_image_new(nil,nil);
end;
function gtk_toolbar_new : PGTKWidget;
begin
result := gtk.gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,GTK_TOOLBAR_BOTH);
end;
procedure gtk_color_selection_get_current_color(colorsel : PGTKColorSelection; Color : PGDKColor);
var
colorArray : array[0..2] of double;
begin
gtk_color_selection_get_color(colorsel, @colorArray[0]);
Color^.pixel := 0;
Color^.red := gushort(TruncToCardinal(colorArray[0] * $FFFF));
Color^.green := gushort(TruncToCardinal(colorArray[1] * $FFFF));
Color^.blue := gushort(TruncToCardinal(colorArray[2] * $FFFF));
{$IFDEF VerboseColorDialog}
DebugLn('gtk_color_selection_get_current_color ',
' Red=',DbgS(Color^.Red),
' Green=',DbgS(Color^.Green),
' Blue=',DbgS(Color^.Blue),
'');
{$ENDIF}
end;
procedure gtk_color_selection_set_current_color(colorsel : PGTKColorSelection;
Color : PGDKColor);
var
SelectionColor: PGDouble;
begin
{$IFDEF VerboseColorDialog}
DebugLn('gtk_color_selection_set_current_color ',
' Red=',DbgS(Color^.Red),
' Green=',DbgS(Color^.Green),
' Blue=',DbgS(Color^.Blue),
'');
{$ENDIF}
GetMem(SelectionColor,4*SizeOf(GDouble));
try
SelectionColor[0]:=gdouble(Color^.Red)/65535;
SelectionColor[1]:=gdouble(Color^.Green)/65535;
SelectionColor[2]:=gdouble(Color^.Blue)/65535;
SelectionColor[3]:=0.0;
gtk_color_selection_set_color(colorSel,SelectionColor);
finally
FreeMem(SelectionColor);
end;
end;
procedure gdk_image_unref(Image : PGdkImage);
begin
gdk_window_unref(PGdkWindow(Image));
end;
procedure gdk_colormap_query_color(colormap : PGDKColormap; Pixel : gulong; Result : PGDKColor);
var
GdkColorContext: PGdkColorContext;
begin
if (Colormap = nil) or (Result = nil) then exit;
GdkColorContext:= gdk_color_context_new(gdk_colormap_get_visual(colormap),colormap);
Result^.Pixel := Pixel;
gdk_color_context_query_color(GdkColorContext, Result);
gdk_color_context_free(GdkColorContext);
end;
function gdk_region_intersect(source1:PGdkRegion; source2:PGdkRegion) : PGdkRegion;
begin
result := gdk_regions_intersect(source1, source2);
end;
function gdk_region_union(source1:PGdkRegion; source2:PGdkRegion) : PGdkRegion;
begin
result := gdk_regions_union(source1, source2);
end;
function gdk_region_subtract(source1:PGdkRegion; source2:PGdkRegion) : PGdkRegion;
begin
result := gdk_regions_subtract(source1, source2);
end;
function gdk_region_xor(source1:PGdkRegion; source2:PGdkRegion) : PGdkRegion;
begin
result := gdk_regions_xor(source1, source2);
end;
function gdk_region_copy(region: PGDKRegion): PGDKRegion;
var
EmptyRegion: PGdkRegion;
begin
EmptyRegion := gdk_region_new;
Result := gdk_regions_union(region, EmptyRegion);
gdk_region_destroy(EmptyRegion);
end;
function gdk_region_rectangle(rect: PGdkRectangle): PGDKRegion;
var
EmptyRegion: PGdkRegion;
begin
EmptyRegion := gdk_region_new;
Result := gdk_region_union_with_rect(EmptyRegion,Rect);
gdk_region_destroy(EmptyRegion);
end;
function gdk_pixmap_create_from_xpm_d (window : PGdkWindow; var mask : PGdkBitmap; transparent_color : PGdkColor; data : PPgchar) : PGdkPixmap;
begin
result := gdk.gdk_pixmap_create_from_xpm_d(window, @mask, transparent_color, data)
end;
function gdk_pixmap_colormap_create_from_xpm_d (window : PGdkWindow; colormap: PGdkColormap; var mask : PGdkBitmap; transparent_color : PGdkColor; data : PPgchar) : PGdkPixmap;
begin
result := gdk.gdk_pixmap_colormap_create_from_xpm_d(window, colormap, @mask, transparent_color, data)
end;
function gdk_pixmap_colormap_create_from_xpm (window : PGdkWindow; colormap: PGdkColormap; var mask : PGdkBitmap; transparent_color : PGdkColor; filename : Pgchar) : PGdkPixmap;
begin
result := gdk.gdk_pixmap_colormap_create_from_xpm(window, colormap, @mask, transparent_color, filename)
end;
procedure gdk_pixbuf_render_pixmap_and_mask(pixbuf : PGdkPixbuf; var pixmap_return : PGdkPixmap; var mask_return : PGdkBitmap; alpha_threshold : gint);
begin
gdkpixbuf.gdk_pixbuf_render_pixmap_and_mask(pixbuf, @pixmap_return, @mask_return, alpha_threshold);
end;
function gdk_pixbuf_new_subpixbuf(src_pixbuf: PGdkPixbuf; src_x: longint; src_y: longint; width: longint; height: longint): PGdkPixbuf;
var
tmp: PGdkPixbuf;
buf: PChar;
rowstride: Integer;
begin
buf := gdk_pixbuf_get_pixels(src_pixbuf);
rowstride := gdk_pixbuf_get_rowstride(src_pixbuf);
inc(buf, src_y * rowstride + src_x * gdk_pixbuf_get_n_channels(src_pixbuf));
tmp := gdk_pixbuf_new_from_data(buf, gdk_pixbuf_get_colorspace(src_pixbuf),
gdk_pixbuf_get_has_alpha(src_pixbuf), gdk_pixbuf_get_bits_per_sample(src_pixbuf),
width, height, rowstride, nil, nil);
Result := gdk_pixbuf_copy(tmp);
gdk_pixbuf_unref(tmp);
end;
function gdk_drawable_get_depth(Drawable : PGDKDrawable) : gint;
begin
gdk_window_get_geometry(Drawable, nil, nil, nil, nil, @result);
end;
procedure gdk_drawable_get_size(Drawable : PGDKDrawable; Width, Height : PGInt);
begin
gdk_window_get_geometry(Drawable, nil, nil, Width, Height, nil);
end;
function gdk_drawable_get_image(Drawable : PGDKDrawable; x, y, width, height : gint) : PGdkImage;
begin
result := gdk_image_get(Drawable, x, y, width, height);
end;
function gdk_drawable_get_colormap(Drawable : PGDKDrawable) : PGdkColormap;
begin
result := gdk_window_get_colormap(Drawable);
end;
{$ifdef HasX}
function gdk_x11_image_get_ximage(image: PGdkImage): PXImage;
begin
Result := PGdkImagePrivate(Image)^.ximage;
end;
{$endif}
|