Module

fDrawers

Path

C:\CPRS\CPRS30\fDrawers.pas

Last Modified

7/15/2014 3:26:36 PM

Comments

Bugs noticed:
  if delete only note (currently editing) then drawers and encounter button still enabled

Initialization Code

initialization
  SpecifyFormIsNotADialog(TfrmDrawers);

end.

Units Used in Interface

Name Comments
fBase508Form -
uTemplates -

Units Used in Implementation

Name Comments
dShared -
fFindingTemplates -
fIconLegend -
fReminderDialog -
fRptBox -
fTemplateDialog -
fTemplateEditor -
fTemplateView -
rTemplates -
uCore -
uReminders -
uVA508CPRSCompatibility -

Classes

Name Comments
TfrmDrawers -

Procedures

Name Owner Declaration Scope Comments
AddTemplateNode TfrmDrawers procedure AddTemplateNode(const tmpl: TTemplate; const Owner: TTreeNode = nil); Protected -
AllCtrls - procedure AllCtrls(AAlign: TAlign); Local -
btnFindClick TfrmDrawers procedure btnFindClick(Sender: TObject); Public/Published -
cbFindOptionClick TfrmDrawers procedure cbFindOptionClick(Sender: TObject); Public/Published -
CheckAsk TfrmDrawers procedure CheckAsk; Protected -
DisableArrowKeyMove TfrmDrawers procedure DisableArrowKeyMove(Sender: TObject); Private -
DisplayDrawers TfrmDrawers procedure DisplayDrawers(Show: Boolean; AEnable, ADisplay: TDrawers); overload; Public -
DisplayDrawers TfrmDrawers procedure DisplayDrawers(Show: Boolean); overload; Public -
edtSearchChange TfrmDrawers procedure edtSearchChange(Sender: TObject); Public/Published -
edtSearchEnter TfrmDrawers procedure edtSearchEnter(Sender: TObject); Public/Published -
edtSearchExit TfrmDrawers procedure edtSearchExit(Sender: TObject); Public/Published -
EnableDrawers TfrmDrawers procedure EnableDrawers(Drawers: TDrawers); Public -
EndInternalResize TfrmDrawers procedure EndInternalResize; Protected -
ExternalReloadTemplates TfrmDrawers procedure ExternalReloadTemplates; Public -
fldAccessRemindersInstructionsQuery TfrmDrawers procedure fldAccessRemindersInstructionsQuery(Sender: TObject; var Text: string); Public/Published -
fldAccessRemindersStateQuery TfrmDrawers procedure fldAccessRemindersStateQuery(Sender: TObject; var Text: string); Public/Published -
fldAccessTemplatesInstructionsQuery TfrmDrawers procedure fldAccessTemplatesInstructionsQuery(Sender: TObject; var Text: string); Public/Published -
fldAccessTemplatesStateQuery TfrmDrawers procedure fldAccessTemplatesStateQuery(Sender: TObject; var Text: string); Public/Published -
FontChanged TfrmDrawers procedure FontChanged(Sender: TObject); Protected -
FormCanResize TfrmDrawers procedure FormCanResize(Sender: TObject; var NewWidth, NewHeight: Integer; var Resize: Boolean); Public/Published -
FormCreate TfrmDrawers procedure FormCreate(Sender: TObject); Public/Published -
FormDestroy TfrmDrawers procedure FormDestroy(Sender: TObject); Public/Published -
FormResize TfrmDrawers procedure FormResize(Sender: TObject); Public/Published -
GetDrawerControls TfrmDrawers procedure GetDrawerControls(Drawer: TDrawer; var Btn: TORAlignSpeedButton; var Ctrl: TWinControl); Protected -
InitButtons TfrmDrawers procedure InitButtons; Protected -
InsertText TfrmDrawers procedure InsertText; Protected -
mnuCollapseTreeClick TfrmDrawers procedure mnuCollapseTreeClick(Sender: TObject); Public/Published -
mnuCopyTemplateClick TfrmDrawers procedure mnuCopyTemplateClick(Sender: TObject); Public/Published -
mnuDefaultClick TfrmDrawers procedure mnuDefaultClick(Sender: TObject); Public/Published -
mnuEditTemplatesClick TfrmDrawers procedure mnuEditTemplatesClick(Sender: TObject); Public/Published -
mnuFindTemplatesClick TfrmDrawers procedure mnuFindTemplatesClick(Sender: TObject); Public/Published -
mnuGotoDefaultClick TfrmDrawers procedure mnuGotoDefaultClick(Sender: TObject); Public/Published -
mnuInsertTemplateClick TfrmDrawers procedure mnuInsertTemplateClick(Sender: TObject); Public/Published -
mnuNewTemplateClick TfrmDrawers procedure mnuNewTemplateClick(Sender: TObject); Public/Published -
mnuPreviewTemplateClick TfrmDrawers procedure mnuPreviewTemplateClick(Sender: TObject); Public/Published -
mnuViewNotesClick TfrmDrawers procedure mnuViewNotesClick(Sender: TObject); Public/Published -
mnuViewTemplateIconLegendClick TfrmDrawers procedure mnuViewTemplateIconLegendClick(Sender: TObject); Public/Published -
MoveCaret TfrmDrawers procedure MoveCaret(X, Y: integer); Protected -
NewRECDragDrop TfrmDrawers procedure NewRECDragDrop(Sender, Source: TObject; X, Y: Integer); Protected -
NewRECDragOver TfrmDrawers procedure NewRECDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); Protected -
NotifyWhenRemTreeChanges TfrmDrawers procedure NotifyWhenRemTreeChanges(Proc: TNotifyEvent); Public -
OpenDrawer TfrmDrawers procedure OpenDrawer(Drawer: TDrawer); Public -
OpenToNode TfrmDrawers procedure OpenToNode(Path: string = ''); Protected -
pnlTemplatesButtonEnter TfrmDrawers procedure pnlTemplatesButtonEnter(Sender: TObject); Public/Published -
pnlTemplatesButtonExit TfrmDrawers procedure pnlTemplatesButtonExit(Sender: TObject); Public/Published -
pnlTemplateSearchResize TfrmDrawers procedure pnlTemplateSearchResize(Sender: TObject); Public/Published -
popTemplatesPopup TfrmDrawers procedure popTemplatesPopup(Sender: TObject); Public/Published -
PositionToReminder TfrmDrawers procedure PositionToReminder(Sender: TObject); Protected -
ReloadTemplates TfrmDrawers procedure ReloadTemplates; Protected -
RemindersChanged TfrmDrawers procedure RemindersChanged(Sender: TObject); Protected -
RemoveNotifyWhenRemTreeChanges TfrmDrawers procedure RemoveNotifyWhenRemTreeChanges(Proc: TNotifyEvent); Public -
ResetTemplates TfrmDrawers procedure ResetTemplates; Public -
ResizeToVisible TfrmDrawers procedure ResizeToVisible; Protected -
sbEncounterClick TfrmDrawers procedure sbEncounterClick(Sender: TObject); Public/Published -
sbOrdersClick TfrmDrawers procedure sbOrdersClick(Sender: TObject); Public/Published -
sbRemindersClick TfrmDrawers procedure sbRemindersClick(Sender: TObject); Public/Published -
sbResize TfrmDrawers procedure sbResize(Sender: TObject); Public/Published -
sbTemplatesClick TfrmDrawers procedure sbTemplatesClick(Sender: TObject); Public/Published -
SetAlign TfrmDrawers procedure SetAlign(const Value: TAlign); Private -
SetFindNext TfrmDrawers procedure SetFindNext(const Value: boolean); Protected -
SetRichEditControl TfrmDrawers procedure SetRichEditControl(const Value: TRichEdit); Protected -
SetSplitter TfrmDrawers procedure SetSplitter(const Value: TSplitter); Protected -
SetSplitterActive TfrmDrawers procedure SetSplitterActive(Active: boolean); Protected -
ShowDrawers TfrmDrawers procedure ShowDrawers(Drawers: TDrawers); Public -
SplitterCanResize TfrmDrawers procedure SplitterCanResize(Sender: TObject; var NewSize: Integer; var Accept: Boolean); Protected -
StartInternalResize TfrmDrawers procedure StartInternalResize; Protected -
ToggleDrawer TfrmDrawers procedure ToggleDrawer(Drawer: TDrawer); Public -
ToggleMenuItem TfrmDrawers procedure ToggleMenuItem(Sender: TObject); Public/Published -
tvRemindersCurListChanged TfrmDrawers procedure tvRemindersCurListChanged(Sender: TObject; Node: TTreeNode); Public/Published -
tvRemindersKeyDown TfrmDrawers procedure tvRemindersKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); Public/Published -
tvRemindersMouseUp TfrmDrawers procedure tvRemindersMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); Public/Published -
tvRemindersNodeCaptioning TfrmDrawers procedure tvRemindersNodeCaptioning(Sender: TObject; var Caption: String); Public/Published -
tvTemplatesClick TfrmDrawers procedure tvTemplatesClick(Sender: TObject); Public/Published -
tvTemplatesCollapsing TfrmDrawers procedure tvTemplatesCollapsing(Sender: TObject; Node: TTreeNode; var AllowCollapse: Boolean); Public/Published -
tvTemplatesDblClick TfrmDrawers procedure tvTemplatesDblClick(Sender: TObject); Public/Published -
tvTemplatesDragging TfrmDrawers procedure tvTemplatesDragging(Sender: TObject; Node: TTreeNode; var CanDrag: Boolean); Public/Published -
tvTemplatesExpanding TfrmDrawers procedure tvTemplatesExpanding(Sender: TObject; Node: TTreeNode; var AllowExpansion: Boolean); Public/Published -
tvTemplatesGetImageIndex TfrmDrawers procedure tvTemplatesGetImageIndex(Sender: TObject; Node: TTreeNode); Public/Published -
tvTemplatesGetSelectedIndex TfrmDrawers procedure tvTemplatesGetSelectedIndex(Sender: TObject; Node: TTreeNode); Public/Published -
tvTemplatesKeyDown TfrmDrawers procedure tvTemplatesKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); Public/Published -
tvTemplatesKeyUp TfrmDrawers procedure tvTemplatesKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); Public/Published -
UpdatePersonalTemplates TfrmDrawers procedure UpdatePersonalTemplates; Public -

