halfway fix the excessive GC problem. more work on resizing

This commit is contained in:
pavlov%pavlov.net 1999-01-09 21:16:20 +00:00
parent 7420687385
commit 6cd2b04993
4 changed files with 19 additions and 113 deletions

View File

@ -313,8 +313,11 @@ void handle_size_allocate(GtkWidget *w, GtkAllocation *alloc, gpointer p)
nsSizeEvent sevent;
InitAllocationEvent(alloc, p, sevent, NS_SIZE);
sevent.mWinWidth = gtk_widget_get_toplevel(w)->allocation.width;
sevent.mWinHeight = gtk_widget_get_toplevel(w)->allocation.height;
sevent.mWinWidth = alloc->width;
sevent.mWinHeight = alloc->height;
/* sevent.mWinWidth = gtk_widget_get_toplevel(w)->allocation.width;
sevent.mWinHeight = gtk_widget_get_toplevel(w)->allocation.height;
*/
nsWindow *win = (nsWindow *)p;

View File

@ -507,19 +507,20 @@ nsresult nsWidget::StandardWindowCreate(nsIWidget *aParent,
CreateNative (parentWidget);
if (parentWidget)
{
gtk_layout_put(GTK_LAYOUT(parentWidget), mWidget, mBounds.x, mBounds.y);
}
Resize(mBounds.width, mBounds.height, PR_FALSE);
InitCallbacks();
/* place the widget in its parent */
if (parentWidget)
gtk_layout_put(GTK_LAYOUT(parentWidget), mWidget, mBounds.x, mBounds.y);
CreateGC();
gtk_widget_pop_colormap();
gtk_widget_pop_visual();
DispatchStandardEvent(NS_CREATE);
InitCallbacks();
return NS_OK;
}
@ -596,26 +597,18 @@ nsIRenderingContext* nsWidget::GetRenderingContext()
void nsWidget::CreateGC()
{
if (nsnull == mGC) {
if (!mWidget) {
mWidget = ::gtk_window_new(GTK_WINDOW_POPUP);
gtk_widget_realize(mWidget);
mGC = ::gdk_gc_new(GTK_WIDGET(mWidget)->window);
}
else if (GTK_IS_LAYOUT(mWidget)) {
if (!GTK_LAYOUT(mWidget)->bin_window) {
if (mWidget && !mGC)
{
if (GTK_IS_LAYOUT(mWidget))
{
if (!GTK_LAYOUT(mWidget)->bin_window)
{
gtk_widget_realize(mWidget);
mGC = ::gdk_gc_new(GTK_LAYOUT(mWidget)->bin_window);
}
else
mGC = ::gdk_gc_new(GTK_LAYOUT(mWidget)->bin_window);
}
else if (!GTK_WIDGET(mWidget)->window) {
gtk_widget_realize(mWidget);
mGC = ::gdk_gc_new(GTK_WIDGET(mWidget)->window);
}
else
mGC = ::gdk_gc_new(GTK_WIDGET(mWidget)->window);
}
}

View File

@ -36,17 +36,10 @@
#include "stdio.h"
#include "mozicon.xpm"
//#define DBG 0
static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID);
extern GtkWidget *gAppContext;
static gint window_realize_callback(GtkWidget *window, gpointer data);
static void set_icon (GdkWindow * w);
//-------------------------------------------------------------------------
//
// nsWindow constructor
@ -122,73 +115,6 @@ NS_METHOD nsWindow::RemoveTooltips()
return NS_OK;
}
static gint window_realize_callback(GtkWidget *window, gpointer data)
{
if (window->window)
set_icon(window->window);
return PR_FALSE;
}
static void set_icon (GdkWindow * w)
{
GdkWindow *ic_win;
GdkWindowAttr att;
XIconSize *is;
gint i, count, j;
GdkPixmap *pmap, *mask;
if ((XGetIconSizes (GDK_DISPLAY (), GDK_ROOT_WINDOW (), &is, &count)) &&
(count > 0))
{
i = 0; /* use first icon size - not much point using the others */
att.width = is[i].max_width;
att.height = is[i].max_height;
/*
* raster had:
* att.height = 3 * att.width / 4;
* but this didn't work (it scaled the icons incorrectly
*/
/* make sure the icon is inside the min and max sizes */
if (att.height < is[i].min_height)
att.height = is[i].min_height;
if (att.height > is[i].max_height)
att.height = is[i].max_height;
if (is[i].width_inc > 0)
{
j = ((att.width - is[i].min_width) / is[i].width_inc);
att.width = is[i].min_width + (j * is[i].width_inc);
}
if (is[i].height_inc > 0)
{
j = ((att.height - is[i].min_height) / is[i].height_inc);
att.height = is[i].min_height + (j * is[i].height_inc);
}
XFree (is);
}
else
/* no icon size hints at all? ok - invent our own size */
{
att.width = 32;
att.height = 24;
}
att.wclass = GDK_INPUT_OUTPUT;
att.window_type = GDK_WINDOW_TOPLEVEL;
att.x = 0;
att.y = 0;
att.visual = gdk_rgb_get_visual ();
att.colormap = gdk_rgb_get_cmap ();
ic_win = gdk_window_new (nsnull, &att, GDK_WA_VISUAL | GDK_WA_COLORMAP);
gdk_window_set_icon (w, ic_win, nsnull, nsnull);
pmap = gdk_pixmap_create_from_xpm_d(w, &mask, 0, mozilla_icon_xpm);
gdk_window_set_back_pixmap (ic_win, pmap, PR_FALSE);
gdk_window_clear (ic_win);
gdk_window_shape_combine_mask (ic_win, mask, 0, 0);
gdk_pixmap_unref(pmap);
}
//-------------------------------------------------------------------------
//
// Create the native widget
@ -214,10 +140,6 @@ NS_METHOD nsWindow::CreateNative(GtkWidget *parentWidget)
mainWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_show (mainWindow);
gtk_signal_connect(GTK_OBJECT(mainWindow),
"realize",
GTK_SIGNAL_FUNC(window_realize_callback),
NULL);
// VBox for the menu, etc.
mVBox = gtk_vbox_new(PR_FALSE, 0);
@ -225,6 +147,7 @@ NS_METHOD nsWindow::CreateNative(GtkWidget *parentWidget)
gtk_container_add(GTK_CONTAINER(mainWindow), mVBox);
gtk_box_pack_start(GTK_BOX(mVBox), mWidget, PR_TRUE, PR_TRUE, 0);
}
// Force cursor to default setting
gtk_widget_set_name(mWidget, "nsWindow");
mCursor = eCursor_select;
@ -240,12 +163,10 @@ NS_METHOD nsWindow::CreateNative(GtkWidget *parentWidget)
//-------------------------------------------------------------------------
void nsWindow::InitCallbacks(char * aName)
{
gtk_signal_connect_after(GTK_OBJECT(mWidget),
"size_allocate",
GTK_SIGNAL_FUNC(handle_size_allocate),
this);
gtk_signal_connect(GTK_OBJECT(mWidget),
"button_press_event",
GTK_SIGNAL_FUNC(handle_button_press_event),
@ -410,17 +331,7 @@ void *nsWindow::GetNativeData(PRUint32 aDataType)
case NS_NATIVE_WIDGET:
return (void *)mWidget;
case NS_NATIVE_GRAPHIC:
{
void *res;
if (mGC) {
res = mGC;
} else {
NS_ASSERTION(mToolkit, "unable to return NS_NATIVE_GRAPHIC");
res = (void *)((nsToolkit *)mToolkit)->GetSharedGC();
}
NS_ASSERTION(res, "unable to return NS_NATIVE_GRAPHIC");
return res;
}
if (mGC) return (void *)mGC;
default:
break;
}

View File

@ -93,7 +93,6 @@ protected:
public:
protected:
nsIFontMetrics *mFontMetrics;
PRBool mIgnoreResize;
PRBool mVisible;
PRBool mDisplayed;