2008-02-03 12:05:55 +00:00
|
|
|
{*********************************************************}
|
|
|
|
{* VPWEEKVIEW.PAS 1.03 *}
|
|
|
|
{*********************************************************}
|
|
|
|
|
|
|
|
{* ***** BEGIN LICENSE BLOCK ***** *}
|
|
|
|
{* Version: MPL 1.1 *}
|
|
|
|
{* *}
|
|
|
|
{* The contents of this file are subject to the Mozilla Public License *}
|
|
|
|
{* Version 1.1 (the "License"); you may not use this file except in *}
|
|
|
|
{* compliance with the License. You may obtain a copy of the License at *}
|
|
|
|
{* http://www.mozilla.org/MPL/ *}
|
|
|
|
{* *}
|
|
|
|
{* Software distributed under the License is distributed on an "AS IS" basis, *}
|
|
|
|
{* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License *}
|
|
|
|
{* for the specific language governing rights and limitations under the *}
|
|
|
|
{* License. *}
|
|
|
|
{* *}
|
|
|
|
{* The Original Code is TurboPower Visual PlanIt *}
|
|
|
|
{* *}
|
|
|
|
{* The Initial Developer of the Original Code is TurboPower Software *}
|
|
|
|
{* *}
|
|
|
|
{* Portions created by TurboPower Software Inc. are Copyright (C) 2002 *}
|
|
|
|
{* TurboPower Software Inc. All Rights Reserved. *}
|
|
|
|
{* *}
|
|
|
|
{* Contributor(s): *}
|
|
|
|
{* *}
|
|
|
|
{* ***** END LICENSE BLOCK ***** *}
|
|
|
|
|
|
|
|
{
|
|
|
|
This unit handles the TVpWeekView component as well as it's inline editor
|
|
|
|
and navigation.
|
|
|
|
|
|
|
|
The rendering of Visual PlanIt components is a bit involved. The component's
|
|
|
|
Paint method calls RenderToCanvas. The RenderToCanvas method of each of
|
|
|
|
the visual VisualPlanIt controls is repsonsible both for drawing to the
|
|
|
|
screen (both design and run time) as well as printing. In the case of
|
|
|
|
printing, the component needs to render itself to an arbitrary rectangle
|
|
|
|
and possibly rotated (for the screen the rectangle is the ClientRect
|
|
|
|
and the rotation angle is always zero). To achieve that goal, the
|
|
|
|
functions in VpCanvasUtils are used to go between the rendering of the
|
|
|
|
control and the TCanvas that it needs to render to.
|
|
|
|
}
|
2021-10-27 18:12:33 +00:00
|
|
|
|
2008-02-03 12:05:55 +00:00
|
|
|
|
|
|
|
unit VpWeekView;
|
|
|
|
|
2021-10-27 18:12:33 +00:00
|
|
|
{$I vp.inc}
|
|
|
|
|
|
|
|
{$IF FPC_FullVersion >= 30200}
|
|
|
|
{$WARN 6058 off : Call to subroutine "$1" marked as inline is not inlined}
|
|
|
|
{$IFEND}
|
|
|
|
|
|
|
|
|
2008-02-03 12:05:55 +00:00
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
{$IFDEF LCL}
|
2016-06-22 07:59:17 +00:00
|
|
|
LMessages, LCLProc, LCLType, LCLIntf, FileUtil,
|
2008-02-03 12:05:55 +00:00
|
|
|
{$ELSE}
|
2016-06-22 07:59:17 +00:00
|
|
|
Windows, Messages,
|
2008-02-03 12:05:55 +00:00
|
|
|
{$ENDIF}
|
2016-11-21 17:12:05 +00:00
|
|
|
Classes, Graphics, Controls, ComCtrls, ExtCtrls, StdCtrls, Forms, Menus,
|
2017-05-22 08:11:27 +00:00
|
|
|
VpConst, VpBase, VpBaseDS, VpMisc, VpData, VpSR, VpCanvasUtils, VpDayView;
|
2008-02-03 12:05:55 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
TVpWeekdayRec = packed record
|
2016-06-18 21:03:53 +00:00
|
|
|
Rec: TRect;
|
|
|
|
Day: TDateTime;
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
|
2016-09-23 11:40:39 +00:00
|
|
|
TVpWeekViewLayout = (wvlVertical, wvlHorizontal);
|
|
|
|
|
2008-02-03 12:05:55 +00:00
|
|
|
type
|
|
|
|
TVpWeekdayArray = array of TVpWeekdayRec;
|
|
|
|
|
|
|
|
{ Forward Declarations }
|
|
|
|
TVpWeekView = class;
|
|
|
|
|
|
|
|
TVpWvInPlaceEdit = class(TCustomEdit)
|
|
|
|
protected{private}
|
|
|
|
procedure CreateParams(var Params: TCreateParams); override;
|
|
|
|
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
|
|
|
|
public
|
|
|
|
constructor Create(AOwner: TComponent); override;
|
|
|
|
end;
|
|
|
|
|
|
|
|
TVpWvHeadAttributes = class(TPersistent)
|
|
|
|
protected{ private }
|
|
|
|
FOwner: TVpWeekView;
|
|
|
|
FColor: TColor;
|
|
|
|
FFont: TVpFont;
|
|
|
|
procedure SetColor(const Value: TColor);
|
|
|
|
procedure SetFont(Value: TVpFont);
|
|
|
|
public
|
|
|
|
constructor Create(AOwner: TVpWeekView);
|
|
|
|
destructor Destroy; override;
|
|
|
|
property Owner: TVpWeekView read FOwner;
|
|
|
|
published
|
|
|
|
property Font: TVpFont read FFont write SetFont;
|
|
|
|
property Color: TColor read FColor write SetColor;
|
|
|
|
end;
|
|
|
|
|
|
|
|
TVpDayHeadAttr = class(TPersistent)
|
|
|
|
protected{private}
|
|
|
|
FWeekView: TVpWeekView;
|
2016-07-15 11:52:21 +00:00
|
|
|
FFont: TVpFont;
|
2008-02-03 12:05:55 +00:00
|
|
|
FDateFormat: string;
|
|
|
|
FColor: TColor;
|
|
|
|
FBordered: Boolean;
|
2022-07-25 22:55:31 +00:00
|
|
|
function IsStoredDateFormat: Boolean;
|
2016-06-18 21:03:53 +00:00
|
|
|
procedure SetColor(Value: TColor);
|
2016-07-15 11:52:21 +00:00
|
|
|
procedure SetFont(Value: TVpFont);
|
2016-06-18 21:03:53 +00:00
|
|
|
procedure SetBordered(Value: Boolean);
|
2008-02-03 12:05:55 +00:00
|
|
|
procedure SetDateFormat(Value: string);
|
|
|
|
public
|
|
|
|
constructor Create(AOwner: TVpWeekView);
|
|
|
|
destructor Destroy; override;
|
|
|
|
property WeekView: TVpWeekView read FWeekView;
|
|
|
|
published
|
2022-07-25 22:55:31 +00:00
|
|
|
property Color: TColor read FColor write SetColor default DEFAULT_COLOR;
|
|
|
|
property DateFormat: string read FDateFormat write SetDateFormat stored IsStoredDateFormat;
|
2016-07-15 11:52:21 +00:00
|
|
|
property Font: TVpFont read FFont write SetFont;
|
2022-07-25 22:55:31 +00:00
|
|
|
property Bordered: Boolean read FBordered write SetBordered default true;
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
|
2008-11-10 13:54:49 +00:00
|
|
|
{ TVpWeekView }
|
|
|
|
|
2008-02-03 12:05:55 +00:00
|
|
|
TVpWeekView = class(TVpLinkableControl)
|
2012-09-24 19:30:17 +00:00
|
|
|
private
|
2017-05-25 21:24:23 +00:00
|
|
|
FComponentHint: TTranslateString;
|
2016-09-12 22:25:34 +00:00
|
|
|
FHintMode: TVpHintMode;
|
|
|
|
FMouseEvent: TVpEvent;
|
2016-09-23 11:40:39 +00:00
|
|
|
FLayout: TVpWeekviewLayout;
|
2016-09-22 23:12:16 +00:00
|
|
|
FOnHoliday: TVpHolidayEvent;
|
2022-07-25 22:55:31 +00:00
|
|
|
function IsStoredDateLabelFormat: Boolean;
|
2012-09-24 19:30:17 +00:00
|
|
|
procedure SetActiveEvent(AValue: TVpEvent);
|
2022-07-12 14:31:42 +00:00
|
|
|
procedure SetApplyCategoryInfos(AValue: Boolean);
|
2016-09-23 11:40:39 +00:00
|
|
|
procedure SetLayout(AValue: TVpWeekviewLayout);
|
2008-02-03 12:05:55 +00:00
|
|
|
protected{ private }
|
2016-06-18 21:03:53 +00:00
|
|
|
FActiveDate: TDateTime;
|
|
|
|
FColumnWidth: Integer;
|
|
|
|
FColor: TColor;
|
|
|
|
FDateLabelFormat: string;
|
|
|
|
FDayHeadAttributes: TVpDayHeadAttr;
|
|
|
|
FDrawingStyle: TVpDrawingStyle;
|
2016-09-03 21:51:37 +00:00
|
|
|
FActiveEvent: TVpEvent;
|
2016-06-18 21:03:53 +00:00
|
|
|
FHeadAttr: TVpWvHeadAttributes;
|
2016-07-15 11:52:21 +00:00
|
|
|
FEventFont: TVpFont; // was: TFont
|
2016-06-18 21:03:53 +00:00
|
|
|
FLineColor: TColor;
|
|
|
|
FLineCount: Integer;
|
|
|
|
FTimeFormat: TVpTimeFormat;
|
|
|
|
FShowEventTime: Boolean;
|
|
|
|
FVisibleLines: Integer;
|
|
|
|
FWeekStartsOn: TVpDayType;
|
|
|
|
FDefaultPopup: TPopupMenu;
|
|
|
|
FAllDayEventAttr: TVpAllDayEventAttributes;
|
2016-06-23 23:16:34 +00:00
|
|
|
FAllowInplaceEdit: Boolean;
|
2016-09-03 17:41:24 +00:00
|
|
|
FAllowDragAndDrop: Boolean;
|
2022-07-12 14:31:42 +00:00
|
|
|
FApplyCategoryInfos: Boolean;
|
2016-09-03 21:51:37 +00:00
|
|
|
FDragDropTransparent: Boolean;
|
2008-02-03 12:05:55 +00:00
|
|
|
{ event variables }
|
2016-06-18 21:03:53 +00:00
|
|
|
FBeforeEdit: TVpBeforeEditEvent;
|
|
|
|
FAfterEdit: TVpAfterEditEvent;
|
|
|
|
FOwnerEditEvent: TVpEditEvent;
|
|
|
|
FOnAddEvent: TVpOnAddNewEvent;
|
2022-06-12 16:12:31 +00:00
|
|
|
FOnModifyEvent: TVpOnModifyEvent;
|
2022-08-05 11:01:59 +00:00
|
|
|
FOnDeletingEvent: TVpOnDeletingEvent;
|
2008-02-03 12:05:55 +00:00
|
|
|
{ internal variables }
|
2016-06-18 21:03:53 +00:00
|
|
|
wvInLinkHandler: Boolean;
|
|
|
|
wvClickTimer: TTimer;
|
|
|
|
wvLoaded: Boolean;
|
|
|
|
wvRowHeight: Integer;
|
2016-07-15 12:29:06 +00:00
|
|
|
// wvDayHeadHeight: Integer;
|
2016-06-18 21:03:53 +00:00
|
|
|
wvHeaderHeight: Integer;
|
|
|
|
wvStartDate: TDateTime;
|
|
|
|
wvSpinButtons: TUpDown;
|
|
|
|
wvEventList: TList;
|
|
|
|
wvEventArray: TVpEventArray;
|
|
|
|
wvWeekdayArray: TVpWeekdayArray;
|
|
|
|
wvActiveEventRec: TRect;
|
|
|
|
wvInPlaceEditor: TVpWvInPlaceEdit;
|
|
|
|
wvCreatingEditor: Boolean;
|
|
|
|
wvPainting: Boolean;
|
2016-09-03 21:51:37 +00:00
|
|
|
wvDragging: Boolean;
|
|
|
|
wvMouseDown: Boolean;
|
|
|
|
wvMouseDownPoint: TPoint;
|
2016-06-18 21:03:53 +00:00
|
|
|
wvHotPoint: TPoint;
|
2008-02-03 12:05:55 +00:00
|
|
|
|
|
|
|
{ property methods }
|
|
|
|
procedure SetDrawingStyle(Value: TVpDrawingStyle);
|
2021-10-27 18:12:33 +00:00
|
|
|
procedure SetColor(Value: TColor); reintroduce;
|
2008-02-03 12:05:55 +00:00
|
|
|
procedure SetLineColor(Value: TColor);
|
|
|
|
procedure SetDateLabelFormat(Value: string);
|
2016-07-15 11:52:21 +00:00
|
|
|
procedure SetEventFont(Value: TVpFont);
|
2008-02-03 12:05:55 +00:00
|
|
|
procedure SetShowEventTime(Value: Boolean);
|
|
|
|
procedure SetTimeFormat(Value: TVpTimeFormat);
|
|
|
|
procedure SetActiveDate(Value: TDateTime);
|
|
|
|
procedure SetWeekStartsOn(Value: TVpDayType);
|
2016-09-03 17:41:24 +00:00
|
|
|
|
2018-06-20 20:56:27 +00:00
|
|
|
{ Popup }
|
2016-06-18 21:03:53 +00:00
|
|
|
procedure PopupAddEvent(Sender: TObject);
|
2018-06-16 16:24:11 +00:00
|
|
|
procedure PopupAddFromICalFile(Sender: TObject);
|
2016-06-18 21:03:53 +00:00
|
|
|
procedure PopupDeleteEvent(Sender: TObject);
|
|
|
|
procedure PopupEditEvent(Sender: TObject);
|
|
|
|
procedure PopupToday(Sender: TObject);
|
|
|
|
procedure PopupNextWeek(Sender: TObject);
|
|
|
|
procedure PopupPrevWeek(Sender: TObject);
|
|
|
|
procedure PopupNextMonth(Sender: TObject);
|
|
|
|
procedure PopupPrevMonth(Sender: TObject);
|
|
|
|
procedure PopupNextYear(Sender: TObject);
|
|
|
|
procedure PopupPrevYear(Sender: TObject);
|
2022-07-11 22:59:40 +00:00
|
|
|
procedure PopupCustomDate(Sender: TObject);
|
2016-09-10 17:26:42 +00:00
|
|
|
procedure PopupPickResourceGroupEvent(Sender: TObject);
|
|
|
|
procedure PopupDropdownEvent(Sender: TObject);
|
2008-02-03 12:05:55 +00:00
|
|
|
procedure InitializeDefaultPopup;
|
2018-06-20 20:56:27 +00:00
|
|
|
|
|
|
|
{ internal methods }
|
|
|
|
procedure wvEditInPlace(Sender: TObject);
|
|
|
|
procedure wvHookUp;
|
2008-02-03 12:05:55 +00:00
|
|
|
procedure wvPopulate;
|
|
|
|
procedure wvSpinButtonClick(Sender: TObject; Button: TUDBtnType);
|
2017-08-02 21:10:14 +00:00
|
|
|
|
|
|
|
{ event related methods }
|
|
|
|
procedure EditEvent;
|
|
|
|
procedure EndEdit(Sender: TObject);
|
2008-02-03 12:05:55 +00:00
|
|
|
function EventAtCoord(Pt: TPoint): Boolean;
|
2016-09-11 17:53:51 +00:00
|
|
|
function GetEventAtCoord(Pt: TPoint): TVpEvent;
|
|
|
|
function GetEventRect(AEvent: TVpEvent): TRect;
|
2008-02-03 12:05:55 +00:00
|
|
|
procedure wvSetDateByCoord(Point: TPoint);
|
2018-05-17 16:35:44 +00:00
|
|
|
procedure wvSpawnEventEditDialog(IsNewEvent: Boolean);
|
2017-08-02 21:10:14 +00:00
|
|
|
|
|
|
|
{ inherited standard methods }
|
|
|
|
procedure CreateParams(var Params: TCreateParams); override;
|
|
|
|
procedure CreateWnd; override;
|
|
|
|
procedure Loaded; override;
|
2008-02-03 12:05:55 +00:00
|
|
|
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
|
2018-06-20 20:56:27 +00:00
|
|
|
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X,Y: Integer); override;
|
2016-09-12 22:25:34 +00:00
|
|
|
procedure MouseEnter; override;
|
|
|
|
procedure MouseLeave; override;
|
2016-09-03 21:51:37 +00:00
|
|
|
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
|
|
|
|
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X,Y: Integer); override;
|
2017-08-02 21:10:14 +00:00
|
|
|
procedure Paint; override;
|
2016-09-03 17:41:24 +00:00
|
|
|
|
|
|
|
{ drag and drop }
|
|
|
|
procedure DoEndDrag(Target: TObject; X, Y: Integer); override;
|
2016-09-03 21:51:37 +00:00
|
|
|
procedure DoStartDrag(var DragObject: TDragObject); override;
|
2016-09-03 17:41:24 +00:00
|
|
|
procedure DragOver(Source: TObject; X, Y: Integer; State: TDragState;
|
|
|
|
var Accept: Boolean); override;
|
|
|
|
|
2016-09-11 17:53:51 +00:00
|
|
|
{ hints }
|
|
|
|
procedure ShowHintWindow(APoint: TPoint; AEvent: TVpEvent);
|
|
|
|
procedure HideHintWindow;
|
2017-05-25 21:24:23 +00:00
|
|
|
procedure SetHint(const AValue: TTranslateString); override;
|
2016-09-11 17:53:51 +00:00
|
|
|
|
2008-02-03 12:05:55 +00:00
|
|
|
{ message handlers }
|
|
|
|
{$IFNDEF LCL}
|
|
|
|
procedure WMSize(var Msg: TWMSize); message WM_SIZE;
|
|
|
|
procedure WMRButtonDown(var Msg : TWMRButtonDown); message WM_RBUTTONDOWN;
|
|
|
|
procedure CMWantSpecialKey(var Msg: TCMWantSpecialKey);
|
|
|
|
message CM_WANTSPECIALKEY;
|
|
|
|
{$ELSE}
|
|
|
|
procedure WMSize(var Msg: TLMSize); message LM_SIZE;
|
|
|
|
procedure WMLButtonDblClk(var Msg : TLMLButtonDblClk); message LM_LBUTTONDBLCLK;
|
2012-09-24 19:30:17 +00:00
|
|
|
//TODO: Bug 0020755 braks this in GTK2...
|
2008-02-03 12:05:55 +00:00
|
|
|
{$ENDIF}
|
2016-06-18 21:03:53 +00:00
|
|
|
|
2008-02-03 12:05:55 +00:00
|
|
|
public
|
|
|
|
constructor Create(AOwner: TComponent); override;
|
|
|
|
destructor Destroy; override;
|
2016-09-12 22:25:34 +00:00
|
|
|
function BuildEventString(AEvent: TVpEvent; AStartTime, AEndTime: TDateTime;
|
|
|
|
UseAsHint: Boolean): String;
|
2008-11-10 13:54:49 +00:00
|
|
|
procedure LoadLanguage;
|
2008-02-03 12:05:55 +00:00
|
|
|
procedure DeleteActiveEvent(Verify: Boolean);
|
2016-09-03 17:41:24 +00:00
|
|
|
procedure DragDrop(Source: TObject; X, Y: Integer); override;
|
2022-08-10 10:20:56 +00:00
|
|
|
function ImportICalFile(const AFileName: String; APreview: Boolean = false;
|
|
|
|
ADefaultCategory: Integer = -1): TVpEventArr;
|
2008-02-03 12:05:55 +00:00
|
|
|
procedure Invalidate; override;
|
2016-09-22 23:12:16 +00:00
|
|
|
function IsHoliday(ADate: TDate; out AHolidayName: String): Boolean;
|
2008-02-03 12:05:55 +00:00
|
|
|
procedure LinkHandler(Sender: TComponent;
|
2016-06-18 21:03:53 +00:00
|
|
|
NotificationType: TVpNotificationType; const Value: Variant); override;
|
|
|
|
function GetControlType: TVpItemType; override;
|
2018-06-12 16:40:51 +00:00
|
|
|
procedure EditSelectedEvent(IsNewEvent: Boolean = false);
|
2016-06-18 21:03:53 +00:00
|
|
|
procedure PaintToCanvas(ACanvas: TCanvas; ARect: TRect;
|
|
|
|
Angle: TVpRotationAngle; ADate: TDateTime);
|
|
|
|
procedure RenderToCanvas(RenderCanvas: TCanvas; RenderIn: TRect;
|
|
|
|
Angle: TVpRotationAngle; Scale: Extended; RenderDate: TDateTime;
|
|
|
|
StartLine: Integer; StopLine: Integer; UseGran: TVpGranularity;
|
|
|
|
DisplayOnly: Boolean); override;
|
2016-09-03 17:41:24 +00:00
|
|
|
|
2018-01-12 12:42:12 +00:00
|
|
|
{$IF VP_LCL_SCALING = 2}
|
|
|
|
procedure ScaleFontsPPI(const AToPPI: Integer; const AProportion: Double); override;
|
|
|
|
{$ELSEIF VP_LCL_SCALING = 1}
|
|
|
|
procedure ScaleFontsPPI(const AProportion: Double); override;
|
|
|
|
{$ENDIF}
|
|
|
|
|
2016-09-03 21:51:37 +00:00
|
|
|
property ActiveEvent: TVpEvent read FActiveEvent write SetActiveEvent;
|
2008-02-03 12:05:55 +00:00
|
|
|
property Date: TDateTime read FActiveDate write SetActiveDate;
|
|
|
|
property VisibleLines: Integer read FVisibleLines;
|
2016-06-18 21:03:53 +00:00
|
|
|
|
2008-02-03 12:05:55 +00:00
|
|
|
published
|
2016-06-23 23:16:34 +00:00
|
|
|
property AllDayEventAttributes: TVpAllDayEventAttributes read FAllDayEventAttr write FAllDayEventAttr;
|
2016-09-03 17:41:24 +00:00
|
|
|
property AllowDragAndDrop: Boolean read FAllowDragAndDrop write FAllowDragAndDrop default false;
|
2016-06-23 23:16:34 +00:00
|
|
|
property AllowInplaceEditing: Boolean read FAllowInplaceEdit write FAllowInplaceEdit default true;
|
2022-07-12 14:31:42 +00:00
|
|
|
property ApplyCategoryInfos: Boolean read FApplyCategoryInfos write SetApplyCategoryInfos default false;
|
2022-07-25 22:55:31 +00:00
|
|
|
property Color: TColor read FColor write SetColor default DEFAULT_COLOR;
|
|
|
|
property DateLabelFormat: string read FDateLabelFormat write SetDateLabelFormat stored IsStoredDateLabelFormat;
|
2016-06-18 21:03:53 +00:00
|
|
|
property DayHeadAttributes: TVpDayHeadAttr read FDayHeadAttributes write FDayHeadAttributes;
|
2016-09-03 21:51:37 +00:00
|
|
|
property DragDropTransparent: Boolean read FDragDropTransparent write FDragDropTransparent default false;
|
2022-07-25 22:55:31 +00:00
|
|
|
property DrawingStyle: TVpDrawingStyle read FDrawingStyle write SetDrawingStyle default ds3d;
|
2016-07-15 11:52:21 +00:00
|
|
|
property EventFont: TVpFont read FEventFont write SetEventFont;
|
2016-06-18 21:03:53 +00:00
|
|
|
property HeadAttributes: TVpWvHeadAttributes read FHeadAttr write FHeadAttr;
|
2016-09-19 22:58:13 +00:00
|
|
|
property HintMode: TVpHintMode read FHintMode write FHintMode default hmPlannerHint;
|
2022-07-25 22:55:31 +00:00
|
|
|
property LineColor: TColor read FLineColor write SetLineColor default DEFAULT_LINECOLOR;
|
2016-09-23 11:40:39 +00:00
|
|
|
property Layout: TVpWeekviewLayout read FLayout write SetLayout default wvlVertical;
|
2022-07-25 22:55:31 +00:00
|
|
|
property TimeFormat: TVpTimeFormat read FTimeFormat write SetTimeFormat default tf12Hour;
|
|
|
|
property ShowEventTime: Boolean read FShowEventTime write SetShowEventTime default true;
|
|
|
|
property WeekStartsOn: TVpDayType read FWeekStartsOn write SetWeekStartsOn default dtSunday;
|
2016-06-18 21:03:53 +00:00
|
|
|
|
2008-02-03 12:05:55 +00:00
|
|
|
{inherited properties}
|
|
|
|
property Align;
|
|
|
|
property Anchors;
|
2018-05-18 07:43:44 +00:00
|
|
|
{$IFDEF LCL}
|
|
|
|
property BorderSpacing;
|
|
|
|
{$ENDIF}
|
2022-07-25 22:55:31 +00:00
|
|
|
property TabStop default true;
|
2008-02-03 12:05:55 +00:00
|
|
|
property TabOrder;
|
|
|
|
|
|
|
|
{events}
|
2016-06-18 21:03:53 +00:00
|
|
|
property AfterEdit : TVpAfterEditEvent read FAfterEdit write FAfterEdit;
|
|
|
|
property BeforeEdit: TVpBeforeEditEvent read FBeforeEdit write FBeforeEdit;
|
|
|
|
property OnAddEvent: TVpOnAddNewEvent read FOnAddEvent write FOnAddEvent;
|
2022-08-05 11:01:59 +00:00
|
|
|
property OnDeletingEvent: TVpOnDeletingEvent read FOnDeletingEvent write FOnDeletingEvent;
|
2016-09-22 23:12:16 +00:00
|
|
|
property OnHoliday: TVpHolidayEvent read FOnHoliday write FOnHoliday;
|
2022-06-12 16:12:31 +00:00
|
|
|
property OnModifyEvent: TVpOnModifyEvent read FOnModifyEvent write FOnModifyEvent;
|
2016-06-18 21:03:53 +00:00
|
|
|
property OnOwnerEditEvent: TVpEditEvent read FOwnerEditEvent write FOwnerEditEvent;
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
|
2016-07-05 10:20:36 +00:00
|
|
|
|
2008-02-03 12:05:55 +00:00
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
2016-09-17 15:48:39 +00:00
|
|
|
{$IFDEF LCL}
|
|
|
|
DateUtils,
|
|
|
|
{$ENDIF}
|
2016-09-11 23:08:34 +00:00
|
|
|
SysUtils, StrUtils, LazUTF8, Dialogs,
|
2022-08-05 20:12:52 +00:00
|
|
|
VpEvntEditDlg, VpWeekViewPainter;
|
2016-09-11 23:08:34 +00:00
|
|
|
|
2008-02-03 12:05:55 +00:00
|
|
|
(*****************************************************************************)
|
|
|
|
{ TVpTGInPlaceEdit }
|
2016-09-11 23:08:34 +00:00
|
|
|
(*****************************************************************************)
|
2008-02-03 12:05:55 +00:00
|
|
|
|
|
|
|
constructor TVpWvInPlaceEdit.Create(AOwner: TComponent);
|
|
|
|
begin
|
|
|
|
inherited Create(AOwner);
|
|
|
|
TabStop := False;
|
|
|
|
BorderStyle := bsNone;
|
|
|
|
{$IFDEF VERSION4}
|
2018-06-04 10:36:57 +00:00
|
|
|
// DoubleBuffered := False;
|
2008-02-03 12:05:55 +00:00
|
|
|
{$ENDIF}
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
|
|
|
procedure TVpWvInPlaceEdit.CreateParams(var Params: TCreateParams);
|
|
|
|
begin
|
|
|
|
inherited CreateParams(Params);
|
2009-12-24 22:41:52 +00:00
|
|
|
// Params.Style := Params.Style or ES_MULTILINE;
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
|
|
|
procedure TVpWvInPlaceEdit.KeyDown(var Key: Word; Shift: TShiftState);
|
|
|
|
var
|
2016-06-18 21:03:53 +00:00
|
|
|
Grid: TVpWeekView;
|
2008-02-03 12:05:55 +00:00
|
|
|
begin
|
|
|
|
Grid := TVpWeekView(Owner);
|
|
|
|
|
|
|
|
case Key of
|
2016-06-18 21:03:53 +00:00
|
|
|
VK_RETURN:
|
|
|
|
begin
|
|
|
|
Key := 0;
|
|
|
|
Grid.EndEdit(Self);
|
|
|
|
end;
|
2008-02-03 12:05:55 +00:00
|
|
|
|
2016-06-18 21:03:53 +00:00
|
|
|
VK_UP:
|
|
|
|
begin
|
|
|
|
Key := 0;
|
|
|
|
Grid.EndEdit(Self);
|
|
|
|
end;
|
2008-02-03 12:05:55 +00:00
|
|
|
|
2016-06-18 21:03:53 +00:00
|
|
|
VK_DOWN:
|
|
|
|
begin
|
|
|
|
Key := 0;
|
|
|
|
Grid.EndEdit(Self);
|
|
|
|
end;
|
2008-02-03 12:05:55 +00:00
|
|
|
|
2016-06-18 21:03:53 +00:00
|
|
|
VK_ESCAPE:
|
|
|
|
begin
|
|
|
|
Key := 0;
|
2018-06-09 11:42:09 +00:00
|
|
|
Hide;
|
|
|
|
Grid.SetFocus;
|
2016-06-18 21:03:53 +00:00
|
|
|
end;
|
2008-02-03 12:05:55 +00:00
|
|
|
|
|
|
|
else
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
end;
|
2022-07-25 22:55:31 +00:00
|
|
|
|
2008-02-03 12:05:55 +00:00
|
|
|
|
|
|
|
(*****************************************************************************)
|
|
|
|
{ TVpContactHeadAttr }
|
|
|
|
constructor TVpDayHeadAttr.Create(AOwner: TVpWeekView);
|
|
|
|
begin
|
|
|
|
inherited Create;
|
|
|
|
FWeekView := AOwner;
|
2022-07-25 22:55:31 +00:00
|
|
|
FDateFormat := 'ddddd';
|
2016-07-15 11:52:21 +00:00
|
|
|
FFont := TVpFont.Create(AOwner);
|
2022-07-25 22:55:31 +00:00
|
|
|
FColor := DEFAULT_COLOR;
|
2008-02-03 12:05:55 +00:00
|
|
|
FBordered := true;
|
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TVpDayHeadAttr.Destroy;
|
|
|
|
begin
|
|
|
|
FFont.Free;
|
|
|
|
end;
|
2022-07-25 22:55:31 +00:00
|
|
|
|
|
|
|
function TVpDayHeadAttr.IsStoredDateFormat: Boolean;
|
|
|
|
begin
|
|
|
|
Result := FDateFormat = 'ddddd';
|
|
|
|
end;
|
2008-02-03 12:05:55 +00:00
|
|
|
|
|
|
|
procedure TVpDayHeadAttr.SetBordered(Value: Boolean);
|
|
|
|
begin
|
|
|
|
if Value <> FBordered then begin
|
|
|
|
FBordered := Value;
|
|
|
|
WeekView.Invalidate;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TVpDayHeadAttr.SetDateFormat(Value: string);
|
|
|
|
begin
|
|
|
|
if Value <> FDateFormat then begin
|
|
|
|
FDateFormat := Value;
|
|
|
|
WeekView.Invalidate;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TVpDayHeadAttr.SetColor(Value: TColor);
|
|
|
|
begin
|
|
|
|
if Value <> FColor then begin
|
|
|
|
FColor := Value;
|
|
|
|
WeekView.Invalidate;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2016-07-15 11:52:21 +00:00
|
|
|
procedure TVpDayHeadAttr.SetFont(Value: TVpFont);
|
2008-02-03 12:05:55 +00:00
|
|
|
begin
|
|
|
|
if Value <> FFont then begin
|
|
|
|
FFont.Assign(Value);
|
|
|
|
WeekView.Invalidate;
|
|
|
|
end;
|
|
|
|
end;
|
2022-07-25 22:55:31 +00:00
|
|
|
|
2008-02-03 12:05:55 +00:00
|
|
|
|
|
|
|
(*****************************************************************************)
|
|
|
|
{ TVpWeekView }
|
|
|
|
|
|
|
|
constructor TVpWeekView.Create(AOwner: TComponent);
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
ControlStyle := [csCaptureMouse, csOpaque, csDoubleClicks];
|
2017-05-25 21:24:23 +00:00
|
|
|
HintWindowClass := TVpHintWindow;
|
2008-02-03 12:05:55 +00:00
|
|
|
|
|
|
|
{ Create internal classes and stuff }
|
|
|
|
FDayHeadAttributes := TVpDayHeadAttr.Create(self);
|
|
|
|
FHeadAttr := TVpWvHeadAttributes.Create(self);
|
2016-07-05 08:42:08 +00:00
|
|
|
FAllDayEventAttr := TVpAllDayEventAttributes.Create(self);
|
2008-02-03 12:05:55 +00:00
|
|
|
|
2016-07-15 11:52:21 +00:00
|
|
|
FEventFont := TVpFont.Create(self);
|
2008-02-03 12:05:55 +00:00
|
|
|
FEventFont.Assign(Font);
|
|
|
|
FShowEventTime := true;
|
|
|
|
wvInLinkHandler := false;
|
|
|
|
wvEventList := TList.Create;
|
|
|
|
wvClickTimer := TTimer.Create(self);
|
|
|
|
wvSpinButtons := TUpDown.Create(self);
|
|
|
|
wvSpinButtons.OnClick := wvSpinButtonClick;
|
|
|
|
wvSpinButtons.Orientation := udHorizontal;
|
|
|
|
wvSpinButtons.Min := -32768;
|
|
|
|
wvSpinButtons.Max := 32767;
|
|
|
|
wvHotPoint := Point(0, 0);
|
2016-09-03 21:51:37 +00:00
|
|
|
wvDragging := false;
|
|
|
|
wvMouseDownPoint := Point(0, 0);
|
|
|
|
wvMouseDown := false;
|
|
|
|
DragMode := dmManual;
|
2008-02-03 12:05:55 +00:00
|
|
|
|
|
|
|
{ Set styles and initialize internal variables }
|
|
|
|
{$IFDEF VERSION4}
|
2018-06-04 10:36:57 +00:00
|
|
|
// DoubleBuffered := true;
|
2008-02-03 12:05:55 +00:00
|
|
|
{$ENDIF}
|
|
|
|
|
2022-07-25 22:55:31 +00:00
|
|
|
FWeekStartsOn := dtSunday;
|
2008-02-03 12:05:55 +00:00
|
|
|
wvClickTimer.Enabled := false;
|
|
|
|
wvClickTimer.Interval := ClickDelay;
|
|
|
|
wvClickTimer.OnTimer := wvEditInPlace;
|
|
|
|
wvCreatingEditor := false;
|
|
|
|
FDrawingStyle := ds3d;
|
|
|
|
wvPainting := false;
|
2022-07-25 22:55:31 +00:00
|
|
|
FColor := DEFAULT_COLOR;
|
|
|
|
FLineColor := DEFAULT_LINECOLOR;
|
2008-02-03 12:05:55 +00:00
|
|
|
wvStartDate := trunc(GetStartOfWeek(Now, FWeekStartsOn));
|
|
|
|
FTimeFormat := tf12Hour;
|
2022-07-25 22:55:31 +00:00
|
|
|
FDateLabelFormat := 'ddddd';
|
2008-02-03 12:05:55 +00:00
|
|
|
FColumnWidth := 200;
|
2016-06-23 23:16:34 +00:00
|
|
|
FAllowInplaceEdit := true;
|
2008-02-03 12:05:55 +00:00
|
|
|
|
|
|
|
{ set up fonts and colors }
|
2016-06-18 21:03:53 +00:00
|
|
|
// FDayHeadAttributes.Font.Name := 'Tahoma';
|
2008-02-03 12:05:55 +00:00
|
|
|
FDayHeadAttributes.Font.Size := 10;
|
|
|
|
FDayHeadAttributes.Font.Style := [];
|
|
|
|
FDayHeadAttributes.Color := clBtnFace;
|
|
|
|
FDayHeadAttributes.Bordered := true;
|
|
|
|
|
|
|
|
SetLength(wvEventArray, MaxVisibleEvents);
|
|
|
|
SetLength(wvWeekdayArray, 7);
|
|
|
|
|
|
|
|
{ size }
|
|
|
|
Height := 225;
|
|
|
|
Width := 300;
|
|
|
|
|
|
|
|
FDefaultPopup := TPopupMenu.Create (Self);
|
2012-09-24 19:30:17 +00:00
|
|
|
Self.PopupMenu := FDefaultPopup;
|
2016-09-10 17:26:42 +00:00
|
|
|
FDefaultPopup.OnPopup := PopupDropDownEvent;
|
2008-11-10 13:54:49 +00:00
|
|
|
LoadLanguage;
|
2008-02-03 12:05:55 +00:00
|
|
|
|
|
|
|
FAllDayEventAttr.BackgroundColor := Color;
|
|
|
|
FAllDayEventAttr.EventBackgroundColor := clBtnFace;
|
|
|
|
FAllDayEventAttr.EventBorderColor := LineColor;
|
|
|
|
FAllDayEventAttr.Font.Assign (Font);
|
|
|
|
|
|
|
|
wvHookUp;
|
2016-07-24 17:55:12 +00:00
|
|
|
SetActiveDate(Now);
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TVpWeekView.Destroy;
|
|
|
|
begin
|
2016-06-10 01:39:39 +00:00
|
|
|
FreeAndNil(wvInplaceEditor);
|
2008-02-03 12:05:55 +00:00
|
|
|
FDayHeadAttributes.Free;
|
|
|
|
FAllDayEventAttr.Free;
|
|
|
|
FHeadAttr.Free;
|
|
|
|
wvClickTimer.Free;
|
|
|
|
FEventFont.Free;
|
|
|
|
wvSpinButtons.Free;
|
|
|
|
wvEventList.Free;
|
|
|
|
FDefaultPopup.Free;
|
|
|
|
inherited;
|
|
|
|
end;
|
2008-11-10 13:54:49 +00:00
|
|
|
|
2016-09-11 23:08:34 +00:00
|
|
|
function TVpWeekView.BuildEventString(AEvent: TVpEvent;
|
2016-09-12 22:25:34 +00:00
|
|
|
AStartTime, AEndTime: TDateTime; UseAsHint: Boolean): String;
|
2016-09-11 23:08:34 +00:00
|
|
|
var
|
|
|
|
timeFmt: String;
|
2016-09-12 22:25:34 +00:00
|
|
|
timeStr: String;
|
|
|
|
s: String;
|
2016-09-11 23:08:34 +00:00
|
|
|
res: TVpResource;
|
|
|
|
grp: TVpResourceGroup;
|
|
|
|
isOverlayed: Boolean;
|
2016-09-12 22:25:34 +00:00
|
|
|
showDetails: Boolean;
|
2016-09-11 23:08:34 +00:00
|
|
|
begin
|
|
|
|
Result := '';
|
|
|
|
|
|
|
|
if (AEvent = nil) or (Datastore = nil) or (Datastore.Resource = nil) then
|
|
|
|
exit;
|
|
|
|
|
|
|
|
grp := Datastore.Resource.Group;
|
2016-09-12 22:25:34 +00:00
|
|
|
showDetails := (grp <> nil) and (odEventDescription in grp.ShowDetails);
|
2016-09-11 23:08:34 +00:00
|
|
|
isOverlayed := AEvent.IsOverlayed;
|
2016-09-12 22:25:34 +00:00
|
|
|
timefmt := GetTimeFormatStr(TimeFormat);
|
|
|
|
|
|
|
|
if UseAsHint then begin
|
|
|
|
{ Usage as hint }
|
|
|
|
if isOverlayed then begin
|
|
|
|
grp := Datastore.Resource.Group;
|
|
|
|
if (odResource in grp.ShowDetails) then begin
|
|
|
|
res := Datastore.Resources.GetResource(AEvent.ResourceID);
|
|
|
|
Result := RSOverlayed + ': ' + res.Description;
|
|
|
|
end else
|
|
|
|
Result := RSOverlayed;
|
|
|
|
end else
|
|
|
|
showDetails := true;
|
|
|
|
|
|
|
|
timeStr := IfThen(AEvent.AllDayEvent,
|
|
|
|
RSAllDay,
|
|
|
|
FormatDateTime(timeFmt, AEvent.StartTime) + ' - ' + FormatDateTime(timeFmt, AEvent.EndTime)
|
|
|
|
);
|
|
|
|
|
|
|
|
Result := IfThen(Result = '',
|
|
|
|
timeStr,
|
|
|
|
Result + LineEnding + timeStr
|
|
|
|
);
|
|
|
|
|
|
|
|
if showDetails then begin
|
|
|
|
// Event description
|
2022-06-12 16:12:31 +00:00
|
|
|
Result := Result + LineEnding2 +
|
2016-09-12 22:25:34 +00:00
|
|
|
RSEvent + ':' + LineEnding + AEvent.Description;
|
|
|
|
|
|
|
|
// Event notes
|
|
|
|
if (AEvent.Notes <> '') then begin
|
|
|
|
s := WrapText(AEvent.Notes, MAX_HINT_WIDTH);
|
|
|
|
s := StripLastLineEnding(s);
|
2022-06-12 16:12:31 +00:00
|
|
|
Result := Result + LineEnding2 +
|
2016-09-12 22:25:34 +00:00
|
|
|
RSNotes + ':' + LineEnding + s;
|
|
|
|
end;
|
2016-09-11 23:08:34 +00:00
|
|
|
|
2016-09-12 22:25:34 +00:00
|
|
|
// Event location
|
|
|
|
if (AEvent.Location <> '') then
|
2022-06-12 16:12:31 +00:00
|
|
|
Result := Result + LineEnding2 +
|
2016-09-12 22:25:34 +00:00
|
|
|
RSLocation + ':' + LineEnding + AEvent.Location;
|
|
|
|
end;
|
|
|
|
end
|
|
|
|
else
|
2016-09-11 23:08:34 +00:00
|
|
|
begin
|
2016-09-12 22:25:34 +00:00
|
|
|
{ Usage as cell text }
|
|
|
|
timeStr := IfThen(ShowEventTime, Format('%s - %s: ', [
|
2016-09-11 23:08:34 +00:00
|
|
|
FormatDateTime(timeFmt, AStartTime),
|
|
|
|
FormatDateTime(timeFmt, AEndTime)
|
2016-09-12 22:25:34 +00:00
|
|
|
]));
|
|
|
|
Result := timeStr;
|
2016-09-11 23:08:34 +00:00
|
|
|
|
2016-09-12 22:25:34 +00:00
|
|
|
if isOverlayed then
|
2016-09-11 23:08:34 +00:00
|
|
|
begin
|
2016-09-12 22:25:34 +00:00
|
|
|
if (grp <> nil) and (odResource in grp.ShowDetails) then
|
|
|
|
begin
|
|
|
|
res := Datastore.Resources.GetResource(AEvent.ResourceID);
|
|
|
|
if res <> nil then
|
|
|
|
Result := Result + '[' + res.Description + '] ';
|
|
|
|
end else
|
|
|
|
Result := Result + '[' + RSOverlayedEvent + '] ';
|
2016-09-11 23:08:34 +00:00
|
|
|
end else
|
2016-09-12 22:25:34 +00:00
|
|
|
showDetails := True;
|
2016-09-11 23:08:34 +00:00
|
|
|
|
2016-09-12 22:25:34 +00:00
|
|
|
if showDetails then
|
|
|
|
Result := Result + AEvent.Description;
|
|
|
|
end;
|
2016-09-11 23:08:34 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-11-10 13:54:49 +00:00
|
|
|
procedure TVpWeekView.LoadLanguage;
|
|
|
|
begin
|
|
|
|
FDefaultPopup.Items.Clear;
|
|
|
|
InitializeDefaultPopup;
|
|
|
|
end;
|
|
|
|
|
2008-02-03 12:05:55 +00:00
|
|
|
{=====}
|
|
|
|
|
|
|
|
procedure TVpWeekView.Invalidate;
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
end;
|
2016-09-22 23:12:16 +00:00
|
|
|
|
|
|
|
function TVpWeekView.IsHoliday(ADate: TDate; out AHolidayName: String): Boolean;
|
|
|
|
begin
|
|
|
|
AHolidayName := '';
|
|
|
|
if Assigned(FOnHoliday) then
|
|
|
|
FOnHoliday(Self, ADate, AHolidayName);
|
|
|
|
Result := AHolidayName <> '';
|
|
|
|
end;
|
2008-02-03 12:05:55 +00:00
|
|
|
|
|
|
|
procedure TVpWeekView.LinkHandler(Sender: TComponent;
|
|
|
|
NotificationType: TVpNotificationType; const Value: Variant);
|
|
|
|
begin
|
|
|
|
wvInLinkHandler := true;
|
|
|
|
try
|
|
|
|
case NotificationType of
|
2016-06-18 21:03:53 +00:00
|
|
|
neDateChange : Date := Value;
|
|
|
|
neDataStoreChange : Invalidate;
|
|
|
|
neInvalidate : Invalidate;
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
finally
|
|
|
|
wvInLinkHandler := false;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TVpWeekView.wvHookUp;
|
|
|
|
var
|
|
|
|
I: Integer;
|
|
|
|
begin
|
|
|
|
{ If the component is being dropped on a form at designtime, then }
|
|
|
|
{ automatically hook up to the first datastore component found }
|
|
|
|
if csDesigning in ComponentState then
|
|
|
|
for I := 0 to pred(Owner.ComponentCount) do begin
|
|
|
|
if (Owner.Components[I] is TVpCustomDataStore) then begin
|
|
|
|
DataStore := TVpCustomDataStore(Owner.Components[I]);
|
|
|
|
Exit;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
|
|
|
procedure TVpWeekView.Loaded;
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
wvLoaded := true;
|
|
|
|
wvPopulate;
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
|
|
|
function TVpWeekView.GetControlType : TVpItemType;
|
|
|
|
begin
|
|
|
|
Result := itWeekView;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TVpWeekView.Paint;
|
|
|
|
begin
|
2016-06-18 21:03:53 +00:00
|
|
|
RenderToCanvas(
|
|
|
|
Canvas, // Paint Canvas
|
|
|
|
Rect (0, 0, Width, Height), // Paint Rectangle
|
|
|
|
ra0,
|
|
|
|
1, // Scale
|
|
|
|
wvStartDate, // Date
|
|
|
|
-1, // Start At
|
|
|
|
-1, // End At
|
|
|
|
gr30Min,
|
|
|
|
False // Display Only
|
|
|
|
);
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
{=====}
|
2016-06-18 21:03:53 +00:00
|
|
|
|
|
|
|
procedure TVpWeekView.PaintToCanvas(ACanvas: TCanvas; ARect: TRect;
|
|
|
|
Angle: TVpRotationAngle; ADate: TDateTime);
|
2008-02-03 12:05:55 +00:00
|
|
|
begin
|
2016-06-18 21:03:53 +00:00
|
|
|
RenderToCanvas(ACanvas, ARect, Angle, 1, ADate, -1, -1, gr30Min, True);
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
2016-06-18 21:03:53 +00:00
|
|
|
procedure TVpWeekView.RenderToCanvas(RenderCanvas: TCanvas; RenderIn: TRect;
|
|
|
|
Angle: TVpRotationAngle; Scale: Extended; RenderDate: TDateTime;
|
|
|
|
StartLine: Integer; StopLine: Integer; UseGran: TVpGranularity;
|
|
|
|
DisplayOnly: Boolean);
|
2008-02-03 12:05:55 +00:00
|
|
|
var
|
2016-06-22 21:04:36 +00:00
|
|
|
painter: TVpWeekViewPainter;
|
2008-02-03 12:05:55 +00:00
|
|
|
begin
|
|
|
|
wvPainting := true;
|
2016-06-22 21:04:36 +00:00
|
|
|
painter := TVpWeekViewPainter.Create(self, RenderCanvas);
|
2008-02-03 12:05:55 +00:00
|
|
|
try
|
2016-06-22 21:04:36 +00:00
|
|
|
painter.RenderToCanvas(RenderIn, Angle, Scale, RenderDate, Startline, StopLine, UseGran, DisplayOnly);
|
2008-02-03 12:05:55 +00:00
|
|
|
finally
|
2016-06-22 21:04:36 +00:00
|
|
|
painter.Free;
|
|
|
|
wvPainting := false;
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
|
|
|
procedure TVpWeekView.wvPopulate;
|
|
|
|
begin
|
|
|
|
if DataStore <> nil then
|
|
|
|
DataStore.Date := FActiveDate;
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
|
|
|
procedure TVpWeekView.DeleteActiveEvent(Verify: Boolean);
|
|
|
|
var
|
|
|
|
DoIt: Boolean;
|
|
|
|
begin
|
2016-07-05 08:42:08 +00:00
|
|
|
if ReadOnly then
|
|
|
|
exit;
|
2016-09-10 19:06:41 +00:00
|
|
|
if (FActiveEvent <> nil) and (not FActiveEvent.CanEdit) then
|
|
|
|
exit;
|
2008-02-03 12:05:55 +00:00
|
|
|
|
2016-07-05 08:42:08 +00:00
|
|
|
wvClickTimer.Enabled := false;
|
2012-09-24 19:30:17 +00:00
|
|
|
EndEdit(nil);
|
2008-02-03 12:05:55 +00:00
|
|
|
|
2016-07-05 08:42:08 +00:00
|
|
|
DoIt := not Verify;
|
|
|
|
|
|
|
|
if ActiveEvent <> nil then begin
|
2022-08-05 11:01:59 +00:00
|
|
|
if Assigned(FOnDeletingEvent) then
|
|
|
|
begin
|
|
|
|
DoIt := true;
|
|
|
|
FOnDeletingEvent(Self, ActiveEvent, DoIt);
|
|
|
|
end else
|
2008-02-03 12:05:55 +00:00
|
|
|
if Verify then
|
2022-06-12 16:12:31 +00:00
|
|
|
DoIt := (MessageDlg(RSConfirmDeleteEvent + LineEnding2 + RSPermanent,
|
2016-06-18 21:03:53 +00:00
|
|
|
mtConfirmation, [mbYes, mbNo], 0) = mrYes);
|
2008-02-03 12:05:55 +00:00
|
|
|
|
|
|
|
if DoIt then begin
|
2012-09-24 19:30:17 +00:00
|
|
|
ActiveEvent.Deleted := true;
|
|
|
|
ActiveEvent := nil;
|
2008-02-03 12:05:55 +00:00
|
|
|
DataStore.PostEvents;
|
|
|
|
Invalidate;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
|
|
|
procedure TVpWeekView.wvSpinButtonClick(Sender: TObject; Button: TUDBtnType);
|
|
|
|
begin
|
|
|
|
if Button = btNext then
|
|
|
|
Date := Date + 7
|
|
|
|
else
|
|
|
|
Date := Date - 7;
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
|
|
|
procedure TVpWeekView.SetColor(Value: TColor);
|
|
|
|
begin
|
|
|
|
if FColor <> Value then begin
|
|
|
|
FColor := Value;
|
|
|
|
Invalidate;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
2012-09-24 19:30:17 +00:00
|
|
|
procedure TVpWeekView.SetActiveEvent(AValue: TVpEvent);
|
|
|
|
begin
|
2016-09-03 21:51:37 +00:00
|
|
|
if FActiveEvent = AValue then Exit;
|
|
|
|
FActiveEvent := AValue;
|
2012-09-24 19:30:17 +00:00
|
|
|
end;
|
|
|
|
|
2022-07-12 14:31:42 +00:00
|
|
|
procedure TVpWeekView.SetApplyCategoryInfos(AValue: Boolean);
|
|
|
|
begin
|
|
|
|
if FApplyCategoryInfos <> AValue then
|
|
|
|
begin
|
|
|
|
FApplyCategoryInfos := AValue;
|
|
|
|
Invalidate;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2008-02-03 12:05:55 +00:00
|
|
|
procedure TVpWeekView.SetDrawingStyle(Value: TVpDrawingStyle);
|
|
|
|
begin
|
|
|
|
if FDrawingStyle <> Value then begin
|
|
|
|
FDrawingStyle := Value;
|
2022-07-12 14:31:42 +00:00
|
|
|
Invalidate;
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
|
|
|
procedure TVpWeekView.SetLineColor(Value: TColor);
|
|
|
|
begin
|
|
|
|
if FLineColor <> Value then begin
|
|
|
|
FLineColor := Value;
|
2022-07-12 14:31:42 +00:00
|
|
|
Invalidate;
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
end;
|
2022-07-25 22:55:31 +00:00
|
|
|
|
|
|
|
function TVpWeekView.IsStoredDateLabelFormat: Boolean;
|
|
|
|
begin
|
|
|
|
Result := FDateLabelFormat <> 'ddddd';
|
|
|
|
end;
|
2008-02-03 12:05:55 +00:00
|
|
|
|
|
|
|
procedure TVpWeekView.SetDateLabelFormat(Value: string);
|
|
|
|
begin
|
|
|
|
if Value <> FDateLabelFormat then begin
|
|
|
|
FDateLabelFormat := Value;
|
|
|
|
Invalidate;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2016-07-15 11:52:21 +00:00
|
|
|
procedure TVpWeekView.SetEventFont(Value: TVpFont);
|
2008-02-03 12:05:55 +00:00
|
|
|
begin
|
|
|
|
FEventFont.Assign(Value);
|
|
|
|
Invalidate;
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
2016-09-23 11:40:39 +00:00
|
|
|
procedure TVpWeekView.SetLayout(AValue: TVpWeekviewLayout);
|
|
|
|
begin
|
|
|
|
if AValue <> FLayout then begin
|
|
|
|
FLayout := AValue;
|
|
|
|
Invalidate;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2008-02-03 12:05:55 +00:00
|
|
|
procedure TVpWeekView.SetShowEventTime(Value: Boolean);
|
|
|
|
begin
|
|
|
|
if Value <> FShowEventTIme then begin
|
|
|
|
FShowEventTime := Value;
|
|
|
|
Invalidate;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
|
|
|
procedure TVpWeekView.SetTimeFormat(Value: TVpTimeFormat);
|
|
|
|
begin
|
|
|
|
if Value <> FTimeFormat then begin
|
|
|
|
FTimeFormat := Value;
|
|
|
|
Invalidate;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
|
|
|
procedure TVpWeekView.SetActiveDate(Value: TDateTime);
|
|
|
|
begin
|
|
|
|
if FActiveDate <> Value then begin
|
|
|
|
FActiveDate := Value;
|
|
|
|
|
|
|
|
if (Value < wvStartDate) or (Value >= wvStartDate + 7) then
|
|
|
|
wvStartDate := Trunc(GetStartOfWeek(Value, FWeekStartsOn));
|
|
|
|
|
|
|
|
if wvStartDate > Value then
|
|
|
|
wvStartDate := wvStartDate - 7;
|
|
|
|
|
|
|
|
if wvLoaded then
|
|
|
|
wvPopulate;
|
|
|
|
|
|
|
|
Invalidate;
|
|
|
|
|
|
|
|
if (not wvInLinkHandler) and (ControlLink <> nil) then
|
|
|
|
ControlLink.Notify(self, neDateChange, FActiveDate);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
|
|
|
procedure TVpWeekView.SetWeekStartsOn(Value: TVpDayType);
|
|
|
|
begin
|
|
|
|
if FWeekStartsOn <> Value then begin
|
|
|
|
FWeekStartsOn := Value;
|
|
|
|
Invalidate;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
|
|
|
{$IFNDEF LCL}
|
|
|
|
procedure TVpWeekView.WMSize(var Msg: TWMSize);
|
|
|
|
{$ELSE}
|
|
|
|
procedure TVpWeekView.WMSize(var Msg: TLMSize);
|
|
|
|
{$ENDIF}
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
{ force a repaint on resize }
|
|
|
|
Invalidate;
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
|
|
|
procedure TVpWeekView.CreateParams(var Params: TCreateParams);
|
|
|
|
begin
|
|
|
|
inherited CreateParams(Params);
|
|
|
|
with Params do
|
|
|
|
begin
|
|
|
|
Style := Style or WS_TABSTOP;
|
2016-06-18 21:03:53 +00:00
|
|
|
{$IFDEF DELPHI}
|
2008-02-03 12:05:55 +00:00
|
|
|
WindowClass.style := CS_DBLCLKS;
|
|
|
|
{$ENDIF}
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
|
|
|
procedure TVpWeekView.CreateWnd;
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
wvSpinButtons.Parent := self;
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
2016-09-03 17:41:24 +00:00
|
|
|
procedure TVpWeekView.DoEndDrag(Target: TObject; X, Y: Integer);
|
|
|
|
begin
|
2016-11-21 17:12:05 +00:00
|
|
|
Unused(Target, X, Y);
|
|
|
|
|
2016-09-03 17:41:24 +00:00
|
|
|
if ReadOnly or (not FAllowDragAndDrop) then
|
|
|
|
Exit;
|
|
|
|
{$IFNDEF LCL}
|
|
|
|
TVpEventDragObject(Target).Free;
|
|
|
|
{$ENDIF}
|
|
|
|
// not needed for LCL: we use DragObjectEx !!
|
|
|
|
end;
|
2016-09-03 21:51:37 +00:00
|
|
|
|
|
|
|
procedure TVpWeekView.DoStartDrag(var DragObject: TDragObject);
|
|
|
|
{$IFDEF LCL}
|
|
|
|
var
|
|
|
|
P, HotSpot: TPoint;
|
|
|
|
EventName: string;
|
|
|
|
{$ENDIF}
|
|
|
|
begin
|
|
|
|
if ReadOnly or not FAllowDragAndDrop then
|
|
|
|
Exit;
|
|
|
|
|
|
|
|
if FActiveEvent <> nil then begin
|
|
|
|
{$IFDEF LCL}
|
2016-11-21 17:12:05 +00:00
|
|
|
GetCursorPos(P{%H-});
|
2016-09-03 21:51:37 +00:00
|
|
|
P := TVpWeekView(Self).ScreenToClient(P);
|
|
|
|
EventName := FActiveEvent.Description;
|
|
|
|
HotSpot := Point(P.X - Self.wvActiveEventRec.Left, P.Y - Self.wvActiveEventRec.Top);
|
|
|
|
DragObject := TVpEventDragObject.CreateWithDragImages(Self as TControl,
|
|
|
|
HotSpot, Self.wvActiveEventRec, EventName, FDragDropTransparent);
|
|
|
|
{$ELSE}
|
|
|
|
DragObject := DragObject := TVpEventDragObject.Create(Self);
|
|
|
|
{$ENDIF}
|
|
|
|
TVpEventDragObject(DragObject).Event := FActiveEvent;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
{$IFDEF LCL}
|
|
|
|
CancelDrag;
|
|
|
|
{$ELSE}
|
|
|
|
DragObject.Free;//EndDrag(false);
|
|
|
|
{$ENDIF}
|
|
|
|
end;
|
2016-09-03 17:41:24 +00:00
|
|
|
|
|
|
|
procedure TVpWeekView.DragDrop(Source: TObject; X, Y: Integer);
|
|
|
|
var
|
|
|
|
Event: TVpEvent;
|
|
|
|
i: Integer;
|
|
|
|
P: TPoint;
|
|
|
|
newDate, dateDiff: TDate;
|
|
|
|
begin
|
|
|
|
if ReadOnly or (not FAllowDragAndDrop) then
|
|
|
|
Exit;
|
|
|
|
|
|
|
|
P := Point(X, Y);
|
|
|
|
newDate := -1;
|
|
|
|
for i := 0 to pred(Length(wvWeekdayArray)) do
|
|
|
|
if PointInRect(P, wvWeekdayArray[i].Rec) then begin
|
|
|
|
newDate := wvWeekdayArray[i].Day;
|
|
|
|
break;
|
|
|
|
end;
|
|
|
|
if newDate = -1 then
|
|
|
|
exit;
|
|
|
|
|
|
|
|
Event := TVpEventDragObject(Source).Event;
|
|
|
|
if Event <> nil then begin
|
|
|
|
dateDiff := trunc(newDate) - trunc(Event.StartTime);
|
|
|
|
Event.StartTime := newDate + frac(Event.StartTime);
|
|
|
|
Event.EndTime := Event.EndTime + dateDiff;
|
|
|
|
DataStore.PostEvents;
|
|
|
|
Repaint;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TVpWeekView.DragOver(Source: TObject; X, Y: Integer; State: TDragState;
|
|
|
|
var Accept: Boolean);
|
|
|
|
begin
|
2016-11-21 17:12:05 +00:00
|
|
|
Unused(Source, X, State);
|
|
|
|
|
2016-09-03 17:41:24 +00:00
|
|
|
Accept := false;
|
|
|
|
if ReadOnly or (not FAllowDragAndDrop) then
|
|
|
|
Exit;
|
|
|
|
|
|
|
|
if (Y > wvHeaderHeight) then
|
|
|
|
Accept := true;
|
|
|
|
end;
|
|
|
|
|
2008-02-03 12:05:55 +00:00
|
|
|
{$IFNDEF LCL}
|
2016-06-18 21:03:53 +00:00
|
|
|
procedure TVpWeekView.WMLButtonDblClk(var Msg: TWMLButtonDblClk);
|
2008-02-03 12:05:55 +00:00
|
|
|
{$ELSE}
|
2016-06-18 21:03:53 +00:00
|
|
|
procedure TVpWeekView.WMLButtonDblClk(var Msg: TLMLButtonDblClk);
|
2008-02-03 12:05:55 +00:00
|
|
|
{$ENDIF}
|
|
|
|
var
|
|
|
|
StartTime, EndTime: TDateTime;
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
wvClickTimer.Enabled := false;
|
2016-09-03 21:51:37 +00:00
|
|
|
wvMouseDownPoint := Point(0, 0);
|
|
|
|
wvMouseDown := false;
|
|
|
|
wvDragging := false;
|
2008-02-03 12:05:55 +00:00
|
|
|
|
2016-06-18 21:03:53 +00:00
|
|
|
if not CheckCreateResource then
|
|
|
|
Exit;
|
2008-02-03 12:05:55 +00:00
|
|
|
|
|
|
|
if DataStore = nil then
|
|
|
|
Exit;
|
|
|
|
|
2012-09-24 19:30:17 +00:00
|
|
|
wvSetDateByCoord(Point(Msg.XPos, Msg.YPos));
|
2018-06-20 20:56:27 +00:00
|
|
|
EventAtCoord(Point(Msg.XPos, Msg.YPos));
|
2012-09-24 19:30:17 +00:00
|
|
|
|
2008-02-03 12:05:55 +00:00
|
|
|
// if the mouse was pressed down in the client area, then select the cell.
|
2016-09-03 21:51:37 +00:00
|
|
|
if not focused then
|
|
|
|
SetFocus;
|
2008-02-03 12:05:55 +00:00
|
|
|
|
|
|
|
if (Msg.YPos > wvHeaderHeight) then
|
|
|
|
begin
|
|
|
|
{ The mouse click landed inside the client area }
|
|
|
|
{ If we have hit an active event then we must want to edit it }
|
2012-09-24 19:30:17 +00:00
|
|
|
if ActiveEvent <> nil then begin
|
2008-02-03 12:05:55 +00:00
|
|
|
{ edit this event }
|
|
|
|
wvSpawnEventEditDialog(False);
|
|
|
|
end
|
2016-06-24 14:16:51 +00:00
|
|
|
else
|
|
|
|
if (DataStore.Resource <> nil) then begin
|
2008-02-03 12:05:55 +00:00
|
|
|
{ otherwise, we must want to create a new event }
|
2019-01-15 22:14:01 +00:00
|
|
|
StartTime := NextFullHour(FActiveDate + Time());
|
2018-06-20 20:56:27 +00:00
|
|
|
// StartTime := trunc(Date) + 0.5; { default to 12:00 noon }
|
2016-06-24 14:16:51 +00:00
|
|
|
EndTime := StartTime + 30 / MinutesInDay; { StartTime + 30 minutes }
|
2012-09-24 19:30:17 +00:00
|
|
|
ActiveEvent := DataStore.Resource.Schedule.AddEvent(
|
2016-06-18 21:03:53 +00:00
|
|
|
DataStore.GetNextID('Events'),
|
|
|
|
StartTime,
|
|
|
|
EndTime
|
|
|
|
);
|
2008-02-03 12:05:55 +00:00
|
|
|
{ edit this new event }
|
2016-06-24 14:16:51 +00:00
|
|
|
wvSpawnEventEditDialog(True); // true = new event
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
2016-09-11 17:53:51 +00:00
|
|
|
|
2022-08-05 20:12:52 +00:00
|
|
|
{ Reads the events listed in the specified ical file and adds them to the
|
|
|
|
day view control. All events imported are collected in the Result array.
|
|
|
|
ADefaultCategory is the category to which the event is assigned if no fitting
|
|
|
|
category has been found in the ical, i.e. when the event's category is 0.
|
|
|
|
If you are not happy with this category replacement you can iterate over the
|
|
|
|
Result array and change it. }
|
|
|
|
function TVpWeekView.ImportICalFile(const AFileName: String;
|
2022-08-10 10:20:56 +00:00
|
|
|
APreview: Boolean = false; ADefaultCategory: Integer = -1): TVpEventArr;
|
2022-08-05 20:12:52 +00:00
|
|
|
begin
|
|
|
|
if ReadOnly or (not CheckCreateResource) or
|
|
|
|
(not Assigned(DataStore)) or (not Assigned(DataStore.Resource))
|
|
|
|
then
|
2022-08-10 10:20:56 +00:00
|
|
|
Exit(nil);
|
2022-08-05 20:12:52 +00:00
|
|
|
|
2022-08-10 10:20:56 +00:00
|
|
|
Result := Datastore.Resource.Schedule.ImportICalFile(AFileName, APreview, ADefaultCategory);
|
|
|
|
if Length(Result) > 0 then
|
|
|
|
begin
|
|
|
|
FActiveEvent := Result[High(Result)];
|
|
|
|
Datastore.PostEvents;
|
|
|
|
Datastore.NotifyDependents;
|
|
|
|
Invalidate;
|
2022-08-05 20:12:52 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2016-09-11 17:53:51 +00:00
|
|
|
{ Hints }
|
|
|
|
|
|
|
|
procedure TVpWeekView.ShowHintWindow(APoint: TPoint; AEvent: TVpEvent);
|
|
|
|
var
|
2016-09-12 22:25:34 +00:00
|
|
|
txt: String;
|
2016-09-11 17:53:51 +00:00
|
|
|
begin
|
2017-05-25 21:24:23 +00:00
|
|
|
HideHintWindow;
|
|
|
|
case FHintMode of
|
|
|
|
hmPlannerHint:
|
|
|
|
begin
|
|
|
|
if (AEvent = nil) or (Datastore = nil) or (Datastore.Resource = nil) then
|
|
|
|
exit;
|
|
|
|
txt := BuildEventString(AEvent, AEvent.StartTime, AEvent.EndTime, true);
|
|
|
|
end;
|
|
|
|
hmComponentHint:
|
|
|
|
txt := FComponentHint;
|
|
|
|
end;
|
|
|
|
if (txt <> '') and not ((wvInplaceEditor <> nil) and wvInplaceEditor.Visible)
|
|
|
|
and not (csDesigning in ComponentState) then
|
2016-09-11 17:53:51 +00:00
|
|
|
begin
|
2017-05-25 21:24:23 +00:00
|
|
|
Hint := txt;
|
|
|
|
Application.Hint := txt;
|
2016-09-12 22:25:34 +00:00
|
|
|
Application.ActivateHint(ClientToScreen(APoint), true);
|
|
|
|
end;
|
2016-09-11 17:53:51 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TVpWeekView.HideHintWindow;
|
|
|
|
begin
|
2017-05-25 21:24:23 +00:00
|
|
|
Application.CancelHint;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TVpWeekView.SetHint(const AValue: TTranslateString);
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
if FHintMode = hmComponentHint then
|
|
|
|
FComponentHint := AValue;
|
2016-09-11 17:53:51 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{ Popup menu }
|
2008-02-03 12:05:55 +00:00
|
|
|
|
|
|
|
procedure TVpWeekView.InitializeDefaultPopup;
|
|
|
|
var
|
2016-06-18 21:03:53 +00:00
|
|
|
NewItem: TMenuItem;
|
|
|
|
NewSubItem: TMenuItem;
|
2016-09-10 19:06:41 +00:00
|
|
|
canEdit: Boolean;
|
2008-02-03 12:05:55 +00:00
|
|
|
begin
|
2016-09-10 19:06:41 +00:00
|
|
|
canEdit := (FActiveEvent <> nil) and FActiveEvent.CanEdit;
|
2016-09-10 17:26:42 +00:00
|
|
|
FDefaultPopup.Items.Clear;
|
|
|
|
|
2018-06-16 16:24:11 +00:00
|
|
|
if RSPopupAddEvent <> '' then begin // Add
|
2016-09-10 19:06:41 +00:00
|
|
|
NewItem := TMenuItem.Create(Self);
|
2016-09-12 22:25:34 +00:00
|
|
|
NewItem.Caption := RSPopupAddEvent;
|
2008-02-03 12:05:55 +00:00
|
|
|
NewItem.OnClick := PopupAddEvent;
|
|
|
|
NewItem.Tag := 0;
|
2016-09-10 19:06:41 +00:00
|
|
|
FDefaultPopup.Items.Add(NewItem);
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
|
2018-06-16 16:24:11 +00:00
|
|
|
if RSPopupAddEventFromICal <> '' then begin
|
|
|
|
NewItem := TMenuItem.Create(Self);
|
|
|
|
NewItem.Caption := RSPopupAddEventFromICal; // Import from iCal
|
|
|
|
NewItem.OnClick := PopupAddFromICalFile;
|
|
|
|
NewItem.Tag := 0;
|
|
|
|
FDefaultPopup.Items.Add(NewItem);
|
|
|
|
end;
|
|
|
|
|
|
|
|
if RSPopupEditEvent <> '' then begin // Edit
|
2016-09-10 19:06:41 +00:00
|
|
|
NewItem := TMenuItem.Create(Self);
|
2016-09-12 22:25:34 +00:00
|
|
|
NewItem.Caption := RSPopupEditEvent;
|
2016-09-10 19:06:41 +00:00
|
|
|
NewItem.Enabled := canEdit;
|
2008-02-03 12:05:55 +00:00
|
|
|
NewItem.OnClick := PopupEditEvent;
|
|
|
|
NewItem.Tag := 1;
|
2016-09-10 19:06:41 +00:00
|
|
|
FDefaultPopup.Items.Add(NewItem);
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
|
2018-06-16 16:24:11 +00:00
|
|
|
if RSPopupDeleteEvent <> '' then begin // Delete
|
2016-09-10 19:06:41 +00:00
|
|
|
NewItem := TMenuItem.Create(Self);
|
2016-09-12 22:25:34 +00:00
|
|
|
NewItem.Caption := RSPopupDeleteEvent;
|
2016-09-10 19:06:41 +00:00
|
|
|
NewItem.Enabled := canEdit;
|
2008-02-03 12:05:55 +00:00
|
|
|
NewItem.OnClick := PopupDeleteEvent;
|
|
|
|
NewItem.Tag := 1;
|
2016-09-10 19:06:41 +00:00
|
|
|
FDefaultPopup.Items.Add(NewItem);
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
|
2018-06-16 16:24:11 +00:00
|
|
|
NewItem := TMenuItem.Create(Self); // ---
|
2016-09-10 19:06:41 +00:00
|
|
|
NewItem.Caption := '-';
|
|
|
|
FDefaultPopup.Items.Add(NewItem);
|
|
|
|
|
2018-06-16 16:24:11 +00:00
|
|
|
if RSPopupChangeDate <> '' then begin // Change date
|
2016-09-10 19:06:41 +00:00
|
|
|
NewItem := TMenuItem.Create(Self);
|
2016-09-12 22:25:34 +00:00
|
|
|
NewItem.Caption := RSPopupChangeDate;
|
2008-02-03 12:05:55 +00:00
|
|
|
NewItem.Tag := 0;
|
2016-09-10 19:06:41 +00:00
|
|
|
FDefaultPopup.Items.Add(NewItem);
|
2008-02-03 12:05:55 +00:00
|
|
|
|
2018-06-16 16:24:11 +00:00
|
|
|
if RSToday <> '' then begin // Today
|
2016-09-10 19:06:41 +00:00
|
|
|
NewSubItem := TMenuItem.Create(Self);
|
2016-09-10 20:08:06 +00:00
|
|
|
NewSubItem.Caption := RSToday;
|
2008-02-03 12:05:55 +00:00
|
|
|
NewSubItem.OnClick := PopupToday;
|
|
|
|
NewSubItem.Tag := 0;
|
2016-09-10 19:06:41 +00:00
|
|
|
NewItem.Add(NewSubItem);
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
|
2018-06-16 16:24:11 +00:00
|
|
|
NewSubItem := TMenuItem.Create(Self); // -------
|
2016-09-10 20:08:06 +00:00
|
|
|
NewSubItem.Caption := '-';
|
|
|
|
NewItem.Add(NewSubItem);
|
|
|
|
|
2018-06-16 16:24:11 +00:00
|
|
|
if RSNextWeek <> '' then begin // Next week
|
2016-09-10 19:06:41 +00:00
|
|
|
NewSubItem := TMenuItem.Create(Self);
|
2016-09-10 20:08:06 +00:00
|
|
|
NewSubItem.Caption := RSNextWeek;
|
2008-02-03 12:05:55 +00:00
|
|
|
NewSubItem.OnClick := PopupNextWeek;
|
|
|
|
NewSubItem.Tag := 0;
|
2016-09-10 19:06:41 +00:00
|
|
|
NewItem.Add(NewSubItem);
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
|
2018-06-16 16:24:11 +00:00
|
|
|
if RSPrevWeek <> '' then begin // Previous week
|
2016-09-10 19:06:41 +00:00
|
|
|
NewSubItem := TMenuItem.Create(Self);
|
2016-09-10 20:08:06 +00:00
|
|
|
NewSubItem.Caption := RSPrevWeek;
|
2008-02-03 12:05:55 +00:00
|
|
|
NewSubItem.OnClick := PopupPrevWeek;
|
|
|
|
NewSubItem.Tag := 0;
|
2016-09-10 19:06:41 +00:00
|
|
|
NewItem.Add(NewSubItem);
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
|
2018-06-16 16:24:11 +00:00
|
|
|
NewSubItem := TMenuItem.Create(Self); // -----
|
2016-09-10 20:08:06 +00:00
|
|
|
NewSubItem.Caption := '-';
|
|
|
|
NewItem.Add(NewSubItem);
|
|
|
|
|
2018-06-16 16:24:11 +00:00
|
|
|
if RSNextMonth <> '' then begin // Next month
|
2016-09-10 19:06:41 +00:00
|
|
|
NewSubItem := TMenuItem.Create(Self);
|
2016-09-10 20:08:06 +00:00
|
|
|
NewSubItem.Caption := RSNextMonth;
|
2008-02-03 12:05:55 +00:00
|
|
|
NewSubItem.OnClick := PopupNextMonth;
|
|
|
|
NewSubItem.Tag := 0;
|
2016-09-10 19:06:41 +00:00
|
|
|
NewItem.Add(NewSubItem);
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
|
2018-06-16 16:24:11 +00:00
|
|
|
if RSPrevMonth <> '' then begin // Previous month
|
2016-09-10 19:06:41 +00:00
|
|
|
NewSubItem := TMenuItem.Create(Self);
|
2016-09-10 20:08:06 +00:00
|
|
|
NewSubItem.Caption := RSPrevMonth;
|
2008-02-03 12:05:55 +00:00
|
|
|
NewSubItem.OnClick := PopupPrevMonth;
|
|
|
|
NewSubItem.Tag := 0;
|
2016-09-10 19:06:41 +00:00
|
|
|
NewItem.Add(NewSubItem);
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
|
2018-06-16 16:24:11 +00:00
|
|
|
NewSubItem := TMenuItem.Create(Self); // -------
|
2016-09-10 20:08:06 +00:00
|
|
|
NewSubItem.Caption := '-';
|
|
|
|
NewItem.Add(NewSubItem);
|
|
|
|
|
2018-06-16 16:24:11 +00:00
|
|
|
if RSNextYear <> '' then begin // Next year
|
2016-09-10 19:06:41 +00:00
|
|
|
NewSubItem := TMenuItem.Create(Self);
|
2016-09-10 20:08:06 +00:00
|
|
|
NewSubItem.Caption := RSNextYear;
|
2008-02-03 12:05:55 +00:00
|
|
|
NewSubItem.OnClick := PopupNextYear;
|
|
|
|
NewSubItem.Tag := 0;
|
2016-09-10 19:06:41 +00:00
|
|
|
NewItem.Add(NewSubItem);
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
|
2018-06-16 16:24:11 +00:00
|
|
|
if RSPrevYear <> '' then begin // previous year
|
2016-09-10 19:06:41 +00:00
|
|
|
NewSubItem := TMenuItem.Create(Self);
|
2016-09-10 20:08:06 +00:00
|
|
|
NewSubItem.Caption := RSPrevYear;
|
2008-02-03 12:05:55 +00:00
|
|
|
NewSubItem.OnClick := PopupPrevYear;
|
|
|
|
NewSubItem.Tag := 0;
|
2016-09-10 19:06:41 +00:00
|
|
|
NewItem.Add(NewSubItem);
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
2022-07-11 22:59:40 +00:00
|
|
|
|
|
|
|
NewSubItem := TMenuItem.Create(Self); // ---
|
|
|
|
NewSubItem.Caption := '-';
|
|
|
|
NewItem.Add(NewSubItem);
|
|
|
|
|
|
|
|
if RSCustomDate <> '' then begin // Custom date
|
|
|
|
NewSubItem := TMenuItem.Create(Self);
|
|
|
|
NewSubItem.Caption := RSCustomDate;
|
|
|
|
NewSubItem.OnClick := PopupCustomDate;
|
|
|
|
NewSubItem.Tag := 0;
|
|
|
|
NewItem.Add(NewSubItem);
|
|
|
|
end;
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
2016-09-10 17:26:42 +00:00
|
|
|
|
|
|
|
if (Datastore <> nil) and (Datastore.Resource <> nil) then
|
|
|
|
AddResourceGroupMenu(FDefaultPopup.Items, Datastore.Resource, PopupPickResourceGroupEvent);
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
2016-06-18 21:03:53 +00:00
|
|
|
procedure TVpWeekView.PopupAddEvent(Sender: TObject);
|
2008-02-03 12:05:55 +00:00
|
|
|
var
|
2016-06-18 21:03:53 +00:00
|
|
|
StartTime: TDateTime;
|
|
|
|
EndTime: TDateTime;
|
2008-02-03 12:05:55 +00:00
|
|
|
begin
|
2018-06-18 20:01:53 +00:00
|
|
|
if ReadOnly or (not CheckCreateResource) or
|
|
|
|
(not Assigned(DataStore) ) or (not Assigned(DataStore.Resource))
|
|
|
|
then
|
2016-06-18 21:03:53 +00:00
|
|
|
Exit;
|
|
|
|
|
2018-06-20 20:56:27 +00:00
|
|
|
StartTime := NextFullHour(Now()); { Default start time: next full hour }
|
|
|
|
EndTime := StartTime + 30 / MinutesInDay; { StartTime + 30 minutes }
|
2016-06-18 21:03:53 +00:00
|
|
|
ActiveEvent := DataStore.Resource.Schedule.AddEvent(
|
|
|
|
DataStore.GetNextID('Events'),
|
|
|
|
StartTime,
|
|
|
|
EndTime
|
|
|
|
);
|
|
|
|
|
2008-02-03 12:05:55 +00:00
|
|
|
{ edit this new event }
|
2016-06-18 21:03:53 +00:00
|
|
|
wvSpawnEventEditDialog(True);
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
2018-06-16 16:24:11 +00:00
|
|
|
procedure TVpWeekView.PopupAddFromICalFile(Sender: TObject);
|
|
|
|
var
|
|
|
|
dlg: TOpenDialog;
|
|
|
|
fn: String;
|
|
|
|
begin
|
2018-06-18 20:01:53 +00:00
|
|
|
if ReadOnly or (not CheckCreateResource) or
|
|
|
|
(not Assigned(DataStore)) or (not Assigned(DataStore.Resource))
|
|
|
|
then
|
|
|
|
Exit;
|
|
|
|
|
2018-06-16 16:24:11 +00:00
|
|
|
dlg := TOpenDialog.Create(nil);
|
|
|
|
try
|
|
|
|
dlg.Title := RSLoadICalTitle;
|
|
|
|
dlg.Filter := RSICalFilter;
|
|
|
|
dlg.FileName := '';
|
|
|
|
dlg.Options := dlg.Options + [ofAllowMultiSelect, ofFileMustExist];
|
|
|
|
if dlg.Execute then begin
|
|
|
|
Screen.Cursor := crHourGlass;
|
|
|
|
try
|
2022-08-05 20:12:52 +00:00
|
|
|
Application.ProcessMessages;
|
|
|
|
for fn in dlg.Files do
|
2022-08-10 10:20:56 +00:00
|
|
|
ImportICalFile(fn, dlg.Files.Count = 1);
|
2018-06-16 16:24:11 +00:00
|
|
|
finally
|
|
|
|
Screen.Cursor := crDefault;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
dlg.Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2016-06-18 21:03:53 +00:00
|
|
|
procedure TVpWeekView.PopupDeleteEvent(Sender: TObject);
|
2008-02-03 12:05:55 +00:00
|
|
|
begin
|
2016-06-18 21:03:53 +00:00
|
|
|
if ReadOnly then
|
|
|
|
Exit;
|
2012-09-24 19:30:17 +00:00
|
|
|
if ActiveEvent <> nil then
|
2008-02-03 12:05:55 +00:00
|
|
|
DeleteActiveEvent (True);
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
2016-06-18 21:03:53 +00:00
|
|
|
procedure TVpWeekView.PopupEditEvent(Sender: TObject);
|
2008-02-03 12:05:55 +00:00
|
|
|
begin
|
2016-06-18 21:03:53 +00:00
|
|
|
if ReadOnly then
|
|
|
|
Exit;
|
2012-09-24 19:30:17 +00:00
|
|
|
if ActiveEvent <> nil then
|
2008-02-03 12:05:55 +00:00
|
|
|
{ edit this Event }
|
|
|
|
wvSpawnEventEditDialog(False);
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
2018-06-12 16:40:51 +00:00
|
|
|
procedure TVpWeekView.EditSelectedEvent(IsNewEvent: Boolean = false);
|
2008-02-03 12:05:55 +00:00
|
|
|
begin
|
2012-09-24 19:30:17 +00:00
|
|
|
if ActiveEvent <> nil then
|
2018-06-12 16:40:51 +00:00
|
|
|
wvSpawnEventEditDialog(IsNewEvent);
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
2016-06-18 21:03:53 +00:00
|
|
|
procedure TVpWeekView.PopupToday(Sender: TObject);
|
2008-02-03 12:05:55 +00:00
|
|
|
begin
|
|
|
|
Date := Now;
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
2016-06-18 21:03:53 +00:00
|
|
|
procedure TVpWeekView.PopupNextWeek(Sender: TObject);
|
2008-02-03 12:05:55 +00:00
|
|
|
begin
|
|
|
|
Date := Date + 7;
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
2016-06-18 21:03:53 +00:00
|
|
|
procedure TVpWeekView.PopupPrevWeek(Sender: TObject);
|
2008-02-03 12:05:55 +00:00
|
|
|
begin
|
|
|
|
Date := Date - 7;
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
2016-06-18 21:03:53 +00:00
|
|
|
procedure TVpWeekView.PopupNextMonth(Sender: TObject);
|
2008-02-03 12:05:55 +00:00
|
|
|
var
|
2016-06-18 21:03:53 +00:00
|
|
|
M, D, Y: Word;
|
2008-02-03 12:05:55 +00:00
|
|
|
begin
|
|
|
|
DecodeDate(Date, Y, M, D);
|
|
|
|
if M = 12 then begin
|
|
|
|
M := 1;
|
|
|
|
Y := Y + 1;
|
|
|
|
end else
|
|
|
|
M := M + 1;
|
2016-09-17 15:48:39 +00:00
|
|
|
if (D > DaysInAMonth(Y, M)) then
|
|
|
|
D := DaysInAMonth(Y, M);
|
2008-02-03 12:05:55 +00:00
|
|
|
|
|
|
|
Date := EncodeDate(Y, M, D);
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
|
|
|
procedure TVpWeekView.PopupPrevMonth(Sender : TObject);
|
|
|
|
var
|
2016-06-18 21:03:53 +00:00
|
|
|
M, D, Y: Word;
|
2008-02-03 12:05:55 +00:00
|
|
|
begin
|
|
|
|
DecodeDate(Date, Y, M, D);
|
|
|
|
if M = 1 then begin
|
|
|
|
M := 12;
|
|
|
|
Y := Y - 1;
|
|
|
|
end else
|
|
|
|
M := M - 1;
|
2016-09-17 15:48:39 +00:00
|
|
|
if (D > DaysInAMonth(Y, M)) then
|
|
|
|
D := DaysInAMonth(Y, M);
|
2008-02-03 12:05:55 +00:00
|
|
|
|
|
|
|
Date := EncodeDate(Y, M, D);
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
2016-06-18 21:03:53 +00:00
|
|
|
procedure TVpWeekView.PopupNextYear(Sender: TObject);
|
2008-02-03 12:05:55 +00:00
|
|
|
var
|
2016-06-18 21:03:53 +00:00
|
|
|
M, D, Y: Word;
|
2008-02-03 12:05:55 +00:00
|
|
|
begin
|
2016-06-18 21:03:53 +00:00
|
|
|
DecodeDate(Date, Y, M, D);
|
|
|
|
Date := EncodeDate(Y + 1, M, 1);
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
2016-06-18 21:03:53 +00:00
|
|
|
procedure TVpWeekView.PopupPrevYear(Sender: TObject);
|
2008-02-03 12:05:55 +00:00
|
|
|
var
|
|
|
|
M, D, Y : Word;
|
|
|
|
begin
|
2016-06-18 21:03:53 +00:00
|
|
|
DecodeDate(Date, Y, M, D);
|
|
|
|
Date := EncodeDate(Y - 1, M, 1);
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
2016-09-10 17:26:42 +00:00
|
|
|
|
2022-07-11 22:59:40 +00:00
|
|
|
procedure TVpWeekView.PopupCustomDate(Sender: TObject);
|
|
|
|
var
|
|
|
|
d: TDate;
|
|
|
|
begin
|
|
|
|
d := Date;
|
|
|
|
if DateDialog(RSSelectCustomDate, d) then
|
|
|
|
Date := d;
|
|
|
|
end;
|
|
|
|
|
2016-09-10 17:26:42 +00:00
|
|
|
procedure TVpWeekView.PopupPickResourceGroupEvent(Sender: TObject);
|
|
|
|
begin
|
2016-09-10 18:27:50 +00:00
|
|
|
Datastore.Resource.Group := TVpResourceGroup(TMenuItem(Sender).Tag);
|
2016-09-10 17:26:42 +00:00
|
|
|
Datastore.UpdateGroupEvents;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TVpWeekView.PopupDropDownEvent(Sender: TObject);
|
|
|
|
begin
|
|
|
|
InitializeDefaultPopup;
|
|
|
|
end;
|
2008-02-03 12:05:55 +00:00
|
|
|
|
2018-05-17 16:35:44 +00:00
|
|
|
procedure TVpWeekView.wvSpawnEventEditDialog(IsNewEvent: Boolean);
|
2008-02-03 12:05:55 +00:00
|
|
|
var
|
|
|
|
AllowIt: Boolean;
|
|
|
|
EventDlg : TVpEventEditDialog;
|
|
|
|
begin
|
|
|
|
if DataStore = nil then Exit;
|
|
|
|
|
2018-05-17 16:35:44 +00:00
|
|
|
if (not IsNewEvent) and (not ActiveEvent.CanEdit) then begin
|
2016-09-10 19:06:41 +00:00
|
|
|
MessageDlg(RSCannotEditOverlayedEvent, mtInformation, [mbOk], 0);
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
|
2008-02-03 12:05:55 +00:00
|
|
|
AllowIt := false;
|
|
|
|
if Assigned(FOwnerEditEvent) then
|
2018-05-17 16:35:44 +00:00
|
|
|
FOwnerEditEvent(self, ActiveEvent, IsNewEvent, DataStore.Resource, AllowIt)
|
2008-02-03 12:05:55 +00:00
|
|
|
else begin
|
|
|
|
EventDlg := TVpEventEditDialog.Create(nil);
|
|
|
|
try
|
|
|
|
EventDlg.DataStore := DataStore;
|
2016-07-16 10:44:10 +00:00
|
|
|
EventDlg.TimeFormat := FTimeFormat;
|
|
|
|
AllowIt := EventDlg.Execute(ActiveEvent);
|
2008-02-03 12:05:55 +00:00
|
|
|
finally
|
|
|
|
EventDlg.Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if AllowIt then begin
|
2012-09-24 19:30:17 +00:00
|
|
|
ActiveEvent.Changed := true;
|
2008-02-03 12:05:55 +00:00
|
|
|
DataStore.PostEvents;
|
2018-05-17 16:35:44 +00:00
|
|
|
if IsNewEvent and Assigned(FOnAddEvent) then
|
2012-09-24 19:30:17 +00:00
|
|
|
FOnAddEvent(self, ActiveEvent);
|
2022-06-12 16:12:31 +00:00
|
|
|
if not IsNewEvent and Assigned(FOnModifyEvent) then
|
|
|
|
FOnModifyEvent(self, ActiveEvent);
|
2008-02-03 12:05:55 +00:00
|
|
|
end else begin
|
2018-05-17 16:35:44 +00:00
|
|
|
if IsNewEvent then begin
|
2012-09-24 19:30:17 +00:00
|
|
|
DataStore.Resource.Schedule.DeleteEvent(ActiveEvent);
|
|
|
|
ActiveEvent := nil;
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
DataStore.PostEvents;
|
|
|
|
end;
|
2018-05-17 16:35:44 +00:00
|
|
|
Invalidate;
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
|
|
|
{$IFNDEF LCL}
|
|
|
|
procedure TVpWeekView.CMWantSpecialKey(var Msg: TCMWantSpecialKey);
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
Msg.Result := 1;
|
|
|
|
end;
|
|
|
|
{$ENDIF}
|
|
|
|
{=====}
|
|
|
|
|
|
|
|
procedure TVpWeekView.wvSetDateByCoord(Point: TPoint);
|
|
|
|
var
|
|
|
|
I: Integer;
|
|
|
|
begin
|
2016-06-18 21:03:53 +00:00
|
|
|
for I := 0 to pred(Length(wvWeekdayArray)) do
|
2016-06-29 21:46:53 +00:00
|
|
|
if PointInRect(Point, wvWeekdayArray[I].Rec) then
|
|
|
|
begin
|
2016-06-18 21:03:53 +00:00
|
|
|
Date := wvWeekdayArray[I].Day;
|
|
|
|
Invalidate;
|
|
|
|
Exit;
|
|
|
|
end;
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
|
|
|
function TVpWeekView.EventAtCoord(Pt: TPoint): Boolean;
|
|
|
|
var
|
|
|
|
I: Integer;
|
|
|
|
begin
|
|
|
|
result := false;
|
|
|
|
for I := 0 to pred(Length(wvEventArray)) do begin
|
2016-07-05 08:42:08 +00:00
|
|
|
// We've hit the end of visible events without finding a match
|
|
|
|
if wvEventArray[I].Event = nil then
|
2016-07-05 10:20:36 +00:00
|
|
|
Break;
|
2008-02-03 12:05:55 +00:00
|
|
|
|
2016-07-05 08:42:08 +00:00
|
|
|
// Point falls inside this event's rectangle
|
2016-06-29 21:46:53 +00:00
|
|
|
if PointInRect(Pt, wvEventArray[I].Rec) then
|
|
|
|
begin
|
2008-02-03 12:05:55 +00:00
|
|
|
wvHotPoint := Pt;
|
2012-09-24 19:30:17 +00:00
|
|
|
ActiveEvent := TVpEvent(wvEventArray[I].Event);
|
2008-02-03 12:05:55 +00:00
|
|
|
wvActiveEventRec := wvEventArray[I].Rec;
|
|
|
|
result := true;
|
|
|
|
Exit;
|
|
|
|
end;
|
|
|
|
end;
|
2016-07-05 10:20:36 +00:00
|
|
|
|
|
|
|
// Not found
|
|
|
|
ActiveEvent := nil;
|
|
|
|
wvActiveEventRec.Top := 0;
|
|
|
|
wvActiveEventRec.Bottom := 0;
|
|
|
|
wvActiveEventRec.Right := 0;
|
|
|
|
wvActiveEventRec.Left := 0;
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
2016-09-11 17:53:51 +00:00
|
|
|
|
|
|
|
function TVpWeekView.GetEventAtCoord(Pt: TPoint): TVpEvent;
|
|
|
|
var
|
|
|
|
i: Integer;
|
|
|
|
begin
|
|
|
|
for i:=0 to High(wvEventArray) do begin
|
|
|
|
// We've hit the end of visible events without finding a match
|
|
|
|
if wvEventArray[i].Event = nil then
|
|
|
|
Break;
|
|
|
|
|
|
|
|
// Point falls inside this event's rectangle
|
|
|
|
if PointInRect(Pt, wvEventArray[i].Rec) then
|
|
|
|
begin
|
|
|
|
Result := wvEventArray[i].Event;
|
|
|
|
Exit;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
Result := nil;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TVpWeekView.GetEventRect(AEvent: TVpEvent): TRect;
|
|
|
|
var
|
|
|
|
i: Integer;
|
|
|
|
begin
|
|
|
|
for i:=0 to High(wvEventArray) do
|
|
|
|
if wvEventArray[i].Event = AEvent then begin
|
|
|
|
Result := wvEventArray[i].Rec;
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2008-02-03 12:05:55 +00:00
|
|
|
{=====}
|
|
|
|
|
2016-07-05 08:42:08 +00:00
|
|
|
{ This is the timer event which spawns an in-place editor.
|
|
|
|
If the event is double-clicked before this timer fires, then the event is
|
|
|
|
edited in a dialog based editor. }
|
2008-02-03 12:05:55 +00:00
|
|
|
procedure TVpWeekView.wvEditInPlace(Sender: TObject);
|
|
|
|
begin
|
|
|
|
wvClickTimer.Enabled := false;
|
|
|
|
EditEvent;
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
|
|
|
procedure TVpWeekView.EditEvent;
|
|
|
|
var
|
|
|
|
AllowIt: Boolean;
|
|
|
|
begin
|
2012-09-24 19:30:17 +00:00
|
|
|
if ActiveEvent <> nil then begin
|
2016-09-10 19:06:41 +00:00
|
|
|
if (not FAllowInplaceEdit) or (not ActiveEvent.CanEdit) then
|
2016-06-23 23:16:34 +00:00
|
|
|
exit;
|
|
|
|
|
2008-02-03 12:05:55 +00:00
|
|
|
AllowIt := true;
|
|
|
|
{ call the user defined BeforeEdit event }
|
|
|
|
if Assigned(FBeforeEdit) then
|
2012-09-24 19:30:17 +00:00
|
|
|
FBeforeEdit(Self, ActiveEvent, AllowIt);
|
2008-02-03 12:05:55 +00:00
|
|
|
|
|
|
|
if AllowIt then begin
|
|
|
|
{ create and spawn the in-place editor }
|
2016-06-10 01:39:39 +00:00
|
|
|
if wvInplaceEditor = nil then begin
|
|
|
|
wvInPlaceEditor := TVpWvInPlaceEdit.Create(Self);
|
|
|
|
wvInPlaceEditor.Parent := self;
|
|
|
|
wvInPlaceEditor.OnExit := EndEdit;
|
|
|
|
end;
|
2016-07-05 08:42:08 +00:00
|
|
|
if ActiveEvent.AllDayEvent then
|
|
|
|
wvInPlaceEditor.SetBounds(
|
|
|
|
wvActiveEventRec.Left + TextMargin,
|
|
|
|
wvActiveEventRec.Top,
|
|
|
|
wvActiveEventRec.Right - TextMargin * 3,
|
|
|
|
wvActiveEventRec.Bottom - TextMargin * 2
|
|
|
|
)
|
|
|
|
else
|
|
|
|
wvInPlaceEditor.SetBounds(
|
|
|
|
wvActiveEventRec.Left + TextMargin,
|
|
|
|
wvActiveEventRec.Top,
|
|
|
|
wvActiveEventRec.Right - TextMargin * 2,
|
|
|
|
wvActiveEventRec.Bottom - TextMargin * 2
|
|
|
|
);
|
2016-06-10 01:39:39 +00:00
|
|
|
wvInplaceEditor.Show;
|
2012-09-24 19:30:17 +00:00
|
|
|
wvInPlaceEditor.Text := ActiveEvent.Description;
|
2008-02-03 12:05:55 +00:00
|
|
|
Invalidate;
|
2009-12-24 22:41:52 +00:00
|
|
|
wvInPlaceEditor.SetFocus;
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
|
|
|
procedure TVpWeekView.KeyDown(var Key: Word; Shift: TShiftState);
|
|
|
|
var
|
|
|
|
PopupPoint : TPoint;
|
|
|
|
begin
|
|
|
|
case Key of
|
|
|
|
VK_DELETE : DeleteActiveEvent(true);
|
|
|
|
VK_RIGHT : if Shift = [ssShift] then
|
|
|
|
PopupNextWeek (Self)
|
|
|
|
else if (Shift = [ssCtrl]) then
|
|
|
|
PopupNextMonth (Self)
|
|
|
|
else if (Shift = [ssShift, ssCtrl]) then
|
|
|
|
PopupNextYear (Self)
|
|
|
|
else if Shift = [] then begin
|
|
|
|
case DayOfWeek (FActiveDate) of
|
|
|
|
1 : FActiveDate := FActiveDate - 4;
|
|
|
|
2 : FActiveDate := FActiveDate + 3;
|
|
|
|
3 : FActiveDate := FActiveDate + 3;
|
|
|
|
4 : FActiveDate := FActiveDate + 3;
|
|
|
|
5 : FActiveDate := FActiveDate - 3;
|
|
|
|
6 : FActiveDate := FActiveDate - 3;
|
|
|
|
7 : FActiveDate := FActiveDate - 3;
|
|
|
|
end;
|
|
|
|
Invalidate;
|
|
|
|
end;
|
|
|
|
VK_LEFT : if Shift = [ssShift] then
|
|
|
|
PopupPrevWeek (Self)
|
|
|
|
else if (Shift = [ssCtrl]) then
|
|
|
|
PopupPrevMonth (Self)
|
|
|
|
else if (Shift = [ssShift, ssCtrl]) then
|
|
|
|
PopupPrevYear (Self)
|
|
|
|
else if Shift = [] then begin
|
|
|
|
case DayOfWeek (FActiveDate) of
|
|
|
|
1 : FActiveDate := FActiveDate - 4;
|
|
|
|
2 : FActiveDate := FActiveDate + 3;
|
|
|
|
3 : FActiveDate := FActiveDate + 3;
|
|
|
|
4 : FActiveDate := FActiveDate + 3;
|
|
|
|
5 : FActiveDate := FActiveDate - 3;
|
|
|
|
6 : FActiveDate := FActiveDate - 3;
|
|
|
|
7 : FActiveDate := FActiveDate - 3;
|
|
|
|
end;
|
|
|
|
Invalidate;
|
|
|
|
end;
|
|
|
|
VK_UP : begin
|
|
|
|
if Shift = [] then
|
|
|
|
case DayOfWeek (FActiveDate) of
|
|
|
|
1 : FActiveDate := FActiveDate - 1;
|
|
|
|
2 : FActiveDate := FActiveDate + 2;
|
|
|
|
3 : FActiveDate := FActiveDate - 1;
|
|
|
|
4 : FActiveDate := FActiveDate - 1;
|
|
|
|
5 : FActiveDate := FActiveDate + 3;
|
|
|
|
6 : FActiveDate := FActiveDate - 1;
|
|
|
|
7 : FActiveDate := FActiveDate - 1;
|
|
|
|
end;
|
|
|
|
Invalidate;
|
|
|
|
end;
|
|
|
|
VK_DOWN : begin
|
|
|
|
if Shift = [] then
|
|
|
|
case DayOfWeek (FActiveDate) of
|
|
|
|
1 : FActiveDate := FActiveDate - 3;
|
|
|
|
2 : FActiveDate := FActiveDate + 1;
|
|
|
|
3 : FActiveDate := FActiveDate + 1;
|
|
|
|
4 : FActiveDate := FActiveDate - 2;
|
|
|
|
5 : FActiveDate := FActiveDate + 1;
|
|
|
|
6 : FActiveDate := FActiveDate + 1;
|
|
|
|
7 : FActiveDate := FActiveDate + 1;
|
|
|
|
end;
|
|
|
|
Invalidate;
|
|
|
|
end;
|
2016-06-18 21:03:53 +00:00
|
|
|
VK_INSERT : PopupAddEvent(Self);
|
2008-02-03 12:05:55 +00:00
|
|
|
{$IFNDEF LCL}
|
|
|
|
VK_TAB :
|
|
|
|
if ssShift in Shift then
|
2016-06-18 21:03:53 +00:00
|
|
|
Windows.SetFocus(GetNextDlgTabItem(GetParent(Handle), Handle, False))
|
2008-02-03 12:05:55 +00:00
|
|
|
else
|
2016-06-18 21:03:53 +00:00
|
|
|
Windows.SetFocus(GetNextDlgTabItem(GetParent(Handle), Handle, True));
|
2008-02-03 12:05:55 +00:00
|
|
|
{$ENDIF}
|
2016-06-18 21:03:53 +00:00
|
|
|
VK_F10:
|
|
|
|
if (ssShift in Shift) and not Assigned(PopupMenu) then begin
|
2008-02-03 12:05:55 +00:00
|
|
|
PopupPoint := GetClientOrigin;
|
2016-06-18 21:03:53 +00:00
|
|
|
FDefaultPopup.Popup(PopupPoint.x + 10, PopupPoint.y + 10);
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
2016-06-18 21:03:53 +00:00
|
|
|
VK_APPS:
|
2008-02-03 12:05:55 +00:00
|
|
|
if not Assigned (PopupMenu) then begin
|
|
|
|
PopupPoint := GetClientOrigin;
|
2016-06-18 21:03:53 +00:00
|
|
|
FDefaultPopup.Popup(PopupPoint.x + 10, PopupPoint.y + 10);
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
|
|
|
procedure TVpWeekView.EndEdit(Sender: TObject);
|
|
|
|
begin
|
2016-06-18 23:31:19 +00:00
|
|
|
if (wvInPlaceEditor <> nil) and wvInplaceEditor.Visible and (ActiveEvent <> nil)
|
|
|
|
then begin
|
2012-09-24 19:30:17 +00:00
|
|
|
if wvInPlaceEditor.Text <> ActiveEvent.Description then begin
|
|
|
|
ActiveEvent.Description := wvInPlaceEditor.Text;
|
|
|
|
ActiveEvent.Changed := true;
|
2008-02-03 12:05:55 +00:00
|
|
|
if Assigned(FAfterEdit) then
|
2012-09-24 19:30:17 +00:00
|
|
|
FAfterEdit(self, ActiveEvent);
|
2008-02-03 12:05:55 +00:00
|
|
|
DataStore.PostEvents;
|
|
|
|
end;
|
2016-06-10 01:39:39 +00:00
|
|
|
wvInplaceEditor.Hide;
|
2008-02-03 12:05:55 +00:00
|
|
|
Invalidate;
|
2009-12-24 22:41:52 +00:00
|
|
|
// SetFocus;
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
end;
|
2016-09-12 22:25:34 +00:00
|
|
|
|
|
|
|
procedure TVpWeekView.MouseEnter;
|
|
|
|
begin
|
|
|
|
FMouseEvent := nil;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TVpWeekView.MouseLeave;
|
|
|
|
begin
|
|
|
|
HideHintWindow;
|
|
|
|
end;
|
2008-02-03 12:05:55 +00:00
|
|
|
|
2016-09-03 21:51:37 +00:00
|
|
|
procedure TVpWeekView.MouseDown(Button: TMouseButton; Shift: TShiftState;
|
|
|
|
X,Y: Integer);
|
|
|
|
var
|
|
|
|
oldDate: TDate;
|
|
|
|
i: Integer;
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
|
|
|
if not Focused then SetFocus;
|
|
|
|
|
|
|
|
{ Left button }
|
|
|
|
if Button = mbLeft then
|
|
|
|
begin
|
|
|
|
if (wvInPlaceEditor <> nil) and wvInPlaceEditor.Visible then
|
|
|
|
EndEdit(Self);
|
|
|
|
|
|
|
|
wvMouseDown := true;
|
|
|
|
wvMouseDownPoint := Point(X, Y);
|
|
|
|
|
|
|
|
if (Y > wvHeaderHeight) then
|
|
|
|
begin
|
|
|
|
{ The mouse click landed inside the client area }
|
|
|
|
oldDate := FActiveDate;
|
|
|
|
wvSetDateByCoord(wvMouseDownPoint);
|
|
|
|
|
|
|
|
{ We must repaint the control here, before evaluation of the click on the
|
|
|
|
events, because if the day has changed by wvSetDateByCoord then events
|
|
|
|
will have different indexes in the event array; and index positions are
|
|
|
|
evaluated during painting. }
|
|
|
|
if oldDate <> FActiveDate then
|
|
|
|
Paint;
|
|
|
|
|
|
|
|
{ If an active event was clicked, then enable the click timer. If the
|
|
|
|
item is double clicked before the click timer fires, then the edit
|
|
|
|
dialog will appear, otherwise the in-place editor will appear. }
|
|
|
|
if EventAtCoord(wvMouseDownPoint) then
|
|
|
|
wvClickTimer.Enabled := true;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ Right button }
|
|
|
|
if Button = mbRight then
|
|
|
|
begin
|
|
|
|
if not Assigned(PopupMenu) then
|
|
|
|
exit;
|
|
|
|
|
|
|
|
{ The mouse click landed inside the client area }
|
|
|
|
wvSetDateByCoord(Point(X, Y));
|
|
|
|
EventAtCoord(Point(X, Y));
|
|
|
|
wvClickTimer.Enabled := false;
|
|
|
|
|
|
|
|
if not Assigned(ActiveEvent) then begin
|
|
|
|
for i := 0 to FDefaultPopup.Items.Count - 1 do
|
|
|
|
if (FDefaultPopup.Items[i].Tag = 1) or (ReadOnly) then
|
|
|
|
FDefaultPopup.Items[i].Enabled := False;
|
|
|
|
end else begin
|
|
|
|
for i := 0 to FDefaultPopup.Items.Count - 1 do
|
|
|
|
FDefaultPopup.Items[i].Enabled := True;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TVpWeekView.MouseMove(Shift: TShiftState; X, Y: Integer);
|
2016-09-11 17:53:51 +00:00
|
|
|
var
|
|
|
|
event: TVpEvent;
|
2016-09-03 21:51:37 +00:00
|
|
|
begin
|
|
|
|
inherited MouseMove(Shift, X, Y);
|
|
|
|
if (FActiveEvent <> nil) and (not ReadOnly) then begin
|
|
|
|
if (not wvDragging) and wvMouseDown and
|
2016-09-10 19:06:41 +00:00
|
|
|
((wvMouseDownPoint.x <> x) or (wvMouseDownPoint.y <> y)) and
|
|
|
|
FActiveEvent.CanEdit
|
2016-09-03 21:51:37 +00:00
|
|
|
then begin
|
|
|
|
wvDragging := true;
|
|
|
|
wvClickTimer.Enabled := false;
|
|
|
|
BeginDrag(true);
|
|
|
|
end;
|
|
|
|
end;
|
2016-09-11 17:53:51 +00:00
|
|
|
|
2016-09-12 22:25:34 +00:00
|
|
|
if ShowHint then
|
|
|
|
begin
|
|
|
|
event := GetEventAtCoord(Point(X, Y));
|
2017-05-25 21:24:23 +00:00
|
|
|
if event = nil then
|
|
|
|
HideHintWindow
|
|
|
|
else if FMouseEvent <> event then begin
|
|
|
|
HideHintWindow;
|
2016-09-12 22:25:34 +00:00
|
|
|
ShowHintWindow(Point(X, Y), event);
|
|
|
|
FMouseEvent := event;
|
|
|
|
end;
|
2016-09-11 17:53:51 +00:00
|
|
|
end;
|
2016-09-03 21:51:37 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TVpWeekView.MouseUp(Button: TMouseButton; Shift: TShiftState;
|
|
|
|
X, Y: Integer);
|
|
|
|
begin
|
|
|
|
inherited MouseUp(Button, Shift, X, Y);
|
|
|
|
if Button = mbLeft then begin
|
|
|
|
wvMouseDownPoint := Point(0, 0);
|
|
|
|
wvMouseDown := false;
|
|
|
|
wvDragging := false;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2018-01-12 11:07:34 +00:00
|
|
|
{$IF VP_LCL_SCALING = 2}
|
|
|
|
procedure TVpWeekView.ScaleFontsPPI(const AToPPI: Integer;
|
|
|
|
const AProportion: Double);
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
DoScaleFontPPI(AllDayEventAttributes.Font, AToPPI, AProportion);
|
|
|
|
DoScaleFontPPI(DayHeadAttributes.Font, AToPPI, AProportion);
|
|
|
|
DoScaleFontPPI(EventFont, AToPPI, AProportion);
|
|
|
|
DoScaleFontPPI(HeadAttributes.Font, AToPPI, AProportion);
|
|
|
|
end;
|
|
|
|
{$ELSEIF VP_LCL_SCALING = 1}
|
2017-05-22 08:11:27 +00:00
|
|
|
procedure TVpWeekView.ScaleFontsPPI(const AProportion: Double);
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
DoScaleFontPPI(AllDayEventAttributes.Font, AProportion);
|
|
|
|
DoScaleFontPPI(DayHeadAttributes.Font, AProportion);
|
|
|
|
DoScaleFontPPI(EventFont, AProportion);
|
|
|
|
DoScaleFontPPI(HeadAttributes.Font, AProportion);
|
|
|
|
end;
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
|
2008-02-03 12:05:55 +00:00
|
|
|
{ TVpWvHeadAttributes }
|
|
|
|
|
|
|
|
constructor TVpWvHeadAttributes.Create(AOwner: TVpWeekView);
|
|
|
|
begin
|
|
|
|
inherited Create;
|
|
|
|
FOwner := AOwner;
|
|
|
|
FColor := clBtnFace;
|
|
|
|
FFont := TVpFont.Create(AOwner);
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
|
|
|
destructor TVpWvHeadAttributes.Destroy;
|
|
|
|
begin
|
|
|
|
FFont.Free;
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
|
|
|
procedure TVpWvHeadAttributes.SetColor(const Value: TColor);
|
|
|
|
begin
|
|
|
|
if FColor <> Value then begin
|
|
|
|
FColor := Value;
|
|
|
|
FOwner.Invalidate;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
|
|
|
procedure TVpWvHeadAttributes.SetFont(Value: TVpFont);
|
|
|
|
begin
|
|
|
|
FFont.Assign(Value);
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
|
|
|
end.
|