BoxDlg.cpp
gehe zur Dokumentation dieser Datei
00001 
00114 // ---------------------------------------------------------------------------
00115 // headers
00116 // ---------------------------------------------------------------------------
00117 
00118 // For compilers that support precompilation, includes "wx/wx.h".
00119 #include "Defs.h"
00120 #include <wx/wxprec.h>
00121 #include <wx/gdicmn.h>
00122 
00123 #ifdef __BORLANDC__
00124 #pragma hdrstop
00125 #endif
00126 
00127 void MutaborBoxSettings::SetBoxNumber (int nr) {
00128         wxASSERT(boxNumber);
00129         if (!boxNumber) return;
00130         int m;
00131         if (nr > (m = boxNumber->GetMax())) nr = m;
00132         if (nr < (m = boxNumber->GetMin())) nr = m;
00133         boxNumber -> SetValue(nr);
00134 }
00135 
00136 void InputFilterPanel::AddPage(wxPanel * panel, const wxString & label, 
00137                                bool selected, MutInputDeviceShape * shape)
00138 {
00139         inputDevice->InvalidateBestSize();
00140         int n = inputDevice->GetPageCount();
00141         if(inputDevice -> InsertPage(n,panel, label, selected)) {
00142                 wxChoice * choice = inputDevice->GetChoiceCtrl();
00143                 choice->SetClientObject(n,new InputShapeData(shape));
00144         } else UNREACHABLEC;
00145 }
00146 
00147 wxWindow * InputFilterPanel::GetCurrentDevicePage()
00148 {
00149         return inputDevice->GetCurrentPage();
00150 }
00151 
00152 MutInputDeviceShape * InputFilterPanel::GetCurrentSelection()
00153 {
00154         if (!inputDevice) {
00155                 UNREACHABLEC;
00156                 return NULL;
00157         }
00158         wxChoice * choice = inputDevice->GetChoiceCtrl();
00159         if (!choice) {
00160                 UNREACHABLEC;
00161                 return NULL;
00162         }
00163         InputShapeData * data = dynamic_cast<InputShapeData *> 
00164         (choice->GetClientObject(choice->GetSelection()));
00165         if (!data) {
00166                 UNREACHABLEC;
00167                 return NULL;
00168         }
00169         return data->GetDevice();
00170 }
00171 
00172 
00173 void OutputFilterPanel::AddPage(wxPanel * panel, const wxString & label, 
00174                                bool selected, MutOutputDeviceShape * shape)
00175 {
00176         outputDevice->InvalidateBestSize();
00177         int n = outputDevice->GetPageCount();
00178         if(outputDevice -> InsertPage(n,panel, label, selected)) {
00179                 wxChoice * choice = outputDevice->GetChoiceCtrl();
00180                 choice->SetClientObject(n, new OutputShapeData(shape));
00181         } else UNREACHABLEC;
00182 }
00183 
00184 wxWindow * OutputFilterPanel::GetCurrentDevicePage()
00185 {
00186         return outputDevice->GetCurrentPage();
00187 }
00188 
00189 MutOutputDeviceShape * OutputFilterPanel::GetCurrentSelection()
00190 {
00191         if (!outputDevice) {
00192                 UNREACHABLEC;
00193                 return NULL;
00194         }
00195         wxChoice * choice = outputDevice->GetChoiceCtrl();
00196         if (!choice) {
00197                 UNREACHABLEC;
00198                 return NULL;
00199         }
00200         OutputShapeData * data = dynamic_cast<OutputShapeData *> 
00201         (choice->GetClientObject(choice->GetSelection()));
00202         if (!data) {
00203                 UNREACHABLEC;
00204                 return NULL;
00205         }
00206         return data->GetDevice();
00207 }
00208 
00209 IMPLEMENT_DYNAMIC_CLASS( RoutePanel, RoutePanelBase )
00210 
00211 
00217 MutBoxShape * RoutePanel::GetBox() { 
00218         if (!box) {
00219                 UNREACHABLEC;
00220                 return NULL;
00221         }
00222         BoxShapeData * data = dynamic_cast<BoxShapeData *> 
00223         (box->GetClientObject(box->GetSelection()));
00224         if (!data) {
00225                 UNREACHABLEC;
00226                 return NULL;
00227         }
00228         return data->GetBox();
00229 }
00230 
00231 
00232 int RoutePanel::AddBox(MutBoxShape * boxShape, bool selected) {
00233         int number;
00234         if (boxShape)
00235                 number = box->Append(boxShape->GetLabel(), new BoxShapeData(boxShape));
00236         else number = box->Append(_T("New Box"), new BoxShapeData(NULL));
00237 #ifdef DEBUG
00238         if (boxShape) {
00239                 DEBUGLOG(dialog,_T("Entry box Id %d at Entry No. %d"),boxShape->GetBoxId(),number);
00240         } else {
00241                 DEBUGLOG(dialog,_T("Entry 'new box' at Entry No. %d"),number);
00242         }
00243 #endif
00244         if (selected) box->SetSelection(number);
00245         return number;
00246 }
00247 
00248 void RoutePanel::EnableRoute(bool enable)
00249 {
00250         
00251         Enable(enable);
00252         if (inPanel)  inPanel  -> Enable(enable);
00253         if (outPanel) outPanel -> Enable(enable);
00254         Show(enable);
00255         if (inPanel) inPanel -> Show(enable);
00256         if (outPanel) outPanel -> Show(enable);
00257 //      Layout();
00258 //      GetSizer()->SetSizeHints(this);
00259 //      Fit();
00260 //      GetParent()->GetSizer()->SetSizeHints(GetParent());
00261 //      GetParent()->FitInside();
00262 }
00263 
00264 BEGIN_EVENT_TABLE( RouteRemoveButton, wxButton )
00265 EVT_BUTTON(wxID_REMOVE, RouteRemoveButton::RemoveButtonPressed)
00266 END_EVENT_TABLE()
00267 IMPLEMENT_DYNAMIC_CLASS( RouteRemoveButton, wxButton )
00268 
00269 
00270 bool RouteRemoveButton::Create(RoutePanel * route, wxWindow* parent, wxWindowID id, const wxString&  label, 
00271             const wxPoint&  pos, const wxSize&  size, 
00272             long style, const wxValidator&  validator, const wxString&  name) {
00273         bool created = wxButton::Create(parent, id, label, pos, size, style, validator, name);
00274         panel = route;
00275         if (created) {
00276                 // Avoid flipping of size.
00277                 EnableRoute(false);
00278                 wxSize disabledSize = DoGetBestSize();
00279                 DEBUGLOG(dialog,_T("disabledSize = (%d,%d)"),disabledSize.x,disabledSize.y);
00280                 EnableRoute(true);
00281                 wxSize enabledSize = DoGetBestSize();
00282                 DEBUGLOG(dialog,_T("enabledSize = (%d,%d)"),enabledSize.x,enabledSize.y);
00283                 SetInitialSize(wxSize(std::max(disabledSize.x,enabledSize.x),std::max(disabledSize.y,enabledSize.y)));
00284         }
00285         return created;
00286 }
00287 
00288 void RouteRemoveButton::EnableRoute(bool enable)
00289 {
00290         SetLabel(enable?_("Remove Route"):_("Undelete Route"));
00291         if (panel) 
00292                 panel->EnableRoute(enable);
00293 }
00294 
00295 void RouteRemoveButton::RemoveButtonPressed( wxCommandEvent& event )
00296 {
00297         if (panel) 
00298                 EnableRoute(!panel->IsEnabled());
00299 }
00300 
00301 BEGIN_EVENT_TABLE( BoxDlg, BoxDlgBase)
00302 EVT_BUTTON(::wxID_ADD, BoxDlg::AddButtonPressed)
00303 EVT_BUTTON( ::wxID_REMOVE, BoxDlg::OnRemoveClick )
00304 END_EVENT_TABLE()
00305 IMPLEMENT_DYNAMIC_CLASS( BoxDlg, BoxDlgBase )
00306 
00307 
00308 BoxDlg::BoxDlg(wxWindow * parent):BoxDlgBase(parent) {
00309         if (boxType)
00310                 boxTypeChoice = boxType -> GetChoiceCtrl();
00311         else
00312                 boxTypeChoice = NULL;
00313         InitializeBoxTypes();
00314 }
00315 
00316 void BoxDlg::InitializeBoxTypes() {
00317 //      int i = 0;
00318         wxASSERT(boxType);
00319         if (!boxType) {
00320                 noBoxPanel = NULL;
00321                 mutaborBoxPanel = NULL;
00322                 guidoFileBoxPanel = NULL;
00323                 return;
00324         }
00325         noBoxPanel = new NoBoxSettings(this);
00326         boxType -> AddPage(noBoxPanel,_("No box / thru mode"));
00327 //      boxTypeChoice->SetClientObject(i++, new ClientData (NoBox));
00328         
00329         mutaborBoxPanel = new MutaborBoxSettings(this);
00330         boxType -> AddPage(mutaborBoxPanel,_("Mutabor box"));
00331 //      boxTypeChoice->SetClientObject(i++, new ClientData (Box0));
00332         
00333         guidoFileBoxPanel = new GuidoFileBoxSettings(this);
00334         boxType -> AddPage(guidoFileBoxPanel,_("GUIDO file box"));
00335 //      boxTypeChoice->SetClientObject(i++, new ClientData (GmnBox));
00336 }
00337 
00338 wxSize BoxDlg::DoGetBestSize() const 
00339 {
00340         wxRect screen = wxGetClientDisplayRect();
00341         wxSize size(0,0);
00342         wxSize routesSize = routeWindow->ClientToWindowSize(routeWindow->GetBestVirtualSize());
00343         wxSize enhancedRoutesSize = ClientToWindowSize(routesSize);
00344         size = BoxDlgBase::DoGetBestSize();
00345         size.y += routesSize.y;
00346         size.x = std::min(std::max(enhancedRoutesSize.x,size.x),screen.width);
00347         size.y = std::min(size.y, screen.height);
00348         return size;
00349 }
00350 
00351 
00352 int BoxDlg::GetBoxType() const {
00353         wxWindow * current = boxType->GetCurrentPage();
00354         if (current == noBoxPanel) return NoBox;
00355         else if (current == mutaborBoxPanel) return Box0;
00356         else if (current == guidoFileBoxPanel) return GmnBox;
00357         else {
00358                 UNREACHABLEC;
00359                 return -99;
00360         }
00361 }
00362 
00363 bool BoxDlg::SetBoxType(int type) {
00364         wxASSERT(boxType && boxTypeChoice);
00365         if (!boxType || !boxTypeChoice) return false;
00366         DEBUGLOG(dialog,_T("Setting box type number %d"), type);
00367         if (0<= type && type < MAX_BOX) type = Box0;
00368         wxWindow * page;
00369         switch (type) {
00370                 case NewBox:
00371                 case NoBox:
00372                         page = noBoxPanel;
00373                         break;
00374                 case Box0:
00375                         page = mutaborBoxPanel;
00376                         break;
00377                 case GmnBox:
00378                         page = guidoFileBoxPanel;
00379                         break;
00380                 default:
00381                         return false;
00382                         break;
00383         }
00384         // This is ineffective, but the GUI does not need so much CPU.
00385         for (size_t i = 0; i < boxTypeChoice -> GetCount() && boxType->GetCurrentPage() != page; i++) boxType->SetSelection(i);
00386         
00387         return (boxType->GetCurrentPage() == page);
00388 }
00389 
00390 void BoxDlg::AddButtonPressed( wxCommandEvent& event )
00391 {
00392         MutRouteWnd * parentwin = dynamic_cast<MutRouteWnd *> (m_parent);
00393         if (!parentwin || !routeWindow) UNREACHABLEC;
00394         MutBoxChannelShape::CreateRoutePanel(NULL, parentwin, routeWindow, GetBoxType()==Box0?GetBoxNumber():GetBoxType());
00395         routeWindow->Layout();
00396         routeWindow->InvalidateBestSize();
00397 // routeWindow->GetSizer()->SetSizeHints(routeWindow);
00398 //      routeWindow->FitInside();
00399         Layout();
00400         InvalidateBestSize();
00401         GetSizer()->SetSizeHints(this);
00402         Fit();
00403 }
00404 
00405 void BoxDlg::OnRemoveClick( wxCommandEvent& event )
00406 {
00407         EndModal(::wxID_REMOVE);
00408 }
00409 

Erzeugt am Sun Aug 21 2011 10:51:53 für Mutabor von doxygen 1.7.4