?? tcmdwin.cpp
字號:
// tcmdwin.cpp// command window functions#include <string.h>#include <errno.h>#include <v/vnotice.h>#include <v/vutil.h>#include <v/vfilesel.h>#include <v/vprinter.h>#include <v/vynreply.h>#include "tcmdwin.h"#include "tchord.h"#include "tutils.h"typedef char string[255];// local symbolsconst ItemVal m_play = 100;const ItemVal m_chord = 101;const ItemVal m_rotated = 102;const ItemVal m_notes = 103;const ItemVal m_status = 104;static vMenu FileMenu[] ={ {"New", M_New, notSens, notChk, noKeyLbl, noKey, noSub}, {"Load...", M_Open, isSens, notChk, noKeyLbl, noKey, noSub}, {"Save", M_Save, notSens, notChk, noKeyLbl, noKey, noSub}, {"Save As...", M_SaveAs, notSens, notChk, noKeyLbl, noKey, noSub}, {"Print...", M_Print, notSens, notChk, noKeyLbl, noKey, noSub},#ifdef vDEBUG {"-", M_Line, notSens, notChk, noKeyLbl, noKey, noSub}, {"Debug...", M_SetDebug, isSens, notChk, noKeyLbl, noKey, noSub},#endif {"-", M_Line, notSens, notChk, noKeyLbl, noKey, noSub}, {"Exit", M_Exit, isSens, notChk, noKeyLbl, noKey, noSub}, {NULL}};static vMenu EditMenu[] ={ {"Undo", M_UnDo, notSens, notChk, noKeyLbl, noKey, noSub}, {"Clear", M_Clear, notSens, notChk, noKeyLbl, noKey, noSub}, {"Cut", M_Cut, notSens, notChk, noKeyLbl, noKey, noSub}, {"Copy", M_Copy, notSens, notChk, noKeyLbl, noKey, noSub}, {"Paste", M_Paste, notSens, notChk, noKeyLbl, noKey, noSub}, {NULL}};static vMenu OptionsMenu[] ={ {"Rotated", m_rotated, notSens, notChk, noKeyLbl, noKey, noSub}, {"Show Notes", m_notes, isSens, isChk, noKeyLbl, noKey, noSub}, {NULL}};static vMenu HelpMenu[] ={ {"About...", M_About, isSens, notChk, noKeyLbl, noKey, noSub}, {NULL}};vMenu StandardMenu[] ={ {"File", M_File, isSens, notUsed, notUsed, noKey, &FileMenu[0]}, {"Edit", M_Edit, isSens, notUsed, notUsed, noKey, &EditMenu[0]}, {"Options", M_Options, isSens, notUsed, notUsed, noKey, &OptionsMenu[0]}, {"Help", M_Help, isSens, notUsed, notUsed, noKey, &HelpMenu[0]}, {NULL}};// list of chords, initially emptychordList_t chord_list = { 0 };// last file loaded or savedstatic char filename[100] = "";// database of chordstutChords chords;static CommandObject CommandBar[] ={ {C_Label, M_None, M_None, "Chord:", NoList, CA_None, isSens, NoFrame, 0, 0}, {C_ComboBox, m_chord, m_chord, "Chord", (void*)chord_list, CA_Text, notSens, NoFrame, 0, 0}, {C_Blank, M_None, M_None, " ", NoList, CA_None, notSens, NoFrame, 0, 0}, {C_Button, m_play, m_play, "Play", NoList, CA_None, notSens, NoFrame, 0, 0}, {C_EndOfList, 0, 0, 0, 0, CA_None, 0, 0, 0}};static vStatus StatBar[] ={ {"No file loaded", m_status, CA_None, isSens, 0}, {0, 0, 0, 0, 0}};tCmdWindow::tCmdWindow(char* name, int height, int width) : vCmdWindow(name, height, width){ UserDebug1(Constructor, "tCmdWindow::tCmdWindow(%s) Constructor\n", name) myMenu = new vMenuPane(StandardMenu); AddPane(myMenu); myCanvas = new tCanvasPane; AddPane(myCanvas); myCmdPane = new vCommandPane(CommandBar); AddPane(myCmdPane); myStatus = new vStatusPane(StatBar); AddPane(myStatus); ShowWindow();}tCmdWindow::~tCmdWindow(){ UserDebug(Destructor, "tCmdWindow::~tCmdWindow() destructor\n") delete myMenu; delete myCanvas; delete myStatus; delete myCmdPane;}void tCmdWindow::WindowCommand(ItemVal id, ItemVal val, CmdType cType){ UserDebug1(CmdEvents, "tCmdWindow:WindowCommand(%d)\n", id) vNoticeDialog note(this); switch (id) { // File Menu commands case M_New: { UserDebug(CmdEvents, "tCmdWindow:WindowCommand(M_New)\n") vYNReplyDialog yesNo(this); int ans = yesNo.AskYN("Do you want to clear the loaded chords?"); if (ans == 1) { chord_list[0] = 0; SetValue(m_chord, 0, ChangeList); SetString(m_status, "No file loaded"); SetValue(m_chord, notSens, Sensitive); SetValue(m_play, notSens, Sensitive); SetValue(M_Save, notSens, Sensitive); SetValue(M_SaveAs, notSens, Sensitive); SetValue(M_Print, notSens, Sensitive); SetValue(M_New, notSens, Sensitive); strings_t strings = {0,0,0,0,0,0}; myCanvas->DrawChord(strings, GetValue(m_notes)); } break; } case M_Open: { UserDebug(CmdEvents, "tCmdWindow:WindowCommand(M_Open)\n") vFileSelect fsel(this); static char* filter[] = { "*.db", "*", 0 }; int fI = 0; int ans = fsel.FileSelect("Load File", filename, 99, filter, fI); if (ans && *filename) { int status = chords.load(filename); if (status == -1) { string s; sprintf(s, "Unable to load file\n`%s'\n%s", filename, strerror(errno)); note.Notice(s); } else { chords.chordNames(chord_list); SetValue(m_chord, 0, ChangeList); // notify that list has changed SetValue(m_chord, 0, Value); // select first item in list string s; sprintf(s, "File: %s", BaseName(filename)); SetString(m_status, s); SetValue(m_chord, isSens, Sensitive); SetValue(m_play, isSens, Sensitive); SetValue(M_Save, isSens, Sensitive); SetValue(M_SaveAs, isSens, Sensitive); SetValue(M_Print, isSens, Sensitive); SetValue(M_New, isSens, Sensitive); strings_t strings; chords.fingering(chord_list[GetValue(m_chord)], strings); myCanvas->DrawChord(strings, GetValue(m_notes)); } } else { note.Notice("No file selected."); } break; } case M_Save: { UserDebug(CmdEvents, "tCmdWindow:WindowCommand(M_Save)\n") // see if file exists by trying to open for reading fstream fs(filename, ios::in); if (!fs.bad()) { fs.close(); vYNReplyDialog yesNo(this); int ans = yesNo.AskYN("File already exists. Okay to overwrite?"); if (ans != 1) { break; } } int status = chords.save(filename); if (status == -1) { string s; sprintf(s, "Unable to save file\n`%s'\n%s", filename, strerror(errno)); note.Notice(s); } break; } case M_SaveAs: { UserDebug(CmdEvents, "tCmdWindow:WindowCommand(M_SaveAs)\n") vFileSelect fsel(this); static char* filter[] = { "*", 0 }; int fI = 0; int ans = fsel.FileSelect("Save As", filename, 99, filter, fI); if (ans && *filename) { int status = chords.save(filename); if (status == -1) { string s; sprintf(s, "Unable to save file\n`%s'\n%s", filename, strerror(errno)); note.Notice(s); } else { string s; sprintf(s, "File: %s", BaseName(filename)); SetString(m_status, s); } } else { note.Notice("No file name selected."); } break; } case M_Print: { UserDebug(CmdEvents, "tCmdWindow:WindowCommand(M_Print)\n") vPrinter printer; int status = printer.Setup(); if (status) { note.Notice("Printing is not yet implemented."); } break; } #ifdef vDEBUG case M_SetDebug: { UserDebug(CmdEvents, "tCmdWindow:WindowCommand(M_SetDebug)\n") vDebugDialog debug(this); debug.SetDebug(); break; }#endif case M_Exit: { UserDebug(CmdEvents, "tCmdWindow:WindowCommand(M_Exit)\n") theApp->Exit(); break; } // Edit Menu commands case M_UnDo: break; case M_Clear: break; case M_Cut: break; case M_Copy: break; case M_Paste: break; // Options Menu commands case m_rotated: // not implemented yet break; case m_notes: { UserDebug(CmdEvents, "tCmdWindow:WindowCommand(m_notes)\n") ItemVal curval = GetValue(id); // Get current status SetValue(m_notes, !curval, Checked); // Toggle check if (chord_list[0] != 0) { strings_t strings; chords.fingering(chord_list[GetValue(m_chord)], strings); myCanvas->DrawChord(strings, GetValue(m_notes)); } break; } // Help Menu commands case M_About: { UserDebug(CmdEvents, "tCmdWindow:WindowCommand(M_About)\n") vNoticeDialog note(this, "About"); note.Notice( "Guitar Tutor version 1.0\n" "by Jeff Tranter for the\n" "Linux Multimedia Guide\n" ); break; } // Command Bar commands case m_chord: { UserDebug(CmdEvents, "tCmdWindow:WindowCommand(m_chord)\n") strings_t strings; chords.fingering(chord_list[val], strings); myCanvas->DrawChord(strings, GetValue(m_notes)); break; } case m_play: { UserDebug(CmdEvents, "tCmdWindow:WindowCommand(m_play)\n") int index = GetValue(m_chord); UserDebug1(CmdEvents, "tCmdWindow:WindowCommand() playing chord %s\n", chord_list[index]); int status = chords.play(chord_list[index]); if (status == -1) { string s; sprintf(s, "Unable to play chord `%s'\n%s", chord_list[index], strerror(errno)); note.Notice(s); } break; } default: vCmdWindow::WindowCommand(id, val, cType); break; }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -