/[pcsx2_0.9.7]/branch/r3113_0.9.7_beta/3rdparty/wxWidgets/src/msw/radiobox.cpp
ViewVC logotype

Contents of /branch/r3113_0.9.7_beta/3rdparty/wxWidgets/src/msw/radiobox.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 32 - (show annotations) (download)
Tue Sep 7 03:29:01 2010 UTC (9 years, 11 months ago) by william
File size: 27274 byte(s)
branching from upstream revision (http://pcsx2.googlecode.com/svn/trunk
): r3113 to
https://svn.netsolutions.dnsalias.com/websvn/ps2/pcsx2/pcsx2_0.9.7/branch/r3113_0.9.7_beta
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/radiobox.cpp
3 // Purpose: wxRadioBox implementation
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id: radiobox.cpp 54927 2008-08-02 15:59:13Z VZ $
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ===========================================================================
13 // declarations
14 // ===========================================================================
15
16 // ---------------------------------------------------------------------------
17 // headers
18 // ---------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #if wxUSE_RADIOBOX
28
29 #include "wx/radiobox.h"
30
31 #ifndef WX_PRECOMP
32 #include "wx/bitmap.h"
33 #include "wx/brush.h"
34 #include "wx/settings.h"
35 #include "wx/log.h"
36 #endif
37
38 #include "wx/msw/subwin.h"
39
40 #if wxUSE_TOOLTIPS
41 #include "wx/tooltip.h"
42 #endif // wxUSE_TOOLTIPS
43
44 // TODO: wxCONSTRUCTOR
45 #if 0 // wxUSE_EXTENDED_RTTI
46 WX_DEFINE_FLAGS( wxRadioBoxStyle )
47
48 wxBEGIN_FLAGS( wxRadioBoxStyle )
49 // new style border flags, we put them first to
50 // use them for streaming out
51 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
52 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
53 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
54 wxFLAGS_MEMBER(wxBORDER_RAISED)
55 wxFLAGS_MEMBER(wxBORDER_STATIC)
56 wxFLAGS_MEMBER(wxBORDER_NONE)
57
58 // old style border flags
59 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
60 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
61 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
62 wxFLAGS_MEMBER(wxRAISED_BORDER)
63 wxFLAGS_MEMBER(wxSTATIC_BORDER)
64 wxFLAGS_MEMBER(wxBORDER)
65
66 // standard window styles
67 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
68 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
69 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
70 wxFLAGS_MEMBER(wxWANTS_CHARS)
71 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
72 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
73 wxFLAGS_MEMBER(wxVSCROLL)
74 wxFLAGS_MEMBER(wxHSCROLL)
75
76 wxFLAGS_MEMBER(wxRA_SPECIFY_COLS)
77 wxFLAGS_MEMBER(wxRA_HORIZONTAL)
78 wxFLAGS_MEMBER(wxRA_SPECIFY_ROWS)
79 wxFLAGS_MEMBER(wxRA_VERTICAL)
80
81 wxEND_FLAGS( wxRadioBoxStyle )
82
83 IMPLEMENT_DYNAMIC_CLASS_XTI(wxRadioBox, wxControl,"wx/radiobox.h")
84
85 wxBEGIN_PROPERTIES_TABLE(wxRadioBox)
86 wxEVENT_PROPERTY( Select , wxEVT_COMMAND_RADIOBOX_SELECTED , wxCommandEvent )
87 wxPROPERTY_FLAGS( WindowStyle , wxRadioBoxStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
88 wxEND_PROPERTIES_TABLE()
89
90 #else
91 IMPLEMENT_DYNAMIC_CLASS(wxRadioBox, wxControl)
92 #endif
93
94 /*
95 selection
96 content
97 label
98 dimension
99 item
100 */
101
102 // ---------------------------------------------------------------------------
103 // private functions
104 // ---------------------------------------------------------------------------
105
106 // wnd proc for radio buttons
107 LRESULT APIENTRY _EXPORT wxRadioBtnWndProc(HWND hWnd,
108 UINT message,
109 WPARAM wParam,
110 LPARAM lParam);
111
112 // ---------------------------------------------------------------------------
113 // global vars
114 // ---------------------------------------------------------------------------
115
116 // the pointer to standard radio button wnd proc
117 static WXFARPROC s_wndprocRadioBtn = (WXFARPROC)NULL;
118
119 // ===========================================================================
120 // implementation
121 // ===========================================================================
122
123 // ---------------------------------------------------------------------------
124 // wxRadioBox creation
125 // ---------------------------------------------------------------------------
126
127 // Radio box item
128 void wxRadioBox::Init()
129 {
130 m_selectedButton = wxNOT_FOUND;
131 m_radioButtons = NULL;
132 m_radioWidth = NULL;
133 m_radioHeight = NULL;
134 }
135
136 bool wxRadioBox::Create(wxWindow *parent,
137 wxWindowID id,
138 const wxString& title,
139 const wxPoint& pos,
140 const wxSize& size,
141 int n,
142 const wxString choices[],
143 int majorDim,
144 long style,
145 const wxValidator& val,
146 const wxString& name)
147 {
148 // common initialization
149 if ( !wxStaticBox::Create(parent, id, title, pos, size, style, name) )
150 return false;
151
152 // the code elsewhere in this file supposes that either wxRA_SPECIFY_COLS
153 // or wxRA_SPECIFY_ROWS is set, ensure that this is indeed the case
154 if ( !(style & (wxRA_SPECIFY_ROWS | wxRA_SPECIFY_COLS)) )
155 style |= wxRA_SPECIFY_COLS;
156
157 #if wxUSE_VALIDATORS
158 SetValidator(val);
159 #else
160 wxUnusedVar(val);
161 #endif // wxUSE_VALIDATORS/!wxUSE_VALIDATORS
162
163 m_radioButtons = new wxSubwindows(n);
164 m_radioWidth = new int[n];
165 m_radioHeight = new int[n];
166
167 for ( int i = 0; i < n; i++ )
168 {
169 m_radioWidth[i] =
170 m_radioHeight[i] = wxDefaultCoord;
171 long styleBtn = BS_AUTORADIOBUTTON | WS_TABSTOP | WS_CHILD | WS_VISIBLE;
172 if ( i == 0 )
173 styleBtn |= WS_GROUP;
174
175 long newId = NewControlId();
176
177 HWND hwndBtn = ::CreateWindow(_T("BUTTON"),
178 choices[i],
179 styleBtn,
180 0, 0, 0, 0, // will be set in SetSize()
181 GetHwndOf(parent),
182 (HMENU)newId,
183 wxGetInstance(),
184 NULL);
185
186 if ( !hwndBtn )
187 {
188 wxLogLastError(wxT("CreateWindow(radio btn)"));
189
190 return false;
191 }
192
193 (*m_radioButtons)[i] = hwndBtn;
194
195 SubclassRadioButton((WXHWND)hwndBtn);
196
197 m_subControls.Add(newId);
198 }
199
200 // Create a dummy radio control to end the group.
201 (void)::CreateWindow(_T("BUTTON"),
202 wxEmptyString,
203 WS_GROUP | BS_AUTORADIOBUTTON | WS_CHILD,
204 0, 0, 0, 0, GetHwndOf(parent),
205 (HMENU)NewControlId(), wxGetInstance(), NULL);
206
207 m_radioButtons->SetFont(GetFont());
208
209 #ifdef __WXWINCE__
210 // Set the z-order correctly
211 SetWindowPos(GetHwnd(), HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
212 #endif
213
214 SetMajorDim(majorDim == 0 ? n : majorDim, style);
215 SetSelection(0);
216 SetSize(pos.x, pos.y, size.x, size.y);
217
218 // Now that we have items determine what is the best size and set it.
219 SetInitialSize(size);
220
221 return true;
222 }
223
224 bool wxRadioBox::Create(wxWindow *parent,
225 wxWindowID id,
226 const wxString& title,
227 const wxPoint& pos,
228 const wxSize& size,
229 const wxArrayString& choices,
230 int majorDim,
231 long style,
232 const wxValidator& val,
233 const wxString& name)
234 {
235 wxCArrayString chs(choices);
236 return Create(parent, id, title, pos, size, chs.GetCount(),
237 chs.GetStrings(), majorDim, style, val, name);
238 }
239
240 wxRadioBox::~wxRadioBox()
241 {
242 m_isBeingDeleted = true;
243
244 delete m_radioButtons;
245 delete[] m_radioWidth;
246 delete[] m_radioHeight;
247 }
248
249 // NB: if this code is changed, wxGetWindowForHWND() which relies on having the
250 // radiobox pointer in GWL_USERDATA for radio buttons must be updated too!
251 void wxRadioBox::SubclassRadioButton(WXHWND hWndBtn)
252 {
253 HWND hwndBtn = (HWND)hWndBtn;
254
255 if ( !s_wndprocRadioBtn )
256 s_wndprocRadioBtn = (WXFARPROC)wxGetWindowProc(hwndBtn);
257
258 wxSetWindowProc(hwndBtn, wxRadioBtnWndProc);
259 wxSetWindowUserData(hwndBtn, this);
260 }
261
262 // ----------------------------------------------------------------------------
263 // events generation
264 // ----------------------------------------------------------------------------
265
266 bool wxRadioBox::MSWCommand(WXUINT cmd, WXWORD id)
267 {
268 if ( cmd == BN_CLICKED )
269 {
270 if (id == GetId())
271 return true;
272
273 int selectedButton = wxNOT_FOUND;
274
275 const unsigned int count = GetCount();
276 for ( unsigned int i = 0; i < count; i++ )
277 {
278 const HWND hwndBtn = (*m_radioButtons)[i];
279 if ( id == wxGetWindowId(hwndBtn) )
280 {
281 // we can get BN_CLICKED for a button which just became focused
282 // but it may not be checked, in which case we shouldn't
283 // generate a radiobox selection changed event for it
284 if ( ::SendMessage(hwndBtn, BM_GETCHECK, 0, 0) == BST_CHECKED )
285 selectedButton = i;
286
287 break;
288 }
289 }
290
291 if ( selectedButton == wxNOT_FOUND )
292 {
293 // just ignore it - due to a hack with WM_NCHITTEST handling in our
294 // wnd proc, we can receive dummy click messages when we click near
295 // the radiobox edge (this is ugly but Julian wouldn't let me get
296 // rid of this...)
297 return false;
298 }
299
300 if ( selectedButton != m_selectedButton )
301 {
302 m_selectedButton = selectedButton;
303
304 SendNotificationEvent();
305 }
306 //else: don't generate events when the selection doesn't change
307
308 return true;
309 }
310 else
311 return false;
312 }
313
314 void wxRadioBox::Command(wxCommandEvent & event)
315 {
316 SetSelection (event.GetInt());
317 SetFocus();
318 ProcessCommand(event);
319 }
320
321 void wxRadioBox::SendNotificationEvent()
322 {
323 wxCommandEvent event(wxEVT_COMMAND_RADIOBOX_SELECTED, m_windowId);
324 event.SetInt( m_selectedButton );
325 event.SetString(GetString(m_selectedButton));
326 event.SetEventObject( this );
327 ProcessCommand(event);
328 }
329
330 // ----------------------------------------------------------------------------
331 // simple accessors
332 // ----------------------------------------------------------------------------
333
334 unsigned int wxRadioBox::GetCount() const
335 {
336 return m_radioButtons ? m_radioButtons->GetCount() : 0u;
337 }
338
339 void wxRadioBox::SetString(unsigned int item, const wxString& label)
340 {
341 wxCHECK_RET( IsValid(item), wxT("invalid radiobox index") );
342
343 m_radioWidth[item] =
344 m_radioHeight[item] = wxDefaultCoord;
345
346 ::SetWindowText((*m_radioButtons)[item], label.c_str());
347
348 InvalidateBestSize();
349 }
350
351 void wxRadioBox::SetSelection(int N)
352 {
353 wxCHECK_RET( IsValid(N), wxT("invalid radiobox index") );
354
355 // unselect the old button
356 if ( m_selectedButton != wxNOT_FOUND )
357 ::SendMessage((*m_radioButtons)[m_selectedButton], BM_SETCHECK, 0, 0L);
358
359 // and select the new one
360 ::SendMessage((*m_radioButtons)[N], BM_SETCHECK, 1, 0L);
361
362 m_selectedButton = N;
363 }
364
365 // Find string for position
366 wxString wxRadioBox::GetString(unsigned int item) const
367 {
368 wxCHECK_MSG( IsValid(item), wxEmptyString,
369 wxT("invalid radiobox index") );
370
371 return wxGetWindowText((*m_radioButtons)[item]);
372 }
373
374 void wxRadioBox::SetFocus()
375 {
376 if ( GetCount() > 0 )
377 {
378 ::SetFocus((*m_radioButtons)[m_selectedButton == wxNOT_FOUND
379 ? 0
380 : m_selectedButton]);
381 }
382 }
383
384 // Enable a specific button
385 bool wxRadioBox::Enable(unsigned int item, bool enable)
386 {
387 wxCHECK_MSG( IsValid(item), false,
388 wxT("invalid item in wxRadioBox::Enable()") );
389
390 BOOL ret = ::EnableWindow((*m_radioButtons)[item], enable);
391
392 return (ret == 0) != enable;
393 }
394
395 bool wxRadioBox::IsItemEnabled(unsigned int item) const
396 {
397 wxCHECK_MSG( IsValid(item), false,
398 wxT("invalid item in wxRadioBox::IsItemEnabled()") );
399
400 return ::IsWindowEnabled((*m_radioButtons)[item]) != 0;
401 }
402
403 // Show a specific button
404 bool wxRadioBox::Show(unsigned int item, bool show)
405 {
406 wxCHECK_MSG( IsValid(item), false,
407 wxT("invalid item in wxRadioBox::Show()") );
408
409 BOOL ret = ::ShowWindow((*m_radioButtons)[item], show ? SW_SHOW : SW_HIDE);
410
411 bool changed = (ret != 0) != show;
412 if ( changed )
413 {
414 InvalidateBestSize();
415 }
416
417 return changed;
418 }
419
420 bool wxRadioBox::IsItemShown(unsigned int item) const
421 {
422 wxCHECK_MSG( IsValid(item), false,
423 wxT("invalid item in wxRadioBox::IsItemShown()") );
424
425 // don't use IsWindowVisible() here because it would return false if the
426 // radiobox itself is hidden while we want to only return false if this
427 // button specifically is hidden
428 return (::GetWindowLong((*m_radioButtons)[item],
429 GWL_STYLE) & WS_VISIBLE) != 0;
430 }
431
432 #if wxUSE_TOOLTIPS
433
434 bool wxRadioBox::HasToolTips() const
435 {
436 return wxStaticBox::HasToolTips() || wxRadioBoxBase::HasItemToolTips();
437 }
438
439 void wxRadioBox::DoSetItemToolTip(unsigned int item, wxToolTip *tooltip)
440 {
441 // we have already checked for the item to be valid in wxRadioBoxBase
442 const HWND hwndRbtn = (*m_radioButtons)[item];
443 if ( tooltip != NULL )
444 tooltip->Add(hwndRbtn);
445 else // unset the tooltip
446 wxToolTip::Remove(hwndRbtn);
447 }
448
449 #endif // wxUSE_TOOLTIPS
450
451 bool wxRadioBox::Reparent(wxWindowBase *newParent)
452 {
453 if ( !wxStaticBox::Reparent(newParent) )
454 {
455 return false;
456 }
457
458 HWND hwndParent = GetHwndOf(GetParent());
459 for ( size_t item = 0; item < m_radioButtons->GetCount(); item++ )
460 {
461 ::SetParent((*m_radioButtons)[item], hwndParent);
462 }
463 #ifdef __WXWINCE__
464 // put static box under the buttons in the Z-order
465 SetWindowPos(GetHwnd(), HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
466 #endif
467 return true;
468 }
469
470 WX_FORWARD_STD_METHODS_TO_SUBWINDOWS(wxRadioBox, wxStaticBox, m_radioButtons)
471
472 // ----------------------------------------------------------------------------
473 // size calculations
474 // ----------------------------------------------------------------------------
475
476 wxSize wxRadioBox::GetMaxButtonSize() const
477 {
478 // calculate the max button size
479 int widthMax = 0,
480 heightMax = 0;
481 const unsigned int count = GetCount();
482 for ( unsigned int i = 0 ; i < count; i++ )
483 {
484 int width, height;
485 if ( m_radioWidth[i] < 0 )
486 {
487 GetTextExtent(wxGetWindowText((*m_radioButtons)[i]), &width, &height);
488
489 // adjust the size to take into account the radio box itself
490 // FIXME this is totally bogus!
491 width += RADIO_SIZE;
492 height *= 3;
493 height /= 2;
494 }
495 else
496 {
497 width = m_radioWidth[i];
498 height = m_radioHeight[i];
499 }
500
501 if ( widthMax < width )
502 widthMax = width;
503 if ( heightMax < height )
504 heightMax = height;
505 }
506
507 return wxSize(widthMax, heightMax);
508 }
509
510 wxSize wxRadioBox::GetTotalButtonSize(const wxSize& sizeBtn) const
511 {
512 // the radiobox should be big enough for its buttons
513 int cx1, cy1;
514 wxGetCharSize(m_hWnd, &cx1, &cy1, GetFont());
515
516 int extraHeight = cy1;
517
518 int height = GetRowCount() * sizeBtn.y + cy1/2 + extraHeight;
519 int width = GetColumnCount() * (sizeBtn.x + cx1) + cx1;
520
521 // Add extra space under the label, if it exists.
522 if (!wxControl::GetLabel().empty())
523 height += cy1/2;
524
525 // and also wide enough for its label
526 int widthLabel;
527 GetTextExtent(GetLabelText(), &widthLabel, NULL);
528 widthLabel += RADIO_SIZE; // FIXME this is bogus too
529 if ( widthLabel > width )
530 width = widthLabel;
531
532 return wxSize(width, height);
533 }
534
535 wxSize wxRadioBox::DoGetBestSize() const
536 {
537 if ( !m_radioButtons )
538 {
539 // if we're not fully initialized yet, we can't meaningfully compute
540 // our best size, we'll do it later
541 return wxSize(1, 1);
542 }
543
544 wxSize best = GetTotalButtonSize(GetMaxButtonSize());
545 CacheBestSize(best);
546 return best;
547 }
548
549 // Restored old code.
550 void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
551 {
552 int currentX, currentY;
553 GetPosition(&currentX, &currentY);
554 int widthOld, heightOld;
555 GetSize(&widthOld, &heightOld);
556
557 int xx = x;
558 int yy = y;
559
560 if (x == wxDefaultCoord && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
561 xx = currentX;
562 if (y == wxDefaultCoord && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
563 yy = currentY;
564
565 int y_offset = yy;
566 int x_offset = xx;
567
568 int cx1, cy1;
569 wxGetCharSize(m_hWnd, &cx1, &cy1, GetFont());
570
571 // Attempt to have a look coherent with other platforms: We compute the
572 // biggest toggle dim, then we align all items according this value.
573 wxSize maxSize = GetMaxButtonSize();
574 int maxWidth = maxSize.x,
575 maxHeight = maxSize.y;
576
577 wxSize totSize = GetTotalButtonSize(maxSize);
578 int totWidth = totSize.x,
579 totHeight = totSize.y;
580
581 // only change our width/height if asked for
582 if ( width == wxDefaultCoord )
583 {
584 if ( sizeFlags & wxSIZE_AUTO_WIDTH )
585 width = totWidth;
586 else
587 width = widthOld;
588 }
589
590 if ( height == wxDefaultCoord )
591 {
592 if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
593 height = totHeight;
594 else
595 height = heightOld;
596 }
597
598 DoMoveWindow(xx, yy, width, height);
599
600 // Now position all the buttons: the current button will be put at
601 // wxPoint(x_offset, y_offset) and the new row/column will start at
602 // startX/startY. The size of all buttons will be the same wxSize(maxWidth,
603 // maxHeight) except for the buttons in the last column which should extend
604 // to the right border of radiobox and thus can be wider than this.
605
606 // Also, remember that wxRA_SPECIFY_COLS means that we arrange buttons in
607 // left to right order and GetMajorDim() is the number of columns while
608 // wxRA_SPECIFY_ROWS means that the buttons are arranged top to bottom and
609 // GetMajorDim() is the number of rows.
610
611 x_offset += cx1;
612 y_offset += cy1;
613
614 // Add extra space under the label, if it exists.
615 if (!wxControl::GetLabel().empty())
616 y_offset += cy1/2;
617
618 int startX = x_offset;
619 int startY = y_offset;
620
621 const unsigned int count = GetCount();
622 for (unsigned int i = 0; i < count; i++)
623 {
624 // the last button in the row may be wider than the other ones as the
625 // radiobox may be wider than the sum of the button widths (as it
626 // happens, for example, when the radiobox label is very long)
627 bool isLastInTheRow;
628 if ( m_windowStyle & wxRA_SPECIFY_COLS )
629 {
630 // item is the last in its row if it is a multiple of the number of
631 // columns or if it is just the last item
632 unsigned int n = i + 1;
633 isLastInTheRow = ((n % GetMajorDim()) == 0) || (n == count);
634 }
635 else // wxRA_SPECIFY_ROWS
636 {
637 // item is the last in the row if it is in the last columns
638 isLastInTheRow = i >= (count/GetMajorDim())*GetMajorDim();
639 }
640
641 // is this the start of new row/column?
642 if ( i && (i % GetMajorDim() == 0) )
643 {
644 if ( m_windowStyle & wxRA_SPECIFY_ROWS )
645 {
646 // start of new column
647 y_offset = startY;
648 x_offset += maxWidth + cx1;
649 }
650 else // start of new row
651 {
652 x_offset = startX;
653 y_offset += maxHeight;
654 if (m_radioWidth[0]>0)
655 y_offset += cy1/2;
656 }
657 }
658
659 int widthBtn;
660 if ( isLastInTheRow )
661 {
662 // make the button go to the end of radio box
663 widthBtn = startX + width - x_offset - 2*cx1;
664 if ( widthBtn < maxWidth )
665 widthBtn = maxWidth;
666 }
667 else
668 {
669 // normal button, always of the same size
670 widthBtn = maxWidth;
671 }
672
673 // make all buttons of the same, maximal size - like this they cover
674 // the radiobox entirely and the radiobox tooltips are always shown
675 // (otherwise they are not when the mouse pointer is in the radiobox
676 // part not belonging to any radiobutton)
677 DoMoveSibling((*m_radioButtons)[i], x_offset, y_offset, widthBtn, maxHeight);
678
679 // where do we put the next button?
680 if ( m_windowStyle & wxRA_SPECIFY_ROWS )
681 {
682 // below this one
683 y_offset += maxHeight;
684 if (m_radioWidth[0]>0)
685 y_offset += cy1/2;
686 }
687 else
688 {
689 // to the right of this one
690 x_offset += widthBtn + cx1;
691 }
692 }
693 }
694
695 int wxRadioBox::GetItemFromPoint(const wxPoint& pt) const
696 {
697 const unsigned int count = GetCount();
698 for ( unsigned int i = 0; i < count; i++ )
699 {
700 RECT rect = wxGetWindowRect((*m_radioButtons)[i]);
701
702 if ( rect.left <= pt.x && pt.x < rect.right &&
703 rect.top <= pt.y && pt.y < rect.bottom )
704 {
705 return i;
706 }
707 }
708
709 return wxNOT_FOUND;
710 }
711
712 // ----------------------------------------------------------------------------
713 // radio box drawing
714 // ----------------------------------------------------------------------------
715
716 #ifndef __WXWINCE__
717
718 WXHRGN wxRadioBox::MSWGetRegionWithoutChildren()
719 {
720 RECT rc;
721 ::GetWindowRect(GetHwnd(), &rc);
722 HRGN hrgn = ::CreateRectRgn(rc.left, rc.top, rc.right + 1, rc.bottom + 1);
723
724 const unsigned int count = GetCount();
725 for ( unsigned int i = 0; i < count; ++i )
726 {
727 // don't clip out hidden children
728 if ( !IsItemShown(i) )
729 continue;
730
731 ::GetWindowRect((*m_radioButtons)[i], &rc);
732 AutoHRGN hrgnchild(::CreateRectRgnIndirect(&rc));
733 ::CombineRgn(hrgn, hrgn, hrgnchild, RGN_DIFF);
734 }
735
736 return (WXHRGN)hrgn;
737 }
738
739 #endif // __WXWINCE__
740
741 // ---------------------------------------------------------------------------
742 // window proc for radio buttons
743 // ---------------------------------------------------------------------------
744
745 LRESULT APIENTRY _EXPORT wxRadioBtnWndProc(HWND hwnd,
746 UINT message,
747 WPARAM wParam,
748 LPARAM lParam)
749 {
750 switch ( message )
751 {
752 case WM_GETDLGCODE:
753 // we must tell IsDialogMessage()/our kbd processing code that we
754 // want to process arrows ourselves because neither of them is
755 // smart enough to handle arrows properly for us
756 {
757 long lDlgCode = ::CallWindowProc(CASTWNDPROC s_wndprocRadioBtn, hwnd,
758 message, wParam, lParam);
759
760 return lDlgCode | DLGC_WANTARROWS;
761 }
762
763 case WM_KEYDOWN:
764 {
765 wxRadioBox *radiobox = (wxRadioBox *)wxGetWindowUserData(hwnd);
766
767 wxCHECK_MSG( radiobox, 0, wxT("radio button without radio box?") );
768
769 bool processed = true;
770
771 wxDirection dir;
772 switch ( wParam )
773 {
774 case VK_UP:
775 dir = wxUP;
776 break;
777
778 case VK_LEFT:
779 dir = wxLEFT;
780 break;
781
782 case VK_DOWN:
783 dir = wxDOWN;
784 break;
785
786 case VK_RIGHT:
787 dir = wxRIGHT;
788 break;
789
790 default:
791 processed = false;
792
793 // just to suppress the compiler warning
794 dir = wxALL;
795 }
796
797 if ( processed )
798 {
799 int selOld = radiobox->GetSelection();
800 int selNew = radiobox->GetNextItem
801 (
802 selOld,
803 dir,
804 radiobox->GetWindowStyle()
805 );
806
807 if ( selNew != selOld )
808 {
809 radiobox->SetSelection(selNew);
810 radiobox->SetFocus();
811
812 // emulate the button click
813 radiobox->SendNotificationEvent();
814
815 return 0;
816 }
817 }
818 }
819 break;
820
821 case WM_SETFOCUS:
822 case WM_KILLFOCUS:
823 {
824 wxRadioBox *radiobox = (wxRadioBox *)wxGetWindowUserData(hwnd);
825
826 wxCHECK_MSG( radiobox, 0, wxT("radio button without radio box?") );
827
828 // if we don't do this, no focus events are generated for the
829 // radiobox and, besides, we need to notify the parent about
830 // the focus change, otherwise the focus handling logic in
831 // wxControlContainer doesn't work
832 if ( message == WM_SETFOCUS )
833 radiobox->HandleSetFocus((WXHWND)wParam);
834 else
835 radiobox->HandleKillFocus((WXHWND)wParam);
836 }
837 break;
838
839 #ifndef __WXWINCE__
840 case WM_HELP:
841 {
842 wxRadioBox *radiobox = (wxRadioBox *)wxGetWindowUserData(hwnd);
843
844 wxCHECK_MSG( radiobox, 0, wxT("radio button without radio box?") );
845
846 bool processed = false;
847
848 wxEvtHandler * const handler = radiobox->GetEventHandler();
849
850 HELPINFO* info = (HELPINFO*) lParam;
851 if ( info->iContextType == HELPINFO_WINDOW )
852 {
853 for ( wxWindow* subjectOfHelp = radiobox;
854 subjectOfHelp;
855 subjectOfHelp = subjectOfHelp->GetParent() )
856 {
857 wxHelpEvent helpEvent(wxEVT_HELP,
858 subjectOfHelp->GetId(),
859 wxPoint(info->MousePos.x,
860 info->MousePos.y));
861 helpEvent.SetEventObject(radiobox);
862 if ( handler->ProcessEvent(helpEvent) )
863 {
864 processed = true;
865 break;
866 }
867 }
868 }
869 else if (info->iContextType == HELPINFO_MENUITEM)
870 {
871 wxHelpEvent helpEvent(wxEVT_HELP, info->iCtrlId);
872 helpEvent.SetEventObject(radiobox);
873 processed = handler->ProcessEvent(helpEvent);
874 }
875
876 if ( processed )
877 return 0;
878 }
879 break;
880 #endif // !__WXWINCE__
881 }
882
883 return ::CallWindowProc(CASTWNDPROC s_wndprocRadioBtn, hwnd, message, wParam, lParam);
884 }
885
886 #endif // wxUSE_RADIOBOX

  ViewVC Help
Powered by ViewVC 1.1.22