xref: /trunk/main/cui/source/dialogs/commonlingui.cxx (revision 2ee96f1c)
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_cui.hxx"
26 #include "commonlingui.hxx"
27 
28 #include <cuires.hrc>
29 #include <dialmgr.hxx>
30 #include <vcl/decoview.hxx>
31 
32 #include "hangulhanjadlg.hrc"
33 
34 //=============================================================================
35 // SvxClickInfoCtr
36 //=============================================================================
37 
38 //-----------------------------------------------------------------------------
SvxClickInfoCtr(Window * pParent,const ResId & rResId)39 SvxClickInfoCtr::SvxClickInfoCtr( Window* pParent, const ResId& rResId ) :
40 		Control( pParent, rResId ),
41 		aFixedInfo( this)
42 {
43 	aFixedInfo.SetSizePixel(GetOutputSizePixel());
44 	aFixedInfo.Show();
45 }
46 
47 //-----------------------------------------------------------------------------
MouseButtonDown(const MouseEvent &)48 void SvxClickInfoCtr::MouseButtonDown( const MouseEvent& )
49 {
50 	aActivateLink.Call(this);
51 }
52 
53 //-----------------------------------------------------------------------------
PreNotify(NotifyEvent & rNEvt)54 long SvxClickInfoCtr::PreNotify( NotifyEvent& rNEvt )
55 {
56 	if(rNEvt.GetType()==EVENT_GETFOCUS || rNEvt.GetType()==EVENT_MOUSEBUTTONDOWN)
57 	{
58 		aActivateLink.Call(this);
59 	}
60 
61 	return Control::PreNotify(rNEvt);
62 }
63 
64 //-----------------------------------------------------------------------------
SetText(const XubString & rStr)65 void SvxClickInfoCtr::SetText( const XubString& rStr )
66 {
67 	aFixedInfo.SetText(rStr );
68 }
69 
70 //-----------------------------------------------------------------------------
GetText() const71 XubString SvxClickInfoCtr::GetText() const
72 {
73 	return aFixedInfo.GetText();
74 }
75 
76 //-----------------------------------------------------------------------------
~SvxClickInfoCtr()77 __EXPORT SvxClickInfoCtr::~SvxClickInfoCtr()
78 {
79 }
80 
81 //=============================================================================
82 // SvxCommonLinguisticControl
83 //=============================================================================
84 //-----------------------------------------------------------------------------
SvxCommonLinguisticControl(ModalDialog * _pParent)85 SvxCommonLinguisticControl::SvxCommonLinguisticControl( ModalDialog* _pParent )
86 	:Window( _pParent, CUI_RES( RID_SVX_WND_COMMON_LINGU ) )
87 	,aWordText		( this,	CUI_RES( FT_WORD ) )
88 	,aAktWord		( this,	CUI_RES( FT_AKTWORD ) )
89 	,aNewWord		( this,	CUI_RES( FT_NEWWORD ) )
90 	,aNewWordED		( this,	CUI_RES( ED_NEWWORD ) )
91 	,aSuggestionFT	( this, CUI_RES( FT_SUGGESTION ) )
92     ,aIgnoreBtn     ( this, CUI_RES( BTN_IGNORE ) )
93 	,aIgnoreAllBtn	( this,	CUI_RES( BTN_IGNOREALL ) )
94 	,aChangeBtn		( this,	CUI_RES( BTN_CHANGE ) )
95 	,aChangeAllBtn	( this,	CUI_RES( BTN_CHANGEALL ) )
96 	,aOptionsBtn	( this, CUI_RES( BTN_OPTIONS ) )
97 	,aStatusText	( this, CUI_RES( FT_STATUS ) )
98     ,aHelpBtn       ( this, CUI_RES( BTN_SPL_HELP ) )
99     ,aCancelBtn     ( this, CUI_RES( BTN_SPL_CANCEL ) )
100     ,aAuditBox      ( this, CUI_RES( GB_AUDIT ) )
101 {
102 	FreeResource();
103 
104 #ifdef FS_PRIV_DEBUG
105 	SetType( WINDOW_TABPAGE );
106 #endif
107 
108 	aAktWord.SetAccessibleName(aWordText.GetText());
109 	SetPosSizePixel( Point( 0, 0 ), _pParent->GetOutputSizePixel() );
110 	Show();
111 }
112 
113 // -----------------------------------------------------------------------
implGetButton(ButtonType _eType) const114 PushButton*	SvxCommonLinguisticControl::implGetButton( ButtonType _eType  ) const
115 {
116 	const PushButton* pButton = NULL;
117 	switch ( _eType )
118 	{
119 		case eClose: pButton = &aCancelBtn; break;
120 		case eIgnore: pButton = &aIgnoreBtn; break;
121 		case eIgnoreAll: pButton = &aIgnoreAllBtn; break;
122 		case eChange: pButton = &aChangeBtn; break;
123 		case eChangeAll: pButton = &aChangeAllBtn; break;
124 		case eOptions: pButton = &aOptionsBtn; break;
125 	}
126 	return const_cast< PushButton* >( pButton );
127 }
128 
129 // -----------------------------------------------------------------------
SetButtonHandler(ButtonType _eType,const Link & _rHandler)130 void SvxCommonLinguisticControl::SetButtonHandler( ButtonType _eType, const Link& _rHandler )
131 {
132 	Button* pButton = GetButton( _eType );
133 	if ( pButton )
134 		pButton->SetClickHdl( _rHandler );
135 }
136 
137 // -----------------------------------------------------------------------
EnableButton(ButtonType _eType,sal_Bool _bEnable)138 void SvxCommonLinguisticControl::EnableButton( ButtonType _eType, sal_Bool _bEnable )
139 {
140 	Button* pButton = GetButton( _eType );
141 	if ( pButton )
142 		pButton->Enable( _bEnable );
143 }
144 
145 // -----------------------------------------------------------------------
InsertControlGroup(Window & _rFirstGroupWindow,Window & _rLastGroupWindow,ControlGroup _eInsertAfter)146 void SvxCommonLinguisticControl::InsertControlGroup( Window& _rFirstGroupWindow, Window& _rLastGroupWindow, ControlGroup _eInsertAfter )
147 {
148 	Window* pInsertAfter = NULL;	// will be the last window of our own "undividable" group, after which we insert the foreign group
149 	switch ( _eInsertAfter )
150 	{
151 		case eLeftRightWords	: pInsertAfter = &aNewWordED; break;
152 		case eSuggestionLabel	: pInsertAfter = &aSuggestionFT; break;
153 		case eActionButtons		: pInsertAfter = &aChangeAllBtn; break;
154 		case eDialogButtons		: pInsertAfter = &aCancelBtn; break;
155 	}
156 
157 	// now loop through the remaining windows of the foreign group
158 	Window* pInsertBehind = pInsertAfter;
159 	Window* pInsert = &_rFirstGroupWindow;
160 
161 	// some strange thing below: asking a window for WINDOW_NEXT or WINDOW_PREV does not take into
162 	// account the border window, _but_ SetZOrder _does_!. Thus, when advancing through a chain
163 	// of windows, we need to work with the border windows (WINDOW_BORDER), instead of simply
164 	// asking for WINDOW_NEXT.
165 
166 	Window* pLoopEnd = _rLastGroupWindow.GetWindow( WINDOW_BORDER );
167 	while ( pInsert && ( pInsertBehind != pLoopEnd ) )
168 	{
169 		// we'll destroy the NEXT relation immediately, so remember the next window
170 		DBG_ASSERT( pInsert->GetWindow( WINDOW_BORDER ), "SvxCommonLinguisticControl::InsertControlGroup: border window is expected to be non NULL!" );
171 		Window* pNextInsert = pInsert->GetWindow( WINDOW_BORDER )->GetWindow( WINDOW_NEXT );
172 		// knit
173 		pInsert->SetZOrder( pInsertBehind, WINDOW_ZORDER_BEHIND );
174 		// advance
175 		pInsertBehind = pInsert;
176 		pInsert = pNextInsert;
177 	}
178 	DBG_ASSERT( pInsertBehind == pLoopEnd, "SvxCommonLinguisticControl::InsertControlGroup: controls do not form a group!" );
179 		// if we did not reach pLoopEnd, then we did not reach _rLastGroupWindow in the loop, then
180 		// (FirstWindow, LastWindow) was no valid control group
181 }
182 
183 //-----------------------------------------------------------------------------
Paint(const Rectangle & rRect)184 void SvxCommonLinguisticControl::Paint( const Rectangle& rRect )
185 {
186 	Window::Paint(rRect );
187 
188 	DecorationView aDecoView( this );
189 
190 	Rectangle aRect( aAuditBox.GetPosPixel(), aAuditBox.GetSizePixel() );
191 	aDecoView.DrawButton( aRect, BUTTON_DRAW_NOFILL );
192 }
193 
194 //-----------------------------------------------------------------------------
Enlarge(sal_Int32 _nX,sal_Int32 _nY)195 void SvxCommonLinguisticControl::Enlarge( sal_Int32 _nX, sal_Int32 _nY )
196 {
197 	Size aSize;
198 	Point aPos;
199 
200 	// the controls which need to be resized
201 	{
202 		Window* pResize[] =
203 		{
204 			this, &aAuditBox, &aStatusText
205 		};
206         for ( sal_uInt32 i = 0; i < sizeof( pResize ) / sizeof( pResize[0] ); ++i )
207 		{
208 			aSize = pResize[i]->GetSizePixel( );
209 			pResize[i]->SetSizePixel( Size( aSize.Width() + _nX, aSize.Height() + _nY ) );
210 		}
211 	}
212 
213 	// the controls which stick to the bottom of the window
214 	{
215 		Window* pMoveDown[] =
216 		{
217 			&aStatusText, &aHelpBtn, &aCancelBtn
218 		};
219         for ( sal_uInt32 i = 0; i < sizeof( pMoveDown ) / sizeof( pMoveDown[0] ); ++i )
220 		{
221 			aPos = pMoveDown[i]->GetPosPixel();
222 			aPos.Y() += _nY;
223 			pMoveDown[i]->SetPosPixel( aPos );
224 		}
225 	}
226 
227 	// the controls which stick to the right
228 	{
229 		Window* pMoveRight[] =
230 		{
231 			&aIgnoreBtn, &aIgnoreAllBtn, &aChangeBtn, &aChangeAllBtn, &aOptionsBtn, &aHelpBtn, &aCancelBtn
232 		};
233         for ( sal_uInt32 i = 0; i < sizeof( pMoveRight ) / sizeof( pMoveRight[0] ); ++i )
234 		{
235 			aPos = pMoveRight[i]->GetPosPixel();
236 			aPos.X() += _nX;
237 			pMoveRight[i]->SetPosPixel( aPos );
238 		}
239 	}
240 }
241