From d42c10d9afd8204eb41e5caeb0e53c1e6f293cbc Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Tue, 11 Oct 2022 18:12:38 +0000 Subject: [PATCH] tvplanit: Fix double-click on monthview finding events in wrong month. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8535 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/tvplanit/source/vpmonthview.pas | 79 ++++++++-------------- 1 file changed, 28 insertions(+), 51 deletions(-) diff --git a/components/tvplanit/source/vpmonthview.pas b/components/tvplanit/source/vpmonthview.pas index 3fff9a1c3..9eb80aa39 100644 --- a/components/tvplanit/source/vpmonthview.pas +++ b/components/tvplanit/source/vpmonthview.pas @@ -94,39 +94,6 @@ type property Color default WEEKEND_COLOR; end; - (* - TVpMvHeadAttr = class(TPersistent) - protected{ private } - FOwner: TVpMonthView; - FColor: TColor; - FFont: TVpFont; - procedure SetColor(const Value: TColor); - procedure SetFont(Value: TVpFont); - public - constructor Create(AOwner: TVpMonthView); - destructor Destroy; override; - property Owner: TVpMonthView read FOwner; - published - property Font: TVpFont read FFont write SetFont; - property Color: TColor read FColor write SetColor; - end; - - TVpDayHeadAttr = class(TPersistent) - protected{private} - FMonthView: TVpMonthView; - FFont: TVpFont; - FColor: TColor; - procedure SetColor(Value: TColor); - procedure SetFont(Value: TVpFont); - public - constructor Create(AOwner: TVpMonthView); - destructor Destroy; override; - property MonthView: TVpMonthView read FMonthView; - published - property Color: TColor read FColor write SetColor; - property Font: TVpFont read FFont write SetFont; - end; - *) TVpMvTodayAttr = class(TVpMonthViewAttr) private FBorderPen: TPen; @@ -1385,40 +1352,50 @@ end; function TVpMonthView.SelectEventAtCoord(Point: TPoint): Boolean; var I: Integer; + y1, m1, d1: Word; + y2, m2, d2: Word; begin - result := false; + Result := false; + + DecodeDate(FDate, y1, m1, d1); I := 0; while I < Length(mvEventArray) do begin if mvEventArray[I].Event = nil then begin Inc(I); Break; end else begin - if (Point.X > mvEventArray[I].Rec.Left) - and (Point.X < mvEventArray[I].Rec.Right) - and (Point.Y > mvEventArray[I].Rec.Top) - and (Point.Y < mvEventArray[I].Rec.Bottom) then begin - result := true; - Break; - end else - Inc(I); + if PtInRect(mvEventArray[I].Rec, Point) then + begin + DecodeDate(TVpEvent(mvEventArray[I].Event).StartTime, y2, m2, d2); + if (y1 = y2) and (m1 = m2) then + begin + mvActiveEvent := TVpEvent(mvEventArray[I].Event); + mvActiveEventRec := mvEventArray[I].Rec; + Result := true; + Break; + end; + end; + Inc(I); end; end; - - if result then begin - mvActiveEvent := TVpEvent(mvEventArray[I].Event); - mvActiveEventRec := mvEventArray[I].Rec; - end; end; procedure TVpMonthView.mvSetDateByCoord(APoint: TPoint); var I: Integer; + d1, m1, y1: Word; + d2, m2, y2: Word; begin - for I := 0 to pred(Length(mvMonthdayArray)) do - if PointInRect(APoint, mvMonthdayArray[I].Rec) then + DecodeDate(FDate, y1, m1, d1); + for I := 0 to pred(Length(mvMonthDayArray)) do + if PointInRect(APoint, mvMonthDayArray[I].Rec) then begin - Date := mvMonthdayArray[I].Date; - break; + DecodeDate(mvMonthDayArray[I].Date, y2, m2, d2); + if (y1 = y2) and (m1 = m2) then + begin + Date := mvMonthdayArray[I].Date; + break; + end; end; end;