nsresult nsWidget::CreateWidget(nsIWidget *aParent, const nsRect &aRect, EVENT_CALLBACK aHandleEventFunction, nsIDeviceContext *aContext, nsIAppShell *aAppShell, nsIToolkit *aToolkit, nsWidgetInitData *aInitData, nsNativeWidget aNativeParent) { PtWidget_t *parentWidget = nsnull; if( aNativeParent ) { parentWidget = (PtWidget_t*)aNativeParent; // we've got a native parent so listen for resizes mListenForResizes = PR_TRUE; } else if( aParent ) { parentWidget = (PtWidget_t*) (aParent->GetNativeData(NS_NATIVE_WIDGET)); mListenForResizes = aInitData ? aInitData->mListenForResizes : PR_FALSE; } if( aInitData->mWindowType == eWindowType_child && !parentWidget ) return NS_ERROR_FAILURE; nsIWidget *baseParent = aInitData && (aInitData->mWindowType == eWindowType_dialog || aInitData->mWindowType == eWindowType_toplevel || aInitData->mWindowType == eWindowType_invisible) ? nsnull : aParent; BaseCreate( baseParent, aRect, aHandleEventFunction, aContext, aAppShell, aToolkit, aInitData ); mParent = aParent; mBounds = aRect; CreateNative (parentWidget); if( aRect.width > 1 && aRect.height > 1 ) Resize(aRect.width, aRect.height, PR_FALSE); if( mWidget ) { SetInstance(mWidget, this); PtAddCallback( mWidget, Pt_CB_GOT_FOCUS, GotFocusCallback, this ); PtAddCallback( mWidget, Pt_CB_LOST_FOCUS, LostFocusCallback, this ); PtAddCallback( mWidget, Pt_CB_IS_DESTROYED, DestroyedCallback, this ); #ifdef PHOTON_DND PtAddCallback( mWidget, Pt_CB_DND, DndCallback, this ); #endif } DispatchStandardEvent(NS_CREATE); return NS_OK; }
// Called in the PM thread. void nsFrameWindow::RealDoCreate( HWND hwndP, nsWindow *aParent, const nsIntRect &aRect, EVENT_CALLBACK aHandleEventFunction, nsIDeviceContext *aContext, nsIAppShell *aAppShell, nsWidgetInitData *aInitData, HWND hwndO) { nsIntRect rect = aRect; if( aParent) // Offset rect by position of owner { nsIntRect clientRect; aParent->GetBounds(rect); aParent->GetClientBounds(clientRect); rect.x += aRect.x + clientRect.x; rect.y += aRect.y + clientRect.y; rect.width = aRect.width; rect.height = aRect.height; hwndP = aParent->GetMainWindow(); rect.y = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN) - (rect.y + rect.height); } else // Use original rect, no owner window { rect = aRect; rect.y = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN) - (aRect.y + aRect.height); } #if DEBUG_sobotka printf("\nIn nsFrameWindow::RealDoCreate:\n"); printf(" hwndP = %lu\n", hwndP); printf(" aParent = 0x%lx\n", &aParent); printf(" aRect = %ld, %ld, %ld, %ld\n", aRect.x, aRect.y, aRect.height, aRect.width); #endif ULONG fcfFlags = GetFCFlags(); ULONG style = WindowStyle(); if( aInitData) { if( aInitData->clipChildren) style |= WS_CLIPCHILDREN; #if 0 // // Windows has a slightly different idea of what the implications are // of a window having or not having the CLIPSIBLINGS style. // All 'canvas' components we create must have clipsiblings, or // strange things happen & performance actually degrades. // else style &= ~WS_CLIPCHILDREN; #endif if( aInitData->clipSiblings) style |= WS_CLIPSIBLINGS; else style &= ~WS_CLIPSIBLINGS; } #ifdef DEBUG_FOCUS mWindowIdentifier = currentWindowIdentifier; currentWindowIdentifier++; if (aInitData && (aInitData->mWindowType == eWindowType_toplevel)) DEBUGFOCUS(Create Frame Window); else DEBUGFOCUS(Create Window); #endif mFrameWnd = WinCreateStdWindow( HWND_DESKTOP, 0, &fcfFlags, WindowClass(), "Title", style, NULLHANDLE, 0, &mWnd); /* Because WinCreateStdWindow doesn't take an owner, we have to set it */ if (hwndP) WinSetOwner(mFrameWnd, hwndP); /* Set some HWNDs and style into properties for fullscreen mode */ HWND hwndTitleBar = WinWindowFromID(mFrameWnd, FID_TITLEBAR); WinSetProperty(mFrameWnd, "hwndTitleBar", (PVOID)hwndTitleBar, 0); HWND hwndSysMenu = WinWindowFromID(mFrameWnd, FID_SYSMENU); WinSetProperty(mFrameWnd, "hwndSysMenu", (PVOID)hwndSysMenu, 0); HWND hwndMinMax = WinWindowFromID(mFrameWnd, FID_MINMAX); WinSetProperty(mFrameWnd, "hwndMinMax", (PVOID)hwndMinMax, 0); SetWindowListVisibility( PR_FALSE); // Hide from Window List until shown NS_ASSERTION( mFrameWnd, "Couldn't create frame"); // Frames have a minimum height based on the pieces they are created with, // such as titlebar, menubar, frame borders, etc. We need this minimum // height so we can correctly set the frame position (coordinate flipping). nsIntRect frameRect = rect; long minheight; if ( fcfFlags & FCF_SIZEBORDER) { minheight = 2 * WinQuerySysValue( HWND_DESKTOP, SV_CYSIZEBORDER); } else if ( fcfFlags & FCF_DLGBORDER) { minheight = 2 * WinQuerySysValue( HWND_DESKTOP, SV_CYDLGFRAME); } else { minheight = 2 * WinQuerySysValue( HWND_DESKTOP, SV_CYBORDER); } if ( fcfFlags & FCF_TITLEBAR) { minheight += WinQuerySysValue( HWND_DESKTOP, SV_CYTITLEBAR); } if ( frameRect.height < minheight) { frameRect.height = minheight; } // Set up parent data - don't addref to avoid circularity mParent = nsnull; // Make sure we have a device context from somewhere if( aContext) { mContext = aContext; NS_ADDREF(mContext); } else { nsresult rc; static NS_DEFINE_IID(kDeviceContextCID, NS_DEVICE_CONTEXT_CID); rc = CallCreateInstance(kDeviceContextCID, &mContext); if( NS_SUCCEEDED(rc)) mContext->Init(this); #ifdef DEBUG else printf( "Couldn't find DC instance for nsWindow\n"); #endif } // Record bounds. This is XP, the rect of the entire main window in // parent space. Returned by GetBounds(). // NB: We haven't subclassed yet, so callbacks to change mBounds won't // have happened! mBounds = frameRect; mBounds.height = frameRect.height; // Record passed in things mEventCallback = aHandleEventFunction; if( mParent) mParent->AddChild( this); // call the event callback to notify about creation DispatchStandardEvent( NS_CREATE ); SubclassWindow(TRUE); PostCreateWidget(); // Subclass frame fnwpDefFrame = WinSubclassWindow( mFrameWnd, fnwpFrame); WinSetWindowPtr( mFrameWnd, QWL_USER, this); WinSetWindowPos(mFrameWnd, 0, frameRect.x, frameRect.y, frameRect.width, frameRect.height, SWP_SIZE | SWP_MOVE); }
void nsWidget::OnDestroy( ) { mOnDestroyCalled = PR_TRUE; // release references to children, device context, toolkit + app shell nsBaseWidget::OnDestroy(); DispatchStandardEvent(NS_DESTROY); }