// wxString xsPropIO::ToString(T value) -> creates a string representation of the given value wxString xsColourDataPropIO::ToString(wxColourData value) { wxString out; out << xsColourPropIO::ToString(value.GetColour()); for(int i = 0; i < 16; i++) { out << wxT("|") << xsColourPropIO::ToString(value.GetCustomColour(i)); } return out; }
void MyFrame::OnColourGalleryButton(wxCommandEvent& evt) { wxRibbonGallery *gallery = wxDynamicCast(evt.GetEventObject(), wxRibbonGallery); if(gallery == NULL) return; m_ribbon->DismissExpandedPanel(); if(gallery->GetSelection()) m_colour_data.SetColour(GetGalleryColour(gallery, gallery->GetSelection(), NULL)); wxColourDialog dlg(this, &m_colour_data); if(dlg.ShowModal() == wxID_OK) { m_colour_data = dlg.GetColourData(); wxColour clr = m_colour_data.GetColour(); // Try to find colour in gallery wxRibbonGalleryItem *item = NULL; for(unsigned int i = 0; i < gallery->GetCount(); ++i) { item = gallery->GetItem(i); if(GetGalleryColour(gallery, item, NULL) == clr) break; else item = NULL; } // Colour not in gallery - add it if(item == NULL) { item = AddColourToGallery(gallery, clr.GetAsString(wxC2S_HTML_SYNTAX), m_bitmap_creation_dc, &clr); gallery->Realise(); } // Set selection gallery->EnsureVisible(item); gallery->SetSelection(item); // Send an event to respond to the selection change wxRibbonGalleryEvent dummy(wxEVT_RIBBONGALLERY_SELECTED, gallery->GetId()); dummy.SetEventObject(gallery); dummy.SetGallery(gallery); dummy.SetGalleryItem(item); ProcessWindowEvent(dummy); } }
wxColour wxGetColourFromUser(wxWindow *parent, const wxColour& colInit, const wxString& caption) { static wxColourData data; data.SetChooseFull(true); if ( colInit.Ok() ) { data.SetColour((wxColour &)colInit); // const_cast } wxColour colRet; wxColourDialog dialog(parent, &data); if (!caption.empty()) dialog.SetTitle(caption); if ( dialog.ShowModal() == wxID_OK ) { colRet = dialog.GetColourData().GetColour(); } //else: leave it invalid return colRet; }
//--------------------------------------------------------- bool DLG_Color(long &_Colour) { static wxColourData Colours; Colours.SetChooseFull(true); wxColour Colour(SG_GET_R(_Colour), SG_GET_G(_Colour), SG_GET_B(_Colour)); wxColourDialog dlg(MDI_Get_Top_Window(), &Colours); dlg.GetColourData().SetColour(Colour); if( dlg.ShowModal() == wxID_OK ) { Colours = dlg.GetColourData(); Colour = dlg.GetColourData().GetColour(); _Colour = Get_Color_asInt(Colour); return( true ); } return( false ); }
/////////////////////////////////////////////////////////////////////////////// // Iterates over all the custom colors in colorData and builds a delimited // string representation of the information. This information can be persisted // by the application and reloaded later by calling Load. // tstring CustomColors::Save( wxColourData& colorData ) { tostringstream result; for ( i32 colorIndex = 0; colorIndex < NumColors; ++colorIndex ) { if ( colorIndex > 0 ) { result << s_ColorDelimiter; } const wxColour& color = colorData.GetCustomColour( colorIndex ); if ( color.IsOk() ) { // GetAsString returns HTML format (example: #FF00FF). Strip the leading #. result << color.GetAsString( wxC2S_HTML_SYNTAX ).substr( 1 ).c_str(); } } return result.str(); }
/////////////////////////////////////////////////////////////////////////////// // Populates the custom colors of colorData with the values stored in the info // string. The info string is expected to have been generated by calling the // above Save function. // void CustomColors::Load( wxColourData& colorData, const tstring& info ) { if ( !info.empty() ) { std::vector< tstring > colors; Tokenize( info, colors, s_ColorDelimiter ); std::vector< tstring >::const_iterator colorItr = colors.begin(); std::vector< tstring >::const_iterator colorEnd = colors.end(); for ( i32 colorIndex = 0; colorItr != colorEnd && colorIndex < NumColors; ++colorItr, ++colorIndex ) { const tstring& colorStr = *colorItr; if ( colorStr.length() >= 6 ) { u32 red = 0; u32 green = 0; u32 blue = 0; _stscanf( colorStr.c_str(), TXT( "%02X%02X%02X" ), &red, &green, &blue ); colorData.SetCustomColour( colorIndex, wxColour( (u8)red, (u8)green, (u8)blue ) ); } } } }