Esempio n. 1
0
void error_dlg(Error& e, const UnicodeString& message) {
  UnicodeString msg;
  msg.add(far_get_msg(MSG_PLUGIN_NAME)).add('\n');
  if (message.size() != 0) msg.add(word_wrap(message, get_msg_width())).add('\n');
  UnicodeString err_msg = word_wrap(e.message(), get_msg_width());
  if (err_msg.size() != 0) msg.add(err_msg).add('\n');
  msg.add_fmt(L"%S:%u v.%u.%u.%u.%u"PLUGIN_TYPE, &extract_file_name(oem_to_unicode(e.file)), e.line, g_version.major, g_version.minor, g_version.patch, g_version.revision);
  far_message(c_error_dialog_guid, msg, 0, FMSG_WARNING | FMSG_MB_OK);
}
Esempio n. 2
0
void error_dlg(const wstring& title, const Error& e) {
  wostringstream st;
  st << title << L'\n';
  if (e.code != E_MESSAGE) {
    wstring sys_msg = get_system_message(e.code, get_lang_id());
    if (!sys_msg.empty())
      st << word_wrap(sys_msg, get_optimal_msg_width()) << L'\n';
  }
  for (list<wstring>::const_iterator msg = e.messages.begin(); msg != e.messages.end(); msg++) {
    st << word_wrap(*msg, get_optimal_msg_width()) << L'\n';
  }
  st << extract_file_name(widen(e.file)) << L':' << e.line;
  message(c_error_dialog_guid, st.str(), 0, FMSG_WARNING | FMSG_MB_OK);
}
Esempio n. 3
0
void main(void)
{
      char *string =
            "This is a long line\nto be wrapped by the w_wrap function. "
            "Hopefully, things will work correctly and it will be wrapped "
            "between words.  On the other hand, maybe I should hope that it "
            "doesn't work well so I will have an opportunity\nto learn more "
            "about what I'm doing";

	printf("Here's a string wrapped to 40 columns:\n\n%s\n\n",
		word_wrap(string, 40));
	printf("And here it's wrapped to 72:\n\n%s\n\n",
		word_wrap(string,72));
}
Esempio n. 4
0
void error_dlg(const std::exception& e) {
  UnicodeString msg;
  msg.add(far_get_msg(MSG_PLUGIN_NAME)).add('\n');
  UnicodeString err_msg = word_wrap(oem_to_unicode(e.what()), get_msg_width());
  if (err_msg.size() != 0) msg.add(err_msg).add('\n');
  msg.add_fmt(L"v.%u.%u.%u.%u"PLUGIN_TYPE, g_version.major, g_version.minor, g_version.patch, g_version.revision);
  far_message(c_error_dialog_guid, msg, 0, FMSG_WARNING | FMSG_MB_OK);
}
Esempio n. 5
0
File: draw.c Progetto: sirpengi/rirc
int
print_line(int row, line *l)
{
	if (l < ccur->chat)
		l += SCROLLBACK_BUFFER;

	if (!l->len || l == ccur->cur_line)
		return 3;

	int count = 1;
	char *ptr1, *ptr2, *wrap;

	ptr1 = l->text;
	ptr2 = l->text + l->len;

	while ((ptr1 = word_wrap(ptr1, ptr2)) != NULL && ptr1 != ptr2)
		count++;

	if (row - count > 2)
		row = print_line(row - count, l - 1) + count - 1;

	ptr1 = l->text;
	if ((wrap = word_wrap(ptr1, ptr2)) != NULL)
		row = print_more(wrap, ptr2, row);
	else
		wrap = ptr2;

	int from_fg;
	char *from_bg = "";

	if (l->type == LINE_JOIN || l->type == LINE_PART || l->type == LINE_QUIT)
		from_fg = 239;
	else if (l->type == LINE_PINGED)
		from_fg = 255, from_bg = BG(1);
	else
		from_fg = nick_col(l->from);

	if (row > 2) {
		printf("\x1b[%d;1H\x1b[2K", row);
		printf(FG(239)" %02d:%02d  %*s"FG(%d)"%s%s"BG_R FG(239)" ~ "FG(250),
				l->time_h, l->time_m,
				(int)(ccur->nick_pad - strlen(l->from)), "",
				from_fg, from_bg, l->from);
		while (ptr1 < wrap)
			putchar(*ptr1++);
	}
Esempio n. 6
0
void printline(struct session *ses, char **str, int prompt)
{
	char *out;

	push_call("printline(%p,%p,%d)",ses,*str,prompt);

	if (ses->scroll_line != -1 && HAS_BIT(ses->flags, SES_FLAG_SCROLLLOCK))
	{
		pop_call();
		return;
	}

	if (HAS_BIT(ses->flags, SES_FLAG_SCAN) && !HAS_BIT(ses->flags, SES_FLAG_VERBOSE))
	{
		pop_call();
		return;
	}

	out = str_alloc(strlen(*str) * 2);

	if (HAS_BIT(ses->flags, SES_FLAG_CONVERTMETA))
	{
		convert_meta(*str, out);
		str_cpy(str, out);
	}

	if (HAS_BIT(ses->flags, SES_FLAG_WORDWRAP))
	{
		word_wrap(ses, *str, out, TRUE);
	}
	else
	{
		strcpy(out, *str);
	}

	if (prompt)
	{
		printf("%s", out);
	}
	else
	{
		printf("%s\n", out);
	}

	str_free(out);

	pop_call();
	return;
}
Esempio n. 7
0
void HelpIndented(const char *text, const unsigned int indent, const unsigned int wrap)
{
	char wrapped_text[strlen(text)+1];
	strcpy(wrapped_text,text);

	word_wrap(wrapped_text,wrap-indent);

	for( unsigned int i = 0; i < indent; i++)
		std::cerr << " ";

	for(unsigned int i=0; i < strlen(wrapped_text); i++)
	{
		std::cerr << wrapped_text[i];
		if ( wrapped_text[i] == '\n')
		{
			for( unsigned int ii = 0; ii < indent; ii++)
				std::cerr << " ";
		}
	}
	std::cerr << "\n";
}
Esempio n. 8
0
void center(FILE *file, char *string, size_t width)
{
      char *line,*end_line;
      size_t spaces;
      int last = 0;
      size_t len;

      word_wrap(string,width);
      line = string;
      while (!last)
      {
            end_line = strchr(line,'\n');
            if (NULL==end_line)
            {
                  last = 1;
                  end_line = strchr(line,'\0');
            }
            len = end_line - line;
            spaces = (width - len) / 2 ;
            fprintf(file,"\n%*c%*.*s",spaces,' ',len,len,line);
            line = end_line + 1;
      }
}
Esempio n. 9
0
int show_buffer(struct session *ses) {
  char temp[STRING_SIZE];
  int scroll_size, scroll_cnt, scroll_tmp, scroll_add, scroll_cut;

  if (ses != gtd->ses) {
    return TRUE;
  }

  scroll_size = get_scroll_size(ses);
  scroll_add = 0 - ses->scroll_base;
  scroll_tmp = 0;
  scroll_cnt = ses->scroll_line;
  scroll_cut = 0;
  /*
     Find the upper limit of the buffer shown
   */

  while (TRUE) {
    if (ses->buffer[scroll_cnt] == NULL) {
      break;
    }

    scroll_tmp = str_hash_lines(ses->buffer[scroll_cnt]);

    if (scroll_add + scroll_tmp > scroll_size) {
      if (scroll_add == scroll_size) {
        scroll_cut = 0;
      } else {
        scroll_cut = scroll_tmp - (scroll_size - scroll_add);
      }
      break;
    }

    scroll_add += scroll_tmp;

    if (scroll_cnt == ses->scroll_max - 1) {
      scroll_cnt = 0;
    } else {
      scroll_cnt++;
    }
  }

  if (ses->buffer[scroll_cnt] == NULL) {
    erase_screen(ses);
  }

  if (IS_SPLIT(ses)) {
    save_pos(ses);
    goto_rowcol(ses, ses->bot_row, 1);
    SET_BIT(ses->flags, SES_FLAG_READMUD);
  }

  /*
     If the top line exists of multiple lines split it in the middle.
   */

  if (ses->buffer[scroll_cnt] && scroll_cut) {
    if (scroll_add >= 0) {
      word_wrap_split(ses, ses->buffer[scroll_cnt], temp, scroll_tmp - scroll_cut, scroll_cut);

      printf("%s\n", temp);
    } else {
      word_wrap_split(ses, ses->buffer[scroll_cnt], temp, ses->scroll_base, scroll_size);

      goto eof;
    }
  }

  /*
     Print away
   */

  while (TRUE) {
    if (scroll_cnt == 0) {
      scroll_cnt = ses->scroll_max - 1;
    } else {
      scroll_cnt--;
    }

    if (ses->buffer[scroll_cnt] == NULL) {
      break;
    }

    scroll_tmp = word_wrap(ses, ses->buffer[scroll_cnt], temp, FALSE);

    if (scroll_add - scroll_tmp < 0) {
      scroll_cut = scroll_add;
      break;
    }

    scroll_add -= scroll_tmp;

    printf("%s\n", temp);
  }

  /*
     If the bottom line exists of multiple lines split it in the middle
   */

  if (scroll_tmp && ses->buffer[scroll_cnt]) {
    word_wrap_split(ses, ses->buffer[scroll_cnt], temp, 0, scroll_cut);
  }

 eof:

  if (IS_SPLIT(ses)) {
    restore_pos(ses);
    DEL_BIT(ses->flags, SES_FLAG_READMUD);
  }
  return TRUE;
}
Esempio n. 10
0
void add_line_buffer(struct session *ses, char *line, int more_output) {
  char linebuf[STRING_SIZE];
  char *pti, *pto;
  int lines;
  int sav_row, sav_col, cur_row, cur_col, top_row, bot_row;

  push_call("add_line_buffer(%p,%s,%d)", ses, line, more_output);

  if (ses->buffer == NULL || HAS_BIT(ses->flags, SES_FLAG_SCROLLSTOP)) {
    pop_call();
    return;
  }

  sav_row = ses->sav_row;
  sav_col = ses->sav_col;
  cur_row = ses->cur_row;
  cur_col = ses->cur_col;
  top_row = ses->top_row;
  bot_row = ses->bot_row;

  if (more_output == TRUE) {
    if (strlen(ses->more_output) < BUFFER_SIZE / 2) {
      strcat(ses->more_output, line);

      pop_call();
      return;
    }
  }

  strcat(ses->more_output, line);

  pti = pto = ses->more_output;

  while (*pti != 0) {
    while (skip_vt102_codes_non_graph(pti)) {
      interpret_vt102_codes(ses, pti, FALSE);

      pti += skip_vt102_codes_non_graph(pti);
    }

    if (*pti == 0) {
      break;
    }

    if (SCROLL(ses)) {
      *pto++ = *pti++;
    } else {
      pti++;
    }
  }
  *pto = 0;

  lines = word_wrap(ses, ses->more_output, linebuf, FALSE);

  ses->more_output[0] = 0;

  ses->buffer[ses->scroll_row] = str_hash(linebuf, lines);

  if (more_output == -1) {
    str_hash_grep(ses->buffer[ses->scroll_row], TRUE);
  }

  if (!HAS_BIT(ses->flags, SES_FLAG_LOGLEVEL)) {
    if (ses->logfile) {
      logit(ses, linebuf, ses->logfile, TRUE);
    }
  }

  if (gtd->chat) {
    chat_forward_session(ses, linebuf);
  }

  if (--ses->scroll_row < 0) {
    ses->scroll_row = ses->scroll_max - 1;
  }

  if (ses->buffer[ses->scroll_row]) {
    ses->buffer[ses->scroll_row] = str_unhash(ses->buffer[ses->scroll_row]);
  }

  ses->sav_row = sav_row;
  ses->sav_col = sav_col;
  ses->cur_row = cur_row;
  ses->cur_col = cur_col;
  ses->top_row = top_row;
  ses->bot_row = bot_row;

  pop_call();
  return;
}
Esempio n. 11
0
/**
 * help_for_event - output event name and description
 * @param i  event number
 *
 * output an help string for the event @i
 */
static void help_for_event(struct op_event * event)
{
	int column;
	uint i, j;
	uint mask;
	size_t nr_counters;
	char buf[32];

	do_arch_specific_event_help(event);
	nr_counters = op_get_nr_counters(cpu_type);

	/* Sanity check */
	if (!event)
		return;

	printf("%s", event->name);

	if(event->counter_mask != 0) {
		printf(": (counter: ");

		mask = event->counter_mask;
		if (hweight(mask) == nr_counters) {
			printf("all");
		} else {
			for (i = 0; i < CHAR_BIT * sizeof(event->counter_mask); ++i) {
				if (mask & (1 << i)) {
					printf("%d", i);
					mask &= ~(1 << i);
					if (mask)
						printf(", ");
				}
			}
		}
	} else	if (event->ext != NULL) {
		/* Handling extended feature interface */
		printf(": (ext: %s", event->ext);
	} else {
		/* Handling arch_perfmon case */
		printf(": (counter: all");
	}   

	printf(")\n\t");
	column = 8;
	word_wrap(8, &column, event->desc);
	snprintf(buf, sizeof buf, " (min count: %d)", event->min_count);
	word_wrap(8, &column, buf);
	putchar('\n');

	if (strcmp(event->unit->name, "zero")) {

		if (event->unit->default_mask_name) {
			printf("\tUnit masks (default %s)\n",
			       event->unit->default_mask_name);
		} else {
			printf("\tUnit masks (default 0x%x)\n",
			       event->unit->default_mask);
		}
		printf("\t----------\n");

		for (j = 0; j < event->unit->num; j++) {
			printf("\t0x%.2x: ",
			       event->unit->um[j].value);
			column = 14;

			/* Named mask */
			if (event->unit->um[j].name) {
				word_wrap(14, &column, "(name=");
				word_wrap(14, &column,
					event->unit->um[j].name);
				word_wrap(14, &column, ") ");
			}

			word_wrap(14, &column, event->unit->um[j].desc);
			putchar('\n');
		}
	}
}
Esempio n. 12
0
/* TODO:
 *
 * Colorize line types
 *
 * Functional first draft, could use some cleaning up */
static void
draw_buffer(channel *c)
{
	/* Dynamically draw the current channel's buffer such that:
	 *
	 * - The scrollback line should always be drawn in full when possible
	 * - Lines wrap on whitespace when possible
	 * - The top-most lines draws partially when required
	 * - Buffers requiring fewer rows than available draw from the top down
	 *
	 * Rows are numbered from the top down, 1 to w.ws_row, so for w.ws_row = N,
	 * the drawable area for the buffer is bounded [r3, rN-2]:
	 *      __________________________
	 * r1   |     (channel bar)      |
	 * r2   |------------------------|
	 * r3   |    ::buffer start::    |
	 *      |                        |
	 * ...  |                        |
	 *      |                        |
	 * rN-2 |     ::buffer end::     |
	 * rN-1 |------------------------|
	 * rN   |______(input bar) ______|
	 *
	 *
	 * So the general steps for drawing are:
	 *
	 * 1. Starting from line L = scrollback, traverse backwards through the
	 *    buffer summing the rows required to draw lines, until the sum
	 *    exceeds the number of rows available
	 *
	 * 2. L now points to the top-most line to be drawn. L might not be able
	 *    to draw in full, so discard the excessive word-wrapped segments and
	 *    draw the remainder
	 *
	 * 3. Traverse forward through the buffer, drawing lines until buffer_head
	 *    is encountered
	 *
	 * 4. Clear any remaining rows that might exist in the case where the lines
	 *    in the channel's buffer are insufficient to fill all rows
	 */

	printf(CURSOR_SAVE);

	/* Establish current, min and max row for drawing */
	int buffer_start = 3, buffer_end = w.ws_row - 2;
	int print_row = buffer_start;
	int max_row = buffer_end - buffer_start + 1;
	int count_row = 0;

	/* Insufficient rows for drawing */
	if (buffer_end < buffer_start)
		return;

	/* (#terminal columns) - strlen((widest nick in c)) - strlen(" HH:MM   ~ ") */
	int text_cols = w.ws_col - c->draw.nick_pad - 11;

	/* Insufficient columns for drawing */
	if (text_cols < 1)
		goto clear_remainder;

	line *tmp, *l = c->draw.scrollback;


	/* Empty buffer */
	if (l->text == NULL)
		goto clear_remainder;

	/* If the window has been resized, force all cached line rows to be recalculated */
	if (c->resized) {
		for (tmp = c->buffer; tmp < &c->buffer[SCROLLBACK_BUFFER]; tmp++)
			tmp->rows = 0;

		c->resized = 0;
	}

	/* 1. Find top-most drawable line */
	for (;;) {

		/* Store the number of rows until a resize */
		if (l->rows == 0)
			l->rows = count_line_rows(text_cols, l);

		count_row += l->rows;

		if (count_row >= max_row)
			break;

		tmp = (l == c->buffer) ? &c->buffer[SCROLLBACK_BUFFER - 1] : l - 1;

		if (tmp->text == NULL || tmp == c->buffer_head)
			break;

		l = tmp;
	}

	/* 2. Handle top-most line if it can't draw in full */
	if (count_row > max_row) {
		char *ptr1 = l->text;
		char *ptr2 = l->text + l->len;

		while (count_row-- > max_row)
			word_wrap(text_cols, &ptr1, ptr2);

		do {
			printf(MOVE(%d, %d) CLEAR_LINE, print_row++, (int)c->draw.nick_pad + 10);
			printf(FG(239) "~" FG(250) " ");

			char *print = ptr1;
			char *wrap = word_wrap(text_cols, &ptr1, ptr2);

			while (print < wrap)
				putchar(*print++);
		} while (*ptr1);


		if (l == c->buffer_head)
			goto clear_remainder;

		l = (l == &c->buffer[SCROLLBACK_BUFFER - 1]) ? c->buffer : l + 1;

		if (l->text == NULL)
			goto clear_remainder;
	}
Esempio n. 13
0
void draw_event() {
    draw_background();
    draw_time();
    gfx_draw_filled_rect(5, 26, 310, 182, GFX_COLOR(8, 8, 8));
    draw_button_hints();

    switch(event_track) {
        case 0:
            gfx_draw_string_aligned("Schedule - KEYNOTES",    11, 2, &sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_YELLOW, TEXT_POS_LEFT, TEXT_ALIGN_LEFT);
            break;
        case 1:
            gfx_draw_string_aligned("Schedule - TRACK 1",    11, 2, &sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_YELLOW, TEXT_POS_LEFT, TEXT_ALIGN_LEFT);
            break;
        case 2:
            gfx_draw_string_aligned("Schedule - TRACK 2",    11, 2, &sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_YELLOW, TEXT_POS_LEFT, TEXT_ALIGN_LEFT);
            break;
        case 3:
            gfx_draw_string_aligned("Schedule - TRACK 3",    11, 2, &sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_YELLOW, TEXT_POS_LEFT, TEXT_ALIGN_LEFT);
            break;
        case 4:
            gfx_draw_string_aligned("Schedule - TRACK 4",    11, 2, &sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_YELLOW, TEXT_POS_LEFT, TEXT_ALIGN_LEFT);
            break;
        case 5:
            gfx_draw_string_aligned("Schedule - TRACK 5",    11, 2, &sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_YELLOW, TEXT_POS_LEFT, TEXT_ALIGN_LEFT);
            break;
    }
    
    uint16_t keynote = 0x0100;
    uint16_t track1 = 0x0200;
    uint16_t track2 = 0x0300;
    uint16_t track3 = 0x0400;
    uint16_t track4 = 0x0500;
    uint16_t track5 = 0x0600;

    uint16_t addresses[] = {keynote, track1, track2, track3, track4, track5};
    //uint16_t max_event[] = {5, 22, 22, 15, 23};

    uint8_t ram_buf[AT45DBX_SECTOR_SIZE];
    at45dbx_read_sector_open(addresses[event_track] + event_index);
    at45dbx_read_sector_to_ram(ram_buf);
    at45dbx_read_close();

    char *array[6];
    uint8_t i = 0;
    array[i] = strtok(ram_buf,";");
    while(array[i] != NULL) {
        array[++i] = strtok(NULL, ";");
    }

    char *title[256];
    uint8_t a = word_wrap(&title, array[0], 30);

    gfx_draw_string_aligned(title, 11, 27, &sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_WHITE, TEXT_POS_LEFT, TEXT_ALIGN_LEFT);

    char event_time[36];
    snprintf(event_time, sizeof(event_time),"%s - %s", array[1], array[2]);
        
    char *names[256];
    uint8_t n = word_wrap(&names, array[3], 33);

        gfx_draw_string_aligned(names, 11, 60+(a*20), &small_sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_RED, TEXT_POS_LEFT, TEXT_ALIGN_LEFT);

        gfx_draw_string_aligned(array[4], 11, 85+(a*20)+(n*20), &tiny_sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_YELLOW, TEXT_POS_LEFT, TEXT_ALIGN_LEFT);
        gfx_draw_string_aligned(event_time, 11, 100+(a*20)+(n*20), &tiny_sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_WHITE, TEXT_POS_LEFT, TEXT_ALIGN_LEFT);
        
        
    // }
}
Esempio n. 14
0
/**
 * @brief Function <b>word_wrap</b> reformats a string into multiple lines, none longer
 * that <b>line_length</b> and each line prefixed with <b>prefix</b>.
 *
 * @param s			a <b>std::string</b> const reference to the string
 *				to word wrap.
 *
 * @param line_length		an <b>unsigned int</b> value of the line length.
 *
 * @param prefix		a <b>std::string</b> const reference to a line
 *				prefix string.
 *
 * @return			a <b>std::string</b> value of the word wrapped string.
 */
inline std::string word_wrap(const std::string &s, unsigned int line_length = 72, const std::string &prefix = "") {
  return word_wrap(s, line_length, prefix, prefix);
}
void api_generator::generate_interface_file(const fc::path& api_description_output_dir, const std::string& generated_filename_suffix)
{
  fc::path api_description_header_path = api_description_output_dir / "include" / "bts" / "api";
  fc::create_directories(api_description_header_path);
  fc::path api_header_filename = api_description_header_path / (_api_classname + ".hpp");

  std::ofstream interface_file(api_header_filename.string() + generated_filename_suffix);
  write_generated_file_header(interface_file);

  interface_file << "#pragma once\n\n";
  write_includes_to_stream(interface_file);
  interface_file << "namespace bts { namespace api {\n\n";

  interface_file << "  class " << _api_classname << "\n";
  interface_file << "  {\n";
  interface_file << "  public:\n";

  for (const method_description& method : _methods)
  {
    interface_file << "    /**\n";
    if (!method.brief_description.empty())
    {
      std::ostringstream brief_description_doc_string;
      brief_description_doc_string << method.brief_description;
      if (method.brief_description.back() != '.')
        brief_description_doc_string << '.';
      interface_file << word_wrap(brief_description_doc_string.str(), "     * ") << "\n";
    }

    if (!method.detailed_description.empty())
    {
      std::istringstream detailed_description_stream(method.detailed_description);
      std::string line;
      while (std::getline(detailed_description_stream, line))
      {
        interface_file << "     *\n";
        interface_file << word_wrap(line, "     * ") << "\n";
      }
    }

    if (!method.parameters.empty())
      interface_file << "     *\n";
    for (const parameter_description& parameter : method.parameters)
    {
      std::ostringstream parameter_doc_string_rest;
      std::ostringstream parameter_doc_string_start;

      parameter_doc_string_start << "@param "  << parameter.name << " ";
      parameter_doc_string_rest << parameter.description << " (";
      if (parameter.default_value)
        parameter_doc_string_rest << parameter.type->get_type_name() << ", optional, defaults to " << fc::json::to_string(parameter.default_value);
      else
        parameter_doc_string_rest << parameter.type->get_type_name() << ", required";
      parameter_doc_string_rest << ")";
      interface_file << word_wrap(parameter_doc_string_rest.str(), "     * ", parameter_doc_string_start.str()) << "\n";      
    }
    if (!std::dynamic_pointer_cast<void_type_mapping>(method.return_type))
    {
      interface_file << "     *\n";
      std::ostringstream returns_doc_string;
      returns_doc_string << "@return " << method.return_type->get_type_name();
      interface_file << word_wrap(returns_doc_string.str(), "     * ") << "\n";      
    }

    interface_file << "     */\n";
    interface_file << "    virtual " << generate_signature_for_method(method, "", true) << " = 0;\n";
  }
  interface_file << "  };\n\n";
  interface_file << "} } // end namespace bts::api\n";
}
Esempio n. 16
0
bool loop(int argc, char** argv) {

	char home[256]; //NEED TO MAKE THIS DYNAMIC
	strcpy(home, getenv("HOME"));

	//parse the config file
	settings.parse_config(strcat(home, config_file));
	//load the controls into list
	ElementList list(settings.card);
	list_ptr = &list;
	//reorder the controls to the order specified in the config file
	settings.reorder_list(&list);

	//set the scale
	list.set_scale((Element::scale_t)settings.scaling);
	//set the auto_mute
	list.set_auto_mute(settings.auto_mute);
	
	//initialize gtk
	gtk_init(&argc, &argv);

	//set up the tray_slider that goes in the tray
	if (settings.enable_tray_icon){
		GtkWidget *tray_frame;
		tray_frame = gtk_alignment_new(0.5,0.0,0,0);
		settings.tray_slider = new retro_slider;
		settings.set_tray_slider(&list);
		settings.apply_to_tray_slider(settings.tray_slider);
		if (list.num_elems > 0){
			settings.tray_slider->init(tray_frame, (void*)settings.tray_control, &Element::get_callback, &Element::set_callback, (settings.tray_control->values > 1));
		} else {
			settings.tray_control = NULL;
		}

		//set up the small window that holds the tray_slider
		settings.slider_window = gtk_window_new (GTK_WINDOW_POPUP);
		gtk_window_set_resizable(GTK_WINDOW(settings.slider_window), false);
		gtk_window_set_decorated(GTK_WINDOW(settings.slider_window), false);
		gtk_window_set_skip_taskbar_hint(GTK_WINDOW(settings.slider_window), true);
		gtk_window_set_skip_pager_hint(GTK_WINDOW(settings.slider_window), true);
		gtk_widget_set_usize(settings.slider_window, settings.tray_slider->width, settings.tray_slider->height);
		//don't want accidental closure of the slider window to destroy the window
		g_signal_connect(settings.slider_window, "delete-event", G_CALLBACK (gtk_widget_hide_on_delete), NULL);
		//want the widow to go away when it loses focus
		g_signal_connect(settings.slider_window, "focus-out-event", G_CALLBACK (gtk_widget_hide), NULL);
		gtk_container_add( GTK_CONTAINER(settings.slider_window), tray_frame );
		//we want it hidden by default, but it must be shown at least once or else scrolling over the icon will cause a hang
		gtk_widget_show_all(settings.slider_window);
		gtk_widget_hide_all(settings.slider_window);
		
			
		//set up tray icon
#if GTK_CHECK_VERSION(2,16,0)
		settings.tray_icon = gtk_status_icon_new();
		gtk_status_icon_set_from_file(settings.tray_icon, VOL_MUTED_IMAGE);
#else
		settings.tray_icon = GTK_WIDGET(egg_tray_icon_new("Retrovol Tray Icon"));
		//set the background color
		bool enable_tray_icon_background_color = settings.enable_tray_icon_background_color; 
		GdkColor bg_color;
		char bg_color_str[8];
		if (cmdline_enable_bg_color){
			enable_tray_icon_background_color = true;
			strcpy(bg_color_str, cmdline_bg_color);
		} else if (settings.enable_tray_icon_background_color){
			settings.nftoh(settings.tray_icon_background_color, bg_color_str);
		}
		if (enable_tray_icon_background_color){
			if (gdk_color_parse(bg_color_str, &bg_color)){
				GtkStyle *style = gtk_style_copy(gtk_widget_get_style(settings.tray_icon));
				style->bg[GTK_STATE_NORMAL] = bg_color;
				gtk_widget_set_style(settings.tray_icon, style);
			} else {
				fprintf(stderr, _("Error:  Failed to set background color to %s\n"), bg_color_str);
			}
		}
		//set up the images
		settings.tray_icon_image = gtk_image_new();
		gtk_container_add( GTK_CONTAINER(settings.tray_icon), settings.tray_icon_image );
		gtk_image_set_from_file(GTK_IMAGE(settings.tray_icon_image), VOL_MEDIUM_IMAGE);
		//set the event mask
		gtk_widget_set_events (settings.tray_icon, GDK_BUTTON_PRESS_MASK | GDK_SCROLL_MASK);
#endif

		//signals
		g_signal_connect(G_OBJECT(settings.tray_icon), "button_press_event", G_CALLBACK (&tray_button_press_event_callback), settings.slider_window);
		if (settings.tray_control){
			g_signal_connect(G_OBJECT(settings.tray_icon), "scroll_event", G_CALLBACK (&retro_slider::scroll_event_callback), settings.tray_slider);
		}

#if GTK_CHECK_VERSION(2,16,0)
		//make icon visible
		gtk_status_icon_set_visible(settings.tray_icon, true);
#else
		//handle situations where the icon's window dies, such as due to the tray itself exiting
		g_signal_connect(G_OBJECT(settings.tray_icon), "delete-event", G_CALLBACK (gtk_widget_hide_on_delete), NULL);

		//make icon visible
		gtk_widget_show_all(settings.tray_icon);
#endif

		//set up the popup menu (the function checks if it should actually do anything)
		set_menu();

	}
	


	//set up the window
	settings.main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	//gtk_window_set_position(GTK_WINDOW(settings.main_window), GTK_WIN_POS_CENTER);
	gtk_window_set_default_size(GTK_WINDOW(settings.main_window), settings.window_width, settings.window_height);
	gtk_window_set_title(GTK_WINDOW(settings.main_window), "Retrovol");
	restore_posdim();
	g_signal_connect(settings.main_window, "configure-event", G_CALLBACK (save_posdim), NULL);
	
	//if the tray icon is enabled, we want the window to hide rather than closing
	if (settings.enable_tray_icon){
		g_signal_connect(settings.main_window, "delete-event", G_CALLBACK (gtk_widget_hide_on_delete), NULL);
	}

	//make the over_box, which will hold stuff like the menu, status bar, and the actual content in the middle
	GtkWidget *over_box;
	over_box = gtk_vbox_new(FALSE, 0);
	gtk_container_add(GTK_CONTAINER(settings.main_window), over_box);

	//define the menu
	GtkItemFactoryEntry menu_items_1[] = {
		{ (gchar*)_("/_File"),           NULL,              NULL,                      0, (gchar*)"<Branch>" },
		{ (gchar*)_("/File/_Configure"), (gchar*)"<CTRL>C", G_CALLBACK(configure),     0, (gchar*)"<StockItem>", GTK_STOCK_EXECUTE },
		{ (gchar*)_("/File/_Quit"),      (gchar*)"<CTRL>Q", G_CALLBACK(close_window),  0, (gchar*)"<StockItem>", GTK_STOCK_QUIT },
	};
	gint nmenu_items_1 = sizeof (menu_items_1) / sizeof (menu_items_1[0]);
	
	GtkItemFactoryEntry menu_items_2[] = {
		{ (gchar*)_("/_File"),           NULL,              NULL,                      0, (gchar*)"<Branch>" },
		{ (gchar*)_("/File/_Configure"), (gchar*)"<CTRL>C", G_CALLBACK(configure),     0, (gchar*)"<StockItem>", GTK_STOCK_EXECUTE },
		{ (gchar*)_("/File/_Exit completely"),      (gchar*)"<CTRL>E", G_CALLBACK(gtk_main_quit),  0, (gchar*)"<StockItem>", GTK_STOCK_QUIT },
		{ (gchar*)_("/File/_Quit"),      (gchar*)"<CTRL>Q", G_CALLBACK(close_window),  0, (gchar*)"<StockItem>", GTK_STOCK_QUIT },
	};
	gint nmenu_items_2 = sizeof (menu_items_2) / sizeof (menu_items_2[0]);

	GtkItemFactoryEntry *menu_items;
	gint nmenu_items;
	//if the tray menu is enabled, don't have the "Exit" entry in the main menu
	if (settings.enable_tray_menu){
		menu_items = menu_items_1;
		nmenu_items = nmenu_items_1;
	} else {
		menu_items = menu_items_2;
		nmenu_items = nmenu_items_2;
	}

	//build the menu
	GtkWidget *menubar;
	menubar = get_menubar_menu(settings.main_window, menu_items, nmenu_items, "<RetrovolMain>");
	gtk_box_pack_start(GTK_BOX(over_box), menubar, FALSE, TRUE, 0);


	//use a scrolled window
	GtkWidget *scrolled_window;
	scrolled_window = gtk_scrolled_window_new(NULL, NULL);
	gtk_scrolled_window_set_policy((GtkScrolledWindow*)scrolled_window, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
	gtk_container_add(GTK_CONTAINER(over_box), scrolled_window);
	
	//put the stuff into a viewport manually, so we can specify that it should have no shadow
	GtkWidget *viewport;
	viewport = gtk_viewport_new(NULL, NULL);
	gtk_viewport_set_shadow_type(GTK_VIEWPORT(viewport), GTK_SHADOW_NONE);
	gtk_container_add(GTK_CONTAINER(scrolled_window), viewport);
	
			
	//and create an Hbox to hold all the stuff
	GtkWidget *hbox;
	if (settings.vertical){
		hbox = gtk_hbox_new(TRUE, 2);
		gtk_container_add(GTK_CONTAINER(viewport), hbox);
	} else {
		hbox = gtk_vbox_new(TRUE, 2);
		gtk_container_add(GTK_CONTAINER(viewport), hbox);
	}
			
	//add the sliders
	retro_slider *sliders = new retro_slider[list.num_items];
	
	for(int i=0; i<list.num_items; i++){
		//use a vbox w/ slider on top and label on bottom
		GtkWidget *vbox;
		if (settings.vertical){
			vbox = gtk_vbox_new(FALSE, 2);
		} else {
			vbox = gtk_hbox_new(FALSE, 2);
		}
		gtk_box_pack_start(GTK_BOX(hbox), vbox, false, false, 0);
		
		if (strcmp(list.items[i]->type, "INTEGER") == 0){
			//integers need sliders
			//the rslider pseudo-widget likes to be inside a container, lets use a GtkAlignment
			GtkWidget *frame;
			if (settings.vertical){
				frame = gtk_alignment_new(0.5,0.0,0,0);
				gtk_box_pack_start(GTK_BOX(vbox), frame, false, false, 0);
			} else {
				frame = gtk_alignment_new(0.0,0.5,0,0);
				gtk_box_pack_end(GTK_BOX(vbox), frame, false, false, 0);
			}
			//make the slider and associate with a control
			settings.apply_to_slider(&sliders[i]);
			sliders[i].init(frame, (void*)list.items[i], &Element::get_callback, &Element::set_callback, (list.items[i]->values > 1));
		
		} else if (strcmp(list.items[i]->type, "BOOLEAN") == 0){
			//booleans need checkboxes
			GtkWidget *alignment;
			if (settings.vertical){
				alignment = gtk_alignment_new(0.5,1.0,0,0);
				gtk_box_pack_start(GTK_BOX(vbox), alignment, true, true, 0);
			} else {
				alignment = gtk_alignment_new(1.0,0.5,0,0);
				gtk_box_pack_end(GTK_BOX(vbox), alignment, true, true, 0);
			}
			GtkWidget *chkbx;
			chkbx = gtk_check_button_new();
			//set it to the current state
			gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chkbx), (bool)list.items[i]->get());
			//bind to the toggle_checkbox function
			Element* ptr = list.items[i];
			g_signal_connect(GTK_TOGGLE_BUTTON(chkbx), "toggled", G_CALLBACK (toggle_checkbox), ptr);
			g_signal_connect_after(GTK_TOGGLE_BUTTON(chkbx), "expose-event", G_CALLBACK (refresh_checkbox), ptr);
			gtk_container_add(GTK_CONTAINER(alignment), chkbx);
		} else if (strcmp(list.items[i]->type, "ENUMERATED") == 0){
			GtkWidget *alignment;
			if (settings.vertical){
				alignment = gtk_alignment_new(0.5,0.5,0,0);
				gtk_box_pack_start(GTK_BOX(vbox), alignment, true, true, 0);
			} else {
				alignment = gtk_alignment_new(1.0,0.5,0,0);
				gtk_box_pack_end(GTK_BOX(vbox), alignment, true, true, 0);
			}
			//insert a combobox with the different options
			GtkWidget *combo_box;
			combo_box=gtk_combo_box_new_text();
			for(unsigned int n=0; n<list.items[i]->number_of_enums; n++){
				gtk_combo_box_append_text(GTK_COMBO_BOX(combo_box), list.items[i]->enums[n]);
			}
			gtk_combo_box_set_active(GTK_COMBO_BOX(combo_box), list.items[i]->get());
			//bind to the change_combo_box function
			g_signal_connect(GTK_COMBO_BOX(combo_box), "changed", G_CALLBACK (change_combo_box), list.items[i]);
			gtk_container_add(GTK_CONTAINER(alignment), combo_box);
		}
		
		//add a checkbox for sliders that are muteable
		if (list.items[i]->switch_id >= 0){
			GtkWidget *alignment;
			if (settings.vertical){
				alignment = gtk_alignment_new(0.5,1.0,0,0);
				gtk_box_pack_start(GTK_BOX(vbox), alignment, true, true, 0);
			} else {
				alignment = gtk_alignment_new(1.0,0.5,0,0);
				gtk_box_pack_end(GTK_BOX(vbox), alignment, true, true, 0);
			}
			GtkWidget *chkbx;
			chkbx = gtk_check_button_new();
			//set it to the current state
			gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chkbx), (bool)list.elems[list.items[i]->switch_id].get());
			//bind to the toggle_checkbox function
			g_signal_connect(GTK_TOGGLE_BUTTON(chkbx), "toggled", G_CALLBACK (toggle_checkbox), &(list.elems[list.items[i]->switch_id]));
			g_signal_connect_after(GTK_TOGGLE_BUTTON(chkbx), "expose-event", G_CALLBACK (refresh_checkbox), &(list.elems[list.items[i]->switch_id]));
			
			gtk_container_add(GTK_CONTAINER(alignment), chkbx);
		}
		
		//display the name of the control
		GtkWidget *alignment;
		char wrapped[256];
		if (settings.vertical){
			alignment = gtk_alignment_new(0.5,1.0,0,0);
			gtk_box_pack_end(GTK_BOX(vbox), alignment, false, false, 0);
			word_wrap(wrapped, list.items[i]->short_name);
		} else {
			alignment = gtk_alignment_new(1.0,0.5,0,0);
			gtk_box_pack_start(GTK_BOX(vbox), alignment, false, false, 0);
			strcpy(wrapped, list.items[i]->short_name);
		}
		GtkWidget *label;
		label = gtk_label_new(wrapped);
		gtk_container_add(GTK_CONTAINER(alignment), label);
	}
	
	//finish the window stuff
	if (!start_hidden){ gtk_widget_show_all(settings.main_window); }
	g_signal_connect(settings.main_window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
	

	//add some periodic refreshment to keep the icon and window up-to-date
	#if GTK_CHECK_VERSION(2,14,0)
		int timeout = g_timeout_add_seconds(1, update, NULL);
	#else
		//this is less efficient than g_timeout_add_seconds()
		int timeout = g_timeout_add(1000, update, NULL);
	#endif
	
	//finished with gtk setup
	gtk_main();

	//stop the timeout
	g_source_remove(timeout);
	
	//have the window shown again if it was open before we restarted
	if (settings.resume_main){
		settings.resume_main = false;
		start_hidden = false;
	} else {
		start_hidden = true;
	}

	return(settings.restart);
}
Esempio n. 17
0
void
test_word_wrap(void)
{
	/* Test edge cases for word wrap algorithm */

	int len;
	char *ptr1, *ptr2, *ret, *end;

	/* Test wraping mid-word */
	char mesg1[] = "testing1 testing2";
	ptr1 = mesg1, ptr2 = mesg1, end = (mesg1 + strlen(mesg1));
	len = strlen("testing1 test");

	ret = word_wrap(len, &ptr2, end), *ret = '\0';
	assert_strcmp(ptr1, "testing1");
	assert_strcmp(ptr2, "testing2");

	/* Test wrap on whitespace */
	char mesg2[] = "testing1 testing2";
	ptr1 = mesg2, ptr2 = mesg2, end = (mesg2 + strlen(mesg2));
	len = strlen("testing1");

	ret = word_wrap(len, &ptr2, end), *ret = '\0';
	assert_strcmp(ptr1, "testing1");
	assert_strcmp(ptr2, "testing2");

	/* Test wrap on extraneous whitespace */
	char mesg3[] = "testing1     testing2";
	ptr1 = mesg3, ptr2 = mesg3, end = (mesg3 + strlen(mesg3));
	len = strlen("testing1   ");

	ret = word_wrap(len, &ptr2, end), *ret = '\0';
	assert_strcmp(ptr1, "testing1");
	assert_strcmp(ptr2, "testing2");

	/* Test wrap on exact length */
	char mesg4[] = "testing1 testing2";
	ptr1 = mesg4, ptr2 = mesg4, end = (mesg4 + strlen(mesg4));
	len = strlen("testing1 testing2");

	ret = word_wrap(len, &ptr2, end), *ret = '\0';
	assert_strcmp(ptr1, "testing1 testing2");
	assert_strcmp(ptr2, "");

	/* Test whole string fits */
	char mesg5[] = "testing";
	ptr1 = mesg5, ptr2 = mesg5, end = (mesg5 + strlen(mesg5));
	len = strlen("testing") * 2;

	ret = word_wrap(len, &ptr2, end), *ret = '\0';
	assert_strcmp(ptr1, "testing");
	assert_strcmp(ptr2, "");

	/* Test all whitespace */
	char mesg6[] = "                  ";
	ptr1 = mesg6, ptr2 = mesg6, end = (mesg6 + strlen(mesg6));
	len = strlen("   ");

	ret = word_wrap(len, &ptr2, end), *ret = '\0';
	assert_strcmp(ptr1, "");
	assert_strcmp(ptr2, "");

	/* Test empty string */
	char mesg7[] = "";
	ptr1 = mesg7, ptr2 = mesg7, end = (mesg7 + strlen(mesg7));
	len = strlen("   ");

	ret = word_wrap(len, &ptr2, end), *ret = '\0';
	assert_strcmp(ptr1, "");
	assert_strcmp(ptr2, "");
}
Esempio n. 18
0
/*
 * Name:    format_paragraph
 * Purpose: format paragraph using left, right, and paragraph margins.
 * Date:    November 27, 1991
 * Passed:  window:  pointer to current window
 */
int  format_paragraph( WINDOW *window )
{
register int len;       /* length of current line */
int  first_line;        /* boolean, first line formatted? */
int  spaces;            /* no. of spaces to add */
line_list_ptr p;        /* scratch pointers */
line_list_ptr pp;
char *source;           /* scratch line buffer pointers */
char *dest;
int  rcol;              /* scratch cols and margins */
int  lm;
int  rm;
int  pm;
int  margin;
int  eop;               /* boolean, (e)nd (o)f (p)aragraph? */
int  old_ww;            /* save state of word wrap flag */
long rline;
WINDOW w;               /* scratch window */

   if (window->ll->len == EOF)
      return( ERROR );
   entab_linebuff( );
   if (un_copy_line( window->ll, window, TRUE ) == ERROR)
      return( ERROR );
   if (!is_line_blank( window->ll->line, window->ll->len )) {
      old_ww = mode.word_wrap;
      if (old_ww == NO_WRAP)
         mode.word_wrap = FIXED_WRAP;
      dup_window_info( &w, window );
      g_status.screen_display = FALSE;

      /*
       * find the beginning of the paragraph.
       */
      p = w.ll->prev;
      if (g_status.command == FormatParagraph) {
         while (p != NULL &&  !is_line_blank( p->line, p->len )) {
            --w.rline;
            w.ll = w.ll->prev;
            p = p->prev;
         }
         pm = mode.parg_margin;

      /*
       * if format text, don't find the beginning of the paragraph.
       *  but we need to know if this is the first line in a paragraph.
       */
      } else if (g_status.command == FormatText) {
         if (p == NULL || is_line_blank( p->line, p->len ))
            pm = mode.parg_margin;
         else
            pm = mode.left_margin;
      } else
         pm = mode.left_margin;

      g_status.command = WordWrap;
      p = w.ll;
      if (mode.word_wrap == FIXED_WRAP)
         lm = mode.left_margin;
      else
         lm = pm = find_left_margin( p, mode.word_wrap );
      rm = mode.right_margin;
      eop = FALSE;

      /*
       * do the paragraph
       */
      for (first_line=TRUE; p != NULL  &&  !is_line_blank( p->line, p->len ) &&
                            eop == FALSE  &&  !g_status.control_break;) {

         /*
          * find out what margin to use
          */
         if (first_line) {
            margin = pm;
            first_line = FALSE;
         } else
            margin = lm;

         /*
          * line up the margin
          */
         w.ll->dirty = TRUE;
         copy_line( w.ll );
         detab_linebuff( );
         remove_spaces( 0 );
         rcol = find_word( (text_ptr)g_status.line_buff,
                                     g_status.line_buff_len, 0 );
         if (rcol != ERROR && rcol != margin) {

            /*
             * must add spaces to get the indentation right
             */
            if (rcol < margin) {
               source = g_status.line_buff;
               spaces = margin - rcol;
               dest = source + spaces;

               assert( g_status.line_buff_len >= 0 );
               assert( g_status.line_buff_len < MAX_LINE_LENGTH );

               memmove( dest, source, g_status.line_buff_len );
               g_status.line_buff_len += spaces;
               while (spaces--)
                  *source++ = ' ';
            } else {
               w.rcol = margin;
               word_delete( &w );
               entab_linebuff( );
               un_copy_line( p, &w, TRUE );
               copy_line( w.ll );
               detab_linebuff( );
               remove_spaces( margin );
            }
         }

         /*
          * now make sure rest of line is formatted
          */

         source = g_status.line_buff;
         len = g_status.line_buff_len;
         for (; len < rm+1 && eop == FALSE;) {
            pp = p->next;
            if (is_line_blank( pp->line, pp->len ))
               eop = TRUE;
            else {
               w.ll = p;
               w.rcol = len + 1;
               if (*(p->line+len-1) == '.')
                  ++w.rcol;
               word_delete( &w );
               entab_linebuff( );
               un_copy_line( p, &w, TRUE );
               copy_line( p );
               detab_linebuff( );
               remove_spaces( margin );
               len = g_status.line_buff_len;
            }
         }
         if (len <= rm+1) {
            entab_linebuff( );
            un_copy_line( p, &w, TRUE );
            p = p->next;
            if (is_line_blank( p->line, p->len ))
               eop = TRUE;
            else {
               w.ll = w.ll->next;
               w.rline++;
            }
         } else {
            w.rcol = rm;
            g_status.key_pressed = *(w.ll->line + rm);
            rline = w.rline;
            word_wrap( &w );
            if (rline == w.rline) {
               w.ll = w.ll->next;
               ++w.rline;
            }
         }
         g_status.copied = FALSE;
         p = w.ll;
      }
      mode.word_wrap = old_ww;
      g_status.copied = FALSE;
      w.file_info->dirty = GLOBAL;
      g_status.screen_display = TRUE;
   }
   return( OK );
}
Esempio n. 19
0
void msg_dlg(const UnicodeString& message) {
  UnicodeString msg;
  msg.add(far_get_msg(MSG_PLUGIN_NAME)).add('\n');
  if (message.size() != 0) msg.add(word_wrap(message, get_msg_width())).add('\n');
  far_message(c_error_dialog_guid, msg, 0, FMSG_MB_OK);
}