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

  1. unit StringGridImpl1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, ActiveX, Classes, Controls, Graphics, Menus, Forms, StdCtrls,
  7.   ComServ, StdVCL, AXCtrls, DelCtrls_TLB, Grids;
  8.  
  9. type
  10.   TStringGridX = class(TActiveXControl, IStringGridX)
  11.   private
  12.     { Private declarations }
  13.     FDelphiControl: TStringGrid;
  14.     FEvents: IStringGridXEvents;
  15.     procedure ClickEvent(Sender: TObject);
  16.     procedure ColumnMovedEvent(Sender: TObject; FromIndex, ToIndex: Integer);
  17.     procedure DblClickEvent(Sender: TObject);
  18.     procedure GetEditMaskEvent(Sender: TObject; ACol, ARow: Integer;
  19.       var Value: String);
  20.     procedure GetEditTextEvent(Sender: TObject; ACol, ARow: Integer;
  21.       var Value: String);
  22.     procedure KeyPressEvent(Sender: TObject; var Key: Char);
  23.     procedure RowMovedEvent(Sender: TObject; FromIndex, ToIndex: Integer);
  24.     procedure SelectCellEvent(Sender: TObject; ACol, ARow: Integer;
  25.       var CanSelect: Boolean);
  26.     procedure SetEditTextEvent(Sender: TObject; ACol, ARow: Integer;
  27.       const Value: String);
  28.     procedure TopLeftChangedEvent(Sender: TObject);
  29.   protected
  30.     { Protected declarations }
  31.     procedure DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage); override;
  32.     procedure EventSinkChanged(const EventSink: IUnknown); override;
  33.     procedure InitializeControl; override;
  34.     function ClassNameIs(const Name: WideString): WordBool; safecall;
  35.     function DrawTextBiDiModeFlags(Flags: Integer): Integer; safecall;
  36.     function DrawTextBiDiModeFlagsReadingOnly: Integer; safecall;
  37.     function Get_BiDiMode: TxBiDiMode; safecall;
  38.     function Get_BorderStyle: TxBorderStyle; safecall;
  39.     function Get_Col: Integer; safecall;
  40.     function Get_ColCount: Integer; safecall;
  41.     function Get_Color: OLE_COLOR; safecall;
  42.     function Get_Ctl3D: WordBool; safecall;
  43.     function Get_Cursor: Smallint; safecall;
  44.     function Get_DefaultColWidth: Integer; safecall;
  45.     function Get_DefaultDrawing: WordBool; safecall;
  46.     function Get_DefaultRowHeight: Integer; safecall;
  47.     function Get_DoubleBuffered: WordBool; safecall;
  48.     function Get_DragCursor: Smallint; safecall;
  49.     function Get_DragMode: TxDragMode; safecall;
  50.     function Get_EditorMode: WordBool; safecall;
  51.     function Get_Enabled: WordBool; safecall;
  52.     function Get_FixedColor: OLE_COLOR; safecall;
  53.     function Get_FixedCols: Integer; safecall;
  54.     function Get_FixedRows: Integer; safecall;
  55.     function Get_Font: IFontDisp; safecall;
  56.     function Get_GridHeight: Integer; safecall;
  57.     function Get_GridLineWidth: Integer; safecall;
  58.     function Get_GridWidth: Integer; safecall;
  59.     function Get_LeftCol: Integer; safecall;
  60.     function Get_ParentColor: WordBool; safecall;
  61.     function Get_ParentCtl3D: WordBool; safecall;
  62.     function Get_ParentFont: WordBool; safecall;
  63.     function Get_Row: Integer; safecall;
  64.     function Get_RowCount: Integer; safecall;
  65.     function Get_ScrollBars: TxScrollStyle; safecall;
  66.     function Get_TopRow: Integer; safecall;
  67.     function Get_Visible: WordBool; safecall;
  68.     function Get_VisibleColCount: Integer; safecall;
  69.     function Get_VisibleRowCount: Integer; safecall;
  70.     function GetControlsAlignment: TxAlignment; safecall;
  71.     function IsRightToLeft: WordBool; safecall;
  72.     function UseRightToLeftAlignment: WordBool; safecall;
  73.     function UseRightToLeftReading: WordBool; safecall;
  74.     function UseRightToLeftScrollBar: WordBool; safecall;
  75.     procedure _Set_Font(const Value: IFontDisp); safecall;
  76.     procedure AboutBox; safecall;
  77.     procedure FlipChildren(AllLevels: WordBool); safecall;
  78.     procedure InitiateAction; safecall;
  79.     procedure MouseToCell(X, Y: Integer; var ACol, ARow: Integer); safecall;
  80.     procedure Set_BiDiMode(Value: TxBiDiMode); safecall;
  81.     procedure Set_BorderStyle(Value: TxBorderStyle); safecall;
  82.     procedure Set_Col(Value: Integer); safecall;
  83.     procedure Set_ColCount(Value: Integer); safecall;
  84.     procedure Set_Color(Value: OLE_COLOR); safecall;
  85.     procedure Set_Ctl3D(Value: WordBool); safecall;
  86.     procedure Set_Cursor(Value: Smallint); safecall;
  87.     procedure Set_DefaultColWidth(Value: Integer); safecall;
  88.     procedure Set_DefaultDrawing(Value: WordBool); safecall;
  89.     procedure Set_DefaultRowHeight(Value: Integer); safecall;
  90.     procedure Set_DoubleBuffered(Value: WordBool); safecall;
  91.     procedure Set_DragCursor(Value: Smallint); safecall;
  92.     procedure Set_DragMode(Value: TxDragMode); safecall;
  93.     procedure Set_EditorMode(Value: WordBool); safecall;
  94.     procedure Set_Enabled(Value: WordBool); safecall;
  95.     procedure Set_FixedColor(Value: OLE_COLOR); safecall;
  96.     procedure Set_FixedCols(Value: Integer); safecall;
  97.     procedure Set_FixedRows(Value: Integer); safecall;
  98.     procedure Set_Font(const Value: IFontDisp); safecall;
  99.     procedure Set_GridLineWidth(Value: Integer); safecall;
  100.     procedure Set_LeftCol(Value: Integer); safecall;
  101.     procedure Set_ParentColor(Value: WordBool); safecall;
  102.     procedure Set_ParentCtl3D(Value: WordBool); safecall;
  103.     procedure Set_ParentFont(Value: WordBool); safecall;
  104.     procedure Set_Row(Value: Integer); safecall;
  105.     procedure Set_RowCount(Value: Integer); safecall;
  106.     procedure Set_ScrollBars(Value: TxScrollStyle); safecall;
  107.     procedure Set_TopRow(Value: Integer); safecall;
  108.     procedure Set_Visible(Value: WordBool); safecall;
  109.   end;
  110.  
  111. implementation
  112.  
  113. uses ComObj, About32;
  114.  
  115. { TStringGridX }
  116.  
  117. procedure TStringGridX.DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage);
  118. begin
  119.   { Define property pages here.  Property pages are defined by calling
  120.     DefinePropertyPage with the class id of the page.  For example,
  121.       DefinePropertyPage(Class_StringGridXPage); }
  122. end;
  123.  
  124. procedure TStringGridX.EventSinkChanged(const EventSink: IUnknown);
  125. begin
  126.   FEvents := EventSink as IStringGridXEvents;
  127. end;
  128.  
  129. procedure TStringGridX.InitializeControl;
  130. begin
  131.   FDelphiControl := Control as TStringGrid;
  132.   FDelphiControl.OnClick := ClickEvent;
  133.   FDelphiControl.OnColumnMoved := ColumnMovedEvent;
  134.   FDelphiControl.OnDblClick := DblClickEvent;
  135.   FDelphiControl.OnGetEditMask := GetEditMaskEvent;
  136.   FDelphiControl.OnGetEditText := GetEditTextEvent;
  137.   FDelphiControl.OnKeyPress := KeyPressEvent;
  138.   FDelphiControl.OnRowMoved := RowMovedEvent;
  139.   FDelphiControl.OnSelectCell := SelectCellEvent;
  140.   FDelphiControl.OnSetEditText := SetEditTextEvent;
  141.   FDelphiControl.OnTopLeftChanged := TopLeftChangedEvent;
  142. end;
  143.  
  144. function TStringGridX.ClassNameIs(const Name: WideString): WordBool;
  145. begin
  146.   Result := FDelphiControl.ClassNameIs(Name);
  147. end;
  148.  
  149. function TStringGridX.DrawTextBiDiModeFlags(Flags: Integer): Integer;
  150. begin
  151.   Result := FDelphiControl.DrawTextBiDiModeFlags(Flags);
  152. end;
  153.  
  154. function TStringGridX.DrawTextBiDiModeFlagsReadingOnly: Integer;
  155. begin
  156.   Result := FDelphiControl.DrawTextBiDiModeFlagsReadingOnly;
  157. end;
  158.  
  159. function TStringGridX.Get_BiDiMode: TxBiDiMode;
  160. begin
  161.   Result := Ord(FDelphiControl.BiDiMode);
  162. end;
  163.  
  164. function TStringGridX.Get_BorderStyle: TxBorderStyle;
  165. begin
  166.   Result := Ord(FDelphiControl.BorderStyle);
  167. end;
  168.  
  169. function TStringGridX.Get_Col: Integer;
  170. begin
  171.   Result := FDelphiControl.Col;
  172. end;
  173.  
  174. function TStringGridX.Get_ColCount: Integer;
  175. begin
  176.   Result := FDelphiControl.ColCount;
  177. end;
  178.  
  179. function TStringGridX.Get_Color: OLE_COLOR;
  180. begin
  181.   Result := OLE_COLOR(FDelphiControl.Color);
  182. end;
  183.  
  184. function TStringGridX.Get_Ctl3D: WordBool;
  185. begin
  186.   Result := FDelphiControl.Ctl3D;
  187. end;
  188.  
  189. function TStringGridX.Get_Cursor: Smallint;
  190. begin
  191.   Result := Smallint(FDelphiControl.Cursor);
  192. end;
  193.  
  194. function TStringGridX.Get_DefaultColWidth: Integer;
  195. begin
  196.   Result := FDelphiControl.DefaultColWidth;
  197. end;
  198.  
  199. function TStringGridX.Get_DefaultDrawing: WordBool;
  200. begin
  201.   Result := FDelphiControl.DefaultDrawing;
  202. end;
  203.  
  204. function TStringGridX.Get_DefaultRowHeight: Integer;
  205. begin
  206.   Result := FDelphiControl.DefaultRowHeight;
  207. end;
  208.  
  209. function TStringGridX.Get_DoubleBuffered: WordBool;
  210. begin
  211.   Result := FDelphiControl.DoubleBuffered;
  212. end;
  213.  
  214. function TStringGridX.Get_DragCursor: Smallint;
  215. begin
  216.   Result := Smallint(FDelphiControl.DragCursor);
  217. end;
  218.  
  219. function TStringGridX.Get_DragMode: TxDragMode;
  220. begin
  221.   Result := Ord(FDelphiControl.DragMode);
  222. end;
  223.  
  224. function TStringGridX.Get_EditorMode: WordBool;
  225. begin
  226.   Result := FDelphiControl.EditorMode;
  227. end;
  228.  
  229. function TStringGridX.Get_Enabled: WordBool;
  230. begin
  231.   Result := FDelphiControl.Enabled;
  232. end;
  233.  
  234. function TStringGridX.Get_FixedColor: OLE_COLOR;
  235. begin
  236.   Result := OLE_COLOR(FDelphiControl.FixedColor);
  237. end;
  238.  
  239. function TStringGridX.Get_FixedCols: Integer;
  240. begin
  241.   Result := FDelphiControl.FixedCols;
  242. end;
  243.  
  244. function TStringGridX.Get_FixedRows: Integer;
  245. begin
  246.   Result := FDelphiControl.FixedRows;
  247. end;
  248.  
  249. function TStringGridX.Get_Font: IFontDisp;
  250. begin
  251.   GetOleFont(FDelphiControl.Font, Result);
  252. end;
  253.  
  254. function TStringGridX.Get_GridHeight: Integer;
  255. begin
  256.   Result := FDelphiControl.GridHeight;
  257. end;
  258.  
  259. function TStringGridX.Get_GridLineWidth: Integer;
  260. begin
  261.   Result := FDelphiControl.GridLineWidth;
  262. end;
  263.  
  264. function TStringGridX.Get_GridWidth: Integer;
  265. begin
  266.   Result := FDelphiControl.GridWidth;
  267. end;
  268.  
  269. function TStringGridX.Get_LeftCol: Integer;
  270. begin
  271.   Result := FDelphiControl.LeftCol;
  272. end;
  273.  
  274. function TStringGridX.Get_ParentColor: WordBool;
  275. begin
  276.   Result := FDelphiControl.ParentColor;
  277. end;
  278.  
  279. function TStringGridX.Get_ParentCtl3D: WordBool;
  280. begin
  281.   Result := FDelphiControl.ParentCtl3D;
  282. end;
  283.  
  284. function TStringGridX.Get_ParentFont: WordBool;
  285. begin
  286.   Result := FDelphiControl.ParentFont;
  287. end;
  288.  
  289. function TStringGridX.Get_Row: Integer;
  290. begin
  291.   Result := FDelphiControl.Row;
  292. end;
  293.  
  294. function TStringGridX.Get_RowCount: Integer;
  295. begin
  296.   Result := FDelphiControl.RowCount;
  297. end;
  298.  
  299. function TStringGridX.Get_ScrollBars: TxScrollStyle;
  300. begin
  301.   Result := Ord(FDelphiControl.ScrollBars);
  302. end;
  303.  
  304. function TStringGridX.Get_TopRow: Integer;
  305. begin
  306.   Result := FDelphiControl.TopRow;
  307. end;
  308.  
  309. function TStringGridX.Get_Visible: WordBool;
  310. begin
  311.   Result := FDelphiControl.Visible;
  312. end;
  313.  
  314. function TStringGridX.Get_VisibleColCount: Integer;
  315. begin
  316.   Result := FDelphiControl.VisibleColCount;
  317. end;
  318.  
  319. function TStringGridX.Get_VisibleRowCount: Integer;
  320. begin
  321.   Result := FDelphiControl.VisibleRowCount;
  322. end;
  323.  
  324. function TStringGridX.GetControlsAlignment: TxAlignment;
  325. begin
  326.  Result := TxAlignment(FDelphiControl.GetControlsAlignment);
  327. end;
  328.  
  329. function TStringGridX.IsRightToLeft: WordBool;
  330. begin
  331.   Result := FDelphiControl.IsRightToLeft;
  332. end;
  333.  
  334. function TStringGridX.UseRightToLeftAlignment: WordBool;
  335. begin
  336.   Result := FDelphiControl.UseRightToLeftAlignment;
  337. end;
  338.  
  339. function TStringGridX.UseRightToLeftReading: WordBool;
  340. begin
  341.   Result := FDelphiControl.UseRightToLeftReading;
  342. end;
  343.  
  344. function TStringGridX.UseRightToLeftScrollBar: WordBool;
  345. begin
  346.   Result := FDelphiControl.UseRightToLeftScrollBar;
  347. end;
  348.  
  349. procedure TStringGridX._Set_Font(const Value: IFontDisp);
  350. begin
  351.   SetOleFont(FDelphiControl.Font, Value);
  352. end;
  353.  
  354. procedure TStringGridX.AboutBox;
  355. begin
  356.   ShowStringGridXAbout;
  357. end;
  358.  
  359. procedure TStringGridX.FlipChildren(AllLevels: WordBool);
  360. begin
  361.   FDelphiControl.FlipChildren(AllLevels);
  362. end;
  363.  
  364. procedure TStringGridX.InitiateAction;
  365. begin
  366.   FDelphiControl.InitiateAction;
  367. end;
  368.  
  369. procedure TStringGridX.MouseToCell(X, Y: Integer; var ACol, ARow: Integer);
  370. begin
  371.  
  372. end;
  373.  
  374. procedure TStringGridX.Set_BiDiMode(Value: TxBiDiMode);
  375. begin
  376.   FDelphiControl.BiDiMode := TBiDiMode(Value);
  377. end;
  378.  
  379. procedure TStringGridX.Set_BorderStyle(Value: TxBorderStyle);
  380. begin
  381.   FDelphiControl.BorderStyle := TBorderStyle(Value);
  382. end;
  383.  
  384. procedure TStringGridX.Set_Col(Value: Integer);
  385. begin
  386.   FDelphiControl.Col := Value;
  387. end;
  388.  
  389. procedure TStringGridX.Set_ColCount(Value: Integer);
  390. begin
  391.   FDelphiControl.ColCount := Value;
  392. end;
  393.  
  394. procedure TStringGridX.Set_Color(Value: OLE_COLOR);
  395. begin
  396.   FDelphiControl.Color := TColor(Value);
  397. end;
  398.  
  399. procedure TStringGridX.Set_Ctl3D(Value: WordBool);
  400. begin
  401.   FDelphiControl.Ctl3D := Value;
  402. end;
  403.  
  404. procedure TStringGridX.Set_Cursor(Value: Smallint);
  405. begin
  406.   FDelphiControl.Cursor := TCursor(Value);
  407. end;
  408.  
  409. procedure TStringGridX.Set_DefaultColWidth(Value: Integer);
  410. begin
  411.   FDelphiControl.DefaultColWidth := Value;
  412. end;
  413.  
  414. procedure TStringGridX.Set_DefaultDrawing(Value: WordBool);
  415. begin
  416.   FDelphiControl.DefaultDrawing := Value;
  417. end;
  418.  
  419. procedure TStringGridX.Set_DefaultRowHeight(Value: Integer);
  420. begin
  421.   FDelphiControl.DefaultRowHeight := Value;
  422. end;
  423.  
  424. procedure TStringGridX.Set_DoubleBuffered(Value: WordBool);
  425. begin
  426.   FDelphiControl.DoubleBuffered := Value;
  427. end;
  428.  
  429. procedure TStringGridX.Set_DragCursor(Value: Smallint);
  430. begin
  431.   FDelphiControl.DragCursor := TCursor(Value);
  432. end;
  433.  
  434. procedure TStringGridX.Set_DragMode(Value: TxDragMode);
  435. begin
  436.   FDelphiControl.DragMode := TDragMode(Value);
  437. end;
  438.  
  439. procedure TStringGridX.Set_EditorMode(Value: WordBool);
  440. begin
  441.   FDelphiControl.EditorMode := Value;
  442. end;
  443.  
  444. procedure TStringGridX.Set_Enabled(Value: WordBool);
  445. begin
  446.   FDelphiControl.Enabled := Value;
  447. end;
  448.  
  449. procedure TStringGridX.Set_FixedColor(Value: OLE_COLOR);
  450. begin
  451.   FDelphiControl.FixedColor := TColor(Value);
  452. end;
  453.  
  454. procedure TStringGridX.Set_FixedCols(Value: Integer);
  455. begin
  456.   FDelphiControl.FixedCols := Value;
  457. end;
  458.  
  459. procedure TStringGridX.Set_FixedRows(Value: Integer);
  460. begin
  461.   FDelphiControl.FixedRows := Value;
  462. end;
  463.  
  464. procedure TStringGridX.Set_Font(const Value: IFontDisp);
  465. begin
  466.   SetOleFont(FDelphiControl.Font, Value);
  467. end;
  468.  
  469. procedure TStringGridX.Set_GridLineWidth(Value: Integer);
  470. begin
  471.   FDelphiControl.GridLineWidth := Value;
  472. end;
  473.  
  474. procedure TStringGridX.Set_LeftCol(Value: Integer);
  475. begin
  476.   FDelphiControl.LeftCol := Value;
  477. end;
  478.  
  479. procedure TStringGridX.Set_ParentColor(Value: WordBool);
  480. begin
  481.   FDelphiControl.ParentColor := Value;
  482. end;
  483.  
  484. procedure TStringGridX.Set_ParentCtl3D(Value: WordBool);
  485. begin
  486.   FDelphiControl.ParentCtl3D := Value;
  487. end;
  488.  
  489. procedure TStringGridX.Set_ParentFont(Value: WordBool);
  490. begin
  491.   FDelphiControl.ParentFont := Value;
  492. end;
  493.  
  494. procedure TStringGridX.Set_Row(Value: Integer);
  495. begin
  496.   FDelphiControl.Row := Value;
  497. end;
  498.  
  499. procedure TStringGridX.Set_RowCount(Value: Integer);
  500. begin
  501.   FDelphiControl.RowCount := Value;
  502. end;
  503.  
  504. procedure TStringGridX.Set_ScrollBars(Value: TxScrollStyle);
  505. begin
  506.   FDelphiControl.ScrollBars := TScrollStyle(Value);
  507. end;
  508.  
  509. procedure TStringGridX.Set_TopRow(Value: Integer);
  510. begin
  511.   FDelphiControl.TopRow := Value;
  512. end;
  513.  
  514. procedure TStringGridX.Set_Visible(Value: WordBool);
  515. begin
  516.   FDelphiControl.Visible := Value;
  517. end;
  518.  
  519. procedure TStringGridX.ClickEvent(Sender: TObject);
  520. begin
  521.   if FEvents <> nil then FEvents.OnClick;
  522. end;
  523.  
  524. procedure TStringGridX.ColumnMovedEvent(Sender: TObject; FromIndex,
  525.   ToIndex: Integer);
  526. begin
  527.   if FEvents <> nil then FEvents.OnColumnMoved(FromIndex, ToIndex);
  528. end;
  529.  
  530. procedure TStringGridX.DblClickEvent(Sender: TObject);
  531. begin
  532.   if FEvents <> nil then FEvents.OnDblClick;
  533. end;
  534.  
  535. procedure TStringGridX.GetEditMaskEvent(Sender: TObject; ACol,
  536.   ARow: Integer; var Value: String);
  537. var
  538.   TempValue: WideString;
  539. begin
  540.   TempValue := WideString(Value);
  541.   if FEvents <> nil then FEvents.OnGetEditMask(ACol, ARow, TempValue);
  542.   Value := String(TempValue);
  543. end;
  544.  
  545. procedure TStringGridX.GetEditTextEvent(Sender: TObject; ACol,
  546.   ARow: Integer; var Value: String);
  547. var
  548.   TempValue: WideString;
  549. begin
  550.   TempValue := WideString(Value);
  551.   if FEvents <> nil then FEvents.OnGetEditText(ACol, ARow, TempValue);
  552.   Value := String(TempValue);
  553. end;
  554.  
  555. procedure TStringGridX.KeyPressEvent(Sender: TObject; var Key: Char);
  556. var
  557.   TempKey: Smallint;
  558. begin
  559.   TempKey := Smallint(Key);
  560.   if FEvents <> nil then FEvents.OnKeyPress(TempKey);
  561.   Key := Char(TempKey);
  562. end;
  563.  
  564. procedure TStringGridX.RowMovedEvent(Sender: TObject; FromIndex,
  565.   ToIndex: Integer);
  566. begin
  567.   if FEvents <> nil then FEvents.OnRowMoved(FromIndex, ToIndex);
  568. end;
  569.  
  570. procedure TStringGridX.SelectCellEvent(Sender: TObject; ACol,
  571.   ARow: Integer; var CanSelect: Boolean);
  572. var
  573.   TempCanSelect: WordBool;
  574. begin
  575.   TempCanSelect := WordBool(CanSelect);
  576.   if FEvents <> nil then FEvents.OnSelectCell(ACol, ARow, TempCanSelect);
  577.   CanSelect := Boolean(TempCanSelect);
  578. end;
  579.  
  580. procedure TStringGridX.SetEditTextEvent(Sender: TObject; ACol,
  581.   ARow: Integer; const Value: String);
  582. begin
  583.   if FEvents <> nil then FEvents.OnSetEditText(ACol, ARow, WideString(Value));
  584. end;
  585.  
  586. procedure TStringGridX.TopLeftChangedEvent(Sender: TObject);
  587. begin
  588.   if FEvents <> nil then FEvents.OnTopLeftChanged;
  589. end;
  590.  
  591. initialization
  592.   TActiveXControlFactory.Create(
  593.     ComServer,
  594.     TStringGridX,
  595.     TStringGrid,
  596.     Class_StringGridX,
  597.     32,
  598.     '{695CDBCC-02E5-11D2-B20D-00C04FA368D4}',
  599.     0,
  600.     tmApartment);
  601. end.
  602.