summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2013-01-08 15:05:55 +0000
committerCaolán McNamara <caolanm@redhat.com>2013-01-09 11:40:54 +0000
commitf5391df4548789acf71a45550742a2d3bbb3b7e4 (patch)
tree254a5c3fba35c9b7763d986b35f76046d5400097
parente3ee30f028d449dbad342b18ae26f71f571a8dbd (diff)
rework unotools doc previewer
split the very opaque SwFrmCtrlWindow into an EventBox which works like GtkEventBox, this a) contains a EventBoxHelper window which EventBox ensures is its first child b) EventBox ensures that all its children are the same size as the EventBox c) The EventBoxHelper is transparent and in front of the rest of the children, so its intercepts all commands d) EventBoxHelper forwards command to the EventBox so you can inherit from EventBox and stick a child in there and the upshot is that the child doesn't get Commands, but the class inherited from EventBox gets them instead Change-Id: I783cd6bbd194e28a1744147e8175cba7895158be
-rw-r--r--sw/source/ui/inc/unotools.hxx42
-rw-r--r--sw/source/ui/utlui/unotools.cxx62
2 files changed, 83 insertions, 21 deletions
diff --git a/sw/source/ui/inc/unotools.hxx b/sw/source/ui/inc/unotools.hxx
index e64352565fe4..f82d541aa666 100644
--- a/sw/source/ui/inc/unotools.hxx
+++ b/sw/source/ui/inc/unotools.hxx
@@ -35,13 +35,50 @@
class SwOneExampleFrame;
-class SwFrmCtrlWindow : public Window
+//Any Commands an EventBoxHelper receives
+//are forwarded to its parent
+class EventBoxHelper : public Window
+{
+public:
+ EventBoxHelper(Window* pParent)
+ : Window(pParent, 0)
+ {
+ SetPaintTransparent(true);
+ SetSizePixel(pParent->GetSizePixel());
+ Show();
+ }
+ virtual void Command(const CommandEvent& rCEvt)
+ {
+ GetParent()->Command(rCEvt);
+ }
+};
+
+//Enforces that it is always the same size
+//as its parent. Any Commands it receives
+//it forwards to its parent
+class EventBox : public Window
+{
+private:
+ EventBoxHelper m_aEventBoxHelper;
+public:
+ EventBox(Window* pParent, WinBits nBits)
+ : Window(pParent, nBits)
+ , m_aEventBoxHelper(this)
+ {
+ }
+ virtual void Command( const CommandEvent& rCEvt ) = 0;
+ virtual void Resize();
+};
+
+class SwFrmCtrlWindow : public EventBox
{
SwOneExampleFrame* pExampleFrame;
public:
SwFrmCtrlWindow(Window* pParent, WinBits nBits, SwOneExampleFrame* pFrame);
- virtual void Command( const CommandEvent& rCEvt );
+ virtual void Command( const CommandEvent& rCEvt );
+ virtual Size GetOptimalSize(WindowSizeType eType) const;
+ virtual void Resize();
};
class MenuResource : public Resource
@@ -71,7 +108,6 @@ class SW_DLLPUBLIC SwOneExampleFrame
::com::sun::star::uno::Reference< ::com::sun::star::text::XTextCursor > _xCursor;
SwFrmCtrlWindow aTopWindow;
- Window& rWindow;
Timer aLoadedTimer;
Link aInitializedLink;
diff --git a/sw/source/ui/utlui/unotools.cxx b/sw/source/ui/utlui/unotools.cxx
index 86c0f3f8af2c..8a18caf358de 100644
--- a/sw/source/ui/utlui/unotools.cxx
+++ b/sw/source/ui/utlui/unotools.cxx
@@ -65,20 +65,18 @@ SwOneExampleFrame::SwOneExampleFrame( Window& rWin,
sal_uInt32 nFlags,
const Link* pInitializedLink,
String* pURL ) :
- aTopWindow( rWin.GetParent(), 0, this ),
- rWindow(rWin),
+ aTopWindow(&rWin, 0, this),
aMenuRes(SW_RES(RES_FRMEX_MENU)),
pModuleView(SW_MOD()->GetView()),
nStyleFlags(nFlags),
bIsInitialized(sal_False),
bServiceAvailable(sal_False)
{
- if(pURL && pURL->Len())
+ if (pURL && pURL->Len())
sArgumentURL = *pURL;
aTopWindow.SetPaintTransparent(sal_True);
- aTopWindow.SetPosSizePixel(rWin.GetPosPixel(), rWin.GetSizePixel());
- aTopWindow.SetZOrder( &rWin, WINDOW_ZORDER_FIRST );
+ aTopWindow.SetPosSizePixel(Point(0, 0), rWin.GetSizePixel());
if( pInitializedLink )
aInitializedLink = *pInitializedLink;
@@ -87,7 +85,6 @@ SwOneExampleFrame::SwOneExampleFrame( Window& rWin,
aLoadedTimer.SetTimeoutHdl(LINK(this, SwOneExampleFrame, TimeoutHdl));
aLoadedTimer.SetTimeout(200);
- rWin.Enable(sal_False);
CreateControl();
aTopWindow.Show();
@@ -109,7 +106,7 @@ SwOneExampleFrame::~SwOneExampleFrame()
DisposeControl();
}
-void SwOneExampleFrame::CreateControl()
+void SwOneExampleFrame::CreateControl()
{
if(_xControl.is())
return ;
@@ -120,15 +117,15 @@ void SwOneExampleFrame::CreateControl()
_xControl = uno::Reference< awt::XControl >(xInst, uno::UNO_QUERY);
if(_xControl.is())
{
- uno::Reference< awt::XWindowPeer > xParent( rWindow.GetComponentInterface() );
+ uno::Reference< awt::XWindowPeer > xParent( aTopWindow.GetComponentInterface() );
uno::Reference< awt::XToolkit > xToolkit( awt::Toolkit::create(xContext), uno::UNO_QUERY_THROW );
_xControl->createPeer( xToolkit, xParent );
uno::Reference< awt::XWindow > xWin( _xControl, uno::UNO_QUERY );
- xWin->setVisible( sal_False );
- Size aWinSize(rWindow.GetOutputSizePixel());
+ xWin->setVisible(sal_False);
+ Size aWinSize(aTopWindow.GetOutputSizePixel());
xWin->setPosSize( 0, 0, aWinSize.Width(), aWinSize.Height(), awt::PosSize::SIZE );
uno::Reference< beans::XPropertySet > xPrSet(xInst, uno::UNO_QUERY);
@@ -342,24 +339,25 @@ IMPL_LINK( SwOneExampleFrame, TimeoutHdl, Timer*, pTimer )
xPProp->setPropertyValue(rtl::OUString::createFromAscii(SW_PROP_NAME_STR(UNO_NAME_RIGHT_MARGIN)), aZero);
}
+ uno::Reference< awt::XWindow > xWin( _xControl, uno::UNO_QUERY );
+ Size aWinSize(aTopWindow.GetOutputSizePixel());
+ fprintf(stderr, "size %ld %ld\n", aWinSize.Width(), aWinSize.Height());
+ xWin->setPosSize( 0, 0, aWinSize.Width(), aWinSize.Height(), awt::PosSize::SIZE );
+
// can only be done here - the SFX changes the ScrollBar values
xViewProps->setPropertyValue(rtl::OUString::createFromAscii(SW_PROP_NAME_STR(UNO_NAME_SHOW_HORI_SCROLL_BAR )), aFalseSet);
xViewProps->setPropertyValue(rtl::OUString::createFromAscii(SW_PROP_NAME_STR(UNO_NAME_SHOW_VERT_SCROLL_BAR )), aFalseSet);
- if( aInitializedLink.IsSet() )
- {
- rWindow.Enable(sal_False, sal_True);
- aInitializedLink.Call(this);
- }
+ if (aInitializedLink.IsSet())
+ aInitializedLink.Call(this);
uno::Reference< text::XTextViewCursorSupplier > xCrsrSupp(_xController, uno::UNO_QUERY);
uno::Reference< view::XScreenCursor > xScrCrsr(xCrsrSupp->getViewCursor(), uno::UNO_QUERY);
if(xScrCrsr.is())
xScrCrsr->screenUp();
- uno::Reference< awt::XWindow > xWin( _xControl, uno::UNO_QUERY );
xWin->setVisible( sal_True );
- rWindow.Show();
+ aTopWindow.Show();
if( xTunnel.is() )
{
@@ -497,13 +495,17 @@ IMPL_LINK(SwOneExampleFrame, PopupHdl, Menu*, pMenu )
SwFrmCtrlWindow::SwFrmCtrlWindow(Window* pParent, WinBits nBits,
SwOneExampleFrame* pFrame) :
- Window(pParent, nBits),
+ EventBox(pParent, nBits),
pExampleFrame(pFrame)
{
+ set_expand(true);
+ set_fill(true);
}
void SwFrmCtrlWindow::Command( const CommandEvent& rCEvt )
{
+ fprintf(stderr, "SwFrmCtrlWindow::Command\n");
+
switch ( rCEvt.GetCommand() )
{
case COMMAND_CONTEXTMENU:
@@ -521,6 +523,30 @@ void SwFrmCtrlWindow::Command( const CommandEvent& rCEvt )
}
}
+void EventBox::Resize()
+{
+ fprintf(stderr, "EventBox::Resize\n");
+ Size aSize(GetSizePixel());
+ for (Window *pChild = GetWindow(WINDOW_FIRSTCHILD); pChild; pChild = pChild->GetWindow(WINDOW_NEXT))
+ {
+ pChild->SetSizePixel(aSize);
+ fprintf(stderr, "child %p\n", pChild);
+ }
+}
+
+Size SwFrmCtrlWindow::GetOptimalSize(WindowSizeType eType) const
+{
+ if (eType == WINDOWSIZE_PREFERRED)
+ return LogicToPixel(Size(82, 124), MapMode(MAP_APPFONT));
+ return Window::GetOptimalSize(eType);
+}
+
+void SwFrmCtrlWindow::Resize()
+{
+ EventBox::Resize();
+ pExampleFrame->ClearDocument(true);
+}
+
MenuResource::MenuResource(const ResId& rResId) :
Resource(rResId),
aMenuArray(ResId(1,*rResId.GetResMgr()))