A weak attempt at closing both 264105 and 264027. move seems to be still

not doing what i want though
This commit is contained in:
zack%kde.org 2004-10-14 21:53:12 +00:00
Родитель 2dc1b399ee
Коммит 7ca16b1dd9
4 изменённых файлов: 168 добавлений и 52 удалений

Просмотреть файл

@ -178,3 +178,11 @@ bool MozQWidget::event(QEvent *e)
return !ignore; return !ignore;
} }
void MozQWidget::setModal(bool modal)
{
if (modal)
setWFlags(Qt::WShowModal);
else
clearWFlags(Qt::WShowModal);
}

Просмотреть файл

@ -12,6 +12,11 @@ class MozQWidget : public QWidget
public: public:
MozQWidget(nsCommonWidget *receiver, QWidget *parent, MozQWidget(nsCommonWidget *receiver, QWidget *parent,
const char *name, WFlags f); const char *name, WFlags f);
/**
* Mozilla helper.
*/
void setModal(bool);
protected: protected:
virtual bool event(QEvent *ev); virtual bool event(QEvent *ev);
private: private:

Просмотреть файл

@ -47,6 +47,8 @@
#include "nsIPrefBranch.h" #include "nsIPrefBranch.h"
#include "nsIPrefService.h" #include "nsIPrefService.h"
#include "mozqwidget.h"
#include <qapplication.h> #include <qapplication.h>
#include <qdesktopwidget.h> #include <qdesktopwidget.h>
#include <qwidget.h> #include <qwidget.h>
@ -249,7 +251,10 @@ keyEventToContextMenuEvent(const nsKeyEvent* aKeyEvent,
nsCommonWidget::nsCommonWidget() nsCommonWidget::nsCommonWidget()
: mContainer(0), : mContainer(0),
mWidget(0), mWidget(0),
mListenForResizes(PR_FALSE) mListenForResizes(PR_FALSE),
mNeedsResize(PR_FALSE),
mNeedsShow(PR_FALSE),
mIsShown(PR_FALSE)
{ {
} }
@ -273,17 +278,29 @@ nsCommonWidget::Initialize(QWidget *widget)
NS_IMETHODIMP NS_IMETHODIMP
nsCommonWidget::Show(PRBool aState) nsCommonWidget::Show(PRBool aState)
{ {
if (!mWidget) { mIsShown = aState;
//XXX: apperently can be null during the printing, check whether
// that's true // Ok, someone called show on a window that isn't sized to a sane
qDebug("nsCommon::Show : widget empty"); // value. Mark this window as needing to have Show() called on it
// and return.
if ((aState && !AreBoundsSane()) || !mWidget) {
qDebug("XX Bounds are insane or window hasn't been created yet");
mNeedsShow = PR_TRUE;
return NS_OK; return NS_OK;
} }
if (mContainer) // If someone is hiding this widget, clear any needing show flag.
mContainer->setShown(aState); if (!aState)
else mNeedsShow = PR_FALSE;
mWidget->setShown(aState);
// If someone is showing this window and it needs a resize then
// resize the widget.
if (aState && mNeedsResize) {
NativeResize(mBounds.width, mBounds.height,
PR_FALSE);
}
NativeShow(aState);
return NS_OK; return NS_OK;
} }
@ -299,7 +316,7 @@ nsCommonWidget::IsVisible(PRBool &visible)
} }
NS_IMETHODIMP NS_IMETHODIMP
nsCommonWidget::ConstrainPosition(int aAllowSlop, PRInt32 *aX, PRInt32 *aY) nsCommonWidget::ConstrainPosition(PRBool aAllowSlop, PRInt32 *aX, PRInt32 *aY)
{ {
if (mContainer) { if (mContainer) {
PRInt32 screenWidth = QApplication::desktop()->width(); PRInt32 screenWidth = QApplication::desktop()->width();
@ -361,28 +378,51 @@ nsCommonWidget::Resize(PRInt32 aWidth,
if (!mWidget || (mWidget->width() == aWidth && if (!mWidget || (mWidget->width() == aWidth &&
mWidget->height() == aHeight)) mWidget->height() == aHeight))
return NS_OK; return NS_OK;
qDebug("Resize: mWidget=%p, aWidth=%d,aHeight=%d", (void*)mWidget, aWidth, aHeight);
if (mWidget) { // There are several cases here that we need to handle, based on a
// matrix of the visibility of the widget, the sanity of this resize
// and whether or not the widget was previously sane.
// Has this widget been set to visible?
if (mIsShown) {
// Are the bounds sane?
if (AreBoundsSane()) { if (AreBoundsSane()) {
//if (mContainer) { // Yep? Resize the window
//mContainer->setGeometry( mBounds.x, mBounds.y, //Maybe, the toplevel has moved
//mBounds.width, mBounds.height); if (mContainer || mNeedsShow)
//} NativeResize(mBounds.x, mBounds.y,
mBounds.width, mBounds.height, aRepaint);
else
NativeResize(mBounds.width, mBounds.height, aRepaint);
mWidget->resize(mBounds.width, mBounds.height); // Does it need to be shown because it was previously insane?
if (mNeedsShow)
if (aRepaint) { NativeShow(PR_TRUE);
if (mWidget->isVisible()) }
mWidget->repaint(false); else {
// If someone has set this so that the needs show flag is false
// and it needs to be hidden, update the flag and hide the
// window. This flag will be cleared the next time someone
// hides the window or shows it. It also prevents us from
// calling NativeShow(PR_FALSE) excessively on the window which
// causes unneeded X traffic.
if (!mNeedsShow) {
mNeedsShow = PR_TRUE;
NativeShow(PR_FALSE);
} }
} }
} else if (mWidget) { }
// If the widget hasn't been shown, mark the widget as needing to be
// resized before it is shown.
else {
if (AreBoundsSane() && mListenForResizes) { if (AreBoundsSane() && mListenForResizes) {
//if (mContainer) // For widgets that we listen for resizes for (widgets created
// mContainer->resize(mBounds.width, mBounds.height); // with native parents) we apparently _always_ have to resize. I
mWidget->resize(mBounds.width, mBounds.height); // dunno why, but apparently we're lame like that.
NativeResize(aWidth, aHeight, aRepaint);
}
else {
mNeedsResize = PR_TRUE;
} }
} }
@ -415,19 +455,45 @@ nsCommonWidget::Resize(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight,
mWidget->width() == aWidth)) mWidget->width() == aWidth))
return NS_OK; return NS_OK;
qDebug("2 Resize: mWidget=%p, aWidth=%d, aHeight=%d, aX = %d, aY = %d", (void*)mWidget, aWidth, aHeight, aX, aY); // There are several cases here that we need to handle, based on a
// matrix of the visibility of the widget, the sanity of this resize
// and whether or not the widget was previously sane.
if (AreBoundsSane()) { // Has this widget been set to visible?
//if (mContainer) if (mIsShown) {
//mContainer->setGeometry(mBounds.x, mBounds.y, // Are the bounds sane?
//mBounds.width, mBounds.height); if (AreBoundsSane()) {
// Yep? Resize the window
NativeResize(aX, aY, aWidth, aHeight, aRepaint);
mWidget->setGeometry( mBounds.x, mBounds.y, // Does it need to be shown because it was previously insane?
mBounds.width, mBounds.height); if (mNeedsShow)
NativeShow(PR_TRUE);
if (aRepaint) { }
if (mWidget->isVisible()) else {
mWidget->repaint(false); // If someone has set this so that the needs show flag is false
// and it needs to be hidden, update the flag and hide the
// window. This flag will be cleared the next time someone
// hides the window or shows it. It also prevents us from
// calling NativeShow(PR_FALSE) excessively on the window which
// causes unneeded X traffic.
if (!mNeedsShow) {
mNeedsShow = PR_TRUE;
NativeShow(PR_FALSE);
}
}
}
// If the widget hasn't been shown, mark the widget as needing to be
// resized before it is shown
else {
if (AreBoundsSane() && mListenForResizes){
// For widgets that we listen for resizes for (widgets created
// with native parents) we apparently _always_ have to resize. I
// dunno why, but apparently we're lame like that.
NativeResize(aX, aY, aWidth, aHeight, aRepaint);
}
else {
mNeedsResize = PR_TRUE;
} }
} }
@ -1386,25 +1452,14 @@ bool nsCommonWidget::ignoreEvent(nsEventStatus aStatus) const
return(PR_FALSE); return(PR_FALSE);
} }
NS_METHOD nsCommonWidget::SetModal(PRBool aModal) NS_METHOD nsCommonWidget::SetModal(PRBool aModal)
{ {
qDebug("------------> SetModal mWidget=%p",(void*) mWidget); qDebug("------------> SetModal mWidget=%p",(void*) mWidget);
//mWidget->setModal(aModal);
return NS_OK;
}
// generic xp assumption is that events should be processed MozQWidget *mozWidget = dynamic_cast<MozQWidget*>(mWidget);
NS_METHOD nsCommonWidget::ModalEventFilter(PRBool aRealEvent, void *aEvent, PRBool *aForWindow) if (mozWidget)
{ mozWidget->setModal(aModal);
qDebug("ModalEventFilter mWidget=%p", (void*)mWidget);
if (!aRealEvent) {
*aForWindow = PR_FALSE;
return NS_OK;
}
*aForWindow = PR_TRUE;
return NS_OK; return NS_OK;
} }
@ -1414,3 +1469,45 @@ NS_IMETHODIMP nsCommonWidget::GetScreenBounds(nsRect &aRect)
WidgetToScreen(origin, aRect); WidgetToScreen(origin, aRect);
return NS_OK; return NS_OK;
} }
void
nsCommonWidget::NativeShow(PRBool aState)
{
mNeedsShow = PR_FALSE;
if (!mWidget) {
//XXX: apperently can be null during the printing, check whether
// that's true
qDebug("nsCommon::Show : widget empty");
return;
}
mWidget->setShown(aState);
}
void
nsCommonWidget::NativeResize(PRInt32 aWidth, PRInt32 aHeight, PRBool aRepaint)
{
mNeedsResize = PR_FALSE;
mWidget->resize( aWidth, aHeight);
if (aRepaint) {
if (mWidget->isVisible())
mWidget->repaint(false);
}
}
void
nsCommonWidget::NativeResize(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight,
PRBool aRepaint)
{
mNeedsResize = PR_FALSE;
mWidget->setGeometry( aX, aY, aWidth, aHeight);
if (aRepaint) {
if (mWidget->isVisible())
mWidget->repaint(false);
}
}

