delphi4arab منتديات دلفي للعرب

نسخة كاملة : Fix TRibbon Bug
أنت حالياً تتصفح نسخة خفيفة من المنتدى . مشاهدة نسخة كاملة مع جميع الأشكال الجمالية .
السلام عليكم و رحمة الله و بركاته

مكون TRibbon الشهير الخاص بدلفي .. يحتوي على Bug عند تغيير الستايل الخاص ب TRibbon في وقت التنفيذ
كود :
http://delphinews.files.wordpress.com/2013/05/ribbon-bug.gif
كما تلاحظ بعد أن يتم تغيير الستايل الخاص TRibbon في وقت التنفيذ لا يتم اعادة رسم ال Page بالستايل الجديد

السبب : هو أنه لا يتم اعادة رسم ActivePage بعد تغيير الستايل , حتى ولو قمت باجبار TRibbon على اعادة الرسم .
PHP كود :
Ribbon1.Refresh; 

عندما يتم تغيير الستايل يتم اعادة رسم ال TRibbon و كل ال Childs الخاصة بها ماعدا الكلاس TCustomRibbonPage , فلا يتم اعادة رسمه .

الحل : يجب أن نقوم بعمل Refresh لل ActivePage
PHP كود :
unit RibbonFix;
{ 
Fix Bug when you change Ribbon Style }

interface

uses

{$IF CompilerVersion >= 23}
  
WinApi.Messages, Vcl.Ribbon,
  
Vcl.RibbonStyleActnCtrls,
  
Vcl.RibbonLunaStyleActnCtrls;
{
$ELSE}
  
Messages, Ribbon, RibbonStyleActnCtrls,
  
RibbonLunaStyleActnCtrls;
{
$IFEND}

type
  TRibbon 
= class(Vcl.Ribbon.TRibbon)
  private

    
FCurrentStyle: TRibbonStyleActionBars;
    function 
GetStyle: TRibbonStyleActionBars;
    
procedure SetStyle(const Value: TRibbonStyleActionBars);

  
published
    property Style
: TRibbonStyleActionBars read GetStyle write SetStyle;

  
end;

implementation

{ --------> By SMP3 <----------- }

function 
TRibbon.GetStyle: TRibbonStyleActionBars;
begin
  
if (ActionManager <> nil) and (ActionManager.Style is TRibbonStyleActionBars)
  
then
    begin
      Result 
:= TRibbonStyleActionBars(ActionManager.Style);
    
end
  
else
    
begin
      Result 
:= RibbonLunaStyle;
      
SetStyle(Result);
    
end;
  if 
FCurrentStyle <> Result then
    Invalidate
;
  
FCurrentStyle := Result;
end;

procedure TRibbon.SetStyle(const Value: TRibbonStyleActionBars);
var
  
i: integer;
begin
  
if ActionManager <> nil then
    begin
      
if (Value = nil) or not(Value is TRibbonStyleActionBars) then
        ActionManager
.Style := RibbonLunaStyle
      
else
        
ActionManager.Style := Value;
      
// Force the recreation of the correct colormap for the selected style
      // SetColorMap(nil);
      
ColorMap := nil;
      
Invalidate;
      
DoGroupStyleChanged;
      
Parent.Perform(WM_NCPAINT, 0, 0);

      for 
i := 0 to Tabs.Count - 1 do
        
Tabs.Items[i].Page.Refresh; { Refresh All Pages }

    
end;

end;

end. 

الآن كل ما عليك فعله هو ارفاق الوحدة RibbonFix في المشروع

ملاحظة : الوحدة RibbonFix يجب أن تكون مرفقة بعد وحدة Ribbon و ليس قبلها .
PHP كود :
uses Vcl.Ribbon,RibbonFix,... ; 

كود :
http://delphinews.files.wordpress.com/2013/05/ribbon-fix.gif