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