[453] | 1 | unit fReminderTree;
|
---|
| 2 |
|
---|
| 3 | interface
|
---|
| 4 |
|
---|
| 5 | uses
|
---|
| 6 | Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
|
---|
| 7 | StdCtrls, ORCtrls, ExtCtrls, ComCtrls, ImgList, ORFn, Menus, DKLang;
|
---|
| 8 |
|
---|
| 9 | type
|
---|
| 10 | TfrmReminderTree = class(TForm)
|
---|
| 11 | pnlTop: TPanel;
|
---|
| 12 | tvRem: TORTreeView;
|
---|
| 13 | hcRem: THeaderControl;
|
---|
| 14 | pnlTopRight: TPanel;
|
---|
| 15 | bvlGap: TBevel;
|
---|
| 16 | lbRem: TORListBox;
|
---|
| 17 | mmMain: TMainMenu;
|
---|
| 18 | memAction: TMenuItem;
|
---|
| 19 | memEvalAll: TMenuItem;
|
---|
| 20 | memEval: TMenuItem;
|
---|
| 21 | N2: TMenuItem;
|
---|
| 22 | memRefresh: TMenuItem;
|
---|
| 23 | memEvalCat: TMenuItem;
|
---|
| 24 | mnuCoverSheet: TMenuItem;
|
---|
| 25 | mnuExit: TMenuItem;
|
---|
| 26 | DKLanguageController1: TDKLanguageController;
|
---|
| 27 | procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
| 28 | procedure FormCreate(Sender: TObject);
|
---|
| 29 | procedure tvRemExpanded(Sender: TObject; Node: TTreeNode);
|
---|
| 30 | procedure tvRemCollapsed(Sender: TObject; Node: TTreeNode);
|
---|
| 31 | procedure pnlTopResize(Sender: TObject);
|
---|
| 32 | procedure lbRemDrawItem(Control: TWinControl; Index: Integer;
|
---|
| 33 | Rect: TRect; State: TOwnerDrawState);
|
---|
| 34 | procedure lbRemChange(Sender: TObject);
|
---|
| 35 | procedure lbRemClick(Sender: TObject);
|
---|
| 36 | procedure tvRemEnter(Sender: TObject);
|
---|
| 37 | procedure tvRemExit(Sender: TObject);
|
---|
| 38 | procedure hcRemSectionClick(HeaderControl: THeaderControl;
|
---|
| 39 | Section: THeaderSection);
|
---|
| 40 | procedure tvRemClick(Sender: TObject);
|
---|
| 41 | procedure tvRemChange(Sender: TObject; Node: TTreeNode);
|
---|
| 42 | procedure tvRemMouseDown(Sender: TObject; Button: TMouseButton;
|
---|
| 43 | Shift: TShiftState; X, Y: Integer);
|
---|
| 44 | procedure memEvalClick(Sender: TObject);
|
---|
| 45 | procedure memEvalAllClick(Sender: TObject);
|
---|
| 46 | procedure FormDestroy(Sender: TObject);
|
---|
| 47 | procedure memRefreshClick(Sender: TObject);
|
---|
| 48 | procedure memActionClick(Sender: TObject);
|
---|
| 49 | procedure memEvalCatClick(Sender: TObject);
|
---|
| 50 | procedure mnuCoverSheetClick(Sender: TObject);
|
---|
| 51 | procedure tvRemNodeCaptioning(Sender: TObject; var Caption: String);
|
---|
| 52 | procedure tvRemAddition(Sender: TObject; Node: TTreeNode);
|
---|
| 53 | procedure tvRemDeletion(Sender: TObject; Node: TTreeNode);
|
---|
| 54 | procedure mnuExitClick(Sender: TObject);
|
---|
| 55 | private
|
---|
| 56 | FLinking: boolean;
|
---|
| 57 | FSortOrder: integer;
|
---|
| 58 | FSortAssending: boolean;
|
---|
| 59 | FSorting: boolean;
|
---|
| 60 | FUpdating: boolean;
|
---|
| 61 | memView: TORMenuItem;
|
---|
| 62 | DateColWidth: integer;
|
---|
| 63 | LastDateColWidth: integer;
|
---|
| 64 | PriorityColWidth: integer;
|
---|
| 65 | procedure SetRemHeaderSectionWidth( SectionIndex: integer; NewWidth: integer);
|
---|
| 66 | protected
|
---|
| 67 | procedure Resync(FromTree: boolean);
|
---|
| 68 | procedure RemindersChanged(Sender: TObject);
|
---|
| 69 | procedure ResetlbItems(RootNode: TTreeNode);
|
---|
| 70 | procedure LinkTopControls(FromTree: boolean);
|
---|
| 71 | procedure SyncTopControls(FromTree: boolean);
|
---|
| 72 | procedure SortNode(const Node: TTreeNode);
|
---|
| 73 | function SortData(Node: TORTreeNode): string;
|
---|
| 74 | // procedure PositionToReminder(Sender: TObject);
|
---|
| 75 | procedure ProcessedRemindersChanged(Sender: TObject);
|
---|
| 76 | public
|
---|
| 77 | procedure EnableActions;
|
---|
| 78 | procedure SetFontSize( NewFontSize: integer);
|
---|
| 79 | end;
|
---|
| 80 |
|
---|
| 81 | procedure ViewReminderTree;
|
---|
| 82 |
|
---|
| 83 | var
|
---|
| 84 | frmReminderTree: TfrmReminderTree = nil;
|
---|
| 85 | RemTreeDlgLeft: integer = 0;
|
---|
| 86 | RemTreeDlgTop: integer = 0;
|
---|
| 87 | RemTreeDlgWidth: integer = 0;
|
---|
| 88 | RemTreeDlgHeight: integer = 0;
|
---|
| 89 |
|
---|
| 90 | const
|
---|
| 91 | ReminderTreeName = 'frmReminderTree';
|
---|
| 92 |
|
---|
| 93 | implementation
|
---|
| 94 |
|
---|
| 95 | uses uReminders, dShared, uConst, fReminderDialog, fNotes, rMisc,
|
---|
| 96 | rReminders, fRemCoverSheet, uAccessibleTreeView, uAccessibleTreeNode;
|
---|
| 97 |
|
---|
| 98 | {$R *.DFM}
|
---|
| 99 |
|
---|
| 100 | const
|
---|
| 101 | UnscaledDateColWidth = 70;
|
---|
| 102 | UnscaledLastDateColWidth = 89;
|
---|
| 103 | UnscaledPriorityColWidth = 43;
|
---|
| 104 |
|
---|
| 105 | procedure ViewReminderTree;
|
---|
| 106 |
|
---|
| 107 | begin
|
---|
| 108 | if(not InitialRemindersLoaded) then
|
---|
| 109 | StartupReminders;
|
---|
| 110 | if(not assigned(frmReminderTree)) then
|
---|
| 111 | frmReminderTree := TfrmReminderTree.Create(Application);
|
---|
| 112 | frmReminderTree.Show;
|
---|
| 113 | end;
|
---|
| 114 |
|
---|
| 115 | procedure TfrmReminderTree.FormClose(Sender: TObject;
|
---|
| 116 | var Action: TCloseAction);
|
---|
| 117 | begin
|
---|
| 118 | Action := caFree;
|
---|
| 119 | end;
|
---|
| 120 |
|
---|
| 121 | procedure TfrmReminderTree.FormCreate(Sender: TObject);
|
---|
| 122 | begin
|
---|
| 123 | memView := TORMenuItem.Create(mmMain);
|
---|
| 124 | memView.Caption := '&View';
|
---|
| 125 | memView.Add(TORMenuItem.Create(memView));
|
---|
| 126 | mmMain.Items.Insert(0, memView);
|
---|
| 127 |
|
---|
| 128 | bvlGap.Height := GetSystemMetrics(SM_CYHSCROLL);
|
---|
| 129 | FSortOrder := -1;
|
---|
| 130 | FSortAssending := TRUE;
|
---|
| 131 | SetReminderMenuSelectRoutine(memView);
|
---|
| 132 | NotifyWhenRemindersChange(RemindersChanged);
|
---|
| 133 | // NotifyWhenProcessingReminderChanges(PositionToReminder);
|
---|
| 134 | ProcessedReminders.Notifier.NotifyWhenChanged(ProcessedRemindersChanged);
|
---|
| 135 | SetFontSize(MainFontSize);
|
---|
| 136 | SetReminderFormBounds(Self, 0, 0, Self.Width, Self.Height,
|
---|
| 137 | RemTreeDlgLeft, RemTreeDlgTop, RemTreeDlgWidth, RemTreeDlgHeight);
|
---|
| 138 | TAccessibleTreeView.WrapControl(tvRem);
|
---|
| 139 | end;
|
---|
| 140 |
|
---|
| 141 | procedure TfrmReminderTree.LinkTopControls(FromTree: boolean);
|
---|
| 142 | var
|
---|
| 143 | idx: integer;
|
---|
| 144 |
|
---|
| 145 | begin
|
---|
| 146 | if(not FLinking) then
|
---|
| 147 | begin
|
---|
| 148 | FLinking := TRUE;
|
---|
| 149 | try
|
---|
| 150 | if(FromTree) then
|
---|
| 151 | begin
|
---|
| 152 | if(assigned(tvRem.Selected)) then
|
---|
| 153 | begin
|
---|
| 154 | idx := lbRem.Items.IndexOfObject(tvRem.Selected);
|
---|
| 155 | lbRem.ItemIndex := idx;
|
---|
| 156 | end
|
---|
| 157 | else
|
---|
| 158 | lbRem.ItemIndex := -1;
|
---|
| 159 | end
|
---|
| 160 | else
|
---|
| 161 | begin
|
---|
| 162 | if(lbRem.ItemIndex < 0) then
|
---|
| 163 | tvRem.Selected := nil
|
---|
| 164 | else
|
---|
| 165 | tvRem.Selected := TTreeNode(lbRem.Items.Objects[lbRem.ItemIndex]);
|
---|
| 166 | end;
|
---|
| 167 | finally
|
---|
| 168 | FLinking := FALSE;
|
---|
| 169 | end;
|
---|
| 170 | end;
|
---|
| 171 | end;
|
---|
| 172 |
|
---|
| 173 | procedure TfrmReminderTree.RemindersChanged(Sender: TObject);
|
---|
| 174 | const
|
---|
| 175 | ARTxt = 'Available Reminders';
|
---|
| 176 |
|
---|
| 177 | var
|
---|
| 178 | OldUpdating: boolean;
|
---|
| 179 |
|
---|
| 180 | begin
|
---|
| 181 | EnableActions;
|
---|
| 182 | if(GetReminderStatus = rsNone) then
|
---|
| 183 | begin
|
---|
| 184 | tvRem.Selected := nil;
|
---|
| 185 | Close;
|
---|
| 186 | exit;
|
---|
| 187 | end;
|
---|
| 188 | OldUpdating := FUpdating;
|
---|
| 189 | try
|
---|
| 190 | FUpdating := TRUE;
|
---|
| 191 | lbRem.Items.BeginUpdate;
|
---|
| 192 | try
|
---|
| 193 | try
|
---|
| 194 | BuildReminderTree(tvRem);
|
---|
| 195 | lbRem.Clear;
|
---|
| 196 | ResetlbItems(nil);
|
---|
| 197 | LinkTopControls(TRUE);
|
---|
| 198 | SyncTopControls(TRUE);
|
---|
| 199 | pnlTopResize(Self);
|
---|
| 200 | finally
|
---|
| 201 | FUpdating := FALSE;
|
---|
| 202 | tvRem.Invalidate;
|
---|
| 203 | lbRem.Invalidate;
|
---|
| 204 | end;
|
---|
| 205 | if(RemindersEvaluatingInBackground) then
|
---|
| 206 | hcRem.Sections[0].Text := ARTxt + ' (Evaluating Reminders...)'
|
---|
| 207 | else
|
---|
| 208 | hcRem.Sections[0].Text := ARTxt;
|
---|
| 209 | finally
|
---|
| 210 | lbRem.Items.EndUpdate;
|
---|
| 211 | end;
|
---|
| 212 | finally
|
---|
| 213 | FUpdating := OldUpdating;
|
---|
| 214 | end;
|
---|
| 215 | end;
|
---|
| 216 |
|
---|
| 217 | procedure TfrmReminderTree.ResetlbItems(RootNode: TTreeNode);
|
---|
| 218 | var
|
---|
| 219 | Firsti, i: integer;
|
---|
| 220 | First, Node: TTreeNode;
|
---|
| 221 | sl: TStringList;
|
---|
| 222 | lvl: integer;
|
---|
| 223 | Add2LB: boolean;
|
---|
| 224 | Tmp, Data: string;
|
---|
| 225 |
|
---|
| 226 | function IsVis(Node: TTreeNode): boolean; // IsVisible doesn't work when updating
|
---|
| 227 | begin
|
---|
| 228 | Result := TRUE;
|
---|
| 229 | Node := Node.Parent;
|
---|
| 230 | while(Result and (assigned(Node))) do
|
---|
| 231 | begin
|
---|
| 232 | Result := Node.Expanded;
|
---|
| 233 | Node := Node.Parent;
|
---|
| 234 | end;
|
---|
| 235 | end;
|
---|
| 236 |
|
---|
| 237 | begin
|
---|
| 238 | if(not FSorting) then
|
---|
| 239 | begin
|
---|
| 240 | if(assigned(RootNode)) then
|
---|
| 241 | begin
|
---|
| 242 | Node := RootNode.GetFirstChild;
|
---|
| 243 | lvl := RootNode.Level;
|
---|
| 244 | Add2LB := RootNode.Expanded;
|
---|
| 245 | Firsti := lbRem.Items.IndexOfObject(RootNode)+1;
|
---|
| 246 | end
|
---|
| 247 | else
|
---|
| 248 | begin
|
---|
| 249 | Node := tvRem.Items.GetFirstNode;
|
---|
| 250 | lvl := -1;
|
---|
| 251 | Add2LB := TRUE;
|
---|
| 252 | Firsti := 0;
|
---|
| 253 | end;
|
---|
| 254 | First := Node;
|
---|
| 255 | if(assigned(Node)) then
|
---|
| 256 | begin
|
---|
| 257 | sl := TStringList.Create;
|
---|
| 258 | try
|
---|
| 259 | sl.Assign(lbRem.Items);
|
---|
| 260 | while(assigned(Node) and (Node.Level > lvl)) do
|
---|
| 261 | begin
|
---|
| 262 | i := sl.IndexOfObject(Node);
|
---|
| 263 | if(i >= 0) then
|
---|
| 264 | sl.Delete(i);
|
---|
| 265 | Node := Node.GetNext;
|
---|
| 266 | end;
|
---|
| 267 | if(Add2LB) then
|
---|
| 268 | begin
|
---|
| 269 | i := Firsti;
|
---|
| 270 | Node := First;
|
---|
| 271 | while(assigned(Node) and (Node.Level > lvl)) do
|
---|
| 272 | begin
|
---|
| 273 | if(IsVis(Node)) then
|
---|
| 274 | begin
|
---|
| 275 | Tmp := TORTreeNode(Node).StringData;
|
---|
| 276 | Data := Piece(Tmp,U,RemTreeDateIdx) + U + Piece(Tmp,U,RemTreeDateIdx+1) + U +
|
---|
| 277 | RemPriorityText[StrToIntDef(Piece(Tmp, U, 5), 2)];
|
---|
| 278 | sl.InsertObject(i, Data, Node);
|
---|
| 279 | inc(i);
|
---|
| 280 | end;
|
---|
| 281 | Node := Node.GetNext;
|
---|
| 282 | end;
|
---|
| 283 | end;
|
---|
| 284 | lbRem.Items.Assign(sl);
|
---|
| 285 | finally
|
---|
| 286 | sl.Free;
|
---|
| 287 | end;
|
---|
| 288 | end;
|
---|
| 289 | end;
|
---|
| 290 | end;
|
---|
| 291 |
|
---|
| 292 | procedure TfrmReminderTree.SyncTopControls(FromTree: boolean);
|
---|
| 293 | begin
|
---|
| 294 | if(lbRem.Items.Count > 0) and (tvRem.TopItem <> lbRem.Items.Objects[lbRem.TopIndex]) then
|
---|
| 295 | begin
|
---|
| 296 | if(FromTree) then
|
---|
| 297 | lbRem.TopIndex := lbRem.Items.IndexOfObject(tvRem.TopItem)
|
---|
| 298 | else
|
---|
| 299 | tvRem.TopItem := TTreeNode(lbRem.Items.Objects[lbRem.TopIndex]);
|
---|
| 300 | end;
|
---|
| 301 | end;
|
---|
| 302 |
|
---|
| 303 | procedure TfrmReminderTree.tvRemExpanded(Sender: TObject; Node: TTreeNode);
|
---|
| 304 | begin
|
---|
| 305 | if(FUpdating) then exit;
|
---|
| 306 | FUpdating := TRUE;
|
---|
| 307 | try
|
---|
| 308 | ResetlbItems(Node);
|
---|
| 309 | pnlTopResize(Self);
|
---|
| 310 | finally
|
---|
| 311 | FUpdating := FALSE;
|
---|
| 312 | end;
|
---|
| 313 | end;
|
---|
| 314 |
|
---|
| 315 | procedure TfrmReminderTree.tvRemCollapsed(Sender: TObject;
|
---|
| 316 | Node: TTreeNode);
|
---|
| 317 | begin
|
---|
| 318 | if(FUpdating) then exit;
|
---|
| 319 | FUpdating := TRUE;
|
---|
| 320 | try
|
---|
| 321 | ResetlbItems(Node);
|
---|
| 322 | pnlTopResize(Self);
|
---|
| 323 | finally
|
---|
| 324 | FUpdating := FALSE;
|
---|
| 325 | end;
|
---|
| 326 | end;
|
---|
| 327 |
|
---|
| 328 | procedure TfrmReminderTree.pnlTopResize(Sender: TObject);
|
---|
| 329 | var
|
---|
| 330 | Tmp,Adj: integer;
|
---|
| 331 |
|
---|
| 332 | begin
|
---|
| 333 | Tmp := DateColWidth + LastDateColWidth + PriorityColWidth + 4;
|
---|
| 334 | if(lbRem.Width <> (lbRem.ClientWidth + 4)) then
|
---|
| 335 | Adj := ScrollBarWidth
|
---|
| 336 | else
|
---|
| 337 | Adj := 0;
|
---|
| 338 | pnlTopRight.Width := Tmp + Adj;
|
---|
| 339 | Tmp := pnlTop.Width - DateColWidth - LastDateColWidth - PriorityColWidth - 2 - Adj;
|
---|
| 340 | SetRemHeaderSectionWidth( 0, Tmp);
|
---|
| 341 | tvRem.Items.BeginUpdate;
|
---|
| 342 | try
|
---|
| 343 | tvRem.Height := pnlTop.Height - hcRem.Height;
|
---|
| 344 | if(tvRem.Width <> (tvRem.ClientWidth+4)) then
|
---|
| 345 | inc(Tmp, ScrollBarWidth);
|
---|
| 346 | tvRem.Width := Tmp;
|
---|
| 347 | finally
|
---|
| 348 | tvRem.Items.EndUpdate;
|
---|
| 349 | end;
|
---|
| 350 | bvlGap.Visible := (tvRem.Height <> (tvRem.ClientHeight+4));
|
---|
| 351 | end;
|
---|
| 352 |
|
---|
| 353 | procedure TfrmReminderTree.lbRemDrawItem(Control: TWinControl;
|
---|
| 354 | Index: Integer; Rect: TRect; State: TOwnerDrawState);
|
---|
| 355 | var
|
---|
| 356 | Tmp: string;
|
---|
| 357 | Flags: Longint;
|
---|
| 358 |
|
---|
| 359 | begin
|
---|
| 360 | SyncTopControls(FALSE);
|
---|
| 361 | if (odSelected in State) then
|
---|
| 362 | begin
|
---|
| 363 | if((ActiveControl = lbRem) or (ActiveControl = tvRem)) then
|
---|
| 364 | begin
|
---|
| 365 | lbRem.Canvas.Brush.Color := clHighlight;
|
---|
| 366 | lbRem.Canvas.Font.Color := clHighlightText
|
---|
| 367 | end
|
---|
| 368 | else
|
---|
| 369 | begin
|
---|
| 370 | lbRem.Canvas.Brush.Color := clInactiveBorder;
|
---|
| 371 | lbRem.Canvas.Font.Color := clWindowText;
|
---|
| 372 | end;
|
---|
| 373 | end;
|
---|
| 374 | Flags := lbRem.DrawTextBiDiModeFlags(DT_SINGLELINE or DT_VCENTER);
|
---|
| 375 | Tmp := piece(lbRem.Items[Index],U,1);
|
---|
| 376 | lbRem.Canvas.FillRect(Rect);
|
---|
| 377 | Inc(Rect.Left, 6);
|
---|
| 378 | DrawText(lbRem.Canvas.Handle, PChar(Tmp), Length(Tmp), Rect, Flags);
|
---|
| 379 | inc(Rect.Left, DateColWidth);
|
---|
| 380 | Tmp := piece(lbRem.Items[Index],U,2);
|
---|
| 381 | DrawText(lbRem.Canvas.Handle, PChar(Tmp), Length(Tmp), Rect, Flags);
|
---|
| 382 | inc(Rect.Left, LastDateColWidth);
|
---|
| 383 | Tmp := piece(lbRem.Items[Index],U,3);
|
---|
| 384 | DrawText(lbRem.Canvas.Handle, PChar(Tmp), Length(Tmp), Rect, Flags);
|
---|
| 385 | end;
|
---|
| 386 |
|
---|
| 387 | procedure TfrmReminderTree.lbRemChange(Sender: TObject);
|
---|
| 388 | begin
|
---|
| 389 | Resync(FALSE);
|
---|
| 390 | tvRem.SetFocus;
|
---|
| 391 | end;
|
---|
| 392 |
|
---|
| 393 | procedure TfrmReminderTree.lbRemClick(Sender: TObject);
|
---|
| 394 | begin
|
---|
| 395 | tvRem.SetFocus;
|
---|
| 396 | end;
|
---|
| 397 |
|
---|
| 398 | procedure TfrmReminderTree.tvRemEnter(Sender: TObject);
|
---|
| 399 | begin
|
---|
| 400 | if(FUpdating) then exit;
|
---|
| 401 | if(ActiveControl = lbRem) or (ActiveControl = tvRem) then
|
---|
| 402 | lbRem.Invalidate;
|
---|
| 403 | end;
|
---|
| 404 |
|
---|
| 405 | procedure TfrmReminderTree.tvRemExit(Sender: TObject);
|
---|
| 406 | begin
|
---|
| 407 | if(FUpdating) then exit;
|
---|
| 408 | if(ActiveControl <> lbRem) and (ActiveControl <> tvRem) then
|
---|
| 409 | lbRem.Invalidate;
|
---|
| 410 | end;
|
---|
| 411 |
|
---|
| 412 | procedure TfrmReminderTree.hcRemSectionClick(HeaderControl: THeaderControl;
|
---|
| 413 | Section: THeaderSection);
|
---|
| 414 | var
|
---|
| 415 | i, SortIdx: integer;
|
---|
| 416 | exp: boolean;
|
---|
| 417 | Sel, Node: TTreeNode;
|
---|
| 418 |
|
---|
| 419 | begin
|
---|
| 420 | SortIdx := -1;
|
---|
| 421 | for i := 0 to 3 do
|
---|
| 422 | begin
|
---|
| 423 | if(Section = hcRem.Sections[i]) then
|
---|
| 424 | begin
|
---|
| 425 | SortIdx := i;
|
---|
| 426 | break;
|
---|
| 427 | end;
|
---|
| 428 | end;
|
---|
| 429 | if(SortIdx >= 0) then
|
---|
| 430 | begin
|
---|
| 431 | Sel := tvRem.Selected;
|
---|
| 432 | if(FSortOrder = SortIdx) then
|
---|
| 433 | FSortAssending := not FSortAssending
|
---|
| 434 | else
|
---|
| 435 | FSortOrder := SortIdx;
|
---|
| 436 |
|
---|
| 437 | FSorting := TRUE;
|
---|
| 438 | tvRem.Items.BeginUpdate;
|
---|
| 439 | try
|
---|
| 440 | Node := tvRem.Items.GetFirstNode;
|
---|
| 441 | while(assigned(Node)) do
|
---|
| 442 | begin
|
---|
| 443 | exp := Node.Expanded;
|
---|
| 444 | SortNode(Node);
|
---|
| 445 | if(Node.Expanded <> exp) then
|
---|
| 446 | Node.Expanded := exp;
|
---|
| 447 | Node := Node.GetNextSibling;
|
---|
| 448 | end;
|
---|
| 449 | finally
|
---|
| 450 | tvRem.Items.EndUpdate;
|
---|
| 451 | FSorting := FALSE;
|
---|
| 452 | end;
|
---|
| 453 | ResetlbItems(nil);
|
---|
| 454 | tvRem.Selected := Sel;
|
---|
| 455 | end;
|
---|
| 456 | end;
|
---|
| 457 |
|
---|
| 458 | procedure TfrmReminderTree.SortNode(const Node: TTreeNode);
|
---|
| 459 | var
|
---|
| 460 | i: integer;
|
---|
| 461 | sl: TStringList;
|
---|
| 462 | Tmp, TmpLast: TTreeNode;
|
---|
| 463 | exp: boolean;
|
---|
| 464 |
|
---|
| 465 | begin
|
---|
| 466 | if(Node.HasChildren) then
|
---|
| 467 | begin
|
---|
| 468 | sl := TStringList.Create;
|
---|
| 469 | try
|
---|
| 470 | Tmp := Node.GetFirstChild;
|
---|
| 471 | while assigned(Tmp) do
|
---|
| 472 | begin
|
---|
| 473 | sl.AddObject(SortData(TORTreeNode(Tmp)), Tmp);
|
---|
| 474 | Tmp := Tmp.GetNextSibling;
|
---|
| 475 | end;
|
---|
| 476 | sl.sort;
|
---|
| 477 | TmpLast := Node;
|
---|
| 478 | for i := 0 to sl.Count-1 do
|
---|
| 479 | begin
|
---|
| 480 | if(FSortAssending) then
|
---|
| 481 | Tmp := TTreeNode(sl.Objects[i])
|
---|
| 482 | else
|
---|
| 483 | Tmp := TTreeNode(sl.Objects[sl.Count-1-i]);
|
---|
| 484 | exp := Tmp.Expanded;
|
---|
| 485 | if(i = 0) then
|
---|
| 486 | Tmp.MoveTo(TmpLast, naAddChildFirst)
|
---|
| 487 | else
|
---|
| 488 | Tmp.MoveTo(TmpLast, naInsert);
|
---|
| 489 | TmpLast := Tmp;
|
---|
| 490 | SortNode(Tmp);
|
---|
| 491 | Tmp.Expanded := exp;
|
---|
| 492 | end;
|
---|
| 493 | finally
|
---|
| 494 | sl.Free;
|
---|
| 495 | end;
|
---|
| 496 | end;
|
---|
| 497 | end;
|
---|
| 498 |
|
---|
| 499 | function TfrmReminderTree.SortData(Node: TORTreeNode): string;
|
---|
| 500 |
|
---|
| 501 | function ZForm(str: string; Num: integer): string;
|
---|
| 502 | begin
|
---|
| 503 | Result := copy(StringOfChar('0', Num)+str,1+length(str),Num);
|
---|
| 504 | end;
|
---|
| 505 |
|
---|
| 506 | begin
|
---|
| 507 | Result := ZForm(piece(Node.StringData, U, RemTreeDateIdx+2),5);
|
---|
| 508 | case FSortOrder of
|
---|
| 509 | 1: Result := ZForm(Piece(Node.StringData, U, 3), 15)+'.'+Result;
|
---|
| 510 | 2: Result := ZForm(Piece(Node.StringData, U, 4), 15)+'.'+Result;
|
---|
| 511 | 3: Result := Piece(Node.StringData, U, 5)+'.'+Result;
|
---|
| 512 | end;
|
---|
| 513 | end;
|
---|
| 514 |
|
---|
| 515 | procedure TfrmReminderTree.tvRemClick(Sender: TObject);
|
---|
| 516 | begin
|
---|
| 517 | Resync(TRUE);
|
---|
| 518 | end;
|
---|
| 519 |
|
---|
| 520 | procedure TfrmReminderTree.tvRemChange(Sender: TObject; Node: TTreeNode);
|
---|
| 521 | var
|
---|
| 522 | p1: string;
|
---|
| 523 |
|
---|
| 524 | begin
|
---|
| 525 | memView.Data := '';
|
---|
| 526 | if(assigned(Node)) then
|
---|
| 527 | begin
|
---|
| 528 | p1 := Piece((Node as TORTreeNode).StringData, U, 1);
|
---|
| 529 | if(Copy(p1,1,1) = RemCode) then
|
---|
| 530 | begin
|
---|
| 531 | memView.Data := (Node as TORTreeNode).StringData;
|
---|
| 532 | end;
|
---|
| 533 | end;
|
---|
| 534 | EnableActions;
|
---|
| 535 |
|
---|
| 536 | Resync(TRUE);
|
---|
| 537 | end;
|
---|
| 538 |
|
---|
| 539 | procedure TfrmReminderTree.tvRemMouseDown(Sender: TObject;
|
---|
| 540 | Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
---|
| 541 | begin
|
---|
| 542 | Resync(TRUE);
|
---|
| 543 | end;
|
---|
| 544 |
|
---|
| 545 | procedure TfrmReminderTree.Resync(FromTree: boolean);
|
---|
| 546 | begin
|
---|
| 547 | if(FUpdating) then exit;
|
---|
| 548 | FUpdating := TRUE;
|
---|
| 549 | try
|
---|
| 550 | LinkTopControls(FromTree);
|
---|
| 551 | SyncTopControls(FromTree);
|
---|
| 552 | finally
|
---|
| 553 | FUpdating := FALSE;
|
---|
| 554 | end;
|
---|
| 555 | end;
|
---|
| 556 |
|
---|
| 557 | {procedure TfrmReminderTree.PositionToReminder(Sender: TObject);
|
---|
| 558 | begin
|
---|
| 559 | if(assigned(Sender)) then
|
---|
| 560 | begin
|
---|
| 561 | if(Sender is TReminder) then
|
---|
| 562 | begin
|
---|
| 563 | tvRem.Selected := tvRem.FindPieceNode(RemCode + (Sender as TReminder).IEN, 1);
|
---|
| 564 | if(assigned(tvRem.Selected)) then
|
---|
| 565 | TORTreeNode(tvRem.Selected).EnsureVisible;
|
---|
| 566 | end;
|
---|
| 567 | end
|
---|
| 568 | else
|
---|
| 569 | tvRem.Selected := nil;
|
---|
| 570 | end;}
|
---|
| 571 |
|
---|
| 572 | procedure TfrmReminderTree.memEvalClick(Sender: TObject);
|
---|
| 573 | var
|
---|
| 574 | Node: TORTreeNode;
|
---|
| 575 | p1: string;
|
---|
| 576 |
|
---|
| 577 | begin
|
---|
| 578 | Node := TORTreeNode(tvRem.Selected);
|
---|
| 579 | if(assigned(Node)) then
|
---|
| 580 | begin
|
---|
| 581 | p1 := Piece(Node.StringData, U, 1);
|
---|
| 582 | if(Copy(p1,1,1) = RemCode) then
|
---|
| 583 | EvalReminder(StrToIntDef(Copy(p1,2,MaxInt),0));
|
---|
| 584 | end;
|
---|
| 585 | end;
|
---|
| 586 |
|
---|
| 587 | procedure TfrmReminderTree.EnableActions;
|
---|
| 588 | var
|
---|
| 589 | OK: boolean;
|
---|
| 590 | Node: TORTreeNode;
|
---|
| 591 | p1: string;
|
---|
| 592 |
|
---|
| 593 | begin
|
---|
| 594 | Node := TORTreeNode(tvRem.Selected);
|
---|
| 595 | if(assigned(Node)) then
|
---|
| 596 | p1 := Piece(Node.StringData, U, 1)
|
---|
| 597 | else
|
---|
| 598 | p1 := '';
|
---|
| 599 | if(assigned(Node)) then
|
---|
| 600 | OK := (Copy(p1,1,1) = RemCode)
|
---|
| 601 | else
|
---|
| 602 | OK := FALSE;
|
---|
| 603 | memEval.Enabled := OK;
|
---|
| 604 | memEvalAll.Enabled := (ProcessedReminders.Count > 0);
|
---|
| 605 | memRefresh.Enabled := (not ReminderDialogActive);
|
---|
| 606 | mnuCoverSheet.Enabled := (NewRemCoverSheetListActive or CanEditAllRemCoverSheetLists);
|
---|
| 607 | memAction.Enabled := (OK or memEvalAll.Enabled or memRefresh.Enabled or mnuCoverSheet.Enabled);
|
---|
| 608 | if(assigned(Node)) then
|
---|
| 609 | OK := ((Copy(p1,1,1) = CatCode) and (p1 <> OtherCatID) and (Node.HasChildren))
|
---|
| 610 | else
|
---|
| 611 | OK := FALSE;
|
---|
| 612 | memEvalCat.Enabled := OK;
|
---|
| 613 | memEvalCat.Tag := integer(Node);
|
---|
| 614 | end;
|
---|
| 615 |
|
---|
| 616 | procedure TfrmReminderTree.ProcessedRemindersChanged(Sender: TObject);
|
---|
| 617 | begin
|
---|
| 618 | EnableActions;
|
---|
| 619 | end;
|
---|
| 620 |
|
---|
| 621 | procedure TfrmReminderTree.memEvalAllClick(Sender: TObject);
|
---|
| 622 | begin
|
---|
| 623 | EvalProcessed;
|
---|
| 624 | end;
|
---|
| 625 |
|
---|
| 626 | procedure TfrmReminderTree.FormDestroy(Sender: TObject);
|
---|
| 627 | begin
|
---|
| 628 | TAccessibleTreeView.UnwrapControl(tvRem);
|
---|
| 629 | frmReminderTree := nil;
|
---|
| 630 | ProcessedReminders.Notifier.RemoveNotify(ProcessedRemindersChanged);
|
---|
| 631 | // RemoveNotifyWhenProcessingReminderChanges(PositionToReminder);
|
---|
| 632 | RemoveNotifyRemindersChange(RemindersChanged);
|
---|
| 633 | RemTreeDlgLeft := Self.Left;
|
---|
| 634 | RemTreeDlgTop := Self.Top;
|
---|
| 635 | RemTreeDlgWidth := Self.Width;
|
---|
| 636 | RemTreeDlgHeight := Self.Height;
|
---|
| 637 | end;
|
---|
| 638 |
|
---|
| 639 | procedure TfrmReminderTree.memRefreshClick(Sender: TObject);
|
---|
| 640 | begin
|
---|
| 641 | KillObj(@ReminderDialogInfo, TRUE);
|
---|
| 642 | UpdateReminderDialogStatus;
|
---|
| 643 | EnableActions;
|
---|
| 644 | end;
|
---|
| 645 |
|
---|
| 646 | procedure TfrmReminderTree.memActionClick(Sender: TObject);
|
---|
| 647 | begin
|
---|
| 648 | EnableActions;
|
---|
| 649 | end;
|
---|
| 650 |
|
---|
| 651 | procedure TfrmReminderTree.memEvalCatClick(Sender: TObject);
|
---|
| 652 | begin
|
---|
| 653 | EvaluateCategoryClicked(nil, Sender);
|
---|
| 654 | end;
|
---|
| 655 |
|
---|
| 656 | procedure TfrmReminderTree.mnuCoverSheetClick(Sender: TObject);
|
---|
| 657 | begin
|
---|
| 658 | EditCoverSheetReminderList(not CanEditAllRemCoverSheetLists);
|
---|
| 659 | end;
|
---|
| 660 |
|
---|
| 661 | procedure TfrmReminderTree.SetFontSize(NewFontSize: integer);
|
---|
| 662 | var
|
---|
| 663 | TotalWidth: integer;
|
---|
| 664 | begin
|
---|
| 665 | DateColWidth := ResizeWidth(Font, MainFont, UnscaledDateColWidth);
|
---|
| 666 | LastDateColWidth := ResizeWidth(Font, MainFont, UnscaledLastDateColWidth);
|
---|
| 667 | PriorityColWidth := ResizeWidth(Font, MainFont, UnscaledPriorityColWidth);
|
---|
| 668 | ResizeAnchoredFormToFont(self);
|
---|
| 669 | TotalWidth := hcRem.Width;
|
---|
| 670 | SetRemHeaderSectionWidth( 0, TotalWidth - DateColWidth - LastDateColWidth - PriorityColWidth);
|
---|
| 671 | SetRemHeaderSectionWidth( 1, DateColWidth);
|
---|
| 672 | SetRemHeaderSectionWidth( 2, LastDateColWidth);
|
---|
| 673 | SetRemHeaderSectionWidth( 3, PriorityColWidth);
|
---|
| 674 |
|
---|
| 675 | lbRem.ItemHeight := ((Abs(Font.Height)+ 6) div 2)*2; //tvRem.ItemHeight;
|
---|
| 676 | //This is called "best guess calibration"
|
---|
| 677 | if Font.Size > 12 then lbRem.ItemHeight := lbRem.ItemHeight + 2;
|
---|
| 678 | //I am reluctant to use an alignment on the tvRem as there si lots of resizing
|
---|
| 679 | //tricks going on with the scroll bar at the bottom.
|
---|
| 680 | tvRem.Top := hcRem.Top+hcRem.Height;
|
---|
| 681 | pnlTopResize(self);
|
---|
| 682 | end;
|
---|
| 683 |
|
---|
| 684 | procedure TfrmReminderTree.SetRemHeaderSectionWidth( SectionIndex: integer; NewWidth: integer);
|
---|
| 685 | begin
|
---|
| 686 | hcRem.Sections[SectionIndex].MinWidth := 0;
|
---|
| 687 | hcRem.Sections[SectionIndex].MaxWidth := NewWidth;
|
---|
| 688 | hcRem.Sections[SectionIndex].MinWidth := NewWidth;
|
---|
| 689 | hcRem.Sections[SectionIndex].Width := NewWidth;
|
---|
| 690 | end;
|
---|
| 691 |
|
---|
| 692 | procedure TfrmReminderTree.tvRemNodeCaptioning(Sender: TObject;
|
---|
| 693 | var Caption: String);
|
---|
| 694 | var
|
---|
| 695 | StringData: string;
|
---|
| 696 | begin
|
---|
| 697 | StringData := (Sender as TORTreeNode).StringData;
|
---|
| 698 | if (Length(StringData) > 0) and (StringData[1] = 'R') then //Only tag reminder statuses
|
---|
| 699 | case StrToIntDef(Piece(StringData,'^',6 {Due}),-1) of
|
---|
| 700 | 0: Caption := Caption + ' -- Applicable';
|
---|
| 701 | 1: Caption := Caption + ' -- DUE';
|
---|
| 702 | 2: Caption := Caption + ' -- Not Applicable';
|
---|
| 703 | else Caption := Caption + ' -- Not Evaluated';
|
---|
| 704 | end;
|
---|
| 705 | end;
|
---|
| 706 |
|
---|
| 707 | procedure TfrmReminderTree.tvRemAddition(Sender: TObject; Node: TTreeNode);
|
---|
| 708 | begin
|
---|
| 709 | TAccessibleTreeNode.WrapControl(Node as TORTreeNode);
|
---|
| 710 | end;
|
---|
| 711 |
|
---|
| 712 | procedure TfrmReminderTree.tvRemDeletion(Sender: TObject; Node: TTreeNode);
|
---|
| 713 | begin
|
---|
| 714 | TAccessibleTreeNode.UnwrapControl(Node as TORTreeNode);
|
---|
| 715 | end;
|
---|
| 716 |
|
---|
| 717 | procedure TfrmReminderTree.mnuExitClick(Sender: TObject);
|
---|
| 718 | begin
|
---|
| 719 | Close;
|
---|
| 720 | end;
|
---|
| 721 |
|
---|
| 722 | end.
|
---|