Пример #1
0
static int
paxwidget_widget_cmd(ClientData data, Tcl_Interp * interp,
		     int argc, char** argv)
{
    PaxWidget * paxwidget = (PaxWidget*)data;
    int result = TCL_OK;
    size_t length;
    char c;

    if (argc < 2)
    {
	Tcl_AppendResult(interp, "wrong # args: should be \"",
			 argv[0], " option ?arg arg ...?\"", (char *) NULL);
	return TCL_ERROR;
    }
    Tk_Preserve((ClientData) paxwidget);
    c = argv[1][0];
    length = strlen(argv[1]);
    if (c == 'b' && strncmp(argv[1], "bgpixel", length) == 0)
    {
	sprintf(Tcl_GetStringResult(interp), "%ld",
		Tk_3DBorderColor(paxwidget->background)->pixel);
    }
    else if ((c == 'c') && (strncmp(argv[1], "cget", length) == 0)
	     && (length >= 2))
    {
	if (argc != 3)
	{
	    Tcl_AppendResult(interp, "wrong # args: should be \"",
			     argv[0], " cget option\"",
			     (char *) NULL);
	    goto error;
	}
	result = Tk_ConfigureValue(interp, paxwidget->tkwin, configSpecs,
				   (char *) paxwidget, argv[2], 0);
    }
    else if ((c == 'c') && (strncmp(argv[1], "configure", length) == 0)
	     && (length >= 2))
    {
	if (argc == 2)
	{
	    result = Tk_ConfigureInfo(interp, paxwidget->tkwin, configSpecs,
				      (char *) paxwidget, (char *) NULL, 0);
	}
	else if (argc == 3)
	{
	    result = Tk_ConfigureInfo(interp, paxwidget->tkwin, configSpecs,
				      (char *) paxwidget, argv[2], 0);
	}
	else
	{
	    result = PaxWidgetConfigure(interp, paxwidget, argc-2, argv+2,
					TK_CONFIG_ARGV_ONLY);
	}
    }
    else if ((c == 'm') && (strncmp(argv[1], "motionhints", length) == 0))
    {
	XSetWindowAttributes* attr;
	if (argc != 2)
	{
	    Tcl_AppendResult(interp, "wrong # args: should be \"",
			     argv[0], " motionhints\"",
			     (char *) NULL);
	    goto error;
	}

	attr = Tk_Attributes(paxwidget->tkwin);
	XSelectInput(Tk_Display(paxwidget->tkwin),
		     Tk_WindowId(paxwidget->tkwin),
		     attr->event_mask | PointerMotionHintMask);

    }
    else if ((c == 'u') && (strncmp(argv[1], "update", length) == 0))
    {
	if (argc != 2)
	{
	    Tcl_AppendResult(interp, "wrong # args: should be \"",
			     argv[0], " update\"",
			     (char *) NULL);
	    goto error;
	}
	PaxWidget_RegisterUpdate(paxwidget);
    }
    else if ((c == 'x') && (strncmp(argv[1], "xview", length) == 0))
    {
	int count, type;
	double fraction;

	type = Tk_GetScrollInfo(interp, argc, argv, &fraction, &count);

	switch (type)
	{
	case TK_SCROLL_ERROR:
	    goto error;
	case TK_SCROLL_MOVETO:
	    paxWidget_CallMethodArgs(paxwidget->obj, ScrollXMoveIdx,
				     Py_BuildValue("(d)", fraction));
	    break;
	case TK_SCROLL_PAGES:
	    paxWidget_CallMethodArgs(paxwidget->obj, ScrollXPagesIdx,
				     Py_BuildValue("(i)", count));
	    break;
	case TK_SCROLL_UNITS:
	    paxWidget_CallMethodArgs(paxwidget->obj, ScrollXUnitsIdx,
				     Py_BuildValue("(i)", count));
	    break;
	}
    }
    else if ((c == 'y') && (strncmp(argv[1], "yview", length) == 0))
    {
	int count, type;
	double fraction;

	type = Tk_GetScrollInfo(interp, argc, argv, &fraction, &count);

	switch (type)
	{
	case TK_SCROLL_ERROR:
	    goto error;
	case TK_SCROLL_MOVETO:
	    paxWidget_CallMethodArgs(paxwidget->obj, ScrollYMoveIdx,
				     Py_BuildValue("(d)", fraction));
	    break;
	case TK_SCROLL_PAGES:
	    paxWidget_CallMethodArgs(paxwidget->obj, ScrollYPagesIdx,
				     Py_BuildValue("(i)", count));
	    break;
	case TK_SCROLL_UNITS:
	    paxWidget_CallMethodArgs(paxwidget->obj, ScrollYUnitsIdx,
				     Py_BuildValue("(i)", count));
	    break;
	}
    }

    Tk_Release((ClientData) paxwidget);
    return result;

 error:
    Tk_Release((ClientData) paxwidget);
    return TCL_ERROR;
}
Пример #2
0
/*
 * EdNames widget command
 */
