home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / yacl-012.zip / ui / pushbtn.cxx < prev    next >
C/C++ Source or Header  |  1995-04-04  |  4KB  |  178 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6. /*
  7.  *
  8.  *          Copyright (C) 1994, M. A. Sridhar
  9.  *  
  10.  *
  11.  *     This software is Copyright M. A. Sridhar, 1994. You are free
  12.  *     to copy, modify or distribute this software  as you see fit,
  13.  *     and to use  it  for  any  purpose, provided   this copyright
  14.  *     notice and the following   disclaimer are included  with all
  15.  *     copies.
  16.  *
  17.  *                        DISCLAIMER
  18.  *
  19.  *     The author makes no warranties, either expressed or implied,
  20.  *     with respect  to  this  software, its  quality, performance,
  21.  *     merchantability, or fitness for any particular purpose. This
  22.  *     software is distributed  AS IS.  The  user of this  software
  23.  *     assumes all risks  as to its quality  and performance. In no
  24.  *     event shall the author be liable for any direct, indirect or
  25.  *     consequential damages, even if the  author has been  advised
  26.  *     as to the possibility of such damages.
  27.  *
  28.  */
  29.  
  30.  
  31.  
  32.  
  33. #if defined(__GNUC__)
  34. #pragma implementation
  35. #endif
  36.  
  37.  
  38.  
  39. #include "ui/pushbtn.h"
  40. #include "ui/cntroler.h"
  41.  
  42. #if defined (__MS_WINDOWS__)
  43.  
  44. #include <windows.h>
  45. #define PUSH_BUTTON_STYLE  \
  46.     BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP
  47.  
  48. #elif defined (__X_MOTIF__)
  49. #include <X11/Intrinsic.h>
  50. #include <Xm/PushB.h>
  51. #include <Xm/PushBG.h>
  52.  
  53. #elif defined (__OS2__)
  54. #define PUSH_BUTTON_STYLE BS_PUSHBUTTON |  WS_VISIBLE
  55. #endif
  56.  
  57. UI_PushButton::UI_PushButton (UI_CompositeVObject* parent,
  58.                               const UI_Rectangle& shape,
  59.                               UI_ViewID id)
  60. : UI_SimpleVObject (parent, shape, id
  61. #if defined(__MS_WINDOWS__)
  62.                     , PUSH_BUTTON_STYLE
  63. #endif
  64.              )
  65. {
  66.     _model = &_title;       // Dirty little trick to share the same string
  67.     _ownModel = FALSE;      // between model and title
  68. #if defined(__OS2__)
  69.     _style = PUSH_BUTTON_STYLE;
  70. #endif
  71. }
  72.  
  73.  
  74.  
  75. #if defined(__MS_WINDOWS__)
  76. UI_PushButton::UI_PushButton (UI_CompositeVObject* parent,
  77.                               UI_ViewID id, UI_ViewHandle h)
  78. : UI_SimpleVObject (parent, id, h)
  79. {
  80.     _model = &_title;       // Dirty little trick to share the same string
  81.     _ownModel = FALSE;     // between model and title
  82. }
  83. #endif
  84.  
  85.  
  86.  
  87. UI_WindowClass UI_PushButton::WindowClass () const
  88. {
  89. #if defined(__MS_WINDOWS__)
  90.     return "button";
  91. #elif defined(__X_MOTIF__)
  92.     return xmPushButtonWidgetClass;
  93. #elif defined(__OS2__)
  94.     return WC_BUTTON;
  95. #endif
  96. }
  97.  
  98.  
  99. #if defined(__X_MOTIF__)
  100. void UI_PushButton::SelectionCallback (Widget w, void* client,
  101.                                        void* call)
  102. {
  103.     UI_PushButton* btn = (UI_PushButton *) client;
  104.     XmPushButtonCallbackStruct* cb = (XmPushButtonCallbackStruct*) call;
  105.     if (cb->reason == XmCR_ACTIVATE) {
  106.         UI_EventType typ = (cb->click_count == 1)
  107.             ? Event_Select : Event_LButtonDblClk;
  108.         _Controller->AddEvent (new UI_Event (typ, btn, btn));
  109.     }
  110. }
  111.  
  112. #endif
  113.  
  114.  
  115.  
  116. //
  117. //----------------- Inherited methods ---------------------------
  118. //
  119.  
  120. bool UI_PushButton::Select ()
  121. {
  122.     return FALSE;
  123. }
  124.  
  125.  
  126. bool UI_PushButton::_ModelChanged (CL_Object&, long)
  127. {
  128. #if defined(__MS_WINDOWS__)
  129.     if (_handle > 0)
  130.         SendMessage (_handle, WM_SETTEXT, 0, (long)(const char*)_title); 
  131.  
  132. #elif defined(__X_MOTIF__)
  133.  
  134.     if (!_xwidget)
  135.         return TRUE;
  136.     Arg arg [2];
  137.     short argn = 0;
  138.  
  139.     XmString label;
  140.  
  141.     label = XmStringCreate ((char *) ( (CL_String *)_model )->AsPtr (), 
  142.                             XmSTRING_DEFAULT_CHARSET 
  143.                             );    
  144.     
  145.     XtSetArg (arg [argn], XmNlabelString, label); argn++;
  146.     XtSetValues (_xwidget, arg, argn);
  147.  
  148.     XmUpdateDisplay (_xwidget);
  149.     XmStringFree (label);
  150. #endif
  151.  
  152.     return TRUE;
  153. }
  154.  
  155.  
  156.  
  157. #if defined(__X_MOTIF__)
  158. void UI_PushButton::_SetupStyle (void* p, short& argn)
  159. {
  160.     Arg* arg = (Arg*) p;
  161.     UI_SimpleVObject::_SetupStyle (arg, argn);
  162.     // Add another resource spec:
  163.     XtSetArg (arg [argn], XmNrecomputeSize, FALSE); argn++;
  164. }
  165. #endif
  166.  
  167.  
  168. bool UI_PushButton::MakeVisualElement ()
  169. {
  170.     bool b = UI_SimpleVObject::MakeVisualElement ();
  171. #if defined(__X_MOTIF__)
  172.     XtAddCallback (_xwidget, XmNactivateCallback, 
  173.                    &UI_PushButton::SelectionCallback, (XtPointer) this);
  174. #endif
  175.     return b;
  176. }
  177.  
  178.