wxRadioButton works under MSW

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/wxUNIVERSAL@8321 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2000-09-10 22:23:05 +00:00
parent 5b1d0de44a
commit 1ca6cc68e0
4 changed files with 174 additions and 24 deletions

View File

@@ -259,7 +259,7 @@ MyUnivFrame::MyUnivFrame(const wxString& title)
wxPoint(10, 150), wxPoint(10, 150),
wxSize(500, 120)); wxSize(500, 120));
box->SetForegroundColour(*wxRED); box->SetForegroundColour(*wxRED);
box->SetBackground(wxBITMAP(bricks), 0, wxTILE); box->SetBackground(bricks_xpm, 0, wxTILE);
x = 15; x = 15;
#define CREATE_STATIC_ALIGN_DEMO(align) \ #define CREATE_STATIC_ALIGN_DEMO(align) \
@@ -280,8 +280,8 @@ MyUnivFrame::MyUnivFrame(const wxString& title)
new wxButton(this, Univ_Button1, _T("&Press me"), wxPoint(10, 300)); new wxButton(this, Univ_Button1, _T("&Press me"), wxPoint(10, 300));
new wxButton(this, Univ_Button2, _T("&And me"), wxPoint(100, 300)); new wxButton(this, Univ_Button2, _T("&And me"), wxPoint(100, 300));
new wxStaticBitmap(this, wxBITMAP(tip), wxPoint(10, 350)); new wxStaticBitmap(this, tip_xpm, wxPoint(10, 350));
new wxStaticBitmap(this, -1, wxBITMAP(tip), wxPoint(50, 350), new wxStaticBitmap(this, -1, tip_xpm, wxPoint(50, 350),
wxDefaultSize, wxSUNKEN_BORDER); wxDefaultSize, wxSUNKEN_BORDER);
#if 0 #if 0
@@ -306,7 +306,7 @@ MyUnivFrame::MyUnivFrame(const wxString& title)
//win->Scroll(10, 0); //win->Scroll(10, 0);
#endif #endif
new wxButton(this, -1, wxBITMAP(open), _T("&Open..."), wxPoint(10, 420)); new wxButton(this, -1, open_xpm, _T("&Open..."), wxPoint(10, 420));
wxBitmap bmp1(wxTheApp->GetStdIcon(wxICON_INFORMATION)), wxBitmap bmp1(wxTheApp->GetStdIcon(wxICON_INFORMATION)),
bmp2(wxTheApp->GetStdIcon(wxICON_WARNING)), bmp2(wxTheApp->GetStdIcon(wxICON_WARNING)),

View File

@@ -74,7 +74,10 @@ bool wxRadioButton::Create(wxWindow *parent,
void wxRadioButton::ChangeValue(bool value) void wxRadioButton::ChangeValue(bool value)
{ {
if ( !IsChecked() && value ) if ( value == IsChecked() )
return;
if ( !IsChecked() )
{ {
// clear all others radio buttons in our group: for this we need to // clear all others radio buttons in our group: for this we need to
// find the radio button which is the first in the group, i.e. the one // find the radio button which is the first in the group, i.e. the one
@@ -119,8 +122,11 @@ void wxRadioButton::ChangeValue(bool value)
SendEvent(); SendEvent();
} }
//else: either nothign chanegd or an attempt was made to clear a checked else // attempt to clear a radio button - this can't be done
// radio button which can't be done {
// but still refresh as ou PRESSED flag changed
Refresh();
}
} }
void wxRadioButton::ClearValue() void wxRadioButton::ClearValue()

View File

@@ -441,6 +441,7 @@ void wxControlRenderer::DrawBitmap(const wxBitmap& bitmap,
{ {
for ( y = 0; y < rect.height; y += height ) for ( y = 0; y < rect.height; y += height )
{ {
// no need to use mask here as we cover the entire window area
m_dc.DrawBitmap(bmp, x, y); m_dc.DrawBitmap(bmp, x, y);
} }
} }

View File

@@ -206,8 +206,18 @@ protected:
wxArrowDirection arrowDir, wxArrowDirection arrowDir,
wxArrowStyle arrowStyle); wxArrowStyle arrowStyle);
// helper of DrawCheckButton // DrawCheckButton/DrawRadioButton helper
void DrawCheckOrRadioButton(wxDC& dc,
const wxString& label,
const wxBitmap& bitmap,
const wxRect& rect,
int flags,
wxAlignment align,
int indexAccel);
// get the standard check/radio button bitmap
wxBitmap GetCheckBitmap(int flags); wxBitmap GetCheckBitmap(int flags);
wxBitmap GetRadioBitmap(int flags);
private: private:
const wxColourScheme *m_scheme; const wxColourScheme *m_scheme;
@@ -1254,6 +1264,106 @@ static char *pressed_unchecked_xpm[] = {
"hhhhhhhhhhhhh" "hhhhhhhhhhhhh"
}; };
static char *checked_radio_xpm[] = {
/* columns rows colors chars-per-pixel */
"13 13 6 1",
" c None",
"w c white",
"b c black",
"d c #7f7f7f",
"g c #c0c0c0",
"h c #e0e0e0",
/* pixels */
" dddd ",
" ddbbbbdd ",
" dbbwwwwbbh ",
" dbwwwwwwgh ",
" dbwwwbbwwwgh",
" dbwwbbbbwwgh",
" dbwwbbbbwwgh",
" dbwwwbbwwwgh",
" dbwwwwwwgh ",
" dggwwwwggh ",
" hhgggghh ",
" hhhh ",
" "
};
static char *pressed_checked_radio_xpm[] = {
/* columns rows colors chars-per-pixel */
"13 13 6 1",
" c None",
"w c white",
"b c black",
"d c #7f7f7f",
"g c #c0c0c0",
"h c #e0e0e0",
/* pixels */
" dddd ",
" ddbbbbdd ",
" dbbggggbbh ",
" dbgggggggh ",
" dbgggbbggggh",
" dbggbbbbgggh",
" dbggbbbbgggh",
" dbgggbbggggh",
" dbgggggggh ",
" dggggggggh ",
" hhgggghh ",
" hhhh ",
" "
};
static char *unchecked_radio_xpm[] = {
/* columns rows colors chars-per-pixel */
"13 13 6 1",
" c None",
"w c white",
"b c black",
"d c #7f7f7f",
"g c #c0c0c0",
"h c #e0e0e0",
/* pixels */
" dddd ",
" ddbbbbdd ",
" dbbwwwwbbh ",
" dbwwwwwwgh ",
" dbwwwwwwwwgh",
" dbwwwwwwwwgh",
" dbwwwwwwwwgh",
" dbwwwwwwwwgh",
" dbwwwwwwgh ",
" dggwwwwggh ",
" hhgggghh ",
" hhhh ",
" "
};
static char *pressed_unchecked_radio_xpm[] = {
/* columns rows colors chars-per-pixel */
"13 13 6 1",
" c None",
"w c white",
"b c black",
"d c #7f7f7f",
"g c #c0c0c0",
"h c #e0e0e0",
/* pixels */
" dddd ",
" ddbbbbdd ",
" dbbggggbbh ",
" dbgggggggh ",
" dbgggggggggh",
" dbgggggggggh",
" dbgggggggggh",
" dbgggggggggh",
" dbgggggggh ",
" dggggggggh ",
" hhgggghh ",
" hhhh ",
" "
};
wxBitmap wxWin32Renderer::GetCheckBitmap(int flags) wxBitmap wxWin32Renderer::GetCheckBitmap(int flags)
{ {
char **xpm; char **xpm;
@@ -1271,13 +1381,30 @@ wxBitmap wxWin32Renderer::GetCheckBitmap(int flags)
return wxBitmap(xpm); return wxBitmap(xpm);
} }
void wxWin32Renderer::DrawCheckButton(wxDC& dc, wxBitmap wxWin32Renderer::GetRadioBitmap(int flags)
const wxString& label, {
const wxBitmap& bitmap, char **xpm;
const wxRect& rect, if ( flags & wxCONTROL_CHECKED )
int flags, {
wxAlignment align, xpm = flags & wxCONTROL_PRESSED ? pressed_checked_radio_xpm
int indexAccel) : checked_radio_xpm;
}
else // unchecked
{
xpm = flags & wxCONTROL_PRESSED ? pressed_unchecked_radio_xpm
: unchecked_radio_xpm;
}
return wxBitmap(xpm);
}
void wxWin32Renderer::DrawCheckOrRadioButton(wxDC& dc,
const wxString& label,
const wxBitmap& bitmap,
const wxRect& rect,
int flags,
wxAlignment align,
int indexAccel)
{ {
// calculate the position of the bitmap and of the label // calculate the position of the bitmap and of the label
wxCoord xBmp, wxCoord xBmp,
@@ -1285,7 +1412,7 @@ void wxWin32Renderer::DrawCheckButton(wxDC& dc,
wxRect rectLabel; wxRect rectLabel;
dc.GetMultiLineTextExtent(label, NULL, &rectLabel.height); dc.GetMultiLineTextExtent(label, NULL, &rectLabel.height);
rectLabel.y = rect.y + (rect.height - rectLabel.height) / 2 - 1; rectLabel.y = rect.y + (rect.height - rectLabel.height) / 2;
if ( align == wxALIGN_RIGHT ) if ( align == wxALIGN_RIGHT )
{ {
@@ -1314,8 +1441,22 @@ void wxWin32Renderer::DrawRadioButton(wxDC& dc,
wxAlignment align, wxAlignment align,
int indexAccel) int indexAccel)
{ {
// FIXME TODO DrawCheckOrRadioButton(dc, label,
DrawCheckButton(dc, label, bitmap, rect, flags, align, indexAccel); bitmap.Ok() ? bitmap : GetRadioBitmap(flags),
rect, flags, align, indexAccel);
}
void wxWin32Renderer::DrawCheckButton(wxDC& dc,
const wxString& label,
const wxBitmap& bitmap,
const wxRect& rect,
int flags,
wxAlignment align,
int indexAccel)
{
DrawCheckOrRadioButton(dc, label,
bitmap.Ok() ? bitmap : GetCheckBitmap(flags),
rect, flags, align, indexAccel);
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -1698,8 +1839,8 @@ bool wxWin32ScrollBarInputHandler::HandleMouseMove(wxControl *control,
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
bool wxWin32CheckboxInputHandler::HandleKey(wxControl *control, bool wxWin32CheckboxInputHandler::HandleKey(wxControl *control,
const wxKeyEvent& event, const wxKeyEvent& event,
bool pressed) bool pressed)
{ {
if ( pressed ) if ( pressed )
{ {
@@ -1711,19 +1852,21 @@ bool wxWin32CheckboxInputHandler::HandleKey(wxControl *control,
action = wxACTION_CHECKBOX_TOGGLE; action = wxACTION_CHECKBOX_TOGGLE;
break; break;
case '-': case WXK_SUBTRACT:
case WXK_NUMPAD_SUBTRACT:
action = wxACTION_CHECKBOX_CHECK; action = wxACTION_CHECKBOX_CHECK;
break; break;
case '+': case WXK_ADD:
case '=': case WXK_NUMPAD_ADD:
case WXK_NUMPAD_EQUAL:
action = wxACTION_CHECKBOX_CLEAR; action = wxACTION_CHECKBOX_CLEAR;
break; break;
} }
if ( !!action ) if ( !!action )
{ {
control->PerformAction(wxACTION_CHECKBOX_TOGGLE); control->PerformAction(action);
return TRUE; return TRUE;
} }