home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 April / Chip_1997-04_cd.bin / prezent / cb / data.z / DEMOLBL.CPP < prev    next >
C/C++ Source or Header  |  1997-01-16  |  2KB  |  76 lines

  1. //---------------------------------------------------------------------------
  2. // Borland C++Builder
  3. // Copyright (c) 1987, 1997 Borland International Inc.  All Rights Reserved.
  4. //---------------------------------------------------------------------------
  5. // Demonstrates FreeNotication to safely link to controls in other forms
  6. //  through form linking and demonstrates preventing a component from being used
  7. //  in form inheritence
  8.  
  9. #if !defined (REGISTER_ALL_CONTROLS)
  10.   #include  "demolbl.h"
  11. #else
  12.   #include "demolbl\demolbl.h"
  13. #endif
  14.  
  15. //#pragma resource "*.res"   //IDE links .res automatically for components
  16.  
  17. namespace Demolbl{
  18. void __fastcall Register()
  19. {
  20.   TComponentClass classes[1] = {__classid(TDemoLabel)};
  21.   RegisterComponents("Samples", classes, 0);
  22. }
  23. } //end namespace
  24.  
  25. __fastcall TDemoLabel::TDemoLabel(TComponent *AOwner):
  26.     TGraphicControl(AOwner)
  27. {
  28.   FComponentStyle >> csInheritable;
  29. }
  30.  
  31. void __fastcall    TDemoLabel::Notification(TComponent *AComponent, TOperation Operation)
  32. {
  33.   TGraphicControl::Notification(AComponent, Operation);
  34.   if ((Operation == opRemove)  && (AComponent == FFocusControl))
  35.     FFocusControl = 0;
  36. }
  37.  
  38. void __fastcall    TDemoLabel::SetFocusControl(TWinControl *Value)
  39. {
  40.   FFocusControl = Value;
  41.  
  42.   // Calling FreeNotification ensures that this component will receive an
  43.   // opRemove when Value is either removed from its owner or when it is
  44.   // destroyed.
  45.  
  46.   Value->FreeNotification(Value);
  47. }
  48.  
  49. void __fastcall    TDemoLabel::Paint()
  50. {
  51.   TRect    Rect = ClientRect;
  52.   Canvas->Font = Font;
  53.   Canvas->Brush->Color = Color;
  54.   Canvas->FillRect(Rect);
  55.   DrawText(Canvas->Handle, Caption.c_str(), Caption.Length(), &RECT(Rect),
  56.     DT_EXPANDTABS | DT_WORDBREAK | DT_LEFT);
  57. }
  58.  
  59. void __fastcall    TDemoLabel::CMDialogChar(TCMDialogKey &Message)
  60. {
  61.   if (FFocusControl != NULL &&
  62.       Enabled == true &&
  63.       IsAccel(Message.CharCode, Caption))
  64.       if (FFocusControl->CanFocus()){
  65.         FFocusControl->SetFocus();
  66.         Message.Result = 1;
  67.       }
  68. }
  69.  
  70. void __fastcall    TDemoLabel::CMTextChanged(TMessage &Message)
  71. {
  72.   Invalidate();
  73. }
  74.  
  75.  
  76.