home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 May / Pcwk5b98.iso / Borland / Cplus45 / BC45 / OWL1.PAK / CONTROL.CPP < prev    next >
Text File  |  1995-08-29  |  3KB  |  98 lines

  1. // ObjectWindows - (C) Copyright 1992 by Borland International
  2.  
  3. /* --------------------------------------------------------
  4.   CONTROL.CPP
  5.   Defines type TControl.  This defines the basic behavior
  6.   of all controls.
  7.   -------------------------------------------------------- */
  8.  
  9. #include "control.h"
  10. #include <alloc.h>   // for farfree
  11.  
  12. /* Constructor for a TControl.  Sets creation attributes using
  13.    the parameters passed and default values. */
  14. TControl::TControl(PTWindowsObject AParent, int AnId, LPSTR ATitle,
  15.                    int X, int Y, int W, int H, PTModule AModule)
  16.                       : TWindow(AParent, ATitle, AModule)
  17. {
  18.   Attr.Id = AnId;
  19.   Attr.X = X;
  20.   Attr.Y = Y;
  21.   Attr.W = W;
  22.   Attr.H = H;
  23.   Attr.Style = WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP;
  24.   SetFlags(WB_MDICHILD, FALSE);   // in case flag was set in TWindow()
  25. }
  26.  
  27. /* Constructor for a TControl to be associated with a MS-Windows
  28.   interface element created by MS-Windows from a resource definition.
  29.   Initializes its data fields using passed parameters.  Data transfer
  30.   is enabled for the TControl. */
  31. TControl::TControl(PTWindowsObject AParent, int ResourceId, PTModule AModule)
  32.          : TWindow(AParent, (LPSTR)NULL, AModule)
  33. {
  34.   if ( HIWORD(Title) )
  35.     farfree(Title); // Free memory allocated by TWindow's constructor
  36.   Title = NULL;
  37.   SetFlags(WB_FROMRESOURCE, TRUE);
  38.   memset(&Attr, 0x0, sizeof Attr);
  39.   Attr.Id = ResourceId;
  40.   Scroller = NULL;
  41.   FocusChildHandle = 0;
  42.   EnableTransfer();
  43. }
  44.  
  45. /* Response method for an incoming WM_PAINT message. If this is a regular
  46.    control call DefWndProc. If this is a custom control call
  47.    TWindow::WMPaint */
  48. void TControl::WMPaint(TMessage& Msg)
  49. {
  50.   if ( IsFlagSet(WB_PREDEFINEDCLASS) )   // predefined Windows class
  51.     DefWndProc(Msg);
  52.   else
  53.     TWindow::WMPaint(Msg);
  54. }
  55.  
  56. void TControl::WMDrawItem(TMessage& Msg)
  57. {
  58.   switch ( ((LPDRAWITEMSTRUCT)(Msg.LParam))->itemAction )
  59.   {
  60.     case ODA_DRAWENTIRE:
  61.          ODADrawEntire(*((LPDRAWITEMSTRUCT)(Msg.LParam)));
  62.          break;
  63.     case ODA_FOCUS:
  64.          ODAFocus(*((LPDRAWITEMSTRUCT)(Msg.LParam)));
  65.          break;
  66.     case ODA_SELECT:
  67.          ODASelect(*((LPDRAWITEMSTRUCT)(Msg.LParam)));
  68.          break;
  69.   }
  70. }
  71.  
  72. /* Function called when an "owner-draw" control needs to be redrawn
  73.    Will usually be redefined by descendants of TControl which use owner draw
  74.    style */
  75. void TControl::ODADrawEntire(DRAWITEMSTRUCT far & DrawInfo)
  76. {
  77.   if (Parent)
  78.     Parent->DrawItem(DrawInfo);
  79. }
  80.  
  81. /* Function called when an "owner-draw" control gains or loses focus
  82.    Will usually be redefined by descendants of TControl which use owner draw
  83.    style */
  84. void TControl::ODAFocus(DRAWITEMSTRUCT far & DrawInfo)
  85. {
  86.   if (Parent)
  87.     Parent->DrawItem(DrawInfo);
  88. }
  89.  
  90. /* Function called when an "owner-draw" control's selection status changes
  91.    Will usually be redefined by descendants of TControl which use owner draw
  92.    style */
  93. void TControl::ODASelect(DRAWITEMSTRUCT far & DrawInfo)
  94. {
  95.   if (Parent)
  96.     Parent->DrawItem(DrawInfo);
  97. }
  98.