diff --git a/widget/src/gtk/nsClipboard.cpp b/widget/src/gtk/nsClipboard.cpp index ea177314bb2..a4befd55d19 100644 --- a/widget/src/gtk/nsClipboard.cpp +++ b/widget/src/gtk/nsClipboard.cpp @@ -37,6 +37,7 @@ #include "nsXPIDLString.h" #include "nsPrimitiveHelpers.h" +#include "nsTextFormatter.h" #include "nsVoidArray.h" @@ -665,8 +666,33 @@ nsClipboard::SelectionReceiver (GtkWidget *aWidget, switch (type) { - case GDK_TARGET_STRING: case TARGET_UTF8: + { + mSelectionData = *aSD; + + static const PRUnichar unicodeFormatter[] = { + (PRUnichar)'%', + (PRUnichar)'s', + (PRUnichar)0, + }; + // convert aSD->data (UTF8) to Unicode and place the unicode data in mSelectionData.data + PRUnichar *unicodeString = nsTextFormatter::smprintf(unicodeFormatter, aSD->data); + + if (!unicodeString) // this would be bad wouldn't it? + return; + + int len = sizeof(unicodeString); + mSelectionData.data = g_new(guchar, len + 2); + memcpy(mSelectionData.data, + unicodeString, + len); + nsTextFormatter::smprintf_free(unicodeString); + mSelectionData.type = TARGET_TEXT_UNICODE; + mSelectionData.length = len; + } + break; + + case GDK_TARGET_STRING: case TARGET_TEXT_PLAIN: case TARGET_TEXT_XIF: case TARGET_TEXT_UNICODE: diff --git a/widget/src/gtk/nsFileWidget.cpp b/widget/src/gtk/nsFileWidget.cpp index aaec2fbfe9c..087cffa9f7e 100644 --- a/widget/src/gtk/nsFileWidget.cpp +++ b/widget/src/gtk/nsFileWidget.cpp @@ -78,6 +78,25 @@ nsFileWidget::~nsFileWidget() static void file_ok_clicked(GtkWidget *w, PRBool *ret) { g_print("user hit ok\n"); +#if 0 + struct stat buf; + + text = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(filesel))); + g_strstrip(text); + while ((text[strlen(text) - 1] == '/') && (strlen(text) != 1)) { + text[strlen(text) - 1] = '\0'; + } + if (stat(text, &buf) == 0) { + if (S_ISDIR(buf.st_mode)) { /* Selected directory -- don't close frequester */ + text2 = g_strdup_printf("%s/", text); + gtk_file_selection_set_filename(GTK_FILE_SELECTION(filesel), text2); + g_free(text2); + return PR_FALSE; + } + } + + g_free(text); +#endif *ret = PR_TRUE; gtk_main_quit(); } diff --git a/widget/src/gtk/nsWidget.cpp b/widget/src/gtk/nsWidget.cpp index 4999ab9724f..511812c7558 100644 --- a/widget/src/gtk/nsWidget.cpp +++ b/widget/src/gtk/nsWidget.cpp @@ -687,8 +687,8 @@ nsIFontMetrics *nsWidget::GetFont(void) //------------------------------------------------------------------------- NS_IMETHODIMP nsWidget::SetFont(const nsFont &aFont) { - nsIFontMetrics *fontMetrics; - mContext->GetMetricsFor(aFont, fontMetrics); + nsCOMPtr fontMetrics; + mContext->GetMetricsFor(aFont, *getter_AddRefs(fontMetrics)); if (!fontMetrics) return NS_ERROR_FAILURE; @@ -699,7 +699,6 @@ NS_IMETHODIMP nsWidget::SetFont(const nsFont &aFont) // FIXME avoid fontset problems.... if (((GdkFont*)fontHandle)->type == GDK_FONT_FONTSET) { g_print("nsWidget:SetFont - got a FontSet.. ignoring\n"); - NS_RELEASE(fontMetrics); return NS_ERROR_FAILURE; } @@ -707,8 +706,6 @@ NS_IMETHODIMP nsWidget::SetFont(const nsFont &aFont) SetFontNative((GdkFont *)fontHandle); } - NS_RELEASE(fontMetrics); - return NS_OK; } diff --git a/widget/src/gtk/nsWindow.cpp b/widget/src/gtk/nsWindow.cpp index 4114192c88d..0f373726612 100644 --- a/widget/src/gtk/nsWindow.cpp +++ b/widget/src/gtk/nsWindow.cpp @@ -530,8 +530,7 @@ nsWindow::DoPaint (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight, aX, aY, aWidth, aHeight); } #endif // NS_DEBUG - if (mEventCallback) - { + if (mEventCallback) { nsPaintEvent event; nsRect rect(aX, aY, aWidth, aHeight); @@ -547,19 +546,8 @@ nsWindow::DoPaint (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight, event.region = nsnull; event.renderingContext = GetRenderingContext(); - if (event.renderingContext) - { - PRBool rv; - - if (aClipRegion != nsnull) - event.renderingContext->SetClipRegion(NS_STATIC_CAST(const nsIRegion &, *aClipRegion), - nsClipCombine_kReplace, rv); - else - { - nsRect clipRect (aX, aY, aWidth, aHeight); - event.renderingContext->SetClipRect(clipRect, - nsClipCombine_kReplace, rv); - } + if (event.renderingContext) { + #ifdef NS_DEBUG if (WANT_PAINT_FLASHING) { @@ -601,28 +589,41 @@ NS_IMETHODIMP nsWindow::Update(void) UnqueueDraw(); if (!mUpdateArea->IsEmpty()) { - nsRegionRectSet *regionRectSet = nsnull; - if (NS_FAILED(mUpdateArea->GetRects(®ionRectSet))) - return NS_ERROR_FAILURE; + PRUint32 numRects; + mUpdateArea->GetNumRects(&numRects); - PRUint32 len; - PRUint32 i; + // if we have 1 or more than 10 rects, just paint the bounding box otherwise + // lets paint each rect by itself - len = regionRectSet->mRectsLen; + if (numRects != 1 && numRects < 10) { + nsRegionRectSet *regionRectSet = nsnull; - for (i=0;imRects[i]); - DoPaint (r->x, r->y, r->width, r->height, mUpdateArea); + if (NS_FAILED(mUpdateArea->GetRects(®ionRectSet))) + return NS_ERROR_FAILURE; + + PRUint32 len; + PRUint32 i; + + len = regionRectSet->mRectsLen; + + for (i=0;imRects[i]); + DoPaint (r->x, r->y, r->width, r->height, mUpdateArea); + } + + mUpdateArea->FreeRects(regionRectSet); + + mUpdateArea->SetTo(0, 0, 0, 0); + return NS_OK; + } else { + PRInt32 x, y, w, h; + mUpdateArea->GetBoundingBox(&x, &y, &w, &h); + DoPaint (x, y, w, h, mUpdateArea); + mUpdateArea->SetTo(0, 0, 0, 0); } - mUpdateArea->FreeRects(regionRectSet); - - mUpdateArea->SetTo(0, 0, 0, 0); - return NS_OK; - } - else { + } else { // g_print("nsWidget::Update(this=%p): avoided update of empty area\n", this); } @@ -636,9 +637,10 @@ NS_IMETHODIMP nsWindow::Update(void) if (children) { nsCOMPtr isupp; + nsCOMPtr child; while (NS_SUCCEEDED(children->CurrentItem(getter_AddRefs(isupp))) && isupp) { - nsCOMPtr child = do_QueryInterface(isupp); + child = do_QueryInterface(isupp); if (child) { child->Update(); @@ -682,9 +684,6 @@ NS_IMETHODIMP nsWindow::CaptureRollupEvents(nsIRollupListener * aListener, gdk_cursor_destroy(cursor); } } else { -#ifdef DEBUG_pavlov - printf("ungrabbing widget\n"); -#endif // make sure that the grab window is marked as released if (mGrabWindow == this) { mGrabWindow = NULL; @@ -734,7 +733,7 @@ NS_IMETHODIMP nsWindow::Invalidate(const nsRect &aRect, PRBool aIsSynchronous) if (!mSuperWin) return NS_OK; - + mUpdateArea->Union(aRect.x, aRect.y, aRect.width, aRect.height); if (aIsSynchronous) @@ -1869,19 +1868,19 @@ NS_IMETHODIMP nsWindow::SetTitle(const nsString& aTitle) nsAutoString charset(""); result = platform->GetCharset(kPlatformCharsetSel_WindowManager, charset); if (NS_SUCCEEDED(result) && (charset.Length() > 0)) { - NS_WITH_SERVICE(nsICharsetConverterManager, manager, - NS_CHARSETCONVERTERMANAGER_PROGID, &result); - if (manager && NS_SUCCEEDED(result)) { - result = manager->GetUnicodeEncoder(&charset, &converter); - if (NS_FAILED(result) && converter) { - NS_RELEASE(converter); - converter = nsnull; - } - else if (converter) { - result = converter->SetOutputErrorBehavior( - nsIUnicodeEncoder::kOnError_Replace, nsnull, '?'); - } - } + NS_WITH_SERVICE(nsICharsetConverterManager, manager, + NS_CHARSETCONVERTERMANAGER_PROGID, &result); + if (manager && NS_SUCCEEDED(result)) { + result = manager->GetUnicodeEncoder(&charset, &converter); + if (NS_FAILED(result) && converter) { + NS_RELEASE(converter); + converter = nsnull; + } + else if (converter) { + result = converter->SetOutputErrorBehavior( + nsIUnicodeEncoder::kOnError_Replace, nsnull, '?'); + } + } } } NS_ASSERTION(converter, "cannot get convert for window title"); @@ -1894,7 +1893,7 @@ NS_IMETHODIMP nsWindow::SetTitle(const nsString& aTitle) PRInt32 srcLen = aTitle.Length() + 1; PRInt32 destLen = sizeof(titleStr) - 1; result = converter->Convert(aTitle.GetUnicode(), &srcLen, titleStr, - &destLen); + &destLen); NS_ASSERTION(NS_SUCCEEDED(result), "cannot convert title string"); if (titleStr[0] && NS_SUCCEEDED(result)) { titleStr[destLen] = 0; @@ -2021,7 +2020,7 @@ NS_IMETHODIMP_(void) nsWindow::Notify(nsITimer* aTimer) if (event.rect->width == 0 || event.rect->height == 0) { - //printf("********\n****** got an expose for 0x0 window?? - ignoring paint for 0x0\n"); + // printf("********\n****** got an expose for 0x0 window?? - ignoring paint for 0x0\n"); NS_RELEASE(aTimer); mExposeTimer = nsnull; delete event.rect; @@ -2041,13 +2040,7 @@ NS_IMETHODIMP_(void) nsWindow::Notify(nsITimer* aTimer) #endif // NS_DEBUG event.renderingContext = GetRenderingContext(); - if (event.renderingContext) - { - PRBool rv; - - event.renderingContext->SetClipRegion(NS_STATIC_CAST(const nsIRegion &, *mUpdateArea), - nsClipCombine_kReplace, rv); - + if (event.renderingContext) { DispatchWindowEvent(&event); NS_RELEASE(event.renderingContext); // NS_RELEASE(mUpdateArea); @@ -2164,16 +2157,9 @@ PRBool nsWindow::OnDraw(nsPaintEvent &event) event.renderingContext = GetRenderingContext(); - if (event.renderingContext) - { - PRBool rv; - - event.renderingContext->SetClipRegion(NS_STATIC_CAST(const nsIRegion &, *mUpdateArea), - nsClipCombine_kReplace, rv); - + if (event.renderingContext) { result = DispatchWindowEvent(&event); NS_RELEASE(event.renderingContext); - // NS_RELEASE(mUpdateArea); } @@ -2266,6 +2252,13 @@ NS_IMETHODIMP nsWindow::Show(PRBool bState) this, bState, mWindowType); #endif + + /* bug #8002 -- this has weird side effects like causing the window to come to the front whenever you mouse over it. + + if (GTK_WIDGET_VISIBLE(mShell) && GTK_WIDGET_REALIZED(mShell) && mShell->window) + gdk_window_raise(mShell->window); + */ + gtk_widget_show(mMozArea); gtk_widget_show(mShell); } @@ -2340,7 +2333,7 @@ NS_IMETHODIMP nsWindow::Move(PRInt32 aX, PRInt32 aY) { // XXX don't move the window if it is toplevel window.. this keeps us from moving the // window's title bar off the screen in some Window managers - if (mWindowType != eWindowType_toplevel) + // if (mWindowType != eWindowType_toplevel) gtk_widget_set_uposition(mShell, aX, aY); } else