home *** CD-ROM | disk | FTP | other *** search
/ PC Expert 29 / Pce29cd.iso / RUNIMAGE / DELPHI40 / DEMOS / ACTIVEX / DELCTRLS / buttonimpl1.pas < prev    next >
Pascal/Delphi Source File  |  1998-06-16  |  8KB  |  296 lines

  1. unit ButtonImpl1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, ActiveX, Classes, Controls, Graphics, Menus, Forms, StdCtrls,
  7.   ComServ, StdVCL, AXCtrls, DelCtrls_TLB;
  8.  
  9. type
  10.   TButtonX = class(TActiveXControl, IButtonX)
  11.   private
  12.     { Private declarations }
  13.     FDelphiControl: TButton;
  14.     FEvents: IButtonXEvents;
  15.     procedure ClickEvent(Sender: TObject);
  16.     procedure KeyPressEvent(Sender: TObject; var Key: Char);
  17.   protected
  18.     { Protected declarations }
  19.     procedure DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage); override;
  20.     procedure EventSinkChanged(const EventSink: IUnknown); override;
  21.     procedure InitializeControl; override;
  22.     function ClassNameIs(const Name: WideString): WordBool; safecall;
  23.     function DrawTextBiDiModeFlags(Flags: Integer): Integer; safecall;
  24.     function DrawTextBiDiModeFlagsReadingOnly: Integer; safecall;
  25.     function Get_BiDiMode: TxBiDiMode; safecall;
  26.     function Get_Cancel: WordBool; safecall;
  27.     function Get_Caption: WideString; safecall;
  28.     function Get_Cursor: Smallint; safecall;
  29.     function Get_Default: WordBool; safecall;
  30.     function Get_DoubleBuffered: WordBool; safecall;
  31.     function Get_DragCursor: Smallint; safecall;
  32.     function Get_DragMode: TxDragMode; safecall;
  33.     function Get_Enabled: WordBool; safecall;
  34.     function Get_Font: IFontDisp; safecall;
  35.     function Get_ParentFont: WordBool; safecall;
  36.     function Get_Visible: WordBool; safecall;
  37.     function GetControlsAlignment: TxAlignment; safecall;
  38.     function IsRightToLeft: WordBool; safecall;
  39.     function UseRightToLeftAlignment: WordBool; safecall;
  40.     function UseRightToLeftReading: WordBool; safecall;
  41.     function UseRightToLeftScrollBar: WordBool; safecall;
  42.     procedure _Set_Font(const Value: IFontDisp); safecall;
  43.     procedure AboutBox; safecall;
  44.     procedure Click; safecall;
  45.     procedure FlipChildren(AllLevels: WordBool); safecall;
  46.     procedure InitiateAction; safecall;
  47.     procedure Set_BiDiMode(Value: TxBiDiMode); safecall;
  48.     procedure Set_Cancel(Value: WordBool); safecall;
  49.     procedure Set_Caption(const Value: WideString); safecall;
  50.     procedure Set_Cursor(Value: Smallint); safecall;
  51.     procedure Set_Default(Value: WordBool); safecall;
  52.     procedure Set_DoubleBuffered(Value: WordBool); safecall;
  53.     procedure Set_DragCursor(Value: Smallint); safecall;
  54.     procedure Set_DragMode(Value: TxDragMode); safecall;
  55.     procedure Set_Enabled(Value: WordBool); safecall;
  56.     procedure Set_Font(const Value: IFontDisp); safecall;
  57.     procedure Set_ParentFont(Value: WordBool); safecall;
  58.     procedure Set_Visible(Value: WordBool); safecall;
  59.   end;
  60.  
  61. implementation
  62.  
  63. uses ComObj, About2;
  64.  
  65. { TButtonX }
  66.  
  67. procedure TButtonX.DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage);
  68. begin
  69.   { Define property pages here.  Property pages are defined by calling
  70.     DefinePropertyPage with the class id of the page.  For example,
  71.       DefinePropertyPage(Class_ButtonXPage); }
  72. end;
  73.  
  74. procedure TButtonX.EventSinkChanged(const EventSink: IUnknown);
  75. begin
  76.   FEvents := EventSink as IButtonXEvents;
  77. end;
  78.  
  79. procedure TButtonX.InitializeControl;
  80. begin
  81.   FDelphiControl := Control as TButton;
  82.   FDelphiControl.OnClick := ClickEvent;
  83.   FDelphiControl.OnKeyPress := KeyPressEvent;
  84. end;
  85.  
  86. function TButtonX.ClassNameIs(const Name: WideString): WordBool;
  87. begin
  88.   Result := FDelphiControl.ClassNameIs(Name);
  89. end;
  90.  
  91. function TButtonX.DrawTextBiDiModeFlags(Flags: Integer): Integer;
  92. begin
  93.   Result := FDelphiControl.DrawTextBiDiModeFlags(Flags);
  94. end;
  95.  
  96. function TButtonX.DrawTextBiDiModeFlagsReadingOnly: Integer;
  97. begin
  98.   Result := FDelphiControl.DrawTextBiDiModeFlagsReadingOnly;
  99. end;
  100.  
  101. function TButtonX.Get_BiDiMode: TxBiDiMode;
  102. begin
  103.   Result := Ord(FDelphiControl.BiDiMode);
  104. end;
  105.  
  106. function TButtonX.Get_Cancel: WordBool;
  107. begin
  108.   Result := FDelphiControl.Cancel;
  109. end;
  110.  
  111. function TButtonX.Get_Caption: WideString;
  112. begin
  113.   Result := WideString(FDelphiControl.Caption);
  114. end;
  115.  
  116. function TButtonX.Get_Cursor: Smallint;
  117. begin
  118.   Result := Smallint(FDelphiControl.Cursor);
  119. end;
  120.  
  121. function TButtonX.Get_Default: WordBool;
  122. begin
  123.   Result := FDelphiControl.Default;
  124. end;
  125.  
  126. function TButtonX.Get_DoubleBuffered: WordBool;
  127. begin
  128.   Result := FDelphiControl.DoubleBuffered;
  129. end;
  130.  
  131. function TButtonX.Get_DragCursor: Smallint;
  132. begin
  133.   Result := Smallint(FDelphiControl.DragCursor);
  134. end;
  135.  
  136. function TButtonX.Get_DragMode: TxDragMode;
  137. begin
  138.   Result := Ord(FDelphiControl.DragMode);
  139. end;
  140.  
  141. function TButtonX.Get_Enabled: WordBool;
  142. begin
  143.   Result := FDelphiControl.Enabled;
  144. end;
  145.  
  146. function TButtonX.Get_Font: IFontDisp;
  147. begin
  148.   GetOleFont(FDelphiControl.Font, Result);
  149. end;
  150.  
  151. function TButtonX.Get_ParentFont: WordBool;
  152. begin
  153.   Result := FDelphiControl.ParentFont;
  154. end;
  155.  
  156. function TButtonX.Get_Visible: WordBool;
  157. begin
  158.   Result := FDelphiControl.Visible;
  159. end;
  160.  
  161. function TButtonX.GetControlsAlignment: TxAlignment;
  162. begin
  163.  Result := TxAlignment(FDelphiControl.GetControlsAlignment);
  164. end;
  165.  
  166. function TButtonX.IsRightToLeft: WordBool;
  167. begin
  168.   Result := FDelphiControl.IsRightToLeft;
  169. end;
  170.  
  171. function TButtonX.UseRightToLeftAlignment: WordBool;
  172. begin
  173.   Result := FDelphiControl.UseRightToLeftAlignment;
  174. end;
  175.  
  176. function TButtonX.UseRightToLeftReading: WordBool;
  177. begin
  178.   Result := FDelphiControl.UseRightToLeftReading;
  179. end;
  180.  
  181. function TButtonX.UseRightToLeftScrollBar: WordBool;
  182. begin
  183.   Result := FDelphiControl.UseRightToLeftScrollBar;
  184. end;
  185.  
  186. procedure TButtonX._Set_Font(const Value: IFontDisp);
  187. begin
  188.   SetOleFont(FDelphiControl.Font, Value);
  189. end;
  190.  
  191. procedure TButtonX.AboutBox;
  192. begin
  193.   ShowButtonXAbout;
  194. end;
  195.  
  196. procedure TButtonX.Click;
  197. begin
  198.   FDelphiControl.Click;
  199. end;
  200.  
  201. procedure TButtonX.FlipChildren(AllLevels: WordBool);
  202. begin
  203.   FDelphiControl.FlipChildren(AllLevels);
  204. end;
  205.  
  206. procedure TButtonX.InitiateAction;
  207. begin
  208.   FDelphiControl.InitiateAction;
  209. end;
  210.  
  211. procedure TButtonX.Set_BiDiMode(Value: TxBiDiMode);
  212. begin
  213.   FDelphiControl.BiDiMode := TBiDiMode(Value);
  214. end;
  215.  
  216. procedure TButtonX.Set_Cancel(Value: WordBool);
  217. begin
  218.   FDelphiControl.Cancel := Value;
  219. end;
  220.  
  221. procedure TButtonX.Set_Caption(const Value: WideString);
  222. begin
  223.   FDelphiControl.Caption := TCaption(Value);
  224. end;
  225.  
  226. procedure TButtonX.Set_Cursor(Value: Smallint);
  227. begin
  228.   FDelphiControl.Cursor := TCursor(Value);
  229. end;
  230.  
  231. procedure TButtonX.Set_Default(Value: WordBool);
  232. begin
  233.   FDelphiControl.Default := Value;
  234. end;
  235.  
  236. procedure TButtonX.Set_DoubleBuffered(Value: WordBool);
  237. begin
  238.   FDelphiControl.DoubleBuffered := Value;
  239. end;
  240.  
  241. procedure TButtonX.Set_DragCursor(Value: Smallint);
  242. begin
  243.   FDelphiControl.DragCursor := TCursor(Value);
  244. end;
  245.  
  246. procedure TButtonX.Set_DragMode(Value: TxDragMode);
  247. begin
  248.   FDelphiControl.DragMode := TDragMode(Value);
  249. end;
  250.  
  251. procedure TButtonX.Set_Enabled(Value: WordBool);
  252. begin
  253.   FDelphiControl.Enabled := Value;
  254. end;
  255.  
  256. procedure TButtonX.Set_Font(const Value: IFontDisp);
  257. begin
  258.   SetOleFont(FDelphiControl.Font, Value);
  259. end;
  260.  
  261. procedure TButtonX.Set_ParentFont(Value: WordBool);
  262. begin
  263.   FDelphiControl.ParentFont := Value;
  264. end;
  265.  
  266. procedure TButtonX.Set_Visible(Value: WordBool);
  267. begin
  268.   FDelphiControl.Visible := Value;
  269. end;
  270.  
  271. procedure TButtonX.ClickEvent(Sender: TObject);
  272. begin
  273.   if FEvents <> nil then FEvents.OnClick;
  274. end;
  275.  
  276. procedure TButtonX.KeyPressEvent(Sender: TObject; var Key: Char);
  277. var
  278.   TempKey: Smallint;
  279. begin
  280.   TempKey := Smallint(Key);
  281.   if FEvents <> nil then FEvents.OnKeyPress(TempKey);
  282.   Key := Char(TempKey);
  283. end;
  284.  
  285. initialization
  286.   TActiveXControlFactory.Create(
  287.     ComServer,
  288.     TButtonX,
  289.     TButton,
  290.     Class_ButtonX,
  291.     2,
  292.     '{695CDADC-02E5-11D2-B20D-00C04FA368D4}',
  293.     0,
  294.     tmApartment);
  295. end.
  296.