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

📄 sxskingroupbox.pas

📁 skin components for design of your applicastions
💻 PAS
📖 第 1 页 / 共 4 页
字号:
                      FDown:=False;
                      StartGlyphChanging(gcaCheck);
                      if Parent<>nil then
                       begin
                        for A:=0 to Parent.ControlCount-1 do
                         begin
                          if (Parent.Controls[A]<>Self) and (Parent.Controls[A] is TSXSkinCustomRadioButton) and
                             TSXSkinCustomRadioButton(Parent.Controls[A]).Checked then
                           begin
                            TSXSkinCustomRadioButton(Parent.Controls[A]).DoUncheck;
                           end else
                          if (Parent.Controls[A]<>Self) and (Parent.Controls[A] is TSXSkinCustomGroupBox) and
                             (TSXSkinCustomGroupBox(Parent.Controls[A]).GlyphType=gtRadioButton) and
                             TSXSkinCustomGroupBox(Parent.Controls[A]).Checked then
                           begin
                            TSXSkinCustomGroupBox(Parent.Controls[A]).DoUncheck;
                           end;                           
                         end;
                       end;
                      FState:=cbChecked;
                      ResetGroupBoxParams([gbrpTextOnFontChange,gbrpGlyphOnSizeChange,
                                           gbrpGlyphOnStyleChange,gbrpInvalidateOnStyleChange,
                                           gbrpTransparentRect]);
                      if Assigned(FOnChange) then
                       FOnChange(Self);
                     end else
                      begin
                       StartGlyphChanging(gcaUp);
                       FDown:=False;
                       ResetGroupBoxParams([gbrpTextOnFontChange,gbrpGlyphOnSizeChange,
                                            gbrpGlyphOnStyleChange,gbrpInvalidateOnStyleChange,
                                            gbrpTransparentRect]);
                      end;
                   end;
   end;
  end else FDown:=False;
end;

procedure TSXSkinCustomGroupBox.Loaded;
begin
 inherited;
 ResetGroupBoxParams([gbrpText,gbrpGlyph,gbrpTransparentRect,gbrpInvalidateOnStyleChange]);
end;

procedure TSXSkinCustomGroupBox.Click;
begin
 FDown:=True;
 DoClick;
 inherited;
end;

procedure TSXSkinCustomGroupBox.DoKeyDown(var Msg: TMessage);
begin
 inherited;
 if Enabled and (Msg.WParam in [VK_SPACE,VK_RETURN]) then
  begin
   StartGlyphChanging(gcaDown);
   FDown:=True;
   ResetGroupBoxParams([gbrpTextOnFontChange,gbrpGlyphOnSizeChange,
                        gbrpGlyphOnStyleChange,gbrpInvalidateOnStyleChange,
                        gbrpTransparentRect]);
  end;
end;

procedure TSXSkinCustomGroupBox.DoKeyUp(var Msg: TMessage);
var OldDown,WasChecked:Boolean;
begin
 inherited;
 if Enabled and FDown then
  begin
   OldDown:=FDown;
   StartGlyphChanging(gcaUp);
   FDown:=False;
   ResetGroupBoxParams([gbrpTextOnFontChange,gbrpGlyphOnSizeChange,
                        gbrpGlyphOnStyleChange,gbrpInvalidateOnStyleChange,
                        gbrpTransparentRect]);
   if OldDown and (Msg.WParam in [VK_SPACE,VK_RETURN]) then
    begin
     WasChecked:=Checked;
     Click;
     if Assigned(FOnUserModified) and not ((FGlyphType=gtRadioButton) and WasChecked) then
      FOnUserModified(Self);
    end;
  end;
end;

procedure TSXSkinCustomGroupBox.AdjustClientRect(var Rect:TRect);
var    A:Integer;
   Style:TSXSkinGroupBoxStyle;
