📄 suiform.pas
字号:
begin
if m_Form.Controls[i] is TsuiForm then
Inc(c);
end;
if c >= 1 then
Exit;
if m_Form.FormStyle = fsMDIChild then
begin
m_OldBottomBorderWidth := SendMessage(Application.MainForm.Handle, SUIPACK_MSG_GETBOTTOMBORDER, 0, 0);
m_OldLeftBorderWidth := SendMessage(Application.MainForm.Handle, SUIPACK_MSG_GETLEFTBORDER, 0, 0);
end
else
begin
P := m_Form.ClientRect.BottomRight;
P := m_Form.ClientToScreen(P);
m_OldBottomBorderWidth := m_Form.Top + m_Form.Height - P.Y;
P := m_Form.ClientRect.TopLeft;
P := m_Form.ClientToScreen(P);
m_OldLeftBorderWidth := P.X - m_Form.Left;
end;
m_Destroyed := false;
m_MaxFlag := false;
m_MaxFlag2 := false;
m_MaxFlag3 := false;
m_BottomBufRgn := TBitmap.Create();
m_BottomBufRgn.PixelFormat := pf24Bit;
m_TitleNeedRegion := false;
m_BottomNeedRegion := false;
m_Form.BorderWidth := 0;
m_FormInitRect := Classes.Rect(m_Form.Left, m_Form.Top, m_Form.Width + m_Form.Left, m_Form.Height + m_Form.Top);
m_FormInitMax := (m_Form.WindowState = wsMaximized);
m_TitleBar := TsuiTitleBar.Create(self);
m_TitleBar.Parent := self;
m_MenuBar := nil;
m_MenuBarColor := Color;
MenuBarToColor := Color;
m_MenuBarHeight := 22;
UIStyle := SUI_THEME_DEFAULT;
m_UIStyleAutoUpdateSub := false;
BevelOuter := bvNone;
BevelInner := bvNone;
BorderStyle := bsNone;
Align := alClient;
Caption := m_Form.Caption;
TitleBarVisible := true;
m_MDIChildFormTitleVisible := true;
m_SelfChanging := false;
inherited Caption := ' ';
for i := 0 to m_Form.ControlCount - 1 do
begin
if m_Form.Controls[i] is TsuiForm then
raise Exception.Create('Sorry, You can create only one TsuiForm component in one form!');
end;
m_Form.Scaled := false;
m_OldBorderStyle := m_Form.BorderStyle;
case m_Form.BorderStyle of
bsNone, bsSingle, bsToolWindow: m_Form.BorderStyle := bsDialog;
end;
SetWindowLong(m_Form.Handle, GWL_STYLE, GetWindowLong(m_Form.Handle, GWL_STYLE) and (not WS_CAPTION));
m_Form.AutoScroll := false;
m_OldWndProc := m_Form.WindowProc;
m_Form.WindowProc := NewParentWndProc;
m_AppEvent := TApplicationEvents.Create(nil);
{$IFDEF SUIPACK_D5}
m_AppEvent.OnHint := OnApplicationHint;
{$ENDIF}
m_AppEvent.OnMessage := OnApplicationMessage;
SetWindowPos(m_Form.Handle, 0, 0, 0, 0, 0, SWP_DRAWFRAME or SWP_NOMOVE or SWP_NOZORDER or SWP_NOSIZE or SWP_NOACTIVATE);
end;
procedure TsuiForm.CreateMenuBar;
begin
if m_MenuBar <> nil then
Exit;
if m_Form.FormStyle = fsMDIChild then
Exit;
m_MenuBar := TsuiMenuBar.Create(self);
m_MenuBar.m_Form := self;
m_MenuBar.Parent := self;
m_MenuBar.Flat := true;
m_MenuBar.EdgeBorders := [];
m_MenuBar.ShowCaptions := true;
m_MenuBar.Height := m_MenuBarHeight;
m_MenuBar.Color := m_MenuBarColor;
if not (csDesigning in ComponentState) then
m_MenuBar.OnCustomDrawButton := DrawButton;
m_MenuBar.OnCustomDraw := DrawMenuBar;
m_MenuBar.Wrapable := true;
m_MenuBar.AutoSize := true;
m_TitleBar.Top := 0;
end;
destructor TsuiForm.Destroy;
begin
m_Destroyed := true;
m_AppEvent.Free();
m_AppEvent := nil;
if m_MenuBar <> nil then
begin
m_MenuBar.Free();
m_MenuBar := nil;
end;
m_TitleBar.Free();
m_TitleBar := nil;
m_BottomBufRgn.Free();
m_BottomBufRgn := nil;
inherited;
end;
procedure TsuiForm.DestroyMenuBar;
begin
if m_Form.FormStyle <> fsMDIChild then
begin
if m_MenuBar <> nil then
begin
m_MenuBar.Free();
m_MenuBar := nil;
end;
end;
m_Menu := nil;
end;
procedure TsuiForm.DrawButton(Sender: TToolBar; Button: TToolButton;
State: TCustomDrawState; var DefaultDraw: Boolean);
var
ACanvas : TCanvas;
ARect : TRect;
R : TRect;
Bmp : TBitmap;
Buf : TBitmap;
Style : TsuiUIStyle;
OutUIStyle : TsuiUIStyle;
CanSetFont : Boolean;
AFileTheme : TsuiFileTheme;
bUseFileTheme : Boolean;
begin
Style := m_UIStyle;
AFileTheme := m_FileTheme;
CanSetFont := false;
ACanvas := Sender.Canvas;
ARect := Button.BoundsRect;
DefaultDraw := false;
Button.Tag := 0;
if Menu <> nil then
begin
if Menu is TsuiMainMenu then
begin
Style := (Menu as TsuiMainMenu).UIStyle;
AFileTheme := (Menu as TsuiMainMenu).FileTheme;
if (m_Menu as TsuiMainMenu).UseSystemFont then
Menu_GetSystemFont(ACanvas.Font)
else
begin
ACanvas.Font.Name := (m_Menu as TsuiMainMenu).FontName;
ACanvas.Font.Size := (m_Menu as TsuiMainMenu).FontSize;
ACanvas.Font.Charset := (m_Menu as TsuiMainMenu).FontCharset;
ACanvas.Font.Color := (m_Menu as TsuiMainMenu).FontColor;
CanSetFont := true;
end;
end;
end;
// MacOS
if (
((cdsHot in State) or (cdsSelected in State)) and
{$IFDEF RES_MACOS} (Style = MacOS) {$ELSE} false {$ENDIF}
) then
begin
DefaultDraw := false;
Button.Tag := 888;
Buf := TBitmap.Create();
Bmp := TBitmap.Create();
Buf.Width := Button.Width;
Buf.Height := Button.Height;
R := Rect(0, 0, Buf.Width, Buf.Height);
Bmp.LoadFromResourceName(hInstance, 'MACOS_MENU_SELECT');
Buf.Canvas.StretchDraw(R, Bmp);
Buf.Canvas.Brush.Style := bsClear;
if CanSetFont then
begin
Buf.Canvas.Font.Name := (m_Menu as TsuiMainMenu).FontName;
Buf.Canvas.Font.Size := (m_Menu as TsuiMainMenu).FontSize;
Buf.Canvas.Font.Charset := (m_Menu as TsuiMainMenu).FontCharset;
end
else
begin
Buf.Canvas.Font.Name := ACanvas.Font.Name;
Buf.Canvas.Font.Size := ACanvas.Font.Size;
Buf.Canvas.Font.Charset := ACanvas.Font.Charset;
end;
Buf.Canvas.Font.Color := GetInsideThemeColor(MacOS, SUI_THEME_MENU_SELECTED_FONT_COLOR);
R.Bottom := R.Bottom + 2;
DrawText(Buf.Canvas.Handle, PChar(Button.Caption), -1, R, DT_CENTER or DT_VCENTER or DT_SINGLELINE);
ACanvas.Draw(ARect.Left, ARect.Top, Buf);
Bmp.Free();
Buf.Free();
end
else if (
(cdsHot in State) or
(cdsSelected in State)
) then
begin // selected or hot top menu
Button.Tag := 888;
// draw client background
if UsingFileTheme(AFileTheme, Style, OutUIStyle) then
begin
ACanvas.Brush.Color := AFileTheme.GetColor(SKIN2_TOPSELECTEDMENUCOLOR);
bUseFileTheme := true
end
else
begin
ACanvas.Brush.Color := GetInsideThemeColor(OutUIStyle, SUI_THEME_MENU_SELECTED_BACKGROUND_COLOR);
bUseFileTheme := false
end;
ACanvas.FillRect(ARect);
// draw border
if bUseFileTheme then
ACanvas.Brush.Color := AFileTheme.GetColor(SKIN2_TOPSELECTEDMENUBORDERCOLOR)
else
ACanvas.Brush.Color := GetInsideThemeColor(OutUIStyle, SUI_THEME_MENU_SELECTED_BORDER_COLOR);
ACanvas.FrameRect(ARect);
// draw text
ARect.Top := ARect.Top + 2;
if bUseFileTheme then
ACanvas.Font.Color := AFileTheme.GetColor(SKIN2_TOPSELECTEDMENUFONTCOLOR)
else
ACanvas.Font.Color := GetInsideThemeColor(OutUIStyle, SUI_THEME_MENU_SELECTED_FONT_COLOR);
DrawText(ACanvas.Handle, PChar(Button.Caption), -1, ARect, DT_CENTER or DT_VCENTER or DT_SINGLELINE);
end
// not select and not hot top menu
else
begin
ACanvas.Brush.Style := bsClear;
ARect.Top := ARect.Top + 2;
if UsingFileTheme(AFileTheme, Style, OutUIStyle) then
ACanvas.Font.Color := AFileTheme.GetColor(SKIN2_TOPMENUFONTCOLOR)
else
ACanvas.Font.Color := GetInsideThemeColor(OutUIStyle, SUI_THEME_MENU_FONT_COLOR);
if not Button.Enabled then
ACanvas.Font.Color := clGray;
DrawText(ACanvas.Handle, PChar(Button.Caption), -1, ARect, DT_CENTER or DT_VCENTER or DT_SINGLELINE);
end;
end;
procedure TsuiForm.DrawMenuBar(Sender: TToolBar; const ARect: TRect;
var DefaultDraw: Boolean);
var
ACanvas : TCanvas;
Buf : TBitmap;
Style : TsuiUIStyle;
begin
Style := m_UIStyle;
if Menu <> nil then
begin
if Menu is TsuiMainMenu then
Style := (Menu as TsuiMainMenu).UIStyle;
end;
{$IFDEF RES_MACOS}
if (Style = MacOS) then
begin
ACanvas := Sender.Canvas;
Buf := TBitmap.Create();
Buf.LoadFromResourceName(hInstance, 'MACOS_MENU_BAR');
ACanvas.StretchDraw(ARect, Buf);
Buf.Free();
Exit;
end;
{$ENDIF}
if MenuBarColor <> MenuBarToColor then
DrawHorizontalGradient(Sender.Canvas, ARect, MenuBarColor, MenuBarToColor);
end;
function TsuiForm.GetButtons: TsuiTitleBarButtons;
begin
if m_TitleBar = nil then
Result := nil
else
Result := m_TitleBar.Buttons;
end;
function TsuiForm.GetCaption: TCaption;
begin
if m_TitleBar = nil then
Result := ''
else
Result := m_TitleBar.Caption;
end;
function TsuiForm.GetDrawAppIcon: Boolean;
begin
if m_TitleBar = nil then
Result := true
else
Result := m_TitleBar.DrawAppIcon;
end;
function TsuiForm.GetFont: TFont;
begin
if m_TitleBar = nil then
Result := nil
else
Result := m_TitleBar.Font;
end;
function TsuiForm.GetInactiveCaptionColor: TColor;
begin
if m_TitleBar <> nil then
Result := m_TitleBar.InactiveCaptionColor
else
Result := clInactiveCaption;
end;
function TsuiForm.GetMDIChild: Boolean;
begin
Result := (m_Form.FormStyle = fsMDIChild);
end;
function TsuiForm.GetMenuBarHeight: Integer;
begin
if (m_MenuBar <> nil) and m_MenuBar.Visible then
Result := m_MenuBar.Height
else
Result := 0;
end;
function TsuiForm.GetOnBtnClick: TsuiTitleBarButtonClickEvent;
begin
if m_TitleBar = nil then
Result := nil
else
Result := m_TitleBar.OnCustomBtnsClick;
end;
function TsuiForm.GetOnHelpBtnClick: TsuiTitleBarButtonClickEvent;
begin
if m_TitleBar = nil then
Result := nil
else
Result := m_TitleBar.OnHelpBtnClick;
end;
function TsuiForm.GetRoundCorner: Integer;
begin
if m_TitleBar = nil then
Result := 0
else if not m_TitleBar.Visible then
Result := 0
else
Result := m_TitleBar.RoundCorner;
end;
function TsuiForm.GetRoundCornerBottom: Integer;
begin
if m_TitleBar = nil then
Result := 0
else if not m_TitleBar.Visible then
Result := 0
else
Result := m_TitleBar.RoundCornerBottom;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -