1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxToolWindow implementation.
4 // Author: Aleksandras Gluchovas
8 // Copyright: (c) Aleksandras Gluchovas
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "toolwnd.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
27 #include "wx/fl/toolwnd.h"
29 #define _IMG_A 0xAA // Note: modified from _A to _IMG_A, _A was already defined (cygwin)
30 #define _IMG_B 0x00 // Note: modified from _B to _IMG_A, _B was already defined (cygwin)
31 #define _IMG_C 0x55 // Note: modified from _C to _IMG_C, for consistency reasons.
32 #define _IMG_D 0x00 // Note: modified from _D to _IMG_D, for consistency reasons.
36 static const unsigned char _gCheckerImg
[16] = { _IMG_A
,_IMG_B
,_IMG_C
,_IMG_D
,
37 _IMG_A
,_IMG_B
,_IMG_C
,_IMG_D
,
38 _IMG_A
,_IMG_B
,_IMG_C
,_IMG_D
,
39 _IMG_A
,_IMG_B
,_IMG_C
,_IMG_D
42 /***** Implementation for class wxToolWindow *****/
44 IMPLEMENT_DYNAMIC_CLASS( wxToolWindow
, wxFrame
)
46 BEGIN_EVENT_TABLE( wxToolWindow
, wxFrame
)
48 EVT_PAINT ( wxToolWindow::OnPaint
)
49 EVT_MOTION ( wxToolWindow::OnMotion
)
50 EVT_LEFT_DOWN( wxToolWindow::OnLeftDown
)
51 EVT_LEFT_UP ( wxToolWindow::OnLeftUp
)
52 EVT_SIZE ( wxToolWindow::OnSize
)
55 EVT_ERASE_BACKGROUND( wxToolWindow::OnEraseBackground
)
59 enum INTERNAL_HIT_CODES
70 HITS_WND_TOP_LEFT_CORNER
,
71 HITS_WND_BOTTOM_RIGHT_CORNER
,
72 HITS_WND_TOP_RIGHT_CORNER
,
73 HITS_WND_BOTTOM_LEFT_CORNER
76 wxToolWindow::wxToolWindow()
78 : mpClientWnd ( NULL
),
81 mTitleFont( 8, wxSWISS
, wxNORMAL
, wxNORMAL
),
83 // just to simulate MS-Dev style
84 mTitleFont( 8, wxSWISS
, wxNORMAL
, wxNORMAL
, false, wxT("MS Sans Serif") ),
97 mResizeStarted( false ),
98 mRealTimeUpdatesOn( true ),
100 mMTolerance ( 5 ), // mouse-resizing tollerance
102 mCursorType( HITS_WND_NOTHING
),
103 mMouseCaptured( false ),
110 wxToolWindow::~wxToolWindow()
112 if ( mpScrDc
) delete mpScrDc
;
114 for( size_t i
= 0; i
!= mButtons
.Count(); ++i
)
118 void wxToolWindow::LayoutMiniButtons()
124 int x
= w
- mWndHorizGap
- mInTitleMargin
- BTN_BOX_WIDTH
;
125 int y
= mWndVertGap
+ 2;
127 for( size_t i
= 0; i
!= mButtons
.Count(); ++i
)
129 mButtons
[i
]->SetPos( wxPoint( x
,y
) );
130 x
-= BTN_BOX_WIDTH
+ mButtonGap
;
134 void wxToolWindow::SetClient( wxWindow
* pWnd
)
139 wxWindow
* wxToolWindow::GetClient()
144 void wxToolWindow::SetTitleFont( wxFont
& font
)
149 void wxToolWindow::AddMiniButton( cbMiniButton
* pBtn
)
153 mButtons
.Add( pBtn
);
155 // not necesserely now..
156 //LayoutMiniButtons();
159 void wxToolWindow::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
161 wxPaintDC
pdc( this );
162 wxWindowDC
dc( this );
167 wxBrush
backGround( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_BTNFACE
), wxSOLID
);
168 //dc.SetBrush( *wxLIGHT_GREY_BRUSH );
169 dc
.SetBrush( backGround
);
170 dc
.SetPen( *wxTRANSPARENT_PEN
);
172 int y
= mWndVertGap
+ mTitleHeight
+ mClntVertGap
;
174 dc
.DrawRectangle( 0,0, w
, y
); // Top grey part.
175 dc
.DrawRectangle( 0,y
-1, mWndHorizGap
+ mClntHorizGap
, h
- y
); // Left grey part.
176 dc
.DrawRectangle( w
- ( mWndHorizGap
+ mClntHorizGap
), y
-1,
177 mWndHorizGap
+ mClntHorizGap
, h
- y
); // Right grey part.
178 dc
.DrawRectangle( 0, h
- mWndVertGap
- mClntVertGap
, w
, mWndVertGap
+ mClntVertGap
); // Bottom grey part.
181 dc
.SetPen( *wxLIGHT_GREY_PEN
);
183 dc
.DrawLine( 0,0, w
, 0 );
184 dc
.DrawLine( 0,0, 0, h
);
186 dc
.SetPen( *wxWHITE_PEN
);
188 dc
.DrawLine( 1,1, w
, 1 );
189 dc
.DrawLine( 1,2, 1, h
);
191 dc
.SetPen( *wxGREY_PEN
);
193 dc
.DrawLine( w
- 2, 1, w
- 2, h
- 1 );
194 dc
.DrawLine( 1, h
- 2, w
- 2, h
- 2 );
196 dc
.SetPen( *wxBLACK_PEN
);
198 dc
.DrawLine( 0, h
- 1, w
, h
- 1 );
199 dc
.DrawLine( w
-1, 0, w
-1, h
);
203 dc
.SetBrush( *wxTheBrushList
->FindOrCreateBrush( wxColour( 0,0,128 ), wxSOLID
) );
205 dc
.DrawRectangle( mWndHorizGap
, mWndVertGap
, w
- mWndHorizGap
*2, mTitleHeight
);
207 dc
.SetFont( mTitleFont
);
209 for( size_t i
= 0; i
!= mButtons
.Count(); ++i
)
210 mButtons
[i
]->Draw( dc
);
212 int x1
= mWndHorizGap
+ mClntHorizGap
;
213 int x2
= mButtons
[ mButtons
.GetCount() - 1 ]->mPos
.x
- mClntHorizGap
*2;
215 dc
.SetClippingRegion( x1
, mWndVertGap
+ mClntVertGap
, x2
- x1
, mTitleHeight
);
217 dc
.SetTextForeground( *wxWHITE
);
218 dc
.SetBackgroundMode( wxTRANSPARENT
);
219 dc
.DrawText( GetTitle(), mWndHorizGap
+ 2, mWndVertGap
+ 1 );
222 void wxToolWindow::GetScrWindowRect( wxRect
& r
)
230 r
.width
= w
; r
.height
= h
;
233 void wxToolWindow::GetScrMousePos( wxMouseEvent
& event
, wxPoint
& pos
)
235 int x
= event
.m_x
, y
= event
.m_y
;
237 ClientToScreen( &x
, &y
);
239 pos
.x
= x
; pos
.y
= y
;
242 int wxToolWindow::HitTestWindow( wxMouseEvent
& event
)
247 GetScrMousePos( event
, pos
);
248 GetScrWindowRect( r
);
252 if ( !( pos
.x
>= r
.x
&& pos
.y
>= r
.y
&&
253 pos
.x
< r
.x
+ r
.width
&&
254 pos
.y
< r
.y
+ r
.height
)
256 return HITS_WND_NOTHING
;
258 if ( pos
.y
<= r
.y
+ k
)
260 if ( pos
.x
< r
.x
+ k
*2 )
261 return HITS_WND_TOP_LEFT_CORNER
;
264 if ( pos
.x
>= r
.x
+ r
.width
- k
*2 )
265 return HITS_WND_TOP_RIGHT_CORNER
;
267 return HITS_WND_TOP_EDGE
;
272 if ( pos
.y
>= r
.y
+ r
.height
- k
)
274 if ( pos
.x
< r
.x
+ k
*2 )
275 return HITS_WND_BOTTOM_LEFT_CORNER
;
278 if ( pos
.x
> r
.x
+ r
.width
- k
*2 )
279 return HITS_WND_BOTTOM_RIGHT_CORNER
;
281 return HITS_WND_BOTTOM_EDGE
;
286 if ( pos
.x
<= r
.x
+ k
)
287 return HITS_WND_LEFT_EDGE
;
290 if ( pos
.x
>= r
.x
+ r
.width
- k
)
291 return HITS_WND_RIGHT_EDGE
;
294 if ( pos
.y
<= r
.y
+ mWndVertGap
+ mTitleHeight
+ mClntVertGap
)
295 return HITS_WND_TITLE
;
297 return HITS_WND_CLIENT
;
304 void wxToolWindow::DrawHintRect( const wxRect
& r
)
306 // BUG BUG BUG (wx):: somehow stippled brush works only
307 // when the bitmap created on stack, not
308 // as a member of the class
310 int prevLF
= mpScrDc
->GetLogicalFunction();
312 mpScrDc
->SetLogicalFunction( wxXOR
);
314 wxBitmap
checker( (const char*)_gCheckerImg
, 8,8 );
316 wxBrush
checkerBrush( checker
);
318 mpScrDc
->SetPen( *wxTRANSPARENT_PEN
);
319 mpScrDc
->SetBrush( checkerBrush
);
321 int half
= mHintBorder
/ 2;
323 mpScrDc
->DrawRectangle( r
.x
- half
, r
.y
- half
,
324 r
.width
+ 2*half
, mHintBorder
);
326 mpScrDc
->DrawRectangle( r
.x
- half
, r
.y
+ r
.height
- half
,
327 r
.width
+ 2*half
, mHintBorder
);
329 mpScrDc
->DrawRectangle( r
.x
- half
, r
.y
+ half
- 1,
330 mHintBorder
, r
.height
- 2*half
+ 2);
332 mpScrDc
->DrawRectangle( r
.x
+ r
.width
- half
,
334 mHintBorder
, r
.height
- 2*half
+ 2);
336 mpScrDc
->SetBrush( wxNullBrush
);
338 mpScrDc
->SetLogicalFunction( prevLF
);
341 void wxToolWindow::SetHintCursor( int type
)
343 if ( mResizeStarted
)
346 if ( type
== HITS_WND_NOTHING
|| type
== HITS_WND_CLIENT
)
348 // the cursor is out of window - reset to arrow
350 if ( mMouseCaptured
)
353 mMouseCaptured
= false;
356 SetCursor( wxCURSOR_ARROW
);
363 if ( !mMouseCaptured
)
365 mMouseCaptured
= true;
369 // did the cursor actually changed?
371 if ( type
!= mCursorType
)
377 case HITS_WND_LEFT_EDGE
: SetCursor( wxCURSOR_SIZEWE
); break;
378 case HITS_WND_RIGHT_EDGE
: SetCursor( wxCURSOR_SIZEWE
); break;
379 case HITS_WND_TOP_EDGE
: SetCursor( wxCURSOR_SIZENS
); break;
380 case HITS_WND_BOTTOM_EDGE
: SetCursor( wxCURSOR_SIZENS
); break;
382 case HITS_WND_TOP_LEFT_CORNER
: SetCursor( wxCURSOR_SIZENWSE
); break;
383 case HITS_WND_BOTTOM_RIGHT_CORNER
: SetCursor( wxCURSOR_SIZENWSE
); break;
384 case HITS_WND_TOP_RIGHT_CORNER
: SetCursor( wxCURSOR_SIZENESW
); break;
385 case HITS_WND_BOTTOM_LEFT_CORNER
: SetCursor( wxCURSOR_SIZENESW
); break;
387 case HITS_WND_TITLE
: SetCursor( wxCURSOR_ARROW
); break;
388 case HITS_WND_CLIENT
: SetCursor( wxCURSOR_ARROW
); break;
395 #define INFINITY 32768
397 static inline void clip_to( int& value
, long from
, long till
)
406 void wxToolWindow::AdjustRectPos( const wxRect
& original
, const wxSize
& newDim
, wxRect
& newRect
)
408 if ( mCursorType
== HITS_WND_TOP_EDGE
||
409 mCursorType
== HITS_WND_TOP_LEFT_CORNER
)
411 newRect
.x
= original
.x
+ original
.width
- newDim
.x
;
412 newRect
.y
= original
.y
+ original
.height
- newDim
.y
;
415 if ( mCursorType
== HITS_WND_LEFT_EDGE
||
416 mCursorType
== HITS_WND_BOTTOM_LEFT_CORNER
)
418 newRect
.x
= original
.x
+ original
.width
- newDim
.x
;
419 newRect
.y
= original
.y
;
422 if ( mCursorType
== HITS_WND_RIGHT_EDGE
||
423 mCursorType
== HITS_WND_TOP_RIGHT_CORNER
)
425 newRect
.x
= original
.x
;
426 newRect
.y
= original
.y
+ original
.height
- newDim
.y
;
429 if ( mCursorType
== HITS_WND_BOTTOM_EDGE
||
430 mCursorType
== HITS_WND_BOTTOM_RIGHT_CORNER
)
432 newRect
.x
= original
.x
;
433 newRect
.y
= original
.y
;
436 newRect
.width
= newDim
.x
;
437 newRect
.height
= newDim
.y
;
440 void wxToolWindow::CalcResizedRect( wxRect
& rect
, wxPoint
& delta
, const wxSize
& minDim
)
442 // Microsoft's rect-coordinates are best suited
443 // for the case of corner-clipping
445 int left
= mInitialRect
.x
;
446 int top
= mInitialRect
.y
;
447 int right
= mInitialRect
.x
+ mInitialRect
.width
;
448 int bottom
= mInitialRect
.y
+ mInitialRect
.height
;
450 // constraint delta edge is dragged
452 switch ( mCursorType
)
454 case HITS_WND_LEFT_EDGE
: delta
.y
= 0; break;
455 case HITS_WND_RIGHT_EDGE
: delta
.y
= 0; break;
456 case HITS_WND_TOP_EDGE
: delta
.x
= 0; break;
457 case HITS_WND_BOTTOM_EDGE
: delta
.x
= 0; break;
461 if ( mCursorType
== HITS_WND_TOP_EDGE
||
462 mCursorType
== HITS_WND_TOP_LEFT_CORNER
)
467 clip_to( left
, -INFINITY
, mInitialRect
.x
+ mInitialRect
.width
- minDim
.x
);
468 clip_to( top
, -INFINITY
, mInitialRect
.y
+ mInitialRect
.height
- minDim
.y
);
471 if ( mCursorType
== HITS_WND_LEFT_EDGE
||
472 mCursorType
== HITS_WND_BOTTOM_LEFT_CORNER
)
477 clip_to( left
, -INFINITY
, mInitialRect
.x
+ mInitialRect
.width
- minDim
.x
);
478 clip_to( bottom
, mInitialRect
.y
+ minDim
.y
, INFINITY
);
481 if ( mCursorType
== HITS_WND_RIGHT_EDGE
||
482 mCursorType
== HITS_WND_TOP_RIGHT_CORNER
)
487 clip_to( right
, mInitialRect
.x
+ minDim
.x
, INFINITY
);
488 clip_to( top
, -INFINITY
, mInitialRect
.y
+ mInitialRect
.height
- minDim
.y
);
491 if ( mCursorType
== HITS_WND_BOTTOM_EDGE
||
492 mCursorType
== HITS_WND_BOTTOM_RIGHT_CORNER
)
497 clip_to( right
, mInitialRect
.x
+ minDim
.x
, INFINITY
);
498 clip_to( bottom
, mInitialRect
.y
+ minDim
.y
, INFINITY
);
502 wxFAIL_MSG( _T("what did the cursor hit?") );
507 rect
.width
= right
- left
;
508 rect
.height
= bottom
- top
;
511 wxSize
wxToolWindow::GetMinimalWndDim()
513 return wxSize( (mWndHorizGap
+ mClntHorizGap
)*2 + BTN_BOX_WIDTH
*4,
514 (mWndVertGap
+ mClntVertGap
)*2 + mTitleHeight
);
517 void wxToolWindow::OnMotion( wxMouseEvent
& event
)
519 if ( !mResizeStarted
)
521 for( size_t i
= 0; i
!= mButtons
.Count(); ++i
)
522 mButtons
[i
]->OnMotion( wxPoint( event
.m_x
, event
.m_y
) );
524 SetHintCursor( HitTestWindow( event
) );
529 GetScrMousePos( event
, pos
);
531 if ( mCursorType
== HITS_WND_TITLE
)
536 SetSize( mInitialRect
.x
+ pos
.x
- mDragOrigin
.x
,
537 mInitialRect
.y
+ pos
.y
- mDragOrigin
.y
,
543 wxPoint
delta( pos
.x
- mDragOrigin
.x
, pos
.y
- mDragOrigin
.y
);
547 wxSize minDim
= GetMinimalWndDim();
549 CalcResizedRect( newRect
, delta
, minDim
);
551 wxSize
borderDim( ( mWndHorizGap
+ mClntHorizGap
)*2,
552 ( mWndVertGap
+ mClntVertGap
)*2 + mTitleHeight
);
554 wxSize preferred
= GetPreferredSize( wxSize( newRect
.width
- borderDim
.x
,
555 newRect
.height
- borderDim
.y
) );
557 preferred
.x
+= borderDim
.x
;
558 preferred
.y
+= borderDim
.y
;
560 //CalcResizedRect( newRect, delta, preferred );
562 wxRect finalRect
= newRect
;
564 AdjustRectPos( newRect
, preferred
, finalRect
);
566 if ( mRealTimeUpdatesOn
)
568 SetSize( finalRect
.x
, finalRect
.y
,
569 finalRect
.width
, finalRect
.height
, 0 );
573 DrawHintRect( mPrevHintRect
);
574 DrawHintRect( finalRect
);
576 ::wxLogTrace(wxT("wxToolWindow"),wxT("%d,%d / %d,%d\n"), finalRect
.x
, finalRect
.y
, finalRect
.width
, finalRect
.height
);
579 mPrevHintRect
= finalRect
;
583 void wxToolWindow::OnLeftDown( wxMouseEvent
& event
)
585 int result
= HitTestWindow( event
);
587 for( size_t i
= 0; i
!= mButtons
.Count(); ++i
)
589 mButtons
[i
]->OnLeftDown( wxPoint( event
.m_x
, event
.m_y
) );
591 if ( mButtons
[i
]->IsPressed() )
592 return; // button hitted,
595 if ( result
>= HITS_WND_LEFT_EDGE
|| result
== HITS_WND_TITLE
)
597 GetScrMousePos( event
, mDragOrigin
);
600 if ( mMouseCaptured `)
603 mMouseCaptured = false;
606 if ( result
== HITS_WND_TITLE
&&
607 HandleTitleClick( event
) )
610 mResizeStarted
= true;
613 GetPosition( &x
, &y
);
619 mInitialRect
.width
= x
;
620 mInitialRect
.height
= y
;
622 mPrevHintRect
= mInitialRect
;
624 if ( mCursorType
!= HITS_WND_TITLE
&& !mRealTimeUpdatesOn
)
626 mpScrDc
= new wxScreenDC();
628 wxScreenDC::StartDrawingOnTop( (wxRect
*)NULL
);
630 DrawHintRect( mInitialRect
);
635 void wxToolWindow::OnLeftUp( wxMouseEvent
& event
)
637 for( size_t i
= 0; i
!= mButtons
.Count(); ++i
)
639 mButtons
[i
]->OnLeftUp( wxPoint( event
.m_x
, event
.m_y
) );
641 if ( mButtons
[i
]->WasClicked() )
643 OnMiniButtonClicked( i
); // notify derived classes
644 mButtons
[i
]->Reset();
648 if ( mResizeStarted
)
650 mResizeStarted
= false;
652 if ( mCursorType
!= HITS_WND_TITLE
)
654 if ( !mRealTimeUpdatesOn
)
656 DrawHintRect( mPrevHintRect
);
658 wxScreenDC::EndDrawingOnTop();
664 SetSize( mPrevHintRect
.x
, mPrevHintRect
.y
,
665 mPrevHintRect
.width
, mPrevHintRect
.height
, 0 );
671 void wxToolWindow::OnSize( wxSizeEvent
& WXUNUSED(event
) )
678 int x
= mWndHorizGap
+ mClntHorizGap
;
679 int y
= mWndVertGap
+ mTitleHeight
+ mClntVertGap
;
681 mpClientWnd
->SetSize( x
-1, y
-1,
682 w
- 2*(mWndHorizGap
+ mClntHorizGap
),
683 h
- y
- mClntVertGap
- mWndVertGap
,
691 wxSize
wxToolWindow::GetPreferredSize( const wxSize
& given
)
696 void wxToolWindow::OnEraseBackground( wxEraseEvent
& WXUNUSED(event
) )
701 /***** Implementation for class cbMiniButton *****/
703 cbMiniButton::cbMiniButton()
713 mWasClicked( false ),
714 mDragStarted( false ),
718 void cbMiniButton::SetPos( const wxPoint
& pos
)
723 bool cbMiniButton::HitTest( const wxPoint
& pos
)
725 if ( !mVisible
) return false;
727 return ( pos
.x
>= mPos
.x
&& pos
.y
>= mPos
.y
&&
728 pos
.x
< mPos
.x
+ BTN_BOX_WIDTH
&&
729 pos
.y
< mPos
.y
+ BTN_BOX_HEIGHT
);
732 void cbMiniButton::OnLeftDown( const wxPoint
& pos
)
734 if ( !mVisible
|| mDragStarted
) return;
736 if ( HitTest( pos
) && mEnabled
)
740 mpLayout
->CaptureEventsForPane( mpPane
);
741 mpLayout
->CaptureEventsForPlugin( mpPlugin
);
744 mpWnd
->CaptureMouse();
754 void cbMiniButton::OnLeftUp( const wxPoint
& WXUNUSED(pos
) )
756 if ( !mVisible
|| !mDragStarted
) return;
760 mpLayout
->ReleaseEventsFromPane( mpPane
);
761 mpLayout
->ReleaseEventsFromPlugin( mpPlugin
);
764 mpWnd
->ReleaseMouse();
766 mWasClicked
= mPressed
;
767 mDragStarted
= false;
773 void cbMiniButton::OnMotion( const wxPoint
& pos
)
775 if ( !mVisible
) return;
779 mPressed
= HitTest( pos
);
785 void cbMiniButton::Refresh()
789 wxClientDC
dc( &mpLayout
->GetParentFrame() );
795 wxWindowDC
dc( mpWnd
);
801 void cbMiniButton::Draw( wxDC
& dc
)
803 if ( !mVisible
) return;
805 dc
.SetPen( *wxTRANSPARENT_PEN
);
807 dc
.SetBrush( *wxLIGHT_GREY_BRUSH
);
809 dc
.DrawRectangle( mPos
.x
+ 1, mPos
.y
+ 1, BTN_BOX_WIDTH
- 2, BTN_BOX_HEIGHT
- 2 );
811 // "hard-code" metafile
814 dc
.SetPen( *wxWHITE_PEN
);
816 dc
.SetPen( *wxBLACK_PEN
);
818 dc
.DrawLine( mPos
.x
, mPos
.y
, mPos
.x
+ BTN_BOX_WIDTH
, mPos
.y
);
819 dc
.DrawLine( mPos
.x
, mPos
.y
, mPos
.x
, mPos
.y
+ BTN_BOX_HEIGHT
);
821 dc
.SetPen( *wxGREY_PEN
);
825 dc
.DrawLine( mPos
.x
+ 1, mPos
.y
+ BTN_BOX_HEIGHT
- 2,
826 mPos
.x
+ BTN_BOX_WIDTH
- 1, mPos
.y
+ BTN_BOX_HEIGHT
- 2 );
828 dc
.DrawLine( mPos
.x
+ BTN_BOX_WIDTH
- 2, mPos
.y
+ 1,
829 mPos
.x
+ BTN_BOX_WIDTH
- 2, mPos
.y
+ BTN_BOX_HEIGHT
- 1 );
833 dc
.DrawLine( mPos
.x
+ 1, mPos
.y
+ 1,
834 mPos
.x
+ BTN_BOX_WIDTH
- 2, mPos
.y
+ 1 );
836 dc
.DrawLine( mPos
.x
+ 1, mPos
.y
+ 1,
837 mPos
.x
+ 1, mPos
.y
+ BTN_BOX_HEIGHT
- 2 );
841 dc
.SetPen( *wxBLACK_PEN
);
843 dc
.SetPen( *wxWHITE_PEN
);
845 dc
.DrawLine( mPos
.x
, mPos
.y
+ BTN_BOX_HEIGHT
- 1,
846 mPos
.x
+ BTN_BOX_WIDTH
, mPos
.y
+ BTN_BOX_HEIGHT
- 1 );
848 dc
.DrawLine( mPos
.x
+ BTN_BOX_WIDTH
- 1, mPos
.y
,
849 mPos
.x
+ BTN_BOX_WIDTH
- 1, mPos
.y
+ BTN_BOX_HEIGHT
);
852 bool cbMiniButton::WasClicked()
857 void cbMiniButton::Reset()
862 /***** Implementation fro class cbCloseBox *****/
864 void cbCloseBox::Draw( wxDC
& dc
)
866 #if defined(__WXGTK__) || defined(__WXX11__)
868 cbMiniButton::Draw( dc
);
870 wxPen
pen( wxColour( 64,64,64 ) ,1, wxSOLID
);
874 int width
= BTN_BOX_WIDTH
- 7;
876 int xOfs
= (mPressed
) ? 4 : 3;
877 int yOfs
= (mPressed
) ? 4 : 3;
880 for( int i
= 0; i
!= BTN_X_WIEGHT
; ++i
)
882 dc
.DrawLine( mPos
.x
+ xOfs
+ i
- one
,
884 mPos
.x
+ xOfs
+ i
+ width
,
885 mPos
.y
+ yOfs
+ width
+ one
);
887 dc
.DrawLine( mPos
.x
+ xOfs
+ i
+ width
,
888 mPos
.y
+ yOfs
- one
- one
,
889 mPos
.x
+ xOfs
+ i
- one
,
890 mPos
.y
+ yOfs
+ width
);
895 cbMiniButton::Draw( dc
);
897 dc
.SetPen( *wxBLACK_PEN
);
899 int width
= BTN_BOX_WIDTH
- 7;
901 int xOfs
= (mPressed
) ? 4 : 3;
902 int yOfs
= (mPressed
) ? 4 : 3;
904 for( int i
= 0; i
!= BTN_X_WIEGHT
; ++i
)
906 dc
.DrawLine( mPos
.x
+ xOfs
+ i
,
908 mPos
.x
+ xOfs
+ i
+ width
,
909 mPos
.y
+ yOfs
+ width
);
911 dc
.DrawLine( mPos
.x
+ xOfs
+ i
+ width
- 1,
913 mPos
.x
+ xOfs
+ i
- 1,
914 mPos
.y
+ yOfs
+ width
);
921 /***** Implementation fro class cbCollapseBox *****/
923 inline static void my_swap( int& a
, int& b
)
930 void cbCollapseBox::Draw( wxDC
& dc
)
932 cbMiniButton::Draw( dc
);
934 dc
.SetPen( *wxTRANSPARENT_PEN
);
938 int yOfs
= (mPressed
) ? 3 : 2;
939 int xOfs
= (mPressed
) ? 5 : 4;
940 int width
= BTN_BOX_WIDTH
- 8;
942 // rotating/shifting triangle inside collapse box
947 arr
[2].y
= BTN_BOX_HEIGHT
- yOfs
- 1;
948 arr
[1].x
= xOfs
+ width
;
949 arr
[1].y
= (arr
[2].y
+ arr
[0].y
)/2;
953 arr
[0].x
= BTN_BOX_WIDTH
- arr
[0].x
;
954 arr
[1].x
= BTN_BOX_WIDTH
- arr
[1].x
;
955 arr
[2].x
= BTN_BOX_WIDTH
- arr
[2].x
;
958 if ( !mpPane
->IsHorizontal() )
960 my_swap( arr
[0].y
, arr
[0].x
);
961 my_swap( arr
[1].y
, arr
[1].x
);
962 my_swap( arr
[2].y
, arr
[2].x
);
978 if ( !mEnabled
) dc
.SetBrush( *wxGREY_BRUSH
);
979 else dc
.SetBrush( *wxBLACK_BRUSH
);
981 dc
.DrawPolygon( 3, arr
);
982 dc
.SetBrush( wxNullBrush
);
985 /***** Implementation for class cbDockBoxBox *****/
987 void cbDockBox::Draw( wxDC
& dc
)
989 cbMiniButton::Draw( dc
);
991 int width
= BTN_BOX_WIDTH
- 7;
993 int xOfs
= (mPressed
) ? 4 : 3;
994 int yOfs
= (mPressed
) ? 4 : 3;
996 dc
.SetPen( *wxBLACK_PEN
);
997 dc
.SetBrush( *wxBLACK_BRUSH
);
999 dc
.DrawRectangle( mPos
.x
+ xOfs
, mPos
.y
+ yOfs
, width
, width
);
1004 dc
.SetBrush( *wxWHITE_BRUSH
);
1006 dc
.DrawRectangle( mPos
.x
+ xOfs
, mPos
.y
+ yOfs
, width
-2, width
-2 );
1009 /***** Implementation for class wxToolWindow *****/
1011 IMPLEMENT_DYNAMIC_CLASS( cbFloatedBarWindow
, wxToolWindow
)
1013 BEGIN_EVENT_TABLE( cbFloatedBarWindow
, wxToolWindow
)
1015 EVT_LEFT_DCLICK( cbFloatedBarWindow::OnDblClick
)
1019 cbFloatedBarWindow::cbFloatedBarWindow()
1023 AddMiniButton( new cbCloseBox() );
1024 AddMiniButton( new cbDockBox() );
1027 void cbFloatedBarWindow::SetBar( cbBarInfo
* pBar
)
1032 cbBarInfo
* cbFloatedBarWindow::GetBar()
1037 void cbFloatedBarWindow::SetLayout( wxFrameLayout
* pLayout
)
1042 void cbFloatedBarWindow::PositionFloatedWnd( int scrX
, int scrY
,
1043 int width
, int height
)
1045 wxSize minDim
= GetMinimalWndDim();
1047 SetSize( scrX
- mWndHorizGap
- mClntHorizGap
,
1048 scrY
- mClntVertGap
- mTitleHeight
- mWndVertGap
,
1049 width
+ minDim
.x
, height
+ minDim
.y
, 0 );
1052 wxSize
cbFloatedBarWindow::GetPreferredSize( const wxSize
& given
)
1054 if ( mpBar
->mDimInfo
.GetDimHandler() )
1056 cbBarDimHandlerBase
* pHandler
= mpBar
->mDimInfo
.GetDimHandler();
1060 // int vtad = *((int*)pHandler);
1062 pHandler
->OnResizeBar( mpBar
, given
, prefDim
);
1068 if ( mpBar
->IsFixed() )
1069 return mpBar
->mDimInfo
.mSizes
[ wxCBAR_FLOATING
];
1071 return given
; // not-fixed bars are resized exactly the way user wants
1075 void cbFloatedBarWindow::OnMiniButtonClicked( int btnIdx
)
1077 // #1 - close mini-button
1078 // #0 - dock mini-button
1082 mpBar
->mAlignment
= -1; // sepcial "marking" for hidden bars out of floated state
1083 mpLayout
->SetBarState( mpBar
, wxCBAR_HIDDEN
, true );
1086 mpLayout
->SetBarState( mpBar
, wxCBAR_DOCKED_HORIZONTALLY
, true );
1089 bool cbFloatedBarWindow::HandleTitleClick( wxMouseEvent
& event
)
1092 mMouseCaptured
= false;
1095 GetScrMousePos( event
, scrPos
);
1100 mpLayout
->GetParentFrame().ScreenToClient( &msX
, &msY
);
1107 wxSize minDim
= GetMinimalWndDim();
1112 x
+= mWndHorizGap
+ mClntHorizGap
;
1113 y
+= mWndVertGap
+ mTitleHeight
+ mClntVertGap
;
1115 mpLayout
->GetParentFrame().ScreenToClient( &x
, &y
);
1117 wxRect
& bounds
= mpBar
->mDimInfo
.mBounds
[ wxCBAR_FLOATING
];
1124 cbStartBarDraggingEvent
dragEvt( mpBar
, wxPoint(msX
,msY
),
1125 mpLayout
->GetPanesArray()[FL_ALIGN_TOP
] );
1127 mpLayout
->FirePluginEvent( dragEvt
);
1132 void cbFloatedBarWindow::OnDblClick( wxMouseEvent
& WXUNUSED(event
) )
1134 mpLayout
->SetBarState( mpBar
, wxCBAR_DOCKED_HORIZONTALLY
, true );
1136 //wxMessageBox("toolWnd - dblClick!");