LibreOffice Module sw (master)  1
PageColumnControl.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <memory>
21 #include "PageColumnControl.hxx"
22 #include <PageColumnPopup.hxx>
23 
24 #include <cmdid.h>
25 
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>
31 
32 namespace sw::sidebar {
33 
35  : WeldToolbarPopup(pControl->getFrameInterface(), pParent, "modules/swriter/ui/pagecolumncontrol.ui", "PageColumnControl")
36  , m_xMoreButton(m_xBuilder->weld_button("moreoptions"))
37  , m_xControl(pControl)
38 {
39  bool bLandscape = false;
40  if ( SfxViewFrame::Current() )
41  {
42  const SfxPoolItem *pItem;
43  SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState( SID_ATTR_PAGE, pItem );
44  bLandscape = static_cast<const SvxPageItem*>(pItem)->IsLandscape();
45  }
46 
47  if ( bLandscape )
48  {
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");
54  }
55  else
56  {
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");
62  }
63 
64  m_xOneColumn->show();
65  m_xTwoColumns->show();
66  m_xThreeColumns->show();
67  m_xLeft->show();
68  m_xRight->show();
69 
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 ) );
75 
76  m_xMoreButton->connect_clicked( LINK( this, PageColumnControl, MoreButtonClickHdl_Impl ) );
77 }
78 
80 {
81  m_xMoreButton->grab_focus();
82 }
83 
85 {
86 }
87 
88 void PageColumnControl::ExecuteColumnChange( const sal_uInt16 nColumnType )
89 {
90  std::unique_ptr<SfxInt16Item> mpPageColumnTypeItem( new SfxInt16Item(SID_ATTR_PAGE_COLUMN) );
91  mpPageColumnTypeItem->SetValue( nColumnType );
92  if ( SfxViewFrame::Current() )
94  SfxCallMode::RECORD, { mpPageColumnTypeItem.get() });
95 }
96 
97 IMPL_LINK( PageColumnControl, ColumnButtonClickHdl_Impl, weld::Button&, rButton, void )
98 {
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 );
109 
110  m_xControl->EndPopupMode();
111 }
112 
113 IMPL_LINK_NOARG( PageColumnControl, MoreButtonClickHdl_Impl, weld::Button&, void )
114 {
115  if ( SfxViewFrame::Current() )
117  m_xControl->EndPopupMode();
118 }
119 
120 } // end of namespace sw::sidebar
121 
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
#define SID_ATTR_PAGE_COLUMN
Definition: cmdid.h:859
Reference< XControl > m_xControl
std::unique_ptr< weld::Button > m_xMoreButton
static void ExecuteColumnChange(const sal_uInt16 nColumnType)
IMPL_LINK(PageColumnControl, ColumnButtonClickHdl_Impl, weld::Button &, rButton, void)
PageColumnControl(PageColumnPopup *pControl, weld::Widget *pParent)
std::unique_ptr< weld::Button > m_xThreeColumns
virtual void GrabFocus() override
std::unique_ptr< weld::Button > m_xRight
std::unique_ptr< weld::Button > m_xOneColumn
SfxBindings & GetBindings()
IMPL_LINK_NOARG(PageColumnControl, MoreButtonClickHdl_Impl, weld::Button &, void)
SfxItemState QueryState(sal_uInt16 nSID, const SfxPoolItem *&rpState)
static SfxViewFrame * Current()
#define FN_FORMAT_PAGE_COLUMN_DLG
Definition: cmdid.h:313
std::unique_ptr< weld::Button > m_xLeft
SfxDispatcher * GetDispatcher() const
const SfxPoolItem * Execute(sal_uInt16 nSlot, SfxCallMode nCall=SfxCallMode::SLOT, const SfxPoolItem **pArgs=nullptr, sal_uInt16 nModi=0, const SfxPoolItem **pInternalArgs=nullptr)
std::unique_ptr< weld::Button > m_xTwoColumns
std::unique_ptr< weld::Builder > m_xBuilder