예제 #1
0
void
DeviceEditWidget::SetConfig(const DeviceConfig &_config)
{
  config = _config;

  if (config.port_type == DeviceConfig::PortType::DISABLED)
    /* if the user configures a new device, forget the old "enabled"
       flag and re-enable the device */
    config.enabled = true;

  WndProperty &port_control = GetControl(Port);
  DataFieldEnum &port_df = *(DataFieldEnum *)port_control.GetDataField();
  SetPort(port_df, config);
  port_control.RefreshDisplay();

  WndProperty &baud_control = GetControl(BaudRate);
  DataFieldEnum &baud_df = *(DataFieldEnum *)baud_control.GetDataField();
  baud_df.Set(config.baud_rate);
  baud_control.RefreshDisplay();

  WndProperty &bulk_baud_control = GetControl(BulkBaudRate);
  DataFieldEnum &bulk_baud_df = *(DataFieldEnum *)
    bulk_baud_control.GetDataField();
  bulk_baud_df.Set(config.bulk_baud_rate);
  bulk_baud_control.RefreshDisplay();

  WndProperty &ip_address_control = GetControl(IP_ADDRESS);
  DataFieldEnum &ip_address_df = *(DataFieldEnum *)
    ip_address_control.GetDataField();
  ip_address_df.Set(config.ip_address);
  ip_address_control.RefreshDisplay();

  WndProperty &tcp_port_control = GetControl(TCPPort);
  DataFieldEnum &tcp_port_df = *(DataFieldEnum *)
    tcp_port_control.GetDataField();
  tcp_port_df.Set(config.tcp_port);
  tcp_port_control.RefreshDisplay();

  WndProperty &i2c_bus_control = GetControl(I2CBus);
  DataFieldEnum &i2c_bus_df = *(DataFieldEnum *)
    i2c_bus_control.GetDataField();
  i2c_bus_df.Set(config.i2c_bus);
  i2c_bus_control.RefreshDisplay();

  WndProperty &i2c_addr_control = GetControl(I2CAddr);
  DataFieldEnum &i2c_addr_df = *(DataFieldEnum *)
    i2c_addr_control.GetDataField();
  i2c_addr_df.Set(config.i2c_addr);
  i2c_addr_control.RefreshDisplay();

  WndProperty &press_control = GetControl(PressureUsage);
  DataFieldEnum &press_df = *(DataFieldEnum *)
    press_control.GetDataField();
  press_df.Set((unsigned)config.press_use);
  press_control.RefreshDisplay();

  WndProperty &driver_control = GetControl(Driver);
  DataFieldEnum &driver_df = *(DataFieldEnum *)driver_control.GetDataField();
  driver_df.Set(config.driver_name);
  driver_control.RefreshDisplay();

  WndProperty &sync_from_control = GetControl(SyncFromDevice);
  DataFieldBoolean &sync_from_df =
      *(DataFieldBoolean *)sync_from_control.GetDataField();
  sync_from_df.Set(config.sync_from_device);
  sync_from_control.RefreshDisplay();

  WndProperty &sync_to_control = GetControl(SyncToDevice);
  DataFieldBoolean &sync_to_df =
      *(DataFieldBoolean *)sync_to_control.GetDataField();
  sync_to_df.Set(config.sync_to_device);
  sync_to_control.RefreshDisplay();

  WndProperty &k6bt_control = GetControl(K6Bt);
  DataFieldBoolean &k6bt_df =
      *(DataFieldBoolean *)k6bt_control.GetDataField();
  k6bt_df.Set(config.k6bt);
  k6bt_control.RefreshDisplay();

  UpdateVisibilities();
}
예제 #2
0
파일: atsui.c 프로젝트: arnelh/Examples
// Draws the current ATSUI data.  Takes a GrafPtr as an argument so
// that it can handle printing as well as drawing into a window.
//
void DrawATSUIStuff(GrafPtr drawingPort)
{
    GrafPtr                             savedPort;
    Rect                                portBounds, quarterRect2, quarterRect3;
    float								windowHeight, quarter;
    CGContextRef						context;
    TXNTextBoxOptionsData				optionsData;
    Boolean								needToUseCGStrokeMethod;

    // Set up the GrafPort
    GetPort(&savedPort);
    SetPort(drawingPort);
    GetPortBounds(drawingPort, &portBounds);
    EraseRect(&portBounds);

    // Divide the window into vertical quarters, and draw the text in the middle two quarters
    windowHeight = portBounds.bottom - portBounds.top;
    quarter = windowHeight / 4.0;
    MacSetRect(&quarterRect2, portBounds.left, portBounds.top + quarter, portBounds.right, portBounds.bottom - (quarter * 2.0));
    FrameRect(&quarterRect2);
    MacSetRect(&quarterRect3, portBounds.left, portBounds.top + (quarter * 2.0), portBounds.right, portBounds.bottom - quarter);
    FrameRect(&quarterRect3);

    // Set up the CGContext
    if (gNewCG) QDBeginCGContext(drawingPort, &context); else CreateCGContextForPort(drawingPort, &context);

    // Setup the options to pass into TXNDrawUnicodeTextBox
    optionsData.optionTags = kTXNUseCGContextRefMask | kTXNSetFlushnessMask | kTXNUseFontFallBackMask;
    optionsData.flushness = X2Frac(0.5);   // Center the text horizontally, just for this demo.
    optionsData.options = (void *)context; // This parameter really needs to be renamed, see 3198383.

    // Draw the text once without the extr bold
    verify_noerr( TXNDrawUnicodeTextBox(gText, gLength, &quarterRect2, gStyle, &optionsData) );

    // ----------------------------------------------------------
    //
    // Here is where we change the setting to do the extra stroke
    // The value of gStrokeThicknessFactor determines how thick the extra stroke is.
    //   The "standard" value used by ATSUI is 0.024;
    //     this was changed to 0.044 for bug 3189696,
    //     and will probably be changed back, so if you
    //     want the extra stroke, you will have to do it
    //     manually, as is done below.
    //
    // The extra stroke method:
    //  - will look good on-screen when CG anti-aliasing is ON
    //  - will look good when printing
    //  - will *NOT* look good on-screen when CG anti-aliasing is OFF
    //     (just use kATSUQDBoldfaceTag in that case)
    //
    needToUseCGStrokeMethod = gCurrentlyPrinting || IsAntiAliased(gPointSize);
    if ( needToUseCGStrokeMethod ) {
        CGContextSaveGState(context);
        CGContextSetTextDrawingMode(context, kCGTextFillStroke);
        CGContextSetLineWidth(context, gStrokeThicknessFactor * Fix2X(gPointSize));
        // You might want to call CGContextSetStrokeColor() here,
        // just to make certain it is the same as the text/fill color.
    }
    else
        MySetBoldfaceTag(gStyle); // This will look very strong on-screen when CG anti-aliasing is off

    // Draw the text again with the extra bold for comparison
    verify_noerr( TXNDrawUnicodeTextBox(gText, gLength, &quarterRect3, gStyle, &optionsData) );

    // Undo the previous CG text mode setting
    if ( needToUseCGStrokeMethod )
        CGContextRestoreGState(context);
    else
        MyClearBoldfaceTag(gStyle);

    // Tear down the CGContext since we are done with it
    if (gNewCG) QDEndCGContext(drawingPort, &context); else CGContextRelease(context);    

    // Restore the GrafPort
    SetPort(savedPort);
}
예제 #3
0
static void ROM_HideMenuBar(_THIS)
{
#if !TARGET_API_MAC_CARBON /* This seems not to be available? -sts Aug 2000 */
	RgnHandle		drawRgn = nil;
	RgnHandle		tempRgn = nil;
	RgnHandle		grayRgn = nil;
	WindowPtr		window = nil;
	GDHandle		gd = nil;
	GrafPtr			savePort;
	long			response;
	short			height;
	EventRecord		theEvent;

	height = GetMBarHeight();
	
	if ( height > 0 ) {
		tempRgn = NewRgn();
		drawRgn = NewRgn();
		gSaveGrayRgn = NewRgn();
		if ( ! tempRgn || ! drawRgn || ! gSaveGrayRgn ) {
			goto CLEANUP;
		}
		grayRgn = GetGrayRgn(); /* No need to check for this */
	
		GetPort(&savePort);

		/* Hide the control strip if it's present, and record its 
		   previous position into the dirty region for redrawing. 
		   This isn't necessary, but may help catch stray bits. */
		CopyRgn(grayRgn, tempRgn);
		if (!Gestalt(gestaltControlStripAttr, &response) && 
			(response & (1L << gestaltControlStripExists))) {
			gSaveCSVis = SBIsControlStripVisible();
			if (gSaveCSVis)
				SBShowHideControlStrip(false);
		}
		DiffRgn(grayRgn, tempRgn, drawRgn);

		/* Save the gray region once the control strip is hidden*/
		CopyRgn(grayRgn, gSaveGrayRgn);

		/* Change the menu height in lowmem */
		gSaveMenuBar = height;
		LMSetMBarHeight(0);
		
		/* Walk the monitor rectangles, and combine any pieces that
		   aren't in GrayRgn: menubar, round corners, fake floaters. */
		for(gd = GetDeviceList(); gd; gd = GetNextDevice(gd)) 
			{
			if (!TestDeviceAttribute(gd, screenDevice)) continue;
			if (!TestDeviceAttribute(gd, screenActive)) continue;

			RectRgn(tempRgn, &(*gd)->gdRect);	/* Get the whole screen */
			DiffRgn(tempRgn, grayRgn, tempRgn); /* Subtract out GrayRgn */
			UnionRgn(tempRgn, drawRgn, drawRgn);/* Combine all the bits */
			}
			
		/* Add the bits into the GrayRgn */
		UnionRgn(drawRgn, grayRgn, grayRgn);

		/* Modify the vis regions of exposed windows */
		window = (FrontWindow()) ? FrontWindow() : (WindowPtr) -1L;
		PaintBehind(window, drawRgn);
		CalcVisBehind(window, drawRgn);

		SetPort(savePort);
		
		/* Yield time so that floaters can catch up */
		EventAvail(0, &theEvent);
		EventAvail(0, &theEvent);
		EventAvail(0, &theEvent);
		EventAvail(0, &theEvent);
		}

CLEANUP:

	if (tempRgn) DisposeRgn(tempRgn);
	if (drawRgn) DisposeRgn(drawRgn);
#endif /* !TARGET_API_MAC_CARBON */
}
예제 #4
0
파일: sock.c 프로젝트: Cloudxtreme/hybserv2
/*
  DoListen()
*/
void DoListen(struct PortInfo *portptr)
{
	struct addrinfo hints;
	struct addrinfo *res, *res_o;
	int error;
	char port[MAXLINE];

	/* can't use standard LookupHostname */
	memset(&hints, 0, sizeof(hints));
	hints.ai_family = PF_UNSPEC;
	hints.ai_socktype = SOCK_STREAM;
	hints.ai_flags = AI_PASSIVE;

	ircsprintf(port, "%d", portptr->port);
	error = getaddrinfo(LocalHostName, port, &hints, &res);

	res_o = res;

	if (error)
	{
		putlog(LOG1,
		       "Unable to get local addresses, this should never happen: %s",
		       gai_strerror(error));
		return;
	}

	while (res != NULL)
	{
		if ((portptr->socket = socket(res->ai_family, SOCK_STREAM, 6)) == -1)
		{
			res = res->ai_next;
			portptr->socket = NOSOCKET;
			continue;
		}

		/* set various socket options */
		SetSocketOptions(portptr->socket);
		SetPort((struct sockaddr *)res->ai_addr, portptr->port);

		if (bind(portptr->socket, res->ai_addr, res->ai_addrlen) == -1)
		{
			putlog(LOG1, "FATAL: Unable to bind port tcp/%d: %s",
			       portptr->port, strerror(errno));
			close(portptr->socket);
			portptr->socket = NOSOCKET;
		}
		else
#ifdef SOMAXCONN
			if (listen(portptr->socket, SOMAXCONN) == -1)
#else

			if (listen(portptr->socket, HYBSERV_SOMAXCONN) == -1)
#endif

			{
				putlog(LOG1, "Unable to listen on port tcp/%d: %s",
				       portptr->port, strerror(errno));
				close(portptr->socket);
				portptr->socket = NOSOCKET;
			}
			else
			{
				putlog(LOG1,
				       "Listener successfully started on host [%s] port tcp/%d",
				       (LocalHostName != NULL) ? LocalHostName : "*",
				       portptr->port);
			}

		res = res->ai_next;
	}

	portptr->tries++;

	if (res_o != NULL)
		freeaddrinfo(res_o);
} /* DoListen() */
예제 #5
0
/*
 * External interface
 */
    static void