Functions

Name Owner Declaration Scope Comments
ButtonHeights TfrmDrawers function ButtonHeights: integer; Protected -
CanEditShared TfrmDrawers function CanEditShared: boolean; Public -
CanEditTemplates TfrmDrawers function CanEditTemplates: boolean; Public -
EnableDrawer TfrmDrawers function EnableDrawer(Drawer: TDrawer; EnableIt: boolean): boolean; Protected -
FindNode - function FindNode: TTreeNode; Local -
GetAlign TfrmDrawers function GetAlign: TAlign; Private -
InsertOK TfrmDrawers function InsertOK(Ask: boolean): boolean; Protected -
MinDrawerControlHeight TfrmDrawers function MinDrawerControlHeight: integer; Private -
REOK - function REOK: boolean; Local -

Constants

Name Declaration Scope Comments
BaseMinDrawerControlHeight 24 Global -
DrawerSplitters 'frmDrawersSplitters' Interfaced -
FindNextText 'Find Next' Global -
odEncounter TDrawer Interfaced -
odNone TDrawer Interfaced -
odOrders TDrawer Interfaced -
odReminders TDrawer Interfaced -
odTemplates TDrawer Interfaced -


Module Source

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

Module Calls (2 levels)


fDrawers
 ├uTemplates
 │ ├uTIU
 │ ├uDCSumm
 │ ├rTemplates
 │ ├uCore
 │ ├dShared
 │ ├fTemplateDialog
 │ ├uTemplateFields
 │ ├fTemplateImport
 │ ├rCore
 │ ├uConst
 │ ├uEventHooks
 │ ├fReminderDialog
 │ └rODBase
 ├fBase508Form
 │ ├uConst
 │ └uHelpManager
 ├fTemplateView
 │ ├fBase508Form...
 │ ├fTemplateDialog...
 │ ├fRptBox
 │ └rMisc
 ├rTemplates...
 ├fTemplateEditor
 │ ├uTemplates...
 │ ├fBase508Form...
 │ ├dShared...
 │ ├uCore...
 │ ├rTemplates...
 │ ├fTemplateObjects
 │ ├uSpell
 │ ├fTemplateView...
 │ ├fTemplateAutoGen
 │ ├fDrawers...
 │ ├fTemplateFieldEditor
 │ ├fTemplateFields
 │ ├fIconLegend
 │ ├uReminders
 │ ├uConst
 │ ├rEventHooks
 │ ├rConsults
 │ ├rMisc...
 │ └fFindingTemplates
 ├dShared...
 ├uReminders...
 ├fReminderDialog...
 ├fRptBox...
 ├fTemplateDialog...
 ├fIconLegend...
 ├uVA508CPRSCompatibility
 │ ├uDlgComponents
 │ ├fFrame
 │ ├uCore...
 │ └mTemplateFieldButton
 └fFindingTemplates...

