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 .
20 #include <svx/svdglue.hxx>
21 #include <svl/intitem.hxx>
22 #include <vcl/toolbox.hxx>
24 #include <strings.hrc>
25 #include <gluectrl.hxx>
26 #include <sdresid.hxx>
29 #include <com/sun/star/frame/XDispatchProvider.hpp>
30 #include <com/sun/star/frame/XFrame.hpp>
32 using namespace ::com::sun::star::uno
;
33 using namespace ::com::sun::star::beans
;
34 using namespace ::com::sun::star::frame
;
36 // at the moment, Joe only supports the methods specified below
37 #define ESCDIR_COUNT 5
38 static const SdrEscapeDirection aEscDirArray
[] =
40 SdrEscapeDirection::SMART
,
41 SdrEscapeDirection::LEFT
,
42 SdrEscapeDirection::RIGHT
,
43 SdrEscapeDirection::TOP
,
44 SdrEscapeDirection::BOTTOM
47 SFX_IMPL_TOOLBOX_CONTROL( SdTbxCtlGlueEscDir
, SfxUInt16Item
)
50 * Constructor for glue point escape direction Listbox
52 GlueEscDirLB::GlueEscDirLB( vcl::Window
* pParent
, const Reference
< XFrame
>& rFrame
) :
53 ListBox( pParent
, WinBits( WB_BORDER
| WB_DROPDOWN
) ),
56 Size
aXSize( GetTextWidth( "X" ), GetTextHeight() );
57 SetSizePixel( Size( aXSize
.Width() * 12, aXSize
.Height() * 10 ) );
62 GlueEscDirLB::~GlueEscDirLB()
67 * Determines the escape direction and sends the corresponding slot
69 void GlueEscDirLB::Select()
71 sal_Int32 nPos
= GetSelectedEntryPos();
72 SfxUInt16Item
aItem( SID_GLUE_ESCDIR
, static_cast<sal_uInt16
>(aEscDirArray
[ nPos
]) );
77 Sequence
< PropertyValue
> aArgs( 1 );
78 aArgs
[0].Name
= "GlueEscapeDirection";
79 aItem
.QueryValue( a
);
81 SfxToolBoxControl::Dispatch( Reference
< XDispatchProvider
>( m_xFrame
->getController(), UNO_QUERY
),
82 ".uno:GlueEscapeDirection",
88 * Fills the Listbox with strings
90 void GlueEscDirLB::Fill()
92 InsertEntry( SdResId( STR_GLUE_ESCDIR_SMART
) );
93 InsertEntry( SdResId( STR_GLUE_ESCDIR_LEFT
) );
94 InsertEntry( SdResId( STR_GLUE_ESCDIR_RIGHT
) );
95 InsertEntry( SdResId( STR_GLUE_ESCDIR_TOP
) );
96 InsertEntry( SdResId( STR_GLUE_ESCDIR_BOTTOM
) );
98 InsertEntry( SdResId( STR_GLUE_ESCDIR_LO ) );
99 InsertEntry( SdResId( STR_GLUE_ESCDIR_LU ) );
100 InsertEntry( SdResId( STR_GLUE_ESCDIR_RO ) );
101 InsertEntry( SdResId( STR_GLUE_ESCDIR_RU ) );
102 InsertEntry( SdResId( STR_GLUE_ESCDIR_HORZ ) );
103 InsertEntry( SdResId( STR_GLUE_ESCDIR_VERT ) );
104 InsertEntry( SdResId( STR_GLUE_ESCDIR_ALL ) );
109 * Constructor for glue point escape direction toolbox control
111 SdTbxCtlGlueEscDir::SdTbxCtlGlueEscDir(
112 sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
& rTbx
) :
113 SfxToolBoxControl( nSlotId
, nId
, rTbx
)
118 * Represents state in the listbox of the controller
120 void SdTbxCtlGlueEscDir::StateChanged( sal_uInt16 nSId
,
121 SfxItemState eState
, const SfxPoolItem
* pState
)
123 if( eState
== SfxItemState::DEFAULT
)
125 GlueEscDirLB
* pGlueEscDirLB
= static_cast<GlueEscDirLB
*> ( GetToolBox().
126 GetItemWindow( GetId() ) );
131 pGlueEscDirLB
->Enable();
132 if ( IsInvalidItem( pState
) )
134 pGlueEscDirLB
->SetNoSelection();
138 SdrEscapeDirection nEscDir
= static_cast<SdrEscapeDirection
>(static_cast<const SfxUInt16Item
*>( pState
)->GetValue());
139 pGlueEscDirLB
->SelectEntryPos( GetEscDirPos( nEscDir
) );
144 pGlueEscDirLB
->Disable();
145 pGlueEscDirLB
->SetNoSelection();
150 SfxToolBoxControl::StateChanged( nSId
, eState
, pState
);
153 VclPtr
<vcl::Window
> SdTbxCtlGlueEscDir::CreateItemWindow( vcl::Window
*pParent
)
155 if( GetSlotId() == SID_GLUE_ESCDIR
)
156 return VclPtr
<GlueEscDirLB
>::Create( pParent
, m_xFrame
).get();
158 return VclPtr
<vcl::Window
>();
162 * Returns position in the array for EscDir (Mapping for Listbox)
164 sal_uInt16
SdTbxCtlGlueEscDir::GetEscDirPos( SdrEscapeDirection nEscDir
)
166 for( sal_uInt16 i
= 0; i
< ESCDIR_COUNT
; i
++ )
168 if( aEscDirArray
[ i
] == nEscDir
)
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */