Пример #1
0
struct options_entry *
options_set_style(struct options *oo, const char *name, const char *value,
    int append)
{
	struct options_entry	*o;
	struct grid_cell	 tmpgc;

	o = options_find1(oo, name);
	if (o == NULL || !append)
		memcpy(&tmpgc, &grid_default_cell, sizeof tmpgc);
	else
		memcpy(&tmpgc, &o->style, sizeof tmpgc);

	if (style_parse(&grid_default_cell, &tmpgc, value) == -1)
		return (NULL);

	if (o == NULL) {
		o = xmalloc(sizeof *o);
		o->name = xstrdup(name);
		RB_INSERT(options_tree, &oo->tree, o);
	} else if (o->type == OPTIONS_STRING)
		free(o->str);

	o->type = OPTIONS_STYLE;
	memcpy(&o->style, &tmpgc, sizeof o->style);
	return (o);
}
Пример #2
0
void style_change(appdata_t *appdata, const char *name) {
  char *new_style = NULL, *fname = NULL;

  file_chain_t *chain = file_scan(".style");

  while(chain) {
    file_chain_t *next = chain->next;
    style_t *style = style_parse(appdata, chain->name, NULL, TRUE);

    if(new_style == NULL && strcmp(style->name, name) == 0) {
      new_style = style_basename(chain->name);
      fname = chain->name;
      chain->name = NULL;
    }

    style_free(style);

    g_free(chain->name);
    g_free(chain);
    chain = next;
  }

  /* check if style has really been changed */
  if(appdata->settings->style &&
     !strcmp(appdata->settings->style, new_style)) {
    g_free(new_style);
    g_free(fname);
    return;
  }

  style_t *nstyle = style_load_fname(appdata, fname);
  if (nstyle == NULL) {
    errorf(GTK_WIDGET(appdata->window),
           _("Error loading style %s"), fname);
    g_free(new_style);
    g_free(fname);
    return;
  }
  g_free(fname);

  g_free(appdata->settings->style);
  appdata->settings->style = new_style;

  map_clear(appdata, MAP_LAYER_OBJECTS_ONLY);
  /* let gtk clean up first */
  while(gtk_events_pending()) {
    putchar('.');
    gtk_main_iteration();
  }

  style_free(appdata->map->style);
  appdata->map->style = nstyle;

  /* canvas background may have changed */
  canvas_set_background(appdata->map->canvas,
			appdata->map->style->background.color);

  map_paint(appdata);
}
Пример #3
0
static style_t *style_load_fname(appdata_t *appdata, const char *filename) {
  xmlChar *fname = NULL;
  style_t *style = style_parse(appdata, filename, &fname, FALSE);

  printf("  elemstyle filename: %s\n", fname);
  style->elemstyles = josm_elemstyles_load((char*)fname);
  xmlFree(fname);

  return style;
}
Пример #4
0
static void style_init(Fl_Text_Buffer *textbuf, Fl_Text_Buffer *stylebuf) {
	char *style = new char[textbuf->length() + 1];
	char *text = textbuf->text();

	memset(style, 'A', textbuf->length());
	style[textbuf->length()] = '\0';

	if(!stylebuf) stylebuf = new Fl_Text_Buffer(textbuf->length());

	style_parse(text, style, textbuf->length());

	stylebuf->text(style);
	delete[] style;
	free(text);
}
Пример #5
0
void
style_init(void) {
  char *style = new char[textbuf->length() + 1];
  const char *text = textbuf->text();

  memset(style, 'A', textbuf->length());
  style[textbuf->length()] = '\0';

  if (!stylebuf) stylebuf = new fltk::TextBuffer(textbuf->length());

  style_parse(text, style, textbuf->length());

  stylebuf->text(style);
  delete[] style;
}
Пример #6
0
GtkWidget *style_select_widget(appdata_t *appdata) {
  file_chain_t *chain = file_scan(".style");

  /* there must be at least one style, otherwise */
  /* the program wouldn't be running */
  g_assert(chain);

  GtkWidget *cbox = combo_box_new(_("Style"));

  /* fill combo box with presets */
  int cnt = 0, match = -1;
  while(chain) {
    file_chain_t *next = chain->next;

    printf("  file: %s\n", chain->name);

    style_t *style = style_parse(appdata, chain->name, NULL, TRUE);
    printf("    name: %s\n", style->name);
    combo_box_append_text(cbox, style->name);

    char *basename = style_basename(chain->name);
    if(strcmp(basename, appdata->settings->style) == 0) match = cnt;
    g_free(basename);

    style_free(style);

    cnt++;

    g_free(chain->name);
    g_free(chain);
    chain = next;
  }

  if(match >= 0)
    combo_box_set_active(cbox, match);

  return cbox;
}
Пример #7
0
/* Write string, similar to nputs, but with embedded formatting (#[]). */
void
screen_write_cnputs(struct screen_write_ctx *ctx, ssize_t maxlen,
    const struct grid_cell *gcp, const char *fmt, ...)
{
	struct grid_cell	 gc;
	struct utf8_data	*ud = &gc.data;
	va_list			 ap;
	char			*msg;
	u_char 			*ptr, *last;
	size_t			 left, size = 0;
	enum utf8_state		 more;

	memcpy(&gc, gcp, sizeof gc);

	va_start(ap, fmt);
	xvasprintf(&msg, fmt, ap);
	va_end(ap);

	ptr = msg;
	while (*ptr != '\0') {
		if (ptr[0] == '#' && ptr[1] == '[') {
			ptr += 2;
			last = ptr + strcspn(ptr, "]");
			if (*last == '\0') {
				/* No ]. Not much point in doing anything. */
				break;
			}
			*last = '\0';

			style_parse(gcp, &gc, ptr);
			ptr = last + 1;
			continue;
		}

		if (*ptr > 0x7f && utf8_open(ud, *ptr) == UTF8_MORE) {
			ptr++;

			left = strlen(ptr);
			if (left < (size_t)ud->size - 1)
				break;
			while ((more = utf8_append(ud, *ptr)) == UTF8_MORE)
				ptr++;
			ptr++;

			if (more != UTF8_DONE)
				continue;
			if (maxlen > 0 && size + ud->width > (size_t)maxlen) {
				while (size < (size_t)maxlen) {
					screen_write_putc(ctx, &gc, ' ');
					size++;
				}
				break;
			}
			size += ud->width;
			screen_write_cell(ctx, &gc);
		} else {
			if (maxlen > 0 && size + 1 > (size_t)maxlen)
				break;

			if (*ptr > 0x1f && *ptr < 0x7f) {
				size++;
				screen_write_putc(ctx, &gc, *ptr);
			}
			ptr++;
		}
	}

	free(msg);
}
Пример #8
0
enum cmd_retval
cmd_select_pane_exec(struct cmd *self, struct cmd_q *cmdq)
{
	struct args		*args = self->args;
	struct winlink		*wl;
	struct window_pane	*wp;
	const char		*style;

	if (self->entry == &cmd_last_pane_entry || args_has(args, 'l')) {
		wl = cmd_find_window(cmdq, args_get(args, 't'), NULL);
		if (wl == NULL)
			return (CMD_RETURN_ERROR);

		if (wl->window->last == NULL) {
			cmdq_error(cmdq, "no last pane");
			return (CMD_RETURN_ERROR);
		}

		if (args_has(self->args, 'e'))
			wl->window->last->flags &= ~PANE_INPUTOFF;
		else if (args_has(self->args, 'd'))
			wl->window->last->flags |= PANE_INPUTOFF;
		else {
			server_unzoom_window(wl->window);
			window_set_active_pane(wl->window, wl->window->last);
			server_status_window(wl->window);
			server_redraw_window_borders(wl->window);
		}

		return (CMD_RETURN_NORMAL);
	}

	if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), NULL, &wp)) == NULL)
		return (CMD_RETURN_ERROR);

	server_unzoom_window(wp->window);
	if (!window_pane_visible(wp)) {
		cmdq_error(cmdq, "pane not visible");
		return (CMD_RETURN_ERROR);
	}

	if (args_has(self->args, 'P') || args_has(self->args, 'g')) {
		if (args_has(args, 'P')) {
			style = args_get(args, 'P');
			if (style_parse(&grid_default_cell, &wp->colgc,
			    style) == -1) {
				cmdq_error(cmdq, "bad style: %s", style);
				return (CMD_RETURN_ERROR);
			}
			wp->flags |= PANE_REDRAW;
		}
		if (args_has(self->args, 'g'))
			cmdq_print(cmdq, "%s", style_tostring(&wp->colgc));
		return (CMD_RETURN_NORMAL);
	}

	if (args_has(self->args, 'L'))
		wp = window_pane_find_left(wp);
	else if (args_has(self->args, 'R'))
		wp = window_pane_find_right(wp);
	else if (args_has(self->args, 'U'))
		wp = window_pane_find_up(wp);
	else if (args_has(self->args, 'D'))
		wp = window_pane_find_down(wp);
	if (wp == NULL) {
		cmdq_error(cmdq, "pane not found");
		return (CMD_RETURN_ERROR);
	}

	if (args_has(self->args, 'e'))
		wp->flags &= ~PANE_INPUTOFF;
	else if (args_has(self->args, 'd'))
		wp->flags |= PANE_INPUTOFF;
	else if (window_set_active_pane(wl->window, wp)) {
		server_status_window(wl->window);
		server_redraw_window_borders(wl->window);
	}

	return (CMD_RETURN_NORMAL);
}
Пример #9
0
/* Write string, similar to nputs, but with embedded formatting (#[]). */
void printflike5
screen_write_cnputs(struct screen_write_ctx *ctx,
    ssize_t maxlen, struct grid_cell *gc, int utf8flag, const char *fmt, ...)
{
	struct grid_cell	 lgc;
	struct utf8_data	 utf8data;
	va_list			 ap;
	char			*msg;
	u_char 			*ptr, *last;
	size_t			 left, size = 0;

	va_start(ap, fmt);
	xvasprintf(&msg, fmt, ap);
	va_end(ap);

	memcpy(&lgc, gc, sizeof lgc);

	ptr = msg;
	while (*ptr != '\0') {
		if (ptr[0] == '#' && ptr[1] == '[') {
			ptr += 2;
			last = ptr + strcspn(ptr, "]");
			if (*last == '\0') {
				/* No ]. Not much point in doing anything. */
				break;
			}
			*last = '\0';

			style_parse(gc, &lgc, ptr);
			ptr = last + 1;
			continue;
		}

		if (utf8flag && *ptr > 0x7f && utf8_open(&utf8data, *ptr)) {
			ptr++;

			left = strlen(ptr);
			if (left < utf8data.size - 1)
				break;
			while (utf8_append(&utf8data, *ptr))
				ptr++;
			ptr++;

			if (maxlen > 0 &&
			    size + utf8data.width > (size_t) maxlen) {
				while (size < (size_t) maxlen) {
					screen_write_putc(ctx, gc, ' ');
					size++;
				}
				break;
			}
			size += utf8data.width;

			grid_cell_set(&lgc, &utf8data);
			screen_write_cell(ctx, &lgc);
		} else {
			if (maxlen > 0 && size + 1 > (size_t) maxlen)
				break;

			size++;
			screen_write_putc(ctx, &lgc, *ptr);
			ptr++;
		}
	}

	free(msg);
}
Пример #10
0
static enum cmd_retval
cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
{
	struct args		*args = self->args;
	struct winlink		*wl = item->state.tflag.wl;
	struct window		*w = wl->window;
	struct session		*s = item->state.tflag.s;
	struct window_pane	*wp = item->state.tflag.wp, *lastwp, *markedwp;
	const char		*style;

	if (self->entry == &cmd_last_pane_entry || args_has(args, 'l')) {
		if (wl->window->last == NULL) {
			cmdq_error(item, "no last pane");
			return (CMD_RETURN_ERROR);
		}

		if (args_has(self->args, 'e'))
			w->last->flags &= ~PANE_INPUTOFF;
		else if (args_has(self->args, 'd'))
			w->last->flags |= PANE_INPUTOFF;
		else {
			server_unzoom_window(w);
			window_redraw_active_switch(w, w->last);
			if (window_set_active_pane(w, w->last)) {
				server_status_window(w);
				server_redraw_window_borders(w);
			}
		}

		return (CMD_RETURN_NORMAL);
	}

	if (args_has(args, 'm') || args_has(args, 'M')) {
		if (args_has(args, 'm') && !window_pane_visible(wp))
			return (CMD_RETURN_NORMAL);
		lastwp = marked_pane.wp;

		if (args_has(args, 'M') || server_is_marked(s, wl, wp))
			server_clear_marked();
		else
			server_set_marked(s, wl, wp);
		markedwp = marked_pane.wp;

		if (lastwp != NULL) {
			server_redraw_window_borders(lastwp->window);
			server_status_window(lastwp->window);
		}
		if (markedwp != NULL) {
			server_redraw_window_borders(markedwp->window);
			server_status_window(markedwp->window);
		}
		return (CMD_RETURN_NORMAL);
	}

	if (args_has(self->args, 'P') || args_has(self->args, 'g')) {
		if (args_has(args, 'P')) {
			style = args_get(args, 'P');
			if (style_parse(&grid_default_cell, &wp->colgc,
			    style) == -1) {
				cmdq_error(item, "bad style: %s", style);
				return (CMD_RETURN_ERROR);
			}
			wp->flags |= PANE_REDRAW;
		}
		if (args_has(self->args, 'g'))
			cmdq_print(item, "%s", style_tostring(&wp->colgc));
		return (CMD_RETURN_NORMAL);
	}

	if (args_has(self->args, 'L')) {
		server_unzoom_window(wp->window);
		wp = window_pane_find_left(wp);
	} else if (args_has(self->args, 'R')) {
		server_unzoom_window(wp->window);
		wp = window_pane_find_right(wp);
	} else if (args_has(self->args, 'U')) {
		server_unzoom_window(wp->window);
		wp = window_pane_find_up(wp);
	} else if (args_has(self->args, 'D')) {
		server_unzoom_window(wp->window);
		wp = window_pane_find_down(wp);
	}
	if (wp == NULL)
		return (CMD_RETURN_NORMAL);

	if (args_has(self->args, 'e')) {
		wp->flags &= ~PANE_INPUTOFF;
		return (CMD_RETURN_NORMAL);
	}
	if (args_has(self->args, 'd')) {
		wp->flags |= PANE_INPUTOFF;
		return (CMD_RETURN_NORMAL);
	}

	if (wp == w->active)
		return (CMD_RETURN_NORMAL);
	server_unzoom_window(wp->window);
	if (!window_pane_visible(wp)) {
		cmdq_error(item, "pane not visible");
		return (CMD_RETURN_ERROR);
	}
	window_redraw_active_switch(w, wp);
	if (window_set_active_pane(w, wp)) {
		server_status_window(w);
		server_redraw_window_borders(w);
	}

	return (CMD_RETURN_NORMAL);
}
Пример #11
0
static enum cmd_retval
cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
{
	struct args		*args = self->args;
	struct cmd_find_state	*current = &item->shared->current;
	struct client		*c = cmd_find_client(item, NULL, 1);
	struct winlink		*wl = item->target.wl;
	struct window		*w = wl->window;
	struct session		*s = item->target.s;
	struct window_pane	*wp = item->target.wp, *lastwp, *markedwp;
	char			*pane_title;
	const char		*style;

	if (self->entry == &cmd_last_pane_entry || args_has(args, 'l')) {
		lastwp = w->last;
		if (lastwp == NULL) {
			cmdq_error(item, "no last pane");
			return (CMD_RETURN_ERROR);
		}
		if (args_has(self->args, 'e'))
			lastwp->flags &= ~PANE_INPUTOFF;
		else if (args_has(self->args, 'd'))
			lastwp->flags |= PANE_INPUTOFF;
		else {
			server_unzoom_window(w);
			window_redraw_active_switch(w, lastwp);
			if (window_set_active_pane(w, lastwp)) {
				cmd_find_from_winlink(current, wl, 0);
				server_status_window(w);
				server_redraw_window_borders(w);
			}
		}
		return (CMD_RETURN_NORMAL);
	}

	if (args_has(args, 'm') || args_has(args, 'M')) {
		if (args_has(args, 'm') && !window_pane_visible(wp))
			return (CMD_RETURN_NORMAL);
		lastwp = marked_pane.wp;

		if (args_has(args, 'M') || server_is_marked(s, wl, wp))
			server_clear_marked();
		else
			server_set_marked(s, wl, wp);
		markedwp = marked_pane.wp;

		if (lastwp != NULL) {
			server_redraw_window_borders(lastwp->window);
			server_status_window(lastwp->window);
		}
		if (markedwp != NULL) {
			server_redraw_window_borders(markedwp->window);
			server_status_window(markedwp->window);
		}
		return (CMD_RETURN_NORMAL);
	}

	if (args_has(self->args, 'P') || args_has(self->args, 'g')) {
		if (args_has(args, 'P')) {
			style = args_get(args, 'P');
			if (style_parse(&grid_default_cell, &wp->colgc,
			    style) == -1) {
				cmdq_error(item, "bad style: %s", style);
				return (CMD_RETURN_ERROR);
			}
			wp->flags |= PANE_REDRAW;
		}
		if (args_has(self->args, 'g'))
			cmdq_print(item, "%s", style_tostring(&wp->colgc));
		return (CMD_RETURN_NORMAL);
	}

	if (args_has(self->args, 'L')) {
		server_unzoom_window(wp->window);
		wp = window_pane_find_left(wp);
	} else if (args_has(self->args, 'R')) {
		server_unzoom_window(wp->window);
		wp = window_pane_find_right(wp);
	} else if (args_has(self->args, 'U')) {
		server_unzoom_window(wp->window);
		wp = window_pane_find_up(wp);
	} else if (args_has(self->args, 'D')) {
		server_unzoom_window(wp->window);
		wp = window_pane_find_down(wp);
	}
	if (wp == NULL)
		return (CMD_RETURN_NORMAL);

	if (args_has(self->args, 'e')) {
		wp->flags &= ~PANE_INPUTOFF;
		return (CMD_RETURN_NORMAL);
	}
	if (args_has(self->args, 'd')) {
		wp->flags |= PANE_INPUTOFF;
		return (CMD_RETURN_NORMAL);
	}

	if (args_has(self->args, 'T')) {
		pane_title = format_single(item, args_get(self->args, 'T'),
		    c, s, wl, wp);
		screen_set_title(&wp->base, pane_title);
		server_status_window(wp->window);
		free(pane_title);
	}

	if (wp == w->active)
		return (CMD_RETURN_NORMAL);
	server_unzoom_window(wp->window);
	if (!window_pane_visible(wp)) {
		cmdq_error(item, "pane not visible");
		return (CMD_RETURN_ERROR);
	}
	window_redraw_active_switch(w, wp);
	if (window_set_active_pane(w, wp)) {
		cmd_find_from_winlink_pane(current, wl, wp, 0);
		hooks_insert(s->hooks, item, current, "after-select-pane");
		server_status_window(w);
		server_redraw_window_borders(w);
	}

	return (CMD_RETURN_NORMAL);
}
Пример #12
0
static void
style_update(int		pos,			// I - Position of update
			 int		nInserted,		// I - Number of inserted chars
			 int		nDeleted,		// I - Number of deleted chars
			 int		/*nRestyled*/,	// I - Number of restyled chars
			 const char * /*deletedText*/,// I - Text that was deleted
			 void		*cbArg) {		// I - Callback data
  int	start,							// Start of text
		end;							// End of text
  char	last,							// Last style on line
		*style,							// Style data
		*text;							// Text data

  SchemeEditor *editor = (SchemeEditor*)cbArg;
  Fl_Text_Buffer *textbuf = editor->buffer();
  Fl_Text_Buffer *stylebuf = editor->style_buffer();

  // If this is just a selection change, just unselect the style buffer...
  if (nInserted == 0 && nDeleted == 0) {
	stylebuf->unselect();
	return;
  }

  // Track changes in the text buffer...
  if (nInserted > 0) {
	// Insert characters into the style buffer...
	style = new char[nInserted + 1];
	memset(style, 'A', nInserted);
	style[nInserted] = '\0';

	stylebuf->replace(pos, pos + nDeleted, style);
	delete[] style;
  } else {
	// Just delete characters in the style buffer...
	stylebuf->remove(pos, pos + nDeleted);
  }

  // Select the area that was just updated to avoid unnecessary
  // callbacks...
  stylebuf->select(pos, pos + nInserted - nDeleted);

  // Re-parse the changed region; we do this by parsing from the
  // beginning of the previous line of the changed region to the end of
  // the line of the changed region...	Then we check the last
  // style character and keep updating if we have a multi-line
  // comment character...
  start = textbuf->line_start(pos);
//	if (start > 0) start = textbuf->line_start(start - 1);
  end	= textbuf->line_end(pos + nInserted);
  text	= textbuf->text_range(start, end);
  style = stylebuf->text_range(start, end);
  if (start==end)
	last = 0;
  else
	last  = style[end - start - 1];

//	printf("start = %d, end = %d, text = \"%s\", style = \"%s\", last='%c'...\n",
//		   start, end, text, style, last);

  style_parse(text, style, end - start);

//	printf("new style = \"%s\", new last='%c'...\n",
//		   style, style[end - start - 1]);

  stylebuf->replace(start, end, style);
  editor->redisplay_range(start, end);

  if (start==end || last != style[end - start - 1]) {
//	  printf("Recalculate the rest of the buffer style\n");
	// Either the user deleted some text, or the last character
	// on the line changed styles, so reparse the
	// remainder of the buffer...
	free(text);
	free(style);

	end	  = textbuf->length();
	text  = textbuf->text_range(start, end);
	style = stylebuf->text_range(start, end);

	style_parse(text, style, end - start);

	stylebuf->replace(start, end, style);
	editor->redisplay_range(start, end);
  }

  free(text);
  free(style);
}