]> git.saurik.com Git - wxWidgets.git/blame - contrib/src/fl/toolwnd.cpp
wxUSE_STL fixes.
[wxWidgets.git] / contrib / src / fl / toolwnd.cpp
CommitLineData
8e08b761 1/////////////////////////////////////////////////////////////////////////////
4cbc57f0
JS
2// Name: toolwnd.cpp
3// Purpose: wxToolWindow implementation.
8e08b761
JS
4// Author: Aleksandras Gluchovas
5// Modified by:
6// Created: 06/09/98
7// RCS-ID: $Id$
8// Copyright: (c) Aleksandras Gluchovas
c82c42d4 9// Licence: wxWindows licence
8e08b761
JS
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13 #pragma implementation "toolwnd.h"
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#ifndef WX_PRECOMP
24#include "wx/wx.h"
25#endif
26
27#include "wx/fl/toolwnd.h"
28
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.
33
34// FOR NOW:: static
35
36static const unsigned char _gCheckerImg[16] = { _IMG_A,_IMG_B,_IMG_C,_IMG_D,
c82c42d4
WS
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
40 };
8e08b761
JS
41
42/***** Implementation for class wxToolWindow *****/
43
7eff657c 44IMPLEMENT_DYNAMIC_CLASS( wxToolWindow, wxFrame)
8e08b761 45
7eff657c 46BEGIN_EVENT_TABLE( wxToolWindow, wxFrame )
8e08b761 47
c82c42d4
WS
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 )
8e08b761
JS
53
54
c82c42d4 55 EVT_ERASE_BACKGROUND( wxToolWindow::OnEraseBackground )
8e08b761
JS
56
57END_EVENT_TABLE()
58
59enum INTERNAL_HIT_CODES
60{
c82c42d4
WS
61 HITS_WND_NOTHING,
62 HITS_WND_CLIENT,
63 HITS_WND_TITLE,
64
65 HITS_WND_LEFT_EDGE,
66 HITS_WND_RIGHT_EDGE,
67 HITS_WND_TOP_EDGE,
68 HITS_WND_BOTTOM_EDGE,
69
70 HITS_WND_TOP_LEFT_CORNER,
71 HITS_WND_BOTTOM_RIGHT_CORNER,
72 HITS_WND_TOP_RIGHT_CORNER,
73 HITS_WND_BOTTOM_LEFT_CORNER
8e08b761
JS
74};
75
76wxToolWindow::wxToolWindow()
77
c82c42d4
WS
78 : mpClientWnd ( NULL ),
79
8e08b761 80#ifndef __WXMSW__
c82c42d4 81 mTitleFont( 8, wxSWISS, wxNORMAL, wxNORMAL ),
8e08b761 82#else
c82c42d4
WS
83 // just to simulate MS-Dev style
84 mTitleFont( 8, wxSWISS, wxNORMAL, wxNORMAL, false, wxT("MS Sans Serif") ),
8e08b761
JS
85#endif
86
c82c42d4
WS
87 mTitleHeight ( 16 ),
88 mClntHorizGap ( 2 ),
89 mClntVertGap ( 2 ),
90 mWndVertGap ( 4 ),
91 mWndHorizGap ( 4 ),
8e08b761 92
c82c42d4
WS
93 mButtonGap ( 2 ),
94 mInTitleMargin( 4 ),
95 mHintBorder ( 4 ),
8e08b761 96
c82c42d4
WS
97 mResizeStarted( false ),
98 mRealTimeUpdatesOn( true ),
8e08b761 99
c82c42d4 100 mMTolerance ( 5 ), // mouse-resizing tollerance
8e08b761 101
c82c42d4
WS
102 mCursorType( HITS_WND_NOTHING ),
103 mMouseCaptured( false ),
104
105 mpScrDc( NULL )
8e08b761
JS
106
107{
108}
109
110wxToolWindow::~wxToolWindow()
111{
c82c42d4 112 if ( mpScrDc ) delete mpScrDc;
8e08b761 113
c82c42d4
WS
114 for( size_t i = 0; i != mButtons.Count(); ++i )
115 delete mButtons[i];
8e08b761
JS
116}
117
118void wxToolWindow::LayoutMiniButtons()
c82c42d4
WS
119{
120 int w,h;
8e08b761 121
c82c42d4 122 GetSize( &w, &h );
8e08b761 123
c82c42d4
WS
124 int x = w - mWndHorizGap - mInTitleMargin - BTN_BOX_WIDTH;
125 int y = mWndVertGap + 2;
8e08b761 126
c82c42d4
WS
127 for( size_t i = 0; i != mButtons.Count(); ++i )
128 {
129 mButtons[i]->SetPos( wxPoint( x,y ) );
130 x-= BTN_BOX_WIDTH + mButtonGap;
131 }
8e08b761
JS
132}
133
134void wxToolWindow::SetClient( wxWindow* pWnd )
135{
c82c42d4 136 mpClientWnd = pWnd;
8e08b761
JS
137}
138
139wxWindow* wxToolWindow::GetClient()
140{
c82c42d4 141 return mpClientWnd;
8e08b761
JS
142}
143
144void wxToolWindow::SetTitleFont( wxFont& font )
145{
c82c42d4 146 mTitleFont = font;
8e08b761
JS
147}
148
149void wxToolWindow::AddMiniButton( cbMiniButton* pBtn )
150{
c82c42d4 151 pBtn->mpWnd = this;
8e08b761 152
c82c42d4 153 mButtons.Add( pBtn );
8e08b761 154
c82c42d4
WS
155 // not necesserely now..
156 //LayoutMiniButtons();
8e08b761
JS
157}
158
196be0f1 159void wxToolWindow::OnPaint( wxPaintEvent& WXUNUSED(event) )
8e08b761
JS
160{
161 wxPaintDC pdc( this );
c82c42d4 162 wxWindowDC dc( this );
8e08b761 163
c82c42d4
WS
164 int w,h;
165 GetSize( &w, &h );
8e08b761 166
8e33234f
GT
167 wxBrush backGround( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_BTNFACE), wxSOLID );
168 //dc.SetBrush( *wxLIGHT_GREY_BRUSH );
169 dc.SetBrush( backGround );
170 dc.SetPen( *wxTRANSPARENT_PEN );
171
172 int y = mWndVertGap + mTitleHeight + mClntVertGap;
c82c42d4 173
8e33234f
GT
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.
8e08b761 179
c82c42d4
WS
180 // draw shades
181 dc.SetPen( *wxLIGHT_GREY_PEN );
8e08b761 182
c82c42d4
WS
183 dc.DrawLine( 0,0, w, 0 );
184 dc.DrawLine( 0,0, 0, h );
8e08b761 185
c82c42d4 186 dc.SetPen( *wxWHITE_PEN );
8e08b761 187
c82c42d4
WS
188 dc.DrawLine( 1,1, w, 1 );
189 dc.DrawLine( 1,2, 1, h );
8e08b761 190
c82c42d4 191 dc.SetPen( *wxGREY_PEN );
8e08b761 192
c82c42d4
WS
193 dc.DrawLine( w - 2, 1, w - 2, h - 1 );
194 dc.DrawLine( 1, h - 2, w - 2, h - 2 );
8e08b761 195
c82c42d4 196 dc.SetPen( *wxBLACK_PEN );
8e08b761 197
c82c42d4
WS
198 dc.DrawLine( 0, h - 1, w, h - 1 );
199 dc.DrawLine( w-1, 0, w-1, h );
8e08b761 200
c82c42d4 201 // fill inner area
8e08b761 202
c82c42d4 203 dc.SetBrush( *wxTheBrushList->FindOrCreateBrush( wxColour( 0,0,128 ), wxSOLID ) );
8e08b761 204
c82c42d4 205 dc.DrawRectangle( mWndHorizGap, mWndVertGap, w - mWndHorizGap*2, mTitleHeight );
8e08b761 206
c82c42d4 207 dc.SetFont( mTitleFont );
8e08b761 208
c82c42d4
WS
209 for( size_t i = 0; i != mButtons.Count(); ++i )
210 mButtons[i]->Draw( dc );
8e08b761 211
c82c42d4
WS
212 int x1 = mWndHorizGap + mClntHorizGap;
213 int x2 = mButtons[ mButtons.GetCount() - 1 ]->mPos.x - mClntHorizGap*2;
8e08b761 214
c82c42d4 215 dc.SetClippingRegion( x1, mWndVertGap + mClntVertGap, x2 - x1, mTitleHeight );
8e08b761 216
c82c42d4
WS
217 dc.SetTextForeground( *wxWHITE );
218 dc.SetBackgroundMode( wxTRANSPARENT );
219 dc.DrawText( GetTitle(), mWndHorizGap + 2, mWndVertGap + 1 );
8e08b761
JS
220}
221
222void wxToolWindow::GetScrWindowRect( wxRect& r )
223{
c82c42d4
WS
224 int x,y;
225 GetPosition(&x,&y);
226 int w,h;
227 GetSize( &w, &h );
8e08b761 228
c82c42d4
WS
229 r.x = x; r.y = y;
230 r.width = w; r.height = h;
8e08b761
JS
231}
232
233void wxToolWindow::GetScrMousePos( wxMouseEvent& event, wxPoint& pos )
234{
c82c42d4 235 int x = event.m_x, y = event.m_y;
8e08b761 236
c82c42d4 237 ClientToScreen( &x, &y );
8e08b761 238
c82c42d4 239 pos.x = x; pos.y = y;
8e08b761
JS
240}
241
242int wxToolWindow::HitTestWindow( wxMouseEvent& event )
243{
c82c42d4
WS
244 wxPoint pos;
245 wxRect r;
246
247 GetScrMousePos( event, pos );
248 GetScrWindowRect( r );
249
250 int k = mMTolerance;
251
252 if ( !( pos.x >= r.x && pos.y >= r.y &&
253 pos.x < r.x + r.width &&
254 pos.y < r.y + r.height )
255 )
256 return HITS_WND_NOTHING;
257
258 if ( pos.y <= r.y + k )
259 {
260 if ( pos.x < r.x + k*2 )
261 return HITS_WND_TOP_LEFT_CORNER;
262 else
263 {
264 if ( pos.x >= r.x + r.width - k*2 )
265 return HITS_WND_TOP_RIGHT_CORNER;
266 else
267 return HITS_WND_TOP_EDGE;
268 }
269 }
270 else
271 {
272 if ( pos.y >= r.y + r.height - k )
273 {
274 if ( pos.x < r.x + k*2 )
275 return HITS_WND_BOTTOM_LEFT_CORNER;
276 else
277 {
278 if ( pos.x > r.x + r.width - k*2 )
279 return HITS_WND_BOTTOM_RIGHT_CORNER;
280 else
281 return HITS_WND_BOTTOM_EDGE;
282 }
283 }
284 else
285 {
286 if ( pos.x <= r.x + k )
287 return HITS_WND_LEFT_EDGE;
288 else
289 {
290 if ( pos.x >= r.x + r.width - k )
291 return HITS_WND_RIGHT_EDGE;
292 else
293 {
294 if ( pos.y <= r.y + mWndVertGap + mTitleHeight + mClntVertGap )
295 return HITS_WND_TITLE;
296 else
297 return HITS_WND_CLIENT;
298 }
299 }
300 }
301 }
8e08b761
JS
302}
303
304void wxToolWindow::DrawHintRect( const wxRect& r )
305{
c82c42d4
WS
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
8e08b761 309
c82c42d4 310 int prevLF = mpScrDc->GetLogicalFunction();
8e08b761 311
c82c42d4 312 mpScrDc->SetLogicalFunction( wxXOR );
8e08b761 313
c82c42d4 314 wxBitmap checker( (const char*)_gCheckerImg, 8,8 );
8e08b761 315
c82c42d4 316 wxBrush checkerBrush( checker );
8e08b761 317
c82c42d4
WS
318 mpScrDc->SetPen( *wxTRANSPARENT_PEN );
319 mpScrDc->SetBrush( checkerBrush );
8e08b761 320
c82c42d4 321 int half = mHintBorder / 2;
8e08b761 322
c82c42d4
WS
323 mpScrDc->DrawRectangle( r.x - half, r.y - half,
324 r.width + 2*half, mHintBorder );
8e08b761 325
c82c42d4
WS
326 mpScrDc->DrawRectangle( r.x - half, r.y + r.height - half,
327 r.width + 2*half, mHintBorder );
8e08b761 328
c82c42d4
WS
329 mpScrDc->DrawRectangle( r.x - half, r.y + half - 1,
330 mHintBorder, r.height - 2*half + 2);
8e08b761 331
c82c42d4
WS
332 mpScrDc->DrawRectangle( r.x + r.width - half,
333 r.y + half - 1,
334 mHintBorder, r.height - 2*half + 2);
8e08b761 335
c82c42d4 336 mpScrDc->SetBrush( wxNullBrush );
8e08b761 337
c82c42d4 338 mpScrDc->SetLogicalFunction( prevLF );
8e08b761
JS
339}
340
341void wxToolWindow::SetHintCursor( int type )
342{
c82c42d4 343 if ( mResizeStarted )
db693128 344 return;
8e08b761 345
c82c42d4
WS
346 if ( type == HITS_WND_NOTHING || type == HITS_WND_CLIENT )
347 {
348 // the cursor is out of window - reset to arrow
349
350 if ( mMouseCaptured )
351 {
352 ReleaseMouse();
353 mMouseCaptured = false;
354 }
355
356 SetCursor( wxCURSOR_ARROW );
357
358 mCursorType = type;
359
360 return;
361 }
362
363 if ( !mMouseCaptured )
364 {
365 mMouseCaptured = true;
366 CaptureMouse();
367 }
368
369 // did the cursor actually changed?
370
371 if ( type != mCursorType )
372 {
373 mCursorType = type;
374
375 switch ( type )
376 {
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;
381
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;
386
387 case HITS_WND_TITLE : SetCursor( wxCURSOR_ARROW ); break;
388 case HITS_WND_CLIENT : SetCursor( wxCURSOR_ARROW ); break;
389
390 default: break;
391 }
392 }
8e08b761
JS
393}
394
395#define INFINITY 32768
396
397static inline void clip_to( int& value, long from, long till )
398{
c82c42d4
WS
399 if ( value < from )
400 value = from;
8e08b761 401
c82c42d4
WS
402 if ( value > till )
403 value = till;
8e08b761
JS
404}
405
406void wxToolWindow::AdjustRectPos( const wxRect& original, const wxSize& newDim, wxRect& newRect )
407{
c82c42d4
WS
408 if ( mCursorType == HITS_WND_TOP_EDGE ||
409 mCursorType == HITS_WND_TOP_LEFT_CORNER )
410 {
411 newRect.x = original.x + original.width - newDim.x;
412 newRect.y = original.y + original.height - newDim.y;
413 }
414 else
415 if ( mCursorType == HITS_WND_LEFT_EDGE ||
416 mCursorType == HITS_WND_BOTTOM_LEFT_CORNER )
417 {
418 newRect.x = original.x + original.width - newDim.x;
419 newRect.y = original.y;
420 }
421 else
422 if ( mCursorType == HITS_WND_RIGHT_EDGE ||
423 mCursorType == HITS_WND_TOP_RIGHT_CORNER )
424 {
425 newRect.x = original.x;
426 newRect.y = original.y + original.height - newDim.y;
427 }
428 else
429 if ( mCursorType == HITS_WND_BOTTOM_EDGE ||
430 mCursorType == HITS_WND_BOTTOM_RIGHT_CORNER )
431 {
432 newRect.x = original.x;
433 newRect.y = original.y;
434 }
435
436 newRect.width = newDim.x;
437 newRect.height = newDim.y;
8e08b761
JS
438}
439
440void wxToolWindow::CalcResizedRect( wxRect& rect, wxPoint& delta, const wxSize& minDim )
441{
c82c42d4
WS
442 // Microsoft's rect-coordinates are best suited
443 // for the case of corner-clipping
444
445 int left = mInitialRect.x;
446 int top = mInitialRect.y;
447 int right = mInitialRect.x + mInitialRect.width;
448 int bottom = mInitialRect.y + mInitialRect.height;
449
450 // constraint delta edge is dragged
451
452 switch ( mCursorType )
453 {
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;
458 default: break;
459 }
460
461 if ( mCursorType == HITS_WND_TOP_EDGE ||
462 mCursorType == HITS_WND_TOP_LEFT_CORNER )
463 {
464 left += delta.x;
465 top += delta.y;
466
467 clip_to( left, -INFINITY, mInitialRect.x + mInitialRect.width - minDim.x );
468 clip_to( top, -INFINITY, mInitialRect.y + mInitialRect.height - minDim.y );
469 }
470 else
471 if ( mCursorType == HITS_WND_LEFT_EDGE ||
472 mCursorType == HITS_WND_BOTTOM_LEFT_CORNER )
473 {
474 left += delta.x;
475 bottom += delta.y;
476
477 clip_to( left, -INFINITY, mInitialRect.x + mInitialRect.width - minDim.x );
478 clip_to( bottom, mInitialRect.y + minDim.y, INFINITY );
479 }
480 else
481 if ( mCursorType == HITS_WND_RIGHT_EDGE ||
482 mCursorType == HITS_WND_TOP_RIGHT_CORNER )
483 {
484 right += delta.x;
485 top += delta.y;
486
487 clip_to( right, mInitialRect.x + minDim.x, INFINITY );
488 clip_to( top, -INFINITY, mInitialRect.y + mInitialRect.height - minDim.y );
489 }
490 else
491 if ( mCursorType == HITS_WND_BOTTOM_EDGE ||
492 mCursorType == HITS_WND_BOTTOM_RIGHT_CORNER )
493 {
494 right += delta.x;
495 bottom += delta.y;
496
497 clip_to( right, mInitialRect.x + minDim.x, INFINITY );
498 clip_to( bottom, mInitialRect.y + minDim.y, INFINITY );
499 }
500 else
501 {
502 wxFAIL_MSG( _T("what did the cursor hit?") );
503 }
504
505 rect.x = left;
506 rect.y = top;
507 rect.width = right - left;
508 rect.height = bottom - top;
8e08b761
JS
509}
510
511wxSize wxToolWindow::GetMinimalWndDim()
512{
c82c42d4
WS
513 return wxSize( (mWndHorizGap + mClntHorizGap)*2 + BTN_BOX_WIDTH*4,
514 (mWndVertGap + mClntVertGap )*2 + mTitleHeight );
8e08b761
JS
515}
516
517void wxToolWindow::OnMotion( wxMouseEvent& event )
518{
c82c42d4
WS
519 if ( !mResizeStarted )
520 {
521 for( size_t i = 0; i != mButtons.Count(); ++i )
522 mButtons[i]->OnMotion( wxPoint( event.m_x, event.m_y ) );
8e08b761 523
c82c42d4
WS
524 SetHintCursor( HitTestWindow( event ) );
525 return;
526 }
8e08b761 527
c82c42d4
WS
528 wxPoint pos;
529 GetScrMousePos( event, pos );
8e08b761 530
c82c42d4
WS
531 if ( mCursorType == HITS_WND_TITLE )
532 {
533 int w,h;
534 GetSize( &w, &h );
8e08b761 535
c82c42d4
WS
536 SetSize( mInitialRect.x + pos.x - mDragOrigin.x,
537 mInitialRect.y + pos.y - mDragOrigin.y,
538 w,h, 0 );
539 }
8e08b761 540
c82c42d4
WS
541 else
542 {
543 wxPoint delta( pos.x - mDragOrigin.x, pos.y - mDragOrigin.y );
8e08b761 544
c82c42d4 545 wxRect newRect;
8e08b761 546
c82c42d4 547 wxSize minDim = GetMinimalWndDim();
8e08b761 548
c82c42d4 549 CalcResizedRect( newRect, delta, minDim );
8e08b761 550
c82c42d4
WS
551 wxSize borderDim( ( mWndHorizGap + mClntHorizGap )*2,
552 ( mWndVertGap + mClntVertGap )*2 + mTitleHeight );
8e08b761 553
c82c42d4
WS
554 wxSize preferred = GetPreferredSize( wxSize( newRect.width - borderDim.x,
555 newRect.height - borderDim.y ) );
8e08b761 556
c82c42d4
WS
557 preferred.x += borderDim.x;
558 preferred.y += borderDim.y;
8e08b761 559
c82c42d4 560 //CalcResizedRect( newRect, delta, preferred );
8e08b761 561
c82c42d4 562 wxRect finalRect = newRect;
8e08b761 563
c82c42d4 564 AdjustRectPos( newRect, preferred, finalRect );
8e08b761 565
c82c42d4
WS
566 if ( mRealTimeUpdatesOn )
567 {
568 SetSize( finalRect.x, finalRect.y,
569 finalRect.width, finalRect.height, 0 );
570 }
571 else
572 {
573 DrawHintRect( mPrevHintRect );
574 DrawHintRect( finalRect );
879da8c8 575
5feef956 576 ::wxLogTrace(wxT("wxToolWindow"),wxT("%d,%d / %d,%d\n"), finalRect.x, finalRect.y, finalRect.width, finalRect.height);
c82c42d4 577 }
8e08b761 578
c82c42d4
WS
579 mPrevHintRect = finalRect;
580 }
8e08b761
JS
581}
582
583void wxToolWindow::OnLeftDown( wxMouseEvent& event )
584{
c82c42d4 585 int result = HitTestWindow( event );
8e08b761 586
c82c42d4
WS
587 for( size_t i = 0; i != mButtons.Count(); ++i )
588 {
589 mButtons[i]->OnLeftDown( wxPoint( event.m_x, event.m_y ) );
8e08b761 590
c82c42d4
WS
591 if ( mButtons[i]->IsPressed() )
592 return; // button hitted,
593 }
8e08b761 594
c82c42d4
WS
595 if ( result >= HITS_WND_LEFT_EDGE || result == HITS_WND_TITLE )
596 {
597 GetScrMousePos( event, mDragOrigin );
8e08b761 598
c82c42d4
WS
599 /*
600 if ( mMouseCaptured `)
601 {
602 ReleaseMouse();
603 mMouseCaptured = false;
604 }*/
8e08b761 605
c82c42d4
WS
606 if ( result == HITS_WND_TITLE &&
607 HandleTitleClick( event ) )
608 return;
8e08b761 609
c82c42d4 610 mResizeStarted = true;
8e08b761 611
c82c42d4
WS
612 int x,y;
613 GetPosition( &x, &y );
8e08b761 614
c82c42d4
WS
615 mInitialRect.x = x;
616 mInitialRect.y = y;
8e08b761 617
c82c42d4
WS
618 GetSize( &x, &y );
619 mInitialRect.width = x;
620 mInitialRect.height = y;
8e08b761 621
c82c42d4 622 mPrevHintRect = mInitialRect;
8e08b761 623
c82c42d4
WS
624 if ( mCursorType != HITS_WND_TITLE && !mRealTimeUpdatesOn )
625 {
626 mpScrDc = new wxScreenDC();
8e08b761 627
c82c42d4 628 wxScreenDC::StartDrawingOnTop( (wxRect*)NULL );
8e08b761 629
c82c42d4
WS
630 DrawHintRect( mInitialRect );
631 }
632 }
8e08b761
JS
633}
634
635void wxToolWindow::OnLeftUp( wxMouseEvent& event )
636{
c82c42d4
WS
637 for( size_t i = 0; i != mButtons.Count(); ++i )
638 {
639 mButtons[i]->OnLeftUp( wxPoint( event.m_x, event.m_y ) );
640
641 if ( mButtons[i]->WasClicked() )
642 {
643 OnMiniButtonClicked( i ); // notify derived classes
644 mButtons[i]->Reset();
645 }
646 }
647
648 if ( mResizeStarted )
649 {
650 mResizeStarted = false;
651
652 if ( mCursorType != HITS_WND_TITLE )
653 {
654 if ( !mRealTimeUpdatesOn )
655 {
656 DrawHintRect( mPrevHintRect );
657
658 wxScreenDC::EndDrawingOnTop();
659
660 delete mpScrDc;
661
662 mpScrDc = NULL;
663
664 SetSize( mPrevHintRect.x, mPrevHintRect.y,
665 mPrevHintRect.width, mPrevHintRect.height, 0 );
666 }
667 }
668 }
8e08b761
JS
669}
670
196be0f1 671void wxToolWindow::OnSize( wxSizeEvent& WXUNUSED(event) )
8e08b761 672{
c82c42d4
WS
673 if ( mpClientWnd )
674 {
675 int w,h;
676 GetSize( &w, &h );
8e08b761 677
c82c42d4
WS
678 int x = mWndHorizGap + mClntHorizGap;
679 int y = mWndVertGap + mTitleHeight + mClntVertGap;
8e08b761 680
8e33234f
GT
681 mpClientWnd->SetSize( x-1, y-1,
682 w - 2*(mWndHorizGap + mClntHorizGap),
683 h - y - mClntVertGap - mWndVertGap,
684 0
685 );
686 }
8e08b761 687
c82c42d4 688 LayoutMiniButtons();
8e08b761
JS
689}
690
691wxSize wxToolWindow::GetPreferredSize( const wxSize& given )
692{
c82c42d4 693 return given;
8e08b761
JS
694}
695
196be0f1 696void wxToolWindow::OnEraseBackground( wxEraseEvent& WXUNUSED(event) )
8e08b761 697{
c82c42d4 698 // nothing
8e08b761
JS
699}
700
701/***** Implementation for class cbMiniButton *****/
702
703cbMiniButton::cbMiniButton()
704
c82c42d4
WS
705 : mVisible( true ),
706 mEnabled( true ),
8e08b761 707
c82c42d4
WS
708 mpLayout( NULL ),
709 mpPane ( NULL ),
710 mpPlugin( NULL ),
711 mpWnd ( NULL ),
8e08b761 712
c82c42d4
WS
713 mWasClicked( false ),
714 mDragStarted( false ),
715 mPressed( false )
8e08b761
JS
716{}
717
718void cbMiniButton::SetPos( const wxPoint& pos )
719{
c82c42d4 720 mPos = pos;
8e08b761
JS
721}
722
723bool cbMiniButton::HitTest( const wxPoint& pos )
724{
c82c42d4 725 if ( !mVisible ) return false;
8e08b761 726
c82c42d4
WS
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 );
8e08b761
JS
730}
731
732void cbMiniButton::OnLeftDown( const wxPoint& pos )
733{
c82c42d4
WS
734 if ( !mVisible || mDragStarted ) return;
735
736 if ( HitTest( pos ) && mEnabled )
737 {
738 if ( mpPlugin )
739 {
740 mpLayout->CaptureEventsForPane( mpPane );
741 mpLayout->CaptureEventsForPlugin( mpPlugin );
742 }
743 else
744 mpWnd->CaptureMouse();
745
746 mDragStarted = true;
747 mPressed = true;
748 mWasClicked = false;
749
750 Refresh();
751 }
8e08b761
JS
752}
753
196be0f1 754void cbMiniButton::OnLeftUp( const wxPoint& WXUNUSED(pos) )
8e08b761 755{
c82c42d4 756 if ( !mVisible || !mDragStarted ) return;
8e08b761 757
c82c42d4
WS
758 if ( mpPlugin )
759 {
760 mpLayout->ReleaseEventsFromPane( mpPane );
761 mpLayout->ReleaseEventsFromPlugin( mpPlugin );
762 }
763 else
764 mpWnd->ReleaseMouse();
8e08b761 765
c82c42d4
WS
766 mWasClicked = mPressed;
767 mDragStarted = false;
8e08b761 768
c82c42d4
WS
769 mPressed = false;
770 Refresh();
8e08b761
JS
771}
772
773void cbMiniButton::OnMotion( const wxPoint& pos )
774{
c82c42d4 775 if ( !mVisible ) return;
8e08b761 776
c82c42d4
WS
777 if ( mDragStarted )
778 {
779 mPressed = HitTest( pos );
8e08b761 780
c82c42d4
WS
781 Refresh();
782 }
8e08b761
JS
783}
784
785void cbMiniButton::Refresh()
786{
c82c42d4
WS
787 if ( mpLayout )
788 {
789 wxClientDC dc( &mpLayout->GetParentFrame() );
790
791 Draw( dc );
792 }
793 else
794 {
795 wxWindowDC dc( mpWnd );
796
797 Draw( dc );
798 }
8e08b761
JS
799}
800
801void cbMiniButton::Draw( wxDC& dc )
802{
c82c42d4 803 if ( !mVisible ) return;
8e08b761 804
c82c42d4 805 dc.SetPen( *wxTRANSPARENT_PEN );
8e08b761 806
c82c42d4 807 dc.SetBrush( *wxLIGHT_GREY_BRUSH );
8e08b761 808
c82c42d4 809 dc.DrawRectangle( mPos.x + 1, mPos.y + 1, BTN_BOX_WIDTH - 2, BTN_BOX_HEIGHT - 2 );
8e08b761 810
c82c42d4 811 // "hard-code" metafile
8e08b761 812
c82c42d4
WS
813 if ( !mPressed )
814 dc.SetPen( *wxWHITE_PEN );
815 else
816 dc.SetPen( *wxBLACK_PEN );
8e08b761 817
c82c42d4
WS
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 );
8e08b761 820
c82c42d4 821 dc.SetPen( *wxGREY_PEN );
8e08b761 822
c82c42d4
WS
823 if ( !mPressed )
824 {
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 );
8e08b761 827
c82c42d4
WS
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 );
830 }
831 else
832 {
833 dc.DrawLine( mPos.x + 1, mPos.y + 1,
834 mPos.x + BTN_BOX_WIDTH - 2, mPos.y + 1 );
8e08b761 835
c82c42d4
WS
836 dc.DrawLine( mPos.x + 1, mPos.y + 1,
837 mPos.x + 1, mPos.y + BTN_BOX_HEIGHT - 2 );
838 }
8e08b761 839
c82c42d4
WS
840 if ( !mPressed )
841 dc.SetPen( *wxBLACK_PEN );
842 else
843 dc.SetPen( *wxWHITE_PEN );
8e08b761 844
c82c42d4
WS
845 dc.DrawLine( mPos.x, mPos.y + BTN_BOX_HEIGHT - 1,
846 mPos.x + BTN_BOX_WIDTH, mPos.y + BTN_BOX_HEIGHT - 1 );
8e08b761 847
c82c42d4
WS
848 dc.DrawLine( mPos.x + BTN_BOX_WIDTH - 1, mPos.y ,
849 mPos.x + BTN_BOX_WIDTH - 1, mPos.y + BTN_BOX_HEIGHT );
8e08b761
JS
850}
851
852bool cbMiniButton::WasClicked()
853{
c82c42d4 854 return mWasClicked;
8e08b761
JS
855}
856
857void cbMiniButton::Reset()
858{
c82c42d4 859 mWasClicked = false;
8e08b761
JS
860}
861
862/***** Implementation fro class cbCloseBox *****/
863
864void cbCloseBox::Draw( wxDC& dc )
865{
618f2efa 866#if defined(__WXGTK__) || defined(__WXX11__)
8e08b761
JS
867
868 cbMiniButton::Draw( dc );
869
870 wxPen pen( wxColour( 64,64,64 ) ,1, wxSOLID );
871
872 dc.SetPen( pen );
873
874 int width = BTN_BOX_WIDTH - 7;
875
876 int xOfs = (mPressed) ? 4 : 3;
c82c42d4 877 int yOfs = (mPressed) ? 4 : 3;
8e08b761
JS
878
879 int one = 1;
880 for( int i = 0; i != BTN_X_WIEGHT; ++i )
881 {
882 dc.DrawLine( mPos.x + xOfs + i - one,
883 mPos.y + yOfs - one,
884 mPos.x + xOfs + i + width,
885 mPos.y + yOfs + width + one);
886
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 );
891 }
892
893#else
894
c82c42d4 895 cbMiniButton::Draw( dc );
8e08b761 896
c82c42d4 897 dc.SetPen( *wxBLACK_PEN );
8e08b761 898
c82c42d4 899 int width = BTN_BOX_WIDTH - 7;
8e08b761 900
c82c42d4
WS
901 int xOfs = (mPressed) ? 4 : 3;
902 int yOfs = (mPressed) ? 4 : 3;
8e08b761 903
c82c42d4
WS
904 for( int i = 0; i != BTN_X_WIEGHT; ++i )
905 {
906 dc.DrawLine( mPos.x + xOfs + i,
907 mPos.y + yOfs,
908 mPos.x + xOfs + i + width,
909 mPos.y + yOfs + width );
8e08b761 910
c82c42d4
WS
911 dc.DrawLine( mPos.x + xOfs + i + width - 1,
912 mPos.y + yOfs,
913 mPos.x + xOfs + i - 1,
914 mPos.y + yOfs + width );
915 }
8e08b761
JS
916
917#endif
918
919}
920
921/***** Implementation fro class cbCollapseBox *****/
922
923inline static void my_swap( int& a, int& b )
924{
c82c42d4
WS
925 long tmp = a;
926 a = b;
927 b = tmp;
8e08b761
JS
928}
929
930void cbCollapseBox::Draw( wxDC& dc )
931{
c82c42d4 932 cbMiniButton::Draw( dc );
8e08b761 933
c82c42d4 934 dc.SetPen( *wxTRANSPARENT_PEN );
8e08b761 935
c82c42d4 936 wxPoint arr[3];
8e08b761 937
c82c42d4
WS
938 int yOfs = (mPressed) ? 3 : 2;
939 int xOfs = (mPressed) ? 5 : 4;
940 int width = BTN_BOX_WIDTH - 8;
8e08b761 941
c82c42d4 942 // rotating/shifting triangle inside collapse box
8e08b761 943
c82c42d4
WS
944 arr[0].x = xOfs;
945 arr[0].y = yOfs-1;
946 arr[2].x = xOfs;
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;
8e08b761 950
c82c42d4
WS
951 if ( !mIsAtLeft )
952 {
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;
956 }
8e08b761 957
c82c42d4
WS
958 if ( !mpPane->IsHorizontal() )
959 {
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 );
8e08b761 963
c82c42d4
WS
964 arr[0].x += 1;
965 arr[1].x += 1;
966 arr[2].x += 1;
8e08b761 967
c82c42d4
WS
968 //arr[1].y -= 1;
969 }
8e08b761 970
c82c42d4
WS
971 arr[0].x += mPos.x;
972 arr[0].y += mPos.y;
973 arr[1].x += mPos.x;
974 arr[1].y += mPos.y;
975 arr[2].x += mPos.x;
976 arr[2].y += mPos.y;
8e08b761 977
c82c42d4
WS
978 if ( !mEnabled ) dc.SetBrush( *wxGREY_BRUSH );
979 else dc.SetBrush( *wxBLACK_BRUSH );
8e08b761 980
c82c42d4
WS
981 dc.DrawPolygon( 3, arr );
982 dc.SetBrush( wxNullBrush );
8e08b761
JS
983}
984
985/***** Implementation for class cbDockBoxBox *****/
986
987void cbDockBox::Draw( wxDC& dc )
988{
c82c42d4 989 cbMiniButton::Draw( dc );
8e08b761 990
c82c42d4 991 int width = BTN_BOX_WIDTH - 7;
8e08b761 992
c82c42d4
WS
993 int xOfs = (mPressed) ? 4 : 3;
994 int yOfs = (mPressed) ? 4 : 3;
8e08b761 995
c82c42d4
WS
996 dc.SetPen( *wxBLACK_PEN );
997 dc.SetBrush( *wxBLACK_BRUSH );
8e08b761 998
c82c42d4 999 dc.DrawRectangle( mPos.x + xOfs, mPos.y + yOfs, width, width );
8e08b761 1000
c82c42d4
WS
1001 xOfs += 1;
1002 yOfs += 1;
8e08b761 1003
c82c42d4 1004 dc.SetBrush( *wxWHITE_BRUSH );
8e08b761 1005
c82c42d4 1006 dc.DrawRectangle( mPos.x + xOfs, mPos.y + yOfs, width-2, width-2 );
8e08b761
JS
1007}
1008
1009/***** Implementation for class wxToolWindow *****/
1010
1011IMPLEMENT_DYNAMIC_CLASS( cbFloatedBarWindow, wxToolWindow )
1012
1013BEGIN_EVENT_TABLE( cbFloatedBarWindow, wxToolWindow )
1014
c82c42d4 1015 EVT_LEFT_DCLICK( cbFloatedBarWindow::OnDblClick )
8e08b761
JS
1016
1017END_EVENT_TABLE()
1018
1019cbFloatedBarWindow::cbFloatedBarWindow()
1020
c82c42d4 1021 : mpBar( NULL )
8e08b761 1022{
c82c42d4
WS
1023 AddMiniButton( new cbCloseBox() );
1024 AddMiniButton( new cbDockBox() );
8e08b761
JS
1025}
1026
1027void cbFloatedBarWindow::SetBar( cbBarInfo* pBar )
1028{
c82c42d4 1029 mpBar = pBar;
8e08b761
JS
1030}
1031
1032cbBarInfo* cbFloatedBarWindow::GetBar()
1033{
c82c42d4 1034 return mpBar;
8e08b761
JS
1035}
1036
1037void cbFloatedBarWindow::SetLayout( wxFrameLayout* pLayout )
1038{
c82c42d4 1039 mpLayout = pLayout;
8e08b761
JS
1040}
1041
1042void cbFloatedBarWindow::PositionFloatedWnd( int scrX, int scrY,
c82c42d4 1043 int width, int height )
8e08b761 1044{
c82c42d4 1045 wxSize minDim = GetMinimalWndDim();
8e08b761 1046
c82c42d4
WS
1047 SetSize( scrX - mWndHorizGap - mClntHorizGap,
1048 scrY - mClntVertGap - mTitleHeight - mWndVertGap,
1049 width + minDim.x, height + minDim.y, 0 );
8e08b761
JS
1050}
1051
1052wxSize cbFloatedBarWindow::GetPreferredSize( const wxSize& given )
1053{
c82c42d4
WS
1054 if ( mpBar->mDimInfo.GetDimHandler() )
1055 {
1056 cbBarDimHandlerBase* pHandler = mpBar->mDimInfo.GetDimHandler();
8e08b761 1057
c82c42d4 1058 wxSize prefDim;
8e08b761 1059
c82c42d4 1060 // int vtad = *((int*)pHandler);
8e08b761 1061
c82c42d4 1062 pHandler->OnResizeBar( mpBar, given, prefDim );
8e08b761 1063
c82c42d4
WS
1064 return prefDim;
1065 }
1066 else
1067 {
1068 if ( mpBar->IsFixed() )
1069 return mpBar->mDimInfo.mSizes[ wxCBAR_FLOATING ];
1070 else
1071 return given; // not-fixed bars are resized exactly the way user wants
1072 }
8e08b761
JS
1073}
1074
1075void cbFloatedBarWindow::OnMiniButtonClicked( int btnIdx )
1076{
c82c42d4
WS
1077 // #1 - close mini-button
1078 // #0 - dock mini-button
1079
1080 if ( btnIdx == 0 )
1081 {
1082 mpBar->mAlignment = -1; // sepcial "marking" for hidden bars out of floated state
1083 mpLayout->SetBarState( mpBar, wxCBAR_HIDDEN, true );
1084 }
1085 else
1086 mpLayout->SetBarState( mpBar, wxCBAR_DOCKED_HORIZONTALLY, true );
8e08b761
JS
1087}
1088
1089bool cbFloatedBarWindow::HandleTitleClick( wxMouseEvent& event )
1090{
c82c42d4
WS
1091 ReleaseMouse();
1092 mMouseCaptured = false;
1093
1094 wxPoint scrPos;
1095 GetScrMousePos( event, scrPos );
8e08b761 1096
c82c42d4
WS
1097 int msX = scrPos.x,
1098 msY = scrPos.y;
8e08b761 1099
c82c42d4 1100 mpLayout->GetParentFrame().ScreenToClient( &msX, &msY );
8e08b761 1101
c82c42d4
WS
1102 int x,y;
1103 GetPosition(&x,&y);
1104 int w,h;
1105 GetSize( &w, &h );
8e08b761 1106
c82c42d4 1107 wxSize minDim = GetMinimalWndDim();
8e08b761 1108
c82c42d4
WS
1109 w -= minDim.x;
1110 h -= minDim.y;
8e08b761 1111
c82c42d4
WS
1112 x += mWndHorizGap + mClntHorizGap;
1113 y += mWndVertGap + mTitleHeight + mClntVertGap;
8e08b761 1114
c82c42d4 1115 mpLayout->GetParentFrame().ScreenToClient( &x, &y );
8e08b761 1116
c82c42d4 1117 wxRect& bounds = mpBar->mDimInfo.mBounds[ wxCBAR_FLOATING ];
8e08b761 1118
c82c42d4
WS
1119 bounds.x = x;
1120 bounds.y = y;
1121 bounds.width = w;
1122 bounds.height = h;
8e08b761 1123
c82c42d4
WS
1124 cbStartBarDraggingEvent dragEvt( mpBar, wxPoint(msX,msY),
1125 mpLayout->GetPanesArray()[FL_ALIGN_TOP] );
8e08b761 1126
c82c42d4 1127 mpLayout->FirePluginEvent( dragEvt );
8e08b761 1128
c82c42d4 1129 return true;
8e08b761
JS
1130}
1131
196be0f1 1132void cbFloatedBarWindow::OnDblClick( wxMouseEvent& WXUNUSED(event) )
8e08b761 1133{
c82c42d4 1134 mpLayout->SetBarState( mpBar, wxCBAR_DOCKED_HORIZONTALLY, true );
8e08b761 1135
c82c42d4 1136 //wxMessageBox("toolWnd - dblClick!");
8e08b761
JS
1137}
1138