begin
 inherited AdjustClientRect(Rect);
 if (SkinLibrary<>nil) and SkinLibrary.CanBeUsed then
  begin
   A:=SkinLibrary.Styles.GetIndexByName(SkinStyle);
   if (A>=0) and (SkinLibrary.Styles[A] is TSXSkinGroupBoxStyle) then
    begin
     Style:=TSXSkinGroupBoxStyle(SkinLibrary.Styles[A]);
     if Style.ClientRect<>'' then
      GetRectFromString(Style.ClientRect,Rect,OnGetVariable);
    end;
  end;
end;

procedure TSXSkinCustomGroupBox.DoUncheck;
begin
 StartGlyphChanging(gcaUncheck);
 FState:=cbUnchecked;
 ResetGroupBoxParams([gbrpTextOnFontChange,gbrpGlyphOnSizeChange,
                      gbrpGlyphOnStyleChange,gbrpInvalidateOnStyleChange]);
end;

procedure TSXSkinCustomGroupBox.ResetGroupBoxParams(Params:TSXSkinGroupBoxResetParams=[]);
var     GW,GH:Integer;
       GStyle:String;
 OldGlyphRect:TRect;
  OldTextRect:TRect;
    TransRect:TRect;
 GlyphChanged:Boolean;
  TextChanged:Boolean;
   SetGBState:Boolean;
      GBState:TSXSkinGroupBoxStateParam;
           FD:TSXFontData;
   B,GTHeight:Integer;
        Flags:Cardinal;

 procedure DoSetGBState;
 begin
  if not SetGBState then
   GetCurrentGBState(GBState);
 end;

