dialcontrol.cxx (f6e50924) | dialcontrol.cxx (ee093554) |
---|---|
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 --- 10 unchanged lines hidden (view full) --- 19 * 20 *************************************************************/ 21 22 23 24// MARKER(update_precomp.py): autogen include statement, do not remove 25#include "precompiled_svx.hxx" 26#include "svx/dialcontrol.hxx" | 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 --- 10 unchanged lines hidden (view full) --- 19 * 20 *************************************************************/ 21 22 23 24// MARKER(update_precomp.py): autogen include statement, do not remove 25#include "precompiled_svx.hxx" 26#include "svx/dialcontrol.hxx" |
27 | 27#include "bmpmask.hrc" 28#include <svx/dialmgr.hxx> 29#include <tools/rcid.h> |
28#include <math.h> 29#include <vcl/virdev.hxx> 30#include <vcl/svapp.hxx> 31#include <vcl/bitmap.hxx> 32#include <vcl/field.hxx> 33#include <svtools/colorcfg.hxx> 34 35namespace svx { 36 37// ============================================================================ 38 39const long DIAL_OUTER_WIDTH = 8; 40 41// ============================================================================ 42 | 30#include <math.h> 31#include <vcl/virdev.hxx> 32#include <vcl/svapp.hxx> 33#include <vcl/bitmap.hxx> 34#include <vcl/field.hxx> 35#include <svtools/colorcfg.hxx> 36 37namespace svx { 38 39// ============================================================================ 40 41const long DIAL_OUTER_WIDTH = 8; 42 43// ============================================================================ 44 |
43class DialControlBmp : public VirtualDevice 44{ 45public: 46 explicit DialControlBmp( Window& rParent ); | |
47 | 45 |
48 void InitBitmap( const Size& rSize, const Font& rFont ); 49 void CopyBackground( const DialControlBmp& rSrc ); 50 void DrawBackground( const Size& rSize, bool bEnabled ); 51 void DrawElements( const String& rText, sal_Int32 nAngle ); 52 53private: 54 const Color& GetBackgroundColor() const; 55 const Color& GetTextColor() const; 56 const Color& GetScaleLineColor() const; 57 const Color& GetButtonLineColor() const; 58 const Color& GetButtonFillColor( bool bMain ) const; 59 60 void Init( const Size& rSize ); 61 void DrawBackground(); 62 63 Window& mrParent; 64 Rectangle maRect; 65 long mnCenterX; 66 long mnCenterY; 67 bool mbEnabled; 68}; 69 | |
70// ---------------------------------------------------------------------------- 71 72DialControlBmp::DialControlBmp( Window& rParent ) : 73 VirtualDevice( rParent, 0, 0 ), | 46// ---------------------------------------------------------------------------- 47 48DialControlBmp::DialControlBmp( Window& rParent ) : 49 VirtualDevice( rParent, 0, 0 ), |
74 mrParent( rParent ), 75 mbEnabled( true ) | 50 mbEnabled( true ), 51 mrParent( rParent ) |
76{ 77 EnableRTL( sal_False ); 78} 79 80void DialControlBmp::InitBitmap( const Size& rSize, const Font& rFont ) 81{ 82 Init( rSize ); 83 SetFont( rFont ); --- 143 unchanged lines hidden (view full) --- 227 // *** clear inner area *** 228 229 SetLineColor(); 230 SetFillColor( GetBackgroundColor() ); 231 DrawEllipse( Rectangle( maRect.Left() + DIAL_OUTER_WIDTH, maRect.Top() + DIAL_OUTER_WIDTH, 232 maRect.Right() - DIAL_OUTER_WIDTH, maRect.Bottom() - DIAL_OUTER_WIDTH ) ); 233} 234 | 52{ 53 EnableRTL( sal_False ); 54} 55 56void DialControlBmp::InitBitmap( const Size& rSize, const Font& rFont ) 57{ 58 Init( rSize ); 59 SetFont( rFont ); --- 143 unchanged lines hidden (view full) --- 203 // *** clear inner area *** 204 205 SetLineColor(); 206 SetFillColor( GetBackgroundColor() ); 207 DrawEllipse( Rectangle( maRect.Left() + DIAL_OUTER_WIDTH, maRect.Top() + DIAL_OUTER_WIDTH, 208 maRect.Right() - DIAL_OUTER_WIDTH, maRect.Bottom() - DIAL_OUTER_WIDTH ) ); 209} 210 |
235// ============================================================================ | |
236 | 211 |
237struct DialControl_Impl 238{ 239 DialControlBmp maBmpEnabled; 240 DialControlBmp maBmpDisabled; 241 DialControlBmp maBmpBuffered; 242 Link maModifyHdl; 243 NumericField* mpLinkField; 244 Size maWinSize; 245 Font maWinFont; 246 sal_Int32 mnAngle; 247 sal_Int32 mnOldAngle; 248 long mnCenterX; 249 long mnCenterY; 250 bool mbNoRot; | |
251 | 212 |
252 explicit DialControl_Impl( Window& rParent ); 253 void Init( const Size& rWinSize, const Font& rWinFont ); 254}; | |
255 256// ---------------------------------------------------------------------------- 257 | 213 214// ---------------------------------------------------------------------------- 215 |
258DialControl_Impl::DialControl_Impl( Window& rParent ) : 259 maBmpEnabled( rParent ), 260 maBmpDisabled( rParent ), 261 maBmpBuffered( rParent ), | 216DialControl::DialControl_Impl::DialControl_Impl ( 217 Window& rParent ) : 218 mpBmpEnabled(new DialControlBmp(rParent)), 219 mpBmpDisabled(new DialControlBmp(rParent)), 220 mpBmpBuffered(new DialControlBmp(rParent)), |
262 mpLinkField( 0 ), 263 mnAngle( 0 ), 264 mbNoRot( false ) 265{ 266} 267 | 221 mpLinkField( 0 ), 222 mnAngle( 0 ), 223 mbNoRot( false ) 224{ 225} 226 |
268void DialControl_Impl::Init( const Size& rWinSize, const Font& rWinFont ) | 227void DialControl::DialControl_Impl::Init( const Size& rWinSize, const Font& rWinFont ) |
269{ 270 // "(x - 1) | 1" creates odd value <= x, to have a well-defined center pixel position 271 maWinSize = Size( (rWinSize.Width() - 1) | 1, (rWinSize.Height() - 1) | 1 ); 272 maWinFont = rWinFont; 273 274 mnCenterX = maWinSize.Width() / 2; 275 mnCenterY = maWinSize.Height() / 2; 276 maWinFont.SetTransparent( sal_True ); 277 | 228{ 229 // "(x - 1) | 1" creates odd value <= x, to have a well-defined center pixel position 230 maWinSize = Size( (rWinSize.Width() - 1) | 1, (rWinSize.Height() - 1) | 1 ); 231 maWinFont = rWinFont; 232 233 mnCenterX = maWinSize.Width() / 2; 234 mnCenterY = maWinSize.Height() / 2; 235 maWinFont.SetTransparent( sal_True ); 236 |
278 maBmpEnabled.DrawBackground( maWinSize, true ); 279 maBmpDisabled.DrawBackground( maWinSize, false ); 280 maBmpBuffered.InitBitmap( maWinSize, maWinFont ); | 237 mpBmpEnabled->DrawBackground( maWinSize, true ); 238 mpBmpDisabled->DrawBackground( maWinSize, false ); 239 mpBmpBuffered->InitBitmap( maWinSize, maWinFont ); |
281} 282 283// ============================================================================ 284 285DialControl::DialControl( Window* pParent, const Size& rSize, const Font& rFont, WinBits nWinStyle ) : 286 Control( pParent, nWinStyle ), 287 mpImpl( new DialControl_Impl( *this ) ) 288{ --- 19 unchanged lines hidden (view full) --- 308 309DialControl::~DialControl() 310{ 311} 312 313void DialControl::Paint( const Rectangle& ) 314{ 315 Point aPos; | 240} 241 242// ============================================================================ 243 244DialControl::DialControl( Window* pParent, const Size& rSize, const Font& rFont, WinBits nWinStyle ) : 245 Control( pParent, nWinStyle ), 246 mpImpl( new DialControl_Impl( *this ) ) 247{ --- 19 unchanged lines hidden (view full) --- 267 268DialControl::~DialControl() 269{ 270} 271 272void DialControl::Paint( const Rectangle& ) 273{ 274 Point aPos; |
316 DrawBitmapEx( aPos, mpImpl->maBmpBuffered.GetBitmapEx( aPos, mpImpl->maWinSize ) ); | 275 DrawBitmapEx( aPos, mpImpl->mpBmpBuffered->GetBitmapEx( aPos, mpImpl->maWinSize ) ); |
317} 318 319void DialControl::StateChanged( StateChangedType nStateChange ) 320{ 321 if( nStateChange == STATE_CHANGE_ENABLE ) 322 InvalidateControl(); 323 324 // update the linked edit field --- 84 unchanged lines hidden (view full) --- 409 410sal_Int32 DialControl::GetRotation() const 411{ 412 return mpImpl->mnAngle; 413} 414 415void DialControl::SetRotation( sal_Int32 nAngle ) 416{ | 276} 277 278void DialControl::StateChanged( StateChangedType nStateChange ) 279{ 280 if( nStateChange == STATE_CHANGE_ENABLE ) 281 InvalidateControl(); 282 283 // update the linked edit field --- 84 unchanged lines hidden (view full) --- 368 369sal_Int32 DialControl::GetRotation() const 370{ 371 return mpImpl->mnAngle; 372} 373 374void DialControl::SetRotation( sal_Int32 nAngle ) 375{ |
417 ImplSetRotation( nAngle, false ); | 376 SetRotation( nAngle, false ); |
418} 419 420void DialControl::SetLinkedField( NumericField* pField ) 421{ 422 // remove modify handler from old linked field 423 ImplSetFieldLink( Link() ); 424 // remember the new linked field 425 mpImpl->mpLinkField = pField; --- 30 unchanged lines hidden (view full) --- 456{ 457 Font aFont( OutputDevice::GetDefaultFont( 458 DEFAULTFONT_UI_SANS, Application::GetSettings().GetUILanguage(), DEFAULTFONT_FLAGS_ONLYONE ) ); 459 Init( rWinSize, aFont ); 460} 461 462void DialControl::InvalidateControl() 463{ | 377} 378 379void DialControl::SetLinkedField( NumericField* pField ) 380{ 381 // remove modify handler from old linked field 382 ImplSetFieldLink( Link() ); 383 // remember the new linked field 384 mpImpl->mpLinkField = pField; --- 30 unchanged lines hidden (view full) --- 415{ 416 Font aFont( OutputDevice::GetDefaultFont( 417 DEFAULTFONT_UI_SANS, Application::GetSettings().GetUILanguage(), DEFAULTFONT_FLAGS_ONLYONE ) ); 418 Init( rWinSize, aFont ); 419} 420 421void DialControl::InvalidateControl() 422{ |
464 mpImpl->maBmpBuffered.CopyBackground( IsEnabled() ? mpImpl->maBmpEnabled : mpImpl->maBmpDisabled ); | 423 mpImpl->mpBmpBuffered->CopyBackground( IsEnabled() ? *mpImpl->mpBmpEnabled : *mpImpl->mpBmpDisabled ); |
465 if( !mpImpl->mbNoRot ) | 424 if( !mpImpl->mbNoRot ) |
466 mpImpl->maBmpBuffered.DrawElements( GetText(), mpImpl->mnAngle ); | 425 mpImpl->mpBmpBuffered->DrawElements( GetText(), mpImpl->mnAngle ); |
467 Invalidate(); 468} 469 | 426 Invalidate(); 427} 428 |
470void DialControl::ImplSetRotation( sal_Int32 nAngle, bool bBroadcast ) | 429void DialControl::SetRotation( sal_Int32 nAngle, bool bBroadcast ) |
471{ 472 bool bOldSel = mpImpl->mbNoRot; 473 mpImpl->mbNoRot = false; 474 475 while( nAngle < 0 ) nAngle += 36000; 476 nAngle = (((nAngle + 50) / 100) * 100) % 36000; 477 if( !bOldSel || (mpImpl->mnAngle != nAngle) ) 478 { --- 28 unchanged lines hidden (view full) --- 507 if( fH != 0.0 ) 508 { 509 double fAngle = acos( nX / fH ); 510 sal_Int32 nAngle = static_cast< sal_Int32 >( fAngle / F_PI180 * 100.0 ); 511 if( nY < 0 ) 512 nAngle = 36000 - nAngle; 513 if( bInitial ) // round to entire 15 degrees 514 nAngle = ((nAngle + 750) / 1500) * 1500; | 430{ 431 bool bOldSel = mpImpl->mbNoRot; 432 mpImpl->mbNoRot = false; 433 434 while( nAngle < 0 ) nAngle += 36000; 435 nAngle = (((nAngle + 50) / 100) * 100) % 36000; 436 if( !bOldSel || (mpImpl->mnAngle != nAngle) ) 437 { --- 28 unchanged lines hidden (view full) --- 466 if( fH != 0.0 ) 467 { 468 double fAngle = acos( nX / fH ); 469 sal_Int32 nAngle = static_cast< sal_Int32 >( fAngle / F_PI180 * 100.0 ); 470 if( nY < 0 ) 471 nAngle = 36000 - nAngle; 472 if( bInitial ) // round to entire 15 degrees 473 nAngle = ((nAngle + 750) / 1500) * 1500; |
515 ImplSetRotation( nAngle, true ); | 474 SetRotation( nAngle, true ); |
516 } 517} 518 519void DialControl::HandleEscapeEvent() 520{ 521 if( IsMouseCaptured() ) 522 { 523 ReleaseMouse(); | 475 } 476} 477 478void DialControl::HandleEscapeEvent() 479{ 480 if( IsMouseCaptured() ) 481 { 482 ReleaseMouse(); |
524 ImplSetRotation( mpImpl->mnOldAngle, true ); | 483 SetRotation( mpImpl->mnOldAngle, true ); |
525 if( mpImpl->mpLinkField ) 526 mpImpl->mpLinkField->GrabFocus(); 527 } 528} 529 530IMPL_LINK( DialControl, LinkedFieldModifyHdl, NumericField*, pField ) 531{ 532 if( pField ) | 484 if( mpImpl->mpLinkField ) 485 mpImpl->mpLinkField->GrabFocus(); 486 } 487} 488 489IMPL_LINK( DialControl, LinkedFieldModifyHdl, NumericField*, pField ) 490{ 491 if( pField ) |
533 ImplSetRotation( static_cast< sal_Int32 >( pField->GetValue() * 100 ), false ); | 492 SetRotation( static_cast< sal_Int32 >( pField->GetValue() * 100 ), false ); |
534 return 0; 535} 536 537// ============================================================================ 538 539DialControlWrapper::DialControlWrapper( DialControl& rDial ) : 540 SingleControlWrapperType( rDial ) 541{ --- 27 unchanged lines hidden --- | 493 return 0; 494} 495 496// ============================================================================ 497 498DialControlWrapper::DialControlWrapper( DialControl& rDial ) : 499 SingleControlWrapperType( rDial ) 500{ --- 27 unchanged lines hidden --- |