📄 suiform.pas
字号:
Color := GetInsideThemeColor(OutUIStyle, SUI_THEME_FORM_BACKGROUND_COLOR);
MenuBarColor := Color;
RoundCorner := GetInsideThemeInt(OutUIStyle, SUI_THEME_FORM_ROUNDCORNER_INT);
end;
m_TitleBar.FileTheme := m_FileTheme;
m_TitleBar.UIStyle := m_UIStyle;
if m_Menu <> nil then
begin
if m_Menu is TsuiMainMenu then
begin
(m_Menu as TsuiMainMenu).UIStyle := m_UIStyle;
(m_Menu as TsuiMainMenu).FileTheme := m_FileTheme;
end;
end;
if m_UIStyleAutoUpdateSub then
ContainerApplyUIStyle(self, m_UIStyle, FileTheme);
if M_Form.FormStyle = fsMDIChild then
M_Form.BoundsRect := Rect;
Repaint();
PaintFormBorder();
end;
procedure TsuiForm.SetVersion(const Value: String);
begin
// do nothing
end;
procedure TsuiForm.UpdateMenu;
var
i : Integer;
Button : TToolButton;
begin
if m_MenuBar = nil then
Exit;
if m_Menu = nil then
begin
DestroyMenuBar();
Exit;
end;
m_MenuBar.AutoSize := false;
for i := 0 to m_MenuBar.ButtonCount - 1 do
m_MenuBar.Buttons[0].Free();
for i := m_Menu.Items.Count - 1 downto 0 do
begin
if m_Menu.Items[i].Parent <> m_Menu.Items then
continue;
Button := TToolButton.Create(self);
Button.Parent := m_MenuBar;
Button.Grouped := true;
Button.MenuItem := m_Menu.Items[i];
Button.AutoSize := true;
end;
m_MenuBar.AutoSize := true;
end;
procedure TsuiForm.UpdateTopMenu;
var
i : Integer;
begin
if m_MenuBar = nil then
Exit;
for i := 0 to m_MenuBar.ButtonCount - 1 do
begin
if m_MenuBar.Buttons[i].MenuItem <> nil then
begin
m_MenuBar.Buttons[i].Caption := m_MenuBar.Buttons[i].MenuItem.Caption;
m_MenuBar.Buttons[i].Enabled := m_MenuBar.Buttons[i].MenuItem.Enabled;
end;
end;
end;
procedure TsuiForm.WMERASEBKGND(var Msg: TMessage);
begin
//
end;
{ TsuiMDIForm }
procedure TsuiMDIForm.Cascade;
procedure GetNextTopLeft(var nTop, nLeft: Integer);
begin
Inc(nTop, 22);
Inc(nLeft, 22);
end;
var
i : Integer;
nLeft, nTop : Integer;
nWidth, nHeight : Integer;
begin
nLeft := 0;
nTop := 0;
nWidth := Trunc(m_Form.ClientWidth * 0.8);
nHeight := Trunc(m_Form.ClientHeight * 0.6);
for i := m_Form.MDIChildCount - 1 downto 0 do
begin
if m_Form.MDIChildren[i].WindowState = wsMinimized then
continue;
m_Form.MDIChildren[i].SetBounds(nLeft, nTop, nWidth, nHeight);
GetNextTopLeft(nTop, nLeft);
end;
end;
constructor TsuiMDIForm.Create(AOwner: TComponent);
var
P : Pointer;
begin
inherited;
if not (AOwner is TForm) then
Raise Exception.Create('Sorry, TsuiMDIForm must be placed on a form');
m_Form := AOwner as TForm;
m_AppOnMsgAssigned := false;
m_TopMenu := nil;
m_Destroyed := false;
m_Form.Constraints.MinHeight := 50;
m_Form.Constraints.MinWidth := 125;
m_Form.Menu := nil;
case m_Form.BorderStyle of
bsNone, bsSingle, bsToolWindow: m_Form.BorderStyle := bsDialog;
end;
m_Form.BorderWidth := 0;
m_TitleBar := TsuiTitleBar.Create(self);
m_TitleBar.Parent := m_Form;
m_TitleBar.Top := 0;
m_TitleBar.Left := 0;
m_TitleBar.Caption := m_Form.Caption;
m_DrawChildCaptions := true;
m_DrawChildMenus := true;
CreateMenuBar();
UpdateMenu();
UIStyle := SUI_THEME_DEFAULT;
m_Form.AutoScroll := false;
SetWindowLong(m_Form.Handle, GWL_STYLE, GetWindowLong(m_Form.Handle, GWL_STYLE) and (not WS_CAPTION));
m_PrevParentWndProc := Pointer(GetWindowLong(TForm(Owner).Handle, GWL_WNDPROC));
P := MakeObjectInstance(NewParentWndProc);
SetWindowLong(TForm(AOwner).Handle, GWL_WNDPROC, LongInt(P));
m_PrevClientWndProc := Pointer(GetWindowLong(TForm(Owner).ClientHandle, GWL_WNDPROC));
P := MakeObjectInstance(NewClientWndProc);
SetWindowLong(TForm(AOwner).ClientHandle, GWL_WNDPROC, LongInt(P));
if not Assigned(Application.OnMessage) then
begin
m_AppOnMsgAssigned := true;
Application.OnMessage := OnApplicationMessage;
end;
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 TsuiMDIForm.CreateMenuBar;
var
i : Integer;
TempBmp : TBitmap;
nLeft : Integer;
begin
if (m_MenuBar <> nil) then
Exit;
m_TopPanel := TPanel.Create(self);
m_TopPanel.BevelOuter := bvNone;
m_TopPanel.BevelInner := bvNone;
m_TopPanel.Align := alTop;
m_TopPanel.Parent := m_Form;
m_TopPanel.AutoSize := true;
m_TopPanel.Visible := false;
m_MenuBar := TToolBar.Create(self);
m_MenuBar.Parent := m_TopPanel;
m_MenuBar.Flat := true;
m_MenuBar.EdgeBorders := [];
m_MenuBar.ShowCaptions := true;
m_MenuBar.AutoSize := true;
m_MenuBar.OnCustomDrawButton := DrawButton;
m_MenuBar.OnCustomDraw := DrawMenuBar;
m_TitleBar.Top := 0;
if (csDesigning in ComponentState) then
exit;
TempBmp := TBitmap.Create();
TempBmp.Transparent := true;
TempBmp.LoadFromResourceName(hInstance, 'MDI_CONTROL_BUTTON');
nLeft := m_TopPanel.Width - 20;
for i := 1 to 3 do
begin
m_ControlBtns[i] := TsuiToolBarSpeedButton.Create(self);
m_ControlBtns[i].Parent := m_TopPanel;
m_ControlBtns[i].Anchors := [akTop, akRight];
SpitBitmap(TempBmp, m_ControlBtns[i].Glyph, 3, 4 - i);
m_ControlBtns[i].Left := nLeft;
m_ControlBtns[i].Top := 1;
Dec(nLeft, 18);
m_ControlBtns[i].Tag := -1380 - i;
m_ControlBtns[i].OnClick := OnControlButtonClick;
m_ControlBtns[i].Color := m_MenuBar.Color;
m_ControlBtns[i].BringToFront();
m_ControlBtns[i].Visible := false;
end;
TempBmp.Free();
end;
destructor TsuiMDIForm.Destroy;
begin
m_Destroyed := true;
DestroyMenuBar();
m_TitleBar.Free();
m_TitleBar := nil;
if not (csDesigning in ComponentState) then
begin
if m_AppOnMsgAssigned then
Application.OnMessage := nil;
end;
inherited;
end;
procedure TsuiMDIForm.DestroyMenuBar;
var
i : Integer;
begin
if (m_MenuBar = nil) then
Exit;
if not (csDesigning in ComponentState) then
for i := 1 to 3 do
begin
m_ControlBtns[i].Free();
m_ControlBtns[i] := nil;
end;
m_MenuBar.Free();
m_MenuBar := nil;
m_TopPanel.Free();
m_TopPanel := nil;
m_Menu := nil;
end;
function TsuiMDIForm.GetActiveChildSUIForm: TsuiForm;
var
i : Integer;
Form : TForm;
begin
Result := nil;
Form := m_Form.ActiveMDIChild;
if Form = nil then
Exit;
for i := 0 to Form.ControlCount - 1 do
begin
if Form.Controls[i] is TsuiForm then
begin
Result := Form.Controls[i] as TsuiForm;
Break;
end;
end;
end;
function TsuiMDIForm.GetCaption: TCaption;
begin
Result := m_Form.Caption;
end;
function TsuiMDIForm.GetMainMenu: TMainMenu;
var
i : Integer;
Form : TForm;
begin
Result := m_Menu;
if not m_DrawChildMenus then
Exit;
if m_TitleBar = nil then
Exit;
if m_Form.ActiveMDIChild = nil then
Exit;
Form := m_Form.ActiveMDIChild;
if Form.Menu <> nil then
begin
Result := Form.Menu;
Exit;
end;
for i := 0 to Form.ControlCount - 1 do
begin
if Form.Controls[i] is TsuiForm then
begin
if (Form.Controls[i] as TsuiForm).Menu <> nil then
Result := (Form.Controls[i] as TsuiForm).Menu;
break;
end;
end;
end;
procedure TsuiMDIForm.HideControlButtons;
var
i : Integer;
begin
for i := 1 to 3 do
m_ControlBtns[i].Visible := false;
end;
procedure TsuiMDIForm.HideMenuBar;
begin
if (m_MenuBar = nil) then
Exit;
m_TopPanel.Visible := false;
end;
procedure TsuiMDIForm.NewClientWndProc(var Msg: TMessage);
begin
if m_Destroyed then
Exit;
Msg.Result := CallWindowProc(m_PrevClientWndProc, TForm(Owner).ClientHandle, Msg.Msg, Msg.WParam, Msg.LParam);
if Msg.Msg = WM_MDIREFRESHMENU then
begin
UpdateMenu();
Caption := m_Form.Caption;
end;
if Msg.Msg = WM_MDIMAXIMIZE then
begin
ShowControlButtons();
Caption := m_Form.Caption;
end;
if Msg.Msg = WM_MDIRESTORE then
begin
HideControlButtons();
Caption := m_Form.Caption;
end;
if Msg.Msg = WM_MDITILE then
begin
Tile();
end;
if Msg.Msg = WM_MDICASCADE then
begin
Cascade();
end;
end;
procedure TsuiMDIForm.NewParentWndProc(var Msg: TMessage);
var
Rect : TRect;
begin
if m_Destroyed then
Exit;
if Msg.Msg <> WM_NCPAINT then
Msg.Result := CallWindowProc(m_PrevParentWndProc, m_Form.Handle, Msg.Msg, Msg.WParam, Msg.LParam);
if Msg.Msg = WM_KEYDOWN then
ProcessKeyPress(Msg);
if Msg.Msg = WM_NCPAINT then
begin
PaintBorder();
end;
if Msg.Msg = WM_ACTIVATE then
begin
if Msg.WParamLo = WA_INACTIVE then
m_TitleBar.FormActive := false
else
m_TitleBar.FormActive := true;
end;
if Msg.Msg = WM_SIZE then
begin
if (m_Form.WindowState = wsMaximized) and (csDesigning in ComponentState) then
Exit;
if (m_Form.WindowState = wsMaximized) and (m_Form.FormStyle <> fsMDIChild) then
begin
Rect := GetWorkAreaRect();
Dec(Rect.Bottom);
PlaceControl(m_Form, Rect);
end;
PaintBorder();
RegionWindow();
end;
end;
procedure TsuiMDIForm.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited;
if AComponent = nil then
Exit;
if (
(Operation = opRemove) and
(AComponent = m_Menu)
) then
begin
m_Menu := nil;
UpdateMenu();
end;
if (
(Operation = opRemove) and
(AComponent = m_MenuBar)
) then
begin
m_MenuBar := nil;
end;
if Operation = opInsert then
begin
if m_MenuBar <> nil then
m_MenuBar.Top := 0;
if m_TitleBar <> nil then
m_TitleBar.Top := 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -