1 /*
   2  * Copyright (c) 1996, 2011, 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 AWT_FRAME_H
  27 #define AWT_FRAME_H
  28 
  29 #include "awt_Window.h"
  30 #include "awt_MenuBar.h" //add for multifont
  31 #include "awt_Toolkit.h"
  32 #include "Hashtable.h"
  33 
  34 #include "java_awt_Frame.h"
  35 #include "sun_awt_windows_WFramePeer.h"
  36 
  37 
  38 /************************************************************************
  39  * AwtFrame class
  40  */
  41 
  42 #define AWT_FRAME_WINDOW_CLASS_NAME TEXT("SunAwtFrame")
  43 
  44 
  45 class AwtFrame : public AwtWindow {
  46 public:
  47     enum FrameExecIds {
  48         FRAME_SETMENUBAR
  49     };
  50 
  51     /* java.awt.Frame fields and method IDs */
  52     static jfieldID undecoratedID;
  53 
  54     /* sun.awt.windows.WEmbeddedFrame fields and method IDs */
  55     static jfieldID handleID;
  56 
  57     static jmethodID setExtendedStateMID;
  58     static jmethodID getExtendedStateMID;
  59 
  60     /* method id for WEmbeddedFrame.requestActivate() method */
  61     static jmethodID activateEmbeddingTopLevelMID;
  62 
  63     AwtFrame();
  64     virtual ~AwtFrame();
  65 
  66     virtual void Dispose();
  67 
  68     virtual LPCTSTR GetClassName();
  69 
  70     /* Create a new AwtFrame.  This must be run on the main thread. */
  71     static AwtFrame* Create(jobject self, jobject parent);
  72 
  73     /* Returns whether this frame is embedded in an external native frame. */
  74     INLINE BOOL IsEmbeddedFrame() { return m_isEmbedded; }
  75     /* Returns whether this frame is lightweight. */
  76     INLINE virtual BOOL IsLightweightFrame() { return m_isLightweight; }
  77 
  78     INLINE BOOL IsSimpleWindow() { return FALSE; }
  79 
  80     /* Returns whether this window is in iconified state. */
  81     INLINE BOOL isIconic() { return m_iconic; }
  82     INLINE void setIconic(BOOL b) { m_iconic = b; }
  83 
  84     /* Returns whether this window is in zoomed state. */
  85     INLINE BOOL isZoomed() { return m_zoomed; }
  86     INLINE void setZoomed(BOOL b) { m_zoomed = b; }
  87 
  88     void SendWindowStateEvent(int oldState, int newState);
  89 
  90     void Show();
  91 
  92     INLINE void DrawMenuBar() { VERIFY(::DrawMenuBar(GetHWnd())); }
  93 
  94     virtual void DoUpdateIcon();
  95     virtual HICON GetEffectiveIcon(int iconType);
  96 
  97     /*for WmDrawItem and WmMeasureItem method */
  98     AwtMenuBar* GetMenuBar();
  99     void SetMenuBar(AwtMenuBar*);
 100 
 101     virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
 102 
 103     MsgRouting WmGetMinMaxInfo(LPMINMAXINFO lpmmi);
 104     MsgRouting WmSize(UINT type, int w, int h);
 105     MsgRouting WmActivate(UINT nState, BOOL fMinimized, HWND opposite);
 106     MsgRouting WmDrawItem(UINT ctrlId, DRAWITEMSTRUCT& drawInfo);
 107     MsgRouting WmMeasureItem(UINT ctrlId, MEASUREITEMSTRUCT& measureInfo);
 108     MsgRouting WmEnterMenuLoop(BOOL isTrackPopupMenu);
 109     MsgRouting WmExitMenuLoop(BOOL isTrackPopupMenu);
 110     MsgRouting WmMouseUp(UINT flags, int x, int y, int button);
 111     MsgRouting WmMouseMove(UINT flags, int x, int y);
 112     MsgRouting WmNcMouseDown(WPARAM hitTest, int x, int y, int button);
 113     MsgRouting WmNcMouseUp(WPARAM hitTest, int x, int y, int button);
 114     MsgRouting WmGetIcon(WPARAM iconType, LRESULT& retVal);
 115     MsgRouting WmShowWindow(BOOL show, UINT status);
 116 
 117     virtual MsgRouting WmSysCommand(UINT uCmdType, int xPos, int yPos);
 118 
 119     LRESULT WinThreadExecProc(ExecuteArgs * args);
 120 
 121     INLINE BOOL IsUndecorated() { return m_isUndecorated; }
 122 
 123     INLINE HWND GetProxyFocusOwner() {
 124         return GetHWnd();
 125     }
 126 
 127     void SetMaximizedBounds(int x, int y, int w, int h);
 128     void ClearMaximizedBounds();
 129 
 130     // returns true if the frame is inputmethod window
 131     INLINE BOOL isInputMethodWindow() { return m_isInputMethodWindow; }
 132     // adjusts the IME candidate window position if needed
 133     void AdjustCandidateWindowPos();
 134 
 135     // invoked on Toolkit thread
 136     static jobject _GetBoundsPrivate(void *param);
 137 
 138     // some methods called on Toolkit thread
 139     static void _SetState(void *param);
 140     static jint _GetState(void *param);
 141     static void _SetMaximizedBounds(void *param);
 142     static void _ClearMaximizedBounds(void *param);
 143     static void _SetMenuBar(void *param);
 144     static void _SetIMMOption(void *param);
 145     static void _SynthesizeWmActivate(void *param);
 146     static void _NotifyModalBlocked(void *param);
 147 
 148     virtual void Reshape(int x, int y, int width, int height);
 149 
 150     virtual BOOL AwtSetActiveWindow(BOOL isMouseEventCause = FALSE, UINT hittest = HTCLIENT);
 151 
 152     void CheckRetainActualFocusedWindow(HWND activatedOpositeHWnd);
 153     BOOL CheckActivateActualFocusedWindow(HWND deactivatedOpositeHWnd);
 154 
 155     INLINE HWND GetImeTargetComponent() { return m_imeTargetComponent; }
 156     INLINE void SetImeTargetComponent(HWND hwnd) { m_imeTargetComponent = hwnd; }
 157 
 158 protected:
 159     /* The frame is undecorated. */
 160     BOOL m_isUndecorated;
 161 
 162 private:
 163     LRESULT ProxyWindowProc(UINT message, WPARAM wParam, LPARAM lParam, MsgRouting &mr);
 164 
 165     /* The frame's embedding parent (if any) */
 166     HWND m_parentWnd;
 167 
 168     /* The frame's menubar. */
 169     AwtMenuBar* menuBar;
 170 
 171     /* The frame is an EmbeddedFrame. */
 172     BOOL m_isEmbedded;
 173 
 174     /* The frame is a LightweightFrame */
 175     BOOL m_isLightweight;
 176 
 177     /* used so that calls to ::MoveWindow in SetMenuBar don't propogate
 178        because they are immediately followed by calls to Component.resize */
 179     BOOL m_ignoreWmSize;
 180 
 181     /* tracks whether or not menu on this frame is dropped down */
 182     BOOL m_isMenuDropped;
 183 
 184     /* The frame is an InputMethodWindow */
 185     BOOL m_isInputMethodWindow;
 186 
 187     // retains the target component for the IME messages
 188     HWND m_imeTargetComponent;
 189 
 190     /*
 191      * Fix for 4823903.
 192      * Retains a focus proxied window to set the focus correctly
 193      * when its owner get activated.
 194      */
 195     AwtWindow *m_actualFocusedWindow;
 196 
 197     /* The original, default WndProc for m_proxyFocusOwner. */
 198     WNDPROC m_proxyDefWindowProc;
 199 
 200     BOOL m_iconic;          /* are we in an iconic state */
 201     BOOL m_zoomed;          /* are we in a zoomed state */
 202 
 203     /* whether WmSize() must unconditionally reset zoomed state */
 204     BOOL m_forceResetZoomed;
 205 
 206     BOOL  m_maxBoundsSet;
 207     POINT m_maxPos;
 208     POINT m_maxSize;
 209 
 210     BOOL isInManualMoveOrSize;
 211     WPARAM grabbedHitTest;
 212     POINT savedMousePos;
 213 
 214     /*
 215      * Hashtable<Thread, BlockedThreadStruct> - a table that contains all the
 216      * information about non-toolkit threads with modal blocked embedded
 217      * frames. This information includes: number of blocked embedded frames
 218      * created on the the thread, and mouse and modal hooks installed for
 219      * that thread. For every thread each hook is installed only once
 220      */
 221     static Hashtable sm_BlockedThreads;
 222 };
 223 
 224 #endif /* AWT_FRAME_H */