|
From: Emilien K. <cur...@us...> - 2005-08-25 17:06:50
|
Update of /cvsroot/wxdevcenter/StdPlugin/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3150/src Modified Files: BitmapProp.cpp Log Message: Read config and use it to propose many format for bitmap. Index: BitmapProp.cpp =================================================================== RCS file: /cvsroot/wxdevcenter/StdPlugin/src/BitmapProp.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** BitmapProp.cpp 25 Aug 2005 14:18:28 -0000 1.4 --- BitmapProp.cpp 25 Aug 2005 17:06:40 -0000 1.5 *************** *** 11,14 **** --- 11,16 ---- #include <wx/bmpbuttn.h> #include <wx/artprov.h> + #include <wx/confbase.h> + using namespace wxDevCenter; *************** *** 139,142 **** --- 141,145 ---- #define ID_RES_TEXT_CTRL 26 #define ID_RESUNIT_CHOICE 27 + #define ID_AUTOFORMAT_CHOICE 28 BEGIN_EVENT_TABLE(BitmapPropertiesDialog, wxDialog) *************** *** 152,155 **** --- 155,159 ---- EVT_CHOICE(ID_UNIT_CHOICE, BitmapPropertiesDialog::OnChangeUnit) EVT_CHOICE(ID_RESUNIT_CHOICE, BitmapPropertiesDialog::OnChangeUnit) + EVT_CHOICE(ID_AUTOFORMAT_CHOICE, BitmapPropertiesDialog::OnAutoFormat) END_EVENT_TABLE() *************** *** 159,163 **** m_bIsUpdatingCtrl(false) { ! // Création des controles. m_pWidthTextCtrl = new wxTextCtrl(this, ID_WIDTH_TEXT_CTRL, wxT("21.0")); m_pHeightTextCtrl = new wxTextCtrl(this, ID_HEIGHT_TEXT_CTRL, wxT("29.7")); --- 163,168 ---- m_bIsUpdatingCtrl(false) { ! // Création des controles. ! m_pFormatAuto = new wxChoice(this, ID_AUTOFORMAT_CHOICE, wxDefaultPosition, wxDefaultSize, 0, NULL); m_pWidthTextCtrl = new wxTextCtrl(this, ID_WIDTH_TEXT_CTRL, wxT("21.0")); m_pHeightTextCtrl = new wxTextCtrl(this, ID_HEIGHT_TEXT_CTRL, wxT("29.7")); *************** *** 174,177 **** --- 179,184 ---- wxSizer* pGlobalSizer = new wxBoxSizer(wxVERTICAL); + // Format automatique + pGlobalSizer->Add(m_pFormatAuto, 0, wxEXPAND|wxALL, 8); // Zone de taille *************** *** 191,195 **** pGlobalSizer->Add(pSizeSizer, 0, wxEXPAND|wxALL, 8); ! // Zone de résolution wxSizer* pResSizer = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Résolution")); pLineSizer = new wxGridSizer(1, 3, 8, 8); --- 198,202 ---- pGlobalSizer->Add(pSizeSizer, 0, wxEXPAND|wxALL, 8); ! // Zone de résolution wxSizer* pResSizer = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Résolution")); pLineSizer = new wxGridSizer(1, 3, 8, 8); *************** *** 206,209 **** --- 213,276 ---- } + // Destructor. + BitmapPropertiesDialog::~BitmapPropertiesDialog() + { + ClearFormat(); + } + + + // Affiche la taille dans une certaine unitée. + void BitmapPropertiesDialog::ShowSize(const SizeUnit& unit) + { + ShowSize(unit.name); + } + + // Affiche la résolution en une certaine unité. + void BitmapPropertiesDialog::ShowRes(const SizeUnit& unit) + { + ShowRes(unit.name); + } + + // Affiche la taille dans une certaine unitée. + void BitmapPropertiesDialog::ShowSize(const wxString& unit) + { + if(unit.CmpNoCase(wxT("Pixel"))==0 || unit.CmpNoCase(wxT("Pixels"))==0) + { + m_pUnitChoice->SetSelection(0); + } + + for(int l=1; l<m_pUnitChoice->GetCount(); l++) + { + SizeUnit* pUnit = (SizeUnit*) m_pUnitChoice->GetClientData(l); + if(pUnit!=NULL) + { + if(pUnit->name.IsSameAs(unit, false)) + { + m_pUnitChoice->SetSelection(l); + return; + } + } + } + } + + // Affiche la résolution en une certaine unité. + void BitmapPropertiesDialog::ShowRes(const wxString& unit) + { + for(int l=0; l<m_pResUnitChoice->GetCount(); l++) + { + SizeUnit* pUnit = (SizeUnit*) m_pResUnitChoice->GetClientData(l); + if(pUnit!=NULL) + { + if(pUnit->name.IsSameAs(unit, false)) + { + m_pResUnitChoice->SetSelection(l); + return; + } + } + } + } + + + // Mise à jour initiale. void BitmapPropertiesDialog::OnInitialUpdate(wxInitDialogEvent& WXUNUSED(event)) *************** *** 211,215 **** long l, nb = sizeof(SizeUnits)/sizeof(SizeUnit); ! // Ajoute les unités de taille. m_pUnitChoice->Append(wxT("Pixel"), (void*)NULL); for(l=0; l<nb; l++) --- 278,284 ---- long l, nb = sizeof(SizeUnits)/sizeof(SizeUnit); ! ReadAutoFormat(); ! ! // Ajoute les unités de taille. m_pUnitChoice->Append(wxT("Pixel"), (void*)NULL); for(l=0; l<nb; l++) *************** *** 217,221 **** m_pUnitChoice->SetSelection(0); ! // Ajoute les unités de résolution. for(l=0; l<nb; l++) m_pResUnitChoice->Append(wxT("Pixel/") + SizeUnits[l].name, (void*)&SizeUnits[l]); --- 286,290 ---- m_pUnitChoice->SetSelection(0); ! // Ajoute les unités de résolution. for(l=0; l<nb; l++) m_pResUnitChoice->Append(wxT("Pixel/") + SizeUnits[l].name, (void*)&SizeUnits[l]); *************** *** 225,229 **** } ! // Met à jour les controles. void BitmapPropertiesDialog::UpdateCtrl(bool bUpdateSize, bool bUpdateRes) { --- 294,298 ---- } ! // Met à jour les controles. void BitmapPropertiesDialog::UpdateCtrl(bool bUpdateSize, bool bUpdateRes) { *************** *** 250,254 **** } ! // Zone de résolution. if(bUpdateRes) { --- 319,323 ---- } ! // Zone de résolution. if(bUpdateRes) { *************** *** 265,269 **** } ! // Récapitulatif de taille. m_pSizeTextCtrl->SetLabel(wxString::Format(wxT("%dx%d pixels - %gppp"), m_BmpProp.GetSize().x,m_BmpProp.GetSize().y, m_BmpProp.GetRes(Units::Inch))); --- 334,338 ---- } ! // Récapitulatif de taille. m_pSizeTextCtrl->SetLabel(wxString::Format(wxT("%dx%d pixels - %gppp"), m_BmpProp.GetSize().x,m_BmpProp.GetSize().y, m_BmpProp.GetRes(Units::Inch))); *************** *** 271,275 **** } ! // Interception d'un changement d'unté d'affichage. void BitmapPropertiesDialog::OnChangeUnit(wxCommandEvent& WXUNUSED(event)) { --- 340,344 ---- } ! // Interception d'un changement d'unté d'affichage. void BitmapPropertiesDialog::OnChangeUnit(wxCommandEvent& WXUNUSED(event)) { *************** *** 310,314 **** } ! // Interception d'un changement de résolution. void BitmapPropertiesDialog::OnResChanged(wxCommandEvent& WXUNUSED(event)) { --- 379,383 ---- } ! // Interception d'un changement de résolution. void BitmapPropertiesDialog::OnResChanged(wxCommandEvent& WXUNUSED(event)) { *************** *** 343,344 **** --- 412,474 ---- } + // Interception de l'application d'un format. + void BitmapPropertiesDialog::OnAutoFormat(wxCommandEvent& event) + { + if(event.GetSelection()!=wxNOT_FOUND) + { + wxString *pStr = (wxString*) event.GetClientData(); + if(pStr!=NULL) + { + /** Ouvre la config.*/ + wxConfigBase& Config = Application::GetApp().GetConfig()[WXDC_BITMAP_CONFIG_ROOT]; + Config.SetPath(wxT("/formats")); + + wxString strUnit; + wxSize sz; + double dRes; + sz.x = Config.Read(*pStr + wxT("size-x"), 0l); + sz.y = Config.Read(*pStr + wxT("size-y"), 0l); + Config.Read(*pStr + wxT("res"), &dRes, 0.0); + + m_BmpProp.SetSize(sz); + m_BmpProp.SetRes(dRes); + + UpdateCtrl(); + + strUnit = Config.Read(*pStr + wxT("size-unit"), wxT("Pixel")); + ShowSize(strUnit); + strUnit = Config.Read(*pStr + wxT("res-unit"), wxT("Inch")); + ShowRes(strUnit); + + } + } + } + + + // Lit les formats préprogrammés et les insere dans le wxChoice. + void BitmapPropertiesDialog::ReadAutoFormat() + { + /** Ouvre la config.*/ + wxConfigBase& Config = Application::GetApp().GetConfig()[WXDC_BITMAP_CONFIG_ROOT]; + Config.SetPath(wxT("/formats")); + + wxString str; + long dummy; + bool bCont = Config.GetFirstGroup(str, dummy); + while(bCont) + { + str << wxT("/"); + m_pFormatAuto->Append(Config.Read(str + wxT("name"), wxT("Unknow")) , (void*)new wxString(str)); + bCont = Config.GetNextGroup(str, dummy); + } + } + + // Efface tous les formats. + void BitmapPropertiesDialog::ClearFormat() + { + if(m_pFormatAuto==NULL) + return; + m_pFormatAuto->Clear(); + } + + |