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 <tools/shl.hxx>
21 : #include <tools/urlobj.hxx>
22 : #include <vcl/msgbox.hxx>
23 : #include <unotools/pathoptions.hxx>
24 : #include <sfx2/app.hxx>
25 : #include <sfx2/dialoghelper.hxx>
26 : #include <sfx2/filedlghelper.hxx>
27 : #include <sfx2/module.hxx>
28 : #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
29 :
30 : #include <cuires.hrc>
31 : #include "tabarea.hrc"
32 : #include "helpid.hrc"
33 : #include "svx/xattr.hxx"
34 : #include <svx/xpool.hxx>
35 : #include <svx/xtable.hxx>
36 : #include "svx/drawitem.hxx"
37 : #include "cuitabarea.hxx"
38 : #include "defdlgname.hxx"
39 : #include "dlgname.hxx"
40 : #include <svx/svxdlg.hxx>
41 : #include <dialmgr.hxx>
42 : #include "svx/dlgutil.hxx"
43 : #include <svx/dialmgr.hxx>
44 : #include "paragrph.hrc"
45 : #include <svx/dialogs.hrc>
46 :
47 0 : SvxHatchTabPage::SvxHatchTabPage
48 : (
49 : Window* pParent,
50 : const SfxItemSet& rInAttrs
51 : ) :
52 :
53 : SvxTabPage ( pParent, "HatchPage", "cui/ui/hatchpage.ui", rInAttrs ),
54 :
55 : rOutAttrs ( rInAttrs ),
56 :
57 : pnHatchingListState ( 0 ),
58 : pnColorListState ( 0 ),
59 : pPageType ( 0 ),
60 : pDlgType ( 0 ),
61 : pPos ( 0 ),
62 : pbAreaTP ( 0 ),
63 :
64 0 : pXPool ( (XOutdevItemPool*) rInAttrs.GetPool() ),
65 : aXFStyleItem ( XFILL_HATCH ),
66 : aXHatchItem ( String(), XHatch() ),
67 : aXFillAttr ( pXPool ),
68 0 : rXFSet ( aXFillAttr.GetItemSet() )
69 :
70 : {
71 0 : get(m_pMtrDistance, "distancemtr");
72 0 : get(m_pMtrAngle, "anglemtr");
73 0 : get(m_pFtAngleDegrees, "anglemtrdegrees");
74 0 : m_pMtrAngle->SetUnit(FUNIT_CUSTOM);
75 0 : m_pMtrAngle->SetCustomUnitText(m_pFtAngleDegrees->GetText());
76 0 : get(m_pCtlAngle, "anglectl");
77 0 : m_pCtlAngle->SetCS(CS_ANGLE);
78 0 : Size aSize = LogicToPixel(Size(39, 39), MAP_APPFONT);
79 0 : m_pCtlAngle->set_width_request(aSize.Width());
80 0 : m_pCtlAngle->set_height_request(aSize.Height());
81 0 : get(m_pLbLineType, "linetypelb");
82 0 : get(m_pLbLineColor, "linecolorlb");
83 0 : get(m_pLbHatchings, "hatchingslb");
84 0 : aSize = LogicToPixel(Size(88, 110), MAP_APPFONT);
85 0 : m_pLbHatchings->set_width_request(aSize.Width());
86 0 : m_pLbHatchings->set_height_request(aSize.Height());
87 0 : get(m_pCtlPreview, "previewctl");
88 0 : get(m_pBtnAdd, "add");
89 0 : get(m_pBtnModify, "modify");
90 0 : get(m_pBtnDelete, "delete");
91 0 : get(m_pBtnLoad, "load");
92 0 : get(m_pBtnSave, "save");
93 :
94 : // this page needs ExchangeSupport
95 0 : SetExchangeSupport();
96 :
97 : // adjust metric
98 0 : FieldUnit eFUnit = GetModuleFieldUnit( rInAttrs );
99 :
100 0 : switch ( eFUnit )
101 : {
102 : case FUNIT_M:
103 : case FUNIT_KM:
104 0 : eFUnit = FUNIT_MM;
105 0 : break;
106 : default: ;//prevent warning
107 : }
108 0 : SetFieldUnit( *m_pMtrDistance, eFUnit );
109 :
110 : // determine PoolUnit
111 0 : SfxItemPool* pPool = rOutAttrs.GetPool();
112 : DBG_ASSERT( pPool, "Wo ist der Pool?" );
113 0 : ePoolUnit = pPool->GetMetric( SID_ATTR_FILL_HATCH );
114 :
115 : // setting the output device
116 0 : rXFSet.Put( aXFStyleItem );
117 0 : rXFSet.Put( aXHatchItem );
118 0 : m_pCtlPreview->SetAttributes( aXFillAttr.GetItemSet() );
119 :
120 0 : m_pLbHatchings->SetSelectHdl( LINK( this, SvxHatchTabPage, ChangeHatchHdl_Impl ) );
121 :
122 0 : Link aLink = LINK( this, SvxHatchTabPage, ModifiedHdl_Impl );
123 0 : m_pMtrDistance->SetModifyHdl( aLink );
124 0 : m_pMtrAngle->SetModifyHdl( aLink );
125 0 : m_pLbLineType->SetSelectHdl( aLink );
126 0 : m_pLbLineColor->SetSelectHdl( aLink );
127 :
128 0 : m_pBtnAdd->SetClickHdl( LINK( this, SvxHatchTabPage, ClickAddHdl_Impl ) );
129 : m_pBtnModify->SetClickHdl(
130 0 : LINK( this, SvxHatchTabPage, ClickModifyHdl_Impl ) );
131 : m_pBtnDelete->SetClickHdl(
132 0 : LINK( this, SvxHatchTabPage, ClickDeleteHdl_Impl ) );
133 0 : m_pBtnLoad->SetClickHdl( LINK( this, SvxHatchTabPage, ClickLoadHdl_Impl ) );
134 0 : m_pBtnSave->SetClickHdl( LINK( this, SvxHatchTabPage, ClickSaveHdl_Impl ) );
135 :
136 0 : m_pCtlPreview->SetDrawMode( GetSettings().GetStyleSettings().GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );
137 :
138 0 : setPreviewsToSamePlace(pParent, this);
139 0 : }
140 :
141 : // -----------------------------------------------------------------------
142 :
143 0 : void SvxHatchTabPage::Construct()
144 : {
145 0 : m_pLbLineColor->Fill( pColorList );
146 0 : m_pLbHatchings->Fill( pHatchingList );
147 0 : }
148 :
149 : // -----------------------------------------------------------------------
150 :
151 0 : void SvxHatchTabPage::ActivatePage( const SfxItemSet& rSet )
152 : {
153 : sal_uInt16 nPos;
154 : sal_uInt16 nCount;
155 :
156 0 : if( *pDlgType == 0 ) // area dialog
157 : {
158 0 : *pbAreaTP = sal_False;
159 :
160 0 : if( pColorList.is() )
161 : {
162 : // ColorList
163 0 : if( *pnColorListState & CT_CHANGED ||
164 0 : *pnColorListState & CT_MODIFIED )
165 : {
166 0 : if( *pnColorListState & CT_CHANGED )
167 0 : pColorList = ( (SvxAreaTabDialog*) GetParentDialog() )->GetNewColorList();
168 :
169 : // LbLineColor
170 0 : nPos = m_pLbLineColor->GetSelectEntryPos();
171 0 : m_pLbLineColor->Clear();
172 0 : m_pLbLineColor->Fill( pColorList );
173 0 : nCount = m_pLbLineColor->GetEntryCount();
174 0 : if( nCount == 0 )
175 : ; // this case should not occur
176 0 : else if( nCount <= nPos )
177 0 : m_pLbLineColor->SelectEntryPos( 0 );
178 : else
179 0 : m_pLbLineColor->SelectEntryPos( nPos );
180 :
181 0 : ModifiedHdl_Impl( this );
182 : }
183 :
184 : // determining (possibly cutting) the name
185 : // and displaying it in the GroupBox
186 0 : OUString aString( CUI_RES( RID_SVXSTR_TABLE ) );
187 0 : aString += ": ";
188 0 : INetURLObject aURL( pHatchingList->GetPath() );
189 :
190 0 : aURL.Append( pHatchingList->GetName() );
191 : DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
192 :
193 0 : if ( aURL.getBase().getLength() > 18 )
194 : {
195 0 : aString += aURL.getBase().copy( 0, 15 );
196 0 : aString += "...";
197 : }
198 : else
199 0 : aString += aURL.getBase();
200 :
201 0 : if( *pPageType == PT_HATCH && *pPos != LISTBOX_ENTRY_NOTFOUND )
202 : {
203 0 : m_pLbHatchings->SelectEntryPos( *pPos );
204 : }
205 : // colors could have been deleted
206 0 : ChangeHatchHdl_Impl( this );
207 :
208 0 : *pPageType = PT_HATCH;
209 0 : *pPos = LISTBOX_ENTRY_NOTFOUND;
210 : }
211 : }
212 :
213 0 : rXFSet.Put ( ( XFillColorItem& ) rSet.Get(XATTR_FILLCOLOR) );
214 0 : rXFSet.Put ( ( XFillBackgroundItem&)rSet.Get(XATTR_FILLBACKGROUND) );
215 0 : m_pCtlPreview->SetAttributes( aXFillAttr.GetItemSet() );
216 0 : m_pCtlPreview->Invalidate();
217 0 : }
218 :
219 : // -----------------------------------------------------------------------
220 :
221 0 : int SvxHatchTabPage::DeactivatePage( SfxItemSet* _pSet )
222 : {
223 0 : if ( CheckChanges_Impl() == -1L )
224 0 : return KEEP_PAGE;
225 :
226 0 : if( _pSet )
227 0 : FillItemSet( *_pSet );
228 :
229 0 : return LEAVE_PAGE;
230 : }
231 :
232 : // -----------------------------------------------------------------------
233 :
234 0 : long SvxHatchTabPage::CheckChanges_Impl()
235 : {
236 0 : if( m_pMtrDistance->GetText() != m_pMtrDistance->GetSavedValue() ||
237 0 : m_pMtrAngle->GetText() != m_pMtrAngle->GetSavedValue() ||
238 0 : m_pLbLineType->GetSelectEntryPos() != m_pLbLineType->GetSavedValue() ||
239 0 : m_pLbLineColor->GetSelectEntryPos() != m_pLbLineColor->GetSavedValue() ||
240 0 : m_pLbHatchings->GetSelectEntryPos() != m_pLbHatchings->GetSavedValue() )
241 : {
242 0 : ResMgr& rMgr = CUI_MGR();
243 0 : Image aWarningBoxImage = WarningBox::GetStandardImage();
244 0 : SvxMessDialog* aMessDlg = new SvxMessDialog(GetParentDialog(),
245 0 : SVX_RESSTR( RID_SVXSTR_HATCH ),
246 0 : CUI_RESSTR( RID_SVXSTR_ASK_CHANGE_HATCH ),
247 0 : &aWarningBoxImage );
248 : DBG_ASSERT(aMessDlg, "Dialogdiet fail!");
249 : aMessDlg->SetButtonText( MESS_BTN_1,
250 0 : String( ResId( RID_SVXSTR_CHANGE, rMgr ) ) );
251 : aMessDlg->SetButtonText( MESS_BTN_2,
252 0 : String( ResId( RID_SVXSTR_ADD, rMgr ) ) );
253 :
254 0 : short nRet = aMessDlg->Execute();
255 :
256 0 : switch( nRet )
257 : {
258 : case RET_BTN_1:
259 : {
260 0 : ClickModifyHdl_Impl( this );
261 : }
262 0 : break;
263 :
264 : case RET_BTN_2:
265 : {
266 0 : ClickAddHdl_Impl( this );
267 : }
268 0 : break;
269 :
270 : case RET_CANCEL:
271 0 : break;
272 : }
273 0 : delete aMessDlg;
274 : }
275 :
276 0 : sal_uInt16 nPos = m_pLbHatchings->GetSelectEntryPos();
277 0 : if( nPos != LISTBOX_ENTRY_NOTFOUND )
278 0 : *pPos = nPos;
279 0 : return 0L;
280 : }
281 :
282 : // -----------------------------------------------------------------------
283 :
284 0 : sal_Bool SvxHatchTabPage::FillItemSet( SfxItemSet& rSet )
285 : {
286 0 : if( *pDlgType == 0 && *pbAreaTP == sal_False ) // area dialog
287 : {
288 0 : if( *pPageType == PT_HATCH )
289 : {
290 : // CheckChanges(); <-- duplicate inquiry ?
291 :
292 0 : XHatch* pXHatch = NULL;
293 0 : String aString;
294 0 : sal_uInt16 nPos = m_pLbHatchings->GetSelectEntryPos();
295 0 : if( nPos != LISTBOX_ENTRY_NOTFOUND )
296 : {
297 0 : pXHatch = new XHatch( pHatchingList->GetHatch( nPos )->GetHatch() );
298 0 : aString = m_pLbHatchings->GetSelectEntry();
299 : }
300 : // gradient has been (unidentifiedly) passed
301 : else
302 : {
303 0 : pXHatch = new XHatch( m_pLbLineColor->GetSelectEntryColor(),
304 0 : (XHatchStyle) m_pLbLineType->GetSelectEntryPos(),
305 0 : GetCoreValue( *m_pMtrDistance, ePoolUnit ),
306 0 : static_cast<long>(m_pMtrAngle->GetValue() * 10) );
307 : }
308 : DBG_ASSERT( pXHatch, "XHatch konnte nicht erzeugt werden" );
309 0 : rSet.Put( XFillStyleItem( XFILL_HATCH ) );
310 0 : rSet.Put( XFillHatchItem( aString, *pXHatch ) );
311 :
312 0 : delete pXHatch;
313 : }
314 : }
315 0 : return sal_True;
316 : }
317 :
318 : // -----------------------------------------------------------------------
319 :
320 0 : void SvxHatchTabPage::Reset( const SfxItemSet& rSet )
321 : {
322 0 : ChangeHatchHdl_Impl( this );
323 :
324 : // determine button state
325 0 : if( pHatchingList->Count() )
326 : {
327 0 : m_pBtnModify->Enable();
328 0 : m_pBtnDelete->Enable();
329 0 : m_pBtnSave->Enable();
330 : }
331 : else
332 : {
333 0 : m_pBtnModify->Disable();
334 0 : m_pBtnDelete->Disable();
335 0 : m_pBtnSave->Disable();
336 : }
337 :
338 0 : rXFSet.Put ( ( XFillColorItem& ) rSet.Get(XATTR_FILLCOLOR) );
339 0 : rXFSet.Put ( ( XFillBackgroundItem&)rSet.Get(XATTR_FILLBACKGROUND) );
340 0 : m_pCtlPreview->SetAttributes( aXFillAttr.GetItemSet() );
341 0 : m_pCtlPreview->Invalidate();
342 0 : }
343 :
344 : // -----------------------------------------------------------------------
345 :
346 0 : SfxTabPage* SvxHatchTabPage::Create( Window* pWindow,
347 : const SfxItemSet& rSet )
348 : {
349 0 : return new SvxHatchTabPage( pWindow, rSet );
350 : }
351 :
352 : //------------------------------------------------------------------------
353 :
354 0 : IMPL_LINK( SvxHatchTabPage, ModifiedHdl_Impl, void *, p )
355 : {
356 0 : if( p == m_pMtrAngle )
357 : {
358 0 : switch( m_pMtrAngle->GetValue() )
359 : {
360 0 : case 135: m_pCtlAngle->SetActualRP( RP_LT ); break;
361 0 : case 90: m_pCtlAngle->SetActualRP( RP_MT ); break;
362 0 : case 45: m_pCtlAngle->SetActualRP( RP_RT ); break;
363 0 : case 180: m_pCtlAngle->SetActualRP( RP_LM ); break;
364 0 : case 0: m_pCtlAngle->SetActualRP( RP_RM ); break;
365 0 : case 225: m_pCtlAngle->SetActualRP( RP_LB ); break;
366 0 : case 270: m_pCtlAngle->SetActualRP( RP_MB ); break;
367 0 : case 315: m_pCtlAngle->SetActualRP( RP_RB ); break;
368 0 : default: m_pCtlAngle->SetActualRP( RP_MM ); break;
369 : }
370 : }
371 :
372 0 : XHatch aXHatch( m_pLbLineColor->GetSelectEntryColor(),
373 0 : (XHatchStyle) m_pLbLineType->GetSelectEntryPos(),
374 : GetCoreValue( *m_pMtrDistance, ePoolUnit ),
375 0 : static_cast<long>(m_pMtrAngle->GetValue() * 10) );
376 :
377 0 : rXFSet.Put( XFillHatchItem( String(), aXHatch ) );
378 0 : m_pCtlPreview->SetAttributes( aXFillAttr.GetItemSet() );
379 :
380 0 : m_pCtlPreview->Invalidate();
381 :
382 0 : return 0L;
383 : }
384 :
385 : //------------------------------------------------------------------------
386 :
387 0 : IMPL_LINK_NOARG(SvxHatchTabPage, ChangeHatchHdl_Impl)
388 : {
389 0 : XHatch* pHatch = NULL;
390 0 : int nPos = m_pLbHatchings->GetSelectEntryPos();
391 :
392 0 : if( nPos != LISTBOX_ENTRY_NOTFOUND )
393 0 : pHatch = new XHatch( ( (XHatchEntry*) pHatchingList->GetHatch( nPos ) )->GetHatch() );
394 : else
395 : {
396 0 : const SfxPoolItem* pPoolItem = NULL;
397 0 : if( SFX_ITEM_SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLSTYLE ), sal_True, &pPoolItem ) )
398 : {
399 0 : if( ( XFILL_HATCH == (XFillStyle) ( ( const XFillStyleItem* ) pPoolItem )->GetValue() ) &&
400 0 : ( SFX_ITEM_SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLHATCH ), sal_True, &pPoolItem ) ) )
401 : {
402 0 : pHatch = new XHatch( ( ( const XFillHatchItem* ) pPoolItem )->GetHatchValue() );
403 : }
404 : }
405 0 : if( !pHatch )
406 : {
407 0 : m_pLbHatchings->SelectEntryPos( 0 );
408 0 : nPos = m_pLbHatchings->GetSelectEntryPos();
409 0 : if( nPos != LISTBOX_ENTRY_NOTFOUND )
410 0 : pHatch = new XHatch( ( (XHatchEntry*) pHatchingList->GetHatch( nPos ) )->GetHatch() );
411 : }
412 : }
413 0 : if( pHatch )
414 : {
415 : m_pLbLineType->SelectEntryPos(
416 0 : sal::static_int_cast< sal_uInt16 >( pHatch->GetHatchStyle() ) );
417 : // if the entry is not in the listbox
418 : // the color is added temporarily
419 0 : m_pLbLineColor->SetNoSelection();
420 0 : m_pLbLineColor->SelectEntry( pHatch->GetColor() );
421 0 : if( m_pLbLineColor->GetSelectEntryCount() == 0 )
422 : {
423 0 : m_pLbLineColor->InsertEntry( pHatch->GetColor(), String() );
424 0 : m_pLbLineColor->SelectEntry( pHatch->GetColor() );
425 : }
426 0 : SetMetricValue( *m_pMtrDistance, pHatch->GetDistance(), ePoolUnit );
427 0 : m_pMtrAngle->SetValue( pHatch->GetAngle() / 10 );
428 :
429 0 : switch( m_pMtrAngle->GetValue() )
430 : {
431 0 : case 135: m_pCtlAngle->SetActualRP( RP_LT ); break;
432 0 : case 90: m_pCtlAngle->SetActualRP( RP_MT ); break;
433 0 : case 45: m_pCtlAngle->SetActualRP( RP_RT ); break;
434 0 : case 180: m_pCtlAngle->SetActualRP( RP_LM ); break;
435 0 : case 0: m_pCtlAngle->SetActualRP( RP_RM ); break;
436 0 : case 225: m_pCtlAngle->SetActualRP( RP_LB ); break;
437 0 : case 270: m_pCtlAngle->SetActualRP( RP_MB ); break;
438 0 : case 315: m_pCtlAngle->SetActualRP( RP_RB ); break;
439 0 : default: m_pCtlAngle->SetActualRP( RP_MM ); break;
440 : }
441 :
442 : // fill ItemSet and pass it on to m_pCtlPreview
443 0 : rXFSet.Put( XFillHatchItem( String(), *pHatch ) );
444 0 : m_pCtlPreview->SetAttributes( aXFillAttr.GetItemSet() );
445 :
446 0 : m_pCtlPreview->Invalidate();
447 0 : delete pHatch;
448 : }
449 0 : m_pMtrDistance->SaveValue();
450 0 : m_pMtrAngle->SaveValue();
451 0 : m_pLbLineType->SaveValue();
452 0 : m_pLbLineColor->SaveValue();
453 0 : m_pLbHatchings->SaveValue();
454 :
455 0 : return 0L;
456 : }
457 :
458 : //------------------------------------------------------------------------
459 :
460 0 : IMPL_LINK_NOARG(SvxHatchTabPage, ClickAddHdl_Impl)
461 : {
462 0 : ResMgr& rMgr = CUI_MGR();
463 0 : String aNewName( SVX_RES( RID_SVXSTR_HATCH ) );
464 0 : String aDesc( CUI_RES( RID_SVXSTR_DESC_HATCH ) );
465 0 : String aName;
466 :
467 0 : long nCount = pHatchingList->Count();
468 0 : long j = 1;
469 0 : sal_Bool bDifferent = sal_False;
470 :
471 0 : while( !bDifferent )
472 : {
473 0 : aName = aNewName;
474 0 : aName += sal_Unicode(' ');
475 0 : aName += OUString::valueOf( j++ );
476 0 : bDifferent = sal_True;
477 :
478 0 : for( long i = 0; i < nCount && bDifferent; i++ )
479 0 : if( aName == pHatchingList->GetHatch( i )->GetName() )
480 0 : bDifferent = sal_False;
481 : }
482 :
483 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
484 : DBG_ASSERT(pFact, "Dialogdiet fail!");
485 0 : AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc );
486 : DBG_ASSERT(pDlg, "Dialogdiet fail!");
487 0 : WarningBox* pWarnBox = NULL;
488 0 : sal_uInt16 nError = RID_SVXSTR_WARN_NAME_DUPLICATE;
489 :
490 0 : while( pDlg->Execute() == RET_OK )
491 : {
492 0 : pDlg->GetName( aName );
493 :
494 0 : bDifferent = sal_True;
495 :
496 0 : for( long i = 0; i < nCount && bDifferent; i++ )
497 0 : if( aName == pHatchingList->GetHatch( i )->GetName() )
498 0 : bDifferent = sal_False;
499 :
500 0 : if( bDifferent ) {
501 0 : nError = 0;
502 0 : break;
503 : }
504 :
505 0 : if( !pWarnBox )
506 : {
507 0 : pWarnBox = new WarningBox( GetParentDialog(),
508 : WinBits( WB_OK_CANCEL ),
509 0 : String( ResId( nError, rMgr ) ) );
510 0 : pWarnBox->SetHelpId( HID_WARN_NAME_DUPLICATE );
511 : }
512 :
513 0 : if( pWarnBox->Execute() != RET_OK )
514 0 : break;
515 : }
516 0 : delete pDlg;
517 0 : delete pWarnBox;
518 :
519 0 : if( !nError )
520 : {
521 0 : XHatch aXHatch( m_pLbLineColor->GetSelectEntryColor(),
522 0 : (XHatchStyle) m_pLbLineType->GetSelectEntryPos(),
523 : GetCoreValue( *m_pMtrDistance, ePoolUnit ),
524 0 : static_cast<long>(m_pMtrAngle->GetValue() * 10) );
525 0 : XHatchEntry* pEntry = new XHatchEntry( aXHatch, aName );
526 :
527 0 : pHatchingList->Insert( pEntry, nCount );
528 :
529 0 : m_pLbHatchings->Append( *pEntry, pHatchingList->GetUiBitmap( nCount ) );
530 :
531 0 : m_pLbHatchings->SelectEntryPos( m_pLbHatchings->GetEntryCount() - 1 );
532 :
533 : #ifdef WNT
534 : // hack: #31355# W.P.
535 : Rectangle aRect( m_pLbHatchings->GetPosPixel(), m_pLbHatchings->GetSizePixel() );
536 : if( sal_True ) { // ??? overlapped with pDlg
537 : // and srolling
538 : Invalidate( aRect );
539 : }
540 : #endif
541 :
542 0 : *pnHatchingListState |= CT_MODIFIED;
543 :
544 0 : ChangeHatchHdl_Impl( this );
545 : }
546 :
547 : // determine button state
548 0 : if( pHatchingList->Count() )
549 : {
550 0 : m_pBtnModify->Enable();
551 0 : m_pBtnDelete->Enable();
552 0 : m_pBtnSave->Enable();
553 : }
554 0 : return 0L;
555 : }
556 :
557 : //------------------------------------------------------------------------
558 :
559 0 : IMPL_LINK_NOARG(SvxHatchTabPage, ClickModifyHdl_Impl)
560 : {
561 0 : sal_uInt16 nPos = m_pLbHatchings->GetSelectEntryPos();
562 :
563 0 : if ( nPos != LISTBOX_ENTRY_NOTFOUND )
564 : {
565 0 : ResMgr& rMgr = CUI_MGR();
566 0 : String aDesc( CUI_RES( RID_SVXSTR_DESC_HATCH ) );
567 0 : String aName( pHatchingList->GetHatch( nPos )->GetName() );
568 0 : String aOldName = aName;
569 :
570 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
571 : DBG_ASSERT(pFact, "Dialogdiet fail!");
572 0 : AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc );
573 : DBG_ASSERT(pDlg, "Dialogdiet fail!");
574 :
575 0 : long nCount = pHatchingList->Count();
576 0 : sal_Bool bDifferent = sal_False;
577 0 : sal_Bool bLoop = sal_True;
578 0 : while( bLoop && pDlg->Execute() == RET_OK )
579 : {
580 0 : pDlg->GetName( aName );
581 0 : bDifferent = sal_True;
582 :
583 0 : for( long i = 0; i < nCount && bDifferent; i++ )
584 : {
585 0 : if( aName == pHatchingList->GetHatch( i )->GetName() &&
586 0 : aName != aOldName )
587 0 : bDifferent = sal_False;
588 : }
589 :
590 0 : if( bDifferent )
591 : {
592 0 : bLoop = sal_False;
593 0 : XHatch aXHatch( m_pLbLineColor->GetSelectEntryColor(),
594 0 : (XHatchStyle) m_pLbLineType->GetSelectEntryPos(),
595 : GetCoreValue( *m_pMtrDistance, ePoolUnit ),
596 0 : static_cast<long>(m_pMtrAngle->GetValue() * 10) );
597 :
598 0 : XHatchEntry* pEntry = new XHatchEntry( aXHatch, aName );
599 :
600 0 : delete pHatchingList->Replace( pEntry, nPos );
601 :
602 0 : m_pLbHatchings->Modify( *pEntry, nPos, pHatchingList->GetUiBitmap( nPos ) );
603 :
604 0 : m_pLbHatchings->SelectEntryPos( nPos );
605 :
606 : // save values for changes recognition (-> method)
607 0 : m_pMtrDistance->SaveValue();
608 0 : m_pMtrAngle->SaveValue();
609 0 : m_pLbLineType->SaveValue();
610 0 : m_pLbLineColor->SaveValue();
611 0 : m_pLbHatchings->SaveValue();
612 :
613 0 : *pnHatchingListState |= CT_MODIFIED;
614 : }
615 : else
616 : {
617 0 : WarningBox aBox( GetParentDialog(), WinBits( WB_OK ),String( ResId( RID_SVXSTR_WARN_NAME_DUPLICATE, rMgr ) ) );
618 0 : aBox.SetHelpId( HID_WARN_NAME_DUPLICATE );
619 0 : aBox.Execute();
620 : }
621 : }
622 0 : delete( pDlg );
623 : }
624 0 : return 0L;
625 : }
626 :
627 : //------------------------------------------------------------------------
628 :
629 0 : IMPL_LINK_NOARG(SvxHatchTabPage, ClickDeleteHdl_Impl)
630 : {
631 0 : sal_uInt16 nPos = m_pLbHatchings->GetSelectEntryPos();
632 :
633 0 : if( nPos != LISTBOX_ENTRY_NOTFOUND )
634 : {
635 0 : QueryBox aQueryBox( GetParentDialog(), WinBits( WB_YES_NO | WB_DEF_NO ),
636 0 : String( CUI_RES( RID_SVXSTR_ASK_DEL_HATCH ) ) );
637 :
638 0 : if( aQueryBox.Execute() == RET_YES )
639 : {
640 0 : delete pHatchingList->Remove( nPos );
641 0 : m_pLbHatchings->RemoveEntry( nPos );
642 0 : m_pLbHatchings->SelectEntryPos( 0 );
643 :
644 0 : m_pCtlPreview->Invalidate();
645 :
646 0 : ChangeHatchHdl_Impl( this );
647 :
648 0 : *pnHatchingListState |= CT_MODIFIED;
649 0 : }
650 : }
651 : // determine button state
652 0 : if( !pHatchingList->Count() )
653 : {
654 0 : m_pBtnModify->Disable();
655 0 : m_pBtnDelete->Disable();
656 0 : m_pBtnSave->Disable();
657 : }
658 0 : return 0L;
659 : }
660 :
661 : // -----------------------------------------------------------------------
662 :
663 0 : IMPL_LINK_NOARG(SvxHatchTabPage, ClickLoadHdl_Impl)
664 : {
665 0 : ResMgr& rMgr = CUI_MGR();
666 0 : sal_uInt16 nReturn = RET_YES;
667 :
668 0 : if ( *pnHatchingListState & CT_MODIFIED )
669 : {
670 0 : nReturn = WarningBox( GetParentDialog(), WinBits( WB_YES_NO_CANCEL ),
671 0 : String( ResId( RID_SVXSTR_WARN_TABLE_OVERWRITE, rMgr ) ) ).Execute();
672 :
673 0 : if ( nReturn == RET_YES )
674 0 : pHatchingList->Save();
675 : }
676 :
677 0 : if ( nReturn != RET_CANCEL )
678 : {
679 : ::sfx2::FileDialogHelper aDlg(
680 : com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
681 0 : 0 );
682 0 : String aStrFilterType( "*.soh" );
683 0 : aDlg.AddFilter( aStrFilterType, aStrFilterType );
684 0 : INetURLObject aFile( SvtPathOptions().GetPalettePath() );
685 0 : aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
686 :
687 0 : if( aDlg.Execute() == ERRCODE_NONE )
688 : {
689 0 : INetURLObject aURL( aDlg.GetPath() );
690 0 : INetURLObject aPathURL( aURL );
691 :
692 0 : aPathURL.removeSegment();
693 0 : aPathURL.removeFinalSlash();
694 :
695 : XHatchListRef pHatchList = XPropertyList::CreatePropertyList(
696 0 : XHATCH_LIST, aPathURL.GetMainURL( INetURLObject::NO_DECODE ) )->AsHatchList();
697 0 : pHatchList->SetName( aURL.getName() );
698 0 : if( pHatchList->Load() )
699 : {
700 0 : pHatchingList = pHatchList;
701 0 : ( (SvxAreaTabDialog*) GetParentDialog() )->SetNewHatchingList( pHatchingList );
702 :
703 0 : m_pLbHatchings->Clear();
704 0 : m_pLbHatchings->Fill( pHatchingList );
705 0 : Reset( rOutAttrs );
706 :
707 0 : pHatchingList->SetName( aURL.getName() );
708 :
709 : // determining (and possibly cutting) the name
710 : // and displaying it in the GroupBox
711 0 : OUString aString( ResId( RID_SVXSTR_TABLE, rMgr ) );
712 0 : aString += ": ";
713 :
714 0 : if ( aURL.getBase().getLength() > 18 )
715 : {
716 0 : aString += aURL.getBase().copy( 0, 15 );
717 0 : aString += "...";
718 : }
719 : else
720 0 : aString += aURL.getBase();
721 :
722 0 : *pnHatchingListState |= CT_CHANGED;
723 0 : *pnHatchingListState &= ~CT_MODIFIED;
724 : }
725 : else
726 0 : ErrorBox( GetParentDialog(), WinBits( WB_OK ),
727 0 : String( ResId( RID_SVXSTR_READ_DATA_ERROR, rMgr ) ) ).Execute();
728 0 : }
729 : }
730 :
731 : // determine button state
732 0 : if ( pHatchingList->Count() )
733 : {
734 0 : m_pBtnModify->Enable();
735 0 : m_pBtnDelete->Enable();
736 0 : m_pBtnSave->Enable();
737 : }
738 : else
739 : {
740 0 : m_pBtnModify->Disable();
741 0 : m_pBtnDelete->Disable();
742 0 : m_pBtnSave->Disable();
743 : }
744 0 : return 0L;
745 : }
746 :
747 : // -----------------------------------------------------------------------
748 :
749 0 : IMPL_LINK_NOARG(SvxHatchTabPage, ClickSaveHdl_Impl)
750 : {
751 : ::sfx2::FileDialogHelper aDlg(
752 0 : com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE, 0 );
753 0 : String aStrFilterType( "*.soh" );
754 0 : aDlg.AddFilter( aStrFilterType, aStrFilterType );
755 :
756 0 : INetURLObject aFile( SvtPathOptions().GetPalettePath() );
757 : DBG_ASSERT( aFile.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
758 :
759 0 : if( pHatchingList->GetName().Len() )
760 : {
761 0 : aFile.Append( pHatchingList->GetName() );
762 :
763 0 : if( aFile.getExtension().isEmpty() )
764 0 : aFile.SetExtension( OUString("soh") );
765 : }
766 :
767 0 : aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
768 0 : if ( aDlg.Execute() == ERRCODE_NONE )
769 : {
770 0 : INetURLObject aURL( aDlg.GetPath() );
771 0 : INetURLObject aPathURL( aURL );
772 :
773 0 : aPathURL.removeSegment();
774 0 : aPathURL.removeFinalSlash();
775 :
776 0 : pHatchingList->SetName( aURL.getName() );
777 0 : pHatchingList->SetPath( aPathURL.GetMainURL( INetURLObject::NO_DECODE ) );
778 :
779 0 : if( pHatchingList->Save() )
780 : {
781 : // determining (and possibly cutting) the name
782 : // and displaying it in the GroupBox
783 0 : OUString aString( CUI_RES( RID_SVXSTR_TABLE ) );
784 0 : aString += ": ";
785 :
786 0 : if ( aURL.getBase().getLength() > 18 )
787 : {
788 0 : aString += aURL.getBase().copy( 0, 15 );
789 0 : aString += "...";
790 : }
791 : else
792 0 : aString += aURL.getBase();
793 :
794 0 : *pnHatchingListState |= CT_SAVED;
795 0 : *pnHatchingListState &= ~CT_MODIFIED;
796 : }
797 : else
798 : {
799 0 : ErrorBox( GetParentDialog(), WinBits( WB_OK ),
800 0 : String( CUI_RES( RID_SVXSTR_WRITE_DATA_ERROR ) ) ).Execute();
801 0 : }
802 : }
803 :
804 0 : return 0L;
805 : }
806 :
807 : //------------------------------------------------------------------------
808 :
809 0 : void SvxHatchTabPage::PointChanged( Window* pWindow, RECT_POINT eRcPt )
810 : {
811 0 : if( pWindow == m_pCtlAngle )
812 : {
813 0 : switch( eRcPt )
814 : {
815 0 : case RP_LT: m_pMtrAngle->SetValue( 135 ); break;
816 0 : case RP_MT: m_pMtrAngle->SetValue( 90 ); break;
817 0 : case RP_RT: m_pMtrAngle->SetValue( 45 ); break;
818 0 : case RP_LM: m_pMtrAngle->SetValue( 180 ); break;
819 0 : case RP_RM: m_pMtrAngle->SetValue( 0 ); break;
820 0 : case RP_LB: m_pMtrAngle->SetValue( 225 ); break;
821 0 : case RP_MB: m_pMtrAngle->SetValue( 270 ); break;
822 0 : case RP_RB: m_pMtrAngle->SetValue( 315 ); break;
823 0 : case RP_MM: break;
824 : }
825 0 : ModifiedHdl_Impl( this );
826 : }
827 0 : }
828 :
829 :
830 0 : void SvxHatchTabPage::DataChanged( const DataChangedEvent& rDCEvt )
831 : {
832 0 : if ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
833 0 : m_pCtlPreview->SetDrawMode( GetSettings().GetStyleSettings().GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );
834 :
835 0 : SvxTabPage::DataChanged( rDCEvt );
836 0 : }
837 :
838 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|