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