00001 #include <creaImageIOWxAttributeSelectionPanel.h>
00002 #include <creaImageIOSystem.h>
00003
00004 #include <creaImageIOGimmick.h>
00005 #ifdef _DEBUG
00006 #define new DEBUG_NEW
00007 #endif
00008 namespace creaImageIO
00009 {
00010 const int ID_COMBO = 180;
00011
00012 WxAttributeSelectionPanel::WxAttributeSelectionPanel(wxWindow *parent,
00013 wxDialog* dial,
00014 WxGimmickView* view,
00015 std::vector<std::string> sAtts,
00016 std::vector<std::string> nsAtts,
00017 int numLev)
00018 : wxPanel( parent,
00019 -1, wxDefaultPosition,
00020 wxDefaultSize,
00021 wxRESIZE_BORDER |
00022 wxSYSTEM_MENU |
00023 wxCLOSE_BOX |
00024 wxMAXIMIZE_BOX |
00025 wxMINIMIZE_BOX |
00026 wxCAPTION
00027 ),
00028 dialog(dial),
00029 shownA(sAtts),
00030 notShownA(nsAtts),
00031 mView(view)
00032 {
00033 GimmickDebugMessage(1,"WxCustomizeConfigPanel::WxCustomizeConfigPanel"
00034 <<std::endl);
00035 wxStaticText * aa=new wxStaticText(this,-1,_T(" Currently shown attributes for level: "), wxPoint(5,10));
00036 wxArrayString as;
00037 std::stringstream out;
00038 for(int i=1;i<=numLev;i++)
00039 {
00040 out<<i;
00041 as.Add(crea::std2wx(out.str()));
00042 out.str("");
00043 }
00044 levels=new wxComboBox(this, ID_COMBO,_T("1"),wxPoint(190, 5),wxDefaultSize,as);
00045 wxStaticText * na=new wxStaticText(this,-1,_T(" Currently hidden attributes: "), wxPoint(255,10));
00046
00047 shownAtts=new wxListCtrl(this, wxID_ANY, wxPoint(5,30), wxSize(160,90), wxLC_REPORT | wxLC_NO_HEADER );
00048
00049 shownAtts->InsertColumn(0,
00050 crea::std2wx(""),
00051 wxLIST_FORMAT_LEFT);
00052 shownAtts->SetColumnWidth(0,155);
00053 shownAtts->Show();
00054
00055 wxButton *add = new wxButton(this,wxID_ANY,_T(">>"), wxPoint(170,50) );
00056 Connect( add->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxAttributeSelectionPanel::OnAdd );
00057
00058 wxButton *remove = new wxButton(this,wxID_ANY,_T("<<"), wxPoint(170,70) );
00059 Connect( remove->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxAttributeSelectionPanel::OnRemove );
00060
00061 notShownAtts=new wxListCtrl(this, wxID_ANY, wxPoint(255,30), wxSize(160,90), wxLC_REPORT | wxLC_NO_HEADER );
00062
00063 notShownAtts->InsertColumn(0,
00064 crea::std2wx(""),
00065 wxLIST_FORMAT_LEFT);
00066 notShownAtts->SetColumnWidth(0,155);
00067 notShownAtts->Show();
00068 LoadCtrls();
00069
00070 wxButton *save = new wxButton(this,wxID_ANY,_T("Save Changes"), wxPoint(5,130) );
00071 Connect( save->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxAttributeSelectionPanel::OnSaveConfig );
00072
00073 Layout();
00074 }
00075
00077 WxAttributeSelectionPanel::~WxAttributeSelectionPanel()
00078 {
00079 GimmickDebugMessage(1,"WxAttributeSelectionPanel::~WxAttributeSelectionPanel"
00080 <<std::endl);
00081 }
00082
00083 void WxAttributeSelectionPanel::OnSaveConfig(wxCommandEvent& event)
00084 {
00085 int n=levels->GetSelection();
00086 if(n<0){n=0;}
00087 mView->OnAttributesChanged(notShownA,n);
00088 dialog->Destroy();
00089 }
00090
00091 void WxAttributeSelectionPanel::OnAdd(wxCommandEvent& event)
00092 {
00093 long item = -1;
00094 for ( ;; )
00095 {
00096 item = shownAtts->GetNextItem(item,
00097 wxLIST_NEXT_ALL,
00098 wxLIST_STATE_SELECTED);
00099 if ( item == -1 )
00100 break;
00101
00102 std::string change = crea::wx2std(shownAtts->GetItemText(item));
00103 std::vector<std::string>::iterator it;
00104 bool found=false;
00105 for(it=shownA.begin();it!=shownA.end()&&!found;++it)
00106 {
00107 if((*it).compare(change)==0)
00108 {
00109 found=true;
00110 }
00111 }
00112 shownA.erase(it-1);
00113 notShownA.push_back(change);
00114 }
00115 LoadCtrls();
00116
00117 }
00118
00119 void WxAttributeSelectionPanel::OnRemove(wxCommandEvent& event)
00120 {
00121
00122 long item = -1;
00123 for ( ;; )
00124 {
00125 item = notShownAtts->GetNextItem(item,
00126 wxLIST_NEXT_ALL,
00127 wxLIST_STATE_SELECTED);
00128 if ( item == -1 )
00129 break;
00130
00131 std::string change = crea::wx2std(notShownAtts->GetItemText(item));
00132 std::vector<std::string>::iterator it;
00133 bool found=false;
00134 for(it=notShownA.begin();it!=notShownA.end()&&!found;++it)
00135 {
00136 if((*it).compare(change)==0)
00137 {
00138 found=true;
00139 }
00140 }
00141 notShownA.erase(it-1);
00142 shownA.push_back(change);
00143
00144 }
00145 LoadCtrls();
00146
00147 }
00148
00149
00150 void WxAttributeSelectionPanel::LoadCtrls()
00151 {
00152
00153 wxListItem item;
00154 item.SetMask(wxLIST_MASK_STATE |
00155 wxLIST_MASK_TEXT |
00156
00157 wxLIST_MASK_DATA |
00158
00159 wxLIST_MASK_FORMAT
00160 );
00161 std::vector<std::string>::iterator it;
00162 shownAtts->DeleteAllItems();
00163 notShownAtts->DeleteAllItems();
00164 for(it=shownA.begin();it!=shownA.end();++it)
00165 {
00166 item.SetText(crea::std2wx(*it));
00167 shownAtts->InsertItem(item);
00168 }
00169
00170
00171 for(it=notShownA.begin();it!=notShownA.end();++it)
00172 {
00173 item.SetText(crea::std2wx(*it));
00174 notShownAtts->InsertItem(item);
00175 }
00176
00177 }
00178 void WxAttributeSelectionPanel::OnComboChange(wxCommandEvent& event)
00179 {
00180 int n=levels->GetSelection()+1;
00181 mView->GetVisibleAttributes(shownA,notShownA,n);
00182 LoadCtrls();
00183 }
00184
00185
00186 BEGIN_EVENT_TABLE(WxAttributeSelectionPanel, wxPanel)
00187 EVT_COMBOBOX (ID_COMBO,WxAttributeSelectionPanel::OnComboChange)
00188 END_EVENT_TABLE()
00189
00190
00191 }
00192
00193