зеркало из https://github.com/mozilla/pjs.git
Add base implementation of gfxQtPlatform and widget/qt
This commit is contained in:
Родитель
c3a7c70696
Коммит
84a99fb93b
|
@ -0,0 +1,102 @@
|
|||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Foundation code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Vladimir Vukicevic <vladimir@pobox.com>
|
||||
* Masayuki Nakano <masayuki@d-toybox.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef GFX_PLATFORM_QT_H
|
||||
#define GFX_PLATFORM_QT_H
|
||||
|
||||
#include "gfxPlatform.h"
|
||||
#include "nsDataHashtable.h"
|
||||
|
||||
typedef struct FT_LibraryRec_ *FT_Library;
|
||||
|
||||
class gfxFontconfigUtils;
|
||||
class FontFamily;
|
||||
class FontEntry;
|
||||
|
||||
class THEBES_API gfxQtPlatform : public gfxPlatform {
|
||||
public:
|
||||
gfxQtPlatform();
|
||||
virtual ~gfxQtPlatform();
|
||||
|
||||
static gfxQtPlatform *GetPlatform() {
|
||||
return (gfxQtPlatform*) gfxPlatform::GetPlatform();
|
||||
}
|
||||
|
||||
already_AddRefed<gfxASurface> CreateOffscreenSurface(const gfxIntSize& size,
|
||||
gfxASurface::gfxImageFormat imageFormat);
|
||||
|
||||
nsresult GetFontList(const nsACString& aLangGroup,
|
||||
const nsACString& aGenericFamily,
|
||||
nsStringArray& aListOfFonts);
|
||||
|
||||
nsresult UpdateFontList();
|
||||
|
||||
nsresult ResolveFontName(const nsAString& aFontName,
|
||||
FontResolverCallback aCallback,
|
||||
void *aClosure, PRBool& aAborted);
|
||||
|
||||
nsresult GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName);
|
||||
|
||||
gfxFontGroup *CreateFontGroup(const nsAString &aFamilies,
|
||||
const gfxFontStyle *aStyle);
|
||||
|
||||
FontFamily *FindFontFamily(const nsAString& aName);
|
||||
FontEntry *FindFontEntry(const nsAString& aFamilyName, const gfxFontStyle& aFontStyle);
|
||||
|
||||
static PRInt32 DPI() {
|
||||
if (sDPI == -1) {
|
||||
InitDPI();
|
||||
}
|
||||
NS_ASSERTION(sDPI > 0, "Something is wrong");
|
||||
return sDPI;
|
||||
}
|
||||
|
||||
FT_Library GetFTLibrary();
|
||||
|
||||
protected:
|
||||
static void InitDPI();
|
||||
|
||||
static PRInt32 sDPI;
|
||||
static gfxFontconfigUtils *sFontconfigUtils;
|
||||
|
||||
private:
|
||||
virtual cmsHPROFILE GetPlatformCMSOutputProfile();
|
||||
};
|
||||
|
||||
#endif /* GFX_PLATFORM_QT_H */
|
||||
|
|
@ -0,0 +1,315 @@
|
|||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Foundation code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Vladimir Vukicevic <vladimir@pobox.com>
|
||||
* Masayuki Nakano <masayuki@d-toybox.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include <QPixmap>
|
||||
#include <QX11Info>
|
||||
#include <QApplication>
|
||||
#include <QWidget>
|
||||
|
||||
#include "gfxQtPlatform.h"
|
||||
|
||||
#include "gfxFontconfigUtils.h"
|
||||
|
||||
#include "cairo.h"
|
||||
|
||||
#include "gfxImageSurface.h"
|
||||
#include "gfxQPainterSurface.h"
|
||||
|
||||
#include "gfxQtFonts.h"
|
||||
|
||||
#include "nsUnicharUtils.h"
|
||||
|
||||
#include <fontconfig/fontconfig.h>
|
||||
|
||||
#include "nsMathUtils.h"
|
||||
|
||||
#include "lcms.h"
|
||||
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
|
||||
PRInt32 gfxQtPlatform::sDPI = -1;
|
||||
gfxFontconfigUtils *gfxQtPlatform::sFontconfigUtils = nsnull;
|
||||
static cairo_user_data_key_t cairo_qt_pixmap_key;
|
||||
static void do_qt_pixmap_unref (void *data)
|
||||
{
|
||||
QPixmap *pmap = (QPixmap*)data;
|
||||
delete pmap;
|
||||
}
|
||||
|
||||
typedef nsDataHashtable<nsStringHashKey, nsRefPtr<FontFamily> > FontTable;
|
||||
static FontTable *gPlatformFonts = NULL;
|
||||
static FT_Library gPlatformFTLibrary = NULL;
|
||||
|
||||
|
||||
gfxQtPlatform::gfxQtPlatform()
|
||||
{
|
||||
if (!sFontconfigUtils)
|
||||
sFontconfigUtils = gfxFontconfigUtils::GetFontconfigUtils();
|
||||
|
||||
|
||||
FT_Init_FreeType(&gPlatformFTLibrary);
|
||||
|
||||
gPlatformFonts = new FontTable();
|
||||
gPlatformFonts->Init(100);
|
||||
UpdateFontList();
|
||||
|
||||
InitDPI();
|
||||
}
|
||||
|
||||
gfxQtPlatform::~gfxQtPlatform()
|
||||
{
|
||||
gfxFontconfigUtils::Shutdown();
|
||||
sFontconfigUtils = nsnull;
|
||||
|
||||
delete gPlatformFonts;
|
||||
gPlatformFonts = NULL;
|
||||
|
||||
cairo_debug_reset_static_data();
|
||||
|
||||
FT_Done_FreeType(gPlatformFTLibrary);
|
||||
gPlatformFTLibrary = NULL;
|
||||
|
||||
|
||||
#if 0
|
||||
// It would be nice to do this (although it might need to be after
|
||||
// the cairo shutdown that happens in ~gfxPlatform). It even looks
|
||||
// idempotent. But it has fatal assertions that fire if stuff is
|
||||
// leaked, and we hit them.
|
||||
FcFini();
|
||||
#endif
|
||||
}
|
||||
|
||||
already_AddRefed<gfxASurface>
|
||||
gfxQtPlatform::CreateOffscreenSurface(const gfxIntSize& size,
|
||||
gfxASurface::gfxImageFormat imageFormat)
|
||||
{
|
||||
// XXX we may be able to create a QPixmap here, instead of a QImage always
|
||||
nsRefPtr<gfxASurface> newSurface =
|
||||
new gfxQPainterSurface (size, imageFormat);
|
||||
|
||||
return newSurface.forget();
|
||||
}
|
||||
|
||||
nsresult
|
||||
gfxQtPlatform::GetFontList(const nsACString& aLangGroup,
|
||||
const nsACString& aGenericFamily,
|
||||
nsStringArray& aListOfFonts)
|
||||
{
|
||||
return sFontconfigUtils->GetFontList(aLangGroup, aGenericFamily,
|
||||
aListOfFonts);
|
||||
}
|
||||
|
||||
nsresult
|
||||
gfxQtPlatform::UpdateFontList()
|
||||
{
|
||||
FcPattern *pat = NULL;
|
||||
FcObjectSet *os = NULL;
|
||||
FcFontSet *fs = NULL;
|
||||
PRInt32 result = -1;
|
||||
|
||||
pat = FcPatternCreate();
|
||||
os = FcObjectSetBuild(FC_FAMILY, FC_FILE, FC_INDEX, FC_WEIGHT, FC_SLANT, FC_WIDTH, NULL);
|
||||
|
||||
fs = FcFontList(NULL, pat, os);
|
||||
|
||||
|
||||
for (int i = 0; i < fs->nfont; i++) {
|
||||
char *str;
|
||||
|
||||
if (FcPatternGetString(fs->fonts[i], FC_FAMILY, 0, (FcChar8 **) &str) != FcResultMatch)
|
||||
continue;
|
||||
|
||||
printf("Family: %s\n", str);
|
||||
|
||||
nsAutoString name(NS_ConvertUTF8toUTF16(nsDependentCString(str)).get());
|
||||
nsAutoString key(name);
|
||||
ToLowerCase(key);
|
||||
nsRefPtr<FontFamily> ff;
|
||||
if (!gPlatformFonts->Get(key, &ff)) {
|
||||
ff = new FontFamily(name);
|
||||
gPlatformFonts->Put(key, ff);
|
||||
}
|
||||
|
||||
nsRefPtr<FontEntry> fe = new FontEntry(ff->mName);
|
||||
ff->mFaces.AppendElement(fe);
|
||||
|
||||
if (FcPatternGetString(fs->fonts[i], FC_FILE, 0, (FcChar8 **) &str) == FcResultMatch) {
|
||||
fe->mFilename = nsDependentCString(str);
|
||||
printf(" - file: %s\n", str);
|
||||
}
|
||||
|
||||
int x;
|
||||
if (FcPatternGetInteger(fs->fonts[i], FC_INDEX, 0, &x) == FcResultMatch) {
|
||||
printf(" - index: %d\n", x);
|
||||
fe->mFTFontIndex = x;
|
||||
} else {
|
||||
fe->mFTFontIndex = 0;
|
||||
}
|
||||
|
||||
if (FcPatternGetInteger(fs->fonts[i], FC_WEIGHT, 0, &x) == FcResultMatch) {
|
||||
switch(x) {
|
||||
case 0:
|
||||
fe->mWeight = 100;
|
||||
break;
|
||||
case 40:
|
||||
fe->mWeight = 200;
|
||||
break;
|
||||
case 50:
|
||||
fe->mWeight = 300;
|
||||
break;
|
||||
case 75:
|
||||
case 80:
|
||||
fe->mWeight = 400;
|
||||
break;
|
||||
case 100:
|
||||
fe->mWeight = 500;
|
||||
break;
|
||||
case 180:
|
||||
fe->mWeight = 600;
|
||||
break;
|
||||
case 200:
|
||||
fe->mWeight = 700;
|
||||
break;
|
||||
case 205:
|
||||
fe->mWeight = 800;
|
||||
break;
|
||||
case 210:
|
||||
fe->mWeight = 900;
|
||||
break;
|
||||
default:
|
||||
// rough estimate
|
||||
fe->mWeight = (((x * 4) + 100) / 100) * 100;
|
||||
break;
|
||||
}
|
||||
printf(" - weight: %d\n", fe->mWeight);
|
||||
}
|
||||
|
||||
fe->mItalic = PR_FALSE;
|
||||
if (FcPatternGetInteger(fs->fonts[i], FC_SLANT, 0, &x) == FcResultMatch) {
|
||||
switch (x) {
|
||||
case FC_SLANT_ITALIC:
|
||||
case FC_SLANT_OBLIQUE:
|
||||
fe->mItalic = PR_TRUE;
|
||||
}
|
||||
printf(" - slant: %d\n", x);
|
||||
}
|
||||
|
||||
if (FcPatternGetInteger(fs->fonts[i], FC_WIDTH, 0, &x) == FcResultMatch)
|
||||
printf(" - width: %d\n", x);
|
||||
// XXX deal with font-stretch stuff later
|
||||
}
|
||||
|
||||
if (pat)
|
||||
FcPatternDestroy(pat);
|
||||
if (os)
|
||||
FcObjectSetDestroy(os);
|
||||
if (fs)
|
||||
FcFontSetDestroy(fs);
|
||||
|
||||
return sFontconfigUtils->UpdateFontList();
|
||||
}
|
||||
|
||||
nsresult
|
||||
gfxQtPlatform::ResolveFontName(const nsAString& aFontName,
|
||||
FontResolverCallback aCallback,
|
||||
void *aClosure,
|
||||
PRBool& aAborted)
|
||||
{
|
||||
return sFontconfigUtils->ResolveFontName(aFontName, aCallback,
|
||||
aClosure, aAborted);
|
||||
}
|
||||
|
||||
nsresult
|
||||
gfxQtPlatform::GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName)
|
||||
{
|
||||
return sFontconfigUtils->GetStandardFamilyName(aFontName, aFamilyName);
|
||||
}
|
||||
|
||||
gfxFontGroup *
|
||||
gfxQtPlatform::CreateFontGroup(const nsAString &aFamilies,
|
||||
const gfxFontStyle *aStyle)
|
||||
{
|
||||
return new gfxQtFontGroup(aFamilies, aStyle);
|
||||
}
|
||||
|
||||
/* static */
|
||||
void
|
||||
gfxQtPlatform::InitDPI()
|
||||
{
|
||||
if (sDPI <= 0) {
|
||||
// Fall back to something sane
|
||||
sDPI = 96;
|
||||
}
|
||||
}
|
||||
|
||||
cmsHPROFILE
|
||||
gfxQtPlatform::GetPlatformCMSOutputProfile()
|
||||
{
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
|
||||
FT_Library
|
||||
gfxQtPlatform::GetFTLibrary()
|
||||
{
|
||||
return gPlatformFTLibrary;
|
||||
}
|
||||
|
||||
FontFamily *
|
||||
gfxQtPlatform::FindFontFamily(const nsAString& aName)
|
||||
{
|
||||
nsAutoString name(aName);
|
||||
ToLowerCase(name);
|
||||
|
||||
nsRefPtr<FontFamily> ff;
|
||||
if (!gPlatformFonts->Get(name, &ff)) {
|
||||
return nsnull;
|
||||
}
|
||||
return ff.get();
|
||||
}
|
||||
|
||||
FontEntry *
|
||||
gfxQtPlatform::FindFontEntry(const nsAString& aName, const gfxFontStyle& aFontStyle)
|
||||
{
|
||||
nsRefPtr<FontFamily> ff = FindFontFamily(aName);
|
||||
if (!ff)
|
||||
return nsnull;
|
||||
|
||||
return ff->FindFontEntry(aFontStyle);
|
||||
}
|
|
@ -0,0 +1,115 @@
|
|||
#
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public License Version
|
||||
# 1.1 (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
# http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
# for the specific language governing rights and limitations under the
|
||||
# License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is
|
||||
# Netscape Communications Corporation.
|
||||
# Portions created by the Initial Developer are Copyright (C) 1998
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# John C. Griggs <johng@corel.com>
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
# in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
# of those above. If you wish to allow use of your version of this file only
|
||||
# under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
# use your version of this file under the terms of the MPL, indicate your
|
||||
# decision by deleting the provisions above and replace them with the notice
|
||||
# and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
# the provisions above, a recipient may use your version of this file under
|
||||
# the terms of any one of the MPL, the GPL or the LGPL.
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = widget
|
||||
LIBRARY_NAME = widget_qt
|
||||
EXPORT_LIBRARY = 1
|
||||
IS_COMPONENT = 1
|
||||
MODULE_NAME = nsWidgetQtModule
|
||||
GRE_MODULE = 1
|
||||
LIBXUL_LIBRARY = 1
|
||||
|
||||
REQUIRES = xpcom \
|
||||
string \
|
||||
gfx \
|
||||
layout \
|
||||
content \
|
||||
dom \
|
||||
appshell \
|
||||
pref \
|
||||
uconv \
|
||||
necko \
|
||||
view \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
nsWidgetFactory.cpp \
|
||||
nsToolkit.cpp \
|
||||
$(NULL)
|
||||
|
||||
SHARED_LIBRARY_LIBS = ../xpwidgets/libxpwidgets_s.a
|
||||
|
||||
EXTRA_DSO_LDOPTS = \
|
||||
$(MOZ_COMPONENT_LIBS) \
|
||||
-lgkgfx \
|
||||
-lthebes \
|
||||
$(LCMS_LIBS) \
|
||||
$(MOZ_JS_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
|
||||
EXTRA_DSO_LDOPTS += -L$(DIST)/lib $(MOZ_XLIB_LDFLAGS)
|
||||
|
||||
# If not primary toolkit, install in secondary path
|
||||
ifneq (qt,$(MOZ_WIDGET_TOOLKIT))
|
||||
INACTIVE_COMPONENT = 1
|
||||
endif
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
CXXFLAGS += $(MOZ_QT_CFLAGS)
|
||||
CFLAGS += $(MOZ_QT_CFLAGS)
|
||||
|
||||
DEFINES += -D_IMPL_NS_WIDGET
|
||||
|
||||
ifeq ($(OS_ARCH), Linux)
|
||||
DEFINES += -D_BSD_SOURCE
|
||||
endif
|
||||
ifeq ($(OS_ARCH), SunOS)
|
||||
ifndef GNU_CC
|
||||
# When using Sun's WorkShop compiler, including
|
||||
# /wherever/workshop-5.0/SC5.0/include/CC/std/time.h
|
||||
# causes most of these compiles to fail with:
|
||||
# line 29: Error: Multiple declaration for std::tm.
|
||||
# So, this gets around the problem.
|
||||
DEFINES += -D_TIME_H=1
|
||||
endif
|
||||
endif
|
||||
|
||||
LOCAL_INCLUDES = \
|
||||
-I$(srcdir)/../xpwidgets \
|
||||
-I$(srcdir) \
|
||||
$(NULL)
|
||||
|
|
@ -0,0 +1,119 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Lars Knoll <knoll@kde.org>
|
||||
* Zack Rusin <zack@kde.org>
|
||||
* John C. Griggs <johng@corel.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nscore.h" // needed for 'nsnull'
|
||||
#include "nsToolkit.h"
|
||||
#include "nsGUIEvent.h"
|
||||
//#include "plevent.h"
|
||||
|
||||
// Static thread local storage index of the Toolkit
|
||||
// object associated with a given thread...
|
||||
static PRUintn gToolkitTLSIndex = 0;
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// constructor
|
||||
//-------------------------------------------------------------------------
|
||||
nsToolkit::nsToolkit()
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// destructor
|
||||
//-------------------------------------------------------------------------
|
||||
nsToolkit::~nsToolkit()
|
||||
{
|
||||
// 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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
nsIToolkit* toolkit = nsnull;
|
||||
nsresult rv = NS_OK;
|
||||
PRStatus status;
|
||||
|
||||
// Create the TLS index the first time through...
|
||||
if (0 == gToolkitTLSIndex) {
|
||||
status = PR_NewThreadPrivateIndex(&gToolkitTLSIndex, NULL);
|
||||
if (PR_FAILURE == status) {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
toolkit = (nsIToolkit*)PR_GetThreadPrivate(gToolkitTLSIndex);
|
||||
|
||||
// Create a new toolkit for this thread...
|
||||
if (!toolkit) {
|
||||
toolkit = new nsToolkit();
|
||||
|
||||
if (!toolkit) {
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
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 {
|
||||
NS_ADDREF(toolkit);
|
||||
}
|
||||
*aResult = toolkit;
|
||||
}
|
||||
return rv;
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* John C. Griggs <johng@corel.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#ifndef nsToolkit_h__
|
||||
#define nsToolkit_h__
|
||||
|
||||
#include "nsIToolkit.h"
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_IMETHOD Init(PRThread *aThread);
|
||||
};
|
||||
|
||||
#endif // nsToolkit_h__
|
|
@ -0,0 +1,163 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* John C. Griggs <johng@corel.com>.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Zack Rusin <zack@kde.org>
|
||||
* Lars Knoll <knoll@kde.org>
|
||||
* John C. Griggs <johng@corel.com>
|
||||
* Dan Rosen <dr@netscape.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsIModule.h"
|
||||
// #include "nsCOMPtr.h"
|
||||
// #include "nsWidgetsCID.h"
|
||||
// #include "nsIComponentRegistrar.h"
|
||||
// #include "nsComponentManagerUtils.h"
|
||||
// #include "nsAutoPtr.h"
|
||||
//
|
||||
// #include "nsWindow.h"
|
||||
// #include "nsAppShell.h"
|
||||
// #include "nsToolkit.h"
|
||||
// #include "nsLookAndFeel.h"
|
||||
// #include "nsTransferable.h"
|
||||
// #include "nsClipboard.h"
|
||||
// #include "nsClipboardHelper.h"
|
||||
// #include "nsHTMLFormatConverter.h"
|
||||
// #include "nsDragService.h"
|
||||
// #include "nsScrollbar.h"
|
||||
// #include "nsFilePicker.h"
|
||||
// #include "nsSound.h"
|
||||
//
|
||||
// #include "nsGUIEvent.h"
|
||||
// #include "nsQtEventDispatcher.h"
|
||||
// #include "nsIRenderingContext.h"
|
||||
// #include "nsIServiceManager.h"
|
||||
// #include "nsGfxCIID.h"
|
||||
// #include "nsIPrefBranch.h"
|
||||
// #include "nsIPrefService.h"
|
||||
//
|
||||
// #include "nsBidiKeyboard.h"
|
||||
// #include "nsNativeThemeQt.h"
|
||||
/*
|
||||
static NS_DEFINE_CID(kNativeScrollCID, NS_NATIVESCROLLBAR_CID);
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsWindow)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(ChildWindow)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(PopupWindow)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAppShell)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsToolkit)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsLookAndFeel)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsTransferable)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboard)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboardHelper)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLFormatConverter)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDragService)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsBidiKeyboard)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsNativeScrollbar)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSound)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFilePicker)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsNativeThemeQt)
|
||||
*/
|
||||
static const nsModuleComponentInfo components[] =
|
||||
{
|
||||
/*
|
||||
{ "Qt nsWindow",
|
||||
NS_WINDOW_CID,
|
||||
"@mozilla.org/widgets/window/qt;1",
|
||||
nsWindowConstructor },
|
||||
{ "Qt Child nsWindow",
|
||||
NS_CHILD_CID,
|
||||
"@mozilla.org/widgets/child_window/qt;1",
|
||||
ChildWindowConstructor },
|
||||
{ "Qt Popup nsWindow",
|
||||
NS_POPUP_CID,
|
||||
"@mozilla.org/widgets/popup_window/qt;1",
|
||||
PopupWindowConstructor },
|
||||
{ "Qt Native Scrollbar",
|
||||
NS_NATIVESCROLLBAR_CID,
|
||||
"@mozilla.org/widget/nativescrollbar/qt;1",
|
||||
nsNativeScrollbarConstructor},
|
||||
{ "Qt AppShell",
|
||||
NS_APPSHELL_CID,
|
||||
"@mozilla.org/widget/appshell/qt;1",
|
||||
nsAppShellConstructor },
|
||||
{ "Qt Toolkit",
|
||||
NS_TOOLKIT_CID,
|
||||
"@mozilla.org/widget/toolkit/qt;1",
|
||||
nsToolkitConstructor },
|
||||
{ "Qt Look And Feel",
|
||||
NS_LOOKANDFEEL_CID,
|
||||
"@mozilla.org/widget/lookandfeel/qt;1",
|
||||
nsLookAndFeelConstructor },
|
||||
{ "Transferrable",
|
||||
NS_TRANSFERABLE_CID,
|
||||
"@mozilla.org/widget/transferable;1",
|
||||
nsTransferableConstructor },
|
||||
{ "Qt Clipboard",
|
||||
NS_CLIPBOARD_CID,
|
||||
"@mozilla.org/widget/clipboard;1",
|
||||
nsClipboardConstructor },
|
||||
{ "Clipboard Helper",
|
||||
NS_CLIPBOARDHELPER_CID,
|
||||
"@mozilla.org/widget/clipboardhelper;1",
|
||||
nsClipboardHelperConstructor },
|
||||
{ "HTML Format Converter",
|
||||
NS_HTMLFORMATCONVERTER_CID,
|
||||
"@mozilla.org/widget/htmlformatconverter/qt;1",
|
||||
nsHTMLFormatConverterConstructor },
|
||||
{ "Qt Drag Service",
|
||||
NS_DRAGSERVICE_CID,
|
||||
"@mozilla.org/widget/dragservice;1",
|
||||
nsDragServiceConstructor },
|
||||
{ "Qt Bidi Keyboard",
|
||||
NS_BIDIKEYBOARD_CID,
|
||||
"@mozilla.org/widget/bidikeyboard;1",
|
||||
nsBidiKeyboardConstructor },
|
||||
{ "Qt Sound",
|
||||
NS_SOUND_CID,
|
||||
"@mozilla.org/sound;1",
|
||||
nsSoundConstructor },
|
||||
{ "Qt File Picker",
|
||||
NS_FILEPICKER_CID,
|
||||
"@mozilla.org/filepicker;1",
|
||||
nsFilePickerConstructor },
|
||||
{ "Native Theme Renderer",
|
||||
NS_THEMERENDERER_CID,
|
||||
"@mozilla.org/chrome/chrome-native-theme;1",
|
||||
nsNativeThemeQtConstructor }
|
||||
*/
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE(nsWidgetQtModule,components)
|
Загрузка…
Ссылка в новой задаче