fix for 5494 and 2nd attempt at command line services (if 0'd out atm)

This commit is contained in:
pavlov%pavlov.net 1999-05-15 05:13:21 +00:00
Родитель 8c649fbcfa
Коммит d4506e3a23
7 изменённых файлов: 132 добавлений и 110 удалений

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

@ -21,24 +21,17 @@
#include "plevent.h"
#include "nsIServiceManager.h"
#include "nsIEventQueueService.h"
#include "nsICmdLineService.h"
#include "nsXPComCIID.h"
#include <stdlib.h>
#include "nsIWidget.h"
//#define CMDLINEARGS
#ifdef CMDLINEARGS
#include "nsICmdLineService.h"
#endif
static NS_DEFINE_IID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
static NS_DEFINE_IID(kIEventQueueServiceIID, NS_IEVENTQUEUESERVICE_IID);
#ifdef CMDLINEARGS
static NS_DEFINE_IID(kCmdLineServiceCID, NS_COMMANDLINE_SERVICE_CID);
static NS_DEFINE_IID(kICmdLineServiceIID, NS_ICOMMANDLINE_SERVICE_IID);
#endif
//-------------------------------------------------------------------------
//
@ -90,32 +83,37 @@ static void event_processor_callback(gpointer data,
//
//-------------------------------------------------------------------------
#ifdef CMDLINEARGS
NS_METHOD nsAppShell::Create(int *bac, char **bav)
#else
NS_METHOD nsAppShell::Create(int *argc, char **argv)
#endif
{
gchar *home;
gchar *path;
#ifdef CMDLINEARGS
int *argc;
char **argv;
nsICmdLineService *cmdLineArgs=nsnull;
nsresult rv = NS_OK;
gchar *home=nsnull;
gchar *path=nsnull;
int *argc=nsnull;
char **argv=nsnull;
#if 0
// why do i get an error if this is defined here??
// nsICmdLineService *cmdLineArgs=nsnull;
nsresult rv = NS_OK;
NS_WITH_SERVICE(nsICmdLineService, cmdLineArgs, kCmdLineServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = cmdLineArgs->GetArgc(argc);
if(NS_FAILED(rv)) return rv;
rv = cmdLineArgs->GetArgv(&argv);
if(NS_FAILED(rv)) return rv;
if (NS_SUCCEEDED(rv))
{
rv = cmdLineArgs->GetArgc(argc);
if(NS_FAILED(rv))
argc = bac;
rv = cmdLineArgs->GetArgv(&argv);
if(NS_FAILED(rv))
argv = bav;
} else {
argc = bac;
argv = bav;
}
#else
argc = bac;
argv = bav;
#endif
gtk_set_locale ();
gtk_init (argc, &argv);
@ -125,12 +123,12 @@ NS_METHOD nsAppShell::Create(int *argc, char **argv)
gdk_rgb_init();
home = g_get_home_dir();
if ( (char *) NULL != home ) {
path = g_strdup_printf("%s%c%s", home, G_DIR_SEPARATOR, ".gtkrc");
if ( (char *) NULL != path ) {
gtk_rc_parse(path);
g_free( path );
}
if ((char*)nsnull != home) {
path = g_strdup_printf("%s%c%s", home, G_DIR_SEPARATOR, ".gtkrc");
if ((char *)nsnull != path) {
gtk_rc_parse(path);
g_free(path);
}
}
return NS_OK;
@ -183,7 +181,7 @@ NS_METHOD nsAppShell::Run()
// If a queue already present use it.
if (EQueue)
goto done;
goto done;
// Create the event queue for the thread
rv = mEventQService->CreateThreadEventQueue();
@ -194,8 +192,8 @@ NS_METHOD nsAppShell::Run()
//Get the event queue for the thread
rv = mEventQService->GetThreadEventQueue(PR_GetCurrentThread(), &EQueue);
if (NS_OK != rv) {
NS_ASSERTION("Could not obtain the thread event queue", PR_FALSE);
return rv;
NS_ASSERTION("Could not obtain the thread event queue", PR_FALSE);
return rv;
}
@ -234,10 +232,9 @@ NS_METHOD nsAppShell::Exit()
void* nsAppShell::GetNativeData(PRUint32 aDataType)
{
if (aDataType == NS_NATIVE_SHELL) {
// this isn't accually used, but if it was, we need to gtk_widget_ref() it.
// this isn't accually used, but if it was, we need to gtk_widget_ref() it.
// return mTopLevel;
// return mTopLevel;
}
return nsnull;
}
@ -249,59 +246,66 @@ NS_METHOD nsAppShell::GetNativeEvent(PRBool &aRealEvent, void *& aEvent)
aEvent = 0;
aRealEvent = PR_FALSE;
event = gdk_event_peek();
if ( (GdkEvent *) NULL != event ) {
aRealEvent = PR_TRUE;
aEvent = event;
if ((GdkEvent *) nsnull != event ) {
aRealEvent = PR_TRUE;
aEvent = event;
} else
g_main_iteration (TRUE);
g_main_iteration (PR_TRUE);
return NS_OK;
}
NS_METHOD nsAppShell::DispatchNativeEvent(PRBool aRealEvent, void *aEvent)
{
if ( aRealEvent == PR_TRUE )
g_main_iteration (TRUE);
g_main_iteration (PR_TRUE);
return NS_OK;
}
NS_METHOD nsAppShell::EventIsForModalWindow(PRBool aRealEvent, void *aEvent,
nsIWidget *aWidget, PRBool *aForWindow)
NS_METHOD nsAppShell::EventIsForModalWindow(PRBool aRealEvent,
void *aEvent,
nsIWidget *aWidget,
PRBool *aForWindow)
{
PRBool isInWindow, isMouseEvent;
GdkEventAny *msg = (GdkEventAny *) aEvent;
if (aRealEvent == PR_FALSE) {
*aForWindow = PR_FALSE;
return NS_OK;
*aForWindow = PR_FALSE;
return NS_OK;
}
isInWindow = PR_FALSE;
if (aWidget != nsnull) {
// Get Native Window for dialog window
GdkWindow *win;
win = (GdkWindow *)aWidget->GetNativeData(NS_NATIVE_WINDOW);
// Get Native Window for dialog window
GdkWindow *win;
win = (GdkWindow *)aWidget->GetNativeData(NS_NATIVE_WINDOW);
// Find top most window of event window
GdkWindow *eWin = msg->window;
if (NULL != eWin) {
if (win == eWin) {
isInWindow = PR_TRUE;
}
}
// Find top most window of event window
GdkWindow *eWin = msg->window;
if (nsnull != eWin) {
if (win == eWin) {
isInWindow = PR_TRUE;
}
}
}
isMouseEvent = PR_FALSE;
switch (msg->type) {
case GDK_MOTION_NOTIFY:
case GDK_BUTTON_PRESS:
case GDK_2BUTTON_PRESS:
case GDK_3BUTTON_PRESS:
case GDK_BUTTON_RELEASE:
isMouseEvent = PR_TRUE;
switch (msg->type)
{
case GDK_MOTION_NOTIFY:
case GDK_BUTTON_PRESS:
case GDK_2BUTTON_PRESS:
case GDK_3BUTTON_PRESS:
case GDK_BUTTON_RELEASE:
isMouseEvent = PR_TRUE;
default:
isMouseEvent = PR_FALSE;
}
*aForWindow = isInWindow == PR_TRUE ||
isMouseEvent == PR_FALSE ? PR_TRUE : PR_FALSE;
isMouseEvent == PR_FALSE ? PR_TRUE : PR_FALSE;
gdk_event_free( (GdkEvent *) aEvent );
return NS_OK;

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

@ -368,6 +368,7 @@ NS_METHOD nsListBox::CreateNative(GtkWidget *parentWindow)
// to handle scrolling
mWidget = gtk_scrolled_window_new (nsnull, nsnull);
gtk_widget_set_name(mWidget, "nsListBox");
gtk_container_set_border_width(GTK_CONTAINER(mWidget), 0);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (mWidget),
GTK_POLICY_NEVER,
GTK_POLICY_AUTOMATIC);

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

@ -108,16 +108,16 @@ NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricID aID, PRInt32 & aMetric)
break;
case eMetric_TextFieldHeight:
{
GtkRequisition req;
GtkWidget *text = gtk_entry_new();
// needed to avoid memory leak
gtk_widget_ref(text);
gtk_object_sink(GTK_OBJECT(text));
gtk_widget_size_request(text,&req);
aMetric = req.height;
gtk_widget_destroy(text);
gtk_widget_unref(text);
}
GtkRequisition req;
GtkWidget *text = gtk_entry_new();
// needed to avoid memory leak
gtk_widget_ref(text);
gtk_object_sink(GTK_OBJECT(text));
gtk_widget_size_request(text,&req);
aMetric = req.height;
gtk_widget_destroy(text);
gtk_widget_unref(text);
}
break;
case eMetric_TextVerticalInsidePadding:
aMetric = 0;
@ -126,10 +126,10 @@ NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricID aID, PRInt32 & aMetric)
aMetric = 0;
break;
case eMetric_TextHorizontalInsideMinimumPadding:
aMetric = 0;
aMetric = 15;
break;
case eMetric_TextShouldUseHorizontalInsideMinimumPadding:
aMetric = 0;
aMetric = 1;
break;
case eMetric_ButtonHorizontalInsidePaddingNavQuirks:
aMetric = 10;

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

@ -44,6 +44,8 @@ nsTextAreaWidget::nsTextAreaWidget()
//-------------------------------------------------------------------------
nsTextAreaWidget::~nsTextAreaWidget()
{
gtk_widget_destroy(mTextWidget);
mTextWidget = nsnull;
}
//-------------------------------------------------------------------------
@ -54,11 +56,21 @@ nsTextAreaWidget::~nsTextAreaWidget()
NS_METHOD nsTextAreaWidget::CreateNative(GtkWidget *parentWindow)
{
PRBool oldIsReadOnly;
mWidget = gtk_text_new(PR_FALSE, PR_FALSE);
gtk_text_set_word_wrap(GTK_TEXT(mWidget), PR_TRUE);
gtk_widget_set_name(mWidget, "nsTextAreaWidget");
mWidget = gtk_scrolled_window_new(nsnull, nsnull);
gtk_container_set_border_width(GTK_CONTAINER(mWidget), 0);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(mWidget),
GTK_POLICY_NEVER,
GTK_POLICY_ALWAYS);
mTextWidget = gtk_text_new(nsnull, nsnull);
gtk_text_set_word_wrap(GTK_TEXT(mTextWidget), PR_TRUE);
gtk_widget_set_name(mTextWidget, "nsTextAreaWidget");
gtk_widget_show(mTextWidget);
SetPassword(mIsPassword);
SetReadOnly(mIsReadOnly, oldIsReadOnly);
gtk_container_add(GTK_CONTAINER(mWidget), mTextWidget);
return NS_OK;
}

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

@ -26,8 +26,6 @@
#include "nsString.h"
#include "nsStringUtil.h"
#define DBG 0
NS_IMPL_ADDREF_INHERITED(nsTextHelper, nsWidget)
NS_IMPL_RELEASE_INHERITED(nsTextHelper, nsWidget)
@ -71,7 +69,7 @@ NS_METHOD nsTextHelper::PreCreateWidget(nsWidgetInitData *aInitData)
NS_METHOD nsTextHelper::SetMaxTextLength(PRUint32 aChars)
{
// This is a normal entry only thing, not a text box
gtk_entry_set_max_length(GTK_ENTRY(mWidget), (int)aChars);
gtk_entry_set_max_length(GTK_ENTRY(mTextWidget), (int)aChars);
return NS_OK;
}
@ -79,14 +77,14 @@ NS_METHOD nsTextHelper::SetMaxTextLength(PRUint32 aChars)
NS_METHOD nsTextHelper::GetText(nsString& aTextBuffer, PRUint32 aBufferSize, PRUint32& aActualSize)
{
char *str = nsnull;
if (GTK_IS_ENTRY(mWidget))
if (GTK_IS_ENTRY(mTextWidget))
{
str = gtk_entry_get_text(GTK_ENTRY(mWidget));
str = gtk_entry_get_text(GTK_ENTRY(mTextWidget));
}
else if (GTK_IS_TEXT(mWidget))
else if (GTK_IS_TEXT(mTextWidget))
{
str = gtk_editable_get_chars (GTK_EDITABLE (mWidget), 0,
gtk_text_get_length (GTK_TEXT (mWidget)));
str = gtk_editable_get_chars (GTK_EDITABLE (mTextWidget), 0,
gtk_text_get_length (GTK_TEXT (mTextWidget)));
}
aTextBuffer.SetLength(0);
aTextBuffer.Append(str);
@ -101,12 +99,12 @@ NS_METHOD nsTextHelper::SetText(const nsString& aText, PRUint32& aActualSize)
{
char *buf = aText.ToNewCString();
if (GTK_IS_ENTRY(mWidget)) {
gtk_entry_set_text(GTK_ENTRY(mWidget), buf);
} else if (GTK_IS_TEXT(mWidget)) {
gtk_editable_delete_text(GTK_EDITABLE(mWidget), 0,
gtk_text_get_length(GTK_TEXT (mWidget)));
gtk_text_insert(GTK_TEXT(mWidget), nsnull, nsnull, nsnull,
if (GTK_IS_ENTRY(mTextWidget)) {
gtk_entry_set_text(GTK_ENTRY(mTextWidget), buf);
} else if (GTK_IS_TEXT(mTextWidget)) {
gtk_editable_delete_text(GTK_EDITABLE(mTextWidget), 0,
gtk_text_get_length(GTK_TEXT (mTextWidget)));
gtk_text_insert(GTK_TEXT(mTextWidget), nsnull, nsnull, nsnull,
buf, aText.Length());
}
@ -121,7 +119,7 @@ NS_METHOD nsTextHelper::InsertText(const nsString &aText, PRUint32 aStartPos, P
{
char *buf = aText.ToNewCString();
gtk_editable_insert_text(GTK_EDITABLE(mWidget), buf, (gint)aText.Length(), (gint*)&aStartPos);
gtk_editable_insert_text(GTK_EDITABLE(mTextWidget), buf, (gint)aText.Length(), (gint*)&aStartPos);
aActualSize = aText.Length();
@ -132,11 +130,11 @@ NS_METHOD nsTextHelper::InsertText(const nsString &aText, PRUint32 aStartPos, P
//-------------------------------------------------------------------------
NS_METHOD nsTextHelper::RemoveText()
{
if (GTK_IS_ENTRY(mWidget)) {
gtk_entry_set_text(GTK_ENTRY(mWidget), "");
} else if (GTK_IS_TEXT(mWidget)) {
gtk_editable_delete_text(GTK_EDITABLE(mWidget), 0,
gtk_text_get_length(GTK_TEXT (mWidget)));
if (GTK_IS_ENTRY(mTextWidget)) {
gtk_entry_set_text(GTK_ENTRY(mTextWidget), "");
} else if (GTK_IS_TEXT(mTextWidget)) {
gtk_editable_delete_text(GTK_EDITABLE(mTextWidget), 0,
gtk_text_get_length(GTK_TEXT (mTextWidget)));
}
return NS_OK;
}
@ -145,8 +143,8 @@ NS_METHOD nsTextHelper::RemoveText()
NS_METHOD nsTextHelper::SetPassword(PRBool aIsPassword)
{
mIsPassword = aIsPassword?PR_FALSE:PR_TRUE;
if (GTK_IS_ENTRY(mWidget)) {
gtk_entry_set_visibility(GTK_ENTRY(mWidget), mIsPassword);
if (GTK_IS_ENTRY(mTextWidget)) {
gtk_entry_set_visibility(GTK_ENTRY(mTextWidget), mIsPassword);
}
// this won't work for gtk_texts
return NS_OK;
@ -155,11 +153,11 @@ NS_METHOD nsTextHelper::SetPassword(PRBool aIsPassword)
//-------------------------------------------------------------------------
NS_METHOD nsTextHelper::SetReadOnly(PRBool aReadOnlyFlag, PRBool& aOldReadOnlyFlag)
{
NS_ASSERTION(nsnull != mWidget,
NS_ASSERTION(nsnull != mTextWidget,
"SetReadOnly - Widget is NULL, Create may not have been called!");
aOldReadOnlyFlag = mIsReadOnly;
mIsReadOnly = aReadOnlyFlag?PR_FALSE:PR_TRUE;
gtk_editable_set_editable(GTK_EDITABLE(mWidget), mIsReadOnly);
gtk_editable_set_editable(GTK_EDITABLE(mTextWidget), mIsReadOnly);
return NS_OK;
}
@ -178,7 +176,7 @@ NS_METHOD nsTextHelper::SelectAll()
//-------------------------------------------------------------------------
NS_METHOD nsTextHelper::SetSelection(PRUint32 aStartSel, PRUint32 aEndSel)
{
gtk_editable_select_region(GTK_EDITABLE(mWidget), aStartSel, aEndSel);
gtk_editable_select_region(GTK_EDITABLE(mTextWidget), aStartSel, aEndSel);
return NS_OK;
}
@ -190,7 +188,7 @@ NS_METHOD nsTextHelper::GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel)
XmTextPosition left;
XmTextPosition right;
if (XmTextGetSelectionPosition(mWidget, &left, &right)) {
if (XmTextGetSelectionPosition(mTextWidget, &left, &right)) {
*aStartSel = (PRUint32)left;
*aEndSel = (PRUint32)right;
} else {
@ -204,13 +202,13 @@ NS_METHOD nsTextHelper::GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel)
//-------------------------------------------------------------------------
NS_METHOD nsTextHelper::SetCaretPosition(PRUint32 aPosition)
{
gtk_editable_set_position(GTK_EDITABLE(mWidget), aPosition);
gtk_editable_set_position(GTK_EDITABLE(mTextWidget), aPosition);
return NS_OK;
}
//-------------------------------------------------------------------------
NS_METHOD nsTextHelper::GetCaretPosition(PRUint32& aPosition)
{
aPosition = (PRUint32)GTK_EDITABLE(mWidget)->current_pos;
aPosition = (PRUint32)GTK_EDITABLE(mTextWidget)->current_pos;
return NS_OK;
}

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

@ -53,6 +53,7 @@ public:
NS_IMETHOD GetCaretPosition(PRUint32& aPosition);
protected:
GtkWidget *mTextWidget;
PRBool mIsPassword;
PRBool mIsReadOnly;

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

@ -45,6 +45,8 @@ nsTextWidget::nsTextWidget() : nsTextHelper()
//-------------------------------------------------------------------------
nsTextWidget::~nsTextWidget()
{
// avoid freeing this twice in other destructors
mTextWidget = nsnull;
}
//-------------------------------------------------------------------------
@ -56,6 +58,10 @@ NS_METHOD nsTextWidget::CreateNative(GtkWidget *parentWindow)
{
PRBool oldIsReadOnly;
mWidget = gtk_entry_new();
// used by nsTextHelper because nsTextArea needs a scrolled_window
mTextWidget = mWidget;
gtk_widget_set_name(mWidget, "nsTextWidget");
gtk_signal_connect(GTK_OBJECT(mWidget),
"key_release_event",