Exemplo n.º 1
0
static pascal OSStatus s86proc(EventHandlerCallRef myHandler, EventRef event, void* userData) {
    OSStatus	err = eventNotHandledErr;
	HIPoint		pos;
	Point		p;
	Rect		ctrlbounds, winbounds;
	PicHandle   pict;

    if (GetEventClass(event)==kEventClassControl && GetEventKind(event)==kEventControlClick ) {
		err = noErr;
        GetEventParameter(event, kEventParamMouseLocation, typeHIPoint, NULL, sizeof(HIPoint), NULL, &pos);
		GetControlBounds((ControlRef)userData, &ctrlbounds);
		GetWindowBounds(soundWin, kWindowContentRgn, &winbounds);
		p.h = (short)pos.x;
		p.h -= (ctrlbounds.left + winbounds.left);
		p.h /= 8;
		if ((p.h < 2) || (p.h >= 10)) {
			return(err);
		}
		p.h -= 2;
		snd86 ^= (1 << p.h);
		set86s();
		setbmp(dipswbmp_getsnd86(snd86), &pict);
		SetControlData((ControlRef)userData, kControlNoPart, kControlPictureHandleTag, sizeof(PicHandle), &pict);
		Draw1Control((ControlRef)userData);
	}

	(void)myHandler;
	(void)userData;
    return err;
}
Exemplo n.º 2
0
CV_IMPL void cvSetTrackbarPos(const char* trackbar_name, const char* window_name, int pos)
{
   CV_FUNCNAME( "cvSetTrackbarPos" );

    __BEGIN__;

    CvWindow* window;
    CvTrackbar* trackbar = 0;

    if( trackbar_name == 0 || window_name == 0 )
        CV_ERROR( CV_StsNullPtr, "NULL trackbar or window name" );

    window = icvFindWindowByName( window_name );
    if( window )
        trackbar = icvFindTrackbarByName( window, trackbar_name );

    if( trackbar )
    {
        if( pos < 0 )
            pos = 0;

        if( pos > trackbar->maxval )
            pos = trackbar->maxval;

    // Set new value and redraw the trackbar
    SetControlValue( trackbar->trackbar, pos );
    Draw1Control( trackbar->trackbar );
    }

    __END__;
    return ;
}
Exemplo n.º 3
0
OSStatus setProgress(int cur, int max)
{
	OSStatus err;
	ControlRef progressBar = NULL;
	ControlID id;

	id.signature = 'prog';
	id.id = 0;

	err = GetControlByID(gWindow, &id, &progressBar);
	if(err == noErr)
	{
		Boolean indeterminate;
		
		if(max == 0)
		{
			indeterminate = true;
			err = SetControlData(progressBar, kControlEntireControl, kControlProgressBarIndeterminateTag, sizeof(Boolean), (Ptr)&indeterminate);
		}
		else
		{
			double percentage = (double)cur / (double)max;
			SetControlMinimum(progressBar, 0);
			SetControlMaximum(progressBar, 100);
			SetControlValue(progressBar, (SInt16)(percentage * 100));

			indeterminate = false;
			err = SetControlData(progressBar, kControlEntireControl, kControlProgressBarIndeterminateTag, sizeof(Boolean), (Ptr)&indeterminate);

			Draw1Control(progressBar);
		}
	}

	return(err);
}
Exemplo n.º 4
0
// --------------------------------------------------------------------------------------
void RedrawPrefsDialogList(DialogRef prefsDialog)
{
	ControlRef listBoxControl;
	
	GetDialogItemAsControl(prefsDialog, iIconList, &listBoxControl);
	Draw1Control(listBoxControl);	// redraw the list box control
}
Exemplo n.º 5
0
void tool_wind_fill_group_combo(void)
{
	int					n,group_idx;
	char				str[256];
	CFStringRef			cf_str;
	HMHelpContentRec	tag;
	
		// old settings
		
	group_idx=GetControl32BitValue(group_combo);
	
		// delete old control and menu
		
	DisposeControl(group_combo);
	
	DeleteMenu(160);
	DisposeMenu(group_menu);
	
		// recreate the menu
		
	CreateNewMenu(group_combo_menu_id,0,&group_menu);
	
	cf_str=CFStringCreateWithCString(kCFAllocatorDefault,"No Group",kCFStringEncodingMacRoman);
	AppendMenuItemTextWithCFString(group_menu,cf_str,0,FOUR_CHAR_CODE('gp01'),NULL);
	CFRelease(cf_str);
	
	AppendMenuItemTextWithCFString(group_menu,NULL,kMenuItemAttrSeparator,0,NULL);
	
	for (n=0;n<map.ngroup;n++) {
		sprintf(str,"%s (%d)",map.groups[n].name,group_count(n));
		cf_str=CFStringCreateWithCString(kCFAllocatorDefault,str,kCFStringEncodingMacRoman);
		AppendMenuItemTextWithCFString(group_menu,cf_str,0,FOUR_CHAR_CODE('gp03'),NULL);
		CFRelease(cf_str);
	}
	
	InsertMenu(group_menu,kInsertHierarchicalMenu);
	
		// recreate the contorl
		
	CreatePopupButtonControl(toolwind,&group_box,NULL,group_combo_menu_id,FALSE,0,0,0,&group_combo);
	Draw1Control(group_combo);
	
		// build the help
	
	tag.version=kMacHelpVersion;
	tag.tagSide=kHMDefaultSide;
	SetRect(&tag.absHotRect,0,0,0,0);
	tag.content[kHMMinimumContentIndex].contentType=kHMCFStringContent;
	tag.content[kHMMinimumContentIndex].u.tagCFString=CFStringCreateWithCString(NULL,"Segment Groups",kCFStringEncodingMacRoman);
	tag.content[kHMMaximumContentIndex].contentType=kHMNoContent;
		
	HMSetControlHelpContent(group_combo,&tag);
	
		// reset the control
		
	SetControl32BitValue(group_combo,group_idx);
}
Exemplo n.º 6
0
void dialog_ring_list_reset(void)
{
	dialog_ring_idx=-1;
	
	RemoveDataBrowserItems(dialog_ring_list,kDataBrowserNoItem,0,NULL,kDataBrowserItemNoProperty);
	AddDataBrowserItems(dialog_ring_list,kDataBrowserNoItem,model.animates[dialog_animate_idx].pose_moves[dialog_pose_move_idx].ring.count,NULL,kDataBrowserItemNoProperty);

	Draw1Control(dialog_ring_list);
}
Exemplo n.º 7
0
void dialog_pose_list_reset(void)
{
	DataBrowserItemID				itemID;

	RemoveDataBrowserItems(dialog_pose_move_list,kDataBrowserNoItem,0,NULL,kDataBrowserItemNoProperty);
	AddDataBrowserItems(dialog_pose_move_list,kDataBrowserNoItem,model.animates[dialog_animate_idx].npose_move,NULL,kDataBrowserItemNoProperty);

	itemID=dialog_pose_move_idx+1;
	SetDataBrowserSelectedItems(dialog_pose_move_list,1,&itemID,kDataBrowserItemsAssign);

	Draw1Control(dialog_pose_move_list);
}
Exemplo n.º 8
0
//-----------------------------------------------------------------------------------
//	Draw
//-----------------------------------------------------------------------------------
//	The fun part of the control
//
void TMultiPane::Draw(
					  RgnHandle				inLimitRgn,
					  CGContextRef			inContext )
{
    bool compositing = (inContext != 0);
	if (!compositing) {
            HIViewRef subPane;
            TViewNoCompositingCompatible::Draw(inLimitRgn,inContext); // For background handling
		// First look for 9999 : this is our background if we have one
		HIViewID id = { kSubPanelSignature + mID, 9999 };
		OSStatus result = HIViewFindByID(GetViewRef(), id, &subPane);
		if (result == noErr) {
			Draw1Control( subPane);
		} else {
			// Else, redraw just the subpane
			HIViewID id = { kSubPanelSignature + mID, GetValue() };
			OSStatus result = HIViewFindByID(GetViewRef(), id, &subPane);
			if (result == noErr) {
				Draw1Control( subPane);
			}
		}
	}
}
Exemplo n.º 9
0
static OSStatus UpdateTextControlView (HIViewRef control)
{
	OSStatus			err;
	WindowAttributes	attr;

	err = GetWindowAttributes(GetControlOwner(control), &attr);
	if (err == noErr)
	{
		if (attr & kWindowCompositingAttribute)
			err = HIViewSetNeedsDisplay(control, true);
		else
			Draw1Control(control);
	}

	return (err);
}
Exemplo n.º 10
0
OSStatus setProgressText(CFStringRef text)
{
	OSStatus err;
	ControlRef progressText = NULL;
	ControlID id;

	id.signature = 'what';
	id.id = 0;

	err = GetControlByID(gWindow, &id, &progressText);
	if(err == noErr)
	{
		err = SetControlData(progressText, kControlEntireControl, kControlStaticTextCFStringTag, sizeof(CFStringRef), (Ptr)&text);
		Draw1Control(progressText);
	}

	return(err);
}
Exemplo n.º 11
0
void
TkpDisplayScrollbar(
    ClientData clientData)	/* Information about window. */
{
    register TkScrollbar *scrollPtr = (TkScrollbar *) clientData;
    register MacScrollbar *macScrollPtr = (MacScrollbar *) clientData;
    register Tk_Window tkwin = scrollPtr->tkwin;
    
    MacDrawable *macDraw;
    CGrafPtr saveWorld;
    GDHandle saveDevice;
    GWorldPtr destPort;
    WindowRef windowRef;
    
    if ((scrollPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) {
	goto done;
    }

    /*
     * Draw the focus or any 3D relief we may have.
     */
    if (scrollPtr->highlightWidth != 0) {
	GC fgGC, bgGC;

	bgGC = Tk_GCForColor(scrollPtr->highlightBgColorPtr,
		Tk_WindowId(tkwin));

	if (scrollPtr->flags & GOT_FOCUS) {
	    fgGC = Tk_GCForColor(scrollPtr->highlightColorPtr,
		    Tk_WindowId(tkwin));
	    TkpDrawHighlightBorder(tkwin, fgGC, bgGC, scrollPtr->highlightWidth,
		Tk_WindowId(tkwin));
	} else {
	    TkpDrawHighlightBorder(tkwin, bgGC, bgGC, scrollPtr->highlightWidth,
		Tk_WindowId(tkwin));
	}
    }
    Tk_Draw3DRectangle(tkwin, Tk_WindowId(tkwin), scrollPtr->bgBorder,
	    scrollPtr->highlightWidth, scrollPtr->highlightWidth,
	    Tk_Width(tkwin) - 2*scrollPtr->highlightWidth,
	    Tk_Height(tkwin) - 2*scrollPtr->highlightWidth,
	    scrollPtr->borderWidth, scrollPtr->relief);

    /*
     * Set up port for drawing Macintosh control.
     */
    macDraw = (MacDrawable *) Tk_WindowId(tkwin);
    destPort = TkMacGetDrawablePort(Tk_WindowId(tkwin));
    GetGWorld(&saveWorld, &saveDevice);
    SetGWorld(destPort, NULL);
    TkMacSetUpClippingRgn(Tk_WindowId(tkwin));

    if (macScrollPtr->sbHandle == NULL) {
        Rect r;
        WindowRef frontNonFloating;
        
        r.left = r.top = 0;
        r.right = r.bottom = 1;
	macScrollPtr->sbHandle = NewControl((WindowRef) destPort, &r, "\p",
		false, (short) 500, 0, 1000,
		scrollBarProc, (SInt32) scrollPtr);

	/*
	 * If we are foremost than make us active.
	 */
	
	if (TkMacHaveAppearance() >= 0x110) {
	    frontNonFloating = FrontNonFloatingWindow();
	} else {
	    frontNonFloating = FrontWindow();
	}
	
	if ((WindowPtr) destPort == FrontWindow() || TkpIsWindowFloating((WindowPtr) destPort)) {
	    macScrollPtr->macFlags |= ACTIVE;
	}
    }

    /*
     * Update the control values before we draw.
     */
    windowRef  = (**macScrollPtr->sbHandle).contrlOwner;    
    UpdateControlValues(macScrollPtr);
    
    if (macScrollPtr->macFlags & ACTIVE) {
	Draw1Control(macScrollPtr->sbHandle);
	if (macScrollPtr->macFlags & DRAW_GROW) {
	    DrawGrowIcon(windowRef);
	}
    } else {
	(**macScrollPtr->sbHandle).contrlHilite = 255;
	Draw1Control(macScrollPtr->sbHandle);
	if (macScrollPtr->macFlags & DRAW_GROW) {
	    DrawGrowIcon(windowRef);
	    Tk_Fill3DRectangle(tkwin, Tk_WindowId(tkwin), scrollPtr->bgBorder,
		Tk_Width(tkwin) - 13, Tk_Height(tkwin) - 13,
		Tk_Width(tkwin), Tk_Height(tkwin),
		0, TK_RELIEF_FLAT);
	}
    }
    
    SetGWorld(saveWorld, saveDevice);
     
    done:
    scrollPtr->flags &= ~REDRAW_PENDING;
}
Exemplo n.º 12
0
bool setPlayerWinTimer(bool bBlank, UInt32 iMSecs)
{
    ControlRef cRef;
    ControlID cID;
    OSStatus iErr;

    Str255 strMins, strSecs;
    char pcFinalStr[259];
    UInt32 iFullSecs;
    char *pcData;

    cID.signature = FOUR_CHAR_CODE('time');
    cID.id = 8;
    if (noErr != (iErr = GetControlByID(g_refPlayerWin, &cID, &cRef)))
    {
        fprintf(stderr, "setPlayerWinTimer() - GetControlByID() failed, returning %lu!\n", (unsigned long) iErr);
        return false;
    }

    if (bBlank)
    {
        pcData = "--:--";
    }
    else
    {
        iFullSecs = (iMSecs - (iMSecs % 1000)) / 1000;
        NumToString((iFullSecs - (iFullSecs % 60)) / 60, strMins);
        NumToString(iFullSecs % 60, strSecs);
        switch (strSecs[0])
        {
            case 0:
                strSecs[0] = '0';  strSecs[1] = '0';  strSecs[2] = '\0';
                break;
            case 1:
                strSecs[0] = '0';  strSecs[2] = '\0';
                break;
            case 2:
                strSecs[0] = strSecs[1];  strSecs[1] = strSecs[2];  strSecs[2] = '\0';
                break;
        }
        switch (strMins[0])
        {
            case 0:
                strMins[0] = '0';  strMins[1] = '0';  strMins[2] = '\0';
                break;
            case 1:
                strMins[0] = '0';  strMins[2] = '\0';
                break;
        }
        pcFinalStr[0] = '\0';
        strcat(pcFinalStr, (const char *) strMins);
        strcat(pcFinalStr, ":");
        strcat(pcFinalStr, (const char *) strSecs);
        pcData = pcFinalStr;
    }

    if (noErr != (iErr = SetControlData(cRef, kControlEditTextPart, kControlEditTextTextTag, strlen(pcData), pcData)))
    {
        fprintf(stderr, "setPlayerWinTimer() - SetControlData() failed, returning %lu!\n", (unsigned long) iErr);
        return false;
    }

    Draw1Control(cRef);
    
    return true;
}
Exemplo n.º 13
0
void
TkpDisplayScrollbar(
    ClientData clientData)        /* Information about window. */
{
    TkScrollbar *scrollPtr = (TkScrollbar *) clientData;
    MacScrollbar *macScrollPtr = (MacScrollbar *) clientData;
    Tk_Window tkwin = scrollPtr->tkwin;
    
    MacDrawable *macDraw;
    CGrafPtr saveWorld;
    GDHandle saveDevice;
    GWorldPtr destPort;
    WindowRef windowRef;
    
    if ((scrollPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) {
        goto done;
    }

    /*
     * Draw the focus or any 3D relief we may have.
     */
    if (scrollPtr->highlightWidth != 0) {
        GC fgGC, bgGC;

        bgGC = Tk_GCForColor(scrollPtr->highlightBgColorPtr,
            Tk_WindowId(tkwin));

        if (scrollPtr->flags & GOT_FOCUS) {
            fgGC = Tk_GCForColor(scrollPtr->highlightColorPtr,
                Tk_WindowId(tkwin));
            TkpDrawHighlightBorder(tkwin, fgGC, bgGC, scrollPtr->highlightWidth,
                Tk_WindowId(tkwin));
        } else {
            TkpDrawHighlightBorder(tkwin, bgGC, bgGC, scrollPtr->highlightWidth,
                Tk_WindowId(tkwin));
        }
    }
    Tk_Draw3DRectangle(tkwin, Tk_WindowId(tkwin), scrollPtr->bgBorder,
        scrollPtr->highlightWidth, scrollPtr->highlightWidth,
        Tk_Width(tkwin) - 2*scrollPtr->highlightWidth,
        Tk_Height(tkwin) - 2*scrollPtr->highlightWidth,
        scrollPtr->borderWidth, scrollPtr->relief);

    /*
     * Set up port for drawing Macintosh control.
     */
    macDraw = (MacDrawable *) Tk_WindowId(tkwin);
    destPort = TkMacOSXGetDrawablePort(Tk_WindowId(tkwin));
    GetGWorld(&saveWorld, &saveDevice);
    SetGWorld(destPort, NULL);
    TkMacOSXSetUpClippingRgn(Tk_WindowId(tkwin));

    if (macScrollPtr->sbHandle == NULL) {
        Rect r;
        SInt16 initialValue;
        SInt16 minValue;
        SInt16 maxValue;
        SInt16 procID;
        WindowRef frontNonFloating;
        
        r.left = r.top = 0;
        r.right = r.bottom = 1;

        minValue = MIN_SCROLLBAR_VALUE;
        maxValue = MAX_SCROLLBAR_VALUE;
        initialValue = (minValue + maxValue)/2;
        procID = kControlScrollBarLiveProc;

        windowRef = GetWindowFromPort(destPort);
        CreateScrollBarControl(windowRef, &r, initialValue,
                                minValue, maxValue,
                                maxValue - minValue, true,
                                NULL, &(macScrollPtr->sbHandle));
        SetControlReference(macScrollPtr->sbHandle, (SInt32) scrollPtr);
        
        /*
         * If we are foremost then make us active.
         */
        
        frontNonFloating = FrontNonFloatingWindow();
        
        if ((windowRef == FrontWindow()) || TkpIsWindowFloating(windowRef)) {
            macScrollPtr->macFlags |= ACTIVE;
        }
    }

    /*
     * Adjust the control size based on its width...
     */

    if (macScrollPtr->info.width < 13) {
        SetControlData(macScrollPtr->sbHandle, kControlNoPart, kControlSizeTag,
                sizeof(kControlSizeSmall), (void *) kControlSizeSmall);
    } else {
        SetControlData(macScrollPtr->sbHandle, kControlNoPart, kControlSizeTag,
                sizeof(kControlSizeSmall), (void *) kControlSizeLarge);
    }        
    
    /*
     * Update the control values before we draw.
     */
    windowRef  = GetControlOwner (macScrollPtr->sbHandle);
    UpdateControlValues(macScrollPtr);
    
    if (macScrollPtr->macFlags & ACTIVE) {
        Draw1Control(macScrollPtr->sbHandle);
        if (macScrollPtr->macFlags & DRAW_GROW) {
            DrawGrowIcon(windowRef);
        }
    } else {
        HiliteControl (macScrollPtr->sbHandle, 255 );
        Draw1Control(macScrollPtr->sbHandle);
        if (macScrollPtr->macFlags & DRAW_GROW) {
            DrawGrowIcon(windowRef);
            Tk_Fill3DRectangle(tkwin, Tk_WindowId(tkwin), scrollPtr->bgBorder,
                Tk_Width(tkwin) - 13, Tk_Height(tkwin) - 13,
                Tk_Width(tkwin), Tk_Height(tkwin),
                0, TK_RELIEF_FLAT);
        }
    }
    
    SetGWorld(saveWorld, saveDevice);
     
    done:
    scrollPtr->flags &= ~REDRAW_PENDING;
}
Exemplo n.º 14
0
static pascal OSStatus spbproc(EventHandlerCallRef myHandler, EventRef event, void* userData) {
    OSStatus	err = eventNotHandledErr;
	HIPoint		pos;
	Point		p;
	BYTE		bit, b;
	Rect		ctrlbounds, winbounds;
	PicHandle   pict;
	BOOL		redraw = FALSE;

    if (GetEventClass(event)==kEventClassControl && GetEventKind(event)==kEventControlClick ) {
		err = noErr;
        GetEventParameter(event, kEventParamMouseLocation, typeHIPoint, NULL, sizeof(HIPoint), NULL, &pos);
		GetControlBounds((ControlRef)userData, &ctrlbounds);
		GetWindowBounds(soundWin, kWindowContentRgn, &winbounds);
		p.h = (short)pos.x;
		p.v = (short)pos.y;
		p.h -= (ctrlbounds.left + winbounds.left);
		p.h /= 9;
		p.v -= (ctrlbounds.top + winbounds.top);
		p.v /= 9;
		if ((p.v < 1) || (p.v >= 3)) {
			return(err);
		}
		if ((p.h >= 2) && (p.h < 5)) {
			b = spb;
			bit = 0x40 << (2 - p.v);
			switch(p.h) {
				case 2:
					b |= bit;
					break;

				case 3:
					b ^= bit;
					break;

				case 4:
					b &= ~bit;
					break;
			}
			if (spb != b) {
				spb = b;
				set26s(b, 'spio', 'spin', 'sprm');
				redraw = TRUE;
			}
		}
		else if (p.h == 7) {
			spb ^= 0x20;
			redraw = TRUE;
		}
		else if ((p.h >= 10) && (p.h < 12)) {
			b = (BYTE)((p.h - 10) << 4);
			if ((spb ^ b) & 0x10) {
				spb &= ~0x10;
				spb |= b;
				set26s(b, 'spio', 'spin', 'sprm');
				redraw = TRUE;
			}
		}
		else if ((p.h >= 14) && (p.h < 19)) {
			b = (BYTE)(p.h - 14);
			if ((spb ^ b) & 7) {
				spb &= ~0x07;
				spb |= b;
				set26s(b, 'spio', 'spin', 'sprm');
				redraw = TRUE;
			}
		}
		else if ((p.h >= 21) && (p.h < 24)) {
			spbvrc ^= (BYTE)(3 - p.v);
			setControlValue('spvl', 0, (spbvrc & 1)?1:0);
			setControlValue('spvr', 0, (spbvrc & 2)?1:0);
			redraw = TRUE;
		}
		if (redraw) {
			setbmp(dipswbmp_getsndspb(spb, spbvrc), &pict);
			SetControlData((ControlRef)userData, kControlNoPart, kControlPictureHandleTag, sizeof(PicHandle), &pict);
			Draw1Control((ControlRef)userData);
		}
	}

	(void)myHandler;
	(void)userData;
    return err;
}
Exemplo n.º 15
0
static void
TkMacOSXDrawControl(
    MacButton *mbPtr,		/* Mac button. */
    GWorldPtr destPort,		/* Off screen GWorld. */
    GC gc,			/* The GC we are drawing into - needed for the
				 * bevel button */
    Pixmap pixmap)		/* The pixmap we are drawing into - needed for
				 * the bevel button */
{
    TkButton *butPtr = (TkButton *) mbPtr;
    TkWindow *winPtr;
    Rect paneRect, cntrRect;
    int active, enabled;
    int rebuild;

    winPtr = (TkWindow *) butPtr->tkwin;

    paneRect.left = winPtr->privatePtr->xOff;
    paneRect.top = winPtr->privatePtr->yOff;
    paneRect.right = paneRect.left + Tk_Width(butPtr->tkwin);
    paneRect.bottom = paneRect.top + Tk_Height(butPtr->tkwin);

    cntrRect = paneRect;

/*
    cntrRect.left += butPtr->inset;
    cntrRect.top += butPtr->inset;
    cntrRect.right -= butPtr->inset;
    cntrRect.bottom -= butPtr->inset;
*/
    cntrRect.left += DEF_INSET_LEFT;
    cntrRect.top += DEF_INSET_TOP;
    cntrRect.right -= DEF_INSET_RIGHT;
    cntrRect.bottom -= DEF_INSET_BOTTOM;

    /*
     * The control has been previously initialised.
     * It may need to be re-initialised
     */
#if 0
    rebuild = (winPtr->flags & TK_REBUILD_TOPLEVEL);
    winPtr->flags &= ~TK_REBUILD_TOPLEVEL;
#else
    rebuild = 0;
#endif
    if (mbPtr->flags) {
	MacControlParams params;

	TkMacOSXComputeControlParams(butPtr, &params);
	if (rebuild || bcmp(&params, &mbPtr->params, sizeof(params))) {
	    /*
	     * The type of control has changed.
	     * Clean it up and clear the flag.
	     */

	    if (mbPtr->userPane) {
		DisposeControl(mbPtr->userPane);
		mbPtr->userPane = NULL;
		mbPtr->control = NULL;
	    }
	    mbPtr->flags = 0;
	}
    }
    if (!(mbPtr->flags & CONTROL_INITIALIZED)) {
	if (TkMacOSXInitControl(mbPtr, destPort, gc, pixmap, &paneRect,
		&cntrRect)) {
	    return;
	}
    }
    SetControlBounds(mbPtr->userPane, &paneRect);
    SetControlBounds(mbPtr->control, &cntrRect);

    if (!mbPtr->useTkText) {
	Str255 controlTitle;
	ControlFontStyleRec fontStyle;
	Tk_Font font;
	int len;

	if (((mbPtr->info.image == NULL) && (mbPtr->info.bitmap == None))
		|| (mbPtr->info.compound != COMPOUND_NONE)) {
	    len = TkFontGetFirstTextLayout(butPtr->textLayout,
		    &font, (char*) controlTitle);
	    controlTitle[len] = 0;
	} else {
	    len = 0;
	    controlTitle[0] = 0;
	}
	if (rebuild || bcmp(mbPtr->controlTitle, controlTitle, len+1)) {
	    CFStringRef cf = CFStringCreateWithCString(NULL,
		    (char*) controlTitle, kCFStringEncodingUTF8);

	    if (cf != NULL) {
		SetControlTitleWithCFString(mbPtr->control, cf);
		CFRelease(cf);
	    }
	    bcopy(controlTitle, mbPtr->controlTitle, len+1);
	}
	if (len) {
	    TkMacOSXInitControlFontStyle(font, &fontStyle);
	    if (bcmp(&mbPtr->fontStyle, &fontStyle, sizeof(fontStyle)) ) {
		ChkErr(SetControlFontStyle, mbPtr->control, &fontStyle);
		bcopy(&fontStyle, &mbPtr->fontStyle, sizeof(fontStyle));
	    }
	}
    }
    if (mbPtr->params.isBevel) {
	/*
	 * Initialiase the image/button parameters.
	 */

	SetupBevelButton(mbPtr, mbPtr->control, destPort, gc, pixmap);
    }

    if (butPtr->flags & SELECTED) {
	SetControlValue(mbPtr->control, 1);
#if 0
    } else if (butPtr->flags & TRISTATED) {
	SetControlValue(mbPtr->control, 2);
#endif
    } else {
	SetControlValue(mbPtr->control, 0);
    }

    active = ((mbPtr->flags & ACTIVE) != 0);
    if (active != IsControlActive(mbPtr->control)) {
	if (active) {
	    ChkErr(ActivateControl, mbPtr->control);
	} else {
	    ChkErr(DeactivateControl, mbPtr->control);
	}
    }
    enabled = !(butPtr->state == STATE_DISABLED);
    if (enabled != IsControlEnabled(mbPtr->control)) {
	if (enabled) {
	    ChkErr(EnableControl, mbPtr->control);
	} else {
	    ChkErr(DisableControl, mbPtr->control);
	}
    }
    if (active && enabled) {
	if (butPtr->state == STATE_ACTIVE) {
	    if (mbPtr->params.isBevel) {
		HiliteControl(mbPtr->control, kControlButtonPart);
	    } else {
		switch (butPtr->type) {
		    case TYPE_BUTTON:
			HiliteControl(mbPtr->control, kControlButtonPart);
			break;
		    case TYPE_RADIO_BUTTON:
			HiliteControl(mbPtr->control, kControlRadioButtonPart);
			break;
		    case TYPE_CHECK_BUTTON:
			HiliteControl(mbPtr->control, kControlCheckBoxPart);
			break;
		}
	    }
	} else {
	    HiliteControl(mbPtr->control, kControlNoPart);
	}
    }
    UpdateControlColors(mbPtr);

    if (butPtr->type == TYPE_BUTTON && !mbPtr->params.isBevel) {
	Boolean isDefault;

	if (butPtr->defaultState == STATE_ACTIVE) {
	    isDefault = true;
	} else {
	    isDefault = false;
	}
	ChkErr(SetControlData, mbPtr->control, kControlNoPart,
		kControlPushButtonDefaultTag, sizeof(isDefault), &isDefault);
    }

    if (mbPtr->flags & FIRST_DRAW) {
	ShowControl(mbPtr->userPane);
	ShowControl(mbPtr->control);
	mbPtr->flags ^= FIRST_DRAW;
    } else {
	SetControlVisibility(mbPtr->control, true, true);
	Draw1Control(mbPtr->userPane);
    }

    if (mbPtr->params.isBevel) {
	if (mbPtr->bevelButtonContent.contentType ==
		kControlContentPictHandle) {
	    KillPicture(mbPtr->bevelButtonContent.u.picture);
	}
    }
}
Exemplo n.º 16
0
bool clearInfoWin()
{
    OSStatus iResult;
    
    /* try to clear the control */

    ControlRef cRef;
    ControlID cID;

    cID.signature = FOUR_CHAR_CODE('finf');
    cID.id = 14;
    if (noErr != (iResult = GetControlByID(g_refInfoWin, &cID, &cRef)))
    {
        clearInfoWin();
        fprintf(stderr, "clearInfoWin() - GetControlByID(finf) failed, returning %lu!\n", (unsigned long) iResult);
        return false;
    }
    if (!setTextBoxContents(cRef, CFSTR("")))
    {
        clearInfoWin();
        fprintf(stderr, "clearInfoWin() - setTextBoxContents(finf) failed!\n");
        return false;
    }
    Draw1Control(cRef);
        
    cID.signature = FOUR_CHAR_CODE('dinf');
    cID.id = 15;
    if (noErr != (iResult = GetControlByID(g_refInfoWin, &cID, &cRef)))
    {
        clearInfoWin();
        fprintf(stderr, "clearInfoWin() - GetControlByID(dinf) failed, returning %lu!\n", (unsigned long) iResult);
        return false;
    }
    if (!setTextBoxContents(cRef, CFSTR("")))
    {
        clearInfoWin();
        fprintf(stderr, "clearInfoWin() - setTextBoxContents(dinf) failed!\n");
        return false;
    }
    Draw1Control(cRef);
    
    cID.signature = FOUR_CHAR_CODE('tags');
    cID.id = 16;
    if (noErr != (iResult = GetControlByID(g_refInfoWin, &cID, &cRef)))
    {
        fprintf(stderr, "clearInfoWin() - GetControlByID(tags) failed, returning %lu!\n", (unsigned long) iResult);
        return false;
    }
    if (noErr != (iResult = RemoveDataBrowserItems(cRef, kDataBrowserNoItem, 0, NULL, kDataBrowserOrderIncreasing)))
    {
        fprintf(stderr, "clearInfoWin() - RemoveDataBrowserItems() failed, returning %lu!\n", (unsigned long) iResult);
        return false;
    }
    Draw1Control(cRef);

    /* clear memory */

    if (NULL != g_psTags)
    {
        for (UInt32 i = 0; i < (2 * g_iNumTags); i++)  {  CFRelease(g_psTags[i]);  }
        delete[] g_psTags;
        g_psTags = NULL;
        g_iNumTags = 0;
    }

    return true;
}
Exemplo n.º 17
0
void
TkpDisplayScale(
    ClientData clientData)	/* Widget record for scale. */
{
    TkScale *scalePtr = (TkScale *) clientData;
    Tk_Window tkwin = scalePtr->tkwin;
    Tcl_Interp *interp = scalePtr->interp;
    int result;
    char string[TCL_DOUBLE_SPACE];
    MacScale *macScalePtr = (MacScale *) clientData;
    Rect r;
    WindowRef windowRef;
    CGrafPtr destPort, savePort;
    Boolean portChanged;
    MacDrawable *macDraw;
    SInt32 initialValue, minValue, maxValue;
    UInt16 numTicks;

#ifdef TK_MAC_DEBUG_SCALE
    TkMacOSXDbgMsg("TkpDisplayScale");
#endif
    scalePtr->flags &= ~REDRAW_PENDING;
    if ((scalePtr->tkwin == NULL) || !Tk_IsMapped(scalePtr->tkwin)) {
	goto done;
    }

    /*
     * Invoke the scale's command if needed.
     */

    Tcl_Preserve((ClientData) scalePtr);
    if ((scalePtr->flags & INVOKE_COMMAND) && (scalePtr->command != NULL)) {
	Tcl_Preserve((ClientData) interp);
	sprintf(string, scalePtr->format, scalePtr->value);
	result = Tcl_VarEval(interp, scalePtr->command, " ", string, NULL);
	if (result != TCL_OK) {
	    Tcl_AddErrorInfo(interp, "\n    (command executed by scale)");
	    Tcl_BackgroundError(interp);
	}
	Tcl_Release((ClientData) interp);
    }
    scalePtr->flags &= ~INVOKE_COMMAND;
    if (scalePtr->flags & SCALE_DELETED) {
	Tcl_Release((ClientData) scalePtr);
	return;
    }
    Tcl_Release((ClientData) scalePtr);

    /*
     * Now handle the part of redisplay that is the same for
     * horizontal and vertical scales: border and traversal
     * highlight.
     */

    if (scalePtr->highlightWidth != 0) {
	GC gc = Tk_GCForColor(scalePtr->highlightColorPtr, Tk_WindowId(tkwin));

	Tk_DrawFocusHighlight(tkwin, gc, scalePtr->highlightWidth,
		Tk_WindowId(tkwin));
    }
    Tk_Draw3DRectangle(tkwin, Tk_WindowId(tkwin), scalePtr->bgBorder,
	    scalePtr->highlightWidth, scalePtr->highlightWidth,
	    Tk_Width(tkwin) - 2*scalePtr->highlightWidth,
	    Tk_Height(tkwin) - 2*scalePtr->highlightWidth,
	    scalePtr->borderWidth, scalePtr->relief);

    /*
     * Set up port for drawing Macintosh control.
     */

    macDraw = (MacDrawable *) Tk_WindowId(tkwin);
    destPort = TkMacOSXGetDrawablePort(Tk_WindowId(tkwin));
    windowRef = TkMacOSXDrawableWindow(Tk_WindowId(tkwin));
    portChanged = QDSwapPort(destPort, &savePort);
    TkMacOSXSetUpClippingRgn(Tk_WindowId(tkwin));

    /*
     * Create Macintosh control.
     */

#define MAC_OSX_SCROLL_WIDTH 10

    if (scalePtr->orient == ORIENT_HORIZONTAL) {
	int offset = (Tk_Height(tkwin) - MAC_OSX_SCROLL_WIDTH)/2;

	if (offset < 0) {
	    offset = 0;
	}

	r.left = macDraw->xOff + scalePtr->inset;
	r.top = macDraw->yOff + offset;
	r.right = macDraw->xOff+Tk_Width(tkwin) - scalePtr->inset;
	r.bottom = macDraw->yOff + offset + MAC_OSX_SCROLL_WIDTH/2;
    } else {
	int offset = (Tk_Width(tkwin) - MAC_OSX_SCROLL_WIDTH)/2;

	if (offset < 0) {
	    offset = 0;
	}

	r.left = macDraw->xOff + offset;
	r.top = macDraw->yOff + scalePtr->inset;
	r.right = macDraw->xOff + offset + MAC_OSX_SCROLL_WIDTH/2;
	r.bottom = macDraw->yOff+Tk_Height(tkwin) - scalePtr->inset;
    }

    if (macScalePtr->scaleHandle == NULL) {
#ifdef TK_MAC_DEBUG_SCALE
	TkMacOSXDbgMsg("Initialising scale");
#endif
	initialValue = scalePtr->value;
	if (scalePtr->orient == ORIENT_HORIZONTAL) {
	    minValue = scalePtr->fromValue;
	    maxValue = scalePtr->toValue;
	} else {
	    minValue = scalePtr->fromValue;
	    maxValue = scalePtr->toValue;
	}

	if (scalePtr->tickInterval == 0) {
	    numTicks = 0;
	} else {
	    numTicks = (maxValue - minValue)/scalePtr->tickInterval;
	}

	CreateSliderControl(windowRef, &r, initialValue, minValue, maxValue,
		kControlSliderPointsDownOrRight, numTicks, 1, scaleActionProc,
		&(macScalePtr->scaleHandle));
	SetControlReference(macScalePtr->scaleHandle, (UInt32) scalePtr);

	if (IsWindowActive(windowRef)) {
	    macScalePtr->flags |= ACTIVE;
	}
    } else {
	SetControlBounds(macScalePtr->scaleHandle, &r);
	SetControl32BitValue(macScalePtr->scaleHandle, scalePtr->value);
	SetControl32BitMinimum(macScalePtr->scaleHandle, scalePtr->fromValue);
	SetControl32BitMaximum(macScalePtr->scaleHandle, scalePtr->toValue);
    }

    /*
     * Finally draw the control.
     */

    SetControlVisibility(macScalePtr->scaleHandle,true,true);
    HiliteControl(macScalePtr->scaleHandle,0);
    Draw1Control(macScalePtr->scaleHandle);

    if (portChanged) {
	QDSwapPort(savePort, NULL);
    }
done:
    scalePtr->flags &= ~REDRAW_ALL;
}
Exemplo n.º 18
0
/*****************************************************
*
* MPWindowEventHandlerProc ( EventHandlerCallRef inCallRef, EventRef inEvent, void* inUserData ) 
*
* Purpose:  Window event handling routine
*
* Returns:  OSStatus	- eventNotHandledErr to allow other EventHandlers to run
*/
static  pascal  OSStatus	MPWindowEventHandlerProc( EventHandlerCallRef inCallRef, EventRef inEvent, void* inUserData )
{
	#pragma unused ( inCallRef, inUserData )
	LongDateRec				lDate;	
	LongDateTime			lSecs;
	unsigned long			secs;
	ControlRef				dateControl;
	WindowRef				window;
	struct kevent			kev;
	HICommand				command;
	FSRef					fsRef;
	CFURLRef				urlRef			= NULL;
	CFURLRef				fullUrlRef		= NULL;
	OSStatus				err				= eventNotHandledErr;
	UInt32					eventKind		= GetEventKind( inEvent );
	UInt32					eventClass		= GetEventClass( inEvent );

	switch ( eventClass )
	{
		case kEventClassMP:
			if ( eventKind == kEventKQueue )
			{
				//  When we receive the kEventKQueue event, we update the date control associated with the path we are watching.
				GetEventParameter( inEvent, kEventParamDirectObject, typeKEvent, NULL, sizeof(struct kevent), NULL, &kev );
				GetEventParameter( inEvent, kEventParamControlRef, typeControlRef, NULL, sizeof(ControlRef), NULL, &dateControl );

				GetDateTime( &secs );
				lSecs   = secs;
				LongSecondsToDate( &lSecs, &lDate );
				(void) SetControlData( dateControl, 0, kControlClockLongDateTag, sizeof(lDate), &lDate );
				Draw1Control( dateControl );
				
				PrintKEvent( GetControlOwner( dateControl ) , &kev );   //  Display the kevent information
			}
			break;

		case kEventClassWindow:
			if ( eventKind == kEventWindowClose )
			{
				GetEventParameter( inEvent, kEventParamDirectObject, typeWindowRef, NULL, sizeof(WindowRef), NULL, &window );
				((MyMPTaskInfo*)GetWRefCon( window ))->done  = true;	//  Flag the thread to terminate (thread checks at least every 30 seconds in this sample)
			}
			break;

		case kEventClassCommand:
			GetEventParameter( inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &command );
			if ( eventKind == kEventCommandProcess )
			{
				if ( command.commandID == 'Help' )						//  Our 'Help' command, just have LaunchServices open the "kqueue.pdf" file within our bundle.
				{
					urlRef	= CFBundleCopyResourcesDirectoryURL( CFBundleGetMainBundle() );
					fullUrlRef	= CFURLCreateCopyAppendingPathComponent( NULL, urlRef, CFSTR("kqueue.pdf"), false );

					CFURLGetFSRef( fullUrlRef, &fsRef );
					(void) LSOpenFSRef( &fsRef, NULL );					//  Open the file

					if ( urlRef != NULL )	CFRelease( urlRef );
					if ( urlRef != NULL )	CFRelease( fullUrlRef );
				}
			}
			break;
	}
    
    return( err );
}
Exemplo n.º 19
0
void
TkpDisplayScrollbar(
    ClientData clientData)	/* Information about window. */
{
    TkScrollbar *scrollPtr = (TkScrollbar *) clientData;
    MacScrollbar *macScrollPtr = (MacScrollbar *) clientData;
    Tk_Window tkwin = scrollPtr->tkwin;
    CGrafPtr destPort, savePort;
    Boolean portChanged;
    WindowRef windowRef;

    if ((scrollPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) {
	goto done;
    }

    /*
     * Draw the focus or any 3D relief we may have.
     */
    if (scrollPtr->highlightWidth != 0) {
	GC fgGC, bgGC;

	bgGC = Tk_GCForColor(scrollPtr->highlightBgColorPtr,
	    Tk_WindowId(tkwin));

	if (scrollPtr->flags & GOT_FOCUS) {
	    fgGC = Tk_GCForColor(scrollPtr->highlightColorPtr,
		Tk_WindowId(tkwin));
	    TkpDrawHighlightBorder(tkwin, fgGC, bgGC, scrollPtr->highlightWidth,
		Tk_WindowId(tkwin));
	} else {
	    TkpDrawHighlightBorder(tkwin, bgGC, bgGC, scrollPtr->highlightWidth,
		Tk_WindowId(tkwin));
	}
    }
    Tk_Draw3DRectangle(tkwin, Tk_WindowId(tkwin), scrollPtr->bgBorder,
	scrollPtr->highlightWidth, scrollPtr->highlightWidth,
	Tk_Width(tkwin) - 2*scrollPtr->highlightWidth,
	Tk_Height(tkwin) - 2*scrollPtr->highlightWidth,
	scrollPtr->borderWidth, scrollPtr->relief);

    if (macScrollPtr->sbHandle == NULL) {
	Rect r = {0, 0, 1, 1};

	windowRef = TkMacOSXDrawableWindow(Tk_WindowId(tkwin));
	CreateScrollBarControl(windowRef, &r, 0, 0, 0, 0, true, NULL,
		&(macScrollPtr->sbHandle));
	SetControlReference(macScrollPtr->sbHandle, (SInt32) scrollPtr);

	if (IsWindowActive(windowRef)) {
	    macScrollPtr->macFlags |= ACTIVE;
	}
    }

    /*
     * Update the control values before we draw.
     */

    UpdateControlValues(macScrollPtr);

    /*
     * Set up port for drawing Macintosh control.
     */
    destPort = TkMacOSXGetDrawablePort(Tk_WindowId(tkwin));
    portChanged = QDSwapPort(destPort, &savePort);
    TkMacOSXSetUpClippingRgn(Tk_WindowId(tkwin));

    /*
     * Scrollbars do not erase the complete control bounds if they are wider
     * than the standard width, so manually erase the extra space.
     */

    if (!EmptyRect(&macScrollPtr->eraseRect)) {
	EraseRect(&macScrollPtr->eraseRect);
    }

    Draw1Control(macScrollPtr->sbHandle);

    if (portChanged) {
	QDSwapPort(savePort, NULL);
    }

    done:
    scrollPtr->flags &= ~REDRAW_PENDING;
}
Exemplo n.º 20
0
bool refreshInfoWin(const CDecoder *pDec)
{
    OSStatus iResult;
    UInt32 i, j;

    if (!g_bLoaded)
    {
        return false;
    }
    
    /* Clean up any previous contents */

    clearInfoWin();

    /* Load new contents */

    g_iNumTags = pDec->getNumTags();

    if (NULL == (g_psTags = new CFStringRef[2 * g_iNumTags]))
    {
        g_iNumTags = 0;
        fprintf(stderr, "refreshInfoWin() - g_psTags allocation failed!\n");
        return false;
    }

    for (i = 0; i < g_iNumTags; i++)
    {
        if (NULL == (g_psTags[2 * i] = pDec->getTagName(i)))
        {
            for (j = 0; j < i; j++)  {  CFRelease(g_psTags[2 * i]);  CFRelease(g_psTags[(2 * i) + 1]);  }
            delete[] g_psTags;
            g_psTags = NULL;
            g_iNumTags = 0;
            
            fprintf(stderr, "refreshInfoWin() - pDec->getTagName() failed!\n");
            return false;
        }

        if (NULL == (g_psTags[(2 * i) + 1] = pDec->getTagData(i)))
        {
            for (j = 0; j < i; j++)  {  CFRelease(g_psTags[2 * i]);  CFRelease(g_psTags[(2 * i) + 1]);  }
            delete[] g_psTags;
            g_psTags = NULL;
            g_iNumTags = 0;

            fprintf(stderr, "refreshInfoWin() - pDec->getTagData() failed!\n");
            return false;
        }

        CFRetain(g_psTags[2 * i]);
        CFRetain(g_psTags[(2 * i) + 1]);
    }

    /* Load up the two text areas. */

    ControlRef cRef;
    ControlID cID;

    cID.signature = FOUR_CHAR_CODE('finf');
    cID.id = 14;
    if (noErr != (iResult = GetControlByID(g_refInfoWin, &cID, &cRef)))
    {
        clearInfoWin();
        fprintf(stderr, "refreshInfoWin() - GetControlByID(finf) failed, returning %lu!\n", (unsigned long) iResult);
        return false;
    }
    if (!setTextBoxContents(cRef, pDec->getSource()->getInfoString()))
    {
        clearInfoWin();
        fprintf(stderr, "refreshInfoWin() - setTextBoxContents(finf) failed!\n");
        return false;
    }
    Draw1Control(cRef);

    cID.signature = FOUR_CHAR_CODE('dinf');
    cID.id = 15;
    if (noErr != (iResult = GetControlByID(g_refInfoWin, &cID, &cRef)))
    {
        clearInfoWin();
        fprintf(stderr, "refreshInfoWin() - GetControlByID(dinf) failed, returning %lu!\n", (unsigned long) iResult);
        return false;
    }
    if (!setTextBoxContents(cRef, pDec->getInfoString()))
    {
        clearInfoWin();
        fprintf(stderr, "refreshInfoWin() - setTextBoxContents(dinf) failed!\n");
        return false;
    }
    Draw1Control(cRef);

    /* Load up the browser control. */

    cID.signature = FOUR_CHAR_CODE('tags');
    cID.id = 16;
    if (noErr != (iResult = GetControlByID(g_refInfoWin, &cID, &cRef)))
    {
        clearInfoWin();
        fprintf(stderr, "refreshInfoWin() - GetControlByID(tags) failed, returning %lu!\n", (unsigned long) iResult);
        return false;
    }
    if (noErr != (iResult = AddDataBrowserItems(cRef, kDataBrowserNoItem, g_iNumTags, NULL, kDataBrowserOrderIncreasing)))
    {
        clearInfoWin();
        fprintf(stderr, "refreshInfoWin() - RemoveDataBrowserItems() failed, returning %lu!\n", (unsigned long) iResult);
        return false;
    }
    Draw1Control(cRef);
    
    return true;
}
Exemplo n.º 21
0
void
TkpDisplayMenuButton(
    ClientData clientData)        /* Information about widget. */
{
    TkMenuButton *butPtr = (TkMenuButton *) clientData;
    Tk_Window tkwin = butPtr->tkwin;
    TkWindow *  winPtr;
    Pixmap      pixmap;
    MacMenuButton * mbPtr = (MacMenuButton *) butPtr;
    GWorldPtr dstPort;
    CGrafPtr saveWorld;
    GDHandle saveDevice;
    int      hasImageOrBitmap = 0;
    int      width, height;
    int      err;
    ControlButtonGraphicAlignment theAlignment;

    Rect paneRect, cntrRect;

    butPtr->flags &= ~REDRAW_PENDING;
    if ((butPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) {
        return;
    }
    pixmap = ( Pixmap )Tk_WindowId(tkwin);
    GetGWorld(&saveWorld, &saveDevice);
    dstPort = TkMacOSXGetDrawablePort(Tk_WindowId(tkwin));
    SetGWorld(dstPort, NULL);
    TkMacOSXSetUpClippingRgn(Tk_WindowId(tkwin));

    winPtr=(TkWindow *)butPtr->tkwin;
    paneRect.left=winPtr->privatePtr->xOff;
    paneRect.top=winPtr->privatePtr->yOff;
    paneRect.right=paneRect.left+Tk_Width(butPtr->tkwin)-1;
    paneRect.bottom=paneRect.top+Tk_Height(butPtr->tkwin)-1;
    
    cntrRect=paneRect;
        
    cntrRect.left+=butPtr->inset;
    cntrRect.top+=butPtr->inset;
    cntrRect.right-=butPtr->inset;
    cntrRect.bottom-=butPtr->inset;

    if (mbPtr->userPane) {
        MenuButtonControlParams params;
        bzero(&params, sizeof(params));
        ComputeMenuButtonControlParams(butPtr, &params );
        if (bcmp(&params,&mbPtr->params,sizeof(params))) {
            if (mbPtr->userPane) {
                DisposeControl(mbPtr->userPane);
                mbPtr->userPane = NULL;
                mbPtr->control = NULL;
            }
        }
     }
     if (!mbPtr->userPane) {
         if (MenuButtonInitControl(mbPtr,&paneRect,&cntrRect ) ) {
             fprintf(stderr,"Init Control failed\n" );
             return;
         }
     }
    SetControlBounds(mbPtr->userPane,&paneRect);
    SetControlBounds(mbPtr->control,&cntrRect); 

    /*
     * We need to cache the title and its style
     */
    if (!(mbPtr->flags&2)) {
        ControlTitleParams titleParams;
        int                titleChanged;
        int                styleChanged;
        ComputeControlTitleParams(butPtr,&titleParams);
        CompareControlTitleParams(&titleParams,&mbPtr->titleParams,
            &titleChanged,&styleChanged);
        if (titleChanged) {
            CFStringRef cf;    	    
            cf = CFStringCreateWithCString(NULL,
                  titleParams.title, kCFStringEncodingUTF8);
            if (hasImageOrBitmap) {
                SetControlTitleWithCFString(mbPtr->control, cf);
            } else {
                SetMenuItemTextWithCFString(mbPtr->menuRef, 1, cf);
            }
            CFRelease(cf);
            bcopy(titleParams.title,mbPtr->titleParams.title,titleParams.len+1);
            mbPtr->titleParams.len = titleParams.len;
        }
        if ((titleChanged||styleChanged) && titleParams .len) {
            if (hasImageOrBitmap) {
                if ((err=SetControlFontStyle(mbPtr->control,&titleParams.style))!=noErr) {
                    fprintf(stderr,"SetControlFontStyle failed %d\n", err);
                    return;
                }
            }
            bcopy(&titleParams.style,&mbPtr->titleParams.style,sizeof(titleParams.style));
        }
    }
    if (butPtr->image != None) {
        Tk_SizeOfImage(butPtr->image, &width, &height);
        hasImageOrBitmap = 1;
    } else if (butPtr->bitmap != None) {
        Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height);
        hasImageOrBitmap = 1;
    }
    if (hasImageOrBitmap) {
        mbPtr->picParams.srcRect.right = width;
        mbPtr->picParams.srcRect.bottom = height; 
        /* Set the flag to circumvent clipping and bounds problems with OS 10.0.4 */
        tkPictureIsOpen = 1;
        if (!(mbPtr->bevelButtonContent.u.picture = OpenCPicture(&mbPtr->picParams)) ) {
            fprintf(stderr,"OpenCPicture failed\n");
        }
        /*
         * TO DO - There is one case where XCopyPlane calls CopyDeepMask,
         * which does not get recorded in the picture.  So the bitmap code
         * will fail in that case.
         */
        if (butPtr->image != NULL) {
            Tk_RedrawImage(butPtr->image, 0, 0, width,
                height, pixmap, 0, 0);
        } else {   
            XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, NULL, 0, 0,
                (unsigned int) width, (unsigned int) height, 0, 0, 1);
        }
        ClosePicture();
        
        tkPictureIsOpen = 0;
        if ( (err=SetControlData(mbPtr->control, kControlButtonPart,
                    kControlBevelButtonContentTag,
                    sizeof(ControlButtonContentInfo),
                    (char *) &mbPtr->bevelButtonContent)) != noErr ) {
                fprintf(stderr,"SetControlData BevelButtonContent failed, %d\n", err );
        }
        switch (butPtr->anchor) {
            case TK_ANCHOR_N:
                theAlignment = kControlBevelButtonAlignTop;
                break;
            case TK_ANCHOR_NE:
                theAlignment = kControlBevelButtonAlignTopRight;
                break;
            case TK_ANCHOR_E:
                theAlignment = kControlBevelButtonAlignRight;
                break;
            case TK_ANCHOR_SE:
                theAlignment = kControlBevelButtonAlignBottomRight;
                break;
            case TK_ANCHOR_S:
                theAlignment = kControlBevelButtonAlignBottom;
                break;
            case TK_ANCHOR_SW:
                theAlignment = kControlBevelButtonAlignBottomLeft;
                break;
            case TK_ANCHOR_W:
                theAlignment = kControlBevelButtonAlignLeft;
                break;
            case TK_ANCHOR_NW:
                theAlignment = kControlBevelButtonAlignTopLeft;
                break;
            case TK_ANCHOR_CENTER:
                theAlignment = kControlBevelButtonAlignCenter;
                break;
        }
    
        if ((err=SetControlData(mbPtr->control, kControlButtonPart,
                kControlBevelButtonGraphicAlignTag,
                sizeof(ControlButtonGraphicAlignment),
                (char *) &theAlignment)) != noErr ) {
            fprintf(stderr,"SetControlData BevelButtonGraphicAlign failed, %d\n", err );
        }
    }
    if (butPtr->flags & GOT_FOCUS) {
        HiliteControl(mbPtr->control,kControlButtonPart);
    } else {
        HiliteControl(mbPtr->control,kControlNoPart);
    }
    UpdateControlColors(mbPtr);
    if (mbPtr->flags&2) {
        ShowControl(mbPtr->control);
        ShowControl(mbPtr->userPane);
        mbPtr->flags ^= 2;
    } else {
        Draw1Control(mbPtr->userPane);
        SetControlVisibility(mbPtr->control, true, true);
    }
    if (hasImageOrBitmap) {
        KillPicture(mbPtr->bevelButtonContent.u.picture);
    }
    SetGWorld(saveWorld, saveDevice);
}
Exemplo n.º 22
0
static pascal OSStatus s26proc(EventHandlerCallRef myHandler, EventRef event, void* userData) {
    OSStatus	err = eventNotHandledErr;
	HIPoint		pos;
	Point		p;
	BYTE		bit, b;
	Rect		ctrlbounds, winbounds;
	PicHandle   pict;
	BOOL		redraw = FALSE;

    if (GetEventClass(event)==kEventClassControl && GetEventKind(event)==kEventControlClick ) {
		err = noErr;
        GetEventParameter(event, kEventParamMouseLocation, typeHIPoint, NULL, sizeof(HIPoint), NULL, &pos);
		GetControlBounds((ControlRef)userData, &ctrlbounds);
		GetWindowBounds(soundWin, kWindowContentRgn, &winbounds);
		p.h = (short)pos.x;
		p.v = (short)pos.y;
		p.h -= (ctrlbounds.left + winbounds.left);
		p.h /= 9;
		p.v -= (ctrlbounds.top + winbounds.top);
		p.v /= 9;
		if ((p.v < 1) || (p.v >= 3)) {
			return(err);
		}
		if ((p.h >= 2) && (p.h < 7)) {
			b = (BYTE)(p.h - 2);
			if ((snd26 ^ b) & 7) {
				snd26 &= ~0x07;
				snd26 |= b;
				redraw = TRUE;
			}
		}
		else if ((p.h >= 9) && (p.h < 12)) {
			b = snd26;
			bit = 0x40 << (2 - p.v);
			switch(p.h) {
				case 9:
					b |= bit;
					break;

				case 10:
					b ^= bit;
					break;

				case 11:
					b &= ~bit;
					break;
			}
			if (snd26 != b) {
				snd26 = b;
				redraw = TRUE;
			}
		}
		else if ((p.h >= 15) && (p.h < 17)) {
			b = (BYTE)((p.h - 15) << 4);
			if ((snd26 ^ b) & 0x10) {
				snd26 &= ~0x10;
				snd26 |= b;
				redraw = TRUE;
			}
		}
		if (redraw) {
			set26s(snd26, '26io', '26in', '26rm');
			setbmp(dipswbmp_getsnd26(snd26), &pict);
			SetControlData((ControlRef)userData, kControlNoPart, kControlPictureHandleTag, sizeof(PicHandle), &pict);
			Draw1Control((ControlRef)userData);
		}
	}

	(void)myHandler;
	(void)userData;
    return err;
}
Exemplo n.º 23
0
void draw_shop_graphics(bool pressed,Rect clip_area_rect)
// mode 1 - drawing dark for button press
{
	Rect area_rect,item_info_from = {11,42,24,56};
	
	Rect face_rect = {6,6,38,38};
	Rect title_rect = {15,48,42,260};
	Rect dest_rect,help_from = {85,36,101,54};
	short faces[13] = {1,1,1,42,43, 1,1,1,1,1, 44,44,44};
	
	short i,what_chosen;
	RGBColor c[7] = {{0,0,0},{0,0,32767},{0,0,14535},{0,0,26623},{0,0,59391},
	{0,40959,0},{0,24575,0}};
	Rect shopper_name = {44,6,56,260};
	short current_pos;
	
	short cur_cost,what_magic_shop,what_magic_shop_item;
	char cur_name[60];
	char cur_info_str[60];
char *cost_strs[] = {"Extremely Cheap","Very Reasonable","Pretty Average","Somewhat Pricey",
	"Expensive","Exorbitant","Utterly Ridiculous"};
	GrafPtr old_port;
	cItemRec base_item;
	
	if (overall_mode != 21) {
		return;
		}
	
	
	GetPort(&old_port);
	SetPort(talk_gworld);
	TextFont(dungeon_font_num);
	TextSize(18);
	TextFace(0);

	if (pressed) {
		ClipRect(&clip_area_rect);	
		}

	GetPortBounds(talk_gworld,&area_rect);
	FrameRect(&area_rect);
	InsetRect(&area_rect,1,1);
	tileImage(area_rect,bg_gworld,bg[12]);

	FrameRect(&shop_frame);
	
	// Place store icon
	if (!pressed) { 
		SetPort(GetWindowPort(mainPtr));
		i = faces[store_shop_type];
		draw_dialog_graphic( talk_gworld, face_rect, i, PICT_TALK, false,1);
		SetPort( talk_gworld);
	}


	// Place name of store and shopper name
	RGBForeColor(&c[3]);
	dest_rect = title_rect;
	OffsetRect(&dest_rect,1,1);
	char_port_draw_string(talk_gworld,dest_rect,store_store_name,2,18);
	OffsetRect(&dest_rect,-1,-1);
	RGBForeColor(&c[4]);
	char_port_draw_string( talk_gworld,dest_rect,store_store_name,2,18);	

	TextFont(geneva_font_num);
	TextSize(12);
	TextFace(bold);

	RGBForeColor(&c[3]);
	switch (store_shop_type) {
		case 3: sprintf(cur_name,"Healing for %s.",univ.party[current_pc].name.c_str()); break;
		case 10: sprintf(cur_name,"Mage Spells for %s.",univ.party[current_pc].name.c_str());break;
		case 11: sprintf(cur_name,"Priest Spells for %s.",univ.party[current_pc].name.c_str()); break;
		case 12: sprintf(cur_name,"Buying Alchemy.");break;
		case 4: sprintf(cur_name,"Buying Food.");break;
		default:sprintf(cur_name,"Shopping for %s.",univ.party[current_pc].name.c_str()); break;
		}
	char_port_draw_string( talk_gworld,shopper_name,cur_name,2,18);	

	// Place help and done buttons
	ForeColor(blackColor);
	GetPortBounds(dlg_buttons_gworld[3][0],&help_from);
	talk_help_rect.right = talk_help_rect.left + help_from.right - help_from.left;
	talk_help_rect.bottom = talk_help_rect.top + help_from.bottom - help_from.top;
	rect_draw_some_item(dlg_buttons_gworld[3][pressed],help_from,talk_gworld,talk_help_rect);
	GetPortBounds(dlg_buttons_gworld[11][0],&help_from);
	//talk_help_rect.right = talk_help_rect.left + help_from.right - help_from.left;
	//talk_help_rect.bottom = talk_help_rect.top + help_from.bottom - help_from.top;
	rect_draw_some_item(dlg_buttons_gworld[11][pressed],help_from,talk_gworld,shop_done_rect);
	
	if (pressed)
		RGBForeColor(&c[4]);
	else ForeColor(blackColor);
		
	// Place all the items
	for (i = 0; i < 8; i++) {
		current_pos = i + GetControlValue(shop_sbar);
		if (store_shop_items[current_pos] < 0)
			break; // theoretically, this shouldn't happen
		cur_cost = store_shop_costs[current_pos];
		what_chosen = store_shop_items[current_pos];
		switch (what_chosen / 100) {
			case 0: case 1: case 2: case 3: case 4: 
				base_item = get_stored_item(what_chosen);
				base_item.ident = true;
				draw_dialog_graphic( talk_gworld, shopping_rects[i][2],base_item.graphic_num,PICT_ITEM, false,1);
				strcpy(cur_name,base_item.full_name.c_str());
				get_item_interesting_string(base_item,cur_info_str);
				break;
			case 5:
				base_item = store_alchemy(what_chosen - 500);
				draw_dialog_graphic( talk_gworld, shopping_rects[i][2],53,PICT_ITEM, false,1);//// all graphic nums
				strcpy(cur_name,base_item.full_name.c_str());
				strcpy(cur_info_str,"");
				break;
			case 6:
				//base_item = food_types[what_chosen - 600];
				//draw_dialog_graphic( talk_gworld, shopping_rects[i][2],633, false,1);
				//strcpy(cur_name,base_item.full_name);
				//get_item_interesting_string(base_item,cur_info_str);
				break;
			case 7:
				what_chosen -= 700;
				draw_dialog_graphic( talk_gworld, shopping_rects[i][2],99,PICT_ITEM, false,1);
				strcpy(cur_name,heal_types[what_chosen]);
				strcpy(cur_info_str,"");
				break;
			case 8:
				base_item = store_mage_spells(what_chosen - 800 - 30);
				draw_dialog_graphic( talk_gworld, shopping_rects[i][2],base_item.graphic_num,PICT_ITEM, false,1);

				strcpy(cur_name,base_item.full_name.c_str());
				strcpy(cur_info_str,"");		
				break;
			case 9:
				base_item = store_priest_spells(what_chosen - 900 - 30);
				draw_dialog_graphic( talk_gworld, shopping_rects[i][2],base_item.graphic_num,PICT_ITEM, false,1);
				strcpy(cur_name,base_item.full_name.c_str());
				strcpy(cur_info_str,"");
				break;
			default:
				what_magic_shop = (what_chosen / 1000) - 1;
				what_magic_shop_item = what_chosen % 1000;
				base_item = univ.party.magic_store_items[what_magic_shop][what_magic_shop_item];
				base_item.ident = true;
				draw_dialog_graphic( talk_gworld, shopping_rects[i][2],base_item.graphic_num,PICT_ITEM, false,1);
				strcpy(cur_name,base_item.full_name.c_str());
				get_item_interesting_string(base_item,cur_info_str);
				break;
			}

		// Now draw item shopping_rects[i][7]
		// 0 - whole area, 1 - active area 2 - graphic 3 - item name
		// 4 - item cost 5 - item extra str  6 - item help button
		TextSize(12);
		char_port_draw_string( talk_gworld,shopping_rects[i][3],cur_name,0,12);
		sprintf(cur_name,"Cost: %d",cur_cost);
		char_port_draw_string( talk_gworld,shopping_rects[i][4],cur_name,0,12);
		TextSize(10);
		char_port_draw_string( talk_gworld,shopping_rects[i][5],cur_info_str,0,12);
		if ((store_shop_type != 3) && (store_shop_type != 4))
			rect_draw_some_item(invenbtn_gworld,item_info_from,talk_gworld,shopping_rects[i][6],pressed ? srcCopy : transparent);

		}

	// Finally, cost info and help strs
	TextSize(12);
	sprintf(cur_name,"Prices here are %s.",cost_strs[store_cost_mult]);
	TextSize(10);
	char_port_draw_string( talk_gworld,bottom_help_rects[0],cur_name,0,12);
	char_port_draw_string( talk_gworld,bottom_help_rects[1],"Click on item name (or type 'a'-'h') to buy.",0,12);
	char_port_draw_string( talk_gworld,bottom_help_rects[2],"Hit done button (or Esc.) to quit.",0,12);
	if ((store_shop_type != 3) && (store_shop_type != 4))
		char_port_draw_string( talk_gworld,bottom_help_rects[3],"'I' button brings up description.",0,12);
	
	
	ForeColor(blackColor);
	GetPortBounds(talk_gworld,&area_rect);
	ClipRect(&area_rect);
	SetPort(old_port);

	refresh_shopping();
	ShowControl(shop_sbar);
	Draw1Control(shop_sbar);
}
Exemplo n.º 24
0
OSErr
RunAllXPIs(short xpiVRefNum, long xpiDirID, short vRefNum, long dirID)
{
	OSErr 				err = noErr;
	FSSpec				tgtDirSpec, xpiStubDirSpec, xpiSpec;
	XPI_InitProc		xpi_initProc;
	XPI_InstallProc		xpi_installProc;
	XPI_ExitProc		xpi_exitProc;
	CFragConnectionID	connID;
	nsresult 			rv = NS_OK;
	StringPtr			pcurrArchive;
	int					i, len, compsDone = 0, numXPIs, currXPICount = 0, instChoice = gControls->opt->instChoice-1;
	Boolean				isCurrXPI = false, indeterminateFlag = false;
	Str255				installingStr, msg;
	StringPtr           pTargetSubfolder = "\p"; /* subfolder is optional so init empty */
	long                dummyDirID = 0;
	
    err = FSMakeFSSpec(vRefNum, dirID, kViewerFolder, &xpiStubDirSpec); /* xpistub dir */
    if (gControls->cfg->targetSubfolder)
    {
        HLock(gControls->cfg->targetSubfolder);
        if (*gControls->cfg->targetSubfolder)
            pTargetSubfolder = CToPascal(*gControls->cfg->targetSubfolder);
        HUnlock(gControls->cfg->targetSubfolder);
    }
    err = FSMakeFSSpec(gControls->opt->vRefNum, gControls->opt->dirID, /* program dir */
	                   pTargetSubfolder, &tgtDirSpec);
	if (err == fnfErr)
	    err = FSpDirCreate(&tgtDirSpec, smSystemScript, &dummyDirID);
	    
	if (err != noErr)
    {
        ErrorHandler(err, nil);
        return err;
    }

	ERR_CHECK_MSG(LoadXPIStub(&xpi_initProc, &xpi_installProc, &xpi_exitProc, &connID, xpiStubDirSpec, msg), err, msg);
	XPI_ERR_CHECK(xpi_initProc( xpiStubDirSpec, tgtDirSpec, NULL, xpicbProgress ));
	    
	// init overall xpi indicator
	numXPIs = CountSelectedXPIs();
	if (gControls->tw->allProgressBar)
	{
		SetControlMaximum(gControls->tw->allProgressBar, numXPIs*2); // numXPIs * 2 so that prog bar moves more
		SetControlData(gControls->tw->allProgressBar, kControlNoPart, kControlProgressBarIndeterminateTag,
						sizeof(indeterminateFlag), (Ptr) &indeterminateFlag);
		SetControlValue(gControls->tw->allProgressBar, 0);
		Draw1Control(gControls->tw->allProgressBar);
	}
	
	if (gControls->tw->xpiProgressBar)
		ShowControl(gControls->tw->xpiProgressBar);
		
	// enumerate through all .xpi's
	// loop through 0 to kMaxComponents
	for(i=0; i<kMaxComponents; i++)
	{
	    BreathFunc();
		// general test: if component in setup type
		if ( (gControls->cfg->st[instChoice].comp[i] == kInSetupType) &&
			 (compsDone < gControls->cfg->st[instChoice].numComps) )
		{ 
			// if custom and selected, or not custom setup type
			// add file to buffer
			if ( ((instChoice == gControls->cfg->numSetupTypes-1) && 
				  (gControls->cfg->comp[i].selected == true)) ||
				 (instChoice < gControls->cfg->numSetupTypes-1) )
			{
				// if LAUNCHAPP and DOWNLOAD_ONLY attr wasn't set
			 	if (!gControls->cfg->comp[i].launchapp && !gControls->cfg->comp[i].download_only)
				{
					HLock(gControls->cfg->comp[i].archive);
					pcurrArchive = CToPascal(*gControls->cfg->comp[i].archive);
					HUnlock(gControls->cfg->comp[i].archive);
		
					isCurrXPI = IsArchiveXPI(pcurrArchive);
								
					err = FSMakeFSSpec(xpiVRefNum, xpiDirID, pcurrArchive, &xpiSpec);
					if (err==noErr && isCurrXPI)
					{
						// update package display name
						if (gControls->tw->allProgressMsg)
						{
							ProgressMsgInit();
							GetResourcedString(installingStr, rInstList, sInstalling);
							TEInsert(&installingStr[1], installingStr[0], gControls->tw->allProgressMsg);
							HLock(gControls->cfg->comp[i].shortDesc);
							len = strlen(*gControls->cfg->comp[i].shortDesc);
							TEInsert(*gControls->cfg->comp[i].shortDesc, (len>64?64:len), gControls->tw->allProgressMsg);
							HUnlock(gControls->cfg->comp[i].shortDesc);
						}
						
						err = RunXPI(xpiSpec, &xpi_installProc);
						BreathFunc();
						if (err != NS_OK)
						    break;
						
						// update progess bar
						if (gControls->tw->allProgressBar)
							SetControlValue(gControls->tw->allProgressBar,
											GetControlValue(gControls->tw->allProgressBar)+1);
					}
					if (pcurrArchive)
						DisposePtr((Ptr) pcurrArchive);
				}
				compsDone++;
			}
		}
		else if (compsDone >= gControls->cfg->st[instChoice].numComps)
			break;  
	}
	
	xpi_exitProc();	
	UnloadXPIStub(&connID);
	
    if (pTargetSubfolder)
	    DisposePtr((Ptr)pTargetSubfolder);
	return err;
}