Exemple #1
0
static gchar* convertUniCharToUTF8(const UChar* characters, gint length, int from, int to)
{
    gint newLength = 0;
    GOwnPtr<gchar> utf8Text(utf16ToUtf8(characters, length, newLength));
    if (!utf8Text)
        return 0;

    gchar* pos = utf8Text.get();
    if (from > 0) {
        // discard the first 'from' characters
        // FIXME: we should do this before the conversion probably
        pos = g_utf8_offset_to_pointer(utf8Text.get(), from);
    }

    gint len = strlen(pos);
    GString* ret = g_string_new_len(NULL, len);

    // replace line break by space
    while (len > 0) {
        gint index, start;
        pango_find_paragraph_boundary(pos, len, &index, &start);
        g_string_append_len(ret, pos, index);
        if (index == start)
            break;
        g_string_append_c(ret, ' ');
        pos += start;
        len -= start;
    }
    return g_string_free(ret, FALSE);
}
/**
 * Retrieves the value of the property given by path. The path syntax is must be something like (here expressed as regex)
 * (container)*(property), where container is a slash and the name of a container class (e.g. layers, figures) and
 * property is the name of a simple property of that container.
 *
 * @param name The name of the property.
 * @param index If the property is a list then this is the index into that list.
 * @return A description of the property value and, if the property is simple, the actual value.
 */
TGCVariant CGenericCanvas::propertyGet(const char* name, unsigned int index)
{
  // TODO: check if all properties are properly handled.

  TGCVariant result;

  switch (getContainerID(name))
  {
    case GC_CONTAINER_UNKNOWN:
      {
        switch (getPropertyID(name))
        {
          case GC_PROPERTY_NAME:
            {
              result = utf16ToUtf8(FName);
              
              break;
            };
          case GC_PROPERTY_DESCRIPTION:
            {
              result = "A generic 2D canvas based on OpenGL.";
              
              break;
            };
          case GC_PROPERTY_OWNER:
            {
              // There is no owner for the canvas in the canvas library itself.
              // However we recognize the request for it by returning NULL
              // instead of "unknown property".
              result = 0;

              break;
            };
        };
        break;
      };
    case GC_CONTAINER_LAYERS:
      {
        if (index < FLayers.size())
		  result = FLayers[index];
        break;
      };
    case GC_CONTAINER_VIEWS:
      {
        if (index < FViews.size())
          result = FViews[index];
        break;
      };
    case GC_CONTAINER_MODEL:
      {
        result = FModel;
        break;
      };
  };

  return result;
}
Exemple #3
0
// virtual
bool ImeModule::onConfigure(HWND hwndParent, LANGID langid, REFGUID rguidProfile) {
	// FIXME: this is inefficient. Should we cache known modules?
	LPOLESTR pGuidStr = NULL;
	if (FAILED(::StringFromCLSID(rguidProfile, &pGuidStr)))
		return false;
	std::string guidStr = utf16ToUtf8(pGuidStr);
	CoTaskMemFree(pGuidStr);

	// find the input method module
	std::wstring dirPath = programDir_ + L"\\server\\input_methods";
	std::wstring configTool;
	// scan the dir for lang profile definition files
	WIN32_FIND_DATA findData = { 0 };
	HANDLE hFind = ::FindFirstFile((dirPath + L"\\*").c_str(), &findData);
	if (hFind != INVALID_HANDLE_VALUE) {
		do {
			if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { // this is a subdir
				if (findData.cFileName[0] != '.') {
					std::wstring imejson = dirPath;
					imejson += '\\';
					imejson += findData.cFileName;
					imejson += L"\\ime.json";
					FILE* fp = _wfopen(imejson.c_str(), L"r");
					if (fp) {
						char buf[4096];
						rapidjson::Document json;
						rapidjson::FileReadStream stream(fp, buf, sizeof(buf));
						json.ParseStream(stream);
						fclose(fp);
						if (guidStr == json["guid"].GetString()) {
							// found the language profile
							std::wstring relPath = utf8ToUtf16(json["configTool"].GetString());
							if (!relPath.empty()) {
								configTool = dirPath;
								configTool += '\\';
								configTool += findData.cFileName;
								configTool += '\\';
								configTool += relPath;
							}
							break;
						}
					}
				}
			}
		} while (::FindNextFile(hFind, &findData));
		CloseHandle(hFind);
	}
	if(!configTool.empty())
		::ShellExecuteW(hwndParent, L"open", configTool.c_str(), NULL, NULL, SW_SHOWNORMAL);
	return true;
}
Exemple #4
0
// called when a compartment value is changed
void Client::onCompartmentChanged(const GUID& key) {
	LPOLESTR str = NULL;
	if (SUCCEEDED(::StringFromCLSID(key, &str))) {
		Json::Value req;
		req["method"] = "onCompartmentChanged";
		req["guid"] = utf16ToUtf8(str);
		::CoTaskMemFree(str);

		Json::Value ret;
		sendRequest(req, ret);
		if (handleReply(ret)) {
		}
	}
}
Exemple #5
0
Client::Client(TextService* service, REFIID langProfileGuid):
	textService_(service),
	pipe_(INVALID_HANDLE_VALUE),
	newSeqNum_(0),
	isActivated_(false),
	connectingServerPipe_(false) {

	LPOLESTR guidStr = NULL;
	if (SUCCEEDED(::StringFromCLSID(langProfileGuid, &guidStr))) {
		guid_ = utf16ToUtf8(guidStr);
		transform(guid_.begin(), guid_.end(), guid_.begin(), tolower);  // convert GUID to lwoer case
		::CoTaskMemFree(guidStr);
	}
}
Exemple #6
0
bool Client::onPreservedKey(const GUID& guid) {
	LPOLESTR str = NULL;
	if (SUCCEEDED(::StringFromCLSID(guid, &str))) {
		Json::Value req;
		req["method"] = "onPreservedKey";
		req["guid"] = utf16ToUtf8(str);
		::CoTaskMemFree(str);

		Json::Value ret;
		sendRequest(req, ret);
		if (handleReply(ret)) {
			return ret["return"].asBool();
		}
	}
	return false;
}
// virtual
void SymbolsPropertyPage::onOK() {
	// create the user directory if not exists
	// NOTE: this call will fail in Windows 8 store apps
	// We need a way to create the dir in desktop mode and
	// set proper ACL, so later we can access it inside apps.
	DWORD attributes = ::GetFileAttributesW(userDir_.c_str());
	if(attributes == INVALID_FILE_ATTRIBUTES) {
		// create the directory if it does not exist
		if(::GetLastError() == ERROR_FILE_NOT_FOUND) {
			::CreateDirectoryW(userDir_.c_str(), NULL);
			attributes = ::GetFileAttributesW(userDir_.c_str());
		}
		// make the directory hidden
		if(attributes != INVALID_FILE_ATTRIBUTES && (attributes & FILE_ATTRIBUTE_HIDDEN) == 0)
			::SetFileAttributesW(userDir_.c_str(), attributes|FILE_ATTRIBUTE_HIDDEN);
	}

	// save current settings
	std::wstring filename = userDir_;
	filename +=  L"\\symbols.dat";
	HANDLE file = CreateFile(filename.c_str(), GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, 0, NULL );
	if( file != INVALID_HANDLE_VALUE ) {
		HWND edit = ::GetDlgItem(hwnd_, IDC_EDIT);
		int len = ::GetWindowTextLengthW(edit) + 1;
		wchar_t* buf = new wchar_t[len];
		len = ::GetWindowText(edit, buf, len);
		buf[len] = 0;
		std::string ustr = utf16ToUtf8(buf);
		delete []buf;

		DWORD wsize;
		WriteFile( file, ustr.c_str(), ustr.length(), &wsize, NULL );
		CloseHandle(file);
	}

	PropertyPage::onOK();
}