source: cprs/trunk/CPRS-Chart/fDrawers.pas@ 483

Last change on this file since 483 was 456, checked in by Kevin Toppenberg, 16 years ago

Initial Upload of Official WV CPRS 1.0.26.76

File size: 43.5 KB
Line 
1unit fDrawers;
2{
3bugs noticed:
4 if delete only note (currently editing) then drawers and encounter button still enabled
5}
6//vw mod for template callup. Checks in test 4/15/07
7interface
8
9uses
10 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
11 ExtCtrls, StdCtrls, Buttons, ORCtrls, ComCtrls, ImgList, uTemplates,
12 Menus, ORClasses, ORFn;
13
14type
15 TDrawer = (odNone, odTemplates, odEncounter, odReminders, odOrders);
16 TDrawers = set of TDrawer;
17
18 TfrmDrawers = class(TForm)
19 lbOrders: TORListBox;
20 sbOrders: TORAlignSpeedButton;
21 sbReminders: TORAlignSpeedButton;
22 sbEncounter: TORAlignSpeedButton;
23 sbTemplates: TORAlignSpeedButton;
24 pnlOrdersButton: TKeyClickPanel;
25 pnlRemindersButton: TKeyClickPanel;
26 pnlEncounterButton: TKeyClickPanel;
27 pnlTemplatesButton: TKeyClickPanel;
28 lbEncounter: TORListBox;
29 popTemplates: TPopupMenu;
30 mnuPreviewTemplate: TMenuItem;
31 pnlTemplates: TPanel;
32 tvTemplates: TORTreeView;
33 N1: TMenuItem;
34 mnuCollapseTree: TMenuItem;
35 N2: TMenuItem;
36 mnuEditTemplates: TMenuItem;
37 pnlTemplateSearch: TPanel;
38 btnFind: TORAlignButton;
39 edtSearch: TCaptionEdit;
40 mnuFindTemplates: TMenuItem;
41 mnuNewTemplate: TMenuItem;
42 cbMatchCase: TCheckBox;
43 cbWholeWords: TCheckBox;
44 mnuInsertTemplate: TMenuItem;
45 tvReminders: TORTreeView;
46 mnuDefault: TMenuItem;
47 N3: TMenuItem;
48 mnuGotoDefault: TMenuItem;
49 N4: TMenuItem;
50 mnuViewNotes: TMenuItem;
51 mnuCopyTemplate: TMenuItem;
52 N5: TMenuItem;
53 mnuViewTemplateIconLegend: TMenuItem;
54 procedure FormCanResize(Sender: TObject; var NewWidth,
55 NewHeight: Integer; var Resize: Boolean);
56 procedure FormResize(Sender: TObject);
57 procedure sbTemplatesClick(Sender: TObject);
58 procedure sbEncounterClick(Sender: TObject);
59 procedure sbRemindersClick(Sender: TObject);
60 procedure sbOrdersClick(Sender: TObject);
61 procedure sbResize(Sender: TObject);
62 procedure tvTemplatesGetImageIndex(Sender: TObject; Node: TTreeNode);
63 procedure tvTemplatesGetSelectedIndex(Sender: TObject;
64 Node: TTreeNode);
65 procedure tvTemplatesExpanding(Sender: TObject; Node: TTreeNode;
66 var AllowExpansion: Boolean);
67 procedure tvTemplatesClick(Sender: TObject);
68 procedure tvTemplatesDblClick(Sender: TObject);
69 procedure tvTemplatesCollapsing(Sender: TObject; Node: TTreeNode;
70 var AllowCollapse: Boolean);
71 procedure tvTemplatesKeyDown(Sender: TObject; var Key: Word;
72 Shift: TShiftState);
73 procedure tvTemplatesKeyUp(Sender: TObject; var Key: Word;
74 Shift: TShiftState);
75 procedure popTemplatesPopup(Sender: TObject);
76 procedure mnuPreviewTemplateClick(Sender: TObject);
77 procedure FormDestroy(Sender: TObject);
78 procedure mnuCollapseTreeClick(Sender: TObject);
79 procedure btnFindClick(Sender: TObject);
80 procedure edtSearchChange(Sender: TObject);
81 procedure ToggleMenuItem(Sender: TObject);
82 procedure edtSearchEnter(Sender: TObject);
83 procedure edtSearchExit(Sender: TObject);
84 procedure mnuFindTemplatesClick(Sender: TObject);
85 procedure tvTemplatesDragging(Sender: TObject; Node: TTreeNode;
86 var CanDrag: Boolean);
87 procedure mnuEditTemplatesClick(Sender: TObject);
88 procedure mnuNewTemplateClick(Sender: TObject);
89 procedure FormCreate(Sender: TObject);
90 procedure pnlTemplateSearchResize(Sender: TObject);
91 procedure cbFindOptionClick(Sender: TObject);
92 procedure mnuInsertTemplateClick(Sender: TObject);
93 procedure tvRemindersMouseUp(Sender: TObject; Button: TMouseButton;
94 Shift: TShiftState; X, Y: Integer);
95 procedure tvRemindersCurListChanged(Sender: TObject; Node: TTreeNode);
96 procedure mnuDefaultClick(Sender: TObject);
97 procedure mnuGotoDefaultClick(Sender: TObject);
98 procedure mnuViewNotesClick(Sender: TObject);
99 procedure mnuCopyTemplateClick(Sender: TObject);
100 procedure mnuViewTemplateIconLegendClick(Sender: TObject);
101 procedure pnlTemplatesButtonEnter(Sender: TObject);
102 procedure pnlTemplatesButtonExit(Sender: TObject);
103 procedure tvRemindersKeyDown(Sender: TObject; var Key: Word;
104 Shift: TShiftState);
105 procedure tvRemindersNodeCaptioning(Sender: TObject;
106 var Caption: String);
107 procedure tvRemindersAddition(Sender: TObject; Node: TTreeNode);
108 procedure tvRemindersDeletion(Sender: TObject; Node: TTreeNode);
109 private
110 FOpenToNode: string;
111 FOldMouseUp: TMouseEvent;
112 FEmptyNodeCount: integer;
113 FOldDragDrop: TDragDropEvent;
114 FOldDragOver: TDragOverEvent;
115 FOldFontChanged: TNotifyEvent;
116 FTextIconWidth: integer;
117 FInternalResize: integer;
118 FHoldResize: integer;
119 FOpenDrawer: TDrawer;
120 FLastOpenSize: integer;
121 FButtonHeights: integer;
122 FInternalExpand :boolean;
123 FInternalHiddenExpand :boolean;
124 FAsk :boolean;
125 FAskExp :boolean;
126 FAskNode :TTreeNode;
127 FDragNode :TTreeNode;
128 FClickOccurred: boolean;
129 FRichEditControl: TRichEdit;
130 FFindNext: boolean;
131 FLastFoundNode: TTreeNode;
132 FSplitter: TSplitter;
133 FOldCanResize: TCanResizeEvent;
134 FSplitterActive: boolean;
135 FHasPersonalTemplates: boolean;
136 FRemNotifyList: TORNotifyList;
137 FDefTempPiece: integer;
138 FNewNoteButton: TButton;
139 FCurrentVisibleDrawers: TDrawers;
140 FCurrentEnabledDrawers: TDrawers;
141 function GetAlign: TAlign;
142 procedure SetAlign(const Value: TAlign);
143 function MinDrawerControlHeight: integer;
144 procedure DisableArrowKeyMove(Sender: TObject);
145 protected
146 procedure PositionToReminder(Sender: TObject);
147 procedure RemindersChanged(Sender: TObject);
148 procedure SetFindNext(const Value: boolean);
149 procedure ReloadTemplates;
150 procedure SetRichEditControl(const Value: TRichEdit);
151 procedure CheckAsk;
152 procedure FontChanged(Sender: TObject);
153 procedure InitButtons;
154 procedure StartInternalResize;
155 procedure EndInternalResize;
156 procedure ResizeToVisible;
157 function ButtonHeights: integer;
158 procedure GetDrawerControls(Drawer: TDrawer;
159 var Btn: TORAlignSpeedButton;
160 var Ctrl: TWinControl);
161 procedure AddTemplateNode(const tmpl: TTemplate; const Owner: TTreeNode = nil);
162 procedure MoveCaret(X, Y: integer);
163 procedure NewRECDragDrop(Sender, Source: TObject; X, Y: Integer);
164 procedure NewRECDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState;
165 var Accept: Boolean);
166 procedure InsertText;
167 procedure SetSplitter(const Value: TSplitter);
168 procedure SplitterCanResize(Sender: TObject; var NewSize: Integer; var Accept: Boolean);
169 procedure SetSplitterActive(Active: boolean);
170 function EnableDrawer(Drawer: TDrawer; EnableIt: boolean): boolean;
171 function InsertOK(Ask: boolean): boolean;
172 procedure OpenToNode(Path: string = '');
173 property FindNext: boolean read FFindNext write SetFindNext;
174 public
175 constructor CreateDrawers(AOwner: TComponent; AParent: TWinControl;
176 VisibleDrawers, EnabledDrawers: TDrawers);
177 procedure ExternalReloadTemplates;
178 procedure OpenDrawer(Drawer: TDrawer);
179 procedure ToggleDrawer(Drawer: TDrawer);
180 procedure ShowDrawers(Drawers: TDrawers);
181 procedure EnableDrawers(Drawers: TDrawers);
182 procedure DisplayDrawers(Show: Boolean); overload;
183 procedure DisplayDrawers(Show: Boolean; AEnable, ADisplay: TDrawers); overload;
184 function CanEditTemplates: boolean;
185 function CanEditShared: boolean;
186 procedure UpdatePersonalTemplates;
187 procedure NotifyWhenRemTreeChanges(Proc: TNotifyEvent);
188 procedure RemoveNotifyWhenRemTreeChanges(Proc: TNotifyEvent);
189 procedure ResetTemplates;
190 property RichEditControl: TRichEdit read FRichEditControl write SetRichEditControl;
191 property NewNoteButton: TButton read FNewNoteButton write FNewNoteButton;
192 property Splitter: TSplitter read FSplitter write SetSplitter;
193 property HasPersonalTemplates: boolean read FHasPersonalTemplates;
194 property LastOpenSize: integer read FLastOpenSize write FLastOpenSize;
195 property DefTempPiece: integer read FDefTempPiece write FDefTempPiece;
196 property TheOpenDrawer: TDrawer read FOpenDrawer;
197 published
198 property Align: TAlign read GetAlign write SetAlign;
199 end;
200
201{ There is a different instance of frmDrawers on each tab, so make the
202 frmDrawers variable local to each tab, do not use this global var! }
203//var
204 //frmDrawers: TfrmDrawers;
205
206const
207 DrawerSplitters = 'frmDrawersSplitters';
208
209implementation
210
211uses fTemplateView, uCore, rTemplates, fTemplateEditor, dShared, uReminders,
212 fReminderDialog, RichEdit, fRptBox, Clipbrd, fTemplateDialog, fIconLegend,
213 uAccessibleTreeView, uAccessibleTreeNode;
214
215{$R *.DFM}
216
217const
218 BaseMinDrawerControlHeight = 24;
219 FindNextText = 'Find Next';
220
221function TfrmDrawers.MinDrawerControlHeight: integer;
222begin
223 result := ResizeHeight( BaseFont, MainFont, BaseMinDrawerControlHeight);
224end;
225
226procedure TfrmDrawers.ResizeToVisible;
227var
228 NewHeight: integer;
229 od: TDrawer;
230 Button: TORAlignSpeedButton;
231 WinCtrl: TWinControl;
232
233 procedure AllCtrls(AAlign: TAlign);
234 var
235 od: TDrawer;
236
237 begin
238 Parent.DisableAlign;
239 try
240 for od := succ(low(TDrawer)) to high(TDrawer) do
241 begin
242 GetDrawerControls(od, Button, WinCtrl);
243 Button.Parent.Align := AAlign;
244 WinCtrl.Align := AAlign;
245 end;
246 finally
247 Parent.EnableAlign;
248 end;
249 end;
250
251begin
252 if((FHoldResize = 0) and Visible) then
253 begin
254 FButtonHeights := -1; //Force re-calculate
255 NewHeight := 0;
256 AllCtrls(alNone);
257 for od := succ(low(TDrawer)) to high(TDrawer) do
258 begin
259 GetDrawerControls(od, Button, WinCtrl);
260 if(Button.Parent.Visible) then
261 begin
262 Button.Parent.Top := NewHeight;
263 inc(NewHeight, Button.Parent.Height);
264 WinCtrl.Top := NewHeight;
265 if(WinCtrl.Visible) then
266 begin
267 if(FLastOpenSize < 10) or (FLastOpenSize > (Parent.Height - 20)) then
268 begin
269 FLastOpenSize := (Parent.Height div 4) * 3;
270 dec(FLastOpenSize, ButtonHeights);
271 if(FLastOpenSize < MinDrawerControlHeight) then
272 FLastOpenSize := MinDrawerControlHeight;
273 end;
274 inc(NewHeight, FLastOpenSize);
275 WinCtrl.Height := FLastOpenSize;
276 end
277 else
278 WinCtrl.Height := 0;
279 end;
280 end;
281 AllCtrls(alTop);
282 StartInternalResize;
283 try
284 ClientHeight := NewHeight
285 finally
286 EndInternalResize;
287 end;
288 end;
289end;
290
291procedure TfrmDrawers.FormCanResize(Sender: TObject; var NewWidth,
292 NewHeight: Integer; var Resize: Boolean);
293var
294 od: TDrawer;
295 Btn: TORAlignSpeedButton;
296 Ctrl: TWinControl;
297 IsVisible: boolean;
298
299begin
300 if(FInternalResize = 0) then
301 begin
302 IsVisible := FALSE;
303 for od := succ(low(TDrawer)) to high(TDrawer) do
304 begin
305 GetDrawerControls(od, Btn, Ctrl);
306 if(Ctrl.Visible) then
307 begin
308 IsVisible := TRUE;
309 break;
310 end;
311 end;
312 if(not IsVisible) then
313 NewHeight := ButtonHeights;
314 end;
315end;
316
317function TfrmDrawers.ButtonHeights: integer;
318begin
319 if(FButtonHeights < 0) then
320 begin
321 FButtonHeights := 0;
322 if(pnlOrdersButton.Visible) then
323 inc(FButtonHeights, sbOrders.Height);
324 if(pnlRemindersButton.Visible) then
325 inc(FButtonHeights, sbReminders.Height);
326 if(pnlEncounterButton.Visible) then
327 inc(FButtonHeights, sbEncounter.Height);
328 if(pnlTemplatesButton.Visible) then
329 inc(FButtonHeights, sbTemplates.Height);
330 end;
331 Result := FButtonHeights;
332end;
333
334procedure TfrmDrawers.ShowDrawers(Drawers: TDrawers);
335var
336 od: TDrawer;
337 Btn: TORAlignSpeedButton;
338 Ctrl: TWinControl;
339 SaveLOS: integer;
340
341begin
342 if(FCurrentVisibleDrawers = []) or (Drawers <> FCurrentVisibleDrawers) then
343 begin
344 FCurrentVisibleDrawers := Drawers;
345 SaveLOS := FLastOpenSize;
346 OpenDrawer(odNone);
347 for od := succ(low(TDrawer)) to high(TDrawer) do
348 begin
349 GetDrawerControls(od, Btn, Ctrl);
350 Btn.Parent.Visible := (od in Drawers);
351 Ctrl.Visible := FALSE;
352 Ctrl.Height := 0;
353 end;
354 FButtonHeights := -1;
355 FLastOpenSize := SaveLOS;
356 ResizeToVisible;
357 if(odReminders in Drawers) then
358 begin
359 NotifyWhenRemindersChange(RemindersChanged);
360 NotifyWhenProcessingReminderChanges(PositionToReminder);
361 end
362 else
363 begin
364 RemoveNotifyRemindersChange(RemindersChanged);
365 RemoveNotifyWhenProcessingReminderChanges(PositionToReminder);
366 end;
367 end;
368end;
369
370procedure TfrmDrawers.OpenDrawer(Drawer: TDrawer);
371var
372 Btn: TORAlignSpeedButton;
373 Ctrl: TWinControl;
374
375begin
376 if(FOpenDrawer <> Drawer) then
377 begin
378 StartInternalResize;
379 try
380 if(FOpenDrawer <> odNone) then
381 begin
382 GetDrawerControls(FOpenDrawer, Btn, Ctrl);
383 Btn.Down := FALSE;
384 with Btn.Parent as TPanel do
385 if BevelOuter = bvLowered then
386 BevelOuter := bvRaised;
387 Ctrl.Visible := FALSE;
388 Ctrl.Height := 0;
389 end;
390 if(Drawer = odNone) then
391 begin
392 FOpenDrawer := Drawer;
393 SetSplitterActive(FALSE);
394 end
395 else
396 begin
397 GetDrawerControls(Drawer, Btn, Ctrl);
398 if(Btn.Parent.Visible) and (Btn.Enabled) then
399 begin
400 SetSplitterActive(TRUE);
401 Btn.Down := TRUE;
402 with Btn.Parent as TPanel do
403 if BevelOuter = bvRaised then
404 BevelOuter := bvLowered;
405 Ctrl.Visible := TRUE;
406 FOpenDrawer := Drawer;
407 end
408 else
409 SetSplitterActive(FALSE);
410 end;
411 finally
412 EndInternalResize;
413 end;
414 ResizeToVisible;
415 end;
416end;
417
418procedure TfrmDrawers.GetDrawerControls(Drawer: TDrawer;
419 var Btn: TORAlignSpeedButton; var Ctrl: TWinControl);
420begin
421 case Drawer of
422 odTemplates:
423 begin
424 Btn := sbTemplates;
425 Ctrl := pnlTemplates;
426 end;
427
428 odEncounter:
429 begin
430 Btn := sbEncounter;
431 Ctrl := lbEncounter;
432 end;
433
434 odReminders:
435 begin
436 Btn := sbReminders;
437 Ctrl := tvReminders;
438 end;
439
440 odOrders:
441 begin
442 Btn := sbOrders;
443 Ctrl := lbOrders;
444 end;
445
446 else
447 begin
448 Btn := nil;
449 Ctrl := nil;
450 end;
451 end;
452end;
453
454constructor TfrmDrawers.CreateDrawers(AOwner: TComponent; AParent: TWinControl;
455 VisibleDrawers, EnabledDrawers: TDrawers);
456begin
457 FInternalResize := 0;
458 StartInternalResize;
459 try
460 Create(AOwner);
461 FButtonHeights := -1;
462 FLastOpenSize := 0;
463 FOpenDrawer := odNone;
464 Parent := AParent;
465 Align := alBottom;
466 FOldFontChanged := Font.OnChange;
467 Font.OnChange := FontChanged;
468 InitButtons;
469 ShowDrawers(VisibleDrawers);
470 EnableDrawers(EnabledDrawers);
471 Show;
472 finally
473 EndInternalResize;
474 end;
475end;
476
477function TfrmDrawers.EnableDrawer(Drawer: TDrawer; EnableIt: boolean): boolean;
478var
479 Btn: TORAlignSpeedButton;
480 Ctrl: TWinControl;
481
482begin
483 inc(FHoldResize);
484 try
485 GetDrawerControls(Drawer, Btn, Ctrl);
486 Btn.Parent.Enabled := EnableIt;
487 if(Drawer = FOpenDrawer) and (not Btn.Parent.Enabled) then
488 OpenDrawer(odNone);
489 finally
490 dec(FHoldResize);
491 end;
492 ResizeToVisible;
493 Result := EnableIt;
494end;
495
496procedure TfrmDrawers.EnableDrawers(Drawers: TDrawers);
497var
498 od: TDrawer;
499
500begin
501 if(FCurrentEnabledDrawers = []) or (Drawers <> FCurrentEnabledDrawers) then
502 begin
503 FCurrentEnabledDrawers := Drawers;
504 inc(FHoldResize);
505 try
506 for od := succ(low(TDrawer)) to high(TDrawer) do
507 EnableDrawer(od, (od in Drawers));
508 finally
509 dec(FHoldResize);
510 end;
511 ResizeToVisible;
512 end;
513end;
514
515procedure TfrmDrawers.FormResize(Sender: TObject);
516begin
517 if(FInternalResize = 0) and (FOpenDrawer <> odNone) then
518 begin
519 FLastOpenSize := Height;
520 dec(FLastOpenSize, ButtonHeights);
521 if(FLastOpenSize < MinDrawerControlHeight) then
522 FLastOpenSize := MinDrawerControlHeight;
523 ResizeToVisible;
524 end;
525end;
526
527procedure TfrmDrawers.sbTemplatesClick(Sender: TObject);
528begin
529 if(FOpenDrawer <> odTemplates) then
530 begin
531 ReloadTemplates;
532 btnFind.Enabled := (edtSearch.Text <> '');
533 pnlTemplateSearch.Visible := mnuFindTemplates.Checked;
534 end;
535 ToggleDrawer(odTemplates);
536end;
537
538procedure TfrmDrawers.sbEncounterClick(Sender: TObject);
539begin
540 ToggleDrawer(odEncounter);
541end;
542
543procedure TfrmDrawers.sbRemindersClick(Sender: TObject);
544begin
545 if(InitialRemindersLoaded) then
546 ToggleDrawer(odReminders)
547 else
548 begin
549 StartupReminders;
550 if(GetReminderStatus = rsNone) then
551 begin
552 EnableDrawer(odReminders, FALSE);
553 sbReminders.Down := FALSE;
554 with sbReminders.Parent as TPanel do
555 if BevelOuter = bvLowered then
556 BevelOuter := bvRaised;
557 end
558 else
559 ToggleDrawer(odReminders)
560 end;
561end;
562
563procedure TfrmDrawers.sbOrdersClick(Sender: TObject);
564begin
565 ToggleDrawer(odOrders);
566end;
567
568procedure TfrmDrawers.ToggleDrawer(Drawer: TDrawer);
569begin
570 if(Drawer = FOpenDrawer) then
571 OpenDrawer(odNone)
572 else
573 OpenDrawer(Drawer);
574end;
575
576procedure TfrmDrawers.EndInternalResize;
577begin
578 if(FInternalResize > 0) then dec(FInternalResize);
579end;
580
581procedure TfrmDrawers.StartInternalResize;
582begin
583 inc(FInternalResize);
584end;
585
586procedure TfrmDrawers.sbResize(Sender: TObject);
587var
588 Button: TORAlignSpeedButton;
589 Mar: integer; // Mar Needed because you can't assign Margin a negative value
590
591begin
592 Button := (Sender as TORAlignSpeedButton);
593 Mar := (Button.Width - FTextIconWidth) div 2;
594 if(Mar < 0) then
595 Mar := 0;
596 Button.Margin := Mar;
597end;
598
599procedure TfrmDrawers.InitButtons;
600var
601 od: TDrawer;
602 Btn: TORAlignSpeedButton;
603 Ctrl: TWinControl;
604 TmpWidth: integer;
605 TmpHeight: integer;
606 MaxHeight: integer;
607
608begin
609 StartInternalResize;
610 try
611 FTextIconWidth := 0;
612 MaxHeight := 0;
613 for od := succ(low(TDrawer)) to high(TDrawer) do
614 begin
615 GetDrawerControls(od, Btn, Ctrl);
616 TmpWidth := Canvas.TextWidth(Btn.Caption) + Btn.Spacing +
617 (Btn.Glyph.Width div Btn.NumGlyphs) + 4;
618 if(TmpWidth > FTextIconWidth) then
619 FTextIconWidth := TmpWidth;
620 TmpHeight := Canvas.TextHeight(Btn.Caption) + 9;
621 if(TmpHeight > MaxHeight) then
622 MaxHeight := TmpHeight;
623 end;
624 if(MaxHeight > 0) then
625 begin
626 for od := succ(low(TDrawer)) to high(TDrawer) do
627 begin
628 GetDrawerControls(od, Btn, Ctrl);
629 Btn.Parent.Height := MaxHeight;
630 end;
631 end;
632 Constraints.MinWidth := FTextIconWidth;
633 finally
634 EndInternalResize;
635 end;
636 ResizeToVisible;
637end;
638
639procedure TfrmDrawers.FontChanged(Sender: TObject);
640var
641 Ht: integer;
642
643begin
644 if(assigned(FOldFontChanged)) then
645 FOldFontChanged(Sender);
646 if(FInternalResize = 0) then
647 begin
648 InitButtons;
649 ResizeToVisible;
650 btnFind.Width := Canvas.TextWidth(FindNextText) + 10;
651 btnFind.Height := edtSearch.Height;
652 btnFind.Left := pnlTemplateSearch.Width - btnFind.Width;
653 edtSearch.Width := pnlTemplateSearch.Width - btnFind.Width;
654 cbMatchCase.Width := Canvas.TextWidth(cbMatchCase.Caption)+23;
655 cbWholeWords.Width := Canvas.TextWidth(cbWholeWords.Caption)+23;
656 Ht := Canvas.TextHeight(cbMatchCase.Caption);
657 if(Ht < 17) then Ht := 17;
658 pnlTemplateSearch.Height := edtSearch.Height + Ht;
659 cbMatchCase.Height := Ht;
660 cbWholeWords.Height := Ht;
661 cbMatchCase.Top := edtSearch.Height;
662 cbWholeWords.Top := edtSearch.Height;
663 pnlTemplateSearchResize(Sender);
664 end;
665end;
666
667procedure TfrmDrawers.AddTemplateNode(const tmpl: TTemplate; const Owner: TTreeNode = nil);
668begin
669 dmodShared.AddTemplateNode(tvTemplates, FEmptyNodeCount, tmpl, FALSE, Owner);
670end;
671
672procedure TfrmDrawers.tvTemplatesGetImageIndex(Sender: TObject;
673 Node: TTreeNode);
674
675begin
676 Node.ImageIndex := dmodShared.ImgIdx(Node);
677end;
678
679procedure TfrmDrawers.tvTemplatesGetSelectedIndex(Sender: TObject;
680 Node: TTreeNode);
681begin
682//vw mod for template callup. Checks in test
683
684 //Application.MessageBox(PChar('Node='+IntToStr(Node.Index)+' tvtemplates.VertScrollPos='+IntToStr(tvTemplates.VertScrollPos)),PChar(Application.Title),MB_ICONINFORMATION);
685 sbTemplates.Caption := 'Templates '+ 'Node='+IntToStr(Node.Index)+' VertScrollPos='+IntToStr(tvTemplates.VertScrollPos) ;
686//end vw mod
687 Node.SelectedIndex := dmodShared.ImgIdx(Node);
688end;
689
690procedure TfrmDrawers.tvTemplatesExpanding(Sender: TObject;
691 Node: TTreeNode; var AllowExpansion: Boolean);
692begin
693 if(assigned(Node)) then
694 begin
695 if(Dragging) then EndDrag(FALSE);
696 if(not FInternalExpand) then
697 begin
698 if(TTemplate(Node.Data).RealType = ttGroup) then
699 begin
700 FAsk := TRUE;
701 FAskExp := TRUE;
702 AllowExpansion := FALSE;
703 FAskNode := Node;
704 end;
705 end;
706 if(AllowExpansion) then
707 begin
708 FClickOccurred := FALSE;
709 AllowExpansion := dmodShared.ExpandNode(tvTemplates, Node, FEmptyNodeCount);
710 if(FInternalHiddenExpand) then AllowExpansion := FALSE;
711 end;
712 end;
713 //vw mod for template callup. Checks in test
714
715 //Application.MessageBox(PChar('Node='+IntToStr(Node.Index)+' tvtemplates.VertScrollPos='+IntToStr(tvTemplates.VertScrollPos)),PChar(Application.Title),MB_ICONINFORMATION);
716 sbTemplates.Caption := 'Templates '+ 'Node='+IntToStr(Node.Index)+' VertScrollPos='+IntToStr(tvTemplates.VertScrollPos) ;
717 //end vw mod
718end;
719
720procedure TfrmDrawers.CheckAsk;
721begin
722 if(FAsk) then
723 begin
724 FAsk := FALSE;
725 FInternalExpand := TRUE;
726 try
727 if(FAskExp) then
728 FAskNode.Expand(FALSE)
729 else
730 FAskNode.Collapse(FALSE);
731 finally
732 FInternalExpand := FALSE;
733 end;
734 end;
735end;
736
737procedure TfrmDrawers.tvTemplatesClick(Sender: TObject);
738begin
739 FClickOccurred := TRUE;
740 CheckAsk;
741end;
742
743procedure TfrmDrawers.tvTemplatesDblClick(Sender: TObject);
744begin
745 if(not FClickOccurred) then CheckAsk
746 else
747 begin
748 FAsk := FALSE;
749 if((assigned(tvTemplates.Selected)) and
750 (TTemplate(tvTemplates.Selected.Data).RealType in [ttDoc, ttGroup])) then
751 InsertText;
752 end;
753end;
754
755procedure TfrmDrawers.tvTemplatesCollapsing(Sender: TObject;
756 Node: TTreeNode; var AllowCollapse: Boolean);
757begin
758 if(assigned(Node)) then
759 begin
760 if(Dragging) then EndDrag(FALSE);
761 if(not FInternalExpand) then
762 begin
763 if(TTemplate(Node.Data).RealType = ttGroup) then
764 begin
765 FAsk := TRUE;
766 FAskExp := FALSE;
767 AllowCollapse := FALSE;
768 FAskNode := Node;
769 end;
770 end;
771 if(AllowCollapse) then
772 FClickOccurred := FALSE;
773 end;
774 //vw mod for template callup. Checks in test
775
776 //Application.MessageBox(PChar('Node='+IntToStr(Node.Index)+' tvtemplates.VertScrollPos='+IntToStr(tvTemplates.VertScrollPos)),PChar(Application.Title),MB_ICONINFORMATION);
777 sbTemplates.Caption := 'Templates '+ 'Node='+IntToStr(Node.Index)+' VertScrollPos='+IntToStr(tvTemplates.VertScrollPos) ;
778 //end vw mod
779end;
780
781procedure TfrmDrawers.tvTemplatesKeyDown(Sender: TObject; var Key: Word;
782 Shift: TShiftState);
783begin
784 CheckAsk;
785 case Key of
786 VK_SPACE, VK_RETURN:
787 begin
788 InsertText;
789 Key := 0;
790 end;
791 end;
792end;
793
794procedure TfrmDrawers.tvTemplatesKeyUp(Sender: TObject; var Key: Word;
795 Shift: TShiftState);
796begin
797 CheckAsk;
798end;
799
800procedure TfrmDrawers.SetRichEditControl(const Value: TRichEdit);
801begin
802 if(FRichEditControl <> Value) then
803 begin
804 if(assigned(FRichEditControl)) then
805 begin
806 FRichEditControl.OnDragDrop := FOldDragDrop;
807 FRichEditControl.OnDragOver := FOldDragOver;
808 end;
809 FRichEditControl := Value;
810 if(assigned(FRichEditControl)) then
811 begin
812 FOldDragDrop := FRichEditControl.OnDragDrop;
813 FOldDragOver := FRichEditControl.OnDragOver;
814 FRichEditControl.OnDragDrop := NewRECDragDrop;
815 FRichEditControl.OnDragOver := NewRECDragOver;
816 end;
817 end;
818end;
819
820
821procedure TfrmDrawers.MoveCaret(X, Y: integer);
822var
823 pt: TPoint;
824
825begin
826 FRichEditControl.SetFocus;
827 pt := Point(x, y);
828 FRichEditControl.SelStart := FRichEditControl.Perform(EM_CHARFROMPOS,0,LParam(@pt));
829end;
830
831
832procedure TfrmDrawers.NewRECDragDrop(Sender, Source: TObject; X,
833 Y: Integer);
834begin
835 if(Source = tvTemplates) then
836 begin
837 MoveCaret(X, Y);
838 InsertText;
839 end
840 else
841 if(assigned(FOldDragDrop)) then
842 FOldDragDrop(Sender, Source, X, Y);
843end;
844
845procedure TfrmDrawers.NewRECDragOver(Sender, Source: TObject; X,
846 Y: Integer; State: TDragState; var Accept: Boolean);
847
848begin
849 Accept := FALSE;
850 if(Source = tvTemplates) then
851 begin
852 if(assigned(FDragNode)) and (TTemplate(FDragNode.Data).RealType in [ttDoc, ttGroup]) then
853 begin
854 Accept := TRUE;
855 MoveCaret(X, Y);
856 end;
857 end
858 else
859 if(assigned(FOldDragOver)) then
860 FOldDragOver(Sender, Source, X, Y, State, Accept);
861end;
862
863procedure TfrmDrawers.InsertText;
864var
865 BeforeLine, AfterTop: integer;
866 txt, DocInfo: string;
867 Template: TTemplate;
868
869begin
870 DocInfo := '';
871 if InsertOK(TRUE) and (dmodShared.TemplateOK(tvTemplates.Selected.Data)) then
872 begin
873 Template := TTemplate(tvTemplates.Selected.Data);
874 Template.TemplatePreviewMode := FALSE;
875 if Template.IsReminderDialog then
876 Template.ExecuteReminderDialog(TForm(Owner))
877 else
878 begin
879 if Template.IsCOMObject then
880 txt := Template.COMObjectText('', DocInfo)
881 else
882 txt := Template.Text;
883 if(txt <> '') then
884 begin
885 CheckBoilerplate4Fields(txt, 'Template: ' + Template.PrintName);
886 BeforeLine := SendMessage(FRichEditControl.Handle, EM_EXLINEFROMCHAR, 0, FRichEditControl.SelStart);
887 FRichEditControl.SelText := txt;
888 FRichEditControl.SetFocus;
889 SendMessage(FRichEditControl.Handle, EM_SCROLLCARET, 0, 0);
890 AfterTop := SendMessage(FRichEditControl.Handle, EM_GETFIRSTVISIBLELINE, 0, 0);
891 SendMessage(FRichEditControl.Handle, EM_LINESCROLL, 0, -1 * (AfterTop - BeforeLine));
892 end;
893 end;
894 end;
895end;
896
897procedure TfrmDrawers.popTemplatesPopup(Sender: TObject);
898var
899 Node: TTreeNode;
900 ok, ok2, NodeFound: boolean;
901 Def: string;
902
903begin
904 ok := FALSE;
905 ok2 := FALSE;
906 if(FOpenDrawer = odTemplates) then
907 begin
908 Node := tvTemplates.Selected;
909 tvTemplates.Selected := Node; // This line prevents selected from changing after menu closes
910 NodeFound := (assigned(Node));
911 if(NodeFound) then
912 begin
913 with TTemplate(Node.Data) do
914 begin
915 ok := (RealType in [ttDoc, ttGroup]);
916 ok2 := ok and (not IsReminderDialog) and (not IsCOMObject);
917 end;
918 end;
919 Def := Piece(GetUserTemplateDefaults, '/', FDefTempPiece);
920 mnuGotoDefault.Enabled := (Def <> '');
921 mnuViewNotes.Enabled := NodeFound and (TTemplate(Node.Data).Description <> '');
922 mnuDefault.Enabled := NodeFound;
923 mnuDefault.Checked := NodeFound and (tvTemplates.GetNodeID(TORTreeNode(Node), 1, ';') = Def);
924 end
925 else
926 begin
927 mnuDefault.Enabled := FALSE;
928 mnuGotoDefault.Enabled := FALSE;
929 mnuViewNotes.Enabled := FALSE;
930 end;
931 mnuPreviewTemplate.Enabled := ok2;
932 mnuCopyTemplate.Enabled := ok2;
933 mnuInsertTemplate.Enabled := ok and InsertOK(FALSE);
934 mnuFindTemplates.Enabled := (FOpenDrawer = odTemplates);
935 mnuCollapseTree.Enabled := ((FOpenDrawer = odTemplates) and
936 (dmodShared.NeedsCollapsing(tvTemplates)));
937 mnuEditTemplates.Enabled := (UserTemplateAccessLevel in [taAll, taEditor]);
938 mnuNewTemplate.Enabled := (UserTemplateAccessLevel in [taAll, taEditor]);
939end;
940
941procedure TfrmDrawers.mnuPreviewTemplateClick(Sender: TObject);
942var
943 tmpl: TTemplate;
944 txt: String;
945
946begin
947 if(assigned(tvTemplates.Selected)) then
948 begin
949 if(dmodShared.TemplateOK(tvTemplates.Selected.Data,'template preview')) then
950 begin
951 tmpl := TTemplate(tvTemplates.Selected.Data);
952 tmpl.TemplatePreviewMode := TRUE; // Prevents "Are you sure?" dialog when canceling
953 txt := tmpl.Text;
954 if(not tmpl.DialogAborted) then
955 ShowTemplateData(Self, tmpl.PrintName, txt);
956 end;
957 end;
958end;
959
960procedure TfrmDrawers.FormDestroy(Sender: TObject);
961begin
962 TAccessibleTreeView.UnwrapControl(tvReminders);
963 dmodShared.RemoveDrawerTree(Self);
964 KillObj(@FRemNotifyList);
965end;
966
967procedure TfrmDrawers.mnuCollapseTreeClick(Sender: TObject);
968begin
969 tvTemplates.Selected := nil;
970 tvTemplates.FullCollapse;
971end;
972
973procedure TfrmDrawers.ReloadTemplates;
974begin
975 LoadTemplateData;
976 if(UserTemplateAccessLevel <> taNone) and (assigned(MyTemplate)) and
977 (MyTemplate.Children in [tcActive, tcBoth]) then
978 begin
979 AddTemplateNode(MyTemplate);
980 FHasPersonalTemplates := TRUE;
981 end;
982 AddTemplateNode(RootTemplate);
983 OpenToNode;
984end;
985
986procedure TfrmDrawers.btnFindClick(Sender: TObject);
987var
988 TmpNode: TTreeNode;
989 Found: boolean;
990 S1,S2: string;
991
992begin
993 if(edtSearch.text <> '') then
994 begin
995 if(FEmptyNodeCount > 0) then
996 begin
997 FInternalExpand := TRUE;
998 FInternalHiddenExpand := TRUE;
999 try
1000 TmpNode := tvTemplates.Items.GetFirstNode;
1001 while(assigned(TmpNode)) do
1002 begin
1003 TmpNode.Expand(TRUE);
1004 TmpNode := TmpNode.GetNextSibling;
1005 end;
1006 finally
1007 FInternalExpand := FALSE;
1008 FInternalHiddenExpand := FALSE;
1009 end;
1010 end;
1011 if((FFindNext) and assigned (FLastFoundNode)) then
1012 TmpNode := FLastFoundNode.GetNext
1013 else
1014 TmpNode := tvTemplates.Items.GetFirstNode;
1015 Found := FALSE;
1016 if(assigned(TmpNode)) then
1017 begin
1018 S1 := edtSearch.Text;
1019 if(not cbMatchCase.Checked) then
1020 S1 := UpperCase(S1);
1021 while (assigned(TmpNode) and (not Found)) do
1022 begin
1023 S2 := TmpNode.Text;
1024 if(not cbMatchCase.Checked) then
1025 S2 := UpperCase(S2);
1026 Found := SearchMatch(S1, S2, cbWholeWords.Checked);
1027 if(not Found) then
1028 TmpNode := TmpNode.GetNext;
1029 end;
1030 end;
1031 if(Found) then
1032 begin
1033 FLastFoundNode := TmpNode;
1034 SetFindNext(TRUE);
1035 FInternalExpand := TRUE;
1036 try
1037 tvTemplates.Selected := TmpNode;
1038 finally
1039 FInternalExpand := FALSE;
1040 end;
1041 end
1042 else
1043 begin
1044 if(FFindNext) then
1045 S1 := ''
1046 else
1047 S1 := ' "' + edtSearch.Text + '" was not Found.';
1048 SetFindNext(FALSE);
1049 InfoBox('Search Complete.' + S1, 'Information', MB_OK or MB_ICONINFORMATION);
1050 end;
1051 end;
1052 edtSearch.SetFocus;
1053end;
1054
1055procedure TfrmDrawers.SetFindNext(const Value: boolean);
1056begin
1057 if(FFindNext <> Value) then
1058 begin
1059 FFindNext := Value;
1060 if(FFindNext) then btnFind.Caption := FindNextText
1061 else btnFind.Caption := 'Find';
1062 end;
1063end;
1064
1065procedure TfrmDrawers.edtSearchChange(Sender: TObject);
1066begin
1067 btnFind.Enabled := (edtSearch.Text <> '');
1068 SetFindNext(FALSE);
1069end;
1070
1071procedure TfrmDrawers.ToggleMenuItem(Sender: TObject);
1072var
1073 TmpMI: TMenuItem;
1074
1075begin
1076 TmpMI := (Sender as TMenuItem);
1077 TmpMI.Checked := not TmpMI.Checked;
1078 SetFindNext(FALSE);
1079 if(pnlTemplateSearch.Visible) then edtSearch.SetFocus;
1080end;
1081
1082procedure TfrmDrawers.edtSearchEnter(Sender: TObject);
1083begin
1084 btnFind.Default := TRUE;
1085end;
1086
1087procedure TfrmDrawers.edtSearchExit(Sender: TObject);
1088begin
1089 btnFind.Default := FALSE;
1090end;
1091
1092procedure TfrmDrawers.mnuFindTemplatesClick(Sender: TObject);
1093var
1094 FindOn: boolean;
1095
1096begin
1097 mnuFindTemplates.Checked := not mnuFindTemplates.Checked;
1098 FindOn := mnuFindTemplates.Checked;
1099 pnlTemplateSearch.Visible := FindOn;
1100 if(FindOn) and (FOpenDrawer = odTemplates) then
1101 edtSearch.SetFocus;
1102end;
1103
1104procedure TfrmDrawers.tvTemplatesDragging(Sender: TObject; Node: TTreeNode;
1105 var CanDrag: Boolean);
1106
1107begin
1108 if(TTemplate(Node.Data).RealType in [ttDoc, ttGroup]) then
1109 begin
1110 FDragNode := Node;
1111 CanDrag := TRUE;
1112 end
1113 else
1114 begin
1115 FDragNode := nil;
1116 CanDrag := FALSE;
1117 end;
1118end;
1119
1120procedure TfrmDrawers.mnuEditTemplatesClick(Sender: TObject);
1121begin
1122 EditTemplates(Self);
1123end;
1124
1125procedure TfrmDrawers.mnuNewTemplateClick(Sender: TObject);
1126begin
1127 EditTemplates(Self, TRUE);
1128end;
1129
1130procedure TfrmDrawers.FormCreate(Sender: TObject);
1131begin
1132 dmodShared.AddDrawerTree(Self);
1133 FHasPersonalTemplates := FALSE;
1134 TAccessibleTreeView.WrapControl(tvReminders);
1135end;
1136
1137procedure TfrmDrawers.ExternalReloadTemplates;
1138begin
1139 if(FOpenToNode = '') and (assigned(tvTemplates.Selected)) then
1140 FOpenToNode := tvTemplates.GetNodeID(TORTreeNode(tvTemplates.Selected),1,';');
1141 tvTemplates.Items.Clear;
1142 FHasPersonalTemplates := FALSE;
1143 FEmptyNodeCount := 0;
1144 ReloadTemplates;
1145end;
1146
1147procedure TfrmDrawers.DisplayDrawers(Show: Boolean);
1148begin
1149 DisplayDrawers(Show, [], []);
1150end;
1151
1152procedure TfrmDrawers.DisplayDrawers(Show: Boolean; AEnable, ADisplay: TDrawers);
1153begin
1154 if(not (csLoading in ComponentState)) then
1155 begin
1156 if Show then
1157 begin
1158 EnableDrawers(AEnable);
1159 ShowDrawers(ADisplay);
1160 end
1161 else
1162 begin
1163 ShowDrawers([]);
1164 end;
1165 if(assigned(FSplitter)) then
1166 begin
1167 if(Show and (FOpenDrawer <> odNone)) then
1168 SetSplitterActive(TRUE)
1169 else
1170 SetSplitterActive(FALSE);
1171 end;
1172 end;
1173end;
1174
1175function TfrmDrawers.CanEditTemplates: boolean;
1176begin
1177 Result := (UserTemplateAccessLevel in [taAll, taEditor]);
1178end;
1179
1180function TfrmDrawers.CanEditShared: boolean;
1181begin
1182 Result := (UserTemplateAccessLevel = taEditor);
1183end;
1184
1185procedure TfrmDrawers.pnlTemplateSearchResize(Sender: TObject);
1186begin
1187 if((cbMatchCase.Width + cbWholeWords.Width) > pnlTemplateSearch.Width) then
1188 cbWholeWords.Left := cbMatchCase.Width
1189 else
1190 cbWholeWords.Left := pnlTemplateSearch.Width - cbWholeWords.Width;
1191end;
1192
1193procedure TfrmDrawers.cbFindOptionClick(Sender: TObject);
1194begin
1195 SetFindNext(FALSE);
1196 if(pnlTemplateSearch.Visible) then edtSearch.SetFocus;
1197end;
1198
1199procedure TfrmDrawers.mnuInsertTemplateClick(Sender: TObject);
1200begin
1201 if((assigned(tvTemplates.Selected)) and
1202 (TTemplate(tvTemplates.Selected.Data).RealType in [ttDoc, ttGroup])) then
1203 InsertText;
1204end;
1205
1206procedure TfrmDrawers.SetSplitter(const Value: TSplitter);
1207begin
1208 if(FSplitter <> Value) then
1209 begin
1210 if(assigned(FSplitter)) then
1211 FSplitter.OnCanResize := FOldCanResize;
1212 FSplitter := Value;
1213 if(assigned(FSplitter)) then
1214 begin
1215 FOldCanResize := FSplitter.OnCanResize;
1216 FSplitter.OnCanResize := SplitterCanResize;
1217 SetSplitterActive(FSplitterActive);
1218 end;
1219 end;
1220end;
1221
1222procedure TfrmDrawers.SplitterCanResize(Sender: TObject; var NewSize: Integer; var Accept: Boolean);
1223begin
1224 Accept := FSplitterActive;
1225end;
1226
1227procedure TfrmDrawers.SetSplitterActive(Active: boolean);
1228begin
1229 FSplitterActive := Active;
1230 if(Active) then
1231 begin
1232 FSplitter.Cursor := crVSplit;
1233 FSplitter.ResizeStyle := rsPattern;
1234 end
1235 else
1236 begin
1237 FSplitter.Cursor := crDefault;
1238 FSplitter.ResizeStyle := ExtCtrls.rsNone;
1239 end;
1240end;
1241
1242procedure TfrmDrawers.UpdatePersonalTemplates;
1243var
1244 NeedPersonal: boolean;
1245 Node: TTreeNode;
1246
1247 function FindNode: TTreeNode;
1248 begin
1249 Result := tvTemplates.Items.GetFirstNode;
1250 while assigned(Result) do
1251 begin
1252 if(Result.Data = MyTemplate) then exit;
1253 Result := Result.getNextSibling;
1254 end;
1255 end;
1256
1257begin
1258 NeedPersonal := (UserTemplateAccessLevel <> taNone);
1259 if(NeedPersonal <> FHasPersonalTemplates) then
1260 begin
1261 if(NeedPersonal) then
1262 begin
1263 if(assigned(MyTemplate)) and (MyTemplate.Children in [tcActive, tcBoth]) then
1264 begin
1265 AddTemplateNode(MyTemplate);
1266 FHasPersonalTemplates := TRUE;
1267 if(assigned(MyTemplate)) then
1268 begin
1269 Node := FindNode;
1270 if(assigned(Node)) then
1271 Node.MoveTo(nil, naAddFirst);
1272 end;
1273 end;
1274 end
1275 else
1276 begin
1277 if(assigned(MyTemplate)) then
1278 begin
1279 Node := FindNode;
1280 if(assigned(Node)) then Node.Delete;
1281 end;
1282 FHasPersonalTemplates := FALSE;
1283 end;
1284 end;
1285end;
1286
1287procedure TfrmDrawers.RemindersChanged(Sender: TObject);
1288begin
1289 inc(FHoldResize);
1290 try
1291 if(EnableDrawer(odReminders, (GetReminderStatus <> rsNone))) then
1292 begin
1293 BuildReminderTree(tvReminders);
1294 FOldMouseUp := tvReminders.OnMouseUp;
1295 end
1296 else
1297 begin
1298 FOldMouseUp := nil;
1299 tvReminders.PopupMenu := nil;
1300 end;
1301 tvReminders.OnMouseUp := tvRemindersMouseUp;
1302 finally
1303 dec(FHoldResize);
1304 end;
1305end;
1306
1307procedure TfrmDrawers.tvRemindersMouseUp(Sender: TObject;
1308 Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
1309begin
1310 if(Button = mbLeft) and (assigned(tvReminders.Selected)) and
1311 (htOnItem in tvReminders.GetHitTestInfoAt(X, Y)) then
1312 ViewReminderDialog(ReminderNode(tvReminders.Selected));
1313end;
1314
1315procedure TfrmDrawers.PositionToReminder(Sender: TObject);
1316var
1317 Rem: TReminder;
1318
1319begin
1320 if(assigned(Sender)) then
1321 begin
1322 if(Sender is TReminder) then
1323 begin
1324 Rem := TReminder(Sender);
1325 if(Rem.CurrentNodeID <> '') then
1326 tvReminders.Selected := tvReminders.FindPieceNode(Rem.CurrentNodeID, 1, IncludeParentID)
1327 else
1328 begin
1329 tvReminders.Selected := tvReminders.FindPieceNode(RemCode + (Sender as TReminder).IEN, 1);
1330 if(assigned(tvReminders.Selected)) then
1331 TORTreeNode(tvReminders.Selected).EnsureVisible;
1332 end;
1333 Rem.CurrentNodeID := '';
1334 end;
1335 end
1336 else
1337 tvReminders.Selected := nil;
1338end;
1339
1340procedure TfrmDrawers.tvRemindersCurListChanged(Sender: TObject;
1341 Node: TTreeNode);
1342begin
1343 if(assigned(FRemNotifyList)) then
1344 FRemNotifyList.Notify(Node);
1345end;
1346
1347procedure TfrmDrawers.NotifyWhenRemTreeChanges(Proc: TNotifyEvent);
1348begin
1349 if(not assigned(FRemNotifyList)) then
1350 FRemNotifyList := TORNotifyList.Create;
1351 FRemNotifyList.Add(Proc);
1352end;
1353
1354procedure TfrmDrawers.RemoveNotifyWhenRemTreeChanges(Proc: TNotifyEvent);
1355begin
1356 if(assigned(FRemNotifyList)) then
1357 FRemNotifyList.Remove(Proc);
1358end;
1359
1360function TfrmDrawers.GetAlign: TAlign;
1361begin
1362 Result := inherited Align;
1363end;
1364
1365procedure TfrmDrawers.SetAlign(const Value: TAlign);
1366begin
1367 inherited Align := Value;
1368 ResizeToVisible;
1369end;
1370
1371procedure TfrmDrawers.ResetTemplates;
1372begin
1373 FOpenToNode := Piece(GetUserTemplateDefaults, '/', FDefTempPiece);
1374end;
1375
1376procedure TfrmDrawers.mnuDefaultClick(Sender: TObject);
1377var
1378 NodeID: string;
1379 UserTempDefNode: string;
1380begin
1381 NodeID := tvTemplates.GetNodeID(TORTreeNode(tvTemplates.Selected), 1, ';');
1382 UserTempDefNode := Piece(GetUserTemplateDefaults, '/', FDefTempPiece);
1383 if NodeID <> UserTempDefNode then
1384 SetUserTemplateDefaults(tvTemplates.GetNodeID(TORTreeNode(tvTemplates.Selected), 1, ';'),
1385 FDefTempPiece)
1386 else SetUserTemplateDefaults('', FDefTempPiece);
1387end;
1388
1389procedure TfrmDrawers.OpenToNode(Path: string = '');
1390var
1391 OldInternalHE, OldInternalEX: boolean;
1392
1393begin
1394 if(Path <> '') then
1395 FOpenToNode := PATH;
1396 if(FOpenToNode <> '') then
1397 begin
1398 OldInternalHE := FInternalHiddenExpand;
1399 OldInternalEX := FInternalExpand;
1400 try
1401 FInternalExpand := TRUE;
1402 FInternalHiddenExpand := FALSE;
1403 dmodShared.SelectNode(tvTemplates, FOpenToNode, FEmptyNodeCount);
1404 finally
1405 FInternalHiddenExpand := OldInternalHE;
1406 FInternalExpand := OldInternalEX;
1407 end;
1408 FOpenToNode := '';
1409 end;
1410end;
1411
1412procedure TfrmDrawers.mnuGotoDefaultClick(Sender: TObject);
1413begin
1414 OpenToNode(Piece(GetUserTemplateDefaults, '/', FDefTempPiece));
1415end;
1416
1417procedure TfrmDrawers.mnuViewNotesClick(Sender: TObject);
1418var
1419 tmpl: TTemplate;
1420 tmpSL: TStringList;
1421
1422begin
1423 if(assigned(tvTemplates.Selected)) then
1424 begin
1425 tmpl := TTemplate(tvTemplates.Selected.Data);
1426 if(tmpl.Description = '') then
1427 ShowMessage('No notes found for ' + tmpl.PrintName)
1428 else
1429 begin
1430 tmpSL := TStringList.Create;
1431 try
1432 tmpSL.Text := tmpl.Description;
1433 ReportBox(tmpSL, tmpl.PrintName + ' Notes:', TRUE);
1434 finally
1435 tmpSL.Free;
1436 end;
1437 end;
1438 end;
1439end;
1440
1441procedure TfrmDrawers.mnuCopyTemplateClick(Sender: TObject);
1442var
1443 txt: string;
1444 Template: TTemplate;
1445
1446begin
1447 txt := '';
1448 if((assigned(tvTemplates.Selected)) and
1449 (TTemplate(tvTemplates.Selected.Data).RealType in [ttDoc, ttGroup])) and
1450 (dmodShared.TemplateOK(tvTemplates.Selected.Data)) then
1451 begin
1452 Template := TTemplate(tvTemplates.Selected.Data);
1453 txt := Template.Text;
1454 CheckBoilerplate4Fields(txt, 'Template: ' + Template.PrintName);
1455 if txt <> '' then
1456 Clipboard.SetTextBuf(PChar(txt));
1457 end;
1458 if txt <> '' then
1459 StatusText('Templated Text copied to clipboard.');
1460end;
1461
1462function TfrmDrawers.InsertOK(Ask: boolean): boolean;
1463
1464 function REOK: boolean;
1465 begin
1466 Result := assigned(FRichEditControl) and
1467 FRichEditControl.Visible and
1468 FRichEditControl.Parent.Visible;
1469 end;
1470
1471begin
1472 Result := REOK;
1473 if (not ask) and (not Result) and (assigned(FNewNoteButton)) then
1474 Result := TRUE
1475 else
1476 if ask and (not Result) and assigned(FNewNoteButton) and
1477 FNewNoteButton.Visible and FNewNoteButton.Enabled then
1478 begin
1479 FNewNoteButton.Click;
1480 Result := REOK;
1481 end;
1482end;
1483
1484procedure TfrmDrawers.mnuViewTemplateIconLegendClick(Sender: TObject);
1485begin
1486 ShowIconLegend(ilTemplates);
1487end;
1488
1489procedure TfrmDrawers.pnlTemplatesButtonEnter(Sender: TObject);
1490begin
1491 with Sender as TPanel do
1492 if (ControlCount > 0) and (Controls[0] is TSpeedButton) and (TSpeedButton(Controls[0]).Down)
1493 then
1494 BevelOuter := bvLowered
1495 else
1496 BevelOuter := bvRaised;
1497end;
1498
1499procedure TfrmDrawers.pnlTemplatesButtonExit(Sender: TObject);
1500begin
1501 with Sender as TPanel do
1502 BevelOuter := bvNone;
1503 DisableArrowKeyMove(Sender);
1504end;
1505
1506procedure TfrmDrawers.tvRemindersKeyDown(Sender: TObject; var Key: Word;
1507 Shift: TShiftState);
1508begin
1509 case Key of
1510 VK_RETURN, VK_SPACE:
1511 begin
1512 ViewReminderDialog(ReminderNode(tvReminders.Selected));
1513 Key := 0;
1514 end;
1515 end;
1516end;
1517
1518procedure TfrmDrawers.tvRemindersNodeCaptioning(Sender: TObject;
1519 var Caption: String);
1520var
1521 StringData: string;
1522begin
1523 StringData := (Sender as TORTreeNode).StringData;
1524 if (Length(StringData) > 0) and (StringData[1] = 'R') then //Only tag reminder statuses
1525 case StrToIntDef(Piece(StringData,'^',6 {Due}),-1) of
1526 0: Caption := Caption + ' -- Applicable';
1527 1: Caption := Caption + ' -- DUE';
1528 2: Caption := Caption + ' -- Not Applicable';
1529 else Caption := Caption + ' -- Not Evaluated';
1530 end;
1531end;
1532
1533procedure TfrmDrawers.tvRemindersAddition(Sender: TObject;
1534 Node: TTreeNode);
1535begin
1536 TAccessibleTreeNode.WrapControl(Node as TORTreeNode);
1537end;
1538
1539procedure TfrmDrawers.tvRemindersDeletion(Sender: TObject;
1540 Node: TTreeNode);
1541begin
1542 TAccessibleTreeNode.UnwrapControl(Node as TORTreeNode);
1543end;
1544
1545procedure TfrmDrawers.DisableArrowKeyMove(Sender: TObject);
1546var
1547 CurrPanel : TKeyClickPanel;
1548begin
1549 if Sender is TKeyClickPanel then
1550 begin
1551 CurrPanel := Sender as TKeyClickPanel;
1552 If Boolean(Hi(GetKeyState(VK_UP)))
1553 OR Boolean(Hi(GetKeyState(VK_DOWN)))
1554 OR Boolean(Hi(GetKeyState(VK_LEFT)))
1555 OR Boolean(Hi(GetKeyState(VK_RIGHT))) then
1556 begin
1557 if Assigned(CurrPanel) then
1558 CurrPanel.SetFocus;
1559 end;
1560 end;
1561end;
1562
1563end.
1564
Note: See TracBrowser for help on using the repository browser.