diff --git a/widget/src/mac/nsButton.cpp b/widget/src/mac/nsButton.cpp index 392fff6c1254..442a36963a18 100644 --- a/widget/src/mac/nsButton.cpp +++ b/widget/src/mac/nsButton.cpp @@ -25,7 +25,6 @@ #include "nsStringUtil.h" #include "nsUnitConversion.h" -#include #include @@ -103,10 +102,6 @@ void nsButton::Create(nsIWidget *aParent, Rect r; nsRectToMacRect(aRect,r); - //mControl = NewControl ( window, &r, title, visible, - //initialValue, minValue, maxValue, - //ctrlType, (long)this); - mWindowRegion = NewRgn(); SetRectRgn(mWindowRegion,aRect.x,aRect.y,aRect.x+aRect.width,aRect.y+aRect.height); @@ -214,7 +209,7 @@ PRBool result; //------------------------------------------------------------------------- -/* Track this control and draw in the different modes depending on the state of the mouse and buttons +/* Draw in the different modes depending on the state of the mouse and buttons * @update dc 08/31/98 * @param aMouseInside -- A boolean indicating if the mouse is inside the control * @return nothing is returned diff --git a/widget/src/mac/nsScrollbar.cpp b/widget/src/mac/nsScrollbar.cpp index a14cf71564a3..37276b022e57 100644 --- a/widget/src/mac/nsScrollbar.cpp +++ b/widget/src/mac/nsScrollbar.cpp @@ -20,89 +20,35 @@ #include "nsToolkit.h" #include "nsGUIEvent.h" #include "nsUnitConversion.h" -#include -#include "nsXtEventHandler.h" +NS_IMPL_ADDREF(nsScrollbar) +NS_IMPL_RELEASE(nsScrollbar) -#define DBG 0 - -//------------------------------------------------------------------------- -// -// nsScrollbar constructor -// -//------------------------------------------------------------------------- -nsScrollbar::nsScrollbar(nsISupports *aOuter, PRBool aIsVertical) : nsWindow(aOuter) +//================================================================= +/* Constructor for the scrollbar + * @update gpk 08/27/98 + * @param aX -- x offset in widget local coordinates + * @param aY -- y offset in widget local coordinates + * @return PR_TRUE if the pt is contained in the widget + */ +nsScrollbar::nsScrollbar(PRBool aIsVertical) { strcpy(gInstanceClassName, "nsScrollbar"); - mOrientation = (aIsVertical) ? XmVERTICAL : XmHORIZONTAL; + mIsVertical = aIsVertical; mLineIncrement = 0; } -//------------------------------------------------------------------------- -// -// Create -// -//------------------------------------------------------------------------- -void nsScrollbar::Create(nsNativeWidget aParent, - const nsRect &aRect, - EVENT_CALLBACK aHandleEventFunction, - nsIDeviceContext *aContext, - nsIAppShell *aAppShell, - nsIToolkit *aToolkit, - nsWidgetInitData *aInitData) -{ - Widget parentWidget = (Widget)aParent; - strcpy(gInstanceClassName, "nsScrollbar"); - - int procDir = mOrientation == XmVERTICAL? XmMAX_ON_BOTTOM:XmMAX_ON_RIGHT; - - mWidget = ::XtVaCreateManagedWidget("scrollbar", - xmScrollBarWidgetClass, - parentWidget, - XmNorientation, mOrientation, - XmNprocessingDirection, procDir, - XmNwidth, aRect.width, - XmNheight, aRect.height, - XmNrecomputeSize, False, - XmNhighlightOnEnter, False, - XmNminimum, 0, - XmNmaximum, 100, - XmNx, aRect.x, - XmNy, aRect.y, - nsnull); - - // save the event callback function - mEventCallback = aHandleEventFunction; - - //InitCallbacks(); - XtAddCallback(mWidget, - XmNdragCallback, - nsXtWidget_Scrollbar_Callback, - this); - - XtAddCallback(mWidget, - XmNdecrementCallback, - nsXtWidget_Scrollbar_Callback, - this); - - XtAddCallback(mWidget, - XmNincrementCallback, - nsXtWidget_Scrollbar_Callback, - this); - - XtAddCallback(mWidget, - XmNvalueChangedCallback, - nsXtWidget_Scrollbar_Callback, - this); - - /*XtAddCallback(mWidget, - XmNresizeCallback, - nsXtWidget_Resize_Callback, - this);*/ - -} - +//================================================================= +/* Creates a scrollbar with aParent as the widgets parent + * @update dc 09/16/98 + * @param aParent -- The parent of this widget + * @param aHandleEventFunction -- Eventhandler + * @param aContext -- Device context for widget + * @param aToolkit -- Tookkit for all the widgets + * @param aInitData -- + * @return nothing + */ void nsScrollbar::Create(nsIWidget *aParent, const nsRect &aRect, EVENT_CALLBACK aHandleEventFunction, @@ -111,15 +57,74 @@ void nsScrollbar::Create(nsIWidget *aParent, nsIToolkit *aToolkit, nsWidgetInitData *aInitData) { - Widget parentWidget; + mParent = aParent; + aParent->AddChild(this); + + WindowPtr window = nsnull; - if (aParent) { - parentWidget = (Widget) aParent->GetNativeData(NS_NATIVE_WIDGET); - } else { - parentWidget = (Widget) aAppShell->GetNativeData(NS_NATIVE_SHELL); - } + if (aParent) + { + window = (WindowPtr) aParent->GetNativeData(NS_NATIVE_WIDGET); + } + else + if (aAppShell) + { + window = (WindowPtr) aAppShell->GetNativeData(NS_NATIVE_SHELL); + } - Create((nsNativeWidget)parentWidget, aRect, aHandleEventFunction, aContext, aAppShell, aToolkit, aInitData); + mIsMainWindow = PR_FALSE; + mWindowMadeHere = PR_TRUE; + mWindowRecord = (WindowRecord*)window; + mWindowPtr = (WindowPtr)window; + + NS_ASSERTION(window!=nsnull,"The WindowPtr for the widget cannot be null") + if (window) + { + InitToolkit(aToolkit, aParent); + // InitDeviceContext(aContext, parentWidget); + + // Set the bounds to the local rect + SetBounds(aRect); + + // Convert to macintosh coordinates + Rect r; + nsRectToMacRect(aRect,r); + + mWindowRegion = NewRgn(); + SetRectRgn(mWindowRegion,aRect.x,aRect.y,aRect.x+aRect.width,aRect.y+aRect.height); + + // save the event callback function + mEventCallback = aHandleEventFunction; + + mMouseDownInButton = PR_FALSE; + mWidgetArmed = PR_FALSE; + + //InitCallbacks("nsButton"); + InitDeviceContext(mContext, (nsNativeWidget)mWindowPtr); + } + +} + +//================================================================= +/* Creates a scrollbar with aParent as the widgets parent, this should never be called + * @update dc 09/16/98 + * @param aParent -- The parent of this widget + * @param aHandleEventFunction -- Eventhandler + * @param aContext -- Device context for widget + * @param aToolkit -- Tookkit for all the widgets + * @param aInitData -- + * @return nothing + */ +void nsScrollbar::Create(nsNativeWidget aParent, + const nsRect &aRect, + EVENT_CALLBACK aHandleEventFunction, + nsIDeviceContext *aContext, + nsIAppShell *aAppShell, + nsIToolkit *aToolkit, + nsWidgetInitData *aInitData) +{ + + NS_ERROR("This Widget must not use this Create method"); } @@ -133,132 +138,246 @@ nsScrollbar::~nsScrollbar() } -//------------------------------------------------------------------------- -// -// Query interface implementation -// -//------------------------------------------------------------------------- -nsresult nsScrollbar::QueryObject(const nsIID& aIID, void** aInstancePtr) +/** + * Implement the standard QueryInterface for NS_IWIDGET_IID and NS_ISUPPORTS_IID + * @param aIID The name of the class implementing the method + * @param _classiiddef The name of the #define symbol that defines the IID + * for the class (e.g. NS_ISUPPORTS_IID) +*/ +nsresult nsScrollbar::QueryInterface(const nsIID& aIID, void** aInstancePtr) { - static NS_DEFINE_IID(kInsScrollbarIID, NS_ISCROLLBAR_IID); - - if (aIID.Equals(kInsScrollbarIID)) { - AddRef(); - *aInstancePtr = (void**) &mAggWidget; - return NS_OK; - } - return nsWindow::QueryObject(aIID, aInstancePtr); - -} - - -//------------------------------------------------------------------------- -// -// Define the range settings -// -//------------------------------------------------------------------------- -void nsScrollbar::SetMaxRange(PRUint32 aEndRange) -{ - int max = aEndRange; - XtVaGetValues(mWidget, XmNmaximum, &max, nsnull); - if (DBG) printf("SetMaxRange %d\n", max); - -} - - -//------------------------------------------------------------------------- -// -// Return the range settings -// -//------------------------------------------------------------------------- -PRUint32 nsScrollbar::GetMaxRange() -{ - int maxRange = 0; - XtVaGetValues(mWidget, XmNmaximum, &maxRange, nsnull); - return (PRUint32)maxRange; -} - - -//------------------------------------------------------------------------- -// -// Set the thumb position -// -//------------------------------------------------------------------------- -void nsScrollbar::SetPosition(PRUint32 aPos) -{ - int pos = (int)aPos; - if (DBG) printf("SetPosition %d\n", pos); - XtVaSetValues(mWidget, XmNvalue, pos, nsnull); -} - - -//------------------------------------------------------------------------- -// -// Get the current thumb position. -// -//------------------------------------------------------------------------- -PRUint32 nsScrollbar::GetPosition() -{ - int pagePos = 0; - XtVaGetValues(mWidget, XmNvalue, &pagePos, nsnull); - - return (PRUint32)pagePos; -} - - -//------------------------------------------------------------------------- -// -// Set the thumb size -// -//------------------------------------------------------------------------- -void nsScrollbar::SetThumbSize(PRUint32 aSize) -{ - if (aSize > 0) { - XtVaSetValues(mWidget, XmNpageIncrement, (int)aSize, nsnull); - XtVaSetValues(mWidget, XmNsliderSize, (int)aSize, nsnull); + if (NULL == aInstancePtr) { + return NS_ERROR_NULL_POINTER; } - if (DBG) printf("SetThumbSize %d\n", aSize); + + static NS_DEFINE_IID(kIScrollbarIID, NS_ISCROLLBAR_IID); + if (aIID.Equals(kIScrollbarIID)) { + *aInstancePtr = (void*) ((nsIScrollbar*)this); + AddRef(); + return NS_OK; + } + + return nsWindow::QueryInterface(aIID,aInstancePtr); +} + +//================================================================= +/* Handle a mousedown event + * @update dc 09/16/98 + * @param nsMouseEvent -- the mouse event to handle + * @return -- True if the event was handled + */ +PRBool +nsScrollbar::DispatchMouseEvent(nsMouseEvent &aEvent) +{ +PRBool result; + + switch (aEvent.message) + { + case NS_MOUSE_LEFT_BUTTON_DOWN: + mMouseDownInButton = PR_TRUE; + DrawWidget(); + result = nsWindow::DispatchMouseEvent(aEvent); + break; + case NS_MOUSE_LEFT_BUTTON_UP: + mMouseDownInButton = PR_FALSE; + DrawWidget(); + if(mWidgetArmed==PR_TRUE) + result = nsWindow::DispatchMouseEvent(aEvent); + break; + case NS_MOUSE_EXIT: + DrawWidget(); + mWidgetArmed = PR_FALSE; + result = nsWindow::DispatchMouseEvent(aEvent); + break; + case NS_MOUSE_ENTER: + DrawWidget(); + mWidgetArmed = PR_TRUE; + result = nsWindow::DispatchMouseEvent(aEvent); + break; + case NS_MOUSE_MOVE: + if(mWidgetArmed) + { + + this->SetPosition(); + this->DrawWidget(); + } + break; + } + + return result; +} + +//------------------------------------------------------------------------- +/* Draw in the different modes depending on the state of the mouse and buttons + * @update dc 08/31/98 + * @param aMouseInside -- A boolean indicating if the mouse is inside the control + * @return nothing is returned + */ +void +nsScrollbar::DrawWidget() +{ +PRInt16 thumbwidth,thumbheight; +PRInt16 width,x,y,tw; +nsRect therect,tr; +Rect macrect; +GrafPtr theport; +RGBColor blackcolor = {0,0,0}; +RgnHandle thergn; + + + GetPort(&theport); + ::SetPort(mWindowPtr); + GetBounds(therect); + nsRectToMacRect(therect,macrect); + thergn = ::NewRgn(); + ::GetClip(thergn); + ::ClipRect(¯ect); + ::PenNormal(); + ::RGBForeColor(&blackcolor); + + // Frame the general scrollbar + ::FrameRect(¯ect); + + + // draw the thumb + if(mIsVertical) + { + tr.width = therect.width; + tr.height = mThumbSize; + tr.x = therect.x; + tr.y = therect.y+mPosition; + } + else + { + tr.width = mThumbSize; + tr.height = therect.height; + tr.x = therect.x+mPosition; + tr.y = therect.y; + } + + nsRectToMacRect(tr,macrect); + ::PaintRect(¯ect); + + ::PenSize(1,1); + ::SetClip(thergn); + ::SetPort(theport); +} + +//================================================================= +/* set the maximum range of a scroll bar + * @update dc 09/16/98 + * @param aMaxRange -- the maximum to set this to + * @return -- If a good size was returned + */ +NS_METHOD nsScrollbar::SetMaxRange(PRUint32 aEndRange) +{ + mMaxRange = aEndRange; + return (NS_OK); +} + +//================================================================= +/* get the maximum range of a scroll bar + * @update dc 09/16/98 + * @param aMaxRange -- The current maximum this slider can be + * @return -- If a good size was returned + */ +NS_METHOD nsScrollbar::GetMaxRange(PRUint32& aMaxRange) +{ + aMaxRange = mMaxRange; + return (NS_OK); +} + +//================================================================= +/* set the current position of the slider + * @update dc 09/16/98 + * @param aMaxRange -- The current value to set the slider position to. + * @return -- NS_OK if the position is valid + */ +NS_METHOD nsScrollbar::SetPosition(PRUint32 aPos) +{ + if(aPos>=0) + { + mPosition = aPos; + this->DrawWidget(); + return (NS_OK); + } + else + return(NS_ERROR_FAILURE); } -//------------------------------------------------------------------------- -// -// Get the thumb size -// -//------------------------------------------------------------------------- -PRUint32 nsScrollbar::GetThumbSize() +//================================================================= +/* get the current position of the slider + * @update dc 09/16/98 + * @param aMaxRange -- The current slider position. + * @return -- NS_OK if the position is valid + */ +NS_METHOD nsScrollbar::GetPosition(PRUint32& aPos) { - int pageSize = 0; - XtVaGetValues(mWidget, XmNpageIncrement, &pageSize, nsnull); - - return (PRUint32)pageSize; + aPos = mPosition; + return (NS_OK); } -//------------------------------------------------------------------------- -// -// Set the line increment for this scrollbar -// -//------------------------------------------------------------------------- -void nsScrollbar::SetLineIncrement(PRUint32 aLineIncrement) +//================================================================= +/* Set the hieght of a vertical, or width of a horizontal scroll bar thumb control + * @update dc 09/16/98 + * @param aSize -- the size to set the thumb control to + * @return -- NS_OK if the position is valid + */ +NS_METHOD nsScrollbar::SetThumbSize(PRUint32 aSize) { - if (aLineIncrement > 0) { + if (aSize > 0) + { + mThumbSize = aSize; + this->DrawWidget(); + return(NS_OK); + } + else + return(NS_ERROR_FAILURE); +} + + +//================================================================= +/* get the height of a vertical, or width of a horizontal scroll bar thumb control + * @update dc 09/16/98 + * @param aSize -- the size to set the thumb control to + * @return -- NS_OK if the position is valid + */ +NS_METHOD nsScrollbar::GetThumbSize(PRUint32& aSize) +{ + + aSize = mThumbSize; + return(NS_OK); +} + + +//================================================================= +/* Set the increment of the scroll bar + * @update dc 09/16/98 + * @param aLineIncrement -- the control increment + * @return -- NS_OK if the position is valid + */ +NS_METHOD nsScrollbar::SetLineIncrement(PRUint32 aLineIncrement) +{ + if (aLineIncrement > 0) + { mLineIncrement = aLineIncrement; - XtVaSetValues(mWidget, XmNincrement, aLineIncrement, nsnull); - } - - if (DBG) printf("SetLineIncrement %d\n", aLineIncrement); + } + return(NS_OK); } -//------------------------------------------------------------------------- -// -// Get the line increment for this scrollbar -// -//------------------------------------------------------------------------- -PRUint32 nsScrollbar::GetLineIncrement() +//================================================================= +/* Get the increment of the scroll bar + * @update dc 09/16/98 + * @param aLineIncrement -- the control increment + * @return NS_OK if the position is valid + */ +NS_METHOD nsScrollbar::GetLineIncrement(PRUint32& aLineIncrement) { - return mLineIncrement; + aLineIncrement = mLineIncrement; + return(NS_OK); } @@ -267,30 +386,17 @@ PRUint32 nsScrollbar::GetLineIncrement() // Set all scrolling parameters // //------------------------------------------------------------------------- -void nsScrollbar::SetParameters(PRUint32 aMaxRange, PRUint32 aThumbSize, +NS_METHOD nsScrollbar::SetParameters(PRUint32 aMaxRange, PRUint32 aThumbSize, PRUint32 aPosition, PRUint32 aLineIncrement) { - int thumbSize = (((int)aThumbSize) > 0?aThumbSize:1); - int maxRange = (((int)aMaxRange) > 0?aMaxRange:10); - mLineIncrement = (((int)aLineIncrement) > 0?aLineIncrement:1); + mThumbSize = (((int)aThumbSize) > 0?aThumbSize:1); + mMaxRange = (((int)aMaxRange) > 0?aMaxRange:10); + mLineIncrement = (((int)aLineIncrement) > 0?aLineIncrement:1); - int maxPos = maxRange - thumbSize; - int pos = ((int)aPosition) > maxPos ? maxPos-1 : ((int)aPosition); - - if (DBG) printf("SetParameters Max: %6d Thumb: %4d Pos: %4d Line: %4d \n", - maxRange, thumbSize, - pos, mLineIncrement); - - XtVaSetValues(mWidget, - XmNincrement, mLineIncrement, - XmNminimum, 0, - XmNmaximum, maxRange, - XmNsliderSize, thumbSize, - XmNpageIncrement, thumbSize, - XmNvalue, pos, - nsnull); + mPosition = ((int)aPosition) > mMaxRange ? mMaxRange-1 : ((int)aPosition); + return(NS_OK); } @@ -301,14 +407,14 @@ void nsScrollbar::SetParameters(PRUint32 aMaxRange, PRUint32 aThumbSize, //------------------------------------------------------------------------- PRBool nsScrollbar::OnPaint(nsPaintEvent & aEvent) { - return PR_FALSE; + DrawWidget(); + return PR_FALSE; } PRBool nsScrollbar::OnResize(nsSizeEvent &aEvent) { - if (DBG) printf("*&*&*&*&*&*&*()()()()(((( nsScrollbar::OnResize\n"); return nsWindow::OnResize(aEvent); //return PR_FALSE; } @@ -319,9 +425,6 @@ int nsScrollbar::AdjustScrollBarPosition(int aPosition) int maxRange; int sliderSize; - XtVaGetValues(mWidget, XmNmaximum, &maxRange, - XmNsliderSize, &sliderSize, - nsnull); int cap = maxRange - sliderSize; return aPosition > cap ? cap : aPosition; } @@ -333,176 +436,104 @@ int nsScrollbar::AdjustScrollBarPosition(int aPosition) //------------------------------------------------------------------------- PRBool nsScrollbar::OnScroll(nsScrollbarEvent & aEvent, PRUint32 cPos) { - PRBool result = PR_TRUE; - int newPosition; +PRBool result = PR_TRUE; +int newPosition; +int range; - switch (aEvent.message) { + switch (aEvent.message) + { + // scroll one line right or down + case NS_SCROLLBAR_LINE_NEXT: + { + newPosition += mLineIncrement; + PRUint32 max = GetMaxRange(range) - GetThumbSize(range); + if (newPosition > (int)max) + newPosition = (int)max; - // scroll one line right or down - case NS_SCROLLBAR_LINE_NEXT: - { - XtVaGetValues(mWidget, XmNvalue, &newPosition, nsnull); - newPosition += mLineIncrement; - PRUint32 max = GetMaxRange() - GetThumbSize(); - if (newPosition > (int)max) - newPosition = (int)max; + // if an event callback is registered, give it the chance + // to change the increment + if (mEventCallback) + { + aEvent.position = newPosition; + result = ConvertStatus((*mEventCallback)(&aEvent)); + newPosition = aEvent.position; + } + break; + } - // if an event callback is registered, give it the chance - // to change the increment - if (mEventCallback) { - aEvent.position = newPosition; - result = ConvertStatus((*mEventCallback)(&aEvent)); - newPosition = aEvent.position; - } - - XtVaSetValues(mWidget, XmNvalue, - AdjustScrollBarPosition(newPosition), nsnull); - break; - } + // scroll one line left or up + case NS_SCROLLBAR_LINE_PREV: + { + newPosition -= mLineIncrement; + if (newPosition < 0) + newPosition = 0; + // if an event callback is registered, give it the chance + // to change the decrement + if (mEventCallback) + { + aEvent.position = newPosition; + result = ConvertStatus((*mEventCallback)(&aEvent)); + newPosition = aEvent.position; + } + break; + } - // scroll one line left or up - case NS_SCROLLBAR_LINE_PREV: - { - XtVaGetValues(mWidget, XmNvalue, &newPosition, nsnull); - - newPosition -= mLineIncrement; - if (newPosition < 0) - newPosition = 0; + // Scrolls one page right or down + case NS_SCROLLBAR_PAGE_NEXT: + { + PRUint32 max = GetMaxRange(range) - GetThumbSize(range); + if (newPosition > (int)max) + newPosition = (int)max; - // if an event callback is registered, give it the chance - // to change the decrement - if (mEventCallback) { - aEvent.position = newPosition; + // if an event callback is registered, give it the chance + // to change the increment + if (mEventCallback) + { + aEvent.position = newPosition; + result = ConvertStatus((*mEventCallback)(&aEvent)); + newPosition = aEvent.position; + } + break; + } - result = ConvertStatus((*mEventCallback)(&aEvent)); - newPosition = aEvent.position; - } + // Scrolls one page left or up. + case NS_SCROLLBAR_PAGE_PREV: + { + //XtVaGetValues(mWidget, XmNvalue, &newPosition, nsnull); + if (newPosition < 0) + newPosition = 0; - XtVaSetValues(mWidget, XmNvalue, newPosition, nsnull); + // if an event callback is registered, give it the chance + // to change the increment + if (mEventCallback) + { + aEvent.position = newPosition; + result = ConvertStatus((*mEventCallback)(&aEvent)); + newPosition = aEvent.position; + } - break; - } + break; + } - // Scrolls one page right or down - case NS_SCROLLBAR_PAGE_NEXT: - { - XtVaGetValues(mWidget, XmNvalue, &newPosition, nsnull); - PRUint32 max = GetMaxRange() - GetThumbSize(); - if (newPosition > (int)max) - newPosition = (int)max; + // Scrolls to the absolute position. The current position is specified by + // the cPos parameter. + case NS_SCROLLBAR_POS: + { + newPosition = cPos; - // if an event callback is registered, give it the chance - // to change the increment - if (mEventCallback) { - aEvent.position = newPosition; - result = ConvertStatus((*mEventCallback)(&aEvent)); - newPosition = aEvent.position; - } - XtVaSetValues(mWidget, XmNvalue, - AdjustScrollBarPosition(newPosition+10), nsnull); - break; - } - - // Scrolls one page left or up. - case NS_SCROLLBAR_PAGE_PREV: - { - XtVaGetValues(mWidget, XmNvalue, &newPosition, nsnull); - if (newPosition < 0) - newPosition = 0; - - // if an event callback is registered, give it the chance - // to change the increment - if (mEventCallback) { - aEvent.position = newPosition; - result = ConvertStatus((*mEventCallback)(&aEvent)); - newPosition = aEvent.position; - } - - XtVaSetValues(mWidget, XmNvalue, newPosition-10, nsnull); - break; - } - - - // Scrolls to the absolute position. The current position is specified by - // the cPos parameter. - case NS_SCROLLBAR_POS: - { - newPosition = cPos; - - // if an event callback is registered, give it the chance - // to change the increment - if (mEventCallback) { - aEvent.position = newPosition; - result = ConvertStatus((*mEventCallback)(&aEvent)); - newPosition = aEvent.position; - } - - XtVaSetValues(mWidget, XmNvalue, - AdjustScrollBarPosition(newPosition), nsnull); - - break; - } + // if an event callback is registered, give it the chance + // to change the increment + if (mEventCallback) + { + aEvent.position = newPosition; + result = ConvertStatus((*mEventCallback)(&aEvent)); + newPosition = aEvent.position; + } + break; + } } return result; } -//---------------------------------------------------------------------- -//---------------------------------------------------------------------- -//---------------------------------------------------------------------- -//---------------------------------------------------------------------- -#define GET_OUTER() ((nsScrollbar*) ((char*)this - nsScrollbar::GetOuterOffset())) - -// nsIScrollbar part -void nsScrollbar::AggScrollbar::SetMaxRange(PRUint32 aEndRange) -{ - GET_OUTER()->SetMaxRange(aEndRange); -} - -PRUint32 nsScrollbar::AggScrollbar::GetMaxRange() -{ - return GET_OUTER()->GetMaxRange(); -} - -void nsScrollbar::AggScrollbar::SetPosition(PRUint32 aPos) -{ - GET_OUTER()->SetPosition(aPos); -} - -PRUint32 nsScrollbar::AggScrollbar::GetPosition() -{ - return GET_OUTER()->GetPosition(); -} - -void nsScrollbar::AggScrollbar::SetThumbSize(PRUint32 aSize) -{ - GET_OUTER()->SetThumbSize(aSize); -} - -PRUint32 nsScrollbar::AggScrollbar::GetThumbSize() -{ - return GET_OUTER()->GetThumbSize(); -} - -void nsScrollbar::AggScrollbar::SetLineIncrement(PRUint32 aSize) -{ - GET_OUTER()->SetLineIncrement(aSize); -} - -PRUint32 nsScrollbar::AggScrollbar::GetLineIncrement() -{ - return GET_OUTER()->GetLineIncrement(); -} - -void nsScrollbar::AggScrollbar::SetParameters(PRUint32 aMaxRange, - PRUint32 aThumbSize, - PRUint32 aPosition, - PRUint32 aLineIncrement) -{ - GET_OUTER()->SetParameters(aMaxRange, aThumbSize, aPosition, aLineIncrement); -} - -//---------------------------------------------------------------------- - -BASE_IWIDGET_IMPL(nsScrollbar, AggScrollbar); diff --git a/widget/src/mac/nsScrollbar.h b/widget/src/mac/nsScrollbar.h index b83fca35a926..5ba393e7c489 100644 --- a/widget/src/mac/nsScrollbar.h +++ b/widget/src/mac/nsScrollbar.h @@ -18,23 +18,27 @@ #ifndef nsScrollbar_h__ #define nsScrollbar_h__ - #include "nsWindow.h" #include "nsIScrollbar.h" +#include + /** - * Native Motif scrollbar wrapper. + * Mac Scrollbar. */ -class nsScrollbar : public nsWindow +class nsScrollbar : public nsWindow, public nsIScrollbar { public: - nsScrollbar(nsISupports *aOuter, PRBool aIsVertical); + nsScrollbar(PRBool aIsVertical); virtual ~nsScrollbar(); - NS_IMETHOD QueryObject(REFNSIID aIID, void** aInstancePtr); + // nsISupports + NS_IMETHOD_(nsrefcnt) AddRef(); + NS_IMETHOD_(nsrefcnt) Release(); + NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr); void Create(nsIWidget *aParent, const nsRect &aRect, @@ -54,58 +58,37 @@ public: // nsIScrollbar part - virtual void SetMaxRange(PRUint32 aEndRange); - virtual PRUint32 GetMaxRange(); - virtual void SetPosition(PRUint32 aPos); - virtual PRUint32 GetPosition(); - virtual void SetThumbSize(PRUint32 aSize); - virtual PRUint32 GetThumbSize(); - virtual void SetLineIncrement(PRUint32 aSize); - virtual PRUint32 GetLineIncrement(); - virtual void SetParameters(PRUint32 aMaxRange, PRUint32 aThumbSize, + NS_IMETHOD SetMaxRange(PRUint32 aEndRange); + NS_IMETHOD GetMaxRange(PRUint32& aMaxRange); + NS_IMETHOD SetPosition(PRUint32 aPos); + NS_IMETHOD GetPosition(PRUint32& aPos); + NS_IMETHOD SetThumbSize(PRUint32 aSize); + NS_IMETHOD GetThumbSize(PRUint32& aSize); + NS_IMETHOD SetLineIncrement(PRUint32 aSize); + NS_IMETHOD GetLineIncrement(PRUint32& aSize); + NS_IMETHOD SetParameters(PRUint32 aMaxRange, PRUint32 aThumbSize, PRUint32 aPosition, PRUint32 aLineIncrement); virtual PRBool OnPaint(nsPaintEvent & aEvent); virtual PRBool OnScroll(nsScrollbarEvent & aEvent, PRUint32 cPos); virtual PRBool OnResize(nsSizeEvent &aEvent); + virtual PRBool DispatchMouseEvent(nsMouseEvent &aEvent); + private: - PRUint32 mLineIncrement; - int mOrientation; + PRUint32 mMaxRange; + PRUint32 mPosition; + PRUint32 mThumbSize; + PRUint32 mLineIncrement; + int mIsVertical; + PRBool mMouseDownInButton; + PRBool mWidgetArmed; + + int AdjustScrollBarPosition(int aPosition); - - // this should not be public - static PRInt32 GetOuterOffset() { - return offsetof(nsScrollbar,mAggWidget); - } - - // Aggregator class and instance variable used to aggregate in the - // nsIButton interface to nsButton w/o using multiple - // inheritance. - class AggScrollbar : public nsIScrollbar { - public: - AggScrollbar(); - virtual ~AggScrollbar(); - - AGGREGATE_METHOD_DEF - - // nsIScrollbar part - virtual void SetMaxRange(PRUint32 aEndRange); - virtual PRUint32 GetMaxRange(); - virtual void SetPosition(PRUint32 aPos); - virtual PRUint32 GetPosition(); - virtual void SetThumbSize(PRUint32 aSize); - virtual PRUint32 GetThumbSize(); - virtual void SetLineIncrement(PRUint32 aSize); - virtual PRUint32 GetLineIncrement(); - virtual void SetParameters(PRUint32 aMaxRange, PRUint32 aThumbSize, - PRUint32 aPosition, PRUint32 aLineIncrement); - }; - AggScrollbar mAggWidget; - friend class AggScrollbar; - + void DrawWidget(); }; diff --git a/widget/src/mac/nsWidgetFactory.cpp b/widget/src/mac/nsWidgetFactory.cpp index 02562ba9c286..8233b42c4637 100644 --- a/widget/src/mac/nsWidgetFactory.cpp +++ b/widget/src/mac/nsWidgetFactory.cpp @@ -30,8 +30,8 @@ #include "nsCheckButton.h" #include "nsTextWidget.h" #include "nsFileWidget.h" +#include "nsScrollbar.h" -//#include "nsScrollbar.h" //#include "nsTextAreaWidget.h" //#include "nsListBox.h" //#include "nsComboBox.h" @@ -59,7 +59,7 @@ static NS_DEFINE_IID(kIWidget, NS_IWIDGET_IID); static NS_DEFINE_IID(kIAppShellIID, NS_IAPPSHELL_IID); static NS_DEFINE_IID(kIButton, NS_IBUTTON_IID); static NS_DEFINE_IID(kICheckButton, NS_ICHECKBUTTON_IID); -//static NS_DEFINE_IID(kIScrollbar, NS_ISCROLLBAR_IID); +static NS_DEFINE_IID(kIScrollbar, NS_ISCROLLBAR_IID); //static NS_DEFINE_IID(kIFileWidget, NS_IFILEWIDGET_IID); //static NS_DEFINE_IID(kIListBox, NS_ILISTBOX_IID); @@ -182,7 +182,13 @@ nsresult nsWidgetFactory::CreateInstance(nsISupports *aOuter, else if (mClassID.Equals(kCFileWidgetCID)) { inst = new nsFileWidget(); } - + else if (mClassID.Equals(kCVertScrollbarCID)) { + inst = new nsScrollbar(PR_TRUE); + } + else if (mClassID.Equals(kCHorzScrollbarCID)) { + inst = new nsScrollbar(PR_FALSE); + } + #ifdef NOTNOW diff --git a/widget/tests/widget/mac/nsWidgetTest.cpp b/widget/tests/widget/mac/nsWidgetTest.cpp index ffcc0ee7350a..2e21ac96d78b 100644 --- a/widget/tests/widget/mac/nsWidgetTest.cpp +++ b/widget/tests/widget/mac/nsWidgetTest.cpp @@ -1252,13 +1252,13 @@ nsresult WidgetTest(int *argc, char **argv) nsRepository::RegisterFactory(kCCheckButtonCID, WIDGET_DLL, PR_FALSE, PR_FALSE); nsRepository::RegisterFactory(kCRadioButtonCID, WIDGET_DLL, PR_FALSE, PR_FALSE); nsRepository::RegisterFactory(kCFileWidgetCID, WIDGET_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCHorzScrollbarCID, WIDGET_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCVertScrollbarCID, WIDGET_DLL, PR_FALSE, PR_FALSE); #ifdef NOTNOW nsRepository::RegisterFactory(kCComboBoxCID, WIDGET_DLL, PR_FALSE, PR_FALSE); nsRepository::RegisterFactory(kCListBoxCID, WIDGET_DLL, PR_FALSE, PR_FALSE); - nsRepository::RegisterFactory(kCHorzScrollbarCID, WIDGET_DLL, PR_FALSE, PR_FALSE); - nsRepository::RegisterFactory(kCVertScrollbarCID, WIDGET_DLL, PR_FALSE, PR_FALSE); nsRepository::RegisterFactory(kCTextAreaCID, WIDGET_DLL, PR_FALSE, PR_FALSE); nsRepository::RegisterFactory(kCTextFieldCID, WIDGET_DLL, PR_FALSE, PR_FALSE); nsRepository::RegisterFactory(kCTabWidgetCID, WIDGET_DLL, PR_FALSE, PR_FALSE); @@ -1415,41 +1415,32 @@ nsresult WidgetTest(int *argc, char **argv) widget->Show(PR_TRUE); NS_RELEASE(widget); -#ifdef NOTNOW //NS_RELEASE(checkButton); y += rect.height + 5; + + // - // create a text widget + // create a scrollbar // + x+=200; - nsITextWidget * textWidget; - rect.SetRect(x, y, 100, TEXT_HEIGHT); - - nsRepository::CreateInstance(kCTextFieldCID, nsnull, kITextWidgetIID, (void**)&textWidget); - textWidget->Create(window, rect, HandleEvent, deviceContext); + rect.SetRect(x, 10, 25, 300); + nsRepository::CreateInstance(kCVertScrollbarCID, nsnull, kIScrollbarIID, (void**)&scrollbar); + NS_CreateScrollBar(window,scrollbar,rect,HandleEvent); + scrollbar->SetMaxRange(300); + scrollbar->SetThumbSize(50); + scrollbar->SetPosition(100); + x += rect.width + 5; - nsFont font("Times", NS_FONT_STYLE_NORMAL, - NS_FONT_VARIANT_NORMAL, - NS_FONT_WEIGHT_BOLD, - 0, - 12); - - textWidget->SetFont(font); - nsString initialText("0123456789"); - textWidget->SetText(initialText); - textWidget->SetMaxTextLength(12); - textWidget->SelectAll(); - textWidget->Show(PR_TRUE); - - //NS_RELEASE(textWidget); - y += rect.height + 5; +#ifdef NOTNOW // // create a text password widget // + nsITextWidget * ptextWidget; rect.SetRect(x, y, 100, TEXT_HEIGHT); nsRepository::CreateInstance(kCTextFieldCID, nsnull, kITextWidgetIID, (void**)&ptextWidget); @@ -1510,16 +1501,6 @@ nsresult WidgetTest(int *argc, char **argv) int saveY = y; saveX = x; - // - // create a scrollbar - // - rect.SetRect(x, 10, 25, 300); - nsRepository::CreateInstance(kCVertScrollbarCID, nsnull, kIScrollbarIID, (void**)&scrollbar); - scrollbar->Create(window, rect, HandleEvent, NULL); - scrollbar->SetMaxRange(300); - scrollbar->SetThumbSize(50); - scrollbar->SetPosition(100); - x += rect.width + 5; // // create a Status Text