Remove obsolete native widget files, and do some minor cleanup. Bug 279510, r=pinkerton

This commit is contained in:
smfr%smfr.org 2005-01-29 02:09:21 +00:00
Родитель 165b6aeac0
Коммит 5516fb204e
17 изменённых файлов: 56 добавлений и 1771 удалений

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

@ -36,11 +36,10 @@
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
#include <ControlDefinitions.h>
#include "nsNativeScrollbar.h" #include "nsNativeScrollbar.h"
#include "nsIDeviceContext.h" #include "nsIDeviceContext.h"
#if TARGET_CARBON || (UNIVERSAL_INTERFACES_VERSION >= 0x0330)
#include <ControlDefinitions.h>
#endif
#include "nsReadableUtils.h" #include "nsReadableUtils.h"
#include "nsWidgetAtoms.h" #include "nsWidgetAtoms.h"

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

@ -37,6 +37,9 @@
#include "nsIFactory.h" #include "nsIFactory.h"
#include "nsISupports.h" #include "nsISupports.h"
#include "nsIComponentManager.h"
#include "nsIGenericFactory.h"
#include "nsWidgetsCID.h" #include "nsWidgetsCID.h"
#include "nsToolkit.h" #include "nsToolkit.h"
@ -49,10 +52,6 @@
#include "nsMenuX.h" #include "nsMenuX.h"
#include "nsMenuItemX.h" #include "nsMenuItemX.h"
#define nsMenuBar nsMenuBarX
#define nsMenu nsMenuX
#define nsMenuItem nsMenuItemX
#include "nsClipboard.h" #include "nsClipboard.h"
#include "nsClipboardHelper.h" #include "nsClipboardHelper.h"
#include "nsTransferable.h" #include "nsTransferable.h"
@ -60,34 +59,24 @@
#include "nsDragService.h" #include "nsDragService.h"
#include "nsDragHelperService.h" #include "nsDragHelperService.h"
#if USE_NATIVE_VERSION
# include "nsCheckButton.h"
#endif
#include "nsLookAndFeel.h" #include "nsLookAndFeel.h"
#include "nsIComponentManager.h"
#include "nsSound.h" #include "nsSound.h"
#include "nsNativeScrollbar.h" #include "nsNativeScrollbar.h"
#include "nsBidiKeyboard.h" #include "nsBidiKeyboard.h"
#include "nsIGenericFactory.h"
NS_GENERIC_FACTORY_CONSTRUCTOR(nsCocoaWindow) NS_GENERIC_FACTORY_CONSTRUCTOR(nsCocoaWindow)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsChildView) NS_GENERIC_FACTORY_CONSTRUCTOR(nsChildView)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFilePicker) NS_GENERIC_FACTORY_CONSTRUCTOR(nsFilePicker)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAppShellCocoa) NS_GENERIC_FACTORY_CONSTRUCTOR(nsAppShellCocoa)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsToolkit) NS_GENERIC_FACTORY_CONSTRUCTOR(nsToolkit)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsLookAndFeel) NS_GENERIC_FACTORY_CONSTRUCTOR(nsLookAndFeel)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMenuBar) NS_GENERIC_FACTORY_CONSTRUCTOR(nsMenuBarX)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMenu) NS_GENERIC_FACTORY_CONSTRUCTOR(nsMenuX)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMenuItem) NS_GENERIC_FACTORY_CONSTRUCTOR(nsMenuItemX)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsNativeScrollbar) NS_GENERIC_FACTORY_CONSTRUCTOR(nsNativeScrollbar)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSound) NS_GENERIC_FACTORY_CONSTRUCTOR(nsSound)
//NS_GENERIC_FACTORY_CONSTRUCTOR(nsFileSpecWithUIImpl)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsTransferable) NS_GENERIC_FACTORY_CONSTRUCTOR(nsTransferable)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLFormatConverter) NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLFormatConverter)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboard) NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboard)
@ -96,7 +85,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsDragService)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDragHelperService) NS_GENERIC_FACTORY_CONSTRUCTOR(nsDragHelperService)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsBidiKeyboard) NS_GENERIC_FACTORY_CONSTRUCTOR(nsBidiKeyboard)
static nsModuleComponentInfo components[] = static const nsModuleComponentInfo gComponents[] =
{ {
{ "nsWindow", { "nsWindow",
NS_WINDOW_CID, NS_WINDOW_CID,
@ -129,15 +118,15 @@ static nsModuleComponentInfo components[] =
{ "Menubar", { "Menubar",
NS_MENUBAR_CID, NS_MENUBAR_CID,
"@mozilla.org/widget/menubar/mac;1", "@mozilla.org/widget/menubar/mac;1",
nsMenuBarConstructor }, nsMenuBarXConstructor },
{ "Menu", { "Menu",
NS_MENU_CID, NS_MENU_CID,
"@mozilla.org/widget/menu/mac;1", "@mozilla.org/widget/menu/mac;1",
nsMenuConstructor }, nsMenuXConstructor },
{ "MenuItem", { "MenuItem",
NS_MENUITEM_CID, NS_MENUITEM_CID,
"@mozilla.org/widget/menuitem/mac;1", "@mozilla.org/widget/menuitem/mac;1",
nsMenuItemConstructor }, nsMenuItemXConstructor },
{ "Sound", { "Sound",
NS_SOUND_CID, NS_SOUND_CID,
"@mozilla.org/sound;1", "@mozilla.org/sound;1",
@ -176,4 +165,4 @@ static nsModuleComponentInfo components[] =
nsNativeScrollbarConstructor } nsNativeScrollbarConstructor }
}; };
NS_IMPL_NSGETMODULE(nsWidgetMacModule, components) NS_IMPL_NSGETMODULE(nsWidgetMacModule, gComponents)

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

@ -84,16 +84,13 @@ GFX_LCPPSRCS = \
CPPSRCS = nsAppShell.cpp \ CPPSRCS = nsAppShell.cpp \
nsBidiKeyboard.cpp \ nsBidiKeyboard.cpp \
nsButton.cpp \
nsChildWindow.cpp \ nsChildWindow.cpp \
nsClipboard.cpp \ nsClipboard.cpp \
nsDeleteObserver.cpp \ nsDeleteObserver.cpp \
nsDragService.cpp \ nsDragService.cpp \
nsDragHelperService.cpp \ nsDragHelperService.cpp \
nsFilePicker.cpp \ nsFilePicker.cpp \
nsLabel.cpp \
nsLookAndFeel.cpp \ nsLookAndFeel.cpp \
nsMacControl.cpp \
nsMacEventHandler.cpp \ nsMacEventHandler.cpp \
nsMacMessagePump.cpp \ nsMacMessagePump.cpp \
nsMacResources.cpp \ nsMacResources.cpp \
@ -103,9 +100,7 @@ CPPSRCS = nsAppShell.cpp \
nsMenuBarX.cpp \ nsMenuBarX.cpp \
nsMenuItemX.cpp \ nsMenuItemX.cpp \
nsMimeMapper.cpp \ nsMimeMapper.cpp \
nsNativeScrollbar.cpp \
nsSound.cpp \ nsSound.cpp \
nsTextWidget.cpp \
nsTSMStrategy.cpp \ nsTSMStrategy.cpp \
nsToolkitBase.cpp \ nsToolkitBase.cpp \
nsToolkit.cpp \ nsToolkit.cpp \
@ -113,6 +108,8 @@ CPPSRCS = nsAppShell.cpp \
nsWindow.cpp \ nsWindow.cpp \
nsMacNativeUnicodeConverter.cpp \ nsMacNativeUnicodeConverter.cpp \
nsStylClipboardUtils.cpp \ nsStylClipboardUtils.cpp \
nsMacControl.cpp \
nsNativeScrollbar.cpp \
$(GFX_LCPPSRCS) \ $(GFX_LCPPSRCS) \
$(NULL) $(NULL)

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

@ -1,92 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the 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 <ControlDefinitions.h>
#include "nsButton.h"
NS_IMPL_ADDREF(nsButton)
NS_IMPL_RELEASE(nsButton)
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
nsButton::nsButton() : nsMacControl(), nsIButton()
{
WIDGET_SET_CLASSNAME("nsButton");
SetControlType(pushButProc);
}
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
nsButton::~nsButton()
{
}
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
NS_INTERFACE_MAP_BEGIN(nsButton)
NS_INTERFACE_MAP_ENTRY(nsIButton)
NS_INTERFACE_MAP_END_INHERITING(nsWindow)
#pragma mark -
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
NS_METHOD nsButton::SetLabel(const nsString& aText)
{
mLabel = aText;
Invalidate(PR_TRUE);
return NS_OK;
}
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
NS_METHOD nsButton::GetLabel(nsString& aBuffer)
{
aBuffer = mLabel;
return NS_OK;
}

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

@ -1,63 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the 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 nsButton_h__
#define nsButton_h__
#include "nsMacControl.h"
#include "nsIButton.h"
class nsButton : public nsMacControl, public nsIButton
{
public:
nsButton();
virtual ~nsButton();
// nsISupports
NS_IMETHOD_(nsrefcnt) AddRef();
NS_IMETHOD_(nsrefcnt) Release();
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
// nsIButton part
NS_IMETHOD SetLabel(const nsString& aText);
NS_IMETHOD GetLabel(nsString& aBuffer);
};
#endif // nsButton_h__

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

@ -1,112 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the 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 "nsCheckButton.h"
#include <ControlDefinitions.h>
NS_IMPL_ADDREF(nsCheckButton)
NS_IMPL_RELEASE(nsCheckButton)
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
nsCheckButton::nsCheckButton() : nsMacControl(), nsICheckButton()
{
gInstanceClassName = "nsCheckButton";
SetControlType(checkBoxProc);
}
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
nsCheckButton::~nsCheckButton()
{
}
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
NS_INTERFACE_MAP_BEGIN(nsCheckButton)
NS_INTERFACE_MAP_ENTRY(nsICheckButton)
NS_INTERFACE_MAP_END_INHERITING(nsWindow)
#pragma mark -
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
NS_METHOD nsCheckButton::SetState(PRBool aState)
{
mValue = (aState ? 1 : 0);
Invalidate(PR_TRUE);
return NS_OK;
}
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
NS_METHOD nsCheckButton::GetState(PRBool& aState)
{
aState = (mValue != 0);
return NS_OK;
}
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
NS_METHOD nsCheckButton::SetLabel(const nsString& aText)
{
mLabel = aText;
Invalidate(PR_TRUE);
return NS_OK;
}
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
NS_METHOD nsCheckButton::GetLabel(nsString& aBuffer)
{
aBuffer = mLabel;
return NS_OK;
}

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

@ -1,66 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the 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 nsCheckButton_h__
#define nsCheckButton_h__
#include "nsMacControl.h"
#include "nsICheckButton.h"
class nsCheckButton : public nsMacControl, public nsICheckButton
{
public:
nsCheckButton();
virtual ~nsCheckButton();
// nsISupports
NS_IMETHOD_(nsrefcnt) AddRef();
NS_IMETHOD_(nsrefcnt) Release();
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
// nsICheckButton part
NS_IMETHOD SetLabel(const nsString& aText);
NS_IMETHOD GetLabel(nsString& aBuffer);
NS_IMETHOD SetState(const PRBool aState);
NS_IMETHOD GetState(PRBool& aState);
};
#endif // nsCheckButton_h__

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

@ -53,7 +53,6 @@
#include <InternetConfig.h> #include <InternetConfig.h>
#include "nsMacControl.h"
#include "nsCarbonHelpers.h" #include "nsCarbonHelpers.h"
#include "nsFilePicker.h" #include "nsFilePicker.h"

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

@ -1,113 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the 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 "nsLabel.h"
NS_IMPL_ADDREF(nsLabel)
NS_IMPL_RELEASE(nsLabel)
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
nsLabel::nsLabel() : nsTextWidget(), nsILabel()
{
WIDGET_SET_CLASSNAME("nsLabel");
}
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
nsLabel::~nsLabel()
{
}
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
NS_INTERFACE_MAP_BEGIN(nsLabel)
NS_INTERFACE_MAP_ENTRY(nsILabel)
NS_INTERFACE_MAP_END_INHERITING(nsTextWidget)
#pragma mark -
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
NS_METHOD nsLabel::SetLabel(const nsString& aText)
{
PRUint32 displayedSize;
return SetText(aText, displayedSize);
}
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
NS_METHOD nsLabel::GetLabel(nsString& aBuffer)
{
PRUint32 maxSize = -1;
PRUint32 displayedSize;
return GetText(aBuffer, maxSize, displayedSize);
}
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
NS_METHOD nsLabel::SetAlignment(nsLabelAlignment aAlignment)
{
if (!mControl)
return NS_ERROR_NOT_INITIALIZED;
SInt16 just;
switch (aAlignment)
{
case eAlign_Right: just = teFlushRight; break;
case eAlign_Left: just = teFlushLeft; break;
case eAlign_Center: just = teCenter; break;
}
ControlFontStyleRec fontStyleRec;
fontStyleRec.flags = (kControlUseJustMask);
fontStyleRec.just = just;
::SetControlFontStyle(mControl, &fontStyleRec);
return NS_OK;
}

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

@ -1,70 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the 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 Label_h__
#define Label_h__
#include "nsTextWidget.h"
#include "nsILabel.h"
//-------------------------------------------------------------------------
//
// nsLabel
//
//-------------------------------------------------------------------------
class nsLabel : public nsTextWidget, public nsILabel
{
public:
nsLabel();
virtual ~nsLabel();
// nsISupports
NS_IMETHOD_(nsrefcnt) AddRef();
NS_IMETHOD_(nsrefcnt) Release();
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
// nsILabel part
NS_IMETHOD SetLabel(const nsString& aText);
NS_IMETHOD GetLabel(nsString& aBuffer);
NS_IMETHOD SetAlignment(nsLabelAlignment aAlignment);
};
#endif // Label_h__

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

@ -37,7 +37,6 @@
#include "nsMacWindow.h" #include "nsMacWindow.h"
#include "nsMacEventHandler.h" #include "nsMacEventHandler.h"
#include "nsMacControl.h"
#include "nsToolkit.h" #include "nsToolkit.h"
#include "nsIServiceManager.h" // for drag and drop #include "nsIServiceManager.h" // for drag and drop
@ -1485,18 +1484,12 @@ NS_IMETHODIMP nsMacWindow::SetTitle(const nsAString& aTitle)
{ {
nsAString::const_iterator begin; nsAString::const_iterator begin;
const PRUnichar *strTitle = aTitle.BeginReading(begin).get(); const PRUnichar *strTitle = aTitle.BeginReading(begin).get();
// Try to use the unicode friendly CFString version first
CFStringRef labelRef = ::CFStringCreateWithCharacters(kCFAllocatorDefault, (UniChar*)strTitle, aTitle.Length()); CFStringRef labelRef = ::CFStringCreateWithCharacters(kCFAllocatorDefault, (UniChar*)strTitle, aTitle.Length());
if (labelRef) { if (labelRef) {
::SetWindowTitleWithCFString(mWindowPtr, labelRef); ::SetWindowTitleWithCFString(mWindowPtr, labelRef);
::CFRelease(labelRef); ::CFRelease(labelRef);
return NS_OK;
} }
Str255 title;
// unicode to file system charset
nsMacControl::StringToStr255(aTitle, title);
::SetWTitle(mWindowPtr, title);
return NS_OK; return NS_OK;
} }

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

@ -45,7 +45,6 @@
#include "nsIContent.h" #include "nsIContent.h"
class nsIScrollbarMediator; class nsIScrollbarMediator;
class StControlProcSingleton5;
// //

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

@ -1,242 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the 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 ***** */
#error "This file is obsolete: nsTextAreaWidget is WASTE-based / nsTextWidget is a control"
#include "nsTextHelper.h"
#include "nsTextWidget.h"
#include "nsToolkit.h"
#include "nsColor.h"
#include "nsGUIEvent.h"
#include "nsString.h"
#include "nsReadableUtils.h"
#define DBG 0
//-------------------------------------------------------------------------
//
// nsTextHelper constructor
//
//-------------------------------------------------------------------------
nsTextHelper::nsTextHelper(nsISupports *aOuter):nsITextWidget(aOuter)
{
LongRect destRect,viewRect;
PRUint32 teFlags=0;
mIsReadOnly = PR_FALSE;
mIsPassword = PR_FALSE;
WENew(&destRect,&viewRect,teFlags,&mTE_Data);
}
//-------------------------------------------------------------------------
//
// nsTextHelper destructor
//
//-------------------------------------------------------------------------
nsTextHelper::~nsTextHelper()
{
}
//-------------------------------------------------------------------------
void nsTextHelper::SetMaxTextLength(PRUint32 aChars)
{
}
//-------------------------------------------------------------------------
PRUint32 nsTextHelper::GetText(nsString& aTextBuffer, PRUint32 aBufferSize)
{
PRUint32 len;
if (!mIsPassword)
{
//char * str = XmTextGetString(mWidget);
aTextBuffer.SetLength(0);
//aTextBuffer.Append(str);
//PRUint32 len = (PRUint32)strlen(str);
//XtFree(str);
return len;
}
else
{
PasswordData * data;
//XtVaGetValues(mWidget, XmNuserData, &data, NULL);
aTextBuffer = data->mPassword;
return aTextBuffer.Length();
}
}
//-------------------------------------------------------------------------
PRUint32 nsTextHelper::SetText(const nsString& aText)
{
//printf("SetText Password %d\n", mIsPassword);
if (!mIsPassword)
{
//XmTextSetString(mWidget, NS_LossyConvertUCS2toASCII(aText).get());
}
else
{
PasswordData * data;
//(mWidget, XmNuserData, &data, NULL);
data->mPassword = aText;
data->mIgnore = PR_TRUE;
char * buf = new char[aText.Length()+1];
memset(buf, '*', aText.Length());
buf[aText.Length()] = 0;
//printf("SetText [%s] [%s]\n", NS_LossyConvertUCS2toASCII(data->mPassword).get(), buf);
//XmTextSetString(mWidget, buf);
data->mIgnore = PR_FALSE;
}
return(aText.Length());
}
//-------------------------------------------------------------------------
PRUint32 nsTextHelper::InsertText(const nsString &aText, PRUint32 aStartPos, PRUint32 aEndPos)
{
if (!mIsPassword)
{
//XmTextInsert(mWidget, aStartPos, NS_LossyConvertUCS2toASCII(aText).get());
}
else
{
PasswordData * data;
//XtVaGetValues(mWidget, XmNuserData, &data, NULL);
data->mIgnore = PR_TRUE;
nsString newText(aText);
data->mPassword.Insert(newText, aStartPos, aText.Length());
char * buf = new char[data->mPassword.Length()+1];
memset(buf, '*', data->mPassword.Length());
buf[data->mPassword.Length()] = 0;
//printf("SetText [%s] [%s]\n", NS_LossyConvertUCS2toASCII(data->mPassword).get(), buf);
//XmTextInsert(mWidget, aStartPos, buf);
data->mIgnore = PR_FALSE;
}
return(aText.Length());
}
//-------------------------------------------------------------------------
void nsTextHelper::RemoveText()
{
char blank[2];
blank[0] = 0;
//XmTextSetString(mWidget, blank);
}
//-------------------------------------------------------------------------
void nsTextHelper::SetPassword(PRBool aIsPassword)
{
mIsPassword = aIsPassword;
}
//-------------------------------------------------------------------------
PRBool nsTextHelper::SetReadOnly(PRBool aReadOnlyFlag)
{
NS_ASSERTION(mWidget != nsnull,
"SetReadOnly - Widget is NULL, Create may not have been called!");
PRBool oldSetting = mIsReadOnly;
mIsReadOnly = aReadOnlyFlag;
//XmTextSetEditable(mWidget, aReadOnlyFlag?False:True);
return(oldSetting);
}
//-------------------------------------------------------------------------
void nsTextHelper::SelectAll()
{
nsString text;
PRUint32 numChars = GetText(text, 0);
SetSelection(0, numChars);
}
//-------------------------------------------------------------------------
void nsTextHelper::SetSelection(PRUint32 aStartSel, PRUint32 aEndSel)
{
//XmTextPosition left = (XmTextPosition)aStartSel;
//XmTextPosition right = (XmTextPosition)aEndSel;
//Time time;
printf("SetSel %d %d\n", left, right);
//XmTextSetSelection(mWidget, left, right, 0);
}
//-------------------------------------------------------------------------
void nsTextHelper::GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel)
{
//XmTextPosition left;
//XmTextPosition right;
/*
if (XmTextGetSelectionPosition(mWidget, &left, &right)) {
printf("left %d right %d\n", left, right);
*aStartSel = (PRUint32)left;
*aEndSel = (PRUint32)right;
} else {
printf("nsTextHelper::GetSelection Error getting positions\n");
}
*/
}
//-------------------------------------------------------------------------
void nsTextHelper::SetCaretPosition(PRUint32 aPosition)
{
//XmTextSetInsertionPosition(mWidget, (XmTextPosition)aPosition);
}
//-------------------------------------------------------------------------
PRUint32 nsTextHelper::GetCaretPosition()
{
//return (PRUint32)XmTextGetInsertionPosition(mWidget);
}
//-------------------------------------------------------------------------
PRBool nsTextHelper::AutoErase()
{
return(PR_TRUE);
}

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

@ -1,83 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the 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 nsTextHelper_h__
#define nsTextHelper_h__
#error "This file is obsolete: nsTextAreaWidget is WASTE-based / nsTextWidget is a control"
#include "nsITextWidget.h"
#include "nsWindow.h"
#include "WASTE.h"
/**
* Base class for nsTextAreaWidget and nsTextWidget
*/
class nsTextHelper : public nsITextWidget
{
public:
nsTextHelper();
virtual ~nsTextHelper();
NS_IMETHOD SelectAll();
NS_IMETHOD SetMaxTextLength(PRUint32 aChars);
NS_IMETHOD GetText(nsString& aTextBuffer, PRUint32 aBufferSize, PRUint32& aActualSize);
NS_IMETHOD SetText(const nsString &aText, PRUint32& aActualSize);
NS_IMETHOD InsertText(const nsString &aText, PRUint32 aStartPos, PRUint32 aEndPos, PRUint32& aActualSize);
NS_IMETHOD RemoveText();
NS_IMETHOD SetPassword(PRBool aIsPassword);
NS_IMETHOD SetReadOnly(PRBool aNewReadOnlyFlag, PRBool& aOldReadOnlyFlag);
NS_IMETHOD SetSelection(PRUint32 aStartSel, PRUint32 aEndSel);
NS_IMETHOD GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel);
NS_IMETHOD SetCaretPosition(PRUint32 aPosition);
NS_IMETHOD GetCaretPosition(PRUint32& aPosition);
virtual PRBool AutoErase();
protected:
PRBool mIsPassword;
PRBool mIsReadOnly;
WEReference mTE_Data;
};
#endif // nsTextHelper_h__

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

@ -1,746 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the 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 "nsTextWidget.h"
#include "nsIRenderingContext.h"
#include "nsCRT.h"
#include <ToolUtils.h>
#include <Appearance.h>
#include <ControlDefinitions.h>
#include <memory>
using std::auto_ptr;
NS_IMPL_ADDREF(nsTextWidget)
NS_IMPL_RELEASE(nsTextWidget)
//-------------------------------------------------------------------------
// ¥ NOTE ABOUT MENU HANDLING ¥
//
// The definitions below, as well as the NS_MENU_SELECTED code in
// DispatchEvent() are temporary hacks only. They require the menu
// resources to be created under Contructor with the standard
// PowerPlant menu IDs. All that will go away because:
// - nsTextWidget will be rewritten as an XP widget by the Editor team.
// - menu handling will be rewritten by the XPApp team.
//-------------------------------------------------------------------------
#include <Scrap.h>
typedef SInt32 MessageT;
typedef PRUint32 Uint32;
const MessageT cmd_Cut = 12; // nil
const MessageT cmd_Copy = 13; // nil
const MessageT cmd_Paste = 14; // nil
const MessageT cmd_Clear = 15; // nil
const MessageT cmd_SelectAll = 16; // nil
enum
{
menu_Apple = 128,
menu_File,
menu_Edit
};
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
nsTextWidget::nsTextWidget() : nsMacControl(), nsITextWidget(), Repeater()
{
WIDGET_SET_CLASSNAME("nsTextWidget");
SetControlType(kControlEditTextProc);
mIsPassword = PR_FALSE;
mIsReadOnly = PR_FALSE;
AcceptFocusOnClick(PR_TRUE);
}
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
nsTextWidget::~nsTextWidget()
{
}
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
NS_IMETHODIMP nsTextWidget::Create(nsIWidget *aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell,
nsIToolkit *aToolkit,
nsWidgetInitData *aInitData)
{
if (aInitData)
{
nsTextWidgetInitData* initData = (nsTextWidgetInitData*)aInitData;
if (initData->mIsPassword)
{
SetControlType(kControlEditTextPasswordProc);
mIsPassword = PR_TRUE;
}
else if (mIsReadOnly)
{
SetControlType(kControlStaticTextProc);
mIsReadOnly = PR_TRUE;
}
}
Inherited::Create(aParent, aRect, aHandleEventFunction,
aContext, aAppShell, aToolkit, aInitData);
return NS_OK;
}
//-------------------------------------------------------------------------
// Destroy
//
//-------------------------------------------------------------------------
// The repeater in this widget needs to use out of band notification
// to sever its ties with the nsTimer. If we just rely on the
// dtor to do it, it will never get called because the nsTimer holds a ref to
// this object.
//
NS_IMETHODIMP
nsTextWidget::Destroy()
{
Inherited::Destroy();
if (mRepeating) RemoveFromRepeatList();
if (mIdling) RemoveFromIdleList();
return NS_OK;
}
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
NS_INTERFACE_MAP_BEGIN(nsTextWidget)
NS_INTERFACE_MAP_ENTRY(nsITextWidget)
NS_INTERFACE_MAP_END_INHERITING(Inherited)
#pragma mark -
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
PRBool nsTextWidget::DispatchMouseEvent(nsMouseEvent &aEvent)
{
PRBool eventHandled = nsWindow::DispatchMouseEvent(aEvent); // we don't want the 'Inherited' nsMacControl behavior
EventRecord* theOSEvent;
if ((! eventHandled) && (mControl != nsnull))
{
switch (aEvent.message)
{
case NS_MOUSE_LEFT_DOUBLECLICK:
case NS_MOUSE_LEFT_BUTTON_DOWN:
Point thePoint;
thePoint.h = aEvent.point.x;
thePoint.v = aEvent.point.y;
short theModifiers;
theOSEvent = (EventRecord*)aEvent.nativeMsg;
if (theOSEvent)
{
theModifiers = theOSEvent->modifiers;
}
else
{
if (aEvent.isShift) theModifiers = shiftKey;
if (aEvent.isControl) theModifiers |= controlKey;
if (aEvent.isAlt) theModifiers |= optionKey;
}
StartDraw();
::HandleControlClick(mControl, thePoint, theModifiers, nil);
EndDraw();
eventHandled = PR_TRUE;
break;
case NS_MOUSE_ENTER:
SetCursor(eCursor_select);
break;
case NS_MOUSE_EXIT:
SetCursor(eCursor_standard);
break;
}
}
return (eventHandled);
}
//-------------------------------------------------------------------------
// DispatchWindowEvent
//
// Handle the following events: keys, focus, edit menu commands.
// The strategy for key events is to use the native OS event
// when it exists, otherwise use the Raptor nsKeyEvent.
//-------------------------------------------------------------------------
PRBool nsTextWidget::DispatchWindowEvent(nsGUIEvent &aEvent)
{
// filter cursor keys
PRBool passKeyEvent = PR_TRUE;
switch (aEvent.message)
{
case NS_KEY_DOWN:
case NS_KEY_UP:
{
// hack: if Enter is pressed, pass Return
nsKeyEvent* keyEvent = (nsKeyEvent*)&aEvent;
#if 0
// this hack is no longer needed, since Enter is being mapped to
// VK_RETURN in the event handler
if (keyEvent->keyCode == kEnterCharCode)
keyEvent->keyCode = NS_VK_RETURN;
#endif
// is this hack really needed?
EventRecord* theOSEvent = (EventRecord*)aEvent.nativeMsg;
if (theOSEvent && ((theOSEvent->message & charCodeMask) == kEnterCharCode))
theOSEvent->message = (theOSEvent->message & ~charCodeMask) + kReturnCharCode;
switch (keyEvent->keyCode)
{
// case NS_VK_PAGE_UP:
// case NS_VK_PAGE_DOWN:
case NS_VK_END:
case NS_VK_HOME:
case NS_VK_LEFT:
case NS_VK_UP:
case NS_VK_RIGHT:
case NS_VK_DOWN:
passKeyEvent = PR_FALSE;
break;
}
break;
}
}
// dispatch the message
PRBool eventHandled = PR_FALSE;
if (passKeyEvent)
eventHandled = Inherited::DispatchWindowEvent(aEvent);
// handle the message here if nobody else processed it already
if ((! eventHandled) && (mControl != nsnull))
{
switch (aEvent.message)
{
case NS_MENU_SELECTED:
{
nsMenuEvent* menuEvent = (nsMenuEvent*)&aEvent;
long menuID = HiWord(menuEvent->mCommand);
long menuItem = LoWord(menuEvent->mCommand);
switch (menuID)
{
case menu_Edit:
{
switch (menuItem)
{
// case cmd_Undo:
case cmd_Cut:
case cmd_Copy:
{
PRUint32 startSel = 0, endSel = 0;
GetSelection ( &startSel, &endSel );
if ( startSel != endSel ) {
const Uint32 selectionLen = endSel - startSel;
// extract out the selection into a different nsString so
// we can keep it unicode as long as possible
PRUint32 unused = 0;
nsString str, selection;
GetText(str, 0, unused );
str.Mid(selection, startSel, selectionLen);
// now |selection| holds the current selection in unicode.
// We need to convert it to a c-string for MacOS.
auto_ptr<char> cRepOfSelection(new char[selectionLen + 1]);
PL_strncpyz(cRepOfSelection.get(),
NS_LossyConvertUCS2toASCII(selection).get(),
selectionLen + 1);
// copy it to the scrapMgr
::ClearCurrentScrap();
ScrapRef scrap;
::GetCurrentScrap(&scrap);
::PutScrapFlavor(scrap, 'TEXT', 0L /* ??? */, selectionLen, cRepOfSelection.get());
// if we're cutting, remove the text from the widget
if ( menuItem == cmd_Cut ) {
unused = 0;
str.Cut ( startSel, selectionLen );
SetText ( str, unused );
SetSelection(startSel, startSel);
}
} // if there is a selection
eventHandled = PR_TRUE;
break;
}
case cmd_Paste:
{
long scrapOffset;
Handle scrapH = ::NewHandle(0);
ScrapRef scrap;
OSStatus err;
err = ::GetCurrentScrap(&scrap);
if (err != noErr) return NS_ERROR_FAILURE;
err = ::GetScrapFlavorSize(scrap, 'TEXT', &scrapOffset);
// XXX uhh.. i don't think this is right..
long scrapLen = scrapOffset;
if ( scrapOffset > 0 )
{
::HLock(scrapH);
// truncate to the first line
char* cr = strchr((char*)*scrapH, '\r');
if (cr != nil)
scrapLen = cr - *scrapH;
// paste text
nsString str;
str.AssignWithConversion((char*)*scrapH, scrapLen);
PRUint32 startSel, endSel;
GetSelection(&startSel, &endSel);
PRUint32 outSize;
InsertText(str, startSel, endSel, outSize);
startSel += str.Length();
SetSelection(startSel, startSel);
::HUnlock(scrapH);
}
::DisposeHandle(scrapH);
eventHandled = PR_TRUE;
break;
}
case cmd_Clear:
{
nsString str;
PRUint32 outSize;
SetText(str, outSize);
eventHandled = PR_TRUE;
break;
}
case cmd_SelectAll:
{
SelectAll();
eventHandled = PR_TRUE;
break;
}
}
break;
}
}
break;
} // case NS_MENU_SELECTED
case NS_GOTFOCUS:
{
StartDraw();
ActivateControl(mControl);
OSErr err = SetKeyboardFocus(mWindowPtr, mControl, kControlFocusNextPart);
if (err == noErr ) {
nsRect rect = mBounds;
rect.x = rect.y = 0;
Rect macRect;
nsRectToMacRect(rect, macRect);
::InsetRect(&macRect, 2, 2);
::DrawThemeFocusRect(&macRect, true);
}
EndDraw();
StartIdling();
break;
}
case NS_LOSTFOCUS:
{
StopIdling();
StartDraw();
OSErr err = SetKeyboardFocus(mWindowPtr, mControl, kControlFocusNoPart);
if ( err == noErr ) {
nsRect rect = mBounds;
rect.x = rect.y = 0;
Rect macRect;
nsRectToMacRect(rect, macRect);
::InsetRect(&macRect, 2, 2);
::DrawThemeFocusRect(&macRect, false);
}
DeactivateControl(mControl);
EndDraw();
break;
}
case NS_KEY_DOWN:
{
char theChar;
unsigned short theKey;
unsigned short theModifiers;
EventRecord* theOSEvent = (EventRecord*)aEvent.nativeMsg;
nsKeyEvent* keyEvent = (nsKeyEvent*)&aEvent;
if (theOSEvent)
{
theChar = (theOSEvent->message & charCodeMask);
theKey = (theOSEvent->message & keyCodeMask) >> 8;
theModifiers = theOSEvent->modifiers;
}
else
{
theChar = keyEvent->keyCode;
theKey = 0; // what else?
if (keyEvent->isShift) theModifiers = shiftKey;
if (keyEvent->isControl) theModifiers |= controlKey;
if (keyEvent->isAlt) theModifiers |= optionKey;
}
if (theChar != NS_VK_RETURN) // don't pass Return: nsTextWidget is a single line editor
{
StartDraw();
::HandleControlKey(mControl, theKey, theChar, theModifiers);
EndDraw();
eventHandled = PR_TRUE;
}
break;
}
}
}
return (eventHandled);
}
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
PRBool nsTextWidget::OnPaint(nsPaintEvent &aEvent)
{
Inherited::OnPaint(aEvent);
/* draw a box.*/
if (mVisible && mIsReadOnly)
{
nsRect ctlRect = mBounds;
ctlRect.x = ctlRect.y = 0;
//ctlRect.Deflate(1, 1);
mTempRenderingContext->SetColor(NS_RGB(0, 0, 0));
mTempRenderingContext->DrawRect(ctlRect);
}
return PR_FALSE;
}
#pragma mark -
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
NS_METHOD nsTextWidget::SetPassword(PRBool aIsPassword)
{
nsresult theResult = NS_OK;
// note: it is assumed that we can't have a read-only password field
if (aIsPassword != mIsPassword)
{
mIsPassword = aIsPassword;
short newControlType = (aIsPassword ? kControlEditTextPasswordProc : kControlEditTextProc);
SetControlType(newControlType);
theResult = CreateOrReplaceMacControl(newControlType);
}
return theResult;
}
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
NS_METHOD nsTextWidget::SetReadOnly(PRBool aReadOnlyFlag, PRBool& aOldFlag)
{
nsresult theResult = NS_OK;
// note: it is assumed that we can't have a read-only password field
aOldFlag = mIsReadOnly;
if (aReadOnlyFlag != mIsReadOnly)
{
mIsReadOnly = aReadOnlyFlag;
short newControlType = (aReadOnlyFlag ? kControlStaticTextProc : kControlEditTextProc);
SetControlType(newControlType);
theResult = CreateOrReplaceMacControl(newControlType);
}
return theResult;
}
#pragma mark -
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
NS_METHOD nsTextWidget::SetMaxTextLength(PRUint32 aChars)
{
//¥TODO: install a kControlEditTextKeyFilterTag proc
return NS_OK;
}
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
NS_METHOD nsTextWidget::GetText(nsString& aTextBuffer, PRUint32 /*aBufferSize*/, PRUint32& aSize)
{
if (!mControl)
return NS_ERROR_NOT_INITIALIZED;
ResType textTag = (mIsPassword ? kControlEditTextPasswordTag : kControlEditTextTextTag);
Size textSize;
::GetControlDataSize(mControl, kControlNoPart, textTag, &textSize);
char* str = new char[textSize];
if (str)
{
::GetControlData(mControl, kControlNoPart, textTag, textSize, (Ptr)str, &textSize);
aTextBuffer.SetLength(0);
aTextBuffer.AppendWithConversion(str, textSize);
aSize = textSize;
delete [] str;
}
else
{
aSize = 0;
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Assumes aSize is |out| only and does not yet have a value.
//-------------------------------------------------------------------------
NS_METHOD nsTextWidget::SetText(const nsString& aText, PRUint32& outSize)
{
outSize = aText.Length();
if (!mControl)
return NS_ERROR_NOT_INITIALIZED;
ResType textTag = (mIsPassword ? kControlEditTextPasswordTag : kControlEditTextTextTag);
::SetControlData(mControl, kControlNoPart, textTag, outSize,
(Ptr)NS_LossyConvertUCS2toASCII(aText).get());
Invalidate(PR_FALSE);
return NS_OK;
}
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
NS_METHOD nsTextWidget::InsertText(const nsString &aText, PRUint32 aStartPos, PRUint32 aEndPos, PRUint32& aSize)
{
if (!mControl)
return NS_ERROR_NOT_INITIALIZED;
Size textSize;
::GetControlDataSize(mControl, kControlNoPart, kControlEditTextTextTag, &textSize);
nsString textStr;
PRUint32 outTextSize;
nsresult retVal = GetText(textStr, textSize, outTextSize);
if (retVal != NS_OK)
return retVal;
if (((PRInt32)aStartPos == -1L) && ((PRInt32)aEndPos == -1L))
{
textStr.Append(aText);
}
else
{
if ((PRInt32)aStartPos < 0)
aStartPos = 0;
if ((PRInt32)aEndPos < 0)
aStartPos = 0;
if (aEndPos < aStartPos)
aEndPos = aStartPos;
textStr.Cut(aStartPos, aEndPos - aStartPos);
textStr.Insert(aText, aStartPos);
}
aSize = textStr.Length();
return (SetText(textStr, aSize));
}
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
NS_METHOD nsTextWidget::RemoveText()
{
if (!mControl)
return NS_ERROR_NOT_INITIALIZED;
StartDraw();
::SetControlData(mControl, kControlNoPart, kControlEditTextTextTag, 0, (Ptr)"");
EndDraw();
return NS_OK;
}
#pragma mark -
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
NS_METHOD nsTextWidget::SelectAll()
{
if (!mControl)
return NS_ERROR_NOT_INITIALIZED;
Size textSize;
::GetControlDataSize(mControl, kControlNoPart, kControlEditTextTextTag, &textSize);
return (SetSelection(0, textSize));
}
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
NS_METHOD nsTextWidget::SetSelection(PRUint32 aStartSel, PRUint32 aEndSel)
{
if (!mControl)
return NS_ERROR_NOT_INITIALIZED;
ControlEditTextSelectionRec textSelectionRec;
textSelectionRec.selStart = aStartSel;
textSelectionRec.selEnd = aEndSel;
StartDraw();
::SetControlData(mControl, kControlNoPart, kControlEditTextSelectionTag,
sizeof(textSelectionRec), (Ptr)&textSelectionRec);
EndDraw();
return NS_OK;
}
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
NS_METHOD nsTextWidget::GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel)
{
if (!mControl)
return NS_ERROR_NOT_INITIALIZED;
ControlEditTextSelectionRec textSelectionRec;
Size dataSize = sizeof(textSelectionRec);
::GetControlData(mControl, kControlNoPart, kControlEditTextSelectionTag,
dataSize, (Ptr)&textSelectionRec, &dataSize);
*aStartSel = textSelectionRec.selStart;
*aEndSel = textSelectionRec.selEnd;
return NS_OK;
}
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
NS_METHOD nsTextWidget::SetCaretPosition(PRUint32 aPosition)
{
return(SetSelection(aPosition, aPosition));
}
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
NS_METHOD nsTextWidget::GetCaretPosition(PRUint32& aPos)
{
PRUint32 startSel, endSel;
nsresult retVal = GetSelection(&startSel, &endSel);
aPos = startSel;
return retVal;
}
#pragma mark -
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
void nsTextWidget::RepeatAction(const EventRecord& inMacEvent)
{
if (mControl)
{
StartDraw();
// This should really live in the window but
// we have to set the graphic environment
IdleControls(mWindowPtr);
EndDraw();
}
}
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
void nsTextWidget::GetRectForMacControl(nsRect &outRect)
{
outRect = mBounds;
outRect.x = outRect.y = 0;
// inset to make space for border
if (mIsReadOnly)
outRect.Deflate(1, 1);
else
outRect.Deflate(4, 4);
}

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

@ -1,100 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the 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 nsTextWidget_h__
#define nsTextWidget_h__
#include "nsMacControl.h"
#include "nsITextWidget.h"
#include "nsRepeater.h"
class nsTextWidget : public nsMacControl, public nsITextWidget, public Repeater
{
private:
typedef nsMacControl Inherited;
public:
nsTextWidget();
virtual ~nsTextWidget();
// nsISupports
NS_IMETHOD_(nsrefcnt) AddRef();
NS_IMETHOD_(nsrefcnt) Release();
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
NS_IMETHOD Create(nsIWidget *aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext = nsnull,
nsIAppShell *aAppShell = nsnull,
nsIToolkit *aToolkit = nsnull,
nsWidgetInitData *aInitData = nsnull);
NS_IMETHOD Destroy ( ) ;
// nsWindow Interface
virtual PRBool DispatchMouseEvent(nsMouseEvent &aEvent);
virtual PRBool DispatchWindowEvent(nsGUIEvent& aEvent);
virtual PRBool OnPaint(nsPaintEvent &aEvent);
// nsITextWidget interface
NS_IMETHOD SetPassword(PRBool aIsPassword);
NS_IMETHOD SetReadOnly(PRBool aNewReadOnlyFlag, PRBool& aOldReadOnlyFlag);
NS_IMETHOD SetMaxTextLength(PRUint32 aChars);
NS_IMETHOD GetText(nsString& aTextBuffer, PRUint32 aBufferSize, PRUint32& aActualSize);
NS_IMETHOD SetText(const nsString &aText, PRUint32& aActualSize);
NS_IMETHOD InsertText(const nsString &aText, PRUint32 aStartPos, PRUint32 aEndPos, PRUint32& aActualSize);
NS_IMETHOD RemoveText();
NS_IMETHOD SelectAll();
NS_IMETHOD SetSelection(PRUint32 aStartSel, PRUint32 aEndSel);
NS_IMETHOD GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel);
NS_IMETHOD SetCaretPosition(PRUint32 aPosition);
NS_IMETHOD GetCaretPosition(PRUint32& aPosition);
// Repeater interface
virtual void RepeatAction(const EventRecord& inMacEvent);
protected:
virtual void GetRectForMacControl(nsRect &outRect);
PRBool mIsPassword;
PRBool mIsReadOnly;
};
#endif // nsTextWidget_h__

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

@ -38,28 +38,21 @@
#include "nsIFactory.h" #include "nsIFactory.h"
#include "nsISupports.h" #include "nsISupports.h"
#include "nsIButton.h" #include "nsIComponentManager.h"
#include "nsITextWidget.h" #include "nsIGenericFactory.h"
#include "nsWidgetsCID.h" #include "nsWidgetsCID.h"
#include "nsToolkit.h" #include "nsToolkit.h"
#include "nsWindow.h" #include "nsWindow.h"
#include "nsMacWindow.h" #include "nsMacWindow.h"
#include "nsAppShell.h" #include "nsAppShell.h"
#include "nsButton.h"
#include "nsTextWidget.h"
#include "nsLabel.h"
#include "nsFilePicker.h" #include "nsFilePicker.h"
#include "nsNativeScrollbar.h" #include "nsNativeScrollbar.h"
#include "nsMenuBarX.h" #include "nsMenuBarX.h"
#include "nsMenuX.h" #include "nsMenuX.h"
#include "nsMenuItemX.h" #include "nsMenuItemX.h"
#define nsMenuBar nsMenuBarX
#define nsMenu nsMenuX
#define nsMenuItem nsMenuItemX
#include "nsClipboard.h" #include "nsClipboard.h"
#include "nsClipboardHelper.h" #include "nsClipboardHelper.h"
@ -67,40 +60,41 @@
#include "nsHTMLFormatConverter.h" #include "nsHTMLFormatConverter.h"
#include "nsDragService.h" #include "nsDragService.h"
#include "nsDragHelperService.h" #include "nsDragHelperService.h"
#if USE_NATIVE_VERSION
# include "nsCheckButton.h"
#endif
#include "nsLookAndFeel.h" #include "nsLookAndFeel.h"
#include "nsIComponentManager.h"
#include "nsSound.h" #include "nsSound.h"
#include "nsBidiKeyboard.h" #include "nsBidiKeyboard.h"
#include "nsIGenericFactory.h" #if USE_NATIVE_VERSION
#include "nsIButton.h"
#include "nsITextWidget.h"
#include "nsButton.h"
#include "nsCheckButton.h"
#include "nsTextWidget.h"
#include "nsLabel.h"
#endif
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMacWindow) NS_GENERIC_FACTORY_CONSTRUCTOR(nsMacWindow)
NS_GENERIC_FACTORY_CONSTRUCTOR(ChildWindow) NS_GENERIC_FACTORY_CONSTRUCTOR(ChildWindow)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsButton)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFilePicker) NS_GENERIC_FACTORY_CONSTRUCTOR(nsFilePicker)
#if USE_NATIVE_VERSION #if USE_NATIVE_VERSION
NS_GENERIC_FACTORY_CONSTRUCTOR(nsButton)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsCheckButton) NS_GENERIC_FACTORY_CONSTRUCTOR(nsCheckButton)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsComboBox) NS_GENERIC_FACTORY_CONSTRUCTOR(nsComboBox)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsRadioButton) NS_GENERIC_FACTORY_CONSTRUCTOR(nsRadioButton)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsListBox) NS_GENERIC_FACTORY_CONSTRUCTOR(nsListBox)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsTextAreaWidget) NS_GENERIC_FACTORY_CONSTRUCTOR(nsTextAreaWidget)
#endif NS_GENERIC_FACTORY_CONSTRUCTOR(nsLabel)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsTextWidget) // used by Viewer? NS_GENERIC_FACTORY_CONSTRUCTOR(nsTextWidget) // used by Viewer?
#endif
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAppShell) NS_GENERIC_FACTORY_CONSTRUCTOR(nsAppShell)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsToolkit) NS_GENERIC_FACTORY_CONSTRUCTOR(nsToolkit)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsLookAndFeel) NS_GENERIC_FACTORY_CONSTRUCTOR(nsLookAndFeel)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsLabel) NS_GENERIC_FACTORY_CONSTRUCTOR(nsMenuBarX)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMenuBar) NS_GENERIC_FACTORY_CONSTRUCTOR(nsMenuX)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMenu) NS_GENERIC_FACTORY_CONSTRUCTOR(nsMenuItemX)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMenuItem)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSound) NS_GENERIC_FACTORY_CONSTRUCTOR(nsSound)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsTransferable) NS_GENERIC_FACTORY_CONSTRUCTOR(nsTransferable)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboard) NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboard)
@ -111,8 +105,22 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsDragHelperService)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsNativeScrollbar) NS_GENERIC_FACTORY_CONSTRUCTOR(nsNativeScrollbar)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsBidiKeyboard) NS_GENERIC_FACTORY_CONSTRUCTOR(nsBidiKeyboard)
static const nsModuleComponentInfo components[] = static const nsModuleComponentInfo gComponents[] =
{ {
#if USE_NATIVE_VERSION
{ "Text Field",
NS_TEXTFIELD_CID,
"@mozilla.org/widgets/textwidget/mac;1",
nsTextWidgetConstructor },
{ "Label",
NS_LABEL_CID,
"@mozilla.org/widget/label/mac;1",
nsLabelConstructor },
{ "Button",
NS_BUTTON_CID,
"@mozilla.org/widgets/button/mac;1",
nsButtonConstructor },
#endif
{ "nsWindow", { "nsWindow",
NS_WINDOW_CID, NS_WINDOW_CID,
"@mozilla.org/widgets/window/mac;1", "@mozilla.org/widgets/window/mac;1",
@ -125,18 +133,10 @@ static const nsModuleComponentInfo components[] =
NS_CHILD_CID, NS_CHILD_CID,
"@mozilla.org/widgets/child_window/mac;1", "@mozilla.org/widgets/child_window/mac;1",
ChildWindowConstructor }, ChildWindowConstructor },
{ "Button",
NS_BUTTON_CID,
"@mozilla.org/widgets/button/mac;1",
nsButtonConstructor },
{ "File Picker", { "File Picker",
NS_FILEPICKER_CID, NS_FILEPICKER_CID,
"@mozilla.org/filepicker;1", "@mozilla.org/filepicker;1",
nsFilePickerConstructor }, nsFilePickerConstructor },
{ "Text Field",
NS_TEXTFIELD_CID,
"@mozilla.org/widgets/textwidget/mac;1",
nsTextWidgetConstructor },
{ "AppShell", { "AppShell",
NS_APPSHELL_CID, NS_APPSHELL_CID,
"@mozilla.org/widget/appshell/mac;1", "@mozilla.org/widget/appshell/mac;1",
@ -149,22 +149,18 @@ static const nsModuleComponentInfo components[] =
NS_LOOKANDFEEL_CID, NS_LOOKANDFEEL_CID,
"@mozilla.org/widget/lookandfeel;1", "@mozilla.org/widget/lookandfeel;1",
nsLookAndFeelConstructor }, nsLookAndFeelConstructor },
{ "Label",
NS_LABEL_CID,
"@mozilla.org/widget/label/mac;1",
nsLabelConstructor },
{ "Menubar", { "Menubar",
NS_MENUBAR_CID, NS_MENUBAR_CID,
"@mozilla.org/widget/menubar/mac;1", "@mozilla.org/widget/menubar/mac;1",
nsMenuBarConstructor }, nsMenuBarXConstructor },
{ "Menu", { "Menu",
NS_MENU_CID, NS_MENU_CID,
"@mozilla.org/widget/menu/mac;1", "@mozilla.org/widget/menu/mac;1",
nsMenuConstructor }, nsMenuXConstructor },
{ "MenuItem", { "MenuItem",
NS_MENUITEM_CID, NS_MENUITEM_CID,
"@mozilla.org/widget/menuitem/mac;1", "@mozilla.org/widget/menuitem/mac;1",
nsMenuItemConstructor }, nsMenuItemXConstructor },
{ "Sound", { "Sound",
NS_SOUND_CID, NS_SOUND_CID,
"@mozilla.org/sound;1", "@mozilla.org/sound;1",
@ -203,5 +199,5 @@ static const nsModuleComponentInfo components[] =
nsBidiKeyboardConstructor }, nsBidiKeyboardConstructor },
}; };
NS_IMPL_NSGETMODULE(nsWidgetMacModule, components) NS_IMPL_NSGETMODULE(nsWidgetMacModule, gComponents)