⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 suiform.pas

📁 suipack ver5控件 suipack ver5控件 suipack ver5控件 suipack ver5控件 suipack ver5控件
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    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;

procedure TsuiForm.RegionWindow;
var
    R1, R2 : TRect;
    Rgn, Rgn1 : HRGN;
    C, C2 : Integer;
    TempRgn : HRGN;
    W, H : Integer;
begin
    if csDesigning in ComponentState then
        Exit;

    H := m_Form.Height;
    W := m_Form.Width;

    R1 := Rect(0, 0, W, H div 2);
    R2 := Rect(0, H div 2, W, H);
    C := RoundCorner;
    C2 := RoundCornerBottom;
    if C2 = -1 then
        C2 := 0;

    Rgn := CreateRoundRectRgn(R1.Left, R1.Top, R1.Right + 1, R1.Bottom + 1, C, C);

    TempRgn := CreateRectRgn(
        R1.Left,
        R1.Bottom,
        R1.Left + C * 2,
        R1.Bottom - C * 2
    );
    CombineRgn(Rgn, Rgn, TempRgn, RGN_OR);
    DeleteObject(TempRgn);

    TempRgn := CreateRectRgn(
        R1.Right,
        R1.Bottom,
        R1.Right - C * 2,
        R1.Bottom - C * 2
    );
    CombineRgn(Rgn, Rgn, TempRgn, RGN_OR);
    DeleteObject(TempRgn);

    Rgn1 := CreateRoundRectRgn(R2.Left, R2.Top, R2.Right + 1, R2.Bottom + 1, C2, C2);

    TempRgn := CreateRectRgn(
        R2.Left,
        R2.Top,
        R2.Left + C2 * 2,
        R2.Top + C2 * 2
    );
    CombineRgn(Rgn1, Rgn1, TempRgn, RGN_OR);
    DeleteObject(TempRgn);

    TempRgn := CreateRectRgn(
        R2.Right,
        R2.Top,
        R2.Right - C2 * 2,
        R2.Top + C2 * 2
    );
    CombineRgn(Rgn1, Rgn1, TempRgn, RGN_OR);
    DeleteObject(TempRgn);

    CombineRgn(Rgn, Rgn, Rgn1, RGN_OR);
    DeleteObject(Rgn1);
    
    if not (csDesigning in m_Form.ComponentState) then
        SetWindowRgn(m_Form.Handle, Rgn, true);

    DeleteObject(Rgn);
end;

procedure TsuiForm.RepaintMenuBar;
begin
    if (m_MenuBar = nil) or (m_Menu = nil) then
        Exit;
    if m_Menu is TsuiMainMenu then
        if (m_Menu as TsuiMainMenu).UseSystemFont then
            Menu_GetSystemFont(m_MenuBar.Font)
        else
        begin
            m_MenuBar.Font.Name := (m_Menu as TsuiMainMenu).FontName;
            m_MenuBar.Font.Size := (m_Menu as TsuiMainMenu).FontSize;
            m_MenuBar.Font.Charset := (m_Menu as TsuiMainMenu).FontCharset;
        end;
    m_MenuBar.Repaint();
end;

procedure TsuiForm.Resize;
begin
    inherited;

    m_TitleBar.Align := alTop;

{$IFDEF SUIPACK_D9UP}
    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;
{$ENDIF}
end;

procedure TsuiForm.SetBorderWidth(const Value: Integer);
begin
    m_Width := Value;

    PaintFormBorder();
end;

procedure TsuiForm.SetButtons(const Value: TsuiTitleBarButtons);
begin
    m_TitleBar.Buttons.Assign(Value);
end;

procedure TsuiForm.SetCaption(const Value: TCaption);
begin
    m_TitleBar.Caption := Value;
    m_Form.Caption := Value;
end;

procedure TsuiForm.SetColor(const Value: TColor);
begin
    m_Color := Value;

    PaintFormBorder();
end;

procedure TsuiForm.SetDrawAppIcon(const Value: Boolean);
begin
    m_TitleBar.DrawAppIcon := Value;
end;

procedure TsuiForm.SetFileTheme(const Value: TsuiFileTheme);
begin
    if m_FileTheme = Value then
        Exit;
    m_FileTheme := Value;
    SetUIStyle(m_UIStyle);
end;

procedure TsuiForm.SetFont(const Value: TFont);
begin
    m_TitleBar.Font := Value;
end;

procedure TsuiForm.SetMenu(const Value: TMainMenu);
begin
    if m_Menu <> nil then
    begin
        if m_Menu is TsuiMainMenu then
            (m_Menu as TsuiMainMenu).Form := nil;
    end;

    m_Menu := Value;

    if m_Menu is TsuiMainMenu then
        (m_Menu as TsuiMainMenu).Form := self;

    if m_Menu <> nil then
    begin
        if m_MenuBar = nil then
            CreateMenuBar();
        UpdateMenu();
    end
    else
        DestroyMenuBar();
end;

procedure TsuiForm.SetMenuBarColor(const Value: TColor);
begin
    m_MenuBarColor := Value;

    if m_MenuBar <> nil then
        m_MenuBar.Color := Value;
end;

procedure TsuiForm.SetMenuBarHeight(const Value: Integer);
var
    i : Integer;
begin
    m_MenuBarHeight := Value;

    if m_MenuBar <> nil then
    begin
        m_MenuBar.Height := m_MenuBarHeight;
        for i := 0 to m_MenuBar.ButtonCount - 1 do
            m_MenuBar.Buttons[i].Height := m_MenuBarHeight;
    end;
end;

procedure TsuiForm.SetOnBtnClick(
  const Value: TsuiTitleBarButtonClickEvent);
begin
    m_TitleBar.OnCustomBtnsClick := Value;
end;

procedure TsuiForm.SetOnHelpBtnClick(
  const Value: TsuiTitleBarButtonClickEvent);
begin
    m_TitleBar.OnHelpBtnClick := Value;
end;

procedure TsuiForm.SetPanel(const Value: TCustomPanel);
begin
    if Value = self then
    begin
        MessageDlg('Sorry, you can''t select the Form assign to FormPanel property', mtError, [mbOK], 0);	 
        Exit;
    end;

    m_Panel := Value;

    if m_Panel = nil then
        Exit;

    m_Panel.Align := alClient;

    if m_Panel is TPanel then
    begin
        TPanel(m_Panel).BevelOuter := bvNone;
        TPanel(m_Panel).BevelInner := bvNone;
        TPanel(m_Panel).BorderStyle := bsNone;
        TPanel(m_Panel).Caption := '';
    end
    else if m_Panel is TsuiImagePanel then
        TsuiImagePanel(m_Panel).Caption := '';
end;

procedure TsuiForm.SetRoundCorner(const Value: Integer);
begin
    m_TitleBar.RoundCorner := Value;
    RegionWindow();
end;

procedure TsuiForm.SetRoundCornerBottom(const Value: Integer);
begin
    m_TitleBar.RoundCornerBottom := Value;
    RegionWindow();
end;

procedure TsuiForm.SetSections(const Value: TsuiTitleBarSections);
begin
    m_TitleBar.Sections.Assign(Value);
end;

procedure TsuiForm.SetTitleBarCustom(const Value: Boolean);
begin
    m_TitleBar.Custom := Value;
end;

procedure TsuiForm.SetTitleBarVisible(const Value: Boolean);
begin
    if m_TitleBar.Visible = Value then
        Exit;
    m_TitleBar.Visible := Value;
    m_TitleBar.Top := 0;
    PaintFormBorder();
end;

procedure TsuiForm.SetUIStyle(const Value: TsuiUIStyle);
var
    OutUIStyle : TsuiUIStyle;
    Rect: TRect;
    Col : TColor;
    B : TBitmap;
begin
    Rect := m_Form.BoundsRect;

    m_UIStyle := Value;

    if UsingFileTheme(m_FileTheme, m_UIStyle, OutUIStyle) then
    begin
        BorderColor := m_FileTheme.GetColor(SUI_THEME_FORM_BORDER_COLOR);
        BorderWidth := m_FileTheme.GetInt(SUI_THEME_FORM_BORDERWIDTH_INT);
        Color := m_FileTheme.GetColor(SUI_THEME_FORM_BACKGROUND_COLOR);
        if m_MenuBar <> nil then
        begin
            Col := m_FileTheme.GetColor(SUI_THEME_MENU_MENUBAR_COLOR);
            if Col = -1 then
            begin
                Col := m_FileTheme.GetColor(SUI_THEME_CONTROL_FONT_COLOR);
                if Col = 131072 then
                    MenuBarColor := $00AC5B3B
                else if Col = 196608 then
                    MenuBarColor := $00996733
                else
                    MenuBarColor := Color;
            end
            else
                MenuBarColor := Col;
        end;
        RoundCorner := m_FileTheme.GetInt(SUI_THEME_FORM_ROUNDCORNER_INT);
        RoundCornerBottom := m_FileTheme.GetInt(SUI_THEME_FORM_BOTTOMROUNDCORNOR_INT);

        B := TBitmap.Create();
        m_FileTheme.GetBitmap(SUI_THEME_FORM_LEFTBORDER_IMAGE, B);
        if (B.Width <> 0) and (B.Height <> 0) then
        begin
            if m_BorderBuf <> nil then
                m_BorderBuf.Free();

            m_BorderBuf := TBitmap.Create();
            m_BorderBuf.Width := B.Width;
            m_BorderBuf.Height := B.Height;
            m_BorderBuf.Canvas.Draw(0, 0, B);
            RoundPicture2(m_BorderBuf);
        end
        else if m_BorderBuf <> nil then
        begin
            m_BorderBuf.Free();
            m_BorderBuf := nil;
        end;
        B.Free();
        B := TBitmap.Create();
        m_FileTheme.GetBitmap(SUI_THEME_FORM_BOTTOMBORDER_IMAGE, B);
        m_BottomBorderWidth := B.Height;
        B.Free();
    end
    else
    begin
        if m_BorderBuf <> nil then
        begin
            m_BorderBuf.Free();
            m_BorderBuf := nil;
        end;
        RoundCornerBottom := 0;
        m_BottomBorderWidth := 0;
        BorderColor := GetInsideThemeColor(OutUIStyle, SUI_THEME_FORM_BORDER_COLOR);
        BorderWidth := GetInsideThemeInt(OutUIStyle, SUI_THEME_FORM_BORDERWIDTH_INT);
        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;

    SetWindowPos(m_Form.Handle, 0, 0, 0, 0, 0, SWP_DRAWFRAME or SWP_NOMOVE or SWP_NOZORDER or SWP_NOSIZE or SWP_NOACTIVATE);        

    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;
    if m_Menu is TsuiMainMenu then
    begin
        if not TsuiMainMenu(m_Menu).UseSystemFont then
            m_MenuBar.Font.Size := TsuiMainMenu(m_Menu).FontSize
        else
            Menu_GetSystemFont(m_MenuBar.Font);
    end;

    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;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -