Пример #1
0
	/* ARGSUSED */
static void
TransformWatchProc(
    ClientData instanceData,	/* Channel to watch. */
    int mask)			/* Events of interest. */
{
    TransformChannelData *dataPtr = instanceData;
    Tcl_Channel downChan;

    /*
     * The caller expressed interest in events occuring for this channel. We
     * are forwarding the call to the underlying channel now.
     */

    dataPtr->watchMask = mask;

    /*
     * No channel handlers any more. We will be notified automatically about
     * events on the channel below via a call to our 'TransformNotifyProc'.
     * But we have to pass the interest down now. We are allowed to add
     * additional 'interest' to the mask if we want to. But this
     * transformation has no such interest. It just passes the request down,
     * unchanged.
     */

    if (dataPtr->self == NULL) {
	return;
    }
    downChan = Tcl_GetStackedChannel(dataPtr->self);

    Tcl_GetChannelType(downChan)->watchProc(
	    Tcl_GetChannelInstanceData(downChan), mask);

    /*
     * Management of the internal timer.
     */

    if ((dataPtr->timer != NULL) &&
	    (!(mask & TCL_READABLE) || ResultEmpty(&dataPtr->result))) {
	/*
	 * A pending timer exists, but either is there no (more) interest in
	 * the events it generates or nothing is available for reading, so
	 * remove it.
	 */

	Tcl_DeleteTimerHandler(dataPtr->timer);
	dataPtr->timer = NULL;
    }

    if ((dataPtr->timer == NULL) && (mask & TCL_READABLE)
	    && !ResultEmpty(&dataPtr->result)) {
	/*
	 * There is no pending timer, but there is interest in readable events
	 * and we actually have data waiting, so generate a timer to flush
	 * that.
	 */

	dataPtr->timer = Tcl_CreateTimerHandler(FLUSH_DELAY,
		TransformChannelHandlerTimer, dataPtr);
    }
}
Пример #2
0
CAMLprim value camltk_add_timer(value milli, value cbid)
{
  CheckInit();
  /* look at tkEvent.c , Tk_Token is an int */
  return (Val_int(Tcl_CreateTimerHandler(Int_val(milli), TimerProc,
                                       (ClientData) (Long_val(cbid)))));
}
Пример #3
0
/*
 *--------------------------------------------------------------
 *
 * PulseDefaultButtonProc --
 *
 *     This function redraws the button on a timer, to pulse
 *     default buttons.
 *
 * Results:
 *     None.
 *
 * Side effects:
 *     Sets a timer to run itself again.
 *
 *--------------------------------------------------------------
 */
static void
PulseDefaultButtonProc(ClientData clientData)
{
    MacButton *mbPtr = (MacButton *)clientData;
    TkpDisplayButton(clientData);
    mbPtr->defaultPulseHandler = Tcl_CreateTimerHandler(
            PULSE_TIMER_MSECS, PulseDefaultButtonProc, clientData);
}
Пример #4
0
dbus_bool_t DBus_AddTimeout(DBusTimeout *timeout, void *data)
{
   Tcl_TimerToken token;
   
   token = Tcl_CreateTimerHandler(dbus_timeout_get_interval(timeout),
				   DBus_Timeout, timeout);
   dbus_timeout_set_data(timeout, token, NULL);
   return TRUE;
}
Пример #5
0
/* ClaimCursor --
 * 	Claim ownership of the insert cursor and blink on.
 */
static void ClaimCursor(CursorManager *cm, WidgetCore *corePtr)
{
    if (cm->owner == corePtr)
        return;
    if (cm->owner)
        LoseCursor(cm, cm->owner);

    corePtr->flags |= CURSOR_ON;
    TtkRedisplayWidget(corePtr);

    cm->owner = corePtr;
    cm->timer = Tcl_CreateTimerHandler(cm->onTime, CursorBlinkProc, cm);
}
Пример #6
0
void DoGraphics(ClientData cl)
{
  /* printf("c doGraph\n"); */
  sprintf(TclCommand,"UpdateTime %g ; update; DoGraphics; update idletasks\n",
	  *theTimeStep);
  Tcl_Eval(interp,TclCommand);
  if(theRunFlag==TRUE) {
#ifdef Tcl75_Tk41
    Tcl_CreateTimerHandler(0, DoMain,(ClientData)NULL);
#endif
#ifdef Tcl74_Tk40
    Tk_CreateTimerHandler(0, DoMain,(ClientData)NULL);
#endif
  }
}
Пример #7
0
/* CursorBlinkProc --
 *	Timer handler to blink the insert cursor on and off.
 */
static void
CursorBlinkProc(ClientData clientData)
{
    CursorManager *cm = (CursorManager*)clientData;
    int blinkTime;

    if (cm->owner->flags & CURSOR_ON) {
        cm->owner->flags &= ~CURSOR_ON;
        blinkTime = cm->offTime;
    } else {
        cm->owner->flags |= CURSOR_ON;
        blinkTime = cm->onTime;
    }
    cm->timer = Tcl_CreateTimerHandler(blinkTime, CursorBlinkProc, clientData);
    TtkRedisplayWidget(cm->owner);
}
Пример #8
0
static void
rcWatchChannel (ClientData cd_, int mask)
{
  ReflectingChannel* chan = (ReflectingChannel*) cd_;

  /* Dec 2001: adopting logic used in Andreas Kupries' memchan, i.e. timers */

  if (mask) {
    chan->_watchMask = mask & chan->_validMask;
    if (chan->_watchMask && chan->_timer == NULL)
      chan->_timer = Tcl_CreateTimerHandler(5, rcTimerProc, cd_);
  } else if (chan->_timer != NULL) {
    Tcl_DeleteTimerHandler(chan->_timer);
    chan->_timer = NULL;
  }
}
Пример #9
0
// called by Gamesman when new game is started
void gPenHandleTclMessage(int options[], char *filename, Tcl_Interp *tclInterp, int debug)
{
	if (hasPenLoaderFinished()) {
		// already read through entire file, no need to do it again
		return;
	}
	if (isPenLoaderStarted()) {
		// loader already started - reset state, change output to new file
		resetGameState();
		startNewPenOutputFile();
	} else if (startPenLoader(filename, debug) == 0) {
		// started loader for the first time - set initial state, start timer
		resetGameState();
		tclInterpreter = tclInterp;
		Tcl_CreateTimerHandler(TCL_TIMER_MS, &TclTimerProc, NULL);
	}
}
Пример #10
0
value caml_Tcl_CreateTimerHandler(value callback_fn, 
				  value milliseconds) {
    timerhandler *h;
    CAMLparam2(callback_fn, milliseconds);

    h = (timerhandler *) (stat_alloc(sizeof(timerhandler)));
    /* This must be a malloc'ed data block. */

    register_global_root(&(h->callback_fn));
    h->callback_fn = callback_fn;
    h->token = 
	Tcl_CreateTimerHandler(Int_val(milliseconds),
			       timer_proc,
			       (ClientData) h);

    CAMLreturn((value) h);
}
Пример #11
0
void
Tk_PointerEvent(
    HWND hwnd,			/* Window for coords, or NULL for the root
				 * window. */
    int x, int y)		/* Coords relative to hwnd, or screen if hwnd
				 * is NULL. */
{
    POINT pos;
    int state;
    Tk_Window tkwin;

    pos.x = x;
    pos.y = y;

    /*
     * Convert client coords to root coords if we were given a window.
     */

    if (hwnd) {
        ClientToScreen(hwnd, &pos);
    }

    /*
     * If the mouse is captured, Windows will report all pointer events to the
     * capture window. So, we need to determine which window the mouse is
     * really over and change the event. Note that the computed hwnd may point
     * to a window not owned by Tk, or a toplevel decorative frame, so tkwin
     * can be NULL.
     */

    if (captured || hwnd == NULL) {
        hwnd = WindowFromPoint(pos);
    }
    tkwin = Tk_HWNDToWindow(hwnd);

    state = TkWinGetModifierState();

    Tk_UpdatePointer(tkwin, pos.x, pos.y, state);

    if ((captured || tkwin) && !mouseTimerSet) {
        mouseTimerSet = 1;
        mouseTimer = Tcl_CreateTimerHandler(MOUSE_TIMER_INTERVAL,
                                            MouseTimerProc, NULL);
    }
}
Пример #12
0
void DoMain(ClientData cl)
{
  char thePDumpFile[80], thePDFRoot[80];

  strncpy(thePDFRoot,theDumpFile,findlen(theDumpFile));
  thePDFRoot[findlen(theDumpFile)] = '\0';
  sprintf(TclCommand,"update \n");
  Tcl_Eval(interp,TclCommand);
  /* printf("c domain\n"); */
  if (theNumberOfSteps==0 || theCurrentStep<=theNumberOfSteps) {
    int il;
    for(il=0;il<iterationsPerXUpdate;il++) {
      XGMainLoop();
      if (theDumpPeriod!=0 && theCurrentStep%theDumpPeriod==0) {
	sprintf(thePDumpFile,"%s%d%s",thePDFRoot,
		theCurrentStep/theDumpPeriod,theDumpExtension);
	if (theIDumpFlag) Dump(thePDumpFile);
	else Dump(theDumpFile);
      }
      theCurrentStep++;
    }
#ifdef Tcl75_Tk41
    Tcl_CreateTimerHandler(0, DoGraphics,(ClientData)NULL);
#endif
#ifdef Tcl74_Tk40
    Tk_CreateTimerHandler(0, DoGraphics,(ClientData)NULL);
#endif
  } else {
    if(theExitFlag) {
      if ((theDumpPeriod!=0) && (theIDumpFlag)) {
	sprintf(thePDumpFile,"%s%d%s",thePDFRoot,
		theCurrentStep/theDumpPeriod+1,theDumpExtension);
	Dump(thePDumpFile);
      } 
      else Dump(theDumpFile);
      XG_Quit();
    } else {
      theNumberOfSteps = 0;
      Tcl_Eval(interp,".lbframe.run invoke\n");
      Tcl_Eval(interp,".lbframe.save invoke\n");
    }
  }
}
Пример #13
0
Файл: tcl.c Проект: grawity/gale
static void on_time(oop_source *x,struct timeval t,oop_call_time *f,void *d) {
        struct timer_handler * const timer = oop_malloc(sizeof(*timer));
        struct timeval now;
        int msec;
        if (NULL == timer) return; /* YUCK */

        gettimeofday(&now,NULL);
        if (t.tv_sec < now.tv_sec
        || (t.tv_sec == now.tv_sec && t.tv_usec < now.tv_usec))
                msec = 0;
        else {
                msec = 1000 * (t.tv_sec - now.tv_sec);
                msec = msec + (t.tv_usec - now.tv_usec) / 1000;
        }

        assert(msec >= 0);
        timer->t = t;
        timer->f = f;
        timer->d = d;
        timer->next = list;
        timer->token = Tcl_CreateTimerHandler(msec,timer_call,timer);
        list = timer;
}
Пример #14
0
// called by Tcl Event loop to check for new data
void TclTimerProc(ClientData clientData)
{
	if (!isPenLoaderStarted()) {
		printLog("Timer stopped\n");
		return;
	}

	// get the next stroke to analyze
	Stroke stroke = getNextAvailableStroke();
	Tcl_CreateTimerHandler(TCL_TIMER_MS, &TclTimerProc, NULL);
	if (stroke.nSamples == 0) {
		return;
	}
	if (gameFinished) {
		printLog("   This game is already finished, skipping stroke\n");
		return;
	}


	// if already have the board, determine and make the move
	if (numBoardLines == 4) {
		Line testLine = newLine(boardCenterX, boardCenterY, stroke.bounds.centerX, stroke.bounds.centerY);
		int crossing = (doLinesIntersect(&testLine, boardLeft)) ? CROSS_LEFT : CROSS_NONE;
		crossing |= (doLinesIntersect(&testLine, boardRight)) ? CROSS_RIGHT : CROSS_NONE;
		crossing |= (doLinesIntersect(&testLine, boardTop)) ? CROSS_TOP : CROSS_NONE;
		crossing |= (doLinesIntersect(&testLine, boardBottom)) ? CROSS_BOTTOM : CROSS_NONE;

		int move = CrossToMove[crossing];
		if (move == -1) {
			printLog("   Invalid crossing value detected: %d, skipping\n", crossing);
			return;
		} else if (movesDone[move] != 0) {
			printLog("   Skipping duplicate move: %d\n", move);
			return;
		}

		movesDone[move] = currentPlayer;
		currentPlayer = (currentPlayer % 2) + 1;
		printLog("   Making move %d\n", move);
		char moveCommand[30];
		sprintf(moveCommand, "ReturnFromHumanMove %d", move);
		Tcl_Eval(tclInterpreter, moveCommand);
		if (checkForFinishCondition()) {
			gameFinished = TRUE;
			printLog("   Game finished\n");
		}
		return;
	}


	// otherwise, add the stroke to the board
	if (stroke.type != STROKE_LINE) {
		printLog("   Board isn't finished, skipping non-LINE stroke\n");
		return;
	}
	boardLines[numBoardLines] = stroke.line;
	numBoardLines++;
	if (numBoardLines < 4) {
		return;
	}


	// determine board lines (two pairs of non-intersecting lines)
	int idx, match1b, match2a, match2b;
	match1b = 0;
	for (idx = 1; idx < 4; idx++) {
		if (!doLinesIntersect(&boardLines[0], &boardLines[idx])) {
			if (match1b != 0) {
				// matched twice, so something is wrong
				match1b = 0;
				break;
			}
			match1b = idx;
			match2a = (idx == 1) ? 2 : 1;
			match2b = (idx == 3) ? 2 : 3;
		}
	}

	// verify that matched lines intersect properly
	if ((match1b == 0) ||
	    (!doLinesIntersect(&boardLines[match1b], &boardLines[match2a])) ||
	    (!doLinesIntersect(&boardLines[match1b], &boardLines[match2b])) ||
	    (doLinesIntersect(&boardLines[match2a], &boardLines[match2b]))) {
		printLog("   Could not match board lines, trying again without first line\n");
		boardLines[0] = boardLines[1];
		boardLines[1] = boardLines[2];
		boardLines[2] = boardLines[3];
		numBoardLines = 3;
		return;
	}

	// assign proper sides (within 90 degree range away from pure vertical or horizontal)
	double angle = fabs(boardLines[0].angleDegrees);
	BOOL isLeft, isTop;
	int leftIdx, rightIdx, topIdx, bottomIdx;
	if (angle >= 45 && angle < 135) {
		// match 1 is vertical, match 2 is horizontal
		isLeft = (boardLines[0].centerX < boardLines[match1b].centerX);
		isTop = (boardLines[match2a].centerY < boardLines[match2b].centerY);
		leftIdx = isLeft ? 0 : match1b;
		rightIdx = isLeft ? match1b : 0;
		topIdx = isTop ? match2a : match2b;
		bottomIdx = isTop ? match2b : match2a;
	} else {
		// match 2 is vertical, match 1 is horizontal
		isLeft = (boardLines[match2a].centerX < boardLines[match2b].centerX);
		isTop = (boardLines[0].centerY < boardLines[match1b].centerY);
		leftIdx = isLeft ? match2a : match2b;
		rightIdx = isLeft ? match2b : match2a;
		topIdx = isTop ? 0 : match1b;
		bottomIdx = isTop ? match1b : 0;
	}
	boardLeft = &boardLines[leftIdx];
	boardRight = &boardLines[rightIdx];
	boardTop = &boardLines[topIdx];
	boardBottom = &boardLines[bottomIdx];

	// calculate center of the board (average of the 4 intersection points)
	double iLeftTop = intersectionPoint(boardLeft, boardTop);
	double iLeftBottom = intersectionPoint(boardLeft, boardBottom);
	double iRightTop = intersectionPoint(boardRight, boardTop);
	double iRightBottom = intersectionPoint(boardRight, boardBottom);
	boardCenterX = projectedX(boardLeft, iLeftTop, TRUE);
	boardCenterX += projectedX(boardLeft, iLeftBottom, TRUE);
	boardCenterX += projectedX(boardRight, iRightTop, TRUE);
	boardCenterX += projectedX(boardRight, iRightBottom, TRUE);
	boardCenterY = projectedY(boardLeft, iLeftTop, TRUE);
	boardCenterY += projectedY(boardLeft, iLeftBottom, TRUE);
	boardCenterY += projectedY(boardRight, iRightTop, TRUE);
	boardCenterY += projectedY(boardRight, iRightBottom, TRUE);
	boardCenterX /= 4;
	boardCenterY /= 4;
	printLog("   Detected board strokes: Left %d, Right %d, Top %d, Bottom %d, with center (%.3f, %.3f)\n", \
	         leftIdx, rightIdx, topIdx, bottomIdx, boardCenterX, boardCenterY);
}
Пример #15
0
static void
TkMacOSXComputeButtonParams(
        TkButton * butPtr,
        ThemeButtonKind* btnkind,
	HIThemeButtonDrawInfo *drawinfo)
{
    MacButton *mbPtr = (MacButton *)butPtr;

    if (butPtr->borderWidth <= 2) {
        *btnkind = kThemeSmallBevelButton;
    } else if (butPtr->borderWidth == 3) {
        *btnkind = kThemeBevelButton;
    } else if (butPtr->borderWidth == 4) {
        *btnkind = kThemeRoundedBevelButton;
    } else {
        *btnkind = kThemePushButton;
    }

    if ((butPtr->image == None) && (butPtr->bitmap == None)) {
        switch (butPtr->type) {
            case TYPE_BUTTON:
                *btnkind = kThemePushButton;
                break;
            case TYPE_RADIO_BUTTON:
                if (butPtr->borderWidth <= 1) {
                    *btnkind = kThemeSmallRadioButton;
		} else {
                    *btnkind = kThemeRadioButton;
		}
		break;
	    case TYPE_CHECK_BUTTON:
                if (butPtr->borderWidth <= 1) {
                    *btnkind = kThemeSmallCheckBox;
	        } else {
                    *btnkind = kThemeCheckBox;
		}
		break;
	}
    }

    if (butPtr->indicatorOn) {
        switch (butPtr->type) {
            case TYPE_RADIO_BUTTON:
                if (butPtr->borderWidth <= 1) {
                    *btnkind = kThemeSmallRadioButton;
                } else {
                    *btnkind = kThemeRadioButton;
                }
                break;
            case TYPE_CHECK_BUTTON:
                if (butPtr->borderWidth <= 1) {
                    *btnkind = kThemeSmallCheckBox;
                } else {
                    *btnkind = kThemeCheckBox;
                }
                break;
        }
    } else {
        if (butPtr->type == TYPE_RADIO_BUTTON ||
	    butPtr->type == TYPE_CHECK_BUTTON
	) {
	    if (*btnkind == kThemePushButton) {
		*btnkind = kThemeBevelButton;
	    }
        }
    }

    if (butPtr->flags & SELECTED) {
        drawinfo->value = kThemeButtonOn;
    } else if (butPtr->flags & TRISTATED) {
        drawinfo->value = kThemeButtonMixed;
    } else {
        drawinfo->value = kThemeButtonOff;
    }

    if ((mbPtr->flags & FIRST_DRAW) != 0) {
	mbPtr->flags &= ~FIRST_DRAW;
	if (Tk_MacOSXIsAppInFront()) {
	    mbPtr->flags |= ACTIVE;
	}
    }

    drawinfo->state = kThemeStateInactive;
    if ((mbPtr->flags & ACTIVE) == 0) {
        if (butPtr->state == STATE_DISABLED) {
            drawinfo->state = kThemeStateUnavailableInactive;
        } else {
            drawinfo->state = kThemeStateInactive;
        }
    } else if (butPtr->state == STATE_DISABLED) {
        drawinfo->state = kThemeStateUnavailable;
    } else if (butPtr->state == STATE_ACTIVE) {
        drawinfo->state = kThemeStatePressed;
    } else {
        drawinfo->state = kThemeStateActive;
    }

    drawinfo->adornment = kThemeAdornmentNone;
    if (butPtr->defaultState == DEFAULT_ACTIVE) {
        drawinfo->adornment |= kThemeAdornmentDefault;
        if (!mbPtr->defaultPulseHandler) {
            mbPtr->defaultPulseHandler = Tcl_CreateTimerHandler(
                    PULSE_TIMER_MSECS, PulseDefaultButtonProc,
                    (ClientData) butPtr);
        }
    } else if (mbPtr->defaultPulseHandler) {
        Tcl_DeleteTimerHandler(mbPtr->defaultPulseHandler);
    }
    if (butPtr->highlightWidth >= 3) {
        if ((butPtr->flags & GOT_FOCUS)) {
            drawinfo->adornment |= kThemeAdornmentFocus;
        }
    }
}
Пример #16
0
Файл: tlsIO.c Проект: fahkri/tls
static void
TlsWatchProc(ClientData instanceData,	/* The socket state. */
             int mask)			/* Events of interest; an OR-ed
                                         * combination of TCL_READABLE,
                                         * TCL_WRITABLE and TCL_EXCEPTION. */
{
    State *statePtr = (State *) instanceData;

    dprintf(stderr, "TlsWatchProc(0x%x)\n", mask);

    /* Pretend to be dead as long as the verify callback is running. 
     * Otherwise that callback could be invoked recursively. */
    if (statePtr->flags & TLS_TCL_CALLBACK) { return; }

    if (channelTypeVersion == TLS_CHANNEL_VERSION_2) {
	Tcl_Channel     downChan;

	statePtr->watchMask = mask;

	/* No channel handlers any more. We will be notified automatically
	 * about events on the channel below via a call to our
	 * 'TransformNotifyProc'. But we have to pass the interest down now.
	 * We are allowed to add additional 'interest' to the mask if we want
	 * to. But this transformation has no such interest. It just passes
	 * the request down, unchanged.
	 */

	downChan = Tls_GetParent(statePtr);

	(Tcl_GetChannelType(downChan))
	    ->watchProc(Tcl_GetChannelInstanceData(downChan), mask);

	/*
	 * Management of the internal timer.
	 */

	if (statePtr->timer != (Tcl_TimerToken) NULL) {
	    Tcl_DeleteTimerHandler(statePtr->timer);
	    statePtr->timer = (Tcl_TimerToken) NULL;
	}
	if ((mask & TCL_READABLE) && Tcl_InputBuffered(statePtr->self) > 0) {
	    /*
	     * There is interest in readable events and we actually have
	     * data waiting, so generate a timer to flush that.
	     */
	    statePtr->timer = Tcl_CreateTimerHandler(TLS_TCL_DELAY,
		    TlsChannelHandlerTimer, (ClientData) statePtr);
	}
    } else {
	if (mask == statePtr->watchMask)
	    return;

	if (statePtr->watchMask) {
	    /*
	     * Remove event handler to underlying channel, this could
	     * be because we are closing for real, or being "unstacked".
	     */

	    Tcl_DeleteChannelHandler(Tls_GetParent(statePtr),
		    TlsChannelHandler, (ClientData) statePtr);
	}
	statePtr->watchMask = mask;
	if (statePtr->watchMask) {
	    /*
	     * Setup active monitor for events on underlying Channel.
	     */

	    Tcl_CreateChannelHandler(Tls_GetParent(statePtr),
		    statePtr->watchMask, TlsChannelHandler,
		    (ClientData) statePtr);
	}
    }
}