OOO330
[LibreOffice.git] / soldep / source / tbox.cxx
blob3279411678080e1676fa580f2c08da5853ade643
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
27 #define private public
29 #include <tools/ref.hxx>
30 #include <vcl/msgbox.hxx>
31 #include <soldep/soldep.hxx>
32 #include <soldep/tbox.hxx>
33 #include <soldep/soldlg.hrc>
37 SoldepToolBox::SoldepToolBox( Window* pParent, const ResId& aId, BOOL bDAble ) :
38 ToolBox( pParent, aId ),
39 bDockable( bDAble ),
40 bCloseMode( FALSE ),
41 bBoxIsVisible( TRUE ),
42 bPinable( TRUE ),
43 aPinedBitmap( DtSodResId( TID_SMALL_PIN_PINED )), // BMP_SMALL_PIN_PINED
44 aUnpinedBitmap( DtSodResId( TID_SMALL_PIN_UNPINED )) // BMP_SMALL_PIN_UNPINED
46 bPinable = TRUE;
48 SetAlign( WINDOWALIGN_TOP );
49 HideItem(TID_SOLDEP_BACK); //Inital hide this item, activated in project view.
50 HideItem(TID_SOLDEP_SAVE); // Hide this item now, not used yet
51 HideItem(TID_SOLDEP_OPEN); // Hide this item now, not used yet
53 //SetMouseDownHdl(LINK(this,SoldepToolBox,MouseDownHdl));
54 //SetFloatingLines( nFloatingLines );
55 //SetFloatingMode( bFloatingMode );
56 BOOL bFloatingMode = FALSE;
57 if ( bFloatingMode )
59 //Point aPos( sToolBoxInfo.GetToken( 4, ',' ).ToInt64(), sToolBoxInfo.GetToken( 5, ',' ).ToInt64());
60 //SetPosPixel( aPos );
63 if ( bDockable ) InsertSeparator( 0 ); // Freiraum für Abreißdödel schaffen
64 // (ein Separator an 1er Pos wird
65 // nicht gezeichnet,
66 // schafft aber Platz.)
67 bBoxIsVisible = FALSE;
68 // if ( sToolBoxInfo.GetToken( 3, ',' ) == "Visible" ) {
69 for ( USHORT i = 0; i < GetItemCount() && !bBoxIsVisible; i++ )
71 // USHORT nItemId = GetItemId( i );
73 switch ( GetItemType( i ))
75 case TOOLBOXITEM_SPACE:
76 break;
77 case TOOLBOXITEM_SEPARATOR :
78 break;
79 default:
80 bBoxIsVisible = TRUE;
81 break;
84 // }
86 if ( bBoxIsVisible ) {
87 if (!bDockable)
88 Show();
89 else
90 Hide();
92 else
93 Hide();
95 bOldFloatMode = IsFloatingMode();
98 /*************************************************************************
99 |* SoldepToolBox::~SoldepToolBox()
100 |************************************************************************/
102 SoldepToolBox::~SoldepToolBox()
106 /*************************************************************************
107 |* SoldepToolBox::Paint()
108 |************************************************************************/
110 void SoldepToolBox::Paint( const Rectangle& rRect )
112 SetOutStyle( TOOLBOX_STYLE_FLAT );
114 // Wenn wir eine Dockable ToolBox haben, ...
116 if ( bDockable )
118 USHORT nItemId = GetItemId( 0 );
120 // ... zeichnen wir den wunderbaren Abreiád”del �ber das erste Item (Seperator)
122 if ( !IsFloatingMode() && ( mnCurLine == 1 )) {
123 BOOL bIsCloseable = (( mnWinStyle & WB_CLOSEABLE ) != 0 );
125 ShowItem( nItemId );
126 Rectangle aRect = GetItemRect( nItemId );
128 ToolBox::Paint( rRect );
130 if ( bIsCloseable )
132 // Paint small cross button left/top of toolbar
133 SetLineColor( Color( COL_WHITE ));
135 DrawLine( Point( aRect.Left(), aRect.Top()), Point( aRect.Left()+6, aRect.Top()));
136 DrawLine( Point( aRect.Left(), aRect.Top()), Point( aRect.Left(), aRect.Top()+6));
138 SetLineColor( Color( COL_GRAY ));
140 DrawLine( Point( aRect.Left(), aRect.Top()+6), Point( aRect.Left()+6, aRect.Top()+6));
141 DrawLine( Point( aRect.Left()+6, aRect.Top()), Point( aRect.Left()+6, aRect.Top()+6));
143 SetLineColor( Color( COL_BLACK ));
145 DrawLine( Point( aRect.Left()+2, aRect.Top()+2), Point( aRect.Left()+4, aRect.Top()+4));
146 DrawLine( Point( aRect.Left()+2, aRect.Top()+4), Point( aRect.Left()+4, aRect.Top()+2));
148 else if ( bPinable )
150 if ( GetPin())
151 DrawBitmap( Point( aRect.Left(), aRect.Top()), aPinedBitmap );
152 else
153 DrawBitmap( Point( aRect.Left(), aRect.Top()), aUnpinedBitmap );
156 SetLineColor( Color( COL_WHITE ));
158 if ( IsHorizontal())
160 if ( bIsCloseable || bPinable ) aRect = Rectangle( Point( aRect.Left(), aRect.Top()+8), Point( aRect.Right(), aRect.Bottom()));
162 DrawLine( Point(aRect.Left(), aRect.Top()), Point(aRect.Left(), aRect.Bottom()));
163 DrawLine( Point(aRect.Left(), aRect.Top()), Point(aRect.Left()+2, aRect.Top()));
165 SetLineColor( Color( COL_WHITE ));
167 DrawLine( Point(aRect.Left()+4, aRect.Top()), Point(aRect.Left()+4, aRect.Bottom()));
168 DrawLine( Point(aRect.Left()+4, aRect.Top()), Point(aRect.Left()+6, aRect.Top()));
170 SetLineColor( Color( COL_GRAY ));//GRAY
172 DrawLine( Point(aRect.Left()+2, aRect.Top()), Point(aRect.Left()+2, aRect.Bottom()));
173 DrawLine( Point(aRect.Left(), aRect.Bottom()), Point(aRect.Left()+2, aRect.Bottom()));
175 SetLineColor( Color( COL_BLACK ));
177 DrawLine( Point(aRect.Left()+6, aRect.Top()), Point(aRect.Left()+6, aRect.Bottom()));
178 DrawLine( Point(aRect.Left()+4, aRect.Bottom()), Point(aRect.Left()+6, aRect.Bottom()));
181 else
183 if ( bIsCloseable || bPinable ) aRect = Rectangle( Point( aRect.Left()+8, aRect.Top()), Point( aRect.Right(), aRect.Bottom()));
185 DrawLine( Point( aRect.Left(), aRect.Top()), Point( aRect.Left(), aRect.Top()+2));
186 DrawLine( Point( aRect.Left(), aRect.Top()), Point( aRect.Right(), aRect.Top()));
188 DrawLine( Point( aRect.Left(), aRect.Top()+4), Point( aRect.Left(), aRect.Top()+6));
189 DrawLine( Point( aRect.Left(), aRect.Top()+4), Point( aRect.Right(), aRect.Top()+4));
191 SetLineColor( Color( COL_GRAY ));
193 DrawLine( Point( aRect.Left(), aRect.Top()+2), Point( aRect.Right(),aRect.Top()+2));
194 DrawLine( Point( aRect.Right(), aRect.Top()), Point( aRect.Right(), aRect.Top()+2));
196 DrawLine( Point( aRect.Left(), aRect.Top()+6), Point( aRect.Right(),aRect.Top()+6));
197 DrawLine( Point( aRect.Right(), aRect.Top()+4), Point( aRect.Right(), aRect.Top()+6));
201 else
203 // Sind wir im FloatingMode, dann wollen wir keinen Abreißdödel haben
204 // und hiden somit das erste Item.
206 //Hiden löscht leider das erste Object der nächsten Zeile, daher nicht
207 //löschen
208 HideItem( nItemId );
209 ToolBox::Paint( rRect );
212 else
214 ToolBox::Paint( rRect );
218 /*************************************************************************
219 |* SoldepToolBox::MouseButtonDown()
220 |************************************************************************/
222 void SoldepToolBox::MouseButtonDown(const MouseEvent& rEvent)
224 // Sind wir im DockingMode, ...
226 if ( !IsFloatingMode() && ((( mnWinStyle & WB_CLOSEABLE ) != 0 ) || bPinable ))
228 // ... dann testen wir, ob am Abreiád”del der Close-Button gedr�ckt wurde ...
230 Rectangle aRect = GetItemRect( GetItemId( 0 ));
231 aRect = Rectangle( aRect.TopLeft(), Point( aRect.Left()+6, aRect.Top()+6 ));
232 if ( rEvent.IsLeft() && aRect.IsInside( rEvent.GetPosPixel()))
234 if ( bPinable ) {
235 TogglePin();
236 Invalidate();
238 else {
239 bCloseMode = TRUE;
241 // ... und zeichnen ggf. den Button gedr�ckt.
243 SetLineColor( Color( COL_WHITE ));
245 DrawLine( Point( aRect.Left(), aRect.Bottom()), Point( aRect.Right(), aRect.Bottom()));
246 DrawLine( Point( aRect.Right(), aRect.Bottom()), Point( aRect.Right(), aRect.Top()));
248 SetLineColor( Color( COL_GRAY ));
250 DrawLine( Point( aRect.Left(), aRect.Top()), Point( aRect.Right(), aRect.Top()));
251 DrawLine( Point( aRect.Left(), aRect.Top()), Point( aRect.Left(), aRect.Bottom()));
254 else
256 ToolBox::MouseButtonDown( rEvent );
259 else
261 ToolBox::MouseButtonDown( rEvent );
264 aMouseDownHdl.Call(this);
267 /*************************************************************************
268 |* SoldepToolBox::MouseButtonUp()
269 |************************************************************************/
271 void SoldepToolBox::MouseButtonUp(const MouseEvent& rEvent)
273 // Wenn der Close-Button am Abreiád”del zuvor gedr�ckt wurde, ...
275 if ( bCloseMode )
277 bCloseMode = FALSE;
279 // ... so zeichen wir diesen wieder normal ...
281 Rectangle aRect = GetItemRect( GetItemId( 0 ));
282 aRect = Rectangle( aRect.TopLeft(), Point( aRect.Left()+6, aRect.Top()+6 ));
284 SetLineColor( Color( COL_WHITE ));
286 DrawLine( Point( aRect.Left(), aRect.Top()), Point( aRect.Right(), aRect.Top()));
287 DrawLine( Point( aRect.Left(), aRect.Top()), Point( aRect.Left(), aRect.Bottom()));
289 SetLineColor( Color( COL_GRAY ));
291 DrawLine( Point( aRect.Left(), aRect.Bottom()), Point( aRect.Right(), aRect.Bottom()));
292 DrawLine( Point( aRect.Right(), aRect.Bottom()), Point( aRect.Right(), aRect.Top()));
294 if ( rEvent.IsLeft() && aRect.IsInside( rEvent.GetPosPixel()))
296 // ... und schlieáen die Box durch Aufruf der virtuellen Methode
297 // CloseDockingMode().
299 CloseDockingMode();
301 else
303 ToolBox::MouseButtonUp( rEvent );
306 else
308 ToolBox::MouseButtonUp( rEvent );
312 /*************************************************************************
313 |* SoldepToolBox::MouseMove()
314 |************************************************************************/
316 void SoldepToolBox::MouseMove(const MouseEvent& rEvent)
318 // Wenn der Close-Button am Abreiád”del zuvor gedr�ckt wurde, ...
320 if ( bCloseMode )
322 Rectangle aRect = GetItemRect( GetItemId( 0 ));
323 aRect = Rectangle( aRect.TopLeft(), Point( aRect.Left()+6, aRect.Top()+6 ));
325 // ... der Mouse-Zeiger jedoch den Close-Button verl„át, ...
327 if ( !aRect.IsInside( rEvent.GetPosPixel()))
329 SetLineColor( Color( COL_WHITE ));
331 // ... zeichnen wir diesen halt wieder normal.
333 DrawLine( Point( aRect.Left(), aRect.Top()), Point( aRect.Right(), aRect.Top()));
334 DrawLine( Point( aRect.Left(), aRect.Top()), Point( aRect.Left(), aRect.Bottom()));
336 SetLineColor( Color( COL_GRAY ));
338 DrawLine( Point( aRect.Left(), aRect.Bottom()), Point( aRect.Right(), aRect.Bottom()));
339 DrawLine( Point( aRect.Right(), aRect.Bottom()), Point( aRect.Right(), aRect.Top()));
341 bCloseMode = FALSE;
343 else
345 ToolBox::MouseMove( rEvent );
348 else
350 ToolBox::MouseMove( rEvent );
354 /*****************************************************************************/
355 void SoldepToolBox::ToggleFloatingMode()
356 /*****************************************************************************/
358 ToolBox::ToggleFloatingMode();
359 CallEventListeners( VCLEVENT_USER_TBOX_RESIZE_APP, this);
362 /*****************************************************************************/
363 void SoldepToolBox::EndDocking( const Rectangle& rRect, BOOL bFloatMode )
364 /*****************************************************************************/
366 ToolBox::EndDocking( rRect, bFloatMode );
367 if ( aResizeHdl.IsSet())
368 CallEventListeners( VCLEVENT_USER_TBOX_RESIZE_APP, this);
369 else
371 GetParent()->Resize();
375 /*****************************************************************************/
376 BOOL SoldepToolBox::Close()
377 /*****************************************************************************/
379 if (!ToolBox::Close()) return FALSE;
381 return TRUE;
384 /*****************************************************************************/
385 void SoldepToolBox::Move()
386 /*****************************************************************************/
390 /*************************************************************************
391 |* SoldepToolBox::CloseDockingMode()
393 |* virtuelle Methode zur Reaktion auf den Close-Button im DockinMode
394 |************************************************************************/
396 void SoldepToolBox::CloseDockingMode()
398 Hide();
399 bBoxIsVisible = FALSE;
400 CallEventListeners( VCLEVENT_USER_TBOX_RESIZE_APP, this);
403 /*************************************************************************
404 |* SoldepToolBox::Command()
405 |************************************************************************/
407 void SoldepToolBox::Command( const CommandEvent& rCEvt)
409 if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
411 if( !IsFloatingMode() && bDockable
412 && ( GetItemRect(GetItemId( 0 )).IsInside(rCEvt.GetMousePosPixel())))
414 // Hier das Context-Menue fuer Abreißdödel dynamisch erzeugen...
416 PopupMenu aPopupMenu;
418 String sText( String::CreateFromAscii( "Floating mode" ));
419 aPopupMenu.InsertItem( 5, sText );
420 aPopupMenu.InsertSeparator();
422 sText = String::CreateFromAscii( "Top" );
423 aPopupMenu.InsertItem( 1, sText );
424 sText = String::CreateFromAscii( "Bottom" );
425 aPopupMenu.InsertItem( 2, sText );
426 sText = String::CreateFromAscii( "Left" );
427 aPopupMenu.InsertItem( 3, sText );
428 sText = String::CreateFromAscii( "Right" );
429 aPopupMenu.InsertItem( 4, sText );
431 switch( GetAlign())
433 case WINDOWALIGN_TOP : aPopupMenu.EnableItem( 1, FALSE ); break;
434 case WINDOWALIGN_BOTTOM : aPopupMenu.EnableItem( 2, FALSE ); break;
435 case WINDOWALIGN_LEFT : aPopupMenu.EnableItem( 3, FALSE ); break;
436 case WINDOWALIGN_RIGHT : aPopupMenu.EnableItem( 4, FALSE ); break;
439 if (( mnWinStyle & WB_CLOSEABLE ) != 0 )
441 aPopupMenu.InsertSeparator();
442 sText = String::CreateFromAscii( "Hide" );
443 aPopupMenu.InsertItem( 6, sText );
445 else if ( bPinable ) {
446 aPopupMenu.InsertSeparator();
447 sText = String::CreateFromAscii( "Pin" );
448 aPopupMenu.InsertItem( 6, sText );
449 aPopupMenu.CheckItem( 6, GetPin());
452 // ... und rufen.
454 aPopupMenu.SetSelectHdl ( LINK ( this, SoldepToolBox, MenuSelectHdl ));
455 aPopupMenu.Execute( this, rCEvt.GetMousePosPixel());
457 else if ( !GetItemId(rCEvt.GetMousePosPixel()))
459 CallContextMenu( this, rCEvt.GetMousePosPixel());
462 else ToolBox::Command( rCEvt );
465 /*************************************************************************
466 |* SoldepToolBox::GetContextMenu()
467 |************************************************************************/
469 PopupMenu *SoldepToolBox::GetContextMenu()
471 InitContextMenu();
472 return &aMenu;
475 /*************************************************************************
476 |* SoldepToolBox::InitContextMenu()
477 |************************************************************************/
479 void SoldepToolBox::InitContextMenu()
481 USHORT nStart = 0;
482 if ( bDockable )
483 nStart = 1;
485 aMenu.Clear();
487 for ( USHORT i = nStart; i < GetItemCount(); i++ )
489 USHORT nItemId = GetItemId( i );
491 switch ( GetItemType( i ))
493 case TOOLBOXITEM_SPACE:
494 break;
495 case TOOLBOXITEM_SEPARATOR :
496 if (!(( i < GetItemCount() - 1 ) && ( GetItemType( i + 1 ) == TOOLBOXITEM_DONTKNOW )))
497 aMenu.InsertSeparator();
498 break;
499 default:
500 aMenu.InsertItem( nItemId, GetItemText( nItemId ), GetItemImage( nItemId ));
501 if (IsItemChecked( nItemId )) aMenu.CheckItem( nItemId, TRUE );
502 if (!IsItemEnabled( nItemId )) aMenu.EnableItem( nItemId, FALSE );
503 if (!IsItemVisible( nItemId )) aMenu.HideItem(nItemId);
504 break;
509 /*************************************************************************
510 |* SoldepToolBox::CallContextMenu()
511 |************************************************************************/
513 void SoldepToolBox::CallContextMenu( Window *pWin, Point aPos )
515 if ( aMenu.IsInExecute())
516 return;
518 InitContextMenu();
520 // ... und rufen.
522 aMenu.SetSelectHdl ( LINK ( this, SoldepToolBox, MenuSelectHdl ));
523 aMenu.Execute( pWin, aPos );
526 void SoldepToolBox::SetPosSizePixel( const Point& rNewPos,
527 const Size& rNewSize )
529 // if(rNewPos != GetPosPixel() || rNewSize != GetSizePixel())
530 // {
531 ToolBox::SetPosSizePixel(rNewPos,rNewSize);
532 // Resize();
533 // }
536 void SoldepToolBox::SetDockingRects( const Rectangle& rOutRect,
537 const Rectangle& rInRect )
539 if(rOutRect != aOutRect || rInRect != aInRect)
541 ToolBox::SetDockingRects(rOutRect,rInRect);
542 Invalidate();
544 aOutRect = rOutRect;
545 aInRect = rInRect;
549 /*****************************************************************************/
550 void SoldepToolBox::StartDocking()
551 /*****************************************************************************/
553 ToolBox::StartDocking();
554 CallEventListeners( VCLEVENT_USER_TBOX_RESIZE_APP, this);
557 BOOL SoldepToolBox::GetPin()
560 return bPin;
563 void SoldepToolBox::TogglePin()
565 bPin = !bPin;
568 void SoldepToolBox::SetPin( BOOL bP )
570 bPin = bP;
573 /*************************************************************************
574 |* SoldepToolBox::MenuSelectHdl()
576 |* Handler, der beim Execute der Context-Men�s gerufen wird
577 |************************************************************************/
579 IMPL_LINK ( SoldepToolBox, MenuSelectHdl, Menu*, pMenu )
581 // Wenn die CurItemId <= 6 ist, dann wurde das Abreiád”del-Context-Men� ausgef�hrt ...
582 ULONG itemid;
583 itemid = pMenu->GetCurItemId();
585 if ( pMenu == &aMenu )
587 // ... Andernfalls wurde das Default-Context-Men� ausgef�hrt ...
588 USHORT nTmpId = mnCurItemId;
589 mnCurItemId = pMenu->GetCurItemId();
591 // ... und der gesetzte Handler (in soldep.cxx) wird gerufen.
592 maSelectHdl.Call( this );
593 mnCurItemId = nTmpId;
595 return 0;