Main Page   Class Hierarchy   Data Structures   File List   Data Fields  

changepageorder.cpp

00001 /***************************************************************************
00002                           changepageorder.cpp  -  description
00003                              -------------------
00004     begin                : Thu Apr 03 2003
00005     copyright            : (C) 2003 by Michael Otto
00006     email                : Michael.Otto@saskathex.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include "changepageorder.h"
00019 
00020 #include "stockmarketvector.h"
00021 #include "stockmarket.h"
00022 
00023 #include <gtkmm/stock.h>
00024 
00025 #include "config.h"
00026 
00030 ChangePageOrder::ChangePageOrder(StockMarketVector * const stockMarketVector) {
00031 
00032   Gtk::Button *buttonNext, *buttonCancel;
00033   Gtk::HButtonBox *hButtonBox;
00034   Gtk::Label *label;
00035   Gtk::HSeparator *hSep;
00036 
00037 
00038   ChangePageOrder::stockMarketVector = stockMarketVector;
00039 
00040   set_title("change page ordering");
00041   set_border_width(5);
00042   set_resizable(false);
00043   set_modal(true);
00044   
00045   vbox = manage(new Gtk::VBox(false, 0));
00046   vbox->set_spacing(5);
00047   add (*vbox);
00048 
00049   if (stockMarketVector->getNumberOfStockMarkets() > 0) {
00050     label = manage (new Gtk::Label("Select a market:", 0));
00051     vbox->pack_start(*label, Gtk::PACK_SHRINK, 0);
00052     hSep = manage(new Gtk::HSeparator());
00053     vbox->pack_start(*hSep, Gtk::PACK_SHRINK, 0);
00054     vboxChoice = manage(new Gtk::VBox(false, 0));
00055 
00056     radioButtons.clear();
00057     Gtk::RadioButton::Group group;
00058     Gtk::RadioButton *rb;
00059     for (int i = 0; i < stockMarketVector->getNumberOfStockMarkets(); i++) {
00060       StockMarket *stockMarket = stockMarketVector->getStockMarket(i);
00061       rb = manage( new Gtk::RadioButton(group, stockMarket->getMarketName()));
00062       radioButtons.push_back(rb);
00063       vboxChoice->pack_start(*rb, Gtk::PACK_SHRINK, 0);
00064     }
00065     vbox->pack_start(*vboxChoice, Gtk::PACK_SHRINK, 0);
00066     hSep = manage(new Gtk::HSeparator());
00067     vbox->pack_start(*hSep, Gtk::PACK_SHRINK, 0);
00068     hButtonBox = manage( new Gtk::HButtonBox());
00069     hButtonBox->set_spacing(5);
00070     vbox->pack_start(*hButtonBox, Gtk::PACK_SHRINK, 0);
00071     buttonCancel = manage( new Gtk::Button(Gtk::Stock::CANCEL));
00072     buttonCancel->signal_clicked().connect(slot(*this,&ChangePageOrder::quit));
00073     hButtonBox->pack_start(*buttonCancel, Gtk::PACK_SHRINK, 0);
00074     buttonNext = manage( new Gtk::Button(Gtk::Stock::GO_FORWARD));
00075     buttonNext->signal_clicked().connect(slot(*this,&ChangePageOrder::setNewPageNumber));
00076     hButtonBox->pack_start(*buttonNext, Gtk::PACK_SHRINK, 0);
00077   } else {
00078     set_title("Message");
00079     label = manage (new Gtk::Label("There are no markets!"));
00080     vbox->pack_start(*label, Gtk::PACK_SHRINK, 0);
00081     buttonCancel = manage(new Gtk::Button(Gtk::Stock::OK));
00082     buttonCancel->signal_clicked().connect(slot(*this,&ChangePageOrder::quit));
00083     vbox->pack_start(*buttonCancel, Gtk::PACK_SHRINK, 0);
00084   }
00085   show_all();
00086 }
00087 
00091 ChangePageOrder::~ChangePageOrder() {
00092 }
00093 
00094 
00098 void ChangePageOrder::quit() {
00099   delete this;
00100 }
00101 
00107 void ChangePageOrder::setNewPageNumber() {
00108   Gtk::Button *buttonCancel, *buttonFinish;
00109   Gtk::HButtonBox *hButtonBox;
00110   Gtk::Table *table;
00111   Gtk::Label *label;
00112   Gtk::HSeparator *hSep;
00113 
00114   Gtk::RadioButton *rb;
00115   for (int i = 0; i < radioButtons.size(); i++) {
00116     rb = radioButtons[i];
00117     if (rb->get_active()) {
00118       stockMarket = stockMarketVector->getStockMarket(i);
00119 #ifdef DEBUG
00120       cout << "selected "<< stockMarket->getMarketName() << endl;
00121 #endif
00122     }
00123   }
00124   for (int i = 0; i < radioButtons.size(); i++) {
00125     rb = radioButtons[i];
00126     delete rb;
00127   }
00128   radioButtons.clear();
00129 
00130   delete vbox;
00131   Gtk::Adjustment *adjustmentNumber, *adjustmentBuyValue, *adjustmentBuyCost;
00132   vbox = manage(new Gtk::VBox(false, 0));
00133   vbox->set_spacing(5);
00134   add(*vbox);
00135   label = manage (new Gtk::Label("Set new page number:", 0));
00136   vbox->pack_start(*label, Gtk::PACK_SHRINK, 0);
00137   hSep = manage(new Gtk::HSeparator());
00138   vbox->pack_start(*hSep, Gtk::PACK_SHRINK, 0);
00139   table = manage(new Gtk::Table(2, 1, false));
00140   table->set_spacings(5);
00141   vbox->pack_start(*table, Gtk::PACK_EXPAND_WIDGET, 0);
00142 
00143   adjustmentNumber = manage(new Gtk::Adjustment(0, 2, stockMarketVector->getNumberOfStockMarkets()+1, 1, 10, 10));
00144   spinbuttonPageNumber = manage(new Gtk::SpinButton(*adjustmentNumber, 1, 0));
00145   spinbuttonPageNumber->set_editable(false);
00146   table->attach(*spinbuttonPageNumber, 1, 2, 1, 2);
00147 
00148   hSep = manage(new Gtk::HSeparator());
00149   vbox->pack_start(*hSep, Gtk::PACK_SHRINK, 0);
00150   hButtonBox = manage( new Gtk::HButtonBox());
00151   hButtonBox->set_spacing(5);
00152   vbox->pack_start(*hButtonBox, Gtk::PACK_SHRINK, 0);
00153   buttonCancel = manage( new Gtk::Button(Gtk::Stock::CANCEL));
00154   buttonCancel->signal_clicked().connect(slot(*this,&ChangePageOrder::quit));
00155   hButtonBox->pack_start(*buttonCancel, Gtk::PACK_SHRINK, 0);
00156   buttonFinish = manage( new Gtk::Button(Gtk::Stock::OK));
00157   buttonFinish->signal_clicked().connect(slot(*this,&ChangePageOrder::finish));
00158   hButtonBox->pack_start(*buttonFinish, Gtk::PACK_SHRINK, 0);
00159   show_all();
00160 }
00161 
00164 void ChangePageOrder::finish() {
00165   int page = spinbuttonPageNumber->get_value_as_int();
00166 #ifdef DEBUG
00167   cout << "new page number " << page << endl;
00168 #endif
00169   stockMarketVector->changeStockMarketPosition(stockMarket, page);
00170   quit();
00171 }
00172 
00177 bool ChangePageOrder::on_delete_event(GdkEventAny *event) {
00178   quit();
00179   return true;
00180 }

Generated on Tue May 27 21:24:01 2003 for gstockcalc by doxygen1.3-rc3