1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Contrib. demo
4 // Author: Aleksandras Gluchovas
8 // Copyright: (c) Aleksandras Gluchovas
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "toolwnd.h"
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
37 static const unsigned char _gCheckerImg
[16] = { _A
,_B
,_C
,_D
,
43 /***** Implementation for class wxToolWindow *****/
45 IMPLEMENT_DYNAMIC_CLASS( wxToolWindow
, wxWindow
)
47 BEGIN_EVENT_TABLE( wxToolWindow
, wxWindow
)
49 EVT_PAINT ( wxToolWindow::OnPaint
)
50 EVT_MOTION ( wxToolWindow::OnMotion
)
51 EVT_LEFT_DOWN( wxToolWindow::OnLeftDown
)
52 EVT_LEFT_UP ( wxToolWindow::OnLeftUp
)
53 EVT_SIZE ( wxToolWindow::OnSize
)
56 EVT_ERASE_BACKGROUND( wxToolWindow::OnEraseBackground
)
60 enum INTERNAL_HIT_CODES
71 HITS_WND_TOP_LEFT_CORNER
,
72 HITS_WND_BOTTOM_RIGHT_CORNER
,
73 HITS_WND_TOP_RIGHT_CORNER
,
74 HITS_WND_BOTTOM_LEFT_CORNER
77 wxToolWindow::wxToolWindow()
79 : mpClientWnd ( NULL
),
91 mMTolerance ( 5 ), // mouse-resizing tollerance
93 mCursorType( HITS_WND_NOTHING
),
94 mMouseCaptured( FALSE
),
96 mResizeStarted( FALSE
),
97 mRealTimeUpdatesOn( TRUE
),
100 mTitleFont( 8, wxSWISS
, wxNORMAL
, wxNORMAL
),
102 // just to simulate MS-Dev style
103 mTitleFont( 8, wxSWISS
, wxNORMAL
, wxNORMAL
, FALSE
, "MS Sans Serif" ),
111 wxToolWindow::~wxToolWindow()
113 if ( mpScrDc
) delete mpScrDc
;
115 for( size_t i
= 0; i
!= mButtons
.Count(); ++i
)
120 void wxToolWindow::LayoutMiniButtons()
126 int x
= w
- mWndHorizGap
- mInTitleMargin
- BTN_BOX_WIDTH
;
127 int y
= mWndVertGap
+ 2;
129 for( size_t i
= 0; i
!= mButtons
.Count(); ++i
)
131 mButtons
[i
]->SetPos( wxPoint( x
,y
) );
132 x
-= BTN_BOX_WIDTH
+ mButtonGap
;
136 void wxToolWindow::SetClient( wxWindow
* pWnd
)
141 wxWindow
* wxToolWindow::GetClient()
146 void wxToolWindow::SetTitleFont( wxFont
& font
)
151 void wxToolWindow::AddMiniButton( cbMiniButton
* pBtn
)
155 mButtons
.Add( pBtn
);
157 // not necesserely now..
158 //LayoutMiniButtons();
161 void wxToolWindow::OnPaint( wxPaintEvent
& event
)
163 wxPaintDC
pdc( this );
164 wxWindowDC
dc( this );
169 dc
.SetBrush( *wxLIGHT_GREY_BRUSH
);
170 dc
.SetPen( *wxTRANSPARENT_PEN
);
172 int y
= mWndVertGap
+ mTitleHeight
+ mClntVertGap
+ 1;
173 dc
.DrawRectangle( 0,0, w
, y
);
174 dc
.DrawRectangle( 0,y
-1, mWndHorizGap
+ mClntHorizGap
+ 1, h
- y
);
175 dc
.DrawRectangle( w
- ( mWndHorizGap
+ mClntHorizGap
), y
-1,
176 mWndHorizGap
+ mClntHorizGap
, h
- y
);
177 dc
.DrawRectangle( 0, h
- mWndVertGap
- mClntVertGap
, w
, mWndVertGap
+ mClntVertGap
);
180 dc
.SetPen( *wxLIGHT_GREY_PEN
);
182 dc
.DrawLine( 0,0, w
, 0 );
183 dc
.DrawLine( 0,0, 0, h
);
185 dc
.SetPen( *wxWHITE_PEN
);
187 dc
.DrawLine( 1,1, w
, 1 );
188 dc
.DrawLine( 1,2, 1, h
);
190 dc
.SetPen( *wxGREY_PEN
);
192 dc
.DrawLine( w
- 2, 1, w
- 2, h
- 1 );
193 dc
.DrawLine( 1, h
- 2, w
- 2, h
- 2 );
195 dc
.SetPen( *wxBLACK_PEN
);
197 dc
.DrawLine( 0, h
- 1, w
, h
- 1 );
198 dc
.DrawLine( w
-1, 0, w
-1, h
);
202 dc
.SetBrush( *wxTheBrushList
->FindOrCreateBrush( wxColour( 0,0,128 ), wxSOLID
) );
204 dc
.DrawRectangle( mWndHorizGap
, mWndVertGap
, w
- mWndHorizGap
*2, mTitleHeight
);
206 dc
.SetFont( mTitleFont
);
208 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 )
262 return HITS_WND_TOP_LEFT_CORNER
;
264 if ( pos
.x
>= r
.x
+ r
.width
- k
*2 )
266 return HITS_WND_TOP_RIGHT_CORNER
;
268 return HITS_WND_TOP_EDGE
;
271 if ( pos
.y
>= r
.y
+ r
.height
- k
)
273 if ( pos
.x
< r
.x
+ k
*2 )
275 return HITS_WND_BOTTOM_LEFT_CORNER
;
277 if ( pos
.x
> r
.x
+ r
.width
- k
*2 )
279 return HITS_WND_BOTTOM_RIGHT_CORNER
;
281 return HITS_WND_BOTTOM_EDGE
;
284 if ( pos
.x
<= r
.x
+ k
)
286 return HITS_WND_LEFT_EDGE
;
288 if ( pos
.x
>= r
.x
+ r
.width
- k
)
290 return HITS_WND_RIGHT_EDGE
;
293 if ( pos
.y
<= r
.y
+ mWndVertGap
+ mTitleHeight
+ mClntVertGap
)
295 return HITS_WND_TITLE
;
297 return HITS_WND_CLIENT
;
301 void wxToolWindow::DrawHintRect( const wxRect
& r
)
303 // BUG BUG BUG (wx):: somehow stippled brush works only
304 // when the bitmap created on stack, not
305 // as a member of the class
307 int prevLF
= mpScrDc
->GetLogicalFunction();
309 mpScrDc
->SetLogicalFunction( wxXOR
);
311 wxBitmap
checker( (const char*)_gCheckerImg
, 8,8 );
313 wxBrush
checkerBrush( checker
);
315 mpScrDc
->SetPen( *wxTRANSPARENT_PEN
);
316 mpScrDc
->SetBrush( checkerBrush
);
318 int half
= mHintBorder
/ 2;
320 mpScrDc
->DrawRectangle( r
.x
- half
, r
.y
- half
,
321 r
.width
+ 2*half
, mHintBorder
);
323 mpScrDc
->DrawRectangle( r
.x
- half
, r
.y
+ r
.height
- half
,
324 r
.width
+ 2*half
, mHintBorder
);
326 mpScrDc
->DrawRectangle( r
.x
- half
, r
.y
+ half
- 1,
327 mHintBorder
, r
.height
- 2*half
+ 2);
329 mpScrDc
->DrawRectangle( r
.x
+ r
.width
- half
,
331 mHintBorder
, r
.height
- 2*half
+ 2);
333 mpScrDc
->SetBrush( wxNullBrush
);
335 mpScrDc
->SetLogicalFunction( prevLF
);
338 void wxToolWindow::SetHintCursor( int type
)
340 if ( mResizeStarted
) return;
342 if ( type
== HITS_WND_NOTHING
|| type
== HITS_WND_CLIENT
)
344 // the cursor is out of window - reset to arrow
346 if ( mMouseCaptured
&& !mResizeStarted
)
349 mMouseCaptured
= FALSE
;
352 if ( mCursorType
== HITS_WND_NOTHING
&& !mResizeStarted
)
354 SetCursor( wxCURSOR_ARROW
);
361 if ( !mMouseCaptured
)
363 mMouseCaptured
= TRUE
;
367 // did the cursor actually changed?
369 if ( type
!= mCursorType
)
375 case HITS_WND_LEFT_EDGE
: SetCursor( wxCURSOR_SIZEWE
); break;
376 case HITS_WND_RIGHT_EDGE
: SetCursor( wxCURSOR_SIZEWE
); break;
377 case HITS_WND_TOP_EDGE
: SetCursor( wxCURSOR_SIZENS
); break;
378 case HITS_WND_BOTTOM_EDGE
: SetCursor( wxCURSOR_SIZENS
); break;
380 case HITS_WND_TOP_LEFT_CORNER
: SetCursor( wxCURSOR_SIZENWSE
); break;
381 case HITS_WND_BOTTOM_RIGHT_CORNER
: SetCursor( wxCURSOR_SIZENWSE
); break;
382 case HITS_WND_TOP_RIGHT_CORNER
: SetCursor( wxCURSOR_SIZENESW
); break;
383 case HITS_WND_BOTTOM_LEFT_CORNER
: SetCursor( wxCURSOR_SIZENESW
); break;
385 case HITS_WND_TITLE
: SetCursor( wxCURSOR_ARROW
); break;
386 case HITS_WND_CLIENT
: SetCursor( wxCURSOR_ARROW
); break;
393 #define INFINITY 32768
395 static inline void clip_to( int& value
, long from
, long till
)
404 void wxToolWindow::AdjustRectPos( const wxRect
& original
, const wxSize
& newDim
, wxRect
& newRect
)
406 if ( mCursorType
== HITS_WND_TOP_EDGE
||
407 mCursorType
== HITS_WND_TOP_LEFT_CORNER
)
409 newRect
.x
= original
.x
+ original
.width
- newDim
.x
;
410 newRect
.y
= original
.y
+ original
.height
- newDim
.y
;
413 if ( mCursorType
== HITS_WND_LEFT_EDGE
||
414 mCursorType
== HITS_WND_BOTTOM_LEFT_CORNER
)
416 newRect
.x
= original
.x
+ original
.width
- newDim
.x
;
417 newRect
.y
= original
.y
;
420 if ( mCursorType
== HITS_WND_RIGHT_EDGE
||
421 mCursorType
== HITS_WND_TOP_RIGHT_CORNER
)
423 newRect
.x
= original
.x
;
424 newRect
.y
= original
.y
+ original
.height
- newDim
.y
;
427 if ( mCursorType
== HITS_WND_BOTTOM_EDGE
||
428 mCursorType
== HITS_WND_BOTTOM_RIGHT_CORNER
)
430 newRect
.x
= original
.x
;
431 newRect
.y
= original
.y
;
434 newRect
.width
= newDim
.x
;
435 newRect
.height
= newDim
.y
;
438 void wxToolWindow::CalcResizedRect( wxRect
& rect
, wxPoint
& delta
, const wxSize
& minDim
)
440 // Microsoft's rect-coordinates are best suited
441 // for the case of corner-clipping
443 int left
= mInitialRect
.x
;
444 int top
= mInitialRect
.y
;
445 int right
= mInitialRect
.x
+ mInitialRect
.width
;
446 int bottom
= mInitialRect
.y
+ mInitialRect
.height
;
448 // constraint delta edge is dragged
450 switch ( mCursorType
)
452 case HITS_WND_LEFT_EDGE
: delta
.y
= 0; break;
453 case HITS_WND_RIGHT_EDGE
: delta
.y
= 0; break;
454 case HITS_WND_TOP_EDGE
: delta
.x
= 0; break;
455 case HITS_WND_BOTTOM_EDGE
: delta
.x
= 0; break;
459 if ( mCursorType
== HITS_WND_TOP_EDGE
||
460 mCursorType
== HITS_WND_TOP_LEFT_CORNER
)
465 clip_to( left
, -INFINITY
, mInitialRect
.x
+ mInitialRect
.width
- minDim
.x
);
466 clip_to( top
, -INFINITY
, mInitialRect
.y
+ mInitialRect
.height
- minDim
.y
);
469 if ( mCursorType
== HITS_WND_LEFT_EDGE
||
470 mCursorType
== HITS_WND_BOTTOM_LEFT_CORNER
)
475 clip_to( left
, -INFINITY
, mInitialRect
.x
+ mInitialRect
.width
- minDim
.x
);
476 clip_to( bottom
, mInitialRect
.y
+ minDim
.y
, INFINITY
);
479 if ( mCursorType
== HITS_WND_RIGHT_EDGE
||
480 mCursorType
== HITS_WND_TOP_RIGHT_CORNER
)
485 clip_to( right
, mInitialRect
.x
+ minDim
.x
, INFINITY
);
486 clip_to( top
, -INFINITY
, mInitialRect
.y
+ mInitialRect
.height
- minDim
.y
);
489 if ( mCursorType
== HITS_WND_BOTTOM_EDGE
||
490 mCursorType
== HITS_WND_BOTTOM_RIGHT_CORNER
)
495 clip_to( right
, mInitialRect
.x
+ minDim
.x
, INFINITY
);
496 clip_to( bottom
, mInitialRect
.y
+ minDim
.y
, INFINITY
);
500 wxASSERT(0); // DBG::
505 rect
.width
= right
- left
;
506 rect
.height
= bottom
- top
;
509 wxSize
wxToolWindow::GetMinimalWndDim()
511 return wxSize( (mWndHorizGap
+ mClntHorizGap
)*2 + BTN_BOX_WIDTH
*4,
512 (mWndVertGap
+ mClntVertGap
)*2 + mTitleHeight
);
515 void wxToolWindow::OnMotion( wxMouseEvent
& event
)
517 if ( !mResizeStarted
)
519 for( size_t i
= 0; i
!= mButtons
.Count(); ++i
)
521 mButtons
[i
]->OnMotion( wxPoint( event
.m_x
, event
.m_y
) );
523 SetHintCursor( HitTestWindow( event
) );
528 GetScrMousePos( event
, pos
);
530 if ( mCursorType
== HITS_WND_TITLE
)
535 SetSize( mInitialRect
.x
+ pos
.x
- mDragOrigin
.x
,
536 mInitialRect
.y
+ pos
.y
- mDragOrigin
.y
,
542 wxPoint
delta( pos
.x
- mDragOrigin
.x
, pos
.y
- mDragOrigin
.y
);
546 wxSize minDim
= GetMinimalWndDim();
548 CalcResizedRect( newRect
, delta
, GetMinimalWndDim() );
550 wxSize
borderDim( ( mWndHorizGap
+ mClntHorizGap
)*2,
551 ( mWndVertGap
+ mClntVertGap
)*2 + mTitleHeight
);
553 wxSize preferred
= GetPreferredSize( wxSize( newRect
.width
- borderDim
.x
,
554 newRect
.height
- borderDim
.y
) );
556 preferred
.x
+= borderDim
.x
;
557 preferred
.y
+= borderDim
.y
;
559 //CalcResizedRect( newRect, delta, preferred );
561 wxRect finalRect
= newRect
;
563 AdjustRectPos( newRect
, preferred
, finalRect
);
565 if ( mRealTimeUpdatesOn
)
567 SetSize( finalRect
.x
, finalRect
.y
,
568 finalRect
.width
, finalRect
.height
, 0 );
572 DrawHintRect( mPrevHintRect
);
573 DrawHintRect( finalRect
);
576 mPrevHintRect
= finalRect
;
580 void wxToolWindow::OnLeftDown( wxMouseEvent
& event
)
582 int result
= HitTestWindow( event
);
584 for( size_t i
= 0; i
!= mButtons
.Count(); ++i
)
586 mButtons
[i
]->OnLeftDown( wxPoint( event
.m_x
, event
.m_y
) );
588 if ( mButtons
[i
]->IsPressed() )
590 return; // button hitted,
593 if ( result
>= HITS_WND_LEFT_EDGE
|| result
== HITS_WND_TITLE
)
595 GetScrMousePos( event
, mDragOrigin
);
598 if ( mMouseCaptured `)
601 mMouseCaptured = FALSE;
604 if ( result
== HITS_WND_TITLE
&&
605 HandleTitleClick( event
)
612 mResizeStarted
= TRUE
;
615 GetPosition( &x
, &y
);
621 mInitialRect
.width
= x
;
622 mInitialRect
.height
= y
;
624 mPrevHintRect
= mInitialRect
;
626 if ( mCursorType
!= HITS_WND_TITLE
&& !mRealTimeUpdatesOn
)
628 mpScrDc
= new wxScreenDC();
630 wxScreenDC::StartDrawingOnTop( (wxRect
*)NULL
);
632 DrawHintRect( mInitialRect
);
637 void wxToolWindow::OnLeftUp( wxMouseEvent
& event
)
639 for( size_t i
= 0; i
!= mButtons
.Count(); ++i
)
641 mButtons
[i
]->OnLeftUp( wxPoint( event
.m_x
, event
.m_y
) );
643 if ( mButtons
[i
]->WasClicked() )
645 OnMiniButtonClicked( i
); // notify derived classes
646 mButtons
[i
]->Reset();
650 if ( mResizeStarted
)
652 mResizeStarted
= FALSE
;
654 if ( mCursorType
!= HITS_WND_TITLE
)
656 if ( !mRealTimeUpdatesOn
)
658 DrawHintRect( mPrevHintRect
);
660 wxScreenDC::EndDrawingOnTop();
666 SetSize( mPrevHintRect
.x
, mPrevHintRect
.y
,
667 mPrevHintRect
.width
, mPrevHintRect
.height
, 0 );
673 void wxToolWindow::OnSize( wxSizeEvent
& event
)
680 int x
= mWndHorizGap
+ mClntHorizGap
;
681 int y
= mWndVertGap
+ mTitleHeight
+ mClntVertGap
;
684 mpClientWnd
->SetSize( x
-1, y
-1,
685 w
- 2*(mWndHorizGap
+ mClntHorizGap
),
686 h
- y
- mClntVertGap
- mWndVertGap
,
695 wxSize
wxToolWindow::GetPreferredSize( const wxSize
& given
)
700 void wxToolWindow::OnEraseBackground( wxEraseEvent
& event
)
705 /***** Implementation for class cbMiniButton *****/
707 cbMiniButton::cbMiniButton()
717 mWasClicked( FALSE
),
718 mDragStarted( FALSE
),
722 void cbMiniButton::SetPos( const wxPoint
& pos
)
727 bool cbMiniButton::HitTest( const wxPoint
& pos
)
729 if ( !mVisible
) return FALSE
;
731 return ( pos
.x
>= mPos
.x
&& pos
.y
>= mPos
.y
&&
732 pos
.x
< mPos
.x
+ BTN_BOX_WIDTH
&&
733 pos
.y
< mPos
.y
+ BTN_BOX_HEIGHT
);
736 void cbMiniButton::OnLeftDown( const wxPoint
& pos
)
738 if ( !mVisible
|| mDragStarted
) return;
740 if ( HitTest( pos
) && mEnabled
)
744 mpLayout
->CaptureEventsForPane( mpPane
);
745 mpLayout
->CaptureEventsForPlugin( mpPlugin
);
748 mpWnd
->CaptureMouse();
758 void cbMiniButton::OnLeftUp( const wxPoint
& pos
)
760 if ( !mVisible
|| !mDragStarted
) return;
764 mpLayout
->ReleaseEventsFromPane( mpPane
);
765 mpLayout
->ReleaseEventsFromPlugin( mpPlugin
);
768 mpWnd
->ReleaseMouse();
770 mWasClicked
= mPressed
;
771 mDragStarted
= FALSE
;
777 void cbMiniButton::OnMotion( const wxPoint
& pos
)
779 if ( !mVisible
) return;
783 mPressed
= HitTest( pos
);
789 void cbMiniButton::Refresh()
793 wxClientDC
dc( &mpLayout
->GetParentFrame() );
799 wxWindowDC
dc( mpWnd
);
805 void cbMiniButton::Draw( wxDC
& dc
)
807 if ( !mVisible
) return;
809 dc
.SetPen( *wxTRANSPARENT_PEN
);
811 dc
.SetBrush( *wxLIGHT_GREY_BRUSH
);
813 dc
.DrawRectangle( mPos
.x
+ 1, mPos
.y
+ 1, BTN_BOX_WIDTH
- 2, BTN_BOX_HEIGHT
- 2 );
815 // "hard-code" metafile
819 dc
.SetPen( *wxWHITE_PEN
);
821 dc
.SetPen( *wxBLACK_PEN
);
823 dc
.DrawLine( mPos
.x
, mPos
.y
, mPos
.x
+ BTN_BOX_WIDTH
, mPos
.y
);
824 dc
.DrawLine( mPos
.x
, mPos
.y
, mPos
.x
, mPos
.y
+ BTN_BOX_HEIGHT
);
826 dc
.SetPen( *wxGREY_PEN
);
830 dc
.DrawLine( mPos
.x
+ 1, mPos
.y
+ BTN_BOX_HEIGHT
- 2,
831 mPos
.x
+ BTN_BOX_WIDTH
- 1, mPos
.y
+ BTN_BOX_HEIGHT
- 2 );
833 dc
.DrawLine( mPos
.x
+ BTN_BOX_WIDTH
- 2, mPos
.y
+ 1,
834 mPos
.x
+ BTN_BOX_WIDTH
- 2, mPos
.y
+ BTN_BOX_HEIGHT
- 1 );
838 dc
.DrawLine( mPos
.x
+ 1, mPos
.y
+ 1,
839 mPos
.x
+ BTN_BOX_WIDTH
- 2, mPos
.y
+ 1 );
841 dc
.DrawLine( mPos
.x
+ 1, mPos
.y
+ 1,
842 mPos
.x
+ 1, mPos
.y
+ BTN_BOX_HEIGHT
- 2 );
847 dc
.SetPen( *wxBLACK_PEN
);
849 dc
.SetPen( *wxWHITE_PEN
);
851 dc
.DrawLine( mPos
.x
, mPos
.y
+ BTN_BOX_HEIGHT
- 1,
852 mPos
.x
+ BTN_BOX_WIDTH
, mPos
.y
+ BTN_BOX_HEIGHT
- 1 );
854 dc
.DrawLine( mPos
.x
+ BTN_BOX_WIDTH
- 1, mPos
.y
,
855 mPos
.x
+ BTN_BOX_WIDTH
- 1, mPos
.y
+ BTN_BOX_HEIGHT
);
858 bool cbMiniButton::WasClicked()
863 void cbMiniButton::Reset()
868 /***** Implementation fro class cbCloseBox *****/
870 void cbCloseBox::Draw( wxDC
& dc
)
874 cbMiniButton::Draw( dc
);
876 wxPen
pen( wxColour( 64,64,64 ) ,1, wxSOLID
);
880 int width
= BTN_BOX_WIDTH
- 7;
882 int xOfs
= (mPressed
) ? 4 : 3;
883 int yOfs
= (mPressed
) ? 4 : 3;
886 for( int i
= 0; i
!= BTN_X_WIEGHT
; ++i
)
888 dc
.DrawLine( mPos
.x
+ xOfs
+ i
- one
,
890 mPos
.x
+ xOfs
+ i
+ width
,
891 mPos
.y
+ yOfs
+ width
+ one
);
893 dc
.DrawLine( mPos
.x
+ xOfs
+ i
+ width
,
894 mPos
.y
+ yOfs
- one
- one
,
895 mPos
.x
+ xOfs
+ i
- one
,
896 mPos
.y
+ yOfs
+ width
);
901 cbMiniButton::Draw( dc
);
903 dc
.SetPen( *wxBLACK_PEN
);
905 int width
= BTN_BOX_WIDTH
- 7;
907 int xOfs
= (mPressed
) ? 4 : 3;
908 int yOfs
= (mPressed
) ? 4 : 3;
910 for( int i
= 0; i
!= BTN_X_WIEGHT
; ++i
)
912 dc
.DrawLine( mPos
.x
+ xOfs
+ i
,
914 mPos
.x
+ xOfs
+ i
+ width
,
915 mPos
.y
+ yOfs
+ width
);
917 dc
.DrawLine( mPos
.x
+ xOfs
+ i
+ width
- 1,
919 mPos
.x
+ xOfs
+ i
- 1,
920 mPos
.y
+ yOfs
+ width
);
927 /***** Implementation fro class cbCollapseBox *****/
929 inline static void my_swap( long& a
, long& b
)
936 void cbCollapseBox::Draw( wxDC
& dc
)
938 cbMiniButton::Draw( dc
);
940 dc
.SetPen( *wxTRANSPARENT_PEN
);
944 int yOfs
= (mPressed
) ? 3 : 2;
945 int xOfs
= (mPressed
) ? 5 : 4;
946 int width
= BTN_BOX_WIDTH
- 8;
948 // rotating/shifting triangle inside collapse box
953 arr
[2].y
= BTN_BOX_HEIGHT
- yOfs
- 1;
954 arr
[1].x
= xOfs
+ width
;
955 arr
[1].y
= (arr
[2].y
+ arr
[0].y
)/2;
959 arr
[0].x
= BTN_BOX_WIDTH
- arr
[0].x
;
960 arr
[1].x
= BTN_BOX_WIDTH
- arr
[1].x
;
961 arr
[2].x
= BTN_BOX_WIDTH
- arr
[2].x
;
964 if ( !mpPane
->IsHorizontal() )
966 my_swap( arr
[0].y
, arr
[0].x
);
967 my_swap( arr
[1].y
, arr
[1].x
);
968 my_swap( arr
[2].y
, arr
[2].x
);
984 if ( !mEnabled
) dc
.SetBrush( *wxGREY_BRUSH
);
985 else dc
.SetBrush( *wxBLACK_BRUSH
);
987 dc
.DrawPolygon( 3, arr
);
988 dc
.SetBrush( wxNullBrush
);
991 /***** Implementation for class cbDockBoxBox *****/
993 void cbDockBox::Draw( wxDC
& dc
)
995 cbMiniButton::Draw( dc
);
997 int width
= BTN_BOX_WIDTH
- 7;
999 int xOfs
= (mPressed
) ? 4 : 3;
1000 int yOfs
= (mPressed
) ? 4 : 3;
1002 dc
.SetPen( *wxBLACK_PEN
);
1003 dc
.SetBrush( *wxBLACK_BRUSH
);
1005 dc
.DrawRectangle( mPos
.x
+ xOfs
, mPos
.y
+ yOfs
, width
, width
);
1010 dc
.SetBrush( *wxWHITE_BRUSH
);
1012 dc
.DrawRectangle( mPos
.x
+ xOfs
, mPos
.y
+ yOfs
, width
-2, width
-2 );
1015 /***** Implementation for class wxToolWindow *****/
1017 IMPLEMENT_DYNAMIC_CLASS( cbFloatedBarWindow
, wxToolWindow
)
1019 BEGIN_EVENT_TABLE( cbFloatedBarWindow
, wxToolWindow
)
1021 EVT_LEFT_DCLICK( cbFloatedBarWindow::OnDblClick
)
1025 cbFloatedBarWindow::cbFloatedBarWindow()
1029 AddMiniButton( new cbCloseBox() );
1030 AddMiniButton( new cbDockBox() );
1033 void cbFloatedBarWindow::SetBar( cbBarInfo
* pBar
)
1038 cbBarInfo
* cbFloatedBarWindow::GetBar()
1043 void cbFloatedBarWindow::SetLayout( wxFrameLayout
* pLayout
)
1048 void cbFloatedBarWindow::PositionFloatedWnd( int scrX
, int scrY
,
1049 int width
, int height
)
1051 wxSize minDim
= GetMinimalWndDim();
1053 SetSize( scrX
- mWndHorizGap
- mClntHorizGap
,
1054 scrY
- mClntVertGap
- mTitleHeight
- mWndVertGap
,
1055 width
+ minDim
.x
, height
+ minDim
.y
, 0 );
1058 wxSize
cbFloatedBarWindow::GetPreferredSize( const wxSize
& given
)
1060 if ( mpBar
->mDimInfo
.GetDimHandler() )
1063 cbBarDimHandlerBase
* pHandler
= mpBar
->mDimInfo
.GetDimHandler();
1067 int vtad
= *((int*)pHandler
);
1069 pHandler
->OnResizeBar( mpBar
, given
, prefDim
);
1075 if ( mpBar
->IsFixed() )
1077 return mpBar
->mDimInfo
.mSizes
[ wxCBAR_FLOATING
];
1079 return given
; // not-fixed bars are resized exactly the way user wants
1083 void cbFloatedBarWindow::OnMiniButtonClicked( int btnIdx
)
1085 // #1 - close mini-button
1086 // #0 - dock mini-button
1090 mpBar
->mAlignment
= -1; // sepcial "marking" for hidden bars out of floated state
1091 mpLayout
->SetBarState( mpBar
, wxCBAR_HIDDEN
, TRUE
);
1094 mpLayout
->SetBarState( mpBar
, wxCBAR_DOCKED_HORIZONTALLY
, TRUE
);
1097 bool cbFloatedBarWindow::HandleTitleClick( wxMouseEvent
& event
)
1100 mMouseCaptured
= FALSE
;
1103 GetScrMousePos( event
, scrPos
);
1108 mpLayout
->GetParentFrame().ScreenToClient( &msX
, &msY
);
1115 wxSize minDim
= GetMinimalWndDim();
1120 x
+= mWndHorizGap
+ mClntHorizGap
;
1121 y
+= mWndVertGap
+ mTitleHeight
+ mClntVertGap
;
1123 mpLayout
->GetParentFrame().ScreenToClient( &x
, &y
);
1125 wxRect
& bounds
= mpBar
->mDimInfo
.mBounds
[ wxCBAR_FLOATING
];
1132 cbStartBarDraggingEvent
dragEvt( mpBar
, wxPoint(msX
,msY
),
1133 mpLayout
->GetPanesArray()[wxTOP
] );
1135 mpLayout
->FirePluginEvent( dragEvt
);
1140 void cbFloatedBarWindow::OnDblClick( wxMouseEvent
& event
)
1142 mpLayout
->SetBarState( mpBar
, wxCBAR_DOCKED_HORIZONTALLY
, TRUE
);
1144 //wxMessageBox("toolWnd - dblClick!");