Beispiel #1
0
	NarrowString(const ttstr &str) : _data(NULL) {
		tjs_int len = str.GetNarrowStrLen();
		if (len > 0) {
			_data = new tjs_nchar[len+1];
			str.ToNarrowStr(_data, len+1);
		}
	}
Beispiel #2
0
/*
	these functions do :
	replace each %%, %1, %2 into %, p1, p2.
	%1 must appear only once in the message string, otherwise internal
	buffer will overflow. ( %2 must also so )
*/
ttstr TVPFormatMessage(const tjs_char *msg, const ttstr & p1)
{
	tjs_char *p;
	tjs_char * buf = new tjs_char[TJS_strlen(msg) + p1.GetLen() + 1];
	p = buf;
	for(;*msg;msg++,p++)
	{
		if(*msg == TJS_W('%'))
		{
			if(msg[1] == TJS_W('%'))
			{
				// %%
				*p = TJS_W('%');
				msg++;
				continue;
			}
			else if(msg[1] == TJS_W('1'))
			{
				// %1
				TJS_strcpy(p, p1.c_str());
				p += p1.GetLen();
				p--;
				msg++;
				continue;
			}
		}
		*p = *msg;
	}

	*p = 0;

	ttstr ret(buf);
	delete [] buf;
	return ret;
}
Beispiel #3
0
	static tTVInteger LayerPropGet(iTJSDispatch2 *lay, ttstr &prop, tTVInteger defval = 0) {
		if (!LayerClass) {
			tTJSVariant var;
			TVPExecuteExpression(TJS_W("Layer"), &var);
			LayerClass = var.AsObjectNoAddRef();
		}
		tTJSVariant val;
		return (TJS_FAILED(LayerClass->PropGet(0, prop.c_str(), prop.GetHint(), &val, lay))) ? defval : val.AsInteger();
	}
Beispiel #4
0
// ttstrをUTF8文字列へ変換
std::string convertTtstrToUtf8String(ttstr &buf)
{
  int maxlen = buf.length() * 6 + 1;
  char *dat = new char[maxlen];
  int len = TVPWideCharToUtf8String(buf.c_str(), dat);
  std::string result(dat, len);
  delete[] dat;
  return result;
}
Beispiel #5
0
	/**
	 * パスをローカル化する&末尾の\を削除
	 * @param path パス名
	 */
	static void getLocalName(ttstr &path) {
		TVPGetLocalName(path);
		if (path.GetLastChar() == TJS_W('\\')) {
			tjs_int i,len = path.length();
			tjs_char* tmp = new tjs_char[len];
			const tjs_char* dp = path.c_str();
			for (i=0,len--; i<len; i++) tmp[i] = dp[i];
			tmp[i] = 0;
			path = tmp;
			delete[] tmp;
		}
	}
Beispiel #6
0
	/**
	 * ファイルハンドルを取得
	 * @param filename ファイル名(ローカル名であること)
	 * @param iswrite 読み書き選択
	 * @param out out_isdir ディレクトリかどうか
	 * @return ファイルハンドル
	 */
	static HANDLE _getFileHandle(ttstr const &filename, bool iswrite, bool *out_isdir = 0) {
		DWORD attr = GetFileAttributes(filename.c_str());
		bool isdir = (attr != 0xFFFFFFFF && (attr & FILE_ATTRIBUTE_DIRECTORY));
		if (out_isdir) *out_isdir = isdir;
		HANDLE hFile;
		if (iswrite) {
			hFile = CreateFile(filename.c_str(), GENERIC_WRITE, FILE_SHARE_READ, NULL ,
							   OPEN_EXISTING,    isdir ? FILE_FLAG_BACKUP_SEMANTICS : FILE_ATTRIBUTE_NORMAL , NULL);
		} else {
			hFile = CreateFile(filename.c_str(), isdir ? READ_CONTROL               : GENERIC_READ, FILE_SHARE_READ, NULL ,
							   OPEN_EXISTING,    isdir ? FILE_FLAG_BACKUP_SEMANTICS : FILE_ATTRIBUTE_NORMAL , NULL);
		}
		return hFile;
	}
