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
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 #include <svx/frmdirlbox.hxx>
27
28 namespace svx {
29
30 // ============================================================================
31
32 namespace {
33
lclEnumToVoid(SvxFrameDirection eDirection)34 inline void* lclEnumToVoid( SvxFrameDirection eDirection )
35 {
36 return reinterpret_cast< void* >( static_cast< sal_uInt32 >( eDirection ) );
37 }
38
lclVoidToEnum(void * pDirection)39 inline SvxFrameDirection lclVoidToEnum( void* pDirection )
40 {
41 return static_cast< SvxFrameDirection >( reinterpret_cast< sal_IntPtr >( pDirection ) );
42 }
43
44 } // namespace
45
46 // ============================================================================
47
FrameDirectionListBox(Window * pParent,WinBits nStyle)48 FrameDirectionListBox::FrameDirectionListBox( Window* pParent, WinBits nStyle ) :
49 ListBox( pParent, nStyle )
50 {
51 }
52
FrameDirectionListBox(Window * pParent,const ResId & rResId)53 FrameDirectionListBox::FrameDirectionListBox( Window* pParent, const ResId& rResId ) :
54 ListBox( pParent, rResId )
55 {
56 }
57
~FrameDirectionListBox()58 FrameDirectionListBox::~FrameDirectionListBox()
59 {
60 }
61
InsertEntryValue(const String & rString,SvxFrameDirection eDirection,sal_uInt16 nPos)62 void FrameDirectionListBox::InsertEntryValue( const String& rString, SvxFrameDirection eDirection, sal_uInt16 nPos )
63 {
64 sal_uInt16 nRealPos = InsertEntry( rString, nPos );
65 SetEntryData( nRealPos, lclEnumToVoid( eDirection ) );
66 }
67
RemoveEntryValue(SvxFrameDirection eDirection)68 void FrameDirectionListBox::RemoveEntryValue( SvxFrameDirection eDirection )
69 {
70 sal_uInt16 nPos = GetEntryPos( lclEnumToVoid( eDirection ) );
71 if( nPos != LISTBOX_ENTRY_NOTFOUND )
72 RemoveEntry( nPos );
73 }
74
SelectEntryValue(SvxFrameDirection eDirection)75 void FrameDirectionListBox::SelectEntryValue( SvxFrameDirection eDirection )
76 {
77 sal_uInt16 nPos = GetEntryPos( lclEnumToVoid( eDirection ) );
78 if( nPos == LISTBOX_ENTRY_NOTFOUND )
79 SetNoSelection();
80 else
81 SelectEntryPos( nPos );
82 }
83
GetSelectEntryValue() const84 SvxFrameDirection FrameDirectionListBox::GetSelectEntryValue() const
85 {
86 sal_uInt16 nPos = GetSelectEntryPos();
87 if( nPos == LISTBOX_ENTRY_NOTFOUND )
88 return static_cast< SvxFrameDirection >( 0xFFFF );
89 return lclVoidToEnum( GetEntryData( nPos ) );
90 }
91
92 // ============================================================================
93
FrameDirListBoxWrapper(FrameDirListBox & rListBox)94 FrameDirListBoxWrapper::FrameDirListBoxWrapper( FrameDirListBox& rListBox ) :
95 SingleControlWrapperType( rListBox )
96 {
97 }
98
IsControlDontKnow() const99 bool FrameDirListBoxWrapper::IsControlDontKnow() const
100 {
101 return GetControl().GetSelectEntryCount() == 0;
102 }
103
SetControlDontKnow(bool bSet)104 void FrameDirListBoxWrapper::SetControlDontKnow( bool bSet )
105 {
106 if( bSet )
107 GetControl().SetNoSelection();
108 }
109
GetControlValue() const110 SvxFrameDirection FrameDirListBoxWrapper::GetControlValue() const
111 {
112 return GetControl().GetSelectEntryValue();
113 }
114
SetControlValue(SvxFrameDirection eValue)115 void FrameDirListBoxWrapper::SetControlValue( SvxFrameDirection eValue )
116 {
117 GetControl().SelectEntryValue( eValue );
118 }
119
120 // ============================================================================
121
122 } // namespace svx
123
124