Re: Looking for help for clipboard in Math

2015-06-23 Thread Michael Stahl
On 23.06.2015 20:46, Regina Henschel wrote:
 But now I have this problem:
 I start module Math with a fresh document, I write a formula into the 
 command window (e.g. a^2+b^2) and then try to save as *.mml.
 I get the errors cited below. I have not used any operations with the 
 clipboard. A build from current trunk does not have this error, so it 
 must be something, which I have introduced. But I do not know, what are 
 possible causes and where to start.
 
 Errormessages:
 
 Locking problem.
 Sharing violation while accessing the object.

this is a problem with file locking that generally only manifests on
Windows: a file has been opened once and is opened a second time; the
second opening fails.  for example, the SvStream class uses file locking
by default.

check for code that opens the file for debug purpose and forgets to
close it, or memory leak of something that contains an open file handle.

or perhaps you have the file open in a text editor?

if it's not obvious try SysInternals Process Monitor, it can trace
system calls and their return values, and even display stack traces of
the calls.

https://technet.microsoft.com/en-us/sysinternals/bb896645.aspx


-
To unsubscribe, e-mail: dev-unsubscr...@openoffice.apache.org
For additional commands, e-mail: dev-h...@openoffice.apache.org



Re: Looking for help for clipboard in Math

2015-06-08 Thread Michael Stahl
On 06.06.2015 22:03, Regina Henschel wrote:
 Hi Michael,
 
 thank-you for looking at my problems.
 
 Michael Stahl schrieb:
 On 05.06.2015 01:44, Regina Henschel wrote:
 Hi all,

 I struggle with the clipboard. My goal is to import MathML in module
 Math from clipboard, similar as it is imported from file. But I'm stuck.
 Therefore some questions:
 [skipped a lot of text]
 
 Helpful comments. Looking around I think, the connection to the OS is 
 done in /main/dtrans/source/win32/
 
 I have found the table m_TranslTable, which refers the SOT_FORMATSTR_IDs 
 from exchange.cxx. I'll try what happens, when I add the MathML format 
 there too. I had already added it in exchange.cxx, but that was not 
 enough to be recognized. [I need some time for that. I will report back, 
 when I have finished.]

that sounds plausible.

 (5)
 I try to use SmViewShell::InsertFrom(SfxMedium rMedium). It seems to
 work, but when the process arrives at SmXMLImport::endDocument(void),
 the node tree is empty.  Any tips, what I might have missed?

 how do you prepare the SfxMedium?  i'm not sure if it requires an actual
 file, or if it can read from an input stream (XInputStream); it probably
 can't read from a Sequencesal_Int8 buffer directly...

 there is a SfxMedium::setStreamToLoadFrom() which looks promising.
 
 I have used:
 
 TransferableDataHelper aDataHelper( 
 TransferableDataHelper::CreateFromSystemClipboard(GetEditWindow()) );
 uno::Reference  io::XInputStream  xStrm;
 aDataHelper.GetInputStream( nId, xStrm );
 SfxMedium* pClipboardMedium = new SfxMedium();
 SfxMedium aClipboardMedium = *pClipboardMedium;

this is probably not a good idea: the aClipboardMedium is now a copy of
pClipboardMedium (using the copy-constructor), so any modification to
aClipboardMedium will not be visible if you use pClipboardMedium.

if you need a pointer, better do it the other way around, and use 
aClipbardMedium when needed.

 aClipboardMedium.setStreamToLoadFrom( xStrm, sal_True /*bIsReadOnly*/ );
 InsertFrom(aClipboardMedium);

oh, nice, the TransferableDataHelper can already get you a stream.

 When I then proof it with
 
 SvStream* pStream = aClipboardMedium.GetInStream();
 ...
 sal_uLong nBytesRead = pStream-Read( aBuffer, nBufferSize );
 printf(%s \n, aBuffer);
 
 I can see, that the stream contains the expected MathML-source in case 
 the clipboard viewer lists the clipboard format application/mathml+xml.

ok, so we can read the data.

do you re-wind the stream with Seek() after this debug output?  perhaps
the import filter reads from the current position, which is going to be
in the middle or at the end of the stream after this.

 In addition I have set the filter by
 
 const SfxFilter* pMathFilter = SfxFilter::GetFilterByName( 
 String::CreateFromAscii(MATHML_XML) );
 aClipboardMedium.SetFilter(pMathFilter);
 
 so that
 
 if ( rFltName.EqualsAscii(MATHML_XML) )
 
 in InsertFrom becomes true

it looks like SmXMLImportWrapper is using the usual xmloff XML-parsing
stuff.

so i would try to check if the root element of the MathML document is
being recognized; set a breakpoint or add a SAL_DEBUG output in the
right CreateChildContext() method...

this is apparently SmXMLImport::CreateContext() - which should create a
SmXMLDocContext_Impl, since there's not going to be a office namespace.

most of the work is going on in the CreateChildContext() and
EndElement() overrides in various child classes of SmXMLImportContext;
basically xmloff maintains a stack of contexts, one for each currently
open XML element; it then calls StartElement() / CreateChildContext() /
EndElement() etc. on the context that is on top of the stack.

this means it's quite annoying to step through the import with a
debugger, since a lot of it is various abstraction layers that are not
very interesting but you still have to step through them; it's best to
set breakpoints in the interesting places and only start stepping into
the lower layers as a last resort if you have no idea why the
interesting place is not reached.

 you can create an input stream from the buffer via SvMemoryStream and
 then wrap that in utl::OInputStreamWrapper.
 
 You mean, it will be possible to use the Unicode-Text? That would 
 help, when copying from Websites. But first I need to solve the problem, 
 that I get no node-tree, and the problem to detect the clipboard correctly.

no, i meant how to convert the clipboard Sequencesal_Int8 to an input
stream, but i missed that TransferableDataHelper::GetInputStream()
already does this for you :)


-
To unsubscribe, e-mail: dev-unsubscr...@openoffice.apache.org
For additional commands, e-mail: dev-h...@openoffice.apache.org



Re: Looking for help for clipboard in Math

2015-06-05 Thread Michael Stahl
On 05.06.2015 01:44, Regina Henschel wrote:
 Hi all,
 
 I struggle with the clipboard. My goal is to import MathML in module 
 Math from clipboard, similar as it is imported from file. But I'm stuck. 
 Therefore some questions:
 
 (1)
 Has someone tried such already and found, that it is not possible?

i have no idea about clipboards or Math, but i'm armed with git grep :)

 (2)
 The comments in file exchange.cxx refer to a document CLIP.SDW. Has 
 someone this document and can provide it?

ehhh i'd not hold my breath on that one :)

 (3)
 I have added a .uno command which is executed in 
 SmViewShell::Execute(SfxRequest rReq)
 
 My current attempt looks like this:
 
 TransferableDataHelper aDataHelper( 
 TransferableDataHelper::CreateFromSystemClipboard(GetEditWindow()) );
 SotFormatStringId nId;
 DataFlavorExVector* pFormats;
 pFormats = aDataHelper.GetDataFlavorExVector();
 DataFlavorExVector::iterator aIter( 
 ((DataFlavorExVector)*pFormats).begin() ),
  aEnd( 
 ((DataFlavorExVector)*pFormats).end() );
 while ( aIter != aEnd )
 {
  nId = (*aIter).mnSotId;
 ...
  aIter++;
 }
 
 I get some nId-values and for some of them I can get a stream and can 
 look at the content. But the clipboard content, which is generated by 
 the Windows program Math Input Control (mip.exe) is not noticed. But I 
 see that the clipboard has a content MathML and a content MathML 
 Presentation using the clipboard viewer Free Clipboard Viewer 2.0. 
 Why do I get no nId for it?

include/sot/exchange.hxx:

struct DataFlavorEx : public ::com::sun::star::datatransfer::DataFlavor

this has a SotClipboardFormatId mnSotId and a string MimeType - how
does the system specifc clipboard data get translated to that...

 (4)
 The numbers I get in nId are those from the list in exchange.cxx, and 
 for application/mathml+xml, which is not listed there, I get the next 
 one following the list. But how can I get the MimeType or the 
 HumanPresentableName for the detected nId? My following try does not 
 work, the strings are empty in all cases:
 
 ::com::sun::star::datatransfer::DataFlavor aFlavor;
 SotExchange::GetFormatDataFlavor( nId, aFlavor ) )
 String sHumanPresentableName(aFlavor.HumanPresentableName);
 String sMimeType(aFlavor.MimeType);

include/sot/formats.hxx: enum class SotClipboardFormatId

there is no MathML in there, but various STARMATH_* ones.

// the point at which we start allocating runtime format IDs
USER_END  = STARWRITERGLOB_8_TEMPLATE

so what you probably have as ID is user-defined, which means we can't
do anything with it really.

it looks like there needs to be some mapping from the OS-specific
clipboard to these office-internal IDs - if there's no ID for MathML it
can't be mapped.

there is a big array in sot/source/base/exchange.cxx, you probably need
to add an entry for MathML there.

the array is ordered and indexed by the SotClipboardFormatId.

/* 48 SotClipboardFormatId::STARMATH_50*/{
application/x-openoffice-starmath-50;windows_formatname=\StarMath
5.0\, StarMath 5.0, cppu::UnoTypeSequencesal_Int8::get() },

that's the mime-type and human-readable name.

i was wondering how this would work on Windows, given that the Win32
clipboard presumably does not use mime-types; apparently the
;windows_formatname=\...\ appendix to the mime-type here covers that.

 (5)
 I try to use SmViewShell::InsertFrom(SfxMedium rMedium). It seems to 
 work, but when the process arrives at SmXMLImport::endDocument(void), 
 the node tree is empty.  Any tips, what I might have missed?

how do you prepare the SfxMedium?  i'm not sure if it requires an actual
file, or if it can read from an input stream (XInputStream); it probably
can't read from a Sequencesal_Int8 buffer directly...

there is a SfxMedium::setStreamToLoadFrom() which looks promising.

you can create an input stream from the buffer via SvMemoryStream and
then wrap that in utl::OInputStreamWrapper.


-
To unsubscribe, e-mail: dev-unsubscr...@openoffice.apache.org
For additional commands, e-mail: dev-h...@openoffice.apache.org