diff --git a/Draw.pas b/Draw.pas new file mode 100644 index 0000000..71d9019 --- /dev/null +++ b/Draw.pas @@ -0,0 +1,131 @@ +Unit Draw; + +Interface + +Uses + Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, + Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.Imaging.Pngimage, System.IOUtils, + Vcl.StdCtrls, Vcl.ActnMan, Vcl.ActnColorMaps; + +Type + TDrawForm = class(TForm) + NoteDrawImage: TImage; + ClearCanvas: TButton; + PenColorBox: TColorBox; + Procedure FormCreate(Sender: TObject); + procedure NoteDrawImageMouseMove(Sender: TObject; Shift: TShiftState; X, + Y: Integer); + procedure FormClose(Sender: TObject; var Action: TCloseAction); + procedure ClearCanvasClick(Sender: TObject); + procedure ColorPickerChange(Sender: TObject); + procedure PenColorBoxChange(Sender: TObject); + Private + { Private declarations } + Public + { Public declarations } + End; + +Var + DrawForm: TDrawForm; + +Implementation + +{$R *.dfm} + +Const + FILE_IMAGE: String = '\ReMind\image.png'; + +Var + PenColor: TColor = clBlack; + +Procedure MakeImageSameSizeAsFormIs(NoteDrawImage: TImage); +Begin + NoteDrawImage.Width := DrawForm.Width; + NoteDrawImage.Height := DrawForm.Height; +End; + +Procedure TDrawForm.ClearCanvasClick(Sender: TObject); +Begin + With NoteDrawImage.Canvas do + Begin + Pen.Color := clWhite; + Brush.Color := clWhite; + Rectangle(0, 0, Width, Height); + End; +End; + +Procedure SetPenColor(NoteDrawImage: TImage; ColorPicker: TComboBox); +Begin + PenColor := StringToColor(ColorPicker.Text); +End; + +Procedure TDrawForm.PenColorBoxChange(Sender: TObject); +Begin + PenColor := PenColorBox.Selected; +End; + +Procedure TDrawForm.ColorPickerChange(Sender: TObject); +Begin + //SetPenColor(NoteDrawImage, ColorPicker); +End; + +Procedure TDrawForm.FormClose(Sender: TObject; var Action: TCloseAction); +Var + Bmp: TBitmap; + Png: TPngImage; +Begin + Bmp := TBitmap.Create; + Try + Bmp.SetSize(NoteDrawImage.Canvas.ClipRect.Right, NoteDrawImage.Canvas.ClipRect.Bottom); + BitBlt(Bmp.Canvas.Handle, 0, 0, Width, Height, NoteDrawImage.Canvas.Handle, 0, 0, SRCCOPY); + Png := TPngImage.Create; + Try + Png.Assign(Bmp); + Png.SaveToFile(TPath.GetDocumentsPath + FILE_IMAGE); + Finally + Png.Free; + End; + Finally + Bmp.Free; + End; +End; + +Procedure SetColorPicker(ColorPicker: TComboBox); +Begin + With ColorPicker.Items do + Begin + Add('clBlack'); + Add('clRed'); + Add('clYellow'); + Add('clGreen'); + Add('clBlue'); + Add('clWhite'); + End; +End; + +Procedure TDrawForm.FormCreate(Sender: TObject); +Var + PNG: TPNGObject; +Begin + MakeImageSameSizeAsFormIs(NoteDrawImage); + PNG := TPNGObject.Create; + PNG.LoadFromFile(TPath.GetDocumentsPath + FILE_IMAGE); + NoteDrawImage.Canvas.Draw(0, 0, PNG); + //SetColorPicker(ColorPicker); +End; + +Procedure TDrawForm.NoteDrawImageMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); +Begin + With NoteDrawImage.Canvas do + Begin + If ssLeft in Shift then + Begin + Pixels[X, Y] := PenColor; + Pixels[X + 1, Y] := PenColor; + Pixels[X, Y + 1] := PenColor; + Pixels[X + 1, Y + 1] := PenColor; + End; + End; +End; + +End. diff --git a/Edit.pas b/Edit.pas index 87f09b4..fdfdd3f 100644 --- a/Edit.pas +++ b/Edit.pas @@ -5,7 +5,7 @@ Uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.WinXCalendars, System.DateUtils, - System.Actions, Vcl.ActnList; + System.Actions, Vcl.ActnList, Vcl.ComCtrls, Vcl.WinXPickers; Type TEditForm = class(TForm) @@ -17,7 +17,6 @@ TEditForm = class(TForm) DatePick1: TCalendarPicker; EditButton1: TButton; CloseButton1: TButton; - SelectedRowIndicator: TLabel; EditActionList: TActionList; aSetPriorities: TAction; DeleteButton1: TButton; diff --git a/Main.pas b/Main.pas index 217c15c..5262342 100644 --- a/Main.pas +++ b/Main.pas @@ -6,7 +6,7 @@ Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Menus, Vcl.Grids, Vcl.StdCtrls, System.IOUtils, System.Actions, Vcl.ActnList, System.ImageList, Vcl.ImgList, Vcl.ToolWin, Vcl.ComCtrls, - Vcl.ExtCtrls, Vcl.AppEvnts; + Vcl.ExtCtrls, Vcl.AppEvnts; Type TMainForm = class(TForm) @@ -26,6 +26,10 @@ TMainForm = class(TForm) tbNotes: TToolButton; MainTrayIcon: TTrayIcon; MainApplicationEvents: TApplicationEvents; + aDrawNote: TAction; + tbDrawNote: TToolButton; + aSetNotification: TAction; + tbSetNotification: TToolButton; Procedure FormCreate(Sender: TObject); Procedure FormResize(Sender: TObject); Procedure Settings1Click(Sender: TObject); @@ -40,11 +44,14 @@ TMainForm = class(TForm) Procedure aClearAllExecute(Sender: TObject); Procedure tbDeleteAllClick(Sender: TObject); Procedure aNotesEditorExecute(Sender: TObject); - procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); - procedure MainGridKeyPress(Sender: TObject; var Key: Char); - procedure MainApplicationEventsMinimize(Sender: TObject); - procedure MainTrayIconClick(Sender: TObject); - procedure MainApplicationEventsException(Sender: TObject; E: Exception); + Procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); + Procedure MainGridKeyPress(Sender: TObject; var Key: Char); + Procedure MainApplicationEventsMinimize(Sender: TObject); + Procedure MainApplicationEventsException(Sender: TObject; E: Exception); + Procedure MainTrayIconDblClick(Sender: TObject); + Procedure tbDrawClick(Sender: TObject); + Procedure aDrawNoteExecute(Sender: TObject); + Procedure aSetNotificationExecute(Sender: TObject); Private { Private declarations } Public @@ -58,10 +65,11 @@ TMainForm = class(TForm) {$R *.dfm} -Uses Settings, AddNew, Edit, Notes; +Uses Settings, AddNew, Edit, Notes, Draw, Notification; Const - ProgramVersion = '1.1b'; + + ProgramVersion = '1.2'; PriorityArray: Array[1..3] of String = ('Low', 'Normal', 'High'); FixedRowCaptionsArray: Array[0..3] of String = ('â„–', 'Information', 'Due To', 'Priority'); FILE_INFO: String = '\ReMind\err_log.dat'; @@ -73,7 +81,7 @@ TMainForm = class(TForm) About: String[255]; Priority: Byte; DueTo: TDateTime; - IsDone: Boolean; + IsDone: Boolean; End; TListElem = ^TElement; TElement = Record @@ -89,6 +97,7 @@ TMainForm = class(TForm) Var MainList, SortedList: TList; OrderAsc: Boolean = True; + EditingRowIndicator: Integer; Procedure DeleteList(var GivenList : TList); Var @@ -457,12 +466,12 @@ TMainForm = class(TForm) IsFound: Boolean; Begin IsFound := False; - CurrentElem := SortedList.PFirst; + CurrentElem := SortedList.PLast; While (CurrentElem <> nil) and not IsFound do Begin If CurrentElem.Data.Number = Key then IsFound := True; - CurrentElem := CurrentElem.PNext; + CurrentElem := CurrentElem.PPrev; End; IsAlreadyAdded := IsFound; End; @@ -557,19 +566,13 @@ TMainForm = class(TForm) Case SortBy of 1: If (CompareDescription(IsAsc, ComparingElement.Data.About[1], CurrentElement.Data.About[1]) = 1) and not (IsAlreadyAdded(CurrentElement.Data.Number)) then - Begin ComparingElement := CurrentElement; - End; 2: If (CompareDate(IsAsc, ComparingElement.Data.DueTo, CurrentElement.Data.DueTo) = 1) and not (IsAlreadyAdded(CurrentElement.Data.Number)) then - Begin ComparingElement := CurrentElement; - End; 3: If (ComparePriority(IsAsc, ComparingElement.Data.Priority, CurrentElement.Data.Priority) = 1) and not (IsAlreadyAdded(CurrentElement.Data.Number)) then - Begin ComparingElement := CurrentElement; - End; End; CurrentElement := CurrentElement.PNext; End; @@ -584,7 +587,7 @@ TMainForm = class(TForm) FoundIn, I: Byte; Begin FoundIn := 100; - For I := 0 to 3 do + For I := 0 to MainGrid.ColCount - 1 do Begin If (MainGrid.Cells[I, 0] = FixedRowCaptionsArray[I] + ' â–²') or (MainGrid.Cells[I, 0] = FixedRowCaptionsArray[I] + ' â–¼') then FoundIn := I; @@ -646,7 +649,7 @@ TMainForm = class(TForm) Procedure TMainForm.AddNew1Click(Sender: TObject); Begin - AddNewForm.Show; + AddNewForm.ShowModal; End; Procedure DeleteListItem(var GivenList: TList; var DeletingElem : TListElem); @@ -715,7 +718,7 @@ TMainForm = class(TForm) Var DeletingElement: TListElem; Begin - DeletingElement := GetByNum(MainList, StrToInt(EditForm.SelectedRowIndicator.Caption)); + DeletingElement := GetByNum(MainList, EditingRowIndicator); DeleteListItem(MainList, DeletingElement); SaveList; OrderListAgain; @@ -728,6 +731,11 @@ TMainForm = class(TForm) End; End; +Procedure TMainForm.aDrawNoteExecute(Sender: TObject); +Begin + DrawForm.ShowModal; +End; + Procedure TMainForm.aEditRecordExecute(Sender: TObject); Var CurrentElem: TListElem; @@ -739,7 +747,7 @@ TMainForm = class(TForm) IsAlreadyEdited := False; While (CurrentElem <> nil) and not (IsAlreadyEdited) do Begin - If ElementNumber = StrToInt(EditForm.SelectedRowIndicator.Caption) then + If ElementNumber = EditingRowIndicator then Begin With CurrentElem.Data do Begin @@ -767,13 +775,19 @@ TMainForm = class(TForm) Procedure TMainForm.aNotesEditorExecute(Sender: TObject); Begin - NotesForm.Show; + NotesForm.ShowModal; NotesForm.aStartController.Execute; End; +Procedure TMainForm.aSetNotificationExecute(Sender: TObject); +Begin + NotificationForm.aSetComboBox.Execute; + NotificationForm.ShowModal; +End; + Procedure TMainForm.aSettingsExecute(Sender: TObject); Begin - SettingsForm.Show; + SettingsForm.ShowModal; End; Procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean); @@ -786,9 +800,6 @@ TMainForm = class(TForm) Else Begin CanClose := False; - MainForm.Visible := False; - MainTrayIcon.Icon := Application.Icon; - MainTrayIcon.Visible := True; End; End; @@ -804,9 +815,10 @@ TMainForm = class(TForm) CreateNewFiles(); RewriteGeneralFiles; ReadFileData; - //EditReadOnlyStatus(False); PrintList(MainGrid, MainList); Self.Caption := Self.Caption + ' v' + ProgramVersion; + + aSetNotification.Execute; End; Procedure TMainForm.FormResize(Sender: TObject); @@ -815,8 +827,6 @@ TMainForm = class(TForm) End; Procedure SetEditFormProperties(MainGrid: TStringGrid; Row: Integer); -Var - CaretPosition: TPoint; Begin With EditForm do Begin @@ -831,9 +841,9 @@ TMainForm = class(TForm) PriorityBox1.ItemIndex := 1 Else If Cells[3, Row] = 'Low' then PriorityBox1.ItemIndex := 0; - SelectedRowIndicator.Caption := Cells[0, Row]; + EditingRowIndicator := StrToInt(Cells[0, Row]); End; - Show; + ShowModal; End; End; @@ -845,7 +855,7 @@ TMainForm = class(TForm) Procedure TMainForm.MainApplicationEventsMinimize(Sender: TObject); Begin MainForm.Visible := False; - MainTrayIcon.Icon := Application.Icon; + //MainTrayIcon.Icon := Application.Icon; MainTrayIcon.Visible := True; End; @@ -871,7 +881,6 @@ TMainForm = class(TForm) MainGrid.Cells[ACol, ARow] := FixedRowCaptionsArray[ACol] + ' â–²' Else MainGrid.Cells[ACol, ARow] := FixedRowCaptionsArray[ACol] + ' â–¼'; - OrderAsc := not OrderAsc; PrintList(MainGrid, SortedList); End; If ACol = 0 then @@ -887,8 +896,8 @@ TMainForm = class(TForm) MainGrid.Cells[ACol, ARow] := FixedRowCaptionsArray[ACol] + ' â–²'; PrintListBackwards(MainGrid, MainList, GetListSize(MainList)); End; - OrderAsc := not OrderAsc; End; + OrderAsc := not OrderAsc; End; Procedure TMainForm.MainGridKeyPress(Sender: TObject; var Key: Char); @@ -899,16 +908,18 @@ TMainForm = class(TForm) End; End; -Procedure TMainForm.MainTrayIconClick(Sender: TObject); +Procedure TMainForm.MainTrayIconDblClick(Sender: TObject); Begin - MainTrayIcon.Visible := False; + MainTrayIcon.Visible := False; MainForm.Visible := True; MainForm.WindowState := wsNormal; + MainForm.FormStyle := fsStayOnTop; + MainForm.FormStyle := fsNormal; End; Procedure TMainForm.Settings1Click(Sender: TObject); Begin - SettingsForm.Show; + SettingsForm.ShowModal; End; Procedure TMainForm.tbDeleteAllClick(Sender: TObject); @@ -916,4 +927,9 @@ TMainForm = class(TForm) aClearAll.Execute; End; +Procedure TMainForm.tbDrawClick(Sender: TObject); +Begin + DrawForm.ShowModal; +End; + End. diff --git a/Notification.pas b/Notification.pas new file mode 100644 index 0000000..e433ae2 --- /dev/null +++ b/Notification.pas @@ -0,0 +1,268 @@ +Unit Notification; + +Interface + +Uses + Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, + Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.WinXCalendars, System.IOUtils, + Vcl.WinXPickers, System.Actions, Vcl.ActnList, Vcl.Samples.Spin, DateUtils, Vcl.ExtCtrls, + System.Notification; + +Type + TNotificationForm = class(TForm) + DescriptionComboBox: TComboBox; + CustomDesc: TEdit; + SelectDesc: TLabel; + SelectTime: TLabel; + TimePicker: TTimePicker; + DatePicker: TCalendarPicker; + InformationMemo: TMemo; + AddButton: TButton; + NotificationsActionList: TActionList; + aSetComboBox: TAction; + DeleteSpinEdit: TSpinEdit; + DeleteButton: TButton; + NotificationTime: TTimer; + NotificationCenter: TNotificationCenter; + procedure FormActivate(Sender: TObject); + Procedure aSetComboBoxExecute(Sender: TObject); + Procedure DescriptionComboBoxChange(Sender: TObject); + Procedure AddButtonClick(Sender: TObject); + procedure DeleteButtonClick(Sender: TObject); + procedure NotificationTimeTimer(Sender: TObject); + Private + { Private declarations } + Public + { Public declarations } + End; + +Var + NotificationForm: TNotificationForm; + +Implementation + +{$R *.dfm} + +Uses Main; + +Type + TNotificationInfo = Record + Description: String[255]; + NotificationTime: TDateTime; + End; + +Const + FILE_NOTIFICATIONS: String = '\ReMind\notification.dat'; + +Var + ANotifications: Array of TNotificationInfo; + +Procedure QuickSort(var A: Array of TNotificationInfo; Min, Max: Integer); +Var + I, J: Integer; + Supp: TDateTime; + Temp: TNotificationInfo; +Begin + Supp := A[Max-((max-min) div 2)].NotificationTime; + I := Min; + J := Max; + While I Supp do + J := J - 1; + If i<=j then + Begin + Temp := A[I]; + A[I] := A[J]; + A[J] := Temp; + I := I + 1; + J := J - 1; + End; + End; + If Min < j then + QuickSort(A, min, J); + If I < Max then + QuickSort(A, I, Max); +End; + +Procedure AddNewNotificationToFile(); +Var + FNotification: File of TNotificationInfo; + I: Integer; +Begin + AssignFile(FNotification, TPath.GetDocumentsPath + FILE_NOTIFICATIONS); + Rewrite(FNotification); + For I := 0 to Length(ANotifications) - 1 do + Begin + Write(FNotification, ANotifications[I]); + End; + Close(FNotification); +End; + +Procedure AddNewNotificationToArray(Notification: TNotificationInfo); +Begin + SetLength(ANotifications, Length(ANotifications) + 1); + ANotifications[Length(ANotifications) - 1] := Notification; +End; + +Procedure ReadFileData(); +Var + FNotification: File of TNotificationInfo; + Notification: TNotificationInfo; +Begin + AssignFile(FNotification, TPath.GetDocumentsPath + FILE_NOTIFICATIONS); + If not FileExists(TPath.GetDocumentsPath + FILE_NOTIFICATIONS) then + Begin + Rewrite(FNotification); + End + Else + Reset(FNotification); + + While not Eof(FNotification) do + Begin + Read(FNotification, Notification); + AddNewNotificationToArray(Notification); + End; + Close(FNotification); +End; + +Procedure PrintNotifications(InformationMemo: TMemo); +Var + I: Integer; +Begin + InformationMemo.Clear; + For I := 0 to Length(ANotifications) - 1 do + Begin + With ANotifications[I] do + Begin + InformationMemo.Lines.Add(Description + ' ' + TimeToStr(NotificationTime) + ' • ' + DateToStr(NotificationTime)); + End; + End; +End; + +Procedure SetSpinEditValues(SE: TSpinEdit; DeleteButton: TButton); +Begin + If Length(ANotifications) = 0 then + Begin + SE.Text := '0'; + SE.MinValue := 0; + End + Else + SE.MinValue := 1; + SE.MaxValue := Length(ANotifications); + DeleteButton.Enabled := Length(ANotifications) > 0; +End; + +Procedure TNotificationForm.AddButtonClick(Sender: TObject); +Var + NewNotification: TNotificationInfo; + NotificationTime: TDateTime; +Begin + If DescriptionComboBox.ItemIndex = DescriptionComboBox.Items.Count - 1 then + NewNotification.Description := CustomDesc.Text + Else + NewNotification.Description := DescriptionComboBox.Text; + + ReplaceDate(NewNotification.NotificationTime, DatePicker.Date); + ReplaceTime(NewNotification.NotificationTime, TimePicker.Time); + AddNewNotificationToArray(NewNotification); + AddNewNotificationToFile(); + + QuickSort(ANotifications, 0, Length(ANotifications) - 1); + PrintNotifications(InformationMemo); + + aSetComboBox.Execute; + CustomDesc.Text := ''; + CustomDesc.Visible := False; + SetSpinEditValues(DeleteSpinEdit, DeleteButton); +End; + +Procedure TNotificationForm.aSetComboBoxExecute(Sender: TObject); +Var + I: Integer; +Begin + DescriptionComboBox.Clear; + For I := 1 to MainForm.MainGrid.RowCount - 1 do + Begin + DescriptionComboBox.Items.Add(MainForm.MainGrid.Cells[1, I]); + End; + DescriptionComboBox.Items.Add('Custom...'); + DatePicker.Date := Now; + TimePicker.Time := Now; +End; + +Procedure DeleteArrayElement(DIndex: Integer); +Var + I: Integer; +Begin + For I := DIndex to Length(ANotifications) - 2 do + Begin + ANotifications[I] := ANotifications[I + 1]; + End; + SetLength(ANotifications, Length(ANotifications) - 1); +End; + +Procedure TNotificationForm.DeleteButtonClick(Sender: TObject); +Var + DeletingItem: Integer; +Begin + DeletingItem := StrToInt(DeleteSpinEdit.Text) - 1; + DeleteArrayElement(DeletingItem); + PrintNotifications(InformationMemo); + SetSpinEditValues(DeleteSpinEdit, DeleteButton); + AddNewNotificationToFile(); +End; + +Procedure TNotificationForm.DescriptionComboBoxChange(Sender: TObject); +Begin + CustomDesc.Visible := DescriptionComboBox.ItemIndex = DescriptionComboBox.Items.Count - 1; +End; + +Procedure TNotificationForm.FormActivate(Sender: TObject); +Begin + InformationMemo.Clear; + SetLength(ANotifications, 0); + ReadFileData(); + If Length(ANotifications) <> 0 then + QuickSort(ANotifications, 0, Length(ANotifications) - 1); + PrintNotifications(InformationMemo); + SetSpinEditValues(DeleteSpinEdit, DeleteButton); +End; + +Procedure TNotificationForm.NotificationTimeTimer(Sender: TObject); +Var + Hour, Min, Sec, MSec: Word; + FHour, FMin, FSec, FMSec: Word; + NewTime, ExistingTime: TDateTime; + NewNotification: TNotification; +Begin + If CompareDate(Date, ANotifications[0].NotificationTime) = 0 then + Begin + DecodeTime(Now, Hour, Min, Sec, MSec); + NewTime := EncodeTime(Hour, Min, 0, 0); + ExistingTime := ANotifications[0].NotificationTime; + DecodeTime(ExistingTime, FHour, FMin, FSec, FMSec); + ExistingTime := EncodeTime(FHour, FMin, 0, 0); + If CompareTime(NewTime, ExistingTime) = 0 then + Begin + NewNotification := NotificationCenter.CreateNotification; + Try + NewNotification.Name := 'Name'; + NewNotification.Title := 'Re:Minder Notification'; + With ANotifications[0] do + NewNotification.AlertBody := Description + #13#10 + TimeToStr(NotificationTime) + ' • ' + DateToStr(NotificationTime); + NotificationCenter.PresentNotification(NewNotification); + Finally + NewNotification.Free; + End; + DeleteArrayElement(0); + PrintNotifications(InformationMemo); + SetSpinEditValues(DeleteSpinEdit, DeleteButton); + AddNewNotificationToFile(); + End; + End; +End; + +End.