]> Creatis software - creaImageIO.git/blob - src/creaImageIOWxAttributeSelectionPanel.cpp
29538b91040bcd48b3b75667d43ec169b5af9d53
[creaImageIO.git] / src / creaImageIOWxAttributeSelectionPanel.cpp
1 #include <creaImageIOWxAttributeSelectionPanel.h>
2 #include <creaImageIOSystem.h>
3
4 #include <creaImageIOGimmick.h>
5 #ifdef _DEBUG
6 #define new DEBUG_NEW
7 #endif
8 namespace creaImageIO
9 {
10         const int  ID_COMBO             = 180;
11   // CTor
12   WxAttributeSelectionPanel::WxAttributeSelectionPanel(wxWindow *parent, 
13           wxDialog* dial, 
14           WxGimmickView* view,
15           std::vector<std::string> sAtts,
16           std::vector<std::string> nsAtts,
17           int numLev)
18  :   wxPanel( parent, 
19                   -1, wxDefaultPosition, 
20                   wxDefaultSize,
21                   wxRESIZE_BORDER | 
22               wxSYSTEM_MENU  |
23                   wxCLOSE_BOX |
24                   wxMAXIMIZE_BOX | 
25                   wxMINIMIZE_BOX | 
26                   wxCAPTION  
27                ),       
28                    dialog(dial),
29                    shownA(sAtts),
30                    notShownA(nsAtts),
31                    mView(view)
32   {
33     GimmickDebugMessage(1,"WxCustomizeConfigPanel::WxCustomizeConfigPanel"
34                         <<std::endl);
35         wxStaticText * aa=new wxStaticText(this,-1,_T(" Currently shown attributes for level: "), wxPoint(5,10));
36         wxArrayString as;
37         std::stringstream out;
38         for(int i=1;i<=numLev;i++)
39         {
40                 out<<i;
41                 as.Add(crea::std2wx(out.str()));
42                 out.str("");
43         }
44         levels=new wxComboBox(this, ID_COMBO,_T("1"),wxPoint(190, 5),wxDefaultSize,as);
45         wxStaticText * na=new wxStaticText(this,-1,_T(" Currently hidden attributes: "), wxPoint(255,10));
46
47     shownAtts=new wxListCtrl(this, wxID_ANY, wxPoint(5,30), wxSize(160,90), wxLC_REPORT | wxLC_NO_HEADER );
48
49         shownAtts->InsertColumn(0, 
50                                    crea::std2wx(""),
51                                    wxLIST_FORMAT_LEFT);
52         shownAtts->SetColumnWidth(0,155);
53         shownAtts->Show();
54
55         wxButton *add = new wxButton(this,wxID_ANY,_T(">>"), wxPoint(170,50) );
56         Connect( add->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxAttributeSelectionPanel::OnAdd ); 
57
58         wxButton *remove = new wxButton(this,wxID_ANY,_T("<<"), wxPoint(170,70) );
59         Connect( remove->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxAttributeSelectionPanel::OnRemove ); 
60         
61         notShownAtts=new wxListCtrl(this, wxID_ANY, wxPoint(255,30), wxSize(160,90), wxLC_REPORT | wxLC_NO_HEADER );
62
63         notShownAtts->InsertColumn(0, 
64                                    crea::std2wx(""),
65                                    wxLIST_FORMAT_LEFT);
66         notShownAtts->SetColumnWidth(0,155);
67         notShownAtts->Show();
68         LoadCtrls();
69
70         wxButton *save = new wxButton(this,wxID_ANY,_T("Save Changes"), wxPoint(5,130) );
71         Connect( save->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxAttributeSelectionPanel::OnSaveConfig ); 
72    
73     Layout(); 
74   }
75
76   /// Destructor
77   WxAttributeSelectionPanel::~WxAttributeSelectionPanel()
78   {
79     GimmickDebugMessage(1,"WxAttributeSelectionPanel::~WxAttributeSelectionPanel"
80                         <<std::endl);
81   }
82
83   void WxAttributeSelectionPanel::OnSaveConfig(wxCommandEvent& event)
84   {
85           int n=levels->GetSelection();
86           if(n<0){n=0;}
87           mView->OnAttributesChanged(notShownA,n);
88           dialog->Destroy();
89   }
90
91   void WxAttributeSelectionPanel::OnAdd(wxCommandEvent& event)
92   {
93         long item = -1;
94         for ( ;; )
95         {
96                 item = shownAtts->GetNextItem(item,
97                         wxLIST_NEXT_ALL,
98                         wxLIST_STATE_SELECTED);
99                 if ( item == -1 )
100                         break;
101         
102                         std::string change = crea::wx2std(shownAtts->GetItemText(item));
103                         std::vector<std::string>::iterator it;
104                         bool found=false;
105                         for(it=shownA.begin();it!=shownA.end()&&!found;++it)
106                         {
107                                 if((*it).compare(change)==0)
108                                 {
109                                         found=true;
110                                 }
111                         }
112                         shownA.erase(it-1);
113                         notShownA.push_back(change);
114         }
115         LoadCtrls();
116         
117   }
118
119   void WxAttributeSelectionPanel::OnRemove(wxCommandEvent& event)
120   {
121
122         long item = -1;
123         for ( ;; )
124         {
125                 item = notShownAtts->GetNextItem(item,
126                         wxLIST_NEXT_ALL,
127                         wxLIST_STATE_SELECTED);
128                 if ( item == -1 )
129                         break;
130         
131                         std::string change = crea::wx2std(notShownAtts->GetItemText(item));
132                         std::vector<std::string>::iterator it;
133                         bool found=false;
134                         for(it=notShownA.begin();it!=notShownA.end()&&!found;++it)
135                         {
136                                 if((*it).compare(change)==0)
137                                 {
138                                         found=true;
139                                 }
140                         }
141                         notShownA.erase(it-1);
142                         shownA.push_back(change);
143                 
144         }
145         LoadCtrls();    
146           
147   }
148   
149
150   void WxAttributeSelectionPanel::LoadCtrls()
151   {
152
153           wxListItem item;
154             item.SetMask(wxLIST_MASK_STATE | 
155                          wxLIST_MASK_TEXT |
156                          //                      wxLIST_MASK_IMAGE |
157                          wxLIST_MASK_DATA |
158                          //                      wxLIST_MASK_WIDTH |
159                          wxLIST_MASK_FORMAT
160                          );
161         std::vector<std::string>::iterator it;
162         shownAtts->DeleteAllItems();
163         notShownAtts->DeleteAllItems();
164         for(it=shownA.begin();it!=shownA.end();++it)
165         {
166                 item.SetText(crea::std2wx(*it));
167                 shownAtts->InsertItem(item);
168         }
169
170         
171         for(it=notShownA.begin();it!=notShownA.end();++it)
172         {
173                 item.SetText(crea::std2wx(*it));
174                 notShownAtts->InsertItem(item);
175         }
176
177   }
178   void WxAttributeSelectionPanel::OnComboChange(wxCommandEvent& event)
179   {
180       int n=levels->GetSelection()+1;
181           mView->GetVisibleAttributes(shownA,notShownA,n);
182           LoadCtrls();
183   }
184   
185 //======================================================================
186 BEGIN_EVENT_TABLE(WxAttributeSelectionPanel, wxPanel)
187 EVT_COMBOBOX  (ID_COMBO,WxAttributeSelectionPanel::OnComboChange)
188 END_EVENT_TABLE()
189 //======================================================================
190
191 } // EO namespace creaImageIO
192
193