private void vm_LineWanted(object sender, LineWantedEventArgs e) { if (wrapperState == VMWrapperState.RequestRestore) entry = "restore"; if (wrapperState == VMWrapperState.RunCommand) entry = saveCommand; if (wrapperState == VMWrapperState.RequestSave) entry = "save"; e.Line = entry; }
private uint glk_select(uint[] args) { DeliverOutput(); if (glkWantLineInput) { string line; if (LineWanted == null) { line = ""; } else { LineWantedEventArgs e = new LineWantedEventArgs(); LineWanted(this, e); line = e.Line; } byte[] bytes = StringToLatin1(line); uint max = Math.Min(glkLineInputBufSize, (uint)bytes.Length); for (uint i = 0; i < max; i++) image.WriteByte(glkLineInputBuffer + i, bytes[i]); // return event GlkWriteReference( args[0], GlkConst.evtype_LineInput, 1, max, 0); glkWantLineInput = false; } else if (glkWantCharInput) { char ch; if (KeyWanted == null) { ch = '\0'; } else { KeyWantedEventArgs e = new KeyWantedEventArgs(); KeyWanted(this, e); ch = e.Char; } // return event GlkWriteReference( args[0], GlkConst.evtype_CharInput, 1, ch, 0); glkWantCharInput = false; } else { // no event GlkWriteReference( args[0], GlkConst.evtype_None, 0, 0, 0); } return 0; }
private void InputLine(uint address, uint bufSize) { string input = null; // we need at least 4 bytes to do anything useful if (bufSize < 4) return; // can't do anything without this event handler if (LineWanted == null) { image.WriteInt32(address, 0); return; } LineWantedEventArgs lineArgs = new LineWantedEventArgs(); // CancelEventArgs waitArgs = new CancelEventArgs(); // ask the application to read a line LineWanted(this, lineArgs); input = lineArgs.Line; if (input == null) { image.WriteInt32(address, 0); } else { byte[] bytes = null; // write the length first try { bytes = StringToLatin1(input); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } image.WriteInt32(address, (uint)bytes.Length); // followed by the character data, truncated to fit the buffer uint max = Math.Min(bufSize, (uint)bytes.Length); for (uint i = 0; i < max; i++) image.WriteByte(address + 4 + i, bytes[i]); } }
private void vm_LineWanted(object sender, LineWantedEventArgs e) { ViewModelLocator.Invoke(RequestLine); inputReadyEvent.WaitOne(); e.Line = command; }