]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/radiobox.cpp
Added files for wxNotebook and wxCocoaNSTabView
[wxWidgets.git] / src / msw / radiobox.cpp
index 36d514174e04c56d58b6f0efc586a3e4b0f322bd..29943e25c8e2f8110bf64f6e874874fa69521331 100644 (file)
@@ -17,7 +17,7 @@
 // headers
 // ---------------------------------------------------------------------------
 
 // headers
 // ---------------------------------------------------------------------------
 
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
     #pragma implementation "radiobox.h"
 #endif
 
     #pragma implementation "radiobox.h"
 #endif
 
     #include "wx/tooltip.h"
 #endif // wxUSE_TOOLTIPS
 
     #include "wx/tooltip.h"
 #endif // wxUSE_TOOLTIPS
 
+// TODO: wxCONSTRUCTOR
+#if 0 // wxUSE_EXTENDED_RTTI
+WX_DEFINE_FLAGS( wxRadioBoxStyle )
+
+wxBEGIN_FLAGS( wxRadioBoxStyle )
+    // new style border flags, we put them first to
+    // use them for streaming out
+    wxFLAGS_MEMBER(wxBORDER_SIMPLE)
+    wxFLAGS_MEMBER(wxBORDER_SUNKEN)
+    wxFLAGS_MEMBER(wxBORDER_DOUBLE)
+    wxFLAGS_MEMBER(wxBORDER_RAISED)
+    wxFLAGS_MEMBER(wxBORDER_STATIC)
+    wxFLAGS_MEMBER(wxBORDER_NONE)
+    
+    // old style border flags
+    wxFLAGS_MEMBER(wxSIMPLE_BORDER)
+    wxFLAGS_MEMBER(wxSUNKEN_BORDER)
+    wxFLAGS_MEMBER(wxDOUBLE_BORDER)
+    wxFLAGS_MEMBER(wxRAISED_BORDER)
+    wxFLAGS_MEMBER(wxSTATIC_BORDER)
+    wxFLAGS_MEMBER(wxBORDER)
+
+    // standard window styles
+    wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
+    wxFLAGS_MEMBER(wxCLIP_CHILDREN)
+    wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
+    wxFLAGS_MEMBER(wxWANTS_CHARS)
+    wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
+    wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
+    wxFLAGS_MEMBER(wxVSCROLL)
+    wxFLAGS_MEMBER(wxHSCROLL)
+
+    wxFLAGS_MEMBER(wxRA_SPECIFY_COLS)
+    wxFLAGS_MEMBER(wxRA_HORIZONTAL)
+    wxFLAGS_MEMBER(wxRA_SPECIFY_ROWS)
+    wxFLAGS_MEMBER(wxRA_VERTICAL)
+
+wxEND_FLAGS( wxRadioBoxStyle )
+
+IMPLEMENT_DYNAMIC_CLASS_XTI(wxRadioBox, wxControl,"wx/radiobox.h")
+
+wxBEGIN_PROPERTIES_TABLE(wxRadioBox)
+    wxEVENT_PROPERTY( Select , wxEVT_COMMAND_RADIOBOX_SELECTED , wxCommandEvent )
+    wxPROPERTY_FLAGS( WindowStyle , wxRadioBoxStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
+wxEND_PROPERTIES_TABLE()
+
+#else
 IMPLEMENT_DYNAMIC_CLASS(wxRadioBox, wxControl)
 IMPLEMENT_DYNAMIC_CLASS(wxRadioBox, wxControl)
+#endif
+
+/*
+       selection
+       content
+               label
+               dimension
+               item
+*/
 
 // there are two possible ways to create the radio buttons: either as children
 // of the radiobox or as siblings of it - allow playing with both variants for
 
 // there are two possible ways to create the radio buttons: either as children
 // of the radiobox or as siblings of it - allow playing with both variants for
@@ -284,7 +340,7 @@ bool wxRadioBox::Create(wxWindow *parent,
 
     // Create a dummy radio control to end the group.
     (void)::CreateWindow(_T("BUTTON"),
 
     // Create a dummy radio control to end the group.
     (void)::CreateWindow(_T("BUTTON"),
-                         _T(""),
+                         wxEmptyString,
                          WS_GROUP | BS_AUTORADIOBUTTON | WS_CHILD,
                          0, 0, 0, 0, hwndParent,
                          (HMENU)NewControlId(), wxGetInstance(), NULL);
                          WS_GROUP | BS_AUTORADIOBUTTON | WS_CHILD,
                          0, 0, 0, 0, hwndParent,
                          (HMENU)NewControlId(), wxGetInstance(), NULL);
@@ -296,6 +352,22 @@ bool wxRadioBox::Create(wxWindow *parent,
     return TRUE;
 }
 
     return TRUE;
 }
 
+bool wxRadioBox::Create(wxWindow *parent,
+                        wxWindowID id,
+                        const wxString& title,
+                        const wxPoint& pos,
+                        const wxSize& size,
+                        const wxArrayString& choices,
+                        int majorDim,
+                        long style,
+                        const wxValidator& val,
+                        const wxString& name)
+{
+    wxCArrayString chs(choices);
+    return Create(parent, id, title, pos, size, chs.GetCount(),
+                  chs.GetStrings(), majorDim, style, val, name);
+}
+
 wxRadioBox::~wxRadioBox()
 {
     m_isBeingDeleted = TRUE;
 wxRadioBox::~wxRadioBox()
 {
     m_isBeingDeleted = TRUE;
@@ -332,7 +404,6 @@ void wxRadioBox::SetSelection(int N)
         ::SendMessage((HWND) m_radioButtons[m_selectedButton], BM_SETCHECK, 0, 0L);
 
     ::SendMessage((HWND)m_radioButtons[N], BM_SETCHECK, 1, 0L);
         ::SendMessage((HWND) m_radioButtons[m_selectedButton], BM_SETCHECK, 0, 0L);
 
     ::SendMessage((HWND)m_radioButtons[N], BM_SETCHECK, 1, 0L);
-    ::SetFocus((HWND)m_radioButtons[N]);
 
     m_selectedButton = N;
 }
 
     m_selectedButton = N;
 }
@@ -634,10 +705,9 @@ void wxRadioBox::SetFocus()
 {
     if (m_noItems > 0)
     {
 {
     if (m_noItems > 0)
     {
-        if (m_selectedButton == -1)
-            ::SetFocus((HWND) m_radioButtons[0]);
-        else
-            ::SetFocus((HWND) m_radioButtons[m_selectedButton]);
+        ::SetFocus((HWND)m_radioButtons[m_selectedButton == -1
+                                            ? 0
+                                            : m_selectedButton]);
     }
 
 }
     }
 
 }
@@ -701,6 +771,7 @@ bool wxRadioBox::ContainsHWND(WXHWND hWnd) const
 void wxRadioBox::Command(wxCommandEvent & event)
 {
     SetSelection (event.m_commandInt);
 void wxRadioBox::Command(wxCommandEvent & event)
 {
     SetSelection (event.m_commandInt);
+    SetFocus();
     ProcessCommand (event);
 }
 
     ProcessCommand (event);
 }
 
@@ -708,16 +779,13 @@ void wxRadioBox::Command(wxCommandEvent & event)
 //     radiobox pointer in GWL_USERDATA for radio buttons must be updated too!
 void wxRadioBox::SubclassRadioButton(WXHWND hWndBtn)
 {
 //     radiobox pointer in GWL_USERDATA for radio buttons must be updated too!
 void wxRadioBox::SubclassRadioButton(WXHWND hWndBtn)
 {
-    // No GWL_USERDATA in Win16, so omit this subclassing.
-#ifdef __WIN32__
     HWND hwndBtn = (HWND)hWndBtn;
 
     if ( !s_wndprocRadioBtn )
     HWND hwndBtn = (HWND)hWndBtn;
 
     if ( !s_wndprocRadioBtn )
-        s_wndprocRadioBtn = (WXFARPROC)::GetWindowLong(hwndBtn, GWL_WNDPROC);
+        s_wndprocRadioBtn = (WXFARPROC)wxGetWindowProc(hwndBtn);
 
 
-    ::SetWindowLong(hwndBtn, GWL_WNDPROC, (long)wxRadioBtnWndProc);
-    ::SetWindowLong(hwndBtn, GWL_USERDATA, (long)this);
-#endif // __WIN32__
+    wxSetWindowProc(hwndBtn, wxRadioBtnWndProc);
+    wxSetWindowUserData(hwndBtn, this);
 }
 
 void wxRadioBox::SendNotificationEvent()
 }
 
 void wxRadioBox::SendNotificationEvent()
@@ -755,7 +823,7 @@ bool wxRadioBox::SetFont(const wxFont& font)
 // our window proc
 // ----------------------------------------------------------------------------
 
 // our window proc
 // ----------------------------------------------------------------------------
 
-long wxRadioBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
+WXLRESULT wxRadioBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
 {
     switch ( nMsg )
     {
 {
     switch ( nMsg )
     {
@@ -771,7 +839,7 @@ long wxRadioBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
 
                 wxBrush *brush = wxTheBrushList->FindOrCreateBrush(colBack, wxSOLID);
 
 
                 wxBrush *brush = wxTheBrushList->FindOrCreateBrush(colBack, wxSOLID);
 
-                return (WXHBRUSH)brush->GetResourceHandle();
+                return (WXLRESULT)brush->GetResourceHandle();
             }
 #endif // Win32
 
             }
 #endif // Win32
 
@@ -821,11 +889,6 @@ WXHBRUSH wxRadioBox::OnCtlColor(WXHDC pDC, WXHWND WXUNUSED(pWnd), WXUINT WXUNUSE
 #endif // wxUSE_CTL3D
 
     HDC hdc = (HDC)pDC;
 #endif // wxUSE_CTL3D
 
     HDC hdc = (HDC)pDC;
-    if (GetParent()->GetTransparentBackground())
-        SetBkMode(hdc, TRANSPARENT);
-    else
-        SetBkMode(hdc, OPAQUE);
-
     wxColour colBack = GetBackgroundColour();
 
     if (!IsEnabled())
     wxColour colBack = GetBackgroundColour();
 
     if (!IsEnabled())
@@ -870,8 +933,8 @@ LRESULT APIENTRY _EXPORT wxRadioBtnWndProc(HWND hwnd,
                 NMHDR* hdr = (NMHDR *)lParam;
                 if ( hdr->code == TTN_NEEDTEXT )
                 {
                 NMHDR* hdr = (NMHDR *)lParam;
                 if ( hdr->code == TTN_NEEDTEXT )
                 {
-                    wxRadioBox *radiobox = (wxRadioBox *)
-                        ::GetWindowLong(hwnd, GWL_USERDATA);
+                    wxRadioBox *
+                        radiobox = (wxRadioBox *)wxGetWindowUserData(hwnd);
 
                     wxCHECK_MSG( radiobox, 0,
                                  wxT("radio button without radio box?") );
 
                     wxCHECK_MSG( radiobox, 0,
                                  wxT("radio button without radio box?") );
@@ -892,8 +955,7 @@ LRESULT APIENTRY _EXPORT wxRadioBtnWndProc(HWND hwnd,
 
         case WM_KEYDOWN:
             {
 
         case WM_KEYDOWN:
             {
-                wxRadioBox *radiobox = (wxRadioBox *)
-                    ::GetWindowLong(hwnd, GWL_USERDATA);
+                wxRadioBox *radiobox = (wxRadioBox *)wxGetWindowUserData(hwnd);
 
                 wxCHECK_MSG( radiobox, 0, wxT("radio button without radio box?") );
 
 
                 wxCHECK_MSG( radiobox, 0, wxT("radio button without radio box?") );
 
@@ -938,6 +1000,7 @@ LRESULT APIENTRY _EXPORT wxRadioBtnWndProc(HWND hwnd,
                     if ( selNew != selOld )
                     {
                         radiobox->SetSelection(selNew);
                     if ( selNew != selOld )
                     {
                         radiobox->SetSelection(selNew);
+                        radiobox->SetFocus();
 
                         // emulate the button click
                         radiobox->SendNotificationEvent();
 
                         // emulate the button click
                         radiobox->SendNotificationEvent();
@@ -948,25 +1011,51 @@ LRESULT APIENTRY _EXPORT wxRadioBtnWndProc(HWND hwnd,
             }
             break;
 
             }
             break;
 
+        case WM_SETFOCUS:
+        case WM_KILLFOCUS:
+            {
+                wxRadioBox *radiobox = (wxRadioBox *)wxGetWindowUserData(hwnd);
+
+                wxCHECK_MSG( radiobox, 0, wxT("radio button without radio box?") );
+
+                // if we don't do this, no focus events are generated for the
+                // radiobox and, besides, we need to notify the parent about
+                // the focus change, otherwise the focus handling logic in
+                // wxControlContainer doesn't work
+                if ( message == WM_SETFOCUS )
+                    radiobox->HandleSetFocus((WXHWND)wParam);
+                else
+                    radiobox->HandleKillFocus((WXHWND)wParam);
+            }
+            break;
+
 #ifdef __WIN32__
         case WM_HELP:
             {
 #ifdef __WIN32__
         case WM_HELP:
             {
-                wxRadioBox *radiobox = (wxRadioBox *)
-                        ::GetWindowLong(hwnd, GWL_USERDATA);
+                wxRadioBox *radiobox = (wxRadioBox *)wxGetWindowUserData(hwnd);
 
                 wxCHECK_MSG( radiobox, 0, wxT("radio button without radio box?") );
 
                 bool processed = TRUE;
 
 
                 wxCHECK_MSG( radiobox, 0, wxT("radio button without radio box?") );
 
                 bool processed = TRUE;
 
+                // HELPINFO doesn't seem to be supported on WinCE.
+#ifndef __WXWINCE__
                 HELPINFO* info = (HELPINFO*) lParam;
                 // Don't yet process menu help events, just windows
                 if (info->iContextType == HELPINFO_WINDOW)
                 HELPINFO* info = (HELPINFO*) lParam;
                 // Don't yet process menu help events, just windows
                 if (info->iContextType == HELPINFO_WINDOW)
+#endif
                 {
                     wxWindow* subjectOfHelp = radiobox;
                     bool eventProcessed = FALSE;
                     while (subjectOfHelp && !eventProcessed)
                     {
                 {
                     wxWindow* subjectOfHelp = radiobox;
                     bool eventProcessed = FALSE;
                     while (subjectOfHelp && !eventProcessed)
                     {
-                        wxHelpEvent helpEvent(wxEVT_HELP, subjectOfHelp->GetId(), wxPoint(info->MousePos.x, info->MousePos.y) ) ; // info->iCtrlId);
+                        wxHelpEvent helpEvent(wxEVT_HELP, subjectOfHelp->GetId(),
+#ifdef __WXWINCE__
+                                              wxPoint(0, 0)
+#else
+                                              wxPoint(info->MousePos.x, info->MousePos.y)
+#endif
+                            ) ; // info->iCtrlId);
                         helpEvent.SetEventObject(radiobox);
                         eventProcessed = radiobox->GetEventHandler()->ProcessEvent(helpEvent);
 
                         helpEvent.SetEventObject(radiobox);
                         eventProcessed = radiobox->GetEventHandler()->ProcessEvent(helpEvent);
 
@@ -975,14 +1064,16 @@ LRESULT APIENTRY _EXPORT wxRadioBtnWndProc(HWND hwnd,
                     }
                     processed = eventProcessed;
                 }
                     }
                     processed = eventProcessed;
                 }
+#ifndef __WXWINCE__
                 else if (info->iContextType == HELPINFO_MENUITEM)
                 {
                     wxHelpEvent helpEvent(wxEVT_HELP, info->iCtrlId) ;
                     helpEvent.SetEventObject(radiobox);
                     processed = radiobox->GetEventHandler()->ProcessEvent(helpEvent);
                 }
                 else if (info->iContextType == HELPINFO_MENUITEM)
                 {
                     wxHelpEvent helpEvent(wxEVT_HELP, info->iCtrlId) ;
                     helpEvent.SetEventObject(radiobox);
                     processed = radiobox->GetEventHandler()->ProcessEvent(helpEvent);
                 }
-                else processed = FALSE;
-
+                else
+                    processed = FALSE;
+#endif
                 if (processed)
                     return 0;
 
                 if (processed)
                     return 0;