📄 suiform.pas
字号:
end;
procedure TsuiForm.WMERASEBKGND(var Msg: TMessage);
begin
PaintFormBorder();
end;
{ TsuiMDIForm }
procedure TsuiMDIForm.Cascade;
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_ChildMaxed := false;
m_AppOnMsgAssigned := false;
m_TopMenu := nil;
m_Form.Constraints.MinHeight := 50;
m_Form.Constraints.MinWidth := 125;
m_Form.BorderWidth := 1;
m_Form.BorderStyle := bsNone;
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;
if not (csDesigning in ComponentState) then
begin
m_Form.AutoScroll := false;
m_PrevParentWndProc := Pointer(GetWindowLong(TForm(Owner).Handle, GWL_WNDPROC));
P := MakeObjectInstance(NewParentWndProc);
SetWindowLong(TForm(AOwner).Handle, GWL_WNDPROC, LongInt(P));
SetWindowLong(m_Form.Handle, GWL_STYLE, GETWINDOWLONG(m_Form.Handle, GWL_STYLE) and (not WS_CAPTION));
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;
end;
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_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
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.GetTitleBarCaption: String;
var
Form : TForm;
begin
if m_Form.ActiveMDIChild = nil then
begin
m_TitleBar.Caption := m_Form.Caption;
Exit;
end;
Form := m_Form.ActiveMDIChild;
if not m_DrawChildCaptions or (Pos(' - [', m_Form.Caption) <> 0) then
m_TitleBar.Caption := m_Form.Caption
else
m_TitleBar.Caption := m_Form.Caption + ' - [' + 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.GetNextTopLeft(var nTop, nLeft: Integer);
begin
Inc(nTop, m_TitleBar.Height + 3);
Inc(nLeft, m_TitleBar.Height + 3);
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
Msg.Result := CallWindowProc(m_PrevClientWndProc, TForm(Owner).ClientHandle, Msg.Msg, Msg.WParam, Msg.LParam);
if Msg.Msg = SUIM_UPDATEMDIMENU then
begin
UpdateMenu();
GetTitleBarCaption();
end;
if Msg.Msg = SUIM_MDICHILDMAX then
begin
ShowControlButtons();
end;
if Msg.Msg = SUIM_MDICHILDNOMAX then
begin
HideControlButtons();
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
Pt : TPoint;
Rect : TRect;
begin
Msg.Result := CallWindowProc(m_PrevParentWndProc, TForm(Owner).Handle, Msg.Msg, Msg.WParam, Msg.LParam);
if Msg.Msg = WM_KEYDOWN then
ProcessKeyPress(Msg);
if (
(Msg.Msg = WM_LBUTTONDOWN) or
(Msg.Msg = WM_LBUTTONUP) or
(Msg.Msg = WM_MOUSEMOVE) or
(Msg.Msg = WM_RBUTTONDOWN) or
(Msg.Msg = WM_RBUTTONUP) or
(Msg.Msg = WM_LBUTTONDBLCLK) or
(Msg.Msg = WM_RBUTTONDBLCLK)
) then
SendMessage(m_TitleBar.Handle, Msg.Msg, Msg.WParam, Msg.LParam);
if Msg.Msg = WM_NCPAINT then
begin
PaintBorder();
m_TitleBar.OnFormReSize();
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 (m_Form.FormStyle <> fsMDIChild) then
begin
Rect := GetWorkAreaRect();
PlaceControl(m_Form, Rect);
end;
PaintBorder();
m_TitleBar.OnFormReSize();
end;
if Msg.Msg = WM_NCHITTEST then
begin
if m_Form.WindowState = wsMaximized then
Exit;
with m_Form do
begin
Pt := Point(Msg.LParamLo, Msg.LParamHi);
Pt := ScreenToClient(Pt);
if (Pt.X < 5) and (Pt.Y < 5) then
Msg.Result := htTopLeft
else if (Pt.X > ClientWidth - 5) and (Pt.y < 5) then
Msg.Result := htTopRight
else if (Pt.X > ClientWidth - 5) and (Pt.Y > ClientHeight - 5) then
Msg.Result := htBottomRight
else if (Pt.X < 5) and (Pt.Y > ClientHeight - 5) then
Msg.Result := htBottomLeft
else if (Pt.X < 5) then
Msg.Result := htLeft
else if (Pt.Y < 5) then
Msg.Result := htTop
else if (Pt.X > ClientWidth - 5) then
Msg.Result := htRight
else if (Pt.Y > ClientHeight - 5) then
Msg.Result := htBottom;
end; // with
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;
end;
if (
(Operation = opRemove) and
(AComponent = m_TitleBar)
) then
begin
m_TitleBar := nil;
end;
if (
(Operation = opRemove) and
(AComponent = m_FileTheme)
)then
begin
m_FileTheme := nil;
SetUIStyle(SUI_THEME_DEFAULT);
end;
end;
procedure TsuiMDIForm.OnApplicationMessage(var Msg: TMsg;
var Handled: Boolean);
var
AMsg : TMessage;
begin
if Msg.message = WM_KEYDOWN then
begin
AMsg.Msg := Msg.message;
AMsg.WParam := Msg.wParam;
AMsg.LParam := Msg.lParam;
ProcessKeyPress(AMsg);
Handled := Boolean(AMsg.Result);
end;
end;
procedure TsuiMDIForm.OnControlButtonClick(Sender: TObject);
begin
if not (Sender is TsuiToolBarSpeedButton) then
Exit;
case (Sender as TsuiToolBarSpeedButton).Tag of
-1383 : // min
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -