Recent

Author Topic: TRxDBLookupCombo missing OnPaint event  (Read 8666 times)

lainz

  • Hero Member
  • *****
  • Posts: 4449
    • https://lainz.github.io/
Re: TRxDBLookupCombo missing OnPaint event
« Reply #15 on: February 07, 2018, 12:24:38 pm »
3. I do not have a Mac. If it is not difficult - register on the bugtracker the error of displaying themes for Mac.

Hi, ok, what I supposed. No problem, I will try to fix it, maybe I can fix the cross compiler and test in the mac VM I have.

lainz

  • Hero Member
  • *****
  • Posts: 4449
    • https://lainz.github.io/
Re: TRxDBLookupCombo missing OnPaint event
« Reply #16 on: February 07, 2018, 10:51:40 pm »
Hi, this is the fix for macOS, fix of the fix =)

Code: Pascal  [Select][+][-]
  1. procedure TRxCustomDBLookupCombo.Paint;
  2. const
  3.   padding : Integer = 1;
  4. var
  5.   Selected:boolean;
  6.   R, R1, R2: TRect;
  7.   AText: string;
  8.   border : Integer;
  9.   Details, DetailsBtn: TThemedElementDetails;
  10.   BtnSize: TSize;
  11.   pr: PRect;
  12. begin
  13.  
  14.   R := Rect(0, 0, ClientWidth, ClientHeight);
  15.  
  16.   if ThemeServices.ThemesEnabled and (FStyle = rxcsDropDownList) then
  17.   begin
  18.     Canvas.Brush.Color := Parent.Color;
  19.     Canvas.FillRect(R);
  20.     {$IFDEF DARWIN}
  21.     if Enabled then
  22.     begin
  23.       if MouseInClient then
  24.       begin
  25.         if FMouseDown then
  26.         begin
  27.           Details := ThemeServices.GetElementDetails(tcDropDownButtonPressed);
  28.           DetailsBtn := ThemeServices.GetElementDetails(tcDropDownButtonPressed);
  29.         end
  30.         else
  31.         begin
  32.           Details := ThemeServices.GetElementDetails(tcDropDownButtonNormal);
  33.           DetailsBtn := ThemeServices.GetElementDetails(tcDropDownButtonNormal);
  34.         end;
  35.       end
  36.       else
  37.       begin
  38.         Details := ThemeServices.GetElementDetails(tcDropDownButtonNormal);
  39.         DetailsBtn := ThemeServices.GetElementDetails(tcDropDownButtonNormal);
  40.       end;
  41.     end
  42.     else
  43.     begin
  44.       Details := ThemeServices.GetElementDetails(tcDropDownButtonDisabled);
  45.       DetailsBtn := ThemeServices.GetElementDetails(tcDropDownButtonDisabled);
  46.     end;
  47.     ThemeServices.DrawElement(Canvas.Handle, Details, R, nil);
  48.     {$ELSE}
  49.     if Enabled then
  50.     begin
  51.       if MouseInClient then
  52.       begin
  53.         if FMouseDown then
  54.         begin
  55.           Details := ThemeServices.GetElementDetails(tbPushButtonPressed);
  56.           DetailsBtn := ThemeServices.GetElementDetails(tcDropDownButtonPressed);
  57.         end
  58.         else
  59.         begin
  60.           Details := ThemeServices.GetElementDetails(tbPushButtonHot);
  61.           DetailsBtn := ThemeServices.GetElementDetails(tcDropDownButtonHot);
  62.         end;
  63.       end
  64.       else
  65.       begin
  66.         Details := ThemeServices.GetElementDetails(tbPushButtonNormal);
  67.         DetailsBtn := ThemeServices.GetElementDetails(tcDropDownButtonNormal);
  68.       end;
  69.     end
  70.     else
  71.     begin
  72.       Details := ThemeServices.GetElementDetails(tbPushButtonDisabled);
  73.       DetailsBtn := ThemeServices.GetElementDetails(tcDropDownButtonDisabled);
  74.     end;
  75.     ThemeServices.DrawElement(Canvas.Handle, Details, R, nil);
  76.     {$ENDIF}
  77.  
  78.     BtnSize.Width:=20;
  79.     {$IFDEF DARWIN}
  80.     {$ELSE}
  81.     //BtnSize:=ThemeServices.GetDetailSize(DetailsBtn);
  82.     // adjust this for each OS, on windows looks fine
  83.     R1 := Rect(ClientWidth - BtnSize.Width, 1, ClientWidth, ClientHeight - 1);
  84.     R2 := Rect(r1.Left+1, r1.Top+1, r1.Right-2, r1.Bottom-1);
  85.     pr := @R2;
  86.     ThemeServices.DrawElement(Canvas.Handle, DetailsBtn, R1, pr);
  87.     {$ENDIF}
  88.     R.Right:=R.Right - BtnSize.Width;
  89.  
  90.     if FDisplayAll then
  91.       PaintDisplayValues(Canvas, R, TextMargin, @Details)
  92.     else
  93.     begin
  94.       if Assigned(FDataField) and FDataField.IsNull then
  95.         AText:=FEmptyValue
  96.       else
  97.       if FValuesList.Count > 0 then
  98.         AText:=FValuesList[FLookupDisplayIndex]
  99.       else
  100.         AText:='';
  101.       R.Left:=R.Left + TextMargin;
  102.       ThemeServices.DrawText(Canvas, Details, AText, R, DT_LEFT or DT_VCENTER or DT_SINGLELINE, 0);
  103.     end;
  104.   end
  105.   else
  106.   begin
  107.     Canvas.Font := Font;
  108.     Canvas.Brush.Color := Color;
  109.     Selected := Focused and (not (csPaintCopy in ControlState)) and  (not PopupVisible);
  110.     if Selected then
  111.     begin
  112.       Canvas.Font.Color := clHighlightText;
  113.       Canvas.Brush.Color := clHighlight;
  114.     end
  115.     else
  116.     if not Enabled {and NewStyleControls }then
  117.     begin
  118.       Canvas.Font.Color := clInactiveCaption;
  119.     end;
  120.  
  121.     if BorderStyle = bsNone then
  122.     begin
  123.       border := 3;
  124.       if Flat then
  125.       begin
  126.         Canvas.Frame3d(R, border, bvLowered);
  127.       end
  128.       else
  129.       begin
  130.         RxFrame3D(Canvas, R, clWindowFrame, clBtnHighlight, 1);
  131.         RxFrame3D(Canvas, R, clBtnShadow, clBtnFace, 1);
  132.       end;
  133.     end
  134.     else
  135.     begin
  136.       border := 1;
  137.     end;
  138.  
  139.     if ClientWidth > 2*border then
  140.     begin
  141.       R1 := Rect(border, border, ClientWidth - border, ClientHeight - border);
  142.       Canvas.FillRect(R1);
  143.       R.Right := R.Right - GetButtonWidth;
  144.       if PopupVisible and (Caption<>'') then
  145.       begin
  146.         AText := Caption;
  147.         Canvas.TextRect(R, TextMargin, Max(0, (HeightOf(R) - Canvas.TextHeight('Wg')) div 2), AText);
  148.       end
  149.       else
  150.       if FDisplayAll then
  151.         PaintDisplayValues(Canvas, R, TextMargin, nil)
  152.       else
  153.       begin
  154.         if Assigned(FDataField) and FDataField.IsNull then
  155.         begin
  156.           R1 := Rect(border + padding, border + padding, ClientWidth - (border + padding) - GetButtonWidth, ClientHeight - (border + padding));
  157.           Canvas.Brush.Color:=FEmptyItemColor;
  158.           Canvas.FillRect(R1);
  159.           AText:=FEmptyValue
  160.         end
  161.         else
  162.         if FValuesList.Count > 0 then
  163.           AText:=FValuesList[FLookupDisplayIndex]
  164.         else
  165.           AText:='';
  166.         Canvas.TextRect(R, TextMargin, Max(0, (HeightOf(R) - Canvas.TextHeight('Wg')) div 2), AText);
  167.       end
  168.     end;
  169.   end;
  170. end;

alexs75

  • Full Member
  • ***
  • Posts: 112
Re: TRxDBLookupCombo missing OnPaint event
« Reply #17 on: February 08, 2018, 12:09:41 pm »
hi
please - test revision 6188.
I modified your code - so it's easier to read it.

lainz

  • Hero Member
  • *****
  • Posts: 4449
    • https://lainz.github.io/
Re: TRxDBLookupCombo missing OnPaint event
« Reply #18 on: February 08, 2018, 01:57:10 pm »
hi
please - test revision 6188.
I modified your code - so it's easier to read it.

OK. I don't know where it's located.

You can upload the new version to OPM, is the way everyone is getting packages now.
http://forum.lazarus.freepascal.org/index.php/topic,34297.0.html

Edit: There is also a problem compiling on 1.8, maybe you can fix that too

I would update, but the same MouseInClient related error was introduced again, see @giuian post above. When you use MouseInClient, you need:
Quote
{$IF lcl_fullversion >= 1090000} 
  if MouseInClient then
{$ELSE}
  if MouseEntered then
Otherwise rx cannot be compiled in stable 1.8. You can download the latest version with a SVN client from here: https://svn.code.sf.net/p/lazarus-ccr/svn/components/rx/trunk
« Last Edit: February 08, 2018, 02:45:41 pm by lainz »

alexs75

  • Full Member
  • ***
  • Posts: 112
Re: TRxDBLookupCombo missing OnPaint event
« Reply #19 on: February 09, 2018, 07:18:59 am »
Quote
There is also a problem compiling on 1.8, maybe you can fix that too
fixed

lainz

  • Hero Member
  • *****
  • Posts: 4449
    • https://lainz.github.io/
Re: TRxDBLookupCombo missing OnPaint event
« Reply #20 on: February 09, 2018, 12:22:38 pm »
Quote
There is also a problem compiling on 1.8, maybe you can fix that too
fixed

Thanks  :)

 

TinyPortal © 2005-2018