From 90944754dd89ce0c880951fb3edb06a3e4992e98 Mon Sep 17 00:00:00 2001 From: "pavlov%pavlov.net" Date: Fri, 5 Mar 1999 02:48:43 +0000 Subject: [PATCH] start fixing file selector, fix menus under apprunner, fix font setting for widgets. --- widget/src/gtk/nsFileWidget.cpp | 7 ++----- widget/src/gtk/nsGtkEventHandler.cpp | 15 +++++++++++++-- widget/src/gtk/nsMenuItem.cpp | 7 +++++++ widget/src/gtk/nsMenuItem.h | 1 + widget/src/gtk/nsWidget.cpp | 19 ++++++++++++------- 5 files changed, 35 insertions(+), 14 deletions(-) diff --git a/widget/src/gtk/nsFileWidget.cpp b/widget/src/gtk/nsFileWidget.cpp index 2045c1630f8e..d9d740727cc8 100644 --- a/widget/src/gtk/nsFileWidget.cpp +++ b/widget/src/gtk/nsFileWidget.cpp @@ -79,9 +79,9 @@ PRBool nsFileWidget::Show() gtk_signal_connect(GTK_OBJECT(fs->cancel_button), "clicked", GTK_SIGNAL_FUNC(file_cancel_clicked), &ret); + // start new loop. ret is set in the above callbacks. gtk_main(); -// returning true causes the browser to try and display the dir structure... -// return PR_TRUE; + return ret; } @@ -148,9 +148,6 @@ NS_METHOD nsFileWidget::Create(nsIWidget *aParent, mWidget = gtk_file_selection_new(title); -// mWnd = (HWND) ((aParent) ? aParent->GetNativeData(NS_NATIVE_WINDOW) : 0); -// mTitle.SetLength(0); -// mTitle.Append(aTitle); return NS_OK; } diff --git a/widget/src/gtk/nsGtkEventHandler.cpp b/widget/src/gtk/nsGtkEventHandler.cpp index 3c00ba6d2d38..663d48a74120 100644 --- a/widget/src/gtk/nsGtkEventHandler.cpp +++ b/widget/src/gtk/nsGtkEventHandler.cpp @@ -28,6 +28,7 @@ #include "nsFileWidget.h" #include "nsGUIEvent.h" #include "nsIMenuItem.h" +#include "nsIMenuListener.h" #include "stdio.h" @@ -566,7 +567,10 @@ gint handle_focus_out_event(GtkWidget *w, GdkEventFocus * event, gpointer p) void menu_item_activate_handler(GtkWidget *w, gpointer p) { g_print("menu selected\n"); - nsIMenuItem * menuItem = (nsIMenuItem *)p; + + nsIMenuListener *menuListener = nsnull; + nsIMenuItem *menuItem = (nsIMenuItem *)p; + if (menuItem != NULL) { nsMenuEvent mevent; mevent.message = NS_MENU_SELECTED; @@ -580,7 +584,14 @@ void menu_item_activate_handler(GtkWidget *w, gpointer p) mevent.time = PR_IntervalNow(); nsEventStatus status; - mevent.widget->DispatchEvent((nsGUIEvent *)&mevent, status); + // FIXME - THIS SHOULD WORK. FIX EVENTS FOR XP CODE!!!!! (pav) +// mevent.widget->DispatchEvent((nsGUIEvent *)&mevent, status); + + menuItem->QueryInterface(kIMenuListenerIID, (void**)&menuListener); + if(menuListener) { + menuListener->MenuSelected(mevent); + NS_IF_RELEASE(menuListener); + } } } diff --git a/widget/src/gtk/nsMenuItem.cpp b/widget/src/gtk/nsMenuItem.cpp index d66f0161db73..795bbceb841b 100644 --- a/widget/src/gtk/nsMenuItem.cpp +++ b/widget/src/gtk/nsMenuItem.cpp @@ -77,6 +77,7 @@ nsMenuItem::nsMenuItem() : nsIMenuItem() mMenuParent = nsnull; mPopUpParent = nsnull; mTarget = nsnull; + mXULCommandListener = nsnull; mIsSeparator = PR_FALSE; } @@ -298,6 +299,9 @@ NS_METHOD nsMenuItem::GetNativeData(void *& aData) //------------------------------------------------------------------------- NS_METHOD nsMenuItem::AddMenuListener(nsIMenuListener * aMenuListener) { + NS_IF_RELEASE(mXULCommandListener); + NS_IF_ADDREF(aMenuListener); + mXULCommandListener = aMenuListener; return NS_OK; } @@ -319,6 +323,9 @@ NS_METHOD nsMenuItem::IsSeparator(PRBool & aIsSep) //------------------------------------------------------------------------- nsEventStatus nsMenuItem::MenuSelected(const nsMenuEvent & aMenuEvent) { + if(mXULCommandListener) + return mXULCommandListener->MenuSelected(aMenuEvent); + g_print("nsMenuItem::MenuSelected\n"); return nsEventStatus_eIgnore; } diff --git a/widget/src/gtk/nsMenuItem.h b/widget/src/gtk/nsMenuItem.h index 7d0cd303195e..237926b104e6 100644 --- a/widget/src/gtk/nsMenuItem.h +++ b/widget/src/gtk/nsMenuItem.h @@ -76,6 +76,7 @@ protected: nsIWidget *GetMenuBarParent(nsISupports * aParentSupports); GtkWidget *GetNativeParent(); + nsIMenuListener *mXULCommandListener; nsString mLabel; PRUint32 mCommand; nsIMenu *mMenuParent; diff --git a/widget/src/gtk/nsWidget.cpp b/widget/src/gtk/nsWidget.cpp index c927767911d6..07f53744dc0d 100644 --- a/widget/src/gtk/nsWidget.cpp +++ b/widget/src/gtk/nsWidget.cpp @@ -324,24 +324,31 @@ nsIFontMetrics *nsWidget::GetFont(void) //------------------------------------------------------------------------- NS_METHOD nsWidget::SetFont(const nsFont &aFont) { - nsIFontMetrics* mFontMetrics; mContext->GetMetricsFor(aFont, mFontMetrics); if (mFontMetrics) { nsFontHandle fontHandle; mFontMetrics->GetFontHandle(fontHandle); + gtk_widget_ensure_style(mWidget); - GtkStyle* style; - style= gtk_widget_get_style(mWidget); + GtkStyle *style = gtk_style_copy(mWidget->style); + // gtk_style_copy ups the ref count of the font gdk_font_unref (style->font); - style->font = (GdkFont *)fontHandle; + GdkFontPrivate *pvt; + + pvt = (GdkFontPrivate*) style->font; + g_print("font refcount: %i\n",pvt->ref_count); + + GdkFont *font = (GdkFont *)fontHandle; + style->font = font; gdk_font_ref(style->font); - gtk_widget_set_style(mWidget, style); + gtk_style_unref(style); + } NS_RELEASE(mFontMetrics); return NS_OK; @@ -583,7 +590,6 @@ nsresult nsWidget::CreateWidget(nsIWidget *aParent, gtk_widget_push_colormap(gdk_rgb_get_cmap()); gtk_widget_push_visual(gdk_rgb_get_visual()); - gtk_widget_push_style(gtk_style_new()); BaseCreate(aParent, aRect, aHandleEventFunction, aContext, aAppShell, aToolkit, aInitData); @@ -608,7 +614,6 @@ nsresult nsWidget::CreateWidget(nsIWidget *aParent, gtk_widget_pop_colormap(); gtk_widget_pop_visual(); - gtk_widget_pop_style (); DispatchStandardEvent(NS_CREATE); InitCallbacks();