Beispiel #1
0
wxDragResult wxDropSource::DoDragDrop(int flags)
{
    wxASSERT_MSG( m_data, wxT("Drop source: no data") );
    
    if (!m_data)
        return (wxDragResult) wxDragNone;
    
    if (m_data->GetFormatCount() == 0)
        return (wxDragResult) wxDragNone;
    
    OSErr result;
    DragReference theDrag;
    RgnHandle dragRegion;
    if ((result = NewDrag(&theDrag)))
    {
        return wxDragNone ;
    }
    // add data to drag
    size_t formatCount = m_data->GetFormatCount() ;
    wxDataFormat *formats = new wxDataFormat[formatCount] ;
    m_data->GetAllFormats( formats ) ;
    ItemReference theItem = 1 ;
    for ( size_t i = 0 ; i < formatCount ; ++i )
    {
        size_t dataSize = m_data->GetDataSize( formats[i] ) ;
        Ptr dataPtr = new char[dataSize] ;
        m_data->GetDataHere( formats[i] , dataPtr ) ;
        OSType type = formats[i].GetFormatId() ;
        if ( type == 'TEXT' || type == 'utxt' )
        {
            if ( dataSize > 0 )
                dataSize-- ;
            dataPtr[ dataSize ] = 0 ;
            if ( type == 'utxt' )
            {
                if ( dataSize > 0 )
                    dataSize-- ;
                dataPtr[ dataSize ] = 0 ;
            }
            AddDragItemFlavor(theDrag, theItem, type , dataPtr, dataSize, 0);      
        }
        else if (type == kDragFlavorTypeHFS )
        {
            HFSFlavor  theFlavor ;
            OSErr err = noErr;
            CInfoPBRec cat;
            
            wxMacFilename2FSSpec( wxString( dataPtr , *wxConvCurrent ) , &theFlavor.fileSpec ) ;
            
            cat.hFileInfo.ioNamePtr = theFlavor.fileSpec.name;
            cat.hFileInfo.ioVRefNum = theFlavor.fileSpec.vRefNum;
            cat.hFileInfo.ioDirID = theFlavor.fileSpec.parID;
            cat.hFileInfo.ioFDirIndex = 0;
            err = PBGetCatInfoSync(&cat);
            if (err == noErr )
            {
                theFlavor.fdFlags = cat.hFileInfo.ioFlFndrInfo.fdFlags;
                if (theFlavor.fileSpec.parID == fsRtParID) {
                    theFlavor.fileCreator = 'MACS';
                    theFlavor.fileType = 'disk';
                } else if ((cat.hFileInfo.ioFlAttrib & ioDirMask) != 0) {
                    theFlavor.fileCreator = 'MACS';
                    theFlavor.fileType = 'fold';
                } else {
                    theFlavor.fileCreator = cat.hFileInfo.ioFlFndrInfo.fdCreator;
                    theFlavor.fileType = cat.hFileInfo.ioFlFndrInfo.fdType;
                }
                AddDragItemFlavor(theDrag, theItem, type , &theFlavor, sizeof(theFlavor), 0);  
            }    
        }
        else
        {
            AddDragItemFlavor(theDrag, theItem, type , dataPtr, dataSize, 0);      
        }
        delete[] dataPtr ;
    }
    delete[] formats ;
    
    dragRegion = NewRgn();
    RgnHandle tempRgn = NewRgn() ;
    
    EventRecord* ev = NULL ;
#if !TARGET_CARBON // TODO
    ev = (EventRecord*) wxTheApp->MacGetCurrentEvent() ;
#else
    EventRecord rec ;
    ev = &rec ;
    wxMacConvertEventToRecord( (EventRef) wxTheApp->MacGetCurrentEvent() , &rec ) ;
#endif
    const short dragRegionOuterBoundary = 10 ;
    const short dragRegionInnerBoundary = 9 ;
    
    SetRectRgn( dragRegion , ev->where.h - dragRegionOuterBoundary , 
        ev->where.v  - dragRegionOuterBoundary ,
        ev->where.h + dragRegionOuterBoundary , 
        ev->where.v + dragRegionOuterBoundary ) ;
    
    SetRectRgn( tempRgn , ev->where.h - dragRegionInnerBoundary , 
        ev->where.v  - dragRegionInnerBoundary ,
        ev->where.h + dragRegionInnerBoundary , 
        ev->where.v + dragRegionInnerBoundary ) ;
    
    DiffRgn( dragRegion , tempRgn , dragRegion ) ;
    DisposeRgn( tempRgn ) ;    
    
    // TODO:work with promises in order to return data only when drag
    // was successfully completed
    
    gTrackingGlobals.m_currentSource = this ;
    result = TrackDrag(theDrag, ev , dragRegion);
    DisposeRgn(dragRegion);
    DisposeDrag(theDrag);
    gTrackingGlobals.m_currentSource = NULL ;
    
    bool optionDown = GetCurrentKeyModifiers() & optionKey ;
    wxDragResult dndresult = wxDragCopy ;
    if ( flags != wxDrag_CopyOnly ) 
    {
        // on mac the option key is always the indication for copy
        dndresult = optionDown ? wxDragCopy : wxDragMove;
    }
    return dndresult;
}
Beispiel #2
0
pascal OSErr wxMacWindowDragTrackingHandler(DragTrackingMessage theMessage, WindowPtr theWindow,
  void *handlerRefCon, DragReference theDrag)
{ 
    MacTrackingGlobals* trackingGlobals = (MacTrackingGlobals*) handlerRefCon;
    Point mouse, localMouse;
    DragAttributes attributes;
    GetDragAttributes(theDrag, &attributes);
    wxTopLevelWindowMac* toplevel = wxFindWinFromMacWindow( theWindow ) ; 

    bool optionDown = GetCurrentKeyModifiers() & optionKey ;
    wxDragResult result = optionDown ? wxDragCopy : wxDragMove;

    switch(theMessage) 
    {
        case kDragTrackingEnterHandler:
            break;
        case kDragTrackingLeaveHandler:
            break;
        case kDragTrackingEnterWindow:
            trackingGlobals->m_currentTargetWindow = NULL ;
            trackingGlobals->m_currentTarget = NULL ;
            break;
        case kDragTrackingInWindow:
            if (toplevel == NULL)
                break;

            GetDragMouse(theDrag, &mouse, 0L);
            localMouse = mouse;
            GlobalToLocal(&localMouse);


            
            {
                wxWindow *win = NULL ;
                ControlPartCode controlPart ;
                ControlRef control = wxMacFindControlUnderMouse( toplevel , localMouse ,
                    theWindow , &controlPart ) ;
                if ( control )
                    win = wxFindControlFromMacControl( control ) ;
                else
                    win = toplevel ;
                
                int localx , localy ;
                localx = localMouse.h ;
                localy = localMouse.v ;

                if ( win )
                    win->MacRootWindowToWindow( &localx , &localy ) ;
                if ( win != trackingGlobals->m_currentTargetWindow )
                {
                    if ( trackingGlobals->m_currentTargetWindow )
                    {
                        // this window is left
                        if ( trackingGlobals->m_currentTarget )
                        {
                            HideDragHilite(theDrag);
                            trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
                            trackingGlobals->m_currentTarget->OnLeave() ;
                            trackingGlobals->m_currentTarget = NULL;
                            trackingGlobals->m_currentTargetWindow = NULL ;
                        }
                    }
                    if ( win )
                    {
                        // this window is entered
                        trackingGlobals->m_currentTargetWindow = win ;
                        trackingGlobals->m_currentTarget = win->GetDropTarget() ;
                        {

                        	if ( trackingGlobals->m_currentTarget )
                        	{
                            	trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
                            	result = trackingGlobals->m_currentTarget->OnEnter(
                                	localx , localy , result ) ;
                            }
                                
                           
                            if ( result != wxDragNone )
                            {
                                int x , y ;
                                x = y = 0 ;
                                win->MacWindowToRootWindow( &x , &y ) ;
                                RgnHandle hiliteRgn = NewRgn() ;
                                Rect r = { y , x , y+win->GetSize().y , x+win->GetSize().x } ;
                                RectRgn( hiliteRgn , &r ) ;
                                ShowDragHilite(theDrag, hiliteRgn, true);
                                DisposeRgn( hiliteRgn ) ;
                            }
                        }
                    }
                }
                else
                {
                    if( trackingGlobals->m_currentTarget )
                    {
                        trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
                        trackingGlobals->m_currentTarget->OnDragOver(
                            localx , localy , result ) ;
                    }
                }

                // set cursor for OnEnter and OnDragOver
                if ( trackingGlobals->m_currentSource && trackingGlobals->m_currentSource->GiveFeedback( result ) == FALSE )
                {
                  if ( trackingGlobals->m_currentSource->MacInstallDefaultCursor( result ) == FALSE )
                  {
                      switch( result )
                      {
                          case wxDragCopy :
                              {
                                  wxCursor cursor(wxCURSOR_COPY_ARROW) ;
                                  cursor.MacInstall() ;
                              }
                              break ;
                          case wxDragMove :
                              {
                                  wxCursor cursor(wxCURSOR_ARROW) ;
                                  cursor.MacInstall() ;
                              }
                              break ;
                          case wxDragNone :
                              {
                                  wxCursor cursor(wxCURSOR_NO_ENTRY) ;
                                  cursor.MacInstall() ;
                              }
                              break ;

                          case wxDragError:
                          case wxDragLink:
                          case wxDragCancel:
                              // put these here to make gcc happy
                              ;
                      }
                  }
                }
                
            }
            break;
        case kDragTrackingLeaveWindow:
            if (trackingGlobals->m_currentTarget) 
            {
                trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
                trackingGlobals->m_currentTarget->OnLeave() ;
                HideDragHilite(theDrag);
                trackingGlobals->m_currentTarget = NULL ;
            }
            trackingGlobals->m_currentTargetWindow = NULL ;
            break;
    }
    return(noErr);
}
bool CDlgEventLog::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
////@begin CDlgEventLog member initialisation
    m_iPreviousRowCount = 0;
    m_iTotalDocCount = 0;
    m_iPreviousTotalDocCount = 0;
    if (!s_bIsFiltered) {
        s_strFilteredProjectName.clear();
    }
    m_iFilteredIndexes.Clear();
	m_bProcessingRefreshEvent = false;
    m_bEventLogIsOpen = true;
////@end CDlgEventLog member initialisation

    CSkinAdvanced* pSkinAdvanced = wxGetApp().GetSkinManager()->GetAdvanced();
    wxPoint oTempPoint;
    wxSize  oTempSize;

    wxASSERT(pSkinAdvanced);
    wxASSERT(wxDynamicCast(pSkinAdvanced, CSkinAdvanced));

    if ((pos == wxDefaultPosition) && (size == wxDefaultSize)) {
        // Get size and position from the previous configuration
        GetWindowDimensions( oTempPoint, oTempSize );

#ifdef __WXMSW__
        // Windows does some crazy things if the initial position is a negative
        // value.
        oTempPoint.x = wxDefaultCoord;
        oTempPoint.y = wxDefaultCoord;
#endif

#ifdef __WXMAC__
        // If the user has changed the arrangement of multiple 
        // displays, make sure the window title bar is still on-screen.
        Rect titleRect = {oTempPoint.y, oTempPoint.x, oTempPoint.y+22, oTempPoint.x+oTempSize.x };
        InsetRect(&titleRect, 5, 5);    // Make sure at least a 5X5 piece visible
        RgnHandle displayRgn = NewRgn();
        CopyRgn(GetGrayRgn(), displayRgn);  // Region encompassing all displays
        Rect menuRect = ((**GetMainDevice())).gdRect;
        menuRect.bottom = GetMBarHeight() + menuRect.top;
        RgnHandle menuRgn = NewRgn();
        RectRgn(menuRgn, &menuRect);                // Region hidden by menu bar
        DiffRgn(displayRgn, menuRgn, displayRgn);   // Subtract menu bar retion
        if (!RectInRgn(&titleRect, displayRgn))
            oTempPoint.y = oTempPoint.x = 30;
        DisposeRgn(menuRgn);
        DisposeRgn(displayRgn);
#endif  // ! __WXMAC__
    } else {
        oTempPoint = pos;
        oTempSize = size;
    }

    wxDialog::Create( parent, id, caption, oTempPoint, oTempSize, style );

    SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS);

    // Initialize Application Title
    wxString strCaption = caption;
    if (strCaption.IsEmpty()) {
        strCaption.Printf(_("%s - Event Log"), pSkinAdvanced->GetApplicationName().c_str());
    }
    SetTitle(strCaption);

    // Initialize Application Icon
    wxIconBundle icons;
    icons.AddIcon(*pSkinAdvanced->GetApplicationIcon());
    icons.AddIcon(*pSkinAdvanced->GetApplicationIcon32());
    SetIcons(icons);

    CreateControls();

	// Create List Pane Items
    m_pList->InsertColumn(COLUMN_PROJECT, _("Project"), wxLIST_FORMAT_LEFT, 109);
    m_pList->InsertColumn(COLUMN_TIME, _("Time"), wxLIST_FORMAT_LEFT, 130);
    m_pList->InsertColumn(COLUMN_MESSAGE, _("Message"), wxLIST_FORMAT_LEFT, 378);

    m_pMessageInfoAttr = new wxListItemAttr(
        wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT),
        wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW),
        wxNullFont
    );
    m_pMessageErrorAttr = new wxListItemAttr(
        *wxRED,
        wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW),
        wxNullFont
    );
