TLama

Untitled

Jan 27th, 2014
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.51 KB | None | 0 0
  1. uses
  2.   Vcl.RibbonStyleActnCtrls;
  3.  
  4. type
  5.   TRibbonGroup = class(Vcl.Ribbon.TRibbonGroup)
  6.   private
  7.     FMouseInControl: Boolean;
  8.     function GetCaptionRect: TRect;
  9.     function GetRibbonStyle: TRibbonStyleActionBars;
  10.     procedure CMMouseEnter(var AMessage: TMessage); message CM_MOUSEENTER;
  11.     procedure CMMouseLeave(var AMessage: TMessage); message CM_MOUSELEAVE;
  12.   protected
  13.     procedure Paint; override;
  14.   end;
  15.  
  16. implementation
  17.  
  18. { TCustomRibbonGroup }
  19.  
  20. function TRibbonGroup.GetCaptionRect: TRect;
  21. begin
  22.   Result := Rect(1, Height - GetCaptionHeight - 1, Width - 2, Height - 2);
  23. end;
  24.  
  25. function TRibbonGroup.GetRibbonStyle: TRibbonStyleActionBars;
  26. begin
  27.   if Style is TRibbonStyleActionBars then
  28.     Result := TRibbonStyleActionBars(Style)
  29.   else
  30.     Result := RibbonLunaStyle;
  31. end;
  32.  
  33. procedure TRibbonGroup.CMMouseEnter(var AMessage: TMessage);
  34. begin
  35.   FMouseInControl := True;
  36.   inherited;
  37. end;
  38.  
  39. procedure TRibbonGroup.CMMouseLeave(var AMessage: TMessage);
  40. begin
  41.   FMouseInControl := False;
  42.   inherited;
  43. end;
  44.  
  45. procedure TRibbonGroup.Paint;
  46. var
  47.   LRect: TRect;
  48.   LCaptionRect: TRect;
  49.   LFlags: Cardinal;
  50.   LStyle: TRibbonStyleActionBars;
  51. begin
  52.   LRect := ClientRect;
  53.   LRect.Left := LRect.Left - 10;
  54.   LRect.Top := LRect.Top - Top;
  55.   LRect.Right := LRect.Right + 10;
  56.   LRect.Bottom := LRect.Top + Parent.Height;
  57.  
  58.   LStyle := GetRibbonStyle;
  59.  
  60.   LStyle.DrawElement(srPage, Canvas, LRect, Page.Ribbon.GetRibbonMetric(rmCaption));
  61.   LRect := ClientRect;
  62.   LCaptionRect := GetCaptionRect;
  63.   if not Enabled then
  64.   begin
  65.     LStyle.DrawElement(srgBackgroundDisabled, Canvas, LRect);
  66.     LStyle.DrawElement(srgCaptionDisabled, Canvas, LCaptionRect);
  67.   end
  68.   else if FMouseInControl then
  69.   begin
  70.     LStyle.DrawElement(srgBackgroundHover, Canvas, LRect);
  71.     LStyle.DrawElement(srgCaptionHover, Canvas, LCaptionRect);
  72.   end
  73.   else
  74.   begin
  75.     LStyle.DrawElement(srgBackground, Canvas, LRect);
  76.     LStyle.DrawElement(srgCaption, Canvas, LCaptionRect);
  77.   end;
  78.   // Adjust caption rect for text
  79.   if (DialogAction <> nil) then
  80.     LCaptionRect.Right := LCaptionRect.Right - 15;
  81.   Canvas.Brush.Style := bsClear;
  82.   Canvas.Font.Assign(Font);
  83.   // Canvas.Font.Color := TCustomRibbonColorMap(ColorMap).GroupFontColor; <- this must go away
  84.   LCaptionRect.Left := LCaptionRect.Left + 3;
  85.   LFlags := DT_CENTER or DT_NOPREFIX or DT_SINGLELINE or DT_END_ELLIPSIS or DT_VCENTER;
  86.   DrawText(Canvas.Handle, Caption, -1, LCaptionRect, LFlags);
  87.   if (DialogAction <> nil) then
  88.     DrawShowDialogButton;
  89. end;
Advertisement
Add Comment
Please, Sign In to add comment