Latest source for Qt-Mozilla from Bugzilla #70511

This commit is contained in:
johng%corel.com 2001-04-06 18:38:16 +00:00
parent 926fa731c5
commit ce5ef6cf8f
62 changed files with 8349 additions and 5173 deletions

View File

@ -17,6 +17,7 @@
# Rights Reserved.
#
# Contributor(s):
# John C. Griggs <johng@corel.com>
#
DEPTH = ../../..
@ -30,7 +31,6 @@ MODULE = layout
LIBRARY_NAME = gfx_qt
IS_COMPONENT = 1
CPPSRCS = \
nsDeviceContextQT.cpp \
nsDeviceContextSpecFactoryQT.cpp \
@ -61,7 +61,6 @@ EXTRA_DSO_LDOPTS += $(MOZ_COMPONENT_LIBS) \
-lgkgfx \
$(MOZ_JS_LIBS) \
$(NULL)
# -lraptorgfx \
DEFINES += -D_IMPL_NS_GFXNONXP
ifeq ($(OS_ARCH), Linux)
@ -82,4 +81,3 @@ INCLUDES += \
-I$(srcdir)/. \
-I$(srcdir)/.. \
$(NULL)

View File

@ -18,7 +18,8 @@
* Rights Reserved.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
* John C. Griggs <johng@corel.com>
*
*/
#include <math.h>
@ -30,11 +31,14 @@
#include "nsCRT.h"
#include "nsDeviceContextQT.h"
#include "nsFontMetricsQT.h"
#include "nsFont.h"
#include "nsGfxCIID.h"
#include "nsRenderingContextQT.h"
#include "nsGfxPSCID.h"
#include "nsIDeviceContextPS.h"
#include <qpaintdevicemetrics.h>
#include <qscrollbar.h>
#include <qpalette.h>
@ -43,163 +47,157 @@
#include "nsIScreenManager.h"
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
#define QCOLOR_TO_NS_RGB(c) \
((nscolor)NS_RGB(c.red(),c.green(),c.blue()))
static NS_DEFINE_CID(kPrefCID,NS_PREF_CID);
nscoord nsDeviceContextQT::mDpi = 96;
NS_IMPL_ISUPPORTS1(nsDeviceContextQT, nsIDeviceContext)
NS_IMPL_ISUPPORTS1(nsDeviceContextQT,nsIDeviceContext)
nsDeviceContextQT::nsDeviceContextQT()
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsDeviceContextQT::nsDeviceContextQT\n"));
NS_INIT_REFCNT();
mTwipsToPixels = 1.0;
mPixelsToTwips = 1.0;
mDepth = 0 ;
mPaletteInfo.isPaletteDevice = PR_FALSE;
mPaletteInfo.sizePalette = 0;
mPaletteInfo.numReserved = 0;
mPaletteInfo.palette = NULL;
mNumCells = 0;
mWidthFloat = 0.0f;
mHeightFloat = 0.0f;
mWidth = -1;
mHeight = -1;
NS_INIT_REFCNT();
mTwipsToPixels = 1.0;
mPixelsToTwips = 1.0;
mDepth = 0 ;
mPaletteInfo.isPaletteDevice = PR_FALSE;
mPaletteInfo.sizePalette = 0;
mPaletteInfo.numReserved = 0;
mPaletteInfo.palette = NULL;
mNumCells = 0;
mWidthFloat = 0.0f;
mHeightFloat = 0.0f;
mWidth = -1;
mHeight = -1;
}
nsDeviceContextQT::~nsDeviceContextQT()
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsDeviceContextQT::~nsDeviceContextQT\n"));
nsresult rv;
nsCOMPtr<nsIPref> prefs = do_GetService(kPrefCID, &rv);
nsCOMPtr<nsIPref> prefs = do_GetService(kPrefCID,&rv);
if (NS_SUCCEEDED(rv)) {
prefs->UnregisterCallback("browser.display.screen_resolution",
prefChanged, (void *)this);
prefChanged,(void*)this);
}
}
NS_IMETHODIMP nsDeviceContextQT::Init(nsNativeWidget aNativeWidget)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsDeviceContextQT::Init\n"));
PRBool bCleanUp = PR_FALSE;
QWidget * pWidget = nsnull;
PRBool bCleanUp = PR_FALSE;
QWidget *pWidget = nsnull;
mWidget = (QWidget *) aNativeWidget;
mWidget = (QWidget*)aNativeWidget;
if (mWidget != nsnull)
pWidget = mWidget;
if (mWidget != nsnull)
pWidget = mWidget;
else {
pWidget = new QWidget();
bCleanUp = PR_TRUE;
}
QPaintDeviceMetrics qPaintMetrics(pWidget);
nsresult ignore;
nsCOMPtr<nsIScreenManager> sm(do_GetService("@mozilla.org/gfx/screenmanager;1",
&ignore));
if (sm) {
nsCOMPtr<nsIScreen> screen;
sm->GetPrimaryScreen(getter_AddRefs(screen));
if (screen) {
PRInt32 x,y,width,height,depth;
screen->GetAvailRect(&x,&y,&width,&height);
screen->GetPixelDepth(&depth);
mWidthFloat = float(width);
mHeightFloat = float(height);
mDepth = NS_STATIC_CAST(PRUint32,depth);
}
}
static int initialized = 0;
if (!initialized) {
initialized = 1;
// Set prefVal the value of the preference "browser.display.screen_resolution"
// or -1 if we can't get it.
// If it's negative, we pretend it's not set.
// If it's 0, it means force use of the operating system's logical resolution.
// If it's positive, we use it as the logical resolution
PRInt32 prefVal = -1;
nsresult res;
NS_WITH_SERVICE(nsIPref,prefs,kPrefCID,&res);
if (NS_SUCCEEDED(res) && prefs) {
res = prefs->GetIntPref("browser.display.screen_resolution",&prefVal);
if (! NS_SUCCEEDED(res)) {
prefVal = -1;
}
prefs->RegisterCallback("browser.display.screen_resolution",prefChanged,
(void*)this);
}
// Set OSVal to what the operating system thinks the logical resolution is.
PRInt32 OSVal = qPaintMetrics.logicalDpiX();
if (prefVal > 0) {
// If there's a valid pref value for the logical resolution,
// use it.
mDpi = prefVal;
}
else if (prefVal == 0 || OSVal > 96) {
// Either if the pref is 0 (force use of OS value) or the OS
// value is bigger than 96, use the OS value.
mDpi = OSVal;
}
else {
pWidget = new QWidget();
bCleanUp = PR_TRUE;
// if we couldn't get the pref or it's negative, and the OS
// value is under 96ppi, then use 96.
mDpi = 96;
}
QPaintDeviceMetrics qPaintMetrics(pWidget);
nsresult ignore;
nsCOMPtr<nsIScreenManager> sm(do_GetService("@mozilla.org/gfx/screenmanager;1",&ignore));
if (sm) {
nsCOMPtr<nsIScreen> screen;
sm->GetPrimaryScreen(getter_AddRefs(screen));
if (screen) {
PRInt32 x, y, width, height, depth;
screen->GetAvailRect(&x,&y,&width,&height);
screen->GetPixelDepth(&depth);
mWidthFloat = float(width);
mHeightFloat = float(height);
mDepth = NS_STATIC_CAST(PRUint32,depth);
}
}
static int initialized = 0;
if (!initialized) {
initialized = 1;
// Set prefVal the value of the preference "browser.display.screen_resolution"
// or -1 if we can't get it.
// If it's negative, we pretend it's not set.
// If it's 0, it means force use of the operating system's logical resolution.
// If it's positive, we use it as the logical resolution
PRInt32 prefVal = -1;
nsresult res;
NS_WITH_SERVICE(nsIPref, prefs, kPrefCID, &res);
if (NS_SUCCEEDED(res) && prefs) {
res = prefs->GetIntPref("browser.display.screen_resolution", &prefVal);
if (! NS_SUCCEEDED(res)) {
prefVal = -1;
}
prefs->RegisterCallback("browser.display.screen_resolution", prefChanged,
(void *)this);
}
// Set OSVal to what the operating system thinks the logical resolution is.
PRInt32 OSVal = qPaintMetrics.logicalDpiX();
if (prefVal > 0) {
// If there's a valid pref value for the logical resolution,
// use it.
mDpi = prefVal;
} else if ((prefVal == 0) || (OSVal > 96)) {
// Either if the pref is 0 (force use of OS value) or the OS
// value is bigger than 96, use the OS value.
mDpi = OSVal;
} else {
// if we couldn't get the pref or it's negative, and the OS
// value is under 96ppi, then use 96.
mDpi = 96;
}
}
// Now for some wacky heuristics.
SetDPI(mDpi);
}
SetDPI(mDpi);
#ifdef DEBUG
static PRBool once = PR_TRUE;
if (once) {
PR_LOG(QtGfxLM,
PR_LOG_DEBUG,
("nsDeviceContextQT::Init dpi=%d, t2p=%d, p2t=%d\n",
mDpi,
mTwipsToPixels,
mPixelsToTwips));
printf("GFX: dpi=%d t2p=%g p2t=%g depth=%d\n",
mDpi,mTwipsToPixels,mPixelsToTwips,mDepth);
once = PR_FALSE;
}
static PRBool once = PR_TRUE;
if (once) {
printf("GFX: dpi=%d t2p=%g p2t=%g depth=%d\n",
mDpi,mTwipsToPixels,mPixelsToTwips,mDepth);
once = PR_FALSE;
}
#endif
QScrollBar * sb = new QScrollBar(nsnull, nsnull);
if (sb) {
sb->setOrientation(QScrollBar::Vertical);
QSize size = sb->sizeHint();
QScrollBar * sb = new QScrollBar(nsnull,nsnull);
if (sb) {
sb->setOrientation(QScrollBar::Vertical);
QSize size = sb->sizeHint();
mScrollbarWidth = size.width();
mScrollbarWidth = size.width();
sb->setOrientation(QScrollBar::Horizontal);
size = sb->sizeHint();
sb->setOrientation(QScrollBar::Horizontal);
size = sb->sizeHint();
mScrollbarHeight = size.height();
}
//QSize size = pWidget->frameSize();
QRect rect = pWidget->frameGeometry();
mScrollbarHeight = size.height();
}
QRect rect = pWidget->frameGeometry();
mWindowBorderWidth = rect.width();
mWindowBorderHeight = rect.height();
mWindowBorderWidth = rect.width();
mWindowBorderHeight = rect.height();
DeviceContextImpl::CommonInit();
DeviceContextImpl::CommonInit();
delete sb;
delete sb;
if (bCleanUp)
delete pWidget;
return NS_OK;
if (bCleanUp)
delete pWidget;
return NS_OK;
}
NS_IMETHODIMP
nsDeviceContextQT::CreateRenderingContext(nsIRenderingContext *&aContext)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsDeviceContextQT::CreateRenderingContext\n"));
nsIRenderingContext *pContext;
nsresult rv;
nsDrawingSurfaceQT *surf;
nsresult rv;
nsDrawingSurfaceQT *surf;
QPaintDevice *pDev = nsnull;
if (mWidget)
@ -208,26 +206,24 @@ nsDeviceContextQT::CreateRenderingContext(nsIRenderingContext *&aContext)
// to call init for this, we need to have a valid nsDrawingSurfaceQT created
pContext = new nsRenderingContextQT();
if (nsnull != pContext)
{
if (nsnull != pContext) {
NS_ADDREF(pContext);
// create the nsDrawingSurfaceQT
surf = new nsDrawingSurfaceQT();
if (surf)
{
QPainter *gc = new QPainter();
if (surf) {
QPainter *gc = new QPainter();
// init the nsDrawingSurfaceQT
if (pDev)
rv = surf->Init(pDev,gc);
else
rv = surf->Init(gc,10,10,0);
// init the nsDrawingSurfaceQT
if (pDev)
rv = surf->Init(pDev,gc);
else
rv = surf->Init(gc,10,10,0);
if (NS_OK == rv)
// Init the nsRenderingContextQT
rv = pContext->Init(this, surf);
if (NS_OK == rv)
// Init the nsRenderingContextQT
rv = pContext->Init(this,surf);
}
else
rv = NS_ERROR_OUT_OF_MEMORY;
@ -235,116 +231,123 @@ nsDeviceContextQT::CreateRenderingContext(nsIRenderingContext *&aContext)
else
rv = NS_ERROR_OUT_OF_MEMORY;
if (NS_OK != rv)
{
if (NS_OK != rv) {
NS_IF_RELEASE(pContext);
}
aContext = pContext;
return rv;
}
NS_IMETHODIMP
nsDeviceContextQT::SupportsNativeWidgets(PRBool &aSupportsWidgets)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsDeviceContextQT::SupportsNativeWidgets\n"));
//XXX it is very critical that this not lie!! MMP
// read the comments in the mac code for this
aSupportsWidgets = PR_TRUE;
//XXX it is very critical that this not lie!! MMP
// read the comments in the mac code for this
aSupportsWidgets = PR_TRUE;
return NS_OK;
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextQT::GetScrollBarDimensions(float &aWidth,
float &aHeight) const
{
aWidth = mScrollbarWidth * mPixelsToTwips;
aHeight = mScrollbarHeight * mPixelsToTwips;
PR_LOG(QtGfxLM,
PR_LOG_DEBUG,
("nsDeviceContextQT::GetScrollBarDimensions: %dx%d\n",
aWidth,
aHeight));
return NS_OK;
aWidth = mScrollbarWidth * mPixelsToTwips;
aHeight = mScrollbarHeight * mPixelsToTwips;
return NS_OK;
}
NS_IMETHODIMP
nsDeviceContextQT::GetSystemAttribute(nsSystemAttrID anID,
SystemAttrStruct * aInfo) const
SystemAttrStruct *aInfo) const
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsDeviceContextQT::GetSystemAttribute\n"));
nsresult status = NS_OK;
QPalette palette = qApp->palette();
QColorGroup normalGroup = palette.inactive();
QColorGroup activeGroup = palette.active();
QColorGroup disabledGroup = palette.disabled();
nsresult status = NS_OK;
QPalette palette = qApp->palette();
QColorGroup normalGroup = palette.inactive();
QColorGroup activeGroup = palette.active();
switch (anID)
{
//---------
// Colors
//---------
switch (anID) {
//---------
// Colors
//---------
case eSystemAttr_Color_WindowBackground:
*aInfo->mColor = normalGroup.background().rgb();
break;
*aInfo->mColor = QCOLOR_TO_NS_RGB(normalGroup.background());
break;
case eSystemAttr_Color_WindowForeground:
*aInfo->mColor = normalGroup.foreground().rgb();
break;
*aInfo->mColor = QCOLOR_TO_NS_RGB(normalGroup.foreground());
break;
case eSystemAttr_Color_WidgetBackground:
*aInfo->mColor = normalGroup.background().rgb();
break;
*aInfo->mColor = QCOLOR_TO_NS_RGB(normalGroup.background());
break;
case eSystemAttr_Color_WidgetForeground:
*aInfo->mColor = normalGroup.foreground().rgb();
break;
*aInfo->mColor = QCOLOR_TO_NS_RGB(normalGroup.foreground());
break;
case eSystemAttr_Color_WidgetSelectBackground:
*aInfo->mColor = activeGroup.background().rgb();
break;
*aInfo->mColor = QCOLOR_TO_NS_RGB(activeGroup.background());
break;
case eSystemAttr_Color_WidgetSelectForeground:
*aInfo->mColor = activeGroup.foreground().rgb();
break;
*aInfo->mColor = QCOLOR_TO_NS_RGB(activeGroup.foreground());
break;
case eSystemAttr_Color_Widget3DHighlight:
*aInfo->mColor = normalGroup.highlight().rgb();
break;
*aInfo->mColor = NS_RGB(0xa0,0xa0,0xa0);
break;
case eSystemAttr_Color_Widget3DShadow:
*aInfo->mColor = normalGroup.shadow().rgb();
break;
*aInfo->mColor = NS_RGB(0x40,0x40,0x40);
break;
case eSystemAttr_Color_TextBackground:
*aInfo->mColor = normalGroup.background().rgb();
break;
*aInfo->mColor = QCOLOR_TO_NS_RGB(normalGroup.background());
break;
case eSystemAttr_Color_TextForeground:
*aInfo->mColor = normalGroup.text().rgb();
break;
*aInfo->mColor = QCOLOR_TO_NS_RGB(normalGroup.text());
break;
case eSystemAttr_Color_TextSelectBackground:
*aInfo->mColor = activeGroup.background().rgb();
break;
*aInfo->mColor = QCOLOR_TO_NS_RGB(activeGroup.highlight());
break;
case eSystemAttr_Color_TextSelectForeground:
*aInfo->mColor = activeGroup.foreground().rgb();
break;
//---------
// Size
//---------
*aInfo->mColor
= QCOLOR_TO_NS_RGB(activeGroup.highlightedText());
break;
//---------
// Size
//---------
case eSystemAttr_Size_ScrollbarHeight:
aInfo->mSize = mScrollbarHeight;
break;
aInfo->mSize = mScrollbarHeight;
break;
case eSystemAttr_Size_ScrollbarWidth:
aInfo->mSize = mScrollbarWidth;
break;
aInfo->mSize = mScrollbarWidth;
break;
case eSystemAttr_Size_WindowTitleHeight:
aInfo->mSize = 0;
break;
aInfo->mSize = 0;
break;
case eSystemAttr_Size_WindowBorderWidth:
aInfo->mSize = mWindowBorderWidth;
break;
aInfo->mSize = mWindowBorderWidth;
break;
case eSystemAttr_Size_WindowBorderHeight:
aInfo->mSize = mWindowBorderHeight;
break;
aInfo->mSize = mWindowBorderHeight;
break;
case eSystemAttr_Size_Widget3DBorder:
aInfo->mSize = 4;
break;
//---------
// Fonts
//---------
aInfo->mSize = 4;
break;
//---------
// Fonts
//---------
case eSystemAttr_Font_Caption:
case eSystemAttr_Font_Icon:
case eSystemAttr_Font_Menu:
@ -363,170 +366,116 @@ nsDeviceContextQT::GetSystemAttribute(nsSystemAttrID anID,
case eSystemAttr_Font_Field:
case eSystemAttr_Font_Tooltips:
case eSystemAttr_Font_Widget:
status = NS_ERROR_FAILURE;
break;
}
return status;
status = GetSystemFontInfo(aInfo->mFont);
break;
}
return status;
}
NS_IMETHODIMP
nsDeviceContextQT::GetDrawingSurface(nsIRenderingContext &aContext,
nsDrawingSurface &aSurface)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsDeviceContextQT::GetDrawingSurface\n"));
aContext.CreateDrawingSurface(nsnull, 0, aSurface);
return (nsnull == aSurface) ? NS_ERROR_OUT_OF_MEMORY : NS_OK;
aContext.CreateDrawingSurface(nsnull,0,aSurface);
return (nsnull == aSurface) ? NS_ERROR_OUT_OF_MEMORY : NS_OK;
}
NS_IMETHODIMP nsDeviceContextQT::ConvertPixel(nscolor aColor,
PRUint32 & aPixel)
PRUint32 &aPixel)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsDeviceContextQT::ConvertPixel\n"));
QColor color(NS_GET_R(aColor), NS_GET_G(aColor), NS_GET_B(aColor));
aPixel = color.rgb();
QColor color(NS_GET_R(aColor),NS_GET_G(aColor),NS_GET_B(aColor));
return NS_OK;
aPixel = color.pixel();
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextQT::CheckFontExistence(const nsString& aFontName)
{
float t2d;
GetTwipsToDevUnits(t2d);
nsresult rv = NS_ERROR_FAILURE;
char* fontName = aFontName.ToNewCString();
PR_LOG(QtGfxLM,
PR_LOG_DEBUG,
("nsDeviceContextQT::CheckFontExistence: looking for %s\n",
fontName));
QFont font(fontName);
QFontInfo fontInfo(font);
if (fontInfo.exactMatch() ||
fontInfo.family() == font.family())
{
rv = NS_OK;
}
delete [] fontName;
if (rv)
{
PR_LOG(QtGfxLM,
PR_LOG_DEBUG,
("nsDeviceContextQT::CheckFontExistence: didn't find it \n"));
}
else
{
PR_LOG(QtGfxLM,
PR_LOG_DEBUG,
("nsDeviceContextQT::CheckFontExistence: found it\n"));
}
return rv;
return nsFontMetricsQT::FamilyExists(aFontName);
}
NS_IMETHODIMP nsDeviceContextQT::GetDeviceSurfaceDimensions(PRInt32 &aWidth,
PRInt32 &aHeight)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsDeviceContextQT::GetDeviceSurfaceDimensions\n"));
if (-1 == mWidth)
mWidth = NSToIntRound(mWidthFloat * mDevUnitsToAppUnits);
if (-1 == mWidth)
mWidth = NSToIntRound(mWidthFloat * mDevUnitsToAppUnits);
if (-1 == mHeight)
mHeight = NSToIntRound(mHeightFloat * mDevUnitsToAppUnits);
if (-1 == mHeight)
mHeight = NSToIntRound(mHeightFloat * mDevUnitsToAppUnits);
aWidth = mWidth;
aHeight = mHeight;
return NS_OK;
aWidth = mWidth;
aHeight = mHeight;
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextQT::GetRect(nsRect &aRect)
{
PRInt32 width, height;
nsresult rv;
PRInt32 width,height;
nsresult rv;
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsDeviceContextQT::GetRect\n"));
rv = GetDeviceSurfaceDimensions(width, height);
aRect.x = 0;
aRect.y = 0;
aRect.width = width;
aRect.height = height;
return rv;
rv = GetDeviceSurfaceDimensions(width,height);
aRect.x = 0;
aRect.y = 0;
aRect.width = width;
aRect.height = height;
return rv;
}
NS_IMETHODIMP nsDeviceContextQT::GetClientRect(nsRect &aRect)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsDeviceContextQT::GetClientRect\n"));
return GetRect(aRect);
return GetRect(aRect);
}
NS_IMETHODIMP
nsDeviceContextQT::GetDeviceContextFor(nsIDeviceContextSpec *aDevice,
nsIDeviceContext *&aContext)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsDeviceContextQT::GetDeviceContextFor\n"));
static NS_DEFINE_CID(kCDeviceContextPS, NS_DEVICECONTEXTPS_CID);
static NS_DEFINE_CID(kCDeviceContextPS,NS_DEVICECONTEXTPS_CID);
// Create a Postscript device context
nsresult rv;
nsIDeviceContextPS *dcps;
// Create a Postscript device context
nsresult rv;
nsIDeviceContextPS *dcps;
rv = nsComponentManager::CreateInstance(kCDeviceContextPS,
nsnull,
NS_GET_IID(nsIDeviceContextPS),
(void **)&dcps);
rv = nsComponentManager::CreateInstance(kCDeviceContextPS,nsnull,
NS_GET_IID(nsIDeviceContextPS),
(void**)&dcps);
NS_ASSERTION(NS_SUCCEEDED(rv),"Couldn't create PS Device context");
dcps->SetSpec(aDevice);
dcps->InitDeviceContextPS((nsIDeviceContext*)aContext,
(nsIDeviceContext*)this);
NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't create PS Device context");
dcps->SetSpec(aDevice);
dcps->InitDeviceContextPS((nsIDeviceContext*)aContext,
(nsIDeviceContext*)this);
rv = dcps->QueryInterface(NS_GET_IID(nsIDeviceContext),
(void **)&aContext);
NS_RELEASE(dcps);
return rv;
rv = dcps->QueryInterface(NS_GET_IID(nsIDeviceContext),
(void**)&aContext);
NS_RELEASE(dcps);
return rv;
}
NS_IMETHODIMP nsDeviceContextQT::BeginDocument(PRUnichar * aTitle)
NS_IMETHODIMP nsDeviceContextQT::BeginDocument(PRUnichar *aTitle)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsDeviceContextQT::BeginDocument\n"));
return NS_OK;
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextQT::EndDocument(void)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsDeviceContextQT::EndDocument\n"));
return NS_OK;
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextQT::BeginPage(void)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsDeviceContextQT::BeginPage\n"));
return NS_OK;
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextQT::EndPage(void)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsDeviceContextQT::EndPage\n"));
return NS_OK;
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextQT::GetDepth(PRUint32& aDepth)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsDeviceContextQT::GetDepth\n"));
aDepth = mDepth;
return NS_OK;
aDepth = mDepth;
return NS_OK;
}
nsresult nsDeviceContextQT::SetDPI(PRInt32 aDpi)
@ -543,17 +492,15 @@ nsresult nsDeviceContextQT::SetDPI(PRInt32 aDpi)
return NS_OK;
}
/* For some reason, Qt seems to want to use its own strcmp */
#define qstrcmp strcmp
int nsDeviceContextQT::prefChanged(const char *aPref, void *aClosure)
int nsDeviceContextQT::prefChanged(const char *aPref,void *aClosure)
{
nsDeviceContextQT *context = (nsDeviceContextQT*)aClosure;
nsresult rv;
if (nsCRT::strcmp(aPref, "browser.display.screen_resolution") == 0) {
if (nsCRT::strcmp(aPref,"browser.display.screen_resolution") == 0) {
PRInt32 dpi;
NS_WITH_SERVICE(nsIPref, prefs, kPrefCID, &rv);
NS_WITH_SERVICE(nsIPref,prefs,kPrefCID,&rv);
rv = prefs->GetIntPref(aPref, &dpi);
if (NS_SUCCEEDED(rv))
context->SetDPI(dpi);
@ -561,6 +508,28 @@ int nsDeviceContextQT::prefChanged(const char *aPref, void *aClosure)
return 0;
}
/* Just in case, put things back to normal */
#undef qstrcmp
nsresult
nsDeviceContextQT::GetSystemFontInfo(nsFont* aFont) const
{
nsresult status = NS_OK;
int rawWeight;
QFont theFont = QApplication::font();
QFontInfo theFontInfo(theFont);
aFont->style = NS_FONT_STYLE_NORMAL;
aFont->weight = NS_FONT_WEIGHT_NORMAL;
aFont->decorations = NS_FONT_DECORATION_NONE;
aFont->name.AssignWithConversion(theFontInfo.family().latin1());
if (theFontInfo.bold()) {
aFont->weight = NS_FONT_WEIGHT_BOLD;
}
rawWeight = theFontInfo.pointSize();
aFont->size = NSIntPixelsToTwips(rawWeight,mPixelsToTwips);
if (theFontInfo.italic()) {
aFont->style = NS_FONT_STYLE_ITALIC;
}
if (theFontInfo.underline()) {
aFont->decorations = NS_FONT_DECORATION_UNDERLINE;
}
return (status);
}

View File

@ -18,8 +18,9 @@
* Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
*
*/
#ifndef nsDeviceContextQT_h___
#define nsDeviceContextQT_h___
@ -29,7 +30,7 @@
#include "nsIView.h"
#include "nsIRenderingContext.h"
#include "nsRenderingContextQT.h"
class QWidget;
class nsDeviceContextQT : public DeviceContextImpl
{
@ -42,12 +43,18 @@ public:
NS_IMETHOD Init(nsNativeWidget aNativeWidget);
NS_IMETHOD CreateRenderingContext(nsIRenderingContext *&aContext);
NS_IMETHOD CreateRenderingContext(nsIView *aView, nsIRenderingContext *&aContext) {return(DeviceContextImpl::CreateRenderingContext(aView,aContext));}
NS_IMETHOD CreateRenderingContext(nsIWidget *aWidget, nsIRenderingContext *&aContext) {return (DeviceContextImpl::CreateRenderingContext(aWidget,aContext));}
NS_IMETHOD CreateRenderingContext(nsIView *aView,nsIRenderingContext *&aContext)
{
return(DeviceContextImpl::CreateRenderingContext(aView,aContext));
}
NS_IMETHOD CreateRenderingContext(nsIWidget *aWidget,nsIRenderingContext *&aContext)
{
return (DeviceContextImpl::CreateRenderingContext(aWidget,aContext));
}
NS_IMETHOD SupportsNativeWidgets(PRBool &aSupportsWidgets);
NS_IMETHOD GetScrollBarDimensions(float &aWidth, float &aHeight) const;
NS_IMETHOD GetScrollBarDimensions(float &aWidth,float &aHeight) const;
NS_IMETHOD GetSystemAttribute(nsSystemAttrID anID,
SystemAttrStruct * aInfo) const;
@ -58,26 +65,26 @@ public:
NS_IMETHOD GetDrawingSurface(nsIRenderingContext &aContext,
nsDrawingSurface &aSurface);
NS_IMETHOD ConvertPixel(nscolor aColor, PRUint32 & aPixel);
NS_IMETHOD CheckFontExistence(const nsString& aFontName);
NS_IMETHOD ConvertPixel(nscolor aColor,PRUint32 &aPixel);
NS_IMETHOD CheckFontExistence(const nsString &aFontName);
NS_IMETHOD GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight);
NS_IMETHOD GetDeviceSurfaceDimensions(PRInt32 &aWidth,PRInt32 &aHeight);
NS_IMETHOD GetClientRect(nsRect &aRect);
NS_IMETHOD GetRect(nsRect &aRect);
NS_IMETHOD GetDeviceContextFor(nsIDeviceContextSpec *aDevice,
nsIDeviceContext *&aContext);
NS_IMETHOD BeginDocument(PRUnichar * aTitle);
NS_IMETHOD BeginDocument(PRUnichar *aTitle);
NS_IMETHOD EndDocument(void);
NS_IMETHOD BeginPage(void);
NS_IMETHOD EndPage(void);
// Overridden DeviceContextImpl functions.
NS_IMETHOD GetDepth(PRUint32& aDepth);
NS_IMETHOD GetDepth(PRUint32 &aDepth);
static int prefChanged(const char *aPref, void *aClosure);
static int prefChanged(const char *aPref,void *aClosure);
nsresult SetDPI(PRInt32 dpi);
private:
@ -89,12 +96,17 @@ private:
PRInt16 mScrollbarWidth;
PRInt16 mWindowBorderWidth;
PRInt16 mWindowBorderHeight;
QWidget * mWidget;
QWidget *mWidget;
PRInt32 mWidth;
PRInt32 mHeight;
float mWidthFloat;
float mHeightFloat;
static nscoord mDpi;
nsresult GetSystemFontInfo(nsFont *aFont) const;
PRUint32 mID;
};
#endif /* nsDeviceContextQT_h___ */

View File

@ -18,6 +18,7 @@
* Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
*/
#include "nsDeviceContextSpecFactoryQT.h"
@ -27,16 +28,25 @@
#include "plstr.h"
#include <qapplication.h>
//JCG #define DBG_JCG 1
#ifdef DBG_JCG
PRUint32 gDCSpecFactoryCount = 0;
PRUint32 gDCSpecFactoryID = 0;
#endif
/** -------------------------------------------------------
* Constructor
* @update dc 2/16/98
*/
nsDeviceContextSpecFactoryQT::nsDeviceContextSpecFactoryQT()
{
PR_LOG(QtGfxLM,
PR_LOG_DEBUG,
("nsDeviceContextSpecFactoryQT::nsDeviceContextSpecFactoryQT\n"));
NS_INIT_REFCNT();
#ifdef DBG_JCG
gDCSpecFactoryCount++;
mID = gDCSpecFactoryID++;
printf("JCG: nsDeviceContextSpecFactoryQT CTOR (%p) ID: %d, Count: %d\n",this,mID,gDCSpecFactoryCount);
#endif
NS_INIT_REFCNT();
}
/** -------------------------------------------------------
@ -45,9 +55,10 @@ nsDeviceContextSpecFactoryQT::nsDeviceContextSpecFactoryQT()
*/
nsDeviceContextSpecFactoryQT::~nsDeviceContextSpecFactoryQT()
{
PR_LOG(QtGfxLM,
PR_LOG_DEBUG,
("nsDeviceContextSpecFactoryQT::~nsDeviceContextSpecFactoryQT\n"));
#ifdef DBG_JCG
gDCSpecFactoryCount--;
printf("JCG: nsDeviceContextSpecFactoryQT DTOR (%p) ID: %d, Count: %d\n",this,mID,gDCSpecFactoryCount);
#endif
}
static NS_DEFINE_IID(kDeviceContextSpecFactoryIID,
@ -66,9 +77,6 @@ NS_IMPL_RELEASE(nsDeviceContextSpecFactoryQT)
*/
NS_IMETHODIMP nsDeviceContextSpecFactoryQT::Init(void)
{
PR_LOG(QtGfxLM,
PR_LOG_DEBUG,
("nsDeviceContextSpecFactoryQT::Init\n"));
return NS_OK;
}
@ -76,18 +84,15 @@ NS_IMETHODIMP nsDeviceContextSpecFactoryQT::Init(void)
* Get a device context specification
* @update dc 2/16/98
*/
NS_IMETHODIMP nsDeviceContextSpecFactoryQT::CreateDeviceContextSpec(nsIWidget *aWidget,
nsIDeviceContextSpec *&aNewSpec,
PRBool aQuiet)
NS_IMETHODIMP
nsDeviceContextSpecFactoryQT::CreateDeviceContextSpec(nsIWidget *aWidget,
nsIDeviceContextSpec *&aNewSpec,
PRBool aQuiet)
{
PR_LOG(QtGfxLM,
PR_LOG_DEBUG,
("nsDeviceContextSpecFactoryQT::CreateDeviceContextSpec\n"));
nsresult rv = NS_ERROR_FAILURE;
nsIDeviceContextSpec *devSpec = nsnull;
nsComponentManager::CreateInstance(kDeviceContextSpecCID,
nsnull,
nsComponentManager::CreateInstance(kDeviceContextSpecCID,nsnull,
kIDeviceContextSpecIID,
(void **)&devSpec);

View File

@ -18,6 +18,8 @@
* Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
*
*/
#ifndef nsDeviceContextSpecFactoryQT_h___

View File

@ -18,6 +18,8 @@
* Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
*
*/
#include "nsDeviceContextSpecQT.h"
@ -25,9 +27,10 @@
#include "nsCOMPtr.h"
#include "nsIServiceManager.h"
#include "nsIPrintOptions.h"
#include "nsGfxCIID.h"
#include "nsIPref.h"
#include "prenv.h" /* for PR_GetEnv */
#include "nsIAppShellComponentImpl.h"
@ -37,18 +40,29 @@
static NS_DEFINE_IID( kAppShellServiceCID, NS_APPSHELL_SERVICE_CID );
static NS_DEFINE_CID(kDialogParamBlockCID, NS_DialogParamBlock_CID);
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
#include "stdlib.h" // getenv() on Solaris/CC
#include <qapplication.h>
//JCG #define DBG_JCG 1
#ifdef DBG_JCG
PRUint32 gDCSpecCount = 0;
PRUint32 gDCSpecID = 0;
#endif
/** -------------------------------------------------------
* Construct the nsDeviceContextSpecQT
* @update dc 12/02/98
*/
nsDeviceContextSpecQT::nsDeviceContextSpecQT()
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsDeviceContextSpecQT::nsDeviceContextSpecQT\n"));
NS_INIT_REFCNT();
#ifdef DBG_JCG
gDCSpecCount++;
mID = gDCSpecID++;
printf("JCG: nsDeviceContextSpecQT CTOR (%p) ID: %d, Count: %d\n",this,mID,gDCSpecCount);
#endif
NS_INIT_REFCNT();
}
/** -------------------------------------------------------
@ -57,7 +71,10 @@ nsDeviceContextSpecQT::nsDeviceContextSpecQT()
*/
nsDeviceContextSpecQT::~nsDeviceContextSpecQT()
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsDeviceContextSpecQT::~nsDeviceContextSpecQT\n"));
#ifdef DBG_JCG
gDCSpecCount--;
printf("JCG: nsDeviceContextSpecQT DTOR (%p) ID: %d, Count: %d\n",this,mID,gDCSpecCount);
#endif
}
static NS_DEFINE_IID(kIDeviceContextSpecIID, NS_IDEVICE_CONTEXT_SPEC_IID);
@ -66,39 +83,38 @@ static NS_DEFINE_IID(kIDeviceContextSpecPSIID, NS_IDEVICE_CONTEXT_SPEC_PS_IID);
NS_IMPL_ADDREF(nsDeviceContextSpecQT)
NS_IMPL_RELEASE(nsDeviceContextSpecQT)
NS_IMETHODIMP nsDeviceContextSpecQT::QueryInterface(REFNSIID aIID, void** aInstancePtr)
NS_IMETHODIMP nsDeviceContextSpecQT::QueryInterface(REFNSIID aIID,
void** aInstancePtr)
{
if (nsnull == aInstancePtr)
return NS_ERROR_NULL_POINTER;
if (aIID.Equals(kIDeviceContextSpecIID))
{
if (aIID.Equals(kIDeviceContextSpecIID)) {
nsIDeviceContextSpec* tmp = this;
*aInstancePtr = (void*) tmp;
*aInstancePtr = (void*)tmp;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIDeviceContextSpecPSIID))
{
if (aIID.Equals(kIDeviceContextSpecPSIID)) {
nsIDeviceContextSpecPS* tmp = this;
*aInstancePtr = (void*) tmp;
*aInstancePtr = (void*)tmp;
NS_ADDREF_THIS();
return NS_OK;
}
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
if (aIID.Equals(kISupportsIID))
{
if (aIID.Equals(kISupportsIID)) {
nsIDeviceContextSpec* tmp = this;
nsISupports* tmp2 = tmp;
*aInstancePtr = (void*) tmp2;
*aInstancePtr = (void*)tmp2;
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
/** -------------------------------------------------------
* Initialize the nsDeviceContextSpecQT
* @update dc 2/15/98
@ -106,17 +122,33 @@ NS_IMETHODIMP nsDeviceContextSpecQT::QueryInterface(REFNSIID aIID, void** aInsta
*/
NS_IMETHODIMP nsDeviceContextSpecQT::Init(PRBool aQuiet)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsDeviceContextSpecQT::Init\n"));
nsresult rv = NS_ERROR_FAILURE;
NS_WITH_SERVICE(nsIPrintOptions,printService,kPrintOptionsCID,&rv);
// if there is a current selection then enable the "Selection" radio button
if (NS_SUCCEEDED(rv) && printService) {
PRBool isOn;
printService->GetPrintOptions(nsIPrintOptions::kPrintOptionsEnableSelectionRB,
&isOn);
nsCOMPtr<nsIPref> pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv) && pPrefs) {
(void)pPrefs->SetBoolPref("print.selection_radio_enabled",isOn);
}
}
char *path;
PRBool reversed = PR_FALSE, color = PR_FALSE, landscape = PR_FALSE;
PRBool reversed = PR_FALSE;
PRBool color = PR_FALSE;
PRBool tofile = PR_FALSE;
PRInt16 printRange = nsIPrintOptions::kRangeAllPages;
PRInt32 paper_size = NS_LETTER_SIZE;
int ileft = 500, iright = 0, itop = 500, ibottom = 0;
char *command;
char *printfile = nsnull;
nsresult rv = NS_OK;
PRInt32 fromPage = 1;
PRInt32 toPage = 1;
PRUnichar *command = nsnull;
PRUnichar *printfile = nsnull;
double dleft = 0.5;
double dright = 0.5;
double dtop = 0.5;
double dbottom = 0.5;
nsCOMPtr<nsIDialogParamBlock> ioParamBlock;
rv = nsComponentManager::CreateInstance(kDialogParamBlockCID,
@ -131,23 +163,19 @@ NS_IMETHODIMP nsDeviceContextSpecQT::Init(PRBool aQuiet)
nsCOMPtr<nsIDOMWindowInternal> mWindow;
JSContext *jsContext;
rv = appShell->GetHiddenWindowAndJSContext(getter_AddRefs(hiddenWindow), &jsContext);
rv = appShell->GetHiddenWindowAndJSContext(getter_AddRefs(hiddenWindow),
&jsContext);
if (NS_SUCCEEDED(rv)) {
void *stackPtr;
jsval *argv = JS_PushArguments(jsContext,
&stackPtr,
"sss%ip",
jsval *argv = JS_PushArguments(jsContext,&stackPtr,"sss%ip",
"chrome://global/content/printdialog.xul",
"_blank",
"chrome,modal",
(const nsIID *) (&NS_GET_IID(nsIDialogParamBlock)),
(nsISupports *) ioParamBlock);
"_blank","chrome,modal",
(const nsIID*)(&NS_GET_IID(nsIDialogParamBlock)),
(nsISupports*)ioParamBlock);
if (argv) {
nsCOMPtr<nsIDOMWindowInternal> newWindow;
rv = hiddenWindow->OpenDialog(jsContext,
argv,
4,
rv = hiddenWindow->OpenDialog(jsContext,argv,4,
getter_AddRefs(newWindow));
if (NS_SUCCEEDED(rv)) {
@ -155,22 +183,37 @@ NS_IMETHODIMP nsDeviceContextSpecQT::Init(PRBool aQuiet)
PRInt32 buttonPressed = 0;
ioParamBlock->GetInt(0, &buttonPressed);
if (buttonPressed == 0) {
nsCOMPtr<nsIPref> pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv) && pPrefs) {
(void) pPrefs->GetBoolPref("print.print_reversed", &reversed);
(void) pPrefs->GetBoolPref("print.print_color", &color);
(void) pPrefs->GetBoolPref("print.print_landscape", &landscape);
(void) pPrefs->GetIntPref("print.print_paper_size", &paper_size);
(void) pPrefs->CopyCharPref("print.print_command", (char **) &command);
(void) pPrefs->GetIntPref("print.print_margin_top", &itop);
(void) pPrefs->GetIntPref("print.print_margin_left", &ileft);
(void) pPrefs->GetIntPref("print.print_margin_bottom", &ibottom);
(void) pPrefs->GetIntPref("print.print_margin_right", &iright);
(void) pPrefs->CopyCharPref("print.print_file", (char **) &printfile);
(void) pPrefs->GetBoolPref("print.print_tofile", &tofile);
sprintf( mPrData.command, command );
sprintf( mPrData.path, printfile );
} else {
if (printService) {
printService->GetPrintReversed(&reversed);
printService->GetPrintInColor(&color);
printService->GetPaperSize(&paper_size);
printService->GetPrintCommand(&command);
printService->GetPrintRange(&printRange);
printService->GetToFileName(&printfile);
printService->GetPrintToFile(&tofile);
printService->GetStartPageRange(&fromPage);
printService->GetEndPageRange(&toPage);
printService->GetMarginTop(&dtop);
printService->GetMarginLeft(&dleft);
printService->GetMarginBottom(&dbottom);
printService->GetMarginRight(&dright);
if (command != nsnull && printfile != nsnull) {
// convert Unicode strings to cstrings
nsAutoString cmdStr;
nsAutoString printFileStr;
cmdStr = command;
printFileStr = printfile;
char *pCmdStr = cmdStr.ToNewCString();
char *pPrintFileStr = printFileStr.ToNewCString();
sprintf(mPrData.command,pCmdStr);
sprintf(mPrData.path,pPrintFileStr);
nsMemory::Free(pCmdStr);
nsMemory::Free(pPrintFileStr);
}
}
else {
#ifndef VMS
sprintf( mPrData.command, "lpr" );
#else
@ -179,26 +222,30 @@ NS_IMETHODIMP nsDeviceContextSpecQT::Init(PRBool aQuiet)
sprintf( mPrData.command, "print" );
#endif
}
mPrData.top = itop / 1000.0;
mPrData.bottom = ibottom / 1000.0;
mPrData.left = ileft / 1000.0;
mPrData.right = iright / 1000.0;
mPrData.top = dtop;
mPrData.bottom = dbottom;
mPrData.left = dleft;
mPrData.right = dright;
mPrData.fpf = !reversed;
mPrData.grayscale = !color;
mPrData.size = paper_size;
mPrData.toPrinter = !tofile;
// PWD, HOME, or fail
if (!printfile) {
if ( ( path = PR_GetEnv( "PWD" ) ) == (char *) NULL )
if ( ( path = PR_GetEnv( "HOME" ) ) == (char *) NULL )
strcpy( mPrData.path, "mozilla.ps" );
if ( path != (char *) NULL )
sprintf( mPrData.path, "%s/mozilla.ps", path );
if ((path = PR_GetEnv("PWD")) == (char*)NULL)
if ((path = PR_GetEnv("HOME")) == (char*)NULL)
strcpy(mPrData.path,"mozilla.ps");
if (path != (char*)NULL)
sprintf(mPrData.path,"%s/mozilla.ps",path);
else
return NS_ERROR_FAILURE;
return NS_ERROR_FAILURE;
}
if (command != nsnull) {
nsMemory::Free(command);
}
if (printfile != nsnull) {
nsMemory::Free(printfile);
}
return NS_OK;
}
@ -223,7 +270,6 @@ NS_IMETHODIMP nsDeviceContextSpecQT::GetFirstPageFirst(PRBool &aFpf)
}
NS_IMETHODIMP nsDeviceContextSpecQT::GetGrayscale(PRBool &aGrayscale)
{
aGrayscale = mPrData.grayscale;
return NS_OK;
@ -235,25 +281,22 @@ NS_IMETHODIMP nsDeviceContextSpecQT::GetSize(int &aSize)
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextSpecQT::GetPageDimensions(float &aWidth,float &aHeight)
NS_IMETHODIMP nsDeviceContextSpecQT::GetPageDimensions(float &aWidth,
float &aHeight)
{
if (mPrData.size == NS_LETTER_SIZE)
{
if (mPrData.size == NS_LETTER_SIZE) {
aWidth = 8.5;
aHeight = 11.0;
}
else if (mPrData.size == NS_LEGAL_SIZE)
{
else if (mPrData.size == NS_LEGAL_SIZE) {
aWidth = 8.5;
aHeight = 14.0;
}
else if (mPrData.size == NS_EXECUTIVE_SIZE)
{
else if (mPrData.size == NS_EXECUTIVE_SIZE) {
aWidth = 7.5;
aHeight = 10.0;
}
else if (mPrData.size == NS_A4_SIZE)
{
else if (mPrData.size == NS_A4_SIZE) {
// 210mm X 297mm == 8.27in X 11.69in
aWidth = 8.27;
aHeight = 11.69;
@ -309,6 +352,5 @@ NS_IMETHODIMP nsDeviceContextSpecQT::GetUserCancelled(PRBool &aCancel)
*/
NS_IMETHODIMP nsDeviceContextSpecQT::ClosePrintManager()
{
PR_LOG(QtGfxLM,PR_LOG_DEBUG,("nsDeviceContextSpecQT::ClosePrintManager\n"));
return NS_OK;
}

View File

@ -18,6 +18,8 @@
* Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
*
*/
#ifndef nsDeviceContextSpecQT_h___

View File

@ -18,30 +18,43 @@
* Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
*
*/
#include "nsDrawingSurfaceQT.h"
#include "nsRenderingContextQT.h"
#include <qpaintdevicemetrics.h>
//JCG #define DBG_JCG 1
#ifdef DBG_JCG
PRUint32 gDSCount = 0;
PRUint32 gDSID = 0;
#endif
NS_IMPL_ISUPPORTS2(nsDrawingSurfaceQT, nsIDrawingSurface, nsIDrawingSurfaceQT)
nsDrawingSurfaceQT::nsDrawingSurfaceQT()
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsDrawingSurfaceQT::nsDrawingSurfaceQT\n"));
NS_INIT_REFCNT();
#ifdef DBG_JCG
gDSCount++;
mID = gDSID++;
printf("JCG: nsDrawingSurfaceQT CTOR (%p) ID: %d, Count: %d\n",this,mID,gDSCount);
#endif
mPaintDevice = nsnull;
mPixmap = nsnull;
mGC = nsnull;
mDepth = -1;
mWidth = 0;
mHeight = 0;
mFlags = 0;
mLockWidth = 0;
mLockHeight = 0;
mLockFlags = 0;
mLocked = PR_FALSE;
NS_INIT_REFCNT();
mPaintDevice = nsnull;
mPixmap = nsnull;
mGC = nsnull;
mDepth = -1;
mWidth = 0;
mHeight = 0;
mFlags = 0;
mLockWidth = 0;
mLockHeight = 0;
mLockFlags = 0;
mLocked = PR_FALSE;
// I have no idea how to compute these values.
// FIXME
@ -58,40 +71,34 @@ nsDrawingSurfaceQT::nsDrawingSurfaceQT()
nsDrawingSurfaceQT::~nsDrawingSurfaceQT()
{
PR_LOG(QtGfxLM,PR_LOG_DEBUG,("nsDrawingSurfaceQT::~nsDrawingSurfaceQT\n"));
#ifdef DBG_JCG
gDSCount--;
printf("JCG: nsDrawingSurfaceQT DTOR (%p) ID: %d, Count: %d\n",this,mID,gDSCount);
#endif
if (mGC && mGC->isActive()) {
PR_LOG(QtGfxLM,
PR_LOG_DEBUG,
("nsDrawingSurfaceQT::~nsDrawingSurfaceQT: calling QPainter::end for %p\n",
mPaintDevice));
mGC->end();
}
if (mGC) {
delete mGC;
mGC = nsnull;
}
if (mPixmap) {
delete mPixmap;
mPixmap = nsnull;
}
if (mPaintDevice) {
if (mIsOffscreen && !mPaintDevice->paintingActive())
delete mPaintDevice;
mPaintDevice = nsnull;
}
if (mGC && mGC->isActive()) {
mGC->end();
}
if (mGC) {
delete mGC;
mGC = nsnull;
}
if (mPixmap) {
delete mPixmap;
mPixmap = nsnull;
}
if (mPaintDevice) {
if (mIsOffscreen && !mPaintDevice->paintingActive())
delete mPaintDevice;
mPaintDevice = nsnull;
}
}
NS_IMETHODIMP nsDrawingSurfaceQT::Lock(PRInt32 aX,
PRInt32 aY,
PRUint32 aWidth,
PRUint32 aHeight,
void ** aBits,
PRInt32 * aStride,
PRInt32 * aWidthBytes,
PRUint32 aFlags)
NS_IMETHODIMP nsDrawingSurfaceQT::Lock(PRInt32 aX,PRInt32 aY,
PRUint32 aWidth,PRUint32 aHeight,
void **aBits,PRInt32 *aStride,
PRInt32 *aWidthBytes,PRUint32 aFlags)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsDrawingSurfaceQT::Lock\n"));
if (mLocked) {
NS_ASSERTION(0, "nested lock attempt");
return NS_ERROR_FAILURE;
@ -119,27 +126,25 @@ NS_IMETHODIMP nsDrawingSurfaceQT::Lock(PRInt32 aX,
NS_IMETHODIMP nsDrawingSurfaceQT::Unlock(void)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsDrawingSurfaceQT::Unlock\n"));
if (!mLocked) {
NS_ASSERTION(0, "attempting to unlock an DrawingSurface that isn't locked");
return NS_ERROR_FAILURE;
}
if (!mPixmap) {
NS_ASSERTION(0, "NULL pixmap in unlock attempt");
return NS_ERROR_FAILURE;
}
if (!(mLockFlags & NS_LOCK_SURFACE_READ_ONLY)) {
mGC->drawPixmap(0, 0, *mPixmap, mLockY, mLockY, mLockWidth, mLockHeight);
}
mLocked = PR_FALSE;
if (!mLocked) {
NS_ASSERTION(0,"attempting to unlock an DrawingSurface that isn't locked");
return NS_ERROR_FAILURE;
}
if (!mPixmap) {
NS_ASSERTION(0, "NULL pixmap in unlock attempt");
return NS_ERROR_FAILURE;
}
if (!(mLockFlags & NS_LOCK_SURFACE_READ_ONLY)) {
mGC->drawPixmap(0,0,*mPixmap,mLockY,mLockY,mLockWidth,mLockHeight);
}
mLocked = PR_FALSE;
return NS_OK;
return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfaceQT::GetDimensions(PRUint32 *aWidth,
PRUint32 *aHeight)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsDrawingSurfaceQT::GetDimensions\n"));
*aWidth = mWidth;
*aHeight = mHeight;
@ -148,21 +153,18 @@ NS_IMETHODIMP nsDrawingSurfaceQT::GetDimensions(PRUint32 *aWidth,
NS_IMETHODIMP nsDrawingSurfaceQT::IsOffscreen(PRBool *aOffScreen)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsDrawingSurfaceQT::IsOffscreen\n"));
*aOffScreen = mIsOffscreen;
return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfaceQT::IsPixelAddressable(PRBool *aAddressable)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsDrawingSurfaceQT::IsPixelAddressable\n"));
*aAddressable = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfaceQT::GetPixelFormat(nsPixelFormat *aFormat)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsDrawingSurfaceQT::GetPixelFormat\n"));
*aFormat = mPixFormat;
return NS_OK;
@ -171,10 +173,6 @@ NS_IMETHODIMP nsDrawingSurfaceQT::GetPixelFormat(nsPixelFormat *aFormat)
NS_IMETHODIMP nsDrawingSurfaceQT::Init(QPaintDevice *aPaintDevice,
QPainter *aGC)
{
PR_LOG(QtGfxLM,
PR_LOG_DEBUG,
("nsDrawingSurfaceQT::Init: paintdevice=%p, painter=%p\n",
aPaintDevice, aGC));
QPaintDeviceMetrics qMetrics(aPaintDevice);
mGC = aGC;
@ -197,67 +195,43 @@ NS_IMETHODIMP nsDrawingSurfaceQT::Init(QPainter *aGC,
PRUint32 aHeight,
PRUint32 aFlags)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsDrawingSurfaceQT::Init: with no paintdevice\n"));
if (nsnull == aGC || aWidth <= 0 || aHeight <= 0) {
return NS_ERROR_FAILURE;
}
mGC = aGC;
mWidth = aWidth;
mHeight = aHeight;
mFlags = aFlags;
if (nsnull == aGC || aWidth <= 0 || aHeight <= 0) {
return NS_ERROR_FAILURE;
}
mGC = aGC;
mWidth = aWidth;
mHeight = aHeight;
mFlags = aFlags;
PR_LOG(QtGfxLM,
PR_LOG_DEBUG,
("nsDrawingSurfaceQT::Init: creating pixmap w=%d, h=%d, d=%d\n",
mWidth, mHeight, mDepth));
mPixmap = new QPixmap(mWidth, mHeight, mDepth);
mPaintDevice = mPixmap;
mPixmap = new QPixmap(mWidth, mHeight, mDepth);
mPaintDevice = mPixmap;
mIsOffscreen = PR_TRUE;
mIsOffscreen = PR_TRUE;
if (!mImage.isNull())
mImage.reset();
if (!mImage.isNull())
mImage.reset();
return CommonInit();
return CommonInit();
}
NS_IMETHODIMP nsDrawingSurfaceQT::CommonInit()
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsDrawingSurfaceQT::CommonInit\n"));
if (nsnull == mGC || nsnull == mPaintDevice) {
return NS_ERROR_FAILURE;
}
if (mGC->isActive()) {
PR_LOG(QtGfxLM,
PR_LOG_DEBUG,
("nsDrawingSurfaceQT::CommonInit: calling QPainter::end\n"));
mGC->end();
}
if (mGC->begin(mPaintDevice)) {
PR_LOG(QtGfxLM,
PR_LOG_DEBUG,
("nsDrawingSurfaceQT::CommonInit: QPainter::begin succeeded for %p\n",
mPaintDevice));
}
else {
PR_LOG(QtGfxLM,
PR_LOG_DEBUG,
("nsDrawingSurfaceQT::CommonInit: QPainter::begin failed for %p\n",
mPaintDevice));
}
return NS_OK;
if (nsnull == mGC || nsnull == mPaintDevice) {
return NS_ERROR_FAILURE;
}
if (mGC->isActive()) {
mGC->end();
}
mGC->begin(mPaintDevice);
return NS_OK;
}
QPainter* nsDrawingSurfaceQT::GetGC()
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsDrawingSurfaceQT::GetGC\n"));
return mGC;
}
QPaintDevice* nsDrawingSurfaceQT::GetPaintDevice()
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsDrawingSurfaceQT::GetPaintDevice\n"));
return mPaintDevice;
}

View File

@ -18,6 +18,8 @@
* Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
*
*/
#ifndef nsDrawingSurfaceQT_h___
@ -27,70 +29,65 @@
#include "nsIDrawingSurfaceQT.h"
#include <qpainter.h>
#include <qpixmap.h>
#include <qimage.h>
class QPixmap;
class nsDrawingSurfaceQT : public nsIDrawingSurface,
public nsIDrawingSurfaceQT
{
public:
nsDrawingSurfaceQT();
virtual ~nsDrawingSurfaceQT();
nsDrawingSurfaceQT();
virtual ~nsDrawingSurfaceQT();
NS_DECL_ISUPPORTS
NS_DECL_ISUPPORTS
//nsIDrawingSurface interface
//nsIDrawingSurface interface
NS_IMETHOD Lock(PRInt32 aX,PRInt32 aY,
PRUint32 aWidth,PRUint32 aHeight,
void **aBits,PRInt32 *aStride,
PRInt32 *aWidthBytes,PRUint32 aFlags);
NS_IMETHOD Unlock(void);
NS_IMETHOD GetDimensions(PRUint32 *aWidth, PRUint32 *aHeight);
NS_IMETHOD IsOffscreen(PRBool *aOffScreen);
NS_IMETHOD IsPixelAddressable(PRBool *aAddressable);
NS_IMETHOD GetPixelFormat(nsPixelFormat *aFormat);
NS_IMETHOD Lock(PRInt32 aX,
PRInt32 aY,
PRUint32 aWidth,
PRUint32 aHeight,
void **aBits,
PRInt32 *aStride,
PRInt32 *aWidthBytes,
PRUint32 aFlags);
NS_IMETHOD Unlock(void);
NS_IMETHOD GetDimensions(PRUint32 *aWidth, PRUint32 *aHeight);
NS_IMETHOD IsOffscreen(PRBool *aOffScreen);
NS_IMETHOD IsPixelAddressable(PRBool *aAddressable);
NS_IMETHOD GetPixelFormat(nsPixelFormat *aFormat);
//nsIDrawingSurfaceQT interface
NS_IMETHOD Init(QPaintDevice * aPaintDevice, QPainter *aGC);
NS_IMETHOD Init(QPainter *aGC,PRUint32 aWidth,PRUint32 aHeight,
PRUint32 aFlags);
//nsIDrawingSurfaceQT interface
NS_IMETHOD Init(QPaintDevice * aPaintDevice, QPainter *aGC);
NS_IMETHOD Init(QPainter *aGC,
PRUint32 aWidth,
PRUint32 aHeight,
PRUint32 aFlags);
// utility functions.
PRInt32 GetDepth() { return mDepth; }
QPainter * GetGC(void);
QPaintDevice * GetPaintDevice(void);
// utility functions.
PRInt32 GetDepth() { return mDepth; }
QPainter *GetGC(void);
QPaintDevice *GetPaintDevice(void);
protected:
NS_IMETHOD CommonInit();
NS_IMETHOD CommonInit();
private:
/* general */
QPaintDevice *mPaintDevice;
QPixmap *mPixmap;
QPainter *mGC;
int mDepth;
nsPixelFormat mPixFormat;
PRUint32 mWidth;
PRUint32 mHeight;
PRUint32 mFlags;
PRBool mIsOffscreen;
/* general */
QPaintDevice *mPaintDevice;
QPixmap *mPixmap;
QPainter *mGC;
int mDepth;
nsPixelFormat mPixFormat;
PRUint32 mWidth;
PRUint32 mHeight;
PRUint32 mFlags;
PRBool mIsOffscreen;
/* for locks */
QImage mImage;
PRInt32 mLockX;
PRInt32 mLockY;
PRUint32 mLockWidth;
PRUint32 mLockHeight;
PRUint32 mLockFlags;
PRBool mLocked;
/* for locks */
QImage mImage;
PRInt32 mLockX;
PRInt32 mLockY;
PRUint32 mLockWidth;
PRUint32 mLockHeight;
PRUint32 mLockFlags;
PRBool mLocked;
PRUint32 mID;
};
#endif

File diff suppressed because it is too large Load Diff

View File

@ -18,22 +18,79 @@
* Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
*
*/
#ifndef nsFontMetricsQT_h__
#define nsFontMetricsQT_h__
#include "nsDeviceContextQT.h"
#include "nsIFontMetrics.h"
#include "nsIFontEnumerator.h"
#include "nsFont.h"
#include "nsString.h"
#include "nsUnitConversion.h"
#include "nsIDeviceContext.h"
#include "nsCRT.h"
#include "nsCOMPtr.h"
#include "nsICharRepresentable.h"
#include "nsICharsetConverterManager.h"
#include "nsICharsetConverterManager2.h"
#include <qfont.h>
#include <qintdict.h>
class nsFont;
class nsString;
class nsRenderingContextQT;
class nsDrawingSurfaceQT;
class nsFontMetricsQT;
class nsFontQTUserDefined;
class QString;
class QFont;
class QFontInfo;
class QFontMetrics;
class QFontDatabase;
#undef FONT_HAS_GLYPH
#define FONT_HAS_GLYPH(map, char) IS_REPRESENTABLE(map, char)
typedef struct nsFontCharSetInfo nsFontCharSetInfo;
typedef int (*nsFontCharSetConverter)(nsFontCharSetInfo* aSelf,
QFontMetrics *aFontMetrics,
const PRUnichar* aSrcBuf,PRInt32 aSrcLen,
char* aDestBuf,PRInt32 aDestLen);
class nsFontQT
{
public:
nsFontQT();
nsFontQT(QFont *aQFont);
virtual ~nsFontQT();
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
virtual QFont* GetQFont(void);
virtual PRBool GetQFontIs10646(void);
inline int SupportsChar(PRUnichar aChar)
{ return (mFont && FONT_HAS_GLYPH(mMap,aChar)); };
virtual int GetWidth(const PRUnichar* aString, PRUint32 aLength) = 0;
virtual int DrawString(nsRenderingContextQT* aContext,
nsDrawingSurfaceQT* aSurface, nscoord aX,
nscoord aY, const PRUnichar* aString,
PRUint32 aLength) = 0;
#ifdef MOZ_MATHML
// bounding metrics for a string
// remember returned values are not in app units
// - to emulate GetWidth () above
virtual nsresult GetBoundingMetrics(const PRUnichar* aString,
PRUint32 aLength,
nsBoundingMetrics& aBoundingMetrics) = 0;
#endif
QFont* mFont;
QFontInfo* mFontInfo;
QFontMetrics* mFontMetrics;
nsFontCharSetInfo* mCharSetInfo;
PRUint32* mMap;
};
class nsFontMetricsQT : public nsIFontMetrics
{
@ -69,33 +126,74 @@ public:
NS_IMETHOD GetLangGroup(nsIAtom** aLangGroup);
NS_IMETHOD GetFontHandle(nsFontHandle &aHandle);
nsCOMPtr<nsIAtom> mLangGroup;
virtual nsresult GetSpaceWidth(nscoord &aSpaceWidth);
nsFontQT* FindFont(PRUnichar aChar);
nsFontQT* FindUserDefinedFont(PRUnichar aChar);
nsFontQT* FindLocalFont(PRUnichar aChar);
nsFontQT* FindGenericFont(PRUnichar aChar);
nsFontQT* FindGlobalFont(PRUnichar aChar);
nsFontQT* FindSubstituteFont(PRUnichar aChar);
nsFontQT* LookUpFontPref(nsCAutoString &aName,PRUnichar aChar);
nsFontQT* LoadFont(QString &aName,PRUnichar aChar);
nsFontQT* LoadFont(QString &aName,const QString &aCharSet,
PRUnichar aChar);
QFont* LoadQFont(QString &aName,const QString &aCharSet);
static nsresult FamilyExists(const nsString& aFontName);
nsFontQT **mLoadedFonts;
PRUint16 mLoadedFontsAlloc;
PRUint16 mLoadedFontsCount;
nsFontQT *mSubstituteFont;
nsFontQTUserDefined *mUserDefinedFont;
nsCOMPtr<nsIAtom> mLangGroup;
nsCStringArray mFonts;
PRUint16 mFontsIndex;
nsVoidArray mFontIsGeneric;
nsCAutoString mDefaultFont;
nsCString *mGeneric;
nsCAutoString mUserDefined;
PRUint8 mTriedAllGenerics;
PRUint8 mIsUserDefined;
static QFontDatabase *GetQFontDB();
protected:
void RealizeFont();
nsIDeviceContext * mDeviceContext;
nsFont * mFont;
QFont * mFontHandle;
nsIDeviceContext *mDeviceContext;
nsFont *mFont;
nsFontQT *mWesternFont;
nscoord mLeading;
nscoord mEmHeight;
nscoord mEmAscent;
nscoord mEmDescent;
nscoord mHeight;
nscoord mAscent;
nscoord mDescent;
nscoord mMaxHeight;
nscoord mMaxAscent;
nscoord mMaxDescent;
nscoord mMaxAdvance;
nscoord mXHeight;
nscoord mSuperscriptOffset;
nscoord mSubscriptOffset;
nscoord mStrikeoutSize;
nscoord mStrikeoutOffset;
nscoord mUnderlineSize;
nscoord mUnderlineOffset;
QString *mQStyle;
PRUint16 mPixelSize;
PRUint16 mWeight;
QIntDict<char> mCharSubst;
nscoord mLeading;
nscoord mEmHeight;
nscoord mEmAscent;
nscoord mEmDescent;
nscoord mMaxHeight;
nscoord mMaxAscent;
nscoord mMaxDescent;
nscoord mMaxAdvance;
nscoord mXHeight;
nscoord mSuperscriptOffset;
nscoord mSubscriptOffset;
nscoord mStrikeoutSize;
nscoord mStrikeoutOffset;
nscoord mUnderlineSize;
nscoord mUnderlineOffset;
nscoord mSpaceWidth;
static QFontDatabase *mQFontDB;
};
class nsFontEnumeratorQT : public nsIFontEnumerator

View File

@ -17,7 +17,8 @@
* Copyright (C) 2000 Christopher Blizzard. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzzard <blizzard@mozilla.org>
* John C. Griggs <johng@corel.com>
*
*/
#include "nsIGenericFactory.h"
@ -50,34 +51,29 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontEnumeratorQT)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsScreenManagerQT)
// our custom constructors
static nsresult nsScriptableRegionConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult)
static nsresult nsScriptableRegionConstructor(nsISupports *aOuter,REFNSIID aIID,void **aResult)
{
nsresult rv;
nsIScriptableRegion *inst;
if ( NULL == aResult )
{
if (NULL == aResult) {
rv = NS_ERROR_NULL_POINTER;
return rv;
}
*aResult = NULL;
if (NULL != aOuter)
{
if (NULL != aOuter) {
rv = NS_ERROR_NO_AGGREGATION;
return rv;
}
// create an nsRegionQT and get the scriptable region from it
nsCOMPtr <nsIRegion> rgn;
NS_NEWXPCOM(rgn, nsRegionQT);
if (rgn != nsnull)
{
if (rgn != nsnull) {
nsCOMPtr<nsIScriptableRegion> scriptableRgn = new nsScriptableRegion(rgn);
inst = scriptableRgn;
}
if (NULL == inst)
{
if (NULL == inst) {
rv = NS_ERROR_OUT_OF_MEMORY;
return rv;
}
@ -88,23 +84,21 @@ static nsresult nsScriptableRegionConstructor(nsISupports *aOuter, REFNSIID aIID
return rv;
}
static nsresult nsImageManagerConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult)
static nsresult nsImageManagerConstructor(nsISupports *aOuter,REFNSIID aIID,void **aResult)
{
nsresult rv;
if ( NULL == aResult )
{
if (NULL == aResult) {
rv = NS_ERROR_NULL_POINTER;
return rv;
}
*aResult = NULL;
if (NULL != aOuter)
{
if (NULL != aOuter) {
rv = NS_ERROR_NO_AGGREGATION;
return rv;
}
// this will return an image manager with a count of 1
rv = NS_NewImageManager((nsIImageManager **)aResult);
rv = NS_NewImageManager((nsIImageManager**)aResult);
return rv;
}

View File

@ -18,6 +18,8 @@
* Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
*
*/
#ifndef nsIDrawingSurfaceQT_h___
@ -62,9 +64,7 @@ public:
* surface created
* @return error status
**/
NS_IMETHOD Init(QPainter * aGC,
PRUint32 aWidth,
PRUint32 aHeight,
NS_IMETHOD Init(QPainter * aGC,PRUint32 aWidth,PRUint32 aHeight,
PRUint32 aFlags) = 0;
};

View File

@ -18,6 +18,8 @@
* Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
*
*/
#include "nsImageQT.h"
@ -25,80 +27,79 @@
#include "nspr.h"
#include <qpixmap.h>
#include <qimage.h>
#define IsFlagSet(a,b) ((a) & (b))
#undef CHEAP_PERFORMANCE_MEASUREMENT
//JCG #define DBG_JCG 1
#ifdef DBG_JCG
PRUint32 gImageCount = 0;
PRUint32 gImageID = 0;
#endif
NS_IMPL_ISUPPORTS1(nsImageQT, nsIImage)
//------------------------------------------------------------
nsImageQT::nsImageQT()
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsImageQT::nsImageQT()\n"));
NS_INIT_REFCNT();
mImageBits = nsnull;
mWidth = 0;
mHeight = 0;
mDepth = 0;
mRequestDepth = 0;
mAlphaBits = nsnull;
mAlphaPixmap = nsnull;
mImagePixmap = nsnull;
mAlphaDepth = 0;
mRowBytes = 0;
mSizeImage = 0;
mAlphaHeight = 0;
mAlphaWidth = 0;
mAlphaRowBytes = 0;
mNumBytesPixel = 0;
mIsTopToBottom = PR_TRUE;
mDecodedX1 = 0;
mDecodedY1 = 0;
mDecodedX2 = 0;
mDecodedY2 = 0;
mNaturalWidth = 0;
mNaturalHeight = 0;
#ifdef DBG_JCG
gImageCount++;
mID = gImageID++;
printf("JCG: nsImageQT CTOR (%p) ID: %d, Count: %d\n",this,mID,gImageCount);
#endif
NS_INIT_REFCNT();
mImageBits = nsnull;
mWidth = 0;
mHeight = 0;
mDepth = 0;
mRequestDepth = 0;
mAlphaBits = nsnull;
mAlphaPixmap = nsnull;
mImagePixmap = nsnull;
mAlphaDepth = 0;
mRowBytes = 0;
mSizeImage = 0;
mAlphaHeight = 0;
mAlphaWidth = 0;
mAlphaRowBytes = 0;
mNumBytesPixel = 0;
mIsTopToBottom = PR_TRUE;
mDecodedX1 = 0;
mDecodedY1 = 0;
mDecodedX2 = 0;
mDecodedY2 = 0;
mNaturalWidth = 0;
mNaturalHeight = 0;
}
//------------------------------------------------------------
nsImageQT::~nsImageQT()
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsImageQT::~nsImageQT()\n"));
if (nsnull != mImageBits) {
delete[] (PRUint8*)mImageBits;
mImageBits = nsnull;
}
if (nsnull != mAlphaBits) {
delete[] (PRUint8*)mAlphaBits;
mAlphaBits = nsnull;
}
if (nsnull != mAlphaPixmap) {
delete mAlphaPixmap;
}
if (nsnull != mImagePixmap) {
delete mImagePixmap;
}
#ifdef DBG_JCG
gImageCount--;
printf("JCG: nsImageQT DTOR (%p) ID: %d, Count: %d\n",this,mID,gImageCount);
#endif
if (nsnull != mImageBits) {
delete[] (PRUint8*)mImageBits;
mImageBits = nsnull;
}
if (nsnull != mAlphaBits) {
delete[] (PRUint8*)mAlphaBits;
mAlphaBits = nsnull;
}
if (nsnull != mAlphaPixmap) {
delete mAlphaPixmap;
}
if (nsnull != mImagePixmap) {
delete mImagePixmap;
}
}
//------------------------------------------------------------
nsresult nsImageQT::Init(PRInt32 aWidth,
PRInt32 aHeight,
nsresult nsImageQT::Init(PRInt32 aWidth,PRInt32 aHeight,
PRInt32 aDepth,
nsMaskRequirements aMaskRequirements)
{
PR_LOG(QtGfxLM,
PR_LOG_DEBUG,
("nsImageQT::Init: width=%d height=%d depth=%d\n",
aWidth,
aHeight,
aDepth));
if (aWidth == 0 && aHeight == 0) {
if (aWidth == 0 || aHeight == 0) {
return NS_ERROR_FAILURE;
}
if (nsnull != mImageBits) {
@ -134,8 +135,7 @@ nsresult nsImageQT::Init(PRInt32 aWidth,
mDepth = 32;
mRequestDepth = aDepth;
}
else
{
else {
NS_ASSERTION(PR_FALSE, "unexpected image depth");
return NS_ERROR_UNEXPECTED;
}
@ -148,17 +148,14 @@ nsresult nsImageQT::Init(PRInt32 aWidth,
mImageBits = (PRUint8*)new PRUint8[mSizeImage];
switch(aMaskRequirements)
{
switch (aMaskRequirements) {
case nsMaskRequirements_kNoMask:
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsImageQT::Init: no mask needed\n"));
mAlphaBits = nsnull;
mAlphaWidth = 0;
mAlphaHeight = 0;
break;
case nsMaskRequirements_kNeeds1Bit:
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsImageQT::Init: 1 bit mask needed\n"));
mAlphaRowBytes = (aWidth + 7) / 8;
mAlphaDepth = 1;
@ -171,7 +168,6 @@ nsresult nsImageQT::Init(PRInt32 aWidth,
break;
case nsMaskRequirements_kNeeds8Bit:
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsImageQT::Init: 8 bit mask needed\n"));
mAlphaRowBytes = aWidth;
mAlphaDepth = 8;
@ -191,112 +187,90 @@ void nsImageQT::ComputeMetrics()
{
mRowBytes = CalcBytesSpan(mWidth);
mSizeImage = mRowBytes * mHeight;
PR_LOG(QtGfxLM,
PR_LOG_DEBUG,
("nsImageQT::ComputeMetrics: mRowBytes=%d, mSizeImage=%d\n",
mRowBytes,
mSizeImage));
}
PRInt32 nsImageQT::GetHeight()
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsImageQT::GetHeight()\n"));
return mHeight;
}
PRInt32 nsImageQT::GetWidth()
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsImageQT::GetWidth()\n"));
return mWidth;
}
PRUint8 * nsImageQT::GetBits()
PRUint8 *nsImageQT::GetBits()
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsImageQT::GetBits()\n"));
return mImageBits;
}
void * nsImageQT::GetBitInfo()
void *nsImageQT::GetBitInfo()
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsImageQT::GetBitInfo()\n"));
return nsnull;
}
PRInt32 nsImageQT::GetLineStride()
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsImageQT::GetLineStride()\n"));
return mRowBytes;
}
nsColorMap * nsImageQT::GetColorMap()
nsColorMap *nsImageQT::GetColorMap()
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsImageQT::GetColorMap()\n"));
return nsnull;
}
PRBool nsImageQT::IsOptimized()
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsImageQT::IsOptimized()\n"));
return PR_TRUE;
}
PRUint8 * nsImageQT::GetAlphaBits()
PRUint8 *nsImageQT::GetAlphaBits()
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsImageQT::GetAlphaBits()\n"));
return mAlphaBits;
}
PRInt32 nsImageQT::GetAlphaWidth()
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsImageQT::GetAlphaWidth()\n"));
return mAlphaWidth;
}
PRInt32 nsImageQT::GetAlphaHeight()
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsImageQT::GetAlphaHeight()\n"));
return mAlphaHeight;
}
PRInt32 nsImageQT::GetAlphaLineStride()
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsImageQT::GetAlphaLineStride()\n"));
return mAlphaRowBytes;
}
nsIImage * nsImageQT::DuplicateImage()
nsIImage *nsImageQT::DuplicateImage()
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsImageQT::DuplicateImage()\n"));
return nsnull;
}
void nsImageQT::SetAlphaLevel(PRInt32 aAlphaLevel)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsImageQT::SetAlphaLevel()\n"));
}
PRInt32 nsImageQT::GetAlphaLevel()
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsImageQT::GetAlphaLevel()\n"));
return 0;
}
void nsImageQT::MoveAlphaMask(PRInt32 aX, PRInt32 aY)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsImageQT::MoveAlphaMask()\n"));
}
//------------------------------------------------------------
PRInt32 nsImageQT::CalcBytesSpan(PRUint32 aWidth)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsImageQT::CalcBytesSpan()\n"));
PRInt32 spanbytes;
spanbytes = (aWidth * mDepth) >> 5;
if (((PRUint32)aWidth * mDepth) & 0x1F)
{
if (((PRUint32)aWidth * mDepth) & 0x1F) {
spanbytes++;
}
spanbytes <<= 2;
@ -307,25 +281,17 @@ PRInt32 nsImageQT::CalcBytesSpan(PRUint32 aWidth)
// set up the palette to the passed in color array, RGB only in this array
void nsImageQT::ImageUpdated(nsIDeviceContext *aContext,
PRUint8 aFlags,
nsRect *aUpdateRect)
PRUint8 aFlags,nsRect *aUpdateRect)
{
if (IsFlagSet(nsImageUpdateFlags_kBitsChanged, aFlags))
{
PR_LOG(QtGfxLM,
PR_LOG_DEBUG,
("nsImageQT::ImageUpdated:Update flags changed\n"));
if (nsnull != mAlphaPixmap)
{
if (IsFlagSet(nsImageUpdateFlags_kBitsChanged,aFlags)) {
if (nsnull != mAlphaPixmap) {
delete mAlphaPixmap;
mAlphaPixmap = nsnull;
}
// mImagePixmap gets created once per unique image bits in Draw()
// ImageUpdated(nsImageUpdateFlags_kBitsChanged) can cause the
// image bits to change and mImagePixmap will be unrefed and nulled.
if (nsnull != mImagePixmap)
{
if (nsnull != mImagePixmap) {
delete mImagePixmap;
mImagePixmap = nsnull;
}
@ -335,18 +301,11 @@ void nsImageQT::ImageUpdated(nsIDeviceContext *aContext,
// Draw the bitmap, this method has a source and destination coordinates
NS_IMETHODIMP nsImageQT::Draw(nsIRenderingContext &aContext,
nsDrawingSurface aSurface,
PRInt32 aSX,
PRInt32 aSY,
PRInt32 aSWidth,
PRInt32 aSHeight,
PRInt32 aDX,
PRInt32 aDY,
PRInt32 aDWidth,
PRInt32 aDHeight)
PRInt32 aSX, PRInt32 aSY,
PRInt32 aSWidth, PRInt32 aSHeight,
PRInt32 aDX, PRInt32 aDY,
PRInt32 aDWidth, PRInt32 aDHeight)
{
PR_LOG(QtGfxLM,
PR_LOG_DEBUG,
("nsImageQT::Draw with source and destination coordinates\n"));
if (nsnull == aSurface) {
return NS_ERROR_FAILURE;
}
@ -364,28 +323,8 @@ NS_IMETHODIMP nsImageQT::Draw(nsIRenderingContext &aContext,
// need to be scaled.
nsDrawingSurfaceQT *drawing = (nsDrawingSurfaceQT*)aSurface;
PR_LOG(QtGfxLM,
PR_LOG_DEBUG,
("nsImageQT::Draw: destx=%d, desty=%d, destwidth=%d, destheight=%d\n",
aDX,
aDY,
aDWidth,
aDHeight));
PR_LOG(QtGfxLM,
PR_LOG_DEBUG,
("nsImageQT::Draw: srcx=%d, srcy=%d, srcwidth=%d, srcheight=%d\n",
aSX,
aSY,
aSWidth,
aSHeight));
drawing->GetGC()->drawImage(aDX,
aDY,
*mImagePixmap,
aSX,
aSY,
aSWidth,
aSHeight);
drawing->GetGC()->drawImage(aDX,aDY,*mImagePixmap,aSX,aSY,
aSWidth,aSHeight);
return NS_OK;
}
@ -394,33 +333,18 @@ NS_IMETHODIMP nsImageQT::Draw(nsIRenderingContext &aContext,
// Draw the bitmap, this draw just has destination coordinates
NS_IMETHODIMP nsImageQT::Draw(nsIRenderingContext &aContext,
nsDrawingSurface aSurface,
PRInt32 aX,
PRInt32 aY,
PRInt32 aWidth,
PRInt32 aHeight)
PRInt32 aX, PRInt32 aY,
PRInt32 aWidth, PRInt32 aHeight)
{
PR_LOG(QtGfxLM,
PR_LOG_DEBUG,
("nsImageQT::Draw with just destination coordinates\n"));
if (nsnull == aSurface) {
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsImageQT::Draw: no surface!!\n"));
return NS_ERROR_FAILURE;
}
// XXX kipp: this is temporary code until we eliminate the
// width/height arguments from the draw method.
if ((aWidth != mWidth) || (aHeight != mHeight)) {
aWidth = mWidth;
aHeight = mHeight;
}
#ifdef TRACE_IMAGE_ALLOCATION
PR_LOG(QtGfxLM,
PR_LOG_DEBUG,
("nsImageQT::Draw:this=%p,x=%d,y=%d,width=%d,height=%d\n",
this, aX, aY, aWidth, aHeight));
#endif
nsDrawingSurfaceQT *drawing = (nsDrawingSurfaceQT*)aSurface;
// Render unique image bits onto an off screen pixmap only once
@ -432,52 +356,62 @@ NS_IMETHODIMP nsImageQT::Draw(nsIRenderingContext &aContext,
if (nsnull == mImagePixmap)
return NS_ERROR_FAILURE;
drawing->GetGC()->drawImage(aX, aY, *mImagePixmap, 0, 0, aWidth, aHeight);
PR_LOG(QtGfxLM,
PR_LOG_DEBUG,
("nsImageQT::Draw:x=%d, y=%d, width=%d, height=%d, imagesize=%d",
aX, aY, aWidth, aHeight, mSizeImage));
drawing->GetGC()->drawImage(aX,aY,*mImagePixmap,0,0,aWidth,aHeight);
return NS_OK;
}
#ifdef USE_IMG2
void nsImageQT::CreateOffscreenPixmap(PRInt32 aWidth,PRInt32 aHeight)
{
if (mImagePixmap)
delete mImagePixmap;
mImagePixmap = new QImage(aWidth,aHeight,mDepth);
if (mImagePixmap) {
mImagePixmap->setAlphaBuffer(PR_TRUE);
mImagePixmap->fill(0);
}
}
#endif
void nsImageQT::CreateImagePixmap(PRInt32 aWidth,PRInt32 aHeight)
{
mImagePixmap = new QImage(aWidth, aHeight, mDepth);
mImagePixmap->setAlphaBuffer(PR_TRUE);
mImagePixmap = new QImage(aWidth,aHeight,mDepth);
if (mImagePixmap) {
PRInt8 BytesPerPixel = mRequestDepth / 8;
PRInt8 bytesPerPixel = mRequestDepth / 8;
PRUint8 *alpha = mAlphaBits;
PRUint8 *image = mImageBits;
PRUint8 *imagePtr;
PRUint32 pixel;
PRInt32 i,j;
QRgb *line;
for (PRInt32 i = 0; i < aHeight; i++) {
QRgb * line = (QRgb*)mImagePixmap->scanLine(i);
mImagePixmap->setAlphaBuffer(PR_TRUE);
for (i = 0; i < aHeight; i++) {
line = (QRgb*)mImagePixmap->scanLine(i);
for (PRInt32 j = 0, l = 0; l < aWidth; j += BytesPerPixel, l++) {
PRUint32 c = 0;
PRUint8 tmp;
for (PRInt8 k = (BytesPerPixel - 1); k >= 0; k--) {
c <<= 8;
tmp = mImageBits[(i * mRowBytes) + j + k];
c |= tmp;
imagePtr = image;
for (j = 0; j < aWidth; j++) {
pixel = 0xFF000000 | *(imagePtr + bytesPerPixel - 1)
| (*(imagePtr + bytesPerPixel - 2) << 8)
| (*(imagePtr + bytesPerPixel - 3) << 16);
if (mAlphaBits) {
if (mAlphaDepth == 1) {
if (!(alpha[j / 8] & (1 << (7 - (j % 8))))) {
pixel &= 0x00FFFFFF;
}
}
else {
pixel &= (alpha[j] << 24);
}
}
PRUint8 a;
PRUint8 r = NS_GET_R(c);
PRUint8 g = NS_GET_G(c);
PRUint8 b = NS_GET_B(c);
if (mAlphaBits)
a = mAlphaDepth == 1 ? ((alpha[l / 8] & (1 << (7 - (l % 8)))) ? 255 : 0) : alpha[l];
else if (BytesPerPixel == 4)
a = NS_GET_A(c);
else
a = 255;
else if (bytesPerPixel == 4)
pixel &= (*(imagePtr + bytesPerPixel - 4) << 24);
QRgb qcolor = qRgba(r, g, b, a);
line[l] = qcolor;
line[j] = pixel;
imagePtr += bytesPerPixel;
}
alpha += mAlphaRowBytes;
image += mRowBytes;
}
}
}
@ -500,8 +434,6 @@ NS_IMETHODIMP nsImageQT::DrawTile(nsIRenderingContext &aContext,
return NS_OK;
}
QPixmap qPmap;
// Render unique image bits onto an off screen pixmap only once
// The image bits can change as a result of ImageUpdated() - for
// example: animated GIFs.
@ -511,6 +443,8 @@ NS_IMETHODIMP nsImageQT::DrawTile(nsIRenderingContext &aContext,
if (nsnull == mImagePixmap)
return NS_ERROR_FAILURE;
QPixmap qPmap;
qPmap.convertFromImage(*mImagePixmap);
drawing->GetGC()->drawTiledPixmap(aTileRect.x,aTileRect.y,
aTileRect.width,aTileRect.height,
@ -533,19 +467,16 @@ NS_IMETHODIMP nsImageQT::DrawTile(nsIRenderingContext &aContext,
nsresult nsImageQT::Optimize(nsIDeviceContext* aContext)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsImageQT::Optimize()\n"));
return NS_OK;
}
PRInt32 nsImageQT::GetBytesPix()
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsImageQT::GetBytesPix()\n"));
return mNumBytesPixel;
}
PRBool nsImageQT::GetIsRowOrderTopToBottom()
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsImageQT::GetIsRowOrderTopToBottom()\n"));
return mIsTopToBottom;
}
@ -569,13 +500,41 @@ nsImageQT::UnlockImagePixels(PRBool aMaskPixels)
* Set the decoded dimens of the image
*/
NS_IMETHODIMP
nsImageQT::SetDecodedRect(PRInt32 x1, PRInt32 y1, PRInt32 x2, PRInt32 y2 )
nsImageQT::SetDecodedRect(PRInt32 x1,PRInt32 y1,PRInt32 x2,PRInt32 y2)
{
mDecodedX1 = x1;
mDecodedY1 = y1;
mDecodedX2 = x2;
mDecodedY2 = y2;
return NS_OK;
}
#ifdef USE_IMG2
NS_IMETHODIMP nsImageQT::DrawToImage(nsIImage *aDstImage,
nscoord aDX,nscoord aDY,
nscoord aDWidth,nscoord aDHeight)
{
nsImageQT *dest = NS_STATIC_CAST(nsImageQT*,aDstImage);
if (!dest)
return NS_ERROR_FAILURE;
if (!mImagePixmap)
CreateImagePixmap(mWidth,mHeight);
if (!mImagePixmap)
return NS_ERROR_FAILURE;
if (!dest->mImagePixmap)
dest->CreateOffscreenPixmap(dest->mWidth,dest->mHeight);
if (!dest->mImagePixmap)
return NS_ERROR_FAILURE;
bitBlt(dest->mImagePixmap,aDX,aDY,mImagePixmap,0,0,mWidth,mHeight,
Qt::CopyROP);
return NS_OK;
}
#endif

View File

@ -18,6 +18,8 @@
* Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
*
*/
#ifndef nsImageQT_h___
@ -26,54 +28,66 @@
#include "nsIImage.h"
#include <qpixmap.h>
#include <qimage.h>
#undef Bool
class nsImageQT : public nsIImage
{
public:
nsImageQT();
virtual ~nsImageQT();
nsImageQT();
virtual ~nsImageQT();
NS_DECL_ISUPPORTS
NS_DECL_ISUPPORTS
/**
@see nsIImage.h
*/
virtual PRInt32 GetBytesPix();
virtual PRBool GetIsRowOrderTopToBottom();
virtual PRInt32 GetHeight();
virtual PRInt32 GetWidth();
virtual PRUint8* GetBits();
virtual void* GetBitInfo();
virtual PRInt32 GetLineStride();
/**
* @see nsIImage.h
*/
virtual PRInt32 GetBytesPix();
virtual PRBool GetIsRowOrderTopToBottom();
virtual PRInt32 GetHeight();
virtual PRInt32 GetWidth();
virtual PRUint8 *GetBits();
virtual void *GetBitInfo();
virtual PRInt32 GetLineStride();
NS_IMETHOD SetNaturalWidth(PRInt32 naturalwidth) { mNaturalWidth= naturalwidth; return NS_OK;}
NS_IMETHOD SetNaturalHeight(PRInt32 naturalheight) { mNaturalHeight= naturalheight; return NS_OK;}
virtual PRInt32 GetNaturalWidth() {return mNaturalWidth; }
virtual PRInt32 GetNaturalHeight() {return mNaturalHeight; }
NS_IMETHOD SetNaturalWidth(PRInt32 naturalwidth)
{
mNaturalWidth = naturalwidth;
return NS_OK;
}
NS_IMETHOD SetNaturalHeight(PRInt32 naturalheight)
{
mNaturalHeight = naturalheight;
return NS_OK;
}
virtual PRInt32 GetNaturalWidth() {return mNaturalWidth;}
virtual PRInt32 GetNaturalHeight() {return mNaturalHeight;}
NS_IMETHOD SetDecodedRect(PRInt32 x1, PRInt32 y1, PRInt32 x2, PRInt32 y2);
virtual PRInt32 GetDecodedX1() { return mDecodedX1;}
virtual PRInt32 GetDecodedY1() { return mDecodedY1;}
virtual PRInt32 GetDecodedX2() { return mDecodedX2;}
virtual PRInt32 GetDecodedY2() { return mDecodedY2;}
NS_IMETHOD SetDecodedRect(PRInt32 x1,PRInt32 y1,
PRInt32 x2,PRInt32 y2);
virtual PRInt32 GetDecodedX1() {return mDecodedX1;}
virtual PRInt32 GetDecodedY1() {return mDecodedY1;}
virtual PRInt32 GetDecodedX2() {return mDecodedX2;}
virtual PRInt32 GetDecodedY2() {return mDecodedY2;}
virtual nsColorMap* GetColorMap();
NS_IMETHOD Draw(nsIRenderingContext &aContext,
nsDrawingSurface aSurface,
PRInt32 aX, PRInt32 aY,
PRInt32 aWidth, PRInt32 aHeight);
NS_IMETHOD Draw(nsIRenderingContext &aContext,
nsDrawingSurface aSurface,
PRInt32 aSX,
PRInt32 aSY,
PRInt32 aSWidth,
PRInt32 aSHeight,
PRInt32 aDX,
PRInt32 aDY,
PRInt32 aDWidth,
PRInt32 aDHeight);
virtual nsColorMap *GetColorMap();
NS_IMETHOD Draw(nsIRenderingContext &aContext,
nsDrawingSurface aSurface,
PRInt32 aX, PRInt32 aY,
PRInt32 aWidth, PRInt32 aHeight);
NS_IMETHOD Draw(nsIRenderingContext &aContext,
nsDrawingSurface aSurface,
PRInt32 aSX, PRInt32 aSY,
PRInt32 aSWidth, PRInt32 aSHeight,
PRInt32 aDX, PRInt32 aDY,
PRInt32 aDWidth, PRInt32 aDHeight);
#ifdef USE_IMG2
void CreateOffscreenPixmap(PRInt32 aWidth,PRInt32 aHeight);
NS_IMETHOD DrawToImage(nsIImage *aDstImage,nscoord aDX,nscoord aDY,
nscoord aDWidth,nscoord aDHeight);
#endif
NS_IMETHOD DrawTile(nsIRenderingContext &aContext,
nsDrawingSurface aSurface,
@ -85,71 +99,73 @@ public:
PRInt32 aSXOffset, PRInt32 aSYOffset,
const nsRect &aTileRect);
virtual void ImageUpdated(nsIDeviceContext *aContext,
PRUint8 aFlags, nsRect *aUpdateRect);
virtual nsresult Init(PRInt32 aWidth, PRInt32 aHeight,
PRInt32 aDepth,
nsMaskRequirements aMaskRequirements);
virtual PRBool IsOptimized();
virtual void ImageUpdated(nsIDeviceContext *aContext,
PRUint8 aFlags,nsRect *aUpdateRect);
virtual nsresult Init(PRInt32 aWidth,PRInt32 aHeight,
PRInt32 aDepth,
nsMaskRequirements aMaskRequirements);
virtual PRBool IsOptimized();
virtual nsresult Optimize(nsIDeviceContext* aContext);
virtual PRBool GetHasAlphaMask() { return mAlphaBits != nsnull; }
virtual PRUint8* GetAlphaBits();
virtual PRInt32 GetAlphaWidth();
virtual PRInt32 GetAlphaHeight();
virtual PRInt32 GetAlphaLineStride();
virtual nsIImage* DuplicateImage();
virtual nsresult Optimize(nsIDeviceContext *aContext);
virtual PRBool GetHasAlphaMask() {return mAlphaBits != nsnull;}
virtual PRUint8 *GetAlphaBits();
virtual PRInt32 GetAlphaWidth();
virtual PRInt32 GetAlphaHeight();
virtual PRInt32 GetAlphaLineStride();
virtual nsIImage *DuplicateImage();
/**
* Calculate the number of bytes spaned for this image for a given width
* @param aWidth is the width to calculate the number of bytes for
* @return the number of bytes in this span
*/
PRInt32 CalcBytesSpan(PRUint32 aWidth);
virtual void SetAlphaLevel(PRInt32 aAlphaLevel);
virtual PRInt32 GetAlphaLevel();
virtual void MoveAlphaMask(PRInt32 aX, PRInt32 aY);
/**
* Calculate the number of bytes spaned for this image for a given width
* @param aWidth is the width to calculate the number of bytes for
* @return the number of bytes in this span
*/
PRInt32 CalcBytesSpan(PRUint32 aWidth);
virtual void SetAlphaLevel(PRInt32 aAlphaLevel);
virtual PRInt32 GetAlphaLevel();
virtual void MoveAlphaMask(PRInt32 aX,PRInt32 aY);
NS_IMETHOD LockImagePixels(PRBool aMaskPixels);
NS_IMETHOD UnlockImagePixels(PRBool aMaskPixels);
private:
/**
* Calculate the amount of memory needed for the initialization of the
* image
*/
void ComputeMetrics();
void ComputePaletteSize(PRIntn nBitCount);
void CreateImagePixmap(PRInt32 aWidth,PRInt32 aHeight);
/**
* Calculate the amount of memory needed for the initialization of the
* image
*/
void ComputeMetrics();
void ComputePaletteSize(PRIntn nBitCount);
void CreateImagePixmap(PRInt32 aWidth,PRInt32 aHeight);
private:
PRInt32 mWidth;
PRInt32 mHeight;
PRInt32 mDepth; // actual bits per pixel
PRInt32 mRequestDepth; // requested bits per pixel
PRInt32 mRowBytes;
PRUint8 * mImageBits;
PRInt32 mSizeImage;
PRBool mIsTopToBottom;
PRInt32 mWidth;
PRInt32 mHeight;
PRInt32 mDepth; // actual bits per pixel
PRInt32 mRequestDepth; // requested bits per pixel
PRInt32 mRowBytes;
PRUint8 *mImageBits;
PRInt32 mSizeImage;
PRBool mIsTopToBottom;
PRInt8 mNumBytesPixel;
PRInt8 mNumBytesPixel;
PRInt32 mNaturalWidth;
PRInt32 mNaturalHeight;
PRInt32 mNaturalWidth;
PRInt32 mNaturalHeight;
PRInt32 mDecodedX1; //Keeps track of what part of image
PRInt32 mDecodedY1; // has been decoded.
PRInt32 mDecodedX2;
PRInt32 mDecodedY2;
PRInt32 mDecodedX1; //Keeps track of what part of image
PRInt32 mDecodedY1; // has been decoded.
PRInt32 mDecodedX2;
PRInt32 mDecodedY2;
// alpha layer members
PRUint8 * mAlphaBits;
QImage * mAlphaPixmap;
PRInt8 mAlphaDepth; // alpha layer depth
PRInt16 mAlphaRowBytes; // alpha bytes per row
PRInt16 mAlphaWidth; // alpha layer width
PRInt16 mAlphaHeight; // alpha layer height
QImage * mImagePixmap;
// alpha layer members
PRUint8 *mAlphaBits;
QImage *mAlphaPixmap;
PRInt8 mAlphaDepth; // alpha layer depth
PRInt16 mAlphaRowBytes; // alpha bytes per row
PRInt16 mAlphaWidth; // alpha layer width
PRInt16 mAlphaHeight; // alpha layer height
QImage *mImagePixmap;
PRUint32 mID;
};
#endif

View File

@ -18,6 +18,8 @@
* Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
*
*/
#include "nsRegionQT.h"
@ -25,33 +27,41 @@
#include "nsRenderingContextQT.h"
#include <qregion.h>
//JCG #define DBG_JCG 1
#ifdef DBG_JCG
PRUint32 gRegionCount = 0;
PRUint32 gRegionID = 0;
#endif
nsRegionQT::nsRegionQT() : mRegion()
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsRegionQT::nsRegionQT()\n"));
NS_INIT_REFCNT();
mRegionType = eRegionComplexity_empty;
#ifdef DBG_JCG
gRegionCount++;
mID = gRegionID++;
printf("JCG: nsRegionQT CTOR (%p) ID: %d, Count: %d\n",this,mID,gRegionCount);
#endif
NS_INIT_REFCNT();
}
nsRegionQT::~nsRegionQT()
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsRegionQT::~nsRegionQT()\n"));
#ifdef DBG_JCG
gRegionCount--;
printf("JCG: nsRegionQT DTOR (%p) ID: %d, Count: %d\n",this,mID,gRegionCount);
#endif
}
NS_IMPL_ISUPPORTS1(nsRegionQT, nsIRegion)
nsresult nsRegionQT::Init(void)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsRegionQT::Init()\n"));
//NS_ADDREF_THIS();
// should this be here?
mRegionType = eRegionComplexity_empty;
SetRegionEmpty();
return NS_OK;
}
void nsRegionQT::SetTo(const nsIRegion &aRegion)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsRegionQT::SetTo()\n"));
nsRegionQT *pRegion = (nsRegionQT*)&aRegion;
SetRegionEmpty();
@ -60,15 +70,13 @@ void nsRegionQT::SetTo(const nsIRegion &aRegion)
void nsRegionQT::SetTo(const nsRegionQT *aRegion)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsRegionQT::SetTo()\n"));
SetRegionEmpty();
mRegion = aRegion->mRegion;
}
void nsRegionQT::SetTo(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
void nsRegionQT::SetTo(PRInt32 aX,PRInt32 aY,PRInt32 aWidth,PRInt32 aHeight)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsRegionQT::SetTo()\n"));
SetRegionEmpty();
QRegion nRegion(aX, aY, aWidth, aHeight);
@ -78,34 +86,28 @@ void nsRegionQT::SetTo(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
void nsRegionQT::Intersect(const nsIRegion &aRegion)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsRegionQT::Intersect()\n"));
nsRegionQT *pRegion = (nsRegionQT*)&aRegion;
mRegion.intersect(pRegion->mRegion);
mRegion = mRegion.intersect(pRegion->mRegion);
}
void nsRegionQT::Intersect(PRInt32 aX,
PRInt32 aY,
PRInt32 aWidth,
PRInt32 aHeight)
void nsRegionQT::Intersect(PRInt32 aX,PRInt32 aY,
PRInt32 aWidth,PRInt32 aHeight)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsRegionQT::Intersect()\n"));
QRegion region(aX, aY, aWidth, aHeight);
mRegion.intersect(region);
mRegion = mRegion.intersect(region);
}
void nsRegionQT::Union(const nsIRegion &aRegion)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsRegionQT::Union()\n"));
nsRegionQT *pRegion = (nsRegionQT*)&aRegion;
mRegion = mRegion.unite(pRegion->mRegion);
}
void nsRegionQT::Union(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
void nsRegionQT::Union(PRInt32 aX,PRInt32 aY,PRInt32 aWidth,PRInt32 aHeight)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsRegionQT::Union()\n"));
QRegion region(aX, aY, aWidth, aHeight);
mRegion = mRegion.unite(region);
@ -113,18 +115,13 @@ void nsRegionQT::Union(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
void nsRegionQT::Subtract(const nsIRegion &aRegion)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsRegionQT::Subtract()\n"));
nsRegionQT *pRegion = (nsRegionQT*)&aRegion;
mRegion = mRegion.subtract(pRegion->mRegion);
}
void nsRegionQT::Subtract(PRInt32 aX,
PRInt32 aY,
PRInt32 aWidth,
PRInt32 aHeight)
void nsRegionQT::Subtract(PRInt32 aX,PRInt32 aY,PRInt32 aWidth,PRInt32 aHeight)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsRegionQT::Subtract()\n"));
QRegion aRegion(aX, aY, aWidth, aHeight);
mRegion = mRegion.subtract(aRegion);
@ -132,24 +129,19 @@ void nsRegionQT::Subtract(PRInt32 aX,
PRBool nsRegionQT::IsEmpty(void)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsRegionQT::IsEmpty()\n"));
return mRegion.isEmpty();
}
PRBool nsRegionQT::IsEqual(const nsIRegion &aRegion)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsRegionQT::IsEqual()\n"));
nsRegionQT *pRegion = (nsRegionQT*)&aRegion;
return (mRegion == pRegion->mRegion);
}
void nsRegionQT::GetBoundingBox(PRInt32 *aX,
PRInt32 *aY,
PRInt32 *aWidth,
PRInt32 *aHeight)
void nsRegionQT::GetBoundingBox(PRInt32 *aX,PRInt32 *aY,
PRInt32 *aWidth,PRInt32 *aHeight)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsRegionQT::GetBoundingBox()\n"));
QRect rect = mRegion.boundingRect();
*aX = rect.x();
@ -160,16 +152,12 @@ void nsRegionQT::GetBoundingBox(PRInt32 *aX,
void nsRegionQT::Offset(PRInt32 aXOffset, PRInt32 aYOffset)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsRegionQT::Offset()\n"));
mRegion.translate(aXOffset, aYOffset);
}
PRBool nsRegionQT::ContainsRect(PRInt32 aX,
PRInt32 aY,
PRInt32 aWidth,
PRInt32 aHeight)
PRBool nsRegionQT::ContainsRect(PRInt32 aX,PRInt32 aY,
PRInt32 aWidth,PRInt32 aHeight)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsRegionQT::ContainsRect()\n"));
QRect rect(aX, aY, aWidth, aHeight);
return mRegion.contains(rect);
@ -177,18 +165,17 @@ PRBool nsRegionQT::ContainsRect(PRInt32 aX,
NS_IMETHODIMP nsRegionQT::GetRects(nsRegionRectSet **aRects)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsRegionQT::GetRects()\n"));
NS_ASSERTION(!(nsnull == aRects), "bad ptr");
QArray<QRect> array = mRegion.rects();
PRUint32 size = array.size();
nsRegionRect *rect = nsnull;
nsRegionRectSet *rects = *aRects;
QArray<QRect> array = mRegion.rects();
PRUint32 size = array.size();
nsRegionRect *rect = nsnull;
nsRegionRectSet *rects = *aRects;
if (nsnull == rects || rects->mRectsLen < (PRUint32)size) {
void *buf = PR_Realloc(rects,
sizeof(nsRegionRectSet) +
(sizeof(nsRegionRect) * (size - 1)));
sizeof(nsRegionRectSet)
+ (sizeof(nsRegionRect) * (size - 1)));
if (nsnull == buf) {
if (nsnull != rects)
@ -220,23 +207,20 @@ NS_IMETHODIMP nsRegionQT::GetRects(nsRegionRectSet **aRects)
NS_IMETHODIMP nsRegionQT::FreeRects(nsRegionRectSet *aRects)
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsRegionQT::FreeRects()\n"));
if (nsnull != aRects) {
PR_Free((void *)aRects);
PR_Free((void*)aRects);
}
return NS_OK;
}
NS_IMETHODIMP nsRegionQT::GetNativeRegion(void *&aRegion) const
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsRegionQT::GetNativeRegion()\n"));
aRegion = (void*)&mRegion;
return NS_OK;
}
NS_IMETHODIMP nsRegionQT::GetRegionComplexity(nsRegionComplexity &aComplexity) const
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsRegionQT::GetRegionComplexity()\n"));
// cast to avoid const-ness problems on some compilers
if (((nsRegionQT*)this)->IsEmpty()) {
aComplexity = eRegionComplexity_empty;
@ -249,7 +233,6 @@ NS_IMETHODIMP nsRegionQT::GetRegionComplexity(nsRegionComplexity &aComplexity) c
void nsRegionQT::SetRegionEmpty()
{
PR_LOG(QtGfxLM, PR_LOG_DEBUG, ("nsRegionQT::SetRegionEmpty()\n"));
if (!IsEmpty()) {
QRegion empty;
mRegion = empty;

View File

@ -18,6 +18,8 @@
* Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
*
*/
#ifndef nsRegionQT_h___
@ -61,8 +63,7 @@ private:
virtual void SetRegionEmpty();
private:
QRegion mRegion;
nsRegionComplexity mRegionType;
QRegion mRegion;
};
#endif // nsRegionQT_h___

File diff suppressed because it is too large Load Diff

View File

@ -18,6 +18,8 @@
* Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
*
*/
#ifndef nsRenderingContextQT_h___
@ -42,7 +44,7 @@
#include "nsDrawingSurfaceQT.h"
#include "prlog.h"
extern PRLogModuleInfo * QtGfxLM;
class nsFontQT;
class nsRenderingContextQT : public nsRenderingContextImpl
{
@ -61,8 +63,9 @@ public:
NS_IMETHOD GetDeviceContext(nsIDeviceContext *&aContext);
NS_IMETHOD LockDrawingSurface(PRInt32 aX, PRInt32 aY, PRUint32 aWidth, PRUint32 aHeight,
void **aBits, PRInt32 *aStride, PRInt32 *aWidthBytes,
NS_IMETHOD LockDrawingSurface(PRInt32 aX,PRInt32 aY,PRUint32 aWidth,
PRUint32 aHeight,void **aBits,
PRInt32 *aStride,PRInt32 *aWidthBytes,
PRUint32 aFlags);
NS_IMETHOD UnlockDrawingSurface(void);
@ -75,10 +78,12 @@ public:
NS_IMETHOD IsVisibleRect(const nsRect& aRect, PRBool &aVisible);
NS_IMETHOD SetClipRect(const nsRect& aRect, nsClipCombine aCombine, PRBool &aClipEmpty);
NS_IMETHOD SetClipRect(const nsRect& aRect,nsClipCombine aCombine,
PRBool &aClipEmpty);
NS_IMETHOD CopyClipRegion(nsIRegion &aRegion);
NS_IMETHOD GetClipRect(nsRect &aRect, PRBool &aClipValid);
NS_IMETHOD SetClipRegion(const nsIRegion& aRegion, nsClipCombine aCombine, PRBool &aClipEmpty);
NS_IMETHOD SetClipRegion(const nsIRegion& aRegion,nsClipCombine aCombine,
PRBool &aClipEmpty);
NS_IMETHOD GetClipRegion(nsIRegion **aRegion);
NS_IMETHOD SetLineStyle(nsLineStyle aLineStyle);
@ -96,57 +101,70 @@ public:
NS_IMETHOD Scale(float aSx, float aSy);
NS_IMETHOD GetCurrentTransform(nsTransform2D *&aTransform);
NS_IMETHOD CreateDrawingSurface(nsRect *aBounds, PRUint32 aSurfFlags, nsDrawingSurface &aSurface);
NS_IMETHOD CreateDrawingSurface(nsRect *aBounds,PRUint32 aSurfFlags,
nsDrawingSurface &aSurface);
NS_IMETHOD DestroyDrawingSurface(nsDrawingSurface aDS);
NS_IMETHOD DrawLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1);
NS_IMETHOD DrawStdLine(nscoord aX0,nscoord aY0,nscoord aX1,nscoord aY1);
NS_IMETHOD DrawPolyline(const nsPoint aPoints[], PRInt32 aNumPoints);
NS_IMETHOD DrawRect(const nsRect& aRect);
NS_IMETHOD DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
NS_IMETHOD DrawRect(nscoord aX,nscoord aY,nscoord aWidth,nscoord aHeight);
NS_IMETHOD FillRect(const nsRect& aRect);
NS_IMETHOD FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
NS_IMETHOD FillRect(nscoord aX,nscoord aY,nscoord aWidth,nscoord aHeight);
NS_IMETHOD InvertRect(const nsRect& aRect);
NS_IMETHOD InvertRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
NS_IMETHOD InvertRect(nscoord aX,nscoord aY,nscoord aWidth,nscoord aHeight);
NS_IMETHOD DrawPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
NS_IMETHOD FillPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
NS_IMETHOD DrawEllipse(const nsRect& aRect);
NS_IMETHOD DrawEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
NS_IMETHOD DrawEllipse(nscoord aX,nscoord aY,nscoord aWidth,
nscoord aHeight);
NS_IMETHOD FillEllipse(const nsRect& aRect);
NS_IMETHOD FillEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
NS_IMETHOD FillEllipse(nscoord aX,nscoord aY,nscoord aWidth,
nscoord aHeight);
NS_IMETHOD DrawArc(const nsRect& aRect, float aStartAngle, float aEndAngle);
NS_IMETHOD DrawArc(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
float aStartAngle, float aEndAngle);
NS_IMETHOD FillArc(const nsRect& aRect, float aStartAngle, float aEndAngle);
NS_IMETHOD FillArc(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
float aStartAngle, float aEndAngle);
NS_IMETHOD DrawArc(const nsRect& aRect,float aStartAngle,float aEndAngle);
NS_IMETHOD DrawArc(nscoord aX,nscoord aY,nscoord aWidth,nscoord aHeight,
float aStartAngle,float aEndAngle);
NS_IMETHOD FillArc(const nsRect& aRect,float aStartAngle,float aEndAngle);
NS_IMETHOD FillArc(nscoord aX,nscoord aY,nscoord aWidth,nscoord aHeight,
float aStartAngle,float aEndAngle);
NS_IMETHOD GetWidth(char aC, nscoord &aWidth);
NS_IMETHOD GetWidth(PRUnichar aC, nscoord &aWidth, PRInt32 *aFontID);
NS_IMETHOD GetWidth(const nsString& aString, nscoord &aWidth, PRInt32 *aFontID);
NS_IMETHOD GetWidth(const char *aString, nscoord &aWidth);
NS_IMETHOD GetWidth(const char *aString, PRUint32 aLength, nscoord &aWidth);
NS_IMETHOD GetWidth(const PRUnichar *aString, PRUint32 aLength, nscoord &aWidth,
NS_IMETHOD GetWidth(const nsString& aString,nscoord &aWidth,
PRInt32 *aFontID);
NS_IMETHOD GetWidth(const char *aString, nscoord &aWidth);
NS_IMETHOD GetWidth(const char *aString,PRUint32 aLength,nscoord &aWidth);
NS_IMETHOD GetWidth(const PRUnichar *aString,PRUint32 aLength,
nscoord &aWidth,PRInt32 *aFontID);
NS_IMETHOD DrawString(const char *aString, PRUint32 aLength,
nscoord aX, nscoord aY,
const nscoord* aSpacing);
NS_IMETHOD DrawString(const PRUnichar *aString, PRUint32 aLength,
nscoord aX, nscoord aY,
PRInt32 aFontID,
const nscoord* aSpacing);
NS_IMETHOD DrawString(const nsString& aString,
nscoord aX, nscoord aY,
PRInt32 aFontID,
#ifdef MOZ_MATHML
/* Returns metrics (in app units) of an 8-bit character string */
NS_IMETHOD GetBoundingMetrics(const char *aString,PRUint32 aLength,
nsBoundingMetrics& aBoundingMetrics);
/* Returns metrics (in app units) of a Unicode character string */
NS_IMETHOD GetBoundingMetrics(const PRUnichar *aString,PRUint32 aLength,
nsBoundingMetrics& aBoundingMetrics,
PRInt32 *aFontID = nsnull);
#endif /* MOZ_MATHML */
void MyDrawString(QPainter *aGC,nscoord aX,nscoord aY,QString &aText);
NS_IMETHOD DrawString(const char *aString,PRUint32 aLength,
nscoord aX,nscoord aY,const nscoord* aSpacing);
NS_IMETHOD DrawString(const PRUnichar *aString,PRUint32 aLength,
nscoord aX,nscoord aY,PRInt32 aFontID,
const nscoord* aSpacing);
NS_IMETHOD DrawString(const nsString& aString,nscoord aX,nscoord aY,
PRInt32 aFontID,const nscoord* aSpacing);
NS_IMETHOD DrawImage(nsIImage *aImage, nscoord aX, nscoord aY);
NS_IMETHOD DrawImage(nsIImage *aImage, nscoord aX, nscoord aY,
nscoord aWidth, nscoord aHeight);
NS_IMETHOD DrawImage(nsIImage *aImage,nscoord aX,nscoord aY,
nscoord aWidth,nscoord aHeight);
NS_IMETHOD DrawImage(nsIImage *aImage, const nsRect& aRect);
NS_IMETHOD DrawImage(nsIImage *aImage, const nsRect& aSRect,
const nsRect& aDRect);
@ -160,7 +178,7 @@ public:
const nsRect &aDestBounds,
PRUint32 aCopyFlags);
NS_IMETHOD RetrieveCurrentNativeGraphicData(PRUint32 * ngd);
NS_IMETHOD RetrieveCurrentNativeGraphicData(PRUint32 *ngd);
//locals
NS_IMETHOD CommonInit();
@ -169,21 +187,20 @@ public:
void CreateClipRegion();
protected:
nsDrawingSurfaceQT * mOffscreenSurface;
nsDrawingSurfaceQT * mSurface;
nsIDeviceContext * mContext;
nsIFontMetrics * mFontMetrics;
nsCOMPtr<nsIRegion> mClipRegion;
float mP2T;
nsDrawingSurfaceQT *mOffscreenSurface;
nsDrawingSurfaceQT *mSurface;
nsIDeviceContext *mContext;
nsIFontMetrics *mFontMetrics;
nsCOMPtr<nsIRegion> mClipRegion;
float mP2T;
// graphic state stack (GraphicsState)
nsVoidArray * mStateCache;
nsVoidArray *mStateCache;
nscolor mCurrentColor;
nsLineStyle mCurrentLineStyle;
nscolor mCurrentColor;
nsLineStyle mCurrentLineStyle;
QFont * mCurrentFont;
QFontMetrics * mCurrentFontMetrics;
nsFontQT *mCurrentFont;
Qt::PenStyle mQLineStyle;
Qt::RasterOp mFunction;
QPainter *mGC;

View File

@ -18,14 +18,27 @@
* Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
*
*/
#include "nsScreenManagerQT.h"
#include "nsScreenQT.h"
//JCG #define DBG_JCG 1
#ifdef DBG_JCG
PRUint32 gSMCount = 0;
PRUint32 gSMID = 0;
#endif
nsScreenManagerQT::nsScreenManagerQT()
{
#ifdef DBG_JCG
gSMCount++;
mID = gSMID++;
printf("JCG: nsScreenManagerQT CTOR (%p) ID: %d, Count: %d\n",this,mID,gSMCount);
#endif
NS_INIT_REFCNT();
// nothing else to do. I guess we could cache a bunch of information
@ -36,14 +49,16 @@ nsScreenManagerQT::nsScreenManagerQT()
nsScreenManagerQT::~nsScreenManagerQT()
{
#ifdef DBG_JCG
gSMCount--;
printf("JCG: nsScreenManagerQT DTOR (%p) ID: %d, Count: %d\n",this,mID,gSMCount);
#endif
// nothing to see here.
}
// addref, release, QI
NS_IMPL_ISUPPORTS(nsScreenManagerQT, NS_GET_IID(nsIScreenManager))
//
// CreateNewScreenObject
//
@ -55,7 +70,7 @@ NS_IMPL_ISUPPORTS(nsScreenManagerQT, NS_GET_IID(nsIScreenManager))
nsIScreen*
nsScreenManagerQT::CreateNewScreenObject()
{
nsIScreen* retval = nsnull;
nsIScreen *retval = nsnull;
if (!mCachedMainScreen)
mCachedMainScreen = new nsScreenQT();
NS_IF_ADDREF(retval = mCachedMainScreen.get());
@ -63,7 +78,6 @@ nsScreenManagerQT::CreateNewScreenObject()
return retval;
}
//
// ScreenForRect
//
@ -81,7 +95,6 @@ nsScreenManagerQT::ScreenForRect(PRInt32 /*inLeft*/, PRInt32 /*inTop*/,
return NS_OK;
} // ScreenForRect
//
// GetPrimaryScreen
//
@ -95,7 +108,6 @@ nsScreenManagerQT::GetPrimaryScreen(nsIScreen **aPrimaryScreen)
return NS_OK;
} // GetPrimaryScreen
//
// GetNumberOfScreens
//
@ -107,4 +119,3 @@ nsScreenManagerQT::GetNumberOfScreens(PRUint32 *aNumberOfScreens)
*aNumberOfScreens = 1;
return NS_OK;
} // GetNumberOfScreens

View File

@ -18,6 +18,8 @@
* Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
*
*/
#ifndef nsScreenManagerQt_h___

View File

@ -18,6 +18,8 @@
* Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
*
*/
#include "nsScreenQT.h"
@ -25,16 +27,32 @@
#include <qcolor.h>
#include <qapplication.h>
nsScreenQT :: nsScreenQT ( )
//JCG #define DBG_JCG 1
#ifdef DBG_JCG
PRUint32 gScreenCount = 0;
PRUint32 gScreenID = 0;
#endif
nsScreenQT::nsScreenQT()
{
#ifdef DBG_JCG
gScreenCount++;
mID = gScreenID++;
printf("JCG: nsScreenQT CTOR (%p) ID: %d, Count: %d\n",this,mID,gScreenCount);
#endif
NS_INIT_REFCNT();
// nothing else to do. I guess we could cache a bunch of information
// here, but we want to ask the device at runtime in case anything
// has changed.
}
nsScreenQT :: ~nsScreenQT()
nsScreenQT::~nsScreenQT()
{
#ifdef DBG_JCG
gScreenCount--;
printf("JCG: nsScreenQT DTOR (%p) ID: %d, Count: %d\n",this,mID,gScreenCount);
#endif
// nothing to see here.
}
@ -42,7 +60,8 @@ nsScreenQT :: ~nsScreenQT()
NS_IMPL_ISUPPORTS(nsScreenQT, NS_GET_IID(nsIScreen))
NS_IMETHODIMP
nsScreenQT :: GetRect(PRInt32 *outLeft, PRInt32 *outTop, PRInt32 *outWidth, PRInt32 *outHeight)
nsScreenQT::GetRect(PRInt32 *outLeft,PRInt32 *outTop,
PRInt32 *outWidth,PRInt32 *outHeight)
{
*outTop = 0;
*outLeft = 0;
@ -53,7 +72,8 @@ nsScreenQT :: GetRect(PRInt32 *outLeft, PRInt32 *outTop, PRInt32 *outWidth, PRIn
} // GetRect
NS_IMETHODIMP
nsScreenQT :: GetAvailRect(PRInt32 *outLeft, PRInt32 *outTop, PRInt32 *outWidth, PRInt32 *outHeight)
nsScreenQT::GetAvailRect(PRInt32 *outLeft,PRInt32 *outTop,
PRInt32 *outWidth,PRInt32 *outHeight)
{
*outTop = 0;
*outLeft = 0;
@ -64,14 +84,14 @@ nsScreenQT :: GetAvailRect(PRInt32 *outLeft, PRInt32 *outTop, PRInt32 *outWidth,
} // GetAvailRect
NS_IMETHODIMP
nsScreenQT :: GetPixelDepth(PRInt32 *aPixelDepth)
nsScreenQT::GetPixelDepth(PRInt32 *aPixelDepth)
{
*aPixelDepth = (PRInt32)QColor::numBitPlanes();
return NS_OK;
} // GetPixelDepth
NS_IMETHODIMP
nsScreenQT :: GetColorDepth(PRInt32 *aColorDepth)
nsScreenQT::GetColorDepth(PRInt32 *aColorDepth)
{
return GetPixelDepth(aColorDepth);
} // GetColorDepth

View File

@ -18,6 +18,8 @@
* Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
*
*/
#ifndef nsScreenQT_h___

View File

@ -17,6 +17,7 @@
# Rights Reserved.
#
# Contributor(s):
# John C. Griggs <johng@corel.com>
#
DEPTH = ../../..
@ -29,51 +30,28 @@ include $(DEPTH)/config/autoconf.mk
LIBRARY_NAME = widget_qt
IS_COMPONENT = 1
CPPSRCS = \
$(MOCSRCS) \
nsQApplication.cpp \
nsAppShell.cpp \
nsBidiKeyboard.cpp \
nsComboBox.cpp \
nsLabel.cpp \
nsScrollbar.cpp \
nsButton.cpp \
nsListBox.cpp \
nsLookAndFeel.cpp \
nsTextAreaWidget.cpp \
nsCheckButton.cpp \
nsMenu.cpp \
nsTextHelper.cpp \
nsMenuBar.cpp \
nsFontRetrieverService.cpp \
nsFontSizeIterator.cpp \
nsTextWidget.cpp \
nsFileWidget.cpp \
nsToolkit.cpp \
nsQEventHandler.cpp \
nsRadioButton.cpp \
nsPopUpMenu.cpp \
nsQWidget.cpp \
nsWidget.cpp \
nsWindow.cpp \
nsDragService.cpp \
nsClipboard.cpp \
nsWidgetFactory.cpp \
nsMime.cpp \
$(NULL)
MOCSRCS = \
moc_nsQApplication.cpp \
moc_nsComboBox.cpp \
moc_nsLabel.cpp \
moc_nsScrollbar.cpp \
moc_nsButton.cpp \
moc_nsListBox.cpp \
moc_nsTextAreaWidget.cpp \
moc_nsCheckButton.cpp \
moc_nsTextWidget.cpp \
moc_nsQEventHandler.cpp \
moc_nsRadioButton.cpp \
moc_nsWindow.cpp \
moc_nsQWidget.cpp \
moc_nsMime.cpp \
$(NULL)
SHARED_LIBRARY_LIBS = $(DIST)/lib/libxpwidgets_s.a
@ -81,9 +59,9 @@ SHARED_LIBRARY_LIBS = $(DIST)/lib/libxpwidgets_s.a
EXTRA_DSO_LDOPTS = \
$(MOZ_COMPONENT_LIBS) \
-lgkgfx \
-I$(topsrcdir)/gfx/src/qt \
$(MOZ_JS_LIBS) \
$(NULL)
# -lraptorgfx \
ifndef MOZ_MONOLITHIC_TOOLKIT
EXTRA_DSO_LDOPTS += -L$(DIST)/lib $(MOZ_QT_LDFLAGS) $(MOZ_XLIB_LDFLAGS)
@ -117,5 +95,7 @@ DEFINES += -D_TIME_H=1
endif
endif
INCLUDES += -I$(srcdir)/../xpwidgets -I$(srcdir)
INCLUDES += -I$(srcdir)/../xpwidgets \
-I$(srcdir) \
-I$(topsrcdir)/gfx/src/qt \
$(NULL)

View File

@ -18,19 +18,22 @@
* Rights Reserved.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
* John C. Griggs <johng@corel.com>
*
*/
#include "nsCOMPtr.h"
#include "nsAppShell.h"
#include "nsIAppShell.h"
#include "nsIServiceManager.h"
#include "nsIEventQueueService.h"
#include "nsICmdLineService.h"
#include <stdlib.h>
#include "nsWidget.h"
#include <qwindowdefs.h>
#include "X11/Xlib.h"
//JCG #define DBG_JCG 1
#ifdef DBG_JCG
PRInt32 gAppShellCount = 0;
PRInt32 gAppShellID = 0;
#endif
//-------------------------------------------------------------------------
//
@ -49,13 +52,15 @@ PRBool nsAppShell::mRunning = PR_FALSE;
//-------------------------------------------------------------------------
nsAppShell::nsAppShell()
{
PR_LOG(QtWidgetsLM,
PR_LOG_DEBUG,
("nsAppShell::nsAppShell()\n"));
NS_INIT_REFCNT();
mDispatchListener = 0;
mEventQueue = nsnull;
mApplication = nsnull;
NS_INIT_REFCNT();
mDispatchListener = 0;
mEventQueue = nsnull;
mApplication = nsnull;
#ifdef DBG_JCG
gAppShellCount++;
mID = gAppShellID++;
printf("JCG: nsAppShell CTOR (%p) ID: %d, Count: %d\n",this,mID,gAppShellCount);
#endif
}
//-------------------------------------------------------------------------
@ -65,11 +70,14 @@ nsAppShell::nsAppShell()
//-------------------------------------------------------------------------
nsAppShell::~nsAppShell()
{
PR_LOG(QtWidgetsLM,
PR_LOG_DEBUG,
("nsAppShell::~nsAppShell()\n"));
mApplication->Release();
mApplication = nsnull;
if (mApplication) {
mApplication->Release();
}
mApplication = nsnull;
#ifdef DBG_JCG
gAppShellCount--;
printf("JCG: nsAppShell DTOR (%p) ID: %d, Count: %d\n",this,mID,gAppShellCount);
#endif
}
//-------------------------------------------------------------------------
@ -83,11 +91,8 @@ NS_IMPL_ISUPPORTS1(nsAppShell, nsIAppShell)
NS_METHOD
nsAppShell::SetDispatchListener(nsDispatchListener* aDispatchListener)
{
PR_LOG(QtWidgetsLM,
PR_LOG_DEBUG,
("nsAppShell::SetDispatchListener()\n"));
mDispatchListener = aDispatchListener;
return NS_OK;
mDispatchListener = aDispatchListener;
return NS_OK;
}
//-------------------------------------------------------------------------
@ -98,53 +103,26 @@ nsAppShell::SetDispatchListener(nsDispatchListener* aDispatchListener)
NS_METHOD nsAppShell::Create(int *bac, char **bav)
{
PR_LOG(QtWidgetsLM,
PR_LOG_DEBUG,
("nsAppShell::Create()\n"));
int argc = bac ? *bac : 0;
char **argv = bav;
nsresult rv;
int argc = bac ? *bac : 0;
char ** argv = bav;
nsresult rv = NS_OK;
Display * aDisplay = nsnull;
Screen * aScreen = nsnull;
// Open the display
aDisplay = XOpenDisplay(NULL);
if (aDisplay == NULL) {
fprintf(stderr, "%s: Cannot connect to X server\n",argv[0]);
exit(1);
nsCOMPtr<nsICmdLineService> cmdLineArgs = do_GetService(kCmdLineServiceCID);
if (cmdLineArgs) {
rv = cmdLineArgs->GetArgc(&argc);
if (NS_FAILED(rv)) {
argc = bac ? *bac : 0;
}
aScreen = DefaultScreenOfDisplay(aDisplay);
nsCOMPtr<nsICmdLineService> cmdLineArgs = do_GetService(kCmdLineServiceCID);
if (cmdLineArgs) {
rv = cmdLineArgs->GetArgc(&argc);
if(NS_FAILED(rv)) {
argc = bac ? *bac : 0;
}
rv = cmdLineArgs->GetArgv(&argv);
if(NS_FAILED(rv)) {
argv = bav;
}
rv = cmdLineArgs->GetArgv(&argv);
if (NS_FAILED(rv)) {
argv = bav;
}
if (aDisplay && aScreen) {
mApplication = nsQApplication::Instance(aDisplay);
}
else {
mApplication = nsQApplication::Instance(argc, argv);
}
if (!mApplication) {
return NS_ERROR_NOT_INITIALIZED;
}
mApplication->setStyle(new QWindowsStyle);
return NS_OK;
}
mApplication = nsQApplication::Instance(argc,argv);
if (!mApplication) {
return NS_ERROR_NOT_INITIALIZED;
}
return NS_OK;
}
//-------------------------------------------------------------------------
@ -154,39 +132,39 @@ NS_METHOD nsAppShell::Create(int *bac, char **bav)
//-------------------------------------------------------------------------
NS_METHOD nsAppShell::Spinup()
{
PR_LOG(QtWidgetsLM,
PR_LOG_DEBUG,
("nsAppShell::Spinup()\n"));
nsresult rv = NS_OK;
nsresult rv = NS_OK;
// Get the event queue service
nsCOMPtr<nsIEventQueueService> eventQService = do_GetService(kEventQueueServiceCID, &rv);
if (NS_FAILED(rv)) {
NS_ASSERTION("Could not obtain event queue service", PR_FALSE);
return rv;
}
//Get the event queue for the thread.
rv = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, getter_AddRefs(mEventQueue));
if (mApplication == nsnull)
return NS_ERROR_NOT_INITIALIZED;
// If a queue already present use it.
if (mEventQueue) {
goto done;
}
// Create the event queue for the thread
rv = eventQService->CreateThreadEventQueue();
if (NS_OK != rv) {
NS_ASSERTION("Could not create the thread event queue", PR_FALSE);
return rv;
}
//Get the event queue for the thread
rv = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, getter_AddRefs(mEventQueue));
if (NS_OK != rv) {
NS_ASSERTION("Could not obtain the thread event queue", PR_FALSE);
return rv;
}
// Get the event queue service
nsCOMPtr<nsIEventQueueService> eventQService = do_GetService(kEventQueueServiceCID,&rv);
if (NS_FAILED(rv)) {
NS_ASSERTION("Could not obtain event queue service",PR_FALSE);
return rv;
}
//Get the event queue for the thread.
rv = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD,getter_AddRefs(mEventQueue));
// If a queue already present use it.
if (mEventQueue) {
goto done;
}
// Create the event queue for the thread
rv = eventQService->CreateThreadEventQueue();
if (NS_FAILED(rv)) {
NS_ASSERTION("Could not create the thread event queue",PR_FALSE);
return rv;
}
//Get the event queue for the thread
rv = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD,getter_AddRefs(mEventQueue));
if (NS_FAILED(rv)) {
NS_ASSERTION("Could not obtain the thread event queue",PR_FALSE);
return rv;
}
done:
mApplication->AddEventProcessorCallback(mEventQueue);
return NS_OK;
mApplication->AddEventProcessorCallback(mEventQueue);
return NS_OK;
}
//-------------------------------------------------------------------------
@ -196,16 +174,15 @@ done:
//-------------------------------------------------------------------------
NS_METHOD nsAppShell::Spindown()
{
PR_LOG(QtWidgetsLM,
PR_LOG_DEBUG,
("nsAppShell::Spindown()\n"));
if (mEventQueue) {
mApplication->RemoveEventProcessorCallback(mEventQueue);
mEventQueue = nsnull;
}
return NS_OK;
}
if (mApplication == nsnull)
return NS_ERROR_NOT_INITIALIZED;
if (mEventQueue) {
mApplication->RemoveEventProcessorCallback(mEventQueue);
mEventQueue = nsnull;
}
return NS_OK;
}
//-------------------------------------------------------------------------
//
@ -214,22 +191,21 @@ NS_METHOD nsAppShell::Spindown()
//-------------------------------------------------------------------------
NS_METHOD nsAppShell::Run()
{
PR_LOG(QtWidgetsLM,
PR_LOG_DEBUG,
("nsAppShell::Run()\n"));
if (mApplication == nsnull)
return NS_ERROR_NOT_INITIALIZED;
if (!mEventQueue)
Spinup();
if (!mEventQueue) {
Spinup();
}
if (!mEventQueue) {
return NS_ERROR_NOT_INITIALIZED;
}
mRunning = PR_TRUE;
mApplication->exec();
mRunning = PR_FALSE;
if (!mEventQueue)
return NS_ERROR_NOT_INITIALIZED;
mRunning = PR_TRUE;
mApplication->exec();
mRunning = PR_FALSE;
Spindown();
return NS_OK;
Spindown();
return NS_OK;
}
//-------------------------------------------------------------------------
@ -240,36 +216,31 @@ NS_METHOD nsAppShell::Run()
NS_METHOD nsAppShell::Exit()
{
PR_LOG(QtWidgetsLM,
PR_LOG_DEBUG,
("nsAppShell::Exit()\n"));
if (mRunning)
mApplication->exit(0);
if (mApplication == nsnull)
return NS_ERROR_NOT_INITIALIZED;
return NS_OK;
if (mRunning)
mApplication->exit(0);
return NS_OK;
}
NS_METHOD nsAppShell::GetNativeEvent(PRBool &aRealEvent, void *& aEvent)
{
PR_LOG(QtWidgetsLM,
PR_LOG_DEBUG,
("nsAppShell::GetNativeEvent()\n"));
aRealEvent = PR_FALSE;
aEvent = 0;
return NS_OK;
aRealEvent = PR_FALSE;
aEvent = 0;
return NS_OK;
}
NS_METHOD nsAppShell::DispatchNativeEvent(PRBool aRealEvent, void *aEvent)
{
PR_LOG(QtWidgetsLM,
PR_LOG_DEBUG,
("nsAppShell::DispatchNativeEvent()\n"));
if (!mRunning)
return NS_ERROR_NOT_INITIALIZED;
if (mApplication == nsnull)
return NS_ERROR_NOT_INITIALIZED;
mApplication->processEvents();
if (!mRunning)
return NS_ERROR_NOT_INITIALIZED;
return NS_OK;
mApplication->processEvents(1);
return NS_OK;
}
NS_IMETHODIMP nsAppShell::ListenToEventQueue(nsIEventQueue *aQueue,

View File

@ -18,21 +18,17 @@
* Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
*
*/
#ifndef nsAppShell_h__
#define nsAppShell_h__
#include "nsIAppShell.h"
#include "nsIEventQueue.h"
#include "nsQApplication.h"
#include <qwindowsstyle.h>
/**
* Native QT Application shell wrapper
*/
/* Native QT Application shell wrapper */
class nsAppShell : public nsIAppShell
{
public:
@ -47,8 +43,8 @@ private:
nsDispatchListener *mDispatchListener;
nsCOMPtr<nsIEventQueue> mEventQueue;
nsQApplication *mApplication;
PRInt32 mID;
static PRBool mRunning;
};
#endif // nsAppShell_h__

View File

@ -18,39 +18,49 @@
* Rights Reserved.
*
* Contributor(s):
* Denis Issoupov <denis@macadamian.com>
* John C. Griggs <johng@corel.com>
*
*/
#ifdef NDEBUG
#define NO_DEBUG
#endif
#include "nsClipboard.h"
// XXXX #include "nsDataObj.h"
#include "nsMime.h"
#include "nsCOMPtr.h"
#include "nsCRT.h"
#include "nsString.h"
#include "nsISupportsArray.h"
#include "nsIClipboardOwner.h"
#include "nsITransferable.h"
#include "nsIWidget.h"
#include "nsISupportsPrimitives.h"
#include "nsXPIDLString.h"
#include "nsPrimitiveHelpers.h"
#include "nsIComponentManager.h"
#include "nsWidgetsCID.h"
#include "nsWidget.h"
#include <qapplication.h>
// XXXX #include "DDCOMM.h"
#include <qapplication.h>
#include <qclipboard.h>
#include <qdragobject.h>
// interface definitions
static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID);
static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID);
NS_IMPL_ADDREF_INHERITED(nsClipboard, nsBaseClipboard)
NS_IMPL_RELEASE_INHERITED(nsClipboard, nsBaseClipboard)
NS_IMPL_ISUPPORTS1(nsClipboard, nsIClipboard);
//-------------------------------------------------------------------------
//
// nsClipboard constructor
//
//-------------------------------------------------------------------------
nsClipboard::nsClipboard() : nsBaseClipboard()
nsClipboard::nsClipboard()
{
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsClipboard::nsClipboard()\n"));
mIgnoreEmptyNotification = PR_FALSE;
mWindow = nsnull;
NS_INIT_REFCNT();
mIgnoreEmptyNotification = PR_FALSE;
mGlobalTransferable = nsnull;
mSelectionTransferable = nsnull;
mGlobalOwner = nsnull;
mSelectionOwner = nsnull;
}
//-------------------------------------------------------------------------
@ -60,89 +70,267 @@ nsClipboard::nsClipboard() : nsBaseClipboard()
//-------------------------------------------------------------------------
nsClipboard::~nsClipboard()
{
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsClipboard::~nsClipboard()\n"));
NS_IF_RELEASE(mWindow);
}
/**
* @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 nsClipboard::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsClipboard::QueryInterface()\n"));
if (NULL == aInstancePtr)
{
return NS_ERROR_NULL_POINTER;
}
nsresult rv = NS_NOINTERFACE;
static NS_DEFINE_IID(kIClipboard, NS_ICLIPBOARD_IID);
if (aIID.Equals(kIClipboard))
{
*aInstancePtr = (void*) ((nsIClipboard*)this);
NS_ADDREF_THIS();
return NS_OK;
}
return rv;
}
/**
*
*
*/
NS_IMETHODIMP nsClipboard::SetNativeClipboardData(PRInt32 aWhichClipboard)
{
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsClipboard::SetNativeClipboardData()\n"));
mIgnoreEmptyNotification = PR_TRUE;
mIgnoreEmptyNotification = PR_TRUE;
nsCOMPtr<nsITransferable> transferable(getter_AddRefs(GetTransferable(aWhichClipboard)));
// make sure we have a good transferable
if (nsnull == mTransferable)
{
return NS_ERROR_FAILURE;
}
if (nsnull == transferable) {
#ifdef NS_DEBUG
printf("nsClipboard::SetNativeClipboardData(): no transferable!\n");
#endif
return NS_ERROR_FAILURE;
}
// get flavor list that includes all flavors that can be written (including
// ones obtained through conversion)
nsCOMPtr<nsISupportsArray> flavorList;
nsresult errCode = transferable->FlavorsTransferableCanExport(getter_AddRefs(flavorList));
if (NS_FAILED(errCode)) {
#ifdef NS_DEBUG
printf("nsClipboard::SetNativeClipboardData(): no FlavorsTransferable !\n");
#endif
return NS_ERROR_FAILURE;
}
QClipboard *cb = QApplication::clipboard();
nsMimeStore* mimeStore = new nsMimeStore();
PRUint32 cnt;
return NS_OK;
flavorList->Count(&cnt);
for (PRUint32 i = 0; i < cnt; ++i) {
nsCOMPtr<nsISupports> genericFlavor;
flavorList->GetElementAt(i,getter_AddRefs(genericFlavor));
nsCOMPtr<nsISupportsString> currentFlavor(do_QueryInterface(genericFlavor));
if (currentFlavor) {
nsXPIDLCString flavorStr;
currentFlavor->ToString(getter_Copies(flavorStr));
// add these types as selection targets
PRUint32 len;
void* data;
nsCOMPtr<nsISupports> clip;
transferable->GetTransferData(flavorStr,getter_AddRefs(clip),&len);
nsPrimitiveHelpers::CreateDataFromPrimitive(flavorStr,clip,&data,len);
mimeStore->AddFlavorData(flavorStr,data,len);
}
}
cb->setData(mimeStore);
mIgnoreEmptyNotification = PR_FALSE;
return NS_OK;
}
/**
*
*
*/
NS_IMETHODIMP
nsClipboard::GetNativeClipboardData(nsITransferable * aTransferable, PRInt32 aWhichClipboard)
nsClipboard::GetNativeClipboardData(nsITransferable *aTransferable,
PRInt32 aWhichClipboard)
{
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsClipboard::GetNativeClipboardData()\n"));
// make sure we have a good transferable
if (nsnull == aTransferable)
{
return NS_ERROR_FAILURE;
}
// make sure we have a good transferable
if (nsnull == aTransferable) {
#ifdef NS_DEBUG
printf(" GetNativeClipboardData: Transferable is null!\n");
#endif
return NS_ERROR_FAILURE;
}
// get flavor list that includes all acceptable flavors (including
// ones obtained through conversion)
nsCOMPtr<nsISupportsArray> flavorList;
nsresult errCode = aTransferable->FlavorsTransferableCanImport(getter_AddRefs(flavorList));
return NS_OK;
if (NS_FAILED(errCode)) {
#ifdef NS_DEBUG
printf("nsClipboard::GetNativeClipboardData(): no FlavorsTransferable %i !\n",
errCode);
#endif
return NS_ERROR_FAILURE;
}
QClipboard *cb = QApplication::clipboard();
QMimeSource *ms = cb->data();
// Walk through flavors and see which flavor matches the one being pasted:
PRUint32 cnt;
flavorList->Count(&cnt);
nsCAutoString foundFlavor;
for (PRUint32 i = 0; i < cnt; ++i) {
nsCOMPtr<nsISupports> genericFlavor;
flavorList->GetElementAt(i,getter_AddRefs(genericFlavor));
nsCOMPtr<nsISupportsString> currentFlavor(do_QueryInterface(genericFlavor));
if (currentFlavor) {
nsXPIDLCString flavorStr;
currentFlavor->ToString(getter_Copies(flavorStr));
foundFlavor = nsCAutoString(flavorStr);
if (ms->provides((const char*)flavorStr)) {
QByteArray ba = ms->encodedData((const char*)flavorStr);
nsCOMPtr<nsISupports> genericDataWrapper;
PRUint32 len = (PRUint32)ba.count();
nsPrimitiveHelpers::CreatePrimitiveForData(foundFlavor,
(void*)ba.data(),len,
getter_AddRefs(genericDataWrapper));
aTransferable->SetTransferData(foundFlavor,genericDataWrapper,len);
}
}
}
return NS_OK;
}
/**
*
*
*/
NS_IMETHODIMP nsClipboard::ForceDataToClipboard(PRInt32 aWhichClipboard)
{
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsClipboard::ForceDataToClipboard()\n"));
// make sure we have a good transferable
if (nsnull == mTransferable)
{
return NS_ERROR_FAILURE;
}
return NS_OK;
// make sure we have a good transferable
nsCOMPtr<nsITransferable> transferable(getter_AddRefs(GetTransferable(aWhichClipboard)));
if (nsnull == transferable) {
return NS_ERROR_FAILURE;
}
return NS_OK;
}
/* inline */
nsITransferable *nsClipboard::GetTransferable(PRInt32 aWhichClipboard)
{
nsITransferable *transferable = nsnull;
switch (aWhichClipboard) {
case kGlobalClipboard:
transferable = mGlobalTransferable;
break;
case kSelectionClipboard:
transferable = mSelectionTransferable;
break;
}
NS_IF_ADDREF(transferable);
return transferable;
}
//-------------------------------------------------------------------------
NS_IMETHODIMP nsClipboard::HasDataMatchingFlavors(nsISupportsArray *aFlavorList,
PRInt32 aWhichClipboard,
PRBool *_retval)
{
*_retval = PR_FALSE;
if (aWhichClipboard != kGlobalClipboard)
return NS_OK;
QClipboard *cb = QApplication::clipboard();
QMimeSource *ms = cb->data();
PRUint32 cnt;
aFlavorList->Count(&cnt);
for (PRUint32 i = 0;i < cnt; ++i) {
nsCOMPtr<nsISupports> genericFlavor;
aFlavorList->GetElementAt(i,getter_AddRefs(genericFlavor));
nsCOMPtr<nsISupportsString> currentFlavor(do_QueryInterface(genericFlavor));
if (currentFlavor) {
nsXPIDLCString flavorStr;
currentFlavor->ToString(getter_Copies(flavorStr));
#ifdef NS_DEBUG
if (strcmp(flavorStr,kTextMime) == 0)
NS_WARNING("DO NOT USE THE text/plain DATA FLAVOR ANY MORE. USE text/unicode INSTEAD");
#endif
if (ms->provides((const char*)flavorStr)) {
*_retval = PR_TRUE;
#ifdef NS_DEBUG
printf("GetFormat %s\n",(const char*)flavorStr);
#endif
break;
}
}
}
return NS_OK;
}
/**
* Sets the transferable object
*/
NS_IMETHODIMP nsClipboard::SetData(nsITransferable *aTransferable,
nsIClipboardOwner *anOwner,
PRInt32 aWhichClipboard)
{
if ((aTransferable == mGlobalTransferable.get()
&& anOwner == mGlobalOwner.get()
&& aWhichClipboard == kGlobalClipboard)
|| (aTransferable == mSelectionTransferable.get()
&& anOwner == mSelectionOwner.get()
&& aWhichClipboard == kSelectionClipboard)) {
return NS_OK;
}
EmptyClipboard(aWhichClipboard);
switch (aWhichClipboard) {
case kSelectionClipboard:
mSelectionOwner = anOwner;
mSelectionTransferable = aTransferable;
break;
case kGlobalClipboard:
mGlobalOwner = anOwner;
mGlobalTransferable = aTransferable;
break;
}
QApplication::clipboard()->clear();
return SetNativeClipboardData(aWhichClipboard);
}
/**
* Gets the transferable object
*/
NS_IMETHODIMP nsClipboard::GetData(nsITransferable *aTransferable,PRInt32 aWhichClipboard)
{
if (nsnull != aTransferable) {
return GetNativeClipboardData(aTransferable,aWhichClipboard);
#ifdef NS_DEBUG
} else {
printf(" nsClipboard::GetData(), aTransferable is NULL.\n");
#endif
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsClipboard::EmptyClipboard(PRInt32 aWhichClipboard)
{
if (mIgnoreEmptyNotification) {
return NS_OK;
}
switch(aWhichClipboard) {
case kSelectionClipboard:
if (mSelectionOwner) {
mSelectionOwner->LosingOwnership(mSelectionTransferable);
mSelectionOwner = nsnull;
}
mSelectionTransferable = nsnull;
break;
case kGlobalClipboard:
if (mGlobalOwner) {
mGlobalOwner->LosingOwnership(mGlobalTransferable);
mGlobalOwner = nsnull;
}
mGlobalTransferable = nsnull;
break;
}
return NS_OK;
}
NS_IMETHODIMP nsClipboard::SupportsSelectionClipboard(PRBool *_retval)
{
*_retval = PR_TRUE; // we support the selection clipboard by default.
return NS_OK;
}

View File

@ -18,44 +18,47 @@
* Rights Reserved.
*
* Contributor(s):
* Denis Issoupov <denis@macadamian.com>
*
*/
#ifndef nsClipboard_h__
#define nsClipboard_h__
#include "nsBaseClipboard.h"
#include "nsIClipboard.h"
#include "nsITransferable.h"
#include "nsIClipboardOwner.h"
#include "nsCOMPtr.h"
class nsITransferable;
class nsIClipboardOwner;
class nsIWidget;
#include <qlist.h>
#include <qcstring.h>
#include <qmime.h>
/**
* Native QT Clipboard wrapper
*/
class nsClipboard : public nsBaseClipboard
/* Native QT Clipboard wrapper */
class nsClipboard : public nsIClipboard
{
public:
nsClipboard();
virtual ~nsClipboard();
//nsISupports
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_ISUPPORTS
// nsIClipboard
NS_IMETHOD ForceDataToClipboard(PRInt32 aWhichClipboard);
NS_DECL_NSICLIPBOARD
protected:
NS_IMETHOD SetNativeClipboardData(PRInt32 aWhichClipboard);
NS_IMETHOD GetNativeClipboardData(nsITransferable * aTransferable, PRInt32 aWhichClipboard);
NS_IMETHOD GetNativeClipboardData(nsITransferable *aTransferable,
PRInt32 aWhichClipboard);
inline nsITransferable *GetTransferable(PRInt32 aWhichClipboard);
PRBool mIgnoreEmptyNotification;
nsIClipboardOwner * mClipboardOwner;
nsITransferable * mTransferable;
nsIWidget * mWindow;
nsCOMPtr<nsIClipboardOwner> mSelectionOwner;
nsCOMPtr<nsIClipboardOwner> mGlobalOwner;
nsCOMPtr<nsITransferable> mSelectionTransferable;
nsCOMPtr<nsITransferable> mGlobalTransferable;
};
#endif // nsClipboard_h__

View File

@ -27,7 +27,7 @@
#include "nsStringUtil.h"
#include "nsIDeviceContext.h"
//JCG #define DBG 0
#define DBG 0
#define INITIAL_MAX_ITEMS 128
#define ITEMS_GROWSIZE 128

View File

@ -19,27 +19,35 @@
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
* Denis Issoupov <denis@macadamian.com>
* John C. Griggs <johng@corel.com>
*
*/
#ifdef NDEBUG
#define NO_DEBUG
#endif
#include "nsDragService.h"
#include "nsITransferable.h"
#include "nsIServiceManager.h"
#include "nsISupportsPrimitives.h"
#include "nsCOMPtr.h"
#include "nsXPIDLString.h"
#include "nsPrimitiveHelpers.h"
#include "nsMime.h"
#include "nsWidgetsCID.h"
static NS_DEFINE_IID(kIDragServiceIID, NS_IDRAGSERVICE_IID);
static NS_DEFINE_IID(kIDragSessionQtIID, NS_IDRAGSESSIONQT_IID);
static NS_DEFINE_CID(kCDragServiceCID, NS_DRAGSERVICE_CID);
// The class statics:
//GtkWidget* nsDragService::sWidget = 0;
NS_IMPL_ADDREF_INHERITED(nsDragService, nsBaseDragService)
NS_IMPL_RELEASE_INHERITED(nsDragService, nsBaseDragService)
NS_IMPL_QUERY_INTERFACE3(nsDragService, nsIDragService, nsIDragSession, nsIDragSessionQt )
//-------------------------------------------------------------------------
// static variables
//-------------------------------------------------------------------------
//static PRBool gHaveDrag = PR_FALSE;
static PRBool gHaveDrag = PR_FALSE;
//-------------------------------------------------------------------------
//
@ -48,7 +56,10 @@ NS_IMPL_RELEASE_INHERITED(nsDragService, nsBaseDragService)
//-------------------------------------------------------------------------
nsDragService::nsDragService()
{
NS_INIT_REFCNT();
NS_INIT_REFCNT();
// our hidden source widget
mHiddenWidget = new QWidget(0,QWidget::tr("DragDrop"),0);
}
//-------------------------------------------------------------------------
@ -58,139 +69,217 @@ nsDragService::nsDragService()
//-------------------------------------------------------------------------
nsDragService::~nsDragService()
{
}
/**
* @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 nsDragService::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
if (NULL == aInstancePtr)
{
return NS_ERROR_NULL_POINTER;
}
nsresult rv = NS_NOINTERFACE;
if (aIID.Equals(NS_GET_IID(nsIDragService)))
{
*aInstancePtr = (void*) ((nsIDragService*)this);
NS_ADDREF_THIS();
return NS_OK;
}
return rv;
delete mHiddenWidget;
}
//---------------------------------------------------------
NS_IMETHODIMP nsDragService::StartDragSession(nsITransferable * aTransferable,
PRUint32 aActionType)
NS_IMETHODIMP
nsDragService::InvokeDragSession(nsIDOMNode *aDOMNode,
nsISupportsArray *aArrayTransferables,
nsIScriptableRegion *aRegion,
PRUint32 aActionType)
{
return NS_OK;
PRUint32 numItemsToDrag = 0;
nsBaseDragService::InvokeDragSession(aDOMNode, aArrayTransferables,
aRegion, aActionType);
// make sure that we have an array of transferables to use
if (!aArrayTransferables) {
return NS_ERROR_INVALID_ARG;
}
// set our reference to the transferables. this will also addref
// the transferables since we're going to hang onto this beyond the
// length of this call
mSourceDataItems = aArrayTransferables;
mSourceDataItems->Count(&numItemsToDrag);
if (!numItemsToDrag) {
return NS_ERROR_FAILURE;
}
if (numItemsToDrag > 1) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsISupports> genericItem;
mSourceDataItems->GetElementAt(0,getter_AddRefs(genericItem));
nsCOMPtr<nsITransferable> transferable(do_QueryInterface(genericItem));
mDragObject = RegisterDragFlavors(transferable);
gHaveDrag = PR_TRUE;
if (aActionType == DRAGDROP_ACTION_MOVE)
mDragObject->dragMove();
else
mDragObject->dragCopy();
gHaveDrag = PR_FALSE;
mDragObject = 0;
return NS_OK;
}
#if 0 //JCG
//-------------------------------------------------------------------------
NS_IMETHODIMP nsDragService::GetData(nsITransferable * aTransferable,
QDragObject *nsDragService::RegisterDragFlavors(nsITransferable *transferable)
{
nsMimeStore *pMimeStore = new nsMimeStore();
nsCOMPtr<nsISupportsArray> flavorList;
if (NS_SUCCEEDED(transferable->FlavorsTransferableCanExport(getter_AddRefs(flavorList)))) {
PRUint32 numFlavors;
flavorList->Count(&numFlavors);
for (PRUint32 flavorIndex = 0; flavorIndex < numFlavors; ++flavorIndex) {
nsCOMPtr<nsISupports> genericWrapper;
flavorList->GetElementAt(flavorIndex,getter_AddRefs(genericWrapper));
nsCOMPtr<nsISupportsString> currentFlavor(do_QueryInterface(genericWrapper));
if (currentFlavor) {
nsXPIDLCString flavorStr;
currentFlavor->ToString(getter_Copies(flavorStr));
PRUint32 len;
void* data;
nsCOMPtr<nsISupports> clip;
transferable->GetTransferData(flavorStr,getter_AddRefs(clip),&len);
nsPrimitiveHelpers::CreateDataFromPrimitive(flavorStr,clip,&data,len);
pMimeStore->AddFlavorData(flavorStr,data,len);
}
} // foreach flavor in item
} // if valid flavor list
#ifdef NS_DEBUG
else
printf(" DnD ERROR: cannot export any flavor\n");
#endif
return new nsDragObject(pMimeStore,mHiddenWidget);
} // RegisterDragItemsAndFlavors
NS_IMETHODIMP nsDragService::StartDragSession()
{
#ifdef NS_DEBUG
printf(" DnD: StartDragSession\n");
#endif
return nsBaseDragService::StartDragSession();
}
NS_IMETHODIMP nsDragService::EndDragSession()
{
#ifdef NS_DEBUG
printf(" DnD: EndDragSession\n");
#endif
mDragObject = 0;
return nsBaseDragService::EndDragSession();
}
// nsIDragSession
NS_IMETHODIMP nsDragService::SetCanDrop(PRBool aCanDrop)
{
mCanDrop = aCanDrop;
return NS_OK;
}
NS_IMETHODIMP nsDragService::GetCanDrop(PRBool *aCanDrop)
{
*aCanDrop = mCanDrop;
return NS_OK;
}
NS_IMETHODIMP nsDragService::GetNumDropItems(PRUint32 *aNumItems)
{
*aNumItems = 1;
return NS_OK;
}
NS_IMETHODIMP nsDragService::GetData(nsITransferable *aTransferable,
PRUint32 aItemIndex)
{
return NS_ERROR_FAILURE;
}
// make sure that we have a transferable
if (!aTransferable)
return NS_ERROR_INVALID_ARG;
//-------------------------------------------------------------------------
void nsDragService::SetTopLevelWidget(QWidget* w)
{
printf(" nsDragService::SetTopLevelWidget\n");
// Don't set up any more event handlers if we're being called twice
// for the same toplevel widget
if (sWidget == w)
return;
nsresult rv = NS_ERROR_FAILURE;
nsCOMPtr<nsISupportsArray> flavorList;
sWidget = w;
rv = aTransferable->FlavorsTransferableCanImport(getter_AddRefs(flavorList));
if (NS_FAILED(rv))
return rv;
// Get the DragService from the service manager.
nsresult rv;
NS_WITH_SERVICE(nsIDragService, dragService, kCDragServiceCID, &rv);
// count the number of flavors
PRUint32 cnt;
if (NS_FAILED(rv))
{
return;
flavorList->Count(&cnt);
// Now walk down the list of flavors. When we find one that is
// actually present, copy out the data into the transferable in that
// format. SetTransferData() implicitly handles conversions.
for (unsigned int i = 0; i < cnt; ++i) {
nsCAutoString foundFlavor;
nsCOMPtr<nsISupports> genericWrapper;
flavorList->GetElementAt(i,getter_AddRefs(genericWrapper));
nsCOMPtr<nsISupportsString> currentFlavor;
currentFlavor = do_QueryInterface(genericWrapper);
if (currentFlavor) {
nsXPIDLCString flavorStr;
currentFlavor->ToString(getter_Copies(flavorStr));
foundFlavor = nsCAutoString(flavorStr);
if (mDragObject && mDragObject->provides(flavorStr)) {
QByteArray ba = mDragObject->encodedData((const char*)flavorStr);
nsCOMPtr<nsISupports> genericDataWrapper;
PRUint32 len = (PRUint32)ba.count();
nsPrimitiveHelpers::CreatePrimitiveForData(foundFlavor,
(void*)ba.data(),len,
getter_AddRefs(genericDataWrapper));
aTransferable->SetTransferData(foundFlavor,genericDataWrapper,len);
}
}
// We're done with our reference to the dragService.
//NS_IF_RELEASE(dragService);
}
return NS_OK;
}
//-------------------------------------------------------------------------
void
nsDragService::DragLeave(QWidget *widget,
QDragContext *context,
unsigned int time)
NS_IMETHODIMP nsDragService::IsDataFlavorSupported(const char *aDataFlavor,
PRBool *_retval)
{
printf("leave\n");
if (!_retval)
return NS_ERROR_INVALID_ARG;
*_retval = PR_FALSE;
if (mDragObject)
*_retval = mDragObject->provides(aDataFlavor);
#ifdef NS_DEBUG
if (!*_retval)
printf("nsDragService::IsDataFlavorSupported not provides [%s] \n", aDataFlavor);
#endif
return NS_OK;
}
//-------------------------------------------------------------------------
PRBool
nsDragService::DragMotion(QWidget *widget,
QDragContext *context,
int x,
int y,
unsigned int time)
NS_IMETHODIMP nsDragService::SetDragReference(QMimeSource* aDragRef)
{
printf("drag motion\n");
return PR_TRUE;
}
nsMimeStore* pMimeStore = new nsMimeStore();
int c = 0;
const char* format;
//-------------------------------------------------------------------------
PRBool
nsDragService::DragDrop(QWidget *widget,
QDragContext *context,
int x,
int y,
unsigned int time)
{
printf("drop\n");
return PR_FALSE;
}
while ((format = aDragRef->format(c++)) != 0) {
// this is usualy between different processes
// so, we need to copy datafrom one to onother
//-------------------------------------------------------------------------
void
nsDragService::DragDataReceived(QWidget *widget,
QDragContext *context,
int x,
int y,
QSelectionData *data,
unsigned int info,
guint time)
{
printf("Data Received!\n");
QByteArray ba = aDragRef->encodedData(format);
char *data = new char[ba.size()];
memcpy(data,ba.data(),ba.size());
pMimeStore->AddFlavorData(format,data,ba.size());
}
mDragObject = new nsDragObject(pMimeStore,mHiddenWidget);
return NS_OK;
}
//-------------------------------------------------------------------------
void
nsDragService::DragDataGet(QWidget *widget,
QDragContext *context,
QSelectionData *selection_data,
unsigned int info,
unsigned int time,
void *data)
{
printf("Get the data!\n");
}
//-------------------------------------------------------------------------
void
nsDragService::DragDataDelete(QWidget *widget,
QDragContext *context,
void *data)
{
printf("Delete the data!\n");
}
#endif /* JCG */

View File

@ -18,79 +18,58 @@
* Rights Reserved.
*
* Contributor(s):
* Denis Issoupov <denis@macadamian.com>
*
*/
#ifndef nsDragService_h__
#define nsDragService_h__
#include "nsBaseDragService.h"
#include "nsClipboard.h"
#include "nsIDragSessionQt.h"
#include <qwidget.h>
#include <qdragobject.h>
/**
* Native QT DragService wrapper
*/
class nsDragService : public nsBaseDragService
//----------------------------------------------------------
/* Native Qt DragService wrapper */
class nsDragService : public nsBaseDragService, public nsIDragSessionQt
{
public:
nsDragService();
virtual ~nsDragService();
nsDragService();
virtual ~nsDragService();
//nsISupports
NS_DECL_ISUPPORTS_INHERITED
//nsISupports
NS_DECL_ISUPPORTS_INHERITED
//nsIDragService
NS_IMETHOD StartDragSession (nsITransferable * aTransferable,
PRUint32 aActionType);
NS_IMETHOD InvokeDragSession(nsIDOMNode *aDOMNode,
nsISupportsArray *anArrayTransferables,
nsIScriptableRegion *aRegion,
PRUint32 aActionType);
NS_IMETHOD StartDragSession();
NS_IMETHOD EndDragSession();
#if 0
// Native Impl.
NS_IMETHOD GetData (nsITransferable * aTransferable, PRUint32 aItemIndex);
// nsIDragSession
NS_IMETHOD SetCanDrop(PRBool aCanDrop);
NS_IMETHOD GetCanDrop(PRBool *aCanDrop);
NS_IMETHOD GetNumDropItems(PRUint32 *aNumItems);
NS_IMETHOD GetData(nsITransferable *aTransferable,PRUint32 aItemIndex);
NS_IMETHOD IsDataFlavorSupported(const char *aDataFlavor,PRBool *_retval);
static void SetTopLevelWidget(QWidget* w);
static Qwidget *sWidget;
// nsIDragSessionQt
NS_IMETHOD SetDragReference(QMimeSource* aDragRef);
protected:
static PRBool gHaveDrag;
QDragObject *RegisterDragFlavors(nsITransferable* transferable);
static void DragLeave(QWidget *widget,
QDragContext *context,
unsigned int time);
private:
// the source of our drags
QWidget *mHiddenWidget;
QDragObject *mDragObject;
static PRBool DragMotion(QWidget *widget,
QDragContext *context,
int x,
int y,
unsigned int time);
static PRBool DragDrop(QWidget *widget,
QDragContext *context,
int x,
int y,
unsigned int time);
static void DragDataReceived(QWidget *widget,
QDragContext *context,
int x,
int y,
QSelectionData *data,
unsigned int info,
unsigned int time);
static void DragDataGet(QWidget *widget,
QDragContext *context,
QSelectionData *selection_data,
unsigned int info,
unsigned int time,
void* data);
static void DragDataDelete(QWidget *widget,
QDragContext *context,
void* data);
#endif
// our source data items
nsCOMPtr<nsISupportsArray> mSourceDataItems;
};
#endif // nsDragService_h__

View File

@ -39,7 +39,8 @@ NS_IMPL_ISUPPORTS2(nsFontRetrieverService, nsIFontRetrieverService, nsIFontNameI
//----------------------------------------------------------
nsFontRetrieverService::nsFontRetrieverService()
{
printf("JCG: nsFontRetrieverService CTOR.\n");
printf("JCG nsFontRetrieverService CTOR\n");
NS_INIT_REFCNT();
mFontList = nsnull;
@ -50,7 +51,8 @@ printf("JCG: nsFontRetrieverService CTOR.\n");
//----------------------------------------------------------
nsFontRetrieverService::~nsFontRetrieverService()
{
printf("JCG: nsFontRetrieverService DTOR.\n");
printf("JCG nsFontRetrieverService DTOR\n");
if (nsnull != mFontList) {
for (PRInt32 i=0;i<mFontList->Count();i++) {
FontInfo * font = (FontInfo *)mFontList->ElementAt(i);
@ -131,10 +133,6 @@ NS_IMETHODIMP nsFontRetrieverService::Reset()
//----------------------------------------------------------
NS_IMETHODIMP nsFontRetrieverService::Get( nsString* aFontName )
{
char *tmp;
printf("JCG: nsFontRetrieverService::Get. FontName: %s\n",(tmp = aFontName->ToNewCString()));
nsMemory::Free((void*)tmp);
if (mNameIterInx < mFontList->Count()) {
FontInfo * fontInfo = (FontInfo *)mFontList->ElementAt(mNameIterInx);
*aFontName = fontInfo->mName;

View File

@ -33,6 +33,8 @@ NS_IMPL_QUERY_INTERFACE(nsFontSizeIterator, NS_GET_IID(nsIFontSizeIterator))
//----------------------------------------------------------
nsFontSizeIterator::nsFontSizeIterator()
{
printf("JCG nsFontSizeIterator CTOR\n");
NS_INIT_REFCNT();
mFontInfo = nsnull;
mSizeIterInx = 0;
@ -41,6 +43,8 @@ nsFontSizeIterator::nsFontSizeIterator()
//----------------------------------------------------------
nsFontSizeIterator::~nsFontSizeIterator()
{
printf("JCG nsFontSizeIterator DTOR\n");
}
///----------------------------------------------------------

View File

@ -0,0 +1,47 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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 Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Denis Issoupov <denis@macadamian.com>
*
*/
#ifndef nsIDragSessionQt_h__
#define nsIDragSessionQt_h__
#include "nsISupports.h"
#include <qdragobject.h>
#define NS_IDRAGSESSIONQT_IID \
{ 0x36c4c381, 0x09e3, 0x11d4, { 0xb0, 0x33, 0xa4, 0x20, 0xf4, 0x2c, 0xfd, 0x7c } };
class nsIDragSessionQt : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IDRAGSESSIONQT_IID)
/**
* Since the drag may originate in an external application, we need some
* way of communicating the QDragObject to the session so it can use it
* when filling in data requests.
*
*/
NS_IMETHOD SetDragReference(QMimeSource* aDragRef) = 0;
};
#endif

View File

@ -18,16 +18,18 @@
* Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
*
*/
#include "nsLookAndFeel.h"
#include "nsQApplication.h"
#include <qpalette.h>
#include "nsWidget.h"
#include "nsXPLookAndFeel.h"
#include <qpalette.h>
#define QCOLOR_TO_NS_RGB(c) \
((nscolor)NS_RGB(c.red(),c.green(),c.blue()))
NS_IMPL_ISUPPORTS1(nsLookAndFeel, nsILookAndFeel)
//-------------------------------------------------------------------------
@ -37,312 +39,382 @@ NS_IMPL_ISUPPORTS1(nsLookAndFeel, nsILookAndFeel)
//-------------------------------------------------------------------------
nsLookAndFeel::nsLookAndFeel()
{
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsLookAndFeel::nsLookAndFeel()\n"));
NS_INIT_REFCNT();
(void)NS_NewXPLookAndFeel(getter_AddRefs(mXPLookAndFeel));
NS_INIT_REFCNT();
NS_NewXPLookAndFeel(getter_AddRefs(mXPLookAndFeel));
}
nsLookAndFeel::~nsLookAndFeel()
{
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsLookAndFeel::~nsLookAndFeel()\n"));
}
NS_IMETHODIMP nsLookAndFeel::GetColor(const nsColorID aID, nscolor &aColor)
NS_IMETHODIMP nsLookAndFeel::GetColor(const nsColorID aID,nscolor &aColor)
{
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsLookAndFeel::GetColor()\n"));
nsresult res = NS_OK;
nsresult res = NS_OK;
if (mXPLookAndFeel)
{
res = mXPLookAndFeel->GetColor(aID, aColor);
if (NS_SUCCEEDED(res))
return res;
res = NS_OK;
if (mXPLookAndFeel) {
res = mXPLookAndFeel->GetColor(aID,aColor);
if (NS_SUCCEEDED(res)) {
return res;
}
res = NS_OK;
}
if (!qApp)
return NS_ERROR_FAILURE;
QPalette palette = qApp->palette();
QColorGroup normalGroup = palette.inactive();
QColorGroup activeGroup = palette.active();
QColorGroup disabledGroup = palette.disabled();
QPalette palette = qApp->palette();
QColorGroup normalGroup = palette.inactive();
QColorGroup activeGroup = palette.active();
QColorGroup disabledGroup = palette.disabled();
switch (aID)
{
switch (aID) {
case eColor_WindowBackground:
aColor = normalGroup.background().rgb();
break;
aColor = QCOLOR_TO_NS_RGB(normalGroup.background());
break;
case eColor_WindowForeground:
aColor = normalGroup.foreground().rgb();
break;
aColor = QCOLOR_TO_NS_RGB(normalGroup.foreground());
break;
case eColor_WidgetBackground:
aColor = normalGroup.background().rgb();
break;
aColor = QCOLOR_TO_NS_RGB(normalGroup.background());
break;
case eColor_WidgetForeground:
aColor = normalGroup.foreground().rgb();
break;
aColor = QCOLOR_TO_NS_RGB(normalGroup.foreground());
break;
case eColor_WidgetSelectBackground:
aColor = activeGroup.background().rgb();
break;
aColor = QCOLOR_TO_NS_RGB(activeGroup.background());
break;
case eColor_WidgetSelectForeground:
aColor = activeGroup.foreground().rgb();
break;
aColor = QCOLOR_TO_NS_RGB(activeGroup.foreground());
break;
case eColor_Widget3DHighlight:
aColor = normalGroup.highlight().rgb();
break;
aColor = NS_RGB(0xa0,0xa0,0xa0);
break;
case eColor_Widget3DShadow:
aColor = normalGroup.shadow().rgb();
break;
aColor = NS_RGB(0x40,0x40,0x40);
break;
case eColor_TextBackground:
aColor = normalGroup.background().rgb();
break;
aColor = QCOLOR_TO_NS_RGB(normalGroup.background());
break;
case eColor_TextForeground:
aColor = normalGroup.text().rgb();
break;
aColor = QCOLOR_TO_NS_RGB(normalGroup.text());
break;
case eColor_TextSelectBackground:
aColor = activeGroup.background().rgb();
break;
aColor = QCOLOR_TO_NS_RGB(activeGroup.highlight());
break;
case eColor_TextSelectForeground:
aColor = activeGroup.foreground().rgb();
break;
aColor = QCOLOR_TO_NS_RGB(activeGroup.highlightedText());
break;
case eColor_activeborder:
aColor = normalGroup.background().rgb();
break;
aColor = QCOLOR_TO_NS_RGB(normalGroup.background());
break;
case eColor_activecaption:
aColor = normalGroup.background().rgb();
break;
aColor = QCOLOR_TO_NS_RGB(normalGroup.background());
break;
case eColor_appworkspace:
aColor = normalGroup.background().rgb();
break;
aColor = QCOLOR_TO_NS_RGB(normalGroup.background());
break;
case eColor_background:
aColor = normalGroup.background().rgb();
break;
aColor = QCOLOR_TO_NS_RGB(normalGroup.background());
break;
case eColor_captiontext:
aColor = normalGroup.text().rgb();
break;
aColor = QCOLOR_TO_NS_RGB(normalGroup.text());
break;
case eColor_graytext:
aColor = disabledGroup.text().rgb();
break;
aColor = QCOLOR_TO_NS_RGB(disabledGroup.text());
break;
case eColor_highlight:
aColor = activeGroup.background().rgb();
break;
aColor = QCOLOR_TO_NS_RGB(activeGroup.highlight());
break;
case eColor_highlighttext:
aColor = activeGroup.text().rgb();
break;
aColor = QCOLOR_TO_NS_RGB(activeGroup.highlightedText());
break;
case eColor_inactiveborder:
aColor = normalGroup.background().rgb();
break;
aColor = QCOLOR_TO_NS_RGB(normalGroup.background());
break;
case eColor_inactivecaption:
aColor = disabledGroup.background().rgb();
break;
aColor = QCOLOR_TO_NS_RGB(disabledGroup.background());
break;
case eColor_inactivecaptiontext:
aColor = disabledGroup.text().rgb();
break;
aColor = QCOLOR_TO_NS_RGB(disabledGroup.text());
break;
case eColor_infobackground:
aColor = normalGroup.background().rgb();
break;
aColor = QCOLOR_TO_NS_RGB(normalGroup.background());
break;
case eColor_infotext:
aColor = normalGroup.text().rgb();
break;
aColor = QCOLOR_TO_NS_RGB(normalGroup.text());
break;
case eColor_menu:
aColor = normalGroup.background().rgb();
break;
aColor = QCOLOR_TO_NS_RGB(normalGroup.background());
break;
case eColor_menutext:
aColor = normalGroup.text().rgb();
break;
aColor = QCOLOR_TO_NS_RGB(normalGroup.text());
break;
case eColor_scrollbar:
aColor = normalGroup.background().rgb();
break;
aColor = QCOLOR_TO_NS_RGB(activeGroup.background());
break;
case eColor_threedface:
case eColor_buttonface:
aColor = normalGroup.background().rgb();
break;
aColor = QCOLOR_TO_NS_RGB(normalGroup.background());
break;
case eColor_buttonhighlight:
case eColor_threedhighlight:
aColor = normalGroup.light().rgb();
break;
aColor = QCOLOR_TO_NS_RGB(normalGroup.light());
break;
case eColor_buttontext:
aColor = normalGroup.text().rgb();
break;
aColor = QCOLOR_TO_NS_RGB(normalGroup.text());
break;
case eColor_buttonshadow:
case eColor_threeddarkshadow:
case eColor_threedshadow: // i think these should be the same
aColor = normalGroup.dark().rgb();
break;
aColor = QCOLOR_TO_NS_RGB(normalGroup.shadow());
break;
case eColor_threeddarkshadow:
aColor = QCOLOR_TO_NS_RGB(normalGroup.dark());
break;
case eColor_threedlightshadow:
aColor = normalGroup.light().rgb();
break;
aColor = QCOLOR_TO_NS_RGB(normalGroup.light());
break;
case eColor_window:
case eColor_windowframe:
aColor = normalGroup.background().rgb();
break;
aColor = QCOLOR_TO_NS_RGB(normalGroup.background());
break;
case eColor_windowtext:
aColor = normalGroup.text().rgb();
break;
aColor = QCOLOR_TO_NS_RGB(normalGroup.text());
break;
// from the CSS3 working draft (not yet finalized)
// http://www.w3.org/tr/2000/wd-css3-userint-20000216.html#color
case eColor__moz_field:
aColor = QCOLOR_TO_NS_RGB(normalGroup.base());
break;
case eColor__moz_dragtargetzone:
aColor = QCOLOR_TO_NS_RGB(activeGroup.background());
break;
default:
aColor = 0;
res = NS_ERROR_FAILURE;
break;
}
return res;
aColor = 0;
res = NS_ERROR_FAILURE;
break;
}
return res;
}
NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricID aID, PRInt32 & aMetric)
NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricID aID,PRInt32 &aMetric)
{
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsLookAndFeel::GetMetric()\n"));
nsresult res = NS_OK;
nsresult res = NS_OK;
if (mXPLookAndFeel)
{
res = mXPLookAndFeel->GetMetric(aID, aMetric);
if (NS_SUCCEEDED(res))
return res;
res = NS_OK;
}
switch (aID)
{
if (mXPLookAndFeel) {
res = mXPLookAndFeel->GetMetric(aID, aMetric);
if (NS_SUCCEEDED(res))
return res;
res = NS_OK;
}
switch (aID) {
case eMetric_WindowTitleHeight:
aMetric = 0;
break;
aMetric = 0;
break;
case eMetric_WindowBorderWidth:
break;
break;
case eMetric_WindowBorderHeight:
break;
break;
case eMetric_Widget3DBorder:
break;
break;
case eMetric_TextFieldHeight:
aMetric = 15;
break;
aMetric = 15;
break;
case eMetric_TextFieldBorder:
aMetric = 2;
break;
aMetric = 2;
break;
case eMetric_TextVerticalInsidePadding:
aMetric = 0;
break;
aMetric = 0;
break;
case eMetric_TextShouldUseVerticalInsidePadding:
aMetric = 0;
break;
aMetric = 0;
break;
case eMetric_TextHorizontalInsideMinimumPadding:
aMetric = 15;
break;
aMetric = 15;
break;
case eMetric_TextShouldUseHorizontalInsideMinimumPadding:
aMetric = 1;
break;
aMetric = 1;
break;
case eMetric_ButtonHorizontalInsidePaddingNavQuirks:
aMetric = 10;
break;
aMetric = 10;
break;
case eMetric_ButtonHorizontalInsidePaddingOffsetNavQuirks:
aMetric = 8;
break;
aMetric = 8;
break;
case eMetric_CheckboxSize:
aMetric = 15;
break;
aMetric = 15;
break;
case eMetric_RadioboxSize:
aMetric = 15;
break;
aMetric = 15;
break;
case eMetric_ListShouldUseHorizontalInsideMinimumPadding:
aMetric = 15;
break;
aMetric = 15;
break;
case eMetric_ListHorizontalInsideMinimumPadding:
aMetric = 15;
break;
aMetric = 15;
break;
case eMetric_ListShouldUseVerticalInsidePadding:
aMetric = 1;
break;
aMetric = 1;
break;
case eMetric_ListVerticalInsidePadding:
aMetric = 1;
break;
aMetric = 1;
break;
case eMetric_CaretBlinkTime:
aMetric = 500;
break;
aMetric = 500;
break;
case eMetric_SingleLineCaretWidth:
case eMetric_MultiLineCaretWidth:
aMetric = 1;
break;
case eMetric_SubmenuDelay:
aMetric = 200;
break;
case eMetric_MenusCanOverlapOSBar:
// we want XUL popups to be able to overlap the task bar.
aMetric = 1;
break;
default:
aMetric = 0;
res = NS_ERROR_FAILURE;
}
aMetric = 1;
break;
return res;
case eMetric_ShowCaretDuringSelection:
aMetric = 0;
break;
case eMetric_SubmenuDelay:
aMetric = 200;
break;
case eMetric_MenusCanOverlapOSBar:
// we want XUL popups to be able to overlap the task bar.
aMetric = 1;
break;
case eMetric_DragFullWindow:
aMetric = 1;
break;
case eMetric_ScrollArrowStyle:
aMetric = eMetric_ScrollArrowStyleSingle;
break;
case eMetric_ScrollSliderStyle:
aMetric = eMetric_ScrollThumbStyleProportional;
break;
default:
aMetric = 0;
res = NS_ERROR_FAILURE;
}
return res;
}
NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricFloatID aID,
float & aMetric)
float &aMetric)
{
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsLookAndFeel::GetMetric()\n"));
nsresult res = NS_OK;
nsresult res = NS_OK;
if (mXPLookAndFeel)
{
res = mXPLookAndFeel->GetMetric(aID, aMetric);
if (NS_SUCCEEDED(res))
return res;
res = NS_OK;
}
switch (aID)
{
if (mXPLookAndFeel) {
res = mXPLookAndFeel->GetMetric(aID, aMetric);
if (NS_SUCCEEDED(res))
return res;
res = NS_OK;
}
switch (aID) {
case eMetricFloat_TextFieldVerticalInsidePadding:
aMetric = 0.25f;
break;
aMetric = 0.25f;
break;
case eMetricFloat_TextFieldHorizontalInsidePadding:
aMetric = 0.95f; // large number on purpose so minimum padding is used
break;
aMetric = 0.95f; // large number on purpose so minimum padding is used
break;
case eMetricFloat_TextAreaVerticalInsidePadding:
aMetric = 0.40f;
break;
aMetric = 0.40f;
break;
case eMetricFloat_TextAreaHorizontalInsidePadding:
aMetric = 0.40f; // large number on purpose so minimum padding is used
break;
aMetric = 0.40f; // large number on purpose so minimum padding is used
break;
case eMetricFloat_ListVerticalInsidePadding:
aMetric = 0.10f;
break;
aMetric = 0.10f;
break;
case eMetricFloat_ListHorizontalInsidePadding:
aMetric = 0.40f;
break;
aMetric = 0.40f;
break;
case eMetricFloat_ButtonVerticalInsidePadding:
aMetric = 0.25f;
break;
aMetric = 0.25f;
break;
case eMetricFloat_ButtonHorizontalInsidePadding:
aMetric = 0.25f;
break;
aMetric = 0.25f;
break;
default:
aMetric = -1.0;
res = NS_ERROR_FAILURE;
}
return res;
aMetric = -1.0;
res = NS_ERROR_FAILURE;
}
return res;
}
#ifdef NS_DEBUG
NS_IMETHODIMP nsLookAndFeel::GetNavSize(const nsMetricNavWidgetID aWidgetID,
const nsMetricNavFontID aFontID,
const PRInt32 aFontSize,
nsSize &aSize)
const nsMetricNavFontID aFontID,
const PRInt32 aFontSize,nsSize &aSize)
{
if (mXPLookAndFeel)
{
nsresult rv = mXPLookAndFeel->GetNavSize(aWidgetID, aFontID, aFontSize, aSize);
if (mXPLookAndFeel) {
nsresult rv = mXPLookAndFeel->GetNavSize(aWidgetID,aFontID,aFontSize,aSize);
if (NS_SUCCEEDED(rv))
return rv;
}
aSize.width = 0;
aSize.height = 0;
return NS_ERROR_NOT_IMPLEMENTED;

View File

@ -18,18 +18,20 @@
* Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
*
*/
#ifndef __nsLookAndFeel
#define __nsLookAndFeel
#include "nsILookAndFeel.h"
#include "nsCOMPtr.h"
class nsLookAndFeel: public nsILookAndFeel
{
public:
NS_DECL_ISUPPORTS
public:
nsLookAndFeel();
virtual ~nsLookAndFeel();
@ -43,9 +45,8 @@ public:
// and font size. This is used in NavQuirks mode to see how closely
// we match its size
NS_IMETHOD GetNavSize(const nsMetricNavWidgetID aWidgetID,
const nsMetricNavFontID aFontID,
const PRInt32 aFontSize,
nsSize &aSize);
const nsMetricNavFontID aFontID,
const PRInt32 aFontSize,nsSize &aSize);
#endif
protected:

161
widget/src/qt/nsMime.cpp Normal file
View File

@ -0,0 +1,161 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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 Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Denis Issoupov <denis@macadamian.com>
*
*/
#include "nsDragService.h"
#include "nsIServiceManager.h"
#include "nsWidget.h"
#include "nsISupportsPrimitives.h"
#include "nsXPIDLString.h"
#include "nsPrimitiveHelpers.h"
#include "nsClipboard.h"
#include "nsMime.h"
#include <qapplication.h>
#include <qclipboard.h>
//----------------------------------------------------------
nsMimeStoreData::nsMimeStoreData(QCString& name, QByteArray& data)
{
flavorName = name;
flavorData = data;
}
nsMimeStoreData::nsMimeStoreData(const char* name,void* rawdata,PRInt32 rawlen)
{
flavorName = name;
flavorData.assign((char*)rawdata,(unsigned int)rawlen);
}
//----------------------------------------------------------
nsMimeStore::nsMimeStore()
{
mMimeStore.setAutoDelete(TRUE);
}
nsMimeStore::~nsMimeStore()
{
}
const char* nsMimeStore::format(int n) const
{
if (n >= (int)mMimeStore.count())
return 0;
// because of const
QList<nsMimeStoreData> *pMimeStore = (QList<nsMimeStoreData>*)&mMimeStore;
nsMimeStoreData* msd;
msd = pMimeStore->at((unsigned int)n);
return msd->flavorName;
}
QByteArray nsMimeStore::encodedData(const char* name) const
{
QByteArray qba;
// because of const
QList<nsMimeStoreData> *pMimeStore = (QList<nsMimeStoreData>*)&mMimeStore;
nsMimeStoreData* msd;
for (msd = pMimeStore->first(); msd != 0; msd = pMimeStore->next()) {
if (strcmp(name, msd->flavorName) == 0) {
qba = msd->flavorData;
return qba;
}
}
#ifdef NS_DEBUG
printf("nsMimeStore::encodedData requested unkown %s\n", name);
#endif
return qba;
}
PRBool nsMimeStore::AddFlavorData(const char* name, void* data, PRInt32 len)
{
nsMimeStoreData* msd;
for (msd = mMimeStore.first(); msd != 0; msd = mMimeStore.next()) {
if (strcmp(name, msd->flavorName) == 0)
return PR_FALSE;
}
mMimeStore.append(new nsMimeStoreData(name, data, len));
if (strcmp(name, kUnicodeMime) == 0) {
// let's look if text/plain is not present yet
for (msd = mMimeStore.first(); msd != 0; msd = mMimeStore.next()) {
if (strcmp("text/plain", msd->flavorName) == 0)
return PR_TRUE;
}
// if we find text/unicode, also advertise text/plain (which we will convert
// on our own in nsDataObj::GetText().
len /= 2;
QChar* qch = new QChar[len];
for (PRInt32 c = 0; c < len; c++)
qch[c] = (QChar)((PRUnichar*)data)[c];
QString ascii(qch, len);
delete qch;
char *as = new char[len];
for (PRInt32 c = 0; c < len; c++)
as[c] = ((const char*)ascii)[c];
// let's text/plain be first for stupid programms
mMimeStore.insert(0, new nsMimeStoreData("text/plain", as, len));
}
return PR_TRUE;
}
//----------------------------------------------------------
nsDragObject::nsDragObject(nsMimeStore* mimeStore,QWidget* dragSource,
const char* name)
: QDragObject(dragSource, name)
{
if (!mimeStore)
NS_ASSERTION(PR_TRUE, "Invalid pointer.");
mMimeStore = mimeStore;
}
nsDragObject::~nsDragObject()
{
delete mMimeStore;
}
const char* nsDragObject::format(int i) const
{
if (i >= (int)mMimeStore->count())
return 0;
const char* frm = mMimeStore->format(i);
#ifdef NS_DEBUG
printf("nsDragObject::format i=%i %s\n",i, frm);
#endif
return frm;
}
QByteArray nsDragObject::encodedData(const char* frm) const
{
#ifdef NS_DEBUG
printf("nsDragObject::encodedData %s\n",frm);
#endif
return mMimeStore->encodedData(frm);
}

82
widget/src/qt/nsMime.h Normal file
View File

@ -0,0 +1,82 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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 Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Denis Issoupov <denis@macadamian.com>
*
*/
#ifndef nsMime_h__
#define nsMime_h__
#include "nsITransferable.h"
#include "nsCOMPtr.h"
#include <qlist.h>
#include <qcstring.h>
#include <qmime.h>
#include <qwidget.h>
#include <qdragobject.h>
class nsMimeStoreData
{
public:
nsMimeStoreData(QCString& name, QByteArray& data);
nsMimeStoreData(const char* name, void* rawdata, PRInt32 rawlen);
QCString flavorName;
QByteArray flavorData;
};
class nsMimeStore: public QMimeSource
{
public:
nsMimeStore();
virtual ~nsMimeStore();
virtual const char* format(int n = 0) const ;
virtual QByteArray encodedData(const char*) const;
PRBool AddFlavorData(const char* name, void* data, PRInt32 len);
PRUint32 count();
protected:
QList<nsMimeStoreData> mMimeStore;
nsMimeStoreData* at(int n);
};
inline PRUint32 nsMimeStore::count() { return mMimeStore.count(); }
//----------------------------------------------------------
class nsDragObject : public QDragObject
{
Q_OBJECT
public:
nsDragObject(nsMimeStore* mimeStore,QWidget* dragSource = 0,
const char* name = 0);
~nsDragObject();
const char* format(int i) const;
virtual QByteArray encodedData(const char*) const;
protected:
nsMimeStore* mMimeStore;
};
#endif

View File

@ -18,82 +18,134 @@
* Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
*
*/
#include "nsQApplication.h"
//JCG #define DBG_JCG 1
#ifdef DEBUG
/* Required for x11EventFilter debugging hook */
#include "nsQApplication.h"
#include "nsQWidget.h"
#include <qwindowsstyle.h>
#include <qcursor.h>
#ifdef DBG_JCG
/* Required for x11EventFilter & _x_error debugging hooks */
#include "X11/Xlib.h"
#include <assert.h>
PRInt32 gQAppID = 0;
PRInt32 gQAppCount = 0;
PRInt32 gQQueueID = 0;
PRInt32 gQQueueCount = 0;
#endif
nsQApplication *nsQApplication::mInstance = nsnull;
QIntDict<nsQtEventQueue> nsQApplication::mQueueDict;
PRUint32 nsQApplication::mRefCnt = 0;
QWidget *nsQApplication::mMasterWidget = nsnull;
nsQApplication *nsQApplication::Instance(int argc, char ** argv)
#ifdef DBG_JCG
int _x_error(Display *display, XErrorEvent *error)
{
if (error->error_code) {
char buf[64];
XGetErrorText (display, error->error_code, buf, 63);
fprintf(stderr,
"X-ERROR **: %s\n serial %ld error_code %d request_code %d minor_code %d, resourceId: %ld\n",
buf, error->serial, error->error_code, error->request_code,
error->minor_code,error->resourceid);
printf("X-ERROR **: %s\n serial %ld error_code %d request_code %d minor_code %d, resourceId: %ld\n",
buf, error->serial, error->error_code, error->request_code,
error->minor_code,error->resourceid);
assert(0);
}
return 0;
}
#endif //DBG_JCG
nsQApplication* nsQApplication::Instance(int argc,char** argv)
{
if (!mInstance)
mInstance = new nsQApplication(argc,argv);
mRefCnt++;
return mInstance;
}
nsQApplication *nsQApplication::Instance(Display * display)
{
if (!mInstance)
mInstance = new nsQApplication(display);
mRefCnt++;
return mInstance;
}
void nsQApplication::Release()
{
mRefCnt--;
if (mRefCnt <= 0)
if (mRefCnt <= 0) {
if (mMasterWidget) {
delete mMasterWidget;
mMasterWidget = nsnull;
}
delete mInstance;
mInstance = nsnull;
}
}
nsQApplication::nsQApplication(int argc, char ** argv)
: QApplication(argc, argv)
QWidget *nsQApplication::GetMasterWidget()
{
if (mInstance)
NS_ASSERTION(mInstance == nsnull,"Attempt to create duplicate QApplication Object.");
mInstance = this;
setGlobalMouseTracking(true);
if (!mMasterWidget)
mMasterWidget = new QWidget();
return mMasterWidget;
}
nsQApplication::nsQApplication(Display * display)
: QApplication(display)
nsQApplication::nsQApplication(int argc,char** argv)
: QApplication(argc,argv)
{
if (mInstance)
NS_ASSERTION(mInstance == nsnull,"Attempt to create duplicate QApplication Object.");
mInstance = this;
setGlobalMouseTracking(true);
#ifdef DBG_JCG
gQAppCount++;
mID = gQAppID++;
printf("JCG nsQApplication CTOR (%p) ID: %d, Count: %d\n",this,mID,gQAppCount);
XSetErrorHandler (_x_error);
#endif
if (mInstance)
NS_ASSERTION(mInstance == nsnull,
"Attempt to create duplicate QApplication Object.");
mInstance = this;
setGlobalMouseTracking(true);
setStyle(new QWindowsStyle);
setOverrideCursor(QCursor(ArrowCursor),PR_TRUE);
connect(this,SIGNAL(lastWindowClosed()),this,SLOT(quit()));
}
nsQApplication::~nsQApplication()
{
setGlobalMouseTracking(false);
#ifdef DBG_JCG
gQAppCount--;
printf("JCG nsQApplication DTOR (%p) ID: %d, Count: %d\n",this,mID,gQAppCount);
#endif
setGlobalMouseTracking(false);
}
void nsQApplication::AddEventProcessorCallback(nsIEventQueue * EQueue)
void nsQApplication::AddEventProcessorCallback(nsIEventQueue* EQueue)
{
nsQtEventQueue *que = nsnull;
nsQtEventQueue* que = nsnull;
if ((que = mQueueDict.find(EQueue->GetEventQueueSelectFD()))) {
que->IncRefCnt();
}
else {
mQueueDict.insert(EQueue->GetEventQueueSelectFD(),new nsQtEventQueue(EQueue));
mQueueDict.insert(EQueue->GetEventQueueSelectFD(),
new nsQtEventQueue(EQueue));
}
}
void nsQApplication::RemoveEventProcessorCallback(nsIEventQueue * EQueue)
void nsQApplication::RemoveEventProcessorCallback(nsIEventQueue* EQueue)
{
nsQtEventQueue *que = nsnull;
nsQtEventQueue* que = nsnull;
if ((que = mQueueDict.find(EQueue->GetEventQueueSelectFD()))) {
que->DataReceived();
@ -104,52 +156,256 @@ void nsQApplication::RemoveEventProcessorCallback(nsIEventQueue * EQueue)
}
}
#ifdef DEBUG
/* Hook for capturing X11 Events before they are processed by Qt */
bool nsQApplication::x11EventFilter(XEvent *event)
bool nsQApplication::x11EventFilter(XEvent* event)
{
if (event->type == ButtonPress || event->type == ButtonRelease) {
int i;
#ifdef DBG_JCG
switch (event->type) {
case ButtonPress:
case ButtonRelease:
{
XButtonPressedEvent *ptr = (XButtonPressedEvent*)event;
printf("JCG: ButtonPress/Release: serial %ld, Window: %ld, Root: %ld, Child: %ld\n",ptr->serial,ptr->window,ptr->root,ptr->subwindow);
}
break;
/* Break here to see Mouse Button Events */
i = 0;
case CirculateNotify:
{
XCirculateEvent *ptr = (XCirculateEvent*)event;
printf("JCG: CirculateNotify: serial %ld, Event: %ld, Window: %ld\n",ptr->serial,ptr->event,ptr->window);
}
break;
case CirculateRequest:
{
XCirculateRequestEvent *ptr = (XCirculateRequestEvent*)event;
printf("JCG: CirculateRequest: serial %ld, Parent: %ld, Window: %ld\n",ptr->serial,ptr->parent,ptr->window);
}
break;
case ClientMessage:
{
XClientMessageEvent *ptr = (XClientMessageEvent*)event;
printf("JCG: ClientMessage: serial %ld, Window: %ld\n",ptr->serial,ptr->window);
}
break;
case ColormapNotify:
{
XColormapEvent *ptr = (XColormapEvent*)event;
printf("JCG: ColormapNotify: serial %ld, Window: %ld\n",ptr->serial,ptr->window);
}
break;
case ConfigureNotify:
{
XConfigureEvent *ptr = (XConfigureEvent*)event;
printf("JCG: ConfigureNotify: serial %ld, Event: %ld, Window: %ld\n",ptr->serial,ptr->event,ptr->window);
}
break;
case ConfigureRequest:
{
XConfigureRequestEvent *ptr = (XConfigureRequestEvent*)event;
printf("JCG: ConfigureRequest: serial %ld, Parent: %ld, Window: %ld\n",ptr->serial,ptr->parent,ptr->window);
}
break;
case CreateNotify:
{
XCreateWindowEvent *ptr = (XCreateWindowEvent*)event;
printf("JCG: CreateNotify: serial %ld, Parent: %ld, Window: %ld\n",ptr->serial,ptr->parent,ptr->window);
}
break;
case DestroyNotify:
{
XDestroyWindowEvent *ptr = (XDestroyWindowEvent*)event;
printf("JCG: DestroyNotify: serial %ld, Event: %ld, Window: %ld\n",ptr->serial,ptr->event,ptr->window);
}
break;
case EnterNotify:
case LeaveNotify:
{
XCrossingEvent *ptr = (XCrossingEvent*)event;
printf("JCG: Enter/LeaveNotify: serial %ld, Window: %ld, Parent: %ld, Child: %ld\n",ptr->serial,ptr->window,ptr->root,ptr->subwindow);
}
break;
case Expose:
{
XExposeEvent *ptr = (XExposeEvent*)event;
printf("JCG: Expose: serial %ld, Window: %ld\n",ptr->serial,ptr->window);
}
break;
case FocusIn:
case FocusOut:
{
XFocusChangeEvent *ptr = (XFocusChangeEvent*)event;
printf("JCG: FocusIn/Out: serial %ld, Window: %ld\n",ptr->serial,ptr->window);
}
break;
case GraphicsExpose:
case NoExpose:
{
printf("JCG: Graphics/NoExpose\n");
}
break;
case GravityNotify:
{
XGravityEvent *ptr = (XGravityEvent*)event;
printf("JCG: GravityNotify: serial %ld, Event: %ld, Window: %ld\n",ptr->serial,ptr->event,ptr->window);
}
break;
case KeymapNotify:
{
XKeymapEvent *ptr = (XKeymapEvent*)event;
printf("JCG: KeymapNotify: serial %ld, Window: %ld\n",ptr->serial,ptr->window);
}
break;
case KeyPress:
case KeyRelease:
{
XKeyEvent *ptr = (XKeyEvent*)event;
printf("JCG: KeyPress/Release: serial %ld, Window: %ld, Parent: %ld, Child: %ld\n",ptr->serial,ptr->window,ptr->root,ptr->subwindow);
}
break;
case MapNotify:
case UnmapNotify:
{
XMapEvent *ptr = (XMapEvent*)event;
printf("JCG: Map/UnmapNotify: serial %ld, Window: %ld, Event: %ld\n",ptr->serial,ptr->window,ptr->event);
}
break;
case MappingNotify:
{
XMappingEvent *ptr = (XMappingEvent*)event;
printf("JCG: MappingNotify: serial %ld, Window: %ld\n",ptr->serial,ptr->window);
}
break;
case MapRequest:
{
XMapRequestEvent *ptr = (XMapRequestEvent*)event;
printf("JCG: MapRequest: serial %ld, Window: %ld, Parent: %ld\n",ptr->serial,ptr->window,ptr->parent);
}
break;
case MotionNotify:
{
XMotionEvent *ptr = (XMotionEvent*)event;
printf("JCG: MotionNotify: serial %ld, Window: %ld, Parent: %ld, Child: %ld\n",ptr->serial,ptr->window,ptr->root,ptr->subwindow);
}
break;
case PropertyNotify:
{
XPropertyEvent *ptr = (XPropertyEvent*)event;
printf("JCG: PropertyNotify: serial %ld, Window: %ld\n",ptr->serial,ptr->window);
}
break;
case ReparentNotify:
{
XReparentEvent *ptr = (XReparentEvent*)event;
printf("JCG: ReparentNotify: serial %ld, Window: %ld, Parent: %ld, Event: %ld\n",ptr->serial,ptr->window,ptr->parent,ptr->event);
}
break;
case ResizeRequest:
{
XResizeRequestEvent *ptr = (XResizeRequestEvent*)event;
printf("JCG: ResizeRequest: serial %ld, Window: %ld\n",ptr->serial,ptr->window);
}
break;
case SelectionClear:
{
XSelectionClearEvent *ptr = (XSelectionClearEvent*)event;
printf("JCG: SelectionClear: serial %ld, Window: %ld\n",ptr->serial,ptr->window);
}
break;
case SelectionNotify:
{
XSelectionEvent *ptr = (XSelectionEvent*)event;
printf("JCG: SelectionNotify: serial %ld, Requestor: %ld\n",ptr->serial,ptr->requestor);
}
break;
case SelectionRequest:
{
XSelectionRequestEvent *ptr = (XSelectionRequestEvent*)event;
printf("JCG: SelectionRequest: serial %ld, Owner: %ld, Requestor: %ld\n",ptr->serial,ptr->owner,ptr->requestor);
}
break;
case VisibilityNotify:
{
XVisibilityEvent *ptr = (XVisibilityEvent*)event;
printf("JCG: VisibilityNotify: serial %ld, Window: %ld\n",ptr->serial,ptr->window);
}
break;
default:
{
printf("JCG: Unknown Event: %d\n",event->type);
}
break;
}
#endif //DBG_JCG
return FALSE;
}
#endif
nsQtEventQueue::nsQtEventQueue(nsIEventQueue * EQueue)
nsQtEventQueue::nsQtEventQueue(nsIEventQueue* EQueue)
{
mQSocket = nsnull;
mEventQueue = EQueue;
NS_IF_ADDREF(mEventQueue);
mRefCnt = 1;
#ifdef DBG_JCG
mID = gQQueueID++;
gQQueueCount++;
printf("JCG nsQtEventQueue CTOR (%p) ID: %d, Count: %d\n",this,mID,gQQueueCount);
#endif
mQSocket = nsnull;
mEventQueue = EQueue;
NS_IF_ADDREF(mEventQueue);
mRefCnt = 1;
mQSocket = new QSocketNotifier(mEventQueue->GetEventQueueSelectFD(),
QSocketNotifier::Read,this);
if (mQSocket)
connect(mQSocket, SIGNAL(activated(int)), this, SLOT(DataReceived()));
mQSocket = new QSocketNotifier(mEventQueue->GetEventQueueSelectFD(),
QSocketNotifier::Read,this);
if (mQSocket)
connect(mQSocket,SIGNAL(activated(int)),this,SLOT(DataReceived()));
}
nsQtEventQueue::~nsQtEventQueue()
{
if (mQSocket)
delete mQSocket;
NS_IF_RELEASE(mEventQueue);
#ifdef DBG_JCG
gQQueueCount--;
printf("JCG nsQtEventQueue DTOR (%p) ID: %d, Count: %d\n",this,mID,gQQueueCount);
#endif
if (mQSocket)
delete mQSocket;
NS_IF_RELEASE(mEventQueue);
}
unsigned long nsQtEventQueue::IncRefCnt()
{
return --mRefCnt;
return ++mRefCnt;
}
unsigned long nsQtEventQueue::DecRefCnt()
{
return ++mRefCnt;
return --mRefCnt;
}
void nsQtEventQueue::DataReceived()
{
if (mEventQueue)
mEventQueue->ProcessPendingEvents();
if (mEventQueue)
mEventQueue->ProcessPendingEvents();
}

View File

@ -18,8 +18,9 @@
* Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
*
*/
#ifndef nsQApplication_h__
#define nsQApplication_h__
@ -29,47 +30,49 @@
class nsQtEventQueue : public QObject
{
Q_OBJECT
Q_OBJECT
public:
nsQtEventQueue(nsIEventQueue *EQueue);
~nsQtEventQueue();
unsigned long IncRefCnt();
unsigned long DecRefCnt();
nsQtEventQueue(nsIEventQueue *EQueue);
~nsQtEventQueue();
unsigned long IncRefCnt();
unsigned long DecRefCnt();
public slots:
void DataReceived();
void DataReceived();
private:
nsIEventQueue *mEventQueue;
QSocketNotifier *mQSocket;
unsigned long mRefCnt;
nsIEventQueue *mEventQueue;
QSocketNotifier *mQSocket;
PRUint32 mRefCnt;
PRInt32 mID;
};
class nsQApplication : public QApplication
{
Q_OBJECT
Q_OBJECT
public:
static nsQApplication *Instance(int argc, char ** argv);
static nsQApplication *Instance(Display * display);
static nsQApplication *Instance(int argc,char **argv);
static void Release();
static void Release();
static void AddEventProcessorCallback(nsIEventQueue * EQueue);
static void RemoveEventProcessorCallback(nsIEventQueue * EQueue);
static void AddEventProcessorCallback(nsIEventQueue *EQueue);
static void RemoveEventProcessorCallback(nsIEventQueue *EQueue);
#ifdef DEBUG
bool x11EventFilter(XEvent *event);
#endif
static QWidget *GetMasterWidget();
///Hook for debugging X11 Events
bool x11EventFilter(XEvent *event);
protected:
nsQApplication(int argc, char ** argv);
nsQApplication(Display * display);
~nsQApplication();
nsQApplication(int argc,char **argv);
~nsQApplication();
private:
static QIntDict<nsQtEventQueue> mQueueDict;
static nsQApplication *mInstance;
static PRUint32 mRefCnt;
PRInt32 mID;
static QIntDict<nsQtEventQueue> mQueueDict;
static nsQApplication *mInstance;
static PRUint32 mRefCnt;
static QWidget *mMasterWidget;
};
#endif // nsQApplication_h__

View File

@ -18,37 +18,24 @@
* Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
*
*/
#include "nsWidget.h"
#include "nsWindow.h"
#include "nsTextWidget.h"
#include "nsCheckButton.h"
#include "nsRadioButton.h"
#include "nsScrollbar.h"
#include "nsFileWidget.h"
#include "nsGUIEvent.h"
#include "nsIMenuItem.h"
#include "nsIMenuListener.h"
#include "stdio.h"
#include "nsQEventHandler.h"
//JCG #define DBG 1
#ifdef DBG
PRUint32 gQEventHandlerCount = 0;
//JCG #define DBG_JCG 1
#ifdef DBG_JCG
PRUint32 gQEventHandlerCount = 0;
#endif
static NS_DEFINE_IID(kCWindow, NS_WINDOW_CID);
static NS_DEFINE_IID(kCChild, NS_CHILD_CID);
struct EventInfo
{
nsWidget *widget; // the widget
nsRect *rect; // the rect
};
static NS_DEFINE_IID(kCWindow, NS_WINDOW_CID);
static NS_DEFINE_IID(kCChild, NS_CHILD_CID);
#if 0 //JCG
struct nsKeyConverter
{
int vkCode; // Platform independent key code
@ -176,6 +163,7 @@ struct nsKeyConverter nsKeycodes[] =
{ NS_VK_CLOSE_BRACKET, Qt::Key_ParenRight },
{ NS_VK_QUOTE, Qt::Key_QuoteDbl }
};
#endif //JCG
PRLogModuleInfo * QtEventsLM = PR_NewLogModule("QtEvents");
@ -185,23 +173,23 @@ PRLogModuleInfo * QtEventsLM = PR_NewLogModule("QtEvents");
*/
nsQEventHandler::nsQEventHandler(nsWidget *aWidget) : QObject()
{
PR_LOG(QtEventsLM, PR_LOG_DEBUG, ("nsQEventHandler::nsQEventHandler()\n"));
mEnabled = true;
mDestroyed = false;
mWidget = aWidget;
#ifdef DBG
PR_LOG(QtEventsLM, PR_LOG_DEBUG, ("nsQEventHandler::nsQEventHandler()\n"));
mEnabled = true;
mDestroyed = false;
mWidget = aWidget;
#ifdef DBG_JCG
gQEventHandlerCount++;
printf("DBG: nsQEventHandler CTOR. Count: %d\n",gQEventHandlerCount);
printf("JCG: nsQEventHandler CTOR. Count: %d\n",gQEventHandlerCount);
#endif
}
nsQEventHandler::~nsQEventHandler()
{
PR_LOG(QtEventsLM, PR_LOG_DEBUG, ("nsQEventHandler::~nsQEventHandler()\n"));
mWidget = nsnull;
#ifdef DBG
PR_LOG(QtEventsLM, PR_LOG_DEBUG, ("nsQEventHandler::~nsQEventHandler()\n"));
mWidget = nsnull;
#ifdef DBG_JCG
gQEventHandlerCount--;
printf("DBG: nsQEventHandler DTOR. Count: %d\n",gQEventHandlerCount);
printf("JCG: nsQEventHandler DTOR. Count: %d\n",gQEventHandlerCount);
#endif
}
@ -210,13 +198,13 @@ void nsQEventHandler::Enable(bool aEnable)
mEnabled = aEnable;
}
void nsQEventHandler::Destroy(void)
void nsQEventHandler::Destroy()
{
mDestroyed = true;
mWidget = nsnull;
}
bool nsQEventHandler::eventFilter(QObject * object, QEvent * event)
bool nsQEventHandler::eventFilter(QObject* object, QEvent* event)
{
bool handled = false;
@ -224,109 +212,173 @@ bool nsQEventHandler::eventFilter(QObject * object, QEvent * event)
return true;
switch (event->type()) {
#if 0 //JCG
case QEvent::MouseButtonPress:
if (mEnabled)
handled = MouseButtonEvent((QMouseEvent *) event, mWidget, true, 1);
if (mEnabled) {
#ifdef DBG_JCG
printf("JCG: Mouse Button Pushed. Widget: %p\n",mWidget);
#endif
handled = MouseButtonEvent((QMouseEvent*)event, mWidget, true, 1);
}
else
handled = true;
break;
case QEvent::MouseButtonRelease:
if (mEnabled)
handled = MouseButtonEvent((QMouseEvent *) event, mWidget, false, 1);
if (mEnabled) {
#ifdef DBG_JCG
printf("JCG: Mouse Button Released widget: %p\n",mWidget);
#endif
handled = MouseButtonEvent((QMouseEvent*)event, mWidget, false, 1);
}
else
handled = true;
break;
case QEvent::MouseButtonDblClick:
if (mEnabled)
handled = MouseButtonEvent((QMouseEvent *) event, mWidget, true, 2);
if (mEnabled) {
#ifdef DBG_JCG
printf("JCG: Mouse Button Double-clicked widget: %p\n",mWidget);
#endif
handled = MouseButtonEvent((QMouseEvent*)event, mWidget, true, 2);
}
else
handled = true;
break;
#endif //JCG
case QEvent::MouseMove:
if (mEnabled)
handled = MouseMovedEvent((QMouseEvent *) event, mWidget);
if (mEnabled) {
#ifdef DBG_JCG
printf("JCG: Mouse Moved widget: %p\n",mWidget);
#endif
handled = MouseMovedEvent((QMouseEvent*)event, mWidget);
}
else
handled = true;
break;
#if 0 //JCG
case QEvent::KeyPress:
if (mEnabled)
handled = KeyPressEvent((QKeyEvent *) event, mWidget);
if (mEnabled) {
#ifdef DBG_JCG
printf("JCG: Key Pressed widget: %p\n",mWidget);
#endif
handled = KeyPressEvent((QKeyEvent*)event, mWidget);
}
else
handled = true;
break;
case QEvent::KeyRelease:
if (mEnabled)
handled = KeyReleaseEvent((QKeyEvent *) event, mWidget);
if (mEnabled) {
#ifdef DBG_JCG
printf("JCG: Key Released widget: %p\n",mWidget);
#endif
handled = KeyReleaseEvent((QKeyEvent*)event, mWidget);
}
else
handled = true;
break;
case QEvent::Enter:
if (mEnabled)
if (mEnabled) {
#ifdef DBG_JCG
printf("JCG: Mouse Enter widget: %p\n",mWidget);
#endif
handled = MouseEnterEvent(event, mWidget);
}
else
handled = true;
break;
case QEvent::Leave:
if (mEnabled)
if (mEnabled) {
#ifdef DBG_JCG
printf("JCG: Mouse Exit widget: %p\n",mWidget);
#endif
handled = MouseExitEvent(event, mWidget);
}
else
handled = true;
break;
case QEvent::Close:
if (!mWidget->IsPopup()) {
handled = DestroyEvent((QCloseEvent *) event, mWidget);
#ifdef DBG_JCG
printf("JCG: Close widget: %p\n",mWidget);
#endif
handled = DestroyEvent((QCloseEvent*)event, mWidget);
}
break;
case QEvent::Destroy:
handled = DestroyEvent((QCloseEvent *) event, mWidget);
#ifdef DBG_JCG
printf("JCG: Destroy widget: %p\n",mWidget);
#endif
handled = DestroyEvent((QCloseEvent*)event, mWidget);
break;
case QEvent::Resize:
handled = ResizeEvent((QResizeEvent *) event, mWidget);
#ifdef DBG_JCG
printf("JCG: Resize widget: %p\n",mWidget);
#endif
handled = ResizeEvent((QResizeEvent*)event, mWidget);
break;
case QEvent::Move:
handled = MoveEvent((QMoveEvent *) event, mWidget);
#ifdef DBG_JCG
printf("JCG: Move widget: %p\n",mWidget);
#endif
handled = MoveEvent((QMoveEvent*)event, mWidget);
break;
#endif //JCG
case QEvent::Paint:
handled = PaintEvent((QPaintEvent *) event, mWidget);
#ifdef DBG_JCG
printf("JCG: Paint widget: %p\n",mWidget);
#endif
handled = PaintEvent((QPaintEvent*)event, mWidget);
break;
#if 0 //JCG
case QEvent::FocusIn:
if (mEnabled)
handled = FocusInEvent((QFocusEvent *) event, mWidget);
if (mEnabled) {
#ifdef DBG_JCG
printf("JCG: Focus In widget: %p\n",mWidget);
#endif
handled = FocusInEvent((QFocusEvent*)event, mWidget);
}
else
handled = true;
break;
case QEvent::FocusOut:
if (mEnabled)
handled = FocusOutEvent((QFocusEvent *) event, mWidget);
if (mEnabled) {
#ifdef DBG_JCG
printf("JCG: Focus In widget: %p\n",mWidget);
#endif
handled = FocusOutEvent((QFocusEvent*)event, mWidget);
}
else
handled = true;
break;
#endif //JCG
default:
#ifdef DBG_JCG
printf("JCG: widget: %p, Other: %d\n",mWidget,event->type());
#endif
break;
}
return handled;
}
bool nsQEventHandler::MouseButtonEvent(QMouseEvent * event,
nsWidget * widget,
bool buttonDown,
int clickCnt)
bool nsQEventHandler::MouseButtonEvent(QMouseEvent *event,
nsWidget *widget,
bool buttonDown,
int clickCnt)
{
if (event && widget) {
nsMouseEvent nsEvent;
@ -338,18 +390,18 @@ bool nsQEventHandler::MouseButtonEvent(QMouseEvent * event,
switch (event->button()) {
case LeftButton:
nsEvent.message = buttonDown ? NS_MOUSE_LEFT_BUTTON_DOWN :
NS_MOUSE_LEFT_BUTTON_UP;
nsEvent.message = buttonDown ? NS_MOUSE_LEFT_BUTTON_DOWN
: NS_MOUSE_LEFT_BUTTON_UP;
break;
case RightButton:
nsEvent.message = buttonDown ? NS_MOUSE_RIGHT_BUTTON_DOWN :
NS_MOUSE_RIGHT_BUTTON_UP;
nsEvent.message = buttonDown ? NS_MOUSE_RIGHT_BUTTON_DOWN
: NS_MOUSE_RIGHT_BUTTON_UP;
break;
case MidButton:
nsEvent.message = buttonDown ? NS_MOUSE_MIDDLE_BUTTON_DOWN :
NS_MOUSE_MIDDLE_BUTTON_UP;
nsEvent.message = buttonDown ? NS_MOUSE_MIDDLE_BUTTON_DOWN
: NS_MOUSE_MIDDLE_BUTTON_UP;
break;
default:
@ -369,7 +421,7 @@ bool nsQEventHandler::MouseButtonEvent(QMouseEvent * event,
nsEvent.isControl = (event->state() & ControlButton) ? PR_TRUE : PR_FALSE;
nsEvent.isAlt = (event->state() & AltButton) ? PR_TRUE : PR_FALSE;
nsEvent.isMeta = PR_FALSE;
nsEvent.time = PR_IntervalNow();
nsEvent.time = PR_IntervalNow();
widget->AddRef();
widget->DispatchMouseEvent(nsEvent);
widget->Release();
@ -380,26 +432,23 @@ bool nsQEventHandler::MouseButtonEvent(QMouseEvent * event,
/* nsWidget & nsWindow, unless either the EventHandler is destroyed */
/* (i.e. "widget" is NULL) or the widget is deleted (i.e. IsInDTOR */
/* returns TRUE). The last item is particularly slimey... */
bool handled = true;
if (widget && !widget->IsInDTOR()) {
if (widget->GetName() == QWidget::tr("nsWindow")
|| widget->GetName() == QWidget::tr("nsWidget")) {
if (buttonDown) {
return false;
}
else {
return true;
handled = false;
}
}
else {
return false;
handled = false;
}
}
else
return true;
return handled;
}
bool nsQEventHandler::MouseMovedEvent(QMouseEvent * event, nsWidget * widget)
bool nsQEventHandler::MouseMovedEvent(QMouseEvent *event,
nsWidget *widget)
{
if (event && widget) {
// Generate XPFE mouse moved event
@ -414,9 +463,14 @@ bool nsQEventHandler::MouseMovedEvent(QMouseEvent * event, nsWidget * widget)
nsEvent.point.y = event->y();
nsEvent.message = NS_MOUSE_MOVE;
nsEvent.widget = widget;
nsEvent.nativeMsg = (void*)event;
nsEvent.nativeMsg = (void*)event;
nsEvent.eventStructType = NS_MOUSE_EVENT;
nsEvent.time = PR_IntervalNow();
nsEvent.time = PR_IntervalNow();
nsEvent.isShift = (event->state() & ShiftButton) ? PR_TRUE : PR_FALSE;
nsEvent.isControl = (event->state() & ControlButton) ? PR_TRUE : PR_FALSE;
nsEvent.isAlt = (event->state() & AltButton) ? PR_TRUE : PR_FALSE;
nsEvent.isMeta = PR_FALSE;
widget->AddRef();
widget->DispatchMouseEvent(nsEvent);
widget->Release();
@ -426,19 +480,21 @@ bool nsQEventHandler::MouseMovedEvent(QMouseEvent * event, nsWidget * widget)
/* native widgets (i.e. NOT nsWidget or nsWindow AND IsInDTOR */
/* returns FALSE) Using IsInDTOR like this is particularly slimey! */
bool handled = false;
if (widget && !widget->IsInDTOR()) {
if (widget->GetName() == QWidget::tr("nsWindow")
|| widget->GetName() == QWidget::tr("nsWidget")) {
return true;
handled = true;
}
else
return false;
}
else
return true;
handled = true;
return handled;
}
bool nsQEventHandler::MouseEnterEvent(QEvent * event, nsWidget * widget)
bool nsQEventHandler::MouseEnterEvent(QEvent *event,
nsWidget *widget)
{
if (event && widget) {
nsMouseEvent nsEvent;
@ -452,7 +508,8 @@ bool nsQEventHandler::MouseEnterEvent(QEvent * event, nsWidget * widget)
nsEvent.widget = widget;
nsEvent.nativeMsg = (void*)event;
nsEvent.eventStructType = NS_MOUSE_EVENT;
nsEvent.time = PR_IntervalNow();
nsEvent.time = PR_IntervalNow();
widget->AddRef();
widget->DispatchMouseEvent(nsEvent);
widget->Release();
@ -460,7 +517,8 @@ bool nsQEventHandler::MouseEnterEvent(QEvent * event, nsWidget * widget)
return true;
}
bool nsQEventHandler::MouseExitEvent(QEvent * event, nsWidget * widget)
bool nsQEventHandler::MouseExitEvent(QEvent *event,
nsWidget *widget)
{
if (event && widget) {
nsMouseEvent nsEvent;
@ -474,7 +532,8 @@ bool nsQEventHandler::MouseExitEvent(QEvent * event, nsWidget * widget)
nsEvent.widget = widget;
nsEvent.nativeMsg = (void*)event;
nsEvent.eventStructType = NS_MOUSE_EVENT;
nsEvent.time = PR_IntervalNow();
nsEvent.time = PR_IntervalNow();
widget->AddRef();
widget->DispatchMouseEvent(nsEvent);
widget->Release();
@ -482,7 +541,8 @@ bool nsQEventHandler::MouseExitEvent(QEvent * event, nsWidget * widget)
return true;
}
bool nsQEventHandler::DestroyEvent(QCloseEvent * event, nsWidget * widget)
bool nsQEventHandler::DestroyEvent(QCloseEvent *event,
nsWidget *widget)
{
if (event && widget) {
// Generate XPFE destroy event
@ -492,55 +552,34 @@ bool nsQEventHandler::DestroyEvent(QCloseEvent * event, nsWidget * widget)
("nsQEventHandler::DestroyEvent for %s\n",
widget->GetName()));
((nsWindow *)widget)->SetIsDestroying(PR_TRUE);
widget->Destroy();
}
return true;
}
bool nsQEventHandler::ResizeEvent(QResizeEvent * event, nsWidget * widget)
bool nsQEventHandler::ResizeEvent(QResizeEvent *event,
nsWidget *widget)
{
if (event && widget) {
// Generate XPFE resize event
nsSizeEvent nsEvent;
PR_LOG(QtEventsLM,
PR_LOG_DEBUG,
("nsQEventHandler::ResizeEvent for %s(%p)\n",
widget->GetName(),
widget));
nsEvent.message = NS_SIZE;
nsEvent.widget = widget;
nsEvent.eventStructType = NS_SIZE_EVENT;
nsRect rect;
widget->GetBounds(rect);
rect.width = event->size().width();
rect.height = event->size().height();
PR_LOG(QtEventsLM,
PR_LOG_DEBUG,
("nsQEventHandler::ResizeEvent: old size:%dx%d, new size:%dx%d\n",
event->oldSize().width(),
event->oldSize().height(),
event->size().width(),
event->size().height()));
nsRect * rect = new nsRect();
widget->GetBounds(*rect);
rect->width = event->size().width();
rect->height = event->size().height();
nsEvent.point.x = 0;
nsEvent.point.y = 0;
nsEvent.windowSize = rect;
nsEvent.mWinHeight = event->size().height();
nsEvent.mWinWidth = event->size().width();
nsEvent.time = PR_IntervalNow();
widget->OnResize(*rect);
delete rect;
widget->OnResize(rect);
}
return false;
}
bool nsQEventHandler::MoveEvent(QMoveEvent * event, nsWidget * widget)
bool nsQEventHandler::MoveEvent(QMoveEvent *event,
nsWidget *widget)
{
if (event && widget) {
PR_LOG(QtEventsLM,
@ -554,7 +593,8 @@ bool nsQEventHandler::MoveEvent(QMoveEvent * event, nsWidget * widget)
return true;
}
bool nsQEventHandler::PaintEvent(QPaintEvent * event, nsWidget * widget)
bool nsQEventHandler::PaintEvent(QPaintEvent *event,
nsWidget *widget)
{
if (event && widget) {
// Generate XPFE paint event
@ -566,26 +606,23 @@ bool nsQEventHandler::PaintEvent(QPaintEvent * event, nsWidget * widget)
widget->GetName(),
widget));
nsEvent.message = NS_PAINT;
nsEvent.widget = widget;
nsEvent.message = NS_PAINT;
nsEvent.widget = widget;
nsEvent.eventStructType = NS_PAINT_EVENT;
nsEvent.time = PR_IntervalNow();
nsEvent.time = PR_IntervalNow();
QRect qrect = event->rect();
PR_LOG(QtEventsLM,
PR_LOG_DEBUG,
PR_LOG(QtEventsLM,PR_LOG_DEBUG,
("nsQEventHandler::PaintEvent: need to paint:x=%d,y=%d,w=%d,h=%d\n",
qrect.x(), qrect.y(), qrect.width(), qrect.height()));
event->rect().x(),event->rect().y(),
event->rect().width(),event->rect().height()));
nsRect * rect = new nsRect(qrect.x(), qrect.y(), qrect.width(), qrect.height());
nsEvent.rect = rect;
nsRect rect(event->rect().x(),event->rect().y(),
event->rect().width(),event->rect().height());
nsEvent.rect = &rect;
widget->AddRef();
widget->OnPaint(nsEvent);
widget->Release();
delete rect;
}
if (widget && widget->GetName() == QWidget::tr("nsWindow")
|| widget->GetName() == QWidget::tr("nsWidget")) {
@ -596,7 +633,8 @@ bool nsQEventHandler::PaintEvent(QPaintEvent * event, nsWidget * widget)
}
}
bool nsQEventHandler::KeyPressEvent(QKeyEvent * event, nsWidget * widget)
bool nsQEventHandler::KeyPressEvent(QKeyEvent *event,
nsWidget *widget)
{
if (event && widget) {
PR_LOG(QtEventsLM,
@ -604,8 +642,9 @@ bool nsQEventHandler::KeyPressEvent(QKeyEvent * event, nsWidget * widget)
("nsQEventHandler::KeyPressEvent for %s\n",
widget->GetName()));
if (event->key() == Qt::Key_Shift || event->key() == Qt::Key_Control
|| event->key() == Qt::Key_Alt)
if (event->key() == Qt::Key_Shift
|| event->key() == Qt::Key_Control
|| event->key() == Qt::Key_Alt)
return false;
nsKeyEvent nsEvent;
@ -613,29 +652,29 @@ bool nsQEventHandler::KeyPressEvent(QKeyEvent * event, nsWidget * widget)
nsEvent.message = NS_KEY_DOWN;
nsEvent.eventStructType = NS_KEY_EVENT;
nsEvent.widget = widget;
nsEvent.keyCode = GetNSKey(event->key(), event->state());
nsEvent.isShift = (event->state() & ShiftButton) ? PR_TRUE : PR_FALSE;
nsEvent.isControl = (event->state() & ControlButton) ? PR_TRUE : PR_FALSE;
nsEvent.isAlt = (event->state() & AltButton) ? PR_TRUE : PR_FALSE;
nsEvent.keyCode = GetNSKey(event->key(),event->state());
nsEvent.isShift = event->state() & ShiftButton;
nsEvent.isControl = event->state() & ControlButton;
nsEvent.isAlt = event->state() & AltButton;
nsEvent.isMeta = PR_FALSE;
nsEvent.point.x = 0;
nsEvent.point.y = 0;
nsEvent.time = PR_IntervalNow();
nsEvent.time = PR_IntervalNow();
nsEvent.charCode = 0;
widget->AddRef();
((nsWindow *)widget)->OnKey(nsEvent);
((nsWindow*)widget)->OnKey(nsEvent);
nsEvent.message = NS_KEY_PRESS;
nsEvent.eventStructType = NS_KEY_EVENT;
nsEvent.widget = widget;
nsEvent.isShift = (event->state() & ShiftButton) ? PR_TRUE : PR_FALSE;
nsEvent.isControl = (event->state() & ControlButton) ? PR_TRUE : PR_FALSE;
nsEvent.isAlt = (event->state() & AltButton) ? PR_TRUE : PR_FALSE;
nsEvent.isShift = event->state() & ShiftButton;
nsEvent.isControl = event->state() & ControlButton;
nsEvent.isAlt = event->state() & AltButton;
nsEvent.isMeta = PR_FALSE;
nsEvent.point.x = 0;
nsEvent.point.y = 0;
nsEvent.time = PR_IntervalNow();
nsEvent.time = PR_IntervalNow();
if (event->text().length() && event->text()[0].isPrint()) {
nsEvent.charCode = (PRInt32)event->text()[0].unicode();
}
@ -647,15 +686,16 @@ bool nsQEventHandler::KeyPressEvent(QKeyEvent * event, nsWidget * widget)
nsEvent.isShift = PR_FALSE;
}
else
nsEvent.keyCode = GetNSKey(event->key(), event->state());
nsEvent.keyCode = GetNSKey(event->key(),event->state());
((nsWindow *)widget)->OnKey(nsEvent);
((nsWindow*)widget)->OnKey(nsEvent);
widget->Release();
}
return true;
}
bool nsQEventHandler::KeyReleaseEvent(QKeyEvent * event, nsWidget * widget)
bool nsQEventHandler::KeyReleaseEvent(QKeyEvent *event,
nsWidget *widget)
{
if (event && widget) {
@ -670,26 +710,27 @@ bool nsQEventHandler::KeyReleaseEvent(QKeyEvent * event, nsWidget * widget)
nsKeyEvent nsEvent;
nsEvent.message = NS_KEY_UP;
nsEvent.message = NS_KEY_UP;
nsEvent.eventStructType = NS_KEY_EVENT;
nsEvent.widget = widget;
nsEvent.charCode = 0;
nsEvent.keyCode = GetNSKey(event->key(), event->state());
nsEvent.isShift = event->state() & ShiftButton;
nsEvent.isControl = event->state() & ControlButton;
nsEvent.isAlt = event->state() & AltButton;
nsEvent.isMeta = PR_FALSE;
nsEvent.time = PR_IntervalNow();
nsEvent.widget = widget;
nsEvent.charCode = 0;
nsEvent.keyCode = GetNSKey(event->key(), event->state());
nsEvent.isShift = event->state() & ShiftButton;
nsEvent.isControl = event->state() & ControlButton;
nsEvent.isAlt = event->state() & AltButton;
nsEvent.isMeta = PR_FALSE;
nsEvent.time = PR_IntervalNow();
widget->AddRef();
((nsWindow *)widget)->OnKey(nsEvent);
((nsWindow*)widget)->OnKey(nsEvent);
widget->Release();
}
return true;
}
PRInt32 nsQEventHandler::GetNSKey(PRInt32 key, PRInt32 state)
#if 0 //JCG
PRInt32 nsQEventHandler::GetNSKey(PRInt32 key,PRInt32 state)
{
PRInt32 nsKey = 0;
PRInt32 length = sizeof(nsKeycodes) / sizeof(nsKeyConverter);
for (PRInt32 i = 0; i < length; i++) {
@ -697,10 +738,12 @@ PRInt32 nsQEventHandler::GetNSKey(PRInt32 key, PRInt32 state)
return nsKeycodes[i].vkCode;
}
}
return nsKey;
return 0;
}
#endif //JCG
bool nsQEventHandler::FocusInEvent(QFocusEvent * event, nsWidget * widget)
bool nsQEventHandler::FocusInEvent(QFocusEvent *event,
nsWidget *widget)
{
if (event && widget) {
nsGUIEvent aEvent;
@ -713,17 +756,19 @@ bool nsQEventHandler::FocusInEvent(QFocusEvent * event, nsWidget * widget)
aEvent.message = NS_GOTFOCUS;
aEvent.eventStructType = NS_GUI_EVENT;
aEvent.widget = widget;
aEvent.time = PR_IntervalNow();
aEvent.point.x = 0;
aEvent.point.y = 0;
aEvent.time = PR_IntervalNow();
aEvent.point.x = 0;
aEvent.point.y = 0;
widget->AddRef();
((nsWindow *)widget)->DispatchFocus(aEvent);
((nsWindow*)widget)->DispatchFocus(aEvent);
widget->Release();
}
return true;
}
bool nsQEventHandler::FocusOutEvent(QFocusEvent * event, nsWidget * widget)
bool nsQEventHandler::FocusOutEvent(QFocusEvent *event,
nsWidget *widget)
{
if (event && widget) {
nsGUIEvent aEvent;
@ -736,12 +781,12 @@ bool nsQEventHandler::FocusOutEvent(QFocusEvent * event, nsWidget * widget)
aEvent.message = NS_LOSTFOCUS;
aEvent.eventStructType = NS_GUI_EVENT;
aEvent.widget = widget;
aEvent.time = PR_IntervalNow();
aEvent.point.x = 0;
aEvent.point.y = 0;
aEvent.time = PR_IntervalNow();
aEvent.point.x = 0;
aEvent.point.y = 0;
widget->AddRef();
((nsWindow *)widget)->DispatchFocus(aEvent);
((nsWindow*)widget)->DispatchFocus(aEvent);
widget->Release();
}
return true;

View File

@ -18,14 +18,12 @@
* Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
*
*/
#ifndef __nsQTEventHandler_h
#define __nsQTEventHandler_h
class nsIWidget;
class nsIMenuItem;
#include "nsWidget.h"
#include <qobject.h>
@ -40,7 +38,7 @@ public:
~nsQEventHandler();
void Enable(bool aEnable);
void Destroy(void);
void Destroy();
bool eventFilter(QObject * object, QEvent * event);
bool MouseButtonEvent(QMouseEvent *event,nsWidget *widget,
@ -62,9 +60,9 @@ protected:
PRInt32 GetNSKey(PRInt32 key, PRInt32 state);
private:
nsWidget * mWidget;
bool mEnabled;
bool mDestroyed;
nsWidget *mWidget;
bool mEnabled;
bool mDestroyed;
};
#endif // __nsQEventHandler.h

1069
widget/src/qt/nsQWidget.cpp Normal file

File diff suppressed because it is too large Load Diff

166
widget/src/qt/nsQWidget.h Normal file
View File

@ -0,0 +1,166 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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 Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
* Denis Issoupov <denis@macadamian.com>
*
*/
#ifndef nsQWidget_h__
#define nsQWidget_h__
#include <qwidget.h>
#include <qstring.h>
#include "nsIWidget.h"
class nsFontQT;
class nsWidget;
/* Utility Functions */
PRBool NS_IsMouseInWindow(void *aWin,PRInt32 aMouseX,PRInt32 aMouseY);
unsigned int NS_GetQWFlags(nsBorderStyle aBorder,nsWindowType aType);
//=============================================================================
// nsQWidget class:
// Customizes QWidget for use in XPFE
//=============================================================================
class nsQWidget : public QWidget
{
Q_OBJECT
public:
nsQWidget(QWidget *aParent,const char *aName = 0,WFlags aFlags = WResizeNoErase);
virtual ~nsQWidget();
virtual void SetModal(PRBool aState);
private:
PRUint32 mQWidgetID;
};
//=============================================================================
// nsQBaseWidget class
// Provides a "two-way" interface, allowing XPFE to access Qt Widget
// functionality and hooking the relevant Qt Events into the XPFE Event
// Handling
//=============================================================================
class nsQBaseWidget : public QObject
{
Q_OBJECT
public:
nsQBaseWidget(nsWidget *aWidget);
virtual ~nsQBaseWidget();
/*** Lifecycle Management ***/
PRBool CreateNative(QWidget *aParent = 0,const char *aName = 0,
unsigned int aFlags = WResizeNoErase);
virtual void Destroy();
/*** Interface to Qt Widget functionality for XPFE ***/
void Enable(PRBool aState);
PRBool HandlePopup(void *aEvent);
virtual void SetCursor(nsCursor aCursor);
virtual void SetFont(nsFontQT *aFont);
virtual void SetModal(PRBool aState)
{
((nsQWidget*)mQWidget)->SetModal(aState);
};
virtual const char *Name() {return mQWidget->name();};
virtual int Width() {return mQWidget->width();};
virtual int Height() {return mQWidget->height();};
virtual int BoundsX() {return 0;};
virtual int BoundsY() {return 0;};
virtual void OffsetXYToGlobal(PRInt32 *aX,PRInt32 *aY)
{
QPoint offset(0,0);
offset = mQWidget->mapToGlobal(offset);
*aX = offset.x();
*aY = offset.y();
};
virtual void OffsetXYFromGlobal(PRInt32 *aX,PRInt32 *aY)
{
QPoint offset(0,0);
offset = mQWidget->mapFromGlobal(offset);
*aX = offset.x();
*aY = offset.y();
};
virtual void Move(PRInt32 aX,PRInt32 aY) {mQWidget->move(aX,aY);};
virtual void Resize(PRInt32 aW,PRInt32 aH) {mQWidget->resize(aW,aH);};
virtual void Scroll(PRInt32 aDx,PRInt32 aDy) {mQWidget->scroll(aDx,aDy);};
virtual void Show() {mQWidget->show();};
virtual void Hide() {mQWidget->hide();};
virtual bool IsVisible() {return mQWidget->isVisible();};
virtual void SetFocus() {mQWidget->setFocus();};
virtual void SetTitle(const char *aTitleStr)
{
mQWidget->setCaption(QString::fromLocal8Bit(aTitleStr));
};
virtual void SetBackgroundColor(const nscolor &aColor)
{
QColor color(NS_GET_R(aColor),NS_GET_G(aColor),NS_GET_B(aColor));
mQWidget->setBackgroundColor(color);
};
virtual void Repaint(PRBool aErase) {mQWidget->repaint(aErase);};
virtual void Repaint(PRInt32 aX,PRInt32 aY,PRInt32 aW, PRInt32 aH,PRBool aErase)
{
mQWidget->repaint(aX,aY,aW,aH,aErase);
};
virtual void Update() {mQWidget->update();};
virtual void Update(PRInt32 aX,PRInt32 aY,PRInt32 aW, PRInt32 aH)
{
mQWidget->update(aX,aY,aW,aH);
};
virtual void *GetNativeWindow() {return((void*)(QPaintDevice*)mQWidget);};
virtual void *GetNativeWidget() {return((void*)mQWidget);};
virtual void* X11Display() {return (void*)mQWidget->x11Display();};
virtual void* WinID() {return (void*)mQWidget->winId();};
/*** Interface to XPFE Event Handling from Qt ***/
bool eventFilter(QObject *aObj,QEvent *aEvent);
virtual PRBool MouseButtonEvent(QMouseEvent *aEvent,PRBool aButtonDown,
int aClickCount);
virtual PRBool MouseMovedEvent(QMouseEvent *aEvent);
virtual PRBool MouseEnterEvent(QEvent *aEvent);
virtual PRBool MouseExitEvent(QEvent *aEvent);
virtual PRBool DestroyEvent();
virtual PRBool ResizeEvent(QResizeEvent *aEvent);
virtual PRBool MoveEvent(QMoveEvent *aEvent);
virtual PRBool PaintEvent(QPaintEvent *aEvent);
virtual PRBool KeyPressEvent(QKeyEvent *aEvent);
virtual PRBool KeyReleaseEvent(QKeyEvent *aEvent);
virtual PRBool FocusInEvent();
virtual PRBool FocusOutEvent();
virtual PRBool DragEnterEvent(QDragEnterEvent *aEvent);
virtual PRBool DragMoveEvent(QDragMoveEvent *aEvent);
virtual PRBool DragLeaveEvent(QDragLeaveEvent *aEvent);
virtual PRBool DropEvent(QDropEvent *aEvent);
protected:
nsWidget *mWidget;
QWidget *mQWidget;
PRBool mEnabled;
PRBool mDestroyed;
private:
PRUint32 mQBaseID;
};
#endif //nsQWidget_h__

View File

@ -18,442 +18,371 @@
* Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
*
*/
#include "nsScrollbar.h"
#include "nsToolkit.h"
#include "nsGUIEvent.h"
#include "nsUnitConversion.h"
#include "nsWindow.h"
PRLogModuleInfo * QtScrollLM = PR_NewLogModule("QtScroll");
//JCG #define DBG_JCG 1
#ifdef DBG_JCG
PRUint32 gQBaseSBCount = 0;
PRUint32 gQBaseSBID = 0;
PRUint32 gQSBCount = 0;
PRUint32 gQSBID = 0;
PRUint32 gNsSBCount = 0;
PRUint32 gNsSBID = 0;
#endif
//=============================================================================
//
// nsQScrollBar class
//
// nsQBaseScrollBar class
//=============================================================================
nsQScrollBar::nsQScrollBar(nsWidget * widget,
int minValue,
int maxValue,
int LineStep,
int PageStep,
int value,
Orientation orientation,
QWidget * parent,
const char * name)
: QScrollBar(minValue,
maxValue,
LineStep,
PageStep,
value,
orientation,
parent,
name),
nsQBaseWidget(widget)
nsQBaseScrollBar::nsQBaseScrollBar(nsWidget *aWidget)
: nsQBaseWidget(aWidget)
{
connect((QScrollBar *)this,
SIGNAL(valueChanged(int)),
SLOT(SetValue(int)));
#ifdef DBG_JCG
gQBaseSBCount++;
mQBaseSBID = gQBaseSBID++;
printf("JCG: nsQBaseScrollBar CTOR (%p) ID: %d, Count: %d\n",
this,mQBaseSBID,gQBaseSBCount);
#endif
}
nsQBaseScrollBar::~nsQBaseScrollBar()
{
#ifdef DBG_JCG
gQBaseSBCount--;
printf("JCG: nsQBaseScrollBar DTOR (%p) ID: %d, Count: %d\n",
this,mQBaseSBID,gQBaseSBCount);
#endif
}
void nsQBaseScrollBar::ValueChanged(int aValue)
{
ScrollBarMoved(NS_SCROLLBAR_POS,aValue);
}
void nsQBaseScrollBar::ScrollBarMoved(int aMessage,int aValue)
{
if (mWidget) {
nsScrollbarEvent nsEvent;
nsEvent.message = aMessage;
nsEvent.widget = mWidget;
nsEvent.eventStructType = NS_SCROLLBAR_EVENT;
nsEvent.position = aValue;
((nsScrollbar*)mWidget)->OnScroll(nsEvent,aValue);
}
}
PRBool nsQBaseScrollBar::CreateNative(int aMinValue,int aMaxValue,
int aLineStep,int aPageStep,int aValue,
Orientation aOrientation,QWidget *aParent,
const char *aName)
{
if (!(mQWidget = new nsQScrollBar(aMinValue,aMaxValue,aLineStep,aPageStep,aValue,
aOrientation,aParent,aName))) {
return PR_FALSE;
}
connect((QScrollBar*)mQWidget,SIGNAL(valueChanged(int)),this,SLOT(ValueChanged(int)));
mQWidget->installEventFilter(this);
return PR_TRUE;
}
void nsQBaseScrollBar::Destroy()
{
mEnabled = PR_FALSE;
if (mWidget) {
mWidget = nsnull;
}
}
PRBool nsQBaseScrollBar::MouseButtonEvent(QMouseEvent *aEvent,PRBool aButtonDown,
int aClickCount)
{
return PR_FALSE;
}
PRBool nsQBaseScrollBar::MouseMovedEvent(QMouseEvent *aEvent)
{
return PR_FALSE;
}
PRBool nsQBaseScrollBar::PaintEvent(QPaintEvent *aEvent)
{
return PR_FALSE;
}
//=============================================================================
// nsQScrollBar class
//=============================================================================
nsQScrollBar::nsQScrollBar(int aMinValue,int aMaxValue,
int aLineStep,int aPageStep,int aValue,
Orientation aOrientation,QWidget *aParent,
const char *aName)
: QScrollBar(aMinValue,aMaxValue,aLineStep,aPageStep,aValue,
aOrientation,aParent,aName)
{
#ifdef DBG_JCG
gQSBCount++;
mQSBID = gQSBID++;
printf("JCG: nsQScrollBar CTOR (%p) ID: %d, Count: %d\n",this,mQSBID,gQSBCount);
#endif
setMouseTracking(PR_TRUE);
setTracking(PR_TRUE);
}
nsQScrollBar::~nsQScrollBar()
{
#ifdef DBG_JCG
gQSBCount--;
printf("JCG: nsQScrollBar DTOR (%p) ID: %d, Count: %d\n",this,mQSBID,gQSBCount);
#endif
}
void nsQScrollBar::SetValue(int value)
void nsQScrollBar::closeEvent(QCloseEvent *aEvent)
{
PR_LOG(QtScrollLM,
PR_LOG_DEBUG,
("nsQScrollBar::SetValue: setting %d\n",
value));
ScrollBarMoved(NS_SCROLLBAR_POS, value);
aEvent->ignore();
}
void nsQScrollBar::PreviousLine()
{
PR_LOG(QtScrollLM,
PR_LOG_DEBUG,
("nsQScrollBar::PreviousLine()\n"));
ScrollBarMoved(NS_SCROLLBAR_LINE_PREV);
}
void nsQScrollBar::NextLine()
{
PR_LOG(QtScrollLM,
PR_LOG_DEBUG,
("nsQScrollBar::NextLine()\n"));
ScrollBarMoved(NS_SCROLLBAR_LINE_NEXT);
}
void nsQScrollBar::PreviousPage()
{
PR_LOG(QtScrollLM,
PR_LOG_DEBUG,
("nsQScrollBar::PreviousPage()\n"));
ScrollBarMoved(NS_SCROLLBAR_PAGE_PREV);
}
void nsQScrollBar::NextPage()
{
PR_LOG(QtScrollLM,
PR_LOG_DEBUG,
("nsQScrollBar::NextPage()\n"));
ScrollBarMoved(NS_SCROLLBAR_PAGE_NEXT);
}
void nsQScrollBar::ScrollBarMoved(int message, int value)
{
PR_LOG(QtScrollLM,
PR_LOG_DEBUG,
("nsQScrollBar::ScrollBarMoved()\n"));
if (mWidget)
{
nsScrollbarEvent nsEvent;
nsEvent.message = message;
nsEvent.widget = mWidget;
NS_IF_ADDREF(nsEvent.widget);
nsEvent.eventStructType = NS_SCROLLBAR_EVENT;
nsEvent.position = value;
((nsScrollbar *)mWidget)->OnScroll(nsEvent, value);
NS_IF_RELEASE(nsEvent.widget);
}
}
void nsQScrollBar::closeEvent(QCloseEvent *ce)
{
ce->ignore();
}
NS_IMPL_ADDREF_INHERITED(nsScrollbar, nsWidget);
NS_IMPL_RELEASE_INHERITED(nsScrollbar, nsWidget);
NS_IMPL_QUERY_INTERFACE2(nsScrollbar, nsIScrollbar, nsIWidget)
//=============================================================================
// nsScrollBar class
//=============================================================================
NS_IMPL_ADDREF_INHERITED(nsScrollbar,nsWidget);
NS_IMPL_RELEASE_INHERITED(nsScrollbar,nsWidget);
NS_IMPL_QUERY_INTERFACE2(nsScrollbar,nsIScrollbar,nsIWidget)
//-------------------------------------------------------------------------
//
// nsScrollbar constructor
//
//-------------------------------------------------------------------------
nsScrollbar::nsScrollbar(PRBool aIsVertical) : nsWidget (), nsIScrollbar ()
nsScrollbar::nsScrollbar(PRBool aIsVertical) : nsWidget(), nsIScrollbar()
{
PR_LOG(QtScrollLM,
PR_LOG_DEBUG,
("nsScrollBar::nsScrollbar()\n"));
mOrientation = aIsVertical ? QScrollBar::Vertical : QScrollBar::Horizontal;
mLineStep = 1;
mPageStep = 10;
mMaxValue = 100;
mValue = 0;
mListenForResizes = PR_TRUE;
#ifdef DBG_JCG
gNsSBCount++;
mNsSBID = gNsSBID++;
printf("JCG: nsScrollBar CTOR (%p) ID: %d, Count: %d\n",this,mNsSBID,gNsSBCount);
#endif
mOrientation = aIsVertical ? QScrollBar::Vertical : QScrollBar::Horizontal;
mLineStep = 1;
mPageStep = 10;
mMaxValue = 100;
mValue = 0;
mListenForResizes = PR_TRUE;
}
//-------------------------------------------------------------------------
//
// nsScrollbar destructor
//
//-------------------------------------------------------------------------
nsScrollbar::~nsScrollbar()
{
PR_LOG(QtScrollLM,
PR_LOG_DEBUG,
("nsScrollBar::~nsScrollbar()\n"));
#ifdef DBG_JCG
gNsSBCount--;
printf("JCG: nsScrollBar DTOR (%p) ID: %d, Count: %d\n",this,mNsSBID,gNsSBCount);
#endif
}
//-------------------------------------------------------------------------
//
// Define the range settings
//
//-------------------------------------------------------------------------
NS_METHOD nsScrollbar::SetMaxRange(PRUint32 aEndRange)
{
PR_LOG(QtScrollLM,
PR_LOG_DEBUG,
("nsScrollBar::SetMaxRange()\n"));
mMaxValue = aEndRange;
((QScrollBar*)mWidget)->setRange(0, mMaxValue - mPageStep);
return NS_OK;
mMaxValue = aEndRange;
((nsQBaseScrollBar*)mWidget)->SetRange(0,mMaxValue - mPageStep);
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Return the range settings
//
//-------------------------------------------------------------------------
NS_METHOD nsScrollbar::GetMaxRange(PRUint32 & aMaxRange)
NS_METHOD nsScrollbar::GetMaxRange(PRUint32 &aMaxRange)
{
PR_LOG(QtScrollLM,
PR_LOG_DEBUG,
("nsScrollBar::GetMaxRange: %d\n",
aMaxRange));
aMaxRange = mMaxValue;
return NS_OK;
aMaxRange = mMaxValue;
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Set the thumb position
//
//-------------------------------------------------------------------------
NS_METHOD nsScrollbar::SetPosition(PRUint32 aPos)
{
PR_LOG(QtScrollLM,
PR_LOG_DEBUG,
("nsScrollBar::SetPosition()\n"));
mValue = aPos;
((QScrollBar*)mWidget)->setValue(mValue);
return NS_OK;
mValue = aPos;
((nsQBaseScrollBar*)mWidget)->SetValue(mValue);
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Get the current thumb position.
//
//-------------------------------------------------------------------------
NS_METHOD nsScrollbar::GetPosition(PRUint32 & aPos)
NS_METHOD nsScrollbar::GetPosition(PRUint32 &aPos)
{
PR_LOG(QtScrollLM,
PR_LOG_DEBUG,
("nsScrollBar::GetPosition %u\n",
mValue));
aPos = mValue;
return NS_OK;
aPos = mValue;
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Set the thumb size
//
//-------------------------------------------------------------------------
NS_METHOD nsScrollbar::SetThumbSize(PRUint32 aSize)
{
PR_LOG(QtScrollLM,
PR_LOG_DEBUG,
("nsScrollBar::SetThumbSize()\n"));
if (aSize > 0)
{
mPageStep = aSize;
if (aSize > 0) {
mPageStep = aSize;
((QScrollBar*)mWidget)->setSteps(mLineStep, mPageStep);
}
return NS_OK;
((nsQBaseScrollBar*)mWidget)->SetSteps(mLineStep,mPageStep);
}
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Get the thumb size
//
//-------------------------------------------------------------------------
NS_METHOD nsScrollbar::GetThumbSize(PRUint32 & aThumbSize)
NS_METHOD nsScrollbar::GetThumbSize(PRUint32 &aThumbSize)
{
PR_LOG(QtScrollLM,
PR_LOG_DEBUG,
("nsScrollBar::GetThumbSize: %u\n",
mPageStep));
aThumbSize = mPageStep;
return NS_OK;
aThumbSize = mPageStep;
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Set the line increment for this scrollbar
//
//-------------------------------------------------------------------------
NS_METHOD nsScrollbar::SetLineIncrement(PRUint32 aLineIncrement)
{
PR_LOG(QtScrollLM,
PR_LOG_DEBUG,
("nsScrollBar::SetLineIncrement\n"));
if (aLineIncrement > 0)
{
mLineStep = aLineIncrement;
if (aLineIncrement > 0) {
mLineStep = aLineIncrement;
((QScrollBar*)mWidget)->setSteps(mLineStep, mPageStep);
}
return NS_OK;
((nsQBaseScrollBar*)mWidget)->SetSteps(mLineStep,mPageStep);
}
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Get the line increment for this scrollbar
//
//-------------------------------------------------------------------------
NS_METHOD nsScrollbar::GetLineIncrement(PRUint32 & aLineInc)
NS_METHOD nsScrollbar::GetLineIncrement(PRUint32 &aLineInc)
{
PR_LOG(QtScrollLM,
PR_LOG_DEBUG,
("nsScrollBar::GetLineIncrement: %u\n",
mLineStep));
aLineInc = mLineStep;
return NS_OK;
aLineInc = mLineStep;
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Set all scrolling parameters
//
//-------------------------------------------------------------------------
NS_METHOD nsScrollbar::SetParameters(PRUint32 aMaxRange,
PRUint32 aThumbSize,
PRUint32 aPosition,
PRUint32 aLineIncrement)
NS_METHOD nsScrollbar::SetParameters(PRUint32 aMaxRange,PRUint32 aThumbSize,
PRUint32 aPosition,PRUint32 aLineIncrement)
{
PR_LOG(QtScrollLM,
PR_LOG_DEBUG,
("nsScrollBar::SetParameters: max=%d,thumb=%d,pos=%d,inc=%d\n",
aMaxRange,
aThumbSize,
aPosition,
aLineIncrement));
mPageStep = (int)(((int)aThumbSize > 0) ? aThumbSize : 1);
mValue = (int)(((int)aPosition > 0) ? aPosition : 0);
mLineStep = (int)(((int)aLineIncrement > 0) ? aLineIncrement : 1);
mMaxValue = (int)(((int)aMaxRange > 0) ? aMaxRange : 10);
mPageStep = (aThumbSize > 0) ? aThumbSize : 1;
mValue = (aPosition > 0) ? aPosition : 0;
mLineStep = (aLineIncrement > 0) ? aLineIncrement : 1;
mMaxValue = (aMaxRange > 0) ? aMaxRange : 10;
((QScrollBar*)mWidget)->setValue(mValue);
((QScrollBar*)mWidget)->setSteps(mLineStep, mPageStep);
((QScrollBar*)mWidget)->setRange(0, mMaxValue - mPageStep);
return NS_OK;
((nsQBaseScrollBar*)mWidget)->SetValue(mValue);
((nsQBaseScrollBar*)mWidget)->SetSteps(mLineStep,mPageStep);
((nsQBaseScrollBar*)mWidget)->SetRange(0,mMaxValue - mPageStep);
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Deal with scrollbar messages (actually implemented only in nsScrollbar)
//
//-------------------------------------------------------------------------
PRBool nsScrollbar::OnScroll(nsScrollbarEvent & aEvent, PRUint32 cPos)
PRBool nsScrollbar::OnScroll(nsScrollbarEvent &aEvent,PRUint32 cPos)
{
PR_LOG(QtScrollLM,
PR_LOG_DEBUG,
("nsScrollBar::OnScroll()\n"));
PRBool result = PR_TRUE;
PRBool result = PR_TRUE;
switch (aEvent.message)
{
// scroll one line right or down
case NS_SCROLLBAR_LINE_NEXT:
((QScrollBar*)mWidget)->addLine();
mValue = ((QScrollBar*)mWidget)->value();
switch (aEvent.message) {
// scroll one line right or down
case NS_SCROLLBAR_LINE_NEXT:
((nsQBaseScrollBar*)mWidget)->AddLine();
mValue = ((nsQBaseScrollBar*)mWidget)->Value();
// if an event callback is registered, give it the chance
// to change the increment
if (mEventCallback)
{
aEvent.position = (PRUint32) mValue;
result = ConvertStatus ((*mEventCallback) (&aEvent));
mValue = aEvent.position;
}
break;
// if an event callback is registered, give it the chance
// to change the increment
if (mEventCallback) {
aEvent.position = (PRUint32)mValue;
result = ConvertStatus((*mEventCallback)(&aEvent));
mValue = aEvent.position;
}
break;
// scroll one line left or up
case NS_SCROLLBAR_LINE_PREV:
((QScrollBar*)mWidget)->subtractLine();
mValue = ((QScrollBar*)mWidget)->value();
// scroll one line left or up
case NS_SCROLLBAR_LINE_PREV:
((nsQBaseScrollBar*)mWidget)->SubtractLine();
mValue = ((nsQBaseScrollBar*)mWidget)->Value();
// if an event callback is registered, give it the chance
// to change the decrement
if (mEventCallback)
{
aEvent.position = (PRUint32) mValue;
result = ConvertStatus ((*mEventCallback) (&aEvent));
mValue = aEvent.position;
}
break;
// if an event callback is registered, give it the chance
// to change the decrement
if (mEventCallback) {
aEvent.position = (PRUint32)mValue;
result = ConvertStatus((*mEventCallback)(&aEvent));
mValue = aEvent.position;
}
break;
// Scrolls one page right or down
case NS_SCROLLBAR_PAGE_NEXT:
((QScrollBar*)mWidget)->addPage();
mValue = ((QScrollBar*)mWidget)->value();
// Scrolls one page right or down
case NS_SCROLLBAR_PAGE_NEXT:
((nsQBaseScrollBar*)mWidget)->AddPage();
mValue = ((nsQBaseScrollBar*)mWidget)->Value();
// if an event callback is registered, give it the chance
// to change the increment
if (mEventCallback)
{
aEvent.position = (PRUint32) mValue;
result = ConvertStatus ((*mEventCallback) (&aEvent));
mValue = aEvent.position;
}
break;
// if an event callback is registered, give it the chance
// to change the increment
if (mEventCallback) {
aEvent.position = (PRUint32)mValue;
result = ConvertStatus((*mEventCallback)(&aEvent));
mValue = aEvent.position;
}
break;
// Scrolls one page left or up.
case NS_SCROLLBAR_PAGE_PREV:
((QScrollBar*)mWidget)->subtractPage();
mValue = ((QScrollBar*)mWidget)->value();
// Scrolls one page left or up.
case NS_SCROLLBAR_PAGE_PREV:
((nsQBaseScrollBar*)mWidget)->SubtractPage();
mValue = ((nsQBaseScrollBar*)mWidget)->Value();
// if an event callback is registered, give it the chance
// to change the increment
if (mEventCallback)
{
aEvent.position = (PRUint32) mValue;
result = ConvertStatus ((*mEventCallback) (&aEvent));
mValue = aEvent.position;
}
break;
// if an event callback is registered, give it the chance
// to change the increment
if (mEventCallback) {
aEvent.position = (PRUint32)mValue;
result = ConvertStatus((*mEventCallback)(&aEvent));
mValue = aEvent.position;
}
break;
// Scrolls to the absolute position. The current position is specified by
// the cPos parameter.
case NS_SCROLLBAR_POS:
mValue = cPos;
// Scrolls to the absolute position. The current position is specified by
// the cPos parameter.
case NS_SCROLLBAR_POS:
mValue = cPos;
// if an event callback is registered, give it the chance
// to change the increment
if (mEventCallback)
{
aEvent.position = (PRUint32) mValue;
result = ConvertStatus ((*mEventCallback) (&aEvent));
mValue = aEvent.position;
}
break;
// if an event callback is registered, give it the chance
// to change the increment
if (mEventCallback) {
aEvent.position = (PRUint32)mValue;
result = ConvertStatus((*mEventCallback)(&aEvent));
mValue = aEvent.position;
}
break;
}
return result;
}
//-------------------------------------------------------------------------
//
// Create the native scrollbar widget
//
//-------------------------------------------------------------------------
NS_METHOD nsScrollbar::CreateNative(QWidget * parentWindow)
NS_METHOD nsScrollbar::CreateNative(QWidget *aParentWindow)
{
PR_LOG(QtScrollLM,
PR_LOG_DEBUG,
("nsScrollBar::CreateNative: max=%d, linestep=%d, pagestep=%d\n",
mMaxValue,
mLineStep,
mPageStep));
mWidget = new nsQScrollBar(this, 0, mMaxValue, mLineStep, mPageStep,
mValue, mOrientation, parentWindow,
QScrollBar::tr("nsScrollBar"));
if (mWidget) {
((QScrollBar*)mWidget)->setTracking(true);
}
return nsWidget::CreateNative(parentWindow);
}
mWidget = new nsQBaseScrollBar(this);
const char *nsScrollbar::GetName()
{
return nsWidget::GetName();
if (!mWidget)
return NS_ERROR_OUT_OF_MEMORY;
if (!((nsQBaseScrollBar*)mWidget)->CreateNative(0,mMaxValue,mLineStep,mPageStep,
mValue,mOrientation,aParentWindow,
QScrollBar::tr("nsScrollBar"))) {
delete mWidget;
mWidget = nsnull;
return NS_ERROR_OUT_OF_MEMORY;
}
return nsWidget::CreateNative(aParentWindow);
}

View File

@ -18,88 +18,124 @@
* Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
*
*/
#ifndef nsScrollbar_h__
#define nsScrollbar_h__
#include "nsWidget.h"
#include "nsWindow.h"
#include "nsQWidget.h"
#include "nsIScrollbar.h"
#include <qscrollbar.h>
#include <qevent.h>
//=============================================================================
//
// nsQScrollBar class
//
// nsQScrollBar class:
// Provides a "two-way" interface, allowing XPFE to access Qt Scrollbar
// functionality and hooking the relevant Qt Events into the XPFE Event
// Handling. Inherits basic functionality from nsQBaseWidget.
//=============================================================================
class nsQScrollBar : public QScrollBar, public nsQBaseWidget
class nsQBaseScrollBar : public nsQBaseWidget
{
Q_OBJECT
Q_OBJECT
public:
nsQScrollBar(nsWidget * widget,
int minValue,
int maxValue,
int LineStep,
int PageStep,
int value,
Orientation orientation,
QWidget * parent,
const char * name=0 );
~nsQScrollBar();
nsQBaseScrollBar(nsWidget *aWidget);
~nsQBaseScrollBar();
void ScrollBarMoved(int message, int value = -1);
void closeEvent(QCloseEvent *ce);
/*** Lifecycle Management ***/
PRBool CreateNative(int aMinValue,int aMaxValue,
int aLineStep,int aPageStep,int aValue,
Orientation aOrientation,QWidget *aParent,
const char *aName = 0);
virtual void Destroy();
/*** Interface to Qt ScrollBar functionality for XPFE ***/
virtual void SetModal(PRBool aState) {};
void SetRange(PRUint32 aMin,PRUint32 aMax) {((QScrollBar*)mQWidget)->setRange(aMin,aMax);};
void SetValue(PRUint32 aValue) {((QScrollBar*)mQWidget)->setValue(aValue);};
void SetSteps(PRUint32 aLineStep,PRUint32 aPageStep)
{
((QScrollBar*)mQWidget)->setSteps(aLineStep,aPageStep);
};
void AddLine() {((QScrollBar*)mQWidget)->addLine();};
void SubtractLine() {((QScrollBar*)mQWidget)->subtractLine();};
void AddPage() {((QScrollBar*)mQWidget)->addPage();};
void SubtractPage() {((QScrollBar*)mQWidget)->subtractPage();};
int Value() {return(((QScrollBar*)mQWidget)->value());};
/*** Interface to XPFE Event Handling from Qt ***/
virtual PRBool MouseButtonEvent(QMouseEvent *aEvent,PRBool aButtonDown,
int aClickCount);
virtual PRBool MouseMovedEvent(QMouseEvent *aEvent);
virtual PRBool PaintEvent(QPaintEvent *aEvent);
void ScrollBarMoved(int aMessage,int aValue = -1);
public slots:
void PreviousLine();
void NextLine();
void PreviousPage();
void NextPage();
void SetValue(int value);
};
/**
* Native QT scrollbar wrapper.
*/
class nsScrollbar : public nsWidget,
public nsIScrollbar
{
public:
nsScrollbar(PRBool aIsVertical);
virtual ~nsScrollbar();
// nsISupports
NS_DECL_ISUPPORTS_INHERITED
// 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);
virtual PRBool OnScroll(nsScrollbarEvent & aEvent, PRUint32 cPos);
const char *GetName();
protected:
NS_IMETHOD CreateNative(QWidget *parentWindow);
void ValueChanged(int aValue);
private:
QScrollBar::Orientation mOrientation;
int mMaxValue;
int mLineStep;
int mPageStep;
int mValue;
PRUint32 mQBaseSBID;
};
#endif // nsScrollbar_
//=============================================================================
// nsQScrollBar class:
// Customizes QScrollBar for use by XPFE
//=============================================================================
class nsQScrollBar : public QScrollBar
{
Q_OBJECT
public:
nsQScrollBar(int aMinValue,int aMaxValue,int aLineStep,int aPageStep,int aValue,
Orientation aOrientation,QWidget *aParent,const char *aName = 0);
~nsQScrollBar();
void closeEvent(QCloseEvent *aEvent);
private:
PRUint32 mQSBID;
};
//=============================================================================
// nsScrollBar class:
// the XPFE Scrollbar
//=============================================================================
class nsScrollbar : public nsWidget, public nsIScrollbar
{
public:
nsScrollbar(PRBool aIsVertical);
virtual ~nsScrollbar();
// nsISupports
NS_DECL_ISUPPORTS_INHERITED
// 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);
virtual PRBool OnScroll(nsScrollbarEvent &aEvent,PRUint32 cPos);
virtual PRBool IsScrollBar() const { return PR_TRUE; };
protected:
NS_IMETHOD CreateNative(QWidget *aParentWindow);
private:
QScrollBar::Orientation mOrientation;
int mMaxValue;
int mLineStep;
int mPageStep;
int mValue;
PRUint32 mNsSBID;
};
#endif // nsScrollbar_h__

View File

@ -26,7 +26,7 @@
#include "nsGUIEvent.h"
#include "nsString.h"
//JCG #define DBG 0
#define DBG 0
//=============================================================================
//

View File

@ -34,7 +34,7 @@
#include <qlineedit.h>
#include <qmultilineedit.h>
//JCG #define DBG 0
#define DBG 0
//-------------------------------------------------------------------------
//

View File

@ -26,7 +26,7 @@
#include "nsGUIEvent.h"
#include "nsString.h"
//JCG #define DBG 0
#define DBG 0
extern int mIsPasswordCallBacksInstalled;

View File

@ -18,66 +18,50 @@
* Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
*
*/
#include "nscore.h" // needed for 'nsnull'
#include "nsToolkit.h"
#include "nsGUIEvent.h"
#include "plevent.h"
#include "nsWidget.h"
//
// Static thread local storage index of the Toolkit
// object associated with a given thread...
//
static PRUintn gToolkitTLSIndex = 0;
//-------------------------------------------------------------------------
//
// constructor
//
//-------------------------------------------------------------------------
nsToolkit::nsToolkit()
{
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsToolkit::nsToolkit()\n"));
NS_INIT_REFCNT();
NS_INIT_REFCNT();
}
//-------------------------------------------------------------------------
//
// destructor
//
//-------------------------------------------------------------------------
nsToolkit::~nsToolkit()
{
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsToolkit::~nsToolkit()\n"));
// Remove the TLS reference to the toolkit...
PR_SetThreadPrivate(gToolkitTLSIndex, nsnull);
// Remove the TLS reference to the toolkit...
PR_SetThreadPrivate(gToolkitTLSIndex, nsnull);
}
//-------------------------------------------------------------------------
//
// nsISupports implementation macro
//
//-------------------------------------------------------------------------
NS_IMPL_ISUPPORTS1(nsToolkit, nsIToolkit)
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
NS_IMETHODIMP nsToolkit::Init(PRThread *aThread)
{
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsToolkit::Init()\n"));
return NS_OK;
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Return the nsIToolkit for the current thread. If a toolkit does not
// yet exist, then one will be created...
//
//-------------------------------------------------------------------------
NS_METHOD NS_GetCurrentToolkit(nsIToolkit* *aResult)
{
@ -86,47 +70,35 @@ NS_METHOD NS_GetCurrentToolkit(nsIToolkit* *aResult)
PRStatus status;
// Create the TLS index the first time through...
if (0 == gToolkitTLSIndex)
{
if (0 == gToolkitTLSIndex) {
status = PR_NewThreadPrivateIndex(&gToolkitTLSIndex, NULL);
if (PR_FAILURE == status)
{
if (PR_FAILURE == status) {
rv = NS_ERROR_FAILURE;
}
}
if (NS_SUCCEEDED(rv))
{
if (NS_SUCCEEDED(rv)) {
toolkit = (nsIToolkit*)PR_GetThreadPrivate(gToolkitTLSIndex);
//
// Create a new toolkit for this thread...
//
if (!toolkit)
{
if (!toolkit) {
toolkit = new nsToolkit();
if (!toolkit)
{
if (!toolkit) {
rv = NS_ERROR_OUT_OF_MEMORY;
}
else
{
else {
NS_ADDREF(toolkit);
toolkit->Init(PR_GetCurrentThread());
//
// The reference stored in the TLS is weak. It is removed in the
// nsToolkit destructor...
//
PR_SetThreadPrivate(gToolkitTLSIndex, (void*)toolkit);
}
}
else
{
else {
NS_ADDREF(toolkit);
}
*aResult = toolkit;
}
return rv;
}

View File

@ -18,25 +18,21 @@
* Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
*
*/
#ifndef TOOLKIT_H
#define TOOLKIT_H
#ifndef nsToolkit_h__
#define nsToolkit_h__
#include "nsIToolkit.h"
struct PLEventQueue;
struct MethodInfo;
/**
* Wrapper around the thread running the message pump.
* The toolkit abstraction is necessary because the message pump must
* execute within the same thread that created the widget under Win32.
*/
class nsToolkit : public nsIToolkit
{
public:
nsToolkit();
virtual ~nsToolkit();
@ -45,4 +41,4 @@ public:
NS_IMETHOD Init(PRThread *aThread);
};
#endif // TOOLKIT_H
#endif // nsToolkit_h__

File diff suppressed because it is too large Load Diff

View File

@ -18,8 +18,9 @@
* Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
*
*/
#ifndef nsWidget_h__
#define nsWidget_h__
@ -30,24 +31,10 @@
#include "nsIRegion.h"
#include "nsIRollupListener.h"
#include "nsLookAndFeel.h"
#include "prlog.h"
#include <qwidget.h>
#include <qptrdict.h>
extern PRLogModuleInfo * QtWidgetsLM;
extern PRLogModuleInfo * QtScrollingLM;
#include "nsQWidget.h"
class nsIAppShell;
class nsIToolkit;
class nsQWidget;
class QPainter;
class QPixmap;
class nsQEventHandler;
/**
* Base of all QT native widgets.
*/
class nsWidget : public nsBaseWidget, public nsIKBStateControl, public nsSupportsWeakReference
{
@ -75,6 +62,7 @@ public:
NS_IMETHOD Destroy(void);
nsIWidget* GetParent(void);
NS_IMETHOD SetModal(PRBool aModal);
NS_IMETHOD Show(PRBool state);
NS_IMETHOD CaptureRollupEvents(nsIRollupListener *aListener,
PRBool aDoCapture,
@ -84,10 +72,7 @@ public:
NS_IMETHOD ConstrainPosition(PRInt32 *aX, PRInt32 *aY);
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,
NS_IMETHOD Resize(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight,
PRBool aRepaint);
NS_IMETHOD Enable(PRBool aState);
@ -117,18 +102,18 @@ public:
NS_IMETHOD GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight);
NS_IMETHOD SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight);
// Use this to set the name of a widget for normal widgets.. not the same
// as the nsWindow version
NS_IMETHOD SetTitle(const nsString& aTitle);
virtual void ConvertToDeviceCoordinates(nscoord &aX, nscoord &aY);
// the following are nsWindow specific, and just stubbed here
NS_IMETHOD Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect);
NS_IMETHOD SetMenuBar(nsIMenuBar *aMenuBar) { return NS_ERROR_FAILURE; }
NS_IMETHOD ShowMenuBar(PRBool aShow) { return NS_ERROR_FAILURE; }
NS_IMETHOD CaptureMouse(PRBool aCapture) { return NS_ERROR_FAILURE; }
virtual PRBool OnPaint(nsPaintEvent &event) { return PR_FALSE; };
virtual PRBool OnKey(nsKeyEvent &aEvent) { return PR_FALSE; };
virtual PRBool DispatchFocus(nsGUIEvent &aEvent) { return PR_FALSE; };
NS_IMETHOD Invalidate(PRBool aIsSynchronous);
NS_IMETHOD Invalidate(const nsRect &aRect, PRBool aIsSynchronous);
@ -138,32 +123,25 @@ public:
// nsIKBStateControl
NS_IMETHOD ResetInputState();
NS_IMETHOD PasswordFieldInit();
void InitEvent(nsGUIEvent& event,
PRUint32 aEventType,
nsPoint* aPoint = nsnull);
nsQEventHandler * GetEventHandler() { return mEventHandler; }
const char *GetName();
void AddChildEventHandler(nsQEventHandler *aEHandler);
void RemoveChildEventHandler(nsQEventHandler *aEHandler);
void InitEvent(nsGUIEvent& event,PRUint32 aEventType,nsPoint* aPoint = nsnull);
// Utility functions
virtual PRBool OnPaint(nsPaintEvent &event) { return PR_FALSE; }
const char *GetName();
PRBool ConvertStatus(nsEventStatus aStatus);
PRBool DispatchMouseEvent(nsMouseEvent& aEvent);
PRBool DispatchStandardEvent(PRUint32 aMsg);
PRBool IsToplevel() const { return mIsToplevel; };
virtual PRBool IsPopup() const { return PR_FALSE; };
virtual PRBool IsDialog() const { return PR_FALSE; };
PRBool IsInDTOR() const { return mInDTOR; };
// Deal with rollup for popups
PRBool HandlePopup(PRInt32 inMouseX,PRInt32 inMouseY);
protected:
virtual void InitCallbacks(char * aName = nsnull);
virtual void OnDestroy();
virtual void DestroyChildren();
NS_IMETHOD CreateNative(QWidget *parentWindow);
@ -178,46 +156,22 @@ protected:
PRBool DispatchWindowEvent(nsGUIEvent* event);
// Deal with rollup for popups
PRBool HandlePopup(PRInt32 inMouseX,PRInt32 inMouseY);
PRBool IsMouseInWindow(QWidget* inWindow,PRInt32 inMouseX,PRInt32 inMouseY);
protected:
QWidget *mWidget;
QPixmap *mPixmap;
QPainter *mPainter;
nsQBaseWidget *mWidget;
nsCOMPtr<nsIWidget> mParent;
// composite update area - union of all Invalidate calls
nsCOMPtr<nsIRegion> mUpdateArea;
PRBool mShown;
PRUint32 mPreferredWidth;
PRUint32 mPreferredHeight;
nsQEventHandler *mEventHandler;
PRBool mListenForResizes;
PRBool mIsToplevel;
PRBool mInDTOR;
QPtrDict<nsQEventHandler> mChildEventHandlers;
PRUint32 mWidgetID;
// this is the rollup listener variables
static nsCOMPtr<nsIRollupListener> gRollupListener;
static nsWeakPtr gRollupWidget;
static PRBool gRollupConsumeRollupEvent;
static PRUint32 gWidgetCount;
};
class nsQBaseWidget
{
public:
nsQBaseWidget(nsWidget * widget);
virtual ~nsQBaseWidget();
public:
nsWidget * GetWidget() { return mWidget; }
void Destroy();
protected:
nsWidget * mWidget;
};
#endif /* nsWidget_h__ */

View File

@ -17,8 +17,8 @@
* Copyright (C) 2000 Christopher Blizzard. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzzard <blizzard@mozilla.org>
* Stuart Parmenter <pavlov@netscape.com>
* John C. Griggs <johng@corel.com>
*
*/
#include "nsIGenericFactory.h"
@ -27,18 +27,12 @@
#include "nsWidgetsCID.h"
#include "nsWindow.h"
#include "nsButton.h"
#include "nsCheckButton.h"
#include "nsFileWidget.h"
#include "nsTextWidget.h"
#include "nsAppShell.h"
#include "nsToolkit.h"
#include "nsLookAndFeel.h"
#include "nsLabel.h"
#include "nsTransferable.h"
#include "nsClipboard.h"
#include "nsHTMLFormatConverter.h"
#include "nsFontRetrieverService.h"
#include "nsDragService.h"
#include "nsFileSpecWithUIImpl.h"
#include "nsScrollbar.h"
@ -49,71 +43,61 @@
NS_GENERIC_FACTORY_CONSTRUCTOR(nsWindow)
NS_GENERIC_FACTORY_CONSTRUCTOR(ChildWindow)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsButton)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsCheckButton)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFileWidget)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsTextWidget)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAppShell)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsToolkit)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsLookAndFeel)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsLabel)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsTransferable)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboard)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLFormatConverter)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontRetrieverService)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDragService)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFileSpecWithUIImpl)
#ifdef IBMBIDI
NS_GENERIC_FACTORY_CONSTRUCTOR(nsBidiKeyboard)
#endif
static nsresult nsHorizScrollbarConstructor (nsISupports *aOuter, REFNSIID aIID, void **aResult)
static nsresult nsHorizScrollbarConstructor(nsISupports *aOuter,REFNSIID aIID,
void **aResult)
{
nsresult rv;
nsISupports *inst = nsnull;
if ( NULL == aResult )
{
if (NULL == aResult) {
rv = NS_ERROR_NULL_POINTER;
return rv;
}
*aResult = NULL;
if (NULL != aOuter)
{
if (NULL != aOuter) {
rv = NS_ERROR_NO_AGGREGATION;
return rv;
}
inst = (nsISupports *)(nsBaseWidget *)(nsWidget *)new nsScrollbar(PR_FALSE);
if (inst == NULL)
{
inst = (nsISupports*)(nsBaseWidget*)(nsWidget*)new nsScrollbar(PR_FALSE);
if (inst == NULL) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(inst);
rv = inst->QueryInterface(aIID, aResult);
rv = inst->QueryInterface(aIID,aResult);
NS_RELEASE(inst);
return rv;
}
static nsresult nsVertScrollbarConstructor (nsISupports *aOuter, REFNSIID aIID, void **aResult)
static nsresult nsVertScrollbarConstructor(nsISupports *aOuter,REFNSIID aIID,
void **aResult)
{
nsresult rv;
nsISupports *inst = nsnull;
if ( NULL == aResult )
{
if (NULL == aResult) {
rv = NS_ERROR_NULL_POINTER;
return rv;
}
*aResult = NULL;
if (NULL != aOuter)
{
if (NULL != aOuter) {
rv = NS_ERROR_NO_AGGREGATION;
return rv;
}
inst = (nsISupports *)(nsBaseWidget *)(nsWidget *)new nsScrollbar(PR_TRUE);
if (inst == NULL)
{
inst = (nsISupports*)(nsBaseWidget*)(nsWidget*)new nsScrollbar(PR_TRUE);
if (inst == NULL) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(inst);
@ -133,18 +117,6 @@ static nsModuleComponentInfo components[] =
NS_CHILD_CID,
"@mozilla.org/widgets/child_window/qt;1",
ChildWindowConstructor },
{ "Qt Button",
NS_BUTTON_CID,
"@mozilla.org/widgets/button/qt;1",
nsButtonConstructor },
{ "Qt Check Button",
NS_CHECKBUTTON_CID,
"@mozilla.org/widgets/checkbutton/qt;1",
nsCheckButtonConstructor },
{ "Qt File Widget",
NS_FILEWIDGET_CID,
"@mozilla.org/widgets/filewidget/qt;1",
nsFileWidgetConstructor },
{ "Qt Horiz Scrollbar",
NS_HORZSCROLLBAR_CID,
"@mozilla.org/widgets/horizscroll/qt;1",
@ -153,10 +125,6 @@ static nsModuleComponentInfo components[] =
NS_VERTSCROLLBAR_CID,
"@mozilla.org/widgets/vertscroll/qt;1",
nsVertScrollbarConstructor },
{ "Qt Text Widget",
NS_TEXTFIELD_CID,
"@mozilla.org/widgets/textwidget/qt;1",
nsTextWidgetConstructor },
{ "Qt AppShell",
NS_APPSHELL_CID,
"@mozilla.org/widget/appshell/qt;1",
@ -169,10 +137,6 @@ static nsModuleComponentInfo components[] =
NS_LOOKANDFEEL_CID,
"@mozilla.org/widget/lookandfeel/qt;1",
nsLookAndFeelConstructor },
{ "Qt Label",
NS_LABEL_CID,
"@mozilla.org/widget/label/qt;1",
nsLabelConstructor },
{ "Transferrable",
NS_TRANSFERABLE_CID,
"@mozilla.org/widget/transferable;1",
@ -185,10 +149,6 @@ static nsModuleComponentInfo components[] =
NS_HTMLFORMATCONVERTER_CID,
"@mozilla.org/widget/htmlformatconverter/qt;1",
nsHTMLFormatConverterConstructor },
{ "Qt Font Retriever Service",
NS_FONTRETRIEVERSERVICE_CID,
"@mozilla.org/widget/fontretrieverservice/qt;1",
nsFontRetrieverServiceConstructor },
{ "Qt Drag Service",
NS_DRAGSERVICE_CID,
"@mozilla.org/widget/dragservice;1",
@ -205,4 +165,4 @@ static nsModuleComponentInfo components[] =
nsFileSpecWithUIImplConstructor }
};
NS_IMPL_NSGETMODULE("nsWidgetQTModule", components)
NS_IMPL_NSGETMODULE("nsWidgetQTModule",components)

View File

@ -18,84 +18,61 @@
* Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
*
*/
#include "nsIServiceManager.h"
#include "nsQWidget.h"
#include "nsWindow.h"
#include "nsIFontMetrics.h"
#include "nsFont.h"
#include "nsGUIEvent.h"
#include "nsIRenderingContext.h"
#include "nsIDeviceContext.h"
#include "nsRect.h"
#include "nsTransform2D.h"
#include "nsGfxCIID.h"
#include "nsMenuBar.h"
#include "nsAppShell.h"
#include "nsClipboard.h"
#include "stdio.h"
#include <qapplication.h>
#include <qobjectlist.h>
static bool gAppTopWindowSet = PR_FALSE;
//JCG #define DBG_JCG = 1
#ifdef DBG_JCG
static PRInt32 gWindowCount = 0;
static PRInt32 gWindowID = 0;
static PRInt32 gChildCount = 0;
static PRInt32 gChildID = 0;
#endif
// are we grabbing?
PRBool nsWindow::mIsGrabbing = PR_FALSE;
nsWindow *nsWindow::mGrabWindow = NULL;
//=============================================================================
//
// nsQWidget class
//
//=============================================================================
nsQWidget::nsQWidget(nsWidget * widget, QWidget * parent, const char * name, WFlags f)
: QWidget(parent, name, f), nsQBaseWidget(widget)
{
}
nsQWidget::~nsQWidget()
{
}
void nsQWidget::Destroy()
{
nsQBaseWidget::Destroy();
}
PRBool nsWindow::mIsGrabbing = PR_FALSE;
nsWindow *nsWindow::mGrabWindow = NULL;
NS_IMPL_ISUPPORTS_INHERITED0(nsWindow, nsWidget)
//-------------------------------------------------------------------------
//
// nsWindow constructor
//
//-------------------------------------------------------------------------
nsWindow::nsWindow()
{
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsWindow::nsWindow()\n"));
mResized = PR_FALSE;
mVisible = PR_FALSE;
mDisplayed = PR_FALSE;
mLowerLeft = PR_FALSE;
mIsDestroying = PR_FALSE;
mIsDialog = PR_FALSE;
mIsPopup = PR_FALSE;
mOnDestroyCalled = PR_FALSE;
mFont = nsnull;
mWindowType = eWindowType_child;
mBorderStyle = eBorderStyle_default;
mBlockFocusEvents = PR_FALSE;
#ifdef DBG_JCG
gWindowCount++;
mWindowID = gWindowID++;
printf("JCG: nsWindow CTOR. (%p) ID: %d, Count: %d\n",this,mWindowID,gWindowCount);
#endif
mIsDialog = PR_FALSE;
mIsPopup = PR_FALSE;
mWindowType = eWindowType_child;
mBorderStyle = eBorderStyle_default;
mBlockFocusEvents = PR_FALSE;
}
//-------------------------------------------------------------------------
//
// nsWindow destructor
//
//-------------------------------------------------------------------------
nsWindow::~nsWindow()
{
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsWindow::~nsWindow()\n"));
#ifdef DBG_JCG
gWindowCount--;
printf("JCG: nsWindow DTOR. (%p) ID: %d, Count: %d\n",this,mWindowID,gWindowCount);
#endif
// make sure that we release the grab indicator here
if (mGrabWindow == this) {
mIsGrabbing = PR_FALSE;
@ -106,366 +83,278 @@ nsWindow::~nsWindow()
//-------------------------------------------------------------------------
PRBool nsWindow::IsChild() const
{
return PR_FALSE;
return PR_FALSE;
}
//-------------------------------------------------------------------------
void nsWindow::ConvertToDeviceCoordinates(nscoord &aX, nscoord &aY)
{
PR_LOG(QtWidgetsLM,
PR_LOG_DEBUG,
("nsWindow::ConvertToDeviceCoordinates()\n"));
}
//-------------------------------------------------------------------------
//
// Setup initial tooltip rectangles
//
//-------------------------------------------------------------------------
NS_METHOD nsWindow::SetTooltips(PRUint32 aNumberOfTips,nsRect* aTooltipAreas[])
NS_METHOD nsWindow::SetTooltips(PRUint32 aNumberOfTips,
nsRect *aTooltipAreas[])
{
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsWindow::SetTooltips()\n"));
return NS_OK;
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Update all tooltip rectangles
//
//-------------------------------------------------------------------------
NS_METHOD nsWindow::UpdateTooltips(nsRect* aNewTips[])
{
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsWindow::UpdateTooltips()\n"));
return NS_OK;
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Remove all tooltip rectangles
//
//-------------------------------------------------------------------------
NS_METHOD nsWindow::RemoveTooltips()
{
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsWindow::RemoveTooltips()\n"));
return NS_OK;
return NS_OK;
}
NS_METHOD nsWindow::SetFocus(PRBool aRaise)
{
PR_LOG(QtWidgetsLM,
PR_LOG_DEBUG,
("nsWindow::SetFocus %s\n",
mWidget ? mWidget->name() : "(null)"));
if (mWidget) {
mWidget->setFocus();
}
// don't recurse
if (mBlockFocusEvents) {
return NS_OK;
}
mBlockFocusEvents = PR_TRUE;
nsGUIEvent event;
event.message = NS_GOTFOCUS;
event.widget = this;
event.eventStructType = NS_GUI_EVENT;
event.time = 0;
event.point.x = 0;
event.point.y = 0;
DispatchFocus(event);
mBlockFocusEvents = PR_FALSE;
if (mWidget) {
mWidget->SetFocus();
}
// don't recurse
if (mBlockFocusEvents) {
return NS_OK;
}
mBlockFocusEvents = PR_TRUE;
nsGUIEvent event;
event.message = NS_GOTFOCUS;
event.widget = this;
event.eventStructType = NS_GUI_EVENT;
event.time = 0;
event.point.x = 0;
event.point.y = 0;
DispatchFocus(event);
mBlockFocusEvents = PR_FALSE;
return NS_OK;
}
NS_METHOD nsWindow::PreCreateWidget(nsWidgetInitData *aInitData)
{
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsWindow::PreCreateWidget()\n"));
if (nsnull != aInitData) {
SetWindowType(aInitData->mWindowType);
SetBorderStyle(aInitData->mBorderStyle);
return NS_OK;
}
return NS_ERROR_FAILURE;
if (nsnull != aInitData) {
SetWindowType(aInitData->mWindowType);
SetBorderStyle(aInitData->mBorderStyle);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
//-------------------------------------------------------------------------
//
// Create the native widget
//
//-------------------------------------------------------------------------
NS_METHOD nsWindow::CreateNative(QWidget *parentWidget)
{
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsWindow::CreateNative()\n"));
switch (mWindowType) {
case eWindowType_toplevel:
#ifdef DBG_JCG
printf("JCG: Top Level Create: %p\n",this);
#endif
break;
QWidget::WFlags w = 0;
case eWindowType_dialog:
#ifdef DBG_JCG
printf("JCG: Dialog Create: %p\n",this);
#endif
mIsDialog = PR_TRUE;
break;
if (mBorderStyle == eBorderStyle_default) {
w = 0;
}
else {
if (mBorderStyle & eBorderStyle_all) {
w |= 0;
}
if (mBorderStyle & eBorderStyle_border) {
w |= Qt::WStyle_DialogBorder;
}
if (mBorderStyle & eBorderStyle_resizeh) {
w |= Qt::WStyle_NormalBorder;
}
if (mBorderStyle & eBorderStyle_title) {
w |= Qt::WStyle_Title;
}
if (mBorderStyle & eBorderStyle_menu) {
w |= Qt::WStyle_SysMenu | Qt::WStyle_Title;
}
if (mBorderStyle & eBorderStyle_minimize) {
w |= Qt::WStyle_Minimize;
}
if (mBorderStyle & eBorderStyle_maximize) {
w |= Qt::WStyle_Maximize;
}
if (mBorderStyle & eBorderStyle_close) {
PR_LOG(QtWidgetsLM,
PR_LOG_DEBUG,
("eBorderStyle_close isn't handled yet... please fix me\n"));
}
}
case eWindowType_popup:
#ifdef DBG_JCG
printf("JCG: Popup Create: %p\n",this);
#endif
mIsPopup = PR_TRUE;
break;
w |= (w) ? Qt::WStyle_Customize : 0;
case eWindowType_child:
#ifdef DBG_JCG
printf("JCG: Child Create: %p\n",this);
#endif
break;
}
mWidget = new nsQBaseWidget(this);
switch (mWindowType) {
case eWindowType_toplevel:
w |= Qt::WType_TopLevel | Qt::WDestructiveClose;
break;
if (!mWidget)
return NS_ERROR_OUT_OF_MEMORY;
case eWindowType_dialog:
mIsDialog = PR_TRUE;
w |= Qt::WType_Modal;
break;
case eWindowType_popup:
mIsPopup = PR_TRUE;
w |= Qt::WType_Popup;
break;
case eWindowType_child:
break;
}
w |= Qt::WRepaintNoErase;
w |= Qt::WResizeNoErase;
mWidget = (QWidget*)new nsQWidget(this, parentWidget, QWidget::tr("nsWindow"), w);
if (!mWidget)
return NS_ERROR_OUT_OF_MEMORY;
if (!parentWidget) {
// This is a top-level window. I'm not sure what special actions need
// to be taken here.
mWidget->resize(mBounds.width, mBounds.height);
mIsToplevel = PR_TRUE;
mListenForResizes = PR_TRUE;
if (!gAppTopWindowSet) {
qApp->setMainWidget(mWidget);
gAppTopWindowSet = PR_TRUE;
}
}
else {
mIsToplevel = PR_FALSE;
}
// Force cursor to default setting
mCursor = eCursor_select;
SetCursor(eCursor_standard);
return nsWidget::CreateNative(parentWidget);
if (!mWidget->CreateNative(parentWidget,QWidget::tr("nsWindow"),
NS_GetQWFlags(mBorderStyle,mWindowType))) {
delete mWidget;
mWidget = nsnull;
return NS_ERROR_OUT_OF_MEMORY;
}
if (!parentWidget && !mIsDialog) {
// This is a top-level window. I'm not sure what special actions
// need to be taken here.
mIsToplevel = PR_TRUE;
mListenForResizes = PR_TRUE;
}
else {
mIsToplevel = PR_FALSE;
}
return nsWidget::CreateNative(parentWidget);
}
//-------------------------------------------------------------------------
//
// Initialize all the Callbacks
//
//-------------------------------------------------------------------------
void nsWindow::InitCallbacks(char * aName)
void nsWindow::InitCallbacks(char *aName)
{
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsWindow::InitCallbacks()\n"));
}
//-------------------------------------------------------------------------
//
// Set the colormap of the window
//
//-------------------------------------------------------------------------
NS_METHOD nsWindow::SetColorMap(nsColorMap *aColorMap)
{
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsWindow::SetColorMap()\n"));
return NS_OK;
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Scroll the bits of a window
//
//-------------------------------------------------------------------------
NS_METHOD nsWindow::Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect)
NS_METHOD nsWindow::Scroll(PRInt32 aDx,PRInt32 aDy,nsRect *aClipRect)
{
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsWindow::Scroll: (%d,%d)\n",
aDx, aDy));
if (mWidget) {
mWidget->scroll(aDx, aDy);
}
return NS_OK;
if (mWidget) {
mWidget->Scroll(aDx,aDy);
}
return NS_OK;
}
NS_METHOD nsWindow::SetTitle(const nsString& aTitle)
{
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsWindow::SetTitle()\n"));
if (!mWidget) {
return NS_ERROR_FAILURE;
}
const char * titleStr = aTitle.ToNewCString();
mWidget->setCaption(QString::fromLocal8Bit(titleStr));
delete[] titleStr;
return NS_OK;
}
/**
* Processes an Expose Event
*
**/
/* Processes an Expose Event */
PRBool nsWindow::OnPaint(nsPaintEvent &event)
{
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsWindow::OnPaint()\n"));
nsresult result ;
PRInt32 x;
PRInt32 y;
PRInt32 width;
PRInt32 height;
nsresult result;
PRInt32 x;
PRInt32 y;
PRInt32 width;
PRInt32 height;
// call the event callback
if (mEventCallback) {
event.renderingContext = nsnull;
if (event.rect) {
PR_LOG(QtWidgetsLM,
PR_LOG_DEBUG,
("nsWindow::OnPaint: this=%p, {%d,%d,%d,%d}\n",
this,
event.rect->x,
event.rect->y,
event.rect->width,
event.rect->height));
x = event.rect->x;
y = event.rect->y;
width = event.rect->width;
height = event.rect->height;
}
else {
PR_LOG(QtWidgetsLM,
PR_LOG_DEBUG,
("nsWindow::OnPaint: this=%p, NO RECT\n",
this));
x = 0;
y = 0;
if (mWidget) {
width = mWidget->width();
height = mWidget->height();
}
else {
width = 0;
height = 0;
}
}
static NS_DEFINE_IID(kRenderingContextCID, NS_RENDERING_CONTEXT_CID);
static NS_DEFINE_IID(kRenderingContextIID, NS_IRENDERING_CONTEXT_IID);
if (NS_OK == nsComponentManager::CreateInstance(kRenderingContextCID,
nsnull,
kRenderingContextIID,
(void **)&event.renderingContext)) {
if (mBounds.width && mBounds.height) {
event.renderingContext->Init(mContext, this);
result = DispatchWindowEvent(&event);
NS_RELEASE(event.renderingContext);
if (mWidget && mPixmap) {
PR_LOG(QtWidgetsLM,
PR_LOG_DEBUG,
("nsWindow::OnPaint: bitBlt: {%d,%d,%d,%d}\n",
x, y, width, height));
bitBlt(mWidget, x, y, mPixmap, x, y, width, height, Qt::CopyROP);
mPixmap->fill(mWidget, 0, 0);
}
}
}
else {
result = PR_FALSE;
}
// call the event callback
if (mEventCallback) {
event.renderingContext = nsnull;
if (event.rect) {
x = event.rect->x;
y = event.rect->y;
width = event.rect->width;
height = event.rect->height;
}
return result;
else {
x = 0;
y = 0;
if (mWidget) {
width = mWidget->Width();
height = mWidget->Height();
}
else {
width = 0;
height = 0;
}
}
static NS_DEFINE_IID(kRenderingContextCID, NS_RENDERING_CONTEXT_CID);
static NS_DEFINE_IID(kRenderingContextIID, NS_IRENDERING_CONTEXT_IID);
if (NS_OK == nsComponentManager::CreateInstance(kRenderingContextCID,
nsnull,
kRenderingContextIID,
(void **)&event.renderingContext)) {
if (mBounds.width && mBounds.height) {
event.renderingContext->Init(mContext, this);
result = DispatchWindowEvent(&event);
NS_IF_RELEASE(event.renderingContext);
}
}
else {
result = PR_FALSE;
}
}
return result;
}
NS_METHOD nsWindow::BeginResizingChildren(void)
{
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsWindow::BeginResizingChildren()\n"));
return NS_OK;
return NS_OK;
}
NS_METHOD nsWindow::EndResizingChildren(void)
{
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsWindow::EndResizingChildren()\n"));
return NS_OK;
return NS_OK;
}
PRBool nsWindow::OnKey(nsKeyEvent &aEvent)
{
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsWindow::OnKey()\n"));
if (mEventCallback) {
return DispatchWindowEvent(&aEvent);
}
return PR_FALSE;
if (mEventCallback) {
return DispatchWindowEvent(&aEvent);
}
return PR_FALSE;
}
PRBool nsWindow::DispatchFocus(nsGUIEvent &aEvent)
{
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsWindow::DispatchFocus()\n"));
if (mEventCallback) {
return DispatchWindowEvent(&aEvent);
}
return PR_FALSE;
if (mEventCallback) {
return DispatchWindowEvent(&aEvent);
}
return PR_FALSE;
}
NS_METHOD nsWindow::GetClientBounds(nsRect &aRect)
{
return GetBounds(aRect);
}
NS_METHOD nsWindow::GetBounds(nsRect &aRect)
{
nsRect Rct(mWidget->BoundsX(),mWidget->BoundsX(),
mWidget->Width(),mWidget->Height());
aRect = Rct;
return NS_OK;
}
NS_IMETHODIMP nsWindow::GetScreenBounds(nsRect &aRect)
{
nsRect nBounds(0,0,mBounds.width,mBounds.height);
aRect = nBounds;
return NS_OK;
}
NS_METHOD nsWindow::GetBoundsAppUnits(nsRect &aRect, float aAppUnits)
{
GetBounds(aRect);
// Convert to twips
aRect.x = nscoord((PRFloat64)aRect.x * aAppUnits);
aRect.y = nscoord((PRFloat64)aRect.y * aAppUnits);
aRect.width = nscoord((PRFloat64)aRect.width * aAppUnits);
aRect.height = nscoord((PRFloat64)aRect.height * aAppUnits);
return NS_OK;
}
PRBool nsWindow::OnScroll(nsScrollbarEvent &aEvent, PRUint32 cPos)
{
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsWindow::OnScroll()\n"));
return PR_FALSE;
return PR_FALSE;
}
NS_METHOD nsWindow::ConstrainPosition(PRInt32 *aX, PRInt32 *aY)
{
return NS_OK;
return NS_OK;
}
NS_METHOD nsWindow::Move(PRInt32 aX, PRInt32 aY)
{
PR_LOG(QtWidgetsLM,
PR_LOG_DEBUG,
("nsWindow::Move %s by (%d,%d)\n",
mWidget ? mWidget->name() : "(null)",
aX, aY));
if (mWidget && mParent && mWindowType == eWindowType_popup) {
nsRect oldrect, newrect;
@ -474,8 +363,8 @@ NS_METHOD nsWindow::Move(PRInt32 aX, PRInt32 aY)
oldrect.x = aX;
oldrect.y = aY;
mParent->WidgetToScreen(oldrect, newrect);
mWidget->move(newrect.x,newrect.y);
mParent->WidgetToScreen(oldrect,newrect);
mWidget->Move(newrect.x,newrect.y);
return NS_OK;
}
@ -483,39 +372,40 @@ NS_METHOD nsWindow::Move(PRInt32 aX, PRInt32 aY)
return(nsWidget::Move(aX,aY));
}
NS_IMETHODIMP nsWindow::CaptureRollupEvents(nsIRollupListener * aListener,
NS_IMETHODIMP nsWindow::CaptureRollupEvents(nsIRollupListener *aListener,
PRBool aDoCapture,
PRBool aConsumeRollupEvent)
{
if (aDoCapture)
{
/* Create a pointer region */
mIsGrabbing = PR_TRUE;
mGrabWindow = this;
if (aDoCapture) {
/* Create a pointer region */
mIsGrabbing = PR_TRUE;
mGrabWindow = this;
gRollupConsumeRollupEvent = PR_TRUE;
gRollupListener = aListener;
gRollupWidget = getter_AddRefs(NS_GetWeakReference(NS_STATIC_CAST(nsIWidget*,this)));
gRollupConsumeRollupEvent = PR_TRUE;
gRollupListener = aListener;
gRollupWidget = getter_AddRefs(NS_GetWeakReference(NS_STATIC_CAST(nsIWidget*,this)));
}
else
{
// make sure that the grab window is marked as released
if (mGrabWindow == this) {
mGrabWindow = NULL;
}
mIsGrabbing = PR_FALSE;
else {
// make sure that the grab window is marked as released
if (mGrabWindow == this) {
mGrabWindow = NULL;
}
mIsGrabbing = PR_FALSE;
gRollupListener = nsnull;
gRollupWidget = nsnull;
gRollupListener = nsnull;
gRollupWidget = nsnull;
}
return NS_OK;
}
//////////////////////////////////////////////////////////////////////
ChildWindow::ChildWindow()
{
#ifdef DBG_JCG
gChildCount++;
mChildID = gChildID++;
printf("JCG: nsChildWindow CTOR. (%p) ID: %d, Count: %d\n",this,mChildID,gChildCount);
#endif
}
ChildWindow::~ChildWindow()
@ -524,22 +414,13 @@ ChildWindow::~ChildWindow()
IndentByDepth(stdout);
printf("ChildWindow::~ChildWindow:%p\n", this);
#endif
if (mEventHandler && mParent) {
((nsWidget*)(mParent.get()))->RemoveChildEventHandler(mEventHandler);
}
#ifdef DBG_JCG
gChildCount--;
printf("JCG: nsChildWindow DTOR. (%p) ID: %d, Count: %d\n",this,mChildID,gChildCount);
#endif
}
PRBool ChildWindow::IsChild() const
{
return PR_TRUE;
}
NS_METHOD ChildWindow::CreateNative(QWidget *parentWidget)
{
nsresult rv;
rv = nsWindow::CreateNative(parentWidget);
if (rv == NS_OK && mEventHandler && mParent)
((nsWidget*)(mParent.get()))->AddChildEventHandler(mEventHandler);
return rv;
}

View File

@ -18,45 +18,15 @@
* Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
*
*/
#ifndef Window_h__
#define Window_h__
#include "nsISupports.h"
#include "nsWidget.h"
#include "nsQEventHandler.h"
#include "nsIAppShell.h"
#include "nsString.h"
#include <qlayout.h>
class nsFont;
#define NSRGB_2_COLOREF(color) \
RGB(NS_GET_R(color),NS_GET_G(color),NS_GET_B(color))
//=============================================================================
//
// nsQWidget class
//
//=============================================================================
class nsQWidget : public QWidget , public nsQBaseWidget
{
Q_OBJECT
public:
nsQWidget(nsWidget * widget,
QWidget * parent = 0,
const char * name = 0,
WFlags f = WResizeNoErase);
~nsQWidget();
void Destroy();
};
/**
* Native QT window wrapper.
*/
/* Native QT window wrapper */
class nsWindow : public nsWidget
{
public:
@ -67,20 +37,19 @@ public:
NS_DECL_ISUPPORTS_INHERITED
// nsIWidget interface
virtual void ConvertToDeviceCoordinates(nscoord &aX, nscoord &aY);
virtual void ConvertToDeviceCoordinates(nscoord &aX,nscoord &aY);
NS_IMETHOD PreCreateWidget(nsWidgetInitData *aWidgetInitData);
NS_IMETHOD SetColorMap(nsColorMap *aColorMap);
NS_IMETHOD Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect);
NS_IMETHOD Scroll(PRInt32 aDx,PRInt32 aDy,nsRect *aClipRect);
NS_IMETHOD SetTitle(const nsString& aTitle);
NS_IMETHOD ConstrainPosition(PRInt32 *aX,PRInt32 *aY);
NS_IMETHOD Move(PRInt32 aX,PRInt32 aY);
NS_IMETHOD ConstrainPosition(PRInt32 *aX, PRInt32 *aY);
NS_IMETHOD Move(PRInt32 aX, PRInt32 aY);
NS_IMETHOD CaptureRollupEvents(nsIRollupListener * aListener,
PRBool aDoCapture,PRBool aConsumeRollupEvent);
NS_IMETHOD CaptureRollupEvents(nsIRollupListener *aListener,
PRBool aDoCapture,
PRBool aConsumeRollupEvent);
NS_IMETHOD SetTooltips(PRUint32 aNumberOfTips,nsRect* aTooltipAreas[]);
NS_IMETHOD UpdateTooltips(nsRect* aNewTips[]);
NS_IMETHOD RemoveTooltips();
@ -89,45 +58,33 @@ public:
NS_IMETHOD EndResizingChildren(void);
NS_IMETHOD SetFocus(PRBool aRaise);
NS_IMETHOD GetBounds(nsRect &aRect);
NS_IMETHOD GetBoundsAppUnits(nsRect &aRect,float aAppUnits);
NS_IMETHOD GetClientBounds(nsRect &aRect);
NS_IMETHOD GetScreenBounds(nsRect &aRect);
virtual PRBool IsChild() const;
virtual PRBool IsPopup() const { return mIsPopup; };
virtual PRBool IsDialog() const { return mIsDialog; };
virtual void SetIsDestroying( PRBool val) { mIsDestroying = val; };
PRBool IsDestroying() const { return mIsDestroying; }
// Utility methods
virtual PRBool OnPaint(nsPaintEvent &event);
PRBool OnKey(nsKeyEvent &aEvent);
PRBool DispatchFocus(nsGUIEvent &aEvent);
virtual PRBool OnScroll(nsScrollbarEvent & aEvent, PRUint32 cPos);
virtual PRBool OnKey(nsKeyEvent &aEvent);
virtual PRBool DispatchFocus(nsGUIEvent &aEvent);
virtual PRBool OnScroll(nsScrollbarEvent &aEvent,PRUint32 cPos);
char gInstanceClassName[256];
protected:
virtual void InitCallbacks(char * aName = nsnull);
virtual void InitCallbacks(char *aName = nsnull);
NS_IMETHOD CreateNative(QWidget *parentWidget);
nsIFontMetrics * mFontMetrics;
PRBool mVisible;
PRBool mDisplayed;
PRBool mIsDestroying;
PRBool mBlockFocusEvents;
PRBool mIsDialog;
PRBool mIsPopup;
// XXX Temporary, should not be caching the font
nsFont * mFont;
// Resize event management
nsRect mResizeRect;
int mResized;
PRBool mLowerLeft;
PRBool mBlockFocusEvents;
PRBool mIsDialog;
PRBool mIsPopup;
// are we doing a grab?
static PRBool mIsGrabbing;
static nsWindow *mGrabWindow;
static PRBool mIsGrabbing;
static nsWindow *mGrabWindow;
PRInt32 mWindowID;
};
//
@ -139,7 +96,8 @@ public:
ChildWindow();
~ChildWindow();
virtual PRBool IsChild() const;
NS_IMETHOD CreateNative(QWidget *parentWidget);
PRInt32 mChildID;
};
#endif // Window_h__

View File

@ -17,6 +17,7 @@
# Rights Reserved.
#
# Contributor(s):
# John C. Griggs <johng@corel.com>
#
DEPTH = ../../../../..
@ -26,25 +27,26 @@ VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = timer
LIBRARY_NAME = timer_$(TIMER_SUFFIX)
REQUIRES = xpcom
CPPSRCS = \
moc_nsTimerEventHandler.cpp \
$(MOCSRCS) \
nsTimerEventHandler.cpp \
nsTimerQt.cpp \
$(NULL)
MOCSRCS = \
moc_nsTimerEventHandler.cpp \
$(NULL)
ifndef MOZ_MONOLITHIC_TOOLKIT
TIMER_SUFFIX = qt
IS_COMPONENT = 1
CPPSRCS += nsTimerQtFactory.cpp
EXTRA_DSO_LDOPTS = $(MOZ_QT_LDFLAGS) $(MOZ_COMPONENT_LIBS)
#CXXFLAGS += $(MOZ_QT_CFLAGS)
#CFLAGS += $(MOZ_QT_CFLAGS)
else
#EXTRA_DSO_LDOPTS = $(TK_LIBS)
#CXXFLAGS += $(TK_CFLAGS)
#CFLAGS += $(TK_CFLAGS)
TIMER_SUFFIX = s
override NO_SHARED_LIB=1
override NO_STATIC_LIB=
@ -58,7 +60,3 @@ else
CXXFLAGS += $(TK_CFLAGS)
INCLUDES += $(TK_CFLAGS) -I$(srcdir)/..
endif
#INCLUDES += \
# -I$(srcdir)/..

View File

@ -18,35 +18,63 @@
* Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
*
*/
#include "nsTimerEventHandler.h"
#include <qtimer.h>
//JCG #define DBG_JCG 1
nsTimerEventHandler::nsTimerEventHandler(nsITimer * aTimer,
#ifdef DBG_JCG
PRUint32 gTimerHandlerCount = 0;
PRUint32 gTimerHandlerID = 0;
#endif
nsTimerEventHandler::nsTimerEventHandler(nsITimer *aTimer,
nsTimerCallbackFunc aFunc,
void *aClosure,
nsITimerCallback *aCallback)
{
mTimer = aTimer;
mFunc = aFunc;
mClosure = aClosure;
mCallback = aCallback;
#ifdef DBG_JCG
gTimerHandlerCount++;
mTimerHandlerID = gTimerHandlerID++;
printf("JCG: nsTimerEventHandler CTOR (%p) ID: %d, Count: %d\n",
this,mTimerHandlerID,gTimerHandlerCount);
#endif
mTimer = aTimer;
mFunc = aFunc;
mClosure = aClosure;
mCallback = aCallback;
}
nsTimerEventHandler::~nsTimerEventHandler()
{
#ifdef DBG_JCG
gTimerHandlerCount--;
printf("JCG: nsTimerEventHandler DTOR (%p) ID: %d, Count: %d\n",
this,mTimerHandlerID,gTimerHandlerCount);
#endif
}
void nsTimerEventHandler::FireTimeout()
{
//debug("nsTimerEventHandler::FireTimeout called");
if (mFunc != NULL)
{
(*mFunc)(mTimer, mClosure);
}
else if (mCallback != NULL)
{
mCallback->Notify(mTimer); // Fire the timer
}
// Always repeating here
#ifdef DBG_JCG
printf("JCG: nsTimerEventHandler::FireTimeout (%p) ID: %d\n",
this,mTimerHandlerID);
#endif
//because Notify can cause 'this' to get destroyed,
// we need to hold a ref
nsCOMPtr<nsITimer> kungFuDeathGrip = mTimer;
if (mFunc != NULL) {
#ifdef DBG_JCG
printf("JCG: nsTimerEventHandler::FireTimeout: Calling Function\n");
#endif
(*mFunc)(mTimer,mClosure);
}
else if (mCallback != NULL) {
#ifdef DBG_JCG
printf("JCG: nsTimerEventHandler::FireTimeout: Calling Notify\n");
#endif
mCallback->Notify(mTimer); // Fire the timer
}
}

View File

@ -18,8 +18,9 @@
* Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
*
*/
#ifndef __nsTimerEventHandler_h__
#define __nsTimerEventHandler_h__
@ -31,22 +32,22 @@
class nsTimerEventHandler : public QObject
{
Q_OBJECT
public:
nsTimerEventHandler(nsITimer * aTimer,
nsTimerEventHandler(nsITimer *aTimer,
nsTimerCallbackFunc aFunc,
void *aClosure,
nsITimerCallback *aCallback);
~nsTimerEventHandler();
public slots:
void FireTimeout();
private:
nsTimerCallbackFunc mFunc;
void * mClosure;
nsITimerCallback * mCallback;
nsITimer * mTimer;
void *mClosure;
nsITimerCallback *mCallback;
nsITimer *mTimer;
PRUint32 mTimerHandlerID;
};
#endif // __nsTimerEventHandler_h__

View File

@ -18,120 +18,137 @@
* Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
*
*/
#include "nsTimerQt.h"
#include "nsTimerEventHandler.h"
#include <qtimer.h>
#include <stdio.h>
//JCG #define DBG_JCG 1
static NS_DEFINE_IID(kITimerIID, NS_ITIMER_IID);
#ifdef DBG_JCG
PRUint32 gTimerCount = 0;
PRUint32 gTimerID = 0;
#endif
static NS_DEFINE_IID(kITimerIID,NS_ITIMER_IID);
nsTimerQt::nsTimerQt()
{
//debug("nsTimerQt::nsTimerQt called for %p", this);
NS_INIT_REFCNT();
mFunc = nsnull;
mCallback = nsnull;
mNext = nsnull;
mTimer = nsnull;
mDelay = 0;
mClosure = nsnull;
mEventHandler = nsnull;
#ifdef DBG_JCG
gTimerCount++;
mTimerID = gTimerID++;
printf("JCG: nsTimerQT CTOR (%p) ID: %d, Count: %d\n",this,mTimerID,gTimerCount);
#endif
NS_INIT_REFCNT();
mFunc = nsnull;
mCallback = nsnull;
mNext = nsnull;
mTimer = nsnull;
mDelay = 0;
mClosure = nsnull;
mEventHandler = nsnull;
mPriority = 0;
mType = NS_TYPE_ONE_SHOT;
}
nsTimerQt::~nsTimerQt()
{
//debug("nsTimerQt::~nsTimerQt called for %p", this);
Cancel();
#ifdef DBG_JCG
gTimerCount--;
printf("JCG: nsTimerQT DTOR (%p) ID: %d, Count: %d\n",this,mTimerID,gTimerCount);
#endif
Cancel();
NS_IF_RELEASE(mCallback);
NS_IF_RELEASE(mCallback);
if (mEventHandler) {
delete mEventHandler;
mEventHandler = nsnull;
}
if (mTimer) {
delete mTimer;
mTimer = nsnull;
}
if (mEventHandler) {
delete mEventHandler;
mEventHandler = nsnull;
}
if (mTimer) {
delete mTimer;
mTimer = nsnull;
}
}
nsresult
nsTimerQt::Init(nsTimerCallbackFunc aFunc, void *aClosure, PRUint32 aDelay,
PRUint32 aPriority, PRUint32 aType)
{
//debug("nsTimerQt::Init called with func + closure with %u delay", aDelay);
mFunc = aFunc;
mClosure = aClosure;
#ifdef DBG_JCG
printf("JCG: nsTimerQT::Init (%p) ID: %d WITH Function\n",this,mTimerID);
printf("JCG: Priority: %d, Delay: %d, OneShot: %s\n",aPriority,aDelay,
(aType == NS_TYPE_ONE_SHOT)?"Y":"N");
#endif
mFunc = aFunc;
mClosure = aClosure;
mPriority = aPriority;
mType = aType;
return Init(aDelay);
return Init(aDelay);
}
nsresult
nsTimerQt::Init(nsITimerCallback *aCallback, PRUint32 aDelay,
PRUint32 aPriority, PRUint32 aType)
{
//debug("nsTimerQt::Init called with callback only with %u delay", aDelay);
mCallback = aCallback;
NS_ADDREF(mCallback);
return Init(aDelay);
#ifdef DBG_JCG
printf("JCG: nsTimerQT::Init (%p) ID: %d WITH Callback\n",this,mTimerID);
printf("JCG: Priority: %d, Delay: %d, OneShot: %s, Now: %ld\n",aPriority,aDelay,
(aType == NS_TYPE_ONE_SHOT)?"Y":"N",PR_Now());
#endif
mCallback = aCallback;
NS_ADDREF(mCallback);
mPriority = aPriority;
mType = aType;
return Init(aDelay);
}
nsresult
nsTimerQt::Init(PRUint32 aDelay)
{
//debug("nsTimerQt::Init called with delay %d only for %p", aDelay, this);
mEventHandler = new nsTimerEventHandler(this,mFunc,mClosure,mCallback);
mEventHandler = new nsTimerEventHandler(this, mFunc, mClosure, mCallback);
mTimer = new QTimer();
if (!mTimer) {
return NS_ERROR_NOT_INITIALIZED;
}
QObject::connect((QTimer*)mTimer,SIGNAL(timeout()),
mEventHandler,SLOT(FireTimeout()));
mTimer = new QTimer();
if (!mTimer) {
return NS_ERROR_NOT_INITIALIZED;
}
QObject::connect((QTimer *)mTimer,
SIGNAL(timeout()),
mEventHandler,
SLOT(FireTimeout()));
mTimer->start(aDelay);
mDelay = aDelay;
return NS_OK;
mTimer->start(aDelay,mType == NS_TYPE_ONE_SHOT);
mDelay = aDelay;
return NS_OK;
}
NS_IMPL_ISUPPORTS1(nsTimerQt, nsITimer)
void
nsTimerQt::Cancel()
{
//debug("nsTimerQt::Cancel called for %p", this);
if (mTimer) {
mTimer->stop();
}
#ifdef DBG_JCG
printf("JCG: nsTimerQT::Cancel (%p) ID: %d\n",this,mTimerID);
#endif
if (mTimer) {
mTimer->stop();
}
}
#ifdef MOZ_MONOLITHIC_TOOLKIT
nsresult NS_NewTimer(nsITimer** aInstancePtrResult)
{
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
if (nsnull == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
nsTimerQt *timer = new nsTimerQt();
if (nsnull == timer) {
return NS_ERROR_OUT_OF_MEMORY;
}
return timer->QueryInterface(kITimerIID, (void **) aInstancePtrResult);
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
if (nsnull == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
nsTimerQt *timer = new nsTimerQt();
if (nsnull == timer) {
return NS_ERROR_OUT_OF_MEMORY;
}
return timer->QueryInterface(kITimerIID,(void**)aInstancePtrResult);
}
int NS_TimeToNextTimeout(struct timeval *aTimer)

View File

@ -18,70 +18,66 @@
* Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
*
*/
#ifndef __nsTimerQt_h__
#define __nsTimerQt_h__
#include "nsTimerEventHandler.h"
#include "nsITimer.h"
#include "nsITimerCallback.h"
/*
* Implementation of timers using Qt QTimer class
*/
class nsTimerEventHandler;
class QTimer;
/* Implementation of timers using Qt QTimer class */
class nsTimerQt : public nsITimer
{
public:
nsTimerQt();
virtual ~nsTimerQt();
virtual nsresult Init(nsTimerCallbackFunc aFunc,
void *aClosure,
PRUint32 aDelay,
PRUint32 aPriority = NS_PRIORITY_NORMAL,
PRUint32 aType = NS_TYPE_ONE_SHOT
);
void *aClosure,PRUint32 aDelay,
PRUint32 aPriority = NS_PRIORITY_NORMAL,
PRUint32 aType = NS_TYPE_ONE_SHOT);
virtual nsresult Init(nsITimerCallback *aCallback,
PRUint32 aDelay,
PRUint32 aPriority = NS_PRIORITY_NORMAL,
PRUint32 aType = NS_TYPE_ONE_SHOT
);
PRUint32 aDelay,
PRUint32 aPriority = NS_PRIORITY_NORMAL,
PRUint32 aType = NS_TYPE_ONE_SHOT);
NS_DECL_ISUPPORTS
virtual void Cancel();
virtual PRUint32 GetDelay() { return mDelay; }
virtual void SetDelay(PRUint32 aDelay) { mDelay=aDelay; };
virtual void SetDelay(PRUint32 aDelay) { mDelay = aDelay; };
virtual PRUint32 GetPriority() { return mPriority; }
virtual void SetPriority(PRUint32 aPriority) { mPriority=aPriority; }
virtual void SetPriority(PRUint32 aPriority) { mPriority = aPriority; }
virtual PRUint32 GetType() { return mType; }
virtual void SetType(PRUint32 aType) { mType=aType; }
virtual void SetType(PRUint32 aType) { mType = aType; }
virtual void* GetClosure() { return mClosure; }
virtual void *GetClosure() { return mClosure; }
void FireTimeout();
private:
nsresult Init(PRUint32 aDelay);
private:
PRUint32 mDelay;
PRUint32 mPriority;
PRUint32 mType;
nsTimerCallbackFunc mFunc;
void * mClosure;
nsITimerCallback * mCallback;
void *mClosure;
nsITimerCallback *mCallback;
PRBool mRepeat;
nsTimerQt * mNext;
QTimer * mTimer;
nsTimerEventHandler * mEventHandler;
nsTimerQt *mNext;
QTimer *mTimer;
nsTimerEventHandler *mEventHandler;
PRUint32 mTimerID;
};
#endif // __nsTimerQt_h__

View File

@ -18,7 +18,8 @@
* Rights Reserved.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
* John C. Griggs <johng@corel.com>
*
*/
#include "nsIGenericFactory.h"
@ -42,4 +43,5 @@ static nsModuleComponentInfo components[] =
nsTimerQtConstructor }
};
NS_IMPL_NSGETMODULE("nsQtTimerModule", components)
NS_IMPL_NSGETMODULE("nsQtTimerModule",components)