Kaydet (Commit) 7e2b1e92 authored tarafından Caolán McNamara's avatar Caolán McNamara

implement a VclEventBox akin to GtkEventBox and map

rework EventBox to inherit from VclBin and rebase SwFrmCtrlWindow on top of it

Change-Id: I25f037b33bf244d3d39f57bfe11cabfaf992bf1c
üst 397722b5
...@@ -20,10 +20,11 @@ ...@@ -20,10 +20,11 @@
#define _UNOTOOLS_HXX #define _UNOTOOLS_HXX
#include <vcl/button.hxx>
#include <vcl/edit.hxx>
#include <vcl/dialog.hxx> #include <vcl/dialog.hxx>
#include <vcl/fixed.hxx> #include <vcl/fixed.hxx>
#include <vcl/edit.hxx> #include <vcl/layout.hxx>
#include <vcl/button.hxx>
#include <actctrl.hxx> #include <actctrl.hxx>
#include <com/sun/star/frame/XController.hpp> #include <com/sun/star/frame/XController.hpp>
#include <com/sun/star/text/XTextCursor.hpp> #include <com/sun/star/text/XTextCursor.hpp>
...@@ -35,46 +36,11 @@ ...@@ -35,46 +36,11 @@
class SwOneExampleFrame; class SwOneExampleFrame;
//Any Commands an EventBoxHelper receives class SwFrmCtrlWindow : public VclEventBox
//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; SwOneExampleFrame* pExampleFrame;
public: public:
SwFrmCtrlWindow(Window* pParent, WinBits nBits, SwOneExampleFrame* pFrame); SwFrmCtrlWindow(Window* pParent, SwOneExampleFrame* pFrame);
virtual void Command( const CommandEvent& rCEvt ); virtual void Command( const CommandEvent& rCEvt );
virtual Size GetOptimalSize(WindowSizeType eType) const; virtual Size GetOptimalSize(WindowSizeType eType) const;
......
...@@ -65,7 +65,7 @@ SwOneExampleFrame::SwOneExampleFrame( Window& rWin, ...@@ -65,7 +65,7 @@ SwOneExampleFrame::SwOneExampleFrame( Window& rWin,
sal_uInt32 nFlags, sal_uInt32 nFlags,
const Link* pInitializedLink, const Link* pInitializedLink,
String* pURL ) : String* pURL ) :
aTopWindow(&rWin, 0, this), aTopWindow(&rWin, this),
aMenuRes(SW_RES(RES_FRMEX_MENU)), aMenuRes(SW_RES(RES_FRMEX_MENU)),
pModuleView(SW_MOD()->GetView()), pModuleView(SW_MOD()->GetView()),
nStyleFlags(nFlags), nStyleFlags(nFlags),
...@@ -75,7 +75,6 @@ SwOneExampleFrame::SwOneExampleFrame( Window& rWin, ...@@ -75,7 +75,6 @@ SwOneExampleFrame::SwOneExampleFrame( Window& rWin,
if (pURL && pURL->Len()) if (pURL && pURL->Len())
sArgumentURL = *pURL; sArgumentURL = *pURL;
aTopWindow.SetPaintTransparent(sal_True);
aTopWindow.SetPosSizePixel(Point(0, 0), rWin.GetSizePixel()); aTopWindow.SetPosSizePixel(Point(0, 0), rWin.GetSizePixel());
if( pInitializedLink ) if( pInitializedLink )
...@@ -366,7 +365,6 @@ IMPL_LINK( SwOneExampleFrame, TimeoutHdl, Timer*, pTimer ) ...@@ -366,7 +365,6 @@ IMPL_LINK( SwOneExampleFrame, TimeoutHdl, Timer*, pTimer )
uno::Reference< awt::XWindow > xWin( _xControl, uno::UNO_QUERY ); uno::Reference< awt::XWindow > xWin( _xControl, uno::UNO_QUERY );
Size aWinSize(aTopWindow.GetOutputSizePixel()); 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 ); xWin->setPosSize( 0, 0, aWinSize.Width(), aWinSize.Height(), awt::PosSize::SIZE );
// can only be done here - the SFX changes the ScrollBar values // can only be done here - the SFX changes the ScrollBar values
...@@ -517,10 +515,9 @@ IMPL_LINK(SwOneExampleFrame, PopupHdl, Menu*, pMenu ) ...@@ -517,10 +515,9 @@ IMPL_LINK(SwOneExampleFrame, PopupHdl, Menu*, pMenu )
return 0; return 0;
}; };
SwFrmCtrlWindow::SwFrmCtrlWindow(Window* pParent, WinBits nBits, SwFrmCtrlWindow::SwFrmCtrlWindow(Window* pParent, SwOneExampleFrame* pFrame)
SwOneExampleFrame* pFrame) : : VclEventBox(pParent)
EventBox(pParent, nBits), , pExampleFrame(pFrame)
pExampleFrame(pFrame)
{ {
set_expand(true); set_expand(true);
set_fill(true); set_fill(true);
...@@ -528,8 +525,6 @@ SwFrmCtrlWindow::SwFrmCtrlWindow(Window* pParent, WinBits nBits, ...@@ -528,8 +525,6 @@ SwFrmCtrlWindow::SwFrmCtrlWindow(Window* pParent, WinBits nBits,
void SwFrmCtrlWindow::Command( const CommandEvent& rCEvt ) void SwFrmCtrlWindow::Command( const CommandEvent& rCEvt )
{ {
fprintf(stderr, "SwFrmCtrlWindow::Command\n");
switch ( rCEvt.GetCommand() ) switch ( rCEvt.GetCommand() )
{ {
case COMMAND_CONTEXTMENU: case COMMAND_CONTEXTMENU:
...@@ -547,27 +542,16 @@ void SwFrmCtrlWindow::Command( const CommandEvent& rCEvt ) ...@@ -547,27 +542,16 @@ 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 Size SwFrmCtrlWindow::GetOptimalSize(WindowSizeType eType) const
{ {
if (eType == WINDOWSIZE_PREFERRED) if (eType == WINDOWSIZE_PREFERRED)
return LogicToPixel(Size(82, 124), MapMode(MAP_APPFONT)); return LogicToPixel(Size(82, 124), MapMode(MAP_APPFONT));
return Window::GetOptimalSize(eType); return VclEventBox::GetOptimalSize(eType);
} }
void SwFrmCtrlWindow::Resize() void SwFrmCtrlWindow::Resize()
{ {
EventBox::Resize(); VclEventBox::Resize();
pExampleFrame->ClearDocument(true); pExampleFrame->ClearDocument(true);
} }
......
...@@ -529,6 +529,50 @@ private: ...@@ -529,6 +529,50 @@ private:
ScrollBar m_aHScroll; ScrollBar m_aHScroll;
}; };
//Enforces that its children are always the same size as itself.
//Intercepts any Commands intended for its children.
//
//by default the Commands are discarded, inherit from this
//and implement "Command" to get them
class VCL_DLLPUBLIC VclEventBox : public VclBin
{
private:
//Any Commands an EventBoxHelper receives are forwarded to its parent
//The VclEventBox ensures that m_aEventBoxHelper is the
//first child and is transparent, but covers the rest of the children
class EventBoxHelper : public Window
{
public:
EventBoxHelper(Window* pParent)
: Window(pParent, 0)
{
SetSizePixel(pParent->GetSizePixel());
EnableChildTransparentMode();
SetPaintTransparent(true);
SetBackground();
}
virtual void Command(const CommandEvent& rCEvt)
{
GetParent()->Command(rCEvt);
}
};
EventBoxHelper m_aEventBoxHelper;
public:
VclEventBox(Window* pParent)
: VclBin(pParent)
, m_aEventBoxHelper(this)
{
m_aEventBoxHelper.Show();
}
virtual Window *get_child();
virtual const Window *get_child() const;
virtual Size calculateRequisition() const;
virtual void setAllocation(const Size &rAllocation);
virtual void Command(const CommandEvent& rCEvt);
};
// retro-fitting utilities // // retro-fitting utilities //
//Get a Size which is large enough to contain all children with //Get a Size which is large enough to contain all children with
......
...@@ -937,6 +937,10 @@ Window *VclBuilder::makeObject(Window *pParent, const OString &name, const OStri ...@@ -937,6 +937,10 @@ Window *VclBuilder::makeObject(Window *pParent, const OString &name, const OStri
{ {
pWindow = new VclScrolledWindow(pParent); pWindow = new VclScrolledWindow(pParent);
} }
else if (name == "GtkEventBox")
{
pWindow = new VclEventBox(pParent);
}
else if (name == "GtkEntry") else if (name == "GtkEntry")
{ {
pWindow = new Edit(pParent, WB_LEFT|WB_VCENTER|WB_BORDER|WB_3DLOOK); pWindow = new Edit(pParent, WB_LEFT|WB_VCENTER|WB_BORDER|WB_3DLOOK);
......
...@@ -17,7 +17,7 @@ VclContainer::VclContainer(Window *pParent, WinBits nStyle) ...@@ -17,7 +17,7 @@ VclContainer::VclContainer(Window *pParent, WinBits nStyle)
{ {
ImplInit(pParent, nStyle, NULL); ImplInit(pParent, nStyle, NULL);
EnableChildTransparentMode(); EnableChildTransparentMode();
SetPaintTransparent(sal_True); SetPaintTransparent(true);
SetBackground(); SetBackground();
} }
...@@ -1331,6 +1331,53 @@ bool VclScrolledWindow::set_property(const rtl::OString &rKey, const rtl::OStrin ...@@ -1331,6 +1331,53 @@ bool VclScrolledWindow::set_property(const rtl::OString &rKey, const rtl::OStrin
return bRet; return bRet;
} }
const Window *VclEventBox::get_child() const
{
const WindowImpl* pWindowImpl = ImplGetWindowImpl();
assert(pWindowImpl->mpFirstChild == &m_aEventBoxHelper);
return pWindowImpl->mpFirstChild->GetWindow(WINDOW_NEXT);
}
Window *VclEventBox::get_child()
{
return const_cast<Window*>(const_cast<const VclEventBox*>(this)->get_child());
}
void VclEventBox::setAllocation(const Size& rAllocation)
{
Point aChildPos(0, 0);
for (Window *pChild = GetWindow(WINDOW_FIRSTCHILD); pChild; pChild = pChild->GetWindow(WINDOW_NEXT))
{
if (!pChild->IsVisible())
continue;
setLayoutAllocation(*pChild, aChildPos, rAllocation);
}
}
Size VclEventBox::calculateRequisition() const
{
Size aRet(0, 0);
for (const Window* pChild = get_child(); pChild;
pChild = pChild->GetWindow(WINDOW_NEXT))
{
if (!pChild->IsVisible())
continue;
Size aChildSize = getLayoutRequisition(*pChild);
aRet.Width() = std::max(aRet.Width(), aChildSize.Width());
aRet.Height() = std::max(aRet.Height(), aChildSize.Height());
}
return aRet;
}
void VclEventBox::Command(const CommandEvent&)
{
//discard events by default to block them reaching children
}
Size getLegacyBestSizeForChildren(const Window &rWindow) Size getLegacyBestSizeForChildren(const Window &rWindow)
{ {
Rectangle aBounds; Rectangle aBounds;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment