1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Contrib. demo
4 // Author: Aleksandras Gluchovas
8 // Copyright: (c) Aleksandras Gluchovas
9 // Licence: wxWindows license
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
, wxWindow
)
46 BEGIN_EVENT_TABLE( wxToolWindow
, wxWindow
)
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
, "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
)
119 void wxToolWindow::LayoutMiniButtons()
125 int x
= w
- mWndHorizGap
- mInTitleMargin
- BTN_BOX_WIDTH
;
126 int y
= mWndVertGap
+ 2;
128 for( size_t i
= 0; i
!= mButtons
.Count(); ++i
)
130 mButtons
[i
]->SetPos( wxPoint( x
,y
) );
131 x
-= BTN_BOX_WIDTH
+ mButtonGap
;
135 void wxToolWindow::SetClient( wxWindow
* pWnd
)
140 wxWindow
* wxToolWindow::GetClient()
145 void wxToolWindow::SetTitleFont( wxFont
& font
)
150 void wxToolWindow::AddMiniButton( cbMiniButton
* pBtn
)
154 mButtons
.Add( pBtn
);
156 // not necesserely now..
157 //LayoutMiniButtons();
160 void wxToolWindow::OnPaint( wxPaintEvent
& event
)
162 wxPaintDC
pdc( this );
163 wxWindowDC
dc( this );
168 dc
.SetBrush( *wxLIGHT_GREY_BRUSH
);
169 dc
.SetPen( *wxTRANSPARENT_PEN
);
171 int y
= mWndVertGap
+ mTitleHeight
+ mClntVertGap
+ 1;
172 dc
.DrawRectangle( 0,0, w
, y
);
173 dc
.DrawRectangle( 0,y
-1, mWndHorizGap
+ mClntHorizGap
+ 1, h
- y
);
174 dc
.DrawRectangle( w
- ( mWndHorizGap
+ mClntHorizGap
), y
-1,
175 mWndHorizGap
+ mClntHorizGap
, h
- y
);
176 dc
.DrawRectangle( 0, h
- mWndVertGap
- mClntVertGap
, w
, mWndVertGap
+ mClntVertGap
);
179 dc
.SetPen( *wxLIGHT_GREY_PEN
);
181 dc
.DrawLine( 0,0, w
, 0 );
182 dc
.DrawLine( 0,0, 0, h
);
184 dc
.SetPen( *wxWHITE_PEN
);
186 dc
.DrawLine( 1,1, w
, 1 );
187 dc
.DrawLine( 1,2, 1, h
);
189 dc
.SetPen( *wxGREY_PEN
);
191 dc
.DrawLine( w
- 2, 1, w
- 2, h
- 1 );
192 dc
.DrawLine( 1, h
- 2, w
- 2, h
- 2 );
194 dc
.SetPen( *wxBLACK_PEN
);
196 dc
.DrawLine( 0, h
- 1, w
, h
- 1 );
197 dc
.DrawLine( w
-1, 0, w
-1, h
);
201 dc
.SetBrush( *wxTheBrushList
->FindOrCreateBrush( wxColour( 0,0,128 ), wxSOLID
) );
203 dc
.DrawRectangle( mWndHorizGap
, mWndVertGap
, w
- mWndHorizGap
*2, mTitleHeight
);
205 dc
.SetFont( mTitleFont
);
207 for( size_t i
= 0; i
!= mButtons
.Count(); ++i
)
209 mButtons
[i
]->Draw( dc
);
211 int x1
= mWndHorizGap
+ mClntHorizGap
;
212 int x2
= mButtons
[ mButtons
.GetCount() - 1 ]->mPos
.x
- mClntHorizGap
*2;
214 dc
.SetClippingRegion( x1
, mWndVertGap
+ mClntVertGap
, x2
- x1
, mTitleHeight
);
216 dc
.SetTextForeground( *wxWHITE
);
217 dc
.SetBackgroundMode( wxTRANSPARENT
);
218 dc
.DrawText( GetTitle(), mWndHorizGap
+ 2, mWndVertGap
+ 1 );
221 void wxToolWindow::GetScrWindowRect( wxRect
& r
)
229 r
.width
= w
; r
.height
= h
;
232 void wxToolWindow::GetScrMousePos( wxMouseEvent
& event
, wxPoint
& pos
)
234 int x
= event
.m_x
, y
= event
.m_y
;
236 ClientToScreen( &x
, &y
);
238 pos
.x
= x
; pos
.y
= y
;
241 int wxToolWindow::HitTestWindow( wxMouseEvent
& event
)
246 GetScrMousePos( event
, pos
);
247 GetScrWindowRect( r
);
251 if ( !( pos
.x
>= r
.x
&& pos
.y
>= r
.y
&&
252 pos
.x
< r
.x
+ r
.width
&&
253 pos
.y
< r
.y
+ r
.height
)
255 return HITS_WND_NOTHING
;
257 if ( pos
.y
<= r
.y
+ k
)
259 if ( pos
.x
< r
.x
+ k
*2 )
261 return HITS_WND_TOP_LEFT_CORNER
;
263 if ( pos
.x
>= r
.x
+ r
.width
- k
*2 )
265 return HITS_WND_TOP_RIGHT_CORNER
;
267 return HITS_WND_TOP_EDGE
;
270 if ( pos
.y
>= r
.y
+ r
.height
- k
)
272 if ( pos
.x
< r
.x
+ k
*2 )
274 return HITS_WND_BOTTOM_LEFT_CORNER
;
276 if ( pos
.x
> r
.x
+ r
.width
- k
*2 )
278 return HITS_WND_BOTTOM_RIGHT_CORNER
;
280 return HITS_WND_BOTTOM_EDGE
;
283 if ( pos
.x
<= r
.x
+ k
)
285 return HITS_WND_LEFT_EDGE
;
287 if ( pos
.x
>= r
.x
+ r
.width
- k
)
289 return HITS_WND_RIGHT_EDGE
;
292 if ( pos
.y
<= r
.y
+ mWndVertGap
+ mTitleHeight
+ mClntVertGap
)
294 return HITS_WND_TITLE
;
296 return HITS_WND_CLIENT
;
300 void wxToolWindow::DrawHintRect( const wxRect
& r
)
302 // BUG BUG BUG (wx):: somehow stippled brush works only
303 // when the bitmap created on stack, not
304 // as a member of the class
306 int prevLF
= mpScrDc
->GetLogicalFunction();
308 mpScrDc
->SetLogicalFunction( wxXOR
);
310 wxBitmap
checker( (const char*)_gCheckerImg
, 8,8 );
312 wxBrush
checkerBrush( checker
);
314 mpScrDc
->SetPen( *wxTRANSPARENT_PEN
);
315 mpScrDc
->SetBrush( checkerBrush
);
317 int half
= mHintBorder
/ 2;
319 mpScrDc
->DrawRectangle( r
.x
- half
, r
.y
- half
,
320 r
.width
+ 2*half
, mHintBorder
);
322 mpScrDc
->DrawRectangle( r
.x
- half
, r
.y
+ r
.height
- half
,
323 r
.width
+ 2*half
, mHintBorder
);
325 mpScrDc
->DrawRectangle( r
.x
- half
, r
.y
+ half
- 1,
326 mHintBorder
, r
.height
- 2*half
+ 2);
328 mpScrDc
->DrawRectangle( r
.x
+ r
.width
- half
,
330 mHintBorder
, r
.height
- 2*half
+ 2);
332 mpScrDc
->SetBrush( wxNullBrush
);
334 mpScrDc
->SetLogicalFunction( prevLF
);
337 void wxToolWindow::SetHintCursor( int type
)
339 if ( mResizeStarted
) return;
341 if ( type
== HITS_WND_NOTHING
|| type
== HITS_WND_CLIENT
)
343 // the cursor is out of window - reset to arrow
345 if ( mMouseCaptured
&& !mResizeStarted
)
348 mMouseCaptured
= FALSE
;
351 if ( mCursorType
== HITS_WND_NOTHING
&& !mResizeStarted
)
353 SetCursor( wxCURSOR_ARROW
);
360 if ( !mMouseCaptured
)
362 mMouseCaptured
= TRUE
;
366 // did the cursor actually changed?
368 if ( type
!= mCursorType
)
374 case HITS_WND_LEFT_EDGE
: SetCursor( wxCURSOR_SIZEWE
); break;
375 case HITS_WND_RIGHT_EDGE
: SetCursor( wxCURSOR_SIZEWE
); break;
376 case HITS_WND_TOP_EDGE
: SetCursor( wxCURSOR_SIZENS
); break;
377 case HITS_WND_BOTTOM_EDGE
: SetCursor( wxCURSOR_SIZENS
); break;
379 case HITS_WND_TOP_LEFT_CORNER
: SetCursor( wxCURSOR_SIZENWSE
); break;
380 case HITS_WND_BOTTOM_RIGHT_CORNER
: SetCursor( wxCURSOR_SIZENWSE
); break;
381 case HITS_WND_TOP_RIGHT_CORNER
: SetCursor( wxCURSOR_SIZENESW
); break;
382 case HITS_WND_BOTTOM_LEFT_CORNER
: SetCursor( wxCURSOR_SIZENESW
); break;
384 case HITS_WND_TITLE
: SetCursor( wxCURSOR_ARROW
); break;
385 case HITS_WND_CLIENT
: SetCursor( wxCURSOR_ARROW
); break;
392 #define INFINITY 32768
394 static inline void clip_to( int& value
, long from
, long till
)
403 void wxToolWindow::AdjustRectPos( const wxRect
& original
, const wxSize
& newDim
, wxRect
& newRect
)
405 if ( mCursorType
== HITS_WND_TOP_EDGE
||
406 mCursorType
== HITS_WND_TOP_LEFT_CORNER
)
408 newRect
.x
= original
.x
+ original
.width
- newDim
.x
;
409 newRect
.y
= original
.y
+ original
.height
- newDim
.y
;
412 if ( mCursorType
== HITS_WND_LEFT_EDGE
||
413 mCursorType
== HITS_WND_BOTTOM_LEFT_CORNER
)
415 newRect
.x
= original
.x
+ original
.width
- newDim
.x
;
416 newRect
.y
= original
.y
;
419 if ( mCursorType
== HITS_WND_RIGHT_EDGE
||
420 mCursorType
== HITS_WND_TOP_RIGHT_CORNER
)
422 newRect
.x
= original
.x
;
423 newRect
.y
= original
.y
+ original
.height
- newDim
.y
;
426 if ( mCursorType
== HITS_WND_BOTTOM_EDGE
||
427 mCursorType
== HITS_WND_BOTTOM_RIGHT_CORNER
)
429 newRect
.x
= original
.x
;
430 newRect
.y
= original
.y
;
433 newRect
.width
= newDim
.x
;
434 newRect
.height
= newDim
.y
;
437 void wxToolWindow::CalcResizedRect( wxRect
& rect
, wxPoint
& delta
, const wxSize
& minDim
)
439 // Microsoft's rect-coordinates are best suited
440 // for the case of corner-clipping
442 int left
= mInitialRect
.x
;
443 int top
= mInitialRect
.y
;
444 int right
= mInitialRect
.x
+ mInitialRect
.width
;
445 int bottom
= mInitialRect
.y
+ mInitialRect
.height
;
447 // constraint delta edge is dragged
449 switch ( mCursorType
)
451 case HITS_WND_LEFT_EDGE
: delta
.y
= 0; break;
452 case HITS_WND_RIGHT_EDGE
: delta
.y
= 0; break;
453 case HITS_WND_TOP_EDGE
: delta
.x
= 0; break;
454 case HITS_WND_BOTTOM_EDGE
: delta
.x
= 0; break;
458 if ( mCursorType
== HITS_WND_TOP_EDGE
||
459 mCursorType
== HITS_WND_TOP_LEFT_CORNER
)
464 clip_to( left
, -INFINITY
, mInitialRect
.x
+ mInitialRect
.width
- minDim
.x
);
465 clip_to( top
, -INFINITY
, mInitialRect
.y
+ mInitialRect
.height
- minDim
.y
);
468 if ( mCursorType
== HITS_WND_LEFT_EDGE
||
469 mCursorType
== HITS_WND_BOTTOM_LEFT_CORNER
)
474 clip_to( left
, -INFINITY
, mInitialRect
.x
+ mInitialRect
.width
- minDim
.x
);
475 clip_to( bottom
, mInitialRect
.y
+ minDim
.y
, INFINITY
);
478 if ( mCursorType
== HITS_WND_RIGHT_EDGE
||
479 mCursorType
== HITS_WND_TOP_RIGHT_CORNER
)
484 clip_to( right
, mInitialRect
.x
+ minDim
.x
, INFINITY
);
485 clip_to( top
, -INFINITY
, mInitialRect
.y
+ mInitialRect
.height
- minDim
.y
);
488 if ( mCursorType
== HITS_WND_BOTTOM_EDGE
||
489 mCursorType
== HITS_WND_BOTTOM_RIGHT_CORNER
)
494 clip_to( right
, mInitialRect
.x
+ minDim
.x
, INFINITY
);
495 clip_to( bottom
, mInitialRect
.y
+ minDim
.y
, INFINITY
);
499 wxFAIL( _T("what did the cursor hit?") );
504 rect
.width
= right
- left
;
505 rect
.height
= bottom
- top
;
508 wxSize
wxToolWindow::GetMinimalWndDim()
510 return wxSize( (mWndHorizGap
+ mClntHorizGap
)*2 + BTN_BOX_WIDTH
*4,
511 (mWndVertGap
+ mClntVertGap
)*2 + mTitleHeight
);
514 void wxToolWindow::OnMotion( wxMouseEvent
& event
)
516 if ( !mResizeStarted
)
518 for( size_t i
= 0; i
!= mButtons
.Count(); ++i
)
520 mButtons
[i
]->OnMotion( wxPoint( event
.m_x
, event
.m_y
) );
522 SetHintCursor( HitTestWindow( event
) );
527 GetScrMousePos( event
, pos
);
529 if ( mCursorType
== HITS_WND_TITLE
)
534 SetSize( mInitialRect
.x
+ pos
.x
- mDragOrigin
.x
,
535 mInitialRect
.y
+ pos
.y
- mDragOrigin
.y
,
541 wxPoint
delta( pos
.x
- mDragOrigin
.x
, pos
.y
- mDragOrigin
.y
);
545 wxSize minDim
= GetMinimalWndDim();
547 CalcResizedRect( newRect
, delta
, minDim
);
549 wxSize
borderDim( ( mWndHorizGap
+ mClntHorizGap
)*2,
550 ( mWndVertGap
+ mClntVertGap
)*2 + mTitleHeight
);
552 wxSize preferred
= GetPreferredSize( wxSize( newRect
.width
- borderDim
.x
,
553 newRect
.height
- borderDim
.y
) );
555 preferred
.x
+= borderDim
.x
;
556 preferred
.y
+= borderDim
.y
;
558 //CalcResizedRect( newRect, delta, preferred );
560 wxRect finalRect
= newRect
;
562 AdjustRectPos( newRect
, preferred
, finalRect
);
564 if ( mRealTimeUpdatesOn
)
566 SetSize( finalRect
.x
, finalRect
.y
,
567 finalRect
.width
, finalRect
.height
, 0 );
571 DrawHintRect( mPrevHintRect
);
572 DrawHintRect( finalRect
);
575 mPrevHintRect
= finalRect
;
579 void wxToolWindow::OnLeftDown( wxMouseEvent
& event
)
581 int result
= HitTestWindow( event
);
583 for( size_t i
= 0; i
!= mButtons
.Count(); ++i
)
585 mButtons
[i
]->OnLeftDown( wxPoint( event
.m_x
, event
.m_y
) );
587 if ( mButtons
[i
]->IsPressed() )
589 return; // button hitted,
592 if ( result
>= HITS_WND_LEFT_EDGE
|| result
== HITS_WND_TITLE
)
594 GetScrMousePos( event
, mDragOrigin
);
597 if ( mMouseCaptured `)
600 mMouseCaptured = FALSE;
603 if ( result
== HITS_WND_TITLE
&&
604 HandleTitleClick( event
)
611 mResizeStarted
= TRUE
;
614 GetPosition( &x
, &y
);
620 mInitialRect
.width
= x
;
621 mInitialRect
.height
= y
;
623 mPrevHintRect
= mInitialRect
;
625 if ( mCursorType
!= HITS_WND_TITLE
&& !mRealTimeUpdatesOn
)
627 mpScrDc
= new wxScreenDC();
629 wxScreenDC::StartDrawingOnTop( (wxRect
*)NULL
);
631 DrawHintRect( mInitialRect
);
636 void wxToolWindow::OnLeftUp( wxMouseEvent
& event
)
638 for( size_t i
= 0; i
!= mButtons
.Count(); ++i
)
640 mButtons
[i
]->OnLeftUp( wxPoint( event
.m_x
, event
.m_y
) );
642 if ( mButtons
[i
]->WasClicked() )
644 OnMiniButtonClicked( i
); // notify derived classes
645 mButtons
[i
]->Reset();
649 if ( mResizeStarted
)
651 mResizeStarted
= FALSE
;
653 if ( mCursorType
!= HITS_WND_TITLE
)
655 if ( !mRealTimeUpdatesOn
)
657 DrawHintRect( mPrevHintRect
);
659 wxScreenDC::EndDrawingOnTop();
665 SetSize( mPrevHintRect
.x
, mPrevHintRect
.y
,
666 mPrevHintRect
.width
, mPrevHintRect
.height
, 0 );
672 void wxToolWindow::OnSize( wxSizeEvent
& event
)
679 int x
= mWndHorizGap
+ mClntHorizGap
;
680 int y
= mWndVertGap
+ mTitleHeight
+ mClntVertGap
;
683 mpClientWnd
->SetSize( x
-1, y
-1,
684 w
- 2*(mWndHorizGap
+ mClntHorizGap
),
685 h
- y
- mClntVertGap
- mWndVertGap
,
694 wxSize
wxToolWindow::GetPreferredSize( const wxSize
& given
)
699 void wxToolWindow::OnEraseBackground( wxEraseEvent
& event
)
704 /***** Implementation for class cbMiniButton *****/
706 cbMiniButton::cbMiniButton()
716 mWasClicked( FALSE
),
717 mDragStarted( FALSE
),
721 void cbMiniButton::SetPos( const wxPoint
& pos
)
726 bool cbMiniButton::HitTest( const wxPoint
& pos
)
728 if ( !mVisible
) return FALSE
;
730 return ( pos
.x
>= mPos
.x
&& pos
.y
>= mPos
.y
&&
731 pos
.x
< mPos
.x
+ BTN_BOX_WIDTH
&&
732 pos
.y
< mPos
.y
+ BTN_BOX_HEIGHT
);
735 void cbMiniButton::OnLeftDown( const wxPoint
& pos
)
737 if ( !mVisible
|| mDragStarted
) return;
739 if ( HitTest( pos
) && mEnabled
)
743 mpLayout
->CaptureEventsForPane( mpPane
);
744 mpLayout
->CaptureEventsForPlugin( mpPlugin
);
747 mpWnd
->CaptureMouse();
757 void cbMiniButton::OnLeftUp( const wxPoint
& pos
)
759 if ( !mVisible
|| !mDragStarted
) return;
763 mpLayout
->ReleaseEventsFromPane( mpPane
);
764 mpLayout
->ReleaseEventsFromPlugin( mpPlugin
);
767 mpWnd
->ReleaseMouse();
769 mWasClicked
= mPressed
;
770 mDragStarted
= FALSE
;
776 void cbMiniButton::OnMotion( const wxPoint
& pos
)
778 if ( !mVisible
) return;
782 mPressed
= HitTest( pos
);
788 void cbMiniButton::Refresh()
792 wxClientDC
dc( &mpLayout
->GetParentFrame() );
798 wxWindowDC
dc( mpWnd
);
804 void cbMiniButton::Draw( wxDC
& dc
)
806 if ( !mVisible
) return;
808 dc
.SetPen( *wxTRANSPARENT_PEN
);
810 dc
.SetBrush( *wxLIGHT_GREY_BRUSH
);
812 dc
.DrawRectangle( mPos
.x
+ 1, mPos
.y
+ 1, BTN_BOX_WIDTH
- 2, BTN_BOX_HEIGHT
- 2 );
814 // "hard-code" metafile
818 dc
.SetPen( *wxWHITE_PEN
);
820 dc
.SetPen( *wxBLACK_PEN
);
822 dc
.DrawLine( mPos
.x
, mPos
.y
, mPos
.x
+ BTN_BOX_WIDTH
, mPos
.y
);
823 dc
.DrawLine( mPos
.x
, mPos
.y
, mPos
.x
, mPos
.y
+ BTN_BOX_HEIGHT
);
825 dc
.SetPen( *wxGREY_PEN
);
829 dc
.DrawLine( mPos
.x
+ 1, mPos
.y
+ BTN_BOX_HEIGHT
- 2,
830 mPos
.x
+ BTN_BOX_WIDTH
- 1, mPos
.y
+ BTN_BOX_HEIGHT
- 2 );
832 dc
.DrawLine( mPos
.x
+ BTN_BOX_WIDTH
- 2, mPos
.y
+ 1,
833 mPos
.x
+ BTN_BOX_WIDTH
- 2, mPos
.y
+ BTN_BOX_HEIGHT
- 1 );
837 dc
.DrawLine( mPos
.x
+ 1, mPos
.y
+ 1,
838 mPos
.x
+ BTN_BOX_WIDTH
- 2, mPos
.y
+ 1 );
840 dc
.DrawLine( mPos
.x
+ 1, mPos
.y
+ 1,
841 mPos
.x
+ 1, mPos
.y
+ BTN_BOX_HEIGHT
- 2 );
846 dc
.SetPen( *wxBLACK_PEN
);
848 dc
.SetPen( *wxWHITE_PEN
);
850 dc
.DrawLine( mPos
.x
, mPos
.y
+ BTN_BOX_HEIGHT
- 1,
851 mPos
.x
+ BTN_BOX_WIDTH
, mPos
.y
+ BTN_BOX_HEIGHT
- 1 );
853 dc
.DrawLine( mPos
.x
+ BTN_BOX_WIDTH
- 1, mPos
.y
,
854 mPos
.x
+ BTN_BOX_WIDTH
- 1, mPos
.y
+ BTN_BOX_HEIGHT
);
857 bool cbMiniButton::WasClicked()
862 void cbMiniButton::Reset()
867 /***** Implementation fro class cbCloseBox *****/
869 void cbCloseBox::Draw( wxDC
& dc
)
873 cbMiniButton::Draw( dc
);
875 wxPen
pen( wxColour( 64,64,64 ) ,1, wxSOLID
);
879 int width
= BTN_BOX_WIDTH
- 7;
881 int xOfs
= (mPressed
) ? 4 : 3;
882 int yOfs
= (mPressed
) ? 4 : 3;
885 for( int i
= 0; i
!= BTN_X_WIEGHT
; ++i
)
887 dc
.DrawLine( mPos
.x
+ xOfs
+ i
- one
,
889 mPos
.x
+ xOfs
+ i
+ width
,
890 mPos
.y
+ yOfs
+ width
+ one
);
892 dc
.DrawLine( mPos
.x
+ xOfs
+ i
+ width
,
893 mPos
.y
+ yOfs
- one
- one
,
894 mPos
.x
+ xOfs
+ i
- one
,
895 mPos
.y
+ yOfs
+ width
);
900 cbMiniButton::Draw( dc
);
902 dc
.SetPen( *wxBLACK_PEN
);
904 int width
= BTN_BOX_WIDTH
- 7;
906 int xOfs
= (mPressed
) ? 4 : 3;
907 int yOfs
= (mPressed
) ? 4 : 3;
909 for( int i
= 0; i
!= BTN_X_WIEGHT
; ++i
)
911 dc
.DrawLine( mPos
.x
+ xOfs
+ i
,
913 mPos
.x
+ xOfs
+ i
+ width
,
914 mPos
.y
+ yOfs
+ width
);
916 dc
.DrawLine( mPos
.x
+ xOfs
+ i
+ width
- 1,
918 mPos
.x
+ xOfs
+ i
- 1,
919 mPos
.y
+ yOfs
+ width
);
926 /***** Implementation fro class cbCollapseBox *****/
928 inline static void my_swap( int& a
, int& b
)
935 void cbCollapseBox::Draw( wxDC
& dc
)
937 cbMiniButton::Draw( dc
);
939 dc
.SetPen( *wxTRANSPARENT_PEN
);
943 int yOfs
= (mPressed
) ? 3 : 2;
944 int xOfs
= (mPressed
) ? 5 : 4;
945 int width
= BTN_BOX_WIDTH
- 8;
947 // rotating/shifting triangle inside collapse box
952 arr
[2].y
= BTN_BOX_HEIGHT
- yOfs
- 1;
953 arr
[1].x
= xOfs
+ width
;
954 arr
[1].y
= (arr
[2].y
+ arr
[0].y
)/2;
958 arr
[0].x
= BTN_BOX_WIDTH
- arr
[0].x
;
959 arr
[1].x
= BTN_BOX_WIDTH
- arr
[1].x
;
960 arr
[2].x
= BTN_BOX_WIDTH
- arr
[2].x
;
963 if ( !mpPane
->IsHorizontal() )
965 my_swap( arr
[0].y
, arr
[0].x
);
966 my_swap( arr
[1].y
, arr
[1].x
);
967 my_swap( arr
[2].y
, arr
[2].x
);
983 if ( !mEnabled
) dc
.SetBrush( *wxGREY_BRUSH
);
984 else dc
.SetBrush( *wxBLACK_BRUSH
);
986 dc
.DrawPolygon( 3, arr
);
987 dc
.SetBrush( wxNullBrush
);
990 /***** Implementation for class cbDockBoxBox *****/
992 void cbDockBox::Draw( wxDC
& dc
)
994 cbMiniButton::Draw( dc
);
996 int width
= BTN_BOX_WIDTH
- 7;
998 int xOfs
= (mPressed
) ? 4 : 3;
999 int yOfs
= (mPressed
) ? 4 : 3;
1001 dc
.SetPen( *wxBLACK_PEN
);
1002 dc
.SetBrush( *wxBLACK_BRUSH
);
1004 dc
.DrawRectangle( mPos
.x
+ xOfs
, mPos
.y
+ yOfs
, width
, width
);
1009 dc
.SetBrush( *wxWHITE_BRUSH
);
1011 dc
.DrawRectangle( mPos
.x
+ xOfs
, mPos
.y
+ yOfs
, width
-2, width
-2 );
1014 /***** Implementation for class wxToolWindow *****/
1016 IMPLEMENT_DYNAMIC_CLASS( cbFloatedBarWindow
, wxToolWindow
)
1018 BEGIN_EVENT_TABLE( cbFloatedBarWindow
, wxToolWindow
)
1020 EVT_LEFT_DCLICK( cbFloatedBarWindow::OnDblClick
)
1024 cbFloatedBarWindow::cbFloatedBarWindow()
1028 AddMiniButton( new cbCloseBox() );
1029 AddMiniButton( new cbDockBox() );
1032 void cbFloatedBarWindow::SetBar( cbBarInfo
* pBar
)
1037 cbBarInfo
* cbFloatedBarWindow::GetBar()
1042 void cbFloatedBarWindow::SetLayout( wxFrameLayout
* pLayout
)
1047 void cbFloatedBarWindow::PositionFloatedWnd( int scrX
, int scrY
,
1048 int width
, int height
)
1050 wxSize minDim
= GetMinimalWndDim();
1052 SetSize( scrX
- mWndHorizGap
- mClntHorizGap
,
1053 scrY
- mClntVertGap
- mTitleHeight
- mWndVertGap
,
1054 width
+ minDim
.x
, height
+ minDim
.y
, 0 );
1057 wxSize
cbFloatedBarWindow::GetPreferredSize( const wxSize
& given
)
1059 if ( mpBar
->mDimInfo
.GetDimHandler() )
1062 cbBarDimHandlerBase
* pHandler
= mpBar
->mDimInfo
.GetDimHandler();
1066 // int vtad = *((int*)pHandler);
1068 pHandler
->OnResizeBar( mpBar
, given
, prefDim
);
1074 if ( mpBar
->IsFixed() )
1076 return mpBar
->mDimInfo
.mSizes
[ wxCBAR_FLOATING
];
1078 return given
; // not-fixed bars are resized exactly the way user wants
1082 void cbFloatedBarWindow::OnMiniButtonClicked( int btnIdx
)
1084 // #1 - close mini-button
1085 // #0 - dock mini-button
1089 mpBar
->mAlignment
= -1; // sepcial "marking" for hidden bars out of floated state
1090 mpLayout
->SetBarState( mpBar
, wxCBAR_HIDDEN
, TRUE
);
1093 mpLayout
->SetBarState( mpBar
, wxCBAR_DOCKED_HORIZONTALLY
, TRUE
);
1096 bool cbFloatedBarWindow::HandleTitleClick( wxMouseEvent
& event
)
1099 mMouseCaptured
= FALSE
;
1102 GetScrMousePos( event
, scrPos
);
1107 mpLayout
->GetParentFrame().ScreenToClient( &msX
, &msY
);
1114 wxSize minDim
= GetMinimalWndDim();
1119 x
+= mWndHorizGap
+ mClntHorizGap
;
1120 y
+= mWndVertGap
+ mTitleHeight
+ mClntVertGap
;
1122 mpLayout
->GetParentFrame().ScreenToClient( &x
, &y
);
1124 wxRect
& bounds
= mpBar
->mDimInfo
.mBounds
[ wxCBAR_FLOATING
];
1131 cbStartBarDraggingEvent
dragEvt( mpBar
, wxPoint(msX
,msY
),
1132 mpLayout
->GetPanesArray()[FL_ALIGN_TOP
] );
1134 mpLayout
->FirePluginEvent( dragEvt
);
1139 void cbFloatedBarWindow::OnDblClick( wxMouseEvent
& event
)
1141 mpLayout
->SetBarState( mpBar
, wxCBAR_DOCKED_HORIZONTALLY
, TRUE
);
1143 //wxMessageBox("toolWnd - dblClick!");