update dev300-m58
[ooovba.git] / soldep / source / tbox.cxx
blob55877b14277c463cd43d944fcac3ecf24b03a98b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tbox.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #define private public
32 #include <tools/ref.hxx>
33 #include <vcl/msgbox.hxx>
34 #include <soldep/soldep.hxx>
35 #include <soldep/tbox.hxx>
36 #include <soldep/soldlg.hrc>
40 SoldepToolBox::SoldepToolBox( Window* pParent, const ResId& aId, BOOL bDAble ) :
41 ToolBox( pParent, aId ),
42 bDockable( bDAble ),
43 bCloseMode( FALSE ),
44 bBoxIsVisible( TRUE ),
45 bPinable( TRUE ),
46 aPinedBitmap( DtSodResId( TID_SMALL_PIN_PINED )), // BMP_SMALL_PIN_PINED
47 aUnpinedBitmap( DtSodResId( TID_SMALL_PIN_UNPINED )) // BMP_SMALL_PIN_UNPINED
49 bPinable = TRUE;
51 SetAlign( WINDOWALIGN_TOP );
52 HideItem(TID_SOLDEP_BACK); //Inital hide this item, activated in project view.
53 HideItem(TID_SOLDEP_SAVE); // Hide this item now, not used yet
54 HideItem(TID_SOLDEP_OPEN); // Hide this item now, not used yet
56 //SetMouseDownHdl(LINK(this,SoldepToolBox,MouseDownHdl));
57 //SetFloatingLines( nFloatingLines );
58 //SetFloatingMode( bFloatingMode );
59 BOOL bFloatingMode = FALSE;
60 if ( bFloatingMode )
62 //Point aPos( sToolBoxInfo.GetToken( 4, ',' ).ToInt64(), sToolBoxInfo.GetToken( 5, ',' ).ToInt64());
63 //SetPosPixel( aPos );
66 if ( bDockable ) InsertSeparator( 0 ); // Freiraum für Abreißdödel schaffen
67 // (ein Separator an 1er Pos wird
68 // nicht gezeichnet,
69 // schafft aber Platz.)
70 bBoxIsVisible = FALSE;
71 // if ( sToolBoxInfo.GetToken( 3, ',' ) == "Visible" ) {
72 for ( USHORT i = 0; i < GetItemCount() && !bBoxIsVisible; i++ )
74 // USHORT nItemId = GetItemId( i );
76 switch ( GetItemType( i ))
78 case TOOLBOXITEM_SPACE:
79 break;
80 case TOOLBOXITEM_SEPARATOR :
81 break;
82 default:
83 bBoxIsVisible = TRUE;
84 break;
87 // }
89 if ( bBoxIsVisible ) {
90 if (!bDockable)
91 Show();
92 else
93 Hide();
95 else
96 Hide();
98 bOldFloatMode = IsFloatingMode();
101 /*************************************************************************
102 |* SoldepToolBox::~SoldepToolBox()
103 |************************************************************************/
105 SoldepToolBox::~SoldepToolBox()
109 /*************************************************************************
110 |* SoldepToolBox::Paint()
111 |************************************************************************/
113 void SoldepToolBox::Paint( const Rectangle& rRect )
115 SetOutStyle( TOOLBOX_STYLE_FLAT );
117 // Wenn wir eine Dockable ToolBox haben, ...
119 if ( bDockable )
121 USHORT nItemId = GetItemId( 0 );
123 // ... zeichnen wir den wunderbaren Abreiád”del �ber das erste Item (Seperator)
125 if ( !IsFloatingMode() && ( mnCurLine == 1 )) {
126 BOOL bIsCloseable = (( mnWinStyle & WB_CLOSEABLE ) != 0 );
128 ShowItem( nItemId );
129 Rectangle aRect = GetItemRect( nItemId );
131 ToolBox::Paint( rRect );
133 if ( bIsCloseable )
135 // Paint small cross button left/top of toolbar
136 SetLineColor( Color( COL_WHITE ));
138 DrawLine( Point( aRect.Left(), aRect.Top()), Point( aRect.Left()+6, aRect.Top()));
139 DrawLine( Point( aRect.Left(), aRect.Top()), Point( aRect.Left(), aRect.Top()+6));
141 SetLineColor( Color( COL_GRAY ));
143 DrawLine( Point( aRect.Left(), aRect.Top()+6), Point( aRect.Left()+6, aRect.Top()+6));
144 DrawLine( Point( aRect.Left()+6, aRect.Top()), Point( aRect.Left()+6, aRect.Top()+6));
146 SetLineColor( Color( COL_BLACK ));
148 DrawLine( Point( aRect.Left()+2, aRect.Top()+2), Point( aRect.Left()+4, aRect.Top()+4));
149 DrawLine( Point( aRect.Left()+2, aRect.Top()+4), Point( aRect.Left()+4, aRect.Top()+2));
151 else if ( bPinable )
153 if ( GetPin())
154 DrawBitmap( Point( aRect.Left(), aRect.Top()), aPinedBitmap );
155 else
156 DrawBitmap( Point( aRect.Left(), aRect.Top()), aUnpinedBitmap );
159 SetLineColor( Color( COL_WHITE ));
161 if ( IsHorizontal())
163 if ( bIsCloseable || bPinable ) aRect = Rectangle( Point( aRect.Left(), aRect.Top()+8), Point( aRect.Right(), aRect.Bottom()));
165 DrawLine( Point(aRect.Left(), aRect.Top()), Point(aRect.Left(), aRect.Bottom()));
166 DrawLine( Point(aRect.Left(), aRect.Top()), Point(aRect.Left()+2, aRect.Top()));
168 SetLineColor( Color( COL_WHITE ));
170 DrawLine( Point(aRect.Left()+4, aRect.Top()), Point(aRect.Left()+4, aRect.Bottom()));
171 DrawLine( Point(aRect.Left()+4, aRect.Top()), Point(aRect.Left()+6, aRect.Top()));
173 SetLineColor( Color( COL_GRAY ));//GRAY
175 DrawLine( Point(aRect.Left()+2, aRect.Top()), Point(aRect.Left()+2, aRect.Bottom()));
176 DrawLine( Point(aRect.Left(), aRect.Bottom()), Point(aRect.Left()+2, aRect.Bottom()));
178 SetLineColor( Color( COL_BLACK ));
180 DrawLine( Point(aRect.Left()+6, aRect.Top()), Point(aRect.Left()+6, aRect.Bottom()));
181 DrawLine( Point(aRect.Left()+4, aRect.Bottom()), Point(aRect.Left()+6, aRect.Bottom()));
184 else
186 if ( bIsCloseable || bPinable ) aRect = Rectangle( Point( aRect.Left()+8, aRect.Top()), Point( aRect.Right(), aRect.Bottom()));
188 DrawLine( Point( aRect.Left(), aRect.Top()), Point( aRect.Left(), aRect.Top()+2));
189 DrawLine( Point( aRect.Left(), aRect.Top()), Point( aRect.Right(), aRect.Top()));
191 DrawLine( Point( aRect.Left(), aRect.Top()+4), Point( aRect.Left(), aRect.Top()+6));
192 DrawLine( Point( aRect.Left(), aRect.Top()+4), Point( aRect.Right(), aRect.Top()+4));
194 SetLineColor( Color( COL_GRAY ));
196 DrawLine( Point( aRect.Left(), aRect.Top()+2), Point( aRect.Right(),aRect.Top()+2));
197 DrawLine( Point( aRect.Right(), aRect.Top()), Point( aRect.Right(), aRect.Top()+2));
199 DrawLine( Point( aRect.Left(), aRect.Top()+6), Point( aRect.Right(),aRect.Top()+6));
200 DrawLine( Point( aRect.Right(), aRect.Top()+4), Point( aRect.Right(), aRect.Top()+6));
204 else
206 // Sind wir im FloatingMode, dann wollen wir keinen Abreißdödel haben
207 // und hiden somit das erste Item.
209 //Hiden löscht leider das erste Object der nächsten Zeile, daher nicht
210 //löschen
211 HideItem( nItemId );
212 ToolBox::Paint( rRect );
215 else
217 ToolBox::Paint( rRect );
221 /*************************************************************************
222 |* SoldepToolBox::MouseButtonDown()
223 |************************************************************************/
225 void SoldepToolBox::MouseButtonDown(const MouseEvent& rEvent)
227 // Sind wir im DockingMode, ...
229 if ( !IsFloatingMode() && ((( mnWinStyle & WB_CLOSEABLE ) != 0 ) || bPinable ))
231 // ... dann testen wir, ob am Abreiád”del der Close-Button gedr�ckt wurde ...
233 Rectangle aRect = GetItemRect( GetItemId( 0 ));
234 aRect = Rectangle( aRect.TopLeft(), Point( aRect.Left()+6, aRect.Top()+6 ));
235 if ( rEvent.IsLeft() && aRect.IsInside( rEvent.GetPosPixel()))
237 if ( bPinable ) {
238 TogglePin();
239 Invalidate();
241 else {
242 bCloseMode = TRUE;
244 // ... und zeichnen ggf. den Button gedr�ckt.
246 SetLineColor( Color( COL_WHITE ));
248 DrawLine( Point( aRect.Left(), aRect.Bottom()), Point( aRect.Right(), aRect.Bottom()));
249 DrawLine( Point( aRect.Right(), aRect.Bottom()), Point( aRect.Right(), aRect.Top()));
251 SetLineColor( Color( COL_GRAY ));
253 DrawLine( Point( aRect.Left(), aRect.Top()), Point( aRect.Right(), aRect.Top()));
254 DrawLine( Point( aRect.Left(), aRect.Top()), Point( aRect.Left(), aRect.Bottom()));
257 else
259 ToolBox::MouseButtonDown( rEvent );
262 else
264 ToolBox::MouseButtonDown( rEvent );
267 aMouseDownHdl.Call(this);
270 /*************************************************************************
271 |* SoldepToolBox::MouseButtonUp()
272 |************************************************************************/
274 void SoldepToolBox::MouseButtonUp(const MouseEvent& rEvent)
276 // Wenn der Close-Button am Abreiád”del zuvor gedr�ckt wurde, ...
278 if ( bCloseMode )
280 bCloseMode = FALSE;
282 // ... so zeichen wir diesen wieder normal ...
284 Rectangle aRect = GetItemRect( GetItemId( 0 ));
285 aRect = Rectangle( aRect.TopLeft(), Point( aRect.Left()+6, aRect.Top()+6 ));
287 SetLineColor( Color( COL_WHITE ));
289 DrawLine( Point( aRect.Left(), aRect.Top()), Point( aRect.Right(), aRect.Top()));
290 DrawLine( Point( aRect.Left(), aRect.Top()), Point( aRect.Left(), aRect.Bottom()));
292 SetLineColor( Color( COL_GRAY ));
294 DrawLine( Point( aRect.Left(), aRect.Bottom()), Point( aRect.Right(), aRect.Bottom()));
295 DrawLine( Point( aRect.Right(), aRect.Bottom()), Point( aRect.Right(), aRect.Top()));
297 if ( rEvent.IsLeft() && aRect.IsInside( rEvent.GetPosPixel()))
299 // ... und schlieáen die Box durch Aufruf der virtuellen Methode
300 // CloseDockingMode().
302 CloseDockingMode();
304 else
306 ToolBox::MouseButtonUp( rEvent );
309 else
311 ToolBox::MouseButtonUp( rEvent );
315 /*************************************************************************
316 |* SoldepToolBox::MouseMove()
317 |************************************************************************/
319 void SoldepToolBox::MouseMove(const MouseEvent& rEvent)
321 // Wenn der Close-Button am Abreiád”del zuvor gedr�ckt wurde, ...
323 if ( bCloseMode )
325 Rectangle aRect = GetItemRect( GetItemId( 0 ));
326 aRect = Rectangle( aRect.TopLeft(), Point( aRect.Left()+6, aRect.Top()+6 ));
328 // ... der Mouse-Zeiger jedoch den Close-Button verl„át, ...
330 if ( !aRect.IsInside( rEvent.GetPosPixel()))
332 SetLineColor( Color( COL_WHITE ));
334 // ... zeichnen wir diesen halt wieder normal.
336 DrawLine( Point( aRect.Left(), aRect.Top()), Point( aRect.Right(), aRect.Top()));
337 DrawLine( Point( aRect.Left(), aRect.Top()), Point( aRect.Left(), aRect.Bottom()));
339 SetLineColor( Color( COL_GRAY ));
341 DrawLine( Point( aRect.Left(), aRect.Bottom()), Point( aRect.Right(), aRect.Bottom()));
342 DrawLine( Point( aRect.Right(), aRect.Bottom()), Point( aRect.Right(), aRect.Top()));
344 bCloseMode = FALSE;
346 else
348 ToolBox::MouseMove( rEvent );
351 else
353 ToolBox::MouseMove( rEvent );
357 /*****************************************************************************/
358 void SoldepToolBox::ToggleFloatingMode()
359 /*****************************************************************************/
361 ToolBox::ToggleFloatingMode();
362 CallEventListeners( VCLEVENT_USER_TBOX_RESIZE_APP, this);
365 /*****************************************************************************/
366 void SoldepToolBox::EndDocking( const Rectangle& rRect, BOOL bFloatMode )
367 /*****************************************************************************/
369 ToolBox::EndDocking( rRect, bFloatMode );
370 if ( aResizeHdl.IsSet())
371 CallEventListeners( VCLEVENT_USER_TBOX_RESIZE_APP, this);
372 else
374 GetParent()->Resize();
378 /*****************************************************************************/
379 BOOL SoldepToolBox::Close()
380 /*****************************************************************************/
382 if (!ToolBox::Close()) return FALSE;
384 return TRUE;
387 /*****************************************************************************/
388 void SoldepToolBox::Move()
389 /*****************************************************************************/
393 /*************************************************************************
394 |* SoldepToolBox::CloseDockingMode()
396 |* virtuelle Methode zur Reaktion auf den Close-Button im DockinMode
397 |************************************************************************/
399 void SoldepToolBox::CloseDockingMode()
401 Hide();
402 bBoxIsVisible = FALSE;
403 CallEventListeners( VCLEVENT_USER_TBOX_RESIZE_APP, this);
406 /*************************************************************************
407 |* SoldepToolBox::Command()
408 |************************************************************************/
410 void SoldepToolBox::Command( const CommandEvent& rCEvt)
412 if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
414 if( !IsFloatingMode() && bDockable
415 && ( GetItemRect(GetItemId( 0 )).IsInside(rCEvt.GetMousePosPixel())))
417 // Hier das Context-Menue fuer Abreißdödel dynamisch erzeugen...
419 PopupMenu aPopupMenu;
421 String sText( String::CreateFromAscii( "Floating mode" ));
422 aPopupMenu.InsertItem( 5, sText );
423 aPopupMenu.InsertSeparator();
425 sText = String::CreateFromAscii( "Top" );
426 aPopupMenu.InsertItem( 1, sText );
427 sText = String::CreateFromAscii( "Bottom" );
428 aPopupMenu.InsertItem( 2, sText );
429 sText = String::CreateFromAscii( "Left" );
430 aPopupMenu.InsertItem( 3, sText );
431 sText = String::CreateFromAscii( "Right" );
432 aPopupMenu.InsertItem( 4, sText );
434 switch( GetAlign())
436 case WINDOWALIGN_TOP : aPopupMenu.EnableItem( 1, FALSE ); break;
437 case WINDOWALIGN_BOTTOM : aPopupMenu.EnableItem( 2, FALSE ); break;
438 case WINDOWALIGN_LEFT : aPopupMenu.EnableItem( 3, FALSE ); break;
439 case WINDOWALIGN_RIGHT : aPopupMenu.EnableItem( 4, FALSE ); break;
442 if (( mnWinStyle & WB_CLOSEABLE ) != 0 )
444 aPopupMenu.InsertSeparator();
445 sText = String::CreateFromAscii( "Hide" );
446 aPopupMenu.InsertItem( 6, sText );
448 else if ( bPinable ) {
449 aPopupMenu.InsertSeparator();
450 sText = String::CreateFromAscii( "Pin" );
451 aPopupMenu.InsertItem( 6, sText );
452 aPopupMenu.CheckItem( 6, GetPin());
455 // ... und rufen.
457 aPopupMenu.SetSelectHdl ( LINK ( this, SoldepToolBox, MenuSelectHdl ));
458 aPopupMenu.Execute( this, rCEvt.GetMousePosPixel());
460 else if ( !GetItemId(rCEvt.GetMousePosPixel()))
462 CallContextMenu( this, rCEvt.GetMousePosPixel());
465 else ToolBox::Command( rCEvt );
468 /*************************************************************************
469 |* SoldepToolBox::GetContextMenu()
470 |************************************************************************/
472 PopupMenu *SoldepToolBox::GetContextMenu()
474 InitContextMenu();
475 return &aMenu;
478 /*************************************************************************
479 |* SoldepToolBox::InitContextMenu()
480 |************************************************************************/
482 void SoldepToolBox::InitContextMenu()
484 USHORT nStart = 0;
485 if ( bDockable )
486 nStart = 1;
488 aMenu.Clear();
490 for ( USHORT i = nStart; i < GetItemCount(); i++ )
492 USHORT nItemId = GetItemId( i );
494 switch ( GetItemType( i ))
496 case TOOLBOXITEM_SPACE:
497 break;
498 case TOOLBOXITEM_SEPARATOR :
499 if (!(( i < GetItemCount() - 1 ) && ( GetItemType( i + 1 ) == TOOLBOXITEM_DONTKNOW )))
500 aMenu.InsertSeparator();
501 break;
502 default:
503 aMenu.InsertItem( nItemId, GetItemText( nItemId ), GetItemImage( nItemId ));
504 if (IsItemChecked( nItemId )) aMenu.CheckItem( nItemId, TRUE );
505 if (!IsItemEnabled( nItemId )) aMenu.EnableItem( nItemId, FALSE );
506 if (!IsItemVisible( nItemId )) aMenu.HideItem(nItemId);
507 break;
512 /*************************************************************************
513 |* SoldepToolBox::CallContextMenu()
514 |************************************************************************/
516 void SoldepToolBox::CallContextMenu( Window *pWin, Point aPos )
518 if ( aMenu.IsInExecute())
519 return;
521 InitContextMenu();
523 // ... und rufen.
525 aMenu.SetSelectHdl ( LINK ( this, SoldepToolBox, MenuSelectHdl ));
526 aMenu.Execute( pWin, aPos );
529 void SoldepToolBox::SetPosSizePixel( const Point& rNewPos,
530 const Size& rNewSize )
532 // if(rNewPos != GetPosPixel() || rNewSize != GetSizePixel())
533 // {
534 ToolBox::SetPosSizePixel(rNewPos,rNewSize);
535 // Resize();
536 // }
539 void SoldepToolBox::SetDockingRects( const Rectangle& rOutRect,
540 const Rectangle& rInRect )
542 if(rOutRect != aOutRect || rInRect != aInRect)
544 ToolBox::SetDockingRects(rOutRect,rInRect);
545 Invalidate();
547 aOutRect = rOutRect;
548 aInRect = rInRect;
552 /*****************************************************************************/
553 void SoldepToolBox::StartDocking()
554 /*****************************************************************************/
556 ToolBox::StartDocking();
557 CallEventListeners( VCLEVENT_USER_TBOX_RESIZE_APP, this);
560 BOOL SoldepToolBox::GetPin()
563 return bPin;
566 void SoldepToolBox::TogglePin()
568 bPin = !bPin;
571 void SoldepToolBox::SetPin( BOOL bP )
573 bPin = bP;
576 /*************************************************************************
577 |* SoldepToolBox::MenuSelectHdl()
579 |* Handler, der beim Execute der Context-Men�s gerufen wird
580 |************************************************************************/
582 IMPL_LINK ( SoldepToolBox, MenuSelectHdl, Menu*, pMenu )
584 // Wenn die CurItemId <= 6 ist, dann wurde das Abreiád”del-Context-Men� ausgef�hrt ...
585 ULONG itemid;
586 itemid = pMenu->GetCurItemId();
588 if ( pMenu == &aMenu )
590 // ... Andernfalls wurde das Default-Context-Men� ausgef�hrt ...
591 USHORT nTmpId = mnCurItemId;
592 mnCurItemId = pMenu->GetCurItemId();
594 // ... und der gesetzte Handler (in soldep.cxx) wird gerufen.
595 maSelectHdl.Call( this );
596 mnCurItemId = nTmpId;
598 return 0;