OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Customize properties window in OOo Writer?

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
doxatesting1
General User
General User


Joined: 23 Oct 2008
Posts: 5

PostPosted: Thu Oct 23, 2008 8:53 pm    Post subject: Customize properties window in OOo Writer? Reply with quote

Hello,

Anybody knows how to remove tab panel by given index as in the properties window, which will pop up when we double click any form control if design mode is set on?

My idea is that:
1. create a window listener which captures the window pop up event.
2. then i can use the event object source to query the pop-up window
3. from the window i manage to get the ui object, e.g. jtabbedpane, or xdialog
4. use the ui object to remove the tab panels by the given index

however, currently i get stuck in step 3 Crying or Very sad . below is my code:

--------------------------------------------------------

//some code omitted here for simplicity, "bean" is my customized OOobean

XWindowPeer windowPeer = (XWindowPeer) UnoRuntime.queryInterface(
XWindowPeer.class, bean.getFrame().getContainerWindow());
XExtendedToolkit extendedToolkit = (XExtendedToolkit) UnoRuntime.queryInterface(
XExtendedToolkit.class, windowPeer.getToolkit());
extendedToolkit.addTopWindowListener(new DoxaWindowListener());

//some code omitted here for simplicity


private class DoxaWindowListener implements XTopWindowListener {

public void windowOpened(EventObject evt) {
System.out.println("window opened");
try {
XAccessible accessible = (XAccessible) UnoRuntime.queryInterface(XAccessible.class, evt.Source);
XAccessibleContext context = accessible.getAccessibleContext();
report(context);
} catch (Exception e) {
e.printStackTrace();
}
}

private void report(XAccessibleContext context) {
try {
System.out.println("[");
System.out.println(context.getAccessibleChildCount());
System.out.println(context.getAccessibleDescription());
System.out.println(context.getAccessibleName());
System.out.println(context.getAccessibleRole());
XAccessibleValue value = (XAccessibleValue) UnoRuntime.queryInterface(XAccessibleValue.class, context);
System.out.println(value);
XAccessibleComponent com = (XAccessibleComponent) UnoRuntime.queryInterface(XAccessibleComponent.class, context);
System.out.print("(" + com.getLocationOnScreen().X);
System.out.print("," + com.getLocationOnScreen().Y);
System.out.print("," + com.getSize().Height);
System.out.println("," + com.getSize().Width + ")");
for (int index = 0; index < context.getAccessibleChildCount(); index++) {
report(context.getAccessibleChild(index).getAccessibleContext());
}
System.out.println("]");
} catch (Exception e) {
e.printStackTrace();
}
}

//other api omitted here for simplicity
}

------------------------------------------------

and the output is

window opened
[
1


21
null
(358,181,376,342)
[
4


40
null
(362,203,350,334)
[
0


40
null
(362,203,0,300)
]
[
0


40
null
(362,553,0,300)
]
[
0


40
null
(362,203,350,0)
]
[
0


40
null
(662,203,350,0)
]
]
]

------------------------------------

Can anybody here give me a clue on how to achieve my goal? Thanks in advance. Very Happy
Back to top
View user's profile Send private message
ms777
Super User
Super User


Joined: 07 Feb 2004
Posts: 1355

PostPosted: Fri Oct 24, 2008 11:34 am    Post subject: Reply with quote

Oops - that was a tough one. But the Accessibility interface is my favorite playground ...

Unfortunately, in OO there seem to be many different ways to implement dialogs. The popup you describe does use a way, which does not allow for modification of the dialog e.g. adding or removing controls.

The workaround: Add an AccessibleEventListener. If you select the unwanted Tab, the listener automatically selects the other one.

Test this in an open writer document, with one push button inserted. Switch to design mode, double click on the button, and then run the Basic code ...

Good luck,

ms777

P.S.: I am still on OO 2.4. Should the dialog have been changed in your version, it won't work. Then, use AnalyzeCreateSxc from http://www.oooforum.org/forum/viewtopic.phtml?p=137570#137570 to identify the PageTabList.


Code:
Global nTabSelected

Sub Main
oWin = GetWindowOpen2("Properties: Button")
oACPageTabList = oWin.AccessibleContext.getAccessibleChild(0).AccessibleContext.getAccessibleChild(4).AccessibleContext.getAccessibleChild(0).AccessibleContext.getAccessibleChild(0).AccessibleContext

oACPageTabList.selectAccessibleChild(0) 'Tab 'General' is Selected now
nTabSelected = 0

oListener = createUnoListener("X_",  "com.sun.star.accessibility.XAccessibleEventListener")
oACPageTabList.com_sun_star_accessibility_XAccessibleEventBroadcaster_addEventListener(oListener)
'AnalyzeCreateSxc(oACPageTabList)
End Sub


sub X_notifyEvent (event as com.sun.star.accessibility.AccessibleEventObject)
  if event.eventId <> com.sun.star.accessibility.AccessibleEventId.SELECTION_CHANGED then
    exit sub
    endif
  nSelected = event.source.getSelectedAccessibleChild ( 0).AccessibleIndexInParent
  if (nSelected<>nTabSelected) then
    if (nSelected = 1) and (nTabSelected=0) then
      nTabSelected = nSelected
      event.source.selectAccessibleChild ( 0)
      endif
    nTabSelected = nSelected
    endif
end sub

sub X_disposing( Source as  com.sun.star.lang.EventObject)
end sub


