Line data Source code
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 <string>
21 :
22 : #include <svx/dialogs.hrc>
23 : #include <svx/svdglue.hxx>
24 : #include <svl/intitem.hxx>
25 : #include <sfx2/app.hxx>
26 : #include <sfx2/dispatch.hxx>
27 : #include <vcl/toolbox.hxx>
28 : #include <sfx2/viewfrm.hxx>
29 :
30 : #include "strings.hrc"
31 : #include "gluectrl.hxx"
32 : #include "sdresid.hxx"
33 : #include "app.hrc"
34 :
35 : using namespace ::com::sun::star::uno;
36 : using namespace ::com::sun::star::beans;
37 : using namespace ::com::sun::star::frame;
38 :
39 : // at the moment, Joe only supports the methods specified below
40 : #define ESCDIR_COUNT 5
41 : static const sal_uInt16 aEscDirArray[] =
42 : {
43 : SDRESC_SMART,
44 : SDRESC_LEFT,
45 : SDRESC_RIGHT,
46 : SDRESC_TOP,
47 : SDRESC_BOTTOM,
48 : // SDRESC_LO,
49 : // SDRESC_LU,
50 : // SDRESC_RO,
51 : // SDRESC_RU,
52 : // SDRESC_HORZ,
53 : // SDRESC_VERT,
54 : // SDRESC_ALL
55 : };
56 :
57 :
58 :
59 0 : SFX_IMPL_TOOLBOX_CONTROL( SdTbxCtlGlueEscDir, SfxUInt16Item )
60 :
61 : /**
62 : * Constructor for glue point escape direction Listbox
63 : */
64 0 : GlueEscDirLB::GlueEscDirLB( Window* pParent, const Reference< XFrame >& rFrame ) :
65 : ListBox( pParent, WinBits( WB_BORDER | WB_DROPDOWN ) ),
66 0 : m_xFrame( rFrame )
67 : {
68 0 : Size aXSize( GetTextWidth( "X" ), GetTextHeight() );
69 0 : SetSizePixel( Size( aXSize.Width() * 12, aXSize.Height() * 10 ) );
70 0 : Fill();
71 0 : Show();
72 0 : }
73 :
74 0 : GlueEscDirLB::~GlueEscDirLB()
75 : {
76 0 : }
77 :
78 : /**
79 : * Determines the escape direction and sends the corresponding slot
80 : */
81 0 : void GlueEscDirLB::Select()
82 : {
83 0 : sal_Int32 nPos = GetSelectEntryPos();
84 0 : SfxUInt16Item aItem( SID_GLUE_ESCDIR, aEscDirArray[ nPos ] );
85 :
86 0 : if ( m_xFrame.is() )
87 : {
88 0 : Any a;
89 0 : Sequence< PropertyValue > aArgs( 1 );
90 0 : aArgs[0].Name = "GlueEscapeDirection";
91 0 : aItem.QueryValue( a );
92 0 : aArgs[0].Value = a;
93 0 : SfxToolBoxControl::Dispatch( Reference< XDispatchProvider >( m_xFrame->getController(), UNO_QUERY ),
94 : ".uno:GlueEscapeDirection",
95 0 : aArgs );
96 0 : }
97 0 : }
98 :
99 : /**
100 : * Fills the Listbox with strings
101 : */
102 0 : void GlueEscDirLB::Fill()
103 : {
104 0 : InsertEntry( SD_RESSTR( STR_GLUE_ESCDIR_SMART ) );
105 0 : InsertEntry( SD_RESSTR( STR_GLUE_ESCDIR_LEFT ) );
106 0 : InsertEntry( SD_RESSTR( STR_GLUE_ESCDIR_RIGHT ) );
107 0 : InsertEntry( SD_RESSTR( STR_GLUE_ESCDIR_TOP ) );
108 0 : InsertEntry( SD_RESSTR( STR_GLUE_ESCDIR_BOTTOM ) );
109 : /*
110 : InsertEntry( SD_RESSTR( STR_GLUE_ESCDIR_LO ) );
111 : InsertEntry( SD_RESSTR( STR_GLUE_ESCDIR_LU ) );
112 : InsertEntry( SD_RESSTR( STR_GLUE_ESCDIR_RO ) );
113 : InsertEntry( SD_RESSTR( STR_GLUE_ESCDIR_RU ) );
114 : InsertEntry( SD_RESSTR( STR_GLUE_ESCDIR_HORZ ) );
115 : InsertEntry( SD_RESSTR( STR_GLUE_ESCDIR_VERT ) );
116 : InsertEntry( SD_RESSTR( STR_GLUE_ESCDIR_ALL ) );
117 : */
118 0 : }
119 :
120 : /**
121 : * Constructor for glue point escape direction toolbox control
122 : */
123 0 : SdTbxCtlGlueEscDir::SdTbxCtlGlueEscDir(
124 : sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
125 0 : SfxToolBoxControl( nSlotId, nId, rTbx )
126 : {
127 0 : }
128 :
129 : /**
130 : * Represents state in the listbox of the controller
131 : */
132 0 : void SdTbxCtlGlueEscDir::StateChanged( sal_uInt16 nSId,
133 : SfxItemState eState, const SfxPoolItem* pState )
134 : {
135 0 : if( eState == SFX_ITEM_AVAILABLE )
136 : {
137 0 : GlueEscDirLB* pGlueEscDirLB = (GlueEscDirLB*) ( GetToolBox().
138 0 : GetItemWindow( GetId() ) );
139 0 : if( pGlueEscDirLB )
140 : {
141 0 : if( pState )
142 : {
143 0 : pGlueEscDirLB->Enable();
144 0 : if ( IsInvalidItem( pState ) )
145 : {
146 0 : pGlueEscDirLB->SetNoSelection();
147 : }
148 : else
149 : {
150 0 : sal_uInt16 nEscDir = ( (const SfxUInt16Item*) pState )->GetValue();
151 0 : pGlueEscDirLB->SelectEntryPos( GetEscDirPos( nEscDir ) );
152 : }
153 : }
154 : else
155 : {
156 0 : pGlueEscDirLB->Disable();
157 0 : pGlueEscDirLB->SetNoSelection();
158 : }
159 : }
160 : }
161 :
162 0 : SfxToolBoxControl::StateChanged( nSId, eState, pState );
163 0 : }
164 :
165 0 : Window* SdTbxCtlGlueEscDir::CreateItemWindow( Window *pParent )
166 : {
167 0 : if( GetSlotId() == SID_GLUE_ESCDIR )
168 : {
169 0 : return( new GlueEscDirLB( pParent, m_xFrame ) );
170 : }
171 :
172 0 : return( NULL );
173 : }
174 :
175 :
176 : /**
177 : * Returns position in the array for EscDir (Mapping for Listbox)
178 : */
179 0 : sal_uInt16 SdTbxCtlGlueEscDir::GetEscDirPos( sal_uInt16 nEscDir )
180 : {
181 0 : for( sal_uInt16 i = 0; i < ESCDIR_COUNT; i++ )
182 : {
183 0 : if( aEscDirArray[ i ] == nEscDir )
184 0 : return( i );
185 : }
186 0 : return( 99 );
187 : }
188 :
189 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|