Re: Looking for help for clipboard in Math

2015-06-26 Thread Regina Henschel

Hi Michael (and others who are interested in Math),

Michael Stahl schrieb:

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.


There was nothing which uses the file.


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


No, the file does not exist when the error occurred.



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



With Process Monitor I could see, that there was no error in file access.

I then revert all my changes and add them piece by piece, testing after 
each step. I found, that the error was, that I had added a clipboard 
format in filter/source/config/fragments/types/math_MathML_XML_Math.xcu


I have attached the current version to 
https://bz.apache.org/ooo/show_bug.cgi?id=107734. I still have no 
environment for LibreOffice, so Gerrit is currently no option for me. If 
you nevertheless will have a look at it, that would be nice.


Kind regards
Regina


-
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-23 Thread Regina Henschel

Hi Michael,

and another report:

I found, what I did wrong. I had used GetTree() and not realized, that 
it does not only return a pointer but actually performs a pop.
For text clipboard content I have followed your tip with SvMemoryStream 
and utl::OInputStreamWrapper.
So now I can import from clipboard, if the clipboard is of MIME type 
application/mathml+xml or if it is of type FORMAT_STRING and is 
actually a math-fragment.


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.


Error: An error or a warning has occurred during XML import/export!
Error-Id: 0x60040004
Flags: 6 ERRROR SEVERE
Class: 4 API
Number: 4
Parameters:
Exception-Message: io exception during writing
 From File 
c:/AOO_debugbuild_420/trunk/main/xmloff/source/core/xmlerror.cxx at Line 193


 Error: cached Sequence not written From File 
C:/AOO_debugbuild_420/trunk/main/sax/source/expatwrap/saxwriter.cxx at 
Line 164



Kind regards
Regina


Michael Stahl schrieb:

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 

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-10 Thread Regina Henschel

Hi Michael,

a short status report:

Michael Stahl schrieb:

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.



I have added the MathML format to m_TranslTable and now I get the 
clipboard content. In addition I have added debug outputs for MimeType 
and HumanPresentableName.


With all that I see:

The MathML-content from Microsoft MathInputPanel can be detected in 
clipboard and the stream contains a complete MathML content, so if saved 
to file it would result in a valid MathML file.


The same is true for copying an equation from Microsoft Word 2010. Among 
15 detected clipboard formats, I can get the correct one by using the 
new introduced SOT_FORMATSTR_ID.


The clipboard format from MathCast is not a real MathML content, but it 
is MimeType = text/plain;charset=windows1252 and HumanPresentableName = 
OEM/ANSI Text. So importing that is a different problem and has to wait 
until the import of valid MathML is successful.


For your tips about XML-parsing I need some more time.

Kind regards
Regina

-
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-06 Thread Regina Henschel

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]


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.


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.]






(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;
aClipboardMedium.setStreamToLoadFrom( xStrm, sal_True /*bIsReadOnly*/ );
InsertFrom(aClipboardMedium);


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.


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


I'm still a novice in coding and it might be, that I do basic things wrong.




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.


Kind regards
Regina

-
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



Looking for help for clipboard in Math

2015-06-04 Thread Regina Henschel

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?

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


(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?


(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);

(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?


Kind regards
Regina


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