function GetWindowOpen2(sTitle as String) as Object
oToolkit = Stardesktop.ActiveFrame.ContainerWindow.Toolkit
lCount = oToolkit.TopWindowCount

for k=0 to lCount -1
  oWin = oToolkit.getTopWindow(k)
  if HasUnoInterfaces(oWin, "com.sun.star.accessibility.XAccessible") then
    oAC = oWin.AccessibleContext
    if not IsNull(oAC) then
      if oAC.AccessibleName <> "" then
        oName = oAC.AccessibleName
        if left(oName, len(sTitle)) = sTitle then
          GetWindowOpen2 = oWin
          exit function
          endif
        endif
      endif
    endif
  next k
end function
Back to top
View user's profile Send private message
doxatesting1
General User
General User


Joined: 23 Oct 2008
Posts: 5

PostPosted: Tue Oct 28, 2008 3:52 am    Post subject: Reply with quote

Brilliant!!! Thanks very much in helping me to solve my problem, ms777, you are great! Very Happy

I was just back to office this morning from the public holiday of Deepavali and pleasantly surprised seeing your reply. Wish you Happy Deepavali.

Now i am able to disable the tabs that i do not want in those popup properties windows. My code is given below in Java.Laughing

Code:
//some code omitted here for simplicity, "bean" is my customized OOobean

XWindowPeer windowPeer = (XWindowPeer) UnoRuntime.queryInterface(
XWindowPeer.class, bean.getFrame().getContainerWindow());
XExtendedToolkit extendedToolkit = (XExtendedToolkit) UnoRuntime.queryInterface(
XExtendedToolkit.class, windowPeer.getToolkit());
extendedToolkit.addTopWindowListener(new DoxaWindowListener());

//some code omitted here for simplicity


private class DoxaWindowListener implements XTopWindowListener {

  private DoxaAccessListener listener;
       
  public void windowOpened(EventObject event) {}

  public void windowClosing(EventObject event) {}

  public void windowClosed(EventObject event) {}

  public void windowMinimized(EventObject event) {}

  public void windowNormalized(EventObject event) {}

  public void windowActivated(EventObject event) {
    try {
      XTopWindow win = (XTopWindow) UnoRuntime.queryInterface(XTopWindow.class, event.Source);
      XAccessible accessible = (XAccessible) UnoRuntime.queryInterface(XAccessible.class, win);
      XAccessibleContext context = accessible.getAccessibleContext();
      String name = context.getAccessibleName();
      if (name.startsWith("Properties: ")) {
        context = context.getAccessibleChild(0).getAccessibleContext();
        context = context.getAccessibleChild(4).getAccessibleContext();
        context = context.getAccessibleChild(0).getAccessibleContext();
        context = context.getAccessibleChild(0).getAccessibleContext();
        XAccessibleSelection selection = (XAccessibleSelection) UnoRuntime.queryInterface(XAccessibleSelection.class, context);
        selection.selectAccessibleChild(0);
        XAccessibleEventBroadcaster broadcaster = (XAccessibleEventBroadcaster) UnoRuntime.queryInterface(XAccessibleEventBroadcaster.class, selection);
        listener = new DoxaAccessListener();
        broadcaster.addEventListener(listener);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  public void windowDeactivated(EventObject event) {
    try {
      XTopWindow win = (XTopWindow) UnoRuntime.queryInterface(XTopWindow.class, event.Source);
      XAccessible accessible = (XAccessible) UnoRuntime.queryInterface(XAccessible.class, win);
      XAccessibleContext context = accessible.getAccessibleContext();
      String name = context.getAccessibleName();
      if (name.startsWith("Properties: ")) {
        context = context.getAccessibleChild(0).getAccessibleContext();
        context = context.getAccessibleChild(4).getAccessibleContext();
        context = context.getAccessibleChild(0).getAccessibleContext();
        context = context.getAccessibleChild(0).getAccessibleContext();
        XAccessibleSelection selection = (XAccessibleSelection) UnoRuntime.queryInterface(XAccessibleSelection.class, context);
        XAccessibleEventBroadcaster broadcaster = (XAccessibleEventBroadcaster) UnoRuntime.queryInterface(XAccessibleEventBroadcaster.class, selection);
        broadcaster.removeEventListener(listener);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  public void disposing(EventObject event) {}
}

private class DoxaAccessListener implements XAccessibleEventListener {
       
  private int tabselected = 0;
       
  public void notifyEvent(AccessibleEventObject event) {
    try {
      if (event.EventId == AccessibleEventId.SELECTION_CHANGED) {
        XAccessibleSelection selection = (XAccessibleSelection) UnoRuntime.queryInterface(XAccessibleSelection.class, event.Source);
        int selected = selection.getSelectedAccessibleChild(0).getAccessibleContext().getAccessibleIndexInParent();
        if (tabselected != selected) {
          if (tabselected == 0 && selected != 0) {
            tabselected = selected;
            selection.selectAccessibleChild(0);
          } else {
            tabselected = selected;
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
       
  public void disposing(EventObject event) {}
}


And by the way, is there any means that i can replace the tabs in that properties window with my own one? My boss asked me to do so, since this is a new requirement from end users. Now scratching my head...

I am not supposed to modify the openoffice source code, which is in c++. However, i can freely use Macro/API to customize the dialogs, although i do not know how to do it now. Can you give me a hint? Smile
Back to top
View user's profile Send private message
hemat
Newbie
Newbie


Joined: 14 May 2013
Posts: 1

PostPosted: Tue May 14, 2013 2:26 am    Post subject: Reply with quote

that was quite helpful Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group