First stab at getting native scrollbars via xbl working with chimera. Not part of the build.

This commit is contained in:
pinkerton%netscape.com 2002-04-02 23:01:05 +00:00
Родитель 9594c84aac
Коммит 69614cc2c3
7 изменённых файлов: 776 добавлений и 263 удалений

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

@ -81,6 +81,7 @@ CMMSRCS = \
nsCocoaWindow.mm \
nsChildView.mm \
nsWidgetFactory.mm \
nsNativeScrollbar.mm \
$(NULL)
XPIDLSRCS += \

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

@ -534,22 +534,22 @@ NS_IMETHODIMP nsChildView::ModalEventFilter(PRBool aRealEvent, void *aEvent,
}
//-------------------------------------------------------------------------
//
// Enable/disable this component
// Enable
//
// Enable/disable this view
//
//-------------------------------------------------------------------------
NS_IMETHODIMP nsChildView::Enable(PRBool aState)
{
// unimplemented.
// unimplemented;
return NS_OK;
}
NS_IMETHODIMP nsChildView::IsEnabled(PRBool *aState)
{
// unimplemented.
if (*aState)
// unimplemented
if (aState)
*aState = PR_TRUE;
return NS_OK;
}

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

@ -0,0 +1,134 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsNativeScrollbar_h__
#define nsNativeScrollbar_h__
#include "nsINativeScrollbar.h"
#include "nsChildView.h"
#include <Controls.h>
#include "nsIContent.h"
class nsIScrollbarMediator;
//
// nsNativeScrollbar
//
// A wrapper around a MacOS native scrollbar that knows how to work
// with a stub gecko frame to scroll in the GFXScrollFrame mechanism
//
// {c2281100-3b4b-11d6-a384-f705fd0766fc}
#define NS_NATIVESCROLLBAR_CID \
{ 0xc2281100, 0x3b4b, 0x11d6, { 0xa3, 0x84, 0xf7, 0x05, 0xfd, 0x07, 0x66, 0xfc } }
class nsNativeScrollbar : public nsChildView, public nsINativeScrollbar
{
private:
typedef nsChildView Inherited;
public:
nsNativeScrollbar();
virtual ~nsNativeScrollbar();
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSINATIVESCROLLBAR
protected:
// nsWindow Interface
virtual PRBool DispatchMouseEvent(nsMouseEvent &aEvent);
NS_IMETHOD Show(PRBool bState);
NS_IMETHOD Enable(PRBool bState);
NS_IMETHOD IsEnabled(PRBool* outState);
NSScroller* GetControl() { return mView; }
void UpdateContentPosition(PRUint32 inNewPos);
virtual NSView* CreateCocoaView() ;
virtual GrafPtr GetQuickDrawPort() ;
private:
friend class StNativeControlActionProcOwner;
static pascal void ScrollActionProc(ControlHandle, ControlPartCode);
void DoScrollAction(ControlPartCode);
// DATA
private:
nsIContent* mContent; // the content node that affects the scrollbar's value
nsIScrollbarMediator* mMediator; // for scrolling with outliners
PRUint32 mValue;
PRUint32 mMaxValue;
PRUint32 mVisibleImageSize;
PRUint32 mLineIncrement;
PRBool mMouseDownInScroll;
ControlPartCode mClickedPartCode;
};
@interface NativeScrollbarView : NSScroller
{
// Our window [WEAK]
NSWindow* mWindow;
// the nsChildView that created the view. It retains this NSView, so
// the link back to it must be weak.
nsChildView* mGeckoChild;
// allows us to redispatch events back to a centralized location
//nsIEventSink* mEventSink;
// tag for our mouse enter/exit tracking rect
NSTrackingRectTag mMouseEnterExitTag;
}
- (void)drawRect:(NSRect)aRect;
- (NSWindow*) getNativeWindow;
- (void) setNativeWindow: (NSWindow*)aWindow;
@end
#endif // nsNativeScrollbar_

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