Beispiel #7
0
bool TVPAcceptSaveAsTLG(void* formatdata, const ttstr & type, class iTJSDispatch2** dic )
{
    bool result = false;
    if( type.StartsWith(TJS_W("tlg")) ) result = true;
    else if( type == TJS_W(".tlg") ) result = true;
    else if( type == TJS_W(".tlg5") ) result = true;
    else if( type == TJS_W(".tlg6") ) result = true;
    if( result && dic ) {
        // mode : select text : opaque, alpha, add, sub, mul, dodge, darken, lighten, screen, addalpha
        //        psnormal, psadd, pssub, psmul, psscreen, psoverlay, pshlight, psslight, psdodge
        //        psdodge5, psburn, pslighten, psdarken, psdiff, psdiff5, psexcl, opaque
        // offs_x : integer
        // offs_y : integer
        // offs_unit : select text : pixel
        tTJSVariant result;
        TVPExecuteExpression(
            TJS_W("(const)%[")
            TJS_W("\"mode\"=>(const)%[\"type\"=>\"select text\",\"items\"=>")
            TJS_W("(const)[\"opaque\", \"alpha\", \"add\", \"sub\", \"mul\", \"dodge\", \"darken\", \"lighten\", \"screen\", \"addalpha\",")
            TJS_W("\"psnormal\", \"psadd\", \"pssub\", \"psmul\", \"psscreen\", \"psoverlay\", \"pshlight\", \"psslight\", \"psdodge\",")
            TJS_W("\"psdodge5\", \"psburn\", \"pslighten\", \"psdarken\", \"psdiff\", \"psdiff5\", \"psexcl\", \"opaque\"],")
            TJS_W("\"desc\"=>\"blending mode\",\"default\"=>\"alpha\"],")

            TJS_W("\"offs_x\"=>(const)%[\"type\"=>\"integer\",\"desc\"=>\"offset x\",\"default\"=>0],")
            TJS_W("\"offs_y\"=>(const)%[\"type\"=>\"integer\",\"desc\"=>\"offset y\",\"default\"=>0],")
            TJS_W("\"offs_unit\"=>(const)%[\"type\"=>\"select text\",\"items\"=>(const)[\"pixel\"],\"desc\"=>\"offset unit\",\"default\"=>\"pixel\"]")
            TJS_W("]"),
            NULL, &result );
        if( result.Type() == tvtObject ) {
            *dic = result.AsObject();
        }
    }
    return result;
}
Beispiel #8
0
static ttstr TVPParseCommandLineOne(const ttstr &i)
{
	// value is specified
	const tjs_char *p, *o;
	p = o = i.c_str();
	p = TJS_strchr(p, '=');

	if(p == NULL) { return i + TJS_W("=yes"); }

	p++;

	ttstr optname(o, p - o);

	if(*p == TJS_W('\'') || *p == TJS_W('\"'))
	{
		// as an escaped string
		tTJSVariant v;
		TJSParseString(v, &p);

		return optname + ttstr(v);
	}
	else
	{
		// as a string
		return optname + p;
	}
}
Beispiel #9
0
	void Deliver()
	{
		if(!TJSIsObjectValid(Target->IsValid(0, NULL, NULL, Target)))
			return; // The target had been invalidated
		tTJSVariant **ArgsPtr = new tTJSVariant*[NumArgs];
		for(tjs_uint i=0; i<NumArgs; i++)
			ArgsPtr[i] = Args + i;
		try
		{
			Target->FuncCall(0, EventName.c_str(), EventName.GetHint(),
				NULL, NumArgs, ArgsPtr,
				Target);
		}
		catch(...)
		{
			delete [] ArgsPtr;
			throw;
		}
		delete [] ArgsPtr;
	}