DoPyCommand(const char *cmd, rangeinitializer init_range, runner run, void *arg)
{
#ifndef PY_CAN_RECURSE
    static int		recursive = 0;
#endif
#if defined(MACOS) && !defined(MACOS_X_UNIX)
    GrafPtr		oldPort;
#endif
#if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
    char		*saved_locale;
#endif
#ifdef PY_CAN_RECURSE
    PyGILState_STATE	pygilstate;
#endif

#ifndef PY_CAN_RECURSE
    if (recursive)
    {
	EMSG(_("E659: Cannot invoke Python recursively"));
	return;
    }
    ++recursive;
#endif

#if defined(MACOS) && !defined(MACOS_X_UNIX)
    GetPort(&oldPort);
    /* Check if the Python library is available */
    if ((Ptr)PyMac_Initialize == (Ptr)kUnresolvedCFragSymbolAddress)
	goto theend;
#endif
    if (Python_Init())
	goto theend;

    init_range(arg);

    Python_Release_Vim();	    /* leave vim */

#if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
    /* Python only works properly when the LC_NUMERIC locale is "C". */
    saved_locale = setlocale(LC_NUMERIC, NULL);
    if (saved_locale == NULL || STRCMP(saved_locale, "C") == 0)
	saved_locale = NULL;
    else
    {
	/* Need to make a copy, value may change when setting new locale. */
	saved_locale = (char *) PY_STRSAVE(saved_locale);
	(void)setlocale(LC_NUMERIC, "C");
    }
#endif

#ifdef PY_CAN_RECURSE
    pygilstate = PyGILState_Ensure();
#else
    Python_RestoreThread();	    /* enter python */
#endif

    run((char *) cmd, arg
#ifdef PY_CAN_RECURSE
	    , &pygilstate
#endif
	    );

#ifdef PY_CAN_RECURSE
    PyGILState_Release(pygilstate);
#else
    Python_SaveThread();	    /* leave python */
#endif

#if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
    if (saved_locale != NULL)
    {
	(void)setlocale(LC_NUMERIC, saved_locale);
	PyMem_Free(saved_locale);
    }
#endif

    Python_Lock_Vim();		    /* enter vim */
    PythonIO_Flush();
#if defined(MACOS) && !defined(MACOS_X_UNIX)
    SetPort(oldPort);
#endif

theend:
#ifndef PY_CAN_RECURSE
    --recursive;
#endif
    return;
}
예제 #6
0
파일: np2.cpp 프로젝트: perabuss/np2wii
int main(int argc, char *argv[]) {

	Rect		wRect;
	EventRecord	event;
	UINT		t;
	GrafPtr		saveport;
	Point		pt;

	dosio_init();
	file_setcd(target);

	InitToolBox();
	macossub_init();
	initload();

	MenuBarInit();

	TRACEINIT();

	keystat_initialize();

	SetRect(&wRect, np2oscfg.posx, np2oscfg.posy, 100, 100);
#if !defined(SUPPORT_PC9821)
	hWndMain = NewWindow(0, &wRect, "\pNeko Project II", FALSE,
								noGrowDocProc, (WindowPtr)-1, TRUE, 0);
#else
	hWndMain = NewWindow(0, &wRect, "\pNeko Project 21", FALSE,
								noGrowDocProc, (WindowPtr)-1, TRUE, 0);
#endif
	if (!hWndMain) {
		TRACETERM();
		macossub_term();
		dosio_term();
		return(0);
	}
	scrnmng_initialize();
	SizeWindow(hWndMain, 640, 400, TRUE);
	ShowWindow(hWndMain);

	menu_setrotate(0);
	menu_setdispmode(np2cfg.DISPSYNC);
	menu_setraster(np2cfg.RASTER);
	menu_setwaitflg(np2oscfg.NOWAIT);
	menu_setframe(np2oscfg.DRAW_SKIP);

	menu_setkey(0);
	menu_setxshift(0);
	menu_setf11key(np2oscfg.F11KEY);
	menu_setf12key(np2oscfg.F12KEY);
	menu_setbeepvol(np2cfg.BEEP_VOL);
	menu_setsound(np2cfg.SOUND_SW);
	menu_setjastsnd(np2oscfg.jastsnd);
	menu_setmotorflg(np2cfg.MOTOR);
	menu_setextmem(np2cfg.EXTMEM);

	menu_setdispclk(np2oscfg.DISPCLK);
	menu_setbtnrapid(np2cfg.BTN_RAPID);
	menu_setbtnmode(np2cfg.BTN_MODE);

	scrnmode = 0;
	if (scrnmng_create(scrnmode) != SUCCESS) {
		TRACETERM();
		macossub_term();
		dosio_term();
		DisposeWindow(hWndMain);
		return(0);
	}

	np2open();
	t = GETTICK();
	while((GETTICK() - t) < 100) {
		if (WaitNextEvent(everyEvent, &event, 0, 0)) {
			eventproc(&event);
		}
	}

	commng_initialize();
	sysmng_initialize();
	mackbd_initialize();
	pccore_init();
	S98_init();

	mousemng_initialize();
	if (np2oscfg.MOUSE_SW) {										// ver0.30
		mousemng_enable(MOUSEPROC_SYSTEM);
	}
//	scrndraw_redraw();
	pccore_reset();

#if defined(SUPPORT_RESUME)
	if (np2oscfg.resume) {
		flagload(np2resumeext, FALSE);
	}
#endif

	SetEventMask(everyEvent);

	np2running = TRUE;
	while(np2running) {
		if (WaitNextEvent(everyEvent, &event, 0, 0)) {
			eventproc(&event);
		}
		else {
			if (np2oscfg.NOWAIT) {
				mackbd_callback();
				mousemng_callback();
				pccore_exec(framecnt == 0);
				if (np2oscfg.DRAW_SKIP) {			// nowait frame skip
					framecnt++;
					if (framecnt >= np2oscfg.DRAW_SKIP) {
						processwait(0);
					}
				}
				else {								// nowait auto skip
					framecnt = 1;
					if (timing_getcount()) {
						processwait(0);
					}
				}
			}
			else if (np2oscfg.DRAW_SKIP) {			// frame skip
				if (framecnt < np2oscfg.DRAW_SKIP) {
					mackbd_callback();
                    mousemng_callback();
					pccore_exec(framecnt == 0);
					framecnt++;
				}
				else {
					processwait(np2oscfg.DRAW_SKIP);
				}
			}
			else {								// auto skip
				if (!waitcnt) {
					UINT cnt;
					mackbd_callback();
                    mousemng_callback();
					pccore_exec(framecnt == 0);
					framecnt++;
					cnt = timing_getcount();
					if (framecnt > cnt) {
						waitcnt = framecnt;
						if (framemax > 1) {
							framemax--;
						}
					}
					else if (framecnt >= framemax) {
						if (framemax < 12) {
							framemax++;
						}
						if (cnt >= 12) {
							timing_reset();
						}
						else {
							timing_setcount(cnt - framecnt);
						}
						framereset();
					}
				}
				else {
					processwait(waitcnt);
					waitcnt = framecnt;
				}
			}
		}
	}

	GetPort(&saveport);
#if TARGET_API_MAC_CARBON
	SetPortWindowPort(hWndMain);
#else
	SetPort(hWndMain);
#endif
	pt.h = 0;
	pt.v = 0;
	LocalToGlobal(&pt);
	SetPort(saveport);
	if ((np2oscfg.posx != pt.h) || (np2oscfg.posy != pt.v)) {
		np2oscfg.posx = pt.h;
		np2oscfg.posy = pt.v;
		sysmng_update(SYS_UPDATEOSCFG);
	}

	np2running = FALSE;

	pccore_cfgupdate();

#if defined(SUPPORT_RESUME)
	if (np2oscfg.resume) {
		flagsave(np2resumeext);
	}
	else {
		flagdelete(np2resumeext);
	}
#endif

	pccore_term();
	S98_trash();

	mousemng_disable(MOUSEPROC_SYSTEM);

	scrnmng_destroy();

	if (sys_updates	& (SYS_UPDATECFG | SYS_UPDATEOSCFG)) {
		initsave();
	}
	TRACETERM();
	macossub_term();
	dosio_term();

	DisposeWindow(hWndMain);

	(void)argc;
	(void)argv;
	return(0);
}
예제 #7
0
Boolean ThermDialog::DisplayTherm(int k,int maxk,unsigned char *st)
{

    Rect r;
    int	maxr;
    Handle h;
    short itemType;
    long 	temp;
    GrafPtr	tdp;
    WindowPtr   	window;
    short       	thePart;
    Rect        	screenRect, updateRect;
    Point			aPoint = {100, 100};
    Boolean 		QuitFlag = FALSE;
    short			item = 0;
    EventRecord 	event;
    short		the_part;
    DialogPtr 	hitdp;

    GetPort(&tdp);
    SetPort(dp);

    if (st != NULL)
    {
        GetDItem (dp,ids[THERM_TEXT], &itemType, &h, &r);
        SetIText(h,st);
    }


    GetDItem (dp, ids[THERM_BOX], &itemType, &h, &r);

    if (k == -1) k = old_k;
    if (maxk == -1) maxk = old_maxk;

    maxr = r.right;
    temp = ((long)k*((long)r.right - (long)r.left))/(long)maxk;
    r.right = r.left + temp;
    if (r.right>maxr) r.right=maxr;

    old_k = k;
    old_maxk = maxk;

    PenNormal ();
    PenPat(&qd.gray);
    PaintRect(&r);

    PenNormal ();

    SetPort(tdp);

    if (GetNextEvent(0xFFFF,&event))
    {
        if (event.what == mouseDown)
        {
            the_part = FindWindow(event.where, &window);
            if (IsDialogEvent(&event))
            {
                DialogSelect(&event,&hitdp,&item);
                if ((hitdp == dp) && (item == ids[THERM_CANCEL]))
                {
                    Quit = TRUE;
                    return FALSE;
                }
            }
            else switch (the_part) {
                case inSysWindow:
                    SystemClick (&event, window);
                    break;
                case inDrag:
                    screenRect = (**GetGrayRgn()).rgnBBox;
                    DragWindow( window, event.where, &screenRect );
                    break;
                }
        }
        else if (event.what == keyDown)
        {
            if ((event.modifiers & 0x0100) && ( (event.message) & charCodeMask == 0x02E))
            {
                Quit = TRUE;
                return FALSE;
            }
        }
        else if (event.what == updateEvt)
        {
            window = (WindowPtr)event.message;
            updateRect = (**(window->visRgn)).rgnBBox;
            SetPort( window ) ;
            BeginUpdate( window );
            DrawDialog( window );
            if (dp == window) box_d_item(dp,ids[THERM_BOX]);
            EndUpdate( window );
        }
    }
    if (Quit) return FALSE;
    return TRUE;
}
예제 #8
0
파일: MacGraph.c 프로젝트: rolk/ug
INT GrowGraphWindow (GRAPH_WINDOW *gw, EventRecord *theEvent, DOC_GROW_EVENT *docGrow)
{
  long growResult;
  Rect r,sizeRect,beforeRect,afterRect;
  WindowPtr theWindow;
  Rect myClipRect;

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

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

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

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

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

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

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

    ClipRect(&myClipRect);

    return (POS_CHANGE);
  }
  else
    return (NO_POS_CHANGE);
}
예제 #9
0
파일: printmac.cpp 프로젝트: Duion/Torsion
bool wxMacPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt)
{
    sm_abortIt = FALSE;
    sm_abortWindow = NULL;
    
    if (!printout)
        return FALSE;
    
    printout->SetIsPreview(FALSE);
    if (m_printDialogData.GetMinPage() < 1)
        m_printDialogData.SetMinPage(1);
    if (m_printDialogData.GetMaxPage() < 1)
        m_printDialogData.SetMaxPage(9999);

    // Create a suitable device context  
    wxDC *dc = NULL;
    if (prompt)
    {
        wxPrintDialog dialog(parent, & m_printDialogData);
        if (dialog.ShowModal() == wxID_OK)
        {
            dc = dialog.GetPrintDC();
            m_printDialogData = dialog.GetPrintDialogData();
        }
    }
    else
    {
        dc = new wxPrinterDC( m_printDialogData.GetPrintData() ) ;
    }
    
    
    // May have pressed cancel.
    if (!dc || !dc->Ok())
    {
        if (dc) delete dc;
        return FALSE;
    }
    
    // on the mac we have always pixels as addressing mode with 72 dpi
    
    printout->SetPPIScreen(72, 72);
    PMResolution res;
    wxMacCarbonPrintData* nativeData = (wxMacCarbonPrintData*)
          (m_printDialogData.GetPrintData().GetNativeData());
    PMGetResolution((PMPageFormat) (nativeData->m_macPageFormat), &res);
    printout->SetPPIPrinter(int(res.hRes), int(res.vRes));
    
    // Set printout parameters  
    printout->SetDC(dc);
    
    int w, h;
    wxCoord ww, hh;
    dc->GetSize(&w, &h);
    printout->SetPageSizePixels((int)w, (int)h);
    dc->GetSizeMM(&ww, &hh);
    printout->SetPageSizeMM((int)ww, (int)hh);
    
    // Create an abort window
    wxBeginBusyCursor();
    
    printout->OnPreparePrinting();
    
    // Get some parameters from the printout, if defined
    int fromPage, toPage;
    int minPage, maxPage;
    printout->GetPageInfo(&minPage, &maxPage, &fromPage, &toPage);
    
    if (maxPage == 0)
    {
        wxEndBusyCursor();
        return FALSE;
    }
    
    // Only set min and max, because from and to have been
    // set by the user
    m_printDialogData.SetMinPage(minPage);
    m_printDialogData.SetMaxPage(maxPage);
    
    wxWindow *win = CreateAbortWindow(parent, printout);
    wxSafeYield(win,true);
    
    if (!win)
    {
        wxEndBusyCursor();
        wxMessageBox(wxT("Sorry, could not create an abort dialog."), wxT("Print Error"), wxOK, parent);
        delete dc;
        return FALSE;
    }
    sm_abortWindow = win;
    sm_abortWindow->Show(TRUE);
    wxSafeYield(win,true);
    
    printout->OnBeginPrinting();
    
    bool keepGoing = TRUE;
    
    int copyCount;
    for (copyCount = 1; copyCount <= m_printDialogData.GetNoCopies(); copyCount ++)
    {
        if (!printout->OnBeginDocument(m_printDialogData.GetFromPage(), m_printDialogData.GetToPage()))
        {
            wxEndBusyCursor();
            wxMessageBox(wxT("Could not start printing."), wxT("Print Error"), wxOK, parent);
            break;
        }
        if (sm_abortIt)
            break;
        
        int pn;
        for (pn = m_printDialogData.GetFromPage(); keepGoing && (pn <= m_printDialogData.GetToPage()) && printout->HasPage(pn);
        pn++)
        {
            if (sm_abortIt)
            {
                keepGoing = FALSE;
                break;
            }
            else
            {
#if TARGET_CARBON
                if ( UMAGetSystemVersion() >= 0x1000 )
#endif
                {
                    GrafPtr thePort ;
                    GetPort( &thePort ) ;
                    wxSafeYield(win,true);
                    SetPort( thePort ) ;
                }
                dc->StartPage();
                keepGoing = printout->OnPrintPage(pn);
                dc->EndPage();
            }
        }
        printout->OnEndDocument();
    }
    
    printout->OnEndPrinting();
    
    if (sm_abortWindow)
    {
        sm_abortWindow->Show(FALSE);
        delete sm_abortWindow;
        sm_abortWindow = NULL;
    }
    
    wxEndBusyCursor();
    
    delete dc;
    
    return TRUE;
}
RangeTrackRawAnalogRangeReader::RangeTrackRawAnalogRangeReader(int port)
// don't delete the following line as it's needed to preserve source code of this autogenerated element
// section -64--88-1-7-672b1494:1245fa68a9a:-8000:0000000000000FB0 begin
{
    SetPort(port);
}
예제 #11
0
void DoMouseDown(EventRecord e)
{
short	partCode;
WindowPtr	whichWindow;
Rect	dragRect;
Point 	pt;

	switch(partCode = FindWindow(e.where, &whichWindow)) {
		case inMenuBar:
			FixMenus();
			ProcessMenu(MenuSelect(e.where));
			break;

		case inSysWindow:
			SystemClick(&e, whichWindow);
			break;

		case inContent:
			if(whichWindow != FrontWindow())
				SelectWindow(whichWindow);
			if(whichWindow==nesWind)
				DoClickInNES(e);
			if(whichWindow==wpWind)
				DoClickInWP(e);
			if(whichWindow==srchWind)
				DoClickInSrch(e);

#ifdef GB_DEBUG
			if(whichWindow==statWind)
				DoClickInStat(e);
			if(whichWindow==patWind)
				DoClickInPat(e);
#endif

			break;

		case inDrag:
			dragRect = qd.screenBits.bounds;
			InsetRect(&dragRect, 5, 5);
			DragWindow(whichWindow, e.where, &dragRect);
			
			if(whichWindow == nesWind) {
				SetPt(&pt,0,0);
				SetPort(nesWind); LocalToGlobal(&pt);
				MoveWindow(nesWind,pt.h & 0xfff8,pt.v,false);

				SetPt(&pt,0,0); LocalToGlobal(&pt);
				if( (pt.h < 0) || (pt.v < 20) )
					MoveWindow(nesWind,8,40,false);

				SetPt(&pt,nesWind->portRect.right,nesWind->portRect.bottom);
				LocalToGlobal(&pt);
				if( (pt.h > scrnW) || (pt.v > scrnH) )
					MoveWindow(nesWind,8,40,false);
			}
			
			WP_RepositionWind();
			Srch_RepositionWind();
			break;

		case inGoAway:
			if(TrackGoAway(whichWindow, e.where))
				DoCloseWindow(whichWindow);
			break;

		default: break;
	}
	
	vVrtFrame = vActFrame;		// keep timing code working
}
예제 #12
0
파일: mac.c 프로젝트: chasonr/retrohack
int
tgetch()

