add live-resizing for macosx. expose update/resize in the event handler to avoid having to hack up EventRecords to fake events. r=saari/sr=smfr/a=asa.

This commit is contained in:
pinkerton%netscape.com 2001-06-01 23:38:27 +00:00
parent cfda3d57fd
commit ff47c898f8
4 changed files with 86 additions and 13 deletions

View File

@ -421,7 +421,7 @@ PRBool nsMacEventHandler::HandleOSEvent ( EventRecord& aOSEvent )
break;
case updateEvt:
retVal = HandleUpdateEvent(aOSEvent);
retVal = UpdateEvent();
break;
case mouseDown:
@ -1180,10 +1180,10 @@ if (KeyDown(0x39)) // press [caps lock] to start the profile
//-------------------------------------------------------------------------
//
// HandleUpdateEvent
// UpdateEvent
//
//-------------------------------------------------------------------------
PRBool nsMacEventHandler::HandleUpdateEvent(EventRecord& aOSEvent)
PRBool nsMacEventHandler::UpdateEvent ( )
{
mTopLevelWidget->HandleUpdateEvent(nil);
@ -1191,6 +1191,25 @@ PRBool nsMacEventHandler::HandleUpdateEvent(EventRecord& aOSEvent)
}
//-------------------------------------------------------------------------
//
// ResizeEvent
//
//-------------------------------------------------------------------------
PRBool nsMacEventHandler::ResizeEvent ( WindowRef inWindow )
{
Rect macRect;
::GetWindowPortBounds ( inWindow, &macRect );
::LocalToGlobal(&topLeft(macRect));
::LocalToGlobal(&botRight(macRect));
mTopLevelWidget->Resize(macRect.right - macRect.left + 1, macRect.bottom - macRect.top + 1, PR_FALSE);
if (nsnull != gRollupListener && (nsnull != gRollupWidget) )
gRollupListener->Rollup();
return PR_TRUE;
}
//-------------------------------------------------------------------------
//
// HandleMouseDownEvent
@ -1262,15 +1281,8 @@ PRBool nsMacEventHandler::HandleMouseDownEvent(EventRecord& aOSEvent)
case inGrow:
{
Rect macRect;
::GetWindowPortBounds ( whichWindow, &macRect );
::LocalToGlobal(&topLeft(macRect));
::LocalToGlobal(&botRight(macRect));
mTopLevelWidget->Resize(macRect.right - macRect.left + 1, macRect.bottom - macRect.top + 1, PR_FALSE);
if (nsnull != gRollupListener && (nsnull != gRollupWidget) ) {
gRollupListener->Rollup();
}
break;
ResizeEvent ( whichWindow );
break;
}
case inGoAway:

View File

@ -126,6 +126,13 @@ public:
virtual nsresult HandleUpdateInputArea(char* text,Size text_size, ScriptCode textScript,long fixedLength,TextRangeArray* textRangeArray);
virtual nsresult ResetInputState();
//
// Synthetic events, generated internally to do things at specific times and
// not have to rely on hacking up EventRecords to fake it.
//
virtual PRBool UpdateEvent ( ) ;
virtual PRBool ResizeEvent ( WindowRef inWindow ) ;
protected:
#if 1
virtual void InitializeKeyEvent(nsKeyEvent& aKeyEvent, EventRecord& aOSEvent, nsWindow* focusedWidget, PRUint32 message);
@ -134,7 +141,6 @@ protected:
#endif
virtual PRBool HandleKeyEvent(EventRecord& aOSEvent);
virtual PRBool HandleActivateEvent(EventRecord& aOSEvent);
virtual PRBool HandleUpdateEvent(EventRecord& aOSEvent);
virtual PRBool HandleMouseDownEvent(EventRecord& aOSEvent);
virtual PRBool HandleMouseUpEvent(EventRecord& aOSEvent);
virtual PRBool HandleMouseMoveEvent(EventRecord& aOSEvent);

View File

@ -540,6 +540,18 @@ nsresult nsMacWindow::StandardCreate(nsIWidget *aParent,
// XXX support it.
if ( mWindowType == eWindowType_popup )
::SetWindowClass(mWindowPtr, kModalWindowClass);
// Setup the live window resizing
if ( mWindowType == eWindowType_toplevel ) {
const UInt32 kWindowLiveResizeAttribute = (1L << 28); // BAD!!! our headers don't yet support this
::ChangeWindowAttributes ( mWindowPtr, kWindowLiveResizeAttribute, kWindowNoAttributes );
EventTypeSpec windEventList[] = { {kEventClassWindow, kEventWindowBoundsChanged} };
OSStatus err = ::InstallWindowEventHandler ( mWindowPtr, NewEventHandlerUPP(WindowEventHandler), 1, windEventList, this, NULL );
// note, passing NULL as the final param to IWEH() causes the UPP to be disposed automatically
// when the event target (the window) goes away. See CarbonEvents.h for info.
NS_ASSERTION(err == noErr, "Couldn't install Carbon Event handler");
}
#endif
// create a phantom scrollbar to catch the attention of mousewheel
@ -578,6 +590,44 @@ nsresult nsMacWindow::StandardCreate(nsIWidget *aParent,
return NS_OK;
}
#if TARGET_CARBON
pascal OSStatus
nsMacWindow :: WindowEventHandler ( EventHandlerCallRef inHandlerChain, EventRef inEvent, void* userData )
{
WindowRef myWind = NULL;
::GetEventParameter ( inEvent, kEventParamDirectObject, typeWindowRef, NULL, sizeof(myWind), NULL, &myWind );
if ( myWind ) {
UInt32 what = ::GetEventKind ( inEvent );
switch ( what ) {
case kEventWindowBoundsChanged:
Rect bounds;
::InvalWindowRect(myWind, ::GetWindowPortBounds(myWind, &bounds));
// resize the window and repaint
nsMacWindow* self = NS_REINTERPRET_CAST(nsMacWindow*, userData);
if ( self ) {
self->mMacEventHandler->ResizeEvent(myWind);
self->mMacEventHandler->UpdateEvent();
}
break;
default:
// do nothing...
break;
} // case of which event?
}
return noErr;
} // WindowEventHandler
#endif
//-------------------------------------------------------------------------
//
// Create a nsMacWindow using a native window provided by the application

View File

@ -122,6 +122,11 @@ protected:
DragTrackingHandlerUPP mDragTrackingHandlerUPP;
DragReceiveHandlerUPP mDragReceiveHandlerUPP;
#if TARGET_CARBON
pascal static OSStatus WindowEventHandler ( EventHandlerCallRef inHandlerChain,
EventRef inEvent, void* userData ) ;
#endif
PRBool mWindowMadeHere; // true if we created the window
PRBool mIsDialog; // true if the window is a dialog
auto_ptr<nsMacEventHandler> mMacEventHandler;