home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / AUTOCALC.PAK / AUTOCALC.H < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  4.5 KB  |  139 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectComponents - (C) Copyright 1994, 1996 by Borland International
  3. //----------------------------------------------------------------------------
  4. #include <ocf/automacr.h>
  5. #include "autocalc.rh"
  6.  
  7. class TUpdate : public TAutoProxy {
  8.   public:
  9.     TUpdate() : TAutoProxy(0x409) {}
  10.     void SetResult(long);
  11. };
  12.  
  13. class TCalcButton : public TAutoBase {
  14.   public:
  15.     TCalcButton(HWND hWnd) : HWnd(hWnd) {}
  16.     HWND HWnd;
  17.     bool GetPush() {return (::SendMessage(HWnd, BM_GETSTATE, 0, 0) & 4) != 0;}
  18.     void SetPush(bool state) {::SendMessage(HWnd, BM_SETSTATE, state, 0);}
  19.     void  SetText(char* text) {::SetWindowText(HWnd, text);}
  20.     char* GetText(){static char b[21]; return ::GetWindowText(HWnd,b,20)? b:0;}
  21.  
  22.   DECLARE_AUTOCLASS(TCalcButton)
  23.     AUTOPROP  (Push, GetPush, SetPush, bool,)
  24.     AUTOPROP  (Text, GetText, SetText, TAutoString,)
  25. };
  26.  
  27. class TCalcWindow;
  28.  
  29. class TCalcButtons {    // class used only to temporarily expose collection
  30.   public:
  31.     TCalcButtons(HWND window) : HWnd(window) {}
  32.     short GetCount() { return IDC_LASTID - IDC_FIRSTID; }
  33.     HWND GetButton(short i) {return ::GetDlgItem(HWnd, i + IDC_FIRSTID+1);}
  34.     HWND HWnd;
  35.  
  36.   DECLARE_AUTOCLASS(TCalcButtons)
  37.     AUTOFUNC0 (Count, GetCount, short,)
  38.     AUTOFUNC1 (Item,  GetButton, TAutoObjectByVal<TCalcButton>, short,
  39.                           AUTOVALIDATE(Arg1 >= 0 && Arg1 < This->GetCount()) )
  40.     AUTOITERATOR(int Id, Id = IDC_FIRSTID+1, Id <= IDC_LASTID, Id++,
  41.                  TAutoObjectByVal<TCalcButton>(::GetDlgItem(This->HWnd,Id)))
  42. };
  43.  
  44. class TCalcWindow : public TAutoBase {
  45.   public:
  46.     TCalcWindow() : hWnd(0), Background(0) {}
  47.    ~TCalcWindow() { if (hWnd) ::DestroyWindow(hWnd); }
  48.     operator bool() {return hWnd != 0;}
  49.     operator HWND() {return hWnd;}
  50.  
  51.     void  SetCaption(const char far* text);
  52.     const char* GetCaption();
  53.     int GetWidth();
  54.     void SetWidth(int);
  55.     int GetHeight();
  56.     void SetHeight(int);
  57.     unsigned long GetBackground() { return Background; }
  58.     void SetBackground(long color);
  59.  
  60.     long Background;
  61.     HWND  hWnd;
  62.  
  63.   DECLARE_AUTOCLASS(TCalcWindow)
  64.     AUTOPROP  (Caption,    GetCaption,SetCaption, TAutoString,)
  65.     AUTOPROP  (Height,     GetHeight,SetHeight,   int,)
  66.     AUTOPROP  (Width,      GetWidth,SetWidth,     int,)
  67.     AUTOPROP  (Background, GetBackground,SetBackground, unsigned long,)
  68.     AUTODATARO(Buttons,    hWnd,   TAutoObjectByVal<TCalcButtons>,)
  69. };
  70.  
  71. enum operators {
  72.   OP_NONE = 0,
  73.   OP_PLUS,
  74.   OP_MINUS,
  75.   OP_MULT,
  76.   OP_DIV,
  77.   OP_EQUALS,
  78.   OP_CLEAR,
  79. };
  80.  
  81. #define COUNT 10
  82.  
  83. class TMyArray {    // class used only to temporarily expose collection
  84.   public:
  85.     TMyArray(short* array) : Array(array) {}
  86.     short* Array;
  87.     long GetCount() {return COUNT;}
  88.     short GetItem(short index) {return Array[index];}
  89.  
  90.   DECLARE_AUTOCLASS(TMyArray)
  91.     AUTOFUNC0 (Count, GetCount, long,)
  92.     AUTOFUNC1 (Item,  GetItem,  short, short,AUTOVALIDATE(Arg1>=0 && Arg1<COUNT))
  93.     AUTOITERATOR(int Index, Index=0, Index<COUNT, Index++, (This->Array)[Index])
  94. };
  95.  
  96. class TCalc : public TAutoBase {
  97.   public:
  98.     TCalc(HINSTANCE hInst, uint32 options);
  99.     void Closed() {Window.hWnd = 0;}
  100.  
  101.     // automated methods and properties
  102.     bool  GetVisible();
  103.     void  SetVisible(bool show);
  104.     bool  Eval();
  105.     void  Clear();
  106.     void  Display();
  107.     bool  Button(const char far* button);
  108.     TCalcWindow& GetWindow() { return Window; }
  109.     long  LookAtWindow(const TCalcWindow& wnd) {return wnd.Background;}
  110.  
  111.     int ButtonPush(int button);  // not exposed via automation
  112.     uint32 Options;
  113.  
  114.   private:
  115.     TUpdate Update;  // callback to controller
  116.     TCalcWindow Window;
  117.     bool  Entry;
  118.  
  119.     // automated data members
  120.     short Op;
  121.     long  Opnd;
  122.     long  Accum;
  123.     short Elem[COUNT];
  124.  
  125.   DECLARE_AUTOCLASS(TCalc)
  126.     AUTODATA  (Accum,   Accum,     long,  )
  127.     AUTODATA  (Opnd,    Opnd,      long,  )
  128.     AUTODATA  (Op,      Op, short, AUTOVALIDATE(Val>=OP_NONE && Val<=OP_CLEAR))
  129.     AUTOFUNC0 (Eval,    Eval,      bool, )
  130.     AUTOFUNC0V(Clear,   Clear,            )
  131.     AUTOFUNC0V(Display, Display,          )
  132.     AUTOFUNC1 (Button,  Button,    bool, TAutoString,)
  133.     AUTOPROPRO(Window,  GetWindow, TAutoObject<TCalcWindow>,  )
  134.     AUTOFUNC1 (LookAt,  LookAtWindow, long, TAutoObject<const TCalcWindow>,)
  135.     AUTODATARO(MyArray, Elem,      TAutoObjectByVal<TMyArray>,)
  136.     AUTOPROXY (Update,  Update, )
  137.     AUTOPROP  (Visible, GetVisible, SetVisible, bool,)
  138. };
  139.