BoxShape.cpp
gehe zur Dokumentation dieser Datei
00001 // -*-C++ -*-
00002 
00146 #include "Defs.h"
00147 #include "Global.h"
00148 //#include "wx/wx.h"
00149 #include "BoxShape.h"
00150 #include "DebugRoute.h"
00151 //#include "MutApp.h"
00152 //#include "MutIcon.h"
00153 //#include "MutRouteWnd.h"
00154 //#include "InputDevDlg.h"
00155 //#include "Device.h"
00156 
00157 wxColour BoxColors[MAX_BOX];
00158 
00159 void initBoxColors() {
00160         for (int i = 1; i<= MAX_BOX; i++) {
00161                 int r = ((i & 0x01) << 7 ) | ((i & 0x08) << 3) | ((i & 0x40) >> 1);
00162                 r = r?r-1:0;
00163                 int g = ((i & 0x02) << 6 ) | ((i & 0x10) << 2) | ((i & 0x80) >> 2);
00164                 g = g?g-1:0;
00165                 int b = ((i & 0x04) << 5 ) | ((i & 0x20) << 1) | ((i & 0x100) >> 3);
00166                 b = b?b-1:0;
00167                 DEBUGLOG2(other,_T("Box %d color %x,%x,%x"),i-1,r,g,b);
00168                 BoxColors[i-1]=wxColour(r,g,b);
00169         }
00170 }
00171 
00172 /*
00173   wxColour BoxColors[MAX_BOX]  =
00174   {
00175   wxColour(0xFF, 0x00, 0x00),
00176   wxColour(0x00, 0xFF, 0x00),
00177   wxColour(0x80, 0x80, 0xFF),
00178   wxColour(0xFF, 0xFF, 0x00),
00179   wxColour(0x00, 0xFF, 0xFF),
00180   wxColour(0xFF, 0x00, 0xFF),
00181   wxColour(0xC0, 0xC0, 0xC0),
00182   wxColour(0x40, 0x80, 0x80),
00183   wxColour(0x00, 0x80, 0x00),
00184   wxColour(0x80, 0xFF, 0x00),
00185   wxColour(0xFF, 0xFF, 0x80),
00186   };
00187 */
00188 wxColour BoxColor(int nr)
00189 {
00190 
00191         DEBUGLOG2(other,_T("Color for box %d requested"),nr);
00192         if ( nr == GmnBox )
00193                 return wxNullColour;
00194         else if (nr == NoBox) 
00195                 return wxNullColour;
00196         //      nr %= 11;
00197         nr %= MAX_BOX;
00198         if (nr < 0) nr += MAX_BOX;
00199         DEBUGLOG2(other,_T("Returning Color for Box number %d"),nr);
00200         return BoxColors[nr];
00201 
00202 }
00203 
00204 
00205 
00206 static inline wxSize GetStaticBoxSize( MutBoxIconShape *box )
00207 {
00208         // this has to be done platform by platform as there is no way to
00209         // guess the thickness of a wxStaticBox border
00210         wxSize s  = box->DoGetBestSize();
00211         DEBUGLOGTYPE(other,*box,_T("Best Size: %dx%d"),s.x,s.y);
00212         return s;
00213 }
00214 
00215 IMPLEMENT_CLASS(MutBoxShape, MutBoxIconShape)
00216 
00217 BEGIN_EVENT_TABLE(MutBoxShape, MutBoxIconShape)
00218 EVT_LEFT_DCLICK(MutBoxShape::LeftDblClickEvent)
00219 //EVT_CLOSE(MutDeviceShape::DeleteSelfEvent)
00220 END_EVENT_TABLE()
00221 
00222 wxSizerFlags MutBoxShape::sizerFlags;
00223 int MutBoxShape::maxBoxId = Box0 - 1;
00224 
00225 
00227 bool MutBoxShape::Create(wxWindow * parent,wxWindowID wid, int Id)
00228 {
00229         MutBoxIconShape::Create(parent,wid);
00230         channels = new wxBoxSizer(wxVERTICAL);
00231         SetSizer(channels);
00232         SetAutoLayout(true);
00233 //      m_icon = new MutBoxIconShape(this,-1);
00234         m_icon = this;
00235         SetBoxId(Id,false);
00236         if (!m_icon) return false;
00237         return true;
00238 }
00239 
00240 
00241 void MutBoxShape::SetBoxId(int Id, bool layout) {
00242         boxId = Id;
00243         if (boxId >= maxBoxId) maxBoxId = boxId + 1;
00244         if (m_icon) {
00245                 switch (boxId) {
00246                         case NewBox:
00247                                 m_icon->SetLabel(_("New Box"));
00248                                 m_icon->SetBackgroundStyle(wxBG_STYLE_SYSTEM);
00249                                 break;
00250                         case NoBox:
00251                                 m_icon->SetLabel(_("No Box / Though mode"));
00252                                 m_icon->SetBackgroundStyle(wxBG_STYLE_SYSTEM);
00253                                 break;
00254                         case GmnBox:
00255                                 m_icon->SetLabel(_("GUIDO Box"));
00256                                 m_icon->SetBackgroundColour(BoxColor(boxId));
00257                                 break;
00258                         default:
00259                                 m_icon->SetLabel(wxString::Format(_("Box %d"),
00260                                                                   boxId));
00261                                 m_icon->SetBackgroundColour(BoxColor(boxId));
00262                                 break;
00263                 }
00264                 if (layout) {
00265                         InvalidateBestSize();
00266                         SetInitialSize(wxDefaultSize);
00267                         m_parent->Layout();
00268                 }
00269         }
00270         
00271 }
00272 
00273 
00274 MutBoxChannelShape * MutBoxShape::AddChannel(MutBoxChannelShape * channel) {
00275         if (channel) {
00276                 channels->Add(channel,0,wxALIGN_CENTER_HORIZONTAL | wxEXPAND);
00277 #ifdef DEBUG
00278                 wxSize s = channel->GetBestSize();
00279                 DEBUGLOG (other, _T("channel best size: %dx%d"),s.x,s.y);
00280 #endif          
00281                 InvalidateBestSize();
00282                 SetInitialSize(wxDefaultSize);
00283                 m_parent->Layout();
00284         }
00285         return channel;
00286 }
00287 
00288 MutBoxChannelShape * MutBoxShape::AddChannel(Route * route)
00289 {
00290         DEBUGLOG (other, _T("Adding route %p to window %p"),route, m_parent);
00291         MutBoxChannelShape * channel = 
00292                 new MutBoxChannelShape(this, wxID_ANY, route);
00293         
00294         return AddChannel(channel);
00295 }
00296 
00297 MutBoxChannelShape * MutBoxShape::AddChannel(RoutePanel * panel) {
00298         Route * route  = new Route (NULL,NULL, RTall, -1,-1, boxId, false);
00299         
00300 # if 0
00301         MutBoxChannelShape * channel = new MutBoxChannelShape(this, wxID_ANY, route);
00302         channel -> ReadPanel(panel);
00303 
00304 
00305         return AddChannel(channel);
00306 # endif
00307         MutBoxChannelShape * channel = AddChannel(route);
00308         if (channel) channel->ReadPanel(panel);
00309         return channel;
00310 }
00311 
00312 bool MutBoxShape::HasChannel(Route * route) {
00313         wxSizerItemList & list = channels->GetChildren();
00314         for (wxSizerItemList::iterator i = list.begin() ; i!= list.end() ; i++) {
00315                 MutBoxChannelShape * channel = static_cast<MutBoxChannelShape *> ((*i)->GetWindow());
00316                 wxASSERT(dynamic_cast<MutBoxChannelShape *>(channel));
00317                 wxASSERT(dynamic_cast<MutBoxChannelShape *>((*i)->GetWindow()));
00318                 if (channel->GetRoute() == route) return true;
00319         }
00320         return false;
00321 }
00322 
00323 void MutBoxShape::AddPossibleOutput(MutOutputDeviceShape * device) {
00324         wxSizerItemList list = channels->GetChildren();
00325         for (wxSizerItemList::iterator i = list.begin(); 
00326              i != (list.end()); i++)
00327         {
00328       
00329                 MutBoxChannelShape * channel = (MutBoxChannelShape *) ((*i)->GetWindow());
00330                 wxASSERT(dynamic_cast<MutBoxChannelShape *>(channel));
00331                 wxASSERT(dynamic_cast<MutBoxChannelShape *>((*i)->GetWindow()));
00332                 channel->AddPossibleOutput(device);
00333         }
00334 }
00335 
00336 
00337 void MutBoxShape::DrawLines(wxDC & dc) 
00338 {
00339         wxSizerItemList list = channels->GetChildren();
00340         for (wxSizerItemList::iterator i = list.begin(); 
00341              i != (list.end()); i++)
00342         {
00343       
00344                 MutBoxChannelShape * channel = static_cast<MutBoxChannelShape *> ((*i)->GetWindow());
00345                 wxASSERT(dynamic_cast<MutBoxChannelShape *>(channel));
00346                 wxASSERT(dynamic_cast<MutBoxChannelShape *>((*i)->GetWindow()));
00347                 channel->DrawLines(dc, GetPosition());
00348         }
00349 }
00350 
00351 bool MutBoxShape::Detach( wxWindow *window )
00352 {
00353         // avoid deleting m_staticBox in our dtor if it's being detached from the
00354         // sizer (which can happen because it's being already destroyed for
00355         // example)
00356         if ( window == m_icon )
00357         {
00358                 UNREACHABLEC;
00359                 m_icon = NULL;
00360         }
00361 
00362         return channels -> Detach( window );
00363 }
00364 
00365 void MutBoxShape::DoLeftDblClick() {
00366         BoxDlg * box = ShowBoxDialog();
00367         wxASSERT(box);
00368         
00369         if (!box) return;
00370         int Res = box->ShowModal();
00371         bool destroySelf = false;
00372         
00373         if (Res == wxID_OK) {
00374                 int type = box->GetBoxType();
00375                 
00376                 if (CanHandleType (type)) {
00377                         readDialog (box);
00378                 } else {
00379                         // MutBoxShape newbox = MutInputDeviceShape::CreateShape (type);
00380                         MutBoxShape * newbox = new MutBoxShape(m_parent, wxID_ANY, type);
00381                         if (newbox) {
00382                                 newbox->readDialog(box);
00383                                 destroySelf = replaceSelfBy(newbox);
00384 //                              m_parent->SetInitialSize(wxDefaultSize);
00385 //                              m_parent->InvalidateBestSize();
00386                         }
00387                 }
00388         } else if (Res == wxID_REMOVE) {
00389                 destroySelf = DetachBox();
00390         }
00391         
00392         box->Destroy();
00393         
00394         // Signalize to delete this control
00395         // Unfortunately WXMAC segfaults if we use Destroy(), here.
00396         if (destroySelf) DeleteSelf();
00397         
00398         if (m_parent) {
00399                 m_parent->Layout();
00400                 Refresh(true);
00401                 m_parent->Refresh(true);
00402         } else  Refresh(true);
00403         
00404         DebugCheckRoutes();
00405 }
00406 
00408 
00412 BoxDlg * MutBoxShape::ShowBoxDialog() const{
00413         MutRouteWnd * parentwin = dynamic_cast<MutRouteWnd *>(GetParent());
00414         wxASSERT(parentwin);
00415         if (!parentwin) return NULL;
00416         
00417         BoxDlg * box = new BoxDlg (parentwin);
00418         wxASSERT(box);
00419         if (!box) return NULL;
00420 
00421         wxWindow * routeWindow = box->GetRouteWindow();
00422         wxASSERT(routeWindow);
00423         if (!routeWindow) {
00424                 box->Destroy();
00425                 return NULL;
00426         }
00427         wxGridSizer * routeSizer = dynamic_cast<wxGridSizer *> (routeWindow->GetSizer());
00428         
00429         if (!routeSizer) {
00430                 if (routeWindow->GetSizer()) UNREACHABLEC;
00431                 
00432                 routeSizer = new wxGridSizer(4);
00433                 if (!routeSizer) box->Destroy(); return NULL;
00434                 routeWindow->SetSizer(routeSizer);              
00435         }
00436         
00437         wxSizerItemList list = channels->GetChildren();
00438         for (wxSizerItemList::iterator i = list.begin(); 
00439              i != (list.end()); i++) {
00440                 wxASSERT(dynamic_cast<MutBoxChannelShape *> ((*i) -> GetWindow()));
00441                 MutBoxChannelShape::CreateRoutePanel(static_cast<MutBoxChannelShape *> ((*i)->GetWindow()),
00442                                                      parentwin, routeWindow, GetBoxId());
00443         }
00444          
00445         InitializeDialog(box);
00446 
00447         routeWindow->Layout();
00448         routeWindow->FitInside();
00449         box->Layout();
00450         box->Fit();
00451         box->CenterOnParent(wxBOTH);
00452         
00453         return box;
00454 }
00455 
00456 void MutBoxShape::InitializeDialog(BoxDlg * dlg) const {
00457         wxASSERT(dlg);
00458         dlg->SetBoxType(boxId);
00459         if (boxId >= Box0) 
00460                 dlg->SetBoxNumber(boxId);
00461         else
00462                 dlg->SetBoxNumber(maxBoxId);
00463 }
00464 
00465 bool MutBoxShape::readDialog (BoxDlg * box) {
00466         wxASSERT(box);
00467         if (!box) return false;
00468         int type = box->GetBoxType();
00469         switch (type) {
00470                 case NoBox:
00471                 case GmnBox:
00472                         SetBoxId(type);
00473                         break;
00474                 default:
00475                         SetBoxId(box->GetBoxNumber());
00476                         break;
00477         }
00478         
00479         wxWindow * routeWindow = box->GetRouteWindow();
00480         wxASSERT(routeWindow);
00481         if (!routeWindow) {
00482                 return false;
00483         }
00484         
00485         wxWindowList & routePanels = routeWindow->GetChildren();
00486         for (wxWindowList::iterator i = routePanels.begin(); 
00487              i != routePanels.end(); i++) {
00488                 RoutePanel * panel = dynamic_cast<RoutePanel *> (*i);
00489                 if (!panel) continue;
00490                 wxASSERT(dynamic_cast<RoutePanel *> (*i));
00491                 MutBoxChannelShape * channel = panel -> GetChannel();
00492                 if (!channel && panel->IsEnabled()) 
00493                         channel = AddChannel(panel);
00494                 if (channel) {
00495                         channel -> ReadPanel(panel);
00496                 }
00497         }
00498         return true;
00499 }
00500 
00501 bool MutBoxShape::replaceSelfBy (MutBoxShape  * newshape)
00502 {
00503         wxASSERT (newshape);
00504         
00505         // this is only used in NewMutBoxShape so far.
00506         // But we need it, when we implement other Box types
00507         UNREACHABLEC;
00508         
00509 /*
00510         for(Route * route = newshape->device->ReplaceDevice (device);
00511             route; route = route->Next) 
00512         {
00513                 void * p = route->getUserData();
00514                 wxASSERT (wxDynamicCast (p,MutBoxChannelShape));
00515                 MutBoxChannelShape * channel = (MutBoxChannelShape *) p;
00516                 
00517                 wxASSERT (channel->GetInput() == this);
00518                 channel->SetInput (newshape);
00519                 
00520                 
00521         }
00522         
00523         delete device;
00524         device = NULL;
00525         
00526         newshape->MoveBeforeInTabOrder (this);
00527         
00528         wxSizer * sizer = GetContainingSizer();
00529         sizer -> Replace (this, newshape, false);
00530         
00531         if (FindFocus()==this) {
00532                 m_parent->Layout();
00533                 m_parent->FitInside();
00534                 m_parent->SetVirtualSize(wxDefaultSize);
00535                 newshape->SetFocus();
00536         }
00537         
00538         Hide(); 
00539         return true;
00540  */
00541         return false;
00542 }
00543 
00544 bool MutBoxShape::DetachBox() {
00545         wxSizerItemList &list = channels->GetChildren();
00546         for (wxSizerItemList::iterator i = list.begin(); 
00547              i != (list.end()); i++) {
00548                 MutBoxChannelShape * channel = dynamic_cast<MutBoxChannelShape *> ((*i) -> GetWindow());
00549                 wxASSERT(channel);
00550                 channel->DetachChannel();
00551         }
00552         return true;
00553 }
00554 
00555 
00556 
00557 
00558 #include "wx/listimpl.cpp"
00559 WX_DEFINE_LIST (MutBoxShapeList);
00560 
00561 /*
00562  * \}
00563  */

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