зеркало из https://github.com/mozilla/pjs.git
Remove duplicate initialization of nsDeviceContext reference count by derived class constructor (which is dangerous since it could be incremented during the base class constructor). Various other cleanup, mostly in xlib port. b=111088 r=rbs sr=jag
This commit is contained in:
Родитель
faf2eaeedc
Коммит
2feca83869
|
@ -62,8 +62,8 @@ static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
|
|||
nscoord nsDeviceContextBeOS::mDpi = 96;
|
||||
|
||||
nsDeviceContextBeOS::nsDeviceContextBeOS()
|
||||
: DeviceContextImpl()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mTwipsToPixels = 1.0;
|
||||
mPixelsToTwips = 1.0;
|
||||
mDepth = 0 ;
|
||||
|
|
|
@ -119,9 +119,8 @@ nscoord nsDeviceContextGTK::mDpi = 96;
|
|||
static nsSystemFontsGTK *gSystemFonts = nsnull;
|
||||
|
||||
nsDeviceContextGTK::nsDeviceContextGTK()
|
||||
: DeviceContextImpl()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
mTwipsToPixels = 1.0;
|
||||
mPixelsToTwips = 1.0;
|
||||
mDepth = 0 ;
|
||||
|
|
|
@ -78,10 +78,10 @@ PRUint32 nsDeviceContextMac::sNumberOfScreens = 0;
|
|||
* @update 12/9/98 dwc
|
||||
*/
|
||||
nsDeviceContextMac :: nsDeviceContextMac()
|
||||
: mSurface(nsnull), mOldPort(nsnull)
|
||||
: DeviceContextImpl(),
|
||||
mSurface(nsnull),
|
||||
mOldPort(nsnull)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
|
|
|
@ -59,9 +59,9 @@ nscoord nsDeviceContextPh::mDpi = 96;
|
|||
|
||||
static nsHashtable* mFontLoadCache = nsnull;
|
||||
|
||||
nsDeviceContextPh :: nsDeviceContextPh( ) {
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
nsDeviceContextPh :: nsDeviceContextPh( )
|
||||
: DeviceContextImpl()
|
||||
{
|
||||
mTwipsToPixels = 1.0;
|
||||
mPixelsToTwips = 1.0;
|
||||
mDepth = 0 ;
|
||||
|
|
|
@ -51,8 +51,8 @@ static NS_DEFINE_IID(kIDeviceContextSpecPSIID, NS_IDEVICE_CONTEXT_SPEC_PS_IID);
|
|||
* @update 12/21/98 dwc
|
||||
*/
|
||||
nsDeviceContextPS :: nsDeviceContextPS()
|
||||
: DeviceContextImpl()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mSpec = nsnull;
|
||||
mParentDeviceContext = nsnull;
|
||||
}
|
||||
|
|
|
@ -53,6 +53,8 @@ class nsIDeviceContextSpecPS : public nsISupports
|
|||
{
|
||||
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IDEVICE_CONTEXT_SPEC_PS_IID)
|
||||
|
||||
/*
|
||||
* If PR_TRUE, print to printer
|
||||
* @update
|
||||
|
|
|
@ -1638,8 +1638,7 @@ PRBool
|
|||
nsPostScriptObj::InitUnixPrinterProps()
|
||||
{
|
||||
nsCOMPtr<nsIPersistentProperties> printerprops_tmp;
|
||||
nsAutoString propertyURL;
|
||||
propertyURL.Assign(NS_LITERAL_STRING("resource:/res/unixpsfonts.properties"));
|
||||
const char propertyURL[] = "resource:/res/unixpsfonts.properties";
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
NS_ENSURE_SUCCESS(NS_NewURI(getter_AddRefs(uri), propertyURL), PR_FALSE);
|
||||
nsCOMPtr<nsIInputStream> in;
|
||||
|
|
|
@ -97,60 +97,17 @@ nsDeviceContextSpecXlib::~nsDeviceContextSpecXlib()
|
|||
{
|
||||
}
|
||||
|
||||
static NS_DEFINE_IID(kIDeviceContextSpecIID, NS_IDEVICE_CONTEXT_SPEC_IID);
|
||||
static NS_DEFINE_IID(kIDeviceContextSpecPSIID, NS_IDEVICE_CONTEXT_SPEC_PS_IID);
|
||||
#ifdef USE_XPRINT
|
||||
static NS_DEFINE_IID(kIDeviceContextSpecXPIID, NS_IDEVICE_CONTEXT_SPEC_XP_IID);
|
||||
NS_IMPL_ISUPPORTS3(nsDeviceContextSpecXlib,
|
||||
nsIDeviceContextSpec,
|
||||
nsIDeviceContextSpecPS,
|
||||
nsIDeviceContextSpecXp)
|
||||
#else
|
||||
NS_IMPL_ISUPPORTS2(nsDeviceContextSpecXlib,
|
||||
nsIDeviceContextSpec,
|
||||
nsIDeviceContextSpecPS)
|
||||
#endif
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextSpecXlib::QueryInterface(REFNSIID aIID, void **aInstancePtr)
|
||||
{
|
||||
if (nsnull == aInstancePtr)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (aIID.Equals(kIDeviceContextSpecIID))
|
||||
{
|
||||
nsIDeviceContextSpec *tmp = this;
|
||||
*aInstancePtr = (void *) tmp;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (aIID.Equals(kIDeviceContextSpecPSIID))
|
||||
{
|
||||
nsIDeviceContextSpecPS *tmp = this;
|
||||
*aInstancePtr = (void *) tmp;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#ifdef USE_XPRINT
|
||||
if (aIID.Equals(kIDeviceContextSpecXPIID))
|
||||
{
|
||||
nsIDeviceContextSpecXp *tmp = this;
|
||||
*aInstancePtr = (void*) tmp;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
#endif /* USE_XPRINT */
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
|
||||
if (aIID.Equals(kISupportsIID))
|
||||
{
|
||||
nsIDeviceContextSpec *tmp = this;
|
||||
nsISupports* tmp2 = tmp;
|
||||
*aInstancePtr = (void *) tmp2;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsDeviceContextSpecXlib)
|
||||
NS_IMPL_RELEASE(nsDeviceContextSpecXlib)
|
||||
|
||||
/** -------------------------------------------------------
|
||||
*/
|
||||
static nsresult DisplayXPDialog(nsIPrintSettings* aPS,
|
||||
|
|
|
@ -447,7 +447,7 @@ nsClipboard::GetNativeClipboardData(nsITransferable * aTransferable,
|
|||
nsXPIDLCString flavorStr;
|
||||
currentFlavor->ToString ( getter_Copies(flavorStr) );
|
||||
if (DoConvert(flavorStr, selectionAtom)) {
|
||||
foundFlavor = nsCAutoString(flavorStr);
|
||||
foundFlavor = flavorStr;
|
||||
foundData = PR_TRUE;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1063,7 +1063,7 @@ nsAppShell::HandleEnterEvent(XEvent *event, nsWidget *aWidget)
|
|||
|
||||
// make sure this is in focus. This will do until I rewrite all the
|
||||
// focus routines. KenF
|
||||
aWidget->SetFocus(PR_FALSE);
|
||||
aWidget->SetFocus();
|
||||
|
||||
NS_ADDREF(aWidget);
|
||||
aWidget->DispatchWindowEvent(enterEvent);
|
||||
|
|
|
@ -37,12 +37,8 @@
|
|||
|
||||
#include "nsButton.h"
|
||||
|
||||
NS_IMPL_ADDREF(nsButton)
|
||||
NS_IMPL_RELEASE(nsButton)
|
||||
|
||||
nsButton::nsButton() : nsWidget() , nsIButton()
|
||||
nsButton::nsButton() : nsWidget()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mName.Assign(NS_LITERAL_STRING("nsButton"));
|
||||
}
|
||||
|
||||
|
@ -50,21 +46,7 @@ nsButton::~nsButton()
|
|||
{
|
||||
}
|
||||
|
||||
nsresult nsButton::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||
{
|
||||
if (NULL == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
static NS_DEFINE_IID(kIButton, NS_IBUTTON_IID);
|
||||
if (aIID.Equals(kIButton)) {
|
||||
*aInstancePtr = (void*) ((nsIButton*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return nsWidget::QueryInterface(aIID,aInstancePtr);
|
||||
}
|
||||
NS_IMPL_ISUPPORTS_INHERITED1(nsButton, nsWidget, nsIButton)
|
||||
|
||||
NS_METHOD nsButton::SetLabel (const nsString &aText)
|
||||
{
|
||||
|
|
|
@ -48,10 +48,7 @@ class nsButton : public nsWidget,
|
|||
nsButton();
|
||||
virtual ~nsButton();
|
||||
|
||||
// from nsISupports
|
||||
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||
NS_IMETHOD_(nsrefcnt) Release(void);
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
// from nsIButton
|
||||
NS_IMETHOD SetLabel(const nsString& aText);
|
||||
|
|
|
@ -37,33 +37,17 @@
|
|||
|
||||
#include "nsCheckButton.h"
|
||||
|
||||
NS_IMPL_ADDREF(nsCheckButton)
|
||||
NS_IMPL_RELEASE(nsCheckButton)
|
||||
|
||||
nsCheckButton::nsCheckButton() : nsWidget() , nsICheckButton(),
|
||||
mState(PR_FALSE)
|
||||
nsCheckButton::nsCheckButton()
|
||||
: nsWidget(),
|
||||
mState(PR_FALSE)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsCheckButton::~nsCheckButton()
|
||||
{
|
||||
}
|
||||
|
||||
nsresult nsCheckButton::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||
{
|
||||
if (NULL == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
static NS_DEFINE_IID(kICheckButtonIID, NS_ICHECKBUTTON_IID);
|
||||
if (aIID.Equals(kICheckButtonIID)) {
|
||||
*aInstancePtr = (void*) ((nsICheckButton*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return nsWidget::QueryInterface(aIID,aInstancePtr);
|
||||
}
|
||||
NS_IMPL_ISUPPORTS_INHERITED1(nsCheckButton, nsWidget, nsICheckButton)
|
||||
|
||||
NS_METHOD nsCheckButton::SetState(const PRBool aState)
|
||||
{
|
||||
|
|
|
@ -50,10 +50,7 @@ public:
|
|||
nsCheckButton();
|
||||
virtual ~nsCheckButton();
|
||||
|
||||
// nsISupports
|
||||
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||
NS_IMETHOD_(nsrefcnt) Release(void);
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
// nsICheckButton part
|
||||
NS_IMETHOD SetLabel(const nsString &aText);
|
||||
|
|
|
@ -83,10 +83,10 @@ Display *nsClipboard::sDisplay;
|
|||
#define DEBUG_CLIPBOARD
|
||||
#endif
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsClipboard, nsIClipboard);
|
||||
NS_IMPL_ISUPPORTS1(nsClipboard, nsIClipboard)
|
||||
|
||||
nsClipboard::nsClipboard() {
|
||||
NS_INIT_REFCNT();
|
||||
NS_INIT_ISUPPORTS();
|
||||
|
||||
sDisplay = xxlib_rgb_get_display(nsAppShell::GetXlibRgbHandle());
|
||||
|
||||
|
|
|
@ -37,6 +37,10 @@
|
|||
|
||||
#include "xlibrgb.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS_INHERITED1(nsDragService,
|
||||
nsBaseDragService,
|
||||
nsIDragSessionXlib)
|
||||
|
||||
/* drag bitmaps */
|
||||
static const unsigned char drag_bitmap[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00,
|
||||
|
@ -64,10 +68,6 @@ static const unsigned char drag_mask[] = {
|
|||
0x00, 0x7c, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(nsDragService, nsBaseDragService)
|
||||
NS_IMPL_RELEASE_INHERITED(nsDragService, nsBaseDragService)
|
||||
NS_IMPL_QUERY_INTERFACE3(nsDragService, nsIDragService, nsIDragSession, nsIDragSessionXlib)
|
||||
|
||||
nsWidget *nsDragService::sWidget = nsnull;
|
||||
Window nsDragService::sWindow;
|
||||
XlibRgbHandle *nsDragService::sXlibRgbHandle;
|
||||
|
|
|
@ -37,12 +37,8 @@
|
|||
|
||||
#include "nsLabel.h"
|
||||
|
||||
NS_IMPL_ADDREF(nsLabel)
|
||||
NS_IMPL_RELEASE(nsLabel)
|
||||
|
||||
nsLabel::nsLabel() : nsWidget(), nsILabel()
|
||||
nsLabel::nsLabel() : nsWidget()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
NS_METHOD nsLabel::PreCreateWidget(nsWidgetInitData *aInitData)
|
||||
|
@ -54,19 +50,7 @@ nsLabel::~nsLabel()
|
|||
{
|
||||
}
|
||||
|
||||
nsresult nsLabel::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||
{
|
||||
nsresult result = nsWidget::QueryInterface(aIID, aInstancePtr);
|
||||
|
||||
static NS_DEFINE_IID(kILabelIID, NS_ILABEL_IID);
|
||||
if (result == NS_NOINTERFACE && aIID.Equals(kILabelIID)) {
|
||||
*aInstancePtr = (void*) ((nsILabel*)this);
|
||||
NS_ADDREF_THIS();
|
||||
result = NS_OK;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
NS_IMPL_ISUPPORTS_INHERITED1(nsLabel, nsWidget, nsILabel)
|
||||
|
||||
NS_METHOD nsLabel::SetAlignment(nsLabelAlignment aAlignment)
|
||||
{
|
||||
|
|
|
@ -53,10 +53,7 @@ public:
|
|||
nsLabel();
|
||||
virtual ~nsLabel();
|
||||
|
||||
// nsISupports
|
||||
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||
NS_IMETHOD_(nsrefcnt) Release(void);
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
// nsILabel part
|
||||
NS_IMETHOD SetLabel(const nsString &aText);
|
||||
|
|
|
@ -1,444 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Tim Copperfield <timecop@japan.co.jp>
|
||||
*
|
||||
* 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 NPL, 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 "nsScrollBar.h"
|
||||
#include "nsGfxCIID.h"
|
||||
#include "xlibrgb.h"
|
||||
|
||||
#define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
|
||||
#define NS_SCROLLBAR_MIN 8
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(nsScrollbar, nsWidget)
|
||||
NS_IMPL_RELEASE_INHERITED(nsScrollbar, nsWidget)
|
||||
NS_IMPL_QUERY_INTERFACE2(nsScrollbar, nsIScrollbar, nsIWidget)
|
||||
|
||||
PRLogModuleInfo *XlibScrollbarLM = PR_NewLogModule("XlibScrollbar");
|
||||
|
||||
nsScrollbar::nsScrollbar(PRBool aIsVertical) : nsWidget(), nsIScrollbar()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mMaxRange = 0;
|
||||
mPosition = 0;
|
||||
mThumbSize = 0;
|
||||
mXScale = 0.0;
|
||||
mYScale = 0.0;
|
||||
mLineIncrement = 1;
|
||||
mIsVertical = aIsVertical;
|
||||
mBackground = NS_RGB(100,100,100);
|
||||
mBackgroundPixel = xxlib_rgb_xpixel_from_rgb(mXlibRgbHandle, mBackground);
|
||||
mBorderPixel = xxlib_rgb_xpixel_from_rgb(mXlibRgbHandle, mBackground);
|
||||
mBar = 0;
|
||||
mBarBounds.x = mBarBounds.y = mBarBounds.width = mBarBounds.height = 0;
|
||||
};
|
||||
|
||||
nsScrollbar::~nsScrollbar()
|
||||
{
|
||||
}
|
||||
|
||||
/* Create scrollbar widget */
|
||||
void nsScrollbar::CreateNative(Window aParent, nsRect aRect)
|
||||
{
|
||||
XSetWindowAttributes attr;
|
||||
unsigned long attr_mask;
|
||||
|
||||
// on a window resize, we don't want to window contents to
|
||||
// be discarded...
|
||||
attr.bit_gravity = NorthWestGravity;
|
||||
// make sure that we listen for events
|
||||
attr.event_mask = StructureNotifyMask | ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask | FocusChangeMask | VisibilityChangeMask;
|
||||
// set the default background color and border to that awful gray
|
||||
attr.background_pixel = mBackgroundPixel;
|
||||
attr.border_pixel = mBorderPixel;
|
||||
// set the colormap
|
||||
attr.colormap = xxlib_rgb_get_cmap(mXlibRgbHandle);
|
||||
// here's what's in the struct
|
||||
attr_mask = CWBitGravity | CWEventMask | CWBackPixel | CWBorderPixel;
|
||||
// check to see if there was actually a colormap.
|
||||
if (attr.colormap)
|
||||
attr_mask |= CWColormap;
|
||||
|
||||
CreateNativeWindow(aParent, mBounds, attr, attr_mask);
|
||||
// set up the scrolling bar.
|
||||
attr.event_mask = Button1MotionMask | ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask | FocusChangeMask | VisibilityChangeMask;
|
||||
attr.background_pixel = xxlib_rgb_xpixel_from_rgb(mXlibRgbHandle, NS_RGB(192,192,192));
|
||||
attr.border_pixel = xxlib_rgb_xpixel_from_rgb(mXlibRgbHandle, NS_RGB(100,100,100));
|
||||
// set up the size
|
||||
CalcBarBounds();
|
||||
mBar = XCreateWindow(mDisplay,
|
||||
mBaseWindow,
|
||||
mBarBounds.x, mBarBounds.y,
|
||||
mBarBounds.width, mBarBounds.height,
|
||||
2, // border width
|
||||
mDepth,
|
||||
InputOutput,
|
||||
mVisual,
|
||||
attr_mask,
|
||||
&attr);
|
||||
XSetWindowBackgroundPixmap(mDisplay, mBar, None);
|
||||
AddWindowCallback(mBar, this);
|
||||
PR_LOG(XlibScrollbarLM, PR_LOG_DEBUG, ("nsScrollbar::CreateNative created window 0x%lx with bar 0x%lx\n",
|
||||
mBaseWindow, mBar));
|
||||
}
|
||||
|
||||
void nsScrollbar::DestroyNative(void)
|
||||
{
|
||||
// override since we have two native widgets
|
||||
if (mBar) {
|
||||
DestroyNativeChildren(mDisplay, mBar);
|
||||
|
||||
XDestroyWindow(mDisplay, mBar);
|
||||
DeleteWindowCallback(mBar);
|
||||
mBar = 0;
|
||||
}
|
||||
if (mBaseWindow) {
|
||||
nsWidget::DestroyNative();
|
||||
mBaseWindow = 0;
|
||||
}
|
||||
}
|
||||
|
||||
NS_METHOD nsScrollbar::SetMaxRange(PRUint32 aEndRange)
|
||||
{
|
||||
PR_LOG(XlibScrollbarLM, PR_LOG_DEBUG, ("nsScrollbar::SetMaxRange()\n"));
|
||||
PR_LOG(XlibScrollbarLM, PR_LOG_DEBUG, ("Max Range set to %d\n", aEndRange));
|
||||
mMaxRange = aEndRange;
|
||||
CalcBarBounds();
|
||||
LayoutBar();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRUint32 nsScrollbar::GetMaxRange(PRUint32& aRange)
|
||||
{
|
||||
PR_LOG(XlibScrollbarLM, PR_LOG_DEBUG, ("nsScrollbar::GetMaxRange()\n"));
|
||||
aRange = mMaxRange;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD nsScrollbar::SetPosition(PRUint32 aPos)
|
||||
{
|
||||
PR_LOG(XlibScrollbarLM, PR_LOG_DEBUG, ("nsScrollbar::SetPosition()\n"));
|
||||
PR_LOG(XlibScrollbarLM, PR_LOG_DEBUG, ("Scroll to %d\n", aPos));
|
||||
mPosition = CLAMP(aPos, 0, mMaxRange);
|
||||
CalcBarBounds();
|
||||
LayoutBar();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRUint32 nsScrollbar::GetPosition(PRUint32& aPosition)
|
||||
{
|
||||
PR_LOG(XlibScrollbarLM, PR_LOG_DEBUG, ("nsScrollbar::GetPosition()\n"));
|
||||
aPosition = mPosition;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD nsScrollbar::SetThumbSize(PRUint32 aSize)
|
||||
{
|
||||
PR_LOG(XlibScrollbarLM, PR_LOG_DEBUG, ("nsScrollbar::SetThumbSize()\n"));
|
||||
PR_LOG(XlibScrollbarLM, PR_LOG_DEBUG, ("Thumb size set to %d\n", aSize));
|
||||
|
||||
mThumbSize = aSize;
|
||||
CalcBarBounds();
|
||||
LayoutBar();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD nsScrollbar::GetThumbSize(PRUint32& aSize)
|
||||
{
|
||||
PR_LOG(XlibScrollbarLM, PR_LOG_DEBUG, ("nsScrollbar::GetThumbSize()\n"));
|
||||
|
||||
aSize = mThumbSize;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD nsScrollbar::SetLineIncrement(PRUint32 aSize)
|
||||
{
|
||||
PR_LOG(XlibScrollbarLM, PR_LOG_DEBUG, ("nsScrollbar::SetLineIncrement()\n"));
|
||||
PR_LOG(XlibScrollbarLM, PR_LOG_DEBUG, ("Set Line Increment to %d\n", aSize));
|
||||
|
||||
mLineIncrement = aSize;
|
||||
CalcBarBounds();
|
||||
LayoutBar();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD nsScrollbar::GetLineIncrement(PRUint32& aSize)
|
||||
{
|
||||
PR_LOG(XlibScrollbarLM, PR_LOG_DEBUG, ("nsScrollbar::GetLineIncrement()\n"));
|
||||
|
||||
aSize = mLineIncrement;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD nsScrollbar::SetParameters(PRUint32 aMaxRange, PRUint32 aThumbSize,
|
||||
PRUint32 aPosition, PRUint32 aLineIncrement)
|
||||
{
|
||||
PR_LOG(XlibScrollbarLM, PR_LOG_DEBUG, ("nsScrollbar::SetParameters()\n"));
|
||||
PR_LOG(XlibScrollbarLM, PR_LOG_DEBUG, ("MaxRange = %d ThumbSize = %d aPosition = %d LineIncrement = %d\n",
|
||||
aMaxRange, aThumbSize, aPosition, aLineIncrement));
|
||||
|
||||
SetMaxRange(aMaxRange);
|
||||
SetThumbSize(aThumbSize);
|
||||
SetPosition(aPosition);
|
||||
SetLineIncrement(aLineIncrement);
|
||||
CalcBarBounds();
|
||||
LayoutBar();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRBool nsScrollbar::OnScroll(PRUint32 scrollCode, int cPos)
|
||||
{
|
||||
PR_LOG(XlibScrollbarLM, PR_LOG_DEBUG, ("nsScrollbar::OnScroll\n"));
|
||||
|
||||
PRBool result = PR_FALSE;
|
||||
switch (scrollCode) {
|
||||
case NS_SCROLLBAR_PAGE_NEXT:
|
||||
result = NextPage();
|
||||
break;
|
||||
case NS_SCROLLBAR_PAGE_PREV:
|
||||
result = PrevPage();
|
||||
break;
|
||||
case NS_SCROLLBAR_POS:
|
||||
if (mIsVertical == PR_TRUE)
|
||||
result = SetPosition(cPos);
|
||||
else
|
||||
result = SetPosition(cPos);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
PRBool nsScrollbar::OnResize(nsSizeEvent &event)
|
||||
{
|
||||
PRBool result;
|
||||
|
||||
PR_LOG(XlibScrollbarLM, PR_LOG_DEBUG, ("nsScrollbar::OnResize\n"));
|
||||
|
||||
nsWidget::OnResize(event);
|
||||
CalcBarBounds();
|
||||
LayoutBar();
|
||||
result = PR_FALSE;
|
||||
return result;
|
||||
}
|
||||
|
||||
PRBool nsScrollbar::DispatchMouseEvent(nsMouseEvent &aEvent)
|
||||
{
|
||||
PRInt32 real;
|
||||
|
||||
PR_LOG(XlibScrollbarLM, PR_LOG_DEBUG, ("nsScrollbar::DispatchMouseEvent\n"));
|
||||
|
||||
/* that calculation is kind of screwed, but better than the original */
|
||||
switch (aEvent.message) {
|
||||
case NS_MOUSE_MIDDLE_BUTTON_DOWN:
|
||||
if (mIsVertical == PR_TRUE) {
|
||||
real = (PRInt32)((float)(PR_MAX(0, aEvent.point.y - ((PRInt32)PR_MAX((mThumbSize * mYScale), NS_SCROLLBAR_MIN) / 2))) / mYScale);
|
||||
OnScroll(NS_SCROLLBAR_POS, real);
|
||||
} else {
|
||||
real = (PRInt32)((float)(PR_MAX(0, aEvent.point.x - ((PRInt32)PR_MAX((mThumbSize * mXScale), NS_SCROLLBAR_MIN) / 2))) / mXScale);
|
||||
OnScroll(NS_SCROLLBAR_POS, real);
|
||||
}
|
||||
break;
|
||||
|
||||
case NS_MOUSE_LEFT_BUTTON_DOWN:
|
||||
if (mIsVertical == PR_TRUE) {
|
||||
if (aEvent.point.y < mBarBounds.y)
|
||||
OnScroll(NS_SCROLLBAR_PAGE_PREV, 0);
|
||||
else if (aEvent.point.y > (mBarBounds.y + mBarBounds.height))
|
||||
OnScroll(NS_SCROLLBAR_PAGE_NEXT, 0);
|
||||
} else { /* !vertical */
|
||||
if (aEvent.point.x < mBarBounds.x)
|
||||
OnScroll(NS_SCROLLBAR_PAGE_PREV, 0);
|
||||
else if (aEvent.point.x > (mBarBounds.x + mBarBounds.width))
|
||||
OnScroll(NS_SCROLLBAR_PAGE_NEXT, 0);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return SendEvent(NS_SCROLLBAR_POS);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsScrollbar::Show(PRBool bState)
|
||||
{
|
||||
PR_LOG(XlibScrollbarLM, PR_LOG_DEBUG, ("nsScrollbar::Show(): %s\n",
|
||||
(bState == PR_TRUE) ? "true" : "false"));
|
||||
nsWidget::Show(bState);
|
||||
if (bState) {
|
||||
if (mBar) {
|
||||
XMapWindow(mDisplay, mBar);
|
||||
}
|
||||
CalcBarBounds();
|
||||
LayoutBar();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsScrollbar::Resize(PRInt32 aWidth,
|
||||
PRInt32 aHeight,
|
||||
PRBool aRepaint)
|
||||
{
|
||||
nsWidget::Resize(aWidth, aHeight, aRepaint);
|
||||
CalcBarBounds();
|
||||
LayoutBar();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsScrollbar::Resize(PRInt32 aX,
|
||||
PRInt32 aY,
|
||||
PRInt32 aWidth,
|
||||
PRInt32 aHeight,
|
||||
PRBool aRepaint)
|
||||
{
|
||||
nsWidget::Resize(aX, aY, aWidth, aHeight, aRepaint);
|
||||
CalcBarBounds();
|
||||
LayoutBar();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsScrollbar::NextPage(void)
|
||||
{
|
||||
PRUint32 max;
|
||||
nsresult result = PR_FALSE;
|
||||
|
||||
// change it locally.
|
||||
PR_LOG(XlibScrollbarLM, PR_LOG_DEBUG, ("nsScrollbar::NextPage(): maxrange is %d thumb is %d position is %d\n", mMaxRange, mThumbSize, mPosition));
|
||||
max = mMaxRange - mThumbSize;
|
||||
PR_LOG(XlibScrollbarLM, PR_LOG_DEBUG, ("nsScrollbar::NextPage(): max is %d\n", max));
|
||||
mPosition += mThumbSize;
|
||||
if (mPosition > max)
|
||||
mPosition = max;
|
||||
PR_LOG(XlibScrollbarLM, PR_LOG_DEBUG, ("nsScrollbar::NextPage(): new position is %d\n", mPosition));
|
||||
|
||||
result = SendEvent(NS_SCROLLBAR_POS);
|
||||
CalcBarBounds();
|
||||
LayoutBar();
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult nsScrollbar::PrevPage(void)
|
||||
{
|
||||
nsresult result = PR_FALSE;
|
||||
|
||||
// check to make sure we don't go backwards
|
||||
if (mThumbSize > mPosition) {
|
||||
mPosition = 0;
|
||||
} else {
|
||||
mPosition -= mThumbSize;
|
||||
}
|
||||
result = SendEvent(NS_SCROLLBAR_POS);
|
||||
CalcBarBounds();
|
||||
LayoutBar();
|
||||
return result;
|
||||
}
|
||||
|
||||
void nsScrollbar::CalcBarBounds(void)
|
||||
{
|
||||
PRUint32 bar_start;
|
||||
PRUint32 bar_end;
|
||||
|
||||
if (mMaxRange == 0) {
|
||||
bar_start = 0;
|
||||
bar_end = 0;
|
||||
mXScale = 0.0;
|
||||
mYScale = 0.0;
|
||||
} else {
|
||||
if (mIsVertical == PR_TRUE) {
|
||||
mYScale = (float)mRequestedSize.height / (float)mMaxRange;
|
||||
bar_start = (PRUint32)((float)mPosition * mYScale);
|
||||
bar_end = (PRUint32)((float)mThumbSize * mYScale);
|
||||
bar_start = CLAMP(bar_start, 0, (PRUint32)(mRequestedSize.height));
|
||||
} else {
|
||||
mXScale = (float)mRequestedSize.width / (float)mMaxRange;
|
||||
bar_start = (PRUint32)((float)mPosition * mXScale);
|
||||
bar_end = (PRUint32)((float)mThumbSize * mXScale);
|
||||
bar_start = CLAMP(bar_start, 0, (PRUint32)(mRequestedSize.width));
|
||||
}
|
||||
}
|
||||
bar_end = PR_MAX(bar_end, NS_SCROLLBAR_MIN);
|
||||
|
||||
if (mIsVertical == PR_TRUE) {
|
||||
mBarBounds.x = 0;
|
||||
mBarBounds.y = bar_start;
|
||||
mBarBounds.width = mRequestedSize.width - 4;
|
||||
mBarBounds.height = bar_end;
|
||||
} else {
|
||||
mBarBounds.x = bar_start;
|
||||
mBarBounds.y = 0;
|
||||
mBarBounds.width = bar_end;
|
||||
mBarBounds.height = mRequestedSize.height - 4;
|
||||
}
|
||||
|
||||
if (mBarBounds.height == 0)
|
||||
mBarBounds.height = 1;
|
||||
|
||||
if (mBarBounds.width == 0)
|
||||
mBarBounds.width = 1;
|
||||
}
|
||||
|
||||
void nsScrollbar::LayoutBar(void)
|
||||
{
|
||||
/* Workaround for bug 77344. I am not sure whether this is mandatory or not. */
|
||||
if (mDisplay)
|
||||
XMoveResizeWindow(mDisplay, mBar,
|
||||
mBarBounds.x, mBarBounds.y,
|
||||
mBarBounds.width, mBarBounds.height);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsScrollbar::Move(PRInt32 aX, PRInt32 aY)
|
||||
{
|
||||
return nsWidget::Move(aX, aY);
|
||||
}
|
||||
|
||||
PRBool nsScrollbar::SendEvent(PRUint32 message)
|
||||
{
|
||||
PRBool result = PR_FALSE;
|
||||
// send the event
|
||||
if (mEventCallback) {
|
||||
nsScrollbarEvent sevent;
|
||||
sevent.message = message;
|
||||
sevent.widget = (nsWidget *)this;
|
||||
sevent.eventStructType = NS_SCROLLBAR_EVENT;
|
||||
sevent.position = (mPosition);
|
||||
// send the event
|
||||
result = ConvertStatus((*mEventCallback) (&sevent));
|
||||
// the gtk code indicates that the callback can
|
||||
// modify the position. how odd.
|
||||
mPosition = sevent.position;
|
||||
}
|
||||
return result;
|
||||
}
|
|
@ -1,105 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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) 1998
|
||||
* 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 NPL, 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 nsScrollbar_h__
|
||||
#define nsScrollbar_h__
|
||||
|
||||
#include "nsWidget.h"
|
||||
#include "nsIScrollbar.h"
|
||||
|
||||
class nsScrollbar : public nsWidget,
|
||||
public nsIScrollbar
|
||||
{
|
||||
|
||||
public:
|
||||
nsScrollbar(PRBool aIsVertical);
|
||||
virtual ~nsScrollbar();
|
||||
|
||||
// nsISupports
|
||||
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||
NS_IMETHOD_(nsrefcnt) Release(void);
|
||||
|
||||
// Override some of the native widget methods for scrollbars
|
||||
PRBool OnResize (nsSizeEvent &event);
|
||||
PRBool DispatchMouseEvent (nsMouseEvent &aEvent);
|
||||
NS_IMETHOD Show (PRBool bState);
|
||||
NS_IMETHOD Move (PRInt32 aX, PRInt32 aY);
|
||||
NS_IMETHOD Resize (PRInt32 aWidth,
|
||||
PRInt32 aHeight,
|
||||
PRBool aRepaint);
|
||||
NS_IMETHOD Resize (PRInt32 aX,
|
||||
PRInt32 aY,
|
||||
PRInt32 aWidth,
|
||||
PRInt32 aHeight,
|
||||
PRBool aRepaint);
|
||||
virtual void DestroyNative(); // override since we have 2 native widgets
|
||||
|
||||
// nsIScrollBar implementation
|
||||
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);
|
||||
|
||||
PRBool OnScroll(PRUint32 scrollCode, int cPos);
|
||||
void CreateNative(Window aParent, nsRect aRect);
|
||||
PRBool SendEvent(PRUint32 message);
|
||||
|
||||
private:
|
||||
void CalcBarBounds(void);
|
||||
void LayoutBar(void);
|
||||
nsresult NextPage(void);
|
||||
nsresult PrevPage(void);
|
||||
PRUint32 mMaxRange;
|
||||
PRUint32 mPosition;
|
||||
PRUint32 mThumbSize;
|
||||
float mXScale;
|
||||
float mYScale;
|
||||
PRUint32 mLineIncrement;
|
||||
PRBool mIsVertical;
|
||||
nsIRenderingContext *mRenderingContext;
|
||||
Window mBar;
|
||||
nsRect mBarBounds;
|
||||
};
|
||||
|
||||
#endif // nsButton_h__
|
|
@ -37,12 +37,8 @@
|
|||
|
||||
#include "nsTextWidget.h"
|
||||
|
||||
NS_IMPL_ADDREF(nsTextWidget)
|
||||
NS_IMPL_RELEASE(nsTextWidget)
|
||||
|
||||
nsTextWidget::nsTextWidget() : nsTextHelper()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mName.Assign(NS_LITERAL_STRING("nsTextWidget"));
|
||||
}
|
||||
|
||||
|
@ -50,19 +46,7 @@ nsTextWidget::~nsTextWidget()
|
|||
{
|
||||
}
|
||||
|
||||
nsresult nsTextWidget::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||
{
|
||||
nsresult result = nsWidget::QueryInterface(aIID, aInstancePtr);
|
||||
|
||||
static NS_DEFINE_IID(kInsTextWidgetIID, NS_ITEXTWIDGET_IID);
|
||||
if (result == NS_NOINTERFACE && aIID.Equals(kInsTextWidgetIID)) {
|
||||
*aInstancePtr = (void*) ((nsITextWidget*)this);
|
||||
NS_ADDREF_THIS();
|
||||
result = NS_OK;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
NS_IMPL_ISUPPORTS_INHERITED1(nsTextWidget, nsWidget, nsITextWidget)
|
||||
|
||||
NS_METHOD nsTextWidget::Paint(nsIRenderingContext& aRenderingContext,
|
||||
const nsRect& aDirtyRect)
|
||||
|
|
|
@ -49,10 +49,7 @@ public:
|
|||
nsTextWidget();
|
||||
virtual ~nsTextWidget();
|
||||
|
||||
// nsISupports
|
||||
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||
NS_IMETHOD_(nsrefcnt) Release(void);
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext,
|
||||
const nsRect& aDirtyRect);
|
||||
|
|
|
@ -47,7 +47,7 @@ static PRUintn gToolkitTLSIndex = 0;
|
|||
|
||||
nsToolkit::nsToolkit()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_INIT_ISUPPORTS();
|
||||
mGC = nsnull;
|
||||
mDisplay = xxlib_rgb_get_display(nsAppShell::GetXlibRgbHandle());
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ public:
|
|||
PRBool aRepaint);
|
||||
|
||||
NS_IMETHOD Enable(PRBool bState);
|
||||
NS_IMETHOD SetFocus(PRBool aRaise);
|
||||
NS_IMETHOD SetFocus(PRBool aRaise = PR_FALSE);
|
||||
NS_IMETHOD SetName(const char * aName);
|
||||
NS_IMETHOD SetBackgroundColor(const nscolor &aColor);
|
||||
virtual nsIFontMetrics* GetFont(void);
|
||||
|
|
|
@ -206,7 +206,6 @@ NS_IMPL_ISUPPORTS_INHERITED0(nsWindow, nsWidget)
|
|||
|
||||
nsWindow::nsWindow() : nsWidget()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mName.Assign(NS_LITERAL_STRING("nsWindow"));
|
||||
mBackground = NS_RGB(255, 255, 255);
|
||||
mBackgroundPixel = xxlib_rgb_xpixel_from_rgb(mXlibRgbHandle, mBackground);
|
||||
|
|
Загрузка…
Ссылка в новой задаче