home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 May / Chip_2002-05_cd1.bin / chplus / cpp / 5 / Komponety.exe / demolbl.cpp < prev    next >
C/C++ Source or Header  |  1998-02-09  |  2KB  |  79 lines

  1. //---------------------------------------------------------------------------
  2. // Borland C++Builder
  3. // Copyright (c) 1987, 1998 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 "source\demolbl.h"
  13. #endif
  14.  
  15. #pragma resource "*.res"   //IDE links .res automatically for components
  16. #pragma package(smart_init)
  17.  
  18. namespace Demolbl{
  19. void __fastcall PACKAGE Register()
  20. {
  21.   TComponentClass classes[1] = {__classid(TDemoLabel)};
  22.   RegisterComponents("Samples", classes, 0);
  23. }
  24. } //end namespace
  25.  
  26. __fastcall TDemoLabel::TDemoLabel(TComponent *AOwner):
  27.     TGraphicControl(AOwner)
  28. {
  29.   FComponentStyle >> csInheritable;
  30.   Width=64;
  31.   Height=13;
  32. }
  33.  
  34. void __fastcall    TDemoLabel::Notification(TComponent *AComponent, TOperation Operation)
  35. {
  36.   TGraphicControl::Notification(AComponent, Operation);
  37.   if ((Operation == opRemove)  && (AComponent == FFocusControl))
  38.     FFocusControl = 0;
  39. }
  40.  
  41. void __fastcall    TDemoLabel::SetFocusControl(TWinControl *Value)
  42. {
  43.   FFocusControl = Value;
  44.  
  45.   // Calling FreeNotification ensures that this component will receive an
  46.   // opRemove when Value is either removed from its owner or when it is
  47.   // destroyed.
  48.  
  49.   Value->FreeNotification(Value);
  50. }
  51.  
  52. void __fastcall    TDemoLabel::Paint()
  53. {
  54.   TRect    Rect = ClientRect;
  55.   Canvas->Font = Font;
  56.   Canvas->Brush->Color = Color;
  57.   Canvas->FillRect(Rect);
  58.   DrawText(Canvas->Handle, Caption.c_str(), Caption.Length(), &RECT(Rect),
  59.     DT_EXPANDTABS | DT_WORDBREAK | DT_LEFT);
  60. }
  61.  
  62. void __fastcall    TDemoLabel::CMDialogChar(TCMDialogKey &Message)
  63. {
  64.   if (FFocusControl != NULL &&
  65.       Enabled == true &&
  66.       IsAccel(Message.CharCode, Caption))
  67.       if (FFocusControl->CanFocus()){
  68.         FFocusControl->SetFocus();
  69.         Message.Result = 1;
  70.       }
  71. }
  72.  
  73. void __fastcall    TDemoLabel::CMTextChanged(TMessage &Message)
  74. {
  75.   Invalidate();
  76. }
  77.  
  78.  
  79.