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 
33 namespace sw { namespace sidebar {
34 
35 PageColumnControl::PageColumnControl(
36     Window* pParent,
37     PagePropertyPanel& rPanel,
38     const sal_uInt16 nColumnType,
39     const bool bLandscape )
40     : ::svx::sidebar::PopupControl( pParent, SW_RES(RID_POPUP_SWPAGE_COLUMN) )
41     , mpColumnValueSet( new ::svx::sidebar::ValueSetWithTextControl( ::svx::sidebar::ValueSetWithTextControl::IMAGE_TEXT, this, SW_RES(VS_COLUMN) ) )
42     , maMoreButton( this, SW_RES(CB_COLUMN_MORE) )
43     , mnColumnType( nColumnType )
44     , mrPagePropPanel(rPanel)
45 {
46     mpColumnValueSet->SetStyle( mpColumnValueSet->GetStyle() | WB_3DLOOK | WB_NO_DIRECTSELECT );
47     mpColumnValueSet->SetColor(GetSettings().GetStyleSettings().GetMenuColor());
48 
49     if ( bLandscape )
50     {
51         mpColumnValueSet->AddItem( SW_RES(IMG_ONE_L), 0, SW_RES(STR_ONE), 0 );
52         mpColumnValueSet->AddItem( SW_RES(IMG_TWO_L), 0, SW_RES(STR_TWO), 0 );
53         mpColumnValueSet->AddItem( SW_RES(IMG_THREE_L), 0, SW_RES(STR_THREE), 0 );
54         mpColumnValueSet->AddItem( SW_RES(IMG_LEFT_L), 0, SW_RES(STR_LEFT), 0 );
55         mpColumnValueSet->AddItem( SW_RES(IMG_RIGHT_L), 0, SW_RES(STR_RIGHT), 0 );
56     }
57     else
58     {
59         mpColumnValueSet->AddItem( SW_RES(IMG_ONE), 0, SW_RES(STR_ONE), 0 );
60         mpColumnValueSet->AddItem( SW_RES(IMG_TWO), 0, SW_RES(STR_TWO), 0 );
61         mpColumnValueSet->AddItem( SW_RES(IMG_THREE), 0, SW_RES(STR_THREE), 0 );
62         mpColumnValueSet->AddItem( SW_RES(IMG_LEFT), 0, SW_RES(STR_LEFT), 0 );
63         mpColumnValueSet->AddItem( SW_RES(IMG_RIGHT), 0, SW_RES(STR_RIGHT), 0 );
64     }
65 
66     mpColumnValueSet->SetNoSelection();
67     mpColumnValueSet->SetSelectHdl( LINK(this, PageColumnControl,ImplColumnHdl ) );
68     mpColumnValueSet->Show();
69     mpColumnValueSet->SelectItem( mnColumnType );
70     mpColumnValueSet->Format();
71     mpColumnValueSet->StartSelection();
72 
73     maMoreButton.SetClickHdl( LINK( this, PageColumnControl, MoreButtonClickHdl_Impl ) );
74     maMoreButton.GrabFocus();
75 
76     FreeResource();
77 }
78 
79 
80 PageColumnControl::~PageColumnControl(void)
81 {
82     delete mpColumnValueSet;
83 }
84 
85 
86 IMPL_LINK(PageColumnControl, ImplColumnHdl, void *, pControl)
87 {
88     mpColumnValueSet->SetNoSelection();
89     if ( pControl == mpColumnValueSet )
90     {
91         const sal_uInt32 nColumnType = mpColumnValueSet->GetSelectItemId();
92         if ( nColumnType != mnColumnType )
93         {
94             mnColumnType = nColumnType;
95             mrPagePropPanel.ExecuteColumnChange( mnColumnType );
96         }
97     }
98 
99     mrPagePropPanel.ClosePageColumnPopup();
100     return 0;
101 }
102 
103 IMPL_LINK(PageColumnControl, MoreButtonClickHdl_Impl, void *, EMPTYARG)
104 {
105     mrPagePropPanel.GetBindings()->GetDispatcher()->Execute( FN_FORMAT_PAGE_COLUMN_DLG, SFX_CALLMODE_ASYNCHRON );
106 
107     mrPagePropPanel.ClosePageColumnPopup();
108     return 0;
109 }
110 
111 
112 } } // end of namespace sw::sidebar
113 
114