Exemplo n.º 1
0
int
dm_StrCopyOut2_U8toW (
    SQLCHAR	* inStr,
    SQLWCHAR	* outStr,
    size_t	  size,
    u_short	* result)
{
    size_t length;

    if (!inStr)
        return -1;

    length = utf8_len (inStr, SQL_NTS);

    if (result)
        *result = (u_short) length;

    if (!outStr)
        return 0;

    if (size >= length + 1)
    {
        length = utf8towcs (inStr, outStr, size);
        outStr[length] = L'\0';
        return 0;
    }
    if (size > 0)
    {
        length = utf8towcs (inStr, outStr, size - 1);
        outStr[length] = L'\0';
    }
    return -1;
}
Exemplo n.º 2
0
void RimeWithWeaselHandler::_GetCandidateInfo(weasel::CandidateInfo & cinfo, RimeContext & ctx)
{
	cinfo.candies.resize(ctx.menu.num_candidates);
	cinfo.comments.resize(ctx.menu.num_candidates);
	cinfo.labels.resize(ctx.menu.num_candidates);
	for (int i = 0; i < ctx.menu.num_candidates; ++i)
	{
		cinfo.candies[i].str = utf8towcs(ctx.menu.candidates[i].text);
		if (ctx.menu.candidates[i].comment)
		{
			cinfo.comments[i].str = utf8towcs(ctx.menu.candidates[i].comment);
		}
		if (RIME_STRUCT_HAS_MEMBER(ctx, ctx.select_labels) && ctx.select_labels)
		{
			cinfo.labels[i].str = utf8towcs(ctx.select_labels[i]);
		}
		else if (ctx.menu.select_keys)
		{
			cinfo.labels[i].str = std::wstring(1, ctx.menu.select_keys[i]);
		}
		else
		{
			cinfo.labels[i].str = std::to_wstring((i + 1) % 10);
		}
	}
	cinfo.highlighted = ctx.menu.highlighted_candidate_index;
	cinfo.currentPage = ctx.menu.page_no;
}
Exemplo n.º 3
0
/* TODO: respect hadj */
void swfTextUTF8(double x, double y, const char *str, double rot, double hadj, const pGEcontext gc, pDevDesc dd)
{
#ifdef SWF_DEBUG
    Rprintf("textUTF8 called\n");
    Rprintf("** family = %s, font = %d\n", gc->fontfamily, gc->fontface);
    Rprintf("** textUTF8(str[0] = %d, str[1] = %d, str[2] = %d, str[3] = %d)\n",
            str[0], str[1], str[2], str[3]);
#endif
    pswfDesc swfInfo = (pswfDesc) dd->deviceSpecific;
    SWFShape text = newSWFShape();
    SWFDisplayItem text_display;
    /* Convert UTF-8 string to Unicode array */
    int maxLen = strlen(str);
    wchar_t *unicode = (wchar_t *) calloc(maxLen + 1, sizeof(wchar_t));
    int len = utf8towcs(unicode, str, maxLen);
    
    FT_Face face = swfGetFTFace(gc, swfInfo);
    double fontSize = gc->ps * gc->cex;

    swfSetTextColor(text, gc, swfInfo);
    SWFShape_addString(text, unicode, len, fontSize, face,
                       &(swfInfo->outlnFuns));
    
    text_display = SWFMovieClip_add(swfInfo->currentFrame, (SWFBlock) text);
    SWFDisplayItem_moveTo(text_display, x, y);
    SWFDisplayItem_rotate(text_display, rot);
}
Exemplo n.º 4
0
void RimeWithWeaselHandler::_GetContext(weasel::Context & weasel_context, UINT session_id)
{
	RIME_STRUCT(RimeContext, ctx);
	if (RimeGetContext(session_id, &ctx))
	{
		if (ctx.composition.length > 0)
		{
			weasel_context.preedit.str = utf8towcs(ctx.composition.preedit);
			if (ctx.composition.sel_start < ctx.composition.sel_end)
			{
				weasel::TextAttribute attr;
				attr.type = weasel::HIGHLIGHTED;
				attr.range.start = utf8towcslen(ctx.composition.preedit, ctx.composition.sel_start);
				attr.range.end = utf8towcslen(ctx.composition.preedit, ctx.composition.sel_end);

				weasel_context.preedit.attributes.push_back(attr);
			}
		}
		if (ctx.menu.num_candidates)
		{
			weasel::CandidateInfo &cinfo(weasel_context.cinfo);
			_GetCandidateInfo(cinfo, ctx);
		}
		RimeFreeContext(&ctx);
	}
}
Exemplo n.º 5
0
void DictManagementDialog::Populate() {
	RimeUserDictIterator iter = {0};
	api_->user_dict_iterator_init(&iter);
	while (const char* dict = api_->next_user_dict(&iter)) {
		user_dict_list_.AddString(utf8towcs(dict));
	}
	api_->user_dict_iterator_destroy(&iter);
	user_dict_list_.SetCurSel(-1);
}
void UIStyleSettingsDialog::Preview(int index) {
	if (index < 0 || index >= preset_.size()) return;
	const std::string file_path(settings_->GetColorSchemePreview(preset_[index].color_scheme_id));
	if (file_path.empty()) return;
	image_.Destroy();
	image_.Load(utf8towcs(file_path.c_str()));
	if (!image_.IsNull()) {
		preview_.SetBitmap(image_);
	}
}
Exemplo n.º 7
0
int
System(char *command)			/* command is a UTF-8 string */
{ STARTUPINFOW sinfo;
  PROCESS_INFORMATION pinfo;
  int shell_rval;
  size_t len;
  wchar_t *wcmd;

  memset(&sinfo, 0, sizeof(sinfo));
  sinfo.cb = sizeof(sinfo);

  len = utf8_strlen(command, strlen(command));
  wcmd = PL_malloc((len+1)*sizeof(wchar_t));
  utf8towcs(wcmd, command);

  if ( CreateProcessW(NULL,			/* module */
		      wcmd,			/* command line */
		      NULL,			/* Security stuff */
		      NULL,			/* Thread security stuff */
		      FALSE,			/* Inherit handles */
		      CREATE_NO_WINDOW,		/* flags */
		      NULL,			/* environment */
		      NULL,			/* CWD */
		      &sinfo,			/* startup info */
		      &pinfo) )			/* process into */
  { BOOL rval;
    DWORD code;

    CloseHandle(pinfo.hThread);			/* don't need this */
    PL_free(wcmd);

    do
    { MSG msg;

      if ( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) )
      { TranslateMessage(&msg);
	DispatchMessage(&msg);
      } else
	Sleep(50);

      rval = GetExitCodeProcess(pinfo.hProcess, &code);
    } while(rval == TRUE && code == STILL_ACTIVE);

    shell_rval = (rval == TRUE ? code : -1);
    CloseHandle(pinfo.hProcess);
  } else
  { PL_free(wcmd);
    return shell_rval = -1;
  }

  return shell_rval;
}
Exemplo n.º 8
0
void SwitcherSettingsDialog::Populate() {
	if (!settings_) return;
	RimeSchemaList available = {0};
	api_->get_available_schema_list(settings_, &available);
	RimeSchemaList selected = {0};
	api_->get_selected_schema_list(settings_, &selected);
	schema_list_.DeleteAllItems();
	size_t k = 0;
	std::set<RimeSchemaInfo*> recruited;
	for (size_t i = 0; i < selected.size; ++i) {
		const char* schema_id = selected.list[i].schema_id;
		for (size_t j = 0; j < available.size; ++j) {
			RimeSchemaListItem& item(available.list[j]);
			RimeSchemaInfo* info = (RimeSchemaInfo*)item.reserved;
			if (!strcmp(item.schema_id, schema_id) && recruited.find(info) == recruited.end()) {
				recruited.insert(info);
				schema_list_.AddItem(k, 0, utf8towcs(item.name));
				schema_list_.SetItemData(k, (DWORD_PTR)info);
				schema_list_.SetCheckState(k, TRUE);
				++k;
				break;
			}
		}
	}
	for (size_t i = 0; i < available.size; ++i) {
		RimeSchemaListItem& item(available.list[i]);
		RimeSchemaInfo* info = (RimeSchemaInfo*)item.reserved;
		if (recruited.find(info) == recruited.end()) {
			recruited.insert(info);
			schema_list_.AddItem(k, 0, utf8towcs(item.name));
			schema_list_.SetItemData(k, (DWORD_PTR)info);
			++k;
		}
	}
	hotkeys_.SetWindowTextW(utf8towcs(api_->get_hotkeys(settings_)));
	loaded_ = true;
	modified_ = false;
}
Exemplo n.º 9
0
void SwitcherSettingsDialog::ShowDetails(RimeSchemaInfo* info) {
	if (!info) return;
	std::string details;
	if (const char* name = api_->get_schema_name(info)) {
		details += name;
	}
    if (const char* author = api_->get_schema_author(info)) {
        (details += "\n\n") += author;
    }
    if (const char* description = api_->get_schema_description(info)) {
        (details += "\n\n") += description;
    }
	description_.SetWindowTextW(utf8towcs(details.c_str()));
}
Exemplo n.º 10
0
void RimeWithWeaselHandler::_UpdateUI(UINT session_id)
{
	weasel::Status weasel_status;
	weasel::Context weasel_context;

	bool is_tsf = _IsSessionTSF(session_id);

	if (session_id == 0)
		weasel_status.disabled = m_disabled;

	_GetStatus(weasel_status, session_id);

	if (!is_tsf) {
		_GetContext(weasel_context, session_id);
	}

	if (!m_ui) return;
	if (RimeGetOption(session_id, "inline_preedit"))
		m_ui->style().client_caps |= weasel::INLINE_PREEDIT_CAPABLE;
	else
		m_ui->style().client_caps &= ~weasel::INLINE_PREEDIT_CAPABLE;


	if (weasel_status.composing)
	{
		m_ui->Update(weasel_context, weasel_status);
		if (!is_tsf) m_ui->Show();
	}
	else if (!_ShowMessage(weasel_context, weasel_status))
	{
		m_ui->Hide();
		m_ui->Update(weasel_context, weasel_status);
	}
	
	// Dangerous, don't touch
	static char app_name[50];
	RimeGetProperty(session_id, "client_app", app_name, sizeof(app_name) - 1);
	if (utf8towcs(app_name) == std::wstring(L"explorer.exe") && m_vista_greater) {
		boost::thread th([=]() {
			::Sleep(100);
			if (_UpdateUICallback) _UpdateUICallback();
		});
	}
	else {
		if (_UpdateUICallback) _UpdateUICallback();
	}

	m_message_type.clear();
	m_message_value.clear();
}
Exemplo n.º 11
0
int
FilterAddKeyword(Document *doc, const TCHAR *fieldName, const char *value, bool includeInEverything)
{
    TCHAR tbuf[TBUF_CHARS + 1];

    utf8towcs(tbuf, value, TBUF_CHARS);

    doc->add(*Field::Keyword(fieldName, tbuf));
    if (includeInEverything) {
        doc->add(*Field::Keyword(_T("everything"), tbuf));
    }

    return 0;
}
Exemplo n.º 12
0
void UIStyleSettingsDialog::Populate() {
	if (!settings_) return;
	std::string active(settings_->GetActiveColorScheme());
	int active_index = -1;
	settings_->GetPresetColorSchemes(&preset_);
	for (size_t i = 0; i < preset_.size(); ++i) {
		color_schemes_.AddString(utf8towcs(preset_[i].name.c_str()));
		if (preset_[i].color_scheme_id == active) {
			active_index = i;
		}
	}
	if (active_index >= 0) {
		color_schemes_.SetCurSel(active_index);
		Preview(active_index);
	}
	loaded_ = true;
}
Exemplo n.º 13
0
codecvt_base::result codecvt_utf8::do_in(mbstate_t &state, const char *from, 
                                         const char *from_end, const char *&from_next, 
                                         wchar_t *to, wchar_t *to_limit, 
                                         wchar_t *&to_next) const
{
   int len = from_end - from;
   int destlen = to_limit - to;
   int res = utf8towcs(from, &len , to, &destlen);
   from_next = from + len;
   to_next = to + destlen;
   if (res < 0)
      return codecvt_base::error;
   else if (res == 1)
      return codecvt_base::partial;

   return codecvt_base::ok;
}
Exemplo n.º 14
0
static SQLWCHAR *
strdup_U8toW (SQLCHAR * str)
{
    SQLWCHAR *ret;
    size_t len;

    if (!str)
        return NULL;

    len = utf8_len (str, SQL_NTS);
    if ((ret = (SQLWCHAR *) malloc ((len + 1) * sizeof (SQLWCHAR))) == NULL)
        return NULL;

    len = utf8towcs (str, ret, len);
    ret[len] = L'\0';

    return ret;
}
Exemplo n.º 15
0
int
FilterAddTextWithBoost(Document *doc, const TCHAR *fieldName, const char *value, float_t boost, bool includeInEverything)
{
    Field *f;
    TCHAR tbuf[TBUF_CHARS + 1];

    utf8towcs(tbuf, value, TBUF_CHARS);

    f = Field::Text(fieldName, tbuf);
    f->setBoost(boost);
    doc->add(*f);
    if (includeInEverything) {
        f = Field::Text(_T("everything"), tbuf);
        f->setBoost(boost);
        doc->add(*f);
    }

    return 0;
}
Exemplo n.º 16
0
void RimeWithWeaselHandler::_GetStatus(weasel::Status & stat, UINT session_id)
{
	RIME_STRUCT(RimeStatus, status);
	if (RimeGetStatus(session_id, &status))
	{
		std::string schema_id = status.schema_id;
		if (schema_id != m_last_schema_id)
		{
			m_last_schema_id = schema_id;
			RimeSetOption(session_id, "__synced", false); // Sync new schema options with front end
			_LoadSchemaSpecificSettings(schema_id);
		}
		stat.schema_name = utf8towcs(status.schema_name);
		stat.ascii_mode = !!status.is_ascii_mode;
		stat.composing = !!status.is_composing;
		stat.disabled = !!status.is_disabled;
		RimeFreeStatus(&status);
	}

}
Exemplo n.º 17
0
int
FilterAddText(Document *doc, const TCHAR *fieldName, const char *value, bool includeInEverything)
{
    TCHAR tbuf[TBUF_CHARS + 1];
    int dbg;
    
    if (!value) {
        return 1;
    }

    dbg = utf8towcs(tbuf, value, TBUF_CHARS);

    doc->add(*Field::Text(fieldName, tbuf));
    
    if (includeInEverything) {
        doc->add(*Field::Text(_T("everything"), tbuf));
    }

    return 0;
}
Exemplo n.º 18
0
double swfStrWidthUTF8(const char *str, const pGEcontext gc, pDevDesc dd)
{
#ifdef SWF_DEBUG
    Rprintf("strWidthUTF8 called\n");
    Rprintf("** family = %s, str[0] = %d, str[1] = %d\n",
        gc->fontfamily, str[0], str[1]);
#endif
    /* Convert UTF-8 string to Unicode array */
    int maxLen = strlen(str);
    wchar_t *unicode = (wchar_t *) calloc(maxLen + 1, sizeof(wchar_t));
    int len = utf8towcs(unicode, str, maxLen);
    /* Get the font face object */
    FT_Face face = swfGetFTFace(gc);
    FT_Error err;
    double fontSize = gc->ps * gc->cex;
    double ratio = fontSize / face->units_per_EM;
    double width = 0.0;
    int i;
    /* Add up the 'advance' of each character */
    for(i = 0; i < len; i++)
    {
        err = FT_Load_Char(face, unicode[i], FT_LOAD_NO_SCALE);
        if(err)
        {
            errorcode(err);
            continue;
        }
        width += face->glyph->metrics.horiAdvance * ratio;
    }
    
    free(unicode);

#ifdef SWF_DEBUG
    Rprintf("** strWidthUTF8(width = %f)\n", width);
#endif

    return width;
}
Exemplo n.º 19
0
xhn::Unicode::Unicode(const char* sz)
{
    vector< wchar_t, FGetCharRealSizeProc<wchar_t> > buf;
	utf8towcs(sz, buf);
	m_unicode = wstring(buf);
}
Exemplo n.º 20
0
bool RimeWithWeaselHandler::_Respond(UINT session_id, EatLine eat)
{
	std::set<std::string> actions;
	std::list<std::string> messages;

	// extract information

	RIME_STRUCT(RimeCommit, commit);
	if (RimeGetCommit(session_id, &commit))
	{
		actions.insert("commit");
		messages.push_back(std::string("commit=") + commit.text + '\n');
		RimeFreeCommit(&commit);
	}
	
	bool is_composing = false;
	RIME_STRUCT(RimeStatus, status);
	if (RimeGetStatus(session_id, &status))
	{
		is_composing = !!status.is_composing;
		actions.insert("status");
		messages.push_back(std::string("status.ascii_mode=") + std::to_string(status.is_ascii_mode) + '\n');
		messages.push_back(std::string("status.composing=") + std::to_string(status.is_composing) + '\n');
		messages.push_back(std::string("status.disabled=") + std::to_string(status.is_disabled) + '\n');
		RimeFreeStatus(&status);
	}
	
	RIME_STRUCT(RimeContext, ctx);
	if (RimeGetContext(session_id, &ctx))
	{
		if (is_composing)
		{
			actions.insert("ctx");
			switch (m_ui->style().preedit_type)
			{
			case weasel::UIStyle::PREVIEW:
				if (ctx.commit_text_preview != NULL)
				{
					std::string first = ctx.commit_text_preview;
					messages.push_back(std::string("ctx.preedit=") + first + '\n');
					messages.push_back(std::string("ctx.preedit.cursor=") +
						std::to_string(utf8towcslen(first.c_str(), 0)) + ',' +
						std::to_string(utf8towcslen(first.c_str(), first.size())) + '\n');
					break;
				}
				// no preview, fall back to composition
			case weasel::UIStyle::COMPOSITION:
				messages.push_back(std::string("ctx.preedit=") + ctx.composition.preedit + '\n');
				if (ctx.composition.sel_start <= ctx.composition.sel_end)
				{
					messages.push_back(std::string("ctx.preedit.cursor=") +
						std::to_string(utf8towcslen(ctx.composition.preedit, ctx.composition.sel_start)) + ',' +
						std::to_string(utf8towcslen(ctx.composition.preedit, ctx.composition.sel_end)) + '\n');
				}
				break;
			}
		}
		if (ctx.menu.num_candidates)
		{
			weasel::CandidateInfo cinfo;
			std::wstringstream ss;
			boost::archive::text_woarchive oa(ss);
			_GetCandidateInfo(cinfo, ctx);

			oa << cinfo;

			messages.push_back(std::string("ctx.cand=") + wcstoutf8(ss.str().c_str()) + '\n');
		}
		RimeFreeContext(&ctx);
	}

	// configuration information
	actions.insert("config");
	messages.push_back(std::string("config.inline_preedit=") + std::to_string((int)m_ui->style().inline_preedit) + '\n');

	// style
	bool has_synced = RimeGetOption(session_id, "__synced");
	if (!has_synced) {
		std::wstringstream ss;
		boost::archive::text_woarchive oa(ss);
		oa << m_ui->style();

		actions.insert("style");
		messages.push_back(std::string("style=") + wcstoutf8(ss.str().c_str()) + '\n');
		RimeSetOption(session_id, "__synced", true);
	}

	// summarize

	if (actions.empty())
	{
		messages.insert(messages.begin(), std::string("action=noop\n"));
	}
	else
	{
		std::string actionList(join(actions, ","));
		messages.insert(messages.begin(), std::string("action=") + actionList + '\n');
	}

	messages.push_back(std::string(".\n"));

	return std::all_of(messages.begin(), messages.end(), [&eat](std::string &msg)
	{
		return eat(std::wstring(utf8towcs(msg.c_str())));
	});
}
Exemplo n.º 21
0
FILE *
pt_popen(const char *cmd, const char *mode)
{ FILE *fptr = NULL;
  PROCESS_INFORMATION piProcInfo;
  STARTUPINFOW siStartInfo;
  int success, redirect_error = 0;
  wchar_t *wcmd = NULL;
  wchar_t *err2out;
  pipe_context *pc;

  size_t utf8len = utf8_strlen(cmd, strlen(cmd));
  if ( !(wcmd = malloc((utf8len+1)*sizeof(wchar_t))) )
  { return NULL;
  }
  utf8towcs(wcmd, cmd);

  if ( !(pc=allocPipeContext()) )
    goto finito;
  if ( !mode || !*mode )
    goto finito;
  pc->mode = *mode;
  if ( pc->mode != 'r' && pc->mode != 'w' )
    goto finito;

  /*
   * Shall we redirect stderr to stdout ? */
  if ( (err2out=wcsstr(wcmd, L"2>&1")) != NULL)
  { /* this option doesn't apply to win32 shells, so we clear it out! */
     wcsncpy(err2out, L"    ", 4);
     redirect_error = 1;
  }

  /*
   * Create the Pipes... */
  if (my_pipe(pc->in)  == -1 ||
      my_pipe(pc->out) == -1)
    goto finito;
  if ( !redirect_error )
  { if ( my_pipe(pc->err) == -1)
      goto finito;
  }

  /*
   * Now create the child process */
  ZeroMemory(&siStartInfo, sizeof(STARTUPINFO));
  siStartInfo.cb           = sizeof(STARTUPINFO);
  siStartInfo.hStdInput    = pc->in[0];
  siStartInfo.hStdOutput   = pc->out[1];
  if ( redirect_error )
    siStartInfo.hStdError  = pc->out[1];
  else
    siStartInfo.hStdError  = pc->err[1];
  siStartInfo.dwFlags      = STARTF_USESTDHANDLES;

  success = CreateProcessW(NULL,
			   wcmd,	// command line
			   NULL,	// process security attributes
			   NULL,	// primary thread security attributes
			   TRUE,	// handles are inherited
			   CREATE_NO_WINDOW,  // creation flags: without window (?)
			   NULL,	// use parent's environment
			   NULL,	// use parent's current directory
			   &siStartInfo, // STARTUPINFO pointer
			   &piProcInfo); // receives PROCESS_INFORMATION

  if ( !success )
    goto finito;

  CloseHandle(piProcInfo.hThread);
  CloseHandle(piProcInfo.hProcess);

  /*
   * These handles listen to the Child process */
  CloseHandle(pc->in[0]);  pc->in[0]  = INVALID_HANDLE_VALUE;
  CloseHandle(pc->out[1]); pc->out[1] = INVALID_HANDLE_VALUE;
  if ( pc->err[1] != INVALID_HANDLE_VALUE )
  { CloseHandle(pc->err[1]);
    pc->err[1] = INVALID_HANDLE_VALUE;
  }

  if ( pc->mode == 'r' )
    fptr = _fdopen(_open_osfhandle((intptr_t)pc->out[0],_O_BINARY),"r");
  else
    fptr = _fdopen(_open_osfhandle((intptr_t)pc->in[1],_O_BINARY),"w");

finito:
  if ( fptr )
  { pc->fd = fptr;
    linkPipeContext(pc);
  } else
  { if ( pc )
      discardPipeContext(pc);
  }
  if ( wcmd )
    free(wcmd);

  return fptr;
}
Exemplo n.º 22
0
static void _UpdateUIStyle(RimeConfig* config, weasel::UI* ui, bool initialize)
{
	if (!ui) return;

	weasel::UIStyle &style(ui->style());

	const int BUF_SIZE = 99;
	char buffer[BUF_SIZE + 1];
	memset(buffer, '\0', sizeof(buffer));
	if (RimeConfigGetString(config, "style/font_face", buffer, BUF_SIZE))
	{
		style.font_face = utf8towcs(buffer);
	}
	RimeConfigGetInt(config, "style/font_point", &style.font_point);
	Bool inline_preedit = False;
	if (RimeConfigGetBool(config, "style/inline_preedit", &inline_preedit) || initialize)
	{
		style.inline_preedit = !!inline_preedit;
	}
	char preedit_type[20] = { 0 };
	if (RimeConfigGetString(config, "style/preedit_type", preedit_type, sizeof(preedit_type) - 1))
	{
		if (!std::strcmp(preedit_type, "composition"))
			style.preedit_type = weasel::UIStyle::COMPOSITION;
		else if (!std::strcmp(preedit_type, "preview"))
			style.preedit_type = weasel::UIStyle::PREVIEW;
	}
	Bool display_tray_icon = False;
	if (RimeConfigGetBool(config, "style/display_tray_icon", &display_tray_icon) || initialize)
	{
		style.display_tray_icon = !!display_tray_icon;
	}
	Bool horizontal = False;
	if (RimeConfigGetBool(config, "style/horizontal", &horizontal) || initialize)
	{
		style.layout_type = horizontal ? weasel::UIStyle::LAYOUT_HORIZONTAL : weasel::UIStyle::LAYOUT_VERTICAL;
	}
	Bool fullscreen = False;
	if (RimeConfigGetBool(config, "style/fullscreen", &fullscreen) && fullscreen)
	{
		style.layout_type = (style.layout_type == weasel::UIStyle::LAYOUT_HORIZONTAL)
			 ? weasel::UIStyle::LAYOUT_HORIZONTAL_FULLSCREEN : weasel::UIStyle::LAYOUT_VERTICAL_FULLSCREEN;
	}
	char label_text_format[128] = { 0 };
	if (RimeConfigGetString(config, "style/label_format", label_text_format, sizeof(label_text_format) - 1))
	{
		style.label_text_format = utf8towcs(label_text_format);
	}
	// layout (alternative to style/horizontal)
	char layout_type[256] = {0};
	if (RimeConfigGetString(config, "style/layout/type", layout_type, sizeof(layout_type) - 1))
	{
		if (!std::strcmp(layout_type, "vertical"))
			style.layout_type = weasel::UIStyle::LAYOUT_VERTICAL;
		else if (!std::strcmp(layout_type, "horizontal"))
			style.layout_type = weasel::UIStyle::LAYOUT_HORIZONTAL;
		if (!std::strcmp(layout_type, "vertical+fullscreen"))
			style.layout_type = weasel::UIStyle::LAYOUT_VERTICAL_FULLSCREEN;
		else if (!std::strcmp(layout_type, "horizontal+fullscreen"))
			style.layout_type = weasel::UIStyle::LAYOUT_HORIZONTAL_FULLSCREEN;
		else
			LOG(WARNING) << "Invalid style type: " << layout_type;
	}
	RimeConfigGetInt(config, "style/layout/min_width", &style.min_width);
	RimeConfigGetInt(config, "style/layout/min_height", &style.min_height);
	if (!RimeConfigGetInt(config, "style/layout/border", &style.border)) {
		RimeConfigGetInt(config, "style/layout/border_width", &style.border);
	}
	RimeConfigGetInt(config, "style/layout/margin_x", &style.margin_x);
	RimeConfigGetInt(config, "style/layout/margin_y", &style.margin_y);
	RimeConfigGetInt(config, "style/layout/spacing", &style.spacing);
	RimeConfigGetInt(config, "style/layout/candidate_spacing", &style.candidate_spacing);
	RimeConfigGetInt(config, "style/layout/hilite_spacing", &style.hilite_spacing);
	RimeConfigGetInt(config, "style/layout/hilite_padding", &style.hilite_padding);
	RimeConfigGetInt(config, "style/layout/round_corner", &style.round_corner);
	// color scheme
	if (initialize && RimeConfigGetString(config, "style/color_scheme", buffer, BUF_SIZE))
	{
		std::string prefix("preset_color_schemes/");
		prefix += buffer;
		RimeConfigGetInt(config, (prefix + "/text_color").c_str(), &style.text_color);
		if (!RimeConfigGetInt(config, (prefix + "/candidate_text_color").c_str(), &style.candidate_text_color))
		{
			style.candidate_text_color = style.text_color;
		}
		RimeConfigGetInt(config, (prefix + "/back_color").c_str(), &style.back_color);
		if (!RimeConfigGetInt(config, (prefix + "/border_color").c_str(), &style.border_color))
		{
			style.border_color = style.text_color;
		}
		if (!RimeConfigGetInt(config, (prefix + "/hilited_text_color").c_str(), &style.hilited_text_color))
		{
			style.hilited_text_color = style.text_color;
		}
		if (!RimeConfigGetInt(config, (prefix + "/hilited_back_color").c_str(), &style.hilited_back_color))
		{
			style.hilited_back_color = style.back_color;
		}
		if (!RimeConfigGetInt(config, (prefix + "/hilited_candidate_text_color").c_str(), &style.hilited_candidate_text_color))
		{
			style.hilited_candidate_text_color = style.hilited_text_color;
		}
		if (!RimeConfigGetInt(config, (prefix + "/hilited_candidate_back_color").c_str(), &style.hilited_candidate_back_color))
		{
			style.hilited_candidate_back_color = style.hilited_back_color;
		}
		if (!RimeConfigGetInt(config, (prefix + "/label_color").c_str(), &style.label_text_color))
		{
			style.label_text_color = blend_colors(style.candidate_text_color, style.back_color);
		}
		if (!RimeConfigGetInt(config, (prefix + "/hilited_label_color").c_str(), &style.hilited_label_text_color))
		{
			style.hilited_label_text_color = blend_colors(style.hilited_candidate_text_color, style.hilited_candidate_back_color);
		}
		style.comment_text_color = style.label_text_color;
		style.hilited_comment_text_color = style.hilited_label_text_color;
		if (RimeConfigGetInt(config, (prefix + "/comment_text_color").c_str(), &style.comment_text_color))
		{
			style.hilited_comment_text_color = style.comment_text_color;
		}
		RimeConfigGetInt(config, (prefix + "/hilited_comment_text_color").c_str(), &style.hilited_comment_text_color);
	}
}
Exemplo n.º 23
0
void RimeWithWeaselHandler::_UpdateUI(UINT session_id)
{
	weasel::Status weasel_status;
	weasel::Context weasel_context;
	if (session_id == 0)
		weasel_status.disabled = m_disabled;

	RimeStatus status = {0};
	RIME_STRUCT_INIT(RimeStatus, status);
	if (RimeGetStatus(session_id, &status))
	{
		weasel_status.schema_name = utf8towcs(status.schema_name);
		weasel_status.ascii_mode = status.is_ascii_mode;
		weasel_status.composing = status.is_composing;
		weasel_status.disabled = status.is_disabled;
		RimeFreeStatus(&status);
	}

	RimeContext ctx = {0};
	RIME_STRUCT_INIT(RimeContext, ctx);
	if (RimeGetContext(session_id, &ctx))
	{
		if (ctx.composition.length > 0)
		{
			weasel_context.preedit.str = utf8towcs(ctx.composition.preedit);
			if (ctx.composition.sel_start < ctx.composition.sel_end)
			{
				weasel::TextAttribute attr;
				attr.type = weasel::HIGHLIGHTED;
				attr.range.start = utf8towcslen(ctx.composition.preedit, ctx.composition.sel_start);
				attr.range.end = utf8towcslen(ctx.composition.preedit, ctx.composition.sel_end);
			
				weasel_context.preedit.attributes.push_back(attr);
			}
		}
		if (ctx.menu.num_candidates)
		{
			weasel::CandidateInfo &cinfo(weasel_context.cinfo);
			cinfo.candies.resize(ctx.menu.num_candidates);
			cinfo.comments.resize(ctx.menu.num_candidates);
			for (int i = 0; i < ctx.menu.num_candidates; ++i)
			{
				cinfo.candies[i].str = utf8towcs(ctx.menu.candidates[i].text);
				if (ctx.menu.candidates[i].comment)
				{
					cinfo.comments[i].str = utf8towcs(ctx.menu.candidates[i].comment);
				}
			}
			cinfo.highlighted = ctx.menu.highlighted_candidate_index;
			cinfo.currentPage = ctx.menu.page_no;
			cinfo.labels = ctx.menu.select_keys;
		}
		RimeFreeContext(&ctx);
	}

	if (!m_ui) return;
	if (RimeGetOption(session_id, "inline_preedit"))
		m_ui->style().client_caps |= weasel::INLINE_PREEDIT_CAPABLE;
	else
		m_ui->style().client_caps &= ~weasel::INLINE_PREEDIT_CAPABLE;
	if (weasel_status.composing)
	{
		m_ui->Update(weasel_context, weasel_status);
		m_ui->Show();
	}
	else if (!_ShowMessage(weasel_context, weasel_status))
	{
		m_ui->Hide();
		m_ui->Update(weasel_context, weasel_status);
	}

	m_message_type.clear();
	m_message_value.clear();
}
Exemplo n.º 24
0
int
FilterAddSummaryInfo(Document *doc, DStoreDocInfo *info)
{
    char buf[CONN_BUFSIZE + 1];
    TCHAR tbuf[TBUF_CHARS + 1];
    Field *f;

    snprintf(buf, sizeof(buf), GUID_FMT, info->guid);
    utf8towcs(tbuf, buf, TBUF_CHARS);
    doc->add(*Field::Keyword(_T("nmap.guid"), tbuf));

    snprintf(buf, sizeof(buf), GUID_FMT, info->conversation);
    utf8towcs(tbuf, buf, TBUF_CHARS);
    doc->add(*Field::Keyword(_T("nmap.conversation"), tbuf));

    if (info->type & STORE_DOCTYPE_FOLDER) {
        utf8towcs(tbuf, "folder", TBUF_CHARS);
        doc->add(*Field::Keyword(_T("nmap.type"), tbuf));
    }
    if (info->type & STORE_DOCTYPE_SHARED) {
        utf8towcs(tbuf, "shared", TBUF_CHARS);
        doc->add(*Field::Keyword(_T("nmap.type"), tbuf));
    }

    AddFlags(doc, info);

    char sortstr[CONN_BUFSIZE];
    char *type = NULL;
    switch (info->type) {
        BongoCalTime t;
        
    case STORE_DOCTYPE_MAIL:
        type = "mail";
        t = BongoCalTimeNewFromUint64(info->data.mail.sent, FALSE, NULL);
        BongoCalTimeToIcal(t, sortstr, sizeof(sortstr));
        break;
    case STORE_DOCTYPE_EVENT:
        type = "event";
        snprintf(sortstr, sizeof(sortstr), "%s%x", 
                 info->data.event.start, info->guid);
        break;
    case STORE_DOCTYPE_AB:
        type = "addressbook";
        /* FIXME: use the contact name */
        t = BongoCalTimeNewFromUint64(info->timeCreatedUTC, FALSE, NULL);
        BongoCalTimeToIcal(t, sortstr, sizeof(sortstr));
        break;
    case STORE_DOCTYPE_CONVERSATION:
        type = "conversation";
        /* FIXME: use the contact name */
        t = BongoCalTimeNewFromUint64(info->data.conversation.lastMessageDate, FALSE, NULL);
        BongoCalTimeToIcal(t, sortstr, sizeof(sortstr));
        break;
    default:
        break;
    }

    if (type != NULL) {
        utf8towcs(tbuf, type, TBUF_CHARS);
        doc->add(*Field::Keyword(_T("nmap.type"), tbuf));

        utf8towcs(tbuf, sortstr, TBUF_CHARS);
        doc->add(*Field::Keyword(_T("nmap.sort"), tbuf));
    }

    return 0;
}
Exemplo n.º 25
0
bool RimeWithWeaselHandler::_Respond(UINT session_id, LPWSTR buffer)
{
	std::set<std::string> actions;
	std::list<std::string> messages;

	// extract information

	RimeCommit commit = {0};
	if (RimeGetCommit(session_id, &commit))
	{
		actions.insert("commit");
		messages.push_back(boost::str(boost::format("commit=%s\n") % commit.text));
		RimeFreeCommit(&commit);
	}
	
	bool is_composing;
	RimeStatus status = {0};
	RIME_STRUCT_INIT(RimeStatus, status);
	if (RimeGetStatus(session_id, &status))
	{
		is_composing = status.is_composing;
		actions.insert("status");
		messages.push_back(boost::str(boost::format("status.ascii_mode=%d\n") % status.is_ascii_mode));
		messages.push_back(boost::str(boost::format("status.composing=%d\n") % status.is_composing));
		messages.push_back(boost::str(boost::format("status.disabled=%d\n") % status.is_disabled));
		RimeFreeStatus(&status);
	}
	
	RimeContext ctx = {0};
	RIME_STRUCT_INIT(RimeContext, ctx);
	if (RimeGetContext(session_id, &ctx))
	{
		if (is_composing)
		{
			actions.insert("ctx");
			messages.push_back(boost::str(boost::format("ctx.preedit=%s\n") % ctx.composition.preedit));
			if (ctx.composition.sel_start <= ctx.composition.sel_end)
			{
				messages.push_back(boost::str(boost::format("ctx.preedit.cursor=%d,%d\n") %
					utf8towcslen(ctx.composition.preedit, ctx.composition.sel_start) %
					utf8towcslen(ctx.composition.preedit, ctx.composition.sel_end)));
			}
		}
		RimeFreeContext(&ctx);
	}

	// configuration information
	actions.insert("config");
	messages.push_back(boost::str(boost::format("config.inline_preedit=%d\n") % (int) m_ui->style().inline_preedit));

	// summarize

	if (actions.empty())
	{
		messages.insert(messages.begin(), std::string("action=noop\n"));
	}
	else
	{
		std::string actionList(boost::join(actions, ","));
		messages.insert(messages.begin(), boost::str(boost::format("action=%s\n") % actionList));
	}

	messages.push_back(std::string(".\n"));

	// printing to stream

	memset(buffer, 0, WEASEL_IPC_BUFFER_SIZE);
	wbufferstream bs(buffer, WEASEL_IPC_BUFFER_LENGTH);

	BOOST_FOREACH(const std::string &msg, messages)
	{
		bs << utf8towcs(msg.c_str());
		if (!bs.good())
		{
			// response text toooo long!
			return false;
		}
	}