From 5502e43d530b712a1ba29b41e18c18d0a25e7d36 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Thu, 17 May 2018 21:21:16 +0000 Subject: [PATCH] tvplanit: Show category colors and icons in category combobox of event editor. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6432 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/tvplanit/source/vpconst.pas | 1 + components/tvplanit/source/vpevnteditdlg.lfm | 5 +- components/tvplanit/source/vpevnteditdlg.pas | 67 ++++++++++++++------ 3 files changed, 51 insertions(+), 22 deletions(-) diff --git a/components/tvplanit/source/vpconst.pas b/components/tvplanit/source/vpconst.pas index 1549a4d54..fdc24d982 100644 --- a/components/tvplanit/source/vpconst.pas +++ b/components/tvplanit/source/vpconst.pas @@ -284,6 +284,7 @@ const VL_LCL_SCALING := 0; {$ENDIF} + DROPDOWN_COUNT = 24; implementation diff --git a/components/tvplanit/source/vpevnteditdlg.lfm b/components/tvplanit/source/vpevnteditdlg.lfm index b088d16d2..19bf3c9cf 100644 --- a/components/tvplanit/source/vpevnteditdlg.lfm +++ b/components/tvplanit/source/vpevnteditdlg.lfm @@ -11,7 +11,7 @@ object DlgEventEdit: TDlgEventEdit OnCreate = FormCreate OnShow = FormShow Position = poScreenCenter - LCLVersion = '1.6.4.0' + LCLVersion = '1.9.0.0' object ButtonPanel: TPanel Left = 0 Height = 37 @@ -205,8 +205,9 @@ object DlgEventEdit: TDlgEventEdit Width = 253 Anchors = [akTop, akLeft, akRight] BorderSpacing.Top = 6 - ItemHeight = 15 + ItemHeight = 17 OnDrawItem = CategoryDrawItem + Style = csOwnerDrawFixed TabOrder = 2 end object imgClock: TImage diff --git a/components/tvplanit/source/vpevnteditdlg.pas b/components/tvplanit/source/vpevnteditdlg.pas index 297886ba2..0cd751293 100644 --- a/components/tvplanit/source/vpevnteditdlg.pas +++ b/components/tvplanit/source/vpevnteditdlg.pas @@ -252,6 +252,9 @@ begin LoadCaptions; EndDate.Enabled := False; EndTime.Enabled := false; + + Category.DropDownCount := DROPDOWN_COUNT; + Category.ItemHeight := LocationEdit.Height - 4; end; {=====} @@ -292,34 +295,58 @@ end; procedure TDlgEventEdit.CategoryDrawItem(Control: TWinControl; Index: Integer; ARect: TRect; State: TOwnerDrawState); var - Color, SaveColor: TColor; - Name: string; + lBkColor, lGutterColor, SavedColor: TColor; + lDesc: string; + lBmp: TBitmap; ColorRect: TRect; + IconX, IconY: Integer; + hTxt, hGutter, hDist, vMargin, hMargin: Integer; + SavedStyle: TBrushStyle; begin - Unused(Control, State); + Unused( State); + hTxt := Category.Canvas.TextHeight('Tj'); + vMargin := ScaleY(2, DesignTimeDPI); + hMargin := ScaleX(3, DesignTimeDPI); + hGutter := ScaleX(10, DesignTimeDPI); + hDist := ScaleX(5, DesignTimeDPI); + + with CatColorMap.GetCategory(Index) do begin + lGutterColor := Color; + lDesc := Description; + lBmp := Bitmap; + lBkColor := BackgroundColor; + end; + + SavedColor := Category.Canvas.Brush.Color; + SavedStyle := Category.Canvas.Brush.Style; + + if State * [odSelected, odFocused] = [] then + Category.Canvas.Brush.Color := lBkColor; Category.Canvas.FillRect(ARect); - Color := CatColorMap.GetCategory(Index).Color; - Name := CatColorMap.GetCategory(Index).Description; - - SaveColor := Category.Canvas.Brush.Color; - Category.Canvas.Brush.Color := Color; + Category.Canvas.Brush.Color := lGutterColor; Category.Canvas.Pen.Color := clBlack; - ColorRect.Left := ARect.Left + 3; - ColorRect.Top := ARect.Top + 2; - ColorRect.Bottom := ARect.Bottom - 2; - ColorRect.Right := ColorRect.Left + 20; + ColorRect.Left := ARect.Left + hMargin; + ColorRect.Top := ARect.Top + vMargin; + ColorRect.Bottom := ARect.Bottom - vMargin; + ColorRect.Right := ColorRect.Left + hGutter; Category.Canvas.FillRect(ColorRect); - {$IFDEF VERSION5} Category.Canvas.Rectangle(ColorRect); - {$ELSE} - Category.Canvas.Rectangle(ColorRect.Left, ColorRect.Top, ColorRect.Right, - ColorRect.Bottom); - {$ENDIF} - ARect.Left := ColorRect.Right + 5; - Category.Canvas.Brush.Color := SaveColor; - Category.Canvas.TextOut(ARect.Left, ARect.Top, Name); + + if lBmp <> nil then begin + IconX := ColorRect.Right + hMargin; + IconY := (ARect.Top + ARect.Bottom - lBmp.Height) div 2; + Category.Canvas.Draw(IconX, IconY, lBmp); + inc(ColorRect.Right, lBmp.Width); + end; + + ARect.Left := ColorRect.Right + hDist; + Category.Canvas.Brush.Style := bsClear; + Category.Canvas.TextOut(ARect.Left, (ARect.Top + ARect.Bottom - hTxt) div 2, lDesc); + + Category.Canvas.Brush.Color := SavedColor; + Category.canvas.Brush.Style := SavedStyle; end; procedure TDlgEventEdit.CancelBtnClick(Sender: TObject);