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,6 +589,14 @@ NS_IMETHODIMP nsWindow::Update(void)
UnqueueDraw(); UnqueueDraw();
if (!mUpdateArea->IsEmpty()) { if (!mUpdateArea->IsEmpty()) {
PRUint32 numRects;
mUpdateArea->GetNumRects(&numRects);
// if we have 1 or more than 10 rects, just paint the bounding box otherwise
// lets paint each rect by itself
if (numRects != 1 && numRects < 10) {
nsRegionRectSet *regionRectSet = nsnull; nsRegionRectSet *regionRectSet = nsnull;
if (NS_FAILED(mUpdateArea->GetRects(&regionRectSet))) if (NS_FAILED(mUpdateArea->GetRects(&regionRectSet)))
@ -611,8 +607,7 @@ NS_IMETHODIMP nsWindow::Update(void)
len = regionRectSet->mRectsLen; len = regionRectSet->mRectsLen;
for (i=0;i<len;++i) for (i=0;i<len;++i) {
{
nsRegionRect *r = &(regionRectSet->mRects[i]); nsRegionRect *r = &(regionRectSet->mRects[i]);
DoPaint (r->x, r->y, r->width, r->height, mUpdateArea); DoPaint (r->x, r->y, r->width, r->height, mUpdateArea);
} }
@ -621,8 +616,14 @@ NS_IMETHODIMP nsWindow::Update(void)
mUpdateArea->SetTo(0, 0, 0, 0); mUpdateArea->SetTo(0, 0, 0, 0);
return NS_OK; 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);
} }
else {
} 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;
@ -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