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

Last change on this file since 1676 was 830, checked in by Kevin Toppenberg, 14 years ago

Upgrading to version 27

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