static int NamesWidgetCmd(ClientData clientData, Tcl_Interp *interp,
			  int argc, char **argv) {
    edNames *en = (edNames *)clientData;
    int result = TCL_OK;

    if (argc < 2) {
        Tcl_AppendResult(interp, "wrong # args: should be \"",
                         argv[0], " option ?arg arg ...?\"",
                         (char *) NULL);
        return TCL_ERROR;
    }

    Tcl_Preserve((ClientData)TKSHEET(en));

    if ('c' == *argv[1] && strcmp(argv[1], "configure") == 0) {
	result = SheetWidgetCmdConfig(interp, TKSHEET(en), argc, argv);

    } else if (!en->xx) {
	en->xx = 0; /* Do nothing and flow through to 'success' */

    } else if ('u' == *argv[1] && strcmp(argv[1], "update_brief") == 0) {
	int x, y;

	if (argc != 4) {
	    Tcl_AppendResult(interp, "wrong # args: should be \"",
			     argv[0], " update_brief xpos ypos\"",
			     (char *) NULL);
	    goto fail;
	}
	
	sheet_arg_x(TKSHEET(en), argv[2], &x);
	sheet_arg_y(TKSHEET(en), argv[3], &y); y++;

	edSetBriefNameStatus(en->xx, x, y);

    } else if ('h' == *argv[1] && strcmp(argv[1], "highlight") == 0) {
	int y, x, mode = -1;

	if (argc != 4 && argc != 5) {
	    Tcl_AppendResult(interp, "wrong # args: should be \"",
			     argv[0], " highlight mode ?xpos? ypos\"",
			     (char *) NULL);
	    goto fail;
	}

	Tcl_GetInt(interp, argv[2], &mode);

	if (argc == 5) {
	    sheet_arg_x(TKSHEET(en), argv[3], &x);
	    y = 4; /* argv number of y, rather than y itself */
	} else {
	    x = 2;
	    y = 3;
	}

	if (*argv[y] == '=') {
	    y = get_gel_num(DBI_io(en->xx), &argv[y][1], GGN_ID);
	    y = rnum_to_edseq(en->xx, y);
	} else {
	    sheet_arg_y(TKSHEET(en), argv[y], &y); y++;
	    y = edGetGelNumber(en->xx, 0, y);
	}

	if (-1 != y) {
	    if (x != 0) {
		edSelectRead(en->xx, y, mode);

		vTcl_SetResult(interp, "%d",
			       (DB_Flags(en->xx, y) & DB_FLAG_SELECTED) ?1:0);
	    } else {
		if (y)
		    select_note(DBI_io(en->xx), GT_Readings,
				DB_Number(en->xx,y));
		else
		    select_note(DBI_io(en->xx), GT_Contigs,
				DBI_contigNum(en->xx));
	    }
	}

    } else if ('g' == *argv[1] && strcmp(argv[1], "get_number") == 0) {
	int x, y, num;

	if (argc != 2 && argc != 4) {
	    Tcl_AppendResult(interp, "wrong # args: should be \"",
			     argv[0], " get_number ?xpos ypos?\"",
			     (char *) NULL);
	    goto fail;
	}

	if (argc == 4) {
	    sheet_arg_x(TKSHEET(en), argv[2], &x);
	    sheet_arg_y(TKSHEET(en), argv[3], &y); y++;

	    if (-1 != (num = edGetGelNumber(en->xx, x, y))) {
		vTcl_SetResult(interp, "%d", num);
	    } /* otherwise return a blank */
	} else {
	    vTcl_SetResult(interp, "%d", en->xx->cursorSeq);
	}

    } else if ('g' == *argv[1] && strcmp(argv[1], "get_read_number") == 0) {
	int num;

	if (argc != 2 && argc != 3) {
	    Tcl_AppendResult(interp, "wrong # args: should be \"",
			     argv[0], " get_read_number ?editor_gel_number?\"",
			     (char *) NULL);
	    goto fail;
	}

	if (argc == 3)
	    Tcl_GetInt(interp, argv[2], &num);
	else
	    num = en->xx->cursorSeq;

	vTcl_SetResult(interp, "%d", DB_Number(en->xx, num));

    } else if ('g' == *argv[1] && strcmp(argv[1], "get_contig_number") == 0) {
	if (argc != 2) {
	    Tcl_AppendResult(interp, "wrong # args: should be \"",
			     argv[0], " get_contig_number",
			     (char *) NULL);
	    goto fail;
	}

	vTcl_SetResult(interp, "%d", -DB_Number(en->xx, 0));

    } else if ('g' == *argv[1] && strcmp(argv[1], "get_name") == 0) {
	char *name;
	int num;

	if (argc != 2 && argc != 3) {
	    Tcl_AppendResult(interp, "wrong # args: should be \"",
			     argv[0], " get_name ?editor_gel_number?\"",
			     (char *) NULL);
	    goto fail;
	}

	if (argc == 3)
	    Tcl_GetInt(interp, argv[2], &num);
	else
	    num = en->xx->cursorSeq;

	Tcl_ResetResult(interp);
	if (NULL != (name = edGetGelName(en->xx, num))) {
	    Tcl_AppendResult(interp, name, NULL);
	} /* otherwise return a blank */

    } else if ('g' == *argv[1] && strcmp(argv[1], "get_names_to_right") == 0) {
	int num;
	dstring_t *ds = NULL;

	if (argc != 2 && argc != 3) {
	    Tcl_AppendResult(interp, "wrong # args: should be \"",
			     argv[0], " get_name ?gel_number?\"",
			     (char *) NULL);
	    goto fail;
	}

	if (argc == 3)
	    Tcl_GetInt(interp, argv[2], &num);
	else
	    num = en->xx->cursorSeq;

	if (NULL != (ds = edGetGelNamesToRight(en->xx, num))) {
	    Tcl_SetResult(interp, dstring_str(ds), TCL_VOLATILE);
	    dstring_destroy(ds);
	} else {
	    /* otherwise return a blank */
	    Tcl_ResetResult(interp);
	}

    } else if ('x' == *argv[1] && strcmp(argv[1], "xview") == 0) {
	int offset, count, type;
	double fraction;

	if (argc == 2) {
	    /* query */
	    vTcl_SetResult(interp, "%d", en->xx->names_xpos);
	} else {
	    if (argc == 3) {
		/* old syntax */
		if (Tcl_GetInt(interp, argv[2], &offset) != TCL_OK) {
		    goto fail;
		}
		setNamePos(en->xx, offset);
	    } else {
		/* new syntax */
		type = Tk_GetScrollInfo(interp, argc, argv, &fraction, &count);
		switch (type) {
                case TK_SCROLL_ERROR:
                    goto fail;
                case TK_SCROLL_MOVETO:
                    offset = (int) (fraction*DB_NAMELEN + 0.5);
                    break;
                case TK_SCROLL_PAGES:
		    count *= 4;
                case TK_SCROLL_UNITS:
		    offset = en->xx->names_xpos + count;
                    break;
		}
		if (offset < 0)
		    offset = 0;
		if (offset + (en->sw.columns - (DB_GELNOLEN + 1)) > DB_NAMELEN)
		    offset = DB_NAMELEN - (en->sw.columns - (DB_GELNOLEN + 1));
		setNamePos(en->xx, offset);
	    }
	    
	    /* Update X scrollbar */
	    ed_set_nslider_pos(en->xx, en->xx->names_xpos);
	}

    } else if ('c' == *argv[1] && strcmp(argv[1], "coords") == 0) {
	int x, y;
	if (argc != 4) {
	    Tcl_AppendResult(interp, "wrong # args: should be \"",
			     argv[0], " update_brief xpos ypos\"",
			     (char *) NULL);
	    goto fail;
	}
	
	sheet_arg_x(TKSHEET(en), argv[2], &x);
	sheet_arg_y(TKSHEET(en), argv[3], &y); y++;

	vTcl_SetResult(interp, "%d %d", x, y);

    } else {
	Tcl_AppendResult(interp, "bad option \"", argv[1], "\": must be FIXME",
			 NULL);
	goto fail;
    }

    Tcl_Release((ClientData)TKSHEET(en));
    return result;

 fail:
    Tcl_Release((ClientData)TKSHEET(en));
    return TCL_ERROR;
}
Пример #3
0
static int
imfsample_widget_cmd(ClientData cldata, Tcl_Interp *interp, int argc, char **argv)
{
    Imfsample *imfsample = (Imfsample *) cldata;
    int result = TCL_OK;
    size_t cmdlength;
    char c;
    int x, y, col, row, n;
    char tclbuf[100];
    int rslt;

    if (argc < 2) {
	Tcl_AppendResult(interp, "wrong # args: should be \"",
		argv[0], " option ?arg arg ...?\"", (char *) NULL);
	return TCL_ERROR;
    }
    Tcl_Preserve((ClientData) imfsample);
    c = argv[1][0];
    cmdlength = strlen(argv[1]);
    if ((c == 'c') && (strncmp(argv[1], "cget", cmdlength) == 0)
	&& (cmdlength >= 2)) {
	if (argc != 3) {
	    Tcl_AppendResult(interp, "wrong # args: should be \"",
		    argv[0], " cget option\"",
		    (char *) NULL);
	    goto error;
	}
	result = Tk_ConfigureValue(interp, imfsample->tkwin, config_specs,
		(char *) imfsample, argv[2], 0);
    } else if ((c == 'c') && (strncmp(argv[1], "configure", cmdlength) == 0)
	       && (cmdlength >= 2)) {
	if (argc == 2) {
	    result = Tk_ConfigureInfo(interp, imfsample->tkwin, config_specs,
		    (char *) imfsample, (char *) NULL, 0);
	} else if (argc == 3) {
	    result = Tk_ConfigureInfo(interp, imfsample->tkwin, config_specs,
		    (char *) imfsample, argv[2], 0);
	} else {
	    result = imfsample_configure(interp, imfsample, argc-2, argv+2,
		    TK_CONFIG_ARGV_ONLY);
	}
    } else if ((c == 'c') && (strncmp(argv[1], "curselection", cmdlength) == 0)
	       && (cmdlength >= 2)) {
        sprintf(Tcl_GetStringResult(interp), "%d", imfsample->selected);
    } else if ((c == 'a') && (strncmp(argv[1], "add", cmdlength) == 0)
	       && (cmdlength >= 2)) {
	if (strcmp(argv[2], "imf") == 0) {
	    imfsample_add_imf(imfsample, argv[3]);
	} else if (strcmp(argv[2], "all") == 0) {
	    imfsample_add_imf(imfsample, "-all");
	}
    } else if ((c == 'e') && (strncmp(argv[1], "emblem", cmdlength) == 0)
	       && (cmdlength >= 2)) {
	n = strtol(argv[2], NULL, 10);
	imfsample->with_emblem = n;
    } else if ((c == 'r') && (strncmp(argv[1], "redraw", cmdlength) == 0)
	       && (cmdlength >= 2)) {
	imfsample->redraw = TRUE;
	if (!imfsample->update_pending) {
		Tcl_DoWhenIdle(imfsample_display, cldata);
		imfsample->update_pending = 1;
	}
    } else if ((c == 'r') && (strncmp(argv[1], "replace", cmdlength) == 0)
	       && (cmdlength >= 2)) {
	if (strcmp(argv[2], "imf") == 0) {
	    imfsample_replace_imf(imfsample, argv[3]);
	} else if (strcmp(argv[2], "emblem") == 0) {
	    imfsample_replace_emblem(imfsample, argv[3]);
	}
    } else if ((c == 'r') && (strncmp(argv[1], "remove", cmdlength) == 0)
	       && (cmdlength >= 2)) {
	if (strcmp(argv[2], "imf") == 0) {
	    imfsample_remove_imf(imfsample, argv[3]);
	} else if (strcmp(argv[2], "emblem") == 0) {
	    imfsample->numimages = 1;
	} else if (strcmp(argv[2], "all") == 0) {
	    imfsample_remove_imf(imfsample, "-all");
	    if (imfsample->imfapp) {
	    	    imfsample->selected = -1;
	    	    imfsample->previous = -1;
		    /* Turn off the scrollbar. */
		    sprintf(tclbuf, ".images.scroll set 0 1");
		    rslt = Tcl_Eval(interp, tclbuf);
		    if (rslt == TCL_ERROR) {
		        fprintf(stderr, "Error: %s\n", Tcl_GetStringResult(interp));
		    }
	    }
	}
    } else if ((c == 's') && (strncmp(argv[1], "select", cmdlength) == 0)
	       && (cmdlength >= 2)) {
	if (imfsample->numimages) {
		x = strtol(argv[2], NULL, 10);
		y = strtol(argv[3], NULL, 10);
		col = x / imfsample->eltw;
		row = y / imfsample->elth + imfsample->firstvisrow;
		n = row * imfsample->cols + col;
		if (n < 0 
		    || n >= imfsample->numimages
		    || col >= imfsample->cols) {
			n = -1;
		}
		/* This rather complicated scheme is to ensure that we can both select
		images and then deselect them by clicking a second time on the image or
		by clicking in an empty region. */
		if (imfsample->selected != n) {
			imfsample->previous = imfsample->selected;
			imfsample->selected = n;
		} else if (n == -1) {
			imfsample->selected = -1;
		} else {
			imfsample->previous = n;
			imfsample->selected = -1;
		}
	}
    } else if ((c == 't') && (strncmp(argv[1], "terrain", cmdlength) == 0)
	       && (cmdlength >= 2)) {
	n = strtol(argv[2], NULL, 10);
	imfsample->with_terrain = n;
    } else if ((c == 'x') && (strncmp(argv[1], "xview", cmdlength) == 0)) {
    } else if ((c == 'y') && (strncmp(argv[1], "yview", cmdlength) == 0)) {
	int count, type, nrow = imfsample->firstvisrow;
	double fraction, fraction2;

	type = Tk_GetScrollInfo(interp, argc, argv, &fraction, &count);
	switch (type) {
		  case TK_SCROLL_ERROR:
		goto error;
		  case TK_SCROLL_MOVETO:
		nrow = fraction * imfsample->rows;
		break;
		  case TK_SCROLL_PAGES:
		nrow += (count * imfsample->numvisrows * 4) / 5;
		break;
		  case TK_SCROLL_UNITS:
		nrow += count;
		break;
	}
	/* Don't allow negative row numbers. */
	imfsample->firstvisrow = max(0, nrow);
	/* Compute the bounds of the visible window. */
	fraction = (double) imfsample->firstvisrow / imfsample->rows;
	fraction2 = (double) (imfsample->firstvisrow + imfsample->numvisrows) / imfsample->rows;
	if (imfsample->imfapp) {
		/* We must set the scrollbar explicitly since the imfsample widget
		lacks a built-in yscrollcommand. */
		sprintf(tclbuf, ".images.scroll set %f %f", fraction, fraction2);
		rslt = Tcl_Eval(interp, tclbuf);
		if (rslt == TCL_ERROR) {
		  fprintf(stderr, "Error: %s\n", Tcl_GetStringResult(interp));
		}
	}
    } else {
	Tcl_AppendResult(interp, "bad option \"", argv[1],
		"\": must be cget, configure, position, replace, remove, select",
		(char *) NULL);
	goto error;
    }
    if (!imfsample->update_pending) {
	Tcl_DoWhenIdle(imfsample_display, (ClientData) imfsample);
	imfsample->update_pending = 1;
    }
    Tcl_Release((ClientData) imfsample);
    return result;

error:
    Tcl_Release((ClientData) imfsample);
    return TCL_ERROR;
}