Exemplo n.º 1
0
static void window_invalidate(WindowRef windowRef)
{
    Rect portRect;

    GetWindowPortBounds(windowRef, &portRect);
    InvalWindowRect(windowRef, &portRect);
}
Exemplo n.º 2
0
static void mac_groweventlog(WindowPtr window, EventRecord *event)
{
    Session *s = mac_windowsession(window);
    Rect limits;
    long grow_result;
#if TARGET_API_MAC_CARBON
    Rect rect;
    Point cellsize;
#else
    GrafPtr saveport;
#endif

    SetRect(&limits, 15, 0, SHRT_MAX, SHRT_MAX);
    grow_result = GrowWindow(window, event->where, &limits);
    if (grow_result == 0) return;
    SizeWindow(window, LoWord(grow_result), HiWord(grow_result), TRUE);
    LSize(LoWord(grow_result) - 15, HiWord(grow_result), s->eventlog);
    mac_adjusteventlogscrollbar(s);
    /* We would use SetListCellSize in Carbon, but it's missing. */
    (*s->eventlog)->cellSize.h = LoWord(grow_result) - 15;
#if TARGET_API_MAC_CARBON
    cellsize.h = LoWord(grow_result) - 15;
    GetListViewBounds(s->eventlog, &rect);
    InvalWindowRect(window, &rect);
#else
    GetPort(&saveport);
    SetPort(window);
    InvalRect(&(*s->eventlog)->rView);
    SetPort(saveport);
#endif
}
Exemplo n.º 3
0
void AquaGui::renderBuffer()
{
    _glue.render();

      Rect rectPort;
      GetWindowPortBounds (myWindow, &rectPort);
      InvalWindowRect (myWindow,  &rectPort); // force redrow
}
static OSStatus handleWindowEvent(EventHandlerCallRef nextHandler, EventRef event, void *userData)
{
    OSStatus err;

    // Get the window
    WindowRef window;
    err = GetEventParameter(event, kEventParamDirectObject, typeWindowRef, 0, sizeof(window), 0, &window);
    if (err != noErr)
        return err;

    // Handle the different kinds of events
    ::UInt32 eventKind = GetEventKind(event);
    switch (eventKind)
    {
    // Quit the application when the user closes the window
    case kEventWindowClose:
        QuitApplicationEventLoop();
        return noErr;

    // Draw the contents of the window
    case kEventWindowDrawContent:
        redraw();
        return noErr;

    case kEventWindowBoundsChanged:
        {
            // Update the GL context
            aglUpdateContext(win->getContext());

            // Find out if we have a move or a resize situation
            ::UInt32 attributes;
            GetEventParameter(event, kEventParamAttributes, typeUInt32, 0, sizeof(attributes), 0, &attributes);

            if ((attributes & kWindowBoundsChangeSizeChanged) != 0)
            {
                // Get the new bounds of the window
                Rect bounds;
                GetEventParameter(event, kEventParamCurrentBounds, typeQDRectangle, 0, sizeof(Rect), 0, &bounds);

                // Resize the OpenSG Window
                GLsizei width = bounds.right - bounds.left;
                GLsizei height = bounds.bottom - bounds.top;
                win->resize(width, height);

                // Redraw the whole window
                Rect portRect;
                GetWindowPortBounds(window, &portRect);
                InvalWindowRect(window, &portRect);
            }

            return noErr;
        }

    default:
        return eventNotHandledErr;
    }
}
Exemplo n.º 5
0
/*	InvalDBox(theDialog, itemNumber)

	Thread Safety: InvalDBox is not thread-safe.
*/
static void
InvalDBox(DialogPtr theDialog, int itemNumber)
{
	WindowRef theWindow;
	Rect box;
	
	theWindow = GetDialogWindow(theDialog);
	GetDBox(theDialog, itemNumber, &box);
	InvalWindowRect(theWindow, &box);
}
void SkOSWindow::onHandleInval(const SkIRect& r)
{
	Rect	rect;
	
	rect.left   = r.fLeft;
	rect.top	= r.fTop;
	rect.right  = r.fRight;
	rect.bottom = r.fBottom;
	InvalWindowRect((WindowRef)fHWND, &rect);
}
Exemplo n.º 7
0
    //------------------------------------------------------------------------
    void platform_support::force_redraw()
    {
    	Rect	bounds;
    	
        m_specific->m_redraw_flag = true;
        // on_ctrl_change ();
		on_draw();

    	SetRect(&bounds, 0, 0, m_rbuf_window.width(), m_rbuf_window.height());
    	InvalWindowRect(m_specific->m_window, &bounds);
    }
OSStatus
TextViewInvalidate( WindowRef window, OSType key )
{
    OSStatus status = eventNotHandledErr;
    Rect viewRect;
    require_action( window != NULL, BadWindow, status = eventNotHandledErr );
    
    TXNGetViewRect( WindowGetTXNObj( window, key ), &viewRect );
    
    status = InvalWindowRect( window, &viewRect );
    
    BadWindow:
    return status;   
}
Exemplo n.º 9
0
void wxTopLevelWindowMac::MacInvalidate( const WXRECTPTR rect, bool eraseBackground )
{
    GrafPtr formerPort ;
    GetPort( &formerPort ) ;
    SetPortWindowPort( (WindowRef)m_macWindow ) ;

    m_macNeedsErasing |= eraseBackground ;

    // if we already know that we will have to erase, there's no need to track the rest
    if ( !m_macNeedsErasing)
    {
        // we end only here if eraseBackground is false
        // if we already have a difference between m_macNoEraseUpdateRgn and UpdateRgn
        // we will have to erase anyway

        RgnHandle       updateRgn = NewRgn();
        RgnHandle       diffRgn = NewRgn() ;
        if ( updateRgn && diffRgn )
        {
            GetWindowUpdateRgn( (WindowRef)m_macWindow , updateRgn );
            Point pt = {0,0} ;
            LocalToGlobal( &pt ) ;
            OffsetRgn( updateRgn , -pt.h , -pt.v ) ;
            DiffRgn( updateRgn , (RgnHandle) m_macNoEraseUpdateRgn , diffRgn ) ;
            if ( !EmptyRgn( diffRgn ) )
            {
                m_macNeedsErasing = true ;
            }
        }
        if ( updateRgn )
            DisposeRgn( updateRgn );
        if ( diffRgn )
            DisposeRgn( diffRgn );

        if ( !m_macNeedsErasing )
        {
            RgnHandle rectRgn = NewRgn() ;
            SetRectRgn( rectRgn , ((Rect*)rect)->left , ((Rect*)rect)->top , ((Rect*)rect)->right , ((Rect*)rect)->bottom ) ;
            UnionRgn( (RgnHandle) m_macNoEraseUpdateRgn , rectRgn , (RgnHandle) m_macNoEraseUpdateRgn ) ;
            DisposeRgn( rectRgn ) ;
        }
    }
    InvalWindowRect( (WindowRef)m_macWindow , (Rect*)rect ) ;
    // turn this on to debug the refreshing cycle
#if wxMAC_DEBUG_REDRAW
    PaintRect( rect ) ;
#endif
    SetPort( formerPort ) ;
}
Exemplo n.º 10
0
void
GelatinePaneView::swapPortsAndDisplay()
{
  GrafPtr savedPort;
  GetPort(&savedPort);
  SetPort(GetWindowPort(_model._windowRef));
  aglSetDrawable(_model._aglContext, GetWindowPort(_model._windowRef));
  aglSetCurrentContext(_model._aglContext);
  display();

    Rect portRect;
    GetWindowPortBounds(getModel().getWindowRef(), &portRect);
    InvalWindowRect(getModel().getWindowRef(), &portRect);
  
  SetPort(savedPort);
}
Exemplo n.º 11
0
pascal OSStatus gelatineRendererEventHandler(EventHandlerCallRef handler,
                                             EventRef event,
                                             void* userData)
{
  OSStatus result = eventNotHandledErr;
  GelatinePaneView* view = reinterpret_cast <GelatinePaneView*> (userData);
  UInt32 eventKind = GetEventKind(event);

  switch (eventKind) {

  case kEventControlInitialize:
    view->init();
    break;

  case kEventControlDispose:
    view->dispose();
    break;

  case kEventControlActivate:
    view->swapPortsAndDisplay();
    break;

  case kEventControlDeactivate:
    break;

  case kEventControlDraw:
    view->swapPortsAndDisplay();
    break;

  case kEventControlBoundsChanged:
    Rect* controlRect = view->getModel()._bounds;

    Rect portRect;
    GetWindowPortBounds(view->getModel().getWindowRef(), &portRect);
    InvalWindowRect(view->getModel().getWindowRef(), &portRect);

    view->resize(controlRect->left,
                 controlRect->top,
                 controlRect->right,
                 controlRect->bottom);
    view->swapPortsAndDisplay();
    break;

  }

  return result;
}
Exemplo n.º 12
0
void
XConfigureWindow(
    Display* display,		/* Display. */
    Window w,			/* Window. */
    unsigned int value_mask,
    XWindowChanges* values)
{
    MacDrawable *macWin = (MacDrawable *) w;
    TkWindow *winPtr = macWin->winPtr;

    display->request++;

    /*
     * Change the shape and/or position of the window.
     */

    if (value_mask & (CWX|CWY|CWWidth|CWHeight)) {
	XMoveResizeWindow(display, w, winPtr->changes.x, winPtr->changes.y,
		winPtr->changes.width, winPtr->changes.height);
    }

    /*
     * Change the stacking order of the window.  Tk actuall keeps all
     * the information we need for stacking order.  All we need to do
     * is make sure the clipping regions get updated and generate damage
     * that will ensure things get drawn correctly.
     */

    if (value_mask & CWStackMode) {
	Rect bounds;
	CGrafPtr destPort;
	
	destPort = TkMacOSXGetDrawablePort(w);
	if (destPort != NULL) {
	    SetPort( destPort);
	    TkMacOSXInvalClipRgns(winPtr->parentPtr);
	    TkMacOSXWinBounds(winPtr, &bounds);
	    InvalWindowRect(GetWindowFromPort(destPort),&bounds);
	}
    } 

    /* TkGenWMMoveRequestEvent(macWin->winPtr, 
	    macWin->winPtr->changes.x, macWin->winPtr->changes.y); */
}
Exemplo n.º 13
0
// Added by Mark Newsam
// When a page is added or deleted to the notebook this function updates
// information held in the control so that it matches the order
// the user would expect.
//
void wxNotebook::MacSetupTabs()
{
    m_peer->SetMaximum( GetPageCount() ) ;

    wxNotebookPage *page;
    ControlTabInfoRecV1 info;

    const size_t countPages = GetPageCount();
    for (size_t ii = 0; ii < countPages; ii++)
    {
        page = m_pages[ii];
        info.version = kControlTabInfoVersionOne;
        info.iconSuiteID = 0;
        wxMacCFStringHolder cflabel( page->GetLabel(), m_font.GetEncoding() ) ;
        info.name = cflabel ;
        m_peer->SetData<ControlTabInfoRecV1>( ii + 1, kControlTabInfoTag, &info ) ;

        if ( GetImageList() && GetPageImage(ii) >= 0 && UMAGetSystemVersion() >= 0x1020 )
        {
            const wxBitmap bmap = GetImageList()->GetBitmap( GetPageImage( ii ) ) ;
            if ( bmap.Ok() )
            {
                ControlButtonContentInfo info ;

                wxMacCreateBitmapButton( &info, bmap ) ;

                OSStatus err = m_peer->SetData<ControlButtonContentInfo>( ii + 1, kControlTabImageContentTag, &info );
                wxASSERT_MSG( err == noErr , wxT("Error when setting icon on tab") ) ;

                wxMacReleaseBitmapButton( &info ) ;
            }
        }

        m_peer->SetTabEnabled( ii + 1, true ) ;
    }

#if wxMAC_USE_CORE_GRAPHICS
    Refresh();
#else
    Rect bounds;
    m_peer->GetRectInWindowCoords( &bounds ) ;
    InvalWindowRect( (WindowRef)MacGetTopLevelWindowRef(), &bounds );
#endif
}
Exemplo n.º 14
0
pascal OSStatus pxWindowNative::doWindowResizeComplete(EventHandlerCallRef nextHandler, EventRef theEvent, void* userData)
{
	pxWindowNative* w = (pxWindowNative*)userData;
	
    Rect rect;
    GetEventParameter(theEvent, kEventParamCurrentBounds,
        typeQDRectangle, NULL, sizeof(Rect), NULL, &rect);
		
	w->onSize(rect.right-rect.left, rect.bottom-rect.top);

	Rect r;
	GetWindowBounds(w->mWindowRef,kWindowContentRgn ,&r);
	r.right -= r.left;
	r.bottom -= r.top;
	r.left = r.top = 0;
	InvalWindowRect(w->mWindowRef,&r);

	return CallNextEventHandler (nextHandler, theEvent);
}	
Exemplo n.º 15
0
void pxWindow::invalidateRect(pxRect* pxr)
{
	Rect r;
	if (!pxr)
	{
		GetWindowBounds(mWindowRef,kWindowContentRgn ,&r);
		r.right -= r.left;
		r.bottom -= r.top;
		r.left = 0;
		r.top = 0;
	}
	else
	{
		r.left = pxr->left();
		r.right = pxr->right();
		r.top = pxr->top();
		r.bottom = pxr->bottom();
	}
	InvalWindowRect(mWindowRef,&r);
}
Exemplo n.º 16
0
void wxControl::MacUpdateDimensions() 
{
    // actually in the current systems this should never be possible, but later reparenting
    // may become a reality
    
    if ( (ControlHandle) m_macControl == NULL )
        return ;
        
    if ( GetParent() == NULL )
        return ;
        
    WindowRef rootwindow = (WindowRef) MacGetRootWindow() ;
    if ( rootwindow == NULL )
        return ;
        
    Rect oldBounds ;       
    GetControlBounds( (ControlHandle) m_macControl , &oldBounds ) ; 
    
    int new_x = m_x + MacGetLeftBorderSize() + m_macHorizontalBorder ;
    int new_y = m_y + MacGetTopBorderSize() + m_macVerticalBorder ;
    int new_width = m_width - MacGetLeftBorderSize() - MacGetRightBorderSize() - 2 * m_macHorizontalBorder ;
    int new_height = m_height - MacGetTopBorderSize() - MacGetBottomBorderSize() - 2 * m_macVerticalBorder ;
    
    GetParent()->MacWindowToRootWindow( & new_x , & new_y ) ;
    bool doMove = new_x != oldBounds.left || new_y != oldBounds.top ;
    bool doResize =  ( oldBounds.right - oldBounds.left ) != new_width || (oldBounds.bottom - oldBounds.top ) != new_height ;
    if ( doMove || doResize )
    {
        InvalWindowRect( rootwindow, &oldBounds ) ;
        if ( doMove )
        {
            UMAMoveControl( (ControlHandle) m_macControl , new_x , new_y ) ;
        }
        if ( doResize )
        {
            UMASizeControl( (ControlHandle) m_macControl , new_width , new_height ) ;
        }
    }
}
Exemplo n.º 17
0
void
PaneView::resize(short left, short top, short right, short bottom)
{
  aglSetCurrentContext(_model._aglContext);
  aglUpdateContext(_model._aglContext);

  short width = right - left;
  short height = bottom - top;
  float aspectRatio =  (float) width / (float) height;
  //  float fieldOfViewY = 45.0f * _model.getSpace().getCurrentShot().getCamera().getZoom();
  float fieldOfViewY = 45.0f * _model.getSpace().getShots().next().getCamera().getZoom();

  Rect portRect;
  GetWindowPortBounds(_model._windowRef, &portRect);
  short portHeight = portRect.bottom - portRect.top;

  GLint bufferRect[4];
  bufferRect[0] = _model._bounds->left; // x
  bufferRect[1] = portHeight - _model._bounds->bottom; // y
  bufferRect[2] = _model._bounds->right - _model._bounds->left; // width
  bufferRect[3] = _model._bounds->bottom - _model._bounds->top; // height

  aglSetInteger(_model._aglContext, AGL_BUFFER_RECT, bufferRect);
  aglEnable(_model._aglContext, AGL_BUFFER_RECT);

  //  aglSetInteger(inData->mContext, AGL_CLIP_REGION, (const GLint*)rgn);
  //  aglEnable(inData->mContext, AGL_CLIP_REGION);

  glViewport(0, 0, width, height);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(fieldOfViewY, aspectRatio, 1.0f, 1000.0f);

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  InvalWindowRect(_model._windowRef, &portRect);
  _model.getSpace().resize(width, height);
}
OSStatus CSMNativeWindow::handleWindowEvent(EventHandlerCallRef  nextHandler, 
                                            EventRef             event      )
{
    OSStatus err;

    // Get the window
    WindowRef window;
    
    err = GetEventParameter(event, 
                            kEventParamDirectObject, 
                            typeWindowRef, 0, sizeof(window), 0, &window);

    if (err != noErr)
        return err;
    
    // Handle the different kinds of events
    ::UInt32 eventKind = GetEventKind(event);
    
    switch (eventKind)
    {
        // Quit the application when the user closes the window
        case kEventWindowClose:
            //QuitApplicationEventLoop();
            _bRun = false;
            return noErr;
            
            // Draw the contents of the window
        case kEventWindowDrawContent:
            //ComplexSceneManager::the()->frame();
        
            //Thread::getCurrentChangeList()->commitChangesAndClear();
            return noErr;
            
        case kEventWindowBoundsChanged:
        {
            // Update the GL context 
            // WARNING this crap might crash later
            aglUpdateContext(_pCarbWindow->getContext());
            
            // Find out if we have a move or a resize situation
            ::UInt32 attributes;
            GetEventParameter(event, 
                              kEventParamAttributes, 
                              typeUInt32, 
                              0, 
                              sizeof(attributes), 
                              0, 
                              &attributes);
            
            if ((attributes & kWindowBoundsChangeSizeChanged) != 0)
            {
                // Get the new bounds of the window
                Rect bounds;
                GetEventParameter(event, 
                                  kEventParamCurrentBounds, 
                                  typeQDRectangle, 
                                  0, 
                                  sizeof(Rect), 
                                  0, 
                                  &bounds);

                // Resize the OpenSG Window
                GLsizei width  = bounds.right - bounds.left;
                GLsizei height = bounds.bottom - bounds.top;

                this->reshape(width, height);

                // Redraw the whole window
                Rect portRect;
                GetWindowPortBounds(window, &portRect);
                InvalWindowRect    (window, &portRect);
            }
            
            return noErr;
        }
        
        default:
            return eventNotHandledErr;
    }
}
Exemplo n.º 19
0
    static pascal OSStatus WindowEventHandler (EventHandlerCallRef myHandler, EventRef event, void* userData)
    {
        WindowRef			window = NULL;
        OSStatus			result = eventNotHandledErr;
        UInt32 				msgClass = GetEventClass (event);
        UInt32 				kind = GetEventKind (event);
        OSXWindowData *oW = (OSXWindowData*)userData;
        
        WindowBase *wB = oW->WindowBaseOwner;
        window = wB->GetWindowHandle();
        ::Rect rectPort;
        
        switch (msgClass) {
            case kEventClassMouse:
                {
                    EventMouseButton button;
                    GetEventParameter (event, kEventParamMouseButton, typeMouseButton, 
                                       NULL, sizeof(EventMouseButton), NULL, &button);
                
                    HIPoint location;
                    GetEventParameter (event, kEventParamWindowMouseLocation, typeHIPoint, 
                                       NULL, sizeof(HIPoint), NULL, &location);

                    UInt32 clickCount;
                    GetEventParameter (event, kEventParamClickCount, typeUInt32, 
                                       NULL, sizeof(UInt32), NULL, &clickCount);

                    if(kind == kEventMouseDown || kind == kEventMouseUp)
                    {
                        MouseButton mB;
                        switch(button)
                        {
                            case kEventMouseButtonPrimary:
                                mB = MOUSE_LEFT;
                                break;
                            case kEventMouseButtonSecondary:
                                mB = MOUSE_MIDDLE;
                                break;
                            case kEventMouseButtonTertiary:
                                mB = MOUSE_RIGHT;
                                break;
                        }
                        wB->EventMouseButton((int)location.x,(int)location.y, mB, clickCount);
                    }
                    else
                        wB->EventMouseMove((int)location.x,(int)location.y);
                }
                break;
            case kEventClassKeyboard:
                switch (kind) {
                    case kEventRawKeyDown:
                        result = handleKeyInput  (myHandler, event, true, oW);
                        break;
                    case kEventRawKeyUp:
                        result = handleKeyInput  (myHandler, event, false, oW);
                        break;
                }
                break;
            case kEventClassWindow:
                GetEventParameter(event, kEventParamDirectObject, typeWindowRef, 
                                  NULL, sizeof(WindowRef), NULL, &window);
                switch (kind) {
                    case kEventWindowDeactivated:
                        wB->EventFocus(false);
                        break;
                    case kEventWindowActivated:
                        wB->EventFocus(true);
                        break;
                    case kEventWindowDrawContent:
                        wB->EventDraw();
                        break;
                    case kEventWindowBoundsChanged:
                    {
                        Rect rect = wB->GetWindowRect();
                        wB->EventSize(rect.width, rect.height);
                        break;                        
                    }
                    case kEventWindowClose:
                        wB->EventClose();
                        wB->DisableEvent();
                        break;
                    // WARNING: This is not called if windows is unminimized!
                    case kEventWindowShown:
                        SetUserFocusWindow (window);
                        GetWindowPortBounds (window, &rectPort);
                        InvalWindowRect (window, &rectPort);
                        wB->EventMain();
                        break;
                }
                break;
        }
        return result;
    }
Exemplo n.º 20
0
static pascal OSStatus WindowEventHandler(EventHandlerCallRef myHandler, EventRef event, void* userData)
{
#pragma unused (myHandler, userData)
    WindowRef		window;
    Rect			bounds;
    OSStatus		result = eventNotHandledErr;
    UInt32			eventClass = GetEventClass( event );
    UInt32			eventKind = GetEventKind( event );
    HICommand		hiCommand;
    Boolean			extractionPaused;
	
	switch(eventClass)
	{
        // Our custom event which is sent by our Core Audio render procedure
        // to indicate the movie audio extraction state:
        //     state = paused or 
        //    state = in progress
        // for the current movie. We update our button 
        // title ("Play" or "Stop") to reflect the audio extraction state.
		case kEventClassMovieExtractState:
		
			if ( eventKind == kEventKQueue )
			{
				GetEventParameter( event, kEventParamDirectObject, typeKEvent, NULL, sizeof(Boolean), NULL, &extractionPaused );
				
				if (extractionPaused)
				{
					SetControlButtonTextPlay();
				}
				else
				{
					SetControlButtonTextStopped();
				}

			}
			break;
			
		case kEventClassCommand:
			if ( eventKind == kEventCommandProcess )
			{
				GetEventParameter( event, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &hiCommand );
				
				// Custom command ('PLAY') for our Play button selection
				//
				// We get this when the user has selected the button to either
				// play/stop the audio extraction for the current movie.
				//
				if ( hiCommand.commandID == 'PLAY' )
				{
					CFStringRef btnTitleString;
					OSStatus status = CopyControlTitleAsCFString(mButtonRef, &btnTitleString);
					if (status == noErr)
					{
						CFComparisonResult compareResult = CFStringCompare (btnTitleString,
                                                                                                                                       playText,
                                                                                                                                       0);
						if (compareResult == kCFCompareEqualTo)
						{
							// Play mode -- start audio extraction & playback
							
							// Optionally you can pass a specific time value
							// for the start time.
							//
							// Here's how you would setup a TimeRecord for this:
							
							/*
							TimeRecord timeRec;
                            timeRec.scale	= GetMovieTimeScale(mCurrentMovie);
                            timeRec.base	= NULL;
                            timeRec.value.hi = 0;
                            timeRec.value.lo = 60 * timeRec.scale; // for instance, to start at time 1:00.00
							*/
							
							// Optionally you can specify an audio effect be added
							// to playback
							
							DoStartMoviePreview(mCurrentMovie, 
                                                nil,        /* start time - 0 means start at beginning*/ 
                                                true);	/* true = use audio effect during playback */
						}
						else
						{
							// Stop mode -- stop audio extraction & playback
                            DoStopMoviePreview();
						}
					}
				}
			}
			break;
		
		case kEventClassWindow:

			GetEventParameter(event, kEventParamDirectObject, typeWindowRef, NULL, sizeof(window), NULL, &window);

			if (eventKind == kEventWindowDrawContent)
			{
				HandleWindowUpdate(window);
				result = noErr;
			}
			else if (eventKind == kEventWindowBoundsChanged)
			{
				InvalWindowRect(window, GetWindowPortBounds(window, &bounds));
				result = noErr;
			}
			else if (eventKind == kEventWindowClose)
			{
				// quit application
				QuitApplicationEventLoop();
				result = noErr;
			}
			break;
	}
	
    return result;
}
Exemplo n.º 21
0
// ---------------------------------------------------------------------------
void OSXWindowImpl::update()
{
  InvalWindowRect(mWindowRef, &mRect);
}
Exemplo n.º 22
0
void wxSlider::MacUpdateDimensions()
{
    // actually in the current systems this should never be possible, but later reparenting
    // may become a reality

    if ( (ControlHandle) m_macControl == NULL )
        return ;

    if ( GetParent() == NULL )
        return ;

    WindowRef rootwindow = (WindowRef) MacGetRootWindow() ;
    if ( rootwindow == NULL )
        return ;

    int  xborder, yborder;
    int  minValWidth, maxValWidth, textwidth, textheight;
    int  sliderBreadth;

    xborder = yborder = 0;

    if (GetWindowStyle() & wxSL_LABELS)
    {
        wxString text;
        int ht;

        // Get maximum text label width and height
        text.Printf(wxT("%d"), m_rangeMin);
        GetTextExtent(text, &minValWidth, &textheight);
        text.Printf(wxT("%d"), m_rangeMax);
        GetTextExtent(text, &maxValWidth, &ht);
        if(ht > textheight) {
            textheight = ht;
        }
        textwidth = (minValWidth > maxValWidth ? minValWidth : maxValWidth);

        xborder = textwidth + wxSLIDER_BORDERTEXT;
        yborder = textheight + wxSLIDER_BORDERTEXT;

        // Get slider breadth
        if(GetWindowStyle() & wxSL_AUTOTICKS) {
            sliderBreadth = wxSLIDER_DIMENSIONACROSS_WITHTICKMARKS;
        }
        else {
            sliderBreadth = wxSLIDER_DIMENSIONACROSS_ARROW;
        }

        if(GetWindowStyle() & wxSL_VERTICAL)
        {
            m_macMinimumStatic->Move(sliderBreadth + wxSLIDER_BORDERTEXT,
                m_height - yborder - textheight);
            m_macMaximumStatic->Move(sliderBreadth + wxSLIDER_BORDERTEXT, 0);
            m_macValueStatic->Move(0, m_height - textheight);
        }
        else
        {
            m_macMinimumStatic->Move(0, sliderBreadth + wxSLIDER_BORDERTEXT);
            m_macMaximumStatic->Move(m_width - xborder - maxValWidth / 2,
                sliderBreadth + wxSLIDER_BORDERTEXT);
            m_macValueStatic->Move(m_width - textwidth, 0);
        }
    }

    Rect oldBounds ;
    GetControlBounds( (ControlHandle) m_macControl , &oldBounds ) ;

    int new_x = m_x + MacGetLeftBorderSize() + m_macHorizontalBorder ;
    int new_y = m_y + MacGetTopBorderSize() + m_macVerticalBorder ;
    int new_width = m_width - MacGetLeftBorderSize() - MacGetRightBorderSize() - 2 * m_macHorizontalBorder - xborder ;
    int new_height = m_height - MacGetTopBorderSize() - MacGetBottomBorderSize() - 2 * m_macVerticalBorder - yborder ;

    GetParent()->MacWindowToRootWindow( & new_x , & new_y ) ;
    bool doMove = new_x != oldBounds.left || new_y != oldBounds.top ;
    bool doResize =  ( oldBounds.right - oldBounds.left ) != new_width || (oldBounds.bottom - oldBounds.top ) != new_height ;
    if ( doMove || doResize )
    {
        InvalWindowRect( rootwindow, &oldBounds ) ;
        if ( doMove )
        {
            UMAMoveControl( (ControlHandle) m_macControl , new_x , new_y ) ;
        }
        if ( doResize )
        {
            UMASizeControl( (ControlHandle) m_macControl , new_width , new_height ) ;
        }
    }
}
Exemplo n.º 23
0
// update the spectrum display - the interesting bit :)
pascal void UpdateSpectrum(EventLoopTimerRef inTimer, void *inUserData)
{
	int x,y,y1;

	if (specmode==3) { // waveform
		int c;
		float *buf;
		BASS_CHANNELINFO ci;
		memset(specbuf,0,sizeof(specbuf));
		BASS_ChannelGetInfo(chan,&ci); // get number of channels
		buf=alloca(ci.chans*SPECWIDTH*sizeof(float)); // allocate buffer for data
		BASS_ChannelGetData(chan,buf,(ci.chans*SPECWIDTH*sizeof(float))|BASS_DATA_FLOAT); // get the sample data (floating-point to avoid 8 & 16 bit processing)
		for (c=0;c<ci.chans;c++) {
			for (x=0;x<SPECWIDTH;x++) {
				int v=(1-buf[x*ci.chans+c])*SPECHEIGHT/2; // invert and scale to fit display
				if (v<0) v=0;
				else if (v>=SPECHEIGHT) v=SPECHEIGHT-1;
				if (!x) y=v;
				do { // draw line from previous sample...
					if (y<v) y++;
					else if (y>v) y--;
					specbuf[y*SPECWIDTH+x]=palette[c&1?127:1]; // left=green, right=red (could add more colours to palette for more chans)
				} while (y!=v);
			}
		}
	} else {
		float fft[1024]; // get the FFT data
		BASS_ChannelGetData(chan,fft,BASS_DATA_FFT2048);

		if (!specmode) { // "normal" FFT
			memset(specbuf,0,sizeof(specbuf));
			for (x=0;x<SPECWIDTH/2;x++) {
#if 1
				y=sqrt(fft[x+1])*3*SPECHEIGHT-4; // scale it (sqrt to make low values more visible)
#else
				y=fft[x+1]*10*SPECHEIGHT; // scale it (linearly)
#endif
				if (y>SPECHEIGHT) y=SPECHEIGHT; // cap it
				if (x && (y1=(y+y1)/2)) // interpolate from previous to make the display smoother
					while (--y1>=0) specbuf[(SPECHEIGHT-1-y1)*SPECWIDTH+x*2-1]=palette[y1+1];
				y1=y;
				while (--y>=0) specbuf[(SPECHEIGHT-1-y)*SPECWIDTH+x*2]=palette[y+1]; // draw level
			}
		} else if (specmode==1) { // logarithmic, acumulate & average bins
			int b0=0;
			memset(specbuf,0,sizeof(specbuf));
#define BANDS 28
			for (x=0;x<BANDS;x++) {
				float peak=0;
				int b1=pow(2,x*10.0/(BANDS-1));
				if (b1>1023) b1=1023;
				if (b1<=b0) b1=b0+1; // make sure it uses at least 1 FFT bin
				for (;b0<b1;b0++)
					if (peak<fft[1+b0]) peak=fft[1+b0];
				y=sqrt(peak)*3*SPECHEIGHT-4; // scale it (sqrt to make low values more visible)
				if (y>SPECHEIGHT) y=SPECHEIGHT; // cap it
				while (--y>=0)
					for (y1=0;y1<SPECWIDTH/BANDS-2;y1++)
						specbuf[(SPECHEIGHT-1-y)*SPECWIDTH+x*(SPECWIDTH/BANDS)+y1]=palette[y+1]; // draw bar
			}
		} else { // "3D"
			for (x=0;x<SPECHEIGHT;x++) {
				y=sqrt(fft[x+1])*3*127; // scale it (sqrt to make low values more visible)
				if (y>127) y=127; // cap it
				specbuf[(SPECHEIGHT-1-x)*SPECWIDTH+specpos]=palette[128+y]; // plot it
			}
			// move marker onto next position
			specpos=(specpos+1)%SPECWIDTH;
			for (x=0;x<SPECHEIGHT;x++) specbuf[x*SPECWIDTH+specpos]=palette[255];
		}
	}

	// update the display
	static const Rect r={0,0,SPECHEIGHT,SPECWIDTH};
	InvalWindowRect(win,&r);
}
Exemplo n.º 24
0
void NCarbonWindowManager::WindowNeedsUpdate(NWindow* windToUpdate, NRect & rectDirty)
{
	Rect r = rectDirty.AsQDRect();
	WindowRef macWindow = GetMacWindowFromNWindow(windToUpdate);
	InvalWindowRect(macWindow, &r);
}
Exemplo n.º 25
0
Arquivo: MacGraph.c Projeto: rolk/ug
INT GrowGraphWindow (GRAPH_WINDOW *gw, EventRecord *theEvent, DOC_GROW_EVENT *docGrow)
{
  long growResult;
  Rect r,sizeRect,beforeRect,afterRect;
  WindowPtr theWindow;
  Rect myClipRect;

  theWindow = MAC_WIN(gw);
  SetPort(GetWindowPort(theWindow));

  /* grow window */
  GetPortBounds(GetWindowPort(theWindow),&beforeRect);
  SetRect(&sizeRect,GRAPHWIN_MINSIZE,GRAPHWIN_MINSIZE,SCREEN_WIDTH-2*MARGIN_TO_SCREEN,SCREEN_HEIGHT-2*MARGIN_TO_SCREEN-MENU_BAR);
  growResult = GrowWindow(theWindow,theEvent->where,&sizeRect);
  if (growResult!=0)
  {
    /* actually change windows size */
    SizeWindow(theWindow,LoWrd(growResult),HiWrd(growResult),true);
    GetPortBounds(GetWindowPort(theWindow),&afterRect);

    /* make the new regions invalid */
    if (afterRect.right>beforeRect.right)
    {
      SetRect(&r,beforeRect.right-15,beforeRect.top,beforeRect.right,beforeRect.bottom-15);
      InvalWindowRect(theWindow,&r);
    }
    else if (afterRect.right<beforeRect.right)
    {
      SetRect(&r,afterRect.right-15,afterRect.top,afterRect.right,afterRect.bottom-15);
      InvalWindowRect(theWindow,&r);
    }
    if (afterRect.bottom>beforeRect.bottom)
    {
      SetRect(&r,beforeRect.left,beforeRect.bottom-15,beforeRect.right,beforeRect.bottom);
      InvalWindowRect(theWindow,&r);
    }
    else if (afterRect.bottom<beforeRect.bottom)
    {
      SetRect(&r,afterRect.left,afterRect.bottom-15,afterRect.right,afterRect.bottom);
      InvalWindowRect(theWindow,&r);
    }

    /* store and report new size */
    docGrow->Global_LL[0] = gw->Global_LL[0];
    docGrow->Global_LL[1] = gw->Global_LL[1] += afterRect.bottom - SCROLL_BAR - gw->Local_LL[1];
    docGrow->Global_UR[0] = gw->Global_UR[0] += afterRect.right  - SCROLL_BAR - gw->Local_UR[0];
    docGrow->Global_UR[1] = gw->Global_UR[1];

    docGrow->Local_LL[0] = gw->Local_LL[0] = afterRect.left;
    docGrow->Local_LL[1] = gw->Local_LL[1] = afterRect.bottom - SCROLL_BAR;
    docGrow->Local_UR[0] = gw->Local_UR[0] = afterRect.right  - SCROLL_BAR;
    docGrow->Local_UR[1] = gw->Local_UR[1] = afterRect.top;

    ClipRect(&afterRect);
    EraseRect(&afterRect);

    /* adjust clipping rectangle */
    myClipRect.left   = gw->Local_LL[0];
    myClipRect.right  = gw->Local_UR[0];
    myClipRect.bottom = gw->Local_LL[1];
    myClipRect.top    = gw->Local_UR[1];

    ClipRect(&myClipRect);

    return (POS_CHANGE);
  }
  else
    return (NO_POS_CHANGE);
}
Exemplo n.º 26
0
pascal void HIDTimer (EventLoopTimerRef inTimer, void* )
{
    #pragma unused (inTimer)
	static AbsoluteTime time = {0, 0};
	long				deadZone = 25;
   pRecContext			pContextInfo = NULL;
//	float				rotation[4] = {0.0f, 0.0f, 0.0f, 0.0f};

    AbsoluteTime currTime = UpTime ();
    float deltaTime = (float) AbsoluteDeltaToDuration (currTime, time);
	time = currTime;	// reset for next time interval
    if (0 > deltaTime)	// if negative microseconds
		deltaTime /= -1000000.0;
    else				// else milliseconds
		deltaTime /= 1000.0;
    if (deltaTime > 10.0) // skip pauses
        return;

    // get input values
    GetInput ();
	// apply to front window
	pContextInfo = GetCurrentContextInfo(FrontWindow()); // call back to main to get the current context info record
	if (!pContextInfo)
	{
		return; // not an application window so do not process
	}
	// apply input
	double panX=0, panY=0;
	if (gActionArray [kActionXAxis].pDevice && gActionArray [kActionXAxis].pElement && (abs (gActionArray [kActionXAxis].value) > deadZone)) {
		// pan
		panX = gActionArray [kActionXAxis].value;
		//panX = abs (gActionArray [kActionXAxis].value) * gActionArray [kActionXAxis].value * 0.002f;
		//panX = abs (gActionArray [kActionXAxis].value) * gActionArray [kActionXAxis].value * 0.002f / (1500.0f / -pContextInfo->camera.viewPos.z);
		//pContextInfo->camera.viewPos.x += panX;
	}
	if (gActionArray [kActionYAxis].pDevice && gActionArray [kActionYAxis].pElement && (abs (gActionArray [kActionYAxis].value) > deadZone)) {
		// pan
		panY = gActionArray [kActionYAxis].value;
		//panY = abs (gActionArray [kActionYAxis].value) * gActionArray [kActionYAxis].value * deltaTime * 0.002f;
		//panY = abs (gActionArray [kActionYAxis].value) * gActionArray [kActionYAxis].value * deltaTime * 0.002f / (1500.0f / -pContextInfo->camera.viewPos.z);
		//pContextInfo->camera.viewPos.y -= panY;
	}
	handleJoystickMovement(pContextInfo, panX, panY);

	//	doMouseDelta(panX, panY);
//	if (gActionArray [kActionZAxis].pDevice && gActionArray [kActionZAxis].pElement && (abs (gActionArray [kActionZAxis].value) > deadZone)) {
//		// dolly
//		GLfloat dolly = abs (gActionArray [kActionZAxis].value) * gActionArray [kActionZAxis].value * deltaTime * 0.002f * -pContextInfo->camera.viewPos.z / 500.0f;
//		pContextInfo->camera.viewPos.z += dolly;
//		if (pContextInfo->camera.viewPos.z == 0.0) // do not let z = 0.0
//			pContextInfo->camera.viewPos.z = 0.0001;
//	}
	// handle rotations about each respective axis
//	if (gActionArray [kActionXRot].pDevice && gActionArray [kActionXRot].pElement && (abs (gActionArray [kActionXRot].value) > deadZone)) {
//		rotation[0] = abs (gActionArray [kActionXRot].value) * -gActionArray [kActionXRot].value * deltaTime * 0.0003f;
//		rotation[1] = 1.0f;
//		rotation[2] = 0.0f;
//		rotation[3] = 0.0f;
//		addToRotationTrackball (rotation, pContextInfo->worldRotation);
//	}
//	if (gActionArray [kActionYRot].pDevice && gActionArray [kActionYRot].pElement && (abs (gActionArray [kActionYRot].value) > deadZone)) {
//		rotation[0] = abs (gActionArray [kActionYRot].value) * gActionArray [kActionYRot].value * deltaTime * 0.0003f;
//		rotation[1] = 0.0f;
//		rotation[2] = 1.0f;
//		rotation[3] = 0.0f;
//		addToRotationTrackball (rotation, pContextInfo->worldRotation);
//	}
//	if (gActionArray [kActionZRot].pDevice && gActionArray [kActionZRot].pElement && (abs (gActionArray [kActionZRot].value) > deadZone)) {
//		rotation[0] = abs (gActionArray [kActionZRot].value) * -gActionArray [kActionZRot].value * deltaTime * 0.0003f;
//		rotation[1] = 0.0f;
//		rotation[2] = 0.0f;
//		rotation[3] = 1.0f;
//		addToRotationTrackball (rotation, pContextInfo->worldRotation);
//	}
	// need to force draw here...
	{
		Rect rectPort;
		WindowRef window = FrontWindow ();
		GetWindowPortBounds (window, &rectPort);
		InvalWindowRect (window, &rectPort);
	}
}
Exemplo n.º 27
0
void 
XMoveWindow(
    Display* display,		/* Display. */
    Window window,		/* Window. */
    int x,
    int y)
{
    MacDrawable *macWin = (MacDrawable *) window;
    CGrafPtr  destPort;

    destPort   = TkMacOSXGetDrawablePort(window);
    if (destPort == NULL) {
	return;
    }

    SetPort( destPort);
    if (Tk_IsTopLevel(macWin->winPtr) && !Tk_IsEmbedded(macWin->winPtr)) {
	/* 
	 * NOTE: we are not adding the new space to the update
	 * region.  It is currently assumed that Tk will need
	 * to completely redraw anway.
	 */
	MoveWindowStructure( GetWindowFromPort(destPort), x, y);

	/* TODO: is the following right? */
	TkMacOSXInvalidateWindow(macWin, TK_WINDOW_ONLY);
	TkMacOSXInvalClipRgns(macWin->winPtr);
    } else {
	int deltaX, deltaY, parentBorderwidth;
	Rect bounds;
	MacDrawable *macParent;
	
        /*
         * Find the Parent window -
         * For an embedded window this will be its container.
         */
         
	if (Tk_IsEmbedded(macWin->winPtr)) {
	    TkWindow *contWinPtr;
	    
	    contWinPtr = TkpGetOtherWindow(macWin->winPtr);
	    if (contWinPtr == NULL) {
	            panic("XMoveWindow could not find container");
	    }
	    macParent = contWinPtr->privatePtr;
	    
	    /*
	     * NOTE: Here we should handle out of process embedding.
	     */
		    
	} else {
	    macParent = macWin->winPtr->parentPtr->privatePtr;   
	    if (macParent == NULL) {
	        return; /* TODO: Probably should be a panic */
	    }
	}

	TkMacOSXInvalClipRgns(macParent->winPtr);
	TkMacOSXInvalidateWindow(macWin, TK_PARENT_WINDOW);

	deltaX = - macWin->xOff;
	deltaY = - macWin->yOff;
	
        /*
	 * If macWin->winPtr is an embedded window, don't offset by its
	 *  parent's borderwidth...
	 */
	 
	if (!Tk_IsEmbedded(macWin->winPtr)) {
	    parentBorderwidth = macWin->winPtr->parentPtr->changes.border_width;
	} else {
	    parentBorderwidth = 0;
	}
	deltaX += macParent->xOff + parentBorderwidth +
	    macWin->winPtr->changes.x;
	deltaY += macParent->yOff + parentBorderwidth +
	    macWin->winPtr->changes.y;
		
	UpdateOffsets(macWin->winPtr, deltaX, deltaY);
	TkMacOSXWinBounds(macWin->winPtr, &bounds);
	InvalWindowRect(GetWindowFromPort(destPort),&bounds);
    }
}
Exemplo n.º 28
0
static Boolean MySystem6or7DialogFilter(DialogRef theDialog, EventRecord *inEvent, DialogItemIndex *itemHit)
{
	if ((inEvent->what == keyDown) || (inEvent->what == autoKey))
	{
		char c = (inEvent->message & charCodeMask);
		
		// return or enter key?
		if ((c == kReturnCharCode) || (c == kEnterCharCode))
		{
			*itemHit = 1;
			return true;
		}
		
		// tab key or arrow keys?
		if (c == kTabCharCode) return false;
		if (c == kLeftArrowCharCode) return false;
		if (c == kRightArrowCharCode) return false;
		if (c == kUpArrowCharCode) return false;
		if (c == kDownArrowCharCode) return false;
		
		// digits only for edittext box item #9 ?
		// pre-Carbon, this would have been: ((DialogPeek)theDialog)->editField+1 == 9
		if (GetDialogKeyboardFocusItem(theDialog) == 9)
		{
			if ((c < '0') || (c > '9'))
			{
				SysBeep(1);
				return true;
			}
		}
	}
	
	// we got a click!
	if (inEvent->what == mouseDown)
	{
		DialogItemType itemType;
		Handle itemHandle;
		Rect itemBox;
		GetDialogItem(theDialog, 13, &itemType, &itemHandle, &itemBox);
		
		// is the user item enabled?
		if (!(itemType & itemDisable))
		{
			CGrafPtr savePort;
			GetPort(&savePort);
			SetPortDialogPort(theDialog);
			Point thePoint = inEvent->where;
			GlobalToLocal(&thePoint);
			Boolean inside = PtInRect(thePoint, &itemBox);
			
			// is the click inside the user item?
			if (inside)
			{
				// let's constrain and move the spot!
				// it's possible to track the spot here but it's complex
				// so we just move on the click and don't track.
				// that's typical of dialog's user items of that era.
				Rect userRect1 = {gUserV-4, gUserH-4, gUserV+4, gUserH+4};
				EraseRect(&userRect1);
				InvalWindowRect(GetDialogWindow(theDialog), &userRect1);
				gUserH = thePoint.h;
				gUserV = thePoint.v;
				if (gUserH < itemBox.left+4) gUserH = itemBox.left+4;
				if (gUserH > itemBox.right-4) gUserH = itemBox.right-4;
				if (gUserV < itemBox.top+4) gUserV = itemBox.top+4;
				if (gUserV > itemBox.bottom-4) gUserV = itemBox.bottom-4;
				Rect userRect2 = {gUserV-4, gUserH-4, gUserV+4, gUserH+4};
				InvalWindowRect(GetDialogWindow(theDialog), &userRect2);
			}
			SetPort(savePort);
		}
	}
	
	return false;
}
Exemplo n.º 29
0
void DoEvent(EventRecord *event)
{
    short	part;
    Boolean	hit;
    char	key;
    Rect	tempRect;
    WindowRef	whichWindow;
        
    switch (event->what) 
    {
        case mouseDown:
            part = FindWindow(event->where, &whichWindow);
            switch (part)
            {
                case inMenuBar:  /* process a moused menu command */
                    DoMenuCommand(MenuSelect(event->where));
                    break;
                    
                case inSysWindow:
                    break;
                
                case inContent:
                    if (whichWindow != FrontWindow()) 
                        SelectWindow(whichWindow);
                    break;
                
                case inDrag:	/* pass screenBits.bounds */
                    GetRegionBounds(GetGrayRgn(), &tempRect);
                    DragWindow(whichWindow, event->where, &tempRect);
                    break;
                    
                case inGrow:
                    break;
                    
                case inGoAway:
                    DisposeWindow(whichWindow);
                    ExitToShell();
                    break;
                    
                case inZoomIn:
                case inZoomOut:
                    hit = TrackBox(whichWindow, event->where, part);
                    if (hit) 
                    {
                        SetPort(GetWindowPort(whichWindow));   // window must be current port
                        EraseRect(GetWindowPortBounds(whichWindow, &tempRect));   // inval/erase because of ZoomWindow bug
                        ZoomWindow(whichWindow, part, true);
                        InvalWindowRect(whichWindow, GetWindowPortBounds(whichWindow, &tempRect));	
                    }
                    break;
                }
                break;
		
                case keyDown:
		case autoKey:
                    key = event->message & charCodeMask;
                    if (event->modifiers & cmdKey)
                        if (event->what == keyDown)
                            DoMenuCommand(MenuKey(key));
		case activateEvt:	       /* if you needed to do something special */
                    break;
                    
                case updateEvt:
			DrawWindow((WindowRef) event->message);
			break;
                        
                case kHighLevelEvent:
			AEProcessAppleEvent( event );
			break;
		
                case diskEvt:
			break;
	}
}
OSStatus CSMNativeWindow::handleMouseEvent(EventHandlerCallRef  nextHandler, 
                                           EventRef             event      )
{
    OSStatus err;

    // Get the window
    WindowRef window;
    err = GetEventParameter(event, 
                            kEventParamWindowRef, 
                            typeWindowRef, 0, 
                            sizeof(window), 0, &window);

    if (err != noErr)
        return err;

    // Get the window rectangle
    Rect portRect;
    GetWindowPortBounds(window, &portRect);

    // Get the pressed mouse button
    EventMouseButton mouseButton;
    err = GetEventParameter(event, 
                            kEventParamMouseButton, 
                            typeMouseButton, 0, 
                            sizeof(mouseButton), 0, &mouseButton);

    if (err != noErr)
        return err;
    
    // Get the modifier keys
    ::UInt32 modifierKeys;
    err = GetEventParameter(event, 
                            kEventParamKeyModifiers, 
                            typeUInt32, 0, 
                            sizeof(modifierKeys), 0, &modifierKeys);

    if (err != noErr)
        return err;

    // Traditionally, Apple mice just have one button. It is common practice 
    // to simulate the middle and the right button by pressing the option or
    // the control key. 

    if(mouseButton == kEventMouseButtonPrimary)
    {
        if(modifierKeys & optionKey)
            mouseButton = kEventMouseButtonTertiary;

        if(modifierKeys & controlKey)
            mouseButton = kEventMouseButtonSecondary;
    }

    // Get the location of the mouse pointer
    ::Point location;
    err = GetEventParameter(event, 
                            kEventParamMouseLocation, 
                            typeQDPoint, 0, 
                            sizeof(location), 0, &location);

    if (err != noErr)
        return err;

    // The location of the mouse pointer is in screen coordinates, so
    // we have to transform it into the local coordinate system of the
    // window content area.
    SetPortWindowPort(window   );
    GlobalToLocal    (&location);

    // Handle the different kinds of events
    ::UInt32 eventKind = GetEventKind(event);

    switch (eventKind)
    {
        // mouse button pressed
        case kEventMouseDown:
        {
            switch (mouseButton)
            {
                case kEventMouseButtonPrimary: // left button
                    this->mouse(MouseData::LeftButton, 
                                MouseData::ButtonDown,
                                0,
                                location.h,
                                location.v);
                    break;
                case kEventMouseButtonSecondary: // right button
                    this->mouse(MouseData::RightButton, 
                                MouseData::ButtonDown,
                                0,
                                location.h,
                                location.v);
                    break;
                case kEventMouseButtonTertiary: // middle button
                    this->mouse(MouseData::MiddleButton, 
                                MouseData::ButtonDown,
                                0,
                                location.h,
                                location.v);
                    break;
            }
        }
        break;
            
            // mouse button released
        case kEventMouseUp:
        {
            switch (mouseButton)
            {
                case kEventMouseButtonPrimary: // left button
                    this->mouse(MouseData::LeftButton, 
                                MouseData::ButtonUp,
                                0,
                                location.h,
                                location.v);
                    break;
                case kEventMouseButtonSecondary: // right button
                    this->mouse(MouseData::RightButton, 
                                MouseData::ButtonUp,
                                0,
                                location.h,
                                location.v);
                    break;
                case kEventMouseButtonTertiary: // middle button
                    this->mouse(MouseData::MiddleButton, 
                                MouseData::ButtonUp,
                                0,
                                location.h,
                                location.v);
                    break;
            }
        }
        break;
            
            // mouse moved while a button is pressed
        case kEventMouseDragged:

            this->motion(location.h, location.v);
            
            // Redraw the whole window
            InvalWindowRect(window, &portRect);
            
            break;
    }
    
    // We have to return eventNotHandledErr, otherwise the system is
    // not able to operate the menu and the window border
    return eventNotHandledErr;
}