home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / tp6goodi / hlpctx / radio.pas
Encoding:
Pascal/Delphi Source File  |  1991-02-04  |  5.7 KB  |  225 lines

  1. {$X+}
  2.  
  3. program Hints;
  4.  
  5. uses Objects, Drivers, Views, Menus, Dialogs, App,Gadgets,MsgBox;
  6.  
  7. const
  8.   CancelButton      = 500;
  9.   OkButton          = 501;
  10.   cmNewDialog       = 102;
  11.   hcInputLine       = 2999;
  12.   hcHvarti          = 3000;
  13.   hcTileSet         = hcHvarti + 1;
  14.   hcJarlsBerg       = hcTileSet + 1;
  15.   hcSolid           = hcJarlsBerg + 1;
  16.   hcRunny           = hcSolid + 1;
  17.   hcMelted          = hcRunny  + 1;
  18.  
  19. type
  20.   PMyRadioButtons = ^TMyRadioButtons;
  21.   TMyRadioButtons = object(TRadioButtons)
  22.    function GetHelpCtx:Word;virtual;
  23.   end;
  24.  
  25.   PMyStatusLine = ^TMyStatusLine;
  26.   TMyStatusLine = object(TStatusLine)
  27.     function Hint(AHelpCtx : Word):String;virtual;
  28.     procedure HandleEvent(var Event : TEvent);virtual;
  29.   end;
  30.  
  31.   TMyApp = object(TApplication)
  32.     HeapViewer : PHeapView;
  33.     constructor Init;
  34.     procedure HandleEvent(var Event: TEvent); virtual;
  35.     procedure InitMenuBar; virtual;
  36.     procedure InitStatusLine; virtual;
  37.     procedure NewDialog;
  38.     procedure Idle;virtual;
  39.   end;
  40.  
  41.   PDemoDialog = ^TDemoDialog;
  42.   TDemoDialog = object(TDialog)
  43.    MyStatusLine : PMyStatusLine;
  44.    procedure HandleEvent(var Event : TEvent);virtual;
  45.   end;
  46.  
  47. procedure TDemoDialog.HandleEvent(var Event : TEvent);
  48. begin
  49.   TDialog.HandleEvent(Event);
  50.   Case event.what of
  51.   evCommand :  case event.command of
  52.                cmDefault : MessageBox('Default button is pressed',nil, mfError or mfOkButton);
  53.                CancelButton : MessageBox('Cancel button is pressed', nil, mfError or mfOkButton);
  54.                OkButton : MessageBox('Ok button is pressed', nil, mfError or mfOkButton);
  55.  
  56.                end;
  57.   else
  58.       exit;
  59.   ClearEvent(Event);
  60.   end;
  61. end;
  62.  
  63.  
  64. function TMyRadioButtons.GetHelpCtx:Word;
  65. begin
  66.    TRadioButtons.GetHelpCtx;
  67.    if State and sfDragging <> 0 then
  68.     GetHelpCtx := hcDragging else
  69.     GetHelpCtx := HelpCtx + Sel;
  70. end;
  71.  
  72. function TMyStatusLine.Hint(AHelpCtx : Word):String;
  73. begin
  74.  case AHelpCtx of
  75.    hcHvarti  : Hint := 'Hvarti is checked';
  76.    hcTileSet : Hint := 'TileSet is checked';
  77.    hcJarlsberg : Hint := 'Jarlsberg is checked';
  78.    hcSolid : Hint := 'Button zero is presssed';
  79.    hcRunny : Hint := 'Button one is pressed';
  80.    hcMelted : Hint := 'Button two is pressed';
  81.    hcInputLine     : Hint := 'InputLine is activated';
  82.  else
  83.   Hint := '';
  84.  end;
  85. end;
  86.  
  87. procedure TMyStatusLine.HandleEvent(var Event : TEvent);
  88. begin
  89.  TStatusLine.HandleEvent(Event);
  90.  Update;
  91. end;
  92.  
  93. procedure TMyApp.Idle;
  94. begin
  95.  TApplication.Idle;
  96.  HeapViewer^.Update;
  97. end;
  98.  
  99. constructor TMyApp.Init;
  100. var
  101.  R : TRect;
  102. begin
  103.   TApplication.Init;
  104.   GetExtent(R);
  105.   Dec(R.B.X);
  106.   R.A.X := R.B.X - 9; R.A.Y := R.B.Y - 1;
  107.   HeapViewer := New(PHeapView,Init(R));
  108.   Insert(HeapViewer);
  109. end;
  110. { TMyApp }
  111.  
  112. procedure TMyApp.HandleEvent(var Event: TEvent);
  113. begin
  114.   TApplication.HandleEvent(Event);
  115.   if Event.What = evCommand then
  116.   begin
  117.     case Event.Command of
  118.       cmNewDialog: NewDialog;
  119.     else
  120.       Exit;
  121.     end;
  122.     ClearEvent(Event);
  123.   end;
  124. end;
  125.  
  126. procedure TMyApp.InitMenuBar;
  127. var R: TRect;
  128. begin
  129.   GetExtent(R);
  130.   R.B.Y := R.A.Y + 1;
  131.   MenuBar := New(PMenuBar, Init(R, NewMenu(
  132.     NewSubMenu('~F~ile', hcNoContext, NewMenu(
  133.       NewLine(
  134.       NewItem('E~x~it', 'Alt-X', kbAltX, cmQuit, hcNoContext,
  135.       nil))),
  136.     NewSubMenu('~W~indow', hcNoContext, NewMenu(
  137.       NewItem('~N~ext', 'F6', kbF6, cmNext, hcNoContext,
  138.       NewItem('~Z~oom', 'F5', kbF5, cmZoom, hcNoContext,
  139.       NewItem('~D~ialog', 'F2', kbF2, cmNewDialog, hcNoContext,
  140.       nil)))),
  141.     nil))
  142.   )));
  143.  
  144. end;
  145.  
  146. procedure TMyApp.InitStatusLine;
  147. var R: TRect;
  148. begin
  149.   GetExtent(R);
  150.   R.A.Y := R.B.Y - 1;
  151.   StatusLine := New(PMyStatusLine, Init(R,
  152.     NewStatusDef(0,0,
  153.       NewStatusKey('', kbF10, cmMenu,
  154.       NewStatusKey('~Alt-X~ Exit', kbAltX, cmQuit,
  155.       NewStatusKey('~Alt-F3~ Close', kbAltF3, cmClose,
  156.       nil))),
  157.     NewStatusDef(1,1,
  158.      NewStatusKey('~No-Key~ Testing -hcDragging',kbNoKey,cmResize,
  159.      nil),
  160.     NewStatusDef(hcInputLine,hcInputLine,
  161.      NewStatusKey('~F3~ Close',kbNoKey,cmResize,
  162.      nil),
  163.     NewStatusDef(hcHvarti, hcMelted,
  164.       NewStatusKey('~F3~ Close',kbAltF3,cmClose,
  165.       nil),nil))))));
  166. end;
  167.  
  168. procedure TMyApp.NewDialog;
  169. var
  170.   CheckBoxes: PCheckBoxes;
  171.   RadioButtons : PRadioButtons;
  172.   InputLine : PInputLine;
  173.   Dialog: PDemoDialog;
  174.   R: TRect;
  175.   C: Word;
  176. begin
  177.   R.Assign(20, 6, 60, 19);
  178.   Dialog := New(PDemoDialog, Init(R, 'Demo Dialog'));
  179.   with Dialog^ do
  180.   begin
  181.     R.Assign(3, 3, 18, 6);
  182.     CheckBoxes := New(PCheckBoxes, Init(R,
  183.       NewSItem('~H~varti',
  184.       NewSItem('~T~ilset',
  185.       NewSItem('~J~arlsberg',
  186.       nil)))
  187.     ));
  188.     CheckBoxes^.HelpCtx := hcHvarti;
  189.     Insert(CheckBoxes);
  190.     R.Assign(2, 2, 10, 3);
  191.     Insert(New(PLabel, Init(R, 'Cheeses', CheckBoxes)));
  192.     R.Assign(22, 3, 34, 6);
  193.     RadioButtons := New(PMyRadioButtons, Init(R,
  194.       NewSItem('~S~olid',
  195.       NewSItem('~R~unny',
  196.       NewSItem('~M~elted',
  197.       nil)))));
  198.     RadioButtons^.HelpCtx := hcSolid;
  199.     Insert(RadioButtons);
  200.     R.Assign(21, 2, 33, 3);
  201.     Insert(New(PLabel, Init(R, 'Consistency', RadioButtons)));
  202.     R.Assign(15, 10, 25, 12);
  203.     Insert(New(PButton, Init(R, '~O~k', OkButton,bfDefault)));
  204.     R.Assign(28, 10, 38, 12);
  205.     Insert(New(PButton, Init(R, 'Cancel', CancelButton, bfNormal)));
  206.     R.Assign(3, 8, 37, 9);
  207.     InputLine := New(PInputLine, Init(R, 34));
  208.     InputLine ^.HelpCtx := hcInputLine;
  209.     Insert(InputLine);
  210.     R.Assign(2, 7, 24, 8);
  211.     Insert(New(PLabel, Init(R, 'Delivery instructions', InputLine)));
  212.    end;
  213.   DeskTop^.ExecView(Dialog);
  214.   Dispose(Dialog, Done);
  215. end;
  216.  
  217. var
  218.   MyApp: TMyApp;
  219.  
  220. begin
  221.   MyApp.Init;
  222.   MyApp.Run;
  223.   MyApp.Done;
  224. end.
  225.