Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / widget / src / beos / nsChildView.cpp
blob0e1e9bc4688a02d7c78743177bd61c3813435db6
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
12 * License.
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.
21 * Contributor(s):
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 "nsChildView.h"
39 nsChildView::nsChildView() : nsWindow()
44 //-------------------------------------------------------------------------
46 // Utility method for implementing both Create(nsIWidget ...) and
47 // Create(nsNativeWidget...)
48 //-------------------------------------------------------------------------
49 nsresult nsChildView::StandardWindowCreate(nsIWidget *aParent,
50 const nsRect &aRect,
51 EVENT_CALLBACK aHandleEventFunction,
52 nsIDeviceContext *aContext,
53 nsIAppShell *aAppShell,
54 nsIToolkit *aToolkit,
55 nsWidgetInitData *aInitData,
56 nsNativeWidget aNativeParent)
59 NS_ASSERTION(aInitData->mWindowType == eWindowType_child
60 || aInitData->mWindowType == eWindowType_java
61 || aInitData->mWindowType == eWindowType_plugin,
62 "The windowtype is not handled by this class." );
64 mIsTopWidgetWindow = PR_FALSE;
66 BaseCreate(aParent, aRect, aHandleEventFunction, aContext, aAppShell,
67 aToolkit, aInitData);
69 mListenForResizes = aNativeParent ? PR_TRUE : aInitData->mListenForResizes;
71 // Switch to the "main gui thread" if necessary... This method must
72 // be executed on the "gui thread"...
74 nsToolkit* toolkit = (nsToolkit *)mToolkit;
75 if (toolkit && !toolkit->IsGuiThread())
77 uint32 args[7];
78 args[0] = (uint32)aParent;
79 args[1] = (uint32)&aRect;
80 args[2] = (uint32)aHandleEventFunction;
81 args[3] = (uint32)aContext;
82 args[4] = (uint32)aAppShell;
83 args[5] = (uint32)aToolkit;
84 args[6] = (uint32)aInitData;
86 if (nsnull != aParent)
88 // nsIWidget parent dispatch
89 MethodInfo info(this, this, nsSwitchToUIThread::CREATE, 7, args);
90 toolkit->CallMethod(&info);
92 else
94 // Native parent dispatch
95 MethodInfo info(this, this, nsSwitchToUIThread::CREATE_NATIVE, 7, args);
96 toolkit->CallMethod(&info);
98 return NS_OK;
101 mParent = aParent;
102 // Useful shortcut, wondering if we can use it also in GetParent() instead
103 // nsIWidget* type mParent.
104 mWindowParent = (nsWindow *) aParent;
105 SetBounds(aRect);
107 //NS_NATIVE_GRAPHIC maybe?
108 //Parent may be a BView if we embed.
109 BView *parent= (BView *)
110 (aParent ? aParent->GetNativeData(NS_NATIVE_WIDGET) : aNativeParent);
111 //There seems to be three of these on startup,
112 //but I believe that these are because of bugs in
113 //other code as they existed before rewriting this
114 //function.
115 NS_PRECONDITION(parent, "Childviews without parents don't get added to anything.");
116 // A childview that is never added to a parent is very strange.
117 if (!parent)
118 return NS_ERROR_FAILURE;
120 mView = new nsViewBeOS(this,
121 BRect(aRect.x, aRect.y, aRect.x + aRect.width - 1, aRect.y + aRect.height - 1)
122 , "Child view", 0, B_WILL_DRAW);
123 #if defined(BeIME)
124 mView->SetFlags(mView->Flags() | B_INPUT_METHOD_AWARE);
125 #endif
126 bool mustUnlock = parent->Parent() && parent->LockLooper();
127 parent->AddChild(mView);
128 if (mustUnlock)
129 parent->UnlockLooper();
130 DispatchStandardEvent(NS_CREATE);
131 return NS_OK;
135 //-------------------------------------------------------------------------
137 // Hide or show this component
139 //-------------------------------------------------------------------------
140 NS_METHOD nsChildView::Show(PRBool bState)
142 if (!mEnabled)
143 return NS_OK;
145 if (!mView || !mView->LockLooper())
146 return NS_OK;
148 //We need to do the IsHidden() checks
149 //because BeOS counts no of Hide()
150 //and Show() checks. BeBook:
151 // For a hidden view to become visible again, the number of Hide() calls
152 // must be matched by an equal number of Show() calls.
153 if (PR_FALSE == bState)
155 if (!mView->IsHidden())
156 mView->Hide();
158 else
160 if (mView->IsHidden())
161 mView->Show();
164 mView->UnlockLooper();
165 mIsVisible = bState;
166 return NS_OK;
170 NS_METHOD nsChildView::SetTitle(const nsAString& aTitle)
172 if (mView)
173 mView->SetName(NS_ConvertUTF16toUTF8(aTitle).get());
174 return NS_OK;