{
	char	ch;
	EventRecord	theEvent;
	Rect cursorRect,box,windowRect;
	long	message,cursorTime,start;
	MenuHandle	theMenu;
	register short	keyCode;
	short	temp;
	term_info	*t;
	GrafPtr	oldPort,oldPort1;
	static char nextCommand;
	short aboutBox();
	char mButtonDown();
	Point	mouseLoc;
	WindowPtr	theWindow;
	void	doUpdate();
#define	clearKey	0x47
#define ESCAPEkey	0x1B
	static int see, saw = 0;
	int eye, cursOff = 100;
	boolean cursRectInv;	/* should be a macflag */
	short	fInFront = TRUE;

	t = (term_info *)GetWRefCon(HackWindow);
	mouseLoc.h = (macflags & fMoveWRTMouse) ? t->tcur_x : (u.ux-1);
	mouseLoc.v = (macflags & fMoveWRTMouse) ? t->tcur_y : (u.uy+1);
	cursorRect.left = t->tcur_x * t->charWidth + Screen_Border;
	cursorRect.right = cursorRect.left + t->charWidth - 1;
	cursorRect.top = t->height * t->tcur_y + Screen_Border;
	cursorRect.bottom = cursorRect.top + t->height - 1;
	cursorTime = GetCaretTime();
	box.left = mouseLoc.h * t->charWidth + Screen_Border - 1;
	box.right = box.left + t->charWidth + 2;
	box.top = mouseLoc.v * t->height + Screen_Border - 1;
	box.bottom = box.top + t->height + 2;
	/* permit use of cursor keys and numeric keypad */
	/* does the same translation as in msdos.c but includes cursor keys */
	ch = '\0';
	/* handle extended command from menu */
	if (nextCommand && (macflags & (fExtCmdSeq1 | fExtCmdSeq2 | fExtCmdSeq3))) {
	    if (macflags & fExtCmdSeq1) {
		ch = '#';
		macflags = macflags ^ (fExtCmdSeq1 | fExtCmdSeq2);
	    } else if (macflags & fExtCmdSeq2) {
		ch = nextCommand;
		macflags = macflags ^ (fExtCmdSeq2 | fExtCmdSeq3);
		if (!(macflags & fExtCmdSeq3))
		    nextCommand = '\0';
	    } else if (macflags & fExtCmdSeq3) {
		ch = '\r';
		macflags &= ~fExtCmdSeq3;
	    }
	}
	GetPort(&oldPort);
	SetPort(HackWindow);
	if (!(macflags & fDoNonKeyEvt)) {
		cursorPos = -1;
		if (! flags.wantspace) SetCursor(&ARROW_CURSOR);
	}
	/* initialize cursor blinking */
	message = TickCount() + ((Invisible || (macflags & fMoveWRTMouse)) ? 0L : cursorTime);
	cursRectInv = FALSE;
	while (!ch) {
		(void)WaitNextEvent(everyEvent, &theEvent, (fInFront) ? 0L : 50L, 0L);
		if ((theEvent.what == keyDown || theEvent.what == autoKey) && (FrontWindow() == HackWindow)) {
			ch = 0;
			ObscureCursor();
			/* use raw key codes */
			keyCode = (LoWord(theEvent.message) & keyCodeMask)>>8;
 			if (keyCode == clearKey) {
				macflags = macflags ^ fToggleNumPad;
				SetWTitle(HackWindow,
					(macflags & fToggleNumPad)	? "\016NetHack [MOVE]"
												: "\015NetHack [NUM]");
				ch = 0;
				continue;
			}
			if ((macflags & fToggleNumPad) && (keyCode>0x40 &&keyCode < 0x5D) 
				|| (keyCode > 0x7A && keyCode<0x7F)) {
				ch = t->keyMap[keyCode-65];
				if ((theEvent.modifiers & shiftKey) && (ch)) {
					ch = (ch == '.') ? ':' : (char)toupper(ch);
				}
				if (ch)
					break;
			}
			if (t->system.keyBoardType < 4 && keyCode == 50) {
				ch = (char)ESCAPEkey;	/* ESC */
				break;
			}			/* make the command key = control key on all non-adb keyboards
						 Now, LEAVE it this way ! Otherwise you'll render non-us
keyboards useless, since here is where "<" and ">" are located */
			if ((theEvent.message & 0xFF) == 0x60) {
				ch = (char)ESCAPEkey;
				break;
			} /* This is the way to fix backquote->esc for all macs */
			if (theEvent.modifiers & cmdKey) {
				ch = (char)(theEvent.message & 0x1F);
				if(ch == ('Q' & 0x1F)) ch = 'Q'; /* For Quit */
				break;
			}
			if (theEvent.modifiers & optionKey) {
				for(start = 43; start < 56; start++) {
					if (t->keyMap[start] == (char)(theEvent.message & 0xFFL)) {
						ch = t->keyMap[start - 13];
						break;
					}
				}
			}
			/* not a cursor key or from the numeric keypad */
			if (!ch) {
				ch = (char)(theEvent.message & 0xFF);
			}
		} else {
		/* what other events to handle */
			switch (theEvent.what) {		
예제 #13
0
// The event handler for the main menu
McoStatus	ToneTab::DoEvents(short item, Point clickPoint, WindowCode *wc, int32 *numwc, void **data,Boolean &changed)
{
int					didit = 0;
int		i,j;
McoStatus 			status = MCO_SUCCESS;	
short 				item2 = item - startNum;
Str255				prompt;
StandardFileReply 	soutReply,sinReply;
Str255				outname = "\p";
SFTypeList			filelist;
Str255				inname;
Rect r1;
short	iType;
Handle	iHandle;
WindowPtr	oldP;

GetPort(&oldP);
SetPort( dp ) ;

	// no codes passed back
	*numwc = 0;
	
	for (i=0; i<numControls; i++) 
		{
		status = controls[i]->DoEvents(item,clickPoint,wc,numwc,data,changed,&didit);
		if (status) return status;
		if (changed) 
			{
			doc->changedLinearTone = 1;
			last_changed = 1;
			CopyOutofControl(i);
			CopyIntoControl(i);
			}
		else last_changed = 0;		
		if (didit) return status;
		}

	if (item2 == EXPORT)
		{
		if (doc->calCurves)
			{
			GetIndString(prompt,PROMPT_STRINGS,STANDARD_PROMPT);
			StandardPutFile(prompt, outname, &soutReply);
			if(soutReply.sfGood)
				{
				memcpy(outname, soutReply.sfFile.name, *(soutReply.sfFile.name)+1);	
				PathNameFromDirID(soutReply.sfFile.parID, soutReply.sfFile.vRefNum, outname);
				ptocstr(outname);
				status = doc->calCurves->exportTone((char*)outname);
				if (status) McoErrorAlert(status);
				else 
					{
					FileFormat ff;
	
					ff.setInfo(&soutReply.sfFile,MONACO_SIG,'TEXT');
					}
				}
			}
		}
	else if (item2 == IMPORT)
		{
		if (doc->calCurves)
			{	
			filelist[0] = 'TEXT';
			StandardGetFile(0L, 1, filelist, &sinReply);
			if(sinReply.sfGood)	
				{
				memcpy(inname, sinReply.sfFile.name, *(sinReply.sfFile.name)+1);
				PathNameFromDirID(sinReply.sfFile.parID, sinReply.sfFile.vRefNum, inname);
				ptocstr(inname);	
				status = doc->calCurves->importTone((char*)inname);
				if (status) McoErrorAlert(status);
				else 
					{
					CopyIntoControl(-1);
					doc->changedLinearTone = 1;
					}
				status = MCO_SUCCESS;
				}
			}
		}
	else
		{
		GetDItem (dp, DESCRIPTION+startNum, &iType, (Handle*)&iHandle, &r1);
		GetIText(iHandle,inname);
		if (inname[0] > 100) inname[0] = 100;
		ptocstr(inname);
		strcpy(doc->printData->setting.toneDesc,(char*)inname);
		}
	SetPort(oldP);		
	return status;
}
예제 #14
0
// --------------------------------------------------------------------------------------
static OSStatus MyDoPrintLoop(PMPrintSession printSession, PMPageFormat pageFormat, 
				PMPrintSettings printSettings, const void *ourDataP,
                                const PrintingProcs *printingProcsP)
{
    OSStatus err = noErr;
    OSStatus tempErr = noErr;
    UInt32 firstPage, lastPage, totalDocPages = MyGetDocumentNumPagesInDoc(ourDataP);
    
    if(!err)
	err = PMGetFirstPage(printSettings, &firstPage);
	
    if (!err)
        err = PMGetLastPage(printSettings, &lastPage);

    if(!err && lastPage > totalDocPages){
        // don't draw more than the number of pages in our document
        lastPage = totalDocPages;
    }

    if (!err)		// tell the printing system the number of pages we are going to print
        err = PMSetLastPage(printSettings, lastPage, false);

    //	Note: we don't have to worry about the number of copies.  The printing
    //	manager handles this.  So we just iterate through the document from the
    //	first page to be printed, to the last.
    if (!err)
    {
        PageDrawProc *drawProc = GetMyDrawPageProc(ourDataP);
        err = printingProcsP->BeginDocumentProc(printSession, printSettings, pageFormat);
        if (!err){
	    UInt32 pageNumber = firstPage;
	    // need to check errors from our print loop and errors from the session for each
	    // time around our print loop before calling our BeginPageProc
            while(pageNumber <= lastPage && err == noErr && PMSessionError(printSession) == noErr)
            {
                err = printingProcsP->BeginPageProc(printSession, pageFormat, NULL);
                if (!err){
                    GrafPtr oldPort = NULL;
                    void *printingContext = NULL;
                    GetPort(&oldPort);	// preserve the existing port
                
                    err = PMSessionGetGraphicsContext(printSession, kPMGraphicsContextQuickdraw,
                                                    (void **)&printingContext);
                    if(!err){
                        Rect pageRect;
                        SetPort((CGrafPtr)printingContext);
                        GetPortBounds(printingContext, &pageRect);
                        err = drawProc(ourDataP, &pageRect, pageNumber); // image the correct page
                        SetPort(oldPort);	// restore the prior port
                    }
                    // we must call EndPage if BeginPage returned noErr
		    tempErr = printingProcsP->EndPageProc(printSession);
                        
		    if(!err)err = tempErr;
                }
		pageNumber++;
            }	// end while loop
            
            // we must call EndDocument if BeginDocument returned noErr
	    tempErr = printingProcsP->EndDocumentProc(printSession);

	    if(!err)err = tempErr;
	    if(!err)
		err = PMSessionError(printSession);
        }
    }
    return err;
}
예제 #15
0
void 
XResizeWindow(
    Display* display,		/* Display. */
    Window window, 		/* Window. */
    unsigned int width,
    unsigned int height)
{
    MacDrawable *macWin = (MacDrawable *) window;
    GWorldPtr destPort;

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

    display->request++;
    SetPort((GrafPtr) destPort);
    if (Tk_IsTopLevel(macWin->winPtr)) {
	if (!Tk_IsEmbedded(macWin->winPtr)) {
	    /* 
	     * NOTE: we are not adding the new space to the update
	     * region.  It is currently assumed that Tk will need
	     * to completely redraw anway.
	     */
	    SizeWindow((WindowRef) destPort,
		    (short) width, (short) height, false);
	    TkMacInvalidateWindow(macWin, TK_WINDOW_ONLY);
	    TkMacInvalClipRgns(macWin->winPtr);
	} else {
	    int deltaX, deltaY;
	    
	    /*
	     * Find the Parent window -
	     *    For an embedded window this will be its container.
	     */
	    TkWindow *contWinPtr;
	    
	    contWinPtr = TkpGetOtherWindow(macWin->winPtr);
	    
	    if (contWinPtr != NULL) {
	        MacDrawable *macParent = contWinPtr->privatePtr;

		TkMacInvalClipRgns(macParent->winPtr);	
		TkMacInvalidateWindow(macWin, TK_PARENT_WINDOW);
		
		deltaX = macParent->xOff +
		    macWin->winPtr->changes.x - macWin->xOff;
		deltaY = macParent->yOff +
		    macWin->winPtr->changes.y - macWin->yOff;
		
		UpdateOffsets(macWin->winPtr, deltaX, deltaY);
	    } else {
	        /*
	         * This is the case where we are embedded in
	         * another app.  At this point, we are assuming that
	         * the changes.x,y is not maintained, if you need
		 * the info get it from Tk_GetRootCoords,
	         * and that the toplevel sits at 0,0 when it is drawn.
	         */
		
		TkMacInvalidateWindow(macWin, TK_PARENT_WINDOW);
		UpdateOffsets(macWin->winPtr, 0, 0);
	    }
	         
	}   
    } else {
	/* TODO: update all xOff & yOffs */
	int deltaX, deltaY, parentBorderwidth;
	MacDrawable *macParent = macWin->winPtr->parentPtr->privatePtr;
	
	if (macParent == NULL) {
	    return; /* TODO: Probably should be a panic */
	}
	
	TkMacInvalClipRgns(macParent->winPtr);	
	TkMacInvalidateWindow(macWin, TK_PARENT_WINDOW);

	deltaX = - macWin->xOff;
	deltaY = - macWin->yOff;

	parentBorderwidth = macWin->winPtr->parentPtr->changes.border_width;
	
	deltaX += macParent->xOff + parentBorderwidth +
	    macWin->winPtr->changes.x;
	deltaY += macParent->yOff + parentBorderwidth +
	    macWin->winPtr->changes.y;
        
	UpdateOffsets(macWin->winPtr, deltaX, deltaY);
    }
}
예제 #16
0
void 
InAdditionsContent(EventRecord* evt, WindowPtr wCurrPtr)
{
	Point 			localPt;
	Rect			r, currCellRect, checkbox;
	ControlPartCode	part;
	int				i;
	Cell			currCell;
	UInt8			hiliteVal;
	PixPatHandle	ppH;
	GrafPtr			oldPort;
	GetPort(&oldPort);
	
	SetPort(wCurrPtr);
	localPt = evt->where;
	GlobalToLocal( &localPt);
	
	/* Mouse Up */
	
	/* scroll */
	SetRect(&r, gControls->aw->compListBox.right, gControls->aw->compListBox.top, 
	            gControls->aw->compListBox.right + kScrollBarWidth, gControls->aw->compListBox.bottom);
	if ((evt->what == mouseUp) && (PtInRect( localPt, &r)))
	{    	    
	    LClick(localPt, evt->modifiers, gControls->aw->compList);
	    
	    SetRect(&r, gControls->aw->compListBox.left, gControls->aw->compListBox.top,
	                gControls->aw->compListBox.right + 1, gControls->aw->compListBox.bottom);
	    FrameRect(&r);
	}
	
	/* or un/check components */
	if ((evt->what == mouseUp) && (PtInRect( localPt, &gControls->aw->compListBox)))
	{
		LClick(localPt, evt->modifiers, gControls->aw->compList);
		AddUpdateRowHighlight(localPt);
		
		/* invert the checkbox rect */
		for (i=0; i<numRows; i++)
		{
			SetPt(&currCell, 0, i);
			LRect(&currCellRect, currCell, gControls->aw->compList);
			if (PtInRect(localPt, &currCellRect))
			{
				SetRect(&checkbox, currCellRect.left+4, currCellRect.top+2, 
							currCellRect.left+16, currCellRect.top+14);		
				INVERT_HIGHLIGHT(&checkbox);
				break;
			}
		}
		
		AddSetOptInfo(false);
	}
	
	/* Mouse Down */
	if ((evt->what == mouseDown) && (PtInRect( localPt, &gControls->aw->compListBox)))
	{
		/* show depressed button state */
	    for (i=0; i<numRows; i++)
		{
			SetPt(&currCell, 0, i);
			LRect(&currCellRect, currCell, gControls->aw->compList);
			if (PtInRect(localPt, &currCellRect))
			{
				SetRect(&checkbox, currCellRect.left+4, currCellRect.top+2, 
							currCellRect.left+16, currCellRect.top+14);	
				ppH = GetPixPat(rGrayPixPattern);
				FillCRect(&checkbox, ppH);	
				FrameRect(&checkbox);	
				if (gControls->cfg->comp[rowToComp[i]].selected)
				{
					/* draw check mark */
					MoveTo(checkbox.left+1, checkbox.top+1);
					LineTo(checkbox.right-2, checkbox.bottom-2);
					MoveTo(checkbox.right-2, checkbox.top+1);
					LineTo(checkbox.left+1, checkbox.bottom-2); 
				}
				/* create 3D depression */
				
				MoveTo(checkbox.left+1, checkbox.top+1);
				LineTo(checkbox.left+1, checkbox.bottom-1);
				MoveTo(checkbox.left+1, checkbox.top+1);
				LineTo(checkbox.right-1, checkbox.top+1);
				
				ForeColor(whiteColor);
				
				MoveTo(checkbox.right-1, checkbox.top+1);
				LineTo(checkbox.right-1, checkbox.bottom-1);
				MoveTo(checkbox.left+1, checkbox.bottom-1);
				LineTo(checkbox.right-1, checkbox.bottom-1);
				
				ForeColor(blackColor);
			
				if (ppH)
					DisposePixPat(ppH);
				break;
			}
		}
	}
			
	HLock((Handle)gControls->backB);
	r = (**(gControls->backB)).contrlRect;
	HUnlock((Handle)gControls->backB);
	if (PtInRect( localPt, &r))
	{
		/* reset all rows to be not highlighted */
		for (i=1; i<numRows; i++)
			gControls->cfg->comp[rowToComp[i]].highlighted = false;
		
		part = TrackControl(gControls->backB, evt->where, NULL);
		if (part)
		{ 
			/* extra handling since we used DrawString for static text msg 
			 * and framed our own listbox etc. 
			 */
			gControls->aw->compListBox.top = 0;
			EraseRect(&gControls->aw->compListBox);
			ClearDiskSpaceMsgs();
			
			KillControls(gWPtr);
			ShowComponentsWin();
			return;
		}
	}
			
	HLock((Handle)gControls->nextB);			
	r = (**(gControls->nextB)).contrlRect;
	HUnlock((Handle)gControls->nextB);
	if (PtInRect( localPt, &r))
	{
		/* reset all rows to be not highlighted */
		for (i=0; i<numRows; i++)
			gControls->cfg->comp[rowToComp[i]].highlighted = false;
			
		part = TrackControl(gControls->nextB, evt->where, NULL);
		if (part)
		{	
			if (!VerifyDiskSpace())
			    return;
			    		
			gControls->aw->compListBox.top = 0;
			EraseRect(&gControls->aw->compListBox);
			ClearDiskSpaceMsgs();
						
			KillControls(gWPtr);
			ShowTerminalWin();
			return;
		}
	}
	SetPort(oldPort);
}
예제 #17
0
void 
XMoveWindow(
    Display* display,		/* Display. */
    Window window,		/* Window. */
    int x,
    int y)
{
    MacDrawable *macWin = (MacDrawable *) window;
    GWorldPtr destPort;

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

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

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

	TkMacInvalClipRgns(macParent->winPtr);
	TkMacInvalidateWindow(macWin, TK_PARENT_WINDOW);

	deltaX = - macWin->xOff;
	deltaY = - macWin->yOff;
	
        /*
	 * If macWin->winPtr is an embedded window, don't offset by its
	 *  parent's borderwidth...
	 */
	 
	if (!Tk_IsEmbedded(macWin->winPtr)) {
	    parentBorderwidth = macWin->winPtr->parentPtr->changes.border_width;
	} else {
	    parentBorderwidth = 0;
	}
	deltaX += macParent->xOff + parentBorderwidth +
	    macWin->winPtr->changes.x;
	deltaY += macParent->yOff + parentBorderwidth +
	    macWin->winPtr->changes.y;
		
	UpdateOffsets(macWin->winPtr, deltaX, deltaY);
	TkMacWinBounds(macWin->winPtr, &bounds);
	InvalRect(&bounds);
    }
}
예제 #18
0
void
ShowAdditionsWin(void)
{
	Str255		next, back;
	Str255		compDescTitle;
	StringPtr	selCompMsg;
	Handle		listBoxRect;
	Rect 		dataBounds, listBoxFrame, viewRect;
	short		reserr;
	int			totalRows = 0, i, instChoice;
	Point		cSize;
	Boolean		bCellSelected;
	GrafPtr		oldPort;
	GetPort(&oldPort);
		
	SetPort(gWPtr);
	
	gCurrWin = kAdditionsID; 
	/* gControls->aw = (CompWin *) NewPtrClear(sizeof(CompWin)); */
	
	GetResourcedString(next, rInstList, sNextBtn);
	GetResourcedString(back, rInstList, sBackBtn);

	// get controls
	listBoxRect = Get1Resource('RECT', rCompListBox);
	reserr = ResError(); 
	if (reserr == noErr && listBoxRect != NULL)
	{
		HLock((Handle)listBoxRect);
		SetRect(&gControls->aw->compListBox, 	((Rect*)*listBoxRect)->left,
												((Rect*)*listBoxRect)->top,
												((Rect*)*listBoxRect)->right,
												((Rect*)*listBoxRect)->bottom);
		HUnlock((Handle)listBoxRect);
	}
	else
	{
		ErrorHandler(reserr, nil);
		return;
	}
	gControls->aw->compDescBox = NULL;
	gControls->aw->compDescBox = GetNewControl(rCompDescBox, gWPtr);
	if (!gControls->aw->compDescBox)
	{
		ErrorHandler(eMem, nil);
		return;
	}

	gControls->aw->compListBox.right -= kScrollBarWidth;
	instChoice = gControls->opt->instChoice-1;
	for (i=0; i<kMaxComponents; i++)
	{
		if (totalRows >= gControls->cfg->numComps)
			break;
		if (!gControls->cfg->comp[i].invisible && gControls->cfg->comp[i].additional &&
			(gControls->cfg->st[instChoice].comp[i] == kInSetupType))
			totalRows++;
	}
		
	SetRect(&dataBounds, 0, 0, 1, totalRows);
	SetPt( &cSize, 0, 0);
	gControls->aw->compList = LNew((const Rect*)&gControls->aw->compListBox, (const Rect*)&dataBounds,
									cSize, rCheckboxLDEF, gWPtr, true, false, false, true);
	(*gControls->aw->compList)->selFlags = lExtendDrag + lUseSense + lDoVAutoscroll;
	
	HLock((Handle)gControls->aw->compDescBox);
	SetRect(&viewRect, (*gControls->aw->compDescBox)->contrlRect.left,
					   (*gControls->aw->compDescBox)->contrlRect.top,
					   (*gControls->aw->compDescBox)->contrlRect.right,
					   (*gControls->aw->compDescBox)->contrlRect.bottom);
	HUnlock((Handle)gControls->aw->compDescBox);
	viewRect.top += kInterWidgetPad;
	SetRect(&viewRect, viewRect.left + kTxtRectPad,
						viewRect.top + kTxtRectPad,
						viewRect.right - kTxtRectPad,
						viewRect.bottom - kTxtRectPad);
	TextFont(applFont);
	TextSize(9);
	gControls->aw->compDescTxt = TENew(&viewRect, &viewRect);
	TextFont(systemFont);
	TextSize(12);
	
	// populate controls
	bCellSelected = AddPopulateCompInfo();
	
	// show controls
	GetResourcedString(compDescTitle, rInstList, sCompDescTitle);
	SetControlTitle(gControls->aw->compDescBox, compDescTitle);
	
	MoveTo( gControls->aw->compListBox.left, gControls->aw->compListBox.top - kInterWidgetPad);
	HLock(gControls->cfg->selCompMsg);
	selCompMsg = CToPascal(*gControls->cfg->selAddMsg);
	if (selCompMsg)
		DrawString( selCompMsg );
	HUnlock(gControls->cfg->selCompMsg);
	SetRect(&listBoxFrame, gControls->aw->compListBox.left, 
						 --gControls->aw->compListBox.top,
						   gControls->aw->compListBox.right + kScrollBarWidth,
						 ++gControls->aw->compListBox.bottom);
	FrameRect(&listBoxFrame);
	ShowNavButtons( back, next );
	if (bCellSelected)
		AddSetOptInfo(true);
	else
		DrawDiskSpaceMsgs( gControls->opt->vRefNum );

	// default highlight first row
	AddInitRowHighlight(0);

#if 0	    
	RGBColor backColorOld;
    Rect adjustedRect, *clRect = &gControls->aw->compListBox;
    SetRect(&adjustedRect, clRect->left, clRect->top+1, clRect->right, clRect->bottom-1);
    GetBackColor(&backColorOld);
    BackColor(whiteColor);
    EraseRect(&adjustedRect);
    RGBBackColor(&backColorOld);
#endif
    
	SetPort(oldPort);
}
예제 #19
0
void
BUrl::SetAuthority(const BString& authority)
{
	fAuthority = authority;

	fUser.Truncate(0);
	fPassword.Truncate(0);
	fHost.Truncate(0);
	fPort = 0;
	fHasPort = false;
	fHasUserName = false;
	fHasPassword = false;

	bool hasUsernamePassword = B_ERROR != fAuthority.FindFirst('@');
	authority_parse_state state = AUTHORITY_USERNAME;
	int32 offset = 0;
	int32 length = authority.Length();
	const char *authority_c = authority.String();

	while (AUTHORITY_COMPLETE != state && offset < length) {

		switch (state) {

			case AUTHORITY_USERNAME:
			{
				if (hasUsernamePassword) {
					int32 end_username = char_offset_until_fn_false(
						authority_c, length, offset,
						authority_is_username_char);

					SetUserName(BString(&authority_c[offset],
						end_username - offset));

					state = AUTHORITY_PASSWORD;
					offset = end_username;
				} else {
					state = AUTHORITY_HOST;
				}
				break;
			}

			case AUTHORITY_PASSWORD:
			{
				if (hasUsernamePassword && ':' == authority[offset]) {
					offset++; // move past the delimiter
					int32 end_password = char_offset_until_fn_false(
						authority_c, length, offset,
						authority_is_password_char);

					SetPassword(BString(&authority_c[offset],
						end_password - offset));

					offset = end_password;
				}

				// if the host was preceded by a username + password couple
				// then there will be an '@' delimiter to avoid.

				if (authority_c[offset] == '@') {
					offset++;
				}

				state = AUTHORITY_HOST;
				break;
			}

			case AUTHORITY_HOST:
			{

				// the host may be enclosed within brackets in order to express
				// an IPV6 address.

				if (authority_c[offset] == '[') {
					int32 end_ipv6_host = char_offset_until_fn_false(
						authority_c, length, offset + 1,
						authority_is_ipv6_host_char);

					if (authority_c[end_ipv6_host] == ']') {
						SetHost(BString(&authority_c[offset],
							(end_ipv6_host - offset) + 1));
						state = AUTHORITY_PORT;
						offset = end_ipv6_host + 1;
					}
				}

				// if an IPV6 host was not found.

				if (AUTHORITY_HOST == state) {
					int32 end_host = char_offset_until_fn_false(
						authority_c, length, offset, authority_is_host_char);

					SetHost(BString(&authority_c[offset], end_host - offset));
					state = AUTHORITY_PORT;
					offset = end_host;
				}

				break;
			}

			case AUTHORITY_PORT:
			{
				if (authority_c[offset] == ':') {
					offset++;
					int32 end_port = char_offset_until_fn_false(
						authority_c, length, offset, authority_is_port_char);
					SetPort(atoi(&authority_c[offset]));
					offset = end_port;
				}

				state = AUTHORITY_COMPLETE;

				break;
			}

			case AUTHORITY_COMPLETE:
				// should never be reached - keeps the compiler happy
				break;
		}
	}

	// An empty authority is still an authority, making it possible to have
	// URLs such as file:///path/to/file.
	// TODO however, there is no way to unset the authority once it is set...
	// We may want to take a const char* parameter and allow NULL.
	fHasHost = true;
}
예제 #20
0
파일: mainwindow.cpp 프로젝트: youngjeff/qt
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), ui(new Ui::MainWindowClass)
{
    //setWindowOpacity(0.9);

    ui->setupUi(this);
    palette.setBrush(QPalette::Base, QBrush(QPixmap("freedom.png")));
    ui->listView->setPalette(palette);









    //-------------------------------------------------------------------
    //------------------------------以下为串口部分-------------------------
    //-------------------------------------------------------------------
    ui->setupUi(this);
    serialPort = new ManageSerialPort();
    senddata="Hello,Baby!";
    SetPort();
    connect(ui->pushButton_Send,SIGNAL(clicked()),this,SLOT(slot_send()));
    connect(this,SIGNAL(SerialPortFail()),this,SLOT(OpenSerialFail()));
    //-------------------------------------------------------------------
    //------------------------------以上为串口部分声明---------------------
    //-------------------------------------------------------------------











    //************************************************************************
    //字母按键按下信号与窗体的关联
    //************************************************************************
    connect(ui->pushButton_A,SIGNAL(clicked()),this,SLOT(accept_A()));
    connect(ui->pushButton_B,SIGNAL(clicked()),this,SLOT(accept_B()));
    connect(ui->pushButton_C,SIGNAL(clicked()),this,SLOT(accept_C()));
    connect(ui->pushButton_D,SIGNAL(clicked()),this,SLOT(accept_D()));
    connect(ui->pushButton_E,SIGNAL(clicked()),this,SLOT(accept_E()));
    connect(ui->pushButton_F,SIGNAL(clicked()),this,SLOT(accept_F()));
    connect(ui->pushButton_G,SIGNAL(clicked()),this,SLOT(accept_G()));
    connect(ui->pushButton_H,SIGNAL(clicked()),this,SLOT(accept_H()));
    connect(ui->pushButton_I,SIGNAL(clicked()),this,SLOT(accept_I()));
    connect(ui->pushButton_J,SIGNAL(clicked()),this,SLOT(accept_J()));
    connect(ui->pushButton_K,SIGNAL(clicked()),this,SLOT(accept_K()));
    connect(ui->pushButton_L,SIGNAL(clicked()),this,SLOT(accept_L()));
    connect(ui->pushButton_M,SIGNAL(clicked()),this,SLOT(accept_M()));
    connect(ui->pushButton_N,SIGNAL(clicked()),this,SLOT(accept_N()));
    connect(ui->pushButton_O,SIGNAL(clicked()),this,SLOT(accept_O()));
    connect(ui->pushButton_P,SIGNAL(clicked()),this,SLOT(accept_P()));
    connect(ui->pushButton_Q,SIGNAL(clicked()),this,SLOT(accept_Q()));
    connect(ui->pushButton_R,SIGNAL(clicked()),this,SLOT(accept_R()));
    connect(ui->pushButton_S,SIGNAL(clicked()),this,SLOT(accept_S()));
    connect(ui->pushButton_T,SIGNAL(clicked()),this,SLOT(accept_T()));
    connect(ui->pushButton_U,SIGNAL(clicked()),this,SLOT(accept_U()));
    connect(ui->pushButton_V,SIGNAL(clicked()),this,SLOT(accept_V()));
    connect(ui->pushButton_W,SIGNAL(clicked()),this,SLOT(accept_W()));
    connect(ui->pushButton_X,SIGNAL(clicked()),this,SLOT(accept_X()));
    connect(ui->pushButton_Y,SIGNAL(clicked()),this,SLOT(accept_Y()));
    connect(ui->pushButton_Z,SIGNAL(clicked()),this,SLOT(accept_Z()));

    connect(ui->pushButton_Reset,SIGNAL(clicked()),this,SLOT(accept_reset()));
    connect(ui->pushButton_Enter,SIGNAL(clicked()),this,SLOT(accept_enter()));
    connect(ui->pushButton_Del,SIGNAL(clicked()),this,SLOT(accept_del()));
    connect(ui->pushButton_Up,SIGNAL(clicked()),this,SLOT(accept_up()));
    connect(ui->pushButton_Down,SIGNAL(clicked()),this,SLOT(accept_down()));


    //***************************************************************************
    //汉字选择信号与槽的关联
    //***************************************************************************
    connect(ui->pushButton_Dis_1,SIGNAL(clicked()),this,SLOT(accept_select_1()));
    connect(ui->pushButton_Dis_2,SIGNAL(clicked()),this,SLOT(accept_select_2()));
    connect(ui->pushButton_Dis_3,SIGNAL(clicked()),this,SLOT(accept_select_3()));
    connect(ui->pushButton_Dis_4,SIGNAL(clicked()),this,SLOT(accept_select_4()));
    connect(ui->pushButton_Dis_5,SIGNAL(clicked()),this,SLOT(accept_select_5()));
    connect(ui->pushButton_Dis_6,SIGNAL(clicked()),this,SLOT(accept_select_6()));
    connect(ui->pushButton_Dis_7,SIGNAL(clicked()),this,SLOT(accept_select_7()));
    connect(ui->pushButton_Dis_8,SIGNAL(clicked()),this,SLOT(accept_select_8()));
    connect(ui->pushButton_Dis_9,SIGNAL(clicked()),this,SLOT(accept_select_9()));
    connect(ui->pushButton_Dis_10,SIGNAL(clicked()),this,SLOT(accept_select_10()));

    //***************************************************************************
    //符号选择信号与槽的关联
    //***************************************************************************
    connect(ui->pushButton_Symbol_1,SIGNAL(clicked()),this,SLOT(accept_select_symbol_1()));
    connect(ui->pushButton_Symbol_2,SIGNAL(clicked()),this,SLOT(accept_select_symbol_2()));
    connect(ui->pushButton_Symbol_3,SIGNAL(clicked()),this,SLOT(accept_select_symbol_3()));
    connect(ui->pushButton_Symbol_4,SIGNAL(clicked()),this,SLOT(accept_select_symbol_4()));


}
예제 #21
0
McoStatus ThermDialog::SetUpTherm(int therm_num)
{

    Rect 		r;
    Handle 		h;
    short 		itemType;
    short 		wi,hi;
    short		ids1[] = THERM_IDs_1;
    short		ids2[] = THERM_IDs_2;
    int 		i;
    Str255		theString;

    Quit = FALSE;

    //if (therm_num == 3)
    for (i=0; i<NUM_THERM_IDS; i++) ids[i] = ids2[i];
    //else for (i=0; i<NUM_THERM_IDS; i++) ids[i] = ids1[i];

    GetPort(&olddp);

    dt = (DialogTHndl) GetResource ('DLOG',ids[THERM_DLG]);

    if (! dt) return(MCO_RSRC_ERROR);

    HNoPurge ((Handle) dt);

    r = (**dt).boundsRect;


#define menuHeight 20

    wi = qd.screenBits.bounds.right;
    hi = qd.screenBits.bounds.bottom;

    OffsetRect (&r, -r.left, -r.top);
    OffsetRect (&r, (wi - r.right) / 2,
                (hi - r.bottom - menuHeight) / 3 + menuHeight);
    (**dt).boundsRect = r;

#undef menuHeight


    dp = GetNewDialog (ids[THERM_DLG], nil, (WindowPtr) -1);



    if (! dp)
    {
        HPurge ((Handle) dt);
        return(MCO_RSRC_ERROR);
    }

    GetDItem (dp,ids[THERM_TEXT], &itemType, &h, &r);
    GetIndString(theString,THERM_MESS,therm_num);
    SetIText(h,theString);

    SetPort(dp);

    ShowWindow(dp);
    DrawDialog(dp);

    box_d_item(dp,ids[THERM_BOX]);
    return MCO_SUCCESS;
}
예제 #22
0
void ZoomRect(Boolean zoomLarger,Rect *smallRect, Rect *bigRect)
{
	double firstStep,stepValue,trailer,zoomRatio;
	short i,step;
	Rect curRect;
	unsigned long ticks;
	Pattern	grayPattern; //used in carbonization
	RgnHandle rgnHandle = NewRgn();
	GrafPtr oldPort;
	Rect	tempRect1;
	
	GetPort(&oldPort);
	SetPort(GetWindowPort(gWindow));
	
	//PenPat(&qd.gray);
	PenPat(GetQDGlobalsGray(&grayPattern));
	PenMode(patXor);
	
	
	firstStep=kZoomRatio;
	for (i=0; i<kNumSteps; i++) {
		firstStep *= kZoomRatio;
	}

	if (!zoomLarger) {
		zoomRatio = 1.0/kZoomRatio;
		firstStep = 1.0-firstStep;
	}
	else
		zoomRatio = kZoomRatio;
		
	trailer = firstStep;
	stepValue = firstStep;
	for (step=0; step<(kNumSteps+kRectsVisible); step++) {
	
		// draw new frame
		
		if (step<kNumSteps) {
			stepValue /= zoomRatio;
			CalcRect(&curRect,smallRect,bigRect,stepValue);
			FrameRect(&curRect);
		}
		
		// erase old frame
		
		if (step>=kRectsVisible) {
			trailer /= zoomRatio;
			CalcRect(&curRect,smallRect,bigRect,trailer);
			FrameRect(&curRect);
		}
		QDFlushPortBuffer(GetWindowPort(gWindow), GetPortVisibleRegion(GetWindowPort(gWindow), rgnHandle));
		Delay(kDelayTicks,&ticks);
		
	}

	PenNormal();
	DisposeRgn(rgnHandle);
	smallRect->top = bigRect->top = -1;
	EraseRect(GetPortBounds(GetWindowPort(gWindow), &tempRect1));
	
	SetPort(oldPort);
}
예제 #23
0
파일: sock.c 프로젝트: Cloudxtreme/hybserv2
/*
 * ConnectHost()
 * args: hostname, port
 * purpose: bind socket and begin a non-blocking connection to
 *          hostname at port
 * return: socket file descriptor if successful connect, -1 if not
 */
int ConnectHost(const char *hostname, unsigned int port)
{
	struct addrinfo *res, *res_o;
	int socketfd; /* socket file descriptor */
	char *resolved = NULL;

	res_o = res = LookupHostname(hostname);

	while (res != NULL)
	{
		resolved = ConvertHostname(res->ai_addr, res->ai_addrlen);

		putlog(LOG1, "Connecting to %s[%s] tcp/%d",
		       hostname, resolved, port);

		if ((socketfd = socket(res->ai_family, SOCK_STREAM, 6)) == -1)
		{
			MyFree(resolved);
			res = res->ai_next;
			continue;
		}

		SetSocketOptions(socketfd);
		SetPort((struct sockaddr *)res->ai_addr, port);

		if (LocalHostName)
		{
			/* bind to virtual host */
			if (bind(socketfd, (struct sockaddr *)&LocalAddr,
			         LocalAddrSize) == -1)
			{
				char *resolved2;
				resolved2 = ConvertHostname((struct sockaddr *)&LocalAddr,
				                            LocalAddrSize);

				putlog(LOG1, "FATAL: Unable to bind virtual host %s[%s]: %s",
				       LocalHostName, resolved2, strerror(errno));

				MyFree(resolved2);
			}
		}

		if ((connect(socketfd, (struct sockaddr *)res->ai_addr,
		             res->ai_addrlen)) == -1)
		{
			putlog(LOG1, "Error connecting to %s[%s] tcp/%d: %s",
			       hostname, resolved, port, strerror(errno));

			close(socketfd);
			MyFree(resolved);
			res = res->ai_next;
			continue;
		}

		/* nope, no error whatsoever */
		freeaddrinfo(res_o);
		MyFree(resolved);
		/* not really the smartest to do... */
		SetNonBlocking(socketfd);
		return socketfd;
	}

	if (res_o != NULL)
		freeaddrinfo(res_o);

	return -1;
} /* ConnectHost() */
예제 #24
0
// --------------------------------------------------------------------------------------
static void drawIconListCell(ListHandle theList, const Rect *cellRect, 
								IconListCellDataRec *theCellData, Boolean selected)
{
	GrafPtr savedPort;
	CGrafPtr listPort;
	ThemeDrawingState savedState;
	Boolean active;
	Rect iconRect, textRect;
	short savedFont, savedSize;
	Style savedFace;
	CFStringRef cellName;
	
	GetPort(&savedPort);
	listPort = GetListPort(theList);
	SetPort((GrafPtr)listPort);
	
	GetThemeDrawingState(&savedState);
	
	if (selected)						// we don't need to change the background 
	{									// color if this Cell isn't highlighted
		Pattern whitePattern;
		RGBColor highlightColor;
		
		GetQDGlobalsWhite(&whitePattern);	// set the background pattern so that 
		BackPat(&whitePattern);				// the color is properly set as a solid color
		
		LMGetHiliteRGB(&highlightColor);
		RGBBackColor(&highlightColor);		// set the background to the highlight color
	}
	
	EraseRect(cellRect);
	
	calculateDrawingBounds(cellRect, &iconRect, &textRect);	// get the drawing Rects
	active = GetListActive(theList);
	
		// draw the IconRef using Icon Services
	PlotIconRef(&iconRect, kAlignNone, active ? kTransformNone : kTransformDisabled, 
				kIconServicesNormalUsageFlag, theCellData->icon);
	
#if TARGET_API_MAC_OS8		// draw TextEdit text in Classic
#pragma unused (cellName)
	savedFont = GetPortTextFont(listPort);	// Get/SetThemeDrawingState doesn't save or 
	savedFace = GetPortTextFace(listPort);	// restore these
	savedSize = GetPortTextSize(listPort);
	
	UseThemeFont(kThemeViewsFont, smCurrentScript);
	TETextBox(&theCellData->name[1], theCellData->name[0], &textRect, teCenter);
	
	TextFont(savedFont);
	TextFace(savedFace);
	TextSize(savedSize);
#else						// draw Appearance text in Carbon
#pragma unused (savedFont, savedSize, savedFace)
	cellName = CFStringCreateWithPascalString(kCFAllocatorDefault, theCellData->name, 
												GetApplicationTextEncoding());
	DrawThemeTextBox(cellName, kThemeViewsFont, 
						active ? kThemeStateActive : kThemeStateInactive, true, 
						&textRect, teCenter, NULL);
	CFRelease(cellName);
#endif
	
	SetThemeDrawingState(savedState, true);
	SetPort(savedPort);
} // drawIconListCell
예제 #25
0
파일: ugView.c 프로젝트: rolk/ug
static int RasterizeFile (FILE *stream, AWindowRecord *myWindow, short wx, short wy)
{
  char *buffer;                                                 /* input buffer						*/
  long blockSize;                                               /* METABUFFERSIZE					*/
  long blockUsed;                                               /* actual buffer size used			*/
  long itemCounter;                                             /* number of commands in buffer		*/
  char *data;                                                           /* data pointer in buffer			*/
  short fx,fy;                                                  /* file screen size					*/
  Fixed sx,sy;                                                  /* scaling factors					*/
  int i,error,j,size;
  char opCode;
  short x,y,r,g,b,n,lw,ts,m,ms,w;
  short x1,y1,x2,y2;
  short xx[SIZE],yy[SIZE];
  PolyHandle myPoly;
  char s[CSIZE];
  unsigned char c;
  RGBColor newColor;
  PaletteHandle myPalette;
  long l;

  /* get file parameters */
  rewind(stream);
  error = fread(&blockSize,4,1,stream); if (error!=1) return(1);       /* block size */
  error = fread(&fx,2,1,stream);            if (error!=1) return(1);       /* x size */
  error = fread(&fy,2,1,stream);        if (error!=1) return(1);       /* y size */

  /* compute scaling factors */
  sx = FixRatio(wx-1,fx-1);
  sy = FixRatio(wy-1,fy-1);

  /* default values */
  lw = 1;
  ts = 12;
  m = 0;
  ms = 6;

  /* allocate input buffer */
  buffer = malloc(blockSize);
  if (buffer==NULL) return(1);

  SetPort((GrafPtr)(myWindow->theWindow));
  EraseRect(&(myWindow->usableRect));

  /* loop through the blocks */
  while (!feof(stream))
  {
    /* read block parameters */
    error = fread(&blockUsed,4,1,stream);    if (error!=1) {free(buffer); return(1);}
    error = fread(&itemCounter,4,1,stream);  if (error!=1) {free(buffer); return(1);}
    error = fread(buffer,blockUsed,1,stream);if (error!=1) {free(buffer); return(1);}

    /* init pointer to next item */
    data = buffer;

    /* for all items */
    for (i=0; i<itemCounter; i++)
    {
      /* get op code */
      opCode = *(data++);

      switch (opCode)
      {
      case opMove :
        x = *((short *)data);
        data += 2;
        y = *((short *)data);
        data += 2;
        TRFMX(x);
        TRFMY(y);
        MoveTo(x,y);
        break;

      case opDraw :
        x = *((short *)data);
        data += 2;
        y = *((short *)data);
        data += 2;
        TRFMX(x);
        TRFMY(y);
        LineTo(x,y);
        break;

      case opPolyline :
        n = *((short *)data);
        data += 2;
        if (n>=SIZE) {free(buffer); return(2);}
        size = n<<1;
        memcpy(xx,data,size);
        data += size;
        memcpy(yy,data,size);
        data += size;
        for (j=0; j<n; j++)
        {
          TRFMX(xx[j]);
          TRFMY(yy[j]);
        }
        MoveTo(xx[0],yy[0]);
        for (j=1; j<n; j++) LineTo(xx[j],yy[j]);
        break;

      case opPolygon :
        n = *((short *)data);
        data += 2;
        if (n>=SIZE) {free(buffer); return(2);}
        size = n<<1;
        memcpy(xx,data,size);
        data += size;
        memcpy(yy,data,size);
        data += size;
        for (j=0; j<n; j++)
        {
          TRFMX(xx[j]);
          TRFMY(yy[j]);
        }
        if (n<3) break;
        myPoly = OpenPoly();
        MoveTo(xx[0],yy[0]);
        for (j=1; j<n; j++) LineTo(xx[j],yy[j]);
        LineTo(xx[0],yy[0]);
        ClosePoly();
        PaintPoly(myPoly);
        FramePoly(myPoly);
        KillPoly(myPoly);
        break;

      case opPolymark :
        n = *((short *)data);
        data += 2;
        if (n>=SIZE) {free(buffer); return(2);}
        size = n<<1;
        memcpy(xx,data,size);
        data += size;
        memcpy(yy,data,size);
        data += size;
        for (j=0; j<n; j++)
        {
          TRFMX(xx[j]);
          TRFMY(yy[j]);
        }
        for (j=0; j<n; j++) Marker(m,ms,xx[j],yy[j]);
        break;

      case opText :
        n = *((short *)data);
        data += 2;
        if (n>=CSIZE-1) {free(buffer); return(2);}
        memcpy(s,data,n);
        s[n] = 0;
        data += n;
        DrawString((ConstStr255Param)c2pstr(s));
        break;

      case opCenteredText :
        x = *((short *)data);
        data += 2;
        y = *((short *)data);
        data += 2;
        TRFMX(x);
        TRFMY(y);
        n = *((short *)data);
        data += 2;
        if (n>=CSIZE-1) {free(buffer); return(2);}
        memcpy(s,data,n);
        s[n] = 0;
        data += n;
        c2pstr(s);
        w = StringWidth((ConstStr255Param)s);
        MoveTo(x-w/2,y+ts/2);
        DrawString((ConstStr255Param)s);
        break;

      case opSetLineWidth :
        n = *((short *)data);
        data += 2;
        lw = n;
        PenSize(n,n);
        break;

      case opSetTextSize :
        n = *((short *)data);
        data += 2;
        ts = n;
        TextSize(n);
        break;

      case opSetMarker :
        n = *((short *)data);
        data += 2;
        m = n;
        break;

      case opSetMarkerSize :
        n = *((short *)data);
        data += 2;
        ms = n;
        break;

      case opSetColor :
        c = *((unsigned char *)data);
        data++;
        PmForeColor((short)c);
        break;

      case opSetEntry :
        c = *((unsigned char *)data);
        data++;
        r = (short) (*((unsigned char *)data));
        data++;
        g = (short) (*((unsigned char *)data));
        data++;
        b = (short) (*((unsigned char *)data));
        data++;
        myPalette = GetPalette(myWindow->theWindow);
        myWindow->red[c]   = newColor.red   = r<<8;
        myWindow->green[c] = newColor.green = g<<8;
        myWindow->blue[c]  = newColor.blue  = b<<8;
        SetEntryColor(myPalette,(short) c,&newColor);
        ActivatePalette(myWindow->theWindow);
        break;

      case opSetPalette :
        x = (short) (*((unsigned char *)data));
        data++;
        y = (short) (*((unsigned char *)data));
        data++;
        myPalette = GetPalette(myWindow->theWindow);
        for (j=x; j<=y; j++)
        {
          r = (short) (*((unsigned char *)data));
          data++;
          g = (short) (*((unsigned char *)data));
          data++;
          b = (short) (*((unsigned char *)data));
          data++;
          myWindow->red[j]   = newColor.red   = r<<8;
          myWindow->green[j] = newColor.green = g<<8;
          myWindow->blue[j]  = newColor.blue  = b<<8;
          SetEntryColor(myPalette,(short) j,&newColor);
        }
        ActivatePalette(myWindow->theWindow);
        break;

      case opNewLine :
        lw = *((unsigned char *)data);
        data++;
        c = *((unsigned char *)data);
        data++;
        x1 = *((short *)data);
        data += 2;
        y1 = *((short *)data);
        data += 2;
        x2 = *((short *)data);
        data += 2;
        y2 = *((short *)data);
        data += 2;
        TRFMX(x1);
        TRFMY(y1);
        TRFMX(x2);
        TRFMY(y2);
        PenSize(lw,lw);
        PmForeColor((short)c);
        MoveTo(x1,y1);
        LineTo(x2,y2);
        break;

      case opNewPolyline :
        lw = *((unsigned char *)data);
        data++;
        c = *((unsigned char *)data);
        data++;
        n = *((short *)data);
        data += 2;
        if (n>=SIZE) {free(buffer); return(2);}
        size = n<<1;
        memcpy(xx,data,size);
        data += size;
        memcpy(yy,data,size);
        data += size;
        for (j=0; j<n; j++)
        {
          TRFMX(xx[j]);
          TRFMY(yy[j]);
        }
        PenSize(lw,lw);
        PmForeColor((short)c);
        MoveTo(xx[0],yy[0]);
        for (j=1; j<n; j++) LineTo(xx[j],yy[j]);
        break;

      case opNewPolygon :
        c = *((unsigned char *)data);
        data++;
        n = *((short *)data);
        data += 2;
        if (n>=SIZE) {free(buffer); return(2);}
        size = n<<1;
        memcpy(xx,data,size);
        data += size;
        memcpy(yy,data,size);
        data += size;
        for (j=0; j<n; j++)
        {
          TRFMX(xx[j]);
          TRFMY(yy[j]);
        }
        if (n<3) break;
        PmForeColor((short)c);
        myPoly = OpenPoly();
        MoveTo(xx[0],yy[0]);
        for (j=1; j<n; j++) LineTo(xx[j],yy[j]);
        LineTo(xx[0],yy[0]);
        ClosePoly();
        PaintPoly(myPoly);
        FramePoly(myPoly);
        KillPoly(myPoly);
        break;

      case opNewPolymark :
        m = *((unsigned char *)data);
        data++;
        ms = *((unsigned char *)data);
        data++;
        c = *((unsigned char *)data);
        data++;
        n = *((short *)data);
        data += 2;
        if (n>=SIZE) {free(buffer); return(2);}
        size = n<<1;
        memcpy(xx,data,size);
        data += size;
        memcpy(yy,data,size);
        data += size;
        for (j=0; j<n; j++)
        {
          TRFMX(xx[j]);
          TRFMY(yy[j]);
        }
        PmForeColor((short)c);
        for (j=0; j<n; j++) Marker(m,ms,xx[j],yy[j]);
        break;

      case opNewText :
        ts = *((unsigned char *)data);
        data++;
        c = *((unsigned char *)data);
        data++;
        x = *((short *)data);
        data += 2;
        y = *((short *)data);
        data += 2;
        TRFMX(x);
        TRFMY(y);
        n = *((short *)data);
        data += 2;
        if (n>=CSIZE-1) {free(buffer); return(2);}
        memcpy(s,data,n);
        s[n] = 0;
        data += n;
        MoveTo(x,y);
        TextSize(ts);
        PmForeColor((short)c);
        DrawString((ConstStr255Param)c2pstr(s));
        break;

      case opNewCenteredText :
        ts = *((unsigned char *)data);
        data++;
        c = *((unsigned char *)data);
        data++;
        x = *((short *)data);
        data += 2;
        y = *((short *)data);
        data += 2;
        TRFMX(x);
        TRFMY(y);
        n = *((short *)data);
        data += 2;
        if (n>=CSIZE-1) {free(buffer); return(2);}
        memcpy(s,data,n);
        s[n] = 0;
        data += n;
        c2pstr(s);
        w = StringWidth((ConstStr255Param)s);
        TextSize(ts);
        PmForeColor((short)c);
        MoveTo(x-w/2,y+ts/2);
        DrawString((ConstStr255Param)c2pstr(s));
        break;

      default :
        break;
      }
    }
  }

  return(0);
}
예제 #26
0
void ZoomRect (Rect *smallrect, Rect *bigrect, Boolean zoomup) 
{
	#if USE_DRAG_MANAGER_FOR_ZOOMS
		if (gZoomOn)
		{
			if (zoomup)
				ZoomRects(smallrect,bigrect,10,kZoomNoAcceleration);
			else
				ZoomRects(bigrect,smallrect,10,kZoomNoAcceleration);
		}
	#else
		Fixed		factor;
		Rect		rect1, rect2, rect3, rect4;
		GrafPtr		savePort, deskPort;
		int			i;
		long        tm;

		if (gZoomOn)
		{
			GetPort (&savePort);
			OpenPort (deskPort = (GrafPtr) NewPtr (sizeof (GrafPort)));
			InitPort (deskPort);
			SetPort (deskPort);
			PenPat (&qd.gray);		//¥ Original, comment for black zoom.
		//	PenPat (&qd.black);		//¥ Uncomment for black zoom.
			PenMode (notPatXor);	//¥ Original, comment for black zoom.
		//	PenMode (patXor);		//¥ Uncomment for black zoom.
			if (zoomup) 
			{
				rect1 = *smallrect;
				factor = FixRatio (6, 5);
				fract = FixRatio (541, 10000);
			}
			else
			{
				rect1 = *bigrect;
				factor = FixRatio (5, 6);
				fract = ONE;
			}
			rect2 = rect1;
			rect3 = rect1;
			FrameRect (&rect1);
			for (i = 1; i <= ZOOMSTEPS; i++) 
			{
				rect4.left = Blend (smallrect->left, bigrect->left);
				rect4.right = Blend (smallrect->right, bigrect->right);
				rect4.top = Blend (smallrect->top, bigrect->top);
				rect4.bottom = Blend (smallrect->bottom, bigrect->bottom);
				FrameRect (&rect4);
				FrameRect (&rect1);
				rect1 = rect2;
				rect2 = rect3;
				rect3 = rect4;
				fract = FixMul (fract, factor);
				tm = TickCount (); // These two lines are a crude waitvbl
				while (tm == TickCount ());
			}
			FrameRect (&rect1);
			FrameRect (&rect2);
			FrameRect (&rect3);
			ClosePort (deskPort);
			DisposePtr ((Ptr) deskPort);
			PenNormal ();
			SetPort (savePort);
		}
	#endif
}
예제 #27
0
void CWindowOSXQT::OnPaint()
{
	int iBytesNeeded = (mSize.iCX + 1) * (mSize.iCY + 1) * 4;
	if (iBytesNeeded > miDrawBufferSize) {
		if (mpcDrawBuffer) {
			delete[] mpcDrawBuffer;
		}

		miDrawBufferSize = iBytesNeeded;
		mpcDrawBuffer = new tuchar[miDrawBufferSize];
	}

	if (mpInvalidater->IsRectInvalidated() == false) {
		// No updating neccasary
		return;
	}
	SRect RectUpdate;
	mpInvalidater->GetInvalidatedRect(RectUpdate);
	mpInvalidater->Reset();

	// Limit update rect to our actual size
	SRect RectThis(SPos(0, 0), mSize);
	RectUpdate.FitInside(RectThis);

	GetPane()->OnDraw(RectUpdate);
	if (mpControlOnTop) {
		mpControlOnTop->OnDraw(RectUpdate);
	}

	PixMap 			srcbm;
	GrafPtr 		saved;
	Rect 			portBounds;
	GrafPtr 		grafPtrThis;
	BitMapPtr 		dstbitmap;
	PixMapHandle	dstpixmap;

	memset(&srcbm,0,sizeof(PixMap));
	// setup begin
	srcbm.baseAddr = nil;
	srcbm.rowBytes = 0x8000;

	srcbm.bounds.left = 0;
	srcbm.bounds.top = 0;
	srcbm.bounds.right = mSize.iCX - 1;
	srcbm.bounds.bottom = mSize.iCY - 1;
	
	// ???
	int bytesPerRow = mSize.iCX * 4;

	srcbm.pmVersion = 4;
	srcbm.packType = 0;
	srcbm.packSize = 0;
	srcbm.hRes = 0x00480000;
	srcbm.vRes = 0x00480000;
	srcbm.pixelType = 0;
	srcbm.pixelSize = 0;
	srcbm.cmpCount = 0;
	srcbm.cmpSize = 0;
	srcbm.pmTable = nil;
	srcbm.pixelType = RGBDirect;
	srcbm.pixelSize = 32;
	srcbm.cmpCount = 3;
	srcbm.cmpSize = 5;
	srcbm.rowBytes = 0x8000 | (unsigned short) bytesPerRow;
	srcbm.baseAddr = (Ptr)mpcDrawBuffer;
	
	unsigned long ulOffsetX, ulOffsetY;
	ulOffsetX = 0;
	ulOffsetY = 0;
	
	Rect SrcRect;	
	SrcRect.left    = RectUpdate.iX;
	SrcRect.right   = RectUpdate.iX + RectUpdate.iCX - 1;
	SrcRect.top     = RectUpdate.iY;
	SrcRect.bottom  = RectUpdate.iY + RectUpdate.iCY - 1;

	Rect DstRect;
	DstRect = SrcRect;
		
	GetPort(&saved);
	
	grafPtrThis = (GrafPtr)::GetWindowPort(GetWindowRef());

	if (saved != grafPtrThis) {
		SetPort(grafPtrThis);
	}

	GetPortBounds(grafPtrThis, &portBounds);

	int port_offsetX = portBounds.left;
	int port_offsetY = portBounds.top;

	SetOrigin( port_offsetX, port_offsetY );
/*	Rect rctClip;
	rctClip.left = 0;
	rctClip.right = rctClip.left + mSize.iCX;
	rctClip.top = 0;
	rctClip.bottom = rctClip.top + mSize.iCY;
	ClipRect(&rctClip);*/
	
	dstpixmap = ::GetPortPixMap(grafPtrThis);
	
	dstbitmap = (BitMapPtr)(*dstpixmap);
	
	ForeColor(blackColor);
	BackColor(whiteColor);
	
	::CopyBits((BitMapPtr)&srcbm,
		dstbitmap,
		&SrcRect,
		&DstRect,
		srcCopy,
		nil);
		
//	SetOrigin(0, 0);

	if (saved != grafPtrThis) {
		SetPort(saved);
	}
}
예제 #28
0
파일: if_python3.c 프로젝트: tonymagro/viw
/*
 * External interface
 */
static void
DoPyCommand(const char *cmd, rangeinitializer init_range, runner run, void *arg)
{
#if defined(MACOS) && !defined(MACOS_X_UNIX)
	GrafPtr		oldPort;
#endif
#if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
	char		*saved_locale;
#endif
	PyObject		*cmdstr;
	PyObject		*cmdbytes;
	PyGILState_STATE	pygilstate;

#if defined(MACOS) && !defined(MACOS_X_UNIX)
	GetPort(&oldPort);
	/* Check if the Python library is available */
	if ((Ptr)PyMac_Initialize == (Ptr)kUnresolvedCFragSymbolAddress)
		goto theend;
#endif
	if (Python3_Init())
		goto theend;

	init_range(arg);

	Python_Release_Vim();	    /* leave vim */

#if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
	/* Python only works properly when the LC_NUMERIC locale is "C". */
	saved_locale = setlocale(LC_NUMERIC, NULL);
	if (saved_locale == NULL || STRCMP(saved_locale, "C") == 0)
		saved_locale = NULL;
	else {
		/* Need to make a copy, value may change when setting new locale. */
		saved_locale = (char *)vim_strsave((char_u *)saved_locale);
		(void)setlocale(LC_NUMERIC, "C");
	}
#endif

	pygilstate = PyGILState_Ensure();

	/* PyRun_SimpleString expects a UTF-8 string. Wrong encoding may cause
	 * SyntaxError (unicode error). */
	cmdstr = PyUnicode_Decode(cmd, strlen(cmd),
							  (char *)ENC_OPT, CODEC_ERROR_HANDLER);
	cmdbytes = PyUnicode_AsEncodedString(cmdstr, "utf-8", CODEC_ERROR_HANDLER);
	Py_XDECREF(cmdstr);

	run(PyBytes_AsString(cmdbytes), arg, &pygilstate);
	Py_XDECREF(cmdbytes);

	PyGILState_Release(pygilstate);

#if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
	if (saved_locale != NULL) {
		(void)setlocale(LC_NUMERIC, saved_locale);
		vim_free(saved_locale);
	}
#endif

	Python_Lock_Vim();		    /* enter vim */
	PythonIO_Flush();
#if defined(MACOS) && !defined(MACOS_X_UNIX)
	SetPort(oldPort);
#endif

theend:
	return;	    /* keeps lint happy */
}
예제 #29
0
static void ROM_ShowMenuBar(_THIS)
{
#if !TARGET_API_MAC_CARBON /* This seems not to be available? -sts Aug 2000 */
	RgnHandle		drawRgn = nil;
	RgnHandle		menuRgn = nil;
	RgnHandle		tempRgn = nil;
	RgnHandle		grayRgn = nil;
	WindowPtr		window = nil;
	GrafPtr			wMgrPort;
	GrafPtr			savePort;
	Rect			menuRect;
	long			response;
	short			height;
	EventRecord		theEvent;
	RGBColor		saveRGB;
	RGBColor		blackRGB = { 0, 0, 0 };

	height = GetMBarHeight();
	
	if ((height <= 0) && (gSaveMenuBar > 0)) {
		drawRgn = NewRgn();
		menuRgn = NewRgn();
		tempRgn = NewRgn();
		if ( ! tempRgn || ! drawRgn || ! gSaveGrayRgn ) {
			goto CLEANUP;
		}
		grayRgn = GetGrayRgn(); /* No need to check for this */
	
		GetPort(&savePort);
		GetWMgrPort(&wMgrPort);

		/* Set the height properly */
		LMSetMBarHeight(gSaveMenuBar);

		/* Restore the old GrayRgn: rounded corners, etc, but not
		   the menubar -- subtract that out first! */
		if (gSaveGrayRgn)
			{
			menuRect = (*GetMainDevice())->gdRect;
			menuRect.bottom = menuRect.top + gSaveMenuBar;
			RectRgn(menuRgn, &menuRect);

			DiffRgn(grayRgn, gSaveGrayRgn, drawRgn); 	/* What do we inval? */
			DiffRgn(drawRgn, menuRgn, drawRgn);			/* Clip out the menu */
			
			/* Now redraw the corners and other bits black */
			SetPort(wMgrPort);
			GetClip(tempRgn);
			SetClip(drawRgn);
			GetForeColor(&saveRGB);
			RGBForeColor(&blackRGB);
			PaintRgn(drawRgn);
			RGBForeColor(&saveRGB);
			SetClip(tempRgn);
			SetPort(savePort);
			
			UnionRgn(drawRgn, menuRgn, drawRgn);		/* Put back the menu */

			/* Now actually restore the GrayRgn */
			CopyRgn(gSaveGrayRgn, grayRgn);
			DisposeRgn(gSaveGrayRgn);
			gSaveGrayRgn = nil;
			}

		/* Modify the vis regions of exposed windows and draw menubar */
		window = (FrontWindow()) ? FrontWindow() : (WindowPtr) -1L;
		PaintBehind(window, drawRgn);
		CalcVisBehind(window, drawRgn);
		DrawMenuBar();

		SetPort(savePort);
		gSaveMenuBar = 0;

		/* Now show the control strip if it's present */
		if (!Gestalt(gestaltControlStripAttr, &response) && 
				(response & (1L << gestaltControlStripExists)))
			{
			if (gSaveCSVis && !SBIsControlStripVisible())
				SBShowHideControlStrip(true);
			gSaveCSVis = true;
			}

		/* Yield time so that floaters can catch up */
		EventAvail(0, &theEvent);
		EventAvail(0, &theEvent);
		EventAvail(0, &theEvent);
		EventAvail(0, &theEvent);
		}

CLEANUP:

	if (drawRgn) DisposeRgn(drawRgn);
	if (menuRgn) DisposeRgn(menuRgn);
	if (tempRgn) DisposeRgn(tempRgn);
#endif /* !TARGET_API_MAC_CARBON */
}
예제 #30
0
// --------------------------------------------------------------------------------------------------------------
static OSStatus MyDoPrintLoop(PMPrintSession printSession, PMPageFormat pageFormat, 
				PMPrintSettings printSettings, const void *ourDataP)
{
    OSStatus err = noErr;
    OSStatus tempErr = noErr;
    UInt32 firstPage, lastPage, totalDocPages = MyGetDocumentNumPagesInDoc(ourDataP);
    PMResolution res;
    float ourAppScaling = 1.;
    
    err = PMGetResolution(pageFormat, &res);
    if(!err){
	ourAppScaling = res.hRes/72.;	// the scale factor we are applying
    }

    if(!err)
	err = PMGetFirstPage(printSettings, &firstPage);
	
    if (!err)
        err = PMGetLastPage(printSettings, &lastPage);

    if(!err && lastPage > totalDocPages){
        // don't draw more than the number of pages in our document
        lastPage = totalDocPages;
    }

    if (!err)		// tell the printing system the number of pages we are going to print
        err = PMSetLastPage(printSettings, lastPage, false);

    if (!err)
    {
        PageDrawProc *drawProc = GetMyDrawPageProc(ourDataP);
        err = PMSessionBeginDocument(printSession, printSettings, pageFormat);
        if (!err){
	    UInt32 pageNumber;
            for(pageNumber = firstPage; 
                err == noErr && (err = PMSessionError(printSession)) == noErr && pageNumber <= lastPage; 
                pageNumber++
            ){
                err = PMSessionBeginPage(printSession, pageFormat, NULL);
                if (!err){
                    GrafPtr oldPort = NULL;
                    void *printingContext = NULL;
                    GetPort(&oldPort);	// preserve the existing port
                
                    err = PMSessionGetGraphicsContext(printSession, kPMGraphicsContextQuickdraw,
                                                    (void **)&printingContext);
                    if(!err){
                        SetPort((CGrafPtr)printingContext);
                        err = drawProc(ourDataP, ourAppScaling);	// supply app drawing resolution
                        SetPort(oldPort);	// restore the prior port
                    }
		    tempErr = PMSessionEndPage(printSession);
		    if(!err)err = tempErr;
                }
            }	// end for loop
	    tempErr = PMSessionEndDocument(printSession);
	    if(!err)err = tempErr;
        }
    }
    return err;
}