@ -0,0 +1,541 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsNativeScrollbar.h"
#include "nsIDeviceContext.h"
#if TARGET_CARBON || (UNIVERSAL_INTERFACES_VERSION >= 0x0330)
#include <ControlDefinitions.h>
#endif
#include "nsWidgetAtoms.h"
#include "nsWatchTask.h"
#include "nsINameSpaceManager.h"
#include "nsIDOMElement.h"
#include "nsIScrollbarMediator.h"
NS_IMPL_ISUPPORTS_INHERITED1(nsNativeScrollbar, nsChildView, nsINativeScrollbar);
#if 0
//
// StControlActionProcOwner
//
// A class that wraps a control action proc so that it is disposed of
// correctly when the shared library shuts down
//
class StNativeControlActionProcOwner {
public:
StNativeControlActionProcOwner ( )
{
sControlActionProc = NewControlActionUPP(nsNativeScrollbar::ScrollActionProc);
NS_ASSERTION(sControlActionProc, "Couldn't create live scrolling action proc");
}
~StNativeControlActionProcOwner ( )
{
if ( sControlActionProc )
DisposeControlActionUPP(sControlActionProc);
}
ControlActionUPP ActionProc() { return sControlActionProc; }
private:
ControlActionUPP sControlActionProc;
};
static ControlActionUPP ScrollbarActionProc ( );
static ControlActionUPP
ScrollbarActionProc ( )
{
static StNativeControlActionProcOwner sActionProcOwner;
return sActionProcOwner.ActionProc();
}
#endif
nsNativeScrollbar::nsNativeScrollbar()
: nsChildView()
, mContent(nsnull)
, mMediator(nsnull)
, mValue(0)
, mMaxValue(0)
, mVisibleImageSize(0)
, mLineIncrement(0)
, mMouseDownInScroll(PR_FALSE)
, mClickedPartCode(0)
{
WIDGET_SET_CLASSNAME("nsNativeScrollbar");
}
nsNativeScrollbar::~nsNativeScrollbar()
{
}
NSView*
nsNativeScrollbar::CreateCocoaView ( )
{
// Cocoa sets the orientation of a scrollbar at creation time by looking
// at its frame and taking the longer side to be the orientation. Since
// chances are good at this point gecko just wants us to be 1x1, use
// the flag at creation to force the desired orientation.
NSRect orientation;
orientation.origin.x = orientation.origin.y = 0;
if ( 1 ) {
orientation.size.width = 20;
orientation.size.height = 100;
}
else {
orientation.size.width = 100;
orientation.size.height = 20;
}
return [[[NativeScrollbarView alloc] initWithFrame:orientation] autorelease];
}
GrafPtr
nsNativeScrollbar::GetQuickDrawPort ( )
{
// pray we're always a child of a NSQuickDrawView
NSQuickDrawView* parent = (NSQuickDrawView*)[mView superview];
return [parent qdPort];
}
//
// ScrollActionProc
//
// Called from the OS toolbox while the scrollbar is being tracked.
//
pascal void
nsNativeScrollbar::ScrollActionProc(ControlHandle ctrl, ControlPartCode part)
{
nsNativeScrollbar* self = (nsNativeScrollbar*)(::GetControlReference(ctrl));
NS_ASSERTION(self, "NULL nsNativeScrollbar");
if ( self )
self->DoScrollAction(part);
}
//
// DoScrollAction
//
// Called from the action proc of the scrollbar, adjust the control's
// value as well as the value in the content node which communicates
// to gecko that the document is scrolling.
//
void
nsNativeScrollbar::DoScrollAction(ControlPartCode part)
{
return;
#if 0
PRUint32 oldPos, newPos;
PRUint32 incr;
PRUint32 visibleImageSize;
PRInt32 scrollBarMessage = 0;
GetPosition(&oldPos);
GetLineIncrement(&incr);
GetViewSize(&visibleImageSize);
switch(part)
{
//
// For the up/down buttons, scroll up or down by the line height and
// update the attributes on the content node (the scroll frame listens
// for these attributes and will scroll accordingly). However,
// if we have a mediator, we're in an outliner and we have to scroll by
// lines. Outliner ignores the params to ScrollbarButtonPressed() except
// to check if one is greater than the other to indicate direction.
//
case kControlUpButtonPart:
if ( mMediator )
mMediator->ScrollbarButtonPressed(1,0);
else {
newPos = oldPos - incr;
UpdateContentPosition(newPos);
}
break;
case kControlDownButtonPart:
if ( mMediator )
mMediator->ScrollbarButtonPressed(0,1);
else {
newPos = oldPos + incr;
UpdateContentPosition(newPos);
}
break;
//
// For page up/down and dragging the thumb, scroll by the page height
// (or directly report the value of the scrollbar) and update the attributes
// on the content node (as above). If we have a mediator, we're in an
// outliner so tell it directly that the position has changed. Note that
// outliner takes signed values, so we have to convert our unsigned to
// signed values first.
//
case kControlPageUpPart:
newPos = oldPos - visibleImageSize;
UpdateContentPosition(newPos);
if ( mMediator ) {
PRInt32 op = oldPos, np = mValue;
if ( np < 0 )
np = 0;
mMediator->PositionChanged(op, np);
}
break;
case kControlPageDownPart:
newPos = oldPos + visibleImageSize;
UpdateContentPosition(newPos);
if ( mMediator ) {
PRInt32 op = oldPos, np = mValue;
if ( np < 0 )
np = 0;
mMediator->PositionChanged(op, np);
}
break;
case kControlIndicatorPart:
newPos = ::GetControl32BitValue(GetControl());
UpdateContentPosition(newPos);
if ( mMediator ) {
PRInt32 op = oldPos, np = mValue;
if ( np < 0 )
np = 0;
mMediator->PositionChanged(op, np);
}
break;
}
EndDraw();
// update the area of the parent uncovered by the scrolling. Since
// we may be in a tight loop, we need to manually validate the area
// we just updated so the update rect doesn't continue to get bigger
// and bigger the more we scroll.
nsCOMPtr<nsIWidget> parent ( dont_AddRef(GetParent()) );
parent->Update();
parent->Validate();
StartDraw();
#endif
}
//
// UpdateContentPosition
//
// Tell the content node that the scrollbar has changed value and
// then update the scrollbar's position
//
void
nsNativeScrollbar::UpdateContentPosition(PRUint32 inNewPos)
{
if ( inNewPos == mValue || !mContent ) // break any possible recursion
return;
// convert the int to a string
char buffer[20];
sprintf(buffer, "%d", inNewPos);
mContent->SetAttr(kNameSpaceID_None, nsWidgetAtoms::curpos, NS_ConvertASCIItoUCS2(buffer), PR_TRUE);
SetPosition(inNewPos);
}
/**-------------------------------------------------------------------------------
* DispatchMouseEvent handle an event for this scrollbar
* @update dc 08/31/98
* @Param aEvent -- The mouse event to respond to for this button
* @return -- True if the event was handled, PR_FALSE if we did not handle it.
*/
PRBool
nsNativeScrollbar::DispatchMouseEvent(nsMouseEvent &aEvent)
{
return PR_TRUE;
}
//
// SetMaxRange
//
// Set the maximum range of a scroll bar. This should be set to the
// full scrollable area minus the visible area.
//
NS_IMETHODIMP
nsNativeScrollbar::SetMaxRange(PRUint32 aEndRange)
{
mMaxValue = ((int)aEndRange) > 0 ? aEndRange : 10;
if ( GetControl() ) {
PRInt32 fullVisibleArea = mVisibleImageSize + mMaxValue;
[mView setFloatValue:[mView floatValue] knobProportion:(mVisibleImageSize / (float)fullVisibleArea)];
}
return NS_OK;
}
//
// GetMaxRange
//
// Get the maximum range of a scroll bar
//
NS_IMETHODIMP
nsNativeScrollbar::GetMaxRange(PRUint32* aMaxRange)
{
*aMaxRange = mMaxValue;
return NS_OK;
}
//
// SetPosition
//
// Set the current position of the slider and redraw the scrollbar
//
NS_IMETHODIMP
nsNativeScrollbar::SetPosition(PRUint32 aPos)
{
if ((PRInt32)aPos < 0)
aPos = 0;
mValue = ((PRInt32)aPos) > mMaxValue ? mMaxValue : ((int)aPos);
[mView setFloatValue:(aPos / (float)mMaxValue)];
return NS_OK;
}
//
// GetPosition
//
// Get the current position of the slider
//
NS_IMETHODIMP
nsNativeScrollbar::GetPosition(PRUint32* aPos)
{
*aPos = mValue;
return NS_OK;
}
//
// SetViewSize
//
// Change the knob proportion to be the ratio of the size of the visible image (given in |aSize|)
// to the total area (visible + max). Recall that the max size is the total minus the
// visible area.
//
NS_IMETHODIMP
nsNativeScrollbar::SetViewSize(PRUint32 aSize)
{
mVisibleImageSize = ((int)aSize) > 0 ? aSize : 1;
PRInt32 fullVisibleArea = mVisibleImageSize + mMaxValue;
[mView setFloatValue:[mView floatValue] knobProportion:(mVisibleImageSize / (float)fullVisibleArea)];
return NS_OK;
}
//
// GetViewSize
//
// Get the height of the visible view area.
//
NS_IMETHODIMP
nsNativeScrollbar::GetViewSize(PRUint32* aSize)
{
*aSize = mVisibleImageSize;
return NS_OK;
}
//
// SetLineIncrement
//
// Set the line increment of the scroll bar
//
NS_IMETHODIMP
nsNativeScrollbar::SetLineIncrement(PRUint32 aLineIncrement)
{
mLineIncrement = (((int)aLineIncrement) > 0 ? aLineIncrement : 1);
return NS_OK;
}
//
// GetLineIncrement
//
// Get the line increment of the scroll bar
//
NS_IMETHODIMP
nsNativeScrollbar::GetLineIncrement(PRUint32* aLineIncrement)
{
*aLineIncrement = mLineIncrement;
return NS_OK;
}
//
// GetNarrowSize
//
// Ask the appearance manager for the dimensions of the narrow axis
// of the scrollbar. We cheat and assume the width of a vertical scrollbar
// is the same as the height of a horizontal scrollbar. *shrug*. Shoot me.
//
NS_IMETHODIMP
nsNativeScrollbar::GetNarrowSize(PRInt32* outSize)
{
if ( *outSize )
return NS_ERROR_FAILURE;
SInt32 width = 0;
::GetThemeMetric(kThemeMetricScrollBarWidth, &width);
*outSize = width;
return NS_OK;
}
//
// SetContent
//
// Hook up this native scrollbar to the rest of gecko. We care about
// the content so we can set attributes on it to affect the scrollview. We
// care about the mediator for <outliner> so we can do row-based scrolling.
//
NS_IMETHODIMP
nsNativeScrollbar::SetContent(nsIContent* inContent, nsIScrollbarMediator* inMediator)
{
mContent = inContent;
mMediator = inMediator;
return NS_OK;
}
//
// Show
//
// Hide or show the scrollbar
//
NS_IMETHODIMP
nsNativeScrollbar::Show(PRBool bState)
{
// the only way to get the scrollbar view to not draw is to remove it
// from the view hierarchy. cache the parent view so that we can
// hook it up later if we're told to show.
if ( mVisible && !bState ) {
mParentView = [mView superview];
[mView removeFromSuperview];
}
else if ( !mVisible && bState ) {
if ( mParentView )
[mParentView addSubview:mView];
}
mVisible = bState;
return NS_OK;
}
//
// Enable
//
// Enable/disable this scrollbar
//
NS_IMETHODIMP
nsNativeScrollbar::Enable(PRBool bState)
{
[mView setEnabled:(bState ? YES : NO)];
return NS_OK;
}
NS_IMETHODIMP
nsNativeScrollbar::IsEnabled(PRBool *aState)
{
if (aState)
*aState = [mView isEnabled] ? PR_TRUE : PR_FALSE;
return NS_OK;
}
#pragma mark -
@implementation NativeScrollbarView
- (NSWindow*) getNativeWindow
{
NSWindow* currWin = [self window];
if (currWin)
return currWin;
else
return mWindow;
}
- (void) setNativeWindow: (NSWindow*)aWindow
{
mWindow = aWindow;
}
- (void)trackKnob:(NSEvent *)theEvent
{
printf("tracking knob\n");
[super trackKnob:theEvent];
printf("done tracking knob\n");
}
- (void)trackScrollButtons:(NSEvent *)theEvent
{
printf("tracking buttons");
[super trackScrollButtons:theEvent];
printf("done tracking buttons");
}
- (BOOL)isFlipped
{
return YES;
}
@end

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

@ -59,27 +59,11 @@ public:
// nsISupports
NS_DECL_ISUPPORTS_INHERITED
#if 0
NS_IMETHODIMP Create(nsIWidget *aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext = nsnull,
nsIAppShell *aAppShell = nsnull,
nsIToolkit *aToolkit = nsnull,
nsWidgetInitData *aInitData = nsnull);
NS_IMETHOD Create(nsNativeWidget aNativeParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell = nsnull,
nsIToolkit *aToolkit = nsnull,
nsWidgetInitData *aInitData = nsnull);
#endif
// nsWindow Interface
virtual PRBool DispatchMouseEvent(nsMouseEvent &aEvent);
NS_IMETHOD Show(PRBool bState);
NS_IMETHOD Enable(PRBool bState);
NS_IMETHOD IsEnabled(PRBool* outState);
// nsIScrollbar part
NS_IMETHOD SetMaxRange(PRUint32 aEndRange);
@ -107,9 +91,9 @@ public:
protected:
virtual PRBool IsVertical ( ) const = 0;
virtual void GetRectForMacControl(nsRect &outRect);
NSScroller* GetControl() { return mView; }
virtual NSView* CreateCocoaView() ;
virtual GrafPtr GetQuickDrawPort() ;
@ -122,14 +106,12 @@ private:
// DATA
private:
PRInt32 mValue;
PRUint32 mFullImageSize;
PRUint32 mMaxValue;
PRUint32 mVisibleImageSize;
PRUint32 mLineIncrement;
PRBool mMouseDownInScroll;
ControlPartCode mClickedPartCode;
static ControlActionUPP sControlActionProc; // we only need one of these
NSView* mParentView; // for showing/hiding
};

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

@ -50,20 +50,13 @@ ControlActionUPP nsScrollbar::sControlActionProc = nsnull;
nsScrollbar::nsScrollbar()
: Inherited()
, mValue(0)
, mFullImageSize(0)
, mMaxValue(0)
, mVisibleImageSize(0)
, mLineIncrement(0)
, mMouseDownInScroll(PR_FALSE)
, mClickedPartCode(0)
, mParentView(nsnull)
{
WIDGET_SET_CLASSNAME("nsScrollbar");
#if 0
SetControlType(kControlScrollBarLiveProc);
if (!sControlActionProc)
sControlActionProc = NewControlActionUPP(nsScrollbar::ScrollActionProc);
// Unfortunately, not disposed when the app quits, but that's still a non-issue.
#endif
}
@ -72,35 +65,6 @@ nsScrollbar::~nsScrollbar()
}
#if 0
/**-------------------------------------------------------------------------------
* The create method for a scrollbar, using a nsIWidget as the parent
* @update dc 08/31/98
* @param aParent -- the widget which will be this widgets parent in the tree
* @param aRect -- The bounds in parental coordinates of this widget
* @param aHandleEventFunction -- Procedures to be executed for this widget
* @param aContext -- device context to be used by this widget
* @param aAppShell --
* @param aToolkit -- toolkit to be used by this widget
* @param aInitData -- Initialization data used by frames
* @return -- NS_OK if everything was created correctly
*/
NS_IMETHODIMP nsScrollbar::Create(nsIWidget *aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell,
nsIToolkit *aToolkit,
nsWidgetInitData *aInitData)
{
//FIXME - probably don't need this at all
Inherited::Create(aParent, aRect, aHandleEventFunction,
aContext, aAppShell, aToolkit, aInitData);
return NS_OK;
}
#endif
NSView*
nsScrollbar::CreateCocoaView ( )
@ -218,202 +182,103 @@ void nsScrollbar::DoScrollAction(ControlPartCode part)
*/
PRBool nsScrollbar::DispatchMouseEvent(nsMouseEvent &aEvent)
{
//FIXME!!!!
return PR_TRUE;
#if 0
PRBool eatEvent = PR_FALSE;
switch (aEvent.message)
{
case NS_MOUSE_LEFT_DOUBLECLICK:
case NS_MOUSE_LEFT_BUTTON_DOWN:
NS_ASSERTION(this != 0, "NULL nsScrollbar2");
// ::SetControlReference(mControl, (UInt32) this);
StartDraw();
{
Point thePoint;
thePoint.h = aEvent.point.x;
thePoint.v = aEvent.point.y;
mClickedPartCode = ::TestControl(mControl, thePoint);
if (mClickedPartCode > 0)
::HiliteControl(mControl, mClickedPartCode);
switch (mClickedPartCode)
{
case kControlUpButtonPart:
case kControlDownButtonPart:
case kControlPageUpPart:
case kControlPageDownPart:
case kControlIndicatorPart:
// We are assuming Appearance 1.1 or later, so we
// have the "live scroll" variant of the scrollbar,
// which lets you pass the action proc to TrackControl
// for the thumb (this was illegal in previous
// versions of the defproc).
::TrackControl(mControl, thePoint, sControlActionProc);
// We don't dispatch the mouseDown event because mouseUp is eaten
// by TrackControl anyway and the only messages the app really
// cares about are the NS_SCROLLBAR_xxx messages.
eatEvent = PR_TRUE;
break;
#if 0
case kControlIndicatorPart:
// This is what you have to do for appearance 1.0 or
// no appearance.
::TrackControl(mControl, thePoint, nsnull);
mValue = ::GetControl32BitValue(mControl);
EndDraw();
nsScrollbarEvent scrollBarEvent;
scrollBarEvent.eventStructType = NS_GUI_EVENT;
scrollBarEvent.widget = this;
scrollBarEvent.message = NS_SCROLLBAR_POS;
scrollBarEvent.position = mValue;
DispatchWindowEvent(scrollBarEvent);
nsIWidget* parent = GetParent();
parent->Update();
NS_RELEASE(parent);
StartDraw();
break;
#endif
}
SetPosition(mValue);
}
EndDraw();
break;
case NS_MOUSE_LEFT_BUTTON_UP:
mClickedPartCode = 0;
break;
case NS_MOUSE_EXIT:
if (mWidgetArmed)
{
StartDraw();
::HiliteControl(mControl, 0);
EndDraw();
}
break;
case NS_MOUSE_ENTER:
if (mWidgetArmed)
{
StartDraw();
::HiliteControl(mControl, mClickedPartCode);
EndDraw();
}
break;
}
if (eatEvent)
return PR_TRUE;
return (Inherited::DispatchMouseEvent(aEvent));
#endif
}
/**-------------------------------------------------------------------------------
* 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) // really means set full image size.
//
// SetMaxRange
//
// Set the maximum range of a scroll bar. This should be set to the
// full scrollable area minus the visible area.
//
NS_METHOD nsScrollbar::SetMaxRange(PRUint32 aEndRange)
{
mFullImageSize = ((int)aEndRange) > 0 ? aEndRange : 10;
mMaxValue = ((int)aEndRange) > 0 ? aEndRange : 10;
if ( GetControl() ) {
PRInt32 fullVisibleArea = mVisibleImageSize + mMaxValue;
[mView setFloatValue:[mView floatValue] knobProportion:(mVisibleImageSize / (float)fullVisibleArea)];
}
return NS_OK;
}
//printf("** max range is %d\n", aEndRange);
//StartDraw();
[mView setFloatValue:[mView floatValue] knobProportion:(mVisibleImageSize / (float)mFullImageSize)];
//EndDraw();
//
// GetMaxRange
//
// Get the maximum range of a scroll bar
//
NS_METHOD nsScrollbar::GetMaxRange(PRUint32& aMaxRange)
{
aMaxRange = mMaxValue;
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) // really means get full image size
{
aMaxRange = mFullImageSize;
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
*/
//
// SetPosition
//
// Set the current position of the slider and redraw the scrollbar
//
NS_METHOD nsScrollbar::SetPosition(PRUint32 aPos)
{
if ((PRInt32)aPos < 0)
aPos = 0;
PRUint32 oldValue = mValue;
mValue = ((PRInt32)aPos) > mFullImageSize ? mFullImageSize : ((int)aPos);
if ((PRInt32)aPos < 0)
aPos = 0;
//printf("** set value to %d\n", aPos);
[mView setFloatValue:(aPos / (float)mFullImageSize)];
return NS_OK;
mValue = ((PRInt32)aPos) > mMaxValue ? mMaxValue : ((int)aPos);
[mView setFloatValue:(aPos / (float)mMaxValue)];
return NS_OK;
}
/**-------------------------------------------------------------------------------
* 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
*/
//
// GetPosition
//
// Get the current position of the slider
//
NS_METHOD nsScrollbar::GetPosition(PRUint32& aPos)
{
aPos = mValue;
return NS_OK;
}
/**-------------------------------------------------------------------------------
* Set 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
*/
//
// SetThumbSize
//
// Change the knob proportion to be the ratio of the size of the visible image (given in |aSize|)
// to the total area (visible + max). Recall that the max size is the total minus the
// visible area.
//
NS_METHOD nsScrollbar::SetThumbSize(PRUint32 aSize)
{
mVisibleImageSize = aSize;
if (mVisibleImageSize > mFullImageSize)
mVisibleImageSize = mFullImageSize;
//printf("** visible image size is %d\n", mVisibleImageSize);
//printf("** new knob proportion %f\n", (mVisibleImageSize / (float)mFullImageSize));
//StartDraw();
[mView setFloatValue:[mView floatValue] knobProportion:(mVisibleImageSize / (float)mFullImageSize)];
//EndDraw();
return NS_OK;
mVisibleImageSize = ((int)aSize) > 0 ? aSize : 1;
PRInt32 fullVisibleArea = mVisibleImageSize + mMaxValue;
[mView setFloatValue:[mView floatValue] knobProportion:(mVisibleImageSize / (float)fullVisibleArea)];
return NS_OK;
}
/**-------------------------------------------------------------------------------
* 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
*/
//
// GetThumbSize
//
// Get the height of the visible view area.
//
NS_METHOD nsScrollbar::GetThumbSize(PRUint32& aSize)
{
aSize = mVisibleImageSize;
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
*/
//
// SetLineIncrement
//
// Set the line increment of the scroll bar
//
NS_METHOD nsScrollbar::SetLineIncrement(PRUint32 aLineIncrement)
{
mLineIncrement = (((int)aLineIncrement) > 0 ? aLineIncrement : 1);
@ -421,12 +286,11 @@ NS_METHOD nsScrollbar::SetLineIncrement(PRUint32 aLineIncrement)
}
/**-------------------------------------------------------------------------------
* 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
*/
//
// GetLineIncrement
//
// Get the line increment of the scroll bar
//
NS_METHOD nsScrollbar::GetLineIncrement(PRUint32& aLineIncrement)
{
aLineIncrement = mLineIncrement;
@ -450,30 +314,6 @@ NS_METHOD nsScrollbar::SetParameters(PRUint32 aMaxRange, PRUint32 aThumbSize,
}
//-------------------------------------------------------------------------
//
// Get the rect which the Mac control uses. This may be different for
// different controls, so this method allows overriding
//
//-------------------------------------------------------------------------
void nsScrollbar::GetRectForMacControl(nsRect &outRect)
{
outRect = mBounds;
outRect.x = outRect.y = 0;
if (mBounds.height > mBounds.width)
{
// vertical scroll bar
outRect.Inflate(0, 1);
}
else
{
// horizontal scroll bar
outRect.Inflate(1, 0);
}
}
//
// Show
//
@ -499,11 +339,11 @@ nsScrollbar::Show(PRBool bState)
}
//-------------------------------------------------------------------------
//
// Enable/disable this component
// Enable
//
// Enable/disable this scrollbar
//
//-------------------------------------------------------------------------
NS_IMETHODIMP
nsScrollbar::Enable(PRBool bState)
{
@ -512,6 +352,15 @@ nsScrollbar::Enable(PRBool bState)
}
NS_IMETHODIMP
nsScrollbar::IsEnabled(PRBool *aState)
{
if (aState)
*aState = [mView isEnabled] ? PR_TRUE : PR_FALSE;
return NS_OK;
}
#pragma mark -
@implementation ScrollbarView

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

@ -70,6 +70,7 @@
#include "nsSound.h"
#include "nsScrollbar.h"
#include "nsNativeScrollbar.h"
#ifdef IBMBIDI
#include "nsBidiKeyboard.h"
@ -89,6 +90,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsMenu)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMenuItem)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsVertScrollbar)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsHorizScrollbar)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsNativeScrollbar)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSound)
//NS_GENERIC_FACTORY_CONSTRUCTOR(nsFileSpecWithUIImpl)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsTransferable)
@ -181,6 +183,10 @@ static nsModuleComponentInfo components[] =
NS_VERTSCROLLBAR_CID,
"@mozilla.org/widgets/vertscroll/mac;1",
nsVertScrollbarConstructor },
{ "Native Scrollbar",
NS_NATIVESCROLLBAR_CID,
"@mozilla.org/widget/nativescrollbar;1",
nsNativeScrollbarConstructor },
};
NS_IMPL_NSGETMODULE(nsWidgetModule, components)