begin
 if Parent=nil then exit;
 OldGlyphRect:=FGlyphRect;
 OldTextRect:=FTextRect;
 GlyphChanged:=False;
 TextChanged:=False;
 SetGBState:=False;
 if Params*[gbrpGlyph,gbrpGlyphOnStyleChange,gbrpGlyphOnSizeChange]<>[] then
  begin
   GetCurrentGlyphStyle(GStyle,@GW,@GH);
   if gbrpGlyph in Params then GlyphChanged:=True else
    begin
     if gbrpGlyphOnSizeChange in Params then
      GlyphChanged:=(GW<>FGlyphRect.Right-FGlyphRect.Left) or
                    (GH<>FGlyphRect.Bottom-FGlyphRect.Top);
     if not GlyphChanged and (gbrpGlyphOnStyleChange in Params) then
      GlyphChanged:=(FLastGlyphStyle<>GStyle);
    end;
   if GlyphChanged then
    FGlyphRect:=Rect(0,0,GW,GH);
   FLastGlyphStyle:=GStyle;
  end;
 if Params*[gbrpText,gbrpTextOnFontChange,gbrpTextIfWordWrap]<>[] then
  begin
   DoSetGBState;
   GetCurrentFontData(FD);
   if gbrpText in Params then TextChanged:=True else
    if FWordWrap and (gbrpTextIfWordWrap in Params) then TextChanged:=True else
    if gbrpTextOnFontChange in Params then
     TextChanged:=not SameFontData(FD,FLastFontData);
   if TextChanged then
    begin
     if FTextBitmap<>nil then
      begin
       FTextBitmap.Free;
       FTextBitmap:=nil;
      end;
     FLastFontData:=FD;
     Canvas.Font.Name:=FD.FontName;
     Canvas.Font.Size:=FD.FontSize;
     Canvas.Font.Style:=FD.FontStyle;
     if FGlyphRect.Right-FGlyphRect.Left=0 then
      FTextRect:=Rect(0,0,Width-2*GBState.CaptionPosition-GBState.CaptionLeftOffset-GBState.CaptionRightOffset,Height) else
       FTextRect:=Rect(0,0,Width-2*GBState.CaptionPosition-FGlyphRect.Right+
        FGlyphRect.Left-GBState.CaptionLeftOffset-GBState.CaptionRightOffset-
        FTextOffset,Height);
     Flags:=DT_NOPREFIX or DT_NOCLIP or DT_TOP or DT_CALCRECT;
     case FAlignment of
      taLeftJustify:  Flags:=Flags or DT_LEFT;
      taRightJustify: Flags:=Flags or DT_RIGHT;
      taCenter:       Flags:=Flags or DT_CENTER;
     end;
     if FWordWrap then Flags:=Flags or DT_WORDBREAK;
     Dec(FTextRect.Right,GBState.TextLeftOffset+GBState.TextRightOffset);
     Dec(FTextRect.Bottom,GBState.TextTopOffset+GBState.TextBottomOffset);
     if FD.SmoothLevel=0 then
      DrawText(Canvas.Handle,PChar(Caption),-1,FTextRect,Flags) else
       DrawSmoothText(Canvas,Caption,FTextRect,Flags,FD.SmoothLevel);
     Inc(FTextRect.Right,GBState.TextLeftOffset+GBState.TextRightOffset);
     Inc(FTextRect.Bottom,GBState.TextTopOffset+GBState.TextBottomOffset);
     //
     FLastTextLeftOffset:=GBState.TextLeftOffset;
     FLastTextTopOffset:=GBState.TextTopOffset;
     FLastTextRightOffset:=GBState.TextRightOffset;
     FLastTextBottomOffset:=GBState.TextBottomOffset;
    end;
  end;
 if (SkinLibrary<>nil) and SkinLibrary.CanBeUsed then
  begin
   DoSetGBState;
   case FCaptionAlignment of
    taLeftJustify:  begin
                     if FGlyphRect.Right-FGlyphRect.Left=0 then
                      FCaptionRect:=Rect(GBState.CaptionPosition,0,
                        GBState.CaptionPosition+GBState.CaptionLeftOffset+
                        FTextRect.Right-FTextRect.Left+GBState.CaptionRightOffset,0) else
                      FCaptionRect:=Rect(GBState.CaptionPosition,0,
                        GBState.CaptionPosition+GBState.CaptionLeftOffset+
                        FGlyphRect.Right-FGlyphRect.Left+FTextOffset+
                        FTextRect.Right-FTextRect.Left+GBState.CaptionRightOffset,0);
                    end;
    taRightJustify: begin
                     if FGlyphRect.Right-FGlyphRect.Left=0 then
                      FCaptionRect:=Rect(Width-GBState.CaptionPosition-
                        GBState.CaptionLeftOffset-FTextRect.Right+
                        FTextRect.Left-GBState.CaptionRightOffset,0,
                        Width-GBState.CaptionPosition,0) else
                      FCaptionRect:=Rect(Width-GBState.CaptionPosition-
                        GBState.CaptionLeftOffset-FGlyphRect.Right+
                        FGlyphRect.Left-FTextOffset-FTextRect.Right+
                        FTextRect.Left-GBState.CaptionRightOffset,0,
                        Width-GBState.CaptionPosition,0);
                    end;
    taCenter:       begin
                     if FGlyphRect.Right-FGlyphRect.Left=0 then
                      B:=GBState.CaptionLeftOffset+FTextRect.Right-
                        FTextRect.Left+GBState.CaptionRightOffset else
                      B:=GBState.CaptionLeftOffset+FGlyphRect.Right-
                        FGlyphRect.Left+FTextOffset+FTextRect.Right-
                        FTextRect.Left+GBState.CaptionRightOffset;
                     FCaptionRect:=Rect((Width-B) div 2,0,(Width+B) div 2,0);
                    end;
   end;
   GTHeight:=Max(FGlyphRect.Bottom-FGlyphRect.Top,FTextRect.Bottom-FTextRect.Top);
   FCaptionRect.Bottom:=GBState.CaptionTopOffset+GBState.CaptionBottomOffset+GTHeight;
   case FGlyphPosition of
    gbgpLeft:  begin
                OffsetRect(FGlyphRect,-FGlyphRect.Left+FCaptionRect.Left+
                  GBState.CaptionLeftOffset,-FGlyphRect.Top+FCaptionRect.Top+
                  GBState.CaptionTopOffset+(GTHeight-FGlyphRect.Bottom+FGlyphRect.Top) div 2);
                if FGlyphRect.Right-FGlyphRect.Left=0 then
                 OffsetRect(FTextRect,-FTextRect.Left+FGlyphRect.Right,
                   -FTextRect.Top+FCaptionRect.Top+GBState.CaptionTopOffset+
                   (GTHeight-FTextRect.Bottom+FTextRect.Top) div 2) else
                 OffsetRect(FTextRect,-FTextRect.Left+FGlyphRect.Right+FTextOffset,
                   -FTextRect.Top+FCaptionRect.Top+GBState.CaptionTopOffset+
                   (GTHeight-FTextRect.Bottom+FTextRect.Top) div 2);
               end;
    gbgpRight: begin
                OffsetRect(FTextRect,-FTextRect.Left+FCaptionRect.Left+
                  GBState.CaptionLeftOffset,-FTextRect.Top+FCaptionRect.Top+
                  GBState.CaptionTopOffset+(GTHeight-FTextRect.Bottom+FTextRect.Top) div 2);
                OffsetRect(FGlyphRect,-FGlyphRect.Left+FTextRect.Right+FTextOffset,
                   -FGlyphRect.Top+FCaptionRect.Top+GBState.CaptionTopOffset+
                   (GTHeight-FGlyphRect.Bottom+FGlyphRect.Top) div 2);
               end;
   end;
  end;
 //Invalidating Regions
 if GlyphChanged or not EqualRect(OldGlyphRect,FGlyphRect) then
  begin
   if HandleAllocated then
    begin
     InvalidateRect(Handle,@OldGlyphRect,False);
     InvalidateRect(Handle,@FGlyphRect,False);
    end;
  end;
 if TextChanged or not EqualRect(OldTextRect,FTextRect) then
  begin
   if HandleAllocated then
    begin
     InvalidateRect(Handle,@OldTextRect,False);
     InvalidateRect(Handle,@FTextRect,False);
    end;
  end;
 //
 if gbrpInvalidateOnStyleChange in Params then
  begin
   DoSetGBState;
   if (GBState.Style<>FLastGBStyle) or (GBState.OverStyle<>FLastGBOverStyle) then
    begin
     if HandleAllocated then
      InvalidateGroupBoxArea;
     FLastGBStyle:=GBState.Style;
     FLastGBOverStyle:=GBState.OverStyle;
    end;
  end;
 if gbrpTransparentRect in Params then
  begin
   DoSetGBState;
   if GBState.TransparentRect<>'' then
    begin
     GetRectFromString(GBState.TransparentRect,TransRect,OnGetVariable);
     if not EqualRect(TransRect,FTransparentRect) then
      begin
       InvalidateGroupBoxArea;
       FTransparentRect:=TransRect;
       InvalidateGroupBoxArea;
      end;
    end else FTransparentRect:=Types.Rect(0,0,0,0);
  end;
end;

procedure TSXSkinCustomGroupBox.SetEnabled(Value:Boolean);
begin
 if Enabled<>Value then
  begin
   if not (csLoading in ComponentState) then
    begin
     if Enabled then
      StartGlyphChanging(gcaDisable) else
       StartGlyphChanging(gcaEnable);
    end;
   inherited;
   if not Enabled then
    begin
     FMouseOver:=False;
     FDown:=False;
    end;
   if not (csLoading in ComponentState) then
    ResetGroupBoxParams([gbrpTextOnFontChange,gbrpGlyphOnSizeChange,
                         gbrpGlyphOnStyleChange,gbrpInvalidateOnStyleChange]);
  end;
end;

function TSXSkinCustomGroupBox.IsTransparent(X,Y:Integer;Limit:Integer=10):Boolean;
var    A:Integer;
   Style:TSXSkinGeneralStyle;
 GBState:TSXSkinGroupBoxStateParam;
begin
 Result:=True;
 if (SkinLibrary<>nil) and SkinLibrary.CanBeUsed then
  begin
   GetCurrentGBState(GBState);
   A:=SkinLibrary.Styles.GetGStyleIndex(GBState.Style,Width,Height);
   if A>=0 then
    begin
     Style:=TSXSkinGeneralStyle(SkinLibrary.Styles[A]);
     Result:=Style.IsTransparent(Self,CEID_Back,X,Y,Width,Height,SkinLibrary,Limit,VComparer);
    end;
   if Result then
    begin
     A:=SkinLibrary.Styles.GetGStyleIndex(GBState.OverStyle,Width,Height);
     if A>=0 then
      begin
       Style:=TSXSkinGeneralStyle(SkinLibrary.Styles[A]);
       Result:=Style.IsTransparent(Self,CEID_Back,X,Y,Width,Height,SkinLibrary,Limit,VComparer);
      end;
    end;
   if Result and (FGlyphStyle<>'') then
    begin
     A:=SkinLibrary.Styles.GetGStyleIndex(FGlyphStyle,Width,Height);
     if A>=0 then
      begin
       Style:=TSXSkinGeneralStyle(SkinLibrary.Styles[A]);
       Result:=Style.IsTransparent(Self,CEID_Glyph,X,Y,Width,Height,SkinLibrary,Limit);
      end;
    end;
  end;
end;

function TSXSkinCustomGroupBox.CapturesMouseAt(X,Y:Integer):Boolean;
var    A:Integer;
   Style:TSXSkinGeneralStyle;
 GBState:TSXSkinGroupBoxStateParam;
begin
 Result:=True;
 if (SkinLibrary<>nil) and SkinLibrary.CanBeUsed then
  begin
   GetCurrentGBState(GBState);
   A:=SkinLibrary.Styles.GetGStyleIndex(GBState.Style,Width,Height);
   if A>=0 then
    begin
     Style:=TSXSkinGeneralStyle(SkinLibrary.Styles[A]);
     Result:=Style.CapturesMouseAt(Self,CEID_Back,X,Y,Width,Height,SkinLibrary,VComparer);
    end;
   if not Result then
    begin
     A:=SkinLibrary.Styles.GetGStyleIndex(GBState.OverStyle,Width,Height);
     if A>=0 then
      begin
       Style:=TSXSkinGeneralStyle(SkinLibrary.Styles[A]);
       Result:=Style.CapturesMouseAt(Self,CEID_Back,X,Y,Width,Height,SkinLibrary,VComparer);
      end;
    end;
   if not Result and (FGlyphStyle<>'') then
    begin
     A:=SkinLibrary.Styles.GetGStyleIndex(FGlyphStyle,FGlyphRect.Right-FGlyphRect.Left,FGlyphRect.Bottom-FGlyphRect.Top);
     if A>=0 then
      begin
       Style:=TSXSkinGeneralStyle(SkinLibrary.Styles[A]);
       Result:=Style.CapturesMouseAt(Self,CEID_Glyph,X-FGlyphRect.Left,Y-FGlyphRect.Top,
          FGlyphRect.Right-FGlyphRect.Left,FGlyphRect.Bottom-FGlyphRect.Top,SkinLibrary);
      end;
    end;
   if not Result then
    Result:=PtInRect(FTextRect,Point(X,Y));
  end;
end;

constructor TSXSkinCustomGroupBox.Create(AOwner:TComponent);
begin
 inherited Create(AOwner);
 CEID_Back:=GetNewCElementID;
 CEID_Glyph:=GetNewCElementID;
 VComparer:=TSXGroupBoxVariableComparer.Create;
 VComparer.Control:=Self;
 VComparer.OnGetVariable:=OnGetVariable;
 ControlStyle:=ControlStyle+[csSetCaption]-[csDoubleClicks];
 FUseLabelStyle:=True;
 FTextOffset:=2;
 SkinStyle:='_GroupBox';
end;

destructor TSXSkinCustomGroupBox.Destroy;
begin
 FThread.Free;
 FTextBitmap.Free;
 FLastGlyph.Free;
 inherited;
 VComparer.Free; 
end;

end.

⌨️ 快捷键说明

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