MutFrame.cpp
gehe zur Dokumentation dieser Datei
00001 
00209 // ===========================================================================
00210 // declarations
00211 // ===========================================================================
00212 
00213 // ---------------------------------------------------------------------------
00214 // headers
00215 // ---------------------------------------------------------------------------
00216 
00217 // For compilers that support precompilation, includes "wx/wx.h".
00218 #include "Defs.h"
00219 #include "wx/wxprec.h"
00220 
00221 #ifdef __BORLANDC__
00222 #pragma hdrstop
00223 #endif
00224 
00225 #ifndef WX_PRECOMP
00226 #include "wx/wx.h"
00227 #include "wx/mdi.h"
00228 #endif
00229 
00230 #include "wx/toolbar.h"
00231 
00232 #if !defined(__WXMSW__)
00233 #include "Icon/Mutabor.xpm"
00234 #include "Icon/Document.xpm"
00235 #include "Icon/Route.xpm"
00236 #include "Icon/KeyTextBox.xpm"
00237 #include "Icon/TSTextBox.xpm"
00238 #include "Icon/ActTextBox.xpm"
00239 #endif
00240 
00241 #include "bitmaps/new.xpm"
00242 #include "bitmaps/open.xpm"
00243 #include "bitmaps/save.xpm"
00244 #include "bitmaps/copy.xpm"
00245 #include "bitmaps/cut.xpm"
00246 #include "bitmaps/paste.xpm"
00247 #include "bitmaps/print.xpm"
00248 #include "bitmaps/help.xpm"
00249 
00250 #include "wx/filename.h"
00251 #include "wx/config.h"
00252 #include "wx/confbase.h"
00253 #include "wx/fileconf.h"
00254 #ifdef __WXMSW__
00255 #  include <wx/msw/regconf.h>
00256 #endif
00257 #include "wx/ffile.h"
00258 #include "MutFrame.h"
00259 #include "MutDocument.h"
00260 #include "MutView.h"
00261 #include "MutChild.h"
00262 //#include "Mutabor.rh"
00263 #include "MutApp.h"
00264 
00265 #include "Defs.h"
00266 #include "mhDefs.h"
00267 #include "Runtime.h"
00268 #include "GrafKern.h"
00269 #include "Action.h"
00270 #include "MutRouteWnd.h"
00271 #include "MutLogicWnd.h"
00272 #include "MutTextBox.h"
00273 #include "MutBitmaps.h"
00274 
00275 using mutaborGUI::MutEditFile;
00276 using mutaborGUI::MutDocument;
00277 using mutaborGUI::MutView;
00278 
00279 #define OPENMENU \
00280         menu = new wxMenu;
00281 
00282 #define CLOSEMENU(name) \
00283         menuBar->Append(menu, name);
00284 
00285 #define MENUITEM(name, id, help) \
00286         menu->Append(id, name, help)
00287 
00288 #define MENUCHECKITEM(name, id, help) \
00289         menu->AppendCheckItem(id, name, help)
00290 
00291 #define MENUITEM_ADD(name, id, help, add) \
00292         menu->Append(id, name, help, add)
00293 
00294 #define MENUITEM_SEPARATOR \
00295     menu->AppendSeparator()
00296 
00297 // ---------------------------------------------------------------------------
00298 // global variables
00299 // ---------------------------------------------------------------------------
00300 
00301 #ifndef HAVE_CONFIG_H
00302 #  define PACKAGE_NAME "Mutabor"
00303 #endif
00304 
00305 #define APPNAME _(PACKAGE_NAME)
00306 
00307 //wxString RcfFile = wxT("Routes.cfg");
00308 MutFrame* theFrame = 0;
00309 bool demo = false;
00310 
00311 bool asTS = true;
00312 bool SaveEditor = true;
00313 bool UseColorBars = true;
00314 bool OWM = false; // One Window Mode
00315 bool CAW = false; // Common Action Window
00316 bool LogicOn = false;
00317 int curBox = 0;
00318 wxWindow *ChildToClose = NULL;
00319 
00320 wxString CompiledFile;
00321 
00322 wxString curLogic[MAX_BOX];
00323 wxString curTS[MAX_BOX];
00324 int curTaste[MAX_BOX][2]; // [0] ... ToneSyst, [1] ... Logic
00325 
00326 bool TextBoxWanted[MAX_BOX][3] = {
00327                                          { false, false, false },
00328                                          { false, false, false },
00329                                          { false, false, false },
00330                                          { false, false, false },
00331                                          { false, false, false },
00332                                          { false, false, false },
00333                                          { false, false, false },
00334                                          { false, false, false },
00335                                          { false, false, false },
00336                                          { false, false, false },
00337                                          { false, false, false },
00338                                          { false, false, false },
00339                                          { false, false, false },
00340                                          { false, false, false },
00341                                          { false, false, false },
00342                                          { false, false, false }
00343                                  };
00344 char WinName[5][12] = { "KEYWIN", "TONSYSTWIN", "ACTIONWIN", "LOGICWIN", "ROUTEWIN" };
00345 
00346 int MutFrame::boxCommandIds[MAX_BOX];
00347 
00348 #define SG_NOTHING 1
00349 #define SG_LOGIC   0
00350 #define SG_RECORD  2
00351 #define SG_PLAY    3
00352 #define SG_PAUSE   4
00353 
00354 #define Compiled (!CompiledFile.IsEmpty())
00355 //#define ROUTE_WIN ((MutRouteWnd*)(Get(WK_ROUTE)->Win))
00356 //#define REPAINT_ROUTE if ( IsOpen(WK_ROUTE) ) ROUTE_WIN->Refresh()
00357 
00358 // ---------------------------------------------------------------------------
00359 // event tables
00360 // ---------------------------------------------------------------------------
00361 
00362 BEGIN_EVENT_TABLE(MutFrame, wxDocChildFrame)
00363         EVT_ERASE_BACKGROUND(MutFrame::OnEraseBackground)
00364         EVT_SIZE(MutFrame::OnSize)
00365 
00366         EVT_MENU(CM_EXECUTE, MutFrame::CmFileOpen)
00367         EVT_MENU(CM_FILESAVE, MutFrame::PassEventToEditor)
00368         //    EVT_MENU(CM_FILESAVEAS, MutFrame::CmFileOpen)
00369         EVT_MENU(CM_DOACTIVATE, MutFrame::CmDoActivate)
00370         EVT_MENU(CM_STOP, MutFrame::CmStop)
00371         EVT_MENU(CM_PANIC, MutFrame::CmPanic)
00372         EVT_UPDATE_UI(CM_EXECUTE, MutFrame::CeExecute)
00373         EVT_UPDATE_UI(CM_ACTIVATE, MutFrame::CeActivate)
00374         EVT_UPDATE_UI(CM_COMPILE, MutFrame::CeActivate)
00375         EVT_UPDATE_UI(CM_DOACTIVATE, MutFrame::CeActivate)
00376         EVT_UPDATE_UI(CM_STOP, MutFrame::CeStop)
00377         EVT_UPDATE_UI(CM_PANIC, MutFrame::CeStop)
00378         EVT_MENU(CM_COMPILE, MutFrame::PassEventToEditor)
00379         EVT_MENU(CM_COMPACT, MutFrame::PassEventToEditor)
00380         EVT_MENU(CM_ACTIVATE, MutFrame::PassEventToEditor)
00381         EVT_MENU(CM_GETLINE, MutFrame::PassEventToEditor)
00382 EVT_MENU (wxID_CLEAR,            MutFrame::PassEventToEditor)
00383 EVT_MENU (wxID_CUT,              MutFrame::PassEventToEditor)
00384 EVT_MENU (wxID_COPY,             MutFrame::PassEventToEditor)
00385 EVT_MENU (wxID_PASTE,            MutFrame::PassEventToEditor)
00386     EVT_MENU (CM_INDENTINC,        MutFrame::PassEventToEditor)
00387     EVT_MENU (CM_INDENTRED,        MutFrame::PassEventToEditor)
00388     EVT_MENU (wxID_SELECTALL,        MutFrame::PassEventToEditor)
00389     EVT_MENU (CM_SELECTLINE,       MutFrame::PassEventToEditor)
00390     EVT_MENU (wxID_REDO,             MutFrame::PassEventToEditor)
00391     EVT_MENU (wxID_UNDO,             MutFrame::PassEventToEditor)
00392     // find
00393     EVT_MENU (wxID_FIND,             MutFrame::PassEventToEditor)
00394     EVT_MENU (CM_FINDNEXT,         MutFrame::PassEventToEditor)
00395     EVT_MENU (CM_REPLACE,          MutFrame::PassEventToEditor)
00396     EVT_MENU (CM_REPLACENEXT,      MutFrame::PassEventToEditor)
00397     EVT_MENU (CM_BRACEMATCH,       MutFrame::PassEventToEditor)
00398     EVT_MENU (CM_GOTO,             MutFrame::PassEventToEditor)
00399     // view
00400     EVT_MENU_RANGE (CM_HILIGHTFIRST, CM_HILIGHTLAST,
00401                                      MutFrame::PassEventToEditor)
00402     EVT_MENU (CM_DISPLAYEOL,       MutFrame::PassEventToEditor)
00403     EVT_MENU (CM_INDENTGUIDE,      MutFrame::PassEventToEditor)
00404     EVT_MENU (CM_LINENUMBER,       MutFrame::PassEventToEditor)
00405     EVT_MENU (CM_LONGLINEON,       MutFrame::PassEventToEditor)
00406     EVT_MENU (CM_WHITESPACE,       MutFrame::PassEventToEditor)
00407     EVT_MENU (CM_FOLDTOGGLE,       MutFrame::PassEventToEditor)
00408     EVT_MENU (CM_OVERTYPE,         MutFrame::PassEventToEditor)
00409     EVT_MENU (CM_READONLY,         MutFrame::PassEventToEditor)
00410     EVT_MENU (CM_WRAPMODEON,       MutFrame::PassEventToEditor)
00411     // extra
00412     EVT_MENU (CM_CHANGELOWER,      MutFrame::PassEventToEditor)
00413     EVT_MENU (CM_CHANGEUPPER,      MutFrame::PassEventToEditor)
00414     EVT_MENU (CM_CONVERTCR,        MutFrame::PassEventToEditor)
00415     EVT_MENU (CM_CONVERTCRLF,      MutFrame::PassEventToEditor)
00416     EVT_MENU (CM_CONVERTLF,        MutFrame::PassEventToEditor)
00417     EVT_MENU (CM_CHARSETANSI,      MutFrame::PassEventToEditor)
00418     EVT_MENU (CM_CHARSETMAC,       MutFrame::PassEventToEditor)
00419         //    EVT_MENU(CM_ROUTES, MutFrame::CmRoutes)
00420 
00421         EVT_MENU(CM_TOGGLEKEY, MutFrame::CmToggleKey)
00422         EVT_MENU(CM_TOGGLETS, MutFrame::CmToggleTS)
00423         EVT_MENU(CM_TOGGLEACT, MutFrame::CmToggleAct)
00424         EVT_MENU(CM_OWM, MutFrame::CmToggleOWM)
00425         EVT_MENU(CM_CAW, MutFrame::CmToggleCAW)
00426         EVT_UPDATE_UI(CM_TOGGLEKEY, MutFrame::CeToggleKey)
00427         EVT_UPDATE_UI(CM_TOGGLETS, MutFrame::CeToggleTS)
00428         EVT_UPDATE_UI(CM_TOGGLEACT, MutFrame::CeToggleAct)
00429         EVT_UPDATE_UI(CM_OWM, MutFrame::CeToggleOWM)
00430         EVT_UPDATE_UI(CM_CAW, MutFrame::CeToggleCAW)
00431 
00432         EVT_MENU(CM_INDEVSTOP, MutFrame::CmInDevStop)
00433         EVT_MENU(CM_INDEVPLAY, MutFrame::CmInDevPlay)
00434         EVT_MENU(CM_INDEVPAUSE, MutFrame::CmInDevPause)
00435         EVT_UPDATE_UI(CM_INDEVSTOP, MutFrame::CeInDevStop)
00436         EVT_UPDATE_UI(CM_INDEVPLAY, MutFrame::CeInDevPlay)
00437         EVT_UPDATE_UI(CM_INDEVPAUSE, MutFrame::CeInDevPause)
00438         //    EVT_ACTIVATE(MutFrame::OnActivate)
00439 
00440         EVT_CLOSE(MutFrame::OnClose)
00441         EVT_MENU(CM_UPDATEUI, MutFrame::UpdateUI)
00442 //      EVT_IDLE(MutFrame::OnIdle)
00443         EVT_MENU(CM_SETTITLE, MutFrame::CmSetTitle)
00444         //    EVT_SIZE(MutFrame::OnSize)
00445 END_EVENT_TABLE()
00446 
00447 // ===========================================================================
00448 // implementation
00449 // ===========================================================================
00450 
00451 // ---------------------------------------------------------------------------
00452 // MutFrame
00453 // ---------------------------------------------------------------------------
00454 
00455 // Define my frame constructor
00456 MutFrame::MutFrame(wxFrame *parent,
00457 
00458                    const wxWindowID id,
00459                    const wxString& title,
00460                    const wxPoint& pos,
00461                    const wxSize& size,
00462                    const long style): wxDocChildFrame(NULL, 
00463                                                       NULL, 
00464                                                       parent, 
00465                                                       id, 
00466                                                       title, 
00467                                                       pos, 
00468                                                       size,
00469                                                       style | wxNO_FULL_REPAINT_ON_RESIZE),
00470         curStatusImg(0)
00471 {
00472 
00473         SetSize (DetermineFrameSize ());
00474         client = NULL;
00475         editmenu = filemenu = NULL;
00476 
00477         auimanager.SetManagedWindow(this);
00478 
00479 
00480 #if wxUSE_TOOLBAR
00481         wxToolBar * tb = new  wxToolBar(this,
00482                                         wxID_ANY,
00483                                         wxDefaultPosition,
00484                                         wxDefaultSize,
00485                                         wxTB_DOCKABLE);
00486         InitToolBar(tb);
00487 
00488         auimanager.AddPane(tb, wxAuiPaneInfo().
00489                            Name(_T("tb")).Caption(_("Toolbar")).
00490                            ToolbarPane().Top().
00491                            LeftDockable(false).RightDockable(false));
00492 #endif // wxUSE_TOOLBAR
00493 
00494 
00495         // Accelerators
00496         /*    wxAcceleratorEntry entries[3];
00497             entries[0].Set(wxACCEL_CTRL, (int) 'N', MDI_NEW_WINDOW);
00498             entries[1].Set(wxACCEL_CTRL, (int) 'X', MDI_QUIT);
00499             entries[2].Set(wxACCEL_CTRL, (int) 'A', MDI_ABOUT);
00500             wxAcceleratorTable accel(3, entries);
00501             SetAcceleratorTable(accel);*/
00502 }
00503 
00504 MutFrame::MutFrame(MutDocument *doc,
00505                    MutView *v,
00506                    wxFrame *frame,
00507                    wxWindowID id,
00508                    const wxString& title,
00509                    const wxPoint& pos,
00510                    const wxSize& size,
00511                    long type,
00512                    const wxString& name):
00513         wxDocChildFrame(doc,v,frame,id,title,pos,size,type,name),
00514         curStatusImg(0)
00515 {
00516 
00517         SetSize (DetermineFrameSize ());
00518         client = NULL;
00519         editmenu = filemenu = NULL;
00520 
00521         auimanager.SetManagedWindow(this);
00522 
00523 
00524 #if wxUSE_TOOLBAR
00525         wxToolBar * tb = new  wxToolBar(this,
00526                                         wxID_ANY,
00527                                         wxDefaultPosition,
00528                                         wxDefaultSize,
00529                                         wxTB_DOCKABLE);
00530         InitToolBar(tb);
00531 
00532         auimanager.AddPane(tb, wxAuiPaneInfo().
00533                            Name(_T("tb")).Caption(_("Toolbar")).
00534                            ToolbarPane().Top().
00535                            LeftDockable(false).RightDockable(false));
00536 #endif // wxUSE_TOOLBAR
00537 
00538 
00539         // Accelerators
00540         /*    wxAcceleratorEntry entries[3];
00541             entries[0].Set(wxACCEL_CTRL, (int) 'N', MDI_NEW_WINDOW);
00542             entries[1].Set(wxACCEL_CTRL, (int) 'X', MDI_QUIT);
00543             entries[2].Set(wxACCEL_CTRL, (int) 'A', MDI_ABOUT);
00544             wxAcceleratorTable accel(3, entries);
00545             SetAcceleratorTable(accel);*/
00546 }
00547 
00548 
00549 
00550 
00551 MutFrame::~MutFrame()
00552 
00553 {
00554         if (filemenu) {
00555                 if (wxGetApp().GetDocumentManager()) 
00556                         wxGetApp().GetDocumentManager()->FileHistoryRemoveMenu(filemenu);
00557         }
00558         if (m_childView) {
00559                 wxASSERT(dynamic_cast<MutView *>(m_childView));
00560                 MutView * v = (MutView *) m_childView;
00561                 v->SetFrame(NULL);
00562                 v->SetTextsw(NULL);
00563         }
00564         auimanager.UnInit();
00565 
00566 //      while (wxGetApp().Pending()) wxGetApp().Dispatch();
00567 }
00568 
00569 #if wxUSE_TOOLBAR
00570 void MutFrame::InitToolBar(wxToolBar* toolBar)
00571 {
00572         MutToolBarBitmaps::Init();
00573 
00574         toolBar->AddTool(CM_FILENEW, _("New"), MutToolBarBitmaps::New, _("New file"));
00575         toolBar->AddTool(CM_FILEOPEN, _("Open"), MutToolBarBitmaps::Open , _("Open file"));
00576         toolBar->AddTool(CM_FILESAVE, _("Save"), MutToolBarBitmaps::Save, _("Save file"));
00577         toolBar->AddTool(CM_FILESAVEAS, _("Save as"), MutToolBarBitmaps::SaveAs, _("Save file with new name"));
00578         toolBar->AddTool(wxID_PRINT, _("Print"), MutToolBarBitmaps::Print, _("Print"));
00579         toolBar->AddSeparator();
00580         toolBar->AddTool(CM_ACTIVATE, _("Activate"), MutToolBarBitmaps::LogicActivate, _("Activate the logic"));        
00581         toolBar->AddTool(CM_STOP, _("Stop"), MutToolBarBitmaps::LogicStop, _("Stop the logic"));        
00582         toolBar->AddTool(CM_PANIC, _("Panic"), MutToolBarBitmaps::LogicPanic, _("Panic: switch all notes off"));        
00583         toolBar->AddSeparator();
00584         toolBar->AddTool(wxID_UNDO, _("Undo"), MutToolBarBitmaps::Undo, _("Undo last changes"));
00585         toolBar->AddTool(wxID_REDO, _("Redo"), MutToolBarBitmaps::Redo,  _("Redo last undone changes"));
00586         toolBar->AddTool(wxID_COPY, _("Copy"), MutToolBarBitmaps::Copy, _("Copy"));
00587         toolBar->AddTool(wxID_CUT, _("Cut"), MutToolBarBitmaps::Cut,  _("Cut"));
00588         toolBar->AddTool(wxID_PASTE, _("Paste"), MutToolBarBitmaps::Paste, _("Paste"));
00589         toolBar->AddSeparator();
00590         // \todo implement search and replace and corresponding toolbar buttons
00591         // toolBar->AddSeparator();
00592         toolBar->AddTool(CM_ROUTELOAD,_("&Load routes"), MutToolBarBitmaps::RouteLoad,
00593                  _("Load the current route configuration from a file"));
00594         toolBar->AddTool(CM_ROUTESAVE,_("&Save routes"), MutToolBarBitmaps::RouteSave,
00595                  _("Save current route configuration to a file."));
00596         toolBar->AddSeparator();
00597         toolBar->AddTool(CM_INDEVPLAY,_("&Play"), MutToolBarBitmaps::IndevsPlay,
00598                  _("Start playing the music from input file devices"));
00599         toolBar->AddTool(CM_INDEVSTOP,_("St&op"), MutToolBarBitmaps::IndevsStop,
00600                  _("Stop playing the music from input file devices"));
00601         toolBar->AddTool(CM_INDEVPAUSE,_("P&ause"), MutToolBarBitmaps::IndevsPause,
00602                  _("Pause plaing the music from input file devices"));
00603         toolBar->AddSeparator();
00604         toolBar->AddTool( CM_ABOUT, _("About"), MutToolBarBitmaps::About, _("Help"));
00605         toolBar->AddSeparator();
00606         toolBar->Realize();
00607 }
00608 
00609 #endif // wxUSE_TOOLBAR
00610 
00611 void MutFrame::PassEventToEditor(wxCommandEvent &event)
00612 {
00613         event.Skip(false);
00614 
00615         if (dynamic_cast<MutEditFile*>(client)) {
00616                 wxPostEvent(client,event);
00617         }
00618 }
00619 
00620 void MutFrame::EventPassOn(wxCommandEvent& event)
00621 {
00622         if ( event.GetEventObject() == NULL )
00623                 // als Flag zur Sicherheit vor Endlosschleifen
00624                 return;
00625 
00626         event.SetEventObject(NULL);
00627 
00628         /*      wxAUIPaneInfoArray &info = auimanager.GetAllPanes();
00629 
00630                 if (!info.empty()) {
00631                         wxAUIPaneInfoArray::iterator it = info.first();
00632 
00633                 }
00634         */
00635         std::cout << "Skippen? " << event.GetSkipped() <<
00636         " Propagate? " << event.ShouldPropagate() << std::endl;
00637 
00638         //        if (!GetClientWindow()->ProcessEvent(event)) {
00639         //      std::cout << "Event ignoriert von:" << GetClientWindow()->GetName().fn_str() << std::endl;
00640         //
00641 
00642         wxWindow * frame = auimanager.GetManagedWindow();
00643 
00644         if (frame) {
00645                 wxPostEvent(frame,event);
00646                 std::cout << "Event " << event.ShouldPropagate() << " war da:"
00647                 << (frame->GetName().fn_str()) << std::endl;
00648         }
00649 
00650         //      }text.mb_str(*wxConvFileName)
00651         std::cout << frame << std::endl;
00652 
00653         event.Skip();
00654 
00655 }
00656 
00657 void MutFrame::OnClose(wxCloseEvent& event)
00658 {
00659         DEBUGLOG (other, _T("%x == %x"),this,theFrame);
00660 
00661         if (theFrame == this) {
00662                 DEBUGLOG (other, _T("We are the active window."));
00663 
00664                 if ( event.CanVeto() ) {
00665                         wxString msg;
00666                         msg.Printf(_("This logic is currently active. On closing it will be deactivated. Really close this window?"));
00667 
00668                         if ( wxMessageBox(msg, _("Please confirm closing."),
00669                                           wxICON_QUESTION | wxYES_NO) != wxYES ) {
00670                                 event.Veto();
00671                                 return;
00672                         }
00673                 }
00674 
00675                 DoStop();
00676         }
00677 
00678 
00679         SaveState();
00680 
00681 
00682         // wxDocChildFrame will veto if there is no View associated
00683         if (m_childView)
00684                 wxDocChildFrame::OnCloseWindow(event);
00685         else 
00686                 Destroy();
00687 }
00688 
00689 void MutFrame::OnPaint(wxPaintEvent& event)
00690 {
00691     wxPaintDC dc(this);
00692 
00693     STUBC; 
00694 /* this code is just copied and must be changed 
00695   to paint into the subwindow which is managed by 
00696   the AUI manager.
00697 
00698   Propably it must be simply moved to the client window.
00699 */
00700     
00701     if (m_childView) 
00702             m_childView->OnDraw(&dc);
00703 }
00704 
00705 
00706 
00707 
00708 void MutFrame::CmFileNew(wxCommandEvent& event)
00709 {
00710         STUBC;
00711         return;
00712 
00713 #ifdef DEBUG
00714         printf("MutFrame::CmFileNew\n");
00715 #endif
00716 
00717         if (client) {
00718                 event.Skip(true);
00719                 return ;
00720         }
00721 
00722         event.Skip(false); // Its our task to try create the file
00723 
00724         OpenFile(wxEmptyString);
00725 }
00726 
00727 
00728 void MutFrame::CmFileOpen(wxCommandEvent& event)
00729 {
00730         STUBC;
00731         return;
00732 
00733         if (client) {
00734                 event . Skip (true);
00735                 return;
00736         }
00737 
00738         event . Skip (false); // it's our task to try to open that file
00739 
00740         wxString path = FileNameDialog(this, event.GetId());
00741 
00742         if ( !path )
00743                 return;
00744 
00745 
00746 #ifdef DEBUG
00747         std::cerr << "MutFrame:CmFileOpen " << CM_EXECUTE << " == "
00748         << event . GetId () << "?" << std::endl;
00749 
00750 #endif
00751 
00752 
00753         switch (event.GetId()) {
00754 
00755         case CM_FILEOPEN:
00756                 OpenFile(path);
00757 
00758                 break;
00759 
00760         case CM_EXECUTE: {
00761                 OpenFile(path);
00762                 wxCommandEvent e (wxEVT_COMMAND_MENU_SELECTED, CM_ACTIVATE);
00763                 ProcessEvent (e);
00764         }
00765 
00766         break;
00767 
00768         case CM_FILESAVEAS:
00769                 event.SetString(path);
00770 
00771                 PassEventToEditor(event);
00772 
00773                 break;
00774 
00775         default:
00776                 wxLogError(_("Unexpected Event in MutFrame::CmFileOpen: %d"),event.GetId());
00777         }
00778 }
00779 
00786 bool MutFrame::OpenFile (wxString path, bool newfile)
00787 {
00788         STUBC;
00789         return false;
00790 
00791         if (client) return false;
00792 
00793         wxString filename = !path ? wxString(_("noname.mut"))
00794                             : wxFileName(path).GetFullName();
00795 
00796         MutEditFile * editor = new MutEditFile(this, wxPoint(0, 0), wxDefaultSize);
00797 
00798 #ifdef DEBUG
00799         std::cout << "MutFrame::OpenFile(): Loading " << (path.fn_str()) << std::endl;
00800 
00801 #endif
00802         if (!(!path))
00803                 editor->LoadFile(path);
00804 
00805         editor->SetSelection(0, 0);
00806         SetTitle(wxString().Format(_("%s -- %s"),APPNAME,filename.c_str()));
00807 
00808         return SetClient(editor,filename);
00809 }
00815 bool MutFrame::SetClient (wxWindow * win, const wxString &title)
00816 {
00817         if (client || !win) {
00818                 wxASSERT(!client);
00819                 wxASSERT(win);
00820                 return false;
00821         }
00822         
00823         DEBUGLOG(docview,_T("Setting client of %x to %x with title '%s'"),
00824                  this,
00825                  win,
00826                  (char *)title.c_str());
00827 
00828         client = win;
00829         SetTitle(title);
00830         auimanager.AddPane(client,wxAuiPaneInfo().
00831                            Caption(title).CenterPane().PaneBorder(false));
00832         auimanager.Update();
00833         return true;
00834 }
00835 
00836 
00837 // Logic-Arbeit: CmDoActivate, CmStop, CmPanic, CmExecute
00838 
00839 
00840 void UpdateUIcallback(int box,bool logic_changed)
00841 {
00842         // todo Update UI
00843         if ( theFrame ) {
00844                 wxCommandEvent event1(wxEVT_COMMAND_MENU_SELECTED,
00845                                            CM_UPDATEUI);
00846                 wxPostEvent(theFrame,event1);
00847         }
00848 }
00849 
00850 void MutFrame::CmDoActivate(wxCommandEvent& event)
00851 {
00852         if (LogicOn) return;
00853 
00854 #ifdef DEBUG
00855         std::cout << "MutFrame::CmDoActivate" << std::endl;
00856 #endif
00857 
00858         if ( !Compiled )
00859                 return;
00860 
00861         wxGetApp().SaveState();
00862 
00863 #ifdef DEBUG
00864         DEBUGLOG (other, _T("Restoring state for debugging"));
00865         wxGetApp().RestoreState();
00866 #endif
00867 
00868 //      ScanDevices(); 
00869 
00870         AktionTraceReset();
00871 
00872         // aktivieren
00873 #ifndef NOACTIVATE
00874 #ifdef DEBUG
00875         std::cerr << "MutFrame::CmDoActivate: Activate" << std::endl;
00876 
00877 #endif
00878         RealTime = true;
00879 
00880         if ( !CheckNeedsRealTime() )
00881                 RealTime = (wxMessageBox(_("There are no realtime \
00882                                            instruments in the routes.\n\
00883                                            Shall Mutabor translate the files in batch mode, \
00884                                            to keep the MIDI files with the original time stamp?\n\
00885                                            (This means also, that you can't modify the tunings \
00886                                            while playing by computer keyboard.)"),
00887                                          _("No realtime => batch mode?"),
00888                                          wxYES_NO | wxICON_QUESTION
00889                                          /*| MB_DEFBUTTON2*/) == wxNO);
00890 
00891         theFrame = this;
00892 
00893         if ( !Activate(RealTime, &UpdateUIcallback) )
00894                 return;
00895 
00896 #endif
00897 
00898 #ifdef DEBUG
00899         std::cerr << "MutFrame::CmDoActivate: Initialize state" << std::endl;
00900 
00901 #endif
00902 
00903         // Variablen initialisieren
00904         for (int instr = 0; instr < MAX_BOX; instr++) {
00905                 curLogic[instr] = _T("(INITIAL)");
00906                 curTS[instr] = _T("0");
00907                 curTaste[instr][0] = 0;
00908                 curTaste[instr][1] = 0;
00909         }
00910 
00911 #ifdef DEBUG
00912         std::cout << "MutFrame::CmDoActivate: Check used boxes" << std::endl;
00913 
00914 #endif
00915         // curBox checken
00916         CheckBoxesUsed();
00917 
00918         if ( !BoxUsed[curBox] ) {
00919                 curBox = 0;
00920 
00921                 for (int i = 0; i < MAX_BOX; i++)
00922                         if ( BoxUsed[i] ) {
00923                                 curBox = i;
00924                                 break;
00925                         }
00926         }
00927 
00928         SetAktuellesKeyboardInstrument(curBox);
00929 
00930         // WinAttrs säubern
00931         DEBUGLOG (other, _T("Clear window attributes"));
00932 
00933         for (WinKind kind = WK_KEY; kind < WK_NULL; kind++) {
00934                 size_t i;
00935 
00936                 while ( (i = WinAttrs[kind].GetCount()) > 0)
00937                         if ( !BoxUsed[WinAttrs[kind][i].Box] )
00938                                 WinAttrs[kind].RemoveAt(i);
00939         }
00940 
00941         DEBUGLOG (other, _T("Open other than logic; One window mode: %d"),OWM);
00942 
00943         // set windows except curBox setzen
00944         if ( !OWM )
00945                 for (WinKind kind = WK_KEY; kind < WK_LOGIC; kind++)
00946                         for (size_t i = 0; i < WinAttrs[kind].GetCount(); i++)
00947                                 if ( WinAttrs[kind][i].Box != curBox
00948                                                 &&  WinAttrs[kind][i].Wanted )
00949                                         TextBoxOpen(kind, WinAttrs[kind][i].Box);
00950 
00951         UpdateBoxMenu();
00952         MutFrame * routewin = dynamic_cast<MutFrame *>(FindWindowById(WK_ROUTE));
00953         if ( routewin ) routewin->UpdateBoxMenu();
00954         DEBUGLOG (other, _T("Open Logic window"));
00955         // curBox-Fenstersetzen
00956         //  LogicWinOpen(curBox);
00957         LogicOn = true;
00958 
00959         // Toolbar
00960         /*2     ControlBar->Remove(*ButtonActivate);
00961         ControlBar->Insert(*ButtonStop, TGadgetWindow::Before, ButtonPanic);
00962         ControlBar->LayoutSession();*/
00963         // Statusbar
00964         SetStatus(SG_LOGIC);
00965 
00966         DEBUGLOG (other, _T("Open Text boxes: %d -- %d"),WK_KEY,WK_ACT);
00967 
00968         for (size_t i = 0; i < MAX_BOX; i++)
00969                 if (BoxUsed[i])
00970                         for (WinKind kind = WK_KEY; kind <= WK_ACT; kind++) {
00971                                 if ( TextBoxWanted[i][kind] )
00972                                         TextBoxOpen(kind, i);
00973                                 else
00974                                         DontWant(kind, i);
00975                         }
00976 
00977 
00978         DEBUGLOG (other, _T("Repaint route"));
00979 
00980         repaint_route();
00981 
00982         DEBUGLOG (other, _T("event.Skip()"));
00983         event.Skip(false);
00984 }
00985 
00986 wxMenuItem * MutFrame::ClearMenuItem(int id)
00987 {
00988         wxMenuItem * item = GetMenuBar()->FindItem(id);
00989 
00990         if (item->IsSubMenu())
00991                 ClearSubMenu(item);
00992 
00993         return item;
00994 }
00995 
00996 void MutFrame::ClearSubMenu(wxMenuItem * item)
00997 {
00998 
00999         wxMenu * menu = item->GetSubMenu();
01000 #ifdef DEBUG
01001         DEBUGLOG (other, _T("item: %s\n"),(item->GetText()).c_str())
01002         std::cerr << " (" << item << ")" << std::endl;
01003 #endif
01004 
01005         if (! menu) return;
01006 
01007         menu->AppendSeparator(); // just to make sure, the item group is finished.
01008 
01009 
01010         wxMenuItemList& l = menu->GetMenuItems();
01011 
01012         DEBUGLOG (other, _T(" %d items"),l.GetCount());
01013 
01014         for (wxMenuItemList::iterator i = l.begin(); i!=l.end(); i=l.begin()) {
01015                 wxMenuItem * node = *i;
01016                 DEBUGLOG (other, _T("ptr %x handling %s"), node,(node->GetText()).c_str());
01017 
01018                 if (node->IsSubMenu())
01019                         ClearSubMenu(node);
01020 
01021                 Disconnect(node->GetId(),wxEVT_COMMAND_MENU_SELECTED);
01022 
01023                 DEBUGLOG (other, _T("destroying %s"),(node->GetText()).c_str());
01024 
01025                 //    node->GetNext();
01026                 menu->Destroy(node);
01027         }
01028 }
01029 
01030 void MutFrame::RaiseLogic(wxCommandEvent& event)
01031 {
01032         if (!RaiseTheFrame()) {
01033                 DEBUGLOG (other, _T("Calling Logic frame for id %d"), event.GetId());
01034                 theFrame -> RaiseLogic(event);
01035                 return;
01036         }
01037 
01038         DEBUGLOG (other, _T("Reached logic frame"));
01039 
01040         wxASSERT(theFrame == this);
01041         DEBUGLOG (other, _T("%d"),event.GetId());
01042 
01043         size_t i = 0;
01044 
01045         while (i < MAX_BOX && boxCommandIds[i] != event.GetId()) i++;
01046 
01047         wxASSERT(i!=MAX_BOX);
01048 
01049         DEBUGLOG (other, _T("%d"),i);
01050 
01051         curBox = i;
01052 
01053         if (WinAttrs[WK_LOGIC][i].Win) {
01054                 WinAttrs[WK_LOGIC][i].Win->SetFocus();
01055 
01056                 wxFrame * win =
01057                         dynamic_cast<wxFrame *>(WinAttrs[WK_LOGIC][i].Win->GetParent());
01058 
01059                 if (win) win->Raise();
01060 
01061                 DEBUGLOG (other, _T("Parent type: %s"), muT(typeid(*( WinAttrs[WK_LOGIC][i].Win->GetParent())).name()).c_str());
01062 
01063                 GetMenuBar()->Check(event.GetId(),true);
01064         }
01065 }
01066 
01067 void MutFrame::DoStop()
01068 {
01069         if ( LogicOn ) {
01070                 LogicOn = false;
01071                 StopInDev();
01072                 Stop();
01073 
01074                 // Ampel umschalten
01075                 /*              ControlBar->Remove(*ButtonStop);
01076                 ControlBar->Insert(*ButtonActivate, TGadgetWindow::Before, ButtonPanic);
01077                 ControlBar->LayoutSession();*/
01078                 // Statusleiste
01079                 SetStatus(SG_NOTHING);
01080                 //              StatusBar->SetText("");
01081                 // Titel
01082                 //    SetTitle(APPNAME);
01083                 // alle Fenser schlieflen
01084                 wxMenuItem * boxSelector = ClearMenuItem(CM_SELECTBOX);
01085                 wxASSERT(boxSelector->IsSubMenu());
01086 
01087                 for (WinKind kind = WK_KEY; kind <= WK_LOGIC; kind++) {
01088                         DEBUGLOG (other, _T("Closing kind %d"),kind);
01089                         theFrame->CloseAll(kind);
01090                 }
01091 
01092                 AktionTraceReset();
01093 
01094                 repaint_route();
01095                 theFrame = NULL;
01096         }
01097 }
01098 
01099 void MutFrame::CmStop(wxCommandEvent& event)
01100 {
01101         DoStop();
01102 }
01103 
01104 void MutFrame::CmPanic(wxCommandEvent& WXUNUSED(event))
01105 {
01106         if ( LogicOn )
01107                 Panic();
01108 }
01109 
01110 void MutFrame::CeExecute(wxUpdateUIEvent& event)
01111 {
01112         //      event.Enable(!LogicOn && (Compiled || ActiveWinKind == WK_EDIT));
01113         event.Enable(!LogicOn);
01114 }
01115 
01116 
01117 void MutFrame::CeActivate(wxUpdateUIEvent& event)
01118 {
01119         //      event.Enable(!LogicOn && (Compiled || ActiveWinKind == WK_EDIT));
01120         event.Enable(!LogicOn && (dynamic_cast<MutEditFile *>(client)));
01121 }
01122 
01123 void MutFrame::CeStop(wxUpdateUIEvent& event)
01124 {
01125         event.Enable(LogicOn);
01126 }
01127 
01128 // Routenfenster anzeigen
01129 
01130 void MutFrame::CmRoutes(wxCommandEvent& event)
01131 {
01132         if ( GetId()== WK_ROUTE ) {
01133                 DEBUGLOG (other, _T("setting Focus"));
01134                 auimanager.Update();
01135                 Raise();
01136                 return;
01137         }
01138 
01139         if (client) {
01140                 event.Skip(true);
01141                 return;
01142         }
01143 
01144 //      MutFrame *subframe = new MutFrame((wxFrame *) NULL,WK_ROUTE, wxString().Format(_("%s -- Routes"),_(PACKAGE_NAME)),
01145 //              wxDefaultPosition,wxDefaultSize,wxDEFAULT_FRAME_STYLE | wxHSCROLL | wxVSCROLL);
01146 //      subframe->SetIcon(ICON(route));
01147 
01148         SetId(WK_ROUTE);
01149 
01150         int width, height;
01151 
01152         GetClientSize(&width, &height);
01153 
01154         client = new MutRouteWnd(this, wxPoint(0, 0), wxSize(width, height));
01155 
01156         auimanager.AddPane(client,wxAuiPaneInfo().Caption(_("Routes")).CenterPane().PaneBorder(false));
01157 
01158         auimanager.Update();
01159 
01160         SetIcon(ICON(route));
01161 
01162         if (LogicOn) UpdateBoxMenu();
01163         
01164         SetSize(wxDefaultSize);
01165 
01166 //      subframe->Show(true);
01167 
01168 }
01169 
01170 // TextBox-Arbeit: ToggleTextBox, TextBoxOpen, CmToggleKey, CmToggleTS
01171 
01172 void MutFrame::LogicWinOpen(int box)
01173 {
01174 //  TMDIChild* curChild = Client->GetActiveMDIChild();
01175         /*  TMDIMutChild *Win = new TMDIMutChild(WK_LOGIC, GeWinAttr(WK_LOGIC, box), *Client, "", new TMutWin(0, Module));
01176           Win->SetIcon(this, IDI_MUTABOR);
01177           Win->SetIconSm(this, IDI_MUTABOR);
01178           if (curChild && (curChild->GetWindowLong(GWL_STYLE) & WS_MAXIMIZE))
01179                   Win->Attr.Style |= WS_MAXIMIZE;
01180           Win->Create();*/
01181 //      MutChild *subframe = NewFrame(WK_LOGIC, box, _("Logic"), ICON(mutabor));
01182 
01183 
01184 
01185         int width, height;
01186         GetClientSize(&width, &height);
01187         width /= 2;
01188         height /= 2;
01189         MutLogicWnd *client = new MutLogicWnd(this, box,
01190                                               wxPoint(0, 0),
01191                                               wxSize(width,height));
01192         wxString Name;
01193         Name.Printf(_("Logic -- Box %d"),box);
01194         DEBUGLOG (other, _T("Adding pane '%s' with caption '%s'"), Name.Format(_T("Logic%d"),box).c_str(),Name.c_str());
01195         auimanager.AddPane(client,
01196                            wxAuiPaneInfo().Name(Name.Format(_T("Logic%d"),box))
01197                            .Caption(Name)
01198                            .Bottom()
01199                            .Floatable(true)
01200                            .CloseButton(false)
01201                            .MaximizeButton(true)
01202                            .Float());
01203         client->SetFocus();
01204         auimanager.Update();
01205 }
01206 
01207 void MutFrame::ToggleTextBox(WinKind kind)
01208 {
01209 #ifdef DEBUG
01210         std::cerr << "MutFrame::ToggleTextBox: kind: " << kind << std::endl
01211         << "MutFrame::ToggleTextBox: TextBoxWanted:"
01212         << TextBoxWanted[curBox][kind] << std::endl;
01213 #endif
01214 
01215         if (theFrame && (theFrame != this)) {
01216                 theFrame->ToggleTextBox(kind);
01217                 return;
01218         }
01219 
01220 
01221         TextBoxWanted[curBox][kind] = !TextBoxWanted[curBox][kind];
01222 
01223 #ifdef DEBUG
01224         std::cerr << "MutFrame::ToggleTextBox: LogicOn"
01225         << LogicOn << std::endl;
01226 #endif
01227 
01228         if ( !LogicOn ) return;
01229 
01230 #ifdef DEBUG
01231         std::cerr << "MutFrame::ToggleTextBox: IsOpen(kind, curBox)"
01232         << IsOpen(kind, curBox) << std::endl;
01233 
01234 #endif
01235         if ( IsOpen(kind, curBox) ) {
01236                 wxWindow *win = Get(kind, curBox)->Win;
01237                 //Get(kind, curBox)->Win->SendMessage(WM_CLOSE);
01238                 auimanager.DetachPane(win);
01239                 win->Close();
01240                 auimanager.Update();
01241                 //win->Close();
01242                 //win->Destroy();
01243         } else
01244                 TextBoxOpen(kind, curBox);
01245 }
01246 
01247 void MutFrame::TextBoxOpen(WinKind kind, int box)
01248 {
01249         DEBUGLOG (other, _T("%d,%d"),kind,box);
01250 
01251         char *s = NULL;
01252         wxString title;
01253 
01254         switch ( kind ) {
01255 
01256         case WK_KEY:
01257                 s = GetKeyString(box, asTS);
01258 
01259                 title.Printf(_("Current keys at Box %d"),box);
01260 
01261                 break;
01262 
01263         case WK_TS:
01264                 s = GetTSString(box, asTS);
01265 
01266                 title.Printf(_("Current tone system at Box %d"),box);
01267 
01268                 break;
01269 
01270         case WK_ACT:
01271                 if (CAW) {
01272                         s = GenerateCAWString();
01273                         title=_("Action log");
01274                 } else {
01275                         s = GenerateACTString(box);
01276                         title.Printf(_("Actions at Box %d"),box);
01277                 }
01278 
01279                 break;
01280 
01281         case WK_LOGIC:
01282                 wxLogWarning(_("Unexpected value: WK_LOGIC"));
01283 
01284                 break;
01285 
01286         case WK_ROUTE:
01287                 wxLogWarning(_("Unexpected value: WK_ROUTE"));
01288 
01289                 break;
01290 
01291         case WK_EDIT:
01292                 wxLogWarning(_("Unexpected value: WK_EDIT"));
01293 
01294                 break;
01295 
01296         case WK_NULL:
01297                 wxLogWarning(_("Unexpected value: WK_NULL"));
01298 
01299                 break;
01300 
01301         default:
01302                 wxLogError(_("Unexpected window kind: %d"), kind);
01303         }
01304 
01305         int width, height;
01306 
01307         GetClientSize(&width, &height);
01308         width /= 2;
01309         height /= 2;
01310 
01311         WinAttr *attr = GetWinAttr(kind, box);
01312         MutTextBox *client = new MutChild(kind,
01313                                           attr,
01314                                           this,
01315                                           -1,
01316                                           wxDefaultPosition,
01317                                           wxSize(width, height));
01318         DEBUGLOG (other, _T("client->winKind=%d"),client->GetKind());
01319         DEBUGLOG (other, _T("s:= %s"),s);
01320         DEBUGLOG (other, _T("client->winKind=%d"),client->GetKind());
01321 
01322         wxString str;
01323 
01324         if (s)
01325                 str = muT(s);
01326         else
01327                 str = wxEmptyString;
01328 
01329         DEBUGLOG (other, _T("client->winKind=%d"),client->GetKind());
01330 
01331         auimanager.AddPane(client,wxAuiPaneInfo().Caption(title)
01332                            .CloseButton(true).MaximizeButton(true)
01333                            .Float()
01334                            .Name(wxString::Format(_T("WK_%d_%d"),kind,box)));
01335 
01336         DEBUGLOG (other, _T("client->winKind=%d"),client->GetKind());
01337 
01338         client->NewText(str, true);
01339 
01340         DEBUGLOG (other, _T("client->winKind=%d"),client->GetKind());
01341 
01342         auimanager.Update();
01343 }
01344 
01345 void MutFrame::CmToggleKey(wxCommandEvent& WXUNUSED(event))
01346 {
01347         ToggleTextBox(WK_KEY);
01348 }
01349 
01350 void MutFrame::CmToggleTS(wxCommandEvent& WXUNUSED(event))
01351 {
01352         ToggleTextBox(WK_TS);
01353 }
01354 
01355 void MutFrame::CmToggleAct(wxCommandEvent& WXUNUSED(event))
01356 {
01357         ToggleTextBox(WK_ACT);
01358 }
01359 
01360 void MutFrame::CmToggleOWM(wxCommandEvent& WXUNUSED(event))
01361 {
01362         OWM = !OWM;
01363 
01364         if ( !LogicOn )
01365                 return;
01366 
01367         if ( OWM ) {
01368                 for (WinKind kind = WK_KEY; kind <= WK_LOGIC; kind++)
01369                         for (size_t i = 0; i < WinAttrs[kind].Count(); i++)
01370                                 if ( WinAttrs[kind][i].Box != curBox && WinAttrs[kind][i].Win ) {
01371                                         WinAttrs[kind][i].Wanted = 2; // um Wanted zu erhalten
01372                                         auimanager.DetachPane(WinAttrs[kind][i].Win);
01373                                 }
01374         } else
01375                 for (WinKind kind = WK_KEY; kind <= WK_LOGIC; kind++)
01376                         for (size_t i = 0; i < WinAttrs[kind].Count(); i++)
01377                                 if ( WinAttrs[kind][i].Box != curBox && WinAttrs[kind][i].Wanted )
01378                                 {
01379                                         if ( kind == WK_LOGIC )
01380                                                 LogicWinOpen(WinAttrs[kind][i].Box);
01381                                         else
01382                                                 TextBoxOpen(kind, WinAttrs[kind][i].Box);
01383                                 }
01384 }
01385 
01386 void MutFrame::CmToggleCAW(wxCommandEvent& WXUNUSED(event))
01387 {
01388         CAW = !CAW;
01389 
01390         if ( !LogicOn )
01391                 return;
01392 
01393         // ActWin f¸r curBox updaten
01394         WinAttr *WinAttr = Get(WK_ACT, curBox);
01395 
01396         if ( WinAttr && WinAttr->Win )
01397                 ((MutTextBox*)WinAttr->Win)->NewText(CAW ? GenerateCAWString() : GenerateACTString(curBox), 1);
01398 
01399         // andere Action-Fenster schlieflen bzw. ˆffnen
01400         if ( CAW ) {
01401                 for (size_t i = 0; i < WinAttrs[WK_ACT].Count(); i++)
01402                         if ( WinAttrs[WK_ACT][i].Box != curBox && WinAttrs[WK_ACT][i].Win ) {
01403                                 WinAttrs[WK_ACT][i].Wanted = 2; // um Wanted zu erhalten
01404                                 auimanager.DetachPane(WinAttrs[WK_ACT][i].Win);
01405                         }
01406         } else
01407                 for (size_t i = 0; i < WinAttrs[WK_ACT].Count(); i++)
01408                         if ( WinAttrs[WK_ACT][i].Box != curBox && WinAttrs[WK_ACT][i].Wanted )
01409                                 TextBoxOpen(WK_ACT, WinAttrs[WK_ACT][i].Box);
01410 }
01411 
01412 void MutFrame::CeToggleKey(wxUpdateUIEvent& event)
01413 {
01414         event.Check(TextBoxWanted[curBox][WK_KEY]);
01415 }
01416 
01417 void MutFrame::CeToggleTS(wxUpdateUIEvent& event)
01418 {
01419         event.Check(TextBoxWanted[curBox][WK_TS]);
01420 }
01421 
01422 void MutFrame::CeToggleAct(wxUpdateUIEvent& event)
01423 {
01424         event.Check(TextBoxWanted[curBox][WK_ACT]);
01425 }
01426 
01427 void MutFrame::CeToggleOWM(wxUpdateUIEvent& event)
01428 {
01429         event.Check(OWM);
01430 }
01431 
01432 void MutFrame::CeToggleCAW(wxUpdateUIEvent& event)
01433 {
01434         event.Check(CAW);
01435 }
01436 
01437 void MutFrame::CmSelectBox()
01438 {
01439         /*wx  TPopupMenu *Menu = new TPopupMenu();
01440           Menu->AppendMenu(0, -1, "Select a box");
01441           Menu->AppendMenu(MF_SEPARATOR , -1, "");
01442           for (int box = 0; box < MAX_BOX; box++)
01443             if ( BoxUsed[box] )
01444             {
01445               char s[80];
01446               sprintf(s, "Box %d", box);
01447               Menu->AppendMenu((box == curBox) ? MF_CHECKED : 0, 10000+box, strdup(s));
01448             }
01449           TPoint p(200, 180);
01450           GetMainWindow()->ClientToScreen(p);
01451           Menu->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON,
01452             p, 0, *GetMainWindow(), 0);
01453           delete Menu;*/
01454 }
01455 
01456 void MutFrame::CmCloseChild()
01457 {
01458         if ( ChildToClose )
01459                 ChildToClose->Close();
01460 }
01461 
01462 // Windowsize -------------------------------------------------------
01463 
01464 wxSize subSize = wxDefaultSize;
01465 
01466 int WSize[4][3] =
01467         { { 640, 530, 252},
01468           { 800, 646, 328},
01469           {1024, 826, 425},
01470           {1280, 994, 620} };
01471 
01472 void MutFrame::WindowSize(MutChild *win)
01473 {
01474         wxLogWarning(_("MutFrame::WindowSize:  not implemented" ));
01475 #if 0
01476 
01477         if ( !subSize.IsFullySpecified() ) {
01478                 wxScreenDC *sdc = new wxScreenDC();
01479                 wxSize deskSize = sdc->GetSize();
01480                 delete sdc;
01481                 subSize.Set(0, 0);
01482 
01483                 for (int i = 0; i < 4; i++)
01484                         if ( deskSize.GetWidth() == WSize[i][0] )
01485                                 subSize.Set(WSize[i][1], WSize[i][2]);
01486         }
01487 
01488         if ( win->winAttr->W ) {
01489                 win->SetSize(win->winAttr->X, win->winAttr->Y,
01490                              win->winAttr->W, win->winAttr->H);
01491         } else {
01492                 int w, h;
01493                 GetClientSize(&w, &h);
01494                 // get size of editor window
01495                 int w1 = w * 4 / 5, h1 = h * 2 / 3;
01496 
01497                 if ( subSize.GetWidth() != 0 ) {
01498                         w1 = subSize.GetWidth();
01499                         h1 = subSize.GetHeight();
01500                 }
01501 
01502                 if ( w - w1 < 112 )
01503                         w1 = w - 112;
01504 
01505                 int n = (NumberOfOpen(win->winKind)-1)*22;
01506 
01507                 if ( demo )
01508                         switch ( win->winKind ) {
01509 
01510                         case WK_KEY:
01511                                 win->SetSize(w / 2-n, n, w / 4, h / 2);
01512 
01513                                 break;
01514 
01515                         case WK_TS:
01516                                 win->SetSize(w / 2 + w / 4-n, n, w / 4, h);
01517 
01518                                 break;
01519 
01520                         case WK_ACT:
01521                                 win->SetSize(w / 2 + n, h / 2-n, w / 4, h - h / 2);
01522 
01523                                 break;
01524 
01525                         case WK_LOGIC:
01526                                 win->SetSize(n, n, w / 2, h);
01527 
01528                                 break;
01529 
01530                         case WK_ROUTE:
01531                                 win->SetSize(n, n, w / 2, h);
01532 
01533                                 break;
01534                         }
01535                 else
01536                         switch ( win->winKind ) {
01537 
01538                         case WK_KEY:
01539                                 win->SetSize(w1-n, n, w - w1, h / 2);
01540 
01541                                 break;
01542 
01543                         case WK_TS:
01544                                 win->SetSize(w1-n, h / 2-n, w - w1, h - h / 2);
01545 
01546                                 break;
01547 
01548                         case WK_ACT:
01549                                 win->SetSize(w1 * 3 / 4-n, h1-n, w1 - w1 * 3 / 4, h - h1);
01550 
01551                                 break;
01552 
01553                         case WK_LOGIC:
01554                                 win->SetSize(n, h1-n, w1 * 3 / 4, h - h1);
01555 
01556                                 break;
01557 
01558                         case WK_ROUTE:
01559                                 win->SetSize(n, h1-n, w1 * 3 / 4, h - h1);
01560 
01561                                 break;
01562                         };
01563         }
01564 
01565 #endif
01566 }
01567 
01568 //
01569 // Save the the position and contents of the windows to the "desktop" file.
01570 //
01571 void MutFrame::SaveState()
01572 {
01573         wxConfigBase *config = wxConfig::Get();
01574 
01575         wxPoint pos = GetPosition();
01576         wxSize size = GetSize();
01577         int DeskMax = size.GetWidth() < GetClientSize().GetWidth();
01578         config->SetPath(_T("Desktop"));
01579         config->Write(_T("X Position"),pos.x);
01580         config->Write(_T("Y Position"),pos.y);
01581         config->Write(_T("Width"),size.GetWidth());
01582         config->Write(_T("Height"),size.GetHeight());
01583         config->Write(_T("DeskMax"),DeskMax);
01584 
01585         config->SetPath(_T(".."));
01586 }
01587 
01588 /*bool CheckMutChild(char *name, char *data)
01589 {
01590         for (TWinKind kind = WK_KEY; kind <= WK_ROUTE; kind++)
01591                 if ( !stricmp(name, WinName[kind]) )
01592                 {
01593       int box, x, y, w, h, wanted;
01594       int test = sscanf (data, " = %d %d %d %d %d %d",
01595         &box, &x, &y, &w, &h, &wanted);
01596                   if (test < 5)
01597                   {
01598                     break;
01599                   }
01600       TWinAttr *WinAttr = GetWinAttr(kind, box);
01601       WinAttr->X = x; WinAttr->Y = y;
01602       WinAttr->W = w; WinAttr->H = h;
01603       WinAttr->Wanted = wanted;
01604       return true;
01605           }
01606   return false;
01607 }*/
01608 
01609 void MutFrame::RestoreState()
01610 {
01611         //  int DeskMax = 1, WinMax = 2, HelpMax = 0;
01612         wxConfigBase *config = wxConfig::Get();
01613         
01614 /* TODO: implement this in a robust way. The current implementation does not check that the window is inside the accesible area of the screen.
01615         int x=0, y=0, w=0, h=0;
01616 
01617         config->SetPath(_T("Desktop"));
01618         //  DeskMax=config->Read(_T("DeskMax"),0l);
01619 
01620         if ((x=config->Read(_T("X Position"),0l)) &&
01621                         (y=config->Read(_T("Y Position"),0l)) &&
01622                         (w=config->Read(_T("Width"),0l)) &&
01623                         (h=config->Read(_T("Height"),0l))) {
01624                 SetSize(x, y, w, h);
01625 
01626 #ifdef DEBUG
01627                 std::cerr << "x=" << x << ", y=" << y << ", w=" << w << ", h=" << h << std::endl;
01628 #endif
01629         }
01630 
01631         config->SetPath(_T(".."));
01632 */
01633         //  wxLogWarning(_("MutFrame::RestoreState() doesn't handle multiple windows"));
01634 }
01635 
01636 // Recorder-Knöpfe --------------------------------------------------
01637 
01638 void MutFrame::StopInDev()
01639 {
01640         int nr = 0;
01641 
01642         for ( InDevice *In = InDevice::GetDeviceList(); In; In = In->GetNext(), 
01643                 nr++)
01644           if ( In->GetMode() == MutaborDevicePlay || In->GetMode() == MutaborDevicePause ) {
01645             //      In->Mode = MutaborDeviceStop;
01646             //          InDeviceAction(nr, In->Mode);
01647             In->Stop();
01648           }
01649 
01650         SetStatus(1-LogicOn);
01651 }
01652 
01653 
01654 void MutFrame::CmInDevStop(wxCommandEvent& WXUNUSED(event))
01655 {
01656         StopInDev();
01657         repaint_route();
01658         SetStatus(1-LogicOn);
01659 }
01660 
01661 void MutFrame::CmInDevPlay(wxCommandEvent& event)
01662 {
01663         DEBUGLOG (other, _T(""));
01664 
01665         if ( !LogicOn )
01666                 CmDoActivate(event);
01667 
01668         int nr = 0;
01669 
01670         for ( InDevice *In = InDevice::GetDeviceList(); In; In = In->GetNext(), nr++)
01671           if ( In->GetMode() == MutaborDeviceStop ||
01672                In->GetMode() == MutaborDevicePause ) {
01673             //                  In->Mode = MutaborDevicePlay;
01674             In->Play();
01675             //                  InDeviceAction(nr, In->Mode);
01676           }
01677         
01678         repaint_route();
01679 
01680         SetStatus(SG_PLAY);
01681 }
01682 
01683 void MutFrame::CmInDevPause(wxCommandEvent& WXUNUSED(event))
01684 {
01685   int nr = 0;
01686 
01687   for ( InDevice *In = InDevice::GetDeviceList(); In; In = In->GetNext(), nr++)
01688     if ( In->GetMode() == MutaborDevicePlay ) {
01689       //                        In->Mode = MutaborDevicePause;
01690       //                InDeviceAction(nr, In->Mode);
01691       In->Pause();
01692     }
01693   
01694   repaint_route();
01695   
01696   SetStatus(SG_PAUSE);
01697 }
01698 
01699 void MutFrame::CeInDevStop(wxUpdateUIEvent& event)
01700 {
01701   for ( InDevice *In = InDevice::GetDeviceList(); In; In = In->GetNext())
01702     if ( In->GetType() >= DTMidiFile &&
01703          (In->GetMode() == MutaborDevicePlay ||
01704           In->GetMode() == MutaborDevicePause) ) {
01705       event.Enable(true);
01706       return;
01707     }
01708   event.Enable(false);
01709 }
01710 
01711 void MutFrame::CeInDevPlay(wxUpdateUIEvent& event)
01712 {
01713   if ( !LogicOn ) {
01714     DEBUGLOG (other, _T("Logic is off"));
01715     event.Enable(false);
01716     return;
01717   }
01718 
01719   for ( InDevice *In = InDevice::GetDeviceList(); In; In = In->GetNext()) {
01720     DEBUGLOG (routing, _T("checking Device type %d >= %d with mode %d for pointer %p"),
01721               In->GetType(),
01722               DTMidiFile,
01723               In->GetMode(),
01724               In);
01725 
01726     if ( In->GetType() >= DTMidiFile &&
01727          (In->GetMode() == MutaborDeviceStop ||
01728           In->GetMode() == MutaborDevicePause) ) {
01729       DEBUGLOG (other, _T("Device can be activated"));
01730       event.Enable(true);
01731       return;
01732     }
01733     
01734     DEBUGLOG (other, _T("Device can not be activated"));
01735   }
01736 
01737   event.Enable(false);
01738 }
01739 
01740 void MutFrame::CeInDevPause(wxUpdateUIEvent& event)
01741 {
01742   bool Pause = 0;
01743   
01744   for ( InDevice *In = InDevice::GetDeviceList(); In; In = In->GetNext())
01745     if ( In->GetType() >= DTMidiFile ) {
01746       if ( In->GetMode() == MutaborDevicePlay ) {
01747         event.Enable(true);
01748         
01749         if ( curStatusImg != SG_PLAY )
01750           SetStatus(SG_PLAY);
01751         
01752         return;
01753       } else if ( In->GetMode() == MutaborDevicePause )
01754         Pause = true;
01755     }
01756   if ( Pause ) {
01757     if ( curStatusImg != SG_PAUSE )
01758       SetStatus(SG_PAUSE);
01759   } else if ( curStatusImg != 1-LogicOn )
01760     SetStatus(1-LogicOn);
01761   
01762   event.Enable(false);
01763 }
01764 
01765 void MutFrame::CmSetTitle(wxCommandEvent& event)
01766 {
01767         SetTitle(wxString::Format(_("%s -- %s"), APPNAME, event.GetString().c_str()));
01768 }
01769 
01770 // Updaten der Protokollfenster
01771 void MutFrame::UpdateUI(wxCommandEvent& WXUNUSED(event))
01772 {
01773         for (size_t i = 0; i < WinAttrs[WK_KEY].GetCount(); i++) {
01774                 WinAttr *winAttr = &WinAttrs[WK_KEY][i];
01775 
01776                 if ( winAttr->Win && KeyChanged(winAttr->Box) )
01777                         ((MutTextBox*)winAttr->Win)->
01778                         NewText(GetKeyString(winAttr->Box, asTS), 1);
01779         }
01780 
01781         for (size_t i = 0; i < WinAttrs[WK_TS].GetCount(); i++) {
01782                 WinAttr *winAttr = &WinAttrs[WK_TS][i];
01783 
01784                 if ( winAttr->Win && TSChanged(winAttr->Box) )
01785                         ((MutTextBox*)winAttr->Win)->
01786                         NewText(GetTSString(winAttr->Box, asTS), 1);
01787         }
01788 
01789         // Aktionen
01790         if ( TakeOverAktions() )
01791         {
01792                 if ( CAW ) {
01793                         WinAttr *winAttr = Get(WK_ACT, curBox);
01794 
01795                         if ( winAttr && winAttr->Win )
01796                                 ((MutTextBox*)winAttr->Win)->NewText(GenerateCAWString(), 1);
01797                 } else {
01798                         for (size_t i = 0; i < WinAttrs[WK_ACT].GetCount(); i++) {
01799                                 WinAttr *winAttr = &WinAttrs[WK_ACT][i];
01800 
01801                                 if ( winAttr->Win && ACTChanged(winAttr->Box) )
01802                                         ((MutTextBox*)winAttr->Win)->
01803                                         NewText(GenerateACTString(winAttr->Box), 1);
01804                         }
01805                 }
01806         }
01807         // Zeilen/Spalte
01808         /*  if ( ActiveWinKind == WK_EDIT )
01809             {
01810             TMDIChild* curChild = Client->GetActiveMDIChild();
01811             if ( curChild )
01812             curChild->SendMessage(WM_COMMAND, CM_GETLINE);
01813             }
01814             else
01815             EditLine = -1;
01816             if ( EditLine != oldEditLine || EditRow != oldEditRow )
01817             {
01818             char s[10] = "";
01819             if ( EditLine != -1 ) sprintf(s, "%d:%d", EditLine, EditRow);
01820             IndikatorGadget->SetText(s);
01821             oldEditLine = EditLine; oldEditRow = EditRow;
01822             }*/
01823 
01824 
01825         if ( InDevicesChanged() ) {
01826                 bool NRT_Finish = false;
01827 
01828 
01829                 for (InDevice *In = InDevice::GetDeviceList(); In; In = In->GetNext()) {
01830                   if ( !In || In->GetMode() == MutaborDeviceCompileError ) continue;
01831                   if ( In->GetMode() ==  MutaborDeviceTimingError ) {
01832                     In->SetMode(MutaborDeviceStop);
01833                     In->Stop();
01834                     NRT_Finish = !RealTime;
01835                   }
01836                 }
01837 
01838                 repaint_route();
01839 
01840                 if ( !RealTime )
01841                         wxMessageBox(_("Translation in batch mode completed. Output was generated."),
01842                                      _("Batch translation finished"), wxOK);
01843         }
01844 }
01845 
01846 
01847 #if 0
01848 void MutFrame::OnIdle(wxIdleEvent& event)
01849 {
01851   //    wxCommandEvent event1(wxEVT_COMMAND_MENU_SELECTED, CM_UPDATEUI);
01852   //    UpdateUI(event1);
01853         event.Skip();
01854 }
01855 #endif
01856 
01857 void MutFrame::OnEraseBackground(wxEraseEvent& event)
01858 {
01859         if (client)
01860                 event.Skip();
01861 }
01862 
01863 wxAuiDockArt* MutFrame::GetDockArt()
01864 {
01865         std::cout << "MutFrame::GetDockArt()" << std::endl;
01866         return auimanager.GetArtProvider();
01867 }
01868 
01869 
01870 
01871 void MutFrame::OnSize(wxSizeEvent& event)
01872 {
01873         event.Skip();
01874 }
01875 
01876 
01877 
01878 wxRect MutFrame::DetermineFrameSize ()
01879 {
01880         DEBUGLOG (other, _T(""));
01881 
01882         wxSize scr = wxGetDisplaySize();
01883 
01884         // determine default frame position/size
01885         wxRect normal;
01886         wxPoint currpos = GetPosition();
01887 
01888         if (scr.x <= 800) {
01889                 normal.x = 40 / 2;
01890                 normal.width = scr.x - 40;
01891         } else {
01892                 normal.x = currpos.x;
01893                 normal.width = 800;                     
01894         }
01895 
01896         if (scr.y <= 600) {
01897                 normal.y = 80 / 2;
01898                 normal.height = scr.y - 80;
01899         } else {
01900                 normal.y = currpos.y;
01901                 normal.height = 600;
01902         }
01903 
01904         return normal;
01905 }
01906 
01908 
01913 void MutFrame::CloseAll(WinKind kind)
01914 {
01915         DEBUGLOG (other, _T(""));
01916 
01917         auimanager.Update();
01918 
01919         for (size_t i = WinAttrs[kind].Count(); i >0; i--) {
01920                 DEBUGLOG (other, _T("kind %d (%d of %d)"),kind,i,WinAttrs[kind].Count());
01921                 WinAttr &win = WinAttrs[kind].Item(i-1);
01922 
01923                 if ( win.Win ) {
01924                         DEBUGLOG (other, _("Closing window of class %s"), muT(typeid(*(win.Win)).name()).c_str());
01925                         win.Wanted = 2;
01926 
01927                         CloseClientWindow(win.Win);
01928                         DEBUGLOG (other, _T("Returned."));
01929                 }
01930         }
01931 }
01932 
01933 void MutFrame::UpdateBoxMenu()
01934 {
01935 #ifdef DEBUG
01936         std::cout << "MutFrame::CmDoActivate: Set Box selection menu" << std::endl;
01937 #endif
01938         wxMenuItem * boxSelector = ClearMenuItem(CM_SELECTBOX);
01939         wxASSERT(boxSelector->IsSubMenu());
01940         wxMenu * boxMenu = boxSelector->GetSubMenu();
01941         wxASSERT(boxMenu);
01942         DEBUGLOG (other, _T("boxMenu = %p"),boxMenu);
01943         //  wxID_HIGHEST
01944         //  wxMenu *
01945 
01946         for (int i = 0, j=0; i < MAX_BOX; i++) {
01947                 if (BoxUsed[i]) {
01948                         if (theFrame == this) LogicWinOpen(i);
01949 
01950                         if (!boxCommandIds[i]) {
01951                                 boxCommandIds[i]=wxNewId();
01952                                 DEBUGLOG (other, _("Box %d got id %d"),i,boxCommandIds[i]);
01953                         }
01954 
01955                         DEBUGLOG (other, _("Currently %d items in box menu"),boxMenu->GetMenuItemCount());
01956 
01957                         DEBUGLOG (other, _("Appending menu for box %d with id %d"),i,boxCommandIds[i]);
01958                         wxString name = wxString::Format(_("Select box %d\tCtrl+%d"),i,i);
01959                         wxString description = wxString::Format(_("Select box %d as the active Box for box specific commands."),i);
01960                         wxASSERT(!(GetMenuBar()->FindItem(boxCommandIds[i])));
01961                         wxMenuItem * item = new wxMenuItem(boxMenu,boxCommandIds[i],
01962                                                            name,
01963                                                            description,
01964                                                            wxITEM_RADIO);
01965                         boxMenu->Append(item);
01966 
01967                         if (i == curBox) boxMenu->Check(boxCommandIds[i],true);
01968 
01969                         DEBUGLOG (other, _("Connecting command with id %d for box %d"),
01970                                  i,boxCommandIds[i]);
01971 
01972                         Connect( boxCommandIds[i],
01973                                  wxEVT_COMMAND_MENU_SELECTED,
01974                                  wxCommandEventHandler(MutFrame::RaiseLogic) );
01975 
01976                 }
01977         }
01978 }
01979 
01980 bool MutFrame::RaiseTheFrame()
01981 {
01982         if (this == theFrame) return true;
01983 
01984         theFrame->Raise();
01985 
01986         return false;
01987 }
01988 
01989 // Boxes used
01990 
01991 bool BoxUsed[MAX_BOX];
01992 
01993 void CheckBoxesUsed()
01994 {
01995         for (int i = 0; i < MAX_BOX; i++)
01996                 BoxUsed[i] = false;
01997 
01998         for (InDevice *In = InDevice::GetDeviceList(); In; In = In->GetNext())
01999           for (Route *R = In->GetRoutes(); R; R = R->GetNext())
02000             if ( R->Box >= 0 ) {
02001               if (R->Box >= MAX_BOX) UNREACHABLE;
02002               else
02003                 BoxUsed[R->Box] = true;
02004             }
02005 }
02006 
02007 
02008 int SmallestBoxUsed()
02009 
02010 {
02011   int Box = MAX_BOX; // unused value
02012 
02013         for (InDevice *In = InDevice::GetDeviceList(); In; In = In->GetNext())
02014           for (Route *R = In->GetRoutes(); R; R = R->GetNext())
02015             if ( R->Box >= 0 )
02016               Box = STD_PRE::min(Box, R->Box);
02017 
02018         if ( Box == MAX_BOX )
02019                 return 0;
02020         else
02021                 return Box;
02022 }
02023 
02024 
02025 //\}

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