예제 #1
0
/*
 * specialMenuCommand - run a command from a specific menu
 */
static vi_rc specialMenuCommand( int menuid )
{
    int             i;
    vi_rc           rc;
    special_menu    *s;

    s = &specialMenus[0];
    for( i = 0; i < sizeof( specialMenus ) / sizeof( special_menu ); i++, s++ ) {
        rc = handleMenuCommand( s->m, menuid );
        if( rc != MENU_COMMAND_NOT_HANDLED ) {
            return( rc );
        }
    }
    return( MENU_COMMAND_NOT_HANDLED );

} /* specialMenuCommand */
bool GHOST_SystemCarbon::handleMouseDown(EventRef event)
{
	WindowPtr window;
	short part;
	BitMap screenBits;
	bool handled = true;
	GHOST_WindowCarbon *ghostWindow;
	Point mousePos = {0, 0};
	
	::GetEventParameter(event, kEventParamMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &mousePos);
	
	part = ::FindWindow(mousePos, &window);
	ghostWindow = (GHOST_WindowCarbon *) ::GetWRefCon(window);
	
	switch (part) {
		case inMenuBar:
			handleMenuCommand(::MenuSelect(mousePos));
			break;
			
		case inDrag:
			/*
			 * The DragWindow() routine creates a lot of kEventWindowBoundsChanged
			 * events. By setting m_ignoreWindowSizedMessages these are suppressed.
			 * \see GHOST_SystemCarbon::handleWindowEvent(EventRef event)
			 */
			/* even worse: scale window also generates a load of events, and nothing 
			 * is handled (read: client's event proc called) until you release mouse (ton) */
			
			GHOST_ASSERT(validWindow(ghostWindow), "GHOST_SystemCarbon::handleMouseDown: invalid window");
			m_ignoreWindowSizedMessages = true;
			::DragWindow(window, mousePos, &GetQDGlobalsScreenBits(&screenBits)->bounds);
			m_ignoreWindowSizedMessages = false;
			
			pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowMove, ghostWindow) );

			break;
		
		case inContent:
			if (window != ::FrontWindow()) {
				::SelectWindow(window);
				/*
				 * We add a mouse down event on the newly actived window
				 */		
				//GHOST_PRINT("GHOST_SystemCarbon::handleMouseDown(): adding mouse down event, " << ghostWindow << "\n");
				EventMouseButton button;
				::GetEventParameter(event, kEventParamMouseButton, typeMouseButton, NULL, sizeof(button), NULL, &button);
				pushEvent(new GHOST_EventButton(getMilliSeconds(), GHOST_kEventButtonDown, ghostWindow, convertButton(button)));
			}
			else {
				handled = false;
			}
			break;
			
		case inGoAway:
			GHOST_ASSERT(ghostWindow, "GHOST_SystemCarbon::handleMouseEvent: ghostWindow==0");
			if (::TrackGoAway(window, mousePos))
			{
				// todo: add option-close, because it's in the HIG
				// if (event.modifiers & optionKey) {
				// Close the clean documents, others will be confirmed one by one.
				//}
				// else {
				pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowClose, ghostWindow));
				//}
			}
			break;
			
		case inGrow:
			GHOST_ASSERT(ghostWindow, "GHOST_SystemCarbon::handleMouseEvent: ghostWindow==0");
			::ResizeWindow(window, mousePos, NULL, NULL);
			break;
			
		case inZoomIn:
		case inZoomOut:
			GHOST_ASSERT(ghostWindow, "GHOST_SystemCarbon::handleMouseEvent: ghostWindow==0");
			if (::TrackBox(window, mousePos, part)) {
				int macState;
				
				macState = ghostWindow->getMac_windowState();
				if (macState == 0)
					::ZoomWindow(window, part, true);
				else 
				if (macState == 2) {     // always ok
					::ZoomWindow(window, part, true);
					ghostWindow->setMac_windowState(1);
				}
				else {       // need to force size again
					//	GHOST_TUns32 scr_x,scr_y; /*unused*/
					Rect outAvailableRect;
						
					ghostWindow->setMac_windowState(2);
					::GetAvailableWindowPositioningBounds(GetMainDevice(), &outAvailableRect);
						
					//this->getMainDisplayDimensions(scr_x,scr_y);
					::SizeWindow(window, outAvailableRect.right - outAvailableRect.left, outAvailableRect.bottom - outAvailableRect.top - 1, false);
					::MoveWindow(window, outAvailableRect.left, outAvailableRect.top, true);
				}
				
			}
			break;

		default:
			handled = false;
			break;
	}
	
	return handled;
}