Beispiel #10
0
//---------------------------------------------------------------------------
// TVPCreateEventObject
//---------------------------------------------------------------------------
iTJSDispatch2 * TVPCreateEventObject(const tjs_char *type,
	iTJSDispatch2 *targthis, iTJSDispatch2 *targ)
{
	// create a dictionary object for event dispatching ( to "action" method )
	iTJSDispatch2 * object = TJSCreateDictionaryObject();

	static ttstr type_name(TJS_W("type"));
	static ttstr target_name(TJS_W("target"));

	{
		tTJSVariant val(type);
		if(TJS_FAILED(object->PropSet(TJS_MEMBERENSURE|TJS_IGNOREPROP,
			type_name.c_str(), type_name.GetHint(), &val, object)))
				TVPThrowInternalError;
	}

	{
		tTJSVariant val(targthis, targ);
		if(TJS_FAILED(object->PropSet(TJS_MEMBERENSURE|TJS_IGNOREPROP,
			target_name.c_str(), target_name.GetHint(), &val, object)))
				TVPThrowInternalError;
	}
	
	return object;
}
Beispiel #11
0
BinaryStream::BinaryStream(const ttstr& name, tjs_uint32 flags)
{
	HRESULT ResultCode = S_OK;
	switch (flags)
	{
	case TJS_BS_READ:
		ResultCode = File.Open(name.c_str(), WinFile::FileRead);
		break;
	case TJS_BS_WRITE:
		ResultCode = File.Open(name.c_str(), WinFile::FileWrite);
		break;
	default:
		MessageBoxW(NULL, L"Flag must be Read-flag or Write-flag", L"Error", MB_OK);
		ExitProcess(-1);
		break;
	}
	if (FAILED(ResultCode))
	{
		MessageBoxW(NULL, L"Failed to craete file", L"Error", MB_OK);
		ExitProcess(-1);
	}
}
Beispiel #12
0
//---------------------------------------------------------------------------
void TVPClipboardSetText(const ttstr & text)
{
	if( ::OpenClipboard(0) ) {
		HGLOBAL ansihandle = NULL;
		HGLOBAL unicodehandle = NULL;
		try {
			// store ANSI string
			std::string ansistr = text.AsNarrowStdString();
			int ansistrlen = (ansistr.length() + 1)*sizeof(char);
			ansihandle = ::GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, ansistrlen);
			if( !ansihandle ) TVPThrowExceptionMessage( TVPFaildClipboardCopy );

			char *mem = (char*)::GlobalLock(ansihandle);
			if(mem) strncpy_s(mem, ansistrlen, ansistr.c_str(),ansistrlen);
			::GlobalUnlock(ansihandle);

			::SetClipboardData( CF_TEXT, ansihandle );
			ansihandle = NULL;

			// store UNICODE string
			unicodehandle = ::GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, (text.GetLen() + 1) * sizeof(tjs_char));
			if(!unicodehandle) TVPThrowExceptionMessage( TVPFaildClipboardCopy );;

			tjs_char *unimem = (tjs_char*)::GlobalLock(unicodehandle);
			if(unimem) TJS_strcpy(unimem, text.c_str());
			::GlobalUnlock(unicodehandle);

			::SetClipboardData( CF_UNICODETEXT, unicodehandle );
			unicodehandle = NULL;
		} catch(...) {
			if(ansihandle) ::GlobalFree(ansihandle);
			if(unicodehandle) ::GlobalFree(unicodehandle);
			::CloseClipboard();
			throw;
		}
		::CloseClipboard();
	}
}
Beispiel #13
0
/*
 * 指定した名前のレイヤの存在チェック
 * @param name パスを含むレイヤ名
 * @param layerIdxRet レイヤインデックス番号を返す
 */
bool
PSD::CheckExistentStorage(const ttstr &filename, int *layerIdxRet)
{
	startStorage();

	// ルート部を取得
	const tjs_char *p = filename.c_str();

	// id指定の場合
	if (wcsncmp(p, L"id/", 3) == 0) {

		p += 3;

		// 拡張子を除去して判定
		const tjs_char *q;
		if (!(q = wcsrchr(p, '/')) && ((q = wcschr(p, '.')) && (wcscmp(q, BMPEXT) == 0))) {
			ttstr name = ttstr(p, q-p);
			q = name.c_str();
			if (checkAllNum(q)) { // 文字混入禁止
				int id = _wtoi(q);
				LayerIdIdxMap::const_iterator n = layerIdIdxMap.find(id);
				if (n != layerIdIdxMap.end()) {
					if (layerIdxRet) *layerIdxRet = n->second;
					return true;
				}
			}
		}

	} else {

		// パスを分離
		ttstr pname, fname;
		// 最後の/を探す
		const tjs_char *q;
		if ((q = wcsrchr(p, '/'))) {
			pname = ttstr(p, q-p+1);
			fname = ttstr(q+1);
		} else {
			return false;
		}

		// 拡張子分離
		ttstr basename;
		p = fname.c_str();
		// 最初の . を探す
		if ((q = wcschr(p, '.')) && (wcscmp(q, BMPEXT) == 0)) {
			basename = ttstr(p, q-p);
		} else {
			return false;
		}

		// 名前を探す
		PathMap::const_iterator n = pathMap.find(pname);
		if (n != pathMap.end()) {
			const NameIdxMap &names = n->second;
			NameIdxMap::const_iterator m = names.find(basename);
			if (m != names.end()) {
				if (layerIdxRet) *layerIdxRet = m->second;
				return true;
			}
		}
	}

	return false;
}
Beispiel #14
0
	SimpleThreadWithMessageWindow(ttstr const &cname, ttstr const &wname, DWORD tout)
		: InheritedClass(tout), messageWindow(0)
	{
		messageWindow = createMessageWindow(cname.c_str(), wname.c_str());
	}
Beispiel #15
0
  // トピックを表示する
  static void displayTopic(ttstr path) {
    HtmlHelp(NULL,
	     path.c_str(),
	     HH_DISPLAY_TOPIC,
	     NULL);
  }