Various improvements in win32 window management

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@21000 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2005-03-29 14:03:30 +00:00
parent 337e25e1ab
commit 584e797dc9
3 changed files with 88 additions and 14 deletions

View file

@ -4,6 +4,12 @@
* Source/x11/XGDragView.m: Rewrite to be a subclass of GSDragView
so that bugfixes from it are in XGDragView. Remove lots of
redundant code. Still quite a bit to do.
* Source/win32/WIN32Server.m: Add code to draw own window decorations
and GSWIN32HandlesWindowDecorations user default to turn it off.
Fixed code for detecting window at a screen point to ignore invisible
windows (fixes crash in DnD).
Altered window type to 'tool' for borderless windows, so that we don't
get a button in the taskbar for every window we create.
2005-03-29 Adrian Robert <arobert@cogsci.ucsd.edu>

View file

@ -30,6 +30,7 @@
#include <Foundation/NSRunLoop.h>
#include <Foundation/NSTimer.h>
#include <Foundation/NSUserDefaults.h>
#include <Foundation/NSException.h>
#include <AppKit/AppKitExceptions.h>
#include <AppKit/NSApplication.h>
#include <AppKit/NSGraphics.h>
@ -48,6 +49,9 @@
#include <sys/file.h>
#endif
static BOOL handlesWindowDecorations = NO;
static void
validateWindow(HWND hwnd, RECT rect);
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg,
@ -58,7 +62,15 @@ LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg,
/* Initialize AppKit backend */
+ (void)initializeBackend
{
NSUserDefaults *defs;
NSDebugLog(@"Initializing GNUstep win32 backend.\n");
defs = [NSUserDefaults standardUserDefaults];
if ([defs objectForKey: @"GSWIN32HandlesWindowDecorations"])
{
handlesWindowDecorations =
[defs boolForKey: @"GSWINHandlesWindowDecorations"];
}
[GSDisplayServer setDefaultServerClass: [WIN32Server class]];
}
@ -187,7 +199,7 @@ LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg,
if ((int)hwnd == win)
{
/*
* If the winodw at the point we want is excluded,
* If the window at the point we want is excluded,
* we must look through ALL windows at a lower level
* until we find one which contains the same point.
*/
@ -197,7 +209,7 @@ LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg,
hwnd = GetWindow(hwnd, GW_HWNDNEXT);
GetWindowRect(hwnd, &r);
if (PtInRect(&r, p))
if (PtInRect(&r, p) && IsWindowVisible(hwnd))
{
break;
}
@ -338,12 +350,30 @@ DWORD windowStyleForGSStyle(unsigned int style)
@implementation WIN32Server (WindowOps)
-(BOOL) handlesWindowDecorations
{
return handlesWindowDecorations;
}
- (int) window: (NSRect)frame : (NSBackingStoreType)type : (unsigned int)style
: (int) screen
{
HWND hwnd;
RECT r;
DWORD wstyle = windowStyleForGSStyle(style);
DWORD wstyle;
DWORD estyle;
if (handlesWindowDecorations)
{
wstyle = windowStyleForGSStyle(style);
estyle = (style == 0 ? WS_EX_TOOLWINDOW : 0);
}
else
{
wstyle = WS_POPUP;
estyle = WS_EX_TOOLWINDOW;
}
r = GSScreenRectToMS(frame, style, self);
@ -351,7 +381,7 @@ DWORD windowStyleForGSStyle(unsigned int style)
type, style, screen);
NSDebugLLog(@"WTrace", @" device frame: %d, %d, %d, %d",
r.left, r.top, r.right - r.left, r.bottom - r.top);
hwnd = CreateWindowEx(0,
hwnd = CreateWindowEx(estyle,
"GNUstepWindowClass",
"GNUstepWindow",
wstyle,
@ -379,6 +409,9 @@ DWORD windowStyleForGSStyle(unsigned int style)
{
DWORD wstyle = windowStyleForGSStyle(style);
NSAssert(handlesWindowDecorations,
@"-stylewindow:: called when handlesWindowDecorations==NO");
NSDebugLLog(@"WTrace", @"stylewindow: %d : %d", style, winNum);
SetWindowLong((HWND)winNum, GWL_STYLE, wstyle);
}
@ -638,17 +671,28 @@ DWORD windowStyleForGSStyle(unsigned int style)
- (void) styleoffsets: (float *) l : (float *) r : (float *) t : (float *) b
: (unsigned int) style
{
DWORD wstyle = windowStyleForGSStyle(style);
RECT rect = {100, 100, 200, 200};
AdjustWindowRectEx(&rect, wstyle, NO, 0);
if (handlesWindowDecorations)
{
DWORD wstyle = windowStyleForGSStyle(style);
RECT rect = {100, 100, 200, 200};
AdjustWindowRectEx(&rect, wstyle, NO, 0);
*l = 100 - rect.left;
*r = rect.right - 200;
*t = 100 - rect.top;
*b = rect.bottom - 200;
//NSLog(@"Sytle %d offset %f %f %f %f", wstyle, *l, *r, *t, *b);
*l = 100 - rect.left;
*r = rect.right - 200;
*t = 100 - rect.top;
*b = rect.bottom - 200;
//NSLog(@"Style %d offset %f %f %f %f", wstyle, *l, *r, *t, *b);
}
else
{
/*
If we don't handle decorations, all our windows are going to be
border- and decorationless. In that case, -gui won't call this method,
but we still use it internally.
*/
*l = *r = *t = *b = 0.0;
}
}
- (void) docedited: (int) edited : (int) winNum
@ -657,6 +701,10 @@ DWORD windowStyleForGSStyle(unsigned int style)
- (void) setinputstate: (int)state : (int)winNum
{
if (handlesWindowDecorations == NO)
{
return;
}
if (state == GSTitleBarKey)
{
SetActiveWindow((HWND)winNum);

View file

@ -180,6 +180,25 @@ RECT GSViewRectToWin(WIN32GState *s, NSRect r)
wscolor = RGB(color.field[0]*255, color.field[1]*255, color.field[2]*255);
}
static inline
RECT GSXWindowRectToMS(WIN32GState *s, NSRect r)
{
RECT r1;
int h;
h = WindowHeight([s window]);
// r.origin.x += s->offset.x;
// r.origin.y += s->offset.y;
r1.left = r.origin.x;
r1.right = r.origin.x + r.size.width;
r1.bottom = h - r.origin.y;
r1.top = h - r.origin.y - r.size.height;
return r1;
}
- (void) _compositeGState: (WIN32GState *) source
fromRect: (NSRect) sourceRect
toPoint: (NSPoint) destPoint
@ -200,6 +219,7 @@ RECT GSViewRectToWin(WIN32GState *s, NSRect r)
NSStringFromRect(sourceRect), NSStringFromPoint(destPoint), op);
rectFrom = GSViewRectToWin(source, sourceRect);
//rectFrom = GSXWindowRectToMS(sourceRect);
h = rectFrom.bottom - rectFrom.top;
destRect.size = sourceRect.size;