Просмотреть файл

@ -90,8 +90,7 @@ public:
NS_IMETHOD Scroll(PRInt32, PRInt32, nsRect*); NS_IMETHOD Scroll(PRInt32, PRInt32, nsRect*);
NS_IMETHOD ScrollWidgets(PRInt32 aDx, PRInt32 aDy); NS_IMETHOD ScrollWidgets(PRInt32 aDx, PRInt32 aDy);
NS_METHOD SetModal(PRBool aModal); NS_IMETHOD SetModal(PRBool aModal);
NS_METHOD ModalEventFilter(PRBool aRealEvent, void *aEvent, PRBool *aForWindow);
virtual void* GetNativeData(PRUint32); virtual void* GetNativeData(PRUint32);
@ -164,6 +163,10 @@ protected:
protected: protected:
virtual QWidget *createQWidget(QWidget *parent, nsWidgetInitData *aInitData) = 0; virtual QWidget *createQWidget(QWidget *parent, nsWidgetInitData *aInitData) = 0;
virtual void NativeResize(PRInt32, PRInt32, PRInt32, PRInt32, PRBool);
virtual void NativeResize(PRInt32, PRInt32, PRBool);
virtual void NativeShow(PRBool);
bool ignoreEvent(nsEventStatus aStatus) const; bool ignoreEvent(nsEventStatus aStatus) const;
/** /**
@ -192,6 +195,9 @@ protected:
QWidget *mWidget; QWidget *mWidget;
nsQtEventDispatcher *mDispatcher; nsQtEventDispatcher *mDispatcher;
PRPackedBool mListenForResizes; PRPackedBool mListenForResizes;
PRPackedBool mNeedsResize;
PRPackedBool mNeedsShow;
PRPackedBool mIsShown;
nsCOMPtr<nsIWidget> mParent; nsCOMPtr<nsIWidget> mParent;
private: private: