Initial implementation for restricting the visible part of a window to a region, also known as shaped windows. qt-only at the moment.

git-svn-id: trunk@18663 -
This commit is contained in:
sekelsenmat 2009-02-13 14:09:05 +00:00
parent a0ffd5e9a7
commit 80be9b456a
8 changed files with 65 additions and 4 deletions

View File

@ -1166,7 +1166,7 @@ begin
Changing;
RequiredState([csHandleValid, csFontValid, csBrushValid]);
Flags := 0;
if TextStyle.Opaque then
If TextStyle.Opaque then
Flags := ETO_Opaque;
ExtUTF8Out(FHandle, X, Y, Flags, nil, PChar(Text), Length(Text), nil);
MoveTo(X + TextWidth(Text), Y);

View File

@ -1472,6 +1472,12 @@ begin
Result:=false;
end;
function TWidgetset.SetWindowRgn(hWnd: HWND;
hRgn: HRGN; bRedraw: Boolean):longint;
begin
Result := 0;
end;
function TWidgetSet.ShowCaret(hWnd: HWND): Boolean;
begin
Result := False;

View File

@ -820,6 +820,11 @@ begin
Result := WidgetSet.SetWindowPos(hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags);
end;
function SetWindowRgn(hWnd: HWND; hRgn: HRGN; bRedraw: Boolean):longint;
begin
Result := WidgetSet.SetWindowRgn(hWnd, hRgn, bRedraw);
end;
function ShowCaret(hWnd: HWND): Boolean;
begin
Result := WidgetSet.ShowCaret(hWnd)

View File

@ -226,6 +226,7 @@ function SetWindowLong(Handle: HWND; Idx: Integer; NewLong : PtrInt): PtrInt;{$I
function SetWindowOrgEx(dc : hdc; NewX, NewY : Integer; OldPoint: PPoint): Boolean; {$IFDEF IF_BASE_MEMBER}virtual;{$ENDIF}
function SetWindowPos(hWnd: HWND; hWndInsertAfter: HWND;
X, Y, cx, cy: Integer; uFlags: UINT): Boolean; {$IFDEF IF_BASE_MEMBER}virtual;{$ENDIF}
function SetWindowRgn(hWnd: HWND; hRgn: HRGN; bRedraw: Boolean):longint; {$IFDEF IF_BASE_MEMBER}virtual;{$ENDIF}
function ShowCaret(hWnd: HWND): Boolean; {$IFDEF IF_BASE_MEMBER}virtual;{$ENDIF}
function ShowScrollBar(Handle: HWND; wBar: Integer; bShow: Boolean): Boolean; {$IFDEF IF_BASE_MEMBER}virtual;{$ENDIF}
function ShowWindow(hWnd: HWND; nCmdShow: Integer): Boolean; {$IFDEF IF_BASE_MEMBER}virtual;{$ENDIF}

View File

@ -1607,7 +1607,9 @@ begin
{$endif}
// Creates the widget
if CreateHandle then Widget := QRegion_create(X1,Y1,X2,Y2, RegionType);
// Note that QRegion_create expects a width and a height,
// and not a X2, Y2 bottom-right point
if CreateHandle then Widget := QRegion_create(X1,Y1,X2-X1,Y2-Y1, RegionType);
end;
constructor TQtRegion.Create(CreateHandle: Boolean; Poly: QPolygonH;

View File

@ -202,7 +202,8 @@ type
procedure setGeometry(ARect: TRect); overload;
procedure setLayoutDirection(ADirection: QtLayoutDirection);
procedure setMaximumSize(AWidth, AHeight: Integer);
procedure setMask(AMask: QBitmapH);
procedure setMask(AMask: QBitmapH); overload;
procedure setMask(AMask: QRegionH); overload;
procedure setMinimumSize(AWidth, AHeight: Integer);
procedure setParent(parent: QWidgetH); virtual;
procedure setText(const W: WideString); virtual;
@ -3013,6 +3014,11 @@ begin
QWidget_setMask(Widget, AMask);
end;
procedure TQtWidget.setMask(AMask: QRegionH);
begin
QWidget_setMask(Widget, AMask);
end;
procedure TQtWidget.setMinimumSize(AWidth, AHeight: Integer);
begin
QWidget_setMinimumSize(Widget, AWidth, AHeight);

View File

@ -493,7 +493,10 @@ end;
{------------------------------------------------------------------------------
Function: CreateEllipticRgn
Params: p1, p2, p3, p4: Integer
Params: p1 - X position of the top-left corner
p2 - Y position of the top-left corner
p3 - X position of the bottom-right corner
p4 - Y position of the bottom-right corner
Returns: HRGN
------------------------------------------------------------------------------}
function TQtWidgetSet.CreateEllipticRgn(p1, p2, p3, p4: Integer): HRGN;
@ -4449,6 +4452,43 @@ begin
end;
end;
{------------------------------------------------------------------------------
Method: SetWindowRgn
Params: hWnd - handle of the widget
hRgn - handle of the region
bRedraw - ?
Returns: 0 if the call failed, any other value if it was successful
Makes the region specifyed in hRgn be the only part of the window which is
visible.
------------------------------------------------------------------------------}
function TQtWidgetSet.SetWindowRgn(hWnd: HWND;
hRgn: HRGN; bRedraw: Boolean):longint;
var
w: TQtWidget;
r: TQtRegion;
begin
Result := 0;
{$ifdef VerboseQtWinAPI}
WriteLn('[WinAPI SetWindowRgn] Handle: ', dbghex(hWnd));
{$endif}
// Basic checks
if (hWnd = 0) then Exit;
w := TQtWidget(hWnd);
r := TQtRegion(hRgn);
// Now set the mask in the widget
w.setMask(r.Widget);
Result := 1;
end;
function TQtWidgetSet.ShowCaret(hWnd: HWND): Boolean;
begin
Result := (hWnd <> 0) and (QtCaret.ShowCaret(TQtWidget(hWnd)));

View File

@ -177,6 +177,7 @@ function SetProp(Handle: hwnd; Str : PChar; Data : Pointer) : Boolean; override;
function SetScrollInfo(Handle : HWND; SBStyle : Integer; ScrollInfo: TScrollInfo; bRedraw : Boolean): Integer; override;
function SetTextColor(DC: HDC; Color: TColorRef): TColorRef; override;
function SetWindowOrgEx(DC : HDC; NewX, NewY : Integer; OldPoint: PPoint) : Boolean; override;
function SetWindowRgn(hWnd: HWND; hRgn: HRGN; bRedraw: Boolean):longint; override;
function ShowCaret(hWnd: HWND): Boolean; override;
function ShowScrollBar(Handle: HWND; wBar: Integer; bShow: Boolean): Boolean; override;
function ShowWindow(hWnd: HWND; nCmdShow: Integer): Boolean; override;