📄 suiform.pas
字号:
ACanvas := Sender.Canvas;
ARect := Button.BoundsRect;
DefaultDraw := false;
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;
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;
if UsingFileTheme(AFileTheme, Style, OutUIStyle) then
Buf.Canvas.Font.Color := AFileTheme.GetColor(SUI_THEME_MENU_SELECTED_FONT_COLOR)
else
Buf.Canvas.Font.Color := GetInsideThemeColor(OutUIStyle, 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
// draw client background
if cdsSelected in State then
ARect.Right := ARect.Right - 2;
if UsingFileTheme(AFileTheme, Style, OutUIStyle) then
begin
ACanvas.Brush.Color := AFileTheme.GetColor(SUI_THEME_MENU_SELECTED_BACKGROUND_COLOR);
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(SUI_THEME_MENU_SELECTED_BORDER_COLOR)
else
ACanvas.Brush.Color := GetInsideThemeColor(OutUIStyle, SUI_THEME_MENU_SELECTED_BORDER_COLOR);
ACanvas.FrameRect(ARect);
// draw text
if cdsSelected in State then
ARect.Left := ARect.Left + 2;
ARect.Top := ARect.Top + 2;
if bUseFileTheme then
ACanvas.Font.Color := AFileTheme.GetColor(SUI_THEME_MENU_SELECTED_FONT_COLOR)
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
begin
if AFileTheme.GetColor(SUI_THEME_CONTROL_FONT_COLOR) = 196608 then
ACanvas.Font.Color := clWhite
else
ACanvas.Font.Color := AFileTheme.GetColor(SUI_THEME_MENU_FONT_COLOR);
end
else
ACanvas.Font.Color := GetInsideThemeColor(OutUIStyle, SUI_THEME_MENU_FONT_COLOR);
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();
end;
{$ENDIF}
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 := false
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.GetMDIChild: Boolean;
begin
Result := (m_Form.FormStyle = fsMDIChild);
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.GetSections: TsuiTitleBarSections;
begin
if m_TitleBar = nil then
Result := nil
else
Result := m_TitleBar.Sections;
end;
function TsuiForm.GetTitleBarCustom: Boolean;
begin
if m_TitleBar = nil then
Result := false
else
Result := m_TitleBar.Custom;
end;
function TsuiForm.GetTitleBarHeight: Integer;
begin
if (m_TitleBar = nil) or (not TitleBarVisible) then
Result := 0
else
Result := m_TitleBar.Height;
end;
function TsuiForm.GetTitleBarVisible: Boolean;
begin
if m_TitleBar = nil then
Result := false
else
Result := m_TitleBar.Visible;
end;
function TsuiForm.GetVersion: String;
begin
Result := '5.2';
end;
var
l_InFlag : Integer = 0;
l_MaxFlag : Boolean = false;
procedure TsuiForm.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_MDIACTIVATE then
begin
if TWMMDIActivate(Msg).ActiveWnd = m_Form.Handle then
begin
SendMessage(Application.MainForm.ClientHandle, WM_MDIREFRESHMENU, m_Form.Handle, 0);
m_TitleBar.FormActive := true;
end
else
m_TitleBar.FormActive := false
end;
if Msg.Msg = WM_KEYDOWN then
ProcessKeyPress(Msg);
if Msg.Msg = WM_SHOWWINDOW then
begin
m_Form.Menu := nil;
end;
if Msg.Msg = WM_DESTROY then
begin
if m_Form.FormStyle = fsMDIChild then
begin
if Application = nil then
Exit;
if Application.MainForm.MDIChildCount = 1 then
SendMessage(Application.MainForm.ClientHandle, WM_MDIREFRESHMENU, m_Form.Handle, 0);
if m_Form.WindowState = wsMaximized then
SendMessage(Application.MainForm.ClientHandle, WM_MDIRESTORE, m_Form.Handle, 0);
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_NCPAINT then
begin
if m_Form.WindowState = wsMinimized then
begin
Msg.Result := CallWindowProc(m_PrevParentWndProc, m_Form.Handle, Msg.Msg, Msg.WParam, Msg.LParam);
end
else
PaintFormBorder();
end;
if Msg.Msg = WM_SIZE then
begin
if (m_Form.WindowState = wsMaximized) and (csDesigning in ComponentState) then
Exit;
if m_FormInitMax then
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);
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;
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 = 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);
SetWindowLong(m_Form.Handle, GWL_WNDPROC, LongInt(m_PrevParentWndProc));
SetWindowPos(m_Form.Handle, 0, 0, 0, 0, 0, SWP_DRAWFRAME or SWP_NOMOVE or SWP_NOZORDER or SWP_NOSIZE or SWP_NOACTIVATE);
end;
if m_AppOnMsgAssigned and (Application <> nil) then
Application.OnMessage := nil;
end;
if (
(Operation = opRemove) and
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -