📄 suiform.pas
字号:
{ 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_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_TitleBar.OnResize := OnTopPanelResize;
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_OldWndProc := m_Form.WindowProc;
m_Form.WindowProc := NewParentWndProc;
m_PrevClientWndProc := Pointer(GetWindowLong(TForm(Owner).ClientHandle, GWL_WNDPROC));
{$IFDEF SUIPACK_D5}
P := Forms.MakeObjectInstance(NewClientWndProc);
{$ENDIF}
{$IFDEF SUIPACK_D6UP}
P := Classes.MakeObjectInstance(NewClientWndProc);
{$ENDIF}
SetWindowLong(TForm(AOwner).ClientHandle, GWL_WNDPROC, LongInt(P));
m_AppEvent := TApplicationEvents.Create(nil);
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 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 := TsuiMenuBar.Create(self);
m_MenuBar.m_MDIForm := 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;
m_AppEvent.Free();
if m_BorderBuf <> nil then
begin
m_BorderBuf.Free();
m_BorderBuf := 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;
pcsp: PNCCalcSizeParams;
P : PWindowPos;
begin
if m_Destroyed then
Exit;
if Msg.Msg = WM_NCCALCSIZE then
begin
if Boolean(Msg.wParam) then
begin
pcsp := PNCCalcSizeParams(Msg.lParam);
P := pcsp^.lppos;
with pcsp^.rgrc[0] do
begin
Top := P^.y;
if m_BorderBuf <> nil then
begin
Right := P^.x + P^.cx - m_BorderBuf.Width + 2;
Left := P^.x + m_BorderBuf.Width - 2;
end
else
begin
Right := P^.x + P^.cx;
Left := P^.x;
end;
Bottom := P^.y + P^.cy - m_BottomBorderWidth + 2;
end;
pcsp^.rgrc[1] := pcsp^.rgrc[0];
Msg.lParam := LongInt(pcsp);
Msg.Result := WVR_VALIDRECTS;
end
else
Msg.Result := 0;
end;
if Msg.Msg = SUIM_GETBORDERWIDTH then
begin
if m_BorderBuf <> nil then
Msg.Result := m_BorderBuf.Width
else
Msg.Result := 0;
Exit;
end;
if Msg.Msg <> WM_NCPAINT then
m_OldWndProc(Msg);
if Msg.Msg = WM_KEYDOWN then
ProcessKeyPress(Msg);
if Msg.Msg = WM_NCPAINT then
begin
PaintBorder();
end;
if Msg.Msg = CM_RECREATEWND then
begin
if WS_CAPTION and GetWindowLong(m_Form.Handle, GWL_STYLE) <> 0 then
begin
SetWindowLong(m_Form.Handle, GWL_STYLE, GetWindowLong(m_Form.Handle, GWL_STYLE) and (not WS_CAPTION));
SetWindowPos(m_Form.Handle, 0, 0, 0, 0, 0, SWP_DRAWFRAME or SWP_NOMOVE or SWP_NOZORDER or SWP_NOSIZE or SWP_NOACTIVATE);
end;
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);
Dec(Rect.Top, 2);
Dec(Rect.Left, 2);
Inc(Rect.Right, 2);
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;
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;
if (
(Operation = opRemove) an
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -