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

📄 wwradiobutton.pas

📁 胜天进销存源码,国产优秀的进销存
💻 PAS
📖 第 1 页 / 共 3 页
字号:
            Result:= tbRadioButtonCheckedDisabled
         end
         else begin
            if GetEffectiveChecked then
            begin
              if Pressed then
//              if (DFCS_PUSHED and StateFlags <>0 ) then
                 Result:= tbRadioButtonCheckedPressed
              else begin
                 if IsMouseInControl and not (csPaintCopy in ControlState) then
                    Result:= tbRadioButtonCheckedHot
                 else
                    Result:= tbRadioButtonCheckedNormal
              end
            end
            else begin
              if Pressed  then
//              if (DFCS_PUSHED and StateFlags <> 0) then
                 Result:= tbRadioButtonUncheckedPressed
              else begin
                 if IsMouseInControl and not (csPaintCopy in ControlState) then
                   Result:= tbRadioButtonUncheckedHot
                 else
                   Result:= tbRadioButtonUncheckedNormal
              end
            end;
         end;
    end;
    {$endif}
  procedure PaintText;
  var ARect, FocusRect: TRect;
      Flags: integer;
      HaveText: boolean;
      DrawRect: TRect;
      Temp: integer;
      {$ifdef wwUseThemeManager}
      Details: TThemedElementDetails;
      CheckboxStyle: TThemedButton;
      {$endif}
  begin
    Canvas.Font.Assign(Font);  //8/6/2001-PYW Uncomment to support radiobuttons font settings.

    ComputeTextRect(ARect);

    // 6/29/02 - Bidi mode
    if UseRightToLeftAlignment then
    begin
       Temp:= ARect.Left;
       ARect.Left:= ClientWidth-ARect.Right;
       ARect.Right:= ClientWidth-Temp;
    end;

//    if (GlyphImages<>nil) and (GetButtonIndex<=GlyphImages.count-1) then
//       ARect.Left:= ARect.Left + TImageList(GlyphImages).Width+2;
    HaveText:= (Text<>'') and GetShowText;
    if Focused and ShowFocusRect and
       (HaveText or (GlyphImages<>nil)) and
       not (csPaintCopy in ControlState) then
    begin
      if HaveText then
        FocusRect:= Rect(ARect.Left - 2, ARect.Top - 2,
                     wwMin(ARect.Right+2, ARect.Left + Canvas.TextWidth(Caption) + 2),
                     ARect.Bottom + 2)
      else begin
        ComputeGlyphRect(DrawRect);
        FocusRect:= DrawRect;
      end;

      Canvas.Brush.Color := Color;
      Canvas.Font.Color := clBlack;
      Canvas.FrameRect(FocusRect);
      Canvas.Brush.Color := clWhite;
      Canvas.Font.Color := clBlack;
      Canvas.DrawFocusRect(FocusRect);
    end;

    if not HaveText then exit;

    SetBkMode(Canvas.Handle, TRANSPARENT);
    Flags:= 0;
    if WordWrap then flags:= flags or DT_EDITCONTROL or DT_WORDBREAK;

    InflateRect(ARect, 0, 2);
    ARect.Top:= ARect.Top + 2;
    Canvas.Font.Color:= Font.Color;

    //9/19/2001-Radiobuttons in grid when dgAlwaysShowEditor is False and grid is still focused will have
    //          their text painted black instead of the highlight text color. This corrects that problem. {PYW}
    if isinGrid and (parent.parent.focused) and not (csPaintCopy in ControlState) then
       Canvas.Font.Color := clHighlightText;

    if (GetPaintCopyTextColor<>clNone) then
       Canvas.Font.Color:= GetPaintCopyTextColor;

    if (not Focused) and IsTransparentEffective and
       (Frame.NonFocusTransparentFontColor<>clNone) then
        Canvas.Font.Color:= Frame.NonFocusTransparentFontColor
    // 4/15/01
    else if (not Focused) and (Frame.Enabled) and
            (Frame.NonFocusFontColor<>clNone) then
       Canvas.Font.Color:= Frame.NonFocusFontColor;

    if (not (parent.Enabled and Enabled)) and not wwUseThemes(parent) then
    begin
      OffsetRect(ARect, 1, 1);
      Canvas.Font.Color:= clBtnHighlight;
      DrawTextEx(Canvas.Handle, Pchar(caption), length(caption), ARect, Flags, nil);
      Canvas.Font.Color:= clGrayText;
      OffsetRect(ARect, -1, -1);
    end;
    
    if wwUseThemes(self.parent) then
    begin
      {$ifdef wwUseThemeManager}
      CheckboxStyle:= GetRadioButtonThemeStyle(False);
      Details := ThemeServices.GetElementDetails(CheckboxStyle);

      if Caption <> '' then
          ThemeServices.DrawText(Canvas.Handle, Details, Caption, ARect, DT_LEFT, 0);
      {$endif}
    end
    else
       DrawTextEx(Canvas.Handle, Pchar(caption), length(caption), ARect, Flags, nil);
  end;

  procedure PaintTextGlyph;
  var drawRect: TRect;
  begin
    if GlyphImages=nil then exit;

    ComputeGlyphRect(DrawRect);
    if (GlyphImages<>nil) and (GetButtonIndex<=GlyphImages.count-1) then begin
       FGlyphImages.Draw(Canvas, drawrect.left, drawrect.top, GetButtonIndex, True);
    end
  end;

  procedure PaintCheckbox;
  var
      DrawRect: TRect;
      StateFlags: integer;
      cp: TPoint;
      {$ifdef wwUseThemeManager}
      Details: TThemedElementDetails;
      CheckboxStyle: TThemedButton;
      PaintRect: TRect;
      {$endif}
  begin
    ComputeImageRect(DrawRect);

    // 6/29/02 - Bidi mode
    if UseRightToLeftAlignment then
    begin
       DrawRect.Right:= ClientWidth-DrawRect.Left;
       DrawRect.Left:= DrawRect.Right-13;
    end;

    StateFlags:= DFCS_BUTTONRADIO;
    if GetEffectiveChecked then
       StateFlags := StateFlags or DFCS_CHECKED;

    if (cslbuttondown in controlstate) and Focused and not (csPaintCopy in ControlState) then
    begin
        if IsInGrid then
        begin
           GetCursorPos(cp);
           cp:= ScreenToClient(cp);
           if PtInRect(Rect(DrawRect.Left-3, DrawRect.Top-3, DrawRect.Right+3, DrawRect.Bottom+3),cp) then
              StateFlags := StateFlags or DFCS_PUSHED;
        end
        else begin
            if IsMouseInControl then
              StateFlags := StateFlags or DFCS_PUSHED;
        end
    end;

    if SpaceKeyPressed and (GetKeyState(vk_space)<0) and Focused and not (csPaintCopy in ControlState) then
       StateFlags := StateFlags or DFCS_PUSHED;

    if GetEffectiveChecked then
    begin
       if (Images<>nil) and (Images.count>1) then begin
          FImages.Draw(Canvas, drawrect.left, drawrect.top, 1, True);
          exit;
       end
    end
    else begin
       if (Images<>nil) and (Images.count>0) then begin
          FImages.Draw(Canvas, drawrect.left, drawrect.top, 0, True);
          exit;
       end
    end;

    if not Enabled then StateFlags:= StateFlags + DFCS_INACTIVE;

    if wwUseThemes(self.parent) then
    begin
         {$ifdef wwUseThemeManager}
         CheckboxStyle:= GetRadioButtonThemeStyle((StateFlags and DFCS_PUSHED)<>0);
         Details := ThemeServices.GetElementDetails(CheckboxStyle);
         PaintRect := DrawRect;
         ThemeServices.DrawElement(Canvas.Handle, Details, PaintRect);
         PaintRect := ThemeServices.ContentRect(Canvas.Handle, Details, PaintRect);
         {$endif}
    end
    else begin
      with DrawRect do
         DrawFrameControl(Canvas.Handle, DrawRect,
             DFC_BUTTON, StateFlags);
    end
  end;

{  procedure PaintRadioButton;
  var
      DrawRect: TRect;
      StateFlags: integer;
  begin
    FCanvas.Brush.Color := clBtnShadow;

    StateFlags:= DFCS_BUTTONRADIO;

    if IsMouseInControl and Focused then
    begin
      if (cslbuttondown in controlstate) then
         StateFlags := StateFlags or DFCS_PUSHED;
    end;
    if SpaceKeyPressed and (GetKeyState(vk_space)<0) and Focused then
       StateFlags := StateFlags or DFCS_PUSHED;

//    if Checked then
    if GetEffectiveChecked then
       StateFlags := StateFlags or DFCS_CHECKED;

//    PaintButton;
    with DrawRect do
       DrawFrameControl(FCanvas.Handle, DrawRect,
           DFC_BUTTON, StateFlags);
  end;
}
  Function Max(x,y: integer): integer;
  begin
     if x>y then result:=x else result:=y
  end;

begin
//   IsInGrid:= False; //parent.parent is TCustomGrid;
   IsInGrid:= parent.parent is TCustomGrid;
   if(not IsTransparentEffective) or
     (not AlwaysTransparent) and (Focused) { or IsInGrid) }then
   begin
      if not (csPaintCopy in ControlState) then
      begin
        r:= ClientRect;

//        if not IsInGrid then
//           InflateRect(r, -2, -2);
        FCanvas.Brush.Color:= Color;
//        rg:= TwwRadioGroup(parent);

        if GetLastBrushColor<>clNone then
           FCanvas.Brush.Color:= GetLastBrushColor

        // 4/15/01 - Back-color support
        else if (not IsTransparentEffective) and
           (not Focused) and (Frame.NonFocusColor<>clNone) then
        begin
           FCanvas.Brush.Color:= Frame.NonFocusColor;
        end;
{        else if not rg.Focused and
           (rg.Frame.Enabled) and (not rg.Frame.Transparent) and
           (Frame.NonFocusColor=clNone) and (rg.Frame.NonFocusColor<>clNOne) then
           FCanvas.Brush.Color:= rg.Frame.NonFocusColor;
}
        if not wwUseThemes(self.parent) then
           FCanvas.FillRect(r);
      end
   end;

{
   RadioButtonSize:= 13;
   offset:= RadioButtonsize div 2;
   TempIndentX:= IndentRadioButtonX;
   if Frame.Enabled and
      (efLeftBorder in Frame.FocusBorders) then
   begin
      TempIndentX:= max(TempIndentX, 3);
   end;

   if Alignment = taRightJustify then
      pt.x:= offset + TempIndentX
   else
      pt.x:= Width - TempIndentX - RadioButtonsize;
   pt.y:= Height div 2;
}
(*     if (not (Frame.Enabled and Frame.Transparent)) or
       (not AlwaysTransparent) and (Focused) then
     begin
        if not (IsInGridPaint(self.parent)) then
        begin
          r:= ClientRect;
//          InflateRect(r, -2, -2); // Seems to cause glyph to not appear
          Canvas.Brush.Color:= Color;
          Canvas.FillRect(r);
        end
     end;
*)
   PaintCheckbox;
   PaintTextGlyph;
   PaintText;
end;

procedure TwwCustomRadioButton.ComputeImageRect(var DrawRect: TRect);
var offsetx, offsety: integer;
    checkboxSizeX, checkboxSizeY: integer;
    pt: TPoint;
    TempIndentCheckboxX: integer;
begin
   if (Images<>nil) and (Images.count>0) then
   begin
      checkboxSizeX:= Images.Width;
      checkboxSizeY:= Images.Height;
   end
   else begin
      checkboxSizex:= 13;
      checkboxSizey:= 13;
   end;

     offsetx:= checkboxsizex div 2;
     offsety:= checkboxsizey div 2;

     TempIndentCheckboxX:= Indents.ButtonX;
     if Frame.Enabled and
        (efLeftBorder in Frame.FocusBorders) then
     begin
        TempIndentCheckboxX:= wwmax(TempIndentCheckboxX, 1);
     end;

     if Alignment = taRightJustify then
        pt.x:= offsetx + TempIndentCheckboxX
     else
        pt.x:= ClientWidth - TempIndentCheckboxX - offsetx -2;
     pt.y:= Height div 2;

     DrawRect.Left:= pt.x - offsetx;
     DrawRect.Right:= pt.x + offsetx+1;
     DrawRect.Top:= pt.y-offsety+Indents.ButtonY;
     DrawRect.Bottom:= pt.y+offsety+1+Indents.ButtonY;

end;

procedure TwwCustomRadioButton.ComputeTextRect(var DrawRect: TRect);
var pt: TPoint;
    NewDrawRect: TRect;
    DrawFlags: integer;
begin
   ComputeImageRect(DrawRect);

   pt.y:= Height div 2;
   if Alignment = taRightJustify then
       NewDrawRect:= Rect(DrawRect.Right + 2 + Indents.TextX, 0,
                     Width, Height)
   else
      NewDrawRect:= Rect(Indents.TextX + 2, 0, DrawRect.Left, Height);
   DrawFlags:= 0;
   if WordWrap then
      DrawFlags:= DrawFlags or DT_EDITCONTROL or DT_WORDBREAK;
   if (GlyphImages<>nil) then
   begin
      NewDrawRect.Left:= NewDrawRect.Left + TImageList(GlyphImages).width +2;
   end;
   DrawTextEx(Canvas.Handle, PChar(Caption),
              Length(Caption), newdrawrect, DrawFlags or DT_CALCRECT, nil);
   DrawRect:= NewDrawRect;
   DrawRect.Top:= Indents.TextY + (ClientHeight -
                   (NewDrawRect.Bottom-NewDrawRect.Top)) div 2;
   DrawRect.Bottom:= DrawRect.Top + NewDrawRect.Bottom; //DrawRect.Bottom - (NewDrawRect.Bottom-NewDrawRect.Top) div 2;

end;

procedure TwwCustomRadioButton.ComputeGlyphRect(var DrawRect: TRect);
begin
   ComputeTextRect(DrawRect);
   if (GlyphImages<>nil) and (GetButtonIndex<=GlyphImages.count-1) then
   begin
      DrawRect.Right:= DrawRect.Left;
      DrawRect.Left:= DrawRect.Left - (TImageList(GlyphImages).Width+2);
   end;
   DrawRect.Top:= {Indents.GlyphY +} (ClientHeight-TImageList(GlyphImages).Height) div 2;
   DrawRect.Bottom:= DrawRect.Top +  TImageList(GlyphImages).Height;
end;

procedure TwwCustomRadioButton.WMLButtonDown(var Message: TWMLButtonDown);
var r: TRect;
    AnyClickToggles: boolean;
begin
   if (parent is TwwCustomRadioGroup) then
      AnyClickToggles:= TwwCustomRadioGroup(parent).AnyClickToggles

⌨️ 快捷键说明

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