1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "PageColumnControl.hxx"
22 #include <PageColumnPopup.hxx>
26 #include <sfx2/bindings.hxx>
27 #include <sfx2/dispatch.hxx>
28 #include <sfx2/viewfrm.hxx>
29 #include <svl/intitem.hxx>
30 #include <svx/pageitem.hxx>
32 namespace sw::sidebar
{
34 PageColumnControl::PageColumnControl(PageColumnPopup
* pControl
, weld::Widget
* pParent
)
35 : WeldToolbarPopup(pControl
->getFrameInterface(), pParent
, "modules/swriter/ui/pagecolumncontrol.ui", "PageColumnControl")
36 , m_xMoreButton(m_xBuilder
->weld_button("moreoptions"))
37 , m_xControl(pControl
)
39 bool bLandscape
= false;
40 if ( SfxViewFrame::Current() )
42 const SfxPoolItem
*pItem
;
43 SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState( SID_ATTR_PAGE
, pItem
);
44 bLandscape
= static_cast<const SvxPageItem
*>(pItem
)->IsLandscape();
49 m_xOneColumn
= m_xBuilder
->weld_button("column1L");
50 m_xTwoColumns
= m_xBuilder
->weld_button("column2L");
51 m_xThreeColumns
= m_xBuilder
->weld_button("column3L");
52 m_xLeft
= m_xBuilder
->weld_button("columnleftL");
53 m_xRight
= m_xBuilder
->weld_button("columnrightL");
57 m_xOneColumn
= m_xBuilder
->weld_button("column1");
58 m_xTwoColumns
= m_xBuilder
->weld_button( "column2");
59 m_xThreeColumns
= m_xBuilder
->weld_button("column3");
60 m_xLeft
= m_xBuilder
->weld_button("columnleft");
61 m_xRight
= m_xBuilder
->weld_button("columnright");
65 m_xTwoColumns
->show();
66 m_xThreeColumns
->show();
70 m_xOneColumn
->connect_clicked( LINK( this, PageColumnControl
, ColumnButtonClickHdl_Impl
) );
71 m_xTwoColumns
->connect_clicked( LINK( this, PageColumnControl
, ColumnButtonClickHdl_Impl
) );
72 m_xThreeColumns
->connect_clicked( LINK( this, PageColumnControl
, ColumnButtonClickHdl_Impl
) );
73 m_xLeft
->connect_clicked( LINK( this, PageColumnControl
, ColumnButtonClickHdl_Impl
) );
74 m_xRight
->connect_clicked( LINK( this, PageColumnControl
, ColumnButtonClickHdl_Impl
) );
76 m_xMoreButton
->connect_clicked( LINK( this, PageColumnControl
, MoreButtonClickHdl_Impl
) );
79 void PageColumnControl::GrabFocus()
81 m_xMoreButton
->grab_focus();
84 PageColumnControl::~PageColumnControl()
88 void PageColumnControl::ExecuteColumnChange( const sal_uInt16 nColumnType
)
90 std::unique_ptr
<SfxInt16Item
> mpPageColumnTypeItem( new SfxInt16Item(SID_ATTR_PAGE_COLUMN
) );
91 mpPageColumnTypeItem
->SetValue( nColumnType
);
92 if ( SfxViewFrame::Current() )
93 SfxViewFrame::Current()->GetBindings().GetDispatcher()->ExecuteList(SID_ATTR_PAGE_COLUMN
,
94 SfxCallMode::RECORD
, { mpPageColumnTypeItem
.get() });
97 IMPL_LINK( PageColumnControl
, ColumnButtonClickHdl_Impl
, weld::Button
&, rButton
, void )
99 if ( &rButton
== m_xOneColumn
.get() )
100 ExecuteColumnChange( 1 );
101 else if ( &rButton
== m_xTwoColumns
.get() )
102 ExecuteColumnChange( 2 );
103 else if ( &rButton
== m_xThreeColumns
.get() )
104 ExecuteColumnChange( 3 );
105 else if ( &rButton
== m_xLeft
.get() )
106 ExecuteColumnChange( 4 );
107 else if ( &rButton
== m_xRight
.get() )
108 ExecuteColumnChange( 5 );
110 m_xControl
->EndPopupMode();
113 IMPL_LINK_NOARG( PageColumnControl
, MoreButtonClickHdl_Impl
, weld::Button
&, void )
115 if ( SfxViewFrame::Current() )
116 SfxViewFrame::Current()->GetBindings().GetDispatcher()->Execute( FN_FORMAT_PAGE_COLUMN_DLG
, SfxCallMode::ASYNCHRON
);
117 m_xControl
->EndPopupMode();
120 } // end of namespace sw::sidebar
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */