modules/graphics/src/main/native-glass/win/BaseWnd.cpp

Print this page




  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include "common.h"
  27 
  28 #include "BaseWnd.h"
  29 #include "GlassApplication.h"
  30 
  31 
  32 //NOTE: it's not thread-safe
  33 unsigned int BaseWnd::sm_classNameCounter = 0;
  34 
  35 static LPCTSTR szBaseWndProp = TEXT("BaseWndProp");
  36 
  37 BaseWnd::BaseWnd(HWND ancestor) :
  38     m_hWnd(NULL),
  39     m_ancestor(ancestor),
  40     m_wndClassAtom(0),
  41     m_isCommonDialogOwner(false),
  42     m_hCursor(NULL)

  43 {
  44 
  45 }
  46 
  47 BaseWnd::~BaseWnd()
  48 {
  49     if (m_wndClassAtom)
  50     {
  51         // This is called from WM_NCDESTROY, and ::UnregisterClass() will fail.
  52         // Schedule the operation for later time when the HWND is dead and
  53         // the window class is really free already.
  54         ENTER_MAIN_THREAD()
  55         {
  56             if (!::UnregisterClass(reinterpret_cast<LPCTSTR>(wndClassAtom),
  57                         ::GetModuleHandle(NULL)))
  58             {
  59                 _tprintf_s(L"BaseWnd::UnregisterClass(%i) error: %u\n",
  60                         (int)wndClassAtom, ::GetLastError());
  61             }
  62         }


 160     }
 161     if (pThis != NULL) {
 162         LRESULT result = pThis->WindowProc(msg, wParam, lParam);
 163         if (msg == WM_NCDESTROY) {
 164             ::RemoveProp(hWnd, szBaseWndProp);
 165             delete pThis;
 166         }
 167         return result;
 168     }
 169     return ::DefWindowProc(hWnd, msg, wParam, lParam);
 170 }
 171 
 172 /*virtual*/
 173 MessageResult BaseWnd::CommonWindowProc(UINT msg, WPARAM wParam, LPARAM lParam)
 174 {
 175     static const MessageResult NOT_PROCESSED;
 176 
 177     switch (msg) {
 178         case WM_SETCURSOR:
 179             if (LOWORD(lParam) == HTCLIENT) {

 180                 ::SetCursor(m_hCursor);

 181                 return TRUE;
 182             }
 183             break;
 184     }
 185 
 186     return NOT_PROCESSED;
 187 }
 188 
 189 void BaseWnd::SetCursor(HCURSOR cursor)
 190 {
 191     m_hCursor = cursor;
 192 
 193     // Might be worth checking the current cursor position.
 194     // However, we've always set cursor unconditionally relying on the caller
 195     // invoking this method only when it processes mouse_move or alike events.
 196     // As long as there's no bugs filed, let it be.
 197     ::SetCursor(m_hCursor);
 198 }
 199 







  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include "common.h"
  27 
  28 #include "BaseWnd.h"
  29 #include "GlassApplication.h"
  30 
  31 
  32 //NOTE: it's not thread-safe
  33 unsigned int BaseWnd::sm_classNameCounter = 0;
  34 
  35 static LPCTSTR szBaseWndProp = TEXT("BaseWndProp");
  36 
  37 BaseWnd::BaseWnd(HWND ancestor) :
  38     m_hWnd(NULL),
  39     m_ancestor(ancestor),
  40     m_wndClassAtom(0),
  41     m_isCommonDialogOwner(false),
  42     m_hCursor(NULL),
  43     m_updatesCursor(true)
  44 {
  45 
  46 }
  47 
  48 BaseWnd::~BaseWnd()
  49 {
  50     if (m_wndClassAtom)
  51     {
  52         // This is called from WM_NCDESTROY, and ::UnregisterClass() will fail.
  53         // Schedule the operation for later time when the HWND is dead and
  54         // the window class is really free already.
  55         ENTER_MAIN_THREAD()
  56         {
  57             if (!::UnregisterClass(reinterpret_cast<LPCTSTR>(wndClassAtom),
  58                         ::GetModuleHandle(NULL)))
  59             {
  60                 _tprintf_s(L"BaseWnd::UnregisterClass(%i) error: %u\n",
  61                         (int)wndClassAtom, ::GetLastError());
  62             }
  63         }


 161     }
 162     if (pThis != NULL) {
 163         LRESULT result = pThis->WindowProc(msg, wParam, lParam);
 164         if (msg == WM_NCDESTROY) {
 165             ::RemoveProp(hWnd, szBaseWndProp);
 166             delete pThis;
 167         }
 168         return result;
 169     }
 170     return ::DefWindowProc(hWnd, msg, wParam, lParam);
 171 }
 172 
 173 /*virtual*/
 174 MessageResult BaseWnd::CommonWindowProc(UINT msg, WPARAM wParam, LPARAM lParam)
 175 {
 176     static const MessageResult NOT_PROCESSED;
 177 
 178     switch (msg) {
 179         case WM_SETCURSOR:
 180             if (LOWORD(lParam) == HTCLIENT) {
 181                 if (m_updatesCursor) {
 182                     ::SetCursor(m_hCursor);
 183                 }
 184                 return TRUE;
 185             }
 186             break;
 187     }
 188 
 189     return NOT_PROCESSED;
 190 }
 191 
 192 void BaseWnd::SetCursor(HCURSOR cursor)
 193 {
 194     m_hCursor = cursor;
 195 
 196     // Might be worth checking the current cursor position.
 197     // However, we've always set cursor unconditionally relying on the caller
 198     // invoking this method only when it processes mouse_move or alike events.
 199     // As long as there's no bugs filed, let it be.
 200     ::SetCursor(m_hCursor);
 201 }
 202 
 203 void BaseWnd::SetUpdatesCursor(bool updatesCursor)
 204 {
 205     m_updatesCursor = updatesCursor;
 206 }
 207