2014-12-04 10:53:59 +00:00
|
|
|
// ux themed
|
2014-12-03 09:39:14 +00:00
|
|
|
//dufa
|
2009-08-05 17:45:57 +00:00
|
|
|
unit mckCtrlDraw;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
2014-12-04 10:53:59 +00:00
|
|
|
uses
|
|
|
|
Windows, Types, KOL, Themes;
|
2009-08-05 17:45:57 +00:00
|
|
|
|
|
|
|
const
|
2014-12-03 09:39:14 +00:00
|
|
|
TextHFlags: array[TTextAlign] of DWORD = (DT_LEFT, DT_RIGHT, DT_CENTER);
|
|
|
|
TextVFlags: array[TVerticalAlign] of DWORD = (DT_TOP, DT_VCENTER, DT_BOTTOM);
|
|
|
|
WordWrapFlags: array[Boolean] of DWORD = (DT_SINGLELINE, 0);//!
|
|
|
|
CheckFlags: array[Boolean] of DWORD = (0, DFCS_CHECKED);
|
2009-08-05 17:45:57 +00:00
|
|
|
|
2014-12-04 10:53:59 +00:00
|
|
|
procedure DrawButton(DC: HDC; R: TRect; aEnabled, aDefBtn: Boolean; dwTextFlags: DWORD; aText: WideString);
|
|
|
|
procedure DrawEditBox(DC: HDC; R: TRect; aEnabled, aIsPwd: Boolean; dwTextFlags: DWORD; aText: WideString);
|
|
|
|
procedure DrawMemo(DC: HDC; R: TRect; aEnabled: Boolean; dwTextFlags: DWORD; aText: WideString);
|
|
|
|
procedure DrawCombobox(DC: HDC; R: TRect; aEnabled: Boolean; aText: WideString);
|
|
|
|
procedure DrawLabel(DC: HDC; R: TRect; dwTextFlags: DWORD; aText: WideString);
|
|
|
|
procedure DrawCheckbox(DC: HDC; R: TRect; aEnabled, aChecked, aHasBorder: Boolean; aText: WideString);
|
|
|
|
procedure DrawRadiobox(DC: HDC; R: TRect; aEnabled, aChecked, aHasBorder: Boolean; aText: WideString);
|
|
|
|
procedure DrawListBox(DC: HDC; R: TRect; aEnabled: Boolean; dwTextFlags: DWORD; aText: WideString);
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
procedure DrawButton(DC: HDC; R: TRect; aEnabled, aDefBtn: Boolean; dwTextFlags: DWORD; aText: WideString);
|
|
|
|
const //enb defbtn
|
|
|
|
arrTThemedButton: array[Boolean, Boolean] of TThemedButton =
|
|
|
|
((tbPushButtonDisabled, tbPushButtonDisabled), (tbPushButtonNormal, tbPushButtonDefaulted));
|
|
|
|
|
2009-08-05 17:45:57 +00:00
|
|
|
var
|
2014-12-03 09:39:14 +00:00
|
|
|
d: TThemedElementDetails;
|
2009-08-05 17:45:57 +00:00
|
|
|
begin
|
2014-12-03 09:39:14 +00:00
|
|
|
// get element
|
2014-12-04 10:53:59 +00:00
|
|
|
d := ThemeServices.GetElementDetails(arrTThemedButton[aEnabled, aDefBtn]);
|
|
|
|
// draw element
|
|
|
|
ThemeServices.DrawElement(DC, d, R, nil);
|
|
|
|
// text
|
|
|
|
ThemeServices.DrawText(DC, d, aText, R, dwTextFlags or DT_SINGLELINE, 0);
|
2009-08-05 17:45:57 +00:00
|
|
|
end;
|
|
|
|
|
2014-12-04 10:53:59 +00:00
|
|
|
procedure DrawEditBox(DC: HDC; R: TRect; aEnabled, aIsPwd: Boolean; dwTextFlags: DWORD; aText: WideString);
|
|
|
|
const
|
|
|
|
arrThemedEdit: array[Boolean] of TThemedEdit = (teEditTextDisabled, teEditTextNormal);
|
|
|
|
|
2009-08-05 17:45:57 +00:00
|
|
|
var
|
2014-12-03 09:39:14 +00:00
|
|
|
d: TThemedElementDetails;
|
2014-12-04 10:53:59 +00:00
|
|
|
// ss: WideString;
|
2009-08-05 17:45:57 +00:00
|
|
|
begin
|
2014-12-03 09:39:14 +00:00
|
|
|
// get element
|
2014-12-04 10:53:59 +00:00
|
|
|
d := ThemeServices.GetElementDetails(arrThemedEdit[aEnabled]);
|
2014-12-03 09:39:14 +00:00
|
|
|
// draw element
|
|
|
|
ThemeServices.DrawElement(DC, d, r, nil);
|
2014-12-04 10:53:59 +00:00
|
|
|
// password text style
|
|
|
|
// ss := aText;
|
|
|
|
// if (Length(ss) > 0) and aIsPwd then
|
|
|
|
// ss := StrRepeat('*', Length(ss));
|
2014-12-03 09:39:14 +00:00
|
|
|
// draw text
|
2014-12-04 10:53:59 +00:00
|
|
|
Inc(r.Left, 6);
|
2014-12-03 09:39:14 +00:00
|
|
|
Inc(r.Top, 3);
|
|
|
|
Dec(r.Right, 3);
|
|
|
|
Dec(r.Bottom, 3);
|
2014-12-04 10:53:59 +00:00
|
|
|
ThemeServices.DrawText(DC, d, {ss}aText, r, dwTextFlags or DT_SINGLELINE, 0);
|
2009-08-05 17:45:57 +00:00
|
|
|
end;
|
|
|
|
|
2014-12-04 10:53:59 +00:00
|
|
|
procedure DrawMemo(DC: HDC; R: TRect; aEnabled: Boolean; dwTextFlags: DWORD; aText: WideString);
|
|
|
|
const
|
|
|
|
arrThemedEdit: array[Boolean] of TThemedEdit = (teEditTextDisabled, teEditTextNormal);
|
|
|
|
|
2009-08-05 17:45:57 +00:00
|
|
|
var
|
2014-12-04 10:53:59 +00:00
|
|
|
d: TThemedElementDetails;
|
2009-08-05 17:45:57 +00:00
|
|
|
begin
|
2014-12-03 09:39:14 +00:00
|
|
|
// get element
|
2014-12-04 10:53:59 +00:00
|
|
|
d := ThemeServices.GetElementDetails(arrThemedEdit[aEnabled]);
|
2014-12-03 09:39:14 +00:00
|
|
|
// draw element
|
|
|
|
ThemeServices.DrawElement(DC, d, r, nil);
|
2014-12-04 10:53:59 +00:00
|
|
|
// get element v-track
|
|
|
|
d := ThemeServices.GetElementDetails(tsLowerTrackVertDisabled);
|
|
|
|
// draw element
|
|
|
|
ThemeServices.DrawElement(DC, d, Rect(r.Right - 20, 1, r.Right - 1, r.Bottom - 1), nil);
|
|
|
|
// get element btn-up
|
|
|
|
d := ThemeServices.GetElementDetails(tsArrowBtnUpDisabled);
|
|
|
|
// draw element
|
|
|
|
ThemeServices.DrawElement(DC, d, Rect(r.Right - 20, 1, r.Right - 1, 20), nil);
|
|
|
|
// get element btn-dn
|
|
|
|
d := ThemeServices.GetElementDetails(tsArrowBtnDownDisabled);
|
|
|
|
// draw element
|
|
|
|
ThemeServices.DrawElement(DC, d, Rect(r.Right - 20, r.Bottom - 40, r.Right - 1, r.Bottom - 20), nil);
|
|
|
|
|
|
|
|
// get element h-track
|
|
|
|
d := ThemeServices.GetElementDetails(tsLowerTrackHorzDisabled);
|
|
|
|
// draw element
|
|
|
|
ThemeServices.DrawElement(DC, d, Rect(1, r.Bottom - 20, r.Right - 20, r.Bottom - 1), nil);
|
|
|
|
// get element btn-left
|
|
|
|
d := ThemeServices.GetElementDetails(tsArrowBtnLeftDisabled);
|
|
|
|
// draw element
|
|
|
|
ThemeServices.DrawElement(DC, d, Rect(1, r.Bottom - 20, 20, r.Bottom - 1), nil);
|
|
|
|
// get element btn-right
|
|
|
|
d := ThemeServices.GetElementDetails(tsArrowBtnRightDisabled);
|
|
|
|
// draw element
|
|
|
|
ThemeServices.DrawElement(DC, d, Rect(r.Right - 40, r.Bottom - 20, r.Right - 20, r.Bottom - 1), nil);
|
|
|
|
|
2014-12-03 09:39:14 +00:00
|
|
|
// draw text
|
2014-12-04 10:53:59 +00:00
|
|
|
Inc(r.Left, 6);
|
2014-12-03 09:39:14 +00:00
|
|
|
Inc(r.Top, 3);
|
2014-12-04 10:53:59 +00:00
|
|
|
Dec(r.Right, 23);
|
|
|
|
Dec(r.Bottom, 23);
|
|
|
|
ThemeServices.DrawText(DC, d, aText, r, dwTextFlags, 0);
|
2009-08-05 17:45:57 +00:00
|
|
|
end;
|
|
|
|
|
2014-12-04 10:53:59 +00:00
|
|
|
procedure DrawCombobox(DC: HDC; R: TRect; aEnabled: Boolean; aText: WideString);
|
|
|
|
const
|
|
|
|
arrThemedComboBox: array[Boolean] of TThemedComboBox = (tcDropDownButtonDisabled, tcDropDownButtonNormal);
|
|
|
|
|
2009-08-05 17:45:57 +00:00
|
|
|
var
|
2014-12-04 10:53:59 +00:00
|
|
|
d: TThemedElementDetails;
|
|
|
|
begin
|
|
|
|
// get element
|
|
|
|
d := ThemeServices.GetElementDetails(tcComboBoxRoot);
|
|
|
|
// draw element
|
|
|
|
ThemeServices.DrawElement(DC, d, r, nil);
|
|
|
|
// get element
|
|
|
|
d := ThemeServices.GetElementDetails(arrThemedComboBox[aEnabled]);
|
|
|
|
// draw element
|
|
|
|
r.Left := r.Right - 18;
|
|
|
|
Inc(r.Top, 1);
|
|
|
|
Dec(r.Right, 1);
|
|
|
|
Dec(r.Bottom, 1);
|
|
|
|
ThemeServices.DrawElement(DC, d, r, nil);
|
|
|
|
// draw text
|
|
|
|
r.Left := 6;
|
|
|
|
Inc(r.Top, 2);
|
|
|
|
Dec(r.Right, 18);
|
|
|
|
Inc(r.Bottom, 1);
|
|
|
|
ThemeServices.DrawText(DC, d, aText, r, DT_LEFT or DT_SINGLELINE, 0);
|
|
|
|
end;
|
|
|
|
|
|
|
|
//TextHFlags[Sender.TextAlign] or TextVFlags[Sender.VerticalAlign] or WordWrapFlags[Sender.WordWrap]
|
|
|
|
procedure DrawLabel(DC: HDC; R: TRect; dwTextFlags: DWORD; aText: WideString);
|
2009-08-05 17:45:57 +00:00
|
|
|
begin
|
2014-12-04 10:53:59 +00:00
|
|
|
// draw
|
|
|
|
FillRect(DC, r, HBRUSH(COLOR_BTNFACE + 1));
|
|
|
|
SetBkMode(DC, TRANSPARENT);
|
|
|
|
DrawTextW(DC, PWideChar(aText), Length(aText), r, dwTextFlags);
|
2014-12-03 09:39:14 +00:00
|
|
|
end;
|
2009-08-05 17:45:57 +00:00
|
|
|
|
2014-12-04 10:53:59 +00:00
|
|
|
procedure DrawCheckbox(DC: HDC; R: TRect; aEnabled, aChecked, aHasBorder: Boolean; aText: WideString);
|
|
|
|
const //enb chk
|
|
|
|
arrTThemedButton: array[Boolean, Boolean] of TThemedButton =
|
|
|
|
((tbCheckBoxUncheckedDisabled, tbCheckBoxCheckedDisabled), (tbCheckBoxUncheckedNormal, tbCheckBoxCheckedNormal));
|
|
|
|
|
2014-12-03 09:39:14 +00:00
|
|
|
var
|
|
|
|
d: TThemedElementDetails;
|
|
|
|
rr: TRect;
|
|
|
|
begin
|
|
|
|
// get element
|
2014-12-04 10:53:59 +00:00
|
|
|
d := ThemeServices.GetElementDetails(arrTThemedButton[aEnabled, aChecked]);
|
|
|
|
// draw back
|
|
|
|
FillRect(DC, r, HBRUSH(COLOR_BTNFACE + 1));
|
|
|
|
// draw border
|
|
|
|
if aHasBorder then
|
|
|
|
ThemeServices.DrawEdge(DC, d, r, EDGE_BUMP, BF_RECT or BF_MIDDLE);
|
2014-12-03 09:39:14 +00:00
|
|
|
// draw element
|
|
|
|
rr := Bounds(-3, -3, 22, 22);
|
|
|
|
ThemeServices.DrawElement(DC, d, rr);
|
|
|
|
// draw text
|
|
|
|
Inc(r.Left, 18);
|
2014-12-04 10:53:59 +00:00
|
|
|
ThemeServices.DrawText(DC, d, aText, r, DT_LEFT, 0);
|
2009-08-05 17:45:57 +00:00
|
|
|
end;
|
|
|
|
|
2014-12-04 10:53:59 +00:00
|
|
|
procedure DrawRadiobox(DC: HDC; R: TRect; aEnabled, aChecked, aHasBorder: Boolean; aText: WideString);
|
|
|
|
const //enb chk
|
|
|
|
arrFlags: array[Boolean, Boolean] of DWORD =
|
|
|
|
((DFCS_INACTIVE, DFCS_CHECKED or DFCS_INACTIVE), (0, DFCS_CHECKED));
|
2014-12-03 09:39:14 +00:00
|
|
|
|
2009-08-05 17:45:57 +00:00
|
|
|
var
|
2014-12-04 10:53:59 +00:00
|
|
|
rr: TRect;
|
2009-08-05 17:45:57 +00:00
|
|
|
begin
|
2014-12-04 10:53:59 +00:00
|
|
|
// draw back
|
|
|
|
FillRect(DC, r, HBRUSH(COLOR_BTNFACE + 1));
|
|
|
|
// draw border
|
|
|
|
if aHasBorder then
|
|
|
|
DrawEdge(DC, r, EDGE_RAISED, BF_RECT or BF_MIDDLE);
|
|
|
|
// draw element
|
|
|
|
rr := Bounds(r.Left + 2, (r.Bottom + r.Top - 13) div 2, 13, 13);
|
|
|
|
DrawFrameControl(DC, rr, DFC_BUTTON, DFCS_BUTTONRADIO or arrFlags[aEnabled, aChecked]);
|
|
|
|
// draw text
|
|
|
|
Inc(r.left, 17);
|
|
|
|
SetBkMode(DC, TRANSPARENT);
|
|
|
|
DrawTextW(DC, PWideChar(aText), Length(aText), r, DT_VCENTER or DT_SINGLELINE);
|
2009-08-05 17:45:57 +00:00
|
|
|
end;
|
|
|
|
|
2014-12-04 10:53:59 +00:00
|
|
|
procedure DrawListBox(DC: HDC; R: TRect; aEnabled: Boolean; dwTextFlags: DWORD; aText: WideString);
|
|
|
|
const
|
|
|
|
arrThemedEdit: array[Boolean] of TThemedListview = (tlListItemDisabled, tlListItemDisabled);
|
|
|
|
|
2014-12-03 09:39:14 +00:00
|
|
|
var
|
2014-12-04 10:53:59 +00:00
|
|
|
d: TThemedElementDetails;
|
2009-08-05 17:45:57 +00:00
|
|
|
begin
|
2014-12-04 10:53:59 +00:00
|
|
|
// get element
|
|
|
|
d := ThemeServices.GetElementDetails(arrThemedEdit[aEnabled]);
|
|
|
|
// draw element
|
|
|
|
ThemeServices.DrawElement(DC, d, r, nil);
|
|
|
|
// draw text
|
|
|
|
Inc(r.Left, 6);
|
|
|
|
Inc(r.Top, 3);
|
|
|
|
Dec(r.Right, 3);
|
|
|
|
Dec(r.Bottom, 3);
|
|
|
|
ThemeServices.DrawText(DC, d, aText, r, dwTextFlags, 0);
|
2009-08-05 17:45:57 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-12-04 10:53:59 +00:00
|
|
|
end.
|