convert UTF8_STRING to unicode in the clipboard. add some nsCOMPtr goodness. remove code cruft. only draw each part of the updated region if there are less than 10 rects making up the region. fix not being able to move windows to where you want them (bug 17703). r=bryner@uiuc.edu

This commit is contained in:
pavlov%netscape.com 2000-02-07 03:43:42 +00:00
Родитель a77bec64b2
Коммит 6e1f084bb4
4 изменённых файлов: 108 добавлений и 73 удалений

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

@ -37,6 +37,7 @@
#include "nsXPIDLString.h" #include "nsXPIDLString.h"
#include "nsPrimitiveHelpers.h" #include "nsPrimitiveHelpers.h"
#include "nsTextFormatter.h"
#include "nsVoidArray.h" #include "nsVoidArray.h"
@ -665,8 +666,33 @@ nsClipboard::SelectionReceiver (GtkWidget *aWidget,
switch (type) switch (type)
{ {
case GDK_TARGET_STRING:
case TARGET_UTF8: 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_PLAIN:
case TARGET_TEXT_XIF: case TARGET_TEXT_XIF:
case TARGET_TEXT_UNICODE: case TARGET_TEXT_UNICODE:

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

@ -78,6 +78,25 @@ nsFileWidget::~nsFileWidget()
static void file_ok_clicked(GtkWidget *w, PRBool *ret) static void file_ok_clicked(GtkWidget *w, PRBool *ret)
{ {
g_print("user hit ok\n"); 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; *ret = PR_TRUE;
gtk_main_quit(); gtk_main_quit();
} }

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

@ -687,8 +687,8 @@ nsIFontMetrics *nsWidget::GetFont(void)
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
NS_IMETHODIMP nsWidget::SetFont(const nsFont &aFont) NS_IMETHODIMP nsWidget::SetFont(const nsFont &aFont)
{ {
nsIFontMetrics *fontMetrics; nsCOMPtr<nsIFontMetrics> fontMetrics;
mContext->GetMetricsFor(aFont, fontMetrics); mContext->GetMetricsFor(aFont, *getter_AddRefs(fontMetrics));
if (!fontMetrics) if (!fontMetrics)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
@ -699,7 +699,6 @@ NS_IMETHODIMP nsWidget::SetFont(const nsFont &aFont)
// FIXME avoid fontset problems.... // FIXME avoid fontset problems....
if (((GdkFont*)fontHandle)->type == GDK_FONT_FONTSET) { if (((GdkFont*)fontHandle)->type == GDK_FONT_FONTSET) {
g_print("nsWidget:SetFont - got a FontSet.. ignoring\n"); g_print("nsWidget:SetFont - got a FontSet.. ignoring\n");
NS_RELEASE(fontMetrics);
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
@ -707,8 +706,6 @@ NS_IMETHODIMP nsWidget::SetFont(const nsFont &aFont)
SetFontNative((GdkFont *)fontHandle); SetFontNative((GdkFont *)fontHandle);
} }
NS_RELEASE(fontMetrics);
return NS_OK; return NS_OK;
} }

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

@ -530,8 +530,7 @@ nsWindow::DoPaint (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight,
aX, aY, aWidth, aHeight); aX, aY, aWidth, aHeight);
} }
#endif // NS_DEBUG #endif // NS_DEBUG
if (mEventCallback) if (mEventCallback) {
{
nsPaintEvent event; nsPaintEvent event;
nsRect rect(aX, aY, aWidth, aHeight); nsRect rect(aX, aY, aWidth, aHeight);
@ -547,19 +546,8 @@ nsWindow::DoPaint (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight,
event.region = nsnull; event.region = nsnull;
event.renderingContext = GetRenderingContext(); event.renderingContext = GetRenderingContext();
if (event.renderingContext) 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);
}
#ifdef NS_DEBUG #ifdef NS_DEBUG
if (WANT_PAINT_FLASHING) if (WANT_PAINT_FLASHING)
{ {
@ -601,28 +589,41 @@ NS_IMETHODIMP nsWindow::Update(void)
UnqueueDraw(); UnqueueDraw();
if (!mUpdateArea->IsEmpty()) { if (!mUpdateArea->IsEmpty()) {
nsRegionRectSet *regionRectSet = nsnull;
if (NS_FAILED(mUpdateArea->GetRects(&regionRectSet))) PRUint32 numRects;
return NS_ERROR_FAILURE; mUpdateArea->GetNumRects(&numRects);
PRUint32 len; // if we have 1 or more than 10 rects, just paint the bounding box otherwise
PRUint32 i; // lets paint each rect by itself
len = regionRectSet->mRectsLen; if (numRects != 1 && numRects < 10) {
nsRegionRectSet *regionRectSet = nsnull;
for (i=0;i<len;++i) if (NS_FAILED(mUpdateArea->GetRects(&regionRectSet)))
{ return NS_ERROR_FAILURE;
nsRegionRect *r = &(regionRectSet->mRects[i]);
DoPaint (r->x, r->y, r->width, r->height, mUpdateArea); PRUint32 len;
PRUint32 i;
len = regionRectSet->mRectsLen;
for (i=0;i<len;++i) {
nsRegionRect *r = &(regionRectSet->mRects[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); } else {
mUpdateArea->SetTo(0, 0, 0, 0);
return NS_OK;
}
else {
// g_print("nsWidget::Update(this=%p): avoided update of empty area\n", this); // g_print("nsWidget::Update(this=%p): avoided update of empty area\n", this);
} }
@ -636,9 +637,10 @@ NS_IMETHODIMP nsWindow::Update(void)
if (children) { if (children) {
nsCOMPtr<nsISupports> isupp; nsCOMPtr<nsISupports> isupp;
nsCOMPtr<nsIWidget> child;
while (NS_SUCCEEDED(children->CurrentItem(getter_AddRefs(isupp))) && isupp) { while (NS_SUCCEEDED(children->CurrentItem(getter_AddRefs(isupp))) && isupp) {
nsCOMPtr<nsIWidget> child = do_QueryInterface(isupp); child = do_QueryInterface(isupp);
if (child) { if (child) {
child->Update(); child->Update();
@ -682,9 +684,6 @@ NS_IMETHODIMP nsWindow::CaptureRollupEvents(nsIRollupListener * aListener,
gdk_cursor_destroy(cursor); gdk_cursor_destroy(cursor);
} }
} else { } else {
#ifdef DEBUG_pavlov
printf("ungrabbing widget\n");
#endif
// make sure that the grab window is marked as released // make sure that the grab window is marked as released
if (mGrabWindow == this) { if (mGrabWindow == this) {
mGrabWindow = NULL; mGrabWindow = NULL;
@ -734,7 +733,7 @@ NS_IMETHODIMP nsWindow::Invalidate(const nsRect &aRect, PRBool aIsSynchronous)
if (!mSuperWin) if (!mSuperWin)
return NS_OK; return NS_OK;
mUpdateArea->Union(aRect.x, aRect.y, aRect.width, aRect.height); mUpdateArea->Union(aRect.x, aRect.y, aRect.width, aRect.height);
if (aIsSynchronous) if (aIsSynchronous)
@ -1869,19 +1868,19 @@ NS_IMETHODIMP nsWindow::SetTitle(const nsString& aTitle)
nsAutoString charset(""); nsAutoString charset("");
result = platform->GetCharset(kPlatformCharsetSel_WindowManager, charset); result = platform->GetCharset(kPlatformCharsetSel_WindowManager, charset);
if (NS_SUCCEEDED(result) && (charset.Length() > 0)) { if (NS_SUCCEEDED(result) && (charset.Length() > 0)) {
NS_WITH_SERVICE(nsICharsetConverterManager, manager, NS_WITH_SERVICE(nsICharsetConverterManager, manager,
NS_CHARSETCONVERTERMANAGER_PROGID, &result); NS_CHARSETCONVERTERMANAGER_PROGID, &result);
if (manager && NS_SUCCEEDED(result)) { if (manager && NS_SUCCEEDED(result)) {
result = manager->GetUnicodeEncoder(&charset, &converter); result = manager->GetUnicodeEncoder(&charset, &converter);
if (NS_FAILED(result) && converter) { if (NS_FAILED(result) && converter) {
NS_RELEASE(converter); NS_RELEASE(converter);
converter = nsnull; converter = nsnull;
} }
else if (converter) { else if (converter) {
result = converter->SetOutputErrorBehavior( result = converter->SetOutputErrorBehavior(
nsIUnicodeEncoder::kOnError_Replace, nsnull, '?'); nsIUnicodeEncoder::kOnError_Replace, nsnull, '?');
} }
} }
} }
} }
NS_ASSERTION(converter, "cannot get convert for window title"); 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 srcLen = aTitle.Length() + 1;
PRInt32 destLen = sizeof(titleStr) - 1; PRInt32 destLen = sizeof(titleStr) - 1;
result = converter->Convert(aTitle.GetUnicode(), &srcLen, titleStr, result = converter->Convert(aTitle.GetUnicode(), &srcLen, titleStr,
&destLen); &destLen);
NS_ASSERTION(NS_SUCCEEDED(result), "cannot convert title string"); NS_ASSERTION(NS_SUCCEEDED(result), "cannot convert title string");
if (titleStr[0] && NS_SUCCEEDED(result)) { if (titleStr[0] && NS_SUCCEEDED(result)) {
titleStr[destLen] = 0; titleStr[destLen] = 0;
@ -2021,7 +2020,7 @@ NS_IMETHODIMP_(void) nsWindow::Notify(nsITimer* aTimer)
if (event.rect->width == 0 || event.rect->height == 0) 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); NS_RELEASE(aTimer);
mExposeTimer = nsnull; mExposeTimer = nsnull;
delete event.rect; delete event.rect;
@ -2041,13 +2040,7 @@ NS_IMETHODIMP_(void) nsWindow::Notify(nsITimer* aTimer)
#endif // NS_DEBUG #endif // NS_DEBUG
event.renderingContext = GetRenderingContext(); event.renderingContext = GetRenderingContext();
if (event.renderingContext) if (event.renderingContext) {
{
PRBool rv;
event.renderingContext->SetClipRegion(NS_STATIC_CAST(const nsIRegion &, *mUpdateArea),
nsClipCombine_kReplace, rv);
DispatchWindowEvent(&event); DispatchWindowEvent(&event);
NS_RELEASE(event.renderingContext); NS_RELEASE(event.renderingContext);
// NS_RELEASE(mUpdateArea); // NS_RELEASE(mUpdateArea);
@ -2164,16 +2157,9 @@ PRBool nsWindow::OnDraw(nsPaintEvent &event)
event.renderingContext = GetRenderingContext(); event.renderingContext = GetRenderingContext();
if (event.renderingContext) if (event.renderingContext) {
{
PRBool rv;
event.renderingContext->SetClipRegion(NS_STATIC_CAST(const nsIRegion &, *mUpdateArea),
nsClipCombine_kReplace, rv);
result = DispatchWindowEvent(&event); result = DispatchWindowEvent(&event);
NS_RELEASE(event.renderingContext); NS_RELEASE(event.renderingContext);
// NS_RELEASE(mUpdateArea);
} }
@ -2266,6 +2252,13 @@ NS_IMETHODIMP nsWindow::Show(PRBool bState)
this, this,
bState, mWindowType); bState, mWindowType);
#endif #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(mMozArea);
gtk_widget_show(mShell); 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 // 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 // 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); gtk_widget_set_uposition(mShell, aX, aY);
} }
else else