Esempio n. 1
0
File: ugView.c Progetto: rolk/ug
static int CreateApplicationWindow (AWindowRecord *wr, char *fname, short h, short v, short dh, short dv)
{
  Rect r;
  GrafPtr myPort;
  PaletteHandle myPalette;
  char name[80];

  /* init AWindowRecord */
  wr->theWindow = (WindowPtr) wr;

  /* read in resources */
  if (GetNewCWindow(appWinId,(Ptr)wr,(WindowPtr) -1)==NULL)
  {
    return(1);
  }
  myPalette = GetNewPalette(defaultPaletteId);
  SetPalette(wr->theWindow,myPalette,false);

  /* move and size window */
  myPort = (GrafPtr) wr->theWindow;
  SetPort(myPort);
  MoveWindow(wr->theWindow,h,v,false);
  SizeWindow(wr->theWindow,dh+15,dv+15,false);
  strcpy(name,fname);
  SetWTitle(wr->theWindow,c2pstr(name));
  ShowWindow(wr->theWindow);
  SelectWindow(wr->theWindow);
  DrawGrowIcon(wr->theWindow);
  r = myPort->portRect;

  TextFont(kFontIDMonaco);

  /* get the scroll bars */
  wr->vScrollBar = GetNewControl(vScrollBarId,wr->theWindow);
  wr->hScrollBar = GetNewControl(hScrollBarId,wr->theWindow);

  /* set correct size of the scroll bars */
  MoveControl(wr->vScrollBar,r.right-15,-1);
  SizeControl(wr->vScrollBar,16,r.bottom-13);
  SetControlMinimum(wr->vScrollBar,0);
  SetControlMaximum(wr->vScrollBar,0);
  SetControlValue(wr->vScrollBar,0);
  ShowControl(wr->vScrollBar);
  MoveControl(wr->hScrollBar,-1,r.bottom-15);
  SizeControl(wr->hScrollBar,r.right-13,16);
  SetControlMinimum(wr->hScrollBar,0);
  SetControlMaximum(wr->hScrollBar,0);
  SetControlValue(wr->hScrollBar,0);
  ShowControl(wr->hScrollBar);
  DrawControls(wr->theWindow);

  SetRect(&(wr->usableRect),0,0,dh,dv);

  return(0);
}
Esempio n. 2
0
/*
 * For some reason, LNew doesn't seem to respect the hasGrow
 * parameter, so we hammer the scrollbar into shape ourselves.
 */
static void mac_adjusteventlogscrollbar(Session *s)
{
#if TARGET_API_MAC_CARBON
    Rect winrect;

    GetPortBounds(GetWindowPort(s->eventlog_window), &winrect);
    SizeControl(GetListVerticalScrollBar(s->eventlog),
		16, winrect.bottom - 13);
#else
    SizeControl((*s->eventlog)->vScroll,
		16, s->eventlog_window->portRect.bottom - 13);
#endif
}
Esempio n. 3
0
/* set the controls in the TextEdit window correctly
 */
void NATEsetscroll(na_win *winp, Boolean moved, Rect *hrect, Rect *vrect)
{
	short		vmax, vvalue, hmax, hvalue;
	TEPtr		te = *teinfo->hTE;
	ControlHandle	vctrl, hctrl;
		

	vmax = te->nLines + (*(*te->hText + te->teLength - 1) == '\015' ? 1 : 0)
		- (te->viewRect.bottom - te->viewRect.top) / teinfo->lheight;
	hmax = (short) teinfo->docwidth - (te->viewRect.right - te->viewRect.left);
	if (vmax < 0) vmax = 0;
	if (hmax < 0) hmax = 0;
	vvalue = (te->viewRect.top - te->destRect.top) / teinfo->lheight;
	hvalue = te->viewRect.left - te->destRect.left;
	if (!(winp->flags & NATE_NOVSCROLL)) {
		if (teinfo->vctrl == (ControlHandle) NULL) {
			teinfo->vctrl = NewControl(winp->pwin, vrect, "\p", true, vvalue, 0, vmax,
				scrollBarProc, 0);
			if (winp->pwin != FrontWindow()) HiliteControl(teinfo->vctrl, 255);
		} else {
			if (vvalue < 0) vvalue = 0;
			if (vvalue > vmax) vvalue = vmax;
			SetCtlMax(vctrl = teinfo->vctrl, vmax);
			SetCtlValue(vctrl, vvalue);
			if (moved) {
				MoveControl(vctrl, vrect->left, vrect->top);
				SizeControl(vctrl, vrect->right - vrect->left,
					vrect->bottom - vrect->top);
				ShowControl(vctrl);
			}
		}
	}
	if (!(winp->flags & NATE_NOHSCROLL)) {
		if (teinfo->hctrl == (ControlHandle) NULL) {
			teinfo->hctrl = NewControl(winp->pwin, hrect, "\p", true, hvalue, 0, hmax,
				scrollBarProc, 0);
			if (winp->pwin != FrontWindow()) HiliteControl(teinfo->hctrl, 255);
		} else {
			if (hvalue < 0) hvalue = 0;
			if (hvalue > hmax) hvalue = hmax;
			SetCtlMax(hctrl = teinfo->hctrl, hmax);
			SetCtlValue(hctrl, hvalue);
			if (moved) {
				MoveControl(hctrl, hrect->left, hrect->top);
				SizeControl(hctrl, hrect->right - hrect->left,
					hrect->bottom - hrect->top);
				ShowControl(hctrl);
			}
		}
	}
}
Esempio n. 4
0
static void window_adjust_scrollbars(WindowRef windowRef)
{
    IMAGE *img;
    Rect   portRect;

    img = (IMAGE*)GetWRefCon(windowRef);
    GetWindowPortBounds(windowRef,&portRect);

    /* Move the crollbars to the edges of the window */
    HideControl(img->scrollbarVertRef);
    HideControl(img->scrollbarHorizRef);

    MoveControl(img->scrollbarVertRef,portRect.right - kScrollBarWidth,
                portRect.top - 1);
    MoveControl(img->scrollbarHorizRef,portRect.left - 1,
                portRect.bottom - kScrollBarWidth);

    SizeControl(img->scrollbarVertRef,kScrollBarWidth + 1,
                portRect.bottom - portRect.top - kScrollBarWidth + 1);
    SizeControl(img->scrollbarHorizRef, portRect.right - portRect.left - kScrollBarWidth + 1,
                kScrollBarWidth + 1);

    /* Adjust the scroll position showing */
    if (img->pixmapHdl)
    {
        PixMap *pixmap = *(img->pixmapHdl);
        int visibleHeight = portRect.bottom - portRect.top - kScrollBarWidth;
        int visibleWidth = portRect.right - portRect.left - kScrollBarWidth;

        if (pixmap->bounds.bottom > visibleHeight)
        {
            SetControl32BitMaximum(img->scrollbarVertRef,
                                   pixmap->bounds.bottom - visibleHeight);
            SetControlViewSize(img->scrollbarVertRef,visibleHeight);
        }
        else
            SetControlMaximum(img->scrollbarVertRef, 0);

        if (pixmap->bounds.right > visibleWidth)
        {
            SetControl32BitMaximum(img->scrollbarHorizRef,
                                   pixmap->bounds.right - visibleWidth);
            SetControlViewSize(img->scrollbarHorizRef, visibleWidth);
        }
        else
            SetControlMaximum(img->scrollbarHorizRef, 0);
    }

    ShowControl(img->scrollbarVertRef);
    ShowControl(img->scrollbarHorizRef);
}
Esempio n. 5
0
void	AUControlGroup::AddAUInfo (		AUCarbonViewBase *			auView,
										const Point &				inLocation,
										const SInt16 				inRightOffset,
										const SInt16				inTotalWidth)
{
#if !__LP64__
   // get component info
	ComponentDescription desc;
    Handle h1 = NewHandleClear(4);
	OSStatus err = GetComponentInfo ((Component)auView->GetEditAudioUnit(), &desc, h1, 0, 0);

    if (err == noErr) {
        // Get the manufacturer's name... look for the ':' character convention
        HLock(h1);
        char* ptr1 = *h1;
        int len = *ptr1++;
        char* displayStr = 0;

        for (int i = 0; i < len; ++i) {
            if (ptr1[i] == ':') { // found the name
                ptr1[i++] = 0;
                displayStr = ptr1;
                break;
            }
        }

        // localize as necessary:
        if (!sLocalized) {
            CFBundleRef mainBundle = CFBundleGetBundleWithIdentifier(kLocalizedStringBundle_AUView);
            if (mainBundle) {
                kStringManufacturer = CFCopyLocalizedStringFromTableInBundle(
                                            kAUViewLocalizedStringKey_Manufacturer, kLocalizedStringTable_AUView,
                                            mainBundle, CFSTR("Manufacturer title string"));
                sLocalized = true;
            }
        }

        // display strings
        ControlRef newControl;
        Rect r;
        r.top = SInt16(inLocation.v);		r.bottom = SInt16(inLocation.v) + 16;
        ControlFontStyleRec fontStyle;
        fontStyle.flags = kControlUseFontMask | kControlUseJustMask;
        fontStyle.font = kControlFontSmallBoldSystemFont;

        // display manufacturer string
        if (displayStr) {
            CFMutableStringRef mfrstring = CFStringCreateMutable(NULL, 0);
            CFStringAppend(mfrstring, kStringManufacturer);		// "Manufacturer"
            CFStringAppend(mfrstring, kAUViewUnlocalizedString_TitleSeparator);
                                                                // "Manufacturer: "
            CFStringRef mfrname = CFStringCreateWithCString(NULL, displayStr, kCFStringEncodingUTF8);
            if (mfrname) {
                CFStringAppend(mfrstring, mfrname);	// "Manufacturer: MFRName"
                CFRelease (mfrname);
            }

            r.left = inLocation.h + inRightOffset;
			r.right = inLocation.h + inTotalWidth - 28;
			fontStyle.just = teFlushRight;

            verify_noerr(CreateStaticTextControl(auView->GetCarbonWindow(), &r, mfrstring, &fontStyle, &newControl));
            verify_noerr(auView->EmbedControl(newControl));
            CFRelease (mfrstring);

            //move displayStr ptr past the manu, to the name
            // we move the characters down an index, because the handle doesn't have any room
            // at the end for the \0
			int i = strlen(displayStr), j = 0;
			while (displayStr[++i] == ' ' && i < len)
				;
			while (i < len)
				displayStr[j++] = displayStr[i++];
			displayStr[j] = 0;
        } else {
			displayStr = ptr1;
			int i = 0, j = 0;
			do {
				displayStr[j] = displayStr[i];
				++j; ++i;
			} while (i < len);

			displayStr[j] = 0;
        }

        // display AudioUnit string
        r.left = inLocation.h;	r.right = r.left + inRightOffset;
        fontStyle.just = 0;

        CFMutableStringRef cfstr = CFStringCreateMutable(NULL, 0);
        CFStringAppend(cfstr, kAUViewLocalizedStringKey_AudioUnit);		// "Audio Unit"
        CFStringAppend(cfstr, kAUViewUnlocalizedString_TitleSeparator);
                                                        // "Audio Unit: "

		CFStringRef auname = CFStringCreateWithCString(NULL, displayStr, kCFStringEncodingUTF8);
		CFStringAppend(cfstr, auname);				// "Audio Unit: AUName"
		CFRelease (auname);

        verify_noerr(CreateStaticTextControl(auView->GetCarbonWindow(), &r, cfstr, &fontStyle, &newControl));

		// size text control correctly
		Boolean bValue = false;
		SetControlData(newControl, kControlEntireControl, 'stim' /* kControlStaticTextIsMultilineTag */, sizeof(Boolean), &bValue);
		SInt16 baseLineOffset;
		Rect bestRect;
		err = GetBestControlRect(newControl, &bestRect, &baseLineOffset);
		if (err == noErr)
		{
			int width = (bestRect.right - bestRect.left) + 1;
			int height = (bestRect.bottom - bestRect.top) + 1;
			SizeControl (newControl, width, height);
		}

        verify_noerr(auView->EmbedControl(newControl));
        CFRelease (cfstr);
    }

	DisposeHandle (h1);
#endif
}
OSStatus			AUCarbonViewBase::CreateCarbonView(AudioUnit inAudioUnit, WindowRef inWindow, ControlRef inParentControl, const Float32Point &inLocation, const Float32Point &inSize, ControlRef &outParentControl)
{
#if !__LP64__
	mEditAudioUnit = inAudioUnit;
	mCarbonWindow = inWindow;

	WindowAttributes attributes;
	verify_noerr(GetWindowAttributes(mCarbonWindow, &attributes));
	mCompositWindow = (attributes & kWindowCompositingAttribute) != 0;

	Rect area;
	area.left = short(inLocation.x); area.top = short(inLocation.y);
	area.right = short(area.left + inSize.x); area.bottom = short(area.top + inSize.y);
	OSStatus err = ::CreateUserPaneControl(inWindow, &area, 
						kControlSupportsEmbedding,
						&mCarbonPane);	// subclass can resize mCarbonPane to taste
	verify_noerr(err);
	if (err) return err;
	outParentControl = mCarbonPane;
	
	// register for mouse-down in our pane -- we want to clear focus
	EventTypeSpec paneEvents[] = {
		{ kEventClassControl, kEventControlClick }
	};
	WantEventTypes(GetControlEventTarget(mCarbonPane), GetEventTypeCount(paneEvents), paneEvents);
	
	if (IsCompositWindow()) {
		verify_noerr(::HIViewAddSubview(inParentControl, mCarbonPane));
		mXOffset = 0;
		mYOffset = 0;
	}
	else {
		verify_noerr(::EmbedControl(mCarbonPane, inParentControl));
		mXOffset = inLocation.x;
		mYOffset = inLocation.y;
	}
	mBottomRight.h = mBottomRight.v = 0;
	
	SizeControl(mCarbonPane, 0, 0);
	if (err = CreateUI(mXOffset, mYOffset))
		return err;

	// we should only resize the control if a subclass has embedded
	// controls in this AND this is done with the EmbedControl call below
	// if mBottomRight is STILL equal to zero, then that wasn't done
	// so don't size the control
	Rect paneBounds;
	GetControlBounds(mCarbonPane, &paneBounds);
	// only resize mCarbonPane if it has not already been resized during CreateUI
	if ((paneBounds.top == paneBounds.bottom) && (paneBounds.left == paneBounds.right)) {
		if (mBottomRight.h != 0 && mBottomRight.v != 0)
			SizeControl(mCarbonPane, (short) (mBottomRight.h - mXOffset), (short) (mBottomRight.v - mYOffset));
	}

	if (IsCompositWindow()) {
		// prepare for handling scroll-events
		EventTypeSpec scrollEvents[] = {
			{ kEventClassScrollable, kEventScrollableGetInfo },
			{ kEventClassScrollable, kEventScrollableScrollTo }
		};
		
		WantEventTypes(GetControlEventTarget(mCarbonPane), GetEventTypeCount(scrollEvents), scrollEvents);
	
		mCurrentScrollPoint.x = mCurrentScrollPoint.y = 0.0f;
	}
	
	return err;
#else
	return noErr;
#endif
}
Esempio n. 7
0
static pascal OSStatus windowEventHandler(EventHandlerCallRef nextHandler, EventRef theEvent, void *inUserData)
{
    CvWindow* window = NULL;
    UInt32 eventKind, eventClass;
    OSErr err = noErr;
    int event = 0;
    UInt32 count = 0;
    HIPoint point = {0,0};
    EventMouseButton eventMouseButton = 0;//FD
    UInt32 modifiers;//FD
    
    WindowRef theWindow = (WindowRef)inUserData;
    if (theWindow == NULL)
        return eventNotHandledErr;
    window = icvWindowByHandle(theWindow);
    if ( window == NULL)
        return eventNotHandledErr;
    
    eventKind = GetEventKind(theEvent);
    eventClass = GetEventClass(theEvent);
        
    switch (eventClass) {
    case kEventClassMouse : {
        switch (eventKind){
        case kEventMouseUp :
        case kEventMouseDown : 
        case kEventMouseMoved : {
            err = CallNextEventHandler(nextHandler, theEvent);
            if (err != eventNotHandledErr)
                return err;
            err = GetEventParameter(theEvent, kEventParamMouseButton, typeMouseButton, NULL, sizeof(eventMouseButton), NULL, &eventMouseButton);
            err = GetEventParameter(theEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(modifiers), NULL, &modifiers);
            err = GetEventParameter(theEvent,kEventParamClickCount,typeUInt32,NULL,sizeof(UInt32),NULL,&count);
            if (err == noErr){
                if (count >1) event += 6;
            } else {
                event = CV_EVENT_MOUSEMOVE;
            }
            
            if (eventKind == kEventMouseUp)
                event +=4;
            if (eventKind == kEventMouseDown)
                event +=1;
            
            err = GetEventParameter(theEvent, kEventParamWindowMouseLocation, typeHIPoint, NULL, sizeof(point), NULL, &point);
            if (eventKind != kEventMouseMoved){
                switch(eventMouseButton){
                    case kEventMouseButtonPrimary:
                        if (modifiers & controlKey) /* ctrl-click for right button */
                            event += 1;
                        break;
                    case kEventMouseButtonSecondary:
                        event += 1;
                        break;
                    case kEventMouseButtonTertiary:
                        event += 2;
                        break;
                }
            }
            int c = icvCountTrackbarInWindow(window);
            
            if (window->on_mouse != NULL){
                int lx,ly;
                Rect structure, content;
                GetWindowBounds(theWindow, kWindowStructureRgn, &structure);
                GetWindowBounds(theWindow, kWindowContentRgn, &content);
                lx = point.x - content.left + structure.left;
                ly = point.y - window->trackbarheight  - content.top + structure.top; /* minus la taille des trackbars */
                if (window->flags & CV_WINDOW_AUTOSIZE) {//FD
                                                         //printf("was %d,%d\n", lx, ly);
                    /* scale the mouse coordinates */
                    lx = lx * window->imageWidth / (content.right - content.left);
                    ly = ly * window->imageHeight / (content.bottom - content.top - window->trackbarheight);
                    //printf("now %d,%d\n", lx, ly);
                }
                //fprintf(stdout,"final OpenCV event is %d\n",event);
                //fprintf(stdout,"event @ %d %d which is localy %d %d offset of %d\n",point.h, point.v ,lx,ly,yOffset);
                if (lx>0 && ly >0){ /* a remettre dans les coordonnŽes locale */
                    window->on_mouse(event,lx,ly,0,NULL);
                }
            }
        }
        default : return eventNotHandledErr;
        }
    }
    case kEventClassWindow : {//FD
        switch (eventKind){
        case kEventWindowBoundsChanged :
        {
            /* resize the trackbars */
            CvTrackbar *t;
            Rect bounds;
            GetWindowBounds(window->window,kWindowContentRgn,&bounds);
            for ( t = window->toolbar.first; t != 0; t = t->next )
                SizeControl(t->trackbar,bounds.right - bounds.left - INTERWIDGETSPACE*3 - LABELWIDTH , WIDGETHEIGHT); 
        }
            /* redraw the image */
            icvDrawImage(window);
            break;
        default :
            return eventNotHandledErr;
        }
    }
    default:
        return eventNotHandledErr;
    }

    return eventNotHandledErr;
}
Esempio n. 8
0
IGraphicsCarbon::IGraphicsCarbon(IGraphicsMac* pGraphicsMac,
                                 WindowRef pWindow,
                                 ControlRef pParentControl,
                                 short leftOffset,
                                 short topOffset)
  : mGraphicsMac(pGraphicsMac)
  , mWindow(pWindow)
  , mView(0)
  , mTimer(0)
  , mControlHandler(0)
  , mWindowHandler(0)
  , mCGC(0)
  , mTextEntryView(0)
  , mTextEntryHandler(0)
  , mEdControl(0)
  , mEdParam(0)
  , mPrevX(0)
  , mPrevY(0)
