home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / Pascal / BPASCAL.700 / D12 / PAINT.ZIP / PAINTDLG.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-10-01  |  4.3 KB  |  164 lines

  1. {************************************************}
  2. {                                                }
  3. {   ObjectWindows Paint demo                     }
  4. {   Copyright (c) 1992 by Borland International  }
  5. {                                                }
  6. {************************************************}
  7.  
  8. unit PaintDlg;
  9.  
  10. { This unit supplies the specialized dialogs for the paint program.
  11. }
  12.  
  13. interface
  14.  
  15. uses ResDef, WinTypes, WinProcs, OWindows, ODialogs;
  16.  
  17. type
  18.  
  19.   PSizeBMInfo = ^TSizeBMInfo;
  20.   TSizeBMInfo = record
  21.     Width, Height: Integer;
  22.     CurrentBMFlag: Integer;
  23.   end;
  24.  
  25.   PSizeBMDialog = ^TSizeBMDialog;
  26.   TSizeBMDialog = object(TDialog)
  27.     constructor Init(AParent: PWindowsObject; AName: PChar; Buf: Pointer);
  28.   end;
  29.  
  30. { Numeric input field }
  31.  
  32.   PNumEdit = ^TNumEdit;
  33.   TNumEdit = object(TEdit)
  34.     MinValue, MaxValue: Longint;
  35.  
  36.     constructor Init(AParent: PWindowsObject; AnId: Integer;
  37.       ATitle: PChar; X, Y, W, H: Integer; Digits: Word;
  38.       AMinValue, AMaxValue: Longint);
  39.     constructor InitResource(AParent: PWindowsObject; ResourceID: Word;
  40.       Digits: Word; AMinValue, AMaxValue: Longint);
  41.     function CanClose: Boolean; virtual;
  42.     function Transfer(DataPtr: Pointer; TransferFlag: Word): Word; virtual;
  43.   end;
  44.  
  45. { Special Radio Buttons }
  46.   
  47.   PIDRadioButton = ^TIDRadioButton;
  48.   TIDRadioButton = object(TRadioButton)
  49.     MyID: Integer;
  50.  
  51.     constructor InitResource(AParent: PWindowsObject; ResourceID: Word);
  52.     function Transfer(DataPtr: Pointer; TransferFlag:Word): Word; virtual;
  53.   end;
  54.  
  55. implementation
  56.  
  57. { TSizeBMDialog }
  58. constructor TSizeBMDialog.Init(AParent: PWindowsObject; AName: PChar;
  59.                                Buf: Pointer);
  60. var
  61.   P: PWindowsObject;
  62. begin
  63.   TDialog.Init(AParent, AName);
  64.  
  65.   TransferBuffer := Buf;
  66.  
  67.   P := New(PNumEdit, InitResource(@Self, id_WidthField, 5, -32768, 32767));
  68.   P := New(PNumEdit, InitResource(@Self, id_HeightField, 5, -32768, 32767));
  69.  
  70.   P := New(PIDRadioButton, InitResource(@Self, id_StretchBM));
  71.   P := New(PIDRadioButton, InitResource(@Self, id_PadBM));
  72.   P := New(PGroupBox, InitResource(@Self, id_CurrentBMGroup));
  73. end;
  74.  
  75. { TNumEdit }
  76.  
  77. constructor TNumEdit.Init(AParent: PWindowsObject; AnId: Integer;
  78.   ATitle: PChar; X, Y, W, H: Integer; Digits: Word;
  79.   AMinValue, AMaxValue: Longint);
  80. begin
  81.   TEdit.Init(AParent, AnId, ATitle, X, Y, W, H, Digits + 1, False);
  82.   MinValue := AMinValue;
  83.   MaxValue := AMaxValue;
  84. end;
  85.  
  86. constructor TNumEdit.InitResource(AParent: PWindowsObject;
  87.   ResourceID: Word; Digits: Word; AMinValue, AMaxValue: Longint);
  88. begin
  89.   TEdit.InitResource(AParent, ResourceID, Digits + 1);
  90.   MinValue := AMinValue;
  91.   MaxValue := AMaxValue;
  92. end;
  93.  
  94. function TNumEdit.CanClose: Boolean;
  95. var
  96.   Valid: Boolean;
  97.   ValCode: Integer;
  98.   Value: LongInt;
  99.   Text: array[0..15] of Char;
  100.   Msg: array[0..63] of Char;
  101. begin
  102.   GetText(Text, SizeOf(Text));
  103.   Val(Text, Value, ValCode);
  104.   Valid := (ValCode = 0) and
  105.     (Value >= MinValue) and (Value <= MaxValue);
  106.   if not Valid then
  107.   begin
  108.     WVSPrintF(Msg, 'Number must be between %ld and %ld', MinValue);
  109.     MessageBox(HWindow, Msg, 'Data error', mb_Ok or mb_IconExclamation);
  110.     SetSelection(0, MaxInt);
  111.     SetFocus(HWindow);
  112.   end;
  113.   CanClose := Valid;
  114. end;
  115.  
  116. function TNumEdit.Transfer(DataPtr: Pointer; TransferFlag: Word): Word;
  117. var
  118.   ValCode: Integer;
  119.   Text: array[0..15] of Char;
  120. begin
  121.   case TransferFlag of
  122.     tf_GetData:
  123.       begin
  124.         GetText(Text, SizeOf(Text));
  125.         Val(Text, Integer(DataPtr^), ValCode);
  126.       end;
  127.     tf_SetData:
  128.       begin
  129.     Str(Integer(DataPtr^), Text);
  130.         SetText(Text);
  131.       end;
  132.   end;
  133.   Transfer := SizeOf(Integer);
  134. end;
  135.  
  136. { TIDRadioButton }
  137. constructor TIDRadioButton.InitResource(AParent: PWindowsObject;
  138.   ResourceID: Word);
  139. begin
  140.   TRadioButton.InitResource(AParent, ResourceID);
  141.   MyID := ResourceID;
  142. end;
  143.  
  144. function TIDRadioButton.Transfer(DataPtr: Pointer; TransferFlag:Word): Word;
  145. begin
  146.   Transfer := 0;
  147.   case TransferFlag of
  148.     tf_GetData:
  149.       if GetCheck = bf_Checked then
  150.       begin
  151.     Integer(DataPtr^) := MyID;
  152.     Transfer := SizeOf(Integer);
  153.       end;
  154.     tf_SetData:
  155.        if (Integer(DataPtr^) = MyID) or (Integer(DataPtr^) = bf_Checked) then
  156.        begin
  157.      Check;
  158.      Transfer := SizeOf(Integer);
  159.        end;
  160.   end;
  161. end;
  162.  
  163. end.
  164.