r = mkaply, a = brendan
OS/2 bringup - remove obsolete widgets, begin font work, get filepicker working
This commit is contained in:
mkaply%us.ibm.com 2000-07-05 19:53:21 +00:00
Родитель e0dd0ccfd2
Коммит a271ea2d06
10 изменённых файлов: 962 добавлений и 22 удалений

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

@ -27,6 +27,7 @@ LIBRARY_NAME = wdgtos2
EXTRA_DSO_LIBS = nggfx
REQUIRES = util img xpcom raptor netlib
DIRS = res
@ -38,38 +39,46 @@ CSRCS = tabctrl.c
CPPSRCS = \
nsAppShell.cpp \
nsBaseList.cpp \
nsCanvas.cpp \
nsCheckbutton.cpp \
nsCombobox.cpp \
nsDirPicker.cpp \
nsEntryField.cpp \
nsFSTree.cpp \
nsFileDialog.cpp \
nsFontServices.cpp \
nsFilePicker.cpp \
nsFontRetrieverService.cpp \
nsFontSizeIterator.cpp \
nsFrameWindow.cpp \
nsLabel.cpp \
nsListbox.cpp \
nsLookAndFeel.cpp \
nsModule.cpp \
nsPushbutton.cpp \
nsRadiobutton.cpp \
nsScrollbar.cpp \
nsSound.cpp \
nsTextArea.cpp \
nsToolkit.cpp \
nsTooltipManager.cpp \
nsWidgetFactory.cpp \
nsWindow.cpp \
$(NULL)
# XXX FILES temporarily removed
# nsClipboard.cpp \
# nsDragService.cpp \
# nsClipboard.cpp \
# nsDragService.cpp \
# nsITabWidget and nsITooltipWidget appear to have been scrapped
# nsTabWidget.cpp \
# nsTooltipWidget.cpp \
# XXX OS2TODO
# nsNativeDragTarget.cpp \
# nsNativeDragSource.cpp \
# nsDataObj.cpp \
# nsDataObjCollection.cpp \
# OBSOLETE FILES
# nsBaseList.cpp \
# nsCheckbutton.cpp \
# nsCombobox.cpp \
# nsEntryField.cpp \
# nsLabel.cpp \
# nsListbox.cpp \
# nsPushbutton.cpp \
# nsRadiobutton.cpp \
# nsTextArea.cpp \
# nsTooltipManager.cpp \
# nsTabWidget.cpp \
# nsTooltipWidget.cpp \
SHARED_LIBRARY_LIBS = $(DIST)/lib/libxpwidgets_s.$(LIB_SUFFIX)

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

@ -0,0 +1,512 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Stuart Parmenter <pavlov@netscape.com>
* Henry Sobotka <sobotka@axess.com>: OS/2 adaptation
*/
#include "nsCOMPtr.h"
#include "nsIServiceManager.h"
#define NS_IMPL_IDS
#include "nsIPlatformCharset.h"
#undef NS_IMPL_IDS
#include "nsFilePicker.h"
#include "nsILocalFile.h"
#include "nsIURL.h"
#include "nsIStringBundle.h"
#include "nsDirPicker.h"
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID);
#define FILEPICKER_PROPERTIES "chrome://global/locale/filepicker.properties"
NS_IMPL_ISUPPORTS1(nsFilePicker, nsIFilePicker)
//-------------------------------------------------------------------------
//
// nsFilePicker constructor
//
//-------------------------------------------------------------------------
nsFilePicker::nsFilePicker()
{
NS_INIT_REFCNT();
mWnd = NULL;
mUnicodeEncoder = nsnull;
mUnicodeDecoder = nsnull;
mDisplayDirectory = do_CreateInstance("component://mozilla/file/local");
}
//-------------------------------------------------------------------------
//
// nsFilePicker destructor
//
//-------------------------------------------------------------------------
nsFilePicker::~nsFilePicker()
{
NS_IF_RELEASE(mUnicodeEncoder);
NS_IF_RELEASE(mUnicodeDecoder);
}
//-------------------------------------------------------------------------
//
// Show - Display the file dialog
//
//-------------------------------------------------------------------------
NS_IMETHODIMP nsFilePicker::Show(PRInt16 *retval)
{
NS_ENSURE_ARG_POINTER(retval);
PRBool result = PR_FALSE;
char fileBuffer[CCHMAXPATH+1] = "";
char *converted = ConvertToFileSystemCharset(mDefault.GetUnicode());
if (nsnull == converted) {
mDefault.ToCString(fileBuffer,CCHMAXPATH);
}
else {
PL_strcpy(fileBuffer, converted);
nsMemory::Free( converted );
}
char *title = ConvertToFileSystemCharset(mTitle.GetUnicode());
if (nsnull == title)
title = mTitle.ToNewCString();
char *initialDir;
mDisplayDirectory->GetPath(&initialDir);
mFile.SetLength(0);
#ifdef XP_OS2
if (mMode == modeGetFolder) {
DIRPICKER dp = { { 0 }, 0, TRUE, 0 }; // modal dialog
HWND ret = FS_PickDirectory(HWND_DESKTOP, mWnd,
gModuleData.hModResources, &dp);
if (ret && dp.lReturn == DID_OK) {
result = PR_TRUE;
mDisplayDirectory->InitWithPath(dp.szFullFile);
mFile.Append(dp.szFullFile);
}
}
else {
FILEDLG fdlg;
memset(&fdlg, 0, sizeof(FILEDLG));
fdlg.cbSize = sizeof(FILEDLG);
fdlg.fl = FDS_CENTER;
fdlg.pszTitle = title;
// XXX Unused because presently "All Files"
// char *filterBuffer = mFilterList.ToNewCString();
// strcpy(fdlg.szFullFile, filterBuffer);
if (mMode == modeOpen)
fdlg.fl |= FDS_OPEN_DIALOG;
else if (mMode == modeSave) {
fdlg.fl |= FDS_SAVEAS_DIALOG | FDS_ENABLEFILELB;
// OS2TODO:
// get URL leaf (if path ends in '/', use "index.html")
// and display in filename field
}
else
NS_ASSERTION(0, "Only open and save modes supported");
WinFileDlg( HWND_DESKTOP, mWnd, &fdlg);
if (fdlg.lReturn == DID_OK) {
result = PR_TRUE;
mDisplayDirectory->InitWithPath(fdlg.szFullFile);
mFile.Append(fdlg.szFullFile);
}
// XXX For when filters work
// if (filterBuffer)
// nsMemory::Free(filterBuffer);
}
#else // Windows version for reference
if (mMode == modeGetFolder) {
BROWSEINFO browserInfo;
browserInfo.hwndOwner = mWnd;
browserInfo.pidlRoot = nsnull;
browserInfo.pszDisplayName = (LPSTR)initialDir;
browserInfo.lpszTitle = title;
browserInfo.ulFlags = BIF_RETURNONLYFSDIRS;//BIF_STATUSTEXT | BIF_RETURNONLYFSDIRS;
browserInfo.lpfn = nsnull;
browserInfo.lParam = nsnull;
browserInfo.iImage = nsnull;
// XXX UNICODE support is needed here --> DONE
LPITEMIDLIST list = ::SHBrowseForFolder(&browserInfo);
if (list != NULL) {
result = ::SHGetPathFromIDList(list, (LPSTR)fileBuffer);
if (result) {
// XXXX ???? nothing done with pathStr - Henry
nsAutoString pathStr;
PRUnichar *unichar = ConvertFromFileSystemCharset(fileBuffer);
if (nsnull == unichar)
pathStr.AssignWithConversion(fileBuffer);
else {
pathStr.Assign(unichar);
nsMemory::Free( unichar );
}
if (result == PR_TRUE) {
// I think it also needs a conversion here (to unicode since appending to nsString)
// but doing that generates garbage file name, weird.
mFile.Append(fileBuffer);
}
}
}
}
else {
OPENFILENAME ofn;
memset(&ofn, 0, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
char *filterBuffer = mFilterList.ToNewCString();
if (initialDir && *initialDir) {
ofn.lpstrInitialDir = initialDir;
}
ofn.lpstrTitle = title;
ofn.lpstrFilter = filterBuffer;
ofn.nFilterIndex = 1;
ofn.hwndOwner = mWnd;
ofn.lpstrFile = fileBuffer;
ofn.nMaxFile = MAX_PATH;
// XXX use OFN_NOCHANGEDIR for M5
ofn.Flags = OFN_SHAREAWARE | OFN_LONGNAMES | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;
if (mMode == modeOpen) {
// FILE MUST EXIST!
ofn.Flags |= OFN_FILEMUSTEXIST;
result = ::GetOpenFileName(&ofn);
}
else if (mMode == modeSave) {
result = ::GetSaveFileName(&ofn);
}
else {
NS_ASSERTION(0, "Only load, save and getFolder are supported modes");
}
// Remember what filter type the user selected
mSelectedType = (PRInt16)ofn.nFilterIndex;
// Store the current directory in mDisplayDirectory
char* newCurrentDirectory = NS_STATIC_CAST( char*, nsMemory::Alloc( MAX_PATH+1 ) );
VERIFY(::GetCurrentDirectory(MAX_PATH, newCurrentDirectory) > 0);
mDisplayDirectory->InitWithPath(newCurrentDirectory);
nsMemory::Free( newCurrentDirectory );
// Clean up filter buffers
if (filterBuffer)
nsMemory::Free( filterBuffer );
// Set user-selected location of file or directory
if (result == PR_TRUE) {
// I think it also needs a conversion here (to unicode since appending to nsString)
// but doing that generates garbage file name, weird.
mFile.Append(fileBuffer);
}
}
#endif
if (title)
nsMemory::Free(title);
if (result)
*retval = returnOK;
else
*retval = returnCancel;
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Set the list of filters
//
//-------------------------------------------------------------------------
NS_IMETHODIMP nsFilePicker::AppendFilters(PRInt32 aFilterMask)
{
nsresult rv;
nsCOMPtr<nsIStringBundleService> stringService = do_GetService(kStringBundleServiceCID);
nsCOMPtr<nsIStringBundle> stringBundle;
nsILocale *locale = nsnull;
rv = stringService->CreateBundle(FILEPICKER_PROPERTIES, locale, getter_AddRefs(stringBundle));
if (NS_FAILED(rv))
return NS_ERROR_FAILURE;
PRUnichar *title;
PRUnichar *filter;
if (aFilterMask & filterAll) {
stringBundle->GetStringFromName(NS_ConvertASCIItoUCS2("allTitle").GetUnicode(), &title);
stringBundle->GetStringFromName(NS_ConvertASCIItoUCS2("allFilter").GetUnicode(), &filter);
AppendFilter(title,filter);
}
if (aFilterMask & filterHTML) {
stringBundle->GetStringFromName(NS_ConvertASCIItoUCS2("htmlTitle").GetUnicode(), &title);
stringBundle->GetStringFromName(NS_ConvertASCIItoUCS2("htmlFilter").GetUnicode(), &filter);
AppendFilter(title,filter);
}
if (aFilterMask & filterText) {
stringBundle->GetStringFromName(NS_ConvertASCIItoUCS2("textTitle").GetUnicode(), &title);
stringBundle->GetStringFromName(NS_ConvertASCIItoUCS2("textFilter").GetUnicode(), &filter);
AppendFilter(title,filter);
}
if (aFilterMask & filterImages) {
stringBundle->GetStringFromName(NS_ConvertASCIItoUCS2("imageTitle").GetUnicode(), &title);
stringBundle->GetStringFromName(NS_ConvertASCIItoUCS2("imageFilter").GetUnicode(), &filter);
AppendFilter(title,filter);
}
if (aFilterMask & filterXML) {
stringBundle->GetStringFromName(NS_ConvertASCIItoUCS2("xmlTitle").GetUnicode(), &title);
stringBundle->GetStringFromName(NS_ConvertASCIItoUCS2("xmlFilter").GetUnicode(), &filter);
AppendFilter(title,filter);
}
if (aFilterMask & filterXUL) {
stringBundle->GetStringFromName(NS_ConvertASCIItoUCS2("xulTitle").GetUnicode(), &title);
stringBundle->GetStringFromName(NS_ConvertASCIItoUCS2("xulFilter").GetUnicode(), &filter);
AppendFilter(title, filter);
}
return NS_OK;
}
NS_IMETHODIMP nsFilePicker::AppendFilter(const PRUnichar *aTitle,
const PRUnichar *aFilter)
{
mFilterList.Append(aTitle);
mFilterList.AppendWithConversion('\0');
mFilterList.Append(aFilter);
mFilterList.AppendWithConversion('\0');
return NS_OK;
}
NS_IMETHODIMP nsFilePicker::GetFile(nsILocalFile **aFile)
{
NS_ENSURE_ARG_POINTER(aFile);
if (mFile.IsEmpty())
return NS_OK;
nsCOMPtr<nsILocalFile> file(do_CreateInstance("component://mozilla/file/local"));
NS_ENSURE_TRUE(file, NS_ERROR_FAILURE);
file->InitWithPath(mFile);
NS_ADDREF(*aFile = file);
return NS_OK;
}
//-------------------------------------------------------------------------
NS_IMETHODIMP nsFilePicker::GetFileURL(nsIFileURL **aFileURL)
{
nsCOMPtr<nsILocalFile> file(do_CreateInstance("component://mozilla/file/local"));
NS_ENSURE_TRUE(file, NS_ERROR_FAILURE);
file->InitWithPath(mFile);
nsCOMPtr<nsIFileURL> fileURL(do_CreateInstance("component://netscape/network/standard-url"));
NS_ENSURE_TRUE(fileURL, NS_ERROR_FAILURE);
fileURL->SetFile(file);
NS_ADDREF(*aFileURL = fileURL);
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Get the file + path
//
//-------------------------------------------------------------------------
NS_IMETHODIMP nsFilePicker::SetDefaultString(const PRUnichar *aString)
{
mDefault = aString;
return NS_OK;
}
NS_IMETHODIMP nsFilePicker::GetDefaultString(PRUnichar **aString)
{
return NS_ERROR_FAILURE;
}
//-------------------------------------------------------------------------
//
// Set the display directory
//
//-------------------------------------------------------------------------
NS_IMETHODIMP nsFilePicker::SetDisplayDirectory(nsILocalFile *aDirectory)
{
mDisplayDirectory = aDirectory;
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Get the display directory
//
//-------------------------------------------------------------------------
NS_IMETHODIMP nsFilePicker::GetDisplayDirectory(nsILocalFile **aDirectory)
{
*aDirectory = mDisplayDirectory;
NS_IF_ADDREF(*aDirectory);
return NS_OK;
}
NS_IMETHODIMP nsFilePicker::Init(nsIDOMWindow *aParent,
const PRUnichar *aTitle,
PRInt16 aMode)
{
return nsBaseFilePicker::Init(aParent, aTitle, aMode);
}
//-------------------------------------------------------------------------
NS_IMETHODIMP nsFilePicker::InitNative(nsIWidget *aParent,
const PRUnichar *aTitle,
PRInt16 aMode)
{
mWnd = (HWND) ((aParent) ? aParent->GetNativeData(NS_NATIVE_WINDOW) : 0);
mTitle.SetLength(0);
mTitle.Append(aTitle);
mMode = aMode;
return NS_OK;
}
//-------------------------------------------------------------------------
void nsFilePicker::GetFileSystemCharset(nsString & fileSystemCharset)
{
static nsAutoString aCharset;
nsresult rv;
if (aCharset.Length() < 1) {
nsCOMPtr <nsIPlatformCharset> platformCharset = do_GetService(NS_PLATFORMCHARSET_PROGID, &rv);
if (NS_SUCCEEDED(rv))
rv = platformCharset->GetCharset(kPlatformCharsetSel_FileName, aCharset);
NS_ASSERTION(NS_SUCCEEDED(rv), "error getting platform charset");
if (NS_FAILED(rv))
aCharset.AssignWithConversion("ISO-8859-1");
}
fileSystemCharset = aCharset;
}
//-------------------------------------------------------------------------
char * nsFilePicker::ConvertToFileSystemCharset(const PRUnichar *inString)
{
char *outString = nsnull;
nsresult rv = NS_OK;
// get file system charset and create a unicode encoder
if (nsnull == mUnicodeEncoder) {
nsAutoString fileSystemCharset;
GetFileSystemCharset(fileSystemCharset);
NS_WITH_SERVICE(nsICharsetConverterManager, ccm, kCharsetConverterManagerCID, &rv);
if (NS_SUCCEEDED(rv)) {
rv = ccm->GetUnicodeEncoder(&fileSystemCharset, &mUnicodeEncoder);
}
}
// converts from unicode to the file system charset
if (NS_SUCCEEDED(rv)) {
PRInt32 inLength = nsCRT::strlen(inString);
PRInt32 outLength;
rv = mUnicodeEncoder->GetMaxLength(inString, inLength, &outLength);
if (NS_SUCCEEDED(rv)) {
outString = NS_STATIC_CAST( char*, nsMemory::Alloc( outLength+1 ) );
if (nsnull == outString) {
return nsnull;
}
rv = mUnicodeEncoder->Convert(inString, &inLength, outString, &outLength);
if (NS_SUCCEEDED(rv)) {
outString[outLength] = '\0';
}
}
}
return NS_SUCCEEDED(rv) ? outString : nsnull;
}
//-------------------------------------------------------------------------
PRUnichar * nsFilePicker::ConvertFromFileSystemCharset(const char *inString)
{
PRUnichar *outString = nsnull;
nsresult rv = NS_OK;
// get file system charset and create a unicode encoder
if (nsnull == mUnicodeDecoder) {
nsAutoString fileSystemCharset;
GetFileSystemCharset(fileSystemCharset);
NS_WITH_SERVICE(nsICharsetConverterManager, ccm, kCharsetConverterManagerCID, &rv);
if (NS_SUCCEEDED(rv)) {
rv = ccm->GetUnicodeDecoder(&fileSystemCharset, &mUnicodeDecoder);
}
}
// converts from the file system charset to unicode
if (NS_SUCCEEDED(rv)) {
PRInt32 inLength = nsCRT::strlen(inString);
PRInt32 outLength;
rv = mUnicodeDecoder->GetMaxLength(inString, inLength, &outLength);
if (NS_SUCCEEDED(rv)) {
outString = NS_STATIC_CAST( PRUnichar*, nsMemory::Alloc( (outLength+1) * sizeof( PRUnichar ) ) );
if (nsnull == outString) {
return nsnull;
}
rv = mUnicodeDecoder->Convert(inString, &inLength, outString, &outLength);
if (NS_SUCCEEDED(rv)) {
outString[outLength] = 0;
}
}
}
NS_ASSERTION(NS_SUCCEEDED(rv), "error charset conversion");
return NS_SUCCEEDED(rv) ? outString : nsnull;
}

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

@ -0,0 +1,73 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Stuart Parmenter <pavlov@netscape.com>
* Henry Sobotka <sobotka@axess.com>: OS/2 adaptation
*/
#ifndef nsFilePicker_h__
#define nsFilePicker_h__
#define NS_IMPL_IDS
#include "nsICharsetConverterManager.h"
#undef NS_IMPL_IDS
#include "nsBaseFilePicker.h"
#include "nsString.h"
#include "nsWidgetDefs.h"
/**
* OS/2 FileSelector wrapper
*/
class nsFilePicker : public nsBaseFilePicker
{
public:
nsFilePicker();
virtual ~nsFilePicker();
NS_DECL_ISUPPORTS
NS_DECL_NSIFILEPICKER
protected:
/* method from nsBaseFilePicker */
NS_IMETHOD InitNative(nsIWidget *aParent,
const PRUnichar *aTitle,
PRInt16 aMode);
void GetFilterListArray(nsString& aFilterList);
static void GetFileSystemCharset(nsString & fileSystemCharset);
char * ConvertToFileSystemCharset(const PRUnichar *inString);
PRUnichar * ConvertFromFileSystemCharset(const char *inString);
HWND mWnd;
nsString mTitle;
PRInt16 mMode;
nsCString mFile;
nsString mFilterList;
nsString mDefault;
nsIUnicodeEncoder* mUnicodeEncoder;
nsIUnicodeDecoder* mUnicodeDecoder;
nsCOMPtr<nsILocalFile> mDisplayDirectory;
PRInt16 mSelectedType;
};
#endif // nsFilePicker_h__

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

@ -0,0 +1,244 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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):
* Pierre Phaneuf <pp@ludusdesign.com>
* Henry Sobotka <sobotka@axess.com>: OS/2 adaptation
*/
#include "nsFontRetrieverService.h"
#include "nsFont.h"
#include "nsVoidArray.h"
#include "nsFontSizeIterator.h"
NS_IMPL_ADDREF(nsFontRetrieverService)
NS_IMPL_RELEASE(nsFontRetrieverService)
//----------------------------------------------------------
nsFontRetrieverService::nsFontRetrieverService()
{
NS_INIT_REFCNT();
mFontList = nsnull;
mSizeIter = nsnull;
mNameIterInx = 0;
}
//----------------------------------------------------------
nsFontRetrieverService::~nsFontRetrieverService()
{
if (nsnull != mFontList) {
for (PRInt32 i=0;i<mFontList->Count();i++) {
FontInfo * font = (FontInfo *)mFontList->ElementAt(i);
if (font->mSizes) {
delete font->mSizes;
}
delete font;
}
delete mFontList;
}
NS_IF_RELEASE(mSizeIter);
}
/**
* @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 nsFontRetrieverService::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
nsresult rv = NS_NOINTERFACE;
if (aIID.Equals(NS_GET_IID(nsIFontRetrieverService))) {
*aInstancePtr = (void*) ((nsIFontRetrieverService*)this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(NS_GET_IID(nsIFontNameIterator))) {
*aInstancePtr = (void*) ((nsIFontNameIterator*)this);
NS_ADDREF_THIS();
return NS_OK;
}
return rv;
}
//----------------------------------------------------------
//-- nsIFontRetrieverService
//----------------------------------------------------------
NS_IMETHODIMP nsFontRetrieverService::CreateFontNameIterator( nsIFontNameIterator** aIterator )
{
if (nsnull == aIterator) {
return NS_ERROR_FAILURE;
}
if (nsnull == mFontList) {
LoadFontList();
}
*aIterator = this;
NS_ADDREF_THIS();
return NS_OK;
}
//----------------------------------------------------------
NS_IMETHODIMP nsFontRetrieverService::CreateFontSizeIterator( const nsString &aFontName,
nsIFontSizeIterator** aIterator )
{
// cache current value in case someone else externally is using it
PRInt32 saveIterInx = mNameIterInx;
PRBool found = PR_FALSE;
Reset();
do {
nsAutoString name;
Get(&name);
if (name.Equals(aFontName)) {
found = PR_TRUE;
break;
}
} while (Advance() == NS_OK);
if (found) {
if (nsnull == mSizeIter) {
mSizeIter = new nsFontSizeIterator();
}
NS_ASSERTION( nsnull != mSizeIter, "nsFontSizeIterator instance pointer is null");
*aIterator = (nsIFontSizeIterator *)mSizeIter;
NS_ADDREF(mSizeIter);
FontInfo * fontInfo = (FontInfo *)mFontList->ElementAt(mNameIterInx);
mSizeIter->SetFontInfo(fontInfo);
mNameIterInx = saveIterInx;
return NS_OK;
}
mNameIterInx = saveIterInx;
return NS_ERROR_FAILURE;
}
//----------------------------------------------------------
//-- nsIFontNameIterator
//----------------------------------------------------------
NS_IMETHODIMP nsFontRetrieverService::Reset()
{
mNameIterInx = 0;
return NS_OK;
}
//----------------------------------------------------------
NS_IMETHODIMP nsFontRetrieverService::Get( nsString* aFontName )
{
if (mNameIterInx < mFontList->Count()) {
FontInfo * fontInfo = (FontInfo *)mFontList->ElementAt(mNameIterInx);
*aFontName = fontInfo->mName;
return NS_OK;
}
return NS_ERROR_FAILURE;
}
//----------------------------------------------------------
NS_IMETHODIMP nsFontRetrieverService::Advance()
{
if (mNameIterInx < mFontList->Count()-1) {
mNameIterInx++;
return NS_OK;
}
return NS_ERROR_FAILURE;
}
//----------------------------------------------------------
NS_IMETHODIMP nsFontRetrieverService::LoadFontList()
{
if (nsnull == mFontList) {
mFontList = new nsVoidArray();
if (nsnull == mFontList) {
return NS_ERROR_FAILURE;
}
}
HPS hps = WinGetScreenPS(HWND_DESKTOP);
LONG lWant = 0, lFonts;
// Get number of fonts
lFonts = GpiQueryFonts(hps, QF_PUBLIC | QF_PRIVATE,
0, &lWant, 0, 0);
PFONTMETRICS fMetrics = new FONTMETRICS[lFonts];
// Get fontmetrics
GpiQueryFonts(hps, QF_PUBLIC | QF_PRIVATE, 0, &lFonts,
sizeof(FONTMETRICS), fMetrics);
// Load fonts
for (LONG i = 0; i < lFonts; i++) {
FontInfo * font = new FontInfo();
font->mName.AssignWithConversion(fMetrics[i].szFamilyname);
font->mIsScalable = PR_FALSE;
font->mSizes = nsnull;
#ifdef DEBUG_sobotka
printf("Added FONT %s\n", font->mName.ToNewCString());
#endif
mFontList->AppendElement(font);
}
// Clean up
delete[] fMetrics;
WinReleasePS(hps);
return NS_OK;
}
//----------------------------------------------------------
NS_IMETHODIMP nsFontRetrieverService::IsFontScalable( const nsString &aFontName, PRBool* aResult )
{
// cache current value in case someone else externally is using it
PRInt32 saveIterInx = mNameIterInx;
PRBool found = PR_FALSE;
Reset();
do {
nsAutoString name;
Get(&name);
if (name.Equals(aFontName)) {
found = PR_TRUE;
break;
}
} while (Advance() == NS_OK);
if (found) {
FontInfo * fontInfo = (FontInfo *)mFontList->ElementAt(mNameIterInx);
*aResult = fontInfo->mIsScalable;
mNameIterInx = saveIterInx;
return NS_OK;
}
mNameIterInx = saveIterInx;
return NS_ERROR_FAILURE;
}

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

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

@ -0,0 +1,89 @@
/* -*- 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):
* Pierre Phaneuf <pp@ludusdesign.com>
*/
#include "nsFontSizeIterator.h"
#include "nsFont.h"
#include "nsVoidArray.h"
NS_IMPL_ADDREF(nsFontSizeIterator)
NS_IMPL_RELEASE(nsFontSizeIterator)
NS_IMPL_QUERY_INTERFACE(nsFontSizeIterator, NS_GET_IID(nsIFontSizeIterator))
//----------------------------------------------------------
nsFontSizeIterator::nsFontSizeIterator()
{
NS_INIT_REFCNT();
mFontInfo = nsnull;
mSizeIterInx = 0;
}
//----------------------------------------------------------
nsFontSizeIterator::~nsFontSizeIterator()
{
}
///----------------------------------------------------------
//-- nsIFontNameIterator
//----------------------------------------------------------
NS_IMETHODIMP nsFontSizeIterator::Reset()
{
mSizeIterInx = 0;
return NS_OK;
}
//----------------------------------------------------------
NS_IMETHODIMP nsFontSizeIterator::Get( double* aFontSize )
{
if (nsnull != mFontInfo->mSizes &&
mFontInfo->mSizes->Count() > 0 &&
mSizeIterInx < mFontInfo->mSizes->Count()) {
PRUint32 size = (PRUint32)mFontInfo->mSizes->ElementAt(mSizeIterInx);
*aFontSize = (double)size;
return NS_OK;
}
return NS_ERROR_FAILURE;
}
//----------------------------------------------------------
NS_IMETHODIMP nsFontSizeIterator::Advance()
{
if (nsnull != mFontInfo->mSizes &&
mFontInfo->mSizes->Count() > 0 &&
mSizeIterInx < mFontInfo->mSizes->Count()-2) {
mSizeIterInx++;
return NS_OK;
}
return NS_ERROR_FAILURE;
}
//----------------------------------------------------------
NS_IMETHODIMP nsFontSizeIterator::SetFontInfo( FontInfo * aFontInfo )
{
mFontInfo = aFontInfo;
return NS_OK;
}

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

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

@ -30,6 +30,7 @@
#define INCL_PM
#define INCL_NLS
#define INCL_DOS
#define INCL_WINSTDFILE
#include <os2.h>
#include <uconv.h> // Rather not have to include these two, but need types...
#include <unikbd.h> //

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

@ -30,6 +30,7 @@
* 03/23/2000 IBM Corp. Added support for directory picker dialog.
* 03/24/2000 IBM Corp. Updated based on nsWinWidgetFactory.cpp.
* 05/31/2000 IBM Corp. Enabled timer stuff
* 06/30/2000 sobotka@axess.com Added nsFilePicker
*/
#include "nsIFactory.h"
@ -39,6 +40,7 @@
#include "nsWidgetDefs.h" // OS/2 only
#include "nsFilePicker.h"
// OS2TODO #include "nsFileWidget.h"
#include "nsFileSpecWithUIImpl.h"
#include "nsLookAndFeel.h"
@ -47,7 +49,7 @@
#include "nsWindow.h"
#include "nsAppShell.h"
#include "nsIServiceManager.h"
// OS2TODO #include "nsFontRetrieverService.h"
#include "nsFontRetrieverService.h"
#include "nsSound.h"
#include "nsWindowsTimer.h"
@ -65,6 +67,7 @@
static NS_DEFINE_IID(kCWindow, NS_WINDOW_CID);
static NS_DEFINE_IID(kCChild, NS_CHILD_CID);
static NS_DEFINE_IID(kCFileOpen, NS_FILEWIDGET_CID);
static NS_DEFINE_IID(kCFilePicker, NS_FILEPICKER_CID);
static NS_DEFINE_IID(kCHorzScrollbar, NS_HORZSCROLLBAR_CID);
static NS_DEFINE_IID(kCVertScrollbar, NS_VERTSCROLLBAR_CID);
static NS_DEFINE_IID(kCAppShell, NS_APPSHELL_CID);
@ -189,6 +192,9 @@ nsresult nsWidgetFactory::CreateInstance( nsISupports* aOuter,
inst = (nsISupports*)new nsFileWidget();
#endif
}
else if (mClassID.Equals(kCFilePicker)) {
inst = (nsISupports*)(nsBaseFilePicker*)new nsFilePicker();
}
else if (mClassID.Equals(kCHorzScrollbar)) {
inst = (nsISupports*)(nsBaseWidget*)(nsWindow*)new nsScrollbar(PR_FALSE);
}
@ -233,6 +239,9 @@ nsresult nsWidgetFactory::CreateInstance( nsISupports* aOuter,
else if (mClassID.Equals(kCTimerManager)) {
inst = (nsISupports*)(nsITimerQueue*) new nsTimerManager();
}
else if (mClassID.Equals(kCFontRetrieverService)) {
inst = (nsISupports*)(nsIFontRetrieverService *)new nsFontRetrieverService();
}
#if 0 // OS2TODO
else if (mClassID.Equals(kCClipboard)) {
@ -241,9 +250,6 @@ nsresult nsWidgetFactory::CreateInstance( nsISupports* aOuter,
else if (mClassID.Equals(kCDragService)) {
inst = (nsISupports*)(nsIDragService *)new nsDragService();
}
else if (mClassID.Equals(kCFontRetrieverService)) {
inst = (nsISupports*)(nsIFontRetrieverService *)new nsFontRetrieverService();
}
#endif
if (inst == NULL) {
return NS_ERROR_OUT_OF_MEMORY;

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

@ -49,7 +49,7 @@
#include "nsGfxCIID.h"
#include "prtime.h"
#include "nsFont.h"
#include "nsTooltipManager.h"
// #include "nsTooltipManager.h"
#include "nsISupportsArray.h"
#include "nsITimer.h"
#include "nsIMenuBar.h"
@ -352,6 +352,7 @@ void nsWindow::RealDoCreate( HWND hwndP,
// Record passed in things
mAppShell = aAppShell;
// NS_IF_ADDREF( mAppShell);
GetAppShell(); // Let the base widget class update the refcount for us....
mEventCallback = aHandleEventFunction;
@ -1207,7 +1208,7 @@ PRBool nsWindow::OnKey( MPARAM mp1, MPARAM mp2)
if( unirc != ULS_SUCCESS)
{
printf( "UniTranslate[Dead]Key returned %d\n", unirc);
printf( "UniTranslate[Dead]Key returned %u\n", unirc);
event.charCode = CHAR2FROMMP(mp2);
}
@ -2172,6 +2173,8 @@ void nsWindow::GetStyle( ULONG &out)
out = WinQueryWindowULong( mWnd, QWL_STYLE);
}
#if 0 // Handled by XP code now
// --------------------------------------------------------------------------
// Tooltips -----------------------------------------------------------------
@ -2193,6 +2196,8 @@ nsresult nsWindow::RemoveTooltips()
return NS_OK;
}
#endif
// --------------------------------------------------------------------------
// Drag'n'drop --------------------------------------------------------------
@ -2420,6 +2425,7 @@ PRUint32 WMChar2KeyCode( MPARAM mp1, MPARAM mp2)
if( !(flags & (KC_VIRTUALKEY | KC_DEADKEY)))
{
rc = SHORT1FROMMP(mp2);
if( rc < 0xFF)
{
// Need nls-correct way of doing this...