34
34
function TGtkDeviceContext.GetGDIObjects(ID: TGDIType): PGdiObject;
37
gdiBitmap: Result:=CurrentBitmap;
38
gdiFont: Result:=CurrentFont;
39
gdiBrush: Result:=CurrentBrush;
40
gdiPen: Result:=CurrentPen;
41
gdiPalette: Result:=CurrentPalette;
42
gdiRegion: Result:=ClipRegion;
37
gdiBitmap: Result:=CurrentBitmap;
38
gdiFont: Result:=CurrentFont;
39
gdiBrush: Result:=CurrentBrush;
40
gdiPen: Result:=CurrentPen;
41
gdiPalette: Result:=CurrentPalette;
42
gdiRegion: Result:=ClipRegion;
46
{------------------------------------------------------------------------------
46
function TGtkDeviceContext.GetClipRectangle: TGdkRectangle;
50
if FClipRegion = nil then
52
if (PaintRectangle.Left<>0) or (PaintRectangle.Top<>0) or
53
(PaintRectangle.Right<>0) or (PaintRectangle.Bottom<>0) then
54
Result := GdkRectFromRect(PaintRectangle)
57
gdk_window_get_size(Drawable, @X, @Y);
58
Result := GdkRectFromRect(Rect(0,0, X, Y));
61
gdk_region_get_clipbox(FClipRegion^.GDIRegionObject, @Result);
49
Returns the DC offset for the DC Origin.
50
------------------------------------------------------------------------------}
51
64
function TGtkDeviceContext.GetOffset: TPoint;
68
AColumn: PGtkTreeViewColumn;
63
if (FWidget <> nil) then
75
Result := Point(0, 0);
76
if Assigned(FWidget) then
65
78
Fixed := GetFixedWidget(FWidget);
66
79
if GTK_WIDGET_NO_WINDOW(FWidget) and
70
83
Inc(Result.X, FWidget^.Allocation.x);
71
84
Inc(Result.y, FWidget^.Allocation.y);
86
if (GTK_IS_SCROLLED_WINDOW(FWidget) and GTK_IS_BIN(FWidget)) or (GTK_IS_TREE_VIEW(FWidget)) then
88
if GTK_IS_TREE_VIEW(FWidget) then
91
AChild := gtk_bin_get_child(PGtkBin(FWidget));
92
if GTK_IS_TREE_VIEW(AChild) and gtk_tree_view_get_headers_visible(PGtkTreeView(AChild)) then
94
AColumn := gtk_tree_view_get_column(PGtkTreeView(AChild), 0);
95
gtk_tree_view_column_cell_get_size(AColumn, @Area, @xoffs, @yoffs, @w, @h);
75
if not FSpecialOrigin then Exit;
76
if FWidget = nil then Exit;
79
103
function TGtkDeviceContext.GetOwnedGDIObjects(ID: TGDIType): PGdiObject;
281
320
procedure TGtkDeviceContext.SetTextMetricsValid(AValid: Boolean);
284
then Include(FFlags, dcfTextMetricsValid)
285
else Exclude(FFlags, dcfTextMetricsValid);
323
Include(FFlags, dcfTextMetricsValid)
325
Exclude(FFlags, dcfTextMetricsValid);
288
328
procedure TGtkDeviceContext.InvTransfPoint(var X1, Y1: Integer);
290
X1 := MulDiv(X1 - FViewPortOrg.x, FWindowExt.x, FViewPortExt.x);
291
Y1 := MulDiv(Y1 - FViewPortOrg.y, FWindowExt.y, FViewPortExt.y);
330
X1 := MulDiv(X1 + FWindowOrg.x - FViewPortOrg.x, FWindowExt.x, FViewPortExt.x);
331
Y1 := MulDiv(Y1 + FWindowOrg.y - FViewPortOrg.y, FWindowExt.y, FViewPortExt.y);
292
332
// to do: put affine inverse transformation here (for all Inv.. methods)
295
335
function TGtkDeviceContext.InvTransfPointIndirect(const P: TPoint): TPoint;
297
Result.X := MulDiv(P.X - FViewPortOrg.x, FWindowExt.x, FViewPortExt.x);
298
Result.Y := MulDiv(P.Y - FViewPortOrg.y, FWindowExt.y, FViewPortExt.y);
337
Result.X := MulDiv(P.X + FWindowOrg.x - FViewPortOrg.x, FWindowExt.x, FViewPortExt.x);
338
Result.Y := MulDiv(P.Y + FWindowOrg.y - FViewPortOrg.y, FWindowExt.y, FViewPortExt.y);
301
341
procedure TGtkDeviceContext.InvTransfRect(var X1, Y1, X2, Y2: Integer);
303
X1 := MulDiv(X1 - FViewPortOrg.x, FWindowExt.x, FViewPortExt.x);
304
Y1 := MulDiv(Y1 - FViewPortOrg.y, FWindowExt.y, FViewPortExt.y);
305
X2 := MulDiv(X2 - FViewPortOrg.x, FWindowExt.x, FViewPortExt.x);
306
Y2 := MulDiv(Y2 - FViewPortOrg.y, FWindowExt.y, FViewPortExt.y);
343
X1 := MulDiv(X1 + FWindowOrg.x - FViewPortOrg.x, FWindowExt.x, FViewPortExt.x);
344
Y1 := MulDiv(Y1 + FWindowOrg.y - FViewPortOrg.y, FWindowExt.y, FViewPortExt.y);
345
X2 := MulDiv(X2 + FWindowOrg.x - FViewPortOrg.x, FWindowExt.x, FViewPortExt.x);
346
Y2 := MulDiv(Y2 + FWindowOrg.y - FViewPortOrg.y, FWindowExt.y, FViewPortExt.y);
309
349
function TGtkDeviceContext.InvTransfRectIndirect(const R: TRect): TRect;
311
Result.Left := MulDiv(R.Left - FViewPortOrg.x, FWindowExt.x, FViewPortExt.x);
312
Result.Top := MulDiv(R.Top - FViewPortOrg.y, FWindowExt.y, FViewPortExt.y);
313
Result.Right := MulDiv(R.Right - FViewPortOrg.x, FWindowExt.x, FViewPortExt.x);
314
Result.Bottom := MulDiv(R.Bottom - FViewPortOrg.y, FWindowExt.y, FViewPortExt.y);
351
Result.Left := MulDiv(R.Left + FWindowOrg.x - FViewPortOrg.x, FWindowExt.x, FViewPortExt.x);
352
Result.Top := MulDiv(R.Top + FWindowOrg.y - FViewPortOrg.y, FWindowExt.y, FViewPortExt.y);
353
Result.Right := MulDiv(R.Right + FWindowOrg.x - FViewPortOrg.x, FWindowExt.x, FViewPortExt.x);
354
Result.Bottom := MulDiv(R.Bottom + FWindowOrg.y - FViewPortOrg.y, FWindowExt.y, FViewPortExt.y);
317
357
procedure TGtkDeviceContext.InvTransfExtent(var ExtX, ExtY: Integer);
357
397
procedure TGtkDeviceContext.TransfPoint(var X1, Y1: Integer);
359
399
// to do: put affine transformation here (for all Transf.. methods)
360
X1 := MulDiv(X1, FViewPortExt.x, FWindowExt.x) + FViewPortOrg.x;
361
Y1 := MulDiv(Y1, FViewPortExt.y, FWindowExt.y) + FViewPortOrg.y;
400
X1 := MulDiv(X1, FViewPortExt.x, FWindowExt.x) + FViewPortOrg.x - FWindowOrg.x;
401
Y1 := MulDiv(Y1, FViewPortExt.y, FWindowExt.y) + FViewPortOrg.y - FWindowOrg.y;
364
404
function TGtkDeviceContext.TransfPointIndirect(const P: TPoint): TPoint;
366
Result.x := MulDiv(P.x, FViewPortExt.x, FWindowExt.x) + FViewPortOrg.x;
367
Result.Y := MulDiv(P.y, FViewPortExt.y, FWindowExt.y) + FViewPortOrg.y;
406
Result.x := MulDiv(P.x, FViewPortExt.x, FWindowExt.x) + FViewPortOrg.x - FWindowOrg.x;
407
Result.Y := MulDiv(P.y, FViewPortExt.y, FWindowExt.y) + FViewPortOrg.y - FWindowOrg.y;
370
410
procedure TGtkDeviceContext.TransfRect(var X1, Y1, X2, Y2: Integer);
372
X1 := MulDiv(X1, FViewPortExt.x, FWindowExt.x) + FViewPortOrg.x;
373
Y1 := MulDiv(Y1, FViewPortExt.y, FWindowExt.y) + FViewPortOrg.y;
374
X2 := MulDiv(X2, FViewPortExt.x, FWindowExt.x) + FViewPortOrg.x;
375
Y2 := MulDiv(Y2, FViewPortExt.y, FWindowExt.y) + FViewPortOrg.y;
412
X1 := MulDiv(X1, FViewPortExt.x, FWindowExt.x) + FViewPortOrg.x - FWindowOrg.x;
413
Y1 := MulDiv(Y1, FViewPortExt.y, FWindowExt.y) + FViewPortOrg.y - FWindowOrg.y;
414
X2 := MulDiv(X2, FViewPortExt.x, FWindowExt.x) + FViewPortOrg.x - FWindowOrg.x;
415
Y2 := MulDiv(Y2, FViewPortExt.y, FWindowExt.y) + FViewPortOrg.y - FWindowOrg.y;
378
418
function TGtkDeviceContext.TransfRectIndirect(const R: TRect): TRect;
380
Result.Left := MulDiv(R.Left, FViewPortExt.x, FWindowExt.x) + FViewPortOrg.x;
381
Result.Top := MulDiv(R.Top, FViewPortExt.y, FWindowExt.y) + FViewPortOrg.y;
382
Result.Right := MulDiv(R.Right, FViewPortExt.x, FWindowExt.x) + FViewPortOrg.x;
383
Result.Bottom := MulDiv(R.Bottom, FViewPortExt.y, FWindowExt.y) + FViewPortOrg.y;
420
Result.Left := MulDiv(R.Left, FViewPortExt.x, FWindowExt.x) + FViewPortOrg.x - FWindowOrg.x;
421
Result.Top := MulDiv(R.Top, FViewPortExt.y, FWindowExt.y) + FViewPortOrg.y - FWindowOrg.y;
422
Result.Right := MulDiv(R.Right, FViewPortExt.x, FWindowExt.x) + FViewPortOrg.x - FWindowOrg.x;
423
Result.Bottom := MulDiv(R.Bottom, FViewPortExt.y, FWindowExt.y) + FViewPortOrg.y - FWindowOrg.y;
386
426
procedure TGtkDeviceContext.TransfExtent(var ExtX, ExtY: Integer);
414
454
if FCurrentFont^.LogFont.lfHeight > 0 then
457
if FCurrentFont^.LogFont.lfHeight < 0 then
418
461
if FCurrentFont^.LogFont.lfHeight <> AHeight then
420
463
FontCache.Unreference(FCurrentFont^.GDIFontObject);
421
464
FCurrentFont^.LogFont.lfHeight := AHeight;
422
TmpObj := PGdiObject(PtrUInt(GTK2WidgetSet.CreateFontIndirect(FCurrentFont^.LogFont)));
465
TmpObj := {%H-}PGdiObject(PtrUInt(GTK2WidgetSet.CreateFontIndirect(FCurrentFont^.LogFont)));
423
466
FCurrentFont^.GDIFontObject := TmpObj^.GDIFontObject;
424
467
TmpObj^.GDIFontObject := nil;
468
TmpObj^.RefCount := 0;
425
469
GTK2WidgetSet.DisposeGDIObject(TmpObj);
473
517
ClientWidget: PGtkWidget;
476
then RaiseWidgetAlreadySet;
520
if FWidget <> nil then
521
RaiseWidgetAlreadySet;
478
523
FWithChildWindows := AWithChildWindows;
479
524
FWidget := AWidget;
526
if AWidget = nil then
483
528
// screen: ToDo: multiple desktops
484
529
FDrawable := gdk_screen_get_root_window(gdk_screen_get_default);
487
if ADoubleBuffer <> nil
532
if ADoubleBuffer <> nil then
489
534
Include(FFlags, dcfDoubleBuffer);
490
535
FOriginalDrawable := AWindow;
491
536
FDrawable := ADoubleBuffer;
494
539
// create a new devicecontext for this window
495
540
Exclude(FFlags, dcfDoubleBuffer);
542
if AWindow = nil then
499
544
ClientWidget := GetFixedWidget(AWidget);
500
545
if ClientWidget = nil then RaiseWidgetWithoutClientArea;
502
547
AWindow := GetControlWindow(ClientWidget);
506
gtk_widget_realize(ClientWidget);
548
if AWindow = nil then
550
W := gtk_widget_get_parent(AWidget);
551
//we are forcing window creation but not for GtkNotebook
552
//see issue #18754 and #20126
553
//Zeljko:This part should be NOT BE REMOVED since TToolbar, TFrame
554
//TGroupBox etc...depend on this. eg.TToolbar will lock
555
//mouse without realizing clientWidget.Also if THintWindow is
556
//visible it crashes sometimes. SO JUST NOTEBOOK !
557
if (W <> nil) and not GTK_IS_NOTEBOOK(W) then
558
gtk_widget_realize(ClientWidget);
507
560
AWindow := GetControlWindow(ClientWidget);
508
561
// Don't raise an exception. Not all operations needs drawable. For example font metrics:
509
562
// http://bugs.freepascal.org/view.php?id=14035
510
563
//if AWindow = nil then RaiseUnableToRealize;
514
567
ClientWidget := AWidget;
517
FSpecialOrigin := GtkWidgetIsA(ClientWidget, GTK_LAYOUT_GET_TYPE);
518
570
FDrawable := AWindow;
519
571
// GC is created on demand
604
653
CurGDIObject: PGDIObject;
606
Result := (Self <> nil) and (ASource <> nil);
655
Result := Assigned(Self) and Assigned(ASource);
607
656
if not Result then Exit;
611
if FWidget <> ASource.FWidget
612
then RaiseRestoreDifferentWidget;
616
then RaiseWidgetAlreadySet;
660
if FWidget <> ASource.FWidget then
661
RaiseRestoreDifferentWidget;
664
if Assigned(FWidget) then
665
RaiseWidgetAlreadySet;
617
666
FWidget := ASource.FWidget;
621
670
FDrawable := ASource.FDrawable;
622
671
FOriginalDrawable := ASource.FOriginalDrawable;
673
if Assigned(FGC) then
627
676
gdk_gc_unref(FGC);
629
678
Exclude(FFlags, dcfPenSelected);
632
if (ASource.FGC <> nil) and (FDrawable <> nil)
681
if Assigned(ASource.FGC) and Assigned(FDrawable) then
634
683
gdk_gc_get_values(ASource.FGC, @FGCValues);
635
684
FGC := gdk_gc_new_with_values(FDrawable, @FGCValues,
636
685
GDK_GC_FOREGROUND or GDK_GC_BACKGROUND or GDK_GC_SUBWINDOW);
637
686
Exclude(FFlags, dcfPenSelected);
640
FOrigin := ASource.FOrigin;
641
FSpecialOrigin := ASource.FSpecialOrigin;
642
PenPos := ASource.PenPos;
644
if dcfTextMetricsValid in ASource.Flags
689
if dcfTextMetricsValid in ASource.Flags then
646
691
Include(FFlags, dcfTextMetricsValid);
647
692
DCTextMetric := ASource.DCTextMetric;
650
695
Exclude(FFlags, dcfTextMetricsValid);
652
for g:=Low(TGDIType) to High(TGDIType) do
697
for g := Low(TGDIType) to High(TGDIType) do
654
699
GDIObjects[g] := ASource.GDIObjects[g];
655
700
if AClearSource then
656
701
ASource.GDIObjects[g] := nil;
660
if OwnedGDIObjects[g]<>nil
662
DeleteObject(HGDIOBJ(PtrUInt(OwnedGDIObjects[g])));
703
if AMoveGDIOwnerShip then
705
if Assigned(OwnedGDIObjects[g]) then
706
DeleteObject(HGDIOBJ({%H-}PtrUInt(OwnedGDIObjects[g])));
665
708
CurGDIObject := ASource.OwnedGDIObjects[g];
710
if Assigned(CurGDIObject) then
669
712
ASource.OwnedGDIObjects[g] := nil;
670
713
OwnedGDIObjects[g] := CurGDIObject;
735
782
gdk_gc_set_function(GC, GDK_COPY);
737
784
DCOrigin := Offset;
785
ClipArea := ClipRect;
738
786
if (CurrentBrush^.GDIBrushFill = GDK_SOLID) and
739
787
(IsBackgroundColor(CurrentBrush^.GDIBrushColor.ColorRef)) then
740
788
StyleFillRectangle(Drawable, GC,
741
789
CurrentBrush^.GDIBrushColor.ColorRef,
742
790
ARect.Left + DCOrigin.X, ARect.Top + DCOrigin.Y,
791
Width, Height, @ClipArea)
745
793
gdk_draw_rectangle(Drawable, GC, 1,
746
794
ARect.Left + DCOrigin.X, ARect.Top + DCOrigin.Y,
1169
1218
gdk_gc_set_clip_region(FGC, nil);
1170
1219
gdk_gc_set_clip_rectangle(FGC, nil);
1172
if ClipRegion <> nil
1221
if ClipRegion <> nil then
1174
1223
RGNType := RegionType(ClipRegion^.GDIRegionObject);
1175
if (RGNType <> ERROR) and (RGNType <> NULLREGION)
1176
then gdk_gc_set_clip_region(FGC, ClipRegion^.GDIRegionObject);
1224
if (RGNType <> ERROR) and (RGNType <> NULLREGION) then
1225
gdk_gc_set_clip_region(FGC, ClipRegion^.GDIRegionObject);
1179
1228
{$IFDEF DebugGDK}EndGDKErrorTrap;{$ENDIF}
1195
1244
function TGtkDeviceContext.GetBitmap: PGdiObject;
1197
if FCurrentBitmap = nil
1246
if FCurrentBitmap = nil then
1200
1249
Result := FCurrentBitmap;
1252
function TGtkDeviceContext.GetFunction: TGdkFunction;
1254
Result := GCValues._function;
1204
1258
procedure SetLayoutText(ALayout: PPangoLayout; AText: PChar; ALength: PtrInt);
1208
1262
OldStr := pango_layout_get_text(ALayout);
1209
if (strlcomp(AText, OldStr, ALength) <> 0) or (strlen(OldStr)<>ALength) then
1263
if (strlen(OldStr)<>ALength) or (strlcomp(AText, OldStr, ALength) <> 0) then
1210
1264
pango_layout_set_text(ALayout, AText, ALength);
1213
{ TGtk2DeviceContext }
1215
function TGtk2DeviceContext.GetFunction: TGdkFunction;
1217
Result := GCValues._function;
1220
procedure TGtk2DeviceContext.DrawTextWithColors(AText: PChar; ALength: LongInt;
1267
procedure TGtkDeviceContext.DrawTextWithColors(AText: PChar; ALength: LongInt;
1221
1268
X, Y: Integer; FGColor, BGColor: PGdkColor);
1223
1270
WidgetCont: PPangoContext;