示例#1
0
bool AP_Win32App::handleModelessDialogMessage( MSG * msg )
{
	int iCounter;
	HWND hWnd = NULL;

	// Try to knock off the easy case quickly
	if( m_IdTable[ 0 ].id == -1 )
		return false;

    for( iCounter = 0; iCounter <= NUM_MODELESSID; iCounter++ )
	{
		if( m_IdTable[ iCounter ].id != -1 )
		{
			hWnd = (HWND) m_IdTable[ iCounter ].pDialog->pGetWindowHandle();

			if(!m_bForceAnsi && UT_IsWinNT())
			{
				// Since the message was fetched with GetMessageW,
				// it must be processed with Unicode functions
				if( hWnd && IsDialogMessageW( hWnd, msg ) )
					return true;
			}
			else
			{
				if( hWnd && IsDialogMessage( hWnd, msg ) )
					return true;
			}
		}
		else
			break;
	}

	return false;
}
UT_Error IE_Exp_Text::_writeDocument(void)
{
	// Don't call base method if user cancels encoding dialog
	if (!(!m_bIsEncoded || m_bExplicitlySetEncoding || _doEncodingDialog(m_szEncoding)))
		return UT_SAVE_CANCELLED;

	// TODO If we're going to the clipboard and the OS supports unicode, set encoding.
	// TODO Only supports Windows so far.
	// TODO Should use a finer-grain technique than IsWinNT() since Win98 supports unicode clipboard.
	if (getDocRange())
	{
#ifdef WIN32
		if (UT_IsWinNT())
			_setEncoding(XAP_EncodingManager::get_instance()->getNativeUnicodeEncodingName());
#endif
	}

	m_pListener = _constructListener();
	if (!m_pListener)
		return UT_IE_NOMEMORY;

	if (getDocRange())
		getDoc()->tellListenerSubset(static_cast<PL_Listener *>(m_pListener),getDocRange());
	else
		getDoc()->tellListener(static_cast<PL_Listener *>(m_pListener));
	DELETEP(m_pListener);

	return ((m_error) ? UT_IE_COULDNOTWRITE : UT_OK);
}
示例#3
0
/*!
    copy data to the clipboard; this is what gets called when the user
    presses Ctrl+C
*/
void AP_Win32App::copyToClipboard(PD_DocumentRange * pDocRange, bool /*bUseClipboard*/)
{
	// copy the given subset of the given document to the
	// system clipboard in a variety of formats.
	// MSFT requests that we post them in the order of
	// importance to us (most preserving to most lossy).
	//
	// TODO do we need to put something in .ABW format on the clipboard ??

	AP_Win32FrameImpl * pFrameImp = static_cast<AP_Win32FrameImpl*>(getLastFocussedFrame()->getFrameImpl());
	UT_return_if_fail(pFrameImp);
	
	if (!m_pClipboard->openClipboard(pFrameImp->getHwndDocument()))
		return;

	m_pClipboard->clearClipboard(); // this also gives us the ownership

	// Be smart: always place RTF on clipboard; the
	// remaining formats we will generate on demand.
	// most of the time it will save us creating multiple importers,
	// but when the user requests other than the default format, it
	// will be a little bit more involved
	// Tomas, June 28, 2003.

#ifndef COPY_ON_DEMAND
	_copyFmtToClipboard(pDocRange, AP_CLIPBOARD_RTF);
#else
	// we need to both cache the present doc and put rtf version on
	// the clipboard, because win32 will ask for it immediately;
	// appart from that, the rtf exporter needs some layout info to
	// deal with bidi issues, which means we cannot construct the rtf
	// from the chached doc properly
	_cacheClipboardDoc(pDocRange);
	_copyFmtToClipboard(pDocRange, AP_CLIPBOARD_RTF);
#endif
	
	// TODO Should use a finer-grain technique than IsWinNT()
	// since Win98 supports unicode clipboard.
	if (UT_IsWinNT())
	{
		// put raw unicode text on the clipboard
#ifndef COPY_ON_DEMAND
		_copyFmtToClipboard(pDocRange, AP_CLIPBOARD_TEXTPLAIN_UCS2);
#else
		_indicateFmtToClipboard(AP_CLIPBOARD_TEXTPLAIN_UCS2);
#endif
	}
	else
	{
		// put raw 8bit text on the clipboard
#ifndef COPY_ON_DEMAND
		_copyFmtToClipboard(pDocRange, AP_CLIPBOARD_TEXTPLAIN_8BIT);
#else
		_indicateFmtToClipboard(AP_CLIPBOARD_TEXTPLAIN_8BIT);
#endif
	}

	m_pClipboard->closeClipboard();				// release clipboard lock
}
示例#4
0
/*!
    This function obtains a DC for the default printer
    The caller needs to call DeleteDC when dc is no longer needed.
*/
HDC  UT_GetDefaultPrinterDC()
{
	wchar_t * pPrinterName  = UT_GetDefaultPrinterName();

	if(!pPrinterName || !*pPrinterName)
		return NULL;

	//	HANDLE hPrinter;
	//	if(!OpenPrinter(pPrinterName, &hPrinter, NULL))
	//		return NULL;

	const wchar_t * pDriver = UT_IsWinNT() ? L"WINSPOOL" : NULL;
	HDC hdc = CreateDCW(pDriver, pPrinterName, NULL, NULL);
	g_free(pPrinterName);
	return hdc;
}
示例#5
0
void ev_Win32Keyboard::remapKeyboard(HKL hKeyboardLayout)
{
    char  szCodePage[16];

    if( m_iconv != UT_ICONV_INVALID )
    {
        UT_iconv_close( m_iconv );
        m_iconv = UT_ICONV_INVALID;
    }
    if( hKeyboardLayout != 0 )
    {
        strcpy( szCodePage, "CP" );
        if( GetLocaleInfo( LOWORD( hKeyboardLayout ),
                           LOCALE_IDEFAULTANSICODEPAGE,
                           &szCodePage[2],
                           sizeof( szCodePage ) / sizeof( szCodePage[0] ) - 2 ))
        {
            // Unicode locale?
            // NT-based systems (at least XP) always produce unicode input irrespective of
            // the ANSI locale -- see WM_CHAR on MSDN and bug 9374
            //
            // (It would be more efficient to do the NT test before calling
            // GetLocaleInfo(), but for maintanence reasons it is better here.)

            if( UT_IsWinNT() || !strcmp( szCodePage, "CP0" ) )
            {
                const char *szUCS2Name
                    = XAP_EncodingManager::get_instance()->getNativeUnicodeEncodingName();

                UT_ASSERT(szUCS2Name);
                m_bIsUnicodeInput = true;
                strcpy( szCodePage, szUCS2Name );
            }
            else
                m_bIsUnicodeInput = false;

            UT_DEBUGMSG(("New keyboard codepage: %s\n",szCodePage));

            m_iconv = UT_iconv_open( "UCS-4-INTERNAL", szCodePage );
        }

        m_hKeyboardLayout = hKeyboardLayout;
    }
}
示例#6
0
void GR_Win32CharWidths::setCharWidthsOfRange(HDC hdc, UT_UCSChar c0, UT_UCSChar c1)
{
	if(m_vRanges.getItemCount() == 0)
	{
		_retrieveFontInfo(hdc);
	}
	
	UINT k;
	int w;
#ifdef DEBUG
	DWORD iErrorCode = 0;
#endif

	// Windows NT and Windows 95 support the Unicode Font file. 
	// All of the Unicode glyphs can be rendered if the glyph is found in
	// the font file. However, Windows 95 does  not support the Unicode 
	// characters other than the characters for which the particular codepage
	// of the font file is defined.
	// Reference Microsoft knowledge base:
	// Q145754 - PRB ExtTextOutW or TextOutW Unicode Text Output Is Blank
	if (UT_IsWinNT())
	{
		for (k=c0; k<=c1; k++)
		{
			if(k == 0x200B || k == 0xFEFF || k == UCS_LIGATURE_PLACEHOLDER)
				setWidth(k,0);
			else if(!_doesGlyphExist(k))
			{
				setWidth(k,GR_CW_ABSENT);
			}
			else
			{
				GetCharWidth32W(hdc,k,k,&w);
#ifdef DEBUG
				ABC abc;
				int iRes = GetCharABCWidthsW(hdc,k,k,&abc);
#endif
				// handle overstriking chars here
				UT_uint32 iOver = UT_isOverstrikingChar(k);
				if(!w || iOver != UT_NOT_OVERSTRIKING)
				{
					iOver &= UT_OVERSTRIKING_TYPE;

					if(iOver == UT_OVERSTRIKING_RIGHT)
					{
						w = 0;
					}
					else
					{
						ABC abc;
						UT_DebugOnly<int> iRes = GetCharABCWidthsW(hdc,k,k,&abc);
						UT_ASSERT( iRes );
						

						if(iOver == UT_OVERSTRIKING_LEFT)
						{
							UT_ASSERT( abc.abcB <  GR_OC_MAX_WIDTH);
							w = abc.abcB | GR_OC_LEFT_FLUSHED;
						}
						else
						{
							w = abc.abcB /*+ abc.abcA + abc.abcC*/;
							w = -w;
						}
					}
				}
				
				setWidth(k,w);
			}
		}
	}
	else
	{
		HFONT hFont = (HFONT) GetCurrentObject(hdc, OBJ_FONT);
		LOGFONTW aLogFont;
		UT_DebugOnly<int> iRes = GetObjectW(hFont, sizeof(LOGFONTW), &aLogFont);
		UT_ASSERT(iRes);

		xxx_UT_DEBUGMSG(("gr_Win32Graphics::getCharWidth: extra interchar. spacing %d\n", GetTextCharacterExtra(hdc)));
		
		if(aLogFont.lfCharSet == SYMBOL_CHARSET)
		{
			// Symbol character handling
			for (k=c0; k<=c1; k++)
			{
				if(!_doesGlyphExist(k))
				{
					setWidth(k,GR_CW_ABSENT);
				}
				else
				{
					SIZE Size;
					char str[sizeof(UT_UCSChar)];
					int iConverted = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR) &k, 1,
														 str, sizeof(str), NULL, NULL);
					GetTextExtentPoint32A(hdc, str, iConverted, &Size);
					setWidth(k, Size.cx);
				}
			}
		}
		else
		{
			// Unicode font and default character sets
			for (k=c0; k<=c1; k++)
			{
				if(k == 0x200B || k == 0xFEFF || k == UCS_LIGATURE_PLACEHOLDER)
					setWidth(k,0);
				else if(!_doesGlyphExist(k))
				{
					setWidth(k,GR_CW_ABSENT);
				}
				else
				{
					SIZE Size;
					wchar_t sz1[2];
					sz1[0] = k;
					
					GetTextExtentPoint32W(hdc, sz1, 1, &Size);
					// handle overstriking chars here
					UT_uint32 iOver = UT_isOverstrikingChar(k);
					if(!Size.cx ||  iOver != UT_NOT_OVERSTRIKING)
					{
						iOver &= UT_OVERSTRIKING_TYPE;

						if(iOver == UT_OVERSTRIKING_RIGHT)
						{
							Size.cx = 0;
						}
						else
						{
							ABC abc;
							iRes = GetCharABCWidthsW(hdc,k,k,&abc);

							// I have commented out the assert below,
							// because when the function above is called for
							// the first time, it seems to always
							// return 0, even though it fills the abc
							// structure with reasonable values,
							// Tomas, June 22, 2003
							// UT_ASSERT( iRes );
#ifdef DEBUG
							if(!iRes)
							{
								iErrorCode = GetLastError();
							}
#endif

							if(iOver == UT_OVERSTRIKING_LEFT)
							{
								UT_ASSERT( abc.abcB <  GR_OC_MAX_WIDTH);
								Size.cx = abc.abcB | GR_OC_LEFT_FLUSHED;
							}
							else
							{
								Size.cx = abc.abcB;
								Size.cx = -Size.cx;
							}
						}
					}
				
#ifdef DEBUG
					if(iErrorCode)
					{
						LPVOID lpMsgBuf;
						FormatMessageW( 
									  FORMAT_MESSAGE_ALLOCATE_BUFFER | 
									  FORMAT_MESSAGE_FROM_SYSTEM | 
									  FORMAT_MESSAGE_IGNORE_INSERTS,
									  NULL,
									  iErrorCode,
									  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
									  (LPWSTR) &lpMsgBuf,
									  0,
									  NULL 
									  );
						// Process any inserts in lpMsgBuf.
						// ...
						// Display the string.
						//MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION );
						UT_DEBUGMSG(("char width error: %s\n", lpMsgBuf));
						// Free the buffer.
						LocalFree( lpMsgBuf );
					}
#endif
					setWidth(k,Size.cx);
					xxx_UT_DEBUGMSG(("gr_Win32Graphics::getCharWidths: 0x%x: Size.cx %d\n", k, Size.cx));
				}
			}
		}
	}
}
示例#7
0
bool AP_Win32App::initialize(void)
{
	bool bSuccess = true;
	const char * szUserPrivateDirectory = getUserPrivateDirectory();
	bool bVerified = s_createDirectoryIfNecessary(szUserPrivateDirectory);

	UT_return_val_if_fail (bVerified, false);

	// load the preferences.
	
	m_prefs = new AP_Win32Prefs();
	UT_return_val_if_fail (m_prefs, false);
	
	m_prefs->fullInit();
		   
	// now that preferences are established, let the xap init

	m_pClipboard = new AP_Win32Clipboard();
	UT_return_val_if_fail (m_pClipboard, false);
	   
	m_pEMC = AP_GetEditMethods();
	UT_return_val_if_fail (m_pEMC, false);

	m_pBindingSet = new AP_BindingSet(m_pEMC);
	UT_return_val_if_fail (m_pBindingSet, false);
	
	m_pMenuActionSet = AP_CreateMenuActionSet();
	UT_return_val_if_fail (m_pMenuActionSet,false);

	m_pToolbarActionSet = AP_CreateToolbarActionSet();
	UT_return_val_if_fail (m_pToolbarActionSet,false);

	//////////////////////////////////////////////////////////////////
	// load the dialog and message box strings
	//////////////////////////////////////////////////////////////////
	
	{
		// assume we will be using the builtin set (either as the main
		// set or as the fallback set).
		
		AP_BuiltinStringSet * pBuiltinStringSet = new AP_BuiltinStringSet(this,AP_PREF_DEFAULT_StringSet);
		UT_return_val_if_fail (pBuiltinStringSet, false);
		m_pStringSet = pBuiltinStringSet;

		// see if we should load an alternate set from the disk
		
		const char * szDirectory = NULL;
		const char * szStringSet = NULL;

		if (   (getPrefsValue(AP_PREF_KEY_StringSet,&szStringSet))
			&& (szStringSet)
			&& (*szStringSet)
			&& (g_ascii_strcasecmp(szStringSet,AP_PREF_DEFAULT_StringSet) != 0))
		{
			getPrefsValueDirectory(true,AP_PREF_KEY_StringSetDirectory,&szDirectory);
			UT_return_val_if_fail ((szDirectory) && (*szDirectory), false);

			char * szPathname = (char *)UT_calloc(sizeof(char),strlen(szDirectory)+strlen(szStringSet)+100);
			UT_return_val_if_fail (szPathname, false);

			sprintf(szPathname,"%s%s%s.strings",
					szDirectory,
					((szDirectory[strlen(szDirectory)-1]=='\\') ? "" : "\\"),
					szStringSet);

			AP_DiskStringSet * pDiskStringSet = new AP_DiskStringSet(this);
			UT_return_val_if_fail (pDiskStringSet, false);

			if (pDiskStringSet->loadStringsFromDisk(szPathname))
			{
				pDiskStringSet->setFallbackStringSet(m_pStringSet);
				m_pStringSet = pDiskStringSet;
                UT_Language_updateLanguageNames();
				UT_DEBUGMSG(("Using StringSet [%s]\n",szPathname));
			}
			else
			{
				UT_DEBUGMSG(("Unable to load StringSet [%s] -- using builtin strings instead.\n",szPathname));				
				DELETEP(pDiskStringSet);
			}
				
			g_free(szPathname);
		}
	}

	// AP_App::initilize() calls for us XAP_Win32App::initialize()
	if (! AP_App::initialize())
		return false;

	
	// let various window types register themselves

	if (!AP_Win32Frame::RegisterClass(this))
	{
		UT_DEBUGMSG(("couldn't register class\n"));
		return false;
	}

	//////////////////////////////////////////////////////////////////
	// Initialize the importers/exporters
	//////////////////////////////////////////////////////////////////
	IE_ImpExp_RegisterXP ();

	//////////////////////////////////////////////////////////////////
	// initializes the spell checker.
	//////////////////////////////////////////////////////////////////
	
	{
#if ENABLE_SPELL
		SpellManager::instance();
#endif
	}
	
	
	// Now we have the strings loaded we can populate the field names correctly
	int i;
	
	for (i = 0; fp_FieldTypes[i].m_Type != FPFIELDTYPE_END; i++)
	{
	    (&fp_FieldTypes[i])->m_Desc = m_pStringSet->getValue(fp_FieldTypes[i].m_DescId);
	    UT_DEBUGMSG(("Setting field type desc for type %d, desc=%s\n", fp_FieldTypes[i].m_Type, fp_FieldTypes[i].m_Desc));
	}

	for (i = 0; fp_FieldFmts[i].m_Tag != NULL; i++)
	{
	    (&fp_FieldFmts[i])->m_Desc = m_pStringSet->getValue(fp_FieldFmts[i].m_DescId);
	    UT_DEBUGMSG(("Setting field desc for field %s, desc=%s\n", fp_FieldFmts[i].m_Tag, fp_FieldFmts[i].m_Desc));
	}

    ///////////////////////////////////////////////////////////////////////
    /// Build a labelset so the plugins can add themselves to something ///
    ///////////////////////////////////////////////////////////////////////

	const char * szMenuLabelSetName = NULL;
	if (getPrefsValue( AP_PREF_KEY_StringSet, (const gchar**)&szMenuLabelSetName)
		&& (szMenuLabelSetName) && (*szMenuLabelSetName))
	{
		;
	}
	else
		szMenuLabelSetName = AP_PREF_DEFAULT_StringSet;

	getMenuFactory()->buildMenuLabelSet(szMenuLabelSetName);	
	
	//////////////////////////////////////////////////////////////////
	// Check for necessary DLLs now that we can do localized error messages
	//////////////////////////////////////////////////////////////////

#if 0 /* re-enable once we use unicows again */
	// Ensure that we have Unicows dll
	if (!UT_IsWinNT())
	{
		HMODULE hModule = LoadLibrary("unicows.dll");
		
		if (!hModule)
		{
			UT_String sErr(UT_String_sprintf(m_pStringSet->getValue(AP_STRING_ID_WINDOWS_NEED_UNICOWS),
											 "Unicows"));

			MessageBox(NULL, sErr.c_str(), NULL, MB_OK);

			bSuccess = false;
		}
		else
			FreeLibrary(hModule);
	}
#endif

	// Ensure that common control DLL is loaded
	HINSTANCE hinstCC = LoadLibrary("comctl32.dll");
	UT_return_val_if_fail (hinstCC, false);
	InitCommonControlsEx_fn  pInitCommonControlsEx = NULL;
	if( hinstCC != NULL )
		pInitCommonControlsEx = (InitCommonControlsEx_fn)GetProcAddress( hinstCC, "InitCommonControlsEx" );
	if( pInitCommonControlsEx != NULL )
	{
		INITCOMMONCONTROLSEX icex;
		icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
		icex.dwICC = ICC_COOL_CLASSES | ICC_BAR_CLASSES 	// load the rebar and toolbar
					| ICC_TAB_CLASSES | ICC_UPDOWN_CLASS	// and tab and spin controls
					;
		pInitCommonControlsEx(&icex);
	}
	else
	{
		InitCommonControls();

		UT_String sErr(UT_String_sprintf(m_pStringSet->getValue(AP_STRING_ID_WINDOWS_COMCTL_WARNING),
										 "Unicows"));

		MessageBox(NULL, sErr.c_str(), NULL, MB_OK);
	}

	//////////////////////////////////////////////////////////////////
	// load the all Plugins from the correct directory
	//////////////////////////////////////////////////////////////////

#ifndef DISABLE_BUILTIN_PLUGINS
	abi_register_builtin_plugins();
#endif

	bool bLoadPlugins = true;
	bool bFound = getPrefsValueBool(XAP_PREF_KEY_AutoLoadPlugins,&bLoadPlugins);

	if(bLoadPlugins || !bFound)
	{
		char szPath[PATH_MAX];
		char szPlugin[PATH_MAX];
		_getExeDir( szPath, PATH_MAX);
#ifdef _MSC_VER
		strcat(szPath, "..\\plugins\\*.dll");
#else
		strcat(szPath, "..\\lib\\" PACKAGE "-" ABIWORD_SERIES "\\plugins\\*.dll");
#endif

	    struct _finddata_t cfile;
		long findtag = _findfirst( szPath, &cfile );
		if( findtag != -1 )
		{
			do
			{	
				_getExeDir( szPlugin, PATH_MAX );
#ifdef _MSC_VER
				strcat( szPlugin, "..\\plugins\\" );
#else
				strcat( szPlugin, "..\\lib\\" PACKAGE "-" ABIWORD_SERIES "\\plugins\\" );
#endif
				strcat( szPlugin, cfile.name );
				XAP_ModuleManager::instance().loadModule( szPlugin );
			} while( _findnext( findtag, &cfile ) == 0 );
		}
		_findclose( findtag );

		UT_String pluginName( getUserPrivateDirectory() ); 
		UT_String pluginDir( getUserPrivateDirectory() );
		pluginDir += "\\AbiWord\\plugins\\*.dll";
		findtag = _findfirst( pluginDir.c_str(), &cfile );
		if( findtag != -1 )
		{
			do
			{	
				pluginName = getUserPrivateDirectory();
				pluginName += "\\AbiWord\\plugins\\";
				pluginName += cfile.name;
				XAP_ModuleManager::instance().loadModule( pluginName.c_str() );
			} while( _findnext( findtag, &cfile ) == 0 );
		}
		_findclose( findtag );
	}
	return bSuccess;
}