📄 suiform.pas
字号:
begin
if m_Form.WindowState <> wsMaximized then
begin
PlaceControl(m_Form, m_FormInitRect);
m_FormInitMax := false;
end
else if l_InFlag = 2 then
begin
m_Form.WindowState := wsMaximized;
end
else
Inc(l_InFlag);
l_MaxFlag := true;
end;
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;
PaintFormBorder();
m_TitleBar.ProcessMaxBtn();
if m_Form.FormStyle = fsMDIChild then
begin
if m_Form.WindowState = wsMaximized then
begin
TitleBarVisible := false;
if not l_MaxFlag then
begin
Self.ScrollBy(0, m_TitleBar.Height * -1 + 3);
l_MaxFlag := true;
SendMessage(Application.MainForm.ClientHandle, WM_MDIMAXIMIZE, m_Form.Handle, 0);
end;
end
else
begin
TitleBarVisible := true;
if l_MaxFlag then
begin
Self.ScrollBy(0, m_TitleBar.Height - 3);
l_MaxFlag := false;
m_TitleBar.ProcessMaxBtn();
SendMessage(Application.MainForm.ClientHandle, WM_MDIRESTORE, 0, 0);
end;
end;
end;
RegionWindow();
end;
if (Msg.Msg = WM_NCHITTEST) and (m_Form.FormStyle = fsMDIChild) and (m_OldBorderStyle = bsSingle) then
begin
if (
(Msg.Result = HTBOTTOM) or
(Msg.Result = HTBOTTOMLEFT) or
(Msg.Result = HTBOTTOMRIGHT) or
(Msg.Result = HTLEFT) or
(Msg.Result = HTRIGHT) or
(Msg.Result = HTTOP) or
(Msg.Result = HTTOPLEFT) or
(Msg.Result = HTTOPRIGHT)
) then
Msg.Result := HTBORDER;
end;
end;
procedure TsuiForm.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited;
if AComponent = nil then
Exit;
if (
(Operation = opInsert) and
(csDesigning in ComponentState) and
(not (csLoading in ComponentState)) and
(AComponent.ClassName <> 'TsuiMainMenu') and
(AComponent is TMainMenu) and
(not g_SUIPackConverting)
) then
begin
MessageDlg(
'Strongly recommend you to use "TsuiMainMenu" instead of "TMainMenu".'
+ SUI_2ENTER + 'If you still want to use TMainForm, '
+ SUI_2ENTER + 'set ' + m_Form.Name + '''s MENU property to NIL please.'
+ SUI_2ENTER + 'And set ' + Name + '''s MENU property to this Menu when you finished designing the menu.',
mtInformation,
[mbOK],
0
);
end;
if (
(Operation = opInsert) and
(csDesigning in ComponentState) and
(not (csLoading in ComponentState)) and
(AComponent is TsuiMainMenu) and
(not g_SUIPackConverting) and
(Menu = nil) and
(AComponent.Owner = m_Form)
) then
begin
Menu := TsuiMainMenu(AComponent);
end;
if (
(Operation = opRemove) and
(AComponent = m_Panel)
)then
m_Panel := nil;
if (
(Operation = opRemove) and
(AComponent = m_Menu)
) then
DestroyMenuBar();
if (
(Operation = opRemove) and
(AComponent = self)
)then
begin
if m_Menu <> nil then
begin
if m_Menu is TsuiMainMenu then
(m_Menu as TsuiMainMenu).Form := nil;
end;
m_Destroyed := true;
if m_Form.HandleAllocated then
begin
SetWindowLong(m_Form.Handle, GWL_STYLE, GetWindowLong(m_Form.Handle, GWL_STYLE) or WS_CAPTION);
m_Form.WindowProc := m_OldWndProc;
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 (
(Operation = opRemove) and
(AComponent = m_FileTheme)
)then
begin
m_FileTheme := nil;
ContainerApplyUIStyle(self, SUI_THEME_DEFAULT, nil);
SetUIStyle(SUI_THEME_DEFAULT);
end;
end;
procedure TsuiForm.OnApplicationMessage(var Msg: TMsg;
var Handled: Boolean);
var
AMsg : TMessage;
begin
if Msg.message = 262 then
if LOWORD(Msg.wParam) = 32 then
begin
m_TitleBar.DefPopupMenu.Popup(Application.MainForm.Left, Application.MainForm.Top + m_TitleBar.Height);
Handled := true;
end;
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 TsuiForm.Paint;
var
Buf : TBitmap;
Bmp : TBitmap;
begin
if m_Destroyed then
Exit;
if {$IFDEF RES_MACOS} (m_UIStyle = MacOS) {$ELSE} false {$ENDIF} or
{$IFDEF RES_PROTEIN} (m_UIStyle = Protein) {$ELSE} false {$ENDIF} then
begin
Buf := TBitmap.Create();
Bmp := TBitmap.Create();
try
Buf.Width := Width;
Buf.Height := Height;
{$IFDEF RES_MACOS}
if m_UIStyle = MacOS then
Bmp.LoadFromResourceName(hInstance, 'MACOS_FORM_BACKGROUND')
else
{$ENDIF}
Bmp.LoadFromResourceName(hInstance, 'PROTEIN_FORM_BACKGROUND');
Buf.Canvas.Brush.Bitmap := Bmp;
Buf.Canvas.FillRect(ClientRect);
BitBlt(Canvas.Handle, 0, 0, Width, Height, Buf.Canvas.Handle, 0, 0, SRCCOPY);
finally
Bmp.Free();
Buf.Free();
end;
end
else
begin
Canvas.Brush.Color := Color;
Canvas.FillRect(ClientRect);
end;
PaintFormBorder();
end;
procedure TsuiForm.PaintFormBorder();
var
R : TRect;
ACanvas : TCanvas;
Bmp : TBitmap;
nLeft, nRight : Integer;
Tmp : TBitmap;
BH : Integer;
W, H : Integer;
begin
if m_Destroyed then
Exit;
if (m_Form = nil) or (not m_Form.HandleAllocated) then
begin
inherited;
Exit;
end;
if (m_Form.WindowState = wsMinimized) and (not (csDesigning in ComponentState)) then
Exit;
ACanvas := TCanvas.Create();
ACanvas.Handle := GetWindowDC(m_Form.Handle);
if m_BorderBuf = nil then
begin
ACanvas.Brush.Color := m_Color;
R := Rect(0, 0, m_Width, m_Form.Height);
ACanvas.FillRect(R);
R := Rect(0, m_Form.Height - m_Width, m_Form.Width, m_Form.Height);
ACanvas.FillRect(R);
R := Rect(m_Form.Width - m_Width, m_Form.Height, m_Form.Width, 0);
ACanvas.FillRect(R);
if m_Width < 4 then
begin
ACanvas.Brush.Color := Color;
R := Rect(m_Width, TitleBarHeight, 3, m_Form.Height - m_Width);
ACanvas.FillRect(R);
R := Rect(m_Width, m_Form.Height - 3, m_Form.Width - m_Width, m_Form.Height - m_Width);
ACanvas.FillRect(R);
R := Rect(m_Form.Width - 3, m_Form.Height - m_Width, m_Form.Width - m_Width, TitleBarHeight);
ACanvas.FillRect(R);
if (m_MenuBar <> nil) and (m_MenuBar.Visible) then
begin
ACanvas.Brush.Color := m_MenuBar.Color;
R := Rect(m_Width, 3 + m_TitleBar.Height, 3, 3 + m_TitleBar.Height + m_MenuBar.Height);
ACanvas.FillRect(R);
R := Rect(m_Form.Width - 3, 3 + m_TitleBar.Height, m_Form.Width - m_Width, 3 + m_TitleBar.Height + m_MenuBar.Height);
ACanvas.FillRect(R);
end;
end;
if TitleBarVisible and m_TitleBar.CanPaint() and (m_Width < 4) then
begin
Tmp := TBitmap.Create();
m_TitleBar.GetLeftImage(Bmp);
Tmp.Width := 3 - m_Width;
Tmp.Height := Bmp.Height;
Tmp.Canvas.Draw(0, 0, Bmp);
ACanvas.Draw(m_Width, 0, Tmp);
m_TitleBar.GetRightImage(Bmp);
if Bmp.Width < 3 then
Tmp.Canvas.StretchDraw(Rect(0, 0, Tmp.Width, Tmp.Height), Bmp)
else
Tmp.Canvas.Draw(2 - Bmp.Width, 0, Bmp);
ACanvas.Draw(m_Form.Width - 3, 0, Tmp);
Tmp.Width := m_Form.Width - 5;
Tmp.Height := 3;
m_TitleBar.GetLeftImage(Bmp);
Tmp.Canvas.Draw(-2, 0, Bmp);
nLeft := Bmp.Width - 2;
m_TitleBar.GetRightImage(Bmp);
nRight := Tmp.Width - Bmp.Width + 3;
Tmp.Canvas.Draw(nRight, 0, Bmp);
m_TitleBar.GetCenterImage(Bmp);
Tmp.Canvas.StretchDraw(Rect(nLeft, 0, nRight, Bmp.Height), Bmp);
ACanvas.Draw(2, 0, Tmp);
if (m_Width = 1) and (RoundCorner = 11) and not (csDesigning in ComponentState) then
begin
ACanvas.Pen.Color := m_Color;
ACanvas.Arc(m_Form.Width - RoundCorner * 2 + 1, -1, m_Form.Width + 1, RoundCorner * 2 - 1, m_Form.Width + 1, RoundCorner - 1, m_Form.Width - RoundCorner + 1, -1);
ACanvas.Arc(-1, -1, RoundCorner * 2 - 1, RoundCorner * 2 - 1, RoundCorner - 1, -1, - 1, RoundCorner - 1);
end;
Tmp.Free();
end
else if not TitleBarVisible then
begin
ACanvas.Brush.Color := m_Color;
R := Rect(0, 0, m_Form.Width, 1);
ACanvas.FillRect(R);
ACanvas.Brush.Color := Color;
R := Rect(m_Width, 1, m_Form.Width - m_Width, 3);
ACanvas.FillRect(R);
end;
end
else
begin
W := m_BorderBuf.Width;
if m_TitleBar.Visible then
H := m_TitleBar.Height
else
H := 0;
// bottom border
Tmp := TBitmap.Create();
m_FileTheme.GetBitmap(SUI_THEME_FORM_BOTTOMBORDER_IMAGE, Tmp);
if not Tmp.Empty then
begin
R := Rect(0, m_Form.Height - Tmp.Height, m_Form.Width, m_Form.Height);
SpitDrawHorizontal(Tmp, ACanvas, R, false);
BH := Tmp.Height;
end
else
BH := 0;
Tmp.Free();
// left border
Tmp := TBitmap.Create();
R := Rect(0, H, W, m_Form.Height - BH);
m_FileTheme.GetBitmap(SUI_THEME_FORM_LEFTBORDER_IMAGE, Tmp);
ACanvas.StretchDraw(R, Tmp);
Tmp.Free();
// right border
R := Rect(m_Form.Width - W, H, m_Form.Width, m_Form.Height - BH);
ACanvas.StretchDraw(R, m_BorderBuf);
// non-border
ACanvas.Brush.Color := Color;
R := Rect(W, H, W + 1, m_Form.Height - BH);
ACanvas.FillRect(R);
R := Rect(W + 1, m_Form.Height - BH - 1, m_Form.Width - W - 1, m_Form.Height - BH);
ACanvas.FillRect(R);
R := Rect(m_Form.Width - W - 1, H, m_Form.Width - W, m_Form.Height - BH);
ACanvas.FillRect(R);
if (m_MenuBar <> nil) and (m_MenuBar.Visible) then
begin
ACanvas.Brush.Color := m_MenuBar.Color;
R := Rect(W, H, W + 1, H + m_MenuBar.Height + 3);
ACanvas.FillRect(R);
R := Rect(m_Form.Width - W - 1, 3 + H, m_Form.Width - W, 3 + H + m_MenuBar.Height);
ACanvas.FillRect(R);
end;
// title
if TitleBarVisible and m_TitleBar.CanPaint() then
begin
Tmp := TBitmap.Create();
m_TitleBar.GetLeftImage(Bmp);
Tmp.Width := W + 2;
Tmp.Height := Bmp.Height;
Tmp.Canvas.Draw(0, 0, Bmp);
ACanvas.Draw(0, 0, Tmp);
m_TitleBar.GetRightImage(Bmp);
Tmp.Width := W + 2;
if Bmp.Width < Tmp.Width then
Tmp.Canvas.StretchDraw(Rect(0, 0, Tmp.Width, Tmp.Height), Bmp)
else
Tmp.Canvas.Draw(Tmp.Width - Bmp.Width, 0, Bmp);
ACanvas.Draw(m_Form.Width - Tmp.Width, 0, Tmp);
Tmp.Width := m_Form.Width - W * 2;
Tmp.Height := 3;
m_TitleBar.GetLeftImage(Bmp);
Tmp.Canvas.Draw(-W + 1, 0, Bmp);
nLeft := Bmp.Width - W;
m_TitleBar.GetRightImage(Bmp);
nRight := Tmp.Width - Bmp.Width + W;
Tmp.Canvas.Draw(nRight, 0, Bmp);
m_TitleBar.GetCenterImage(Bmp);
Tmp.Canvas.StretchDraw(Rect(nLeft, 0, nRight, Bmp.Height), Bmp);
ACanvas.Draw(W, 0, Tmp);
Tmp.Free();
end
else
begin
R := Rect(W, 0, m_Form.Width - W, 3);
if m_MenuBar <> nil then
ACanvas.Brush.Color := m_MenuBar.Color
else
ACanvas.Brush.Color := m_Form.Color;
ACanvas.FillRect(R);
end;
end;
ReleaseDC(m_Form.Handle, ACanvas.Handle);
ACanvas.Free();
end;
procedure TsuiForm.ProcessKeyPress(var Msg: TMessage);
begin
if m_Destroyed then
Exit;
if (not FormHasFocus(m_Form)) or (not m_Form.Active) then
Msg.Result := 0
else if not Assigned(Menu) then
Msg.Result := 0
else if m_Menu.IsShortCut(TWMKEY(Msg)) then
Msg.Result := 1
else
Msg.Result := 0;
end;
procedure TsuiForm.ReAssign;
begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -