initial checkin for nsLabel and nsDialog

This commit is contained in:
rods%netscape.com 1998-08-28 22:49:12 +00:00
Родитель cfd714770c
Коммит c49e6ad540
4 изменённых файлов: 616 добавлений и 0 удалений

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

@ -0,0 +1,193 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsDialog.h"
#include "nsIDialog.h"
#include "nsToolkit.h"
#include "nsColor.h"
#include "nsGUIEvent.h"
#include "nsString.h"
#include "nsStringUtil.h"
#include "nsXtEventHandler.h"
#include <Xm/DialogS.h>
#define DBG 0
//-------------------------------------------------------------------------
//
// nsDialog constructor
//
//-------------------------------------------------------------------------
nsDialog::nsDialog(nsISupports *aOuter) : nsWindow(aOuter)
{
}
void nsDialog::Create(nsIWidget *aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell,
nsIToolkit *aToolkit,
nsWidgetInitData *aInitData)
{
aParent->AddChild(this);
Widget parentWidget = nsnull;
if (DBG) fprintf(stderr, "aParent 0x%x\n", aParent);
if (aParent) {
parentWidget = (Widget) aParent->GetNativeData(NS_NATIVE_WIDGET);
} else if (aAppShell) {
parentWidget = (Widget) aAppShell->GetNativeData(NS_NATIVE_SHELL);
}
InitToolkit(aToolkit, aParent);
InitDeviceContext(aContext, parentWidget);
if (DBG) fprintf(stderr, "Parent 0x%x\n", parentWidget);
unsigned char alignment = GetNativeAlignment();
mWidget = ::XtVaCreateManagedWidget("Dialog",
xmDialogShellWidgetClass,
parentWidget,
XmNwidth, aRect.width,
XmNheight, aRect.height,
XmNrecomputeSize, False,
XmNhighlightOnEnter, False,
XmNx, aRect.x,
XmNy, aRect.y,
XmNalignment, alignment,
nsnull);
if (DBG) fprintf(stderr, "Dialog 0x%x this 0x%x\n", mWidget, this);
// save the event callback function
mEventCallback = aHandleEventFunction;
InitCallbacks("nsDialog");
}
void nsDialog::Create(nsNativeWidget aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell,
nsIToolkit *aToolkit,
nsWidgetInitData *aInitData)
{
}
//-------------------------------------------------------------------------
//
// nsDialog destructor
//
//-------------------------------------------------------------------------
nsDialog::~nsDialog()
{
}
//-------------------------------------------------------------------------
//
// Query interface implementation
//
//-------------------------------------------------------------------------
nsresult nsDialog::QueryObject(REFNSIID aIID, void** aInstancePtr)
{
static NS_DEFINE_IID(kIDialogIID, NS_IDIALOG_IID);
if (aIID.Equals(kIDialogIID)) {
AddRef();
*aInstancePtr = (void**) &mAggWidget;
return NS_OK;
}
return nsWindow::QueryObject(aIID, aInstancePtr);
}
//-------------------------------------------------------------------------
//
// Set this button label
//
//-------------------------------------------------------------------------
void nsDialog::SetLabel(const nsString& aText)
{
NS_ALLOC_STR_BUF(label, aText, 256);
XmString str;
str = XmStringCreate(label, XmFONTLIST_DEFAULT_TAG);
XtVaSetValues(mWidget, XmNlabelString, str, nsnull);
NS_FREE_STR_BUF(label);
XmStringFree(str);
}
//-------------------------------------------------------------------------
//
// Get this button label
//
//-------------------------------------------------------------------------
void nsDialog::GetLabel(nsString& aBuffer)
{
XmString str;
XtVaGetValues(mWidget, XmNlabelString, &str, nsnull);
char * text;
if (XmStringGetLtoR(str, XmFONTLIST_DEFAULT_TAG, &text)) {
aBuffer.SetLength(0);
aBuffer.Append(text);
XtFree(text);
}
XmStringFree(str);
}
//-------------------------------------------------------------------------
//
// paint message. Don't send the paint out
//
//-------------------------------------------------------------------------
PRBool nsDialog::OnPaint(nsPaintEvent &aEvent)
{
//printf("** nsDialog::OnPaint **\n");
return PR_FALSE;
}
PRBool nsDialog::OnResize(nsSizeEvent &aEvent)
{
return PR_FALSE;
}
#define GET_OUTER() ((nsDialog*) ((char*)this - nsDialog::GetOuterOffset()))
void nsDialog::AggDialog::GetLabel(nsString& aBuffer)
{
GET_OUTER()->GetLabel(aBuffer);
}
void nsDialog::AggDialog::SetLabel(const nsString& aText)
{
GET_OUTER()->SetLabel(aText);
}
//----------------------------------------------------------------------
BASE_IWIDGET_IMPL(nsDialog, AggDialog);

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

@ -0,0 +1,92 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsDialog_h__
#define nsDialog_h__
//#include "nsdefs.h"
#include "nsWindow.h"
#include "nsIDialog.h"
/**
* Native Motif Dialog wrapper
*/
class nsDialog : public nsWindow
{
public:
nsDialog(nsISupports *aOuter);
virtual ~nsDialog();
NS_IMETHOD QueryObject(const nsIID& aIID, void** aInstancePtr);
void Create(nsIWidget *aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext = nsnull,
nsIAppShell *aAppShell = nsnull,
nsIToolkit *aToolkit = nsnull,
nsWidgetInitData *aInitData = nsnull);
void Create(nsNativeWidget aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext = nsnull,
nsIAppShell *aAppShell = nsnull,
nsIToolkit *aToolkit = nsnull,
nsWidgetInitData *aInitData = nsnull);
// nsIDialog part
virtual void SetLabel(const nsString& aText);
virtual void GetLabel(nsString& aBuffer);
virtual PRBool OnPaint(nsPaintEvent & aEvent);
virtual PRBool OnResize(nsSizeEvent &aEvent);
virtual void PreCreateWidget(nsWidgetInitData *aInitData);
private:
// this should not be public
static PRInt32 GetOuterOffset() {
return offsetof(nsDialog,mAggWidget);
}
// Aggregator class and instance variable used to aggregate in the
// nsIDialog interface to nsDialog w/o using multiple
// inheritance.
class AggDialog : public nsIDialog {
public:
AggDialog();
virtual ~AggDialog();
AGGREGATE_METHOD_DEF
// nsIDialog
virtual void SetLabel(const nsString &aText);
virtual void GetLabel(nsString &aBuffer);
};
AggDialog mAggWidget;
friend class AggDialog;
};
#endif // nsDialog_h__

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

@ -0,0 +1,233 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsLabel.h"
#include "nsILabel.h"
#include "nsToolkit.h"
#include "nsColor.h"
#include "nsGUIEvent.h"
#include "nsString.h"
#include "nsStringUtil.h"
#include "nsXtEventHandler.h"
#include <Xm/Label.h>
#define DBG 0
//-------------------------------------------------------------------------
//
// nsLabel constructor
//
//-------------------------------------------------------------------------
nsLabel::nsLabel(nsISupports *aOuter) : nsWindow(aOuter)
{
}
void nsLabel::Create(nsIWidget *aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell,
nsIToolkit *aToolkit,
nsWidgetInitData *aInitData)
{
aParent->AddChild(this);
Widget parentWidget = nsnull;
if (DBG) fprintf(stderr, "aParent 0x%x\n", aParent);
if (aParent) {
parentWidget = (Widget) aParent->GetNativeData(NS_NATIVE_WIDGET);
} else if (aAppShell) {
parentWidget = (Widget) aAppShell->GetNativeData(NS_NATIVE_SHELL);
}
InitToolkit(aToolkit, aParent);
InitDeviceContext(aContext, parentWidget);
if (DBG) fprintf(stderr, "Parent 0x%x\n", parentWidget);
unsigned char alignment = GetNativeAlignment();
mWidget = ::XtVaCreateManagedWidget("label",
xmLabelWidgetClass,
parentWidget,
XmNwidth, aRect.width,
XmNheight, aRect.height,
XmNrecomputeSize, False,
XmNhighlightOnEnter, False,
XmNx, aRect.x,
XmNy, aRect.y,
XmNalignment, alignment,
nsnull);
if (DBG) fprintf(stderr, "Label 0x%x this 0x%x\n", mWidget, this);
// save the event callback function
mEventCallback = aHandleEventFunction;
InitCallbacks("nsLabel");
}
void nsLabel::Create(nsNativeWidget aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell,
nsIToolkit *aToolkit,
nsWidgetInitData *aInitData)
{
}
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
void nsLabel::PreCreateWidget(nsWidgetInitData *aInitData)
{
if (nsnull != aInitData) {
nsLabelInitData* data = (nsLabelInitData *) aInitData;
mAlignment = data->mAlignment;
}
}
//-------------------------------------------------------------------------
//
// Set alignment
//
//-------------------------------------------------------------------------
void nsLabel::SetAlignment(nsLabelAlignment aAlignment)
{
mAlignment = aAlignment;
}
//-------------------------------------------------------------------------
//
// nsLabel destructor
//
//-------------------------------------------------------------------------
nsLabel::~nsLabel()
{
}
//-------------------------------------------------------------------------
//
// Query interface implementation
//
//-------------------------------------------------------------------------
nsresult nsLabel::QueryObject(REFNSIID aIID, void** aInstancePtr)
{
static NS_DEFINE_IID(kILabelIID, NS_ILABEL_IID);
if (aIID.Equals(kILabelIID)) {
AddRef();
*aInstancePtr = (void**) &mAggWidget;
return NS_OK;
}
return nsWindow::QueryObject(aIID, aInstancePtr);
}
//-------------------------------------------------------------------------
//
// return window styles
//
//-------------------------------------------------------------------------
unsigned char nsLabel::GetNativeAlignment()
{
switch (mAlignment) {
case eAlign_Right : return XmALIGNMENT_END;
case eAlign_Left : return XmALIGNMENT_BEGINNING;
case eAlign_Center: return XmALIGNMENT_CENTER;
default :
return XmALIGNMENT_BEGINNING;
}
return XmALIGNMENT_BEGINNING;
}
//-------------------------------------------------------------------------
//
// Set this button label
//
//-------------------------------------------------------------------------
void nsLabel::SetLabel(const nsString& aText)
{
NS_ALLOC_STR_BUF(label, aText, 256);
XmString str;
str = XmStringCreate(label, XmFONTLIST_DEFAULT_TAG);
XtVaSetValues(mWidget, XmNlabelString, str, nsnull);
NS_FREE_STR_BUF(label);
XmStringFree(str);
}
//-------------------------------------------------------------------------
//
// Get this button label
//
//-------------------------------------------------------------------------
void nsLabel::GetLabel(nsString& aBuffer)
{
XmString str;
XtVaGetValues(mWidget, XmNlabelString, &str, nsnull);
char * text;
if (XmStringGetLtoR(str, XmFONTLIST_DEFAULT_TAG, &text)) {
aBuffer.SetLength(0);
aBuffer.Append(text);
XtFree(text);
}
XmStringFree(str);
}
//-------------------------------------------------------------------------
//
// paint message. Don't send the paint out
//
//-------------------------------------------------------------------------
PRBool nsLabel::OnPaint(nsPaintEvent &aEvent)
{
//printf("** nsLabel::OnPaint **\n");
return PR_FALSE;
}
PRBool nsLabel::OnResize(nsSizeEvent &aEvent)
{
return PR_FALSE;
}
#define GET_OUTER() ((nsLabel*) ((char*)this - nsLabel::GetOuterOffset()))
void nsLabel::AggLabel::GetLabel(nsString& aBuffer)
{
GET_OUTER()->GetLabel(aBuffer);
}
void nsLabel::AggLabel::SetLabel(const nsString& aText)
{
GET_OUTER()->SetLabel(aText);
}
//----------------------------------------------------------------------
BASE_IWIDGET_IMPL(nsLabel, AggLabel);

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

@ -0,0 +1,98 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsLabel_h__
#define nsLabel_h__
//#include "nsdefs.h"
#include "nsWindow.h"
#include "nsILabel.h"
/**
* Native Motif Label wrapper
*/
class nsLabel : public nsWindow
{
public:
nsLabel(nsISupports *aOuter);
virtual ~nsLabel();
NS_IMETHOD QueryObject(const nsIID& aIID, void** aInstancePtr);
void Create(nsIWidget *aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext = nsnull,
nsIAppShell *aAppShell = nsnull,
nsIToolkit *aToolkit = nsnull,
nsWidgetInitData *aInitData = nsnull);
void Create(nsNativeWidget aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext = nsnull,
nsIAppShell *aAppShell = nsnull,
nsIToolkit *aToolkit = nsnull,
nsWidgetInitData *aInitData = nsnull);
// nsILabel part
virtual void SetAlignment(nsLabelAlignment aAlignment);
virtual void SetLabel(const nsString& aText);
virtual void GetLabel(nsString& aBuffer);
virtual PRBool OnPaint(nsPaintEvent & aEvent);
virtual PRBool OnResize(nsSizeEvent &aEvent);
virtual void PreCreateWidget(nsWidgetInitData *aInitData);
protected:
unsigned char nsLabel::GetNativeAlignment();
nsLabelAlignment mAlignment;
private:
// this should not be public
static PRInt32 GetOuterOffset() {
return offsetof(nsLabel,mAggWidget);
}
// Aggregator class and instance variable used to aggregate in the
// nsILabel interface to nsLabel w/o using multiple
// inheritance.
class AggLabel : public nsILabel {
public:
AggLabel();
virtual ~AggLabel();
AGGREGATE_METHOD_DEF
// nsILabel
virtual void SetLabel(const nsString &aText);
virtual void GetLabel(nsString &aBuffer);
virtual void SetAlignment(nsLabelAlignment aAlignment);
};
AggLabel mAggWidget;
friend class AggLabel;
};
#endif // nsLabel_h__