preserve custom colours between calls to wxGetColourFromUser(), also allow passing a custom wxColourData to it (modified patch 1832582)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50056 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2007-11-18 19:33:34 +00:00
parent 2349ba4cf9
commit e6ef9ea4ed
7 changed files with 162 additions and 32 deletions

View File

@@ -1419,24 +1419,56 @@ wxString wxGetPasswordFromUser(const wxString& message,
#if wxUSE_COLOURDLG
wxColour wxGetColourFromUser(wxWindow *parent, const wxColour& colInit, const wxString& caption)
wxColour wxGetColourFromUser(wxWindow *parent,
const wxColour& colInit,
const wxString& caption,
wxColourData *ptrData)
{
// contains serialized representation of wxColourData used the last time
// the dialog was shown: we want to reuse it the next time in order to show
// the same custom colours to the user (and we can't just have static
// wxColourData itself because it's a GUI object and so should be destroyed
// before GUI shutdown and doing it during static cleanup is too late)
static wxString s_strColourData;
wxColourData data;
data.SetChooseFull(true);
if ( colInit.Ok() )
if ( !ptrData )
{
data.SetColour((wxColour &)colInit); // const_cast
ptrData = &data;
if ( !s_strColourData.empty() )
{
if ( !data.FromString(s_strColourData) )
{
wxFAIL_MSG( "bug in wxColourData::FromString()?" );
}
#ifdef __WXMSW__
// we don't get back the "choose full" flag value from the native
// dialog and so we can't preserve it between runs, so we decide to
// always use it as it seems better than not using it (user can
// just ignore the extra controls in the dialog but having to click
// a button each time to show them would be very annoying
data.SetChooseFull(true);
#endif // __WXMSW__
}
}
if ( colInit.IsOk() )
{
ptrData->SetColour(colInit);
}
wxColour colRet;
wxColourDialog dialog(parent, &data);
wxColourDialog dialog(parent, ptrData);
if (!caption.empty())
dialog.SetTitle(caption);
if ( dialog.ShowModal() == wxID_OK )
{
colRet = dialog.GetColourData().GetColour();
*ptrData = dialog.GetColourData();
colRet = ptrData->GetColour();
s_strColourData = ptrData->ToString();
}
//else: leave it invalid
//else: leave colRet invalid
return colRet;
}