mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-22 11:59:29 +02:00
rewrite to enable drawing of disabled button
git-svn-id: trunk@5280 -
This commit is contained in:
parent
17c9fe03bd
commit
8f6882a494
@ -172,61 +172,81 @@ var
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure DrawOwnerButton(Data: PDrawItemStruct);
|
procedure DrawOwnerButton(Data: PDrawItemStruct);
|
||||||
var flags:integer; // How the button looks like (pressed or not pressed)
|
var Flags:integer; // How the button looks like (pressed or not pressed)
|
||||||
BitmapHandle: HBITMAP; // Handle of bitmap
|
BitmapHandle: HBITMAP; // Handle of the button glyph
|
||||||
OldBitmapHandle: HBITMAP; // Handle of provious bitmap in hdcBitmap
|
OldBitmapHandle: HBITMAP; // Handle of the provious bitmap in hdcNewBitmap
|
||||||
|
HdcNewBitmap: HDC; // Device context of the new Bitmap
|
||||||
|
OldFontHandle: HFONT; // Handle of previous font in hdcNewBitmap
|
||||||
BitmapBuf: BITMAP; // Buffer for bitmap
|
BitmapBuf: BITMAP; // Buffer for bitmap
|
||||||
hdcBitmap: HDC; // Memory device context for the bitmap
|
XDestBitmap: integer; // X coordinate of destination rectangle for bitmap
|
||||||
xDestBitmap: integer; // X coordinate of destination rectangle for bitmap
|
YDestBitmap: integer; // Y coordinate of destination rectangle for bitmap
|
||||||
yDestBitmap: integer; // Y coordinate of destination rectangle for bitmap
|
|
||||||
TextSize: SIZE; // For computing the length of button caption in pixels
|
TextSize: SIZE; // For computing the length of button caption in pixels
|
||||||
TextPosFlags:integer; // Flags for text position on the button
|
NewBitmap: HBITMAP; // Handle of the new bitmap
|
||||||
|
ButtonCaption: string; // Text written on the button
|
||||||
|
XDestText: integer; // X coordinate of destination rectangle for caption
|
||||||
|
YDestText: integer; // Y coordinate of destination rectangle for caption
|
||||||
|
BitmapFlags: integer; // flags for glyph (enabled or disabled)
|
||||||
|
TextFlags: integer; // flags for caption (enabled or disabled)
|
||||||
begin
|
begin
|
||||||
flags:=DFCS_BUTTONPUSH;
|
ButtonCaption := TBitBtn(Sender).Caption;
|
||||||
if (Data^.itemState and ODS_SELECTED)<>0 then
|
NewBitmap := CreateCompatibleBitmap(Data^._HDC, Data^.rcItem.Right - Data^.rcItem.Left + 1, Data^.rcItem.Bottom - Data^.rcItem.Top + 1);
|
||||||
flags:=flags or DFCS_PUSHED;
|
HdcNewBitmap := CreateCompatibleDC(Data^._HDC);
|
||||||
DrawFrameControl(Data^._HDC, Data^.rcItem, DFC_BUTTON, flags);
|
OldBitmapHandle := SelectObject(hdcNewBitmap, NewBitmap);
|
||||||
InflateRect(Data^.rcItem, -2, -2);
|
OldFontHandle := SelectObject(hdcNewBitmap, TBitBtn(Sender).Font.Handle);
|
||||||
if (Data^.itemState and ODS_SELECTED)<>0 then
|
|
||||||
OffsetRect(Data^.rcItem, 1, 1);
|
|
||||||
SetBkMode(Data^._HDC, TRANSPARENT);
|
|
||||||
BitmapHandle := TBitBtn(Sender).Glyph.Handle;
|
BitmapHandle := TBitBtn(Sender).Glyph.Handle;
|
||||||
hdcBitmap := Windows.CreateCompatibleDC(Data^._HDC);
|
|
||||||
Windows.GetObject(BitmapHandle, sizeof(BitmapBuf), @BitmapBuf);
|
Windows.GetObject(BitmapHandle, sizeof(BitmapBuf), @BitmapBuf);
|
||||||
OldBitmapHandle := Windows.SelectObject(hdcBitmap, BitmapHandle);
|
GetTextExtentPoint32(Data^._HDC, LPSTR(ButtonCaption), length(ButtonCaption), TextSize);
|
||||||
{Windows.}GetTextExtentPoint32(Data^._HDC, LPSTR(TBitBtn(Sender).Caption), length(TBitBtn(Sender).Caption), TextSize);
|
|
||||||
case TBitBtn(Sender).Layout of
|
case TBitBtn(Sender).Layout of
|
||||||
blGlyphLeft: begin
|
blGlyphLeft: begin
|
||||||
xDestBitmap:=Data^.rcItem.Left+((Data^.rcItem.Right-Data^.rcItem.Left)-(TextSize.cx+BitmapBuf.bmWidth+2)) shr 1;
|
XDestBitmap := Data^.rcItem.Left + ((Data^.rcItem.Right - Data^.rcItem.Left) - (TextSize.cx + BitmapBuf.bmWidth + 2)) shr 1;
|
||||||
yDestBitmap:=Data^.rcItem.Top+((Data^.rcItem.Bottom-Data^.rcItem.Top)-BitmapBuf.bmHeight) shr 1;
|
YDestBitmap := Data^.rcItem.Top + ((Data^.rcItem.Bottom - Data^.rcItem.Top) - BitmapBuf.bmHeight) shr 1;
|
||||||
TextPosFlags:=DT_SINGLELINE or DT_LEFT or DT_VCENTER;
|
XDestText := XDestBitmap+BitmapBuf.bmWidth + 2;
|
||||||
Inc(Data^.rcItem.Left, xDestBitmap+BitmapBuf.bmWidth+2);
|
YDestText := (Data^.rcItem.Bottom - Data^.rcItem.Top - TextSize.cy) shr 1;
|
||||||
end;
|
end;
|
||||||
blGlyphRight: begin
|
blGlyphRight: begin
|
||||||
xDestBitmap:=Data^.rcItem.Right-((Data^.rcItem.Right-Data^.rcItem.Left)-(TextSize.cx+BitmapBuf.bmWidth+2)) shr 1 - BitmapBuf.bmWidth;
|
XDestBitmap := Data^.rcItem.Right - ((Data^.rcItem.Right - Data^.rcItem.Left) - (TextSize.cx + BitmapBuf.bmWidth + 2)) shr 1 - BitmapBuf.bmWidth;
|
||||||
yDestBitmap:=Data^.rcItem.Top+((Data^.rcItem.Bottom-Data^.rcItem.Top)-BitmapBuf.bmHeight) shr 1;
|
YDestBitmap := Data^.rcItem.Top + ((Data^.rcItem.Bottom - Data^.rcItem.Top) - BitmapBuf.bmHeight) shr 1;
|
||||||
TextPosFlags:=DT_SINGLELINE or DT_RIGHT or DT_VCENTER;
|
XDestText := XDestBitmap - 2 - TextSize.cx;
|
||||||
Data^.rcItem.Right:=xDestBitmap-2;
|
YDestText := (Data^.rcItem.Bottom - Data^.rcItem.Top - TextSize.cy) shr 1;
|
||||||
end;
|
end;
|
||||||
blGlyphTop: begin
|
blGlyphTop: begin
|
||||||
xDestBitmap:=Data^.rcItem.Left+((Data^.rcItem.Right-Data^.rcItem.Left)-BitmapBuf.bmWidth) shr 1;
|
XDestBitmap := Data^.rcItem.Left + ((Data^.rcItem.Right - Data^.rcItem.Left) - BitmapBuf.bmWidth) shr 1;
|
||||||
yDestBitmap:=Data^.rcItem.Top+((Data^.rcItem.Bottom-Data^.rcItem.Top)-(TextSize.cy+BitmapBuf.bmHeight+2)) shr 1;
|
YDestBitmap := Data^.rcItem.Top + ((Data^.rcItem.Bottom - Data^.rcItem.Top) - (TextSize.cy + BitmapBuf.bmHeight + 2)) shr 1;
|
||||||
TextPosFlags:=DT_SINGLELINE or DT_CENTER or DT_TOP;
|
XDestText := (Data^.rcItem.Right - Data^.rcItem.Left - TextSize.cx) shr 1;
|
||||||
Inc(Data^.rcItem.Top, yDestBitmap+BitmapBuf.bmHeight+2);
|
YDestText := YDestBitmap + BitmapBuf.bmHeight + 2;
|
||||||
end;
|
end;
|
||||||
blGlyphBottom: begin
|
blGlyphBottom: begin
|
||||||
xDestBitmap:=Data^.rcItem.Left+((Data^.rcItem.Right-Data^.rcItem.Left)-BitmapBuf.bmWidth) shr 1;
|
XDestBitmap := Data^.rcItem.Left + ((Data^.rcItem.Right - Data^.rcItem.Left) - BitmapBuf.bmWidth) shr 1;
|
||||||
yDestBitmap:=Data^.rcItem.Bottom-((Data^.rcItem.Bottom-Data^.rcItem.Top)-(TextSize.cy+BitmapBuf.bmHeight+2)) shr 1 - BitmapBuf.bmHeight;
|
YDestBitmap := Data^.rcItem.Bottom - ((Data^.rcItem.Bottom - Data^.rcItem.Top) - (TextSize.cy + BitmapBuf.bmHeight + 2)) shr 1 - BitmapBuf.bmHeight;
|
||||||
TextPosFlags:=DT_SINGLELINE or DT_CENTER or DT_BOTTOM;
|
XDestText := (Data^.rcItem.Right - Data^.rcItem.Left - TextSize.cx) shr 1;
|
||||||
Data^.rcItem.Bottom:=yDestBitmap-2;
|
YDestText := YDestBitmap - 2 - TextSize.cy;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
Windows.BitBlt(Data^._HDC, xDestBitmap, yDestBitmap, BitmapBuf.bmWidth, BitmapBuf.bmHeight, hdcBitmap, 0, 0, SRCCOPY);
|
Flags := DFCS_BUTTONPUSH;
|
||||||
Windows.DrawText(Data^._HDC, LPSTR(TBitBtn(Sender).Caption), -1,
|
BitmapFlags := DST_BITMAP;
|
||||||
{$ifdef VER1_0}Windows.Rect({$endif}Data^.rcItem{$ifdef VER1_0}){$endif}, TextPosFlags);
|
TextFlags := DST_PREFIXTEXT;
|
||||||
if OldBitmapHandle <> 0 then
|
if (Data^.itemState and ODS_DISABLED) <> 0 then
|
||||||
Windows.SelectObject(hdcBitmap, OldBitmapHandle);
|
begin
|
||||||
Windows.DeleteDC(hdcBitmap);
|
BitmapFlags := BitmapFlags or DSS_DISABLED;
|
||||||
|
TextFlags := TextFlags or DSS_DISABLED;
|
||||||
|
end;
|
||||||
|
if (Data^.itemState and ODS_SELECTED) <> 0 then
|
||||||
|
begin
|
||||||
|
inc(XDestBitmap);
|
||||||
|
inc(YDestBitmap);
|
||||||
|
inc(XDestText);
|
||||||
|
inc(YDestText);
|
||||||
|
Flags := Flags or DFCS_PUSHED;
|
||||||
|
end;
|
||||||
|
DrawFrameControl(HdcNewBitmap, Data^.rcItem, DFC_BUTTON, Flags);
|
||||||
|
SetBkMode(HdcNewBitmap, TRANSPARENT);
|
||||||
|
DrawState(HdcNewBitmap, 0, nil, BitmapHandle, 0, XDestBitmap, YDestBitmap, 0, 0, BitmapFlags);
|
||||||
|
DrawState(HdcNewBitmap, 0, nil, LPARAM(LPSTR(ButtonCaption)), 0, XDestText, YDestText, 0, 0, TextFlags);
|
||||||
|
SelectObject(HdcNewBitmap, OldBitmapHandle);
|
||||||
|
SelectObject(HdcNewBitmap, OldFontHandle);
|
||||||
|
DrawState(Data^._HDC, 0, nil, NewBitmap, 0, 0, 0, 0, 0, DST_BITMAP);
|
||||||
|
DeleteDC(HdcNewBitmap);
|
||||||
|
DeleteObject(NewBitmap);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure DrawCheckListBoxItem(CheckListBox: TCheckListBox; Data: PDrawItemStruct);
|
procedure DrawCheckListBoxItem(CheckListBox: TCheckListBox; Data: PDrawItemStruct);
|
||||||
@ -2921,6 +2941,9 @@ end;
|
|||||||
{ =============================================================================
|
{ =============================================================================
|
||||||
|
|
||||||
$Log$
|
$Log$
|
||||||
|
Revision 1.104 2004/03/07 12:26:31 micha
|
||||||
|
rewrite to enable drawing of disabled button
|
||||||
|
|
||||||
Revision 1.103 2004/03/05 12:16:09 micha
|
Revision 1.103 2004/03/05 12:16:09 micha
|
||||||
fix designer (overlay) window transparency issue
|
fix designer (overlay) window transparency issue
|
||||||
fix releasedesignerdc to use correct window
|
fix releasedesignerdc to use correct window
|
||||||
|
Loading…
Reference in New Issue
Block a user