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

  1. //---------------------------------------------------------------------------
  2. // Borland C++Builder
  3. // Copyright (c) 1987, 1998 Borland International Inc.  All Rights Reserved.
  4. //---------------------------------------------------------------------------
  5. #pragma hdrstop   
  6. #include <SysUtils.hpp>
  7. #include <memory>          //For use of auto_ptr
  8. #include  "piereg.h"
  9. #include "pies.cpp"
  10. #include "samp.h"
  11.  
  12. #pragma resource "*.dfm"
  13. #pragma resource "*.res"    
  14. #pragma package(smart_init)
  15.  
  16. //---------------------------------------------------------------------------
  17. namespace Pies{
  18. void __fastcall PACKAGE Register()
  19. {
  20.   TComponentClass classes[1] = {__classid(TPie)};
  21.   RegisterComponents(LoadStr(Tab_101), classes, 0);
  22.   RegisterComponentEditor(__classid(TPie), __classid(TPieEditor));
  23.   RegisterPropertyEditor(__typeinfo(TAngles),
  24.                          NULL,
  25.                          "",
  26.                          __classid(TAnglesProperty));
  27. }
  28. } //namespace
  29.  
  30. //---------------------------------------------------------------------------
  31. // TAngleEditorDlg
  32.  
  33. __fastcall TAngleEditorDlg::TAngleEditorDlg(TComponent* AOwner) : TForm(AOwner) { }
  34. __fastcall TAngleEditorDlg::TAngleEditorDlg(TComponent* AOwner, int Dummy) : TForm(AOwner, Dummy) { }
  35. __fastcall TAngleEditorDlg::TAngleEditorDlg(HWND ParentWindow) : TForm(ParentWindow) { }
  36. __fastcall TAngleEditorDlg::~TAngleEditorDlg(void) { }
  37.  
  38. void __fastcall TAngleEditorDlg::STrackBarChange(TObject* /*Sender*/)
  39. {
  40.   SetStartAngle(STrackBar->Position);
  41. }
  42.  
  43. void __fastcall TAngleEditorDlg::ETrackBarChange(TObject* /*Sender*/)
  44. {
  45.   SetEndAngle(ETrackBar->Position);
  46. }
  47.  
  48. void __fastcall TAngleEditorDlg::SetStartAngle(Integer Value)
  49. {
  50.   STrackBar->Position = Value;
  51.   SAngleLabel->Caption = LoadStr(StartAngle_RC) + String(Value);
  52.   FAngles->StartAngle = Value;
  53. }
  54.  
  55. void __fastcall TAngleEditorDlg::SetEndAngle(Integer Value)
  56. {
  57.   ETrackBar->Position = Value;
  58.   EAngleLabel->Caption = LoadStr(EndAngle_RC) + String(Value);
  59.   FAngles->EndAngle = Value;
  60. }
  61.  
  62. void __fastcall TAngleEditorDlg::SetAngles(TAngles* Value)
  63. {
  64.   FAngles = Value;
  65.   FOrigStart = Value->StartAngle;
  66.   FOrigEnd = Value->EndAngle;
  67.   SetStartAngle(Value->StartAngle);
  68.   SetEndAngle(Value->EndAngle);
  69. }
  70.  
  71. void __fastcall TAngleEditorDlg::CancelClick(TObject* /*Sender*/)
  72. {
  73.   SetStartAngle(FOrigStart);
  74.   SetEndAngle(FOrigEnd);
  75. }
  76.  
  77. //---------------------------------------------------------------------------
  78. // TAnglesProperty
  79.  
  80. __fastcall TAnglesProperty::TAnglesProperty(void) : TClassProperty() { }
  81. __fastcall TAnglesProperty::~TAnglesProperty(void) { }
  82.  
  83. void __fastcall TAnglesProperty::Edit()
  84. {
  85.   //We use the auto_ptr so that the object is destroyed automatically
  86.   //on exit of the function.
  87.   //  std::auto_ptr<TAngles> Angles(new TAngles());
  88.   std::auto_ptr<TAngleEditorDlg> AngleEditor(new TAngleEditorDlg(Application));
  89.  
  90.   AngleEditor->EditorAngles = (TAngles*)GetOrdValue();
  91.   AngleEditor->ShowModal();
  92. }
  93.  
  94. TPropertyAttributes __fastcall TAnglesProperty::GetAttributes()
  95. {
  96.   return (TPropertyAttributes() << paDialog << paSubProperties);
  97. }
  98.  
  99. //---------------------------------------------------------------------------
  100. //TPieEditor
  101. __fastcall TPieEditor::TPieEditor(TComponent* AComponent, TFormDesigner* ADesigner)
  102.                       : TDefaultEditor(AComponent, ADesigner) { }
  103. __fastcall TPieEditor::~TPieEditor(void) { }
  104.  
  105. void __fastcall TPieEditor::EditProperty(TPropertyEditor* PropertyEditor,
  106.                                          bool& Continue,
  107.                                          bool& /*FreeEditor*/)
  108. {
  109.   String PropName(PropertyEditor->GetName());
  110.   if (strcmpi(PropName.c_str(),"ANGLES") == 0){
  111.     PropertyEditor->Edit();
  112.     Continue = false;
  113.   }
  114. }
  115.  
  116. int __fastcall TPieEditor::GetVerbCount()
  117. {
  118.   return 1;
  119. }
  120.  
  121. String __fastcall TPieEditor::GetVerb(Integer Index)
  122. {
  123.   if (Index == 0)
  124.     return  LoadStr(EditAngle_RC);
  125.   else return "";
  126. }
  127.  
  128. void __fastcall TPieEditor::ExecuteVerb(Integer Index)
  129. {
  130.   if (Index == 0) Edit();
  131. }
  132. //---------------------------------------------------------------------------
  133.