Ignore:
Timestamp:
May 7, 2015, 12:34:29 PM (10 years ago)
Author:
healthsevak
Message:

Updating the working copy to CPRS version 28

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cprs/trunk/CPRS-Chart/rMisc.pas

    r830 r1679  
    33interface
    44
    5 uses SysUtils, Windows, Classes, Forms, Controls, ComCtrls, Grids, ORFn, ORNet;
     5uses SysUtils, Windows, Classes, Forms, Controls, ComCtrls, Grids, ORFn, ORNet,
     6    Menus, Contnrs, StrUtils;
    67
    78const
     
    910
    1011type
    11   TToolItem = record
     12  TToolMenuItem = class
     13  public
    1214    Caption: string;
     15    Caption2: string;
    1316    Action: string;
    14   end;
    15 
    16   TToolItemList = array[0..MAX_TOOLITEMS] of TToolItem;
    17 
     17    MenuID: string;
     18    SubMenuID: string;
     19    MenuItem: TMenuItem;
     20  end;
     21
     22var
     23  uToolMenuItems: TObjectList = nil;
     24
     25type
    1826  {An Object of this Class is Created to Hold the Sizes of Controls(Forms)
    1927   while the app is running, thus reducing calls to RPCs SAVESIZ and LOADSIZ}
     
    3038
    3139function DetailPrimaryCare(const DFN: string): TStrings;  //*DFN*
    32 procedure GetToolMenu(var ToolItems: TToolItemList; var OverLimit: boolean);
     40procedure GetToolMenu;
    3341procedure ListSymbolTable(Dest: TStrings);
    3442function MScalar(const x: string): string;
     
    4553procedure SetUserWidths(var AControl: TControl);
    4654procedure SetUserColumns(var AControl: TControl);
     55procedure SetUserString(StrName: string; var Str: string);
    4756function StrUserBounds(AControl: TControl): string;
    4857function StrUserBounds2(AName: string; v1, v2, v3, v4: integer): string;
    4958function StrUserWidth(AControl: TControl): string;
    5059function StrUserColumns(AControl: TControl): string;
     60function StrUserString(StrName: string; Str: string): string;
    5161function UserFontSize: integer;
    5262procedure SaveUserFontSize( FontSize: integer);
     
    6878end;
    6979
    70 procedure GetToolMenu(var ToolItems: TToolItemList; var OverLimit: boolean);
    71 var
    72   i: Integer;
    73   x: string;
    74   LoopIndex: integer;
    75 begin
    76   for i := 0 to MAX_TOOLITEMS do with ToolItems[i] do
    77   begin
    78     Caption := '';
    79     Action := '';
    80   end;
     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;
     89var
     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;
     96begin
     97  if not assigned(uToolMenuItems) then
     98    uToolMenuItems := TObjectList.Create
     99  else
     100    uToolMenuItems.Clear;
    81101  CallV('ORWU TOOLMENU', [nil]);
    82   OverLimit := (MAX_TOOLITEMS < RPCBrokerV.Results.Count - 1);
    83   LoopIndex := Min(MAX_TOOLITEMS, RPCBrokerV.Results.Count - 1);
    84   with RPCBrokerV do for i := 0 to LoopIndex do with ToolItems[i] do
    85   begin
    86     x := Piece(Results[i], U, 1);
    87     Caption := Piece(x, '=', 1);
    88     Action := Copy(x, Pos('=', x) + 1, Length(x));
     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;
    89187  end;
    90188end;
     
    251349end;
    252350
     351procedure SetUserString(StrName: string; var Str: string);
     352begin
     353  Str := uColumns.Values[StrName];
     354end;
     355
    253356procedure SaveUserBounds(AControl: TControl);
    254357var
    255358  x: string;
     359  NewHeight: integer;
    256360begin
    257361  if (AControl is TForm) and (TForm(AControl).WindowState = wsMaximized) then
     
    259363  else
    260364    with AControl do
    261       x := IntToStr(Left) + ',' + IntToStr(Top) + ',' +
    262            IntToStr(Width) + ',' + IntToStr(Height);
     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;
    263371//  CallV('ORWCH SAVESIZ', [AControl.Name, x]);
    264372  SizeHolder.SetSize(AControl.Name, x);
     
    348456end;
    349457
     458function StrUserString(StrName: string; Str: string): string;
     459begin
     460  Result := 'C' + U + StrName + U + Str;
     461end;
     462
    350463{ TSizeHolder }
    351464
     
    355468  i: integer;
    356469begin
    357   for i := 0 to FNameList.Count-1 do begin
    358     if Piece(FNameList[i],U,1) = 'C' then
    359       theList.Add(FNameList[i] + U + FSizeList[i])
    360     else
    361       theList.Add('B' + U + FNameList[i] + U + FSizeList[i]);
    362   end;
     470  for i := 0 to FNameList.Count-1 do
     471    theList.Add('B' + U + FNameList[i] + U + FSizeList[i]);
    363472end;
    364473
     
    399508  else //Currently is in the NameList
    400509    rSizeVal := FSizeList[nameIndex];
    401   if (rSizeVal = '') and (Piece(AName,U,1) = 'C') then begin
    402     if not Assigned(uColumns) then LoadSizes;
    403     rSizeVal := uColumns.Values[Piece(AName,U,2)];
    404   end;
    405510  result := rSizeVal;
    406511end;
     
    430535  if uWidths  <> nil then uWidths.Free;
    431536  if uColumns <> nil then uColumns.Free;
     537  if assigned(uToolMenuItems) then
     538    FreeAndNil(uToolMenuItems);
    432539
    433540end.
Note: See TracChangeset for help on using the changeset viewer.