+ wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
+
+ wxCHECK_RET( tlw, wxT("button without top level window?") );
+
+ wxWindow* pWinOldDefault = tlw->GetDefaultItem();
+
+ tlw->SetTmpDefaultItem(this);
+ SetDefaultStyle( wxDynamicCast(pWinOldDefault, wxButton), false);
+ SetDefaultStyle( this, true );
+} // end of wxButton::SetTmpDefault
+
+void wxButton::UnsetTmpDefault()
+{
+ wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
+
+ wxCHECK_RET( tlw, wxT("button without top level window?") );
+
+ tlw->SetTmpDefaultItem(NULL);
+
+ wxWindow* pWinOldDefault = tlw->GetDefaultItem();
+
+ SetDefaultStyle( this, false );
+ SetDefaultStyle( wxDynamicCast(pWinOldDefault, wxButton), true );
+} // end of wxButton::UnsetTmpDefault
+
+void wxButton::SetDefaultStyle(
+ wxButton* pBtn
+, bool bOn
+)
+{
+ long lStyle;
+ //
+ // We may be called with NULL pointer -- simpler to do the check here than
+ // in the caller which does wxDynamicCast()
+ //
+ if (!pBtn)
+ return;
+
+ //
+ // First, let DefDlgProc() know about the new default button
+ //
+ if (bOn)
+ {
+ if (!wxTheApp->IsActive())
+ return;
+
+ //
+ // In OS/2 the dialog/panel doesn't really know it has a default
+ // button, the default button simply has that style. We'll just
+ // simulate by setting focus to it
+ //
+ pBtn->SetFocus();
+ }
+ lStyle = ::WinQueryWindowULong(GetHwndOf(pBtn), QWL_STYLE);
+ if (!(lStyle & BS_DEFAULT) == bOn)
+ {
+ if ((lStyle & BS_USERBUTTON) != BS_USERBUTTON)
+ {
+ if (bOn)
+ lStyle |= BS_DEFAULT;
+ else
+ lStyle &= ~BS_DEFAULT;
+ ::WinSetWindowULong(GetHwndOf(pBtn), QWL_STYLE, lStyle);
+ }
+ else
+ {
+ //
+ // Redraw the button - it will notice itself that it's not the
+ // default one any longer
+ //
+ pBtn->Refresh();
+ }
+ }
+} // end of wxButton::UpdateDefaultStyle
+
+// ----------------------------------------------------------------------------
+// event/message handlers
+// ----------------------------------------------------------------------------
+
+bool wxButton::OS2Command(WXUINT uParam, WXWORD WXUNUSED(wId))
+{
+ bool bProcessed = false;
+
+ switch (uParam)
+ {
+ case BN_CLICKED: // normal buttons send this
+ case BN_DBLCLICKED: // owner-drawn ones also send this
+ bProcessed = SendClickEvent();
+ break;
+ }
+
+ return bProcessed;
+} // end of wxButton::OS2Command
+
+WXHBRUSH wxButton::OnCtlColor( WXHDC WXUNUSED(pDC),
+ WXHWND WXUNUSED(pWnd),
+ WXUINT WXUNUSED(nCtlColor),
+ WXUINT WXUNUSED(uMessage),
+ WXWPARAM WXUNUSED(wParam),
+ WXLPARAM WXUNUSED(lParam) )
+{
+ wxBrush* pBackgroundBrush = wxTheBrushList->FindOrCreateBrush( GetBackgroundColour()
+ ,wxSOLID
+ );
+
+ return (WXHBRUSH)pBackgroundBrush->GetResourceHandle();
+} // end of wxButton::OnCtlColor
+
+void wxButton::MakeOwnerDrawn()
+{
+ long lStyle = 0L;
+
+ lStyle = ::WinQueryWindowULong(GetHwnd(), QWL_STYLE);
+ if ((lStyle & BS_USERBUTTON) != BS_USERBUTTON)
+ {
+ //
+ // Make it so
+ //
+ lStyle |= BS_USERBUTTON;
+ ::WinSetWindowULong(GetHwnd(), QWL_STYLE, lStyle);
+ }
+} // end of wxButton::MakeOwnerDrawn
+
+WXDWORD wxButton::OS2GetStyle(
+ long lStyle
+, WXDWORD* pdwExstyle
+) const
+{
+ //
+ // Buttons never have an external border, they draw their own one
+ //
+ WXDWORD dwStyle = wxControl::OS2GetStyle( (lStyle & ~wxBORDER_MASK) | wxBORDER_NONE
+ ,pdwExstyle
+ );
+
+ //
+ // We must use WS_CLIPSIBLINGS with the buttons or they would draw over
+ // each other in any resizable dialog which has more than one button in
+ // the bottom
+ //
+ dwStyle |= WS_CLIPSIBLINGS;
+ return dwStyle;
+} // end of wxButton::OS2GetStyle
+
+MRESULT wxButton::WindowProc( WXUINT uMsg,
+ WXWPARAM wParam,
+ WXLPARAM lParam )
+{
+ //
+ // When we receive focus, we want to temporary become the default button in
+ // our parent panel so that pressing "Enter" would activate us -- and when
+ // losing it we should restore the previous default button as well
+ //
+ if (uMsg == WM_SETFOCUS)
+ {
+ if (SHORT1FROMMP(lParam) == TRUE)
+ SetTmpDefault();
+ else
+ UnsetTmpDefault();
+
+ //
+ // Let the default processign take place too
+ //
+ }
+
+ else if (uMsg == WM_BUTTON1DBLCLK)
+ {
+ //
+ // Emulate a click event to force an owner-drawn button to change its
+ // appearance - without this, it won't do it
+ //
+ (void)wxControl::OS2WindowProc( WM_BUTTON1DOWN
+ ,wParam
+ ,lParam
+ );
+
+ //
+ // And conitnue with processing the message normally as well
+ //
+ }