1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tbox.cxx,v $
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
),
44 bBoxIsVisible( TRUE
),
46 aPinedBitmap( DtSodResId( TID_SMALL_PIN_PINED
)), // BMP_SMALL_PIN_PINED
47 aUnpinedBitmap( DtSodResId( TID_SMALL_PIN_UNPINED
)) // BMP_SMALL_PIN_UNPINED
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
;
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
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
:
80 case TOOLBOXITEM_SEPARATOR
:
89 if ( bBoxIsVisible
) {
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, ...
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 );
129 Rectangle aRect
= GetItemRect( nItemId
);
131 ToolBox::Paint( rRect
);
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));
154 DrawBitmap( Point( aRect
.Left(), aRect
.Top()), aPinedBitmap
);
156 DrawBitmap( Point( aRect
.Left(), aRect
.Top()), aUnpinedBitmap
);
159 SetLineColor( Color( COL_WHITE
));
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()));
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));
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
212 ToolBox::Paint( rRect
);
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()))
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()));
259 ToolBox::MouseButtonDown( rEvent
);
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, ...
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().
306 ToolBox::MouseButtonUp( rEvent
);
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, ...
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()));
348 ToolBox::MouseMove( rEvent
);
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);
374 GetParent()->Resize();
378 /*****************************************************************************/
379 BOOL
SoldepToolBox::Close()
380 /*****************************************************************************/
382 if (!ToolBox::Close()) return FALSE
;
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()
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
);
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());
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()
478 /*************************************************************************
479 |* SoldepToolBox::InitContextMenu()
480 |************************************************************************/
482 void SoldepToolBox::InitContextMenu()
490 for ( USHORT i
= nStart
; i
< GetItemCount(); i
++ )
492 USHORT nItemId
= GetItemId( i
);
494 switch ( GetItemType( i
))
496 case TOOLBOXITEM_SPACE
:
498 case TOOLBOXITEM_SEPARATOR
:
499 if (!(( i
< GetItemCount() - 1 ) && ( GetItemType( i
+ 1 ) == TOOLBOXITEM_DONTKNOW
)))
500 aMenu
.InsertSeparator();
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
);
512 /*************************************************************************
513 |* SoldepToolBox::CallContextMenu()
514 |************************************************************************/
516 void SoldepToolBox::CallContextMenu( Window
*pWin
, Point aPos
)
518 if ( aMenu
.IsInExecute())
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())
534 ToolBox::SetPosSizePixel(rNewPos
,rNewSize
);
539 void SoldepToolBox::SetDockingRects( const Rectangle
& rOutRect
,
540 const Rectangle
& rInRect
)
542 if(rOutRect
!= aOutRect
|| rInRect
!= aInRect
)
544 ToolBox::SetDockingRects(rOutRect
,rInRect
);
552 /*****************************************************************************/
553 void SoldepToolBox::StartDocking()
554 /*****************************************************************************/
556 ToolBox::StartDocking();
557 CallEventListeners( VCLEVENT_USER_TBOX_RESIZE_APP
, this);
560 BOOL
SoldepToolBox::GetPin()
566 void SoldepToolBox::TogglePin()
571 void SoldepToolBox::SetPin( BOOL 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 ...
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
;