From 67811dddf63ec0b4f9c539b5d2caa923df537c22 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Tue, 13 Mar 2018 00:10:34 +0000 Subject: [PATCH] jvcllaz: Add TJvYearGrid git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6241 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../jvcllaz/design/JvJans/images/images.txt | 1 + .../jvcllaz/design/JvJans/images/make_res.bat | 1 + .../design/JvJans/images/tjvyeargrid.bmp | Bin 0 -> 1654 bytes .../jvcllaz/design/JvJans/jvjansreg.pas | 27 + components/jvcllaz/packages/jvjanslazd.lpk | 46 + components/jvcllaz/packages/jvjanslazr.lpk | 44 + components/jvcllaz/resource/jvjansreg.res | Bin 0 -> 1724 bytes components/jvcllaz/run/JvCore/JvJVCLUtils.pas | 8 +- components/jvcllaz/run/JvJans/JvYearGrid.pas | 1618 +++++++++++++++++ .../jvcllaz/run/JvJans/JvYearGridEditForm.lfm | 118 ++ .../jvcllaz/run/JvJans/JvYearGridEditForm.pas | 85 + 11 files changed, 1944 insertions(+), 4 deletions(-) create mode 100644 components/jvcllaz/design/JvJans/images/images.txt create mode 100644 components/jvcllaz/design/JvJans/images/make_res.bat create mode 100644 components/jvcllaz/design/JvJans/images/tjvyeargrid.bmp create mode 100644 components/jvcllaz/design/JvJans/jvjansreg.pas create mode 100644 components/jvcllaz/packages/jvjanslazd.lpk create mode 100644 components/jvcllaz/packages/jvjanslazr.lpk create mode 100644 components/jvcllaz/resource/jvjansreg.res create mode 100644 components/jvcllaz/run/JvJans/JvYearGrid.pas create mode 100644 components/jvcllaz/run/JvJans/JvYearGridEditForm.lfm create mode 100644 components/jvcllaz/run/JvJans/JvYearGridEditForm.pas diff --git a/components/jvcllaz/design/JvJans/images/images.txt b/components/jvcllaz/design/JvJans/images/images.txt new file mode 100644 index 000000000..7ffe3857a --- /dev/null +++ b/components/jvcllaz/design/JvJans/images/images.txt @@ -0,0 +1 @@ +tjvyeargrid.bmp diff --git a/components/jvcllaz/design/JvJans/images/make_res.bat b/components/jvcllaz/design/JvJans/images/make_res.bat new file mode 100644 index 000000000..674a3c543 --- /dev/null +++ b/components/jvcllaz/design/JvJans/images/make_res.bat @@ -0,0 +1 @@ +lazres ../../../resource/jvjansreg.res @images.txt diff --git a/components/jvcllaz/design/JvJans/images/tjvyeargrid.bmp b/components/jvcllaz/design/JvJans/images/tjvyeargrid.bmp new file mode 100644 index 0000000000000000000000000000000000000000..32b379682467fac88189eb846c1c708f58a48ca9 GIT binary patch literal 1654 zcmajdF>>2L3_wvh6q-p26b45iQD_lP zX@$WNNEBL3n5HP^!x2andMr(qY;Xh;g&xZ`B^w-pM4`tgaU~lZfkdIl=L#ho9Dzik z$EQps8ytZ|p~q(~B^w-pM4^{oV69|>BakSx1nUn`%qw@yN21UYDo_|4fkdIlZ!;wu z9Dzik$1imy8ytZ|p~vs$B@qTkAW`VC6;jCtM<7w?u}wJXOy9 ztB!O1zzbKgj6Xkrn5Ku-`TzREMf{!Tn{l2;ysnRT$##FZ80K^{*O|=I(|Ss@Z`OA= y#-YAi)Oj@dNB!!2c>exM%;PNO!%NKf=lat5a+&K_W4GDAiRBM&ZggyJbo>E;gFPw$ literal 0 HcmV?d00001 diff --git a/components/jvcllaz/design/JvJans/jvjansreg.pas b/components/jvcllaz/design/JvJans/jvjansreg.pas new file mode 100644 index 000000000..0f6cbb3aa --- /dev/null +++ b/components/jvcllaz/design/JvJans/jvjansreg.pas @@ -0,0 +1,27 @@ +unit JvJansReg; + +{$mode objfpc}{$H+} + +interface + +uses + SysUtils; + +procedure Register; + +implementation + +{$R ../../resource/jvjansreg.res} + +uses + Classes, JvDsgnConsts, JvYearGrid; + +procedure Register; +begin + RegisterComponents(RsPaletteJvcl, [ + TJvYearGrid + ]); +end; + +end. + diff --git a/components/jvcllaz/packages/jvjanslazd.lpk b/components/jvcllaz/packages/jvjanslazd.lpk new file mode 100644 index 000000000..6685b2ac7 --- /dev/null +++ b/components/jvcllaz/packages/jvjanslazd.lpk @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/components/jvcllaz/packages/jvjanslazr.lpk b/components/jvcllaz/packages/jvjanslazr.lpk new file mode 100644 index 000000000..678f04989 --- /dev/null +++ b/components/jvcllaz/packages/jvjanslazr.lpk @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/components/jvcllaz/resource/jvjansreg.res b/components/jvcllaz/resource/jvjansreg.res new file mode 100644 index 0000000000000000000000000000000000000000..3c12f20cd930310332a07624e679a9ba05912b2c GIT binary patch literal 1724 zcmajfv2GJV5P;!Hga~Cy$|-pOq*S&C351|T2#Ib=9%CM53XA8M4vA-=m`6w(1?Bkf z*2H!a!`^+Kz1j2L?(OPCL=@9BP(3Q&o{PLDGfn66Sw6}a`6}<^jeL^#_#kh0cVAxa z|MrUN%bhcMu{7BEzFp3!&z2G*oDwktzf`5Fq<)oL|NPDX4GtPKQD_kpD5#htkSMf> z3ls(}Jdh~#?zu`dI0A`6i%^wR7#x8_p&6t=VQ>Tzg%;tIRu~+CM4`omVTxit9Dzik z$JA7b21g)K=rL_mqQMbJ6neZ8SE9iYNECX!u27=E5l9qzyvkIf!4XIldc5XRqQMbJ z6na?#Yb6>SfkdGtn16_3p1ET_5`~sffx_SjBnmy2&6H?x1QLZFOX^BAI0A`6kLBhe z5e7#fQRuN1Qi%pfAW`VCO-hLdM<7w?WeY_s(clOq3N6L_OB4o2ATb|3ww5Z<;0PoN zJ+_@G(clOq3O%-@E79NxBnmyYYbep+2qX$UwsI=b;0PoNJ+^r%(clQAT;EQz<-VXl zz8uRre_*JAWBJxh@?(8aR;$(B?@P=uKb|G4&Gx99-Nl?|FgG`cL!y2%zdq3q`GZN__a^_yKRF)m mfA&O~`&rW4eVMQC^GoCYXU;!a)>oTHWm&= 0) and (ARow >= 0) then + begin + S := S + FYearData[ACol, ARow].InfoText; + if S <> '' then + begin + HintInfo.CursorRect := CellRect(ACol, ARow); + HintStr := S; + CanShow := True; + end; + end; + end; +end; + +procedure TJvYearGrid.MakeHTML(AList: TStringList; Border, Filter: Boolean); +var + ACol, ARow, W: Integer; + DS, Tbs, Infs: string; + Month, Day: Word; + ADate: TDate; + CanAdd: Boolean; +begin + AList.Clear; + if Border then + Tbs := '1' + else + Tbs := '0'; + AList.Append('Year ' + IntToStr(Year) + ''); + AList.Append(''); + AList.Append(''); + AList.Append('

Year ' + IntToStr(Year) + '

'); + AList.Append(''); + for ARow := 1 to 12 do + for ACol := 1 to 37 do + begin + CanAdd := FYearData[ACol, ARow].DisplayText <> ''; + if CanAdd then + CanAdd := FYearData[ACol, ARow].InfoText <> ''; + if CanAdd and Filter then + CanAdd := FYearData[ACol, ARow].BookMark; + if CanAdd then + begin + Month := ARow; + Day := StrToInt(FYearData[ACol, ARow].DisplayText); + ADate := EncodeDate(Year, Month, Day); + DS := FormatDateTime('d-mmm-yyyy', ADate); + W := DayOfWeek(ADate); + DS := FormatSettings.ShortDayNames[W] + ' ' + DS; + AList.Append(''); + AList.Append(''); + Infs := FYearData[ACol, ARow].InfoText; + Infs := StringReplace(Infs, Cr, '
', [rfReplaceAll]); + AList.Append(''); + AList.Append(''); + end; + end; + AList.Append('
' + DS + '' + Infs + '
'); + AList.Append('
'); +end; + +procedure TJvYearGrid.SaveAsHTML(Sender: TObject); +var + List: TStringList; + FileName: string; +begin + List := TStringList.Create; + MakeHTML(List, HTMLBorder, False); + FileName := ChangeFileExt(FYearFile, '.htm'); + List.SaveToFile(FileName); + List.Free; + Launch(FileName); +end; + +procedure TJvYearGrid.SetHTMLBorder(const Value: Boolean); +begin + FHTMLBorder := Value; +end; + +procedure TJvYearGrid.SetYearChanged(const Value: TOnYearChanged); +begin + FOnYearChanged := Value; +end; + +procedure TJvYearGrid.SetYear(const Value: Integer); +var + AYear, AMonth, ADay: Word; +begin + if Value <> FYear then + begin + FYear := Value; + if Value = 0 then + begin + DecodeDate(Now, AYear, AMonth, ADay); + FYear := AYear; + end + else + FYear := Value; + SetupYearData; + + if Assigned(FOnYearChanged) then + FOnYearChanged(Self, FYear); + end; +end; + +procedure TJvYearGrid.SaveYear(FileName: string); +var + MonthIndex, DayIndex: Integer; + YList, DList: TStringList; + S: string; +begin + YList := TStringList.Create; + DList := TStringList.Create; + try + for MonthIndex := 0 to 12 do + begin + for DayIndex := 0 to 37 do + begin + DList.Clear; + DList.Append(FYearData[DayIndex, MonthIndex].DisplayText); + S := FYearData[DayIndex, MonthIndex].InfoText; + S := StringReplace(S, Cr, '||', [rfReplaceAll]); + DList.Append(S); + DList.Append(ColorToString(FYearData[DayIndex, MonthIndex].DefaultColor)); + DList.Append(ColorToString(FYearData[DayIndex, MonthIndex].CustomColor)); + if FYearData[DayIndex, MonthIndex].Custom then + S := 'true' + else + S := 'false'; + DList.Append(S); + YList.Append(DList.CommaText); + end; + end; + if FileName = '' then + YList.SaveToFile(FYearFile) + else + YList.SaveToFile(FileName); + finally + DList.Free; + YList.Free; + end; +end; + +procedure TJvYearGrid.LoadYear(FileName: string); +var + MonthIndex, DayIndex, Index: Integer; + YList, DList: TStringList; + S: string; +begin + YList := TStringList.Create; + DList := TStringList.Create; + try + if FileName = '' then + YList.LoadFromFile(FYearFile) + else + YList.LoadFromFile(FileName); + + Index := 0; + for MonthIndex := 0 to 12 do + begin + for DayIndex := 0 to 37 do + begin + DList.CommaText := YList[Index]; + Inc(Index); + FYearData[DayIndex, MonthIndex].DisplayText := DList[0]; + S := DList[1]; + S := StringReplace(S, '||', Cr, [rfReplaceAll]); + FYearData[DayIndex, MonthIndex].InfoText := S; + FYearData[DayIndex, MonthIndex].DefaultColor := StringToColor(DList[2]); + FYearData[DayIndex, MonthIndex].CustomColor := StringToColor(DList[3]); + FYearData[DayIndex, MonthIndex].Custom := (DList[4] = 'true'); + end; + end; + finally + DList.Free; + YList.Free; + end; + Invalidate; +end; + +procedure TJvYearGrid.SetupYearData; +var + S, D: string; + DayOfWeekIndex, DayIndex, MonthIndex: Integer; + AColor: TColor; +begin + SetupMonths; + for MonthIndex := 0 to 12 do + for DayIndex := 0 to 37 do + begin + S := ''; + if DayIndex > 0 then + begin + // This gives a value from 1 to 7, with 1 being the first day + // of the week. + DayOfWeekIndex := ((DayIndex - 1) mod 7) + 1; + + // As ShortDayNames considers the first day to be a Sunday, + // we have to offset the value of DayOfTheWeekIndex to match the + // desired first day of the week + Inc(DayOfWeekIndex, Integer(FFirstDayOfWeek)+1); + If DayOfWeekIndex > 7 then + DayOfWeekIndex := DayOfWeekIndex - 7; + case FDayFormat of + dfInitial: D := FormatSettings.ShortDayNames[DayOfWeekIndex][1]; + dfShort : D := FormatSettings.ShortDayNames[DayOfWeekIndex]; + dfLong : D := FormatSettings.LongDayNames[DayOfWeekIndex]; + end; + end; + + // By default, there is no day in the current cell + FYearData[DayIndex, MonthIndex].DayInMonth := 0; + + if (MonthIndex = 0) and (DayIndex = 0) then + S := IntToStr(Year); + if (MonthIndex = 0) and (DayIndex > 0) then + S := D; + if (MonthIndex <> 0) and (DayIndex = 0) then + case FMonthFormat of + mfShort: S := FormatSettings.ShortMonthNames[MonthIndex]; + mfLong : S := FormatSettings.LongMonthNames[MonthIndex]; + end; + if (MonthIndex <> 0) and (DayIndex > 0) then + begin + if (DayIndex >= StartDays[MonthIndex]) and (DayIndex < StartDays[MonthIndex] + DaysInMonth[MonthIndex]) then + begin + FYearData[DayIndex, MonthIndex].DayInMonth := DayIndex - StartDays[MonthIndex] + 1; + S := IntToStr(FYearData[DayIndex, MonthIndex].DayInMonth); + end; + end; + + // AColor might have not been initialized with the following code. + //if ((ACol>0)and (D='S')) then + // AColor:=clsilver; + //if ((ACol>0)and (D<>'S')) then + // AColor:=clwhite; + // Change to: + if (DayIndex > 0) and (DayOfWeekIndex in [1, 7]) then //(D = 'S') then + AColor := FWeekendColor + else + AColor := clWhite; + FYearData[DayIndex, MonthIndex].DisplayText := S; + FYearData[DayIndex, MonthIndex].InfoText := ''; + FYearData[DayIndex, MonthIndex].DefaultColor := AColor; + FYearData[DayIndex, MonthIndex].CustomColor := AColor; + FYearData[DayIndex, MonthIndex].Custom := False; + FYearData[DayIndex, MonthIndex].BookMark := False; + end; + AdjustBounds; + Invalidate; +end; + +procedure TJvYearGrid.ClearBookMarks; +var + ACol, ARow: Integer; + Cleared: Boolean; +begin + Cleared := False; + for ARow := 0 to 12 do + for ACol := 0 to 37 do + begin + Cleared := Cleared or FYearData[ACol, ARow].BookMark; + FYearData[ACol, ARow].BookMark := False; + end; + if Cleared then + Invalidate; +end; + +procedure TJvYearGrid.SetupMonths; +var + AYear, AMonth, ADay: Word; + ADate: TDate; + I: Integer; +begin + for I := 1 to 12 do + begin + AYear := Self.Year; + AMonth := I + 1; + if AMonth = 13 then + begin + AYear := AYear + 1; + AMonth := 1; + end; + ADay := 1; + ADate := EncodeDate(AYear, AMonth, ADay); + ADate := ADate - 1; + DecodeDate(ADate, AYear, AMonth, ADay); + DaysInMonth[I] := ADay; + AYear := Self.Year; + AMonth := I; + ADay := 1; + ADate := EncodeDate(AYear, AMonth, ADay); + StartDays[I] := DayOfWeek(ADate); + Dec(StartDays[I], Integer(FFirstDayOfWeek)+1); + If StartDays[I] < 1 then + StartDays[I] := StartDays[I] + 7; + end; +end; + +function TJvYearGrid.GetCellData(var S: string): Boolean; +var + ACol, ARow: Integer; +begin + ACol := Col; + ARow := Row; + Result := False; + if (ACol > 0) and (ARow > 0) then + if FYearData[ACol, ARow].DisplayText <> '' then + begin + S := FYearData[ACol, ARow].InfoText; + Result := True; + end; +end; + +function TJvYearGrid.SetCellData(S: string): Boolean; +var + ACol, ARow: Integer; +begin + ACol := Col; + ARow := Row; + Result := False; + if (ACol > 0) and (ARow > 0) then + if FYearData[ACol, ARow].DisplayText <> '' then + begin + FYearData[ACol, ARow].InfoText := S; + Result := True; + end; +end; + +procedure TJvYearGrid.Copy1Click(Sender: TObject); +var + S: string; +begin + if GetCellData(S) then + Clipboard.AsText := S; +end; + +procedure TJvYearGrid.Cut1Click(Sender: TObject); +var + S: string; +begin + if GetCellData(S) then + begin + Clipboard.AsText := S; + SetCellData(''); + end; +end; + +procedure TJvYearGrid.Year1Click(Sender: TObject); +var + S: string; + AYear: Word; +begin + S := InputBox(RsYearGrid, RsEnterYear, IntToStr(Self.Year)); + try + if S = '' then + Exit; + AYear := StrToInt(S); + if (AYear < 1999) or (AYear > 2050) then + Exit; + Self.Year := AYear; + except + ShowMessage(RsInvalidYear); + end; +end; + +procedure TJvYearGrid.Paste1Click(Sender: TObject); +var + S: string; +begin + if GetCellData(S) then + if Clipboard.HasFormat(CF_TEXT) then + SetCellData(Clipboard.AsText); +end; + +procedure TJvYearGrid.Delete1Click(Sender: TObject); +var + S: string; +begin + if GetCellData(S) then + SetCellData(''); +end; + +procedure TJvYearGrid.CreatePopup; +const + cMenuBreakCaption = '-'; +var + G: TPopupMenu; + M: TMenuItem; +begin + FGridPop := TPopupMenu.Create(Self); + G := FGridPop; + M := TMenuItem.Create(G); + M.Caption := RsYear; + M.OnClick := @Year1Click; + M.Tag := 1; + G.Items.Add(M); + M := TMenuItem.Create(G); + M.Caption := cMenuBreakCaption; + G.Items.Add(M); + M := TMenuItem.Create(G); + M.Caption := RsEdit; + M.OnClick := @Edit1Click; + G.Items.Add(M); + M := TMenuItem.Create(G); + M.Caption := RsColor; + M.OnClick := @Color1Click; + G.Items.Add(M); + M := TMenuItem.Create(G); + M.Caption := RsNoColor; + M.OnClick := @NoColor1Click; + G.Items.Add(M); + M := TMenuItem.Create(G); + M.Caption := cMenuBreakCaption; + G.Items.Add(M); + M := TMenuItem.Create(G); + M.Caption := RsCopyItem; + M.OnClick := @Copy1Click; + G.Items.Add(M); + M := TMenuItem.Create(G); + M.Caption := RsCutItem; + M.OnClick := @Cut1Click; + G.Items.Add(M); + M := TMenuItem.Create(G); + M.Caption := RsPasteItem; + M.OnClick := @Paste1Click; + G.Items.Add(M); + M := TMenuItem.Create(G); + M.Caption := RsDeleteItem; + M.OnClick := @Delete1Click; + G.Items.Add(M); + M := TMenuItem.Create(G); + M.Caption := cMenuBreakCaption; + G.Items.Add(M); + M := TMenuItem.Create(G); + M.Caption := RsSaveAllInfo; + M.OnClick := @SaveAsHTML; + M.Tag := 1; + G.Items.Add(M); + M := TMenuItem.Create(G); + M.Caption := RsSaveFoundInfo; + M.OnClick := @SaveFound; + M.Tag := 1; + G.Items.Add(M); + M := TMenuItem.Create(G); + M.Caption := cMenuBreakCaption; + G.Items.Add(M); + M := TMenuItem.Create(G); + M.Caption := RsBorderColor; + M.OnClick := @BorderColor1Click; + M.Tag := 1; + G.Items.Add(M); + M := TMenuItem.Create(G); + M.Caption := RsBookMarkColor; + M.OnClick := @BookMarkColor1Click; + M.Tag := 1; + G.Items.Add(M); + M := TMenuItem.Create(G); + M.Caption := cMenuBreakCaption; + G.Items.Add(M); + M := TMenuItem.Create(G); + M.Caption := RsFindItem; + M.OnClick := @Find1Click; + M.Tag := 1; + G.Items.Add(M); + M := TMenuItem.Create(G); + M.Caption := RsClearFind; + M.OnClick := @ClearFind1Click; + M.Tag := 1; + G.Items.Add(M); +end; + +procedure TJvYearGrid.Edit1Click(Sender: TObject); +var + DS: string; + lCol, lRow: Integer; + F: TYearGridEditForm; + CanChange: Boolean; + InfoText: string; +begin + lCol := Col; + lRow := Row; + if (lCol < 1) or (lRow < 1) then + Exit; + DS := FYearData[lCol, lRow].DisplayText; + if DS = '' then + Exit; + F := TYearGridEditForm.Create(Application); + try + InfoText := FYearData[lCol, lRow].InfoText; + F.MemoText.Text := InfoText; + F.Caption := 'Edit ' + DateToStr(CellToDate(lCol, lRow)); + if F.ShowModal = mrOk then + begin + InfoText := F.MemoText.Text; + CanChange := True; + if Assigned(FOnInfoChanging) then + FOnInfoChanging(Self, InfoText, CanChange); + if CanChange then + begin + FYearData[lCol, lRow].InfoText := InfoText; + if InfoText = '' then + FYearData[lCol, lRow].Custom := False + else + if not FYearData[lCol, lRow].Custom then + begin + FYearData[lCol, lRow].Custom := True; + FYearData[lCol, lRow].CustomColor := RGB(206, 250, 253); + end; + end; + end; + finally + F.Free; + end; +end; + +procedure TJvYearGrid.Color1Click(Sender: TObject); +var + CD: TColorDialog; +begin + if (Col < 1) or (Row < 1) or (FYearData[Col, Row].DisplayText = '') then + Exit; + CD := TColorDialog.Create(Application); + { -- not available in LCL: + CD.Options := [cdFullOpen, cdAnyColor]; + } + if CD.Execute then + begin + FYearData[Col, Row].CustomColor := CD.Color; + FYearData[Col, Row].Custom := True; + Invalidate; + end; + CD.Free; +end; + +procedure TJvYearGrid.NoColor1Click(Sender: TObject); +begin + if (Col < 1) or (Row < 1) or (FYearData[Col, Row].DisplayText = '') then + Exit; + FYearData[Col, Row].Custom := False; + Invalidate; +end; + +procedure TJvYearGrid.SetupGridPop(Sender: TObject); +var + I: Integer; +begin + if (Col > 0) and (Row > 0) and (FYearData[Col, Row].DisplayText <> '') then + for I := 0 to FGridPop.Items.Count - 1 do + FGridPop.Items[I].Enabled := True + else + for I := 0 to FGridPop.Items.Count - 1 do + FGridPop.Items[I].Enabled := (FGridPop.Items[I].Tag = 1); +end; + +procedure TJvYearGrid.Launch(AFile: string); +begin + OpenDocument(AFile); +end; + +procedure TJvYearGrid.SetHTMLFontName(const Value: string); +begin + FHTMLFontName := Value; +end; + +function TJvYearGrid.GetSelDateText: string; +var + DS: string; +begin + if (Col < 1) or (Row < 1) then + Exit; + DS := FYearData[Col, Row].DisplayText; + if DS = '' then + Exit; + Result := FYearData[Col, Row].InfoText; +end; + +procedure TJvYearGrid.SetSelDateText(AText: string); +var + DS: string; +begin + if (Col < 1) or (Row < 1) then + Exit; + DS := FYearData[Col, Row].DisplayText; + if DS = '' then + Exit; + FYearData[Col, Row].InfoText := AText; +end; + +procedure TJvYearGrid.SetSelectDate(const Value: TOnSelectDate); +begin + FOnSelectDate := Value; +end; + +function TJvYearGrid.SelectCell(ACol, ARow: Longint): Boolean; +var + DS: string; + ADate: TDate; + InfoText: string; + InfoColor: TColor; +// Month, Day: Word; + MonthIndex, DayIndex: Integer; + CanSelect: Boolean; +begin + CanSelect := True; + if Assigned(OnSelectCell) then + OnSelectCell(Self, ACol, ARow, CanSelect); + if not CanSelect then + begin + Result := False; + Exit; + end; + Result := False; + if (ACol < 1) or (ARow < 1) then + Exit; + + ColRowToDayMonthIndex(ACol, ARow, DayIndex, MonthIndex); + + DS := FYearData[DayIndex, MonthIndex].DisplayText; + if DS = '' then + Exit; +// Month := ARow; +// Day := StrToInt(FYearData[ACol, ARow].DisplayText); + ADate := EncodeDate(Year, MonthIndex, FYearData[DayIndex, MonthIndex].DayInMonth); + InfoText := FYearData[DayIndex, MonthIndex].InfoText; + if FYearData[DayIndex, MonthIndex].Custom then + InfoColor := FYearData[DayIndex, MonthIndex].CustomColor + else + InfoColor := FYearData[DayIndex, MonthIndex].DefaultColor; + if Assigned(FOnSelectDate) then + FOnSelectDate(Self, ADate, InfoText, InfoColor); + Result := True; +end; + +procedure TJvYearGrid.DblClick; +begin + if Assigned(OnDblClick) then + OnDblClick(Self) + else + if (Col > 0) and (Row > 0) and (FYearData[Col, Row].DisplayText <> '') then + Edit1Click(nil); +end; + +procedure TJvYearGrid.SetBorderColor(const Value: TColor); +begin + if Value <> FBorderColor then + begin + FBorderColor := Value; + Invalidate; + end; +end; + +procedure TJvYearGrid.BorderColor1Click(Sender: TObject); +var + CD: TColorDialog; +begin + CD := TColorDialog.Create(Application); + { --- not available in LCL + CD.Options := [cdFullOpen, cdAnyColor]; + } + if CD.Execute then + BorderColor := CD.Color; + CD.Free; +end; + +procedure TJvYearGrid.BookMarkColor1Click(Sender: TObject); +var + CD: TColorDialog; +begin + CD := TColorDialog.Create(Application); + { --- not available in LCL + CD.Options := [cdFullOpen, cdAnyColor]; + } + if CD.Execute then + BookMarkColor := CD.Color; + CD.Free; +end; + +procedure TJvYearGrid.SetInfoChanging(const Value: TOnInfoChanging); +begin + FOnInfoChanging := Value; +end; + +function TJvYearGrid.DateToCell(ADate: TDate; out ACol, ARow: Integer): Boolean; +var + AYear, AMonth, ADay: Word; + WD: Integer; +begin + Result := False; + DecodeDate(ADate, AYear, AMonth, ADay); + if AYear <> Self.Year then + Exit; + WD := DayOfWeek(EncodeDate(AYear, AMonth, 1)); + Inc(WD, Integer(FirstDayOfWeek)); + if WD > 7 then + Dec(WD, 7); + DayMonthIndexToColRow(WD + ADay - 1, AMonth, ACol, ARow); + Result := True; +end; + +function TJvYearGrid.CellToDate(ACol, ARow: Integer): TDate; +var + WD: Integer; + lMonth, lDay: Integer; +begin + lMonth := ARow; + ColRowToDayMonthIndex(ACol, ARow, lDay, lMonth); + WD := DayOfWeek(EncodeDate(FYear, lMonth, 1)); + Inc(WD, Integer(FirstDayOfWeek)); + if WD > 7 then + Dec(WD, 7); + lDay := lDay - WD + 2; + if lDay < 1 then lDay := 1; + if lDay > DaysInMonth[lMonth] then lDay := DaysInMonth[lMonth]; + Result := EncodeDate(FYear, lMonth, lDay); +end; + +function TJvYearGrid.GetDateInfo(ADate: TDate; var AText: string): Boolean; +var + lCol, lRow: Integer; +begin + Result := DateToCell(ADate, lCol, lRow); + if Result then + AText := FYearData[lCol, lRow].InfoText; +end; + +function TJvYearGrid.SetDateInfo(ADate: TDate; AText: string): Boolean; +var + lCol, lRow: Integer; +begin + Result := DateToCell(ADate, lCol, lRow); + if Result then + FYearData[lCol, lRow].InfoText := AText; +end; + +procedure TJvYearGrid.SetBookMarkColor(const Value: TColor); +begin + if Value <> FBookMarkColor then + begin + FBookMarkColor := Value; + Invalidate; + end; +end; + +procedure TJvYearGrid.Find1Click(Sender: TObject); +var + S: string; + lCol, lRow: Integer; +begin + ClearBookMarks; + S := InputBox(RsYearGridFind, RsEnterSeachText, ''); + if S = '' then + Exit; + S := LowerCase(S); + for lRow := 0 to 12 do + for lCol := 0 to 37 do + if Pos(S, LowerCase(FYearData[lCol, lRow].InfoText)) > 0 then + FYearData[lCol, lRow].BookMark := True; + Invalidate; +end; + +procedure TJvYearGrid.ClearFind1Click(Sender: TObject); +begin + ClearBookMarks; +end; + +procedure TJvYearGrid.Find; +begin + Find1Click(nil); +end; + +procedure TJvYearGrid.SaveFound(Sender: TObject); +var + List: TStringList; + FileName: string; +begin + List := TStringList.Create; + MakeHTML(List, HTMLBorder, True); + FileName := Format(RsFounds, [ChangeFileExt(FYearFile, '.htm')]); + List.SaveToFile(FileName); + List.Free; + Launch(FileName); +end; + +procedure TJvYearGrid.SetOrientation(const Value: TJvYearGridOrientation); +begin + if FOrientation <> Value then + begin + FOrientation := Value; + if FOrientation = yoHorizontal then + begin + ColCount := 38; + RowCount := 13; + end + else + begin + ColCount := 13; + RowCount := 38; + end; + AdjustBounds; + Invalidate; + end; +end; + +procedure TJvYearGrid.SetFirstDayOfWeek(const Value: TJvWeekDay); +begin + if FFirstDayOfWeek <> Value then + begin + FFirstDayOfWeek := Value; + SetupYearData; + end; +end; + +procedure TJvYearGrid.SetAutoSize(Value: Boolean); +begin + if Value then + begin + if (aoGrid in AutoSizeOptions) then + begin + FSavedScrollBars := ScrollBars; + ScrollBars := ssNone; + end; + end + else + ScrollBars := FSavedScrollBars; + + FAutoSize := Value; + AdjustBounds; +end; + +function TJvYearGrid.GetDefaultColWidth: Integer; +begin + Result := inherited DefaultColWidth; +end; + { +function TJvYearGrid.GetDefaultRowHeight: Integer; +begin + Result := inherited DefaultRowHeight; +end; + } +procedure TJvYearGrid.SetDefaultColWidth(const Value: Integer); +var + SavedFirstColWidth: Integer; +begin + SavedFirstColWidth := ColWidths[0]; + inherited DefaultColWidth := Value; + ColWidths[0] := SavedFirstColWidth; +end; + +procedure TJvYearGrid.SetDefaultRowHeihgt(const Value: Integer); +var + SavedFirstRowHeight: Integer; +begin + SavedFirstRowHeight := RowHeights[0]; + inherited DefaultRowHeight := Value; + RowHeights[0] := SavedFirstRowHeight; +end; + +procedure TJvYearGrid.SetFirstColWidth(const Value: Integer); +begin + ColWidths[0] := Value; +end; + +procedure TJvYearGrid.SetFirstRowHeight(const Value: Integer); +begin + RowHeights[0] := Value; +end; + +procedure TJvYearGrid.SetWeekendColor(const AValue: TColor); +begin + if FWeekendColor <> AValue then begin + FWeekendColor := AValue; + Invalidate; + end; +end; + +procedure TJvYearGrid.SetWeekendDays(const Value: TJvWeekDaySet); +begin + FWeekendDays := Value; +end; + +procedure TJvYearGrid.SetAutoSizeOptions(const Value: TJvAutoSizeOptions); +begin + FAutoSizeOptions := Value; +end; + +procedure TJvYearGrid.UpdateAllSizes; +var + I: Integer; + CurValue: Integer; + MaxValue: Integer; + + function GetHighestTextInRow(Row: Integer): Integer; + var + I: Integer; + CurValue: Integer; + begin + // find the highest text in the row. + Result := 0; + for I := 0 to ColCount-1 do + begin + if Orientation = yoHorizontal then + CurValue := Canvas.TextHeight(FYearData[I,Row].DisplayText) + else + CurValue := Canvas.TextHeight(FYearData[Row,I].DisplayText); + if CurValue > Result then + Result := CurValue; + end; + end; + + function GetWidestTextInColumn(Column: Integer): Integer; + var + I: Integer; + CurValue: Integer; + begin + // find the largest text in the column + Result := 0; + for I := 0 to RowCount-1 do + begin + if Orientation = yoHorizontal then + CurValue := Canvas.TextWidth(FYearData[Column,I].DisplayText) + else + CurValue := Canvas.TextWidth(FYearData[I,Column].DisplayText); + if CurValue > Result then + Result := CurValue; + end; + end; + +begin + if AutoSize then + begin + Canvas.Font.Style := [fsBold]; + if aoFirstRow in AutoSizeOptions then + RowHeights[0] := GetHighestTextInRow(0) + CellMargins.Top + CellMargins.Bottom; + + if aoFirstColumn in AutoSizeOptions then + ColWidths[0] := GetWidestTextInColumn(0) + CellMargins.Left + CellMargins.Right; + + if aoRows in AutoSizeOptions then + begin + // find the highest text in each row and only use the + // highest value among those found + MaxValue := 0; + for I := 1 to RowCount-1 do + begin + CurValue := GetHighestTextInRow(I); + if CurValue > MaxValue then + MaxValue := CurValue; + end; + + for I := 1 to RowCount-1 do + RowHeights[I] := MaxValue + CellMargins.Top + CellMargins.Bottom; + end; + + if aoColumns in AutoSizeOptions then + begin + // find the widest text in each column and only use + // the highest value among those found + MaxValue := 0; + for I := 1 to ColCount-1 do + begin + CurValue := GetWidestTextInColumn(I); + if CurValue > MaxValue then + MaxValue := CurValue; + end; + for I := 1 to ColCount-1 do + ColWidths[I] := MaxValue + CellMargins.Left + CellMargins.Right; + end; + end; +end; + +procedure TJvYearGrid.SetCellMargins(const Value: TJvRect); +begin + FCellMargins.Assign(Value); + AdjustBounds; +end; + +procedure TJvYearGrid.AdjustBounds; +var + NewWidth, NewHeight: Integer; + tmp: Integer; +begin + if not (csReading in ComponentState) and FAutoSize then + begin + UpdateAllSizes; + if aoGrid in AutoSizeOptions then + begin + Scrollbars := ssNone; + ColRowToOffset(true, false, ColCount-1, tmp, NewWidth); + ColRowToOffset(false, false, RowCount-1, tmp, NewHeight); + SetBounds(Left, Top, NewWidth, NewHeight); + end; + end; +end; + +procedure TJvYearGrid.Loaded; +begin + inherited Loaded; + AdjustBounds; +end; + +procedure TJvYearGrid.SetParent( AParent: TWinControl); +begin + inherited SetParent(AParent); + if Parent <> nil then + AdjustBounds; +end; + +procedure TJvYearGrid.CellMarginsChange(Sender: TObject); +begin + AdjustBounds; + Invalidate; +end; + +procedure TJvYearGrid.SetDayFormat(const AValue: TJvDayFormat); +begin + if FDayFormat <> AValue then + begin + FDayFormat := AValue; + SetupYearData; + AdjustBounds; + Invalidate; + end; +end; + +procedure TJvYearGrid.SetDayNamesAlignment(const Value: TAlignment); +begin + if FDayNamesAlignment <> Value then + begin + FDayNamesAlignment := Value; + Invalidate; + end; +end; + +procedure TJvYearGrid.SetDaysAlignment(const Value: TAlignment); +begin + if FDaysAlignment <> Value then + begin + FDaysAlignment := Value; + Invalidate; + end; +end; + +procedure TJvYearGrid.SetMonthFormat(const AValue: TJvMonthFormat); +begin + if FMonthFormat <> AValue then + begin + FMonthFormat := AValue; + SetupYearData; + AdjustBounds; + Invalidate; + end; +end; + +procedure TJvYearGrid.SetMonthNamesAlignment(const Value: TAlignment); +begin + if FMonthNamesAlignment <> Value then + begin + FMonthNamesAlignment := Value; + Invalidate; + end; +end; + +procedure TJvYearGrid.SetYearAlignment(const Value: TAlignment); +begin + if FYearAlignment <> Value then + begin + FYearAlignment := Value; + Invalidate; + end; +end; + +function TJvYearGrid.GetFirstColWidth: Integer; +begin + Result := ColWidths[0]; +end; + +function TJvYearGrid.GetFirstRowHeight: Integer; +begin + Result := RowHeights[0]; +end; + +function TJvYearGrid.GetFlat: Boolean; +begin + Result := inherited Flat; +end; + +procedure TJvYearGrid.SetFlat(AValue: Boolean); +begin + inherited Flat := AValue; + AdjustBounds; +end; + +function TJvYearGrid.IsCurrentYear: Boolean; +begin + Result := Year = FCurrentYear; +end; + +procedure TJvYearGrid.ReadGridYear(Reader: TReader); +begin + Year := Reader.ReadInteger; +end; + +procedure TJvYearGrid.WriteGridYear(Writer: TWriter); +begin + // Do nothing, we only provide read support for legacy reasons +end; + +procedure TJvYearGrid.DefineProperties(Filer: TFiler); +begin + inherited; + Filer.DefineProperty('GridYear', @ReadGridYear, @WriteGridYear, False); +end; + +procedure TJvYearGrid.ColRowToDayMonthIndex(ACol, ARow: Integer; + out DayIndex, MonthIndex: Integer); +begin + if Orientation = yoHorizontal then + begin + DayIndex := ACol; + MonthIndex := ARow; + end + else + begin + DayIndex := ARow; + MonthIndex := ACol; + end; +end; + +procedure TJvYearGrid.DayMonthIndexToColRow(DayIndex, MonthIndex: Integer; + out ACol, ARow: Integer); +begin + if Orientation = yoHorizontal then + begin + ACol := DayIndex; + ARow := MonthIndex; + end + else + begin + ARow := DayIndex; + ACol := MonthIndex; + end; +end; + +procedure TJvYearGrid.ColRowToDayMonth(ACol, ARow: Integer; var ADay, + AMonth: Integer); +var + DayIndex, MonthIndex: Integer; +begin + ColRowToDayMonthIndex(ACol, ARow, DayIndex, MonthIndex); + AMonth := MonthIndex; + ADay := FYearData[MonthIndex, DayIndex].DayInMonth; +end; + +procedure TJvYearGrid.DayMonthToColRow(ADay, AMonth: Integer; var ACol, + ARow: Integer); +begin + DayMonthIndexToColRow(ADay, AMonth, ACol, ARow); +end; + +procedure TJvYearGrid.DoPrepareCanvas(ACol, ARow:Integer; AState: TGridDrawState); +var + DayIndex, MonthIndex: Integer; + S: String; +begin + ColRowToDayMonthIndex(ACol, ARow, DayIndex, MonthIndex); + S := FYearData[DayIndex, MonthIndex].DisplayText; + + with Canvas do + begin + Font.Color := clBlack; + if (ACol = 0) and (ARow = 0) then + Font.Style := Font.Style + [fsBold] + else + Font.Style := Font.Style - [fsBold]; + + if (DayIndex = 0) or (MonthIndex = 0) then + Brush.Color := BorderColor; + + if (DayIndex > 0) and (MonthIndex > 0) then + begin + if IsCurrentYear and (MonthIndex = FCurrentMonth) and (S = IntToStr(FCurrentDay)) then + begin + Font.Color := TodayFontColor; + Brush.Color := TodayBrushColor; + Font.Style := Font.Style + [fsBold]; + end + else + if FYearData[DayIndex, MonthIndex].Custom then + Brush.Color := FYearData[DayIndex, MonthIndex].CustomColor + else + Brush.Color := FYearData[DayIndex, MonthIndex].DefaultColor; + end; + if FYearData[DayIndex, MonthIndex].BookMark then + Brush.Color := BookMarkColor; + end; +end; + +procedure TJvYearGrid.DrawTextInCell(ACol,ARow: Integer; + ARect: TRect; AState: TGridDrawState); +var + DayIndex, MonthIndex: Integer; + S: String; + SExt: TSize; + textLeft: Integer; + + function GetTextLeft(Alignment: TAlignment; AWidth: Integer): Integer; + begin + case Alignment of + taRightJustify: + Result := ARect.Right - AWidth - CellMargins.Right; + taCenter: + Result := ARect.Left + (ARect.Right - ARect.Left - AWidth) div 2; + else + Result := ARect.Left + CellMargins.Left; + end; + end; + +begin + ColRowToDayMonthIndex(ACol, ARow, DayIndex, MonthIndex); + S := FYearData[DayIndex, MonthIndex].DisplayText; + textLeft := ARect.Left; + + with Canvas do + begin + SExt := TextExtent(S); + + if (DayIndex = 0) then + textLeft := GetTextLeft(MonthNamesAlignment, SExt.CX); + + if (MonthIndex = 0) then + begin + if DayIndex = 0 then + textLeft := GetTextLeft(YearAlignment, SExt.CX) + else + textLeft := GetTextLeft(DayNamesAlignment, SExt.CX); + end; + + if (DayIndex > 0) and (MonthIndex > 0) then + textLeft := GetTextLeft(DaysAlignment, SExt.CX); + + TextRect(ARect, textLeft, (ARect.Top + ARect.Bottom - SExt.CY) div 2, S); + end; +end; + +end. diff --git a/components/jvcllaz/run/JvJans/JvYearGridEditForm.lfm b/components/jvcllaz/run/JvJans/JvYearGridEditForm.lfm new file mode 100644 index 000000000..b15d98096 --- /dev/null +++ b/components/jvcllaz/run/JvJans/JvYearGridEditForm.lfm @@ -0,0 +1,118 @@ +object YearGridEditForm: TYearGridEditForm + Left = 303 + Height = 367 + Top = 154 + Width = 394 + BorderStyle = bsDialog + Caption = 'YearGrid Edit' + ClientHeight = 367 + ClientWidth = 394 + Color = clBtnFace + Font.Color = clWindowText + OnShow = FormShow + Position = poScreenCenter + LCLVersion = '1.9.0.0' + object Panel1: TPanel + Left = 0 + Height = 35 + Top = 332 + Width = 394 + Align = alBottom + AutoSize = True + ClientHeight = 35 + ClientWidth = 394 + TabOrder = 0 + object BtnOK: TBitBtn + AnchorSideTop.Control = BitCancel + AnchorSideTop.Side = asrCenter + AnchorSideRight.Control = BitCancel + AnchorSideBottom.Side = asrBottom + Left = 241 + Height = 26 + Top = 4 + Width = 62 + Anchors = [akTop, akRight] + AutoSize = True + BorderSpacing.Left = 16 + BorderSpacing.Right = 4 + Caption = 'OK' + Default = True + Kind = bkOK + ModalResult = 1 + TabOrder = 0 + end + object BitCancel: TBitBtn + AnchorSideTop.Control = Panel1 + AnchorSideTop.Side = asrCenter + AnchorSideRight.Control = Panel1 + AnchorSideRight.Side = asrBottom + Left = 307 + Height = 26 + Top = 4 + Width = 82 + Anchors = [akTop, akRight] + AutoSize = True + BorderSpacing.Top = 4 + BorderSpacing.Right = 4 + BorderSpacing.Bottom = 4 + Cancel = True + Caption = 'Cancel' + Kind = bkCancel + ModalResult = 2 + TabOrder = 1 + end + object BtnLoad: TButton + AnchorSideLeft.Control = Panel1 + AnchorSideTop.Control = BtnOK + AnchorSideBottom.Control = BtnOK + AnchorSideBottom.Side = asrBottom + Left = 5 + Height = 26 + Top = 4 + Width = 61 + Anchors = [akTop, akLeft, akBottom] + AutoSize = True + BorderSpacing.Left = 4 + Caption = '&Load...' + OnClick = BtnLoadClick + TabOrder = 2 + end + object BtnSave: TButton + AnchorSideLeft.Control = BtnLoad + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = BtnLoad + AnchorSideBottom.Control = BtnLoad + AnchorSideBottom.Side = asrBottom + Left = 70 + Height = 26 + Top = 4 + Width = 59 + Anchors = [akTop, akLeft, akBottom] + AutoSize = True + BorderSpacing.Left = 4 + BorderSpacing.Right = 16 + Caption = '&Save...' + OnClick = BtnSaveClick + TabOrder = 3 + end + end + object MemoText: TMemo + Left = 0 + Height = 332 + Top = 0 + Width = 394 + Align = alClient + TabOrder = 1 + end + object OpenDialog: TOpenDialog + Filter = 'Text Files|*.txt|All Files|*.*' + left = 88 + top = 104 + end + object SaveDialog: TSaveDialog + DefaultExt = '.txt' + Filter = 'Text Files|*.txt|All Files|*.*' + left = 120 + top = 104 + end +end diff --git a/components/jvcllaz/run/JvJans/JvYearGridEditForm.pas b/components/jvcllaz/run/JvJans/JvYearGridEditForm.pas new file mode 100644 index 000000000..c51672f28 --- /dev/null +++ b/components/jvcllaz/run/JvJans/JvYearGridEditForm.pas @@ -0,0 +1,85 @@ +{----------------------------------------------------------------------------- +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/MPL-1.1.html + +Software distributed under the License is distributed on an "AS IS" basis, +WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for +the specific language governing rights and limitations under the License. + +The Original Code is: JvYearGridEdit.PAS, released on 2002-06-15. + +The Initial Developer of the Original Code is Jan Verhoeven [jan1 dott verhoeven att wxs dott nl] +Portions created by Jan Verhoeven are Copyright (C) 2002 Jan Verhoeven. +All Rights Reserved. + +Contributor(s): Robert Love [rlove att slcdug dott org]. + +You may retrieve the latest version of this file at the Project JEDI's JVCL home page, +located at http://jvcl.delphi-jedi.org + +Known Issues: +-----------------------------------------------------------------------------} +// $Id$ + +unit JvYearGridEditForm; + +{$mode objfpc}{$H+} + +interface + +uses + SysUtils, Classes, Windows, Messages, Graphics, Controls, + Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, + JvComponent; + +type + TYearGridEditForm = class(TForm) //JvForm) + Panel1: TPanel; + BtnOK: TBitBtn; + BitCancel: TBitBtn; + MemoText: TMemo; + BtnLoad: TButton; + BtnSave: TButton; + OpenDialog: TOpenDialog; + SaveDialog: TSaveDialog; + procedure BtnLoadClick(Sender: TObject); + procedure BtnSaveClick(Sender: TObject); + procedure FormShow(Sender: TObject); + public + end; + + +implementation + +{$R *.lfm} + +procedure TYearGridEditForm.BtnLoadClick(Sender: TObject); +begin + if OpenDialog.Execute then + MemoText.Lines.LoadFromFile(OpenDialog.FileName); + MemoText.SetFocus; +end; + +procedure TYearGridEditForm.BtnSaveClick(Sender: TObject); +begin + if SaveDialog.Execute then + MemoText.Lines.SaveToFile(SaveDialog.FileName); + MemoText.SetFocus; +end; + +procedure TYearGridEditForm.FormShow(Sender: TObject); +begin + MemoText.SetFocus; +end; + +{$IFDEF UNITVERSIONING} +initialization + RegisterUnitVersion(HInstance, UnitVersioning); + +finalization + UnregisterUnitVersion(HInstance); +{$ENDIF UNITVERSIONING} + +end.