Free only resources alloceted by our code

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@13548 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2002-04-27 10:12:58 +00:00
parent d1be1c2b09
commit ab1582b112
3 changed files with 59 additions and 37 deletions

View file

@ -39,6 +39,7 @@
typedef struct _win_intern { typedef struct _win_intern {
BOOL useHDC; BOOL useHDC;
HDC hdc; HDC hdc;
HGDIOBJ old;
MINMAXINFO minmax; MINMAXINFO minmax;
} WIN_INTERN; } WIN_INTERN;

View file

@ -39,6 +39,9 @@
float lineWidth; float lineWidth;
float miterlimit; float miterlimit;
HRGN clipRegion; HRGN clipRegion;
HGDIOBJ oldBrush;
HGDIOBJ oldPen;
} }
- (void) setWindow: (HWND)number; - (void) setWindow: (HWND)number;

View file

@ -317,25 +317,29 @@ DWORD windowStyleForGSStyle(int style)
if (win->useHDC) if (win->useHDC)
{ {
HGDIOBJ old;
old = SelectObject(win->hdc, win->old);
DeleteObject(old);
DeleteDC(win->hdc); DeleteDC(win->hdc);
win->hdc = NULL; win->hdc = NULL;
win->old = NULL;
win->useHDC = NO;
} }
if (type == NSBackingStoreBuffered) if (type == NSBackingStoreBuffered)
{ {
HDC hdc, hdc2; HDC hdc, hdc2;
HBITMAP hbitmap; HBITMAP hbitmap;
HGDIOBJ old;
RECT r; RECT r;
GetClientRect((HWND)winNum, &r); GetClientRect((HWND)winNum, &r);
hdc = GetDC((HWND)winNum); hdc = GetDC((HWND)winNum);
hdc2 = CreateCompatibleDC(hdc); hdc2 = CreateCompatibleDC(hdc);
hbitmap = CreateCompatibleBitmap(hdc, r.right - r.left, r.bottom - r.top); hbitmap = CreateCompatibleBitmap(hdc, r.right - r.left, r.bottom - r.top);
old = SelectObject(hdc2, hbitmap); win->old = SelectObject(hdc2, hbitmap);
DeleteObject(old);
win->hdc = hdc2; win->hdc = hdc2;
win->useHDC = YES;
ReleaseDC((HWND)winNum, hdc); ReleaseDC((HWND)winNum, hdc);
} }
@ -412,14 +416,40 @@ DWORD windowStyleForGSStyle(int style)
- (void) placewindow: (NSRect)frame : (int) winNum - (void) placewindow: (NSRect)frame : (int) winNum
{ {
RECT r; RECT r;
RECT r2;
WIN_INTERN *win = (WIN_INTERN *)GetWindowLong((HWND)winNum, GWL_USERDATA);
r = GSScreenRectToMS(frame); r = GSScreenRectToMS(frame);
GetWindowRect((HWND)winNum, &r2);
//NSLog(@"Placing at %d, %d, %d, %d", r.left, r.top, r.right - r.left, r.bottom - r.top); //NSLog(@"Placing at %d, %d, %d, %d", r.left, r.top, r.right - r.left, r.bottom - r.top);
SetWindowPos((HWND)winNum, NULL, r.left, r.top, r.right - r.left, r.bottom - r.top, SetWindowPos((HWND)winNum, NULL, r.left, r.top, r.right - r.left, r.bottom - r.top,
SWP_NOZORDER | SWP_NOREDRAW); SWP_NOZORDER | SWP_NOREDRAW);
if ((win->useHDC) &&
(r.right - r.left != r2.right - r2.left) &&
(r.bottom - r.top != r2.bottom - r2.top))
{
HDC hdc, hdc2;
HBITMAP hbitmap;
HGDIOBJ old;
//NSLog(@"Change backing store to %d %d", r.right - r.left, r.bottom - r.top);
old = SelectObject(win->hdc, win->old);
DeleteObject(old);
DeleteDC(win->hdc);
win->hdc = NULL;
win->old = NULL;
GetClientRect((HWND)winNum, &r);
hdc = GetDC((HWND)winNum);
hdc2 = CreateCompatibleDC(hdc);
hbitmap = CreateCompatibleBitmap(hdc, r.right - r.left, r.bottom - r.top);
win->old = SelectObject(hdc2, hbitmap);
win->hdc = hdc2;
ReleaseDC((HWND)winNum, hdc);
}
} }
- (BOOL) findwindow: (NSPoint)loc : (int) op : (int) otherWin - (BOOL) findwindow: (NSPoint)loc : (int) op : (int) otherWin
@ -543,7 +573,7 @@ DWORD windowStyleForGSStyle(int style)
return MSScreenPointToGS(p.x, p.y); return MSScreenPointToGS(p.x, p.y);
} }
- (NSPoint) mouseLocationOnScreen: (int)screen window: (void *)win - (NSPoint) mouseLocationOnScreen: (int)screen window: (int *)win
{ {
return [self mouselocation]; return [self mouselocation];
} }
@ -994,8 +1024,8 @@ invalidateWindow(HWND hwnd, RECT rect)
NSRect r = MSWindowRectToGS((HWND)hwnd, rect); NSRect r = MSWindowRectToGS((HWND)hwnd, rect);
/* /*
NSLog(@"INvalidated window %d %@", hwnd, NSLog(@"Invalidated window %d %@ (%d, %d, %d, %d)", hwnd,
NSStringFromRect(MSWindowRectToGS((HWND)hwnd, rect))); NSStringFromRect(r), rect.left, rect.top, rect.right, rect.bottom);
*/ */
// Repaint the window's client area. // Repaint the window's client area.
[[window contentView] setNeedsDisplayInRect: r]; [[window contentView] setNeedsDisplayInRect: r];
@ -1095,15 +1125,13 @@ LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg,
HDC hdc, hdc2; HDC hdc, hdc2;
HBITMAP hbitmap; HBITMAP hbitmap;
RECT r; RECT r;
HGDIOBJ old;
GetClientRect((HWND)hwnd, &r); GetClientRect((HWND)hwnd, &r);
hdc = GetDC(hwnd); hdc = GetDC(hwnd);
hdc2 = CreateCompatibleDC(hdc); hdc2 = CreateCompatibleDC(hdc);
hbitmap = CreateCompatibleBitmap(hdc, r.right - r.left, hbitmap = CreateCompatibleBitmap(hdc, r.right - r.left,
r.bottom - r.top); r.bottom - r.top);
old = SelectObject(hdc2, hbitmap); win->old = SelectObject(hdc2, hbitmap);
DeleteObject(old);
win->hdc = hdc2; win->hdc = hdc2;
win->useHDC = YES; win->useHDC = YES;
@ -1124,25 +1152,8 @@ LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg,
//NSLog(@"Got Message %s for %d", "WINDOWPOSCHANGED", hwnd); //NSLog(@"Got Message %s for %d", "WINDOWPOSCHANGED", hwnd);
break; break;
case WM_MOVE: case WM_MOVE:
{
NSPoint eventLocation = NSMakePoint(0,0);
int xPos = (int)(short) LOWORD(lParam);
int yPos = (int)(short) HIWORD(lParam);
NSPoint p;
p = MSWindowOriginToGS(hwnd, xPos, yPos);
//NSLog(@"Got Message %s for %d to %f, %f", "MOVE", hwnd, p.x, p.y); //NSLog(@"Got Message %s for %d to %f, %f", "MOVE", hwnd, p.x, p.y);
ev = [NSEvent otherEventWithType: NSAppKitDefined
location: eventLocation
modifierFlags: 0
timestamp: 0
windowNumber: (int)hwnd
context: GSCurrentContext()
subtype: GSAppKitWindowMoved
data1: p.x
data2: p.y];
break; break;
}
case WM_MOVING: case WM_MOVING:
//NSLog(@"Got Message %s for %d", "MOVING", hwnd); //NSLog(@"Got Message %s for %d", "MOVING", hwnd);
break; break;
@ -1162,24 +1173,25 @@ LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg,
RECT r; RECT r;
WIN_INTERN *win = (WIN_INTERN *)GetWindowLong((HWND)hwnd, GWL_USERDATA); WIN_INTERN *win = (WIN_INTERN *)GetWindowLong((HWND)hwnd, GWL_USERDATA);
// FIXME: We should check if the size really did change. And this should // FIXME: We should check if the size really did change.
// be called on program size changes as well!
if (win->useHDC) if (win->useHDC)
{ {
HDC hdc, hdc2; HDC hdc, hdc2;
HBITMAP hbitmap; HBITMAP hbitmap;
HGDIOBJ old; HGDIOBJ old;
old = SelectObject(win->hdc, win->old);
DeleteObject(old);
DeleteDC(win->hdc); DeleteDC(win->hdc);
win->hdc = NULL; win->hdc = NULL;
win->old = NULL;
GetClientRect((HWND)hwnd, &r); GetClientRect((HWND)hwnd, &r);
//NSLog(@"Change backing store to %d %d", r.right - r.left, r.bottom - r.top);
hdc = GetDC((HWND)hwnd); hdc = GetDC((HWND)hwnd);
hdc2 = CreateCompatibleDC(hdc); hdc2 = CreateCompatibleDC(hdc);
hbitmap = CreateCompatibleBitmap(hdc, r.right - r.left, r.bottom - r.top); hbitmap = CreateCompatibleBitmap(hdc, r.right - r.left, r.bottom - r.top);
old = SelectObject(hdc2, hbitmap); win->old = SelectObject(hdc2, hbitmap);
DeleteObject(old);
//NSLog(@"Change backing store to %d %d", r.right - r.left, r.bottom - r.top);
win->hdc = hdc2; win->hdc = hdc2;
ReleaseDC((HWND)hwnd, hdc); ReleaseDC((HWND)hwnd, hdc);
@ -1319,7 +1331,13 @@ LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg,
//NSLog(@"Got Message %s for %d", "DESTROY", hwnd); //NSLog(@"Got Message %s for %d", "DESTROY", hwnd);
if (win->useHDC) if (win->useHDC)
{
HGDIOBJ old;
old = SelectObject(win->hdc, win->old);
DeleteObject(old);
DeleteDC(win->hdc); DeleteDC(win->hdc);
}
objc_free(win); objc_free(win);
break; break;
} }