void *GHOST_DropTargetWin32::getDropDataAsString(IDataObject *pDataObject)
{
	char *tmp_string;
	FORMATETC fmtetc = { CF_UNICODETEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
	STGMEDIUM stgmed;

	// Try unicode first.
	// Check if dataobject supplies the format we want.
	if (pDataObject->QueryGetData(&fmtetc) == S_OK)
	{
		if (pDataObject->GetData(&fmtetc, &stgmed) == S_OK)
		{
			LPCWSTR wstr = (LPCWSTR) ::GlobalLock(stgmed.hGlobal);
			if (!(tmp_string = alloc_utf_8_from_16((wchar_t *)wstr, 0)) )
			{
				::GlobalUnlock(stgmed.hGlobal);
				return NULL;
			}
			// Free memory
			::GlobalUnlock(stgmed.hGlobal);
			::ReleaseStgMedium(&stgmed);
#ifdef GHOST_DEBUG
			::printf("\n<converted droped unicode string>\n%s\n</droped converted unicode string>\n", tmp_string);
#endif // GHOST_DEBUG
			return tmp_string;
		}
	}

	fmtetc.cfFormat = CF_TEXT;

	if (pDataObject->QueryGetData(&fmtetc) == S_OK)
	{
		if (pDataObject->GetData(&fmtetc, &stgmed) == S_OK)
		{
			char *str = (char *)::GlobalLock(stgmed.hGlobal);
			
			tmp_string = (char *)::malloc(::strlen(str) + 1);
			if (!tmp_string)
			{
				::GlobalUnlock(stgmed.hGlobal);
				return NULL;
			}

			if (!::strcpy(tmp_string, str) )
			{
				::free(tmp_string);
				::GlobalUnlock(stgmed.hGlobal);
				return NULL;
			}
			// Free memory
			::GlobalUnlock(stgmed.hGlobal);
			::ReleaseStgMedium(&stgmed);

			return tmp_string;
		}
	}
	
	return NULL;
}
示例#2
0
GHOST_TUns8 *GHOST_SystemWin32::getClipboard(bool selection) const
{
	char *temp_buff;
	
	if (IsClipboardFormatAvailable(CF_UNICODETEXT) && OpenClipboard(NULL) ) {
		wchar_t *buffer;
		HANDLE hData = GetClipboardData(CF_UNICODETEXT);
		if (hData == NULL) {
			CloseClipboard();
			return NULL;
		}
		buffer = (wchar_t *)GlobalLock(hData);
		if (!buffer) {
			CloseClipboard();
			return NULL;
		}
		
		temp_buff = alloc_utf_8_from_16(buffer, 0);
		
		/* Buffer mustn't be accessed after CloseClipboard
		 * it would like accessing free-d memory */
		GlobalUnlock(hData);
		CloseClipboard();
		
		return (GHOST_TUns8 *)temp_buff;
	}
	else if (IsClipboardFormatAvailable(CF_TEXT) && OpenClipboard(NULL) ) {
		char *buffer;
		size_t len = 0;
		HANDLE hData = GetClipboardData(CF_TEXT);
		if (hData == NULL) {
			CloseClipboard();
			return NULL;
		}
		buffer = (char *)GlobalLock(hData);
		if (!buffer) {
			CloseClipboard();
			return NULL;
		}
		
		len = strlen(buffer);
		temp_buff = (char *) malloc(len + 1);
		strncpy(temp_buff, buffer, len);
		temp_buff[len] = '\0';
		
		/* Buffer mustn't be accessed after CloseClipboard
		 * it would like accessing free-d memory */
		GlobalUnlock(hData);
		CloseClipboard();
		
		return (GHOST_TUns8 *)temp_buff;
	}
	else {
		return NULL;
	}
}
void *GHOST_DropTargetWin32::getDropDataAsFilenames(IDataObject *pDataObject)
{
	UINT totfiles, nvalid = 0;
	WCHAR fpath[MAX_PATH];
	char *temp_path;
	GHOST_TStringArray *strArray = NULL;
	FORMATETC fmtetc = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
	STGMEDIUM stgmed;
	HDROP hdrop;

	// Check if dataobject supplies the format we want.
	// Double checking here, first in getGhostType.
	if (pDataObject->QueryGetData(&fmtetc) == S_OK)
	{
		if (pDataObject->GetData(&fmtetc, &stgmed) == S_OK)
		{
			hdrop = (HDROP) ::GlobalLock(stgmed.hGlobal);

			totfiles = ::DragQueryFileW(hdrop, -1, NULL, 0);
			if (!totfiles)
			{
				::GlobalUnlock(stgmed.hGlobal);
				return NULL;
			}

			strArray = (GHOST_TStringArray *) ::malloc(sizeof(GHOST_TStringArray));
			strArray->count = 0;
			strArray->strings = (GHOST_TUns8 **) ::malloc(totfiles * sizeof(GHOST_TUns8 *));

			for (UINT nfile = 0; nfile < totfiles; nfile++)
			{
				if (::DragQueryFileW(hdrop, nfile, fpath, MAX_PATH) > 0)
				{
					if (!(temp_path = alloc_utf_8_from_16(fpath, 0)) )
					{
						continue;
					} 
					// Just ignore paths that could not be converted verbatim.

					strArray->strings[nvalid] = (GHOST_TUns8 *) temp_path;
					strArray->count = nvalid + 1;
					nvalid++;
				}
			}
			// Free up memory.
			::GlobalUnlock(stgmed.hGlobal);
			::ReleaseStgMedium(&stgmed);
			
			return strArray;
		}
	}
	return NULL;
}
示例#4
0
char * u_alloc_getenv(const char *varname)
{
    char * r = 0;
    wchar_t * str;
    UTF16_ENCODE(varname);
    if (varname_16) {
        str = _wgetenv(varname_16);
        r = alloc_utf_8_from_16(str, 0);
    }
    UTF16_UN_ENCODE(varname);

    return r;
}
示例#5
0
int main(int argc, const char **argv)
#endif
{
	bContext *C = CTX_create();
	SYS_SystemHandle syshandle;

#ifndef WITH_PYTHON_MODULE
	bArgs *ba;
#endif

#ifdef WIN32
	wchar_t **argv_16 = CommandLineToArgvW(GetCommandLineW(), &argc);
	int argci = 0;
	char **argv = MEM_mallocN(argc * sizeof(char *), "argv array");
	for (argci = 0; argci < argc; argci++) {
		argv[argci] = alloc_utf_8_from_16(argv_16[argci], 0);
	}
	LocalFree(argv_16);
#endif

#ifdef WITH_PYTHON_MODULE
#ifdef __APPLE__
	environ = *_NSGetEnviron();
#endif

#undef main
	evil_C = C;
#endif



#ifdef WITH_BINRELOC
	br_init(NULL);
#endif

#ifdef WITH_LIBMV
	libmv_initLogging(argv[0]);
#endif

	setCallbacks();
#if defined(__APPLE__) && !defined(WITH_PYTHON_MODULE)
	/* patch to ignore argument finder gives us (pid?) */
	if (argc == 2 && strncmp(argv[1], "-psn_", 5) == 0) {
		extern int GHOST_HACK_getFirstFile(char buf[]);
		static char firstfilebuf[512];

		argc = 1;

		if (GHOST_HACK_getFirstFile(firstfilebuf)) {
			argc = 2;
			argv[1] = firstfilebuf;
		}
	}

#endif

#ifdef __FreeBSD__
	fpsetmask(0);
#endif

	/* initialize path to executable */
	BLI_init_program_path(argv[0]);

	BLI_threadapi_init();

	initglobals();  /* blender.c */

	IMB_init();
	BKE_images_init();

	BKE_brush_system_init();

	BLI_callback_global_init();

#ifdef WITH_GAMEENGINE
	syshandle = SYS_GetSystem();
#else
	syshandle = 0;
#endif

	/* first test for background */
#ifndef WITH_PYTHON_MODULE
	ba = BLI_argsInit(argc, (const char **)argv); /* skip binary path */
	setupArguments(C, ba, &syshandle);

	BLI_argsParse(ba, 1, NULL, NULL);

	if (use_crash_handler) {
		/* after parsing args */
		signal(SIGSEGV, blender_crash_handler);
	}
#else
	G.factory_startup = true;  /* using preferences or user startup makes no sense for py-as-module */
	(void)syshandle;
#endif

#ifdef WITH_FFMPEG
	IMB_ffmpeg_init();
#endif

	/* after level 1 args, this is so playanim skips RNA init */
	RNA_init();

	RE_engines_init();
	init_nodesystem();
	/* end second init */


#if defined(WITH_PYTHON_MODULE) || defined(WITH_HEADLESS)
	G.background = true; /* python module mode ALWAYS runs in background mode (for now) */
#else
	/* for all platforms, even windos has it! */
	if (G.background) {
		signal(SIGINT, blender_esc);  /* ctrl c out bg render */
	}
#endif

	/* background render uses this font too */
	BKE_vfont_builtin_register(datatoc_bfont_pfb, datatoc_bfont_pfb_size);

	/* Initialize ffmpeg if built in, also needed for bg mode if videos are
	 * rendered via ffmpeg */
	sound_init_once();
	
	init_def_material();

	if (G.background == 0) {
#ifndef WITH_PYTHON_MODULE
		BLI_argsParse(ba, 2, NULL, NULL);
		BLI_argsParse(ba, 3, NULL, NULL);
#endif
		WM_init(C, argc, (const char **)argv);

		/* this is properly initialized with user defs, but this is default */
		/* call after loading the startup.blend so we can read U.tempdir */
		BLI_init_temporary_dir(U.tempdir);

#ifdef WITH_SDL
		BLI_setenv("SDL_VIDEODRIVER", "dummy");
#endif
	}
	else {
#ifndef WITH_PYTHON_MODULE
		BLI_argsParse(ba, 3, NULL, NULL);
#endif

		WM_init(C, argc, (const char **)argv);

		/* don't use user preferences temp dir */
		BLI_init_temporary_dir(NULL);
	}
#ifdef WITH_PYTHON
	/**
	 * NOTE: the U.pythondir string is NULL until WM_init() is executed,
	 * so we provide the BPY_ function below to append the user defined
	 * python-dir to Python's sys.path at this point.  Simply putting
	 * WM_init() before #BPY_python_start() crashes Blender at startup.
	 */

	/* TODO - U.pythondir */
#else
	printf("\n* WARNING * - Blender compiled without Python!\nthis is not intended for typical usage\n\n");
#endif
	
	CTX_py_init_set(C, 1);
	WM_keymap_init(C);

#ifdef WITH_FREESTYLE
	/* initialize Freestyle */
	FRS_initialize();
	FRS_set_context(C);
#endif

	/* OK we are ready for it */
#ifndef WITH_PYTHON_MODULE
	BLI_argsParse(ba, 4, load_file, C);
	
	if (G.background == 0) {
		if (!G.file_loaded)
			if (U.uiflag2 & USER_KEEP_SESSION)
				WM_recover_last_session(C, NULL);
	}

#endif

#ifndef WITH_PYTHON_MODULE
	BLI_argsFree(ba);
#endif

#ifdef WIN32
	while (argci) {
		free(argv[--argci]);
	}
	MEM_freeN(argv);
	argv = NULL;
#endif

#ifdef WITH_PYTHON_MODULE
	return 0; /* keep blender in background mode running */
#endif

	if (G.background) {
		/* actually incorrect, but works for now (ton) */
		WM_exit(C);
	}
	else {
		if (G.fileflags & G_FILE_AUTOPLAY) {
			if (G.f & G_SCRIPT_AUTOEXEC) {
				if (WM_init_game(C)) {
					return 0;
				}
			}
			else {
				if (!(G.f & G_SCRIPT_AUTOEXEC_FAIL_QUIET)) {
					G.f |= G_SCRIPT_AUTOEXEC_FAIL;
					BLI_snprintf(G.autoexec_fail, sizeof(G.autoexec_fail), "Game AutoStart");
				}
			}
		}

		if (!G.file_loaded) {
			WM_init_splash(C);
		}
	}

	WM_main(C);

	return 0;
} /* end of int main(argc, argv)	*/