зеркало из https://github.com/mozilla/pjs.git
added support to offset child window to correct location.
This commit is contained in:
Родитель
06ef02bf00
Коммит
cb68173af5
|
@ -149,7 +149,8 @@ nsButton::~nsButton()
|
||||||
PRBool nsButton::OnPaint(nsPaintEvent &aEvent)
|
PRBool nsButton::OnPaint(nsPaintEvent &aEvent)
|
||||||
{
|
{
|
||||||
|
|
||||||
DrawWidget(FALSE);
|
|
||||||
|
DrawWidget(FALSE,aEvent.renderingContext);
|
||||||
return PR_FALSE;
|
return PR_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,26 +186,29 @@ nsButton::PtInWindow(PRInt32 aX,PRInt32 aY)
|
||||||
PRBool
|
PRBool
|
||||||
nsButton::DispatchMouseEvent(nsMouseEvent &aEvent)
|
nsButton::DispatchMouseEvent(nsMouseEvent &aEvent)
|
||||||
{
|
{
|
||||||
PRBool result;
|
PRBool result;
|
||||||
|
nsIRenderingContext *theRC;
|
||||||
|
|
||||||
|
theRC = this->GetRenderingContext();
|
||||||
|
|
||||||
switch (aEvent.message)
|
switch (aEvent.message)
|
||||||
{
|
{
|
||||||
case NS_MOUSE_LEFT_BUTTON_DOWN:
|
case NS_MOUSE_LEFT_BUTTON_DOWN:
|
||||||
mMouseDownInButton = PR_TRUE;
|
mMouseDownInButton = PR_TRUE;
|
||||||
DrawWidget(PR_TRUE);
|
DrawWidget(PR_TRUE,theRC);
|
||||||
result = nsWindow::DispatchMouseEvent(aEvent);
|
result = nsWindow::DispatchMouseEvent(aEvent);
|
||||||
result = nsEventStatus_eConsumeDoDefault;
|
result = nsEventStatus_eConsumeDoDefault;
|
||||||
break;
|
break;
|
||||||
case NS_MOUSE_LEFT_BUTTON_UP:
|
case NS_MOUSE_LEFT_BUTTON_UP:
|
||||||
mMouseDownInButton = PR_FALSE;
|
mMouseDownInButton = PR_FALSE;
|
||||||
DrawWidget(PR_TRUE);
|
DrawWidget(PR_TRUE,theRC);
|
||||||
if(mWidgetArmed==PR_TRUE)
|
if(mWidgetArmed==PR_TRUE)
|
||||||
result = nsWindow::DispatchMouseEvent(aEvent);
|
result = nsWindow::DispatchMouseEvent(aEvent);
|
||||||
break;
|
break;
|
||||||
case NS_MOUSE_EXIT:
|
case NS_MOUSE_EXIT:
|
||||||
if(mMouseDownInButton)
|
if(mMouseDownInButton)
|
||||||
{
|
{
|
||||||
DrawWidget(PR_FALSE);
|
DrawWidget(PR_FALSE,theRC);
|
||||||
mWidgetArmed = PR_FALSE;
|
mWidgetArmed = PR_FALSE;
|
||||||
}
|
}
|
||||||
result = nsWindow::DispatchMouseEvent(aEvent);
|
result = nsWindow::DispatchMouseEvent(aEvent);
|
||||||
|
@ -212,7 +216,7 @@ PRBool result;
|
||||||
case NS_MOUSE_ENTER:
|
case NS_MOUSE_ENTER:
|
||||||
if(mMouseDownInButton)
|
if(mMouseDownInButton)
|
||||||
{
|
{
|
||||||
DrawWidget(PR_TRUE);
|
DrawWidget(PR_TRUE,theRC);
|
||||||
mWidgetArmed = PR_TRUE;
|
mWidgetArmed = PR_TRUE;
|
||||||
}
|
}
|
||||||
result = nsWindow::DispatchMouseEvent(aEvent);
|
result = nsWindow::DispatchMouseEvent(aEvent);
|
||||||
|
@ -230,7 +234,7 @@ PRBool result;
|
||||||
* @return nothing is returned
|
* @return nothing is returned
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
nsButton::DrawWidget(PRBool aMouseInside)
|
nsButton::DrawWidget(PRBool aMouseInside,nsIRenderingContext *aTheContext)
|
||||||
{
|
{
|
||||||
PRInt16 width,x,y;
|
PRInt16 width,x,y;
|
||||||
PRInt32 offx,offy;
|
PRInt32 offx,offy;
|
||||||
|
@ -239,7 +243,7 @@ Rect macrect,crect;
|
||||||
GrafPtr theport;
|
GrafPtr theport;
|
||||||
RGBColor blackcolor = {0,0,0};
|
RGBColor blackcolor = {0,0,0};
|
||||||
RgnHandle thergn;
|
RgnHandle thergn;
|
||||||
//FontInfo fi;
|
|
||||||
|
|
||||||
CalcOffset(offx,offy);
|
CalcOffset(offx,offy);
|
||||||
GetPort(&theport);
|
GetPort(&theport);
|
||||||
|
|
|
@ -69,7 +69,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void DrawWidget(PRBool aMouseInside);
|
void DrawWidget(PRBool aMouseInside,nsIRenderingContext *aRContext);
|
||||||
|
|
||||||
nsString mLabel;
|
nsString mLabel;
|
||||||
PRBool mMouseDownInButton;
|
PRBool mMouseDownInButton;
|
||||||
|
|
|
@ -184,9 +184,10 @@ WindowPtr whichwindow;
|
||||||
nsWindow *thewindow;
|
nsWindow *thewindow;
|
||||||
nsRect rect;
|
nsRect rect;
|
||||||
RgnHandle updateregion;
|
RgnHandle updateregion;
|
||||||
nsPaintEvent pevent;
|
nsPaintEvent pEvent;
|
||||||
nsRefData *theRefData;
|
nsRefData *theRefData;
|
||||||
|
|
||||||
|
|
||||||
::GetPort(&curport);
|
::GetPort(&curport);
|
||||||
whichwindow = (WindowPtr)aTheEvent->message;
|
whichwindow = (WindowPtr)aTheEvent->message;
|
||||||
|
|
||||||
|
@ -208,17 +209,18 @@ nsRefData *theRefData;
|
||||||
rect.height = bounds.top + (bounds.bottom-bounds.top);
|
rect.height = bounds.top + (bounds.bottom-bounds.top);
|
||||||
|
|
||||||
// generate a paint event
|
// generate a paint event
|
||||||
pevent.message = NS_PAINT;
|
pEvent.message = NS_PAINT;
|
||||||
pevent.widget = thewindow;
|
pEvent.renderingContext = thewindow->GetRenderingContext();
|
||||||
pevent.eventStructType = NS_PAINT_EVENT;
|
pEvent.widget = thewindow;
|
||||||
pevent.point.x = 0;
|
pEvent.eventStructType = NS_PAINT_EVENT;
|
||||||
pevent.point.y = 0;
|
pEvent.point.x = 0;
|
||||||
pevent.rect = ▭
|
pEvent.point.y = 0;
|
||||||
pevent.time = 0;
|
pEvent.rect = ▭
|
||||||
thewindow->OnPaint(pevent);
|
pEvent.time = 0;
|
||||||
|
thewindow->OnPaint(pEvent);
|
||||||
|
|
||||||
// take care of the childern
|
// take care of the childern
|
||||||
thewindow->DoPaintWidgets(updateregion);
|
thewindow->DoPaintWidgets(updateregion,pEvent.renderingContext);
|
||||||
}
|
}
|
||||||
EndUpdate(whichwindow);
|
EndUpdate(whichwindow);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1071,25 +1071,14 @@ nsRect rr;
|
||||||
GetBounds(rr);
|
GetBounds(rr);
|
||||||
event.rect = &rr;
|
event.rect = &rr;
|
||||||
|
|
||||||
event.renderingContext = nsnull;
|
|
||||||
static NS_DEFINE_IID(kRenderingContextCID, NS_RENDERING_CONTEXT_CID);
|
|
||||||
static NS_DEFINE_IID(kRenderingContextIID, NS_IRENDERING_CONTEXT_IID);
|
|
||||||
|
|
||||||
if (NS_OK == nsRepository::CreateInstance(kRenderingContextCID,
|
|
||||||
nsnull,
|
|
||||||
kRenderingContextIID,
|
|
||||||
(void **)&event.renderingContext))
|
|
||||||
{
|
{
|
||||||
PRInt32 offx,offy;
|
PRInt32 offx,offy;
|
||||||
GrafPtr theport;
|
GrafPtr theport;
|
||||||
Rect macrect;
|
Rect macrect;
|
||||||
nsRect therect;
|
nsRect therect;
|
||||||
RgnHandle thergn;
|
RgnHandle thergn;
|
||||||
RGBColor redcolor = {0xff00,0,0};
|
|
||||||
RGBColor greencolor = {0,0xff00,0};
|
|
||||||
|
|
||||||
|
CalcTotalOffset(offx,offy);
|
||||||
CalcOffset(offx,offy);
|
|
||||||
GetPort(&theport);
|
GetPort(&theport);
|
||||||
::SetPort(mWindowPtr);
|
::SetPort(mWindowPtr);
|
||||||
::SetOrigin(-offx,-offy);
|
::SetOrigin(-offx,-offy);
|
||||||
|
@ -1102,8 +1091,8 @@ nsRect rr;
|
||||||
::GetClip(thergn);
|
::GetClip(thergn);
|
||||||
::ClipRect(¯ect);
|
::ClipRect(¯ect);
|
||||||
::PenNormal();
|
::PenNormal();
|
||||||
::RGBForeColor(&greencolor);
|
//::RGBForeColor(&greencolor);
|
||||||
::FrameRect(¯ect);
|
//::FrameRect(¯ect);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1115,22 +1104,11 @@ nsRect rr;
|
||||||
thergn = ::NewRgn();
|
thergn = ::NewRgn();
|
||||||
::GetClip(thergn);
|
::GetClip(thergn);
|
||||||
::ClipRect(¯ect);
|
::ClipRect(¯ect);
|
||||||
::PenNormal();
|
|
||||||
::RGBForeColor(&redcolor);
|
|
||||||
::EraseRect(¯ect);
|
|
||||||
::FrameRect(¯ect);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result = (DispatchWindowEvent(&event));
|
||||||
SetOrigin(0,0);
|
SetOrigin(0,0);
|
||||||
SetPort(theport);
|
SetPort(theport);
|
||||||
|
|
||||||
event.renderingContext->Init(mContext, this);
|
|
||||||
result = (DispatchWindowEvent(&event));
|
|
||||||
NS_RELEASE(event.renderingContext);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
result = PR_FALSE;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -1311,20 +1289,22 @@ nsWindow::PtInWindow(PRInt32 aX,PRInt32 aY)
|
||||||
{
|
{
|
||||||
PRBool result = PR_FALSE;
|
PRBool result = PR_FALSE;
|
||||||
nsPoint hitPt(aX,aY);
|
nsPoint hitPt(aX,aY);
|
||||||
nsRect bounds;
|
nsRect bounds,newbounds;
|
||||||
PRInt32 offx,offy;
|
PRInt32 offx,offy;
|
||||||
|
|
||||||
GetBounds(bounds);
|
GetBounds(bounds);
|
||||||
|
|
||||||
if(this->GetParent())
|
if(this->GetParent())
|
||||||
{
|
{
|
||||||
CalcOffset(offx,offy);
|
CalcOffset(offx,offy);
|
||||||
bounds.MoveBy(offx,offy);
|
bounds.x +=offx;
|
||||||
|
bounds.y +=offy;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
offx = bounds.x;
|
// no parent, the bounds in global, so make a local coorinate system at 0,0
|
||||||
offy = bounds.y;
|
bounds.x = 0;
|
||||||
bounds.MoveBy(-offx,-offy);
|
bounds.y = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(bounds.Contains(hitPt))
|
if(bounds.Contains(hitPt))
|
||||||
|
@ -1377,11 +1357,12 @@ void nsWindow::MacRectToNSRect(const Rect& aMacRect, nsRect& aRect) const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
//
|
//========================================================================
|
||||||
// Locate the widget that contains the point
|
/*
|
||||||
//
|
* Find the widget hit
|
||||||
//-------------------------------------------------------------------------
|
@param aThePoint -- a point in local coordinats to test for the hit.
|
||||||
|
*/
|
||||||
nsWindow*
|
nsWindow*
|
||||||
nsWindow::FindWidgetHit(Point aThePoint)
|
nsWindow::FindWidgetHit(Point aThePoint)
|
||||||
{
|
{
|
||||||
|
@ -1423,7 +1404,7 @@ nsRect rect;
|
||||||
* @return nothing is returned
|
* @return nothing is returned
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
nsWindow::DoPaintWidgets(RgnHandle aTheRegion)
|
nsWindow::DoPaintWidgets(RgnHandle aTheRegion,nsIRenderingContext *aRC)
|
||||||
{
|
{
|
||||||
nsWindow *child = this;
|
nsWindow *child = this;
|
||||||
nsRect rect;
|
nsRect rect;
|
||||||
|
@ -1455,6 +1436,7 @@ nsPaintEvent pevent;
|
||||||
|
|
||||||
// generate a paint event
|
// generate a paint event
|
||||||
pevent.message = NS_PAINT;
|
pevent.message = NS_PAINT;
|
||||||
|
pevent.renderingContext = aRC;
|
||||||
pevent.widget = child;
|
pevent.widget = child;
|
||||||
pevent.eventStructType = NS_PAINT_EVENT;
|
pevent.eventStructType = NS_PAINT_EVENT;
|
||||||
pevent.point.x = 0;
|
pevent.point.x = 0;
|
||||||
|
@ -1464,7 +1446,7 @@ nsPaintEvent pevent;
|
||||||
child->OnPaint(pevent);
|
child->OnPaint(pevent);
|
||||||
|
|
||||||
// now go check out the childern
|
// now go check out the childern
|
||||||
child->DoPaintWidgets(aTheRegion);
|
child->DoPaintWidgets(aTheRegion,aRC);
|
||||||
}
|
}
|
||||||
child = (nsWindow*)mChildren->Next();
|
child = (nsWindow*)mChildren->Next();
|
||||||
}
|
}
|
||||||
|
@ -1574,6 +1556,36 @@ nsRect therect;
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
/* Calculate the x and y offsets for this particular widget
|
||||||
|
* @update ps 09/22/98
|
||||||
|
* @param aX -- x offset amount
|
||||||
|
* @param aY -- y offset amount
|
||||||
|
* @return NOTHING
|
||||||
|
*/
|
||||||
|
NS_IMETHODIMP nsWindow::CalcTotalOffset(PRInt32 &aX,PRInt32 &aY)
|
||||||
|
{
|
||||||
|
nsIWidget *theparent,*child;
|
||||||
|
nsRect therect;
|
||||||
|
|
||||||
|
aX = mBounds.x;
|
||||||
|
aY = mBounds.y;
|
||||||
|
theparent = this->GetParent();
|
||||||
|
while(theparent)
|
||||||
|
{
|
||||||
|
theparent->GetBounds(therect);
|
||||||
|
child = theparent->GetParent();
|
||||||
|
if(child)
|
||||||
|
{
|
||||||
|
aX += therect.x;
|
||||||
|
aY += therect.y;
|
||||||
|
}
|
||||||
|
theparent = child;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
|
|
@ -147,7 +147,7 @@ public:
|
||||||
NS_IMETHOD SetBounds(const Rect& aMacRect);
|
NS_IMETHOD SetBounds(const Rect& aMacRect);
|
||||||
void MacRectToNSRect(const Rect& aMacRect, nsRect& aRect) const;
|
void MacRectToNSRect(const Rect& aMacRect, nsRect& aRect) const;
|
||||||
void nsRectToMacRect(const nsRect& aRect, Rect& aMacRect) const;
|
void nsRectToMacRect(const nsRect& aRect, Rect& aMacRect) const;
|
||||||
void DoPaintWidgets(RgnHandle aTheRegion);
|
void DoPaintWidgets(RgnHandle aTheRegion,nsIRenderingContext *aRC);
|
||||||
void DoResizeWidgets(nsSizeEvent &aEvent);
|
void DoResizeWidgets(nsSizeEvent &aEvent);
|
||||||
PRBool RgnIntersects(RgnHandle aTheRegion,RgnHandle aIntersectRgn);
|
PRBool RgnIntersects(RgnHandle aTheRegion,RgnHandle aIntersectRgn);
|
||||||
|
|
||||||
|
@ -191,6 +191,7 @@ protected:
|
||||||
NS_IMETHOD UpdateVisibilityFlag();
|
NS_IMETHOD UpdateVisibilityFlag();
|
||||||
NS_IMETHOD UpdateDisplay();
|
NS_IMETHOD UpdateDisplay();
|
||||||
NS_IMETHOD CalcOffset(PRInt32 &aX,PRInt32 &aY);
|
NS_IMETHOD CalcOffset(PRInt32 &aX,PRInt32 &aY);
|
||||||
|
NS_IMETHOD CalcTotalOffset(PRInt32 &aX,PRInt32 &aY);
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
Загрузка…
Ссылка в новой задаче