2 Copyright (C) 2000 Paul Barton-Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <stdio.h> /* for sprintf, sigh ... */
25 #include <gdk/gdkkeysyms.h>
26 #include <gtkmm2ext/hexentry.h>
29 using namespace Gtkmm2ext;
32 HexEntry::on_key_press_event (GdkEventKey *ev)
35 if ((ev->keyval >= GDK_a && ev->keyval <= GDK_f) ||
36 (ev->keyval >= GDK_A && ev->keyval <= GDK_A) ||
37 (ev->keyval >= GDK_0 && ev->keyval <= GDK_9) ||
38 ev->keyval == GDK_space ||
39 ev->keyval == GDK_Tab ||
40 ev->keyval == GDK_Return ||
41 ev->keyval == GDK_BackSpace ||
42 ev->keyval == GDK_Delete) {
43 return Gtk::Entry::on_key_press_event (ev);
52 HexEntry::set_hex (unsigned char *msg, unsigned int len)
55 /* create a textual representation of the MIDI message */
60 rep = new char[(len * 3) + 1];
61 for (size_t i = 0; i < len; i++) {
62 sprintf (&rep[i*3], "%02x ", msg[i]);
73 HexEntry::get_hex (unsigned char *hexbuf, size_t buflen)
78 string text = get_text();
79 string::size_type length = text.length ();
80 string::size_type offset;
87 offset = text.find_first_of ("abcdef0123456789", offset);
89 if (offset == string::npos) {
93 /* grab two characters, but no more */
95 buf[0] = text[offset];
97 if (offset < length - 1) {
98 buf[1] = text[offset+1];
105 hexbuf[fetched_len++] = (char) strtol (buf, 0, 16);