home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bc45 / autocalc.pak / AUTOCALC.H < prev    next >
C/C++ Source or Header  |  1997-07-23  |  5KB  |  141 lines

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