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

Last change on this file since 1722 was 1679, checked in by healthsevak, 10 years ago

Updating the working copy to CPRS version 28

File size: 43.0 KB
Line 
1unit fDrawers;
2{
3bugs noticed:
4 if delete only note (currently editing) then drawers and encounter button still enabled
5}
6interface
7
8uses
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
14type
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
214const
215 DrawerSplitters = 'frmDrawersSplitters';
216
217implementation
218
219uses fTemplateView, uCore, rTemplates, fTemplateEditor, dShared, uReminders,
220 fReminderDialog, RichEdit, fRptBox, Clipbrd, fTemplateDialog, fIconLegend,
221 VA508AccessibilityRouter, uVA508CPRSCompatibility, VAUtils, fFindingTemplates;
222
223{$R *.DFM}
224
225const
226 BaseMinDrawerControlHeight = 24;
227 FindNextText = 'Find Next';
228
229function TfrmDrawers.MinDrawerControlHeight: integer;
230begin
231 result := ResizeHeight( BaseFont, MainFont, BaseMinDrawerControlHeight);
232end;
233
234procedure TfrmDrawers.ResizeToVisible;
235var
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
259begin
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;
297end;
298
299procedure TfrmDrawers.FormCanResize(Sender: TObject; var NewWidth,
300 NewHeight: Integer; var Resize: Boolean);
301var
302 od: TDrawer;
303 Btn: TORAlignSpeedButton;
304 Ctrl: TWinControl;
305 IsVisible: boolean;
306
307begin
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;
323end;
324
325function TfrmDrawers.ButtonHeights: integer;
326begin
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;
340end;
341
342procedure TfrmDrawers.ShowDrawers(Drawers: TDrawers);
343var
344 od: TDrawer;
345 Btn: TORAlignSpeedButton;
346 Ctrl: TWinControl;
347 SaveLOS: integer;
348
349begin
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;
376end;
377
378procedure TfrmDrawers.OpenDrawer(Drawer: TDrawer);
379var
380 Btn: TORAlignSpeedButton;
381 Ctrl: TWinControl;
382
383begin
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;
424end;
425
426procedure TfrmDrawers.GetDrawerControls(Drawer: TDrawer;
427 var Btn: TORAlignSpeedButton; var Ctrl: TWinControl);
428begin
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;
460end;
461
462constructor TfrmDrawers.CreateDrawers(AOwner: TComponent; AParent: TWinControl;
463 VisibleDrawers, EnabledDrawers: TDrawers);
464begin
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;
483end;
484
485function TfrmDrawers.EnableDrawer(Drawer: TDrawer; EnableIt: boolean): boolean;
486var
487 Btn: TORAlignSpeedButton;
488 Ctrl: TWinControl;
489
490begin
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;
502end;
503
504procedure TfrmDrawers.EnableDrawers(Drawers: TDrawers);
505var
506 od: TDrawer;
507
508begin
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;
521end;
522
523procedure TfrmDrawers.FormResize(Sender: TObject);
524begin
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;
533end;
534
535procedure TfrmDrawers.sbTemplatesClick(Sender: TObject);
536begin
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;
546end;
547
548procedure TfrmDrawers.sbEncounterClick(Sender: TObject);
549begin
550 ToggleDrawer(odEncounter);
551end;
552
553procedure TfrmDrawers.sbRemindersClick(Sender: TObject);
554begin
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;
573end;
574
575procedure TfrmDrawers.sbOrdersClick(Sender: TObject);
576begin
577 ToggleDrawer(odOrders);
578end;
579
580procedure TfrmDrawers.ToggleDrawer(Drawer: TDrawer);
581begin
582 if(Drawer = FOpenDrawer) then
583 OpenDrawer(odNone)
584 else
585 OpenDrawer(Drawer);
586end;
587
588procedure TfrmDrawers.EndInternalResize;
589begin
590 if(FInternalResize > 0) then dec(FInternalResize);
591end;
592
593procedure TfrmDrawers.StartInternalResize;
594begin
595 inc(FInternalResize);
596end;
597
598procedure TfrmDrawers.sbResize(Sender: TObject);
599var
600 Button: TORAlignSpeedButton;
601 Mar: integer; // Mar Needed because you can't assign Margin a negative value
602
603begin
604 Button := (Sender as TORAlignSpeedButton);
605 Mar := (Button.Width - FTextIconWidth) div 2;
606 if(Mar < 0) then
607 Mar := 0;
608 Button.Margin := Mar;
609end;
610
611procedure TfrmDrawers.InitButtons;
612var
613 od: TDrawer;
614 Btn: TORAlignSpeedButton;
615 Ctrl: TWinControl;
616 TmpWidth: integer;
617 TmpHeight: integer;
618 MaxHeight: integer;
619
620begin
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;
649end;
650
651procedure TfrmDrawers.FontChanged(Sender: TObject);
652var
653 Ht: integer;
654
655begin
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;
677end;
678
679procedure TfrmDrawers.AddTemplateNode(const tmpl: TTemplate; const Owner: TTreeNode = nil);
680begin
681 dmodShared.AddTemplateNode(tvTemplates, FEmptyNodeCount, tmpl, FALSE, Owner);
682end;
683
684procedure TfrmDrawers.tvTemplatesGetImageIndex(Sender: TObject;
685 Node: TTreeNode);
686
687begin
688 Node.ImageIndex := dmodShared.ImgIdx(Node);
689end;
690
691procedure TfrmDrawers.tvTemplatesGetSelectedIndex(Sender: TObject;
692 Node: TTreeNode);
693begin
694 Node.SelectedIndex := dmodShared.ImgIdx(Node);
695end;
696
697procedure TfrmDrawers.tvTemplatesExpanding(Sender: TObject;
698 Node: TTreeNode; var AllowExpansion: Boolean);
699begin
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;
720end;
721
722procedure TfrmDrawers.CheckAsk;
723begin
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;
737end;
738
739procedure TfrmDrawers.tvTemplatesClick(Sender: TObject);
740begin
741 FClickOccurred := TRUE;
742 CheckAsk;
743end;
744
745procedure TfrmDrawers.tvTemplatesDblClick(Sender: TObject);
746begin
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;
755end;
756
757procedure TfrmDrawers.tvTemplatesCollapsing(Sender: TObject;
758 Node: TTreeNode; var AllowCollapse: Boolean);
759begin
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;
776end;
777
778procedure TfrmDrawers.tvTemplatesKeyDown(Sender: TObject; var Key: Word;
779 Shift: TShiftState);
780begin
781 CheckAsk;
782 case Key of
783 VK_SPACE, VK_RETURN:
784 begin
785 InsertText;
786 Key := 0;
787 end;
788 end;
789end;
790
791procedure TfrmDrawers.tvTemplatesKeyUp(Sender: TObject; var Key: Word;
792 Shift: TShiftState);
793begin
794 CheckAsk;
795end;
796
797procedure TfrmDrawers.SetRichEditControl(const Value: TRichEdit);
798begin
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;
815end;
816
817
818procedure TfrmDrawers.MoveCaret(X, Y: integer);
819var
820 pt: TPoint;
821
822begin
823 FRichEditControl.SetFocus;
824 pt := Point(x, y);
825 FRichEditControl.SelStart := FRichEditControl.Perform(EM_CHARFROMPOS,0,LParam(@pt));
826end;
827
828
829procedure TfrmDrawers.NewRECDragDrop(Sender, Source: TObject; X,
830 Y: Integer);
831begin
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);
840end;
841
842procedure TfrmDrawers.NewRECDragOver(Sender, Source: TObject; X,
843 Y: Integer; State: TDragState; var Accept: Boolean);
844
845begin
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);
858end;
859
860procedure TfrmDrawers.InsertText;
861var
862 BeforeLine, AfterTop: integer;
863 txt, DocInfo: string;
864 Template: TTemplate;
865
866begin
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;
896end;
897
898procedure TfrmDrawers.popTemplatesPopup(Sender: TObject);
899var
900 Node: TTreeNode;
901 ok, ok2, NodeFound: boolean;
902 Def: string;
903
904begin
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]);
940end;
941
942procedure TfrmDrawers.mnuPreviewTemplateClick(Sender: TObject);
943var
944 tmpl: TTemplate;
945 txt: String;
946
947begin
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;
959end;
960
961procedure TfrmDrawers.FormDestroy(Sender: TObject);
962begin
963 dmodShared.RemoveDrawerTree(Self);
964 KillObj(@FRemNotifyList);
965end;
966
967procedure TfrmDrawers.mnuCollapseTreeClick(Sender: TObject);
968begin
969 tvTemplates.Selected := nil;
970 tvTemplates.FullCollapse;
971end;
972
973procedure TfrmDrawers.ReloadTemplates;
974begin
975 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;
985end;
986
987procedure TfrmDrawers.btnFindClick(Sender: TObject);
988var
989 Found, TmpNode: TTreeNode;
990 IsNext: boolean;
991
992begin
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;
1023end;
1024
1025procedure TfrmDrawers.SetFindNext(const Value: boolean);
1026begin
1027 if(FFindNext <> Value) then
1028 begin
1029 FFindNext := Value;
1030 if(FFindNext) then btnFind.Caption := FindNextText
1031 else btnFind.Caption := 'Find';
1032 end;
1033end;
1034
1035procedure TfrmDrawers.edtSearchChange(Sender: TObject);
1036begin
1037 btnFind.Enabled := (edtSearch.Text <> '');
1038 SetFindNext(FALSE);
1039end;
1040
1041procedure TfrmDrawers.ToggleMenuItem(Sender: TObject);
1042var
1043 TmpMI: TMenuItem;
1044
1045begin
1046 TmpMI := (Sender as TMenuItem);
1047 TmpMI.Checked := not TmpMI.Checked;
1048 SetFindNext(FALSE);
1049 if(pnlTemplateSearch.Visible) then edtSearch.SetFocus;
1050end;
1051
1052procedure TfrmDrawers.edtSearchEnter(Sender: TObject);
1053begin
1054 btnFind.Default := TRUE;
1055end;
1056
1057procedure TfrmDrawers.edtSearchExit(Sender: TObject);
1058begin
1059 btnFind.Default := FALSE;
1060end;
1061
1062procedure TfrmDrawers.mnuFindTemplatesClick(Sender: TObject);
1063var
1064 FindOn: boolean;
1065
1066begin
1067 mnuFindTemplates.Checked := not mnuFindTemplates.Checked;
1068 FindOn := mnuFindTemplates.Checked;
1069 pnlTemplateSearch.Visible := FindOn;
1070 if(FindOn) and (FOpenDrawer = odTemplates) then
1071 edtSearch.SetFocus;
1072end;
1073
1074procedure TfrmDrawers.tvTemplatesDragging(Sender: TObject; Node: TTreeNode;
1075 var CanDrag: Boolean);
1076
1077begin
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;
1088end;
1089
1090procedure TfrmDrawers.mnuEditTemplatesClick(Sender: TObject);
1091begin
1092 EditTemplates(Self);
1093end;
1094
1095procedure TfrmDrawers.mnuNewTemplateClick(Sender: TObject);
1096begin
1097 EditTemplates(Self, TRUE);
1098end;
1099
1100procedure TfrmDrawers.FormCreate(Sender: TObject);
1101begin
1102 dmodShared.AddDrawerTree(Self);
1103 FHasPersonalTemplates := FALSE;
1104end;
1105
1106procedure TfrmDrawers.ExternalReloadTemplates;
1107begin
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;
1114end;
1115
1116procedure TfrmDrawers.fldAccessRemindersInstructionsQuery(Sender: TObject;
1117 var Text: string);
1118begin
1119 inherited;
1120 if FOpenDrawer = odReminders then
1121 Text := 'to close'
1122 else
1123 Text := 'to open';
1124 Text := Text + ' drawer press space bar';
1125end;
1126
1127procedure TfrmDrawers.fldAccessRemindersStateQuery(Sender: TObject;
1128 var Text: string);
1129begin
1130 inherited;
1131 if FOpenDrawer = odReminders then
1132 Text := ', Drawer Open'
1133 else
1134 Text := ', Drawer Closed';
1135end;
1136
1137procedure TfrmDrawers.fldAccessTemplatesInstructionsQuery(Sender: TObject;
1138 var Text: string);
1139begin
1140 inherited;
1141 if FOpenDrawer = odTemplates then
1142 Text := 'to close'
1143 else
1144 Text := 'to open';
1145 Text := Text + ' drawer press space bar';
1146end;
1147
1148procedure TfrmDrawers.fldAccessTemplatesStateQuery(Sender: TObject;
1149 var Text: string);
1150begin
1151 if FOpenDrawer = odTemplates then
1152 Text := ', Drawer Open'
1153 else
1154 Text := ', Drawer Closed';
1155end;
1156
1157procedure TfrmDrawers.DisplayDrawers(Show: Boolean);
1158begin
1159 DisplayDrawers(Show, [], []);
1160end;
1161
1162procedure TfrmDrawers.DisplayDrawers(Show: Boolean; AEnable, ADisplay: TDrawers);
1163begin
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;
1183end;
1184
1185function TfrmDrawers.CanEditTemplates: boolean;
1186begin
1187 Result := (UserTemplateAccessLevel in [taAll, taEditor]);
1188end;
1189
1190function TfrmDrawers.CanEditShared: boolean;
1191begin
1192 Result := (UserTemplateAccessLevel = taEditor);
1193end;
1194
1195procedure TfrmDrawers.pnlTemplateSearchResize(Sender: TObject);
1196begin
1197 if((cbMatchCase.Width + cbWholeWords.Width) > pnlTemplateSearch.Width) then
1198 cbWholeWords.Left := cbMatchCase.Width
1199 else
1200 cbWholeWords.Left := pnlTemplateSearch.Width - cbWholeWords.Width;
1201end;
1202
1203procedure TfrmDrawers.cbFindOptionClick(Sender: TObject);
1204begin
1205 SetFindNext(FALSE);
1206 if(pnlTemplateSearch.Visible) then edtSearch.SetFocus;
1207end;
1208
1209procedure TfrmDrawers.mnuInsertTemplateClick(Sender: TObject);
1210begin
1211 if((assigned(tvTemplates.Selected)) and
1212 (TTemplate(tvTemplates.Selected.Data).RealType in [ttDoc, ttGroup])) then
1213 InsertText;
1214end;
1215
1216procedure TfrmDrawers.SetSplitter(const Value: TSplitter);
1217begin
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;
1230end;
1231
1232procedure TfrmDrawers.SplitterCanResize(Sender: TObject; var NewSize: Integer; var Accept: Boolean);
1233begin
1234 Accept := FSplitterActive;
1235end;
1236
1237procedure TfrmDrawers.SetSplitterActive(Active: boolean);
1238begin
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;
1250end;
1251
1252procedure TfrmDrawers.UpdatePersonalTemplates;
1253var
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
1267begin
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;
1295end;
1296
1297procedure TfrmDrawers.RemindersChanged(Sender: TObject);
1298begin
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;
1315end;
1316
1317procedure TfrmDrawers.tvRemindersMouseUp(Sender: TObject;
1318 Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
1319begin
1320 if(Button = mbLeft) and (assigned(tvReminders.Selected)) and
1321 (htOnItem in tvReminders.GetHitTestInfoAt(X, Y)) then
1322 ViewReminderDialog(ReminderNode(tvReminders.Selected));
1323end;
1324
1325procedure TfrmDrawers.PositionToReminder(Sender: TObject);
1326var
1327 Rem: TReminder;
1328
1329begin
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;
1348end;
1349
1350procedure TfrmDrawers.tvRemindersCurListChanged(Sender: TObject;
1351 Node: TTreeNode);
1352begin
1353 if(assigned(FRemNotifyList)) then
1354 FRemNotifyList.Notify(Node);
1355end;
1356
1357procedure TfrmDrawers.NotifyWhenRemTreeChanges(Proc: TNotifyEvent);
1358begin
1359 if(not assigned(FRemNotifyList)) then
1360 FRemNotifyList := TORNotifyList.Create;
1361 FRemNotifyList.Add(Proc);
1362end;
1363
1364procedure TfrmDrawers.RemoveNotifyWhenRemTreeChanges(Proc: TNotifyEvent);
1365begin
1366 if(assigned(FRemNotifyList)) then
1367 FRemNotifyList.Remove(Proc);
1368end;
1369
1370function TfrmDrawers.GetAlign: TAlign;
1371begin
1372 Result := inherited Align;
1373end;
1374
1375procedure TfrmDrawers.SetAlign(const Value: TAlign);
1376begin
1377 inherited Align := Value;
1378 ResizeToVisible;
1379end;
1380
1381procedure TfrmDrawers.ResetTemplates;
1382begin
1383 FOpenToNode := Piece(GetUserTemplateDefaults, '/', FDefTempPiece);
1384end;
1385
1386procedure TfrmDrawers.mnuDefaultClick(Sender: TObject);
1387var
1388 NodeID: string;
1389 UserTempDefNode: string;
1390begin
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);
1397end;
1398
1399procedure TfrmDrawers.OpenToNode(Path: string = '');
1400var
1401 OldInternalHE, OldInternalEX: boolean;
1402
1403begin
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;
1420end;
1421
1422procedure TfrmDrawers.mnuGotoDefaultClick(Sender: TObject);
1423begin
1424 OpenToNode(Piece(GetUserTemplateDefaults, '/', FDefTempPiece));
1425end;
1426
1427procedure TfrmDrawers.mnuViewNotesClick(Sender: TObject);
1428var
1429 tmpl: TTemplate;
1430 tmpSL: TStringList;
1431
1432begin
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;
1449end;
1450
1451procedure TfrmDrawers.mnuCopyTemplateClick(Sender: TObject);
1452var
1453 txt: string;
1454 Template: TTemplate;
1455
1456begin
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.');
1473end;
1474
1475function 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
1484begin
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;
1495end;
1496
1497procedure TfrmDrawers.mnuViewTemplateIconLegendClick(Sender: TObject);
1498begin
1499 ShowIconLegend(ilTemplates);
1500end;
1501
1502procedure TfrmDrawers.pnlTemplatesButtonEnter(Sender: TObject);
1503begin
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;
1510end;
1511
1512procedure TfrmDrawers.pnlTemplatesButtonExit(Sender: TObject);
1513begin
1514 with Sender as TPanel do
1515 BevelOuter := bvNone;
1516 DisableArrowKeyMove(Sender);
1517end;
1518
1519procedure TfrmDrawers.tvRemindersKeyDown(Sender: TObject; var Key: Word;
1520 Shift: TShiftState);
1521begin
1522 case Key of
1523 VK_RETURN, VK_SPACE:
1524 begin
1525 ViewReminderDialog(ReminderNode(tvReminders.Selected));
1526 Key := 0;
1527 end;
1528 end;
1529end;
1530
1531procedure TfrmDrawers.tvRemindersNodeCaptioning(Sender: TObject;
1532 var Caption: String);
1533var
1534 StringData: string;
1535begin
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;
1544end;
1545
1546procedure TfrmDrawers.DisableArrowKeyMove(Sender: TObject);
1547var
1548 CurrPanel : TKeyClickPanel;
1549begin
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;
1562end;
1563
1564initialization
1565 SpecifyFormIsNotADialog(TfrmDrawers);
1566
1567end.
1568
Note: See TracBrowser for help on using the repository browser.