//, mRgn(NewRgn())
  , mLeftOffset(leftOffset)
  , mTopOffset(topOffset)
{
  TRACE;

  Rect r;   // Client.
  r.left = r.top = 0;
  r.right = pGraphicsMac->Width();
  r.bottom = pGraphicsMac->Height();

  WindowAttributes winAttrs = 0;
  GetWindowAttributes(pWindow, &winAttrs);
  mIsComposited = (winAttrs & kWindowCompositingAttribute);

  UInt32 features =  kControlSupportsFocus | kControlHandlesTracking | kControlSupportsEmbedding;

  if (mIsComposited)
  {
    features |= kHIViewIsOpaque | kHIViewFeatureDoesNotUseSpecialParts;
  }

  CreateUserPaneControl(pWindow, &r, features, &mView);

  const EventTypeSpec controlEvents[] =
  {
    { kEventClassControl, kEventControlDraw },
  };

  InstallControlEventHandler(mView, MainEventHandler, GetEventTypeCount(controlEvents), controlEvents, this, &mControlHandler);

  const EventTypeSpec windowEvents[] =
  {
    { kEventClassMouse, kEventMouseDown },
    { kEventClassMouse, kEventMouseUp },
    { kEventClassMouse, kEventMouseMoved },
    { kEventClassMouse, kEventMouseDragged },
    { kEventClassMouse, kEventMouseWheelMoved },

    { kEventClassKeyboard, kEventRawKeyDown },

    { kEventClassWindow, kEventWindowDeactivated }
  };

  InstallWindowEventHandler(mWindow, MainEventHandler, GetEventTypeCount(windowEvents), windowEvents, this, &mWindowHandler);

  double t = kEventDurationSecond / (double) pGraphicsMac->FPS();

  OSStatus s = InstallEventLoopTimer(GetMainEventLoop(), 0., t, TimerHandler, this, &mTimer);

  if (mIsComposited)
  {
    if (!pParentControl)
    {
      HIViewRef hvRoot = HIViewGetRoot(pWindow);
      s = HIViewFindByID(hvRoot, kHIViewWindowContentID, &pParentControl);
    }

    s = HIViewAddSubview(pParentControl, mView);
  }
  else
  {
    if (!pParentControl)
    {
      if (GetRootControl(pWindow, &pParentControl) != noErr)
      {
        CreateRootControl(pWindow, &pParentControl);
      }
    }
    s = EmbedControl(mView, pParentControl);
  }

  if (s == noErr)
  {
    SizeControl(mView, r.right, r.bottom);  // offset?
  }
}
Esempio n. 9
0
OSStatus ElCAJASView::CreateUI(Float32 xoffset, Float32 yoffset) {

    int xoff = (int)xoffset;
    int yoff = (int)yoffset;
    
        	
#define kLabelWidth 80
#define kLabelHeight 18
#define kEditTextWidth 40
#define kMinMaxWidth 45
	ControlRef newControl;
	ControlFontStyleRec fontStyle;
	fontStyle.flags = kControlUseFontMask | kControlUseJustMask;
	fontStyle.font = kControlFontSmallSystemFont;
	fontStyle.just = teFlushRight;
	
	Rect r;
	Point labelSize, textSize;
	labelSize.v = textSize.v = kLabelHeight;
	labelSize.h = kMinMaxWidth;
	textSize.h = kEditTextWidth;
	
	
        
	
	{
		AUVParameter auvp(mEditAudioUnit, kDryLevel, kAudioUnitScope_Global, 0);
		
		r.top = 10 + yoff;
        r.bottom = r.top + kLabelHeight;
		r.left = 10;
        r.right = r.left + kLabelWidth;
		verify_noerr(CreateStaticTextControl(mCarbonWindow, &r, auvp.GetName(), &fontStyle, &newControl));
                
	}

         {
		
		r.top = 50 + yoff;
        r.bottom = r.top + 80;
		r.left = xoff;
        r.right = r.left + 350;
		verify_noerr(CreateStaticTextControl(mCarbonWindow, &r, CFSTR("Johnny Petrantoni JACK-insert, (c) 2003 - 2004.    ") , &fontStyle, &newControl));
		verify_noerr(EmbedControl(newControl));
		r.top = 75 + yoff;
        r.bottom = r.top + 80;
		r.left = xoff;
        r.right = r.left + 350;
		verify_noerr(CreateStaticTextControl(mCarbonWindow, &r, CFSTR("[email protected]    ") , &fontStyle, &newControl));
		verify_noerr(EmbedControl(newControl));
		r.top = 100 + yoff;
        r.bottom = r.top + 80;
		r.left = xoff;
        r.right = r.left + 350;
		verify_noerr(CreateStaticTextControl(mCarbonWindow, &r, CFSTR("http://www.jackosx.com/    ") , &fontStyle, &newControl));
		verify_noerr(EmbedControl(newControl));

		
	}
        
            
        
	
	
	SizeControl(mCarbonPane, mBottomRight.h + 15, mBottomRight.v - 30);
	return noErr;

}
Esempio n. 10
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//	AUMixer3DView::CreateUI
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
OSStatus	AUMixer3DView::CreateUI(Float32	inXOffset, Float32 	inYOffset)
{
	EventHandlerUPP  handlerUPP = NewEventHandlerUPP(MyEventHandlerDispatch);

	EventTypeSpec    eventTypes[] =
	{
		{kEventClassKeyboard, kEventRawKeyDown},
		{kEventClassKeyboard, kEventRawKeyRepeat},
		{kEventClassMouse, kEventMouseDown},
		{kEventClassMouse, kEventMouseUp},
		{kEventClassMouse, kEventMouseDragged},
		{kEventClassCommand, kEventCommandProcess},
		
		{kEventClassWindow, kEventWindowDrawContent},
		
		{kEventClassWindow, kEventWindowUpdate},
		
	};


	SizeControl(mCarbonPane, 400, 400);

	InstallWindowEventHandler( GetCarbonWindow(), handlerUPP, sizeof(eventTypes) / sizeof(EventTypeSpec), eventTypes, this, NULL);

	RGBColor color1;
	color1.red = 65535;
	color1.green = 0;
	color1.blue = 0;
	gTrackers[0] = new TrackingLine(color1, (int)inXOffset, (int)inYOffset, 400, 400);

	RGBColor color2;
	color2.red = 0;
	color2.green = 65535;
	color2.blue = 0;
	gTrackers[1]  = new TrackingLine(color2, (int)inXOffset, (int)inYOffset, 400, 400);
        
	RGBColor color3;
	color3.red = 0;
	color3.green = 0;
	color3.blue = 65535;
	gTrackers[2]  = new TrackingLine(color3, (int)inXOffset, (int)inYOffset, 400, 400);
        
	RGBColor color4;
	color4.red = 20000;
	color4.green = 20000;
	color4.blue = 20000;
	gListener  = new TrackingLine(color4, (int)inXOffset, (int)inYOffset, 400, 400);
	gListener->ScaleDistance(0.0);
	
	
	mOffsetX = (int)inXOffset;
	mOffsetY = (int)inYOffset;

	SetRenderingFlagsCheckboxes();


	UInt32 algo;
	UInt32 size = sizeof(algo);
	AudioUnitGetProperty(
		GetEditAudioUnit(),
		kAudioUnitProperty_SpatializationAlgorithm,
		kAudioUnitScope_Input,
		0,
		&algo,
		&size );

	SetRenderingAlgorithmControl(algo);

	mBackgroundColor.red = 50000;
	mBackgroundColor.green = 50000;
	mBackgroundColor.blue = 50000;
	
	TrackingLine::SetBackgroundColor(mBackgroundColor );
	
	mIsTrackingMouse = false;

	
	EventLoopTimerUPP timerUPP = ::NewEventLoopTimerUPP(MixerTimerProc);

//printf("timerUPP = %x\n", timerUPP );
	
	EventLoopTimerRef timerRef;
	EventLoopRef mainEventLoop = GetMainEventLoop();

//printf("mainEventLoop = %x\n", mainEventLoop);
//printf("this = %x\n", (int)this );

gAUMixer3DView = this;
	
	OSStatus timerResult =  ::InstallEventLoopTimer(
									mainEventLoop,
									0.005 /* delay */,
									0.020 /* interval */,
									timerUPP,
									this,
									&timerRef );                       

//printf("timerResult = %d\n", timerResult );
//printf("timerRef = %x\n", timerRef );
  
	return timerResult;
}
Esempio n. 11
0
int FileDialog::ShowModal()
{
   OSErr err;
   NavDialogCreationOptions dialogCreateOptions;
   // set default options
   ::NavGetDefaultDialogCreationOptions(&dialogCreateOptions);
   
   // this was always unset in the old code
   dialogCreateOptions.optionFlags &= ~kNavSelectDefaultLocation;
   
   wxMacCFStringHolder message(m_message, GetFont().GetEncoding());
   dialogCreateOptions.windowTitle = message;
   
   wxMacCFStringHolder defaultFileName(m_fileName, GetFont().GetEncoding());
   dialogCreateOptions.saveFileName = defaultFileName;
   
   NavDialogRef dialog;
   NavObjectFilterUPP navFilterUPP = NULL;
   CustomData myData;
   
   SetRect(&myData.bounds, 0, 0, 0, 0);
   myData.me = this;
   myData.window = NULL;
   myData.defaultLocation = m_dir;
   myData.userpane = NULL;
   myData.choice = NULL;
   myData.button = NULL;
   myData.saveMode = false;
   myData.showing = true;
   
   Rect r;
   SInt16 base;
   SInt16 margin = 3;
   SInt16 gap = 0;
   
   MakeUserDataRec(&myData , m_wildCard);
   myData.currentfilter = m_filterIndex;
   size_t numFilters = myData.extensions.GetCount();
   if (numFilters)
   {
      CreateNewMenu(0, 0, &myData.menu);
      
      for ( size_t i = 0 ; i < numFilters ; ++i )
      {
         ::AppendMenuItemTextWithCFString(myData.menu,
                                          wxMacCFStringHolder(myData.name[i],
                                                              GetFont().GetEncoding()),
                                          4,
                                          i,
                                          NULL);
      }
      
      SetRect(&r, 0, margin, 0, 0);
      CreatePopupButtonControl(NULL, &r, CFSTR("Format:"), -12345, true, -1, teJustLeft, normal, &myData.choice);
      SetControlID(myData.choice, &kChoiceID);
      SetControlPopupMenuRef(myData.choice, myData.menu);
      SetControl32BitMinimum(myData.choice, 1);
      SetControl32BitMaximum(myData.choice, myData.name.GetCount());
      SetControl32BitValue(myData.choice, myData.currentfilter + 1);
      GetBestControlRect(myData.choice, &r, &base);
      SizeControl(myData.choice, r.right - r.left, r.bottom - r.top);
      UnionRect(&myData.bounds, &r, &myData.bounds);
      gap = 15;

      HIObjectSetAuxiliaryAccessibilityAttribute((HIObjectRef)myData.choice, 0, kAXDescriptionAttribute, CFSTR("Format"));
   }
   
   if (!m_buttonlabel.IsEmpty())
   {
      wxMacCFStringHolder cfString(wxStripMenuCodes(m_buttonlabel).c_str(), wxFONTENCODING_DEFAULT);
      SetRect(&r, myData.bounds.right + gap, margin, 0, 0);
      CreatePushButtonControl(NULL, &r, cfString, &myData.button);
      SetControlID(myData.button, &kButtonID);
      GetBestControlRect(myData.button, &r, &base);
      SizeControl(myData.button, r.right - r.left, r.bottom - r.top);
      UnionRect(&myData.bounds, &r, &myData.bounds);
   }
   
   // Expand bounding rectangle to include a top and bottom margin
   myData.bounds.top -= margin;
   myData.bounds.bottom += margin;
   
   dialogCreateOptions.optionFlags |= kNavNoTypePopup;
   
   if (m_dialogStyle & wxFD_SAVE)
   {
      dialogCreateOptions.modality = kWindowModalityWindowModal;
      dialogCreateOptions.parentWindow = (WindowRef) GetParent()->MacGetTopLevelWindowRef();
   
      myData.saveMode = true;
      
      if (!numFilters)
      {
         dialogCreateOptions.optionFlags |= kNavNoTypePopup;
      }
      dialogCreateOptions.optionFlags |= kNavDontAutoTranslate;
      dialogCreateOptions.optionFlags |= kNavDontAddTranslateItems;
      
      // The extension is important
      if (numFilters < 2)
         dialogCreateOptions.optionFlags |= kNavPreserveSaveFileExtension;
      
#if TARGET_API_MAC_OSX
      if (!(m_dialogStyle & wxFD_OVERWRITE_PROMPT))
      {
         dialogCreateOptions.optionFlags |= kNavDontConfirmReplacement;
      }
#endif
      
      err = ::NavCreatePutFileDialog(&dialogCreateOptions,
                                     // Suppresses the 'Default' (top) menu item
                                     kNavGenericSignature, kNavGenericSignature,
                                     sStandardNavEventFilter,
                                     &myData, // for defaultLocation
                                     &dialog);
   }
   else
   {
      
      //let people select bundles/programs in dialogs
      dialogCreateOptions.optionFlags |= kNavSupportPackages;
      
      navFilterUPP = NewNavObjectFilterUPP(CrossPlatformFilterCallback);
      err = ::NavCreateGetFileDialog(&dialogCreateOptions,
                                     NULL, // NavTypeListHandle
                                     sStandardNavEventFilter,
                                     NULL, // NavPreviewUPP
                                     navFilterUPP,
                                     (void *) &myData, // inClientData
                                     &dialog);
   }
   
   if (err == noErr)
      err = ::NavDialogRun(dialog);
   
   if (err == noErr)
   {
      myData.window = NavDialogGetWindow(dialog);
      Rect r;

      // This creates our "fake" dialog with the same dimensions as the sheet so
      // that Options dialogs will center properly on the sheet.  The "fake" dialog
      // is never actually seen.
      GetWindowBounds(myData.window, kWindowStructureRgn, &r);
      wxDialog::Create(NULL,  // no parent...otherwise strange things happen
                       wxID_ANY,
                       wxEmptyString,
                       wxPoint(r.left, r.top),
                       wxSize(r.right - r.left, r.bottom - r.top));
      
      BeginAppModalStateForWindow(myData.window);
      
      while (myData.showing)
      {
         wxTheApp->MacDoOneEvent();
      }
      
      EndAppModalStateForWindow(myData.window);
   }
   
   // clean up filter related data, etc.
   if (navFilterUPP)
      ::DisposeNavObjectFilterUPP(navFilterUPP);
   
   if (err != noErr)
      return wxID_CANCEL;
   
   NavReplyRecord navReply;
   err = ::NavDialogGetReply(dialog, &navReply);
   if (err == noErr && navReply.validRecord)
   {
      AEKeyword   theKeyword;
      DescType    actualType;
      Size        actualSize;
      FSRef       theFSRef;
      wxString thePath ;
      
      m_filterIndex = myData.currentfilter;
      
      long count;
      ::AECountItems(&navReply.selection , &count);
      for (long i = 1; i <= count; ++i)
      {
         err = ::AEGetNthPtr(&(navReply.selection), i, typeFSRef, &theKeyword, &actualType,
                             &theFSRef, sizeof(theFSRef), &actualSize);
         if (err != noErr)
            break;
         
         if (m_dialogStyle & wxFD_SAVE)
            thePath = wxMacFSRefToPath( &theFSRef , navReply.saveFileName ) ;
         else
            thePath = wxMacFSRefToPath( &theFSRef ) ;
         
         if (!thePath)
         {
            ::NavDisposeReply(&navReply);
            return wxID_CANCEL;
         }
         
         m_path = ConvertSlashInFileName(thePath);
         m_paths.Add(m_path);
         m_fileName = wxFileNameFromPath(m_path);
         m_fileNames.Add(m_fileName);
      }
      // set these to the first hit
      m_path = m_paths[0];
      m_fileName = wxFileNameFromPath(m_path);
      m_dir = wxPathOnly(m_path);
   }
   ::NavDisposeReply(&navReply);
   
   return (err == noErr) ? wxID_OK : wxID_CANCEL;
}
Esempio n. 12
0
static pascal OSStatus windowEventHandler(EventHandlerCallRef nextHandler, EventRef theEvent, void *inUserData)
{
    CvWindow* window = NULL;
    UInt32 eventKind, eventClass;
    OSErr err = noErr;
    int event = 0;
    UInt32 count = 0;
    HIPoint point = {0,0};
    EventMouseButton eventMouseButton = 0;//FD
    UInt32 modifiers;//FD

    WindowRef theWindow = (WindowRef)inUserData;
    if (theWindow == NULL)
        return eventNotHandledErr;
    window = icvWindowByHandle(theWindow);
    if ( window == NULL)
        return eventNotHandledErr;

    eventKind = GetEventKind(theEvent);
    eventClass = GetEventClass(theEvent);

    switch (eventClass) {
    case kEventClassMouse : {
        switch (eventKind){
        case kEventMouseUp :
        case kEventMouseDown :
        case kEventMouseMoved :
        case kEventMouseDragged : {
            err = CallNextEventHandler(nextHandler, theEvent);
            if (err != eventNotHandledErr)
                return err;
            err = GetEventParameter(theEvent, kEventParamMouseButton, typeMouseButton, NULL, sizeof(eventMouseButton), NULL, &eventMouseButton);
            err = GetEventParameter(theEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(modifiers), NULL, &modifiers);
            err = GetEventParameter(theEvent,kEventParamClickCount,typeUInt32,NULL,sizeof(UInt32),NULL,&count);
            if (err == noErr){
                if (count >1) event += 6;
            } else {
                event = CV_EVENT_MOUSEMOVE;
            }

            if (eventKind == kEventMouseUp)
                event +=4;
            if (eventKind == kEventMouseDown)
                event +=1;

            unsigned int flags = 0;

            err = GetEventParameter(theEvent, kEventParamWindowMouseLocation, typeHIPoint, NULL, sizeof(point), NULL, &point);
            if (eventKind != kEventMouseMoved){
                switch(eventMouseButton){
                    case kEventMouseButtonPrimary:
                        if (modifiers & controlKey){
                            flags += CV_EVENT_FLAG_RBUTTON;
                            event += 1;
                        } else {
                            flags += CV_EVENT_FLAG_LBUTTON;
                        }
                        break;
                    case kEventMouseButtonSecondary:
                        flags += CV_EVENT_FLAG_RBUTTON;
                        event += 1;
                        break;
                    case kEventMouseButtonTertiary:
                        flags += CV_EVENT_FLAG_MBUTTON;
                        event += 2;
                        break;
                }
            }

            if (modifiers&controlKey) flags += CV_EVENT_FLAG_CTRLKEY;
            if (modifiers&shiftKey)   flags += CV_EVENT_FLAG_SHIFTKEY;
            if (modifiers& cmdKey )   flags += CV_EVENT_FLAG_ALTKEY;

            if (window->on_mouse != NULL){
                int lx,ly;
                Rect structure, content;
                GetWindowBounds(theWindow, kWindowStructureRgn, &structure);
                GetWindowBounds(theWindow, kWindowContentRgn, &content);
                lx = (int)point.x - content.left + structure.left;
                ly = (int)point.y - window->trackbarheight  - content.top + structure.top;
                if (window->flags & CV_WINDOW_AUTOSIZE) {//FD
                                                         //printf("was %d,%d\n", lx, ly);
                    /* scale the mouse coordinates */
                    lx = lx * window->imageWidth / (content.right - content.left);
                    ly = ly * window->imageHeight / (content.bottom - content.top - window->trackbarheight);
                }

                if (lx>0 && ly >0){
                    window->on_mouse (event, lx, ly, flags, window->on_mouse_param);
                    return noErr;
                }
            }
        }
        default : return eventNotHandledErr;
        }
    }
    case kEventClassWindow : {//FD
        switch (eventKind){
        case kEventWindowBoundsChanged :
        {
            /* resize the trackbars */
            CvTrackbar *t;
            Rect bounds;
            GetWindowBounds(window->window,kWindowContentRgn,&bounds);
            for ( t = window->toolbar.first; t != 0; t = t->next )
                SizeControl(t->trackbar,bounds.right - bounds.left - INTERWIDGETSPACE*3 - LABELWIDTH , WIDGETHEIGHT);
        }
            /* redraw the image */
            icvDrawImage(window);
            break;
        default :
            return eventNotHandledErr;
        }
    }
    default:
        return eventNotHandledErr;
    }

    return eventNotHandledErr;
}
Esempio n. 13
0
// --------------------------------------------------------------------------------------
void AdjustControls(WindowRef prefsWindow)
{
    Rect contentRect, listViewRect;
    ControlRef rootControl, userPane;
    SInt16 userPaneWidth, userPaneHeight;
    UInt16 panelIndex;
    ListHandle iconList;
    short oldListHeight, newListHeight;

    GetWindowBounds(prefsWindow, kWindowContentRgn, &contentRect);

    userPaneWidth = (contentRect.right - contentRect.left) -
                    (gWindowEdgeSpacing + kListWidth + kScrollBarWidth + kControlSpacing) -
                    (kSizeBoxWidth + gMinimumSpacing);
    userPaneHeight = (contentRect.bottom - contentRect.top) - gWindowEdgeSpacing -
                     (kSizeBoxWidth + gMinimumSpacing);

    GetRootControl(prefsWindow, &rootControl);
    for (panelIndex = 1; panelIndex <= kNumberOfRows; panelIndex++)
    {
        GetIndexedSubControl(rootControl, panelIndex, &userPane);
        SizeControl(userPane, userPaneWidth, userPaneHeight);
    }

    GetWindowProperty(prefsWindow, kAppSignature, kIconListTag, sizeof(ListHandle), NULL,
                      &iconList);

    GetListViewBounds(iconList, &listViewRect);
    oldListHeight = listViewRect.bottom - listViewRect.top;

    newListHeight = (contentRect.bottom - contentRect.top) - gWindowEdgeSpacing -
                    gWindowEdgeSpacing;
    newListHeight -= newListHeight % kCellHeight;	// make the list height a multiple
    if (newListHeight > kMaxListHeight)				// of the cell height and don't make
        newListHeight = kMaxListHeight;				// it bigger than we have cells for

    if (newListHeight != oldListHeight)
    {
        Rect invalRect;

        listViewRect.right += kScrollBarWidth;	// we will need to redraw the scroll bar as well
        // we need to invalidate the area where a cell will be drawn or erased
        if (newListHeight > oldListHeight)
            SetRect(&invalRect, listViewRect.left - 5, listViewRect.bottom - 5,
                    listViewRect.right + 5, contentRect.bottom);	// the extra 5 pixels are
        // to cause the bottom of the list box frame to get erased
        else
            SetRect(&invalRect, listViewRect.left - 5, gWindowEdgeSpacing + newListHeight - 5,
                    listViewRect.right + 5, contentRect.bottom);

        // the drawing section is as far down as possible to avoid any screen flickering
        DrawThemeFocusRect(&listViewRect, false);			// erase the focus rectangle
        LSize(kListWidth, newListHeight, iconList);			// resize the List
        drawFrameAndFocus(iconList, true, prefsWindow);		// draw the focus rectangle back
        InvalWindowRect(prefsWindow, &invalRect);
    }

#if TARGET_API_MAC_OS8
    CalculateBalloonHelpRects(prefsWindow);
#endif
} // AdjustControls