#if EVENT_LOG_STRIPES
    m_pMessageInfoGrayAttr = new wxListItemAttr(
        wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT),
        wxColour(240, 240, 240),
        wxNullFont
    );
    m_pMessageErrorGrayAttr = new wxListItemAttr(*wxRED, wxColour(240, 240, 240), wxNullFont);
#else
    m_pMessageInfoGrayAttr = new wxListItemAttr(*m_pMessageInfoAttr);
    m_pMessageErrorGrayAttr = new wxListItemAttr(*m_pMessageErrorAttr);
#endif

    SetTextColor();
    RestoreState();

    return true;
}
Beispiel #4
0
void MCStack::realize()
{ //create window
	if (!MCnoui && MCModeMakeLocalWindows())
	{
		if ( getextendedstate(ECS_FULLSCREEN) )
		{
		//TS-2008-08-01 : [[Bug 5703 - fullscreen stack prop interacts badly with HideMenuBar]]
			if (!((MCScreenDC*)MCscreen)->getmenubarhidden())
				SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar);

			const MCDisplay *t_display;
			t_display = MCscreen -> getnearestdisplay(rect);
			MCRectangle t_workarea, t_viewport;
			t_workarea = t_display -> workarea;
			t_viewport = t_display -> viewport ;
			setrect(t_viewport);
		}
		else
		{
			if (!((MCScreenDC*)MCscreen)->getmenubarhidden())
				SetSystemUIMode(kUIModeNormal, NULL);
		}

		Rect wrect;
		MCScreenDC *psdc = (MCScreenDC *)MCscreen;
		psdc->MCRect2MacRect(rect, wrect);
		window = new _Drawable;
		window->type = DC_WINDOW;
		window->handle.window = 0;
		char *tmpname = NULL;
		const unsigned char *namePascal;
		if (!isunnamed())
		{ //set window title to name of stack temporarily.
			tmpname = strclone(getname_cstring()); //it will be changed by setname() later.
			namePascal = c2pstr(tmpname);
		}
		else
			namePascal = (unsigned char*)"\p";

		loadwindowshape();


		window->handle.window = NULL;
		uint32_t wclass;
		uint32_t wattributes;
		getWinstyle(wattributes,wclass);
		
		wattributes |= kWindowCompositingAttribute;

		long testdecorations = WD_TITLE | WD_MENU | WD_CLOSE | WD_MINIMIZE | WD_MAXIMIZE;

		if (m_window_shape != NULL)
		{
			static WindowDefUPP s_window_mask_proc = NULL;
			if (s_window_mask_proc == NULL)
				s_window_mask_proc = NewWindowDefUPP(WindowMaskProc);
			
			WindowDefSpec t_spec;
			t_spec . defType = kWindowDefProcPtr;
			t_spec . u . defProc = s_window_mask_proc;
			
			CreateCustomWindow(&t_spec, wclass, wattributes, &wrect, (WindowPtr *)&window -> handle . window);
			HIWindowChangeFeatures((WindowPtr)window -> handle . window, 0, kWindowIsOpaque);
		}
		else if (((flags & F_DECORATIONS && !(decorations & testdecorations))
		          || wclass == kPlainWindowClass))
		{
			static WindowDefUPP s_borderless_proc = NULL;
			if (s_borderless_proc == NULL)
				s_borderless_proc = NewWindowDefUPP(BorderlessWindowProc);
				
			WindowDefSpec t_spec;
			t_spec . defType = kWindowDefProcPtr;
			t_spec . u . defProc = s_borderless_proc;

			if (wclass == kPlainWindowClass)
				wclass = kUtilityWindowClass;

			CreateCustomWindow(&t_spec, wclass, wattributes, &wrect, (WindowPtr *)&window->handle.window);
		}
		else
			CreateNewWindow(wclass, wattributes,&wrect, (WindowPtr *)&window->handle.window);

		if (wclass == kFloatingWindowClass)
			ChangeWindowAttributes((WindowPtr)window -> handle . window, kWindowNoAttributes, kWindowHideOnSuspendAttribute);
		
		// MW-2009-10-31: Make sure we can collapse any rev window
		HIWindowChangeFeatures((WindowPtr)window -> handle . window, kWindowCanCollapse, 0);
		
		if (window->handle.window == NULL)
			SetWTitle((WindowPtr)window->handle.window, namePascal);
		SetWTitle((WindowPtr)window->handle.window, namePascal);
		setopacity(blendlevel * 255 / 100);
		SetWRefCon((WindowPtr)window->handle.window, mode);
		
		ControlRef t_control;
		MCRevolutionStackViewCreate(this, &t_control);
		ControlRef t_root_control;
		GetRootControl((WindowPtr)window -> handle . window, &t_root_control);
		HIViewAddSubview(t_root_control, t_control);
		ShowControl(t_control);
		
		if (wclass == kDrawerWindowClass)
		{
			Window pwindow = NULL;
			if (parentwindow != DNULL)
				pwindow = parentwindow;
			else
				if (MCdefaultstackptr && MCdefaultstackptr->getw() != DNULL )
					pwindow = MCdefaultstackptr->getw();
			if (pwindow && GetWRefCon((WindowPtr)pwindow->handle.window) != WM_DRAWER)
			{
				SetDrawerParent((WindowPtr)window->handle.window, (WindowPtr)pwindow->handle.window);
				WindowAttributes watt;
				GetWindowAttributes((WindowPtr)pwindow->handle.window,&watt);
				if (wattributes & kWindowResizableAttribute)
					ChangeWindowAttributes((WindowPtr)pwindow->handle.window, kWindowLiveResizeAttribute, 0);
				OptionBits draweredge;
				switch (wposition)
				{
				case WP_PARENTTOP:
					draweredge = kWindowEdgeTop;
					break;
				case WP_PARENTRIGHT:
					draweredge = kWindowEdgeRight;
					break;
				case WP_PARENTBOTTOM:
					draweredge = kWindowEdgeBottom;
					break;
				case WP_PARENTLEFT:
					draweredge = kWindowEdgeLeft;
					break;
				default:
					draweredge =  kWindowEdgeDefault;
					break;
				}
				SetDrawerPreferredEdge((WindowPtr)window->handle.window, draweredge);
				if (walignment)
				{
					MCRectangle parentwindowrect;
					MCscreen->getwindowgeometry(pwindow, parentwindowrect);
					int2 wspace = 0;
					RgnHandle r = NewRgn();
					GetWindowRegion((WindowPtr)window->handle.window, kWindowStructureRgn, r);
					Rect tRect;
					GetRegionBounds(r, &tRect);
					DisposeRgn(r);
					MCRectangle drawerwindowrect;
					psdc->MacRect2MCRect(tRect, drawerwindowrect);
					if (wposition == WP_PARENTTOP || wposition == WP_PARENTBOTTOM)
					{
						wspace = parentwindowrect.width - drawerwindowrect.width;
						if (watt & kWindowMetalAttribute)
							if (wspace)
								wspace += 10; //for metal
					}
					else
					{
						wspace = parentwindowrect.height - drawerwindowrect.height;
						if (watt & kWindowMetalAttribute)
							if (wspace)
								wspace += 5; //for metal
					}
					if (wspace > 0)
						switch (walignment)
						{
						case OP_CENTER:
							SetDrawerOffsets ((WindowPtr)window->handle.window,ceil(wspace/2) -1,floor(wspace/2) + 1);
							break;
						case OP_RIGHT:
						case OP_BOTTOM:
							SetDrawerOffsets ((WindowPtr)window->handle.window,wspace,0);
							break;
						case OP_TOP:
						case OP_LEFT:
							SetDrawerOffsets ((WindowPtr)window->handle.window,0,wspace);
							break;
						}
				}
			}
		}
		delete tmpname;


		// MW-2005-11-06: We also need to catch window constraining events so we can flush
		//   the screen geometry cache.
		EventTypeSpec list[] =
		{
		
			{kEventClassWindow, kEventWindowCollapsed},
			{kEventClassWindow, kEventWindowExpanded},
			{kEventClassMouse, kEventMouseWheelMoved},
			{kEventClassWindow, kEventWindowBoundsChanging},
			{kEventClassWindow, kEventWindowBoundsChanged},
			{kEventClassWindow, kEventWindowConstrain},
			{kEventClassWindow, kEventWindowFocusAcquired},
			{kEventClassWindow, kEventWindowFocusRelinquish},
			{kEventClassWindow, kEventWindowActivated},
			{kEventClassWindow, kEventWindowDeactivated},
			{kEventClassWindow, kEventWindowClose},
		};

		EventHandlerRef ref;
		
		// MW-2005-09-07: Pass the window handle as user data, otherwise 'takewindow' causes problems
		InstallWindowEventHandler((WindowPtr)window->handle.window, MCS_weh, sizeof(list) / sizeof(EventTypeSpec), list, (WindowPtr)window -> handle . window, &ref);
		
		ChangeWindowAttributes((WindowPtr)window->handle.window, 0, kWindowHideOnFullScreenAttribute);
		
		updatemodifiedmark();
	}
	start_externals();
}
Beispiel #5
0
OSStatus HIRevolutionStackViewHandler(EventHandlerCallRef p_call_ref, EventRef p_event, void *p_data)
{
	OSStatus t_status;
	t_status = eventNotHandledErr;
	
	UInt32 t_event_class;
	t_event_class = GetEventClass(p_event);
	
	UInt32 t_event_kind;
	t_event_kind = GetEventKind(p_event);
	
	HIRevolutionStackViewData *t_context;
	t_context = (HIRevolutionStackViewData *)p_data;
	
	switch(t_event_class)
	{
	case 'revo':
		switch(t_event_kind)
		{
			case 'rlnk':
				GetEventParameter(p_event, 'Stak', typeVoidPtr, NULL, sizeof(void *), NULL, &t_context -> stack);
			break;
		}
	break;
	
	case kEventClassHIObject:
		switch(t_event_kind)
		{
		case kEventHIObjectConstruct:
		{
			HIRevolutionStackViewData *t_data;
			t_data = new HIRevolutionStackViewData;
			t_data -> stack = NULL;
			GetEventParameter(p_event, kEventParamHIObjectInstance, typeHIObjectRef, NULL, sizeof(HIObjectRef), NULL, (HIObjectRef *)&t_data -> view);
			SetEventParameter(p_event, kEventParamHIObjectInstance, typeVoidPtr, sizeof(HIRevolutionStackViewData *), &t_data);
			t_status = noErr;
		}
		break;
		
		case kEventHIObjectInitialize:
		{
			GetEventParameter(p_event, 'Stak', typeVoidPtr, NULL, sizeof(void *), NULL, &t_context -> stack);
			
			Rect t_bounds;
			t_bounds . left = 0;
			// MW-2011-09-12: [[ MacScroll ]] Make sure the top of the HIView takes into
			//   account the scroll.
			t_bounds . top = -t_context -> stack -> getscroll();
			t_bounds . right = t_context -> stack -> getrect() . width;
			t_bounds . bottom = t_context -> stack -> getrect() . height;
			SetControlBounds((ControlRef)t_context -> view, &t_bounds);
			
			t_status = noErr;
		}
		break;
		
		case kEventHIObjectDestruct:
		{
			delete t_context;
			t_status = noErr;
		}
		break;
		}
	break;
	
	case kEventClassControl:
		switch(t_event_kind)
		{
		case kEventControlInitialize:
		{
			t_status = noErr;
		}
		break;
		
		case kEventControlDraw:
		{
			CGContextRef t_graphics;
			GetEventParameter(p_event, kEventParamCGContextRef, typeCGContextRef, NULL, sizeof(CGContextRef), NULL, &t_graphics);
			
			RgnHandle t_dirty_rgn;
			GetEventParameter(p_event, kEventParamRgnHandle, typeQDRgnHandle, NULL, sizeof(RgnHandle), NULL, &t_dirty_rgn);

			if (t_context -> stack != NULL)
			{
				// Compute the clip region for players.
				RgnHandle t_clip_rgn, t_rect_rgn;
				t_clip_rgn = NULL;
				t_rect_rgn = NULL;
				for(MCPlayer *t_player = MCplayers; t_player != NULL; t_player = t_player -> getnextplayer())
					if (t_player -> isvisible() && t_player -> getcard() == t_context -> stack -> getcurcard() && !t_player -> isbuffering())
					{
						MCRectangle t_rect;
						Rect t_mac_rect;
						
						t_rect = t_player -> getactiverect();
						
						if (t_clip_rgn == NULL)
						{
							t_clip_rgn = NewRgn();
							CopyRgn((RgnHandle)t_dirty_rgn, t_clip_rgn);
							t_rect_rgn = NewRgn();
						}
						
						SetRect(&t_mac_rect, t_rect . x, t_rect . y, t_rect . x + t_rect . width, t_rect . y + t_rect . height);
						RectRgn(t_rect_rgn, &t_mac_rect);
						DiffRgn(t_clip_rgn, t_rect_rgn, t_clip_rgn);
						
					}
				
				// We don't need the rect rgn anymore.
				if (t_rect_rgn != NULL)
					DisposeRgn(t_rect_rgn);

				// If the clip region is non-nil, then apply it.
				if (t_clip_rgn != NULL)
				{
					// As we can't clip to empty path, if the region is empty, we set the context
					// to nil.
					if (!EmptyRgn(t_clip_rgn))
					{
						HIShapeRef t_shape;
						t_shape = HIShapeCreateWithQDRgn(t_clip_rgn);
						HIShapeReplacePathInCGContext(t_shape, t_graphics);
						CGContextClip(t_graphics);
						CFRelease(t_shape);
					}
					else
						t_graphics = nil;
					DisposeRgn(t_clip_rgn);
				}

				// If the graphics context is non-nil (i.e. we aren't completely occluded) then
				// draw something.
				if (t_graphics != nil)
				{
					// HIView gives us a context in top-left origin mode which isn't so good
					// for our CG rendering so, revert back to bottom-left.
					CGContextScaleCTM(t_graphics, 1.0, -1.0);
					CGContextTranslateCTM(t_graphics, 0.0, -t_context -> stack -> getcurcard() -> getrect() . height);
					
					// Save the context state
					CGContextSaveGState(t_graphics);
					
					// If we don't have an update pixmap, then use redrawwindow.
					if (s_update_pixmap == nil)
					{
						MCMacStackSurface t_surface(t_context -> stack, (MCRegionRef)t_dirty_rgn, t_graphics);
						t_context -> stack -> redrawwindow(&t_surface, (MCRegionRef)t_dirty_rgn);
					}
					else
					{
						int32_t t_height;
						t_height = t_context -> stack -> getcurcard() -> getrect() . height;
						
						MCRectangle t_rect;
						t_rect = MCRegionGetBoundingBox((MCRegionRef)t_dirty_rgn);
						
						CGRect t_area;
						t_area = CGRectMake(t_rect . x, t_height - (t_rect . y + t_rect . height), t_rect . width, t_rect . height);
						
						CGContextClearRect(t_graphics, t_area);

						void *t_bits;
						uint32_t t_stride;
						MCscreen -> lockpixmap(s_update_pixmap, t_bits, t_stride);
						MCMacRenderBitsToCG(t_graphics, t_area, t_bits, t_stride, t_context -> stack -> getwindowshape() != nil ? true : false);
						MCscreen -> unlockpixmap(s_update_pixmap, t_bits, t_stride);
					}

					// Restore the context state
					CGContextRestoreGState(t_graphics);
				}
				
				// MW-2011-11-23: [[ Bug ]] Force a redraw of the players on the stack
				//   after we've drawn the rest of the content. This ensures players
				//   which are just appearing don't disappear behind said content.
				for(MCPlayer *t_player = MCplayers; t_player != NULL; t_player = t_player -> getnextplayer())
					if (t_player -> isvisible() && t_player -> getcard() == t_context -> stack -> getcurcard() && !t_player -> isbuffering())
						MCDoAction((MovieController)t_player -> getMovieController(), mcActionDraw, t_context -> stack -> getqtwindow());
			}
			
			t_status = noErr;
		}
		break;
		
		case kEventControlHitTest:
		break;
		
		case kEventControlGetPartRegion:
		{
			ControlPartCode t_part;
			GetEventParameter(p_event, kEventParamControlPart, typeControlPartCode, NULL, sizeof(ControlPartCode), NULL, &t_part);
			
			RgnHandle t_region;
			GetEventParameter(p_event, kEventParamControlRegion, typeQDRgnHandle, NULL, sizeof(RgnHandle), NULL, &t_region);
		}
		break;
		
		case kEventControlHiliteChanged:
		break;
		
		case kEventControlActivate:
		break;
		
		case kEventControlDeactivate:
		break;
		}
	break;
	}

	return t_status;
}
Beispiel #6
0
void LCD_drawTxt(Lcd *x, char *stng)     /* drawn in response to update event */
{
	GrafPort *gp;
	short		chars;
	Rect	r,area;
	PaletteHandle pH;
	RGBColor fColor;
	RgnHandle cur;
	short		font,size;
	
	gp = patcher_setport(x->lcd_box.b_patcher);
	if (gp) {
		font = gp->txFont;
		size = gp->txSize;
		r = x->lcd_box.b_rect;
		if (x->f_width == -1) { /* window not visible before */
			if (!x->font && !x->f_size) {
				x->font = font;
				x->f_size = size;
			}
			LCD_calcfont(x);
			LCD_resize(x);
		}
		TextFont(x->font);
		TextSize(x->f_size);

		if ((x->lcd_row+1)<=x->rows) {
			if (!box_nodraw((void *)x)) {
				/* chars = x->cols-x->lcd_col;  DDZ removed this stuff */
				if (/* chars > 0 */ 1) {
#ifdef never
					MoveTo(	(x->lcd_col*x->f_width)+r.left+BORDER_WIDTH,
							(x->lcd_row+1)*x->f_height+(x->lcd_row)*x->f_lineSpace+r.top-x->f_descent);

					/* erase area where we will write */
					area.top = (x->lcd_row*x->f_height)+r.top+BORDER_HEIGHT;
					area.bottom = ((x->lcd_row+1)*x->f_height)+r.top+BORDER_HEIGHT;
					area.left = (x->lcd_col*x->f_width)+r.left+BORDER_WIDTH;
					area.right = ((x->lcd_col+chars)*x->f_width)+r.left+BORDER_WIDTH;
#else
					MoveTo(x->lcd_where.h+r.left+BORDER_WIDTH,x->lcd_where.v+r.top);
#endif
					/* chars = MIN(chars,(short)strlen(stng)); */
					chars = strlen(stng);  /* DDZ just made it draw any string */
					
					cur = NewRgn();
					GetClip(cur);
					SetClip(x->lcd_region);
#ifdef never
					EraseRect(&area);
#endif
					setUpPalette(x,&fColor,&pH);

					DrawText(stng,0,chars);
					x->lcd_where.h += TextWidth(stng,0,chars);
					restorePalette(x,&fColor,&pH);
					SetClip(cur);
					DisposeRgn(cur);
					x->lcd_col += chars;		/* advance cursor */
					if (x->lcd_col > x->cols-1 )
						x->lcd_col--;			/* make it stick to last col */
				}
			}
		}
		TextFont(font);
		TextSize(size);

		SetPort(gp);
	}
}
Beispiel #7
0
void LCD_doreson(Lcd *x, Symbol *s, short argc, Atom *argv)
{
	short i,x1,y1,y2,height,width;
	double	freq,ampl,band;
	Rect	r;
	PaletteHandle pH;
	RGBColor fColor;
	GrafPort *gp;
	RgnHandle cur;
	Rect	 b;
	double xscale;
	double bscale;
	double yscale;				
	
	EnterCallback();

	if((argc%3)!=0)
	{
		post("bad number of resonance parameters %d", argc);
	} else {
		gp = patcher_setport(x->lcd_box.b_patcher);

		if (gp) {
			if (!box_nodraw((void *)x)) {
				cur = NewRgn();
				GetClip(cur);
				SetClip(x->lcd_region);
				setUpPalette(x,&fColor,&pH);
				
				r = x->lcd_box.b_rect;
				width	= r.right-r.left;
				height	= r.bottom-r.top;
				xscale=width/(x->reson_sampleRate);
				bscale = (0.1*height);
				yscale = height/x->reson_spectScale;
				for (i=0;i<argc;i++)
				{
					freq = (double)argv[i].a_w.w_float;
					ampl =argv[++i].a_w.w_float;
					if(ampl<0.0f)
						ampl = -ampl;
					ampl = 20.0*log10(ampl);
					band = (double)argv[++i].a_w.w_float;
					if(freq>0.0 && freq<(x->reson_sampleRate)	&& band>0.0)
					{
						x1 = (freq*xscale);
						{
							float ydisp = ampl*yscale;
							if(ydisp>(r.bottom-r.top))
								y1 = r.bottom -r. top;
							else
								y1= ydisp;
						}
						y2 = bscale*3.1415926/sqrt(MINMAX(band,0.1,40.0));
				
						if (x->lcd_debug)
							post("x1: %d y1: %d y2: %d",x1,y1,y2);
								
						MoveTo(r.left+x1,r.top+y1);
						Line(0,y2);
					}
				}
		
				restorePalette(x,&fColor,&pH);
				SetClip(cur);
				DisposeRgn(cur);
			}
			SetPort(gp);
		}
	
	}
	ExitCallback();
}