home *** CD-ROM | disk | FTP | other *** search
- /* This is a standalone .CPP file translated from the Delphi Demos\DEMOLBL.PAS
- component. This is a component that can be add to the Samples Palette via
- Component | Install | Add.
-
- Translation by:
- EDJ 08-15-96
- */
- /*
- { Demonstrates FreeNotication to safely link to controls in other forms
- through form linking and demonstrates preventing a component from being used
- in form inheritence }
- */
-
- #include <vcl.h>
- #include <vcl/controls.hpp>
- //unit DemoLbl;
-
- //interface
-
- /*
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
- */
-
- //type
- /*
- TDemoLabel = class(TGraphicControl)
- private
- FFocusControl: TWinControl;
- procedure SetFocusControl(Value: TWinControl);
- procedure CMDialogChar(var Message: TCMDialogChar); message CM_DIALOGCHAR;
- procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
- protected
- procedure Notification(AComponent: TComponent;
- Operation: TOperation); override;
- procedure Paint; override;
- public
- constructor Create(AOwner: TComponent); override;
- published
- property Caption;
- property Color;
- property FocusControl: TWinControl read FFocusControl write SetFocusControl;
- property Font;
- property ParentColor;
- property ParentFont;
- end;
- */
- class __declspec(delphiclass) TDemoLabel;
- class TDemoLabel: public TGraphicControl
- {
- private:
- TWinControl *FFocusControl;
- void __fastcall SetFocusControl(TWinControl *Value);
- MESSAGE void __fastcall CMDialogChar(TCMDialogKey &Message);
- MESSAGE void __fastcall CMTextChanged(TMessage &Message);
-
- protected:
- virtual void __fastcall Notification(TComponent *AComponent, TOperation Operation);
- virtual void __fastcall Paint();
-
- public:
- __fastcall virtual TDemoLabel(TComponent *AOwner);
-
- protected:
- __property Caption;
- __property Color;
- __property TWinControl *FocusControl =
- { read = FFocusControl,
- write = SetFocusControl
- };
- __property Font;
- __property ParentColor;
- __property ParentFont;
- };
-
- /*
- procedure Register;
-
- implementation
-
- { TDemoLabel }
- */
-
- __fastcall TDemoLabel::TDemoLabel(TComponent *AOwner):
- TGraphicControl(AOwner)
- {
- // inherited Create(AOwner);
- FComponentStyle >> csInheritable;
- }
-
- void __fastcall TDemoLabel::Notification(TComponent *AComponent, TOperation Operation)
- {
- TGraphicControl::Notification(AComponent, Operation);
- if ((Operation == opRemove)// &&
- // (*AComponent == FFocusControl)
- )
- FFocusControl = 0;
- }
-
- void __fastcall TDemoLabel::SetFocusControl(TWinControl *Value)
- {
- FFocusControl = Value;
-
- /*
- { Calling FreeNotification ensures that this component will receive an
- opRemove when Value is either removed from its owner or when it is
- destroyed. }
- */
-
- Value->FreeNotification(Value);
- }
-
- void __fastcall TDemoLabel::Paint()
- {
- TRect Rect = ClientRect;
- Canvas->Font = Font;
- Canvas->Brush->Color = Color;
- Canvas->FillRect(Rect);
- DrawText(Canvas->Handle, Caption.c_str(), Caption.Length(), Rect,
- DT_EXPANDTABS | DT_WORDBREAK | DT_LEFT);
- }
-
- void __fastcall TDemoLabel::CMDialogChar(TCMDialogKey &Message)
- {
- if (//*FFocusControl &&
- Enabled && IsAccel(Message.CharCode, Caption))
- if (FFocusControl->CanFocus())
- {
- FFocusControl->SetFocus();
- Message.Result = 1;
- }
- }
-
- void __fastcall TDemoLabel::CMTextChanged(TMessage &Message)
- {
- // inherited CMTextChanged(Message);
- Invalidate();
- }
-
- void __fastcall Register()
- {
- TComponentClass classes[1] = {__classid(TDemoLabel)};
- RegisterComponents("Samples", classes, 0);
- }
-