Module Called-By (2 levels)


                   fDrawers
                   fFrame┤ 
              CPRSChart┤ │ 
                  fPage┤ │ 
                uOrders┤ │ 
                fODBase┤ │ 
                UBACore┤ │ 
                fOrders┤ │ 
                   uPCE┤ │ 
      fBALocalDiagnoses┤ │ 
             fEncVitals┤ │ 
                fVitals┤ │ 
                 fCover┤ │ 
                 rCover┤ │ 
              fPtSelMsg┤ │ 
                 fPtSel┤ │ 
            fOrdersSign┤ │ 
         fPrintLocation┤ │ 
                  fMeds┤ │ 
                fRptBox┤ │ 
                 fNotes┤ │ 
               fReports┤ │ 
                 fEncnt┤ │ 
                 fProbs┤ │ 
          fReportsPrint┤ │ 
                fGraphs┤ │ 
              fConsults┤ │ 
                fDCSumm┤ │ 
        fReminderDialog┤ │ 
                  fLabs┤ │ 
              fLabPrint┤ │ 
                fReview┤ │ 
            fIconLegend┤ │ 
           fOrdersPrint┤ │ 
               fSurgery┤ │ 
uVA508CPRSCompatibility┤ │ 
           fOrdersRenew┤ │ 
             fODConsult┤ │ 
                fODProc┤ │ 
                 fODRad┤ │ 
                 fODLab┤ │ 
                fODMeds┤ │ 
               fODMedIV┤ │ 
              fODVitals┤ │ 
                fODAuto┤ │ 
                 fOMSet┤ │ 
         fOrdersRelease┤ │ 
              fODMedNVA┤ │ 
         fOrdersOnChart┤ │ 
             fOCSession┤ │ 
              fODActive┤ │ 
               fPCEEdit┘ │ 
                  dShared┤ 
              CPRSChart┤ │ 
                uODBase┤ │ 
             uTemplates┤ │ 
            fDrawers...┤ │ 
        fTemplateDialog┤ │ 
             uReminders┤ │ 
              fNotes...┤ │ 
            fReports...┤ │ 
           fConsults...┤ │ 
             fDCSumm...┤ │ 
        fTemplateEditor┤ │ 
            fSurgery...┤ │ 
       fTemplateObjects┤ │ 
       fTemplateAutoGen┘ │ 
            uReminders...┤ 
                fNotes...┤ 
             fConsults...┤ 
               fDCSumm...┤ 
       fTemplateEditor...┤ 
              fSurgery...┘