home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / wxos2240.zip / wxWindows-2.4.0 / src / os2 / control.cpp < prev    next >
C/C++ Source or Header  |  2002-12-27  |  10KB  |  294 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name:        control.cpp
  3. // Purpose:     wxControl class
  4. // Author:      David Webster
  5. // Modified by:
  6. // Created:     09/17/99
  7. // RCS-ID:      $Id: CONTROL.CPP,v 1.23.2.1 2002/12/27 14:49:34 JS Exp $
  8. // Copyright:   (c) Julian Smart and Markus Holzem
  9. // Licence:     wxWindows licence
  10. /////////////////////////////////////////////////////////////////////////////
  11.  
  12. #ifdef __GNUG__
  13. #pragma implementation "control.h"
  14. #endif
  15.  
  16. // For compilers that support precompilation, includes "wx.h".
  17. #include "wx/wxprec.h"
  18.  
  19. #ifndef WX_PRECOMP
  20. #include "wx/event.h"
  21. #include "wx/app.h"
  22. #include "wx/dcclient.h"
  23. #include "wx/scrolwin.h"
  24. #include "wx/log.h"
  25. #endif
  26. #include "wx/os2/private.h"
  27. #include "wx/control.h"
  28.  
  29. IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
  30.  
  31. BEGIN_EVENT_TABLE(wxControl, wxWindow)
  32.     EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground)
  33. END_EVENT_TABLE()
  34.  
  35. // Item members
  36. wxControl::wxControl()
  37. {
  38.  
  39. #if WXWIN_COMPATIBILITY
  40.   m_callback = 0;
  41. #endif // WXWIN_COMPATIBILITY
  42. } // end of wxControl::wxControl
  43.  
  44. bool wxControl::Create(
  45.   wxWindow*                         pParent
  46. , wxWindowID                        vId
  47. , const wxPoint&                    rPos
  48. , const wxSize&                     rSize
  49. , long                              lStyle
  50. , const wxValidator&                rValidator
  51. , const wxString&                   rsName
  52. )
  53. {
  54.     bool                            bRval = wxWindow::Create( pParent
  55.                                                              ,vId
  56.                                                              ,rPos
  57.                                                              ,rSize
  58.                                                              ,lStyle
  59.                                                              ,rsName
  60.                                                             );
  61.     if (bRval)
  62.     {
  63. #if wxUSE_VALIDATORS
  64.         SetValidator(rValidator);
  65. #endif
  66.     }
  67.     return bRval;
  68. } // end of wxControl::Create
  69.  
  70. wxControl::~wxControl()
  71. {
  72.     m_isBeingDeleted = TRUE;
  73. }
  74.  
  75. bool wxControl::OS2CreateControl(
  76.   const wxChar*                     zClassname
  77. , const wxString&                   rsLabel
  78. , const wxPoint&                    rPos
  79. , const wxSize&                     rSize
  80. , long                              lStyle
  81. )
  82. {
  83.     WXDWORD                         dwExstyle;
  84.     WXDWORD                         dwStyle = OS2GetStyle( lStyle
  85.                                                           ,&dwExstyle
  86.                                                          );
  87.  
  88.     return OS2CreateControl( zClassname
  89.                             ,dwStyle
  90.                             ,rPos
  91.                             ,rSize
  92.                             ,rsLabel
  93.                             ,dwExstyle
  94.                            );
  95. } // end of wxControl::OS2CreateControl
  96.  
  97. bool wxControl::OS2CreateControl(
  98.   const wxChar*                     zClassname
  99. , WXDWORD                           dwStyle
  100. , const wxPoint&                    rPos
  101. , const wxSize&                     rSize
  102. , const wxString&                   rsLabel
  103. , WXDWORD                           dwExstyle
  104. )
  105. {
  106.     bool                            bWant3D = FALSE;
  107.  
  108.     //
  109.     // Doesn't do anything at all under OS/2
  110.     //
  111.     if (dwExstyle == (WXDWORD)-1)
  112.     {
  113.         dwExstyle = Determine3DEffects(WS_EX_CLIENTEDGE, &bWant3D);
  114.     }
  115.     //
  116.     // All controls should have these styles (wxWindows creates all controls
  117.     // visible by default)
  118.     //
  119.     if (m_isShown )
  120.         dwStyle |= WS_VISIBLE;
  121.  
  122.     wxWindow*                       pParent = GetParent();
  123.     PSZ                             zClass;
  124.  
  125.     if (!pParent)
  126.         return FALSE;
  127.  
  128.     if ((strcmp(zClassname, "COMBOBOX")) == 0)
  129.         zClass = WC_COMBOBOX;
  130.     else if ((strcmp(zClassname, "STATIC")) == 0)
  131.         zClass = WC_STATIC;
  132.     else if ((strcmp(zClassname, "BUTTON")) == 0)
  133.         zClass = WC_BUTTON;
  134.     else if ((strcmp(zClassname, "NOTEBOOK")) == 0)
  135.         zClass = WC_NOTEBOOK;
  136.     dwStyle |= WS_VISIBLE;
  137.  
  138.     m_hWnd = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
  139.                                        ,(PSZ)zClass              // Window class
  140.                                        ,(PSZ)rsLabel.c_str()     // Initial Text
  141.                                        ,(ULONG)dwStyle           // Style flags
  142.                                        ,(LONG)0                  // X pos of origin
  143.                                        ,(LONG)0                  // Y pos of origin
  144.                                        ,(LONG)0                  // control width
  145.                                        ,(LONG)0                  // control height
  146.                                        ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
  147.                                        ,HWND_TOP                 // initial z position
  148.                                        ,(ULONG)GetId()           // Window identifier
  149.                                        ,NULL                     // no control data
  150.                                        ,NULL                     // no Presentation parameters
  151.                                       );
  152.  
  153.     if ( !m_hWnd )
  154.     {
  155. #ifdef __WXDEBUG__
  156.         wxLogError(wxT("Failed to create a control of class '%s'"), zClassname);
  157. #endif // DEBUG
  158.  
  159.         return FALSE;
  160.     }
  161.     //
  162.     // Subclass again for purposes of dialog editing mode
  163.     //
  164.     SubclassWin(m_hWnd);
  165.  
  166.     //
  167.     // Controls use the same font and colours as their parent dialog by default
  168.     //
  169.     InheritAttributes();
  170.     SetXComp(0);
  171.     SetYComp(0);
  172.     SetSize( rPos.x
  173.             ,rPos.y
  174.             ,rSize.x
  175.             ,rSize.y
  176.            );
  177.     return TRUE;
  178. } // end of wxControl::OS2CreateControl
  179.  
  180. wxSize wxControl::DoGetBestSize() const
  181. {
  182.     return wxSize(DEFAULT_ITEM_WIDTH, DEFAULT_ITEM_HEIGHT);
  183. } // end of wxControl::DoGetBestSize
  184.  
  185. bool wxControl::ProcessCommand(wxCommandEvent& event)
  186. {
  187. #if WXWIN_COMPATIBILITY
  188.     if ( m_callback )
  189.     {
  190.         (void)(*m_callback)(this, event);
  191.  
  192.         return TRUE;
  193.     }
  194.     else
  195. #endif // WXWIN_COMPATIBILITY
  196.  
  197.     return GetEventHandler()->ProcessEvent(event);
  198. }
  199.  
  200. WXHBRUSH wxControl::OnCtlColor(
  201.   WXHDC                             hWxDC
  202. , WXHWND                            hWnd
  203. , WXUINT                            uCtlColor
  204. , WXUINT                            uMessage
  205. , WXWPARAM                          wParam
  206. , WXLPARAM                          lParam
  207. )
  208. {
  209.     HPS                             hPS = (HPS)hWxDC; // pass in a PS handle in OS/2
  210.     wxColour                        vColFore = GetForegroundColour();
  211.     wxColour                        vColBack = GetBackgroundColour();
  212.  
  213.     if (GetParent()->GetTransparentBackground())
  214.         ::GpiSetBackMix(hPS, BM_LEAVEALONE);
  215.     else
  216.         ::GpiSetBackMix(hPS, BM_OVERPAINT);
  217.  
  218.     ::GpiSetBackColor(hPS, vColBack.GetPixel());
  219.     ::GpiSetColor(hPS, vColFore.GetPixel());
  220.  
  221.     wxBrush*                        pBrush = wxTheBrushList->FindOrCreateBrush( vColBack
  222.                                                                                ,wxSOLID
  223.                                                                               );
  224.     return (WXHBRUSH)pBrush->GetResourceHandle();
  225. } // end of wxControl::OnCtlColor
  226.  
  227. void wxControl::OnEraseBackground(
  228.   wxEraseEvent&                     rEvent
  229. )
  230. {
  231.     RECTL                           vRect;
  232.     HPS                             hPS = rEvent.GetDC()->GetHPS();
  233.     SIZEL                           vSize = {0,0};
  234.  
  235.     ::GpiSetPS(hPS, &vSize, PU_PELS | GPIF_DEFAULT);
  236.     ::WinQueryWindowRect((HWND)GetHwnd(), &vRect);
  237.     ::WinFillRect(hPS, &vRect, GetBackgroundColour().GetPixel());
  238. } // end of wxControl::OnEraseBackground
  239.  
  240. WXDWORD wxControl::OS2GetStyle(
  241.   long                              lStyle
  242. , WXDWORD*                          pdwExstyle
  243. ) const
  244. {
  245.     long                            dwStyle = wxWindow::OS2GetStyle( lStyle
  246.                                                                     ,pdwExstyle
  247.                                                                    );
  248.  
  249.     if (AcceptsFocus())
  250.     {
  251.         dwStyle |= WS_TABSTOP;
  252.     }
  253.     return dwStyle;
  254. } // end of wxControl::OS2GetStyle
  255.  
  256. // ---------------------------------------------------------------------------
  257. // global functions
  258. // ---------------------------------------------------------------------------
  259.  
  260. // Call this repeatedly for several wnds to find the overall size
  261. // of the widget.
  262. // Call it initially with -1 for all values in rect.
  263. // Keep calling for other widgets, and rect will be modified
  264. // to calculate largest bounding rectangle.
  265. void wxFindMaxSize(
  266.   WXHWND                            hWnd
  267. , RECT*                             pRect
  268. )
  269. {
  270.     int                             nLeft = pRect->xLeft;
  271.     int                             nRight = pRect->xRight;
  272.     int                             nTop = pRect->yTop;
  273.     int                             nBottom = pRect->yBottom;
  274.  
  275.     ::WinQueryWindowRect((HWND)hWnd, pRect);
  276.  
  277.     if (nLeft < 0)
  278.         return;
  279.  
  280.     if (nLeft < pRect->xLeft)
  281.         pRect->xLeft = nLeft;
  282.  
  283.     if (nRight > pRect->xRight)
  284.         pRect->xRight = nRight;
  285.  
  286.     if (nTop < pRect->yTop)
  287.         pRect->yTop = nTop;
  288.  
  289.     if (nBottom > pRect->yBottom)
  290.         pRect->yBottom = nBottom;
  291. } // end of wxFindMaxSize
  292.  
  293.  
  294.