home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161b.iso / full / delphi / INSTALL / data.z / DGRDIMPL.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-08-05  |  13.3 KB  |  499 lines

  1. unit DGrdImpl;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, ActiveX, Classes, Controls, Graphics, Menus, Forms, StdCtrls,
  7.   ComServ, StdVCL, AXCtrls, DelC_TLB, Grids;
  8.  
  9. type
  10.   TDrawGridX = class(TActiveXControl, IDrawGridX)
  11.   private
  12.     { Private declarations }
  13.     FDelphiControl: TDrawGrid;
  14.     FEvents: IDrawGridXEvents;
  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; Col, Row: 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 InitializeControl; override;
  32.     procedure EventSinkChanged(const EventSink: IUnknown); override;
  33.     procedure DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage); override;
  34.     function Get_BorderStyle: TxBorderStyle; safecall;
  35.     function Get_Col: Integer; safecall;
  36.     function Get_ColCount: Integer; safecall;
  37.     function Get_Color: TColor; safecall;
  38.     function Get_Ctl3D: WordBool; safecall;
  39.     function Get_Cursor: Smallint; safecall;
  40.     function Get_DefaultColWidth: Integer; safecall;
  41.     function Get_DefaultDrawing: WordBool; safecall;
  42.     function Get_DefaultRowHeight: Integer; safecall;
  43.     function Get_DragCursor: Smallint; safecall;
  44.     function Get_DragMode: TxDragMode; safecall;
  45.     function Get_EditorMode: WordBool; safecall;
  46.     function Get_Enabled: WordBool; safecall;
  47.     function Get_FixedColor: TColor; safecall;
  48.     function Get_FixedCols: Integer; safecall;
  49.     function Get_FixedRows: Integer; safecall;
  50.     function Get_Font: Font; safecall;
  51.     function Get_GridHeight: Integer; safecall;
  52.     function Get_GridLineWidth: Integer; safecall;
  53.     function Get_GridWidth: Integer; safecall;
  54.     function Get_LeftCol: Integer; safecall;
  55.     function Get_ParentColor: WordBool; safecall;
  56.     function Get_ParentCtl3D: WordBool; safecall;
  57.     function Get_Row: Integer; safecall;
  58.     function Get_RowCount: Integer; safecall;
  59.     function Get_ScrollBars: TxScrollStyle; safecall;
  60.     function Get_TopRow: Integer; safecall;
  61.     function Get_Visible: WordBool; safecall;
  62.     function Get_VisibleColCount: Integer; safecall;
  63.     function Get_VisibleRowCount: Integer; safecall;
  64.     procedure AboutBox; safecall;
  65.     procedure MouseToCell(X, Y: Integer; var ACol, ARow: Integer); safecall;
  66.     procedure Set_BorderStyle(Value: TxBorderStyle); safecall;
  67.     procedure Set_Col(Value: Integer); safecall;
  68.     procedure Set_ColCount(Value: Integer); safecall;
  69.     procedure Set_Color(Value: TColor); safecall;
  70.     procedure Set_Ctl3D(Value: WordBool); safecall;
  71.     procedure Set_Cursor(Value: Smallint); safecall;
  72.     procedure Set_DefaultColWidth(Value: Integer); safecall;
  73.     procedure Set_DefaultDrawing(Value: WordBool); safecall;
  74.     procedure Set_DefaultRowHeight(Value: Integer); safecall;
  75.     procedure Set_DragCursor(Value: Smallint); safecall;
  76.     procedure Set_DragMode(Value: TxDragMode); safecall;
  77.     procedure Set_EditorMode(Value: WordBool); safecall;
  78.     procedure Set_Enabled(Value: WordBool); safecall;
  79.     procedure Set_FixedColor(Value: TColor); safecall;
  80.     procedure Set_FixedCols(Value: Integer); safecall;
  81.     procedure Set_FixedRows(Value: Integer); safecall;
  82.     procedure Set_Font(const Value: Font); safecall;
  83.     procedure Set_GridLineWidth(Value: Integer); safecall;
  84.     procedure Set_LeftCol(Value: Integer); safecall;
  85.     procedure Set_ParentColor(Value: WordBool); safecall;
  86.     procedure Set_ParentCtl3D(Value: WordBool); safecall;
  87.     procedure Set_Row(Value: Integer); safecall;
  88.     procedure Set_RowCount(Value: Integer); safecall;
  89.     procedure Set_ScrollBars(Value: TxScrollStyle); safecall;
  90.     procedure Set_TopRow(Value: Integer); safecall;
  91.     procedure Set_Visible(Value: WordBool); safecall;
  92.   end;
  93.  
  94. implementation
  95.  
  96. uses About9;
  97.  
  98. { TDrawGridX }
  99.  
  100. procedure TDrawGridX.InitializeControl;
  101. begin
  102.   FDelphiControl := Control as TDrawGrid;
  103.   FDelphiControl.OnClick := ClickEvent;
  104.   FDelphiControl.OnColumnMoved := ColumnMovedEvent;
  105.   FDelphiControl.OnDblClick := DblClickEvent;
  106.   FDelphiControl.OnGetEditMask := GetEditMaskEvent;
  107.   FDelphiControl.OnGetEditText := GetEditTextEvent;
  108.   FDelphiControl.OnKeyPress := KeyPressEvent;
  109.   FDelphiControl.OnRowMoved := RowMovedEvent;
  110.   FDelphiControl.OnSelectCell := SelectCellEvent;
  111.   FDelphiControl.OnSetEditText := SetEditTextEvent;
  112.   FDelphiControl.OnTopLeftChanged := TopLeftChangedEvent;
  113. end;
  114.  
  115. procedure TDrawGridX.EventSinkChanged(const EventSink: IUnknown);
  116. begin
  117.   FEvents := EventSink as IDrawGridXEvents;
  118. end;
  119.  
  120. procedure TDrawGridX.DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage);
  121. begin
  122.   { Define property pages here.  Property pages are defined by calling
  123.     DefinePropertyPage with the class id of the page.  For example,
  124.       DefinePropertyPage(Class_DrawGridXPage); }
  125. end;
  126.  
  127. function TDrawGridX.Get_BorderStyle: TxBorderStyle;
  128. begin
  129.   Result := Ord(FDelphiControl.BorderStyle);
  130. end;
  131.  
  132. function TDrawGridX.Get_Col: Integer;
  133. begin
  134.   Result := FDelphiControl.Col;
  135. end;
  136.  
  137. function TDrawGridX.Get_ColCount: Integer;
  138. begin
  139.   Result := FDelphiControl.ColCount;
  140. end;
  141.  
  142. function TDrawGridX.Get_Color: TColor;
  143. begin
  144.   Result := FDelphiControl.Color;
  145. end;
  146.  
  147. function TDrawGridX.Get_Ctl3D: WordBool;
  148. begin
  149.   Result := FDelphiControl.Ctl3D;
  150. end;
  151.  
  152. function TDrawGridX.Get_Cursor: Smallint;
  153. begin
  154.   Result := Smallint(FDelphiControl.Cursor);
  155. end;
  156.  
  157. function TDrawGridX.Get_DefaultColWidth: Integer;
  158. begin
  159.   Result := FDelphiControl.DefaultColWidth;
  160. end;
  161.  
  162. function TDrawGridX.Get_DefaultDrawing: WordBool;
  163. begin
  164.   Result := FDelphiControl.DefaultDrawing;
  165. end;
  166.  
  167. function TDrawGridX.Get_DefaultRowHeight: Integer;
  168. begin
  169.   Result := FDelphiControl.DefaultRowHeight;
  170. end;
  171.  
  172. function TDrawGridX.Get_DragCursor: Smallint;
  173. begin
  174.   Result := Smallint(FDelphiControl.DragCursor);
  175. end;
  176.  
  177. function TDrawGridX.Get_DragMode: TxDragMode;
  178. begin
  179.   Result := Ord(FDelphiControl.DragMode);
  180. end;
  181.  
  182. function TDrawGridX.Get_EditorMode: WordBool;
  183. begin
  184.   Result := FDelphiControl.EditorMode;
  185. end;
  186.  
  187. function TDrawGridX.Get_Enabled: WordBool;
  188. begin
  189.   Result := FDelphiControl.Enabled;
  190. end;
  191.  
  192. function TDrawGridX.Get_FixedColor: TColor;
  193. begin
  194.   Result := FDelphiControl.FixedColor;
  195. end;
  196.  
  197. function TDrawGridX.Get_FixedCols: Integer;
  198. begin
  199.   Result := FDelphiControl.FixedCols;
  200. end;
  201.  
  202. function TDrawGridX.Get_FixedRows: Integer;
  203. begin
  204.   Result := FDelphiControl.FixedRows;
  205. end;
  206.  
  207. function TDrawGridX.Get_Font: Font;
  208. begin
  209.   GetOleFont(FDelphiControl.Font, Result);
  210. end;
  211.  
  212. function TDrawGridX.Get_GridHeight: Integer;
  213. begin
  214.   Result := FDelphiControl.GridHeight;
  215. end;
  216.  
  217. function TDrawGridX.Get_GridLineWidth: Integer;
  218. begin
  219.   Result := FDelphiControl.GridLineWidth;
  220. end;
  221.  
  222. function TDrawGridX.Get_GridWidth: Integer;
  223. begin
  224.   Result := FDelphiControl.GridWidth;
  225. end;
  226.  
  227. function TDrawGridX.Get_LeftCol: Integer;
  228. begin
  229.   Result := FDelphiControl.LeftCol;
  230. end;
  231.  
  232. function TDrawGridX.Get_ParentColor: WordBool;
  233. begin
  234.   Result := FDelphiControl.ParentColor;
  235. end;
  236.  
  237. function TDrawGridX.Get_ParentCtl3D: WordBool;
  238. begin
  239.   Result := FDelphiControl.ParentCtl3D;
  240. end;
  241.  
  242. function TDrawGridX.Get_Row: Integer;
  243. begin
  244.   Result := FDelphiControl.Row;
  245. end;
  246.  
  247. function TDrawGridX.Get_RowCount: Integer;
  248. begin
  249.   Result := FDelphiControl.RowCount;
  250. end;
  251.  
  252. function TDrawGridX.Get_ScrollBars: TxScrollStyle;
  253. begin
  254.   Result := Ord(FDelphiControl.ScrollBars);
  255. end;
  256.  
  257. function TDrawGridX.Get_TopRow: Integer;
  258. begin
  259.   Result := FDelphiControl.TopRow;
  260. end;
  261.  
  262. function TDrawGridX.Get_Visible: WordBool;
  263. begin
  264.   Result := FDelphiControl.Visible;
  265. end;
  266.  
  267. function TDrawGridX.Get_VisibleColCount: Integer;
  268. begin
  269.   Result := FDelphiControl.VisibleColCount;
  270. end;
  271.  
  272. function TDrawGridX.Get_VisibleRowCount: Integer;
  273. begin
  274.   Result := FDelphiControl.VisibleRowCount;
  275. end;
  276.  
  277. procedure TDrawGridX.AboutBox;
  278. begin
  279.   ShowDrawGridXAbout;
  280. end;
  281.  
  282. procedure TDrawGridX.MouseToCell(X, Y: Integer; var ACol, ARow: Integer);
  283. begin
  284.  
  285. end;
  286.  
  287. procedure TDrawGridX.Set_BorderStyle(Value: TxBorderStyle);
  288. begin
  289.   FDelphiControl.BorderStyle := TBorderStyle(Value);
  290. end;
  291.  
  292. procedure TDrawGridX.Set_Col(Value: Integer);
  293. begin
  294.   FDelphiControl.Col := Value;
  295. end;
  296.  
  297. procedure TDrawGridX.Set_ColCount(Value: Integer);
  298. begin
  299.   FDelphiControl.ColCount := Value;
  300. end;
  301.  
  302. procedure TDrawGridX.Set_Color(Value: TColor);
  303. begin
  304.   FDelphiControl.Color := Value;
  305. end;
  306.  
  307. procedure TDrawGridX.Set_Ctl3D(Value: WordBool);
  308. begin
  309.   FDelphiControl.Ctl3D := Value;
  310. end;
  311.  
  312. procedure TDrawGridX.Set_Cursor(Value: Smallint);
  313. begin
  314.   FDelphiControl.Cursor := TCursor(Value);
  315. end;
  316.  
  317. procedure TDrawGridX.Set_DefaultColWidth(Value: Integer);
  318. begin
  319.   FDelphiControl.DefaultColWidth := Value;
  320. end;
  321.  
  322. procedure TDrawGridX.Set_DefaultDrawing(Value: WordBool);
  323. begin
  324.   FDelphiControl.DefaultDrawing := Value;
  325. end;
  326.  
  327. procedure TDrawGridX.Set_DefaultRowHeight(Value: Integer);
  328. begin
  329.   FDelphiControl.DefaultRowHeight := Value;
  330. end;
  331.  
  332. procedure TDrawGridX.Set_DragCursor(Value: Smallint);
  333. begin
  334.   FDelphiControl.DragCursor := TCursor(Value);
  335. end;
  336.  
  337. procedure TDrawGridX.Set_DragMode(Value: TxDragMode);
  338. begin
  339.   FDelphiControl.DragMode := TDragMode(Value);
  340. end;
  341.  
  342. procedure TDrawGridX.Set_EditorMode(Value: WordBool);
  343. begin
  344.   FDelphiControl.EditorMode := Value;
  345. end;
  346.  
  347. procedure TDrawGridX.Set_Enabled(Value: WordBool);
  348. begin
  349.   FDelphiControl.Enabled := Value;
  350. end;
  351.  
  352. procedure TDrawGridX.Set_FixedColor(Value: TColor);
  353. begin
  354.   FDelphiControl.FixedColor := Value;
  355. end;
  356.  
  357. procedure TDrawGridX.Set_FixedCols(Value: Integer);
  358. begin
  359.   FDelphiControl.FixedCols := Value;
  360. end;
  361.  
  362. procedure TDrawGridX.Set_FixedRows(Value: Integer);
  363. begin
  364.   FDelphiControl.FixedRows := Value;
  365. end;
  366.  
  367. procedure TDrawGridX.Set_Font(const Value: Font);
  368. begin
  369.   SetOleFont(FDelphiControl.Font, Value);
  370. end;
  371.  
  372. procedure TDrawGridX.Set_GridLineWidth(Value: Integer);
  373. begin
  374.   FDelphiControl.GridLineWidth := Value;
  375. end;
  376.  
  377. procedure TDrawGridX.Set_LeftCol(Value: Integer);
  378. begin
  379.   FDelphiControl.LeftCol := Value;
  380. end;
  381.  
  382. procedure TDrawGridX.Set_ParentColor(Value: WordBool);
  383. begin
  384.   FDelphiControl.ParentColor := Value;
  385. end;
  386.  
  387. procedure TDrawGridX.Set_ParentCtl3D(Value: WordBool);
  388. begin
  389.   FDelphiControl.ParentCtl3D := Value;
  390. end;
  391.  
  392. procedure TDrawGridX.Set_Row(Value: Integer);
  393. begin
  394.   FDelphiControl.Row := Value;
  395. end;
  396.  
  397. procedure TDrawGridX.Set_RowCount(Value: Integer);
  398. begin
  399.   FDelphiControl.RowCount := Value;
  400. end;
  401.  
  402. procedure TDrawGridX.Set_ScrollBars(Value: TxScrollStyle);
  403. begin
  404.   FDelphiControl.ScrollBars := TScrollStyle(Value);
  405. end;
  406.  
  407. procedure TDrawGridX.Set_TopRow(Value: Integer);
  408. begin
  409.   FDelphiControl.TopRow := Value;
  410. end;
  411.  
  412. procedure TDrawGridX.Set_Visible(Value: WordBool);
  413. begin
  414.   FDelphiControl.Visible := Value;
  415. end;
  416.  
  417. procedure TDrawGridX.ClickEvent(Sender: TObject);
  418. begin
  419.   if FEvents <> nil then FEvents.OnClick;
  420. end;
  421.  
  422. procedure TDrawGridX.ColumnMovedEvent(Sender: TObject; FromIndex,
  423.   ToIndex: Integer);
  424. begin
  425.   if FEvents <> nil then FEvents.OnColumnMoved(FromIndex, ToIndex);
  426. end;
  427.  
  428. procedure TDrawGridX.DblClickEvent(Sender: TObject);
  429. begin
  430.   if FEvents <> nil then FEvents.OnDblClick;
  431. end;
  432.  
  433. procedure TDrawGridX.GetEditMaskEvent(Sender: TObject; ACol, ARow: Integer;
  434.   var Value: String);
  435. var
  436.   TempValue: WideString;
  437. begin
  438.   TempValue := WideString(Value);
  439.   if FEvents <> nil then FEvents.OnGetEditMask(ACol, ARow, TempValue);
  440.   Value := String(TempValue);
  441. end;
  442.  
  443. procedure TDrawGridX.GetEditTextEvent(Sender: TObject; ACol, ARow: Integer;
  444.   var Value: String);
  445. var
  446.   TempValue: WideString;
  447. begin
  448.   TempValue := WideString(Value);
  449.   if FEvents <> nil then FEvents.OnGetEditText(ACol, ARow, TempValue);
  450.   Value := String(TempValue);
  451. end;
  452.  
  453. procedure TDrawGridX.KeyPressEvent(Sender: TObject; var Key: Char);
  454. var
  455.   TempKey: Smallint;
  456. begin
  457.   TempKey := Smallint(Key);
  458.   if FEvents <> nil then FEvents.OnKeyPress(TempKey);
  459.   Key := Char(TempKey);
  460. end;
  461.  
  462. procedure TDrawGridX.RowMovedEvent(Sender: TObject; FromIndex,
  463.   ToIndex: Integer);
  464. begin
  465.   if FEvents <> nil then FEvents.OnRowMoved(FromIndex, ToIndex);
  466. end;
  467.  
  468. procedure TDrawGridX.SelectCellEvent(Sender: TObject; Col, Row: Integer;
  469.   var CanSelect: Boolean);
  470. var
  471.   TempCanSelect: WordBool;
  472. begin
  473.   TempCanSelect := WordBool(CanSelect);
  474.   if FEvents <> nil then FEvents.OnSelectCell(Col, Row, TempCanSelect);
  475.   CanSelect := Boolean(TempCanSelect);
  476. end;
  477.  
  478. procedure TDrawGridX.SetEditTextEvent(Sender: TObject; ACol, ARow: Integer;
  479.   const Value: String);
  480. begin
  481.   if FEvents <> nil then FEvents.OnSetEditText(ACol, ARow, WideString(Value));
  482. end;
  483.  
  484. procedure TDrawGridX.TopLeftChangedEvent(Sender: TObject);
  485. begin
  486.   if FEvents <> nil then FEvents.OnTopLeftChanged;
  487. end;
  488.  
  489. initialization
  490.   TActiveXControlFactory.Create(
  491.     ComServer,
  492.     TDrawGridX,
  493.     TDrawGrid,
  494.     Class_DrawGridX,
  495.     9,
  496.     '{FA7B835C-9ED7-11D0-AA40-444553540000}',
  497.     0);
  498. end.
  499.