source: cprs/branches/foia-cprs/CPRS-Chart/fDrawers.pas@ 1679

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

Adding foia-cprs branch

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