Example #1
0
/*!
 * Import graphic for cell background.
 */
void AP_Dialog_FormatFrame::askForGraphicPathName(void)
{
	UT_return_if_fail(m_pApp);
	XAP_Frame * pFrame = m_pApp->getLastFocussedFrame();

	UT_return_if_fail(pFrame);
	XAP_DialogFactory * pDialogFactory
		= static_cast<XAP_DialogFactory *>(pFrame->getDialogFactory());

	UT_return_if_fail(pDialogFactory);
	XAP_Dialog_FileOpenSaveAs * pDialog
		= static_cast<XAP_Dialog_FileOpenSaveAs *>(pDialogFactory->requestDialog(XAP_DIALOG_ID_INSERT_PICTURE));
	UT_return_if_fail (pDialog);

	pDialog->setCurrentPathname(NULL);
	pDialog->setSuggestFilename(false);

	// to fill the file types popup list, we need to convert AP-level
	// ImpGraphic descriptions, suffixes, and types into strings.

	UT_uint32 filterCount = IE_ImpGraphic::getImporterCount();

	const char ** szDescList = static_cast<const char **>(UT_calloc(filterCount + 1, sizeof(char *)));
	const char ** szSuffixList = static_cast<const char **>(UT_calloc(filterCount + 1, sizeof(char *)));
	IEGraphicFileType * nTypeList = (IEGraphicFileType *)
		 UT_calloc(filterCount + 1,	sizeof(IEGraphicFileType));
	UT_uint32 k = 0;

	while (IE_ImpGraphic::enumerateDlgLabels(k, &szDescList[k], &szSuffixList[k], &nTypeList[k]))
		k++;

	pDialog->setFileTypeList(szDescList, szSuffixList, static_cast<const UT_sint32 *>(nTypeList));
	pDialog->runModal(pFrame);

	XAP_Dialog_FileOpenSaveAs::tAnswer ans = pDialog->getAnswer();
	bool bOK = (ans == XAP_Dialog_FileOpenSaveAs::a_OK);

	if (bOK)
	{
		m_sImagePath = pDialog->getPathname();
		UT_sint32 type = pDialog->getFileType();

		// If the number is negative, it's a special type.
		// Some operating systems which depend solely on filename
		// suffixes to identify type (like Windows) will always
		// want auto-detection.
		if (type < 0)
			switch (type)
			{
			case XAP_DIALOG_FILEOPENSAVEAS_FILE_TYPE_AUTO:
				// do some automagical detecting
				m_iGraphicType = IEGFT_Unknown;
				break;
			default:
				// it returned a type we don't know how to handle
				UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN);
			}
		else
			m_iGraphicType = static_cast<IEGraphicFileType>(pDialog->getFileType());
	}

	FREEP(szDescList);
	FREEP(szSuffixList);
	FREEP(nTypeList);

	pDialogFactory->releaseDialog(pDialog);
	if(m_sImagePath.size() == 0)
	{
		return;
	}

	FG_Graphic* pFG = NULL;

	UT_Error errorCode;

	errorCode = IE_ImpGraphic::loadGraphic(m_sImagePath.c_str(), m_iGraphicType, &pFG);
	if(errorCode != UT_OK || !pFG)
	{
		ShowErrorBox(m_sImagePath, errorCode);
		return;
	}

	DELETEP(m_pGraphic);
	DELETEP(m_pImage);
	m_pGraphic = pFG->clone();
	GR_Graphics * pG = m_pFormatFramePreview->getGraphics();

	FV_View * pView = static_cast<FV_View *>(pFrame->getCurrentView());
	UT_return_if_fail(pView && pView->getDocument());

	UT_uint32 uid = pView->getDocument()->getUID(UT_UniqueId::Image); //see Bug 10851
	m_sImagePath.clear();
	m_sImagePath = UT_std_string_sprintf("%d",uid);

    m_pImage = _makeImageForRaster(m_sImagePath, pG, m_pGraphic);

	// draw the preview with the changed properties
	if(m_pFormatFramePreview)
		m_pFormatFramePreview->draw();

}
Example #2
0
// TODO Can we add a feature to the language dialog to restrict the
// languages it offers? de en es fr it no pt
// 
static bool _getTranslationCode(FV_View * pView, std::string & langCode)
{
	XAP_Frame * pFrame = static_cast <XAP_Frame *>(pView->getParentData());
	UT_return_val_if_fail(pFrame,false);

	bool bRet = false;

	pFrame->raise();

	XAP_Dialog_Id id = XAP_DIALOG_ID_LANGUAGE;

	XAP_DialogFactory * pDialogFactory = static_cast<XAP_DialogFactory *>(pFrame->getDialogFactory());

	XAP_Dialog_Language * pDialog = static_cast<XAP_Dialog_Language *>(pDialogFactory->requestDialog(id));
	UT_return_val_if_fail(pDialog, false);

	std::string code;

	PP_PropertyVector props_in;
	if (pView->getCharFormat(props_in))
   	{
		code = PP_getAttribute("lang", props_in);
		if (code.size() >= 2)
	   	{
			code = code.substr(0, 2);
			code += '_';
		}

		pDialog->setLanguageProperty(PP_getAttribute("lang", props_in).c_str());
	}
	// run the dialog 
	pDialog->runModal(pFrame);

	// extract what they did 
	bool bOK = (pDialog->getAnswer() == XAP_Dialog_Language::a_OK);

	if (bOK)
   	{
		const gchar * s;
		if (pDialog->getChangedLangProperty(&s))
	   	{
			std::string changedLang = s;
			if (changedLang.size() >= 2)
		   	{
				changedLang = changedLang.substr(0, 2);
				code += changedLang;
				langCode = code;
				bRet = true;

				// Languages: de en es fr it no pt
				// English -> XXX
				if (langCode == "en_de")
					langCode = "English/German";
				else if (langCode == "en_es")
					langCode = "English/Spanish";
				else if (langCode == "en_fr")
					langCode = "English/French";
				else if (langCode == "en_it")
					langCode = "English/Italian";
				// This combo is not supported
				// else if (langCode == "en_no")
				// langCode = "English/Norwegian";
				else if (langCode == "en_pt")
					langCode = "English/Portuguese";

				// XXX -> English
				else if (langCode == "de_en")
					langCode = "German/English";
				else if (langCode == "es_en")
					langCode = "Spanish/English";
				else if (langCode == "fr_en")
					langCode = "French/English";
				else if (langCode == "it_en")
					langCode = "Italian/English";
				else if (langCode == "no_en")
					langCode = "Norwegian/English";
				else if (langCode == "pt_en")
					langCode = "Portuguese/English";
				else
					langCode = "English/German";
				// bRet = false;
			}
		}
	}

	pDialogFactory->releaseDialog(pDialog);

	return bRet;
}
static bool _getTranslationCode (FV_View * pView, UT_String & langCode)
{
  XAP_Frame * pFrame = static_cast<XAP_Frame *> (pView->getParentData());
  UT_return_val_if_fail(pFrame,false);
  
  bool bRet = false;

  pFrame->raise();
  
  XAP_Dialog_Id id = XAP_DIALOG_ID_LANGUAGE;
  
  XAP_DialogFactory * pDialogFactory
    = static_cast<XAP_DialogFactory *>(pFrame->getDialogFactory());

  XAP_Dialog_Language * pDialog
    = static_cast<XAP_Dialog_Language *>(pDialogFactory->requestDialog(id));
  UT_return_val_if_fail(pDialog,false);

  UT_String code ("en-US");
  
  const gchar ** props_in = NULL;
  if (pView->getCharFormat(&props_in))
    {
      const gchar * xml_code = UT_getAttribute("lang", props_in);
      if ( xml_code )
	{
	  code = xml_code ;
	  if ( code.size() >= 2 )
	    {
	      code = code.substr (0, 2);
	      code += '_';
	    }
	}
      
      pDialog->setLanguageProperty(UT_getAttribute("lang", props_in));
      FREEP(props_in);
    }
  
  // run the dialog  
  pDialog->runModal(pFrame);
  
  // extract what they did  
  bool bOK = (pDialog->getAnswer() == XAP_Dialog_Language::a_OK);
  
  if (bOK)
    {
      const gchar * s;
      if (pDialog->getChangedLangProperty(&s))
	{
	  UT_String changedLang = s;
	  if (changedLang.size() >= 2)
	    {
	      code += changedLang.substr(0, 2);
	      langCode = code;
	      bRet = true;
	    }
	}
    }

  pDialogFactory->releaseDialog(pDialog);

  return bRet;
}