xref: /aoo41x/main/soldep/source/tbox.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 #define private public
28 
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>
34 
35 
36 
37 SoldepToolBox::SoldepToolBox( Window* pParent, const ResId& aId, sal_Bool bDAble ) :
38 				ToolBox( pParent, aId ),
39 				bDockable( bDAble ),
40 				bCloseMode( sal_False ),
41 				bBoxIsVisible( sal_True ),
42 				bPinable( sal_True ),
43                 aPinedBitmap( DtSodResId( TID_SMALL_PIN_PINED )),     // BMP_SMALL_PIN_PINED
44                 aUnpinedBitmap( DtSodResId( TID_SMALL_PIN_UNPINED ))   // BMP_SMALL_PIN_UNPINED
45 {
46     bPinable = sal_True;
47 
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
52 
53     //SetMouseDownHdl(LINK(this,SoldepToolBox,MouseDownHdl));
54 	//SetFloatingLines( nFloatingLines );
55 	//SetFloatingMode( bFloatingMode );
56 	sal_Bool bFloatingMode = sal_False;
57 	if ( bFloatingMode )
58 	{
59 		//Point aPos( sToolBoxInfo.GetToken( 4, ',' ).ToInt64(), sToolBoxInfo.GetToken( 5, ',' ).ToInt64());
60 		//SetPosPixel( aPos );
61 	}
62 
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 = sal_False;
68 //	if ( sToolBoxInfo.GetToken( 3, ',' ) == "Visible" ) {
69 		for ( sal_uInt16 i = 0; i < GetItemCount() && !bBoxIsVisible; i++ )
70 		{
71 //			sal_uInt16 nItemId = GetItemId( i );
72 
73 			switch ( GetItemType( i ))
74 			{
75 				case TOOLBOXITEM_SPACE:
76 					break;
77 				case TOOLBOXITEM_SEPARATOR :
78 					break;
79 				default:
80 					bBoxIsVisible = sal_True;
81 					break;
82 			}
83 		}
84 //	}
85 
86 	if ( bBoxIsVisible ) {
87 		if (!bDockable)
88 			Show();
89 		else
90 			Hide();
91 	}
92 	else
93 		Hide();
94 
95 	bOldFloatMode = IsFloatingMode();
96 }
97 
98 /*************************************************************************
99 |* SoldepToolBox::~SoldepToolBox()
100 |************************************************************************/
101 
102 SoldepToolBox::~SoldepToolBox()
103 {
104 }
105 
106 /*************************************************************************
107 |* SoldepToolBox::Paint()
108 |************************************************************************/
109 
110 void SoldepToolBox::Paint( const Rectangle& rRect )
111 {
112 		SetOutStyle(  TOOLBOX_STYLE_FLAT );
113 
114 	// Wenn wir eine Dockable ToolBox haben, ...
115 
116 	if ( bDockable )
117 	{
118 		sal_uInt16 nItemId = GetItemId( 0 );
119 
120 		// ... zeichnen wir den wunderbaren Abrei�d�del �ber das erste Item (Seperator)
121 
122 		if ( !IsFloatingMode() && ( mnCurLine == 1 )) {
123 			sal_Bool bIsCloseable = (( mnWinStyle & WB_CLOSEABLE ) != 0 );
124 
125 			ShowItem( nItemId );
126 			Rectangle aRect = GetItemRect( nItemId );
127 
128 			ToolBox::Paint( rRect );
129 
130 			if ( bIsCloseable )
131 			{
132 				// Paint small cross button left/top of toolbar
133                 SetLineColor( Color( COL_WHITE ));
134 
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));
137 
138                 SetLineColor( Color( COL_GRAY ));
139 
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));
142 
143                 SetLineColor( Color( COL_BLACK ));
144 
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));
147 			}
148 			else if ( bPinable )
149 			{
150 				if ( GetPin())
151 					DrawBitmap( Point( aRect.Left(), aRect.Top()), aPinedBitmap );
152 				else
153 					DrawBitmap( Point( aRect.Left(), aRect.Top()), aUnpinedBitmap );
154 			}
155 
156             SetLineColor( Color( COL_WHITE ));
157 
158 			if ( IsHorizontal())
159 			{
160 				if ( bIsCloseable || bPinable ) aRect = Rectangle( Point( aRect.Left(), aRect.Top()+8), Point( aRect.Right(), aRect.Bottom()));
161 
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()));
164 
165 				SetLineColor( Color( COL_WHITE ));
166 
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()));
169 
170                 SetLineColor( Color( COL_GRAY ));//GRAY
171 
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()));
174 
175 				SetLineColor( Color( COL_BLACK ));
176 
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()));
179 
180 			}
181 			else
182 			{
183 				if ( bIsCloseable || bPinable ) aRect = Rectangle( Point( aRect.Left()+8, aRect.Top()), Point( aRect.Right(), aRect.Bottom()));
184 
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()));
187 
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));
190 
191                 SetLineColor( Color( COL_GRAY ));
192 
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));
195 
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));
198 
199 			}
200 		}
201 		else
202 		{
203             // Sind wir im FloatingMode, dann wollen wir keinen Abrei�d�del haben
204 			// und hiden somit das erste Item.
205 
206             //Hiden l�scht leider das erste Object der n�chsten Zeile, daher nicht
207             //l�schen
208 			HideItem( nItemId );
209 			ToolBox::Paint( rRect );
210 		}
211 	}
212 	else
213 	{
214 		ToolBox::Paint( rRect );
215 	}
216 }
217 
218 /*************************************************************************
219 |* SoldepToolBox::MouseButtonDown()
220 |************************************************************************/
221 
222 void SoldepToolBox::MouseButtonDown(const MouseEvent& rEvent)
223 {
224 	// Sind wir im DockingMode, ...
225 
226 	if ( !IsFloatingMode() && ((( mnWinStyle & WB_CLOSEABLE ) != 0 ) || bPinable ))
227 	{
228 		// ... dann testen wir, ob am Abrei�d�del der Close-Button gedr�ckt wurde ...
229 
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()))
233 		{
234 			if ( bPinable ) {
235 				TogglePin();
236 				Invalidate();
237 			}
238 			else {
239 				bCloseMode = sal_True;
240 
241 				// ... und zeichnen ggf. den Button gedr�ckt.
242 
243                 SetLineColor( Color( COL_WHITE ));
244 
245 				DrawLine( Point( aRect.Left(), aRect.Bottom()), Point( aRect.Right(), aRect.Bottom()));
246 				DrawLine( Point( aRect.Right(), aRect.Bottom()), Point( aRect.Right(), aRect.Top()));
247 
248                 SetLineColor( Color( COL_GRAY ));
249 
250 				DrawLine( Point( aRect.Left(), aRect.Top()), Point( aRect.Right(), aRect.Top()));
251 				DrawLine( Point( aRect.Left(), aRect.Top()), Point( aRect.Left(), aRect.Bottom()));
252 			}
253 		}
254 		else
255 		{
256 			ToolBox::MouseButtonDown( rEvent );
257 		}
258 	}
259 	else
260 	{
261 		ToolBox::MouseButtonDown( rEvent );
262 	}
263 
264 	aMouseDownHdl.Call(this);
265 }
266 
267 /*************************************************************************
268 |* SoldepToolBox::MouseButtonUp()
269 |************************************************************************/
270 
271 void SoldepToolBox::MouseButtonUp(const MouseEvent& rEvent)
272 {
273 	// Wenn der Close-Button am Abrei�d�del zuvor gedr�ckt wurde, ...
274 
275 	if ( bCloseMode )
276 	{
277 		bCloseMode = sal_False;
278 
279 		// ... so zeichen wir diesen wieder normal ...
280 
281 		Rectangle aRect = GetItemRect( GetItemId( 0 ));
282 		aRect = Rectangle( aRect.TopLeft(), Point( aRect.Left()+6, aRect.Top()+6 ));
283 
284         SetLineColor( Color( COL_WHITE ));
285 
286 		DrawLine( Point( aRect.Left(), aRect.Top()), Point( aRect.Right(), aRect.Top()));
287 		DrawLine( Point( aRect.Left(), aRect.Top()), Point( aRect.Left(), aRect.Bottom()));
288 
289         SetLineColor( Color( COL_GRAY ));
290 
291 		DrawLine( Point( aRect.Left(), aRect.Bottom()), Point( aRect.Right(), aRect.Bottom()));
292 		DrawLine( Point( aRect.Right(), aRect.Bottom()), Point( aRect.Right(), aRect.Top()));
293 
294 		if ( rEvent.IsLeft() && aRect.IsInside( rEvent.GetPosPixel()))
295 		{
296 			// ... und schlie�en die Box durch Aufruf der virtuellen Methode
297 			// CloseDockingMode().
298 
299 			CloseDockingMode();
300 		}
301 		else
302 		{
303 			ToolBox::MouseButtonUp( rEvent );
304 		}
305 	}
306 	else
307 	{
308 		ToolBox::MouseButtonUp( rEvent );
309 	}
310 }
311 
312 /*************************************************************************
313 |* SoldepToolBox::MouseMove()
314 |************************************************************************/
315 
316 void SoldepToolBox::MouseMove(const MouseEvent& rEvent)
317 {
318 	// Wenn der Close-Button am Abrei�d�del zuvor gedr�ckt wurde, ...
319 
320 	if ( bCloseMode )
321 	{
322 		Rectangle aRect = GetItemRect( GetItemId( 0 ));
323 		aRect = Rectangle( aRect.TopLeft(), Point( aRect.Left()+6, aRect.Top()+6 ));
324 
325 		// ... der Mouse-Zeiger jedoch den Close-Button verl��t, ...
326 
327 		if ( !aRect.IsInside( rEvent.GetPosPixel()))
328 		{
329             SetLineColor( Color( COL_WHITE ));
330 
331 			// ... zeichnen wir diesen halt wieder normal.
332 
333 			DrawLine( Point( aRect.Left(), aRect.Top()), Point( aRect.Right(), aRect.Top()));
334 			DrawLine( Point( aRect.Left(), aRect.Top()), Point( aRect.Left(), aRect.Bottom()));
335 
336             SetLineColor( Color( COL_GRAY ));
337 
338 				DrawLine( Point( aRect.Left(), aRect.Bottom()), Point( aRect.Right(), aRect.Bottom()));
339 			DrawLine( Point( aRect.Right(), aRect.Bottom()), Point( aRect.Right(), aRect.Top()));
340 
341 			bCloseMode = sal_False;
342 		}
343 		else
344 		{
345 			ToolBox::MouseMove( rEvent );
346 		}
347 	}
348 	else
349 	{
350 		ToolBox::MouseMove( rEvent );
351 	}
352 }
353 
354 /*****************************************************************************/
355 void SoldepToolBox::ToggleFloatingMode()
356 /*****************************************************************************/
357 {
358 	ToolBox::ToggleFloatingMode();
359 	CallEventListeners( VCLEVENT_USER_TBOX_RESIZE_APP, this);
360 }
361 
362 /*****************************************************************************/
363 void SoldepToolBox::EndDocking( const Rectangle& rRect, sal_Bool bFloatMode )
364 /*****************************************************************************/
365 {
366 	ToolBox::EndDocking( rRect, bFloatMode );
367 	if ( aResizeHdl.IsSet())
368 		CallEventListeners( VCLEVENT_USER_TBOX_RESIZE_APP, this);
369 	else
370         {
371            GetParent()->Resize();
372         }
373 };
374 
375 /*****************************************************************************/
376 sal_Bool SoldepToolBox::Close()
377 /*****************************************************************************/
378 {
379 	if (!ToolBox::Close()) return sal_False;
380 
381 	return sal_True;
382 }
383 
384 /*****************************************************************************/
385 void SoldepToolBox::Move()
386 /*****************************************************************************/
387 {
388 }
389 
390 /*************************************************************************
391 |* SoldepToolBox::CloseDockingMode()
392 |*
393 |* virtuelle Methode zur Reaktion auf den Close-Button im DockinMode
394 |************************************************************************/
395 
396 void SoldepToolBox::CloseDockingMode()
397 {
398 	Hide();
399 	bBoxIsVisible = sal_False;
400 	CallEventListeners( VCLEVENT_USER_TBOX_RESIZE_APP, this);
401 }
402 
403 /*************************************************************************
404 |* SoldepToolBox::Command()
405 |************************************************************************/
406 
407 void SoldepToolBox::Command( const CommandEvent& rCEvt)
408 {
409 	if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
410 	{
411 		if( !IsFloatingMode() && bDockable
412 			&& ( GetItemRect(GetItemId( 0 )).IsInside(rCEvt.GetMousePosPixel())))
413 		{
414             // Hier das Context-Menue fuer Abrei�d�del dynamisch erzeugen...
415 
416 			PopupMenu aPopupMenu;
417 
418 			String sText( String::CreateFromAscii( "Floating mode" ));
419 			aPopupMenu.InsertItem( 5, sText );
420 			aPopupMenu.InsertSeparator();
421 
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 );
430 
431 			switch( GetAlign())
432 			{
433                 case WINDOWALIGN_TOP : aPopupMenu.EnableItem( 1, sal_False ); break;
434                 case WINDOWALIGN_BOTTOM : aPopupMenu.EnableItem( 2, sal_False ); break;
435                 case WINDOWALIGN_LEFT : aPopupMenu.EnableItem( 3, sal_False ); break;
436                 case WINDOWALIGN_RIGHT : aPopupMenu.EnableItem( 4, sal_False ); break;
437 			}
438 
439 			if (( mnWinStyle & WB_CLOSEABLE ) != 0 )
440 			{
441 				aPopupMenu.InsertSeparator();
442 				sText = String::CreateFromAscii( "Hide" );
443 				aPopupMenu.InsertItem( 6, sText );
444 			}
445 			else if ( bPinable ) {
446 				aPopupMenu.InsertSeparator();
447 				sText = String::CreateFromAscii( "Pin" );
448 				aPopupMenu.InsertItem( 6, sText );
449 				aPopupMenu.CheckItem( 6, GetPin());
450 			}
451 
452 			// ... und rufen.
453 
454             aPopupMenu.SetSelectHdl ( LINK ( this, SoldepToolBox, MenuSelectHdl ));
455 			aPopupMenu.Execute( this, rCEvt.GetMousePosPixel());
456 		}
457 		else if ( !GetItemId(rCEvt.GetMousePosPixel()))
458 		{
459 			CallContextMenu( this, rCEvt.GetMousePosPixel());
460 		}
461 	}
462 	else ToolBox::Command( rCEvt );
463 }
464 
465 /*************************************************************************
466 |* SoldepToolBox::GetContextMenu()
467 |************************************************************************/
468 
469 PopupMenu *SoldepToolBox::GetContextMenu()
470 {
471 	InitContextMenu();
472 	return &aMenu;
473 }
474 
475 /*************************************************************************
476 |* SoldepToolBox::InitContextMenu()
477 |************************************************************************/
478 
479 void SoldepToolBox::InitContextMenu()
480 {
481 	sal_uInt16 nStart = 0;
482 	if ( bDockable )
483 		nStart = 1;
484 
485 	aMenu.Clear();
486 
487 	for ( sal_uInt16 i = nStart; i < GetItemCount(); i++ )
488 	{
489 		sal_uInt16 nItemId = GetItemId( i );
490 
491 		switch ( GetItemType( i ))
492 		{
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, sal_True );
502 				if (!IsItemEnabled( nItemId )) aMenu.EnableItem( nItemId, sal_False );
503                 if (!IsItemVisible( nItemId )) aMenu.HideItem(nItemId);
504 				break;
505 		}
506 	}
507 }
508 
509 /*************************************************************************
510 |* SoldepToolBox::CallContextMenu()
511 |************************************************************************/
512 
513 void SoldepToolBox::CallContextMenu( Window *pWin, Point aPos )
514 {
515 	if ( aMenu.IsInExecute())
516 		return;
517 
518 	InitContextMenu();
519 
520 	// ... und rufen.
521 
522     aMenu.SetSelectHdl ( LINK ( this, SoldepToolBox, MenuSelectHdl ));
523 	aMenu.Execute( pWin, aPos );
524 }
525 
526 void SoldepToolBox::SetPosSizePixel( const Point& rNewPos,
527 										 const Size& rNewSize )
528 {
529 //	if(rNewPos != GetPosPixel() || rNewSize != GetSizePixel())
530 //	{
531 		ToolBox::SetPosSizePixel(rNewPos,rNewSize);
532 //		Resize();
533 //	}
534 }
535 
536 void SoldepToolBox::SetDockingRects( const Rectangle& rOutRect,
537 										 const Rectangle& rInRect )
538 {
539 	if(rOutRect != aOutRect || rInRect != aInRect)
540 	{
541 		ToolBox::SetDockingRects(rOutRect,rInRect);
542 		Invalidate();
543 
544 		aOutRect = rOutRect;
545 		aInRect  = rInRect;
546 	}
547 }
548 
549 /*****************************************************************************/
550 void SoldepToolBox::StartDocking()
551 /*****************************************************************************/
552 {
553 	ToolBox::StartDocking();
554 	CallEventListeners( VCLEVENT_USER_TBOX_RESIZE_APP, this);
555 };
556 
557 sal_Bool SoldepToolBox::GetPin()
558 
559 {
560     return bPin;
561 }
562 
563 void SoldepToolBox::TogglePin()
564 {
565      bPin = !bPin;
566 }
567 
568 void SoldepToolBox::SetPin( sal_Bool bP )
569 {
570     bPin = bP;
571 }
572 
573 /*************************************************************************
574 |* SoldepToolBox::MenuSelectHdl()
575 |*
576 |* Handler, der beim Execute der Context-Men�s gerufen wird
577 |************************************************************************/
578 
579 IMPL_LINK ( SoldepToolBox, MenuSelectHdl, Menu*, pMenu )
580 {
581 	// Wenn die CurItemId <= 6 ist, dann wurde das Abrei�d�del-Context-Men� ausgef�hrt ...
582     sal_uIntPtr itemid;
583     itemid = pMenu->GetCurItemId();
584 
585 	if ( pMenu == &aMenu )
586 	{
587 		// ... Andernfalls wurde das Default-Context-Men� ausgef�hrt ...
588 		sal_uInt16 nTmpId = mnCurItemId;
589 		mnCurItemId = pMenu->GetCurItemId();
590 
591 		// ... und der gesetzte Handler (in soldep.cxx) wird gerufen.
592 		maSelectHdl.Call( this );
593 		mnCurItemId = nTmpId;
594 	}
595 	return 0;
596 }
597