home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161b.iso / full / delphi / RUNIMAGE / DELPHI30 / DEMOS / ACTIVEX / DELCTRLS / CALIMPL.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-08-04  |  7.8 KB  |  315 lines

  1. unit CalImpl;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, ActiveX, Classes, Controls, Graphics, Menus, Forms, StdCtrls,
  7.   ComServ, StdVCL, AXCtrls, DelC_TLB, Calendar, Grids;
  8.  
  9. type
  10.   TCalendarX = class(TActiveXControl, ICalendarX)
  11.   private
  12.     { Private declarations }
  13.     FDelphiControl: TCalendar;
  14.     FEvents: ICalendarXEvents;
  15.     procedure ChangeEvent(Sender: TObject);
  16.     procedure ClickEvent(Sender: TObject);
  17.     procedure DblClickEvent(Sender: TObject);
  18.     procedure KeyPressEvent(Sender: TObject; var Key: Char);
  19.   protected
  20.     { Protected declarations }
  21.     procedure InitializeControl; override;
  22.     procedure EventSinkChanged(const EventSink: IUnknown); override;
  23.     procedure DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage); override;
  24.     function Get_BorderStyle: TxBorderStyle; safecall;
  25.     function Get_CalendarDate: Double; safecall;
  26.     function Get_Color: TColor; safecall;
  27.     function Get_Ctl3D: WordBool; safecall;
  28.     function Get_Cursor: Smallint; safecall;
  29.     function Get_Day: Integer; safecall;
  30.     function Get_Enabled: WordBool; safecall;
  31.     function Get_Font: Font; safecall;
  32.     function Get_GridLineWidth: Integer; safecall;
  33.     function Get_Month: Integer; safecall;
  34.     function Get_ParentColor: WordBool; safecall;
  35.     function Get_ReadOnly: WordBool; safecall;
  36.     function Get_StartOfWeek: Smallint; safecall;
  37.     function Get_UseCurrentDate: WordBool; safecall;
  38.     function Get_Visible: WordBool; safecall;
  39.     function Get_Year: Integer; safecall;
  40.     procedure AboutBox; safecall;
  41.     procedure NextMonth; safecall;
  42.     procedure NextYear; safecall;
  43.     procedure PrevMonth; safecall;
  44.     procedure PrevYear; safecall;
  45.     procedure Set_BorderStyle(Value: TxBorderStyle); safecall;
  46.     procedure Set_CalendarDate(Value: Double); safecall;
  47.     procedure Set_Color(Value: TColor); safecall;
  48.     procedure Set_Ctl3D(Value: WordBool); safecall;
  49.     procedure Set_Cursor(Value: Smallint); safecall;
  50.     procedure Set_Day(Value: Integer); safecall;
  51.     procedure Set_Enabled(Value: WordBool); safecall;
  52.     procedure Set_Font(const Value: Font); safecall;
  53.     procedure Set_GridLineWidth(Value: Integer); safecall;
  54.     procedure Set_Month(Value: Integer); safecall;
  55.     procedure Set_ParentColor(Value: WordBool); safecall;
  56.     procedure Set_ReadOnly(Value: WordBool); safecall;
  57.     procedure Set_StartOfWeek(Value: Smallint); safecall;
  58.     procedure Set_UseCurrentDate(Value: WordBool); safecall;
  59.     procedure Set_Visible(Value: WordBool); safecall;
  60.     procedure Set_Year(Value: Integer); safecall;
  61.     procedure UpdateCalendar; safecall;
  62.   end;
  63.  
  64. implementation
  65.  
  66. uses About3;
  67.  
  68. { TCalendarX }
  69.  
  70. procedure TCalendarX.InitializeControl;
  71. begin
  72.   FDelphiControl := Control as TCalendar;
  73.   FDelphiControl.OnChange := ChangeEvent;
  74.   FDelphiControl.OnClick := ClickEvent;
  75.   FDelphiControl.OnDblClick := DblClickEvent;
  76.   FDelphiControl.OnKeyPress := KeyPressEvent;
  77. end;
  78.  
  79. procedure TCalendarX.EventSinkChanged(const EventSink: IUnknown);
  80. begin
  81.   FEvents := EventSink as ICalendarXEvents;
  82. end;
  83.  
  84. procedure TCalendarX.DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage);
  85. begin
  86.   { Define property pages here.  Property pages are defined by calling
  87.     DefinePropertyPage with the class id of the page.  For example,
  88.       DefinePropertyPage(Class_CalendarXPage); }
  89. end;
  90.  
  91. function TCalendarX.Get_BorderStyle: TxBorderStyle;
  92. begin
  93.   Result := Ord(FDelphiControl.BorderStyle);
  94. end;
  95.  
  96. function TCalendarX.Get_CalendarDate: Double;
  97. begin
  98.   Result := Double(FDelphiControl.CalendarDate);
  99. end;
  100.  
  101. function TCalendarX.Get_Color: TColor;
  102. begin
  103.   Result := FDelphiControl.Color;
  104. end;
  105.  
  106. function TCalendarX.Get_Ctl3D: WordBool;
  107. begin
  108.   Result := FDelphiControl.Ctl3D;
  109. end;
  110.  
  111. function TCalendarX.Get_Cursor: Smallint;
  112. begin
  113.   Result := Smallint(FDelphiControl.Cursor);
  114. end;
  115.  
  116. function TCalendarX.Get_Day: Integer;
  117. begin
  118.   Result := FDelphiControl.Day;
  119. end;
  120.  
  121. function TCalendarX.Get_Enabled: WordBool;
  122. begin
  123.   Result := FDelphiControl.Enabled;
  124. end;
  125.  
  126. function TCalendarX.Get_Font: Font;
  127. begin
  128.   GetOleFont(FDelphiControl.Font, Result);
  129. end;
  130.  
  131. function TCalendarX.Get_GridLineWidth: Integer;
  132. begin
  133.   Result := FDelphiControl.GridLineWidth;
  134. end;
  135.  
  136. function TCalendarX.Get_Month: Integer;
  137. begin
  138.   Result := FDelphiControl.Month;
  139. end;
  140.  
  141. function TCalendarX.Get_ParentColor: WordBool;
  142. begin
  143.   Result := FDelphiControl.ParentColor;
  144. end;
  145.  
  146. function TCalendarX.Get_ReadOnly: WordBool;
  147. begin
  148.   Result := FDelphiControl.ReadOnly;
  149. end;
  150.  
  151. function TCalendarX.Get_StartOfWeek: Smallint;
  152. begin
  153.   Result := Smallint(FDelphiControl.StartOfWeek);
  154. end;
  155.  
  156. function TCalendarX.Get_UseCurrentDate: WordBool;
  157. begin
  158.   Result := FDelphiControl.UseCurrentDate;
  159. end;
  160.  
  161. function TCalendarX.Get_Visible: WordBool;
  162. begin
  163.   Result := FDelphiControl.Visible;
  164. end;
  165.  
  166. function TCalendarX.Get_Year: Integer;
  167. begin
  168.   Result := FDelphiControl.Year;
  169. end;
  170.  
  171. procedure TCalendarX.AboutBox;
  172. begin
  173.   ShowCalendarXAbout;
  174. end;
  175.  
  176. procedure TCalendarX.NextMonth;
  177. begin
  178.   FDelphiControl.NextMonth;
  179. end;
  180.  
  181. procedure TCalendarX.NextYear;
  182. begin
  183.   FDelphiControl.NextYear;
  184. end;
  185.  
  186. procedure TCalendarX.PrevMonth;
  187. begin
  188.   FDelphiControl.PrevMonth;
  189. end;
  190.  
  191. procedure TCalendarX.PrevYear;
  192. begin
  193.   FDelphiControl.PrevYear;
  194. end;
  195.  
  196. procedure TCalendarX.Set_BorderStyle(Value: TxBorderStyle);
  197. begin
  198.   FDelphiControl.BorderStyle := TBorderStyle(Value);
  199. end;
  200.  
  201. procedure TCalendarX.Set_CalendarDate(Value: Double);
  202. begin
  203.   FDelphiControl.CalendarDate := TDateTime(Value);
  204. end;
  205.  
  206. procedure TCalendarX.Set_Color(Value: TColor);
  207. begin
  208.   FDelphiControl.Color := Value;
  209. end;
  210.  
  211. procedure TCalendarX.Set_Ctl3D(Value: WordBool);
  212. begin
  213.   FDelphiControl.Ctl3D := Value;
  214. end;
  215.  
  216. procedure TCalendarX.Set_Cursor(Value: Smallint);
  217. begin
  218.   FDelphiControl.Cursor := TCursor(Value);
  219. end;
  220.  
  221. procedure TCalendarX.Set_Day(Value: Integer);
  222. begin
  223.   FDelphiControl.Day := Value;
  224. end;
  225.  
  226. procedure TCalendarX.Set_Enabled(Value: WordBool);
  227. begin
  228.   FDelphiControl.Enabled := Value;
  229. end;
  230.  
  231. procedure TCalendarX.Set_Font(const Value: Font);
  232. begin
  233.   SetOleFont(FDelphiControl.Font, Value);
  234. end;
  235.  
  236. procedure TCalendarX.Set_GridLineWidth(Value: Integer);
  237. begin
  238.   FDelphiControl.GridLineWidth := Value;
  239. end;
  240.  
  241. procedure TCalendarX.Set_Month(Value: Integer);
  242. begin
  243.   FDelphiControl.Month := Value;
  244. end;
  245.  
  246. procedure TCalendarX.Set_ParentColor(Value: WordBool);
  247. begin
  248.   FDelphiControl.ParentColor := Value;
  249. end;
  250.  
  251. procedure TCalendarX.Set_ReadOnly(Value: WordBool);
  252. begin
  253.   FDelphiControl.ReadOnly := Value;
  254. end;
  255.  
  256. procedure TCalendarX.Set_StartOfWeek(Value: Smallint);
  257. begin
  258.   FDelphiControl.StartOfWeek := TDayOfWeek(Value);
  259. end;
  260.  
  261. procedure TCalendarX.Set_UseCurrentDate(Value: WordBool);
  262. begin
  263.   FDelphiControl.UseCurrentDate := Value;
  264. end;
  265.  
  266. procedure TCalendarX.Set_Visible(Value: WordBool);
  267. begin
  268.   FDelphiControl.Visible := Value;
  269. end;
  270.  
  271. procedure TCalendarX.Set_Year(Value: Integer);
  272. begin
  273.   FDelphiControl.Year := Value;
  274. end;
  275.  
  276. procedure TCalendarX.UpdateCalendar;
  277. begin
  278.   FDelphiControl.UpdateCalendar;
  279. end;
  280.  
  281. procedure TCalendarX.ChangeEvent(Sender: TObject);
  282. begin
  283.   if FEvents <> nil then FEvents.OnChange;
  284. end;
  285.  
  286. procedure TCalendarX.ClickEvent(Sender: TObject);
  287. begin
  288.   if FEvents <> nil then FEvents.OnClick;
  289. end;
  290.  
  291. procedure TCalendarX.DblClickEvent(Sender: TObject);
  292. begin
  293.   if FEvents <> nil then FEvents.OnDblClick;
  294. end;
  295.  
  296. procedure TCalendarX.KeyPressEvent(Sender: TObject; var Key: Char);
  297. var
  298.   TempKey: Smallint;
  299. begin
  300.   TempKey := Smallint(Key);
  301.   if FEvents <> nil then FEvents.OnKeyPress(TempKey);
  302.   Key := Char(TempKey);
  303. end;
  304.  
  305. initialization
  306.   TActiveXControlFactory.Create(
  307.     ComServer,
  308.     TCalendarX,
  309.     TCalendar,
  310.     Class_CalendarX,
  311.     3,
  312.     '{FA7B82F1-9ED7-11D0-AA40-444553540000}',
  313.     0);
  314. end.
  315.