1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #include "precompiled_sw.hxx"
23 
24 #include "PageColumnControl.hxx"
25 #include "PagePropertyPanel.hxx"
26 #include "PagePropertyPanel.hrc"
27 
28 #include <cmdid.h>
29 #include <swtypes.hxx>
30 
31 #include <svx/sidebar/ValueSetWithTextControl.hxx>
32 #include <sfx2/bindings.hxx>
33 #include <sfx2/dispatch.hxx>
34 
35 namespace sw { namespace sidebar {
36 
PageColumnControl(Window * pParent,PagePropertyPanel & rPanel,const sal_uInt16 nColumnType,const bool bLandscape)37 PageColumnControl::PageColumnControl(
38     Window* pParent,
39     PagePropertyPanel& rPanel,
40     const sal_uInt16 nColumnType,
41     const bool bLandscape )
42     : ::svx::sidebar::PopupControl( pParent, SW_RES(RID_POPUP_SWPAGE_COLUMN) )
43     , mpColumnValueSet( new ::svx::sidebar::ValueSetWithTextControl( ::svx::sidebar::ValueSetWithTextControl::IMAGE_TEXT, this, SW_RES(VS_COLUMN) ) )
44     , maMoreButton( this, SW_RES(CB_COLUMN_MORE) )
45     , mnColumnType( nColumnType )
46     , mrPagePropPanel(rPanel)
47 {
48     mpColumnValueSet->SetStyle( mpColumnValueSet->GetStyle() | WB_3DLOOK | WB_NO_DIRECTSELECT );
49     mpColumnValueSet->SetColor(GetSettings().GetStyleSettings().GetMenuColor());
50 
51     if ( bLandscape )
52     {
53         mpColumnValueSet->AddItem( SW_RES(IMG_ONE_L), 0, SW_RES(STR_ONE), 0 );
54         mpColumnValueSet->AddItem( SW_RES(IMG_TWO_L), 0, SW_RES(STR_TWO), 0 );
55         mpColumnValueSet->AddItem( SW_RES(IMG_THREE_L), 0, SW_RES(STR_THREE), 0 );
56         mpColumnValueSet->AddItem( SW_RES(IMG_LEFT_L), 0, SW_RES(STR_LEFT), 0 );
57         mpColumnValueSet->AddItem( SW_RES(IMG_RIGHT_L), 0, SW_RES(STR_RIGHT), 0 );
58     }
59     else
60     {
61         mpColumnValueSet->AddItem( SW_RES(IMG_ONE), 0, SW_RES(STR_ONE), 0 );
62         mpColumnValueSet->AddItem( SW_RES(IMG_TWO), 0, SW_RES(STR_TWO), 0 );
63         mpColumnValueSet->AddItem( SW_RES(IMG_THREE), 0, SW_RES(STR_THREE), 0 );
64         mpColumnValueSet->AddItem( SW_RES(IMG_LEFT), 0, SW_RES(STR_LEFT), 0 );
65         mpColumnValueSet->AddItem( SW_RES(IMG_RIGHT), 0, SW_RES(STR_RIGHT), 0 );
66     }
67 
68     mpColumnValueSet->SetNoSelection();
69     mpColumnValueSet->SetSelectHdl( LINK(this, PageColumnControl,ImplColumnHdl ) );
70     mpColumnValueSet->Show();
71     mpColumnValueSet->SelectItem( mnColumnType );
72     mpColumnValueSet->Format();
73     mpColumnValueSet->StartSelection();
74 
75     maMoreButton.SetClickHdl( LINK( this, PageColumnControl, MoreButtonClickHdl_Impl ) );
76     maMoreButton.GrabFocus();
77 
78     FreeResource();
79 }
80 
81 
~PageColumnControl(void)82 PageColumnControl::~PageColumnControl(void)
83 {
84     delete mpColumnValueSet;
85 }
86 
87 
IMPL_LINK(PageColumnControl,ImplColumnHdl,void *,pControl)88 IMPL_LINK(PageColumnControl, ImplColumnHdl, void *, pControl)
89 {
90     mpColumnValueSet->SetNoSelection();
91     if ( pControl == mpColumnValueSet )
92     {
93         const sal_uInt32 nColumnType = mpColumnValueSet->GetSelectItemId();
94         if ( nColumnType != mnColumnType )
95         {
96             mnColumnType = nColumnType;
97             mrPagePropPanel.ExecuteColumnChange( mnColumnType );
98         }
99     }
100 
101     mrPagePropPanel.ClosePageColumnPopup();
102     return 0;
103 }
104 
IMPL_LINK(PageColumnControl,MoreButtonClickHdl_Impl,void *,EMPTYARG)105 IMPL_LINK(PageColumnControl, MoreButtonClickHdl_Impl, void *, EMPTYARG)
106 {
107     mrPagePropPanel.GetBindings()->GetDispatcher()->Execute( FN_FORMAT_PAGE_COLUMN_DLG, SFX_CALLMODE_ASYNCHRON );
108 
109     mrPagePropPanel.ClosePageColumnPopup();
110     return 0;
111 }
112 
113 
114 } } // end of namespace sw::sidebar
115 
116