Logo Search packages:      
Sourcecode: xulrunner version File versions  Download package

nsresult nsIView::CreateWidget ( const nsIID aWindowIID,
nsWidgetInitData aWidgetInitData = nsnull,
nsNativeWidget  aNative = nsnull,
PRBool  aEnableDragDrop = PR_TRUE,
PRBool  aResetVisibility = PR_TRUE,
nsContentType  aWindowType = eContentTypeInherit 
) [inherited]

Create a widget to associate with this view.

Parameters:
aWindowIID IID for Widget type that this view should have associated with it. if nsull, then no width will be created for this view
aWidgetInitData data used to initialize this view's widget before its create is called.
aNative native window that will be used as parent of aWindowIID. if nsnull, then parent will be derived from parent view and it's ancestors
aWindowType is either content, UI or inherit from parent window. This is used to expose what type of window this is to assistive technology like screen readers.
Returns:
error status

Definition at line 650 of file nsView.cpp.

References nsWidgetInitData::clipChildren, nsWidgetInitData::clipSiblings, nsIWidget::Create(), nsIWidget::EnableDragDrop(), nsIWidget::GetNativeData(), nsIView::GetNearestWidget(), nsIView::GetParent(), nsIView::GetViewManager(), nsIView::GetVisibility(), nsWidgetInitData::mContentType, nsWidgetInitData::mListenForResizes, nsWidgetInitData::mWindowType, and nsIWidget::SetClientData().

Referenced by nsIFrame::CreateWidgetForView().

{
  nsIDeviceContext  *dx;
  nsRect            trect = mDimBounds;

  if (NS_UNLIKELY(!!mWindow)) {
    NS_ERROR("We already have a window for this view? BAD");
    ViewWrapper* wrapper = GetWrapperFor(mWindow);
    NS_IF_RELEASE(wrapper);
    mWindow->SetClientData(nsnull);
    NS_RELEASE(mWindow);
  }

  mViewManager->GetDeviceContext(dx);
  float scale = dx->AppUnitsToDevUnits();

  trect *= scale;

  nsView* v = NS_STATIC_CAST(nsView*, this);
  if (NS_OK == v->LoadWidget(aWindowIID))
  {
    PRBool usewidgets;

    dx->SupportsNativeWidgets(usewidgets);

    if (PR_TRUE == usewidgets)
    {
      PRBool initDataPassedIn = PR_TRUE;
      nsWidgetInitData initData;
      if (!aWidgetInitData) {
        // No initData, we're a child window
        // Create initData to pass in params
        initDataPassedIn = PR_FALSE;
        initData.clipChildren = PR_TRUE; // Clip child window's children
        initData.clipSiblings = PR_TRUE; // Clip child window's siblings
        aWidgetInitData = &initData;
      }
      aWidgetInitData->mContentType = aContentType;

      if (aNative)
        mWindow->Create(aNative, trect, ::HandleEvent, dx, nsnull, nsnull, aWidgetInitData);
      else
      {
        if (!initDataPassedIn && GetParent() && 
          GetParent()->GetViewManager() != mViewManager)
          initData.mListenForResizes = PR_TRUE;

        nsPoint offset(0, 0);
        nsIWidget* parentWidget = GetParent() ? GetParent()->GetNearestWidget(&offset)
          : nsnull;
        trect += offset;
        if (aWidgetInitData->mWindowType == eWindowType_popup) {
          mWindow->Create(parentWidget->GetNativeData(NS_NATIVE_WIDGET), trect,
                          ::HandleEvent, dx, nsnull, nsnull, aWidgetInitData);
        } else {
          mWindow->Create(parentWidget, trect,
                          ::HandleEvent, dx, nsnull, nsnull, aWidgetInitData);
        }
      }
      if (aEnableDragDrop) {
        mWindow->EnableDragDrop(PR_TRUE);
      }
      
      // propagate the z-index to the widget.
      UpdateNativeWidgetZIndexes(v, FindNonAutoZIndex(v));
    }
  }

  //make sure visibility state is accurate
  
  if (aResetVisibility) {
    v->SetVisibility(GetVisibility());
  }

  NS_RELEASE(dx);

  return NS_OK;
}


Generated by  Doxygen 1.6.0   Back to index