Esempio n. 1
0
void ToolbarView::MessageReceived(BMessage *msg) {
UT_UTF8String ucsText;
	switch (msg->what) {
	case 'ddwn': {
		int32 i, id, item;
		msg->FindInt32("id", &id);
		msg->FindInt32("item", &item);
		
		for (i=0; i<item_count; i++) {
			if (items[i].id == id)
				break;
		}
		if(i >= item_count) {
			return;
		}
		BMenuItem *mnuitem;
		mnuitem = items[i].menu->Menu()->FindMarked();
		//char buffer[255];
		//strcpy(buffer, mnuitem->Label());
		ucsText = mnuitem->Label();
		m_pBeOSToolbar->toolbarEvent(id, ucsText.ucs4_str().ucs4_str(), ucsText.ucs4_str().length());
		break;
	}
		
	default:		
		BView::MessageReceived(msg);
	}
}
bool fp_FieldTableSumCols::calculateValue(void)
{
	FV_View * pView = _getView();
	pf_Frag_Strux* tableSDH= NULL;
	UT_sint32 numRows =0;
	UT_sint32 numCols = 0;
	bUseCurrency = false;
	cCurrency = '$';
	pf_Frag_Strux* sdh = getBlock()->getStruxDocHandle();
	PD_Document * pDoc = getBlock()->getDocument();
	if(pDoc->isPieceTableChanging())
	{
		return false;
	}
	if(getLine() == NULL)
	{
		return false;
	}
	fp_Container * pCol = getLine()->getColumn();
	if(pCol == NULL)
	{
		return false;
	}
	fp_ShadowContainer * pShad =NULL;
	fl_HdrFtrShadow * pShadL = NULL;
	if(pCol->getContainerType() == FP_CONTAINER_COLUMN_SHADOW)
	{
		pShad = static_cast<fp_ShadowContainer *>(pCol);
		pShadL = pShad->getShadow();
	}
	PT_DocPosition pos = pDoc->getStruxPosition(sdh)+1;
	pDoc->getStruxOfTypeFromPosition(pos,PTX_SectionTable,&tableSDH);
	pDoc-> getRowsColsFromTableSDH(tableSDH, pView->isShowRevisions(), pView->getRevisionLevel(), &numRows, &numCols);

	UT_UTF8String sValF;
	if(!pView->isInTable(pos))
	{
		sValF = "???";
		return _setValue(sValF.ucs4_str().ucs4_str());
	}

	fl_CellLayout * pCell = NULL;
	UT_sint32 myLeft,myRight,myTop,myBot;
	pView->getCellParams(pos,&myLeft,&myRight,&myTop,&myBot);
	UT_sint32 col = 0;
	UT_sint32 row = myTop;
	UT_sint32 lastCol = -1;
	double dSum = 0.0;
	for(col = 0; col < numCols; col++)
	{
		pf_Frag_Strux* sdhCell = pDoc->getCellSDHFromRowCol(tableSDH,true,99999,row,col);
		UT_sint32 i = getBlock()->getDocLayout()->getLID();
		fl_ContainerLayout* fmtCell = pDoc->getNthFmtHandle(sdhCell,i);
		pCell = static_cast<fl_CellLayout *>(fmtCell);
		if(pCell->getLeftAttach() == lastCol)
		{
			continue;
		}
		if((pCell->getTopAttach() == myTop) && (pCell->getLeftAttach() == myLeft))
		{
			continue;
		}
		UT_GrowBuf grText;
		pCell->appendTextToBuf(grText);
		if(grText.getLength() == 0)
		{
			fl_ContainerLayout * pC = pCell->getFirstLayout();
			while(pC)
			{
				if(pC->getContainerType() == FL_CONTAINER_BLOCK)
				{
					fl_BlockLayout * pBL = static_cast<fl_BlockLayout *>(pC);
					if(pShadL)
					{
						pBL = static_cast<fl_BlockLayout *>(pShadL->findMatchingContainer(pBL));
					}
					if(pBL == NULL)
					{
						continue;
					}
					fp_Run * pRun = pBL->getFirstRun();
					while(pRun)
					{
						if(pRun->getType() == FPRUN_FIELD)
						{
							fp_FieldRun * pFRun = static_cast<fp_FieldRun *>(pRun);
							const  UT_UCS4Char * szVal = pFRun->getValue(); 
							sValF.clear();
							sValF.appendUCS4(szVal);
							dSum += dGetVal(sValF.utf8_str());
							pRun = NULL;
							pC = NULL;
							break;
						}
						pRun = pRun->getNextRun();
					}
				}
				if(pC)
				{
					pC = pC->getNext();
				}
			}
		}
		else
		{
			sValF.clear();
			sValF.appendUCS4(reinterpret_cast<const UT_UCS4Char *>(grText.getPointer(0)),grText.getLength());
			dSum += dGetVal(sValF.utf8_str());
		}
		lastCol = col;
	}
	sFormatDouble(sValF,dSum);
	return _setValue(sValF.ucs4_str().ucs4_str());
}
gint XAP_UnixDialog_FileOpenSaveAs::previewPicture (void)
{
    UT_ASSERT (m_FC && m_preview);

    UT_ASSERT(XAP_App::getApp());

    const XAP_StringSet * pSS = m_pApp->getStringSet();
    UT_return_val_if_fail( pSS, 0 );

    // attach and clear the area immediately
    GR_UnixCairoAllocInfo ai(m_preview);
    GR_CairoGraphics* pGr =
        (GR_CairoGraphics*) XAP_App::getApp()->newGraphics(ai);

    const gchar * file_name = gtk_file_chooser_get_uri (m_FC);

    GR_Font * fnt = pGr->findFont("Times New Roman",
                                  "normal", "", "normal",
                                  "", "12pt",
                                  pSS->getLanguageName());
    pGr->setFont(fnt);

    UT_UTF8String str;
    pSS->getValueUTF8(XAP_STRING_ID_DLG_IP_No_Picture_Label, str);

    int answer = 0;

    FG_Graphic * pGraphic = 0;
    GR_Image *pImage = NULL;

    double		scale_factor = 0.0;
    UT_sint32     scaled_width,scaled_height;
    UT_sint32     iImageWidth,iImageHeight;

    {
        GR_Painter painter(pGr);
        painter.clearArea(0, 0, pGr->tlu(m_preview->allocation.width), pGr->tlu(m_preview->allocation.height));

        if (!file_name)
        {
            painter.drawChars (str.ucs4_str().ucs4_str(), 0, str.size(), pGr->tlu(12), pGr->tlu(static_cast<int>(m_preview->allocation.height / 2)) - pGr->getFontHeight(fnt)/2);
            goto Cleanup;
        }

        // are we dealing with a file or directory here?
        struct stat st;
        if (!stat (file_name, &st))
        {
            if (!S_ISREG(st.st_mode))
            {
                painter.drawChars (str.ucs4_str().ucs4_str(), 0, str.size(), pGr->tlu(12), pGr->tlu(static_cast<int>(m_preview->allocation.height / 2)) - pGr->getFontHeight(fnt)/2);
                goto Cleanup;
            }
        }

        GsfInput * input = NULL;
        UT_DEBUGMSG(("file_name %s \n",file_name));
        input = UT_go_file_open (file_name, NULL);
        if (!input)
            goto Cleanup;
        char Buf[4097] = "";  // 4096+nul ought to be enough
        UT_uint32 iNumbytes = UT_MIN(4096, gsf_input_size(input));
        gsf_input_read(input, iNumbytes, (guint8 *)(Buf));
        Buf[iNumbytes] = '\0';

        IEGraphicFileType ief = IE_ImpGraphic::fileTypeForContents(Buf,4096);
        if((ief == IEGFT_Unknown) || (ief == IEGFT_Bogus))
        {
            painter.drawChars (str.ucs4_str().ucs4_str(), 0, str.size(), pGr->tlu(12), pGr->tlu(static_cast<int>(m_preview->allocation.height / 2)) - pGr->getFontHeight(fnt)/2);
            g_object_unref (G_OBJECT (input));
            goto Cleanup;
        }
        g_object_unref (G_OBJECT (input));
        input = UT_go_file_open (file_name, NULL);
        size_t num_bytes = gsf_input_size(input);
        UT_Byte * bytes = (UT_Byte *) gsf_input_read(input, num_bytes,NULL );
        if(bytes == NULL)
        {
            painter.drawChars (str.ucs4_str().ucs4_str(), 0, str.size(), pGr->tlu(12), pGr->tlu(static_cast<int>(m_preview->allocation.height / 2)) - pGr->getFontHeight(fnt)/2);
            g_object_unref (G_OBJECT (input));
            goto Cleanup;
        }
        UT_ByteBuf * pBB = new UT_ByteBuf();
        pBB->append(bytes,num_bytes);
        g_object_unref (G_OBJECT (input));
        //
        // OK load the data into a GdkPixbuf
        //
        bool bLoadFailed = false;
        //
        GdkPixbuf * pixbuf = pixbufForByteBuf ( pBB);
        delete pBB;
        if(pixbuf == NULL)
        {
            //
            // Try a fallback loader here.
            //
            painter.drawChars (str.ucs4_str().ucs4_str(), 0, str.size(), pGr->tlu(12), pGr->tlu(static_cast<int>(m_preview->allocation.height / 2)) - pGr->getFontHeight(fnt)/2);
            bLoadFailed = true;
            goto Cleanup;
        }

        pImage = new GR_UnixImage(NULL,pixbuf);

        iImageWidth = gdk_pixbuf_get_width (pixbuf);
        iImageHeight = gdk_pixbuf_get_height (pixbuf);
        if (m_preview->allocation.width >= iImageWidth && m_preview->allocation.height >= iImageHeight)
            scale_factor = 1.0;
        else
            scale_factor = MIN( static_cast<double>(m_preview->allocation.width)/iImageWidth,
                                static_cast<double>(m_preview->allocation.height)/iImageHeight);

        scaled_width  = static_cast<int>(scale_factor * iImageWidth);
        scaled_height = static_cast<int>(scale_factor * iImageHeight);

        static_cast<GR_UnixImage *>(pImage)->scale(scaled_width,scaled_height);
        painter.drawImage(pImage,
                          pGr->tlu(static_cast<int>((m_preview->allocation.width  - scaled_width ) / 2)),
                          pGr->tlu(static_cast<int>((m_preview->allocation.height - scaled_height) / 2)));

        answer = 1;
    }

Cleanup:
    FREEP(file_name);
    DELETEP(pImage);
    DELETEP(pGr);
    DELETEP(pGraphic);

    return answer;
}