home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / progs / CB / DATA.Z / DEMOLBL.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-27  |  3.6 KB  |  145 lines

  1. /* This is a standalone .CPP file translated from the Delphi Demos\DEMOLBL.PAS
  2.    component.  This is a component that can be add to the Samples Palette via
  3.    Component | Install | Add.
  4.  
  5.    Translation by:
  6.    EDJ 08-15-96
  7. */
  8. /*
  9. { Demonstrates FreeNotication to safely link to controls in other forms
  10.   through form linking and demonstrates preventing a component from being used
  11.   in form inheritence }
  12. */
  13.  
  14. #include    <vcl.h>
  15. #include    <vcl/controls.hpp>
  16. //unit DemoLbl;
  17.  
  18. //interface
  19.  
  20. /*
  21. uses
  22.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
  23. */
  24.  
  25. //type
  26. /*
  27.   TDemoLabel = class(TGraphicControl)
  28.   private
  29.     FFocusControl: TWinControl;
  30.     procedure SetFocusControl(Value: TWinControl);
  31.     procedure CMDialogChar(var Message: TCMDialogChar); message CM_DIALOGCHAR;
  32.     procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
  33.   protected
  34.     procedure Notification(AComponent: TComponent;
  35.       Operation: TOperation); override;
  36.     procedure Paint; override;
  37.   public
  38.     constructor Create(AOwner: TComponent); override;
  39.   published
  40.     property Caption;
  41.     property Color;
  42.     property FocusControl: TWinControl read FFocusControl write SetFocusControl;
  43.     property Font;
  44.     property ParentColor;
  45.     property ParentFont;
  46.   end;
  47. */
  48. class __declspec(delphiclass) TDemoLabel;
  49. class TDemoLabel: public TGraphicControl
  50. {
  51.   private:
  52.   TWinControl                            *FFocusControl;
  53.   void __fastcall                    SetFocusControl(TWinControl *Value);
  54.   MESSAGE void __fastcall CMDialogChar(TCMDialogKey &Message);
  55.   MESSAGE void __fastcall    CMTextChanged(TMessage &Message);
  56.  
  57.   protected:
  58.   virtual void __fastcall    Notification(TComponent *AComponent, TOperation Operation);
  59.   virtual void __fastcall Paint();
  60.  
  61.   public:
  62.   __fastcall virtual TDemoLabel(TComponent *AOwner);
  63.  
  64.   protected:
  65.   __property Caption;
  66.   __property Color;
  67.   __property TWinControl    *FocusControl    =
  68.   {    read    = FFocusControl,
  69.     write    = SetFocusControl
  70.   };
  71.   __property Font;
  72.   __property ParentColor;
  73.   __property ParentFont;
  74. };
  75.  
  76. /*
  77. procedure Register;
  78.  
  79. implementation
  80.  
  81. { TDemoLabel }
  82. */
  83.  
  84. __fastcall TDemoLabel::TDemoLabel(TComponent *AOwner):
  85.     TGraphicControl(AOwner)
  86. {
  87. //  inherited Create(AOwner);
  88.   FComponentStyle >> csInheritable;
  89. }
  90.  
  91. void __fastcall    TDemoLabel::Notification(TComponent *AComponent, TOperation Operation)
  92. {
  93.   TGraphicControl::Notification(AComponent, Operation);
  94.   if ((Operation == opRemove)// &&
  95. //        (*AComponent == FFocusControl)
  96. )
  97.     FFocusControl = 0;
  98. }
  99.  
  100. void __fastcall    TDemoLabel::SetFocusControl(TWinControl *Value)
  101. {
  102.   FFocusControl = Value;
  103.  
  104. /*
  105.   { Calling FreeNotification ensures that this component will receive an
  106.     opRemove when Value is either removed from its owner or when it is
  107.     destroyed. }
  108. */
  109.  
  110.   Value->FreeNotification(Value);
  111. }
  112.  
  113. void __fastcall    TDemoLabel::Paint()
  114. {
  115.     TRect    Rect    = ClientRect;
  116.   Canvas->Font    = Font;
  117.   Canvas->Brush->Color    = Color;
  118.   Canvas->FillRect(Rect);
  119.   DrawText(Canvas->Handle, Caption.c_str(), Caption.Length(), Rect,
  120.     DT_EXPANDTABS | DT_WORDBREAK | DT_LEFT);
  121. }
  122.  
  123. void __fastcall    TDemoLabel::CMDialogChar(TCMDialogKey &Message)
  124. {
  125.   if (//*FFocusControl &&
  126.        Enabled && IsAccel(Message.CharCode, Caption))
  127.       if (FFocusControl->CanFocus())
  128.       {
  129.         FFocusControl->SetFocus();
  130.         Message.Result = 1;
  131.       }
  132. }
  133.  
  134. void __fastcall    TDemoLabel::CMTextChanged(TMessage &Message)
  135. {
  136. //    inherited CMTextChanged(Message);
  137.   Invalidate();
  138. }
  139.  
  140. void __fastcall Register()
  141. {
  142.   TComponentClass classes[1] = {__classid(TDemoLabel)};
  143.   RegisterComponents("Samples", classes, 0);
  144. }
  145.