home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 February / PCWK0296.iso / po7_win / object10 / oowl.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-21  |  10.2 KB  |  461 lines

  1. /* Copyright (c) Oracle Corporation 1994.  All Rights Reserved */
  2.  
  3. /*
  4.     This source code is provided as a debugging aid for developers
  5.     who have purchased Oracle Objects for OLE    .  Please see the
  6.     provided help file for documentation of these classes.
  7.  
  8. */
  9.  
  10. /*
  11.     Oracle Objects for OLE    
  12.     C++ classes for bound Widget support
  13.     MFC version
  14.                            
  15.     CREATED    ********   11/22/94
  16.  
  17. */
  18.  
  19. #ifndef OOWL_ORACLE
  20. #include "oowl.h"
  21. #endif
  22.  
  23. // ---------------------------------------
  24. // OBoundEdit member functions
  25.  
  26. DEFINE_RESPONSE_TABLE1(OBoundEdit, TEdit)
  27.   EV_WM_KEYDOWN,
  28. END_RESPONSE_TABLE;
  29.  
  30. OBoundEdit::OBoundEdit(TWindow* parent, int Id, const char far* text, int x, int y, int w,
  31.                  int h, UINT textLen, BOOL multiline, TModule* module)
  32. :TEdit(parent, Id, text, x, y, w, h, textLen, multiline, module)
  33. {
  34.     m_mode = OBOUND_READWRITE;
  35. }
  36.  
  37. OBoundEdit::OBoundEdit(TWindow* parent, int resourceID, UINT textLen, TModule* module)
  38. : TEdit(parent, resourceID, textLen, module)
  39. {
  40.     m_mode = OBOUND_READWRITE;
  41. }
  42.  
  43. OBoundEdit::~OBoundEdit()
  44. {
  45. }
  46.  
  47. oresult OBoundEdit::SetProperty(BOOL mode)
  48. {
  49.     m_mode = mode;
  50.     SetReadOnly(m_mode==OBOUND_READONLY);
  51.  
  52.     return (OSUCCESS);
  53. }
  54.  
  55. void OBoundEdit::EvKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  56. {
  57.     if (m_mode==OBOUND_READWRITE)
  58.         Changed();  // remember that there's been a change
  59.     TEdit::EvKeyDown(nChar, nRepCnt, nFlags);
  60. }
  61.  
  62. oresult OBoundEdit::Refresh(const OValue &val)
  63. {
  64.      // change text in textedit
  65.      const char *cp = (const char *) val;
  66.      SetText(cp);
  67.  
  68.      return(OSUCCESS);
  69. }
  70.  
  71. oresult OBoundEdit::SaveChange(void)
  72. {
  73.     // get the value from the text
  74.     int length = GetTextLen();
  75.     char *temps = new char[length+1];
  76.     GetText(temps, length+1);
  77.     OValue val = temps;
  78.     delete temps;
  79.     
  80.     oresult ores = SetValue(val);
  81.     
  82.     if (ores == OSUCCESS) 
  83.         Changed(FALSE);
  84.      
  85.     return(ores);
  86. }
  87.  
  88. // ---------------------------------------
  89. // OBoundStatic member functions
  90.  
  91. DEFINE_RESPONSE_TABLE1(OBoundStatic, TStatic)
  92. END_RESPONSE_TABLE;
  93.  
  94. OBoundStatic::OBoundStatic(TWindow* parent, int Id, const char far* title, int x, int y, int w,
  95.                  int h, UINT textLen, TModule* module)
  96. :TStatic(parent, Id, title, x, y, w, h, textLen, module)
  97. {
  98. }
  99.  
  100. OBoundStatic::OBoundStatic(TWindow* parent, int resourceID, UINT textLen, TModule* module)
  101. : TStatic(parent, resourceID, textLen, module)
  102. {
  103. }
  104.  
  105. OBoundStatic::~OBoundStatic()
  106. {
  107. }
  108.  
  109. oresult OBoundStatic::Refresh(const OValue &val)
  110. {
  111.      // change text in textedit
  112.      const char *cp = (const char *) val;
  113.      SetText(cp);
  114.  
  115.      return(OSUCCESS);
  116. }
  117.  
  118. // ---------------------------------------
  119. // OBoundCheckBox member functions
  120.  
  121. DEFINE_RESPONSE_TABLE1(OBoundCheckBox, TCheckBox)
  122.   EV_WM_LBUTTONUP,
  123.   EV_WM_KEYDOWN,
  124. END_RESPONSE_TABLE;
  125.  
  126. OBoundCheckBox::OBoundCheckBox(TWindow* parent, int Id, const char far* title, int x, int y, int w,
  127.                  int h, TGroupBox *group, TModule* module)
  128. :TCheckBox(parent, Id, title, x, y, w, h, group, module)
  129. {
  130.     m_onvalue.Clear();
  131.     m_offvalue.Clear();
  132.     m_curvalue.Clear();
  133.     m_tristate = FALSE;
  134.     m_mode = OBOUND_READWRITE;
  135. }
  136.  
  137. OBoundCheckBox::OBoundCheckBox(TWindow* parent, int resourceID, TGroupBox *group, TModule* module)
  138. : TCheckBox(parent, resourceID, group, module)
  139. {
  140.     m_onvalue.Clear();
  141.     m_offvalue.Clear();
  142.     m_curvalue.Clear();
  143.     m_tristate = FALSE;
  144.     m_mode = OBOUND_READWRITE;
  145. }                                            
  146.  
  147. OBoundCheckBox::~OBoundCheckBox()
  148. {
  149. }
  150.  
  151. oresult OBoundCheckBox::Refresh(const OValue &val)
  152. {
  153.      m_curvalue.Clear();          
  154.      int check;
  155.      if (val==m_onvalue)
  156.         check = 1;
  157.      else if (val==m_offvalue)
  158.         check = 0;
  159.      else     
  160.      {
  161.         check = (m_tristate) ? 2 : 0;
  162.         m_curvalue = val;
  163.      }
  164.      
  165.      SetCheck(check);
  166.  
  167.      return(OSUCCESS);
  168. }
  169.  
  170. oresult OBoundCheckBox::SaveChange(void)
  171. {
  172.     int check = GetCheck();
  173.     oresult ores;
  174.     
  175.     if (check == 0)
  176.         ores = SetValue(m_offvalue);
  177.     else if (check == 1)
  178.         ores = SetValue(m_onvalue);
  179.     else
  180.         ores = SetValue(m_curvalue);
  181.      
  182.     if (ores == OSUCCESS) 
  183.         Changed(FALSE);
  184.  
  185.     return(ores);
  186. }
  187.  
  188. void OBoundCheckBox::EvLButtonUp(UINT modKeys, TPoint& point) 
  189. {
  190.      if (m_mode==OBOUND_READWRITE)
  191.          Changed();
  192.      TCheckBox::EvLButtonUp(modKeys, point);
  193. }
  194.  
  195. void OBoundCheckBox::EvKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  196. {
  197.     if (m_mode==OBOUND_READWRITE && nChar==VK_SPACE)
  198.         Changed();  // remember that there's been a change
  199.     TCheckBox::EvKeyDown(nChar, nRepCnt, nFlags);
  200. }
  201.  
  202. oresult OBoundCheckBox::SetProperty(const OValue &onvalue, const OValue &offvalue, BOOL mode)
  203. {
  204.     m_mode = mode;
  205.     m_onvalue = onvalue;
  206.     m_offvalue = offvalue;
  207.     long style = GetWindowLong(GWL_STYLE)&0x0000000F;
  208.     if ((style==BS_3STATE) || (style==BS_AUTO3STATE))
  209.          m_tristate = TRUE;
  210.     else m_tristate = FALSE;
  211.  
  212.     if (m_mode==OBOUND_READONLY)
  213.     {
  214.         if (m_tristate)
  215.             SetStyle((UINT)BS_3STATE, TRUE);
  216.         else 
  217.             SetStyle((UINT)BS_CHECKBOX, TRUE);
  218.     }
  219.     else 
  220.     {  
  221.         if (m_tristate)
  222.             SetStyle((UINT)BS_AUTO3STATE, TRUE);
  223.         else
  224.             SetStyle((UINT)BS_AUTOCHECKBOX, TRUE);
  225.     }
  226.  
  227.     return (OSUCCESS);
  228. }
  229.  
  230. // ---------------------------------------
  231. // OBoundRadioButton member functions
  232.  
  233. DEFINE_RESPONSE_TABLE1(OBoundRadioButton, TRadioButton)
  234.   EV_WM_LBUTTONUP,
  235.   EV_WM_KEYDOWN,
  236. END_RESPONSE_TABLE;
  237.  
  238. OBoundRadioButton::OBoundRadioButton(TWindow* parent, int Id, const char far* title, int x, int y, int w,
  239.                  int h, TGroupBox *group, TModule* module)
  240. :TRadioButton(parent, Id, title, x, y, w, h, group, module)
  241. {
  242.     m_value.Clear();
  243.     m_mode = OBOUND_READWRITE;
  244. }
  245.  
  246. OBoundRadioButton::OBoundRadioButton(TWindow* parent, int resourceID, TGroupBox *group, TModule* module)
  247. : TRadioButton(parent, resourceID, group, module)
  248. {
  249.     m_value.Clear();
  250.     m_mode = OBOUND_READWRITE;
  251. }                                            
  252.  
  253. OBoundRadioButton::~OBoundRadioButton()
  254. {
  255. }
  256.  
  257. oresult OBoundRadioButton::Refresh(const OValue &val)
  258. {
  259.      if (val==m_value)
  260.         SetCheck(BF_CHECKED);
  261.     else 
  262.         SetCheck(BF_UNCHECKED);
  263.      return(OSUCCESS);
  264. }
  265.  
  266. oresult OBoundRadioButton::SaveChange(void)
  267. {
  268.     int check = GetCheck();
  269.     oresult ores = OSUCCESS;
  270.     if (check == 1)
  271.     {
  272.         ores = SetValue(m_value);
  273.         if (ores == OSUCCESS) 
  274.             Changed(FALSE);
  275.     }
  276.     
  277.     return(ores);
  278. }
  279.  
  280. void OBoundRadioButton::EvLButtonUp(UINT modKeys, TPoint& point) 
  281. {
  282.     int check = GetCheck();                  // for most cases, even for keystrokes
  283.     TRadioButton::EvLButtonUp(modKeys, point);
  284.     if ((m_mode == OBOUND_READWRITE) &&      // double protection and speeds up 
  285.          (GetCheck() != check))
  286.         Changed();
  287. }
  288.  
  289. void OBoundRadioButton::EvKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  290. {
  291.     int check = GetCheck();                   
  292.     TRadioButton::EvKeyDown(nChar, nRepCnt, nFlags); 
  293.     if ((m_mode == OBOUND_READWRITE) &&      // double protection and speeds up
  294.          (GetCheck() != check))
  295.         Changed();
  296. }
  297.  
  298. oresult OBoundRadioButton::SetProperty(const OValue &value, BOOL mode)
  299. {
  300.     m_mode = mode;
  301.     m_value = value;
  302.  
  303.     if (m_mode==OBOUND_READONLY)
  304.         SetStyle((UINT)BS_RADIOBUTTON, TRUE);
  305.     else 
  306.         SetStyle((UINT)BS_AUTORADIOBUTTON, TRUE);
  307.  
  308.     return (OSUCCESS);
  309. }
  310.  
  311. // ---------------------------------------
  312. // OBoundHSlider member functions
  313.  
  314. DEFINE_RESPONSE_TABLE1(OBoundHSlider, THSlider)
  315.   EV_WM_HSCROLL,
  316. END_RESPONSE_TABLE;
  317.  
  318. OBoundHSlider::OBoundHSlider(TWindow* parent, int Id, int x, int y, int w,
  319.                  int h, TResId thumbResId, TModule* module)
  320. :THSlider(parent, Id, x, y, w, h, thumbResId, module)
  321. {
  322.     m_mode = OBOUND_READWRITE;
  323. }
  324.  
  325. OBoundHSlider::~OBoundHSlider()
  326. {
  327. }
  328.  
  329. oresult OBoundHSlider::Refresh(const OValue &val)
  330. {
  331.      SetPosition((int)val);
  332.  
  333.      return(OSUCCESS);
  334. }
  335.  
  336. oresult OBoundHSlider::SaveChange(void)
  337. {
  338.     oresult ores = OSUCCESS;
  339.     
  340.     if (m_mode == OBOUND_READWRITE)
  341.     {
  342.         OValue val = GetPosition();
  343.         ores = SetValue(val);           
  344.         if (ores == OSUCCESS) 
  345.             Changed(FALSE);
  346.     }   
  347.     
  348.     return(ores);
  349. }
  350.  
  351. void OBoundHSlider::EvHScroll(UINT scrollCode, UINT thumbPos, HWND hWndCtl)
  352. {
  353.     if (m_mode==OBOUND_READWRITE)
  354.     {
  355.         Changed();  // remember that there's been a change
  356.         THSlider::EvHScroll(scrollCode, thumbPos, hWndCtl);
  357.     }
  358. }
  359.  
  360. oresult OBoundHSlider::SetProperty(const OValue &min, const OValue &max, BOOL mode)
  361. {
  362.     m_mode = mode;
  363.     SetRange((int)min, (int)max);
  364.     
  365.     return (OSUCCESS);
  366. }
  367.  
  368. // ---------------------------------------
  369. // OBoundVSlider member functions
  370.  
  371. DEFINE_RESPONSE_TABLE1(OBoundVSlider, TVSlider)
  372.   EV_WM_VSCROLL,
  373. END_RESPONSE_TABLE;
  374.  
  375. OBoundVSlider::OBoundVSlider(TWindow* parent, int Id, int x, int y, int w,
  376.                  int h, TResId thumbResId, TModule* module)
  377. :TVSlider(parent, Id, x, y, w, h, thumbResId, module)
  378. {
  379.     m_mode = OBOUND_READWRITE;
  380. }
  381.  
  382. OBoundVSlider::~OBoundVSlider()
  383. {
  384. }
  385.  
  386. oresult OBoundVSlider::Refresh(const OValue &val)
  387. {
  388.      SetPosition((int)val);
  389.  
  390.      return(OSUCCESS);
  391. }
  392.  
  393. oresult OBoundVSlider::SaveChange(void)
  394. {
  395.     oresult ores = OSUCCESS;
  396.     
  397.     if (m_mode == OBOUND_READWRITE)
  398.     {
  399.         OValue val = GetPosition();
  400.         ores = SetValue(val);           
  401.         if (ores == OSUCCESS) 
  402.             Changed(FALSE);
  403.     }   
  404.     
  405.     return(ores);
  406. }
  407.  
  408. void OBoundVSlider::EvVScroll(UINT scrollCode, UINT thumbPos, HWND hWndCtl)
  409. {
  410.     if (m_mode==OBOUND_READWRITE)
  411.     {
  412.         Changed();  // remember that there's been a change
  413.         TVSlider::EvVScroll(scrollCode, thumbPos, hWndCtl);
  414.     }
  415. }
  416.  
  417. oresult OBoundVSlider::SetProperty(const OValue &min, const OValue &max, BOOL mode)
  418. {
  419.     m_mode = mode;
  420.     SetRange((int)min, (int)max);
  421.     
  422.     return (OSUCCESS);
  423. }
  424.  
  425. // ---------------------------------------
  426. // OBoundGauge member functions
  427.  
  428. DEFINE_RESPONSE_TABLE1(OBoundGauge, TGauge)
  429. END_RESPONSE_TABLE;
  430.  
  431. OBoundGauge::OBoundGauge(TWindow* parent, const char far* title,int Id, int x, int y, int w,
  432.                  int h,BOOL isHorizontal, int margin, TModule* module)
  433. :TGauge(parent, title, Id, x, y, w, h, isHorizontal, margin, module)
  434. {
  435. }
  436.  
  437. OBoundGauge::~OBoundGauge()
  438. {
  439. }
  440.  
  441. oresult OBoundGauge::Refresh(const OValue &val)
  442. {
  443.     int current = (int)val;
  444.     int min, max;
  445.     GetRange(min, max);
  446.     if (current<min) current = min;
  447.     if (current>max) current = max;
  448.     TGauge::SetValue(current);
  449.  
  450.     return(OSUCCESS);
  451. }
  452.  
  453. oresult OBoundGauge::SetProperty(const OValue &min, const OValue &max)
  454. {
  455.     SetRange((int)min, (int)max);
  456.     
  457.     return (OSUCCESS);
  458. }
  459.  
  460.  
  461.