Canola  0.8.D001
canola/dialog/special_key_symbol.cc
Go to the documentation of this file.
00001 //
00002 // canola - canon canola 1614p emulator
00003 // Copyright (C) 2011, 2012 Peter Miller
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License, version 3, as
00007 // published by the Free Software Foundation.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License along
00015 // with this program. If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 
00018 #include <canola/calculator/gnome.h>
00019 #include <canola/dialog/special_key_symbol.h>
00020 #include <canola/load_image.h>
00021 
00022 
00023 dialog_special_key_symbol::~dialog_special_key_symbol()
00024 {
00025 }
00026 
00027 
00028 dialog_special_key_symbol::dialog_special_key_symbol(
00029     calculator_gnome *a_subject
00030 ) :
00031     Dialog("Special Key Symbol", *a_subject, true),
00032     subject(a_subject),
00033     opcodes(16, 8)
00034 {
00035     set_icon(load_gui_image("canola"));
00036 
00037     std::string text =
00038         "The original Canola 1614P allowed you to \"chord\" keys to "
00039         "enter special key symbols from the keyboard.  This emulator "
00040         "can't do that, so this dialog is provided instead, so that "
00041         "you can enter any key symbol value."
00042         ;
00043     message.set_text(text);
00044     message.set_line_wrap(true);
00045     get_content_area()->add(message);
00046     message.show();
00047 
00048     Gdk::RGBA red("#FF0000");
00049     Gdk::RGBA gray("#cc8888");
00050     for (int y = 0; y < 8; ++y)
00051     {
00052         for (int x = 0; x < 16; ++x)
00053         {
00054             int n = (y << 4) + x;
00055             Gtk::Button &b = buttons[n];
00056             opcode_t op = (opcode_t)n;
00057             b.set_label(opcode_uname(op));
00058             b.signal_clicked().connect
00059             (
00060                 sigc::bind<int>
00061                 (
00062                     sigc::mem_fun(*this, &dialog_special_key_symbol::response),
00063                     n
00064                 )
00065             );
00066 
00067             Gtk::Label *label = dynamic_cast<Gtk::Label *>(b.get_child());
00068             if (label)
00069             {
00070                 label->set_justify(Gtk::JUSTIFY_CENTER);
00071                 if (opcode_valid(op))
00072                 {
00073                     if (opcode_red(op))
00074                     {
00075                         label->override_color(red, Gtk::STATE_FLAG_NORMAL);
00076                         label->override_color(red, Gtk::STATE_FLAG_ACTIVE);
00077                     }
00078                 }
00079                 else
00080                 {
00081                     label->override_color(gray, Gtk::STATE_FLAG_NORMAL);
00082                     label->override_color(gray, Gtk::STATE_FLAG_ACTIVE);
00083                 }
00084             }
00085             opcodes.attach(b, x, x + 1, y, y + 1);
00086         }
00087     }
00088     opcodes.show_all();
00089     get_content_area()->add(opcodes);
00090 
00091     add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
00092     set_default_response(Gtk::RESPONSE_CANCEL);
00093 }