1 /*
   2  * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #ifndef _BASEWND_INCLUDED_
  27 #define _BASEWND_INCLUDED_
  28 
  29 
  30 class GlassView;
  31 
  32 struct MessageResult {
  33     const bool processed;
  34     const LRESULT result; // only valid if processed == true
  35 
  36     MessageResult() : processed(false), result(0) {}
  37     MessageResult(LRESULT r) : processed(true), result(r) {}
  38 };
  39 
  40 class BaseWnd {
  41 public:
  42     BaseWnd(HWND ancestor = NULL);
  43     virtual ~BaseWnd();
  44     
  45     //XXX: might eliminate hParent and use m_ancestor instead
  46     HWND Create(HWND hParent, int x, int y, int width, int height,
  47                 LPCTSTR lpWindowName, DWORD dwExStyle, DWORD dwStyle, HBRUSH hbrBackground);
  48 
  49     // Creates an overlapped window with default x, y, width and height and
  50     // returns its bounds. This method is used to find the default window
  51     // size/location when CW_USEDEFAULT can't be used (e.g. for WS_POPUP windows).
  52     static BOOL GetDefaultWindowBounds(LPRECT r);
  53     
  54     HWND GetHWND() { return m_hWnd; }
  55 
  56     static BaseWnd* FromHandle(HWND hWnd);
  57 
  58     inline virtual bool IsGlassWindow() { return false; }
  59 
  60     virtual BOOL EnterFullScreenMode(GlassView * view, BOOL animate, BOOL keepRatio) { return FALSE; }
  61     virtual void ExitFullScreenMode(BOOL animate) {}
  62 
  63     HWND GetAncestor() const { return m_ancestor; }
  64     void SetAncestor(HWND ancestor) { m_ancestor = ancestor; }
  65 
  66     void SetCommonDialogOwner(bool owner) { m_isCommonDialogOwner = owner; }
  67     
  68     void SetCursor(HCURSOR cursor);
  69 
  70 private:
  71     HWND m_hWnd;
  72     static LRESULT CALLBACK StaticWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
  73 
  74     static unsigned int sm_classNameCounter;
  75     
  76     HWND m_ancestor;  // either owner or parent. a window can't have both at once anyway
  77 
  78     ATOM m_wndClassAtom;
  79     bool m_isCommonDialogOwner;
  80     HCURSOR m_hCursor;
  81 protected:
  82     virtual LRESULT WindowProc(UINT msg, WPARAM wParam, LPARAM lParam) = 0;
  83     virtual MessageResult CommonWindowProc(UINT msg, WPARAM wParam, LPARAM lParam);
  84     
  85     virtual LPCTSTR GetWindowClassNameSuffix() = 0;
  86 
  87     bool IsCommonDialogOwner() { return m_isCommonDialogOwner; }
  88 
  89 };
  90    
  91 #endif  // _BASEWND_INCLUDED_