📄 sskinprovider.pas
字号:
IconRect.Left, IconRect.Top,
Application.Icon.Handle,
TitleIconWidth(SkinProvider),
TitleIconHeight(SkinProvider), 0, 0, DI_NORMAL);
end
else begin
iW := iffi(TitleIcon.Width = 0, CaptionHeight - IconRect.Top, TitleIcon.Width);
iH := iffi(TitleIcon.Height = 0, CaptionHeight - IconRect.Top, TitleIcon.Height);
if (iH > 16) and (AppIconLarge <> nil)
then DrawIconEx(FCommonData.FCacheBmp.Canvas.Handle,
IconRect.Left, IconRect.Top,
AppIconLarge.Handle,
iW,
iH,
0, 0, di_Normal)
else if (AppIcon <> nil) then DrawIconEx(FCommonData.FCacheBmp.Canvas.Handle,
IconRect.Left, IconRect.Top,
AppIcon.Handle,
iW,
iH,
0, 0, di_Normal)
else DrawIconEx(FCommonData.FCacheBmp.Canvas.Handle,
IconRect.Left, IconRect.Top,
LoadIcon(0, IDI_APPLICATION),
TitleIconWidth(SkinProvider),
TitleIconHeight(SkinProvider),
0, 0, di_Normal);
end;
end;
end;
function GetWindowWidth(Handle : hwnd) : integer;
var
R : TRect;
begin
GetWindowRect(Handle, R);
Result := WidthOf(R)
end;
function GetClientWidth(Handle : hwnd) : integer;
var
R : TRect;
begin
GetClientRect(Handle, R);
Result := WidthOf(R)
end;
function GetWindowHeight(Handle : hwnd) : integer;
var
R : TRect;
begin
GetWindowRect(Handle, R);
Result := HeightOf(R)
end;
function GetClientHeight(Handle : hwnd) : integer;
var
R : TRect;
begin
GetClientRect(Handle, R);
Result := HeightOf(R)
end;
{ TsSkinProvider }
procedure TsSkinProvider.AfterConstruction;
begin
inherited;
if Assigned(FCommonData.SkinManager) and FCommonData.SkinManager.Active and not (csDesigning in ComponentState) then begin
PrepareForm;
end;
end;
function TsSkinProvider.BarWidth(i : integer): integer;
begin
if Assigned(FCommonData.SkinManager.ma[i].Bmp) then begin
Result := (FCommonData.SkinManager.ma[i].Bmp.Width div 9) * 2 + TitleBtnsWidth;
end
else begin
Result := (WidthOf(FCommonData.SkinManager.ma[i].R) div (3 * FCommonData.SkinManager.ma[i].ImageCount)) * 2 + TitleBtnsWidth;
end;
end;
function TsSkinProvider.BorderHeight: integer;
begin
Result := SysBorderHeight + Form.BorderWidth
end;
function TsSkinProvider.BorderWidth: integer;
begin
Result := SysBorderHeight + Form.BorderWidth
end;
function TsSkinProvider.ButtonHeight: integer;
begin
if FCommonData.SkinManager.IsValidImgIndex(ButtonClose.ImageIndex) then begin
if FCommonData.SkinManager.ma[ButtonClose.ImageIndex].Bmp = nil
then Result := HeightOf(FCommonData.SkinManager.ma[ButtonClose.ImageIndex].R) div (1 + FCommonData.SkinManager.ma[ButtonClose.ImageIndex].MaskType)
else Result := FCommonData.SkinManager.ma[ButtonClose.ImageIndex].Bmp.Height div 2;
end
else Result := 21;
end;
function TsSkinProvider.SysButtonsCount: integer;
begin
Result := 0;
if (biSystemMenu in Form.BorderIcons) and Assigned(SystemMenu) then begin
inc(Result);
if SystemMenu.VisibleMax then inc(Result);
if SystemMenu.VisibleMin then inc(Result);
if (biHelp in Form.BorderIcons) then inc(Result);
end;
end;
function TsSkinProvider.SysButtonWidth(Btn : TsCaptionButton): integer;
begin
if FCommonData.SkinManager.IsValidImgIndex(Btn.ImageIndex) then begin
if FCommonData.SkinManager.ma[Btn.ImageIndex].Bmp = nil
then Result := WidthOf(FCommonData.SkinManager.ma[Btn.ImageIndex].R) div FCommonData.SkinManager.ma[Btn.ImageIndex].ImageCount
else Result := FCommonData.SkinManager.ma[Btn.ImageIndex].Bmp.Width div FCommonData.SkinManager.ma[Btn.ImageIndex].ImageCount;
end
else Result := 21;
end;
function TsSkinProvider.CaptionHeight: integer;
begin
if HaveBorder(Self) and (GetWindowLong(Form.Handle, GWL_STYLE) and WS_CAPTION = WS_CAPTION) or IsIconic(Form.Handle)
then begin
if Form.BorderStyle in [bsToolWindow, bsSizeToolWin]
then Result := GetSystemMetrics(SM_CYSMCAPTION)
else Result := GetSystemMetrics(SM_CYCAPTION)
end
else Result := 0;
end;
constructor TsSkinProvider.Create(AOwner: TCOmponent);
var
i : integer;
begin
inherited Create(AOwner);
Form := TForm(GetOwnerForm(Self));
fAnimating := False;
InMenu := False;
FCommonData := TsCommonData.Create(Self, True);
FCommonData.SkinSection := s_Form;
FCommonData.COC := COC_TsSkinProvider;
if Form.ControlState <> []
then FCommonData.Updating := True;
FResizeMode := rmStandard;
FUseGlobalColor := True;
MDIForm := nil;
MenuChanged := True;
FMakeSkinMenu := DefMakeSkinMenu;
MenusInitialized := False;
RgnChanged := True;
RgnChanging := False;
FScreenSnap := False;
FSnapBuffer := 10;
FShowAppIcon := True;
FCaptionAlignment := taLeftJustify;
FTitleIcon := TsTitleIcon.Create;
FTitleButtons := TsTitleButtons.Create(Self);
FGripMode := gmNone;
ClearButtons := False;
OldCaptFormProc := nil;
for i := 0 to Form.ComponentCount - 1 do begin
if (Form.Components[i] is TsSkinProvider) and (Form.Components[i] <> Self) then begin
Form := nil;
if (csDesigning in ComponentState) then ShowWarning('Only one instance of the TsSkinProvider component is allowed!');
break;
end;
end;
if not (csDesigning in ComponentState) and (Form <> nil) then begin
Form.DoubleBuffered := False;
TempBmp := TBitmap.Create;
MenuLineBmp := CreateBmp24(0, 0);
ClearButtons := True;
SetLength(ArOR, 0);
FLinesCount := -1;
OldWndProc := Form.WindowProc;
Form.WindowProc := NewWndProc;
IntSkinForm(Form);
FormActive := True;
end;
end;
destructor TsSkinProvider.Destroy;
begin
if not (csDesigning in ComponentState) then begin
if Form <> nil then begin
IntUnskinForm(Form);
Form.WindowProc := OldWndProc;
if (Form.FormStyle = fsMDIChild) and Assigned(Form.Menu) then begin
if Assigned(MDISkinProvider) and
not (csDestroying in TsSkinProvider(MDISkinProvider).ComponentState) and
not (csDestroying in TsSkinProvider(MDISkinProvider).Form.ComponentState)
then begin
TsSkinProvider(MDISkinProvider).FCommonData.BGChanged := True;
TsSkinProvider(MDISkinProvider).FLinesCount := -1;
SendMessage(TsSkinProvider(MDISkinProvider).Form.Handle, WM_NCPAINT, 0, 0);
end;
end;
if MDISkinProvider = Self then begin
if MDIForm <> nil then HookMDI(False);
MDISkinProvider := nil;
end;
end;
if Assigned(SystemMenu) then FreeAndNil(SystemMenu);
if Assigned(TempBmp) then FreeAndnil(TempBmp);
if Assigned(MenuLineBmp) then FreeAndNil(MenuLineBmp);
if TitleBG <> nil then FreeAndNil(TitleBG);
end;
if ChildProvider = Self then ChildProvider := nil;
if Assigned(FTitleIcon) then FreeAndNil(FTitleIcon);
if Assigned(FTitleButtons) then FreeAndNil(FTitleButtons);
if Assigned(Adapter) then FreeAndNil(Adapter);
if ListSW <> nil then FreeAndNil(ListSW);
if FCommonData <> nil then FreeAndNil(FCommonData);
inherited Destroy;
end;
procedure TsSkinProvider.RepaintButton(i: integer);
var
DC, SavedDC : hdc;
CurButton : TsCaptionButton;
cx, ind : integer;
BtnDisabled : boolean;
begin
CurButton.State := -1;
case i of
HTCLOSE : CurButton := ButtonClose;
HTMAXBUTTON : CurButton := ButtonMax;
HTMINBUTTON : CurButton := ButtonMin;
HTHELP : CurButton := ButtonHelp;
HTCHILDCLOSE : CurButton := MDIClose;
HTCHILDMAX : CurButton := MDIMax;
HTCHILDMIN : CurButton := MDIMin
else if Between(i, HTUDBTN, (HTUDBTN + TitleButtons.Count - 1))
then CurButton := TitleButtons.Items[i - HTUDBTN].BtnData;
end;
if CurButton.State <> -1 then begin
BtnDisabled := False;
if CurButton.Rect.Left <= IconRect.Right then Exit;
cx := FCommonData.FCacheBmp.Width - CurButton.Rect.Left;
BitBlt(FCommonData.FCacheBmp.Canvas.Handle, // Restore a button BG
CurButton.Rect.Left, CurButton.Rect.Top, SysButtonwidth(CurButton), ButtonHeight,
TempBmp.Canvas.Handle, TempBmp.Width - cx, CurButton.Rect.Top, SRCCOPY);
// if Max btn and form is maximized then Norm btn
if (i = HTMAXBUTTON) and (Form.WindowState = wsMaximized) then ind := FCommonData.SkinManager.GetMaskIndex(FCommonData.SkinIndex, s_GlobalInfo, s_BorderIconNormalize)
else case i of
HTCHILDMIN : begin
ind := CurButton.ImageIndex;
if ChildProvider <> nil then BtnDisabled := not ChildProvider.SystemMenu.EnabledMin;
if BtnDisabled then Exit;
end;
HTCHILDMAX : begin // Correction of the Maximize button (may be Normalize)
if Assigned(Form.ActiveMDIChild) and (Form.ActiveMDIChild.WindowState = wsMaximized) then begin
ind := FCommonData.SkinManager.GetMaskIndex(FCommonData.SkinManager.ConstData.IndexGlobalInfo, s_GlobalInfo, s_SmallIconNormalize);
if ind < 0 then ind := FCommonData.SkinManager.GetMaskIndex(FCommonData.SkinIndex, s_GlobalInfo, s_BorderIconNormalize) // For compatibility
end
else ind := CurButton.ImageIndex;
if ChildProvider <> nil then BtnDisabled := not ChildProvider.SystemMenu.EnabledRestore;
end
else if IsIconic(Form.Handle) then begin
case i of
HTMINBUTTON : begin
ind := FCommonData.SkinManager.GetMaskIndex(FCommonData.SkinManager.ConstData.IndexGlobalInfo, s_GlobalInfo, s_BorderIconNormalize);
if ind < 0 then ind := FCommonData.SkinManager.GetMaskIndex(FCommonData.SkinIndex, FCommonData.SkinSection, s_BorderIconNormalize); // For compatibility
end;
HTMAXBUTTON : begin
ind := FCommonData.SkinManager.GetMaskIndex(FCommonData.SkinManager.ConstData.IndexGlobalInfo, s_GlobalInfo, s_BorderIconMaximize);
if ind < 0 then ind := FCommonData.SkinManager.GetMaskIndex(FCommonData.SkinIndex, FCommonData.SkinSection, s_BorderIconMaximize); // For compatibility
if not SystemMenu.EnabledMax then BtnDisabled := True;
end
else ind := CurButton.ImageIndex;
end
end else ind := CurButton.ImageIndex;
end;
if FCommonData.SkinManager.IsValidImgIndex(ind) then begin // Drawing of the button from skin
if i < HTUDBTN // if not user defined
then DrawSkinGlyph(FCommonData.FCacheBmp, Point(CurButton.Rect.Left, CurButton.Rect.Top),
CurButton.State, 1 + integer(not FormActive or BtnDisabled) * integer(not (CurButton.State > 0) or BtnDisabled), FCommonData.SkinManager.ma[ind])
else if (TitleButtons.Items[i - HTUDBTN].UseSkinData)
then DrawSkinGlyph(FCommonData.FCacheBmp, Point(CurButton.Rect.Left, CurButton.Rect.Top),
CurButton.State, 1 + integer(not FormActive) * integer(not (CurButton.State > 0)), FCommonData.SkinManager.ma[ind]);
end;
// If user Glyph is defined
if (i >= HTUDBTN) and Assigned(TitleButtons.Items[i - HTUDBTN].Glyph) then begin
TitleButtons.Items[i - HTUDBTN].Glyph.PixelFormat := pf24bit;
CopyTransBitmaps(FCommonData.FCacheBmp, TitleButtons.Items[i - HTUDBTN].Glyph,
CurButton.Rect.Left + integer(CurButton.State = 2) + (WidthOf(CurButton.Rect) - TitleButtons.Items[i - HTUDBTN].Glyph.Width) div 2,
CurButton.Rect.Top + integer(CurButton.State = 2) + (HeightOf(CurButton.Rect) - TitleButtons.Items[i - HTUDBTN].Glyph.Height) div 2,
ColorToSColor(TitleButtons.Items[i - HTUDBTN].Glyph.Canvas.Pixels[0, TitleButtons.Items[i - HTUDBTN].Glyph.Height - 1]));
end;
// Copying to form
DC := GetWindowDC(Form.Handle);
SavedDC := SaveDC(DC);
try
BitBlt(DC, CurButton.Rect.Left, CurButton.Rect.Top, WidthOf(CurButton.Rect), HeightOf(CurButton.Rect),
FCommonData.FCacheBmp.Canvas.Handle, CurButton.Rect.Left, CurButton.Rect.Top, SRCCOPY);
finally
RestoreDC(DC, SavedDC);
ReleaseDC(Form.Handle, DC);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -