source: cprs/branches/HealthSevak-CPRS/CPRS-Chart/rMisc.pas@ 1710

Last change on this file since 1710 was 1693, checked in by healthsevak, 10 years ago

Committing the files for first time to this new branch

File size: 16.1 KB
RevLine 
[456]1unit rMisc;
2
3interface
4
[1693]5uses SysUtils, Windows, Classes, Forms, Controls, ComCtrls, Grids, ORFn, ORNet,
6 Menus, Contnrs, StrUtils;
[456]7
8const
9 MAX_TOOLITEMS = 30;
10
11type
[1693]12 TToolMenuItem = class
13 public
[456]14 Caption: string;
[1693]15 Caption2: string;
[456]16 Action: string;
[1693]17 MenuID: string;
18 SubMenuID: string;
19 MenuItem: TMenuItem;
[456]20 end;
21
[1693]22var
23 uToolMenuItems: TObjectList = nil;
[456]24
[1693]25type
[456]26 {An Object of this Class is Created to Hold the Sizes of Controls(Forms)
27 while the app is running, thus reducing calls to RPCs SAVESIZ and LOADSIZ}
28 TSizeHolder = class(TObject)
29 private
30 FSizeList,FNameList: TStringList;
31 public
32 constructor Create;
33 destructor Destroy; override;
34 function GetSize(AName: String): String;
35 procedure SetSize(AName,ASize: String);
36 procedure AddSizesToStrList(theList: TStringList);
37 end;
38
39function DetailPrimaryCare(const DFN: string): TStrings; //*DFN*
[1693]40procedure GetToolMenu;
[456]41procedure ListSymbolTable(Dest: TStrings);
42function MScalar(const x: string): string;
43procedure SetShareNode(const DFN: string; AHandle: HWND); //*DFN*
44function ServerHasPatch(const x: string): Boolean;
45function ServerVersion(const Option, VerClient: string): string;
46function PackageVersion(const Namespace: string): string;
47
48procedure SaveUserBounds(AControl: TControl);
49procedure SaveUserSizes(SizingList: TStringList);
50procedure SetFormPosition(AForm: TForm);
51procedure SetUserBounds(var AControl: TControl);
52procedure SetUserBounds2(AName: string; var v1, v2, v3, v4: integer);
53procedure SetUserWidths(var AControl: TControl);
54procedure SetUserColumns(var AControl: TControl);
[1693]55procedure SetUserString(StrName: string; var Str: string);
[456]56function StrUserBounds(AControl: TControl): string;
57function StrUserBounds2(AName: string; v1, v2, v3, v4: integer): string;
58function StrUserWidth(AControl: TControl): string;
59function StrUserColumns(AControl: TControl): string;
[1693]60function StrUserString(StrName: string; Str: string): string;
[456]61function UserFontSize: integer;
62procedure SaveUserFontSize( FontSize: integer);
63
64var
65 SizeHolder : TSizeHolder;
66
67implementation
68
69uses TRPCB, fOrders, math;
70
71var
72 uBounds, uWidths, uColumns: TStringList;
73
74function DetailPrimaryCare(const DFN: string): TStrings; //*DFN*
75begin
76 CallV('ORWPT1 PCDETAIL', [DFN]);
77 Result := RPCBrokerV.Results;
78end;
79
[1693]80const
81 SUBMENU_KEY = 'SUBMENU';
82 SUBMENU_KEY_LEN = length(SUBMENU_KEY);
83 SUB_LEFT = '[';
84 SUB_RIGHT = ']';
85 MORE_ID = 'MORE^';
86 MORE_NAME = 'More...';
87
88procedure GetToolMenu;
[456]89var
[1693]90 i, p, LastIdx, count, MenuCount: Integer;
91 id, x: string;
92 LastItem, item: TToolMenuItem;
93 caption, action: string;
94 CurrentMenuID: string;
95 MenuIDs: TStringList;
[456]96begin
[1693]97 if not assigned(uToolMenuItems) then
98 uToolMenuItems := TObjectList.Create
99 else
100 uToolMenuItems.Clear;
[456]101 CallV('ORWU TOOLMENU', [nil]);
[1693]102 MenuIDs := TStringList.Create;
103 try
104 for i := 0 to RPCBrokerV.Results.Count - 1 do
105 begin
106 x := Piece(RPCBrokerV.Results[i], U, 1);
107 item := TToolMenuItem.Create;
108 Caption := Piece(x, '=', 1);
109 Action := Copy(x, Pos('=', x) + 1, Length(x));
110 item.Caption2 := Caption;
111 if UpperCase(copy(Action,1,SUBMENU_KEY_LEN)) = SUBMENU_KEY then
112 begin
113 id := UpperCase(Trim(Copy(Action, SUBMENU_KEY_LEN+1, MaxInt)));
114 if (LeftStr(id,1) = SUB_LEFT) and (RightStr(id,1) = SUB_RIGHT) then
115 id := copy(id, 2, length(id)-2);
116 item.MenuID := id;
117 Action := '';
118 if MenuIDs.IndexOf(item.MenuID) < 0 then
119 MenuIDs.Add(item.MenuID)
120 else
121 begin
122 item.SubMenuID := item.MenuID;
123 item.MenuID := '';
124 end;
125 end;
126 if RightStr(Caption, 1) = SUB_RIGHT then
127 begin
128 p := length(Caption) - 2;
129 while (p > 0) and (Caption[p] <> SUB_LEFT) do
130 dec(p);
131 if (p > 0) and (Caption[p] = SUB_LEFT) then
132 begin
133 item.SubMenuID := UpperCase(Trim(copy(Caption,p+1, length(Caption)-1-p)));
134 Caption := copy(Caption,1,p-1);
135 end;
136 end;
137 item.Caption := Caption;
138 item.Action := Action;
139 uToolMenuItems.add(item);
140 end;
141 // see if all child menu items have parents
142 for I := 0 to uToolMenuItems.Count - 1 do
143 begin
144 item := TToolMenuItem(uToolMenuItems[i]);
145 if MenuIDs.IndexOf(item.SubMenuID) < 0 then
146 begin
147 item.SubMenuID := '';
148 item.Caption := item.Caption2;
149 end;
150 end;
151
152 // see if there are more than MAX_TOOLITEMS in the root menu
153 // if there are, add automatic sub menus
154 LastIdx := (MAX_TOOLITEMS - 1);
155 count := 0;
156 CurrentMenuID := '';
157 i := 0;
158 LastItem := nil;
159 MenuCount := 0;
160 repeat
161 item := TToolMenuItem(uToolMenuItems[i]);
162 if item.SubMenuID = '' then
163 begin
164 item.SubMenuID := CurrentMenuID;
165 inc(count);
166 if Count > MAX_TOOLITEMS then
167 begin
168 item.SubMenuID := '';
169 inc(MenuCount);
170 item := TToolMenuItem.Create;
171 item.Caption := MORE_NAME;
172 item.MenuID := MORE_ID + IntToStr(MenuCount);
173 item.SubMenuID := CurrentMenuID;
174 CurrentMenuID := item.MenuID;
175 LastItem.SubMenuID := CurrentMenuID;
176 uToolMenuItems.Insert(LastIdx, item);
177 inc(LastIdx,MAX_TOOLITEMS);
178 Count := 1;
179 end;
180 LastItem := item;
181 end;
182 inc(i);
183 until i >= uToolMenuItems.Count;
184
185 finally
186 MenuIDs.Free;
[456]187 end;
188end;
189
190procedure ListSymbolTable(Dest: TStrings);
191var
192 i: Integer;
193 x: string;
194begin
195 Dest.Clear;
196 CallV('ORWUX SYMTAB', [nil]);
197 i := 0;
198 with RPCBrokerV.Results do while i < Count do
199 begin
200 x := Strings[i] + '=';
201 Inc(i);
202 if i < Count then x := x + Strings[i];
203 Dest.Add(x);
204 Inc(i);
205 end;
206end;
207
208function MScalar(const x: string): string;
209begin
210 with RPCBrokerV do
211 begin
212 ClearParameters := True;
213 RemoteProcedure := 'XWB GET VARIABLE VALUE';
214 Param[0].Value := x;
215 Param[0].PType := reference;
216 CallBroker;
217 Result := Results[0];
218 end;
219end;
220
221function ServerHasPatch(const x: string): Boolean;
222begin
223 Result := sCallV('ORWU PATCH', [x]) = '1';
224end;
225
226function ServerVersion(const Option, VerClient: string): string;
227begin
228 Result := sCallV('ORWU VERSRV', [Option, VerClient]);
229end;
230
231function PackageVersion(const Namespace: string): string;
232begin
233 Result := sCallV('ORWU VERSION', [Namespace]);
234end;
235
236function UserFontSize: integer;
237begin
238 Result := StrToIntDef(sCallV('ORWCH LDFONT', [nil]),8);
[830]239 If Result = 24 then Result := 18; // CQ #12322 removed 24 pt font
[456]240end;
241
242procedure LoadSizes;
243var
244 i, p: Integer;
245begin
246 uBounds := TStringList.Create;
247 uWidths := TStringList.Create;
248 uColumns := TStringList.Create;
249 CallV('ORWCH LOADALL', [nil]);
250 with RPCBrokerV do
251 begin
252 for i := 0 to Results.Count - 1 do // change '^' to '='
253 begin
254 p := Pos(U, Results[i]);
255 if p > 0 then Results[i] := Copy(Results[i], 1, p - 1) + '=' +
256 Copy(Results[i], p + 1, Length(Results[i]));
257 end;
258 ExtractItems(uBounds, RPCBrokerV.Results, 'Bounds');
259 ExtractItems(uWidths, RPCBrokerV.Results, 'Widths');
260 ExtractItems(uColumns, RPCBrokerV.Results, 'Columns');
261 end;
262end;
263
264procedure SetShareNode(const DFN: string; AHandle: HWND); //*DFN*
265begin
266 // sets node that allows other apps to see which patient is currently selected
267 sCallV('ORWPT SHARE', [DottedIPStr, IntToHex(AHandle, 8), DFN]);
268end;
269
270procedure SetUserBounds(var AControl: TControl);
271var
272 x: string;
273begin
274 if uBounds = nil then LoadSizes;
275 x := AControl.Name;
276 if not (AControl is TForm) and (Assigned(AControl.Owner)) then x := AControl.Owner.Name + '.' + x;
277 x := uBounds.Values[x];
278 if (x = '0,0,0,0') and (AControl is TForm)
279 then TForm(AControl).WindowState := wsMaximized
280 else
281 begin
282 AControl.Left := HigherOf(StrToIntDef(Piece(x, ',', 1), AControl.Left), 0);
283 AControl.Top := HigherOf(StrToIntDef(Piece(x, ',', 2), AControl.Top), 0);
284 if Assigned( AControl.Parent ) then
285 begin
286 AControl.Width := LowerOf(StrToIntDef(Piece(x, ',', 3), AControl.Width), AControl.Parent.Width - AControl.Left);
287 AControl.Height := LowerOf(StrToIntDef(Piece(x, ',', 4), AControl.Height), AControl.Parent.Height - AControl.Top);
288 end
289 else
290 begin
291 AControl.Width := StrToIntDef(Piece(x, ',', 3), AControl.Width);
292 AControl.Height := StrToIntDef(Piece(x, ',', 4), AControl.Height);
293 end;
294 end;
295 //if (x = '0,0,' + IntToStr(Screen.Width) + ',' + IntToStr(Screen.Height)) and
296 // (AControl is TForm) then TForm(AControl).WindowState := wsMaximized;
297end;
298
299procedure SetUserBounds2(AName: string; var v1, v2, v3, v4: integer);
300var
301 x: string;
302begin
303 if uBounds = nil then LoadSizes;
304 x := uBounds.Values[AName];
305 v1 := StrToIntDef(Piece(x, ',', 1), 0);
306 v2 := StrToIntDef(Piece(x, ',', 2), 0);
307 v3 := StrToIntDef(Piece(x, ',', 3), 0);
308 v4 := StrToIntDef(Piece(x, ',', 4), 0);
309end;
310
311
312procedure SetUserWidths(var AControl: TControl);
313var
314 x: string;
315begin
316 if uWidths = nil then LoadSizes;
317 x := AControl.Name;
318 if not (AControl is TForm) and (Assigned(AControl.Owner)) then x := AControl.Owner.Name + '.' + x;
319 x := uWidths.Values[x];
320 if Assigned (AControl.Parent) then
321 AControl.Width := LowerOf(StrToIntDef(x, AControl.Width), AControl.Parent.Width - AControl.Left)
322 else
323 AControl.Width := StrToIntDef(x, AControl.Width);
324end;
325
326procedure SetUserColumns(var AControl: TControl);
327var
328 x: string;
329 i, AWidth: Integer;
330 couldSet: boolean;
331begin
332 couldSet := False;
333 if uColumns = nil then LoadSizes;
334 x := AControl.Name;
335 if not (AControl is TForm) and (Assigned(AControl.Owner)) then x := AControl.Owner.Name + '.' + x;
336 if AnsiCompareText(x,'frmOrders.hdrOrders')=0 then
337 couldSet := True;
338 x := uColumns.Values[x];
339 if AControl is THeaderControl then with THeaderControl(AControl) do
340 for i := 0 to Sections.Count - 1 do
341 begin
342 //Make sure all of the colmumns fit, even if it means scrunching the last ones.
343 AWidth := LowerOf(StrToIntDef(Piece(x, ',', i + 1), 0), HigherOf(ClientWidth - (Sections.Count - i)*5 - Sections.Items[i].Left, 5));
344 if AWidth > 0 then Sections.Items[i].Width := AWidth;
345 if couldSet and (i=0) and (AWidth>0) then
346 frmOrders.EvtColWidth := AWidth;
347 end;
348 if AControl is TCustomGrid then {nothing for now};
349end;
350
[1693]351procedure SetUserString(StrName: string; var Str: string);
352begin
353 Str := uColumns.Values[StrName];
354end;
355
[456]356procedure SaveUserBounds(AControl: TControl);
357var
358 x: string;
[1693]359 NewHeight: integer;
[456]360begin
361 if (AControl is TForm) and (TForm(AControl).WindowState = wsMaximized) then
362 x := '0,0,0,0'
363 else
364 with AControl do
[1693]365 begin
366 //Done to remove the adjustment for Window XP style before saving the form size
367 NewHeight := Height - (GetSystemMetrics(SM_CYCAPTION) - 19);
368 x := IntToStr(Left) + ',' + IntToStr(Top) + ',' +
369 IntToStr(Width) + ',' + IntToStr(NewHeight);
370 end;
[456]371// CallV('ORWCH SAVESIZ', [AControl.Name, x]);
372 SizeHolder.SetSize(AControl.Name, x);
373end;
374
375procedure SaveUserSizes(SizingList: TStringList);
376begin
377 CallV('ORWCH SAVEALL', [SizingList]);
378end;
379
380procedure SaveUserFontSize( FontSize: integer);
381begin
382 CallV('ORWCH SAVFONT', [IntToStr(FontSize)]);
383end;
384
385procedure SetFormPosition(AForm: TForm);
386var
387 x: string;
388 Rect: TRect;
389begin
390// x := sCallV('ORWCH LOADSIZ', [AForm.Name]);
391 x := SizeHolder.GetSize(AForm.Name);
392 if x = '' then Exit; // allow default bounds to be passed in, else screen center?
393 if (x = '0,0,0,0') then
394 AForm.WindowState := wsMaximized
395 else
396 begin
397 AForm.SetBounds(StrToIntDef(Piece(x, ',', 1), AForm.Left),
398 StrToIntDef(Piece(x, ',', 2), AForm.Top),
399 StrToIntDef(Piece(x, ',', 3), AForm.Width),
400 StrToIntDef(Piece(x, ',', 4), AForm.Height));
401 Rect := AForm.BoundsRect;
402 ForceInsideWorkArea(Rect);
403 AForm.BoundsRect := Rect;
404 end;
405end;
406
407function StrUserBounds(AControl: TControl): string;
408var
409 x: string;
410begin
411 x := AControl.Name;
412 if not (AControl is TForm) and (Assigned(AControl.Owner)) then x := AControl.Owner.Name + '.' + x;
413 with AControl do Result := 'B' + U + x + U + IntToStr(Left) + ',' + IntToStr(Top) + ',' +
414 IntToStr(Width) + ',' + IntToStr(Height);
415 if (AControl is TForm) and (TForm(AControl).WindowState = wsMaximized)
416 then Result := 'B' + U + x + U + '0,0,0,0';
417end;
418
419function StrUserBounds2(AName: string; v1, v2, v3, v4: integer): string;
420begin
421 Result := 'B' + U + AName + U + IntToStr(v1) + ',' + IntToStr(v2) + ',' +
422 IntToStr(v3) + ',' + IntToStr(v4);
423end;
424
425function StrUserWidth(AControl: TControl): string;
426var
427 x: string;
428begin
429 x := AControl.Name;
430 if not (AControl is TForm) and (Assigned(AControl.Owner)) then x := AControl.Owner.Name + '.' + x;
431 with AControl do Result := 'W' + U + x + U + IntToStr(Width);
432end;
433
434function StrUserColumns(AControl: TControl): string;
435var
436 x: string;
437 i: Integer;
438 shouldSave: boolean;
439begin
440 shouldSave := False;
441 x := AControl.Name;
442 if not (AControl is TForm) and (Assigned(AControl.Owner)) then x := AControl.Owner.Name + '.' + x;
443 if AnsiCompareText(x,'frmOrders.hdrOrders') = 0 then
444 shouldSave := True;
445 Result := 'C' + U + x + U;
446 if AControl is THeaderControl then with THeaderControl(AControl) do
447 for i := 0 to Sections.Count - 1 do
448 begin
449 if shouldSave and (i = 0) then
450 Result := Result + IntToStr(frmOrders.EvtColWidth) + ','
451 else
452 Result := Result + IntToStr(Sections.Items[i].Width) + ',';
453 end;
454 if AControl is TCustomGrid then {nothing for now};
455 if CharAt(Result, Length(Result)) = ',' then Result := Copy(Result, 1, Length(Result) - 1);
456end;
457
[1693]458function StrUserString(StrName: string; Str: string): string;
459begin
460 Result := 'C' + U + StrName + U + Str;
461end;
462
[456]463{ TSizeHolder }
464
465procedure TSizeHolder.AddSizesToStrList(theList: TStringList);
466{Adds all the Sizes in the TSizeHolder Object to theList String list parameter}
467var
468 i: integer;
469begin
[1693]470 for i := 0 to FNameList.Count-1 do
471 theList.Add('B' + U + FNameList[i] + U + FSizeList[i]);
[456]472end;
473
474constructor TSizeHolder.Create;
475begin
476 inherited;
477 FNameList := TStringList.Create;
478 FSizeList := TStringList.Create;
479end;
480
481
482destructor TSizeHolder.Destroy;
483begin
484 FNameList.Free;
485 FSizeList.Free;
486 inherited;
487end;
488
489function TSizeHolder.GetSize(AName: String): String;
490{Fuctions returns a String of the Size(s) Of the Name parameter passed,
491 if the Size(s) are already loaded into the object it will return those,
492 otherwise it will make the apropriate RPC call to LOADSIZ}
493var
494 rSizeVal: String; //return Size value
495 nameIndex: integer;
496begin
497 rSizeVal := '';
498 nameIndex := FNameList.IndexOf(AName);
499 if nameIndex = -1 then //Currently Not in the NameList
500 begin
501 rSizeVal := sCallV('ORWCH LOADSIZ', [AName]);
502 if rSizeVal <> '' then
503 begin
504 FNameList.Add(AName);
505 FSizeList.Add(rSizeVal);
506 end;
507 end
508 else //Currently is in the NameList
509 rSizeVal := FSizeList[nameIndex];
510 result := rSizeVal;
511end;
512
513procedure TSizeHolder.SetSize(AName, ASize: String);
514{Store the Size(s) Of the ASize parameter passed, Associate it with the AName
515 Parameter. This only stores the sizes in the objects member variables.
516 to Store on the MUMPS Database call SendSizesToDB()}
517var
518 nameIndex: integer;
519begin
520 nameIndex := FNameList.IndexOf(AName);
521 if nameIndex = -1 then //Currently Not in the NameList
522 begin
523 FNameList.Add(AName);
524 FSizeList.Add(ASize);
525 end
526 else //Currently is in the NameList
527 FSizeList[nameIndex] := ASize;
528end;
529
530initialization
531 // nothing for now
532
533finalization
534 if uBounds <> nil then uBounds.Free;
535 if uWidths <> nil then uWidths.Free;
536 if uColumns <> nil then uColumns.Free;
[1693]537 if assigned(uToolMenuItems) then
538 FreeAndNil(uToolMenuItems);
[456]539
540end.
Note: See TracBrowser for help on using the repository browser.