1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxToolWindow implementation.
4 // Author: Aleksandras Gluchovas
8 // Copyright: (c) Aleksandras Gluchovas
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/fl/toolwnd.h"
25 #define _IMG_A 0xAA // Note: modified from _A to _IMG_A, _A was already defined (cygwin)
26 #define _IMG_B 0x00 // Note: modified from _B to _IMG_A, _B was already defined (cygwin)
27 #define _IMG_C 0x55 // Note: modified from _C to _IMG_C, for consistency reasons.
28 #define _IMG_D 0x00 // Note: modified from _D to _IMG_D, for consistency reasons.
32 static const unsigned char _gCheckerImg
[16] = { _IMG_A
,_IMG_B
,_IMG_C
,_IMG_D
,
33 _IMG_A
,_IMG_B
,_IMG_C
,_IMG_D
,
34 _IMG_A
,_IMG_B
,_IMG_C
,_IMG_D
,
35 _IMG_A
,_IMG_B
,_IMG_C
,_IMG_D
38 /***** Implementation for class wxToolWindow *****/
40 IMPLEMENT_DYNAMIC_CLASS( wxToolWindow
, wxFrame
)
42 BEGIN_EVENT_TABLE( wxToolWindow
, wxFrame
)
44 EVT_PAINT ( wxToolWindow::OnPaint
)
45 EVT_MOTION ( wxToolWindow::OnMotion
)
46 EVT_LEFT_DOWN( wxToolWindow::OnLeftDown
)
47 EVT_LEFT_UP ( wxToolWindow::OnLeftUp
)
48 EVT_SIZE ( wxToolWindow::OnSize
)
51 EVT_ERASE_BACKGROUND( wxToolWindow::OnEraseBackground
)
55 enum INTERNAL_HIT_CODES
66 HITS_WND_TOP_LEFT_CORNER
,
67 HITS_WND_BOTTOM_RIGHT_CORNER
,
68 HITS_WND_TOP_RIGHT_CORNER
,
69 HITS_WND_BOTTOM_LEFT_CORNER
72 wxToolWindow::wxToolWindow()
74 : mpClientWnd ( NULL
),
77 mTitleFont( 8, wxSWISS
, wxNORMAL
, wxNORMAL
),
79 // just to simulate MS-Dev style
80 mTitleFont( 8, wxSWISS
, wxNORMAL
, wxNORMAL
, false, wxT("MS Sans Serif") ),
93 mResizeStarted( false ),
94 mRealTimeUpdatesOn( true ),
96 mMTolerance ( 5 ), // mouse-resizing tollerance
98 mCursorType( HITS_WND_NOTHING
),
99 mMouseCaptured( false ),
106 wxToolWindow::~wxToolWindow()
108 if ( mpScrDc
) delete mpScrDc
;
110 for( size_t i
= 0; i
!= mButtons
.Count(); ++i
)
114 void wxToolWindow::LayoutMiniButtons()
120 int x
= w
- mWndHorizGap
- mInTitleMargin
- BTN_BOX_WIDTH
;
121 int y
= mWndVertGap
+ 2;
123 for( size_t i
= 0; i
!= mButtons
.Count(); ++i
)
125 mButtons
[i
]->SetPos( wxPoint( x
,y
) );
126 x
-= BTN_BOX_WIDTH
+ mButtonGap
;
130 void wxToolWindow::SetClient( wxWindow
* pWnd
)
135 wxWindow
* wxToolWindow::GetClient()
140 void wxToolWindow::SetTitleFont( wxFont
& font
)
145 void wxToolWindow::AddMiniButton( cbMiniButton
* pBtn
)
149 mButtons
.Add( pBtn
);
151 // not necesserely now..
152 //LayoutMiniButtons();
155 void wxToolWindow::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
157 wxPaintDC
pdc( this );
158 wxWindowDC
dc( this );
163 wxBrush
backGround( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
), wxSOLID
);
164 //dc.SetBrush( *wxLIGHT_GREY_BRUSH );
165 dc
.SetBrush( backGround
);
166 dc
.SetPen( *wxTRANSPARENT_PEN
);
168 int y
= mWndVertGap
+ mTitleHeight
+ mClntVertGap
;
170 dc
.DrawRectangle( 0,0, w
, y
); // Top grey part.
171 dc
.DrawRectangle( 0,y
-1, mWndHorizGap
+ mClntHorizGap
, h
- y
); // Left grey part.
172 dc
.DrawRectangle( w
- ( mWndHorizGap
+ mClntHorizGap
), y
-1,
173 mWndHorizGap
+ mClntHorizGap
, h
- y
); // Right grey part.
174 dc
.DrawRectangle( 0, h
- mWndVertGap
- mClntVertGap
, w
, mWndVertGap
+ mClntVertGap
); // Bottom grey part.
177 dc
.SetPen( *wxLIGHT_GREY_PEN
);
179 dc
.DrawLine( 0,0, w
, 0 );
180 dc
.DrawLine( 0,0, 0, h
);
182 dc
.SetPen( *wxWHITE_PEN
);
184 dc
.DrawLine( 1,1, w
, 1 );
185 dc
.DrawLine( 1,2, 1, h
);
187 dc
.SetPen( *wxGREY_PEN
);
189 dc
.DrawLine( w
- 2, 1, w
- 2, h
- 1 );
190 dc
.DrawLine( 1, h
- 2, w
- 2, h
- 2 );
192 dc
.SetPen( *wxBLACK_PEN
);
194 dc
.DrawLine( 0, h
- 1, w
, h
- 1 );
195 dc
.DrawLine( w
-1, 0, w
-1, h
);
199 dc
.SetBrush( *wxTheBrushList
->FindOrCreateBrush( wxColour( 0,0,128 ), wxSOLID
) );
201 dc
.DrawRectangle( mWndHorizGap
, mWndVertGap
, w
- mWndHorizGap
*2, mTitleHeight
);
203 dc
.SetFont( mTitleFont
);
205 for( size_t i
= 0; i
!= mButtons
.Count(); ++i
)
206 mButtons
[i
]->Draw( dc
);
208 int x1
= mWndHorizGap
+ mClntHorizGap
;
209 int x2
= mButtons
[ mButtons
.GetCount() - 1 ]->mPos
.x
- mClntHorizGap
*2;
211 dc
.SetClippingRegion( x1
, mWndVertGap
+ mClntVertGap
, x2
- x1
, mTitleHeight
);
213 dc
.SetTextForeground( *wxWHITE
);
214 dc
.SetBackgroundMode( wxTRANSPARENT
);
215 dc
.DrawText( GetTitle(), mWndHorizGap
+ 2, mWndVertGap
+ 1 );
218 void wxToolWindow::GetScrWindowRect( wxRect
& r
)
226 r
.width
= w
; r
.height
= h
;
229 void wxToolWindow::GetScrMousePos( wxMouseEvent
& event
, wxPoint
& pos
)
231 int x
= event
.m_x
, y
= event
.m_y
;
233 ClientToScreen( &x
, &y
);
235 pos
.x
= x
; pos
.y
= y
;
238 int wxToolWindow::HitTestWindow( wxMouseEvent
& event
)
243 GetScrMousePos( event
, pos
);
244 GetScrWindowRect( r
);
248 if ( !( pos
.x
>= r
.x
&& pos
.y
>= r
.y
&&
249 pos
.x
< r
.x
+ r
.width
&&
250 pos
.y
< r
.y
+ r
.height
)
252 return HITS_WND_NOTHING
;
254 if ( pos
.y
<= r
.y
+ k
)
256 if ( pos
.x
< r
.x
+ k
*2 )
257 return HITS_WND_TOP_LEFT_CORNER
;
260 if ( pos
.x
>= r
.x
+ r
.width
- k
*2 )
261 return HITS_WND_TOP_RIGHT_CORNER
;
263 return HITS_WND_TOP_EDGE
;
268 if ( pos
.y
>= r
.y
+ r
.height
- k
)
270 if ( pos
.x
< r
.x
+ k
*2 )
271 return HITS_WND_BOTTOM_LEFT_CORNER
;
274 if ( pos
.x
> r
.x
+ r
.width
- k
*2 )
275 return HITS_WND_BOTTOM_RIGHT_CORNER
;
277 return HITS_WND_BOTTOM_EDGE
;
282 if ( pos
.x
<= r
.x
+ k
)
283 return HITS_WND_LEFT_EDGE
;
286 if ( pos
.x
>= r
.x
+ r
.width
- k
)
287 return HITS_WND_RIGHT_EDGE
;
290 if ( pos
.y
<= r
.y
+ mWndVertGap
+ mTitleHeight
+ mClntVertGap
)
291 return HITS_WND_TITLE
;
293 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
)
342 if ( type
== HITS_WND_NOTHING
|| type
== HITS_WND_CLIENT
)
344 // the cursor is out of window - reset to arrow
346 if ( mMouseCaptured
)
349 mMouseCaptured
= false;
352 SetCursor( wxCURSOR_ARROW
);
359 // did the cursor actually changed?
361 if ( type
!= mCursorType
)
367 case HITS_WND_LEFT_EDGE
: SetCursor( wxCURSOR_SIZEWE
); break;
368 case HITS_WND_RIGHT_EDGE
: SetCursor( wxCURSOR_SIZEWE
); break;
369 case HITS_WND_TOP_EDGE
: SetCursor( wxCURSOR_SIZENS
); break;
370 case HITS_WND_BOTTOM_EDGE
: SetCursor( wxCURSOR_SIZENS
); break;
372 case HITS_WND_TOP_LEFT_CORNER
: SetCursor( wxCURSOR_SIZENWSE
); break;
373 case HITS_WND_BOTTOM_RIGHT_CORNER
: SetCursor( wxCURSOR_SIZENWSE
); break;
374 case HITS_WND_TOP_RIGHT_CORNER
: SetCursor( wxCURSOR_SIZENESW
); break;
375 case HITS_WND_BOTTOM_LEFT_CORNER
: SetCursor( wxCURSOR_SIZENESW
); break;
377 case HITS_WND_TITLE
: SetCursor( wxCURSOR_ARROW
); break;
378 case HITS_WND_CLIENT
: SetCursor( wxCURSOR_ARROW
); break;
385 mMouseCaptured
= false;
390 if ( !mMouseCaptured
)
392 mMouseCaptured
= true;
397 #define FL_INFINITY 32768
399 static inline void clip_to( int& value
, long from
, long till
)
408 void wxToolWindow::AdjustRectPos( const wxRect
& original
, const wxSize
& newDim
, wxRect
& newRect
)
410 if ( mCursorType
== HITS_WND_TOP_EDGE
||
411 mCursorType
== HITS_WND_TOP_LEFT_CORNER
)
413 newRect
.x
= original
.x
+ original
.width
- newDim
.x
;
414 newRect
.y
= original
.y
+ original
.height
- newDim
.y
;
417 if ( mCursorType
== HITS_WND_LEFT_EDGE
||
418 mCursorType
== HITS_WND_BOTTOM_LEFT_CORNER
)
420 newRect
.x
= original
.x
+ original
.width
- newDim
.x
;
421 newRect
.y
= original
.y
;
424 if ( mCursorType
== HITS_WND_RIGHT_EDGE
||
425 mCursorType
== HITS_WND_TOP_RIGHT_CORNER
)
427 newRect
.x
= original
.x
;
428 newRect
.y
= original
.y
+ original
.height
- newDim
.y
;
431 if ( mCursorType
== HITS_WND_BOTTOM_EDGE
||
432 mCursorType
== HITS_WND_BOTTOM_RIGHT_CORNER
)
434 newRect
.x
= original
.x
;
435 newRect
.y
= original
.y
;
438 newRect
.width
= newDim
.x
;
439 newRect
.height
= newDim
.y
;
442 void wxToolWindow::CalcResizedRect( wxRect
& rect
, wxPoint
& delta
, const wxSize
& minDim
)
444 // Microsoft's rect-coordinates are best suited
445 // for the case of corner-clipping
447 int left
= mInitialRect
.x
;
448 int top
= mInitialRect
.y
;
449 int right
= mInitialRect
.x
+ mInitialRect
.width
;
450 int bottom
= mInitialRect
.y
+ mInitialRect
.height
;
452 // constraint delta edge is dragged
454 switch ( mCursorType
)
456 case HITS_WND_LEFT_EDGE
: delta
.y
= 0; break;
457 case HITS_WND_RIGHT_EDGE
: delta
.y
= 0; break;
458 case HITS_WND_TOP_EDGE
: delta
.x
= 0; break;
459 case HITS_WND_BOTTOM_EDGE
: delta
.x
= 0; break;
463 if ( mCursorType
== HITS_WND_TOP_EDGE
||
464 mCursorType
== HITS_WND_TOP_LEFT_CORNER
)
469 clip_to( left
, -FL_INFINITY
, mInitialRect
.x
+ mInitialRect
.width
- minDim
.x
);
470 clip_to( top
, -FL_INFINITY
, mInitialRect
.y
+ mInitialRect
.height
- minDim
.y
);
473 if ( mCursorType
== HITS_WND_LEFT_EDGE
||
474 mCursorType
== HITS_WND_BOTTOM_LEFT_CORNER
)
479 clip_to( left
, -FL_INFINITY
, mInitialRect
.x
+ mInitialRect
.width
- minDim
.x
);
480 clip_to( bottom
, mInitialRect
.y
+ minDim
.y
, FL_INFINITY
);
483 if ( mCursorType
== HITS_WND_RIGHT_EDGE
||
484 mCursorType
== HITS_WND_TOP_RIGHT_CORNER
)
489 clip_to( right
, mInitialRect
.x
+ minDim
.x
, FL_INFINITY
);
490 clip_to( top
, -FL_INFINITY
, mInitialRect
.y
+ mInitialRect
.height
- minDim
.y
);
493 if ( mCursorType
== HITS_WND_BOTTOM_EDGE
||
494 mCursorType
== HITS_WND_BOTTOM_RIGHT_CORNER
)
499 clip_to( right
, mInitialRect
.x
+ minDim
.x
, FL_INFINITY
);
500 clip_to( bottom
, mInitialRect
.y
+ minDim
.y
, FL_INFINITY
);
504 wxFAIL_MSG( _T("what did the cursor hit?") );
509 rect
.width
= right
- left
;
510 rect
.height
= bottom
- top
;
513 wxSize
wxToolWindow::GetMinimalWndDim()
515 return wxSize( (mWndHorizGap
+ mClntHorizGap
)*2 + BTN_BOX_WIDTH
*4,
516 (mWndVertGap
+ mClntVertGap
)*2 + mTitleHeight
);
519 void wxToolWindow::OnMotion( wxMouseEvent
& event
)
521 if ( !mResizeStarted
)
523 for( size_t i
= 0; i
!= mButtons
.Count(); ++i
)
524 mButtons
[i
]->OnMotion( wxPoint( event
.m_x
, event
.m_y
) );
526 SetHintCursor( HitTestWindow( event
) );
531 GetScrMousePos( event
, pos
);
533 if ( mCursorType
== HITS_WND_TITLE
)
538 SetSize( mInitialRect
.x
+ pos
.x
- mDragOrigin
.x
,
539 mInitialRect
.y
+ pos
.y
- mDragOrigin
.y
,
545 wxPoint
delta( pos
.x
- mDragOrigin
.x
, pos
.y
- mDragOrigin
.y
);
549 wxSize minDim
= GetMinimalWndDim();
551 CalcResizedRect( newRect
, delta
, minDim
);
553 wxSize
borderDim( ( mWndHorizGap
+ mClntHorizGap
)*2,
554 ( mWndVertGap
+ mClntVertGap
)*2 + mTitleHeight
);
556 wxSize preferred
= GetPreferredSize( wxSize( newRect
.width
- borderDim
.x
,
557 newRect
.height
- borderDim
.y
) );
559 preferred
.x
+= borderDim
.x
;
560 preferred
.y
+= borderDim
.y
;
562 //CalcResizedRect( newRect, delta, preferred );
564 wxRect finalRect
= newRect
;
566 AdjustRectPos( newRect
, preferred
, finalRect
);
568 if ( mRealTimeUpdatesOn
)
570 SetSize( finalRect
.x
, finalRect
.y
,
571 finalRect
.width
, finalRect
.height
, 0 );
575 DrawHintRect( mPrevHintRect
);
576 DrawHintRect( finalRect
);
578 ::wxLogTrace(wxT("wxToolWindow"),wxT("%d,%d / %d,%d\n"), finalRect
.x
, finalRect
.y
, finalRect
.width
, finalRect
.height
);
581 mPrevHintRect
= finalRect
;
585 void wxToolWindow::OnLeftDown( wxMouseEvent
& event
)
587 int result
= HitTestWindow( event
);
589 for( size_t i
= 0; i
!= mButtons
.Count(); ++i
)
591 mButtons
[i
]->OnLeftDown( wxPoint( event
.m_x
, event
.m_y
) );
593 if ( mButtons
[i
]->IsPressed() )
594 return; // button hitted,
597 if ( result
>= HITS_WND_LEFT_EDGE
|| result
== HITS_WND_TITLE
)
599 GetScrMousePos( event
, mDragOrigin
);
602 if ( mMouseCaptured `)
605 mMouseCaptured = false;
608 if ( result
== HITS_WND_TITLE
&&
609 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
& WXUNUSED(event
) )
680 int x
= mWndHorizGap
+ mClntHorizGap
;
681 int y
= mWndVertGap
+ mTitleHeight
+ mClntVertGap
;
683 mpClientWnd
->SetSize( x
-1, y
-1,
684 w
- 2*(mWndHorizGap
+ mClntHorizGap
),
685 h
- y
- mClntVertGap
- mWndVertGap
,
693 wxSize
wxToolWindow::GetPreferredSize( const wxSize
& given
)
698 void wxToolWindow::OnEraseBackground( wxEraseEvent
& WXUNUSED(event
) )
703 /***** Implementation for class cbMiniButton *****/
705 cbMiniButton::cbMiniButton()
715 mWasClicked( false ),
716 mDragStarted( false ),
720 void cbMiniButton::SetPos( const wxPoint
& pos
)
725 bool cbMiniButton::HitTest( const wxPoint
& pos
)
727 if ( !mVisible
) return false;
729 return ( pos
.x
>= mPos
.x
&& pos
.y
>= mPos
.y
&&
730 pos
.x
< mPos
.x
+ BTN_BOX_WIDTH
&&
731 pos
.y
< mPos
.y
+ BTN_BOX_HEIGHT
);
734 void cbMiniButton::OnLeftDown( const wxPoint
& pos
)
736 if ( !mVisible
|| mDragStarted
) return;
738 if ( HitTest( pos
) && mEnabled
)
742 mpLayout
->CaptureEventsForPane( mpPane
);
743 mpLayout
->CaptureEventsForPlugin( mpPlugin
);
746 mpWnd
->CaptureMouse();
756 void cbMiniButton::OnLeftUp( const wxPoint
& WXUNUSED(pos
) )
758 if ( !mVisible
|| !mDragStarted
) return;
762 mpLayout
->ReleaseEventsFromPane( mpPane
);
763 mpLayout
->ReleaseEventsFromPlugin( mpPlugin
);
766 mpWnd
->ReleaseMouse();
768 mWasClicked
= mPressed
;
769 mDragStarted
= false;
775 void cbMiniButton::OnMotion( const wxPoint
& pos
)
777 if ( !mVisible
) return;
781 mPressed
= HitTest( pos
);
787 void cbMiniButton::Refresh()
791 wxClientDC
dc( &mpLayout
->GetParentFrame() );
797 wxWindowDC
dc( mpWnd
);
803 void cbMiniButton::Draw( wxDC
& dc
)
805 if ( !mVisible
) return;
807 dc
.SetPen( *wxTRANSPARENT_PEN
);
809 dc
.SetBrush( *wxLIGHT_GREY_BRUSH
);
811 dc
.DrawRectangle( mPos
.x
+ 1, mPos
.y
+ 1, BTN_BOX_WIDTH
- 2, BTN_BOX_HEIGHT
- 2 );
813 // "hard-code" metafile
816 dc
.SetPen( *wxWHITE_PEN
);
818 dc
.SetPen( *wxBLACK_PEN
);
820 dc
.DrawLine( mPos
.x
, mPos
.y
, mPos
.x
+ BTN_BOX_WIDTH
, mPos
.y
);
821 dc
.DrawLine( mPos
.x
, mPos
.y
, mPos
.x
, mPos
.y
+ BTN_BOX_HEIGHT
);
823 dc
.SetPen( *wxGREY_PEN
);
827 dc
.DrawLine( mPos
.x
+ 1, mPos
.y
+ BTN_BOX_HEIGHT
- 2,
828 mPos
.x
+ BTN_BOX_WIDTH
- 1, mPos
.y
+ BTN_BOX_HEIGHT
- 2 );
830 dc
.DrawLine( mPos
.x
+ BTN_BOX_WIDTH
- 2, mPos
.y
+ 1,
831 mPos
.x
+ BTN_BOX_WIDTH
- 2, mPos
.y
+ BTN_BOX_HEIGHT
- 1 );
835 dc
.DrawLine( mPos
.x
+ 1, mPos
.y
+ 1,
836 mPos
.x
+ BTN_BOX_WIDTH
- 2, mPos
.y
+ 1 );
838 dc
.DrawLine( mPos
.x
+ 1, mPos
.y
+ 1,
839 mPos
.x
+ 1, mPos
.y
+ BTN_BOX_HEIGHT
- 2 );
843 dc
.SetPen( *wxBLACK_PEN
);
845 dc
.SetPen( *wxWHITE_PEN
);
847 dc
.DrawLine( mPos
.x
, mPos
.y
+ BTN_BOX_HEIGHT
- 1,
848 mPos
.x
+ BTN_BOX_WIDTH
, mPos
.y
+ BTN_BOX_HEIGHT
- 1 );
850 dc
.DrawLine( mPos
.x
+ BTN_BOX_WIDTH
- 1, mPos
.y
,
851 mPos
.x
+ BTN_BOX_WIDTH
- 1, mPos
.y
+ BTN_BOX_HEIGHT
);
854 bool cbMiniButton::WasClicked()
859 void cbMiniButton::Reset()
864 /***** Implementation fro class cbCloseBox *****/
866 void cbCloseBox::Draw( wxDC
& dc
)
868 cbMiniButton::Draw( dc
);
870 dc
.SetPen( *wxBLACK_PEN
);
872 int width
= BTN_BOX_WIDTH
- 7;
874 int xOfs
= (mPressed
) ? 4 : 3;
875 int yOfs
= (mPressed
) ? 4 : 3;
877 for( int i
= 0; i
!= BTN_X_WEIGHT
; ++i
)
879 dc
.DrawLine( mPos
.x
+ xOfs
+ i
,
881 mPos
.x
+ xOfs
+ i
+ width
,
882 mPos
.y
+ yOfs
+ width
);
884 dc
.DrawLine( mPos
.x
+ xOfs
+ i
+ width
- 1,
886 mPos
.x
+ xOfs
+ i
- 1,
887 mPos
.y
+ yOfs
+ width
);
891 /***** Implementation fro class cbCollapseBox *****/
893 inline static void my_swap( int& a
, int& b
)
900 void cbCollapseBox::Draw( wxDC
& dc
)
902 cbMiniButton::Draw( dc
);
904 dc
.SetPen( *wxTRANSPARENT_PEN
);
908 int yOfs
= (mPressed
) ? 3 : 2;
909 int xOfs
= (mPressed
) ? 5 : 4;
910 int width
= BTN_BOX_WIDTH
- 8;
912 // rotating/shifting triangle inside collapse box
917 arr
[2].y
= BTN_BOX_HEIGHT
- yOfs
- 1;
918 arr
[1].x
= xOfs
+ width
;
919 arr
[1].y
= (arr
[2].y
+ arr
[0].y
)/2;
923 arr
[0].x
= BTN_BOX_WIDTH
- arr
[0].x
;
924 arr
[1].x
= BTN_BOX_WIDTH
- arr
[1].x
;
925 arr
[2].x
= BTN_BOX_WIDTH
- arr
[2].x
;
928 if ( !mpPane
->IsHorizontal() )
930 my_swap( arr
[0].y
, arr
[0].x
);
931 my_swap( arr
[1].y
, arr
[1].x
);
932 my_swap( arr
[2].y
, arr
[2].x
);
948 if ( !mEnabled
) dc
.SetBrush( *wxGREY_BRUSH
);
949 else dc
.SetBrush( *wxBLACK_BRUSH
);
951 dc
.DrawPolygon( 3, arr
);
952 dc
.SetBrush( wxNullBrush
);
955 /***** Implementation for class cbDockBoxBox *****/
957 void cbDockBox::Draw( wxDC
& dc
)
959 cbMiniButton::Draw( dc
);
961 int width
= BTN_BOX_WIDTH
- 7;
963 int xOfs
= (mPressed
) ? 4 : 3;
964 int yOfs
= (mPressed
) ? 4 : 3;
966 dc
.SetPen( *wxBLACK_PEN
);
967 dc
.SetBrush( *wxBLACK_BRUSH
);
969 dc
.DrawRectangle( mPos
.x
+ xOfs
, mPos
.y
+ yOfs
, width
, width
);
974 dc
.SetBrush( *wxWHITE_BRUSH
);
976 dc
.DrawRectangle( mPos
.x
+ xOfs
, mPos
.y
+ yOfs
, width
-2, width
-2 );
979 /***** Implementation for class wxToolWindow *****/
981 IMPLEMENT_DYNAMIC_CLASS( cbFloatedBarWindow
, wxToolWindow
)
983 BEGIN_EVENT_TABLE( cbFloatedBarWindow
, wxToolWindow
)
985 EVT_LEFT_DCLICK( cbFloatedBarWindow::OnDblClick
)
989 cbFloatedBarWindow::cbFloatedBarWindow()
993 AddMiniButton( new cbCloseBox() );
994 AddMiniButton( new cbDockBox() );
997 void cbFloatedBarWindow::SetBar( cbBarInfo
* pBar
)
1002 cbBarInfo
* cbFloatedBarWindow::GetBar()
1007 void cbFloatedBarWindow::SetLayout( wxFrameLayout
* pLayout
)
1012 void cbFloatedBarWindow::PositionFloatedWnd( int scrX
, int scrY
,
1013 int width
, int height
)
1015 wxSize minDim
= GetMinimalWndDim();
1017 SetSize( scrX
- mWndHorizGap
- mClntHorizGap
,
1018 scrY
- mClntVertGap
- mTitleHeight
- mWndVertGap
,
1019 width
+ minDim
.x
, height
+ minDim
.y
, 0 );
1022 wxSize
cbFloatedBarWindow::GetPreferredSize( const wxSize
& given
)
1024 if ( mpBar
->mDimInfo
.GetDimHandler() )
1026 cbBarDimHandlerBase
* pHandler
= mpBar
->mDimInfo
.GetDimHandler();
1030 // int vtad = *((int*)pHandler);
1032 pHandler
->OnResizeBar( mpBar
, given
, prefDim
);
1038 if ( mpBar
->IsFixed() )
1039 return mpBar
->mDimInfo
.mSizes
[ wxCBAR_FLOATING
];
1041 return given
; // not-fixed bars are resized exactly the way user wants
1045 void cbFloatedBarWindow::OnMiniButtonClicked( int btnIdx
)
1047 // #1 - close mini-button
1048 // #0 - dock mini-button
1052 mpBar
->mAlignment
= -1; // sepcial "marking" for hidden bars out of floated state
1053 mpLayout
->SetBarState( mpBar
, wxCBAR_HIDDEN
, true );
1056 mpLayout
->SetBarState( mpBar
, wxCBAR_DOCKED_HORIZONTALLY
, true );
1059 bool cbFloatedBarWindow::HandleTitleClick( wxMouseEvent
& event
)
1062 mMouseCaptured
= false;
1065 GetScrMousePos( event
, scrPos
);
1070 mpLayout
->GetParentFrame().ScreenToClient( &msX
, &msY
);
1077 wxSize minDim
= GetMinimalWndDim();
1082 x
+= mWndHorizGap
+ mClntHorizGap
;
1083 y
+= mWndVertGap
+ mTitleHeight
+ mClntVertGap
;
1085 mpLayout
->GetParentFrame().ScreenToClient( &x
, &y
);
1087 wxRect
& bounds
= mpBar
->mDimInfo
.mBounds
[ wxCBAR_FLOATING
];
1094 cbStartBarDraggingEvent
dragEvt( mpBar
, wxPoint(msX
,msY
),
1095 mpLayout
->GetPanesArray()[FL_ALIGN_TOP
] );
1097 mpLayout
->FirePluginEvent( dragEvt
);
1102 void cbFloatedBarWindow::OnDblClick( wxMouseEvent
& WXUNUSED(event
) )
1104 mpLayout
->SetBarState( mpBar
, wxCBAR_DOCKED_HORIZONTALLY
, true );
1106 //wxMessageBox("toolWnd - dblClick!");