[api-dev] Re: Unfocussing a non-modal dialog
Mathias Bauer napisał(a): Zbigniew Banach wrote: As I've said, the setFocus() call comes after the dialog is created and displayed. Is the dialog creation process somehow asynchronous? If so, you could be right that the setFocus() call comes too early. Would I need to set a focus listener or something like that to catch the right moment? At least on some platforms it can be asynchronous. As you seem to use Linux: yes, possible. Yup, that must be it. Now I've run the same code on Linux (Ubuntu) and Windows 2k, and under Windows setFocus() works as expected, while in Linux the focus is not transferred. Guess I'll have to put some Linux-specific hacking exploration on my TODO list :) Thanks for pointing me in the right direction once again, Mathias! Cheers, Zbigniew Banach - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
[api-dev] Re: Unfocussing a non-modal dialog
Hi Mathias, Thanks for your response. I'm astonished to read that a setFocus call at either the ContainerWindow or the ComponentWindow didn't work for you. At least that's what OOo is doing in its own code when it wants to move the focus to a document. Once the dialog is shown (using setVisible()), I've tried calling setFocus() on the document frame's ContainerWindow and ComponentWindow, obtained though calls to XSCRIPTCONTEXT.getDocument().getCurrentController().getFrame(), but to no avail. At first I thought it might be the wrong frame, but it seems there's not much other choice. Perhaps you called it too early, before even your dialog got the focus from the operating system? As I've said, the setFocus() call comes after the dialog is created and displayed. Is the dialog creation process somehow asynchronous? If so, you could be right that the setFocus() call comes too early. Would I need to set a focus listener or something like that to catch the right moment? Any further ideas appreciated :) Zbigniew Banach - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
[api-dev] Re: Cursor Position during DD operation
Hi Sascha, Is there any way to set the ViewCursor to a specified position? It's a TextCursor, so you can use gotoRange() on it, passing some other cursor as the target position. HTH Zbigniew Banach - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
[api-dev] Unfocussing a non-modal dialog
Hello folks, More dialog problems from me, I'm afraid. A quick and (hopefully) easy question today. I've created and displayed a non-modal dialog in the standard way: smgr = XSCRIPTCONTEXT.getComponentContext().ServiceManager ctx = XSCRIPTCONTEXT.getComponentContext() dialogModel = smgr.createInstance( com.sun.star.awt.UnoControlDialogModel) controlContainer = smgr.createInstance( com.sun.star.awt.UnoControlDialog) controlContainer.setModel(dialogModel) toolkit = smgr.createInstanceWithContext( com.sun.star.awt.Toolkit, ctx) controlContainer.createPeer(toolkit, None) controlContainer.setVisible(True) (BTW, I've found that, strangely enough, the setVisible() call is not necessary to display the dialog -- createPeer() already does that). What I want is to display the dialog from Writer and immediately restore focus to the document, so the user can keep typing and use the info in the dialog for reference (it's a glossary, FTW) without having to click the document or Alt+Tab to it. But after creation, the dialog is focussed and I can't find a way to shift focus back to the main document window. I've been examining the frame/window properties and even when the dialog is focussed, the document frame is still reported as the top and active frame, and no combination of setFocus(), toFront(), toBack() etc on the dialog or the document window seems to do the trick. I hope I'm just missing something trivial here, and I'd greatly appreciate a pointer in the right direction. Cheers, Zbigniew Banach - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
[api-dev] Re: Accessing a dialog from the frame hierarchy
Paolo Mantovani napisał(a): First I create and display the dialog in one macro -- pretty standard stuff except that I pass the current frame's container window as the peer: smgr = XSCRIPTCONTEXT.getComponentContext().ServiceManager ctx = XSCRIPTCONTEXT.getComponentContext() dialogModel = smgr.createInstanceWithContext( com.sun.star.awt.UnoControlDialogModel, ctx) dialogModel.Title = FooBar controlContainer = smgr.createInstanceWithContext( com.sun.star.awt.UnoControlDialog, ctx) controlContainer.setModel(dialogModel) toolkit = smgr.createInstanceWithContext( com.sun.star.awt.Toolkit, ctx) containerWin = XSCRIPTCONTEXT.getDocument().getCurrentController() .getFrame().getContainerWindow() controlContainer.createPeer(toolkit, containerWin) controlContainer.setVisible(True) This is the old way, when men were men and created their own AWT-Windows :-) Apart from jokes, is there any reasons for not using the (relatively) new css.awt.DialogProvider ? In this way you could design the dialog in the Starbasic IDE and then recall it from anywhere. Yes, I rather prefer the manly way -- visual IDEs are for wimps :) Actually, I made an initial design decision to create all the dialogs for my app from code exclusively, so I could contain everything in a single file to ease distribution and installation later on. Looking back I'm not so sure it was the best choice, but it works so far, so I'm sticking with it :) That aside, it seems to me that my problem of accessing an open dialog would still apply, regardless of whether the dialog was created in code or instantiated from a ready model using the DialogProvider. Perhaps I can propose an idea for a workaround, see below: --- 8 --- As you can see, the dialog is now attached to a frame that belongs to the frames hierarchy. In this way you can access to your dialog from anywhere in (more or less) this way: (Basic example - adapt to your context) oMyFrame = StarDesktop.findFrame(MyOwnFrame, _ com.sun.star.frame.FrameSearchFlag.GLOBAL) oDialog = oMyFrame.ComponentWindow Paolo, you're the best :) This is exactly what I needed - just had to find someone with a better understanding of the whole UI structure than myself, and who better than you. Thanks a million! And if not, what could I do to get a similar effect (maybe abandon dialogs and create a window some other way)? Of course you can use a TopWindow instead of an UnoDialog this would give you more flexibility but at the cost of some more code lines, especially for the UnoControls management That's why I was reluctant to let go of the UnoDialog-based approach -- it's convenient and pretty intuitive to work with, as it is basically similar to other GUI frameworks I've used previously (Swing, wxWidgets etc.) Thanks for your help, Paolo, this will have me well on my way :) Cheers, Zbigniew Banach - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
[api-dev] Accessing a dialog from the frame hierarchy
Hi everyone, I posted a similar question a few months back, but now I'm more or less running around the same problem. I've done some extra research, so I hope someone will be able to help. I want to create and show a non-modal dialog from one macro (I'm using Python) and once it's open I want to access and modify its controls from another macro. I haven't found a way to store a global reference to the dialog window, so I'm trying to access it through the frame hierarchy. It's almost there, but I'm finally stuck. First I create and display the dialog in one macro -- pretty standard stuff except that I pass the current frame's container window as the peer: smgr = XSCRIPTCONTEXT.getComponentContext().ServiceManager ctx = XSCRIPTCONTEXT.getComponentContext() dialogModel = smgr.createInstanceWithContext( com.sun.star.awt.UnoControlDialogModel, ctx) dialogModel.Title = FooBar controlContainer = smgr.createInstanceWithContext( com.sun.star.awt.UnoControlDialog, ctx) controlContainer.setModel(dialogModel) toolkit = smgr.createInstanceWithContext( com.sun.star.awt.Toolkit, ctx) containerWin = XSCRIPTCONTEXT.getDocument().getCurrentController() .getFrame().getContainerWindow() controlContainer.createPeer(toolkit, containerWin) controlContainer.setVisible(True) Now the dialog is displayed (non-modally, because I used setVisible() instead of execute()), I want to access it via the frame hierarchy from another macro. Using through the same frame's toolkit and going through its TopWindows, in a separate macro I've managed to get hold of what seems to be the dialog's container window (it's the only one with a Title, and it's the same Title as for my dialog): tk = XSCRIPTCONTEXT.getDocument().getCurrentController().getFrame() .getContainerWindow().getToolkit() for i in range(0, tk.getTopWindowCount()): currWin = tk.getTopWindow(i) if Title in dir(currWin) and currWin.Title == FooBar: dialogRef = currWin break (For non-Python speakers, dir() returns a sequence of available attributes). Now dialogRef is an XTopWindow and XDialog, and a call to its getWindows() shows an XWindow and XButton (presumably the dialog window and default close button). However, I can't find a way of getting the dialog model from dialogRef nor its inner XWindow, which is what I really need. So my question: is it at all possible to achieve what I'm doing, i.e. access the controls of an open dialog window through the frame hierarchy? If so, am I going the right way? And if not, what could I do to get a similar effect (maybe abandon dialogs and create a window some other way)? For my original question, Mathias Bauer suggested implementing a singleton UNO service for the dialog, but I was hoping for some simpler way. I'm basically trying to create a glossary window for my app, acting something like the OOo Stylist (non-modal, always-on-top) and fully accessible to macros from the API. Bit long for a question, but it seems to me a useful problem to resolve. Hope someone can help me out here. Thanks in advance, Zbigniew Banach - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
[api-dev] Re: paragraph enumeration causes mysterious cursor movement....
ashok _ napisał(a): Okay,I will do that... is there any other alternative than using getString() to get the text content for the range ? (I guess not... :-( ... ) Well, I don't know if that's what you need, but I've just recently found out you can enumerate the content of the text range. This will give you an enumeration of paragraphs, and for each paragraph you can enumerate portions, whose strings you can then concatenate to get the full string of the range. See Noelson Duarte's 19.09 reply to my own question for a code sample. HTH, Zbigniew Banach - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
[api-dev] Re: Getting the string of a numbered list item
Hi, Because the numbering character and delimiter can be more or less anything (if user-defined), it's impossible to universally strip them off (especially as the delimiter can be omitted). Is there any way of getting just the string? Any help will be greatly appreciated, as I really need this and I've been going in circles with the issue. I think you've to enumerate your Paragraph: '- sub testParaNumberRules doc = thiscomponent texto = doc.getText() enum = texto.createEnumeration() while enum.hasMoreElements() txt = enum.nextElement() nrules = txt.NumberingRules if not IsEmpty(nrules) Then enum2 = txt.createEnumeration() paraString = ' get all TextPortions while enum2.hasMoreElements() portion = enum2.nextElement() paraString = paraString portion.getString() wend print paraString end if wend end sub '- Thanks a lot, I'll look into using this approach! Here's a issue about: http://www.openoffice.org/issues/show_bug.cgi?id=68511 I'm sort of glad it's a bug - I was starting to think there's something wrong with me :) Doesn't look like there's much happening around it, but I've just voted for it anyway. Thanks again for your help. Cheers, Zbigniew Banach - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
[api-dev] Getting the string of a numbered list item
Hi all, Some time ago I posted a question about lists in Writer documents, and I am still having problems. I thought I'd simplify the question and re-post now. How can I get the actual text string of a numbered list item? Calling getString() on a TextCursor or Paragraph returns the numbering character as well, so e.g. foobar--- Paragraph.getString() returns foobar - foobar --- Paragraph.getString() returns foobar 1. foobar --- Paragraph.getString() returns 1.foobar Because the numbering character and delimiter can be more or less anything (if user-defined), it's impossible to universally strip them off (especially as the delimiter can be omitted). Is there any way of getting just the string? Any help will be greatly appreciated, as I really need this and I've been going in circles with the issue. Cheers, Zbigniew Banach - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
[api-dev] Identifying numbered lists
Hi all, I've been looking (unsuccessfully) for a way to determine whether a paragraph in a Writer document is a numbered list. So far I know you can check a com.sun.star.text.Paragraph's NumberingIsNumber property to find out if you're dealing with a list at all, but this property is true both for numbered and bulleted lists. The reason I need to differentiate between a numbered and a bulleted list is that I've got a macro that works on document text fetched using Paragraph.getString(), and for a numbered list I'm getting undesirable results. To illustrate: foobar--- Paragraph.getString() returns foobar - foobar --- Paragraph.getString() returns foobar 1. foobar --- Paragraph.getString() returns 1.foobar My macro relies on the paragraph starting with a certain character sequence, so I need a way of telling whether the paragraph is a numbered list so I can ignore the initial number (though maybe someone knows a way of getting the paragraph text without the number appended -- if so, do tell :)). Any help would be greatly appreciated. Regards, Zbigniew Banach - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
[api-dev] Re: Resetting to default character style
Have you thought of using the DispatchHelper api ? Something like (in basic): dim args(1) as new com.sun.star.beans.PropertyValue args(0).Name = Template args(0).Value = Default args(1).Name = Family args(1).Value = 2 dispatcher.executeDispatch(document, .uno:StyleApply, , 0, args()) Thanks for the suggestion, but after a quick test it seems to me that the style name supplied here (in this case as args(0).Value) still has to be the style name from the UI, which for the default style gets localized (and thus setting Default would only work in an English-based locale). This is the exact same problem I'm having with TextCursor.CharStyleName, so it seems using the dispatch won't help. Other suggestions most welcome :) Cheers, Zbigniew Banach I'm trying to reset the character style in a piece of Writer document text to default from the API (using a Python macro). To illustrate, I've got a com.sun.star.text.TextCursor full of selected text with the character style 'foo' (set earlier via TextCursor.CharStyleName) and I need to reset the selected text character style to default . I've been trying to crack this for a looong while now, but with no luck, so I guess I need professional help now :) The Reference says (section 8.4.1): The office comes with a set of default styles. These styles use programmatic names on the API level. (...) Additionally the built-in styles have two different names: a true object name and an alias that is displayed at the user interface. This is not usually visible in an English OpenOffice.org version, except for the default styles that are named Standard as programmatic name and Default in the user interface. This explains why the CharStyleName property cannot be used to directly set the default style (it only has the localized UI name). Elsewhere (can't remember where), I found the information that the default isn't a proper style, but a feature that simply clears all formatting and styles from the text. So how can I access it from the API? AFAIK TextCursor's only property/method related to character styles is CharStyleName, which in this case is useless. Googling around I've found others had this problem, but I found no answers. So far I'm relying on a hack based on the observation that the default style is always (?) last in the style list accessible via document.getStyleFamilies().getByName(CharacterStyles), but it's hardly elegant and seems asking for trouble. I'd appreciate any help or ideas, as I've been going in circles on this for the last few months. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
[api-dev] Re: Resetting to default character style
Fernand Vanrie napisał(a): you can also use *setAllPropertiesToDefault*(); as a direct change to the selctect text Thanks for the hint -- that set me in the right direction. I just want the character style set to default, so the actual call I need is: textcursor.setPropertyToDefault('CharStyleName') And it works! Thanks a bunch. Cheers, Zbigniew Banach - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
[api-dev] Re: Getting the parent of a dialog
Mathias Bauer napisał(a): The parent is the one you gave to the toolkit when the dialog is constructed. In your case it is obviously None. So it's not surprising that you don't find a parent. :-) Ah, the marvels of copy-and-paste programming. Duh. Thanks a lot for pointing this out, Mathias, I'll try specifying a parent (maybe the Desktop) and see where I go from there :) In case you have one dialog for all macros you want to use you should consider something like a global variable. That works in Basic, don't know about Python. From what I've experienced with Python macros so far it seems that you can't have a global variable value that is persisted between macro calls (but maybe someone can prove me wrong). Cheers, Zbigniew Banach - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]