]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/fl/newbmpbtn.cpp
Added MSW toplevel.cpp and regenerated makefiles and such.
[wxWidgets.git] / contrib / src / fl / newbmpbtn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: No names yet.
3 // Purpose: Contrib. demo
4 // Author: Aleksandras Gluchovas
5 // Modified by:
6 // Created: ??/09/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Aleksandras Gluchovas
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "newbmpbtn.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx/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/newbmpbtn.h"
28 #include "wx/utils.h" // import wxMin,wxMax macros
29
30 ///////////// button-label rendering helpers //////////////////
31
32 static int* create_array( int width, int height, int fill = 0 )
33 {
34 int* array = new int[width*height];
35
36 int len = width*height;
37 for( int i = 0; i != len; ++i ) array[i] = fill;
38
39 return array;
40 }
41
42 #define GET_ELEM(array,x,y) (array[width*(y)+(x)])
43
44 #define MIN_COLOR_DIFF 10
45
46 #define IS_IN_ARRAY(x,y) ( (x) < width && (y) < height && (x) >= 0 && (y) >= 0 )
47
48 #define GET_RED(col) col & 0xFF
49 #define GET_GREEN(col) (col >> 8) & 0xFF
50 #define GET_BLUE(col) (col >> 16) & 0xFF
51
52 #define MAKE_INT_COLOR(red,green,blue) ( (red) | \
53 ( ( (green) << 8 ) & 0xFF00 ) | \
54 ( ( (blue) << 16) & 0xFF0000) \
55 )
56
57 #define IS_GREATER(col1,col2) ( ( (GET_RED(col1) ) > (GET_RED(col2) ) + MIN_COLOR_DIFF ) && \
58 ( (GET_GREEN(col1)) > (GET_GREEN(col2)) + MIN_COLOR_DIFF ) && \
59 ( (GET_BLUE(col1) ) > (GET_BLUE(col2) ) + MIN_COLOR_DIFF ) \
60 )
61
62 #define MASK_BG 0
63 #define MASK_DARK 1
64 #define MASK_LIGHT 2
65
66 // helper function, used internally
67
68 static void gray_out_pixmap( int* src, int* dest, int width, int height )
69 {
70 // assuming the pixels along the edges are of the background color
71
72 int x = 0;
73 int y = 1;
74
75 do
76 {
77 int cur = GET_ELEM(src,x,y);
78
79
80 if ( IS_IN_ARRAY(x-1,y-1) )
81 {
82 int upperElem = GET_ELEM(src,x-1,y-1);
83
84 // if the upper element is lighter than current
85 if ( IS_GREATER(upperElem,cur) )
86 {
87 GET_ELEM(dest,x,y) = MASK_DARK;
88 }
89 else
90 // if the current element is ligher than the upper
91 if ( IS_GREATER(cur,upperElem) )
92 {
93 GET_ELEM(dest,x,y) = MASK_LIGHT;
94 }
95 else
96 {
97 if ( GET_ELEM(dest,x-1,y-1) == MASK_LIGHT )
98
99 GET_ELEM(dest,x,y) = MASK_BG;
100
101 if ( GET_ELEM(dest,x-1,y-1 ) == MASK_DARK )
102
103 GET_ELEM(dest,x,y) = MASK_DARK;
104 else
105 GET_ELEM(dest,x,y) = MASK_BG;
106 }
107 }
108
109 // go zig-zag
110
111 if ( IS_IN_ARRAY(x+1,y-1) )
112 {
113 ++x;--y;
114 }
115 else
116 {
117 while( IS_IN_ARRAY(x-1,y+1) )
118 {
119 --x;++y;
120 }
121
122 if ( IS_IN_ARRAY(x,y+1) )
123 {
124 ++y; continue;
125 }
126 else
127 {
128 if ( IS_IN_ARRAY(x+1,y) )
129 {
130 ++x; continue;
131 }
132 else break;
133 }
134 }
135
136 } while(1);
137 }
138
139 // alg. for making the image look "grayed" (e.g. disabled button)
140 // NOTE:: used GetPixel(), which is Windows-Only!
141
142 void gray_out_image_on_dc( wxDC& dc, int width, int height )
143 {
144 // assuming the pixels along the edges are of the background color
145 wxColour bgCol;
146 dc.GetPixel( 0, 0, &bgCol );
147
148 wxPen darkPen ( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DSHADOW),1, wxSOLID );
149 wxPen lightPen( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DHIGHLIGHT),1, wxSOLID );
150 wxPen bgPen ( bgCol, 1, wxSOLID );
151
152 int* src = create_array( width, height, MASK_BG );
153 int* dest = create_array( width, height, MASK_BG );
154
155 int y = 0;
156 for( y = 0; y != height; ++y )
157
158 for( int x = 0; x != width; ++x )
159 {
160 wxColour col;
161 dc.GetPixel( x,y, &col );
162
163
164 GET_ELEM(src,x,y) = MAKE_INT_COLOR( col.Red(), col.Green(), col.Blue() );
165 }
166
167 gray_out_pixmap( src, dest, width, height );
168
169 for( y = 0; y != height; ++y )
170
171 for( int x = 0; x != width; ++x )
172 {
173 int mask = GET_ELEM(dest,x,y);
174
175 switch (mask)
176 {
177 case MASK_BG : { dc.SetPen( bgPen );
178 dc.DrawPoint( x,y ); break;
179 }
180 case MASK_DARK : { dc.SetPen( darkPen );
181 dc.DrawPoint( x,y ); break;
182 }
183 case MASK_LIGHT : { dc.SetPen( lightPen );
184 dc.DrawPoint( x,y ); break;
185 }
186 default : break;
187 }
188 }
189
190 delete [] src;
191 delete [] dest;
192 }
193
194 ///////////////////////////////
195
196 /***** Impelementation for class wxNewBitmapButton *****/
197
198 IMPLEMENT_DYNAMIC_CLASS(wxNewBitmapButton, wxPanel)
199
200 BEGIN_EVENT_TABLE( wxNewBitmapButton, wxPanel )
201
202 EVT_LEFT_DOWN( wxNewBitmapButton::OnLButtonDown )
203 EVT_LEFT_UP ( wxNewBitmapButton::OnLButtonUp )
204 EVT_MOTION ( wxNewBitmapButton::OnMouseMove )
205
206 EVT_SIZE ( wxNewBitmapButton::OnSize )
207 EVT_PAINT( wxNewBitmapButton::OnPaint )
208
209 //EVT_KILL_FOCUS( wxNewBitmapButton::OnKillFocus )
210
211 EVT_ERASE_BACKGROUND( wxNewBitmapButton::OnEraseBackground )
212
213 END_EVENT_TABLE()
214
215 wxNewBitmapButton::wxNewBitmapButton( const wxBitmap& labelBitmap,
216 const wxString& labelText,
217 int alignText,
218 bool isFlat,
219 int firedEventType,
220 int marginX,
221 int marginY,
222 int textToLabelGap,
223 bool isSticky)
224 : mTextToLabelGap ( textToLabelGap ),
225 mMarginX( marginX ),
226 mMarginY( marginY ),
227 mTextAlignment( alignText ),
228 mIsSticky( isSticky ),
229 mIsFlat( isFlat ),
230 mLabelText( labelText ),
231 mImageFileType( wxBITMAP_TYPE_INVALID ),
232 mDepressedBmp( labelBitmap ),
233
234 mpDepressedImg( NULL ),
235 mpPressedImg ( NULL ),
236 mpDisabledImg ( NULL ),
237 mpFocusedImg ( NULL ),
238
239
240 mDragStarted ( FALSE ),
241 mIsPressed ( FALSE ),
242 mIsInFocus( FALSE ),
243 mPrevPressedState( FALSE ),
244 mPrevInFocusState( FALSE ),
245 mHasFocusedBmp( FALSE ),
246 mFiredEventType( firedEventType ),
247
248 mBlackPen( wxColour( 0, 0, 0), 1, wxSOLID ),
249 mDarkPen ( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DSHADOW), 1, wxSOLID ),
250 mGrayPen ( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE), 1, wxSOLID ),
251 mLightPen( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DHIGHLIGHT), 1, wxSOLID ),
252
253 mIsCreated( FALSE ),
254 mSizeIsSet( FALSE )
255
256 {
257 }
258
259 wxNewBitmapButton::wxNewBitmapButton( const wxString& bitmapFileName,
260 const wxBitmapType bitmapFileType,
261 const wxString& labelText,
262 int alignText,
263 bool isFlat,
264 int firedEventType,
265 int marginX,
266 int marginY,
267 int textToLabelGap,
268 bool isSticky)
269
270 : mTextToLabelGap ( 2 ),
271 mMarginX( 2 ),
272 mMarginY( 2 ),
273 mTextAlignment( alignText ),
274 mIsSticky( FALSE ),
275 mIsFlat( isFlat ),
276 mLabelText( labelText ),
277 mImageFileName( bitmapFileName ),
278 mImageFileType( bitmapFileType ),
279
280 mpDepressedImg( NULL ),
281 mpPressedImg ( NULL ),
282 mpDisabledImg ( NULL ),
283 mpFocusedImg ( NULL ),
284
285 mDragStarted ( FALSE ),
286 mIsPressed ( FALSE ),
287 mIsInFocus ( FALSE ),
288 mPrevPressedState( FALSE ),
289 mPrevInFocusState( FALSE ),
290 mHasFocusedBmp( FALSE ),
291 mFiredEventType( wxEVT_COMMAND_MENU_SELECTED ),
292
293 mBlackPen( wxColour( 0, 0, 0), 1, wxSOLID ),
294 mDarkPen ( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DSHADOW), 1, wxSOLID ),
295 mGrayPen ( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE), 1, wxSOLID ),
296 mLightPen( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DHIGHLIGHT), 1, wxSOLID ),
297
298 mIsCreated( FALSE ),
299 mSizeIsSet( FALSE )
300
301 {
302 }
303
304 wxNewBitmapButton::~wxNewBitmapButton(void)
305 {
306 DestroyLabels();
307 }
308
309 void wxNewBitmapButton::DrawShade( int outerLevel,
310 wxDC& dc,
311 wxPen& upperLeftSidePen,
312 wxPen& lowerRightSidePen )
313 {
314 wxBitmap* pBmp = GetStateLabel();
315
316 int x = mMarginX - (outerLevel + 1);
317 int y = mMarginY - (outerLevel + 1);
318
319 int height = pBmp->GetHeight() + (outerLevel + 1)*2 - 1;
320 int width = pBmp->GetWidth() + (outerLevel + 1)*2 - 1;
321
322 dc.SetPen( upperLeftSidePen );
323 dc.DrawLine( x,y, x + width, y );
324 dc.DrawLine( x,y, x, y + height );
325
326 dc.SetPen( lowerRightSidePen );
327 dc.DrawLine( x + width, y, x + width, y + height + 1 );
328 dc.DrawLine( x, y + height, x + width, y + height );
329 }
330
331 void wxNewBitmapButton::DestroyLabels()
332 {
333 if ( mpDepressedImg ) delete mpDepressedImg;
334 if ( mpPressedImg ) delete mpPressedImg;
335 if ( mpDisabledImg ) delete mpDisabledImg;
336 if ( mpFocusedImg ) delete mpFocusedImg;
337
338 mpDepressedImg = NULL;
339 mpPressedImg = NULL;
340 mpDisabledImg = NULL;
341 mpFocusedImg = NULL;
342 }
343
344 wxBitmap* wxNewBitmapButton::GetStateLabel()
345 {
346 if ( IsEnabled() )
347 {
348 if ( mIsPressed )
349 {
350 return mpPressedImg;
351 }
352 else
353 {
354 if ( mIsInFocus )
355 {
356 if ( mHasFocusedBmp )
357
358 return mpFocusedImg;
359 else
360 return mpDepressedImg;
361 }
362 else
363 return mpDepressedImg;
364 }
365 }
366 else
367 return mpDisabledImg;
368 }
369
370 static const unsigned char _gDisableImage[] = { 0x55,0xAA,0x55,0xAA,
371 0x55,0xAA,0x55,0xAA,
372 0x55,0xAA,0x55,0xAA,
373 0x55,0xAA,0x55,0xAA
374 };
375 void wxNewBitmapButton::RenderLabelImage( wxBitmap*& destBmp, wxBitmap* srcBmp,
376 bool isEnabled, bool isPressed )
377 {
378 if ( destBmp != 0 ) return;
379
380 // render lables on-demand
381
382 wxMemoryDC srcDc;
383 srcDc.SelectObject( *srcBmp );
384
385 bool hasText = ( mTextAlignment != NB_NO_TEXT ) &&
386 ( mLabelText.length() != 0 );
387
388 bool hasImage = (mTextAlignment != NB_NO_IMAGE);
389
390 wxSize destDim;
391 wxPoint txtPos;
392 wxPoint imgPos;
393
394 if ( hasText )
395 {
396 long txtWidth, txtHeight;
397
398 srcDc.SetFont( wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT) );
399 srcDc.GetTextExtent( mLabelText, &txtWidth, &txtHeight );
400
401 if ( mTextAlignment == NB_ALIGN_TEXT_RIGHT )
402 {
403 destDim.x = srcBmp->GetWidth() + 2*mTextToLabelGap + txtWidth;
404
405 destDim.y =
406 wxMax( srcBmp->GetHeight(), txtHeight );
407
408 txtPos.x = srcBmp->GetWidth() + mTextToLabelGap;
409 txtPos.y = (destDim.y - txtHeight)/2;
410 imgPos.x = 0;
411 imgPos.y = (destDim.y - srcBmp->GetHeight())/2;
412 }
413 else
414 if ( mTextAlignment == NB_ALIGN_TEXT_BOTTOM )
415 {
416 destDim.x =
417 wxMax( srcBmp->GetWidth(), txtWidth );
418
419 destDim.y = srcBmp->GetHeight() + mTextToLabelGap + txtHeight;
420
421 txtPos.x = (destDim.x - txtWidth)/2;
422 txtPos.y = srcBmp->GetHeight() + mTextToLabelGap;
423 imgPos.x = (destDim.x - srcBmp->GetWidth())/2;
424 imgPos.y = 0;
425 }
426 else
427 {
428 int avoidCompilerWarning = 0;
429 wxASSERT(avoidCompilerWarning);// unsupported alignment type
430 }
431 }
432 else
433 {
434 imgPos.x = 0;
435 imgPos.y = 0;
436 destDim.x = srcBmp->GetWidth();
437 destDim.y = srcBmp->GetHeight();
438 }
439
440 destBmp = new wxBitmap( int(destDim.x), int(destDim.y) );
441
442 wxMemoryDC destDc;
443 destDc.SelectObject( *destBmp );
444
445 wxBrush grayBrush( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE), wxSOLID );
446 wxPen nullPen( wxColour(0,0,0), 1, wxTRANSPARENT );
447
448 destDc.SetBrush( grayBrush );
449 destDc.SetPen( nullPen );
450
451 destDc.DrawRectangle( 0,0, destDim.x+1, destDim.y+1 );
452
453 if ( isPressed )
454 {
455 ++imgPos.x; ++imgPos.y;
456 ++txtPos.x; ++txtPos.y;
457 }
458
459 if ( hasImage )
460 {
461
462 destDc.Blit( imgPos.x, imgPos.y,
463 srcBmp->GetWidth()+1,
464 srcBmp->GetHeight()+1,
465 &srcDc, 0,0, wxCOPY,TRUE );
466 }
467
468 if ( hasText )
469 {
470 wxWindow* pTopWnd = this;
471
472 do
473 {
474 wxWindow* pParent = pTopWnd->GetParent();
475
476 if ( pParent == 0 )
477 break;
478
479 pTopWnd = pParent;
480 } while(1);
481
482 destDc.SetFont( wxSystemSettings::GetSystemFont( wxSYS_DEFAULT_GUI_FONT) );
483
484 if ( isEnabled )
485 {
486 destDc.SetTextForeground( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_BTNTEXT) );
487 }
488 else
489 {
490 destDc.SetTextForeground( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DSHADOW) );
491 }
492 destDc.SetTextBackground( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_BTNFACE) );
493
494 destDc.DrawText( mLabelText, txtPos.x, txtPos.y );
495 }
496
497
498 destDc.SetBrush( grayBrush );
499 destDc.SetPen( nullPen );
500
501 destDc.DrawRectangle( 0,0, destDim.x+1, destDim.y+1 );
502
503 if ( isPressed )
504 {
505 ++imgPos.x; ++imgPos.y;
506 ++txtPos.x; ++txtPos.y;
507 }
508
509 if ( hasImage )
510 {
511
512 destDc.Blit( imgPos.x, imgPos.y,
513 srcBmp->GetWidth()+1,
514 srcBmp->GetHeight()+1,
515 &srcDc, 0,0, wxCOPY,TRUE );
516 }
517
518 if ( hasText )
519 {
520 wxWindow* pTopWnd = this;
521
522 do
523 {
524 wxWindow* pParent = pTopWnd->GetParent();
525
526 if ( pParent == 0 )
527 break;
528
529 pTopWnd = pParent;
530 } while(1);
531
532 destDc.SetFont( wxSystemSettings::GetSystemFont( wxSYS_DEFAULT_GUI_FONT) );
533
534 if ( isEnabled )
535 {
536 destDc.SetTextForeground( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_BTNTEXT) );
537 }
538 else
539 {
540 destDc.SetTextForeground( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DSHADOW) );
541 }
542 destDc.SetTextBackground( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_BTNFACE) );
543
544 destDc.DrawText( mLabelText, txtPos.x, txtPos.y );
545 }
546
547 if ( !isEnabled ){
548
549 #ifdef __WXMSW__ // This is currently MSW specific
550 gray_out_image_on_dc( destDc, destDim.x, destDim.y );
551 #else
552 wxBrush checkerBrush( wxBitmap( (const char*)_gDisableImage,8,8) );
553 checkerBrush.SetColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE ) );
554 destDc.SetBrush( checkerBrush );
555 destDc.DrawRectangle( imgPos.x, imgPos.y, srcBmp->GetWidth()+1, srcBmp->GetHeight()+1);
556 #endif
557 }
558 // adjust button size to fit the new dimensions of the label
559 if ( !mSizeIsSet && 0 )
560 {
561 mSizeIsSet = TRUE;
562 SetSize( -1,-1,
563 destBmp->GetWidth() + mMarginX*2,
564 destBmp->GetHeight() + mMarginY*2, 0
565 );
566 }
567 }
568 void wxNewBitmapButton::RenderAllLabelImages()
569 {
570 if ( !mIsCreated )
571 return;
572 RenderLabelImage( mpDisabledImg, &mDepressedBmp, FALSE );
573 RenderLabelImage( mpPressedImg, &mDepressedBmp, TRUE, TRUE );
574 RenderLabelImage( mpDepressedImg, &mDepressedBmp, TRUE, FALSE );
575 if ( mHasFocusedBmp )
576 {
577 RenderLabelImage( mpFocusedImg, &mFocusedBmp, TRUE, FALSE );
578 }
579 }
580
581
582 void wxNewBitmapButton::RenderLabelImages()
583 {
584 if ( !mIsCreated )
585 return;
586
587 if ( !IsEnabled() )
588 {
589 RenderLabelImage( mpDisabledImg, &mDepressedBmp, FALSE );
590 }
591 else
592
593 if ( mIsPressed )
594
595 RenderLabelImage( mpPressedImg, &mDepressedBmp, TRUE, TRUE );
596 else
597 {
598 if ( mIsInFocus )
599 {
600 if ( mHasFocusedBmp )
601 RenderLabelImage( mpFocusedImg, &mFocusedBmp, TRUE, FALSE );
602 else
603 RenderLabelImage( mpDepressedImg, &mDepressedBmp, TRUE, FALSE );
604 }
605 else
606 RenderLabelImage( mpDepressedImg, &mDepressedBmp, TRUE, FALSE );
607 }
608 }
609
610 void wxNewBitmapButton::DrawDecorations( wxDC& dc )
611 {
612 if ( mIsFlat )
613 {
614 DrawShade( 1, dc, mGrayPen, mGrayPen );
615
616 if ( mIsInFocus )
617 {
618 if ( mIsPressed )
619 DrawShade( 0, dc, mDarkPen, mLightPen );
620 else
621 DrawShade( 0, dc, mLightPen, mDarkPen );
622 }
623 else
624 DrawShade( 0, dc, mGrayPen, mGrayPen );
625 }
626 else
627 {
628 if ( mIsPressed )
629 {
630 DrawShade( 0, dc, mDarkPen, mGrayPen );
631 DrawShade( 1, dc, mBlackPen, mLightPen );
632 }
633 else
634 {
635 DrawShade( 0, dc, mGrayPen, mDarkPen );
636 DrawShade( 1, dc, mLightPen, mBlackPen );
637 }
638 }
639 }
640
641 void wxNewBitmapButton::SetLabel(const wxBitmap& labelBitmap,
642 const wxString& labelText )
643 {
644 DestroyLabels();
645
646 mLabelText = labelText;
647 mDepressedBmp = labelBitmap;
648
649 //RenderLabelImages();
650 RenderAllLabelImages();
651 }
652
653 void wxNewBitmapButton::SetAlignments( int alignText,
654 int marginX,
655 int marginY,
656 int textToLabelGap)
657 {
658 DestroyLabels();
659
660 mMarginX = marginX;
661 mMarginY = marginY;
662 mTextAlignment = alignText;
663 mTextToLabelGap = textToLabelGap;
664
665 //RenderLabelImages();
666 RenderAllLabelImages();
667 }
668
669 // event handlers
670
671 void wxNewBitmapButton::OnLButtonDown( wxMouseEvent& event )
672 {
673 mPrevPressedState = FALSE;
674 mDragStarted = TRUE;
675 mIsPressed = TRUE;
676 Refresh();
677
678 if ( !mIsInFocus )
679 CaptureMouse();
680 }
681
682 void wxNewBitmapButton::OnLButtonUp( wxMouseEvent& event )
683 {
684 if ( !mDragStarted )
685 return;
686
687 mDragStarted = FALSE;
688 mIsPressed = FALSE;
689 mIsInFocus = FALSE;
690 Refresh();
691
692 ReleaseMouse();
693
694 if ( IsInWindow( event.m_x, event.m_y ) )
695 {
696 // fire event, if mouse was released
697 // within the bounds of button
698 wxCommandEvent cmd( mFiredEventType, GetId() );
699 GetParent()->ProcessEvent( cmd );
700 }
701 }
702
703 bool wxNewBitmapButton::IsInWindow( int x, int y )
704 {
705 int width, height;
706 GetSize( &width, &height );
707
708 return ( x >= 0 && y >= 0 &&
709 x < width &&
710 y < height );
711 }
712
713 void wxNewBitmapButton::OnMouseMove( wxMouseEvent& event )
714 {
715 mPrevPressedState=mIsPressed;
716 mPrevInFocusState=mIsInFocus;
717 if ( !mIsInFocus && IsInWindow( event.m_x, event.m_y ) )
718 {
719 if ( !mDragStarted )
720 CaptureMouse();
721
722 mIsInFocus = TRUE;
723 }
724 else
725 if ( mIsInFocus && !IsInWindow( event.m_x, event.m_y ) )
726 {
727 mIsInFocus = FALSE;
728
729 if ( !mDragStarted )
730 ReleaseMouse();
731 }
732
733 if ( mDragStarted )
734 {
735 if ( IsInWindow( event.m_x, event.m_y ) )
736
737 mIsPressed = TRUE;
738 else
739 mIsPressed = FALSE;
740 }
741
742 if ((mIsPressed != mPrevPressedState) ||
743 (mIsInFocus!=mPrevInFocusState))
744 {
745 Refresh();
746 }
747 }
748
749 void wxNewBitmapButton::OnSize( wxSizeEvent& event )
750 {
751 //Reshape();
752 }
753
754 void wxNewBitmapButton::Reshape( )
755 {
756
757 bool wasCreated = mIsCreated;
758 mIsCreated = TRUE;
759
760 if ( !wasCreated )
761 {
762 // in the case of loading button from stream, check if we
763 // have non-empty image-file name, load if possible
764
765 if ( mImageFileName != "" )
766 {
767 mDepressedBmp.LoadFile( mImageFileName, mImageFileType );
768
769 //wxMessageBox("Image Loaded!!!");
770 }
771
772 //RenderLabelImages();
773 RenderAllLabelImages();
774
775 wxBitmap* pCurImg = GetStateLabel();
776
777 int w = pCurImg->GetWidth(),
778 h = pCurImg->GetHeight();
779
780 SetSize( 0,0, w + mMarginX*2, h + mMarginY*2 , 0 );
781 }
782 }
783
784 void wxNewBitmapButton::DrawLabel( wxDC& dc )
785 {
786 wxBitmap* pCurBmp = GetStateLabel();
787
788 if ( pCurBmp == NULL )
789 {
790 wxSizeEvent evt;
791 OnSize( evt ); // fake it up!
792
793 //RenderLabelImages();
794 pCurBmp = GetStateLabel();
795 }
796
797 wxMemoryDC mdc;
798 mdc.SelectObject( *pCurBmp );
799
800 dc.Blit( mMarginX, mMarginY,
801 pCurBmp->GetWidth(),
802 pCurBmp->GetHeight(),
803 &mdc, 0,0, wxCOPY
804 );
805
806 mdc.SelectObject( wxNullBitmap );
807 }
808
809 void wxNewBitmapButton::OnPaint( wxPaintEvent& event )
810 {
811 wxPaintDC dc(this);
812
813 // first, make sure images for current state are prepared
814 //RenderLabelImages();
815
816 DrawLabel( dc );
817
818 DrawDecorations( dc );
819 }
820
821 void wxNewBitmapButton::OnEraseBackground( wxEraseEvent& event )
822 {
823 // do nothing
824 }
825
826 void wxNewBitmapButton::OnKillFocus( wxFocusEvent& event )
827 {
828 // useless
829
830 wxMessageBox("kill-focus for button!");
831 }
832