1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is the Mozilla Browser.
16 * The Initial Developer of the Original Code is
17 * Fredrik Holmqvist <thesuckiestemail@yahoo.se>.
18 * Portions created by the Initial Developer are Copyright (C) 2006
19 * the Initial Developer. All Rights Reserved.
23 * Alternatively, the contents of this file may be used under the terms of
24 * either the GNU General Public License Version 2 or later (the "GPL"), or
25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 * in which case the provisions of the GPL or the LGPL are applicable instead
27 * of those above. If you wish to allow use of your version of this file only
28 * under the terms of either the GPL or the LGPL, and not to allow others to
29 * use your version of this file under the terms of the MPL, indicate your
30 * decision by deleting the provisions above and replace them with the notice
31 * and other provisions required by the GPL or the LGPL. If you do not delete
32 * the provisions above, a recipient may use your version of this file under
33 * the terms of any one of the MPL, the GPL or the LGPL.
35 * ***** END LICENSE BLOCK ***** */
37 #include "nsPopupWindow.h"
39 nsPopupWindow::nsPopupWindow() : nsWindow()
44 //-------------------------------------------------------------------------
46 // Utility method for implementing both Create(nsIWidget ...) and
47 // Create(nsNativeWidget...)
48 //-------------------------------------------------------------------------
49 nsresult
nsPopupWindow::StandardWindowCreate(nsIWidget
*aParent
,
51 EVENT_CALLBACK aHandleEventFunction
,
52 nsIDeviceContext
*aContext
,
53 nsIAppShell
*aAppShell
,
55 nsWidgetInitData
*aInitData
,
56 nsNativeWidget aNativeParent
)
58 NS_ASSERTION(aInitData
->mWindowType
== eWindowType_popup
,
59 "The windowtype is not handled by this class.");
61 NS_ASSERTION(!aParent
, "Popups should not be hooked into nsIWidget hierarchy");
63 mIsTopWidgetWindow
= PR_FALSE
;
65 BaseCreate(aParent
, aRect
, aHandleEventFunction
, aContext
, aAppShell
,
68 mListenForResizes
= aNativeParent
? PR_TRUE
: aInitData
->mListenForResizes
;
70 // Switch to the "main gui thread" if necessary... This method must
71 // be executed on the "gui thread"...
73 nsToolkit
* toolkit
= (nsToolkit
*)mToolkit
;
74 if (toolkit
&& !toolkit
->IsGuiThread())
77 args
[0] = (uint32
)aParent
;
78 args
[1] = (uint32
)&aRect
;
79 args
[2] = (uint32
)aHandleEventFunction
;
80 args
[3] = (uint32
)aContext
;
81 args
[4] = (uint32
)aAppShell
;
82 args
[5] = (uint32
)aToolkit
;
83 args
[6] = (uint32
)aInitData
;
85 if (nsnull
!= aParent
)
87 // nsIWidget parent dispatch
88 MethodInfo
info(this, this, nsSwitchToUIThread::CREATE
, 7, args
);
89 toolkit
->CallMethod(&info
);
93 // Native parent dispatch
94 MethodInfo
info(this, this, nsSwitchToUIThread::CREATE_NATIVE
, 7, args
);
95 toolkit
->CallMethod(&info
);
101 // Useful shortcut, wondering if we can use it also in GetParent() instead
102 // nsIWidget* type mParent.
103 mWindowParent
= (nsWindow
*)aParent
;
106 // Default mode for window, everything switched off.
107 // B_AVOID_FOCUS | B_NO_WORKSPACE_ACTIVATION :
108 // popups always avoid focus and don't force the user to another workspace.
109 uint32 flags
= B_NOT_RESIZABLE
| B_NOT_MINIMIZABLE
| B_NOT_ZOOMABLE
110 | B_NOT_CLOSABLE
| B_ASYNCHRONOUS_CONTROLS
| B_AVOID_FOCUS
111 | B_NO_WORKSPACE_ACTIVATION
;
112 window_look look
= B_NO_BORDER_WINDOW_LOOK
;
114 //eBorderStyle_default is to ask the OS to handle it as it sees best.
115 //eBorderStyle_all is same as top_level window default.
116 if ( !(eBorderStyle_default
== mBorderStyle
|| eBorderStyle_all
& mBorderStyle
))
118 if (eBorderStyle_border
& mBorderStyle
)
119 look
= B_MODAL_WINDOW_LOOK
;
121 if (eBorderStyle_resizeh
& mBorderStyle
)
123 //Resize demands at least border
124 look
= B_MODAL_WINDOW_LOOK
;
125 flags
&= !B_NOT_RESIZABLE
;
128 //We don't have titlebar menus, so treat like title as it demands titlebar.
129 if (eBorderStyle_title
& mBorderStyle
|| eBorderStyle_menu
& mBorderStyle
)
130 look
= B_TITLED_WINDOW_LOOK
;
132 if (eBorderStyle_minimize
& mBorderStyle
)
133 flags
&= !B_NOT_MINIMIZABLE
;
135 if (eBorderStyle_maximize
& mBorderStyle
)
136 flags
&= !B_NOT_ZOOMABLE
;
138 if (eBorderStyle_close
& mBorderStyle
)
139 flags
&= !B_NOT_CLOSABLE
;
144 // Due poor BeOS capability to control windows hierarchy/z-order we use this
145 // workaround to show eWindowType_popup (e.g. drop-downs) over floating
146 // (subset) parent window.
147 if (((BView
*)aNativeParent
)->Window() &&
148 ((BView
*)aNativeParent
)->Window()->IsFloating())
150 mBWindowFeel
= B_FLOATING_ALL_WINDOW_FEEL
;
155 nsWindowBeOS
* w
= new nsWindowBeOS(this,
156 BRect(aRect
.x
, aRect
.y
, aRect
.x
+ aRect
.width
- 1, aRect
.y
+ aRect
.height
- 1),
157 "", look
, mBWindowFeel
, flags
);
159 return NS_ERROR_OUT_OF_MEMORY
;
161 mView
= new nsViewBeOS(this, w
->Bounds(), "popup view",
162 B_FOLLOW_ALL
, B_WILL_DRAW
);
165 return NS_ERROR_OUT_OF_MEMORY
;
168 // Run Looper. No proper destroy without it.
170 DispatchStandardEvent(NS_CREATE
);
174 NS_METHOD
nsPopupWindow::Show(PRBool bState
)
176 //Bring popup to correct workspace.
177 if (bState
== PR_TRUE
&& mView
&& mView
->Window() != NULL
)
178 mView
->Window()->SetWorkspaces(B_CURRENT_WORKSPACE
);
180 return nsWindow::Show(bState
);