// Calterm, the Gnome Terminal frontend for Calculators
// Copyright (C) 2001, Sebastian Ritterbusch (Rascal@Ritterbusch.de)
//                     Davide Angelocola
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//

#ifndef CALTERM_HPP_INCLUDED
#define CALTERM_HPP_INCLUDED

#include <string>
#include <vector>

using std::string;
using std::vector;

#include <gtk/gtk.h>

class Calterm;
class MenuEntry;

class Calterm
{
   public:
   
      // ---------- Constructors ---------
      Calterm(void); // when using this, you have to use setClientPath later!

      Calterm(string aClientPath);

      Calterm(string aWindowName,
              string aClientPath,
              int    aScrollBackLines=1000, 
              int    aScrollPosRight=1,
              int    aCursorBlink=1);

      Calterm(string aWindowName,
              string aClientPath,
              string aClientCommandLineOptions,
              int    aScrollBackLines=1000, 
              int    aScrollPosRight=1,
              int    aCursorBlink=1);
              
      // ---------- Configuration before start -------

      string      WindowName(void) const { return iWindowName; }
      Calterm &   setWindowName(string aWindowName) { iWindowName=aWindowName; return *this; }

      string      ClientPath(void) const { return iClientPath; }
      Calterm &   setClientPath(string aClientPath) { iClientPath=aClientPath; return *this; }

      int         ScrollBackLines(void) const { return iScrollBackLines; }
      Calterm &   setScrollBackLines(int aScrollBackLines) { iScrollBackLines=aScrollBackLines; return *this; }

      int         ScrollPosRight(void) const { return iScrollPosRight; }
      Calterm &   setScrollPosRight(int aScrollPosRight) { iScrollPosRight=aScrollPosRight; return *this; }

      int         CursorBlink(void) const { return iCursorBlink; }
      Calterm &   setCursorBlink(int aCursorBlink) { iCursorBlink=aCursorBlink; return *this; }
      
      Calterm &   addMenu(MenuEntry * a) { iMenuEntries.push_back(a); return *this; }
       
      // ---------- Starting the client -------
                                 
      void        start(int *argcP,char ***argvP);   
                                 // This starts the application
                                 // Invoke this method after all 
                                 // configuration is done.

      // ---------- Methods after start ------- 

      string      do_command(string c,int transparent=0); 
                                      // sends string to client
                                      // and returns result
                                      // show in window if
                                      // transparent is "on"
                                      
      void        send_command(string c);
                                      // send command to client
                                      // just like user input

      // ---------- Destructor ----------------

     ~Calterm(void);

      // ---------- Internal data -------------
   private:
      string   iWindowName;            // Name in titlebar
      string   iClientPath;            // Path and name of client program
      string   iClientCommandLineOptions; // Command line options for client
      int      iScrollBackLines;       // How many lines in Scrollback buffer
      int      iScrollPosRight;        // Where shall the scroll slider be
      int      iCursorBlink;           // Shall the cursor blink?
      
      Calterm & operator =(const Calterm &) { return *this; } // No assignment allowed

      GtkWidget   *iTerminal;           // The terminal widget
      GtkWidget   *iWindow;             // The window
      
      vector<MenuEntry *> iMenuEntries;   // List of dynamically generated
                                          // Menuitems
};

//
// MenuEntry helpers to be used with "addMenu"-method above:
//
// Generally all helpers have "menu" and "shortcut" (alias accelerator)
// parameters. A valid "menu" parameter is "/File/_Open".
//
// MenuFileSelect(menu,shortcut,title,function)
//    Creates Menuitem that starts a fileselector-box
//    with "title". On success the function will be called
//    with the string of the filename that was choosen.
//
// MenuFunction(menu,shortcut,function)
//    Creates a Menuitem which calls the function specified
//    This should be used for functions which open own windows as well
//
// MenuShowUrl(menu,shortcut,url)
//    Creates a Menuitem which opens a browser and displays the url
//
// MenuSimpleSend(menu,shortcut,send)
//    Selecting this menuitem sends the string "send" to the client
//
// MenuGtkFunction(menu,shortcut,function)
//    Like MenuFunction, but the functions have gtk-parameters
//    
// MenuSeparator(menu)
//    Inserts a separation-line (just take a dummy name 
//    like "/File/sep1" for the menu-name)
//
// MenuTop(menu,shortcut)
//    Inserts a top-menu (left aligned) like "File", "Edit", ...
//
// MenuTopRightAlign(menu,shortcut)
//    Inserts a top-menu (right alignment) for "Help"
//

class MenuEntry
{
   public:
      MenuEntry(string aMenu,string aShortcut="");
      
      GtkItemFactoryEntry Entry(void);

   protected:
      virtual GtkItemFactoryCallback CallBack(void)       { return NULL; }
      virtual guint                  CallBackAction(void) { return 0; }
      virtual gchar *                ItemType(void)       { return ""; }
      
   private:
      string iMenu,iShortcut;
};

class MenuFileSelect : public MenuEntry
{
   public:
      MenuFileSelect(string aMenu,string aShortcut,
                     string aTitle,void (*aFunction)(string,Calterm &));

      virtual GtkItemFactoryCallback CallBack(void);
      virtual guint                  CallBackAction(void) { return iAction; }
      virtual gchar *                ItemType(void)       { return ""; }
   private:
      int   iAction;
};

class MenuFunction : public MenuEntry
{
   public:
      MenuFunction(string aMenu,string aShortcut,
                   void (*aFunction)(Calterm &));

      virtual GtkItemFactoryCallback CallBack(void);
      virtual guint                  CallBackAction(void) { return iAction; }
      virtual gchar *                ItemType(void)       { return ""; }
   private:
      int   iAction;
};

class MenuShowUrl : public MenuEntry
{
   public:
      MenuShowUrl(string aMenu,string aShortcut,string aUrl);
      
      virtual GtkItemFactoryCallback CallBack(void);
      virtual guint                  CallBackAction(void) { return iAction; }
      virtual gchar *                ItemType(void)       { return ""; }
   private:
      int   iAction;
};

class MenuSimpleSend : public MenuEntry
{
   public:
      MenuSimpleSend(string aMenu,string aShortcut,string aSend);

      virtual GtkItemFactoryCallback CallBack(void);
      virtual guint                  CallBackAction(void) { return iAction; }
      virtual gchar *                ItemType(void)       { return ""; }
   private:
      int   iAction;
};

class MenuGtkFunction : public MenuEntry
{
   public:
      MenuGtkFunction(string aMenu,string aShortcut,GtkItemFactoryCallback aCallback)
                  : MenuEntry(aMenu,aShortcut), iCallback(aCallback) {}
      MenuGtkFunction(string aMenu,string aShortcut,GtkItemFactoryCallback1 aCallback)
                  : MenuEntry(aMenu,aShortcut), iCallback((GtkItemFactoryCallback)aCallback) {}

      virtual GtkItemFactoryCallback CallBack(void)       { return iCallback; }
      virtual guint                  CallBackAction(void) { return 0; }
      virtual gchar *                ItemType(void)       { return ""; }
   private:
      GtkItemFactoryCallback iCallback;
};

class MenuSeparator : public MenuEntry
{
   public:
      MenuSeparator(string aMenu) : MenuEntry(aMenu,"") {}
      virtual GtkItemFactoryCallback CallBack(void)       { return NULL; }
      virtual guint                  CallBackAction(void) { return 0; }
      virtual gchar *                ItemType(void)       { return "<Separator>"; }
};

class MenuTop : public MenuEntry
{
   public:
      MenuTop(string aMenu, string aShortcut="") : MenuEntry(aMenu,aShortcut) {}
      virtual GtkItemFactoryCallback CallBack(void)       { return NULL; }
      virtual guint                  CallBackAction(void) { return 0; }
      virtual gchar *                ItemType(void)       { return "<Branch>"; }
};

class MenuTopRightAlign : public MenuEntry
{
   public:
      MenuTopRightAlign(string aMenu, string aShortcut="") : MenuEntry(aMenu,aShortcut) {}
      virtual GtkItemFactoryCallback CallBack(void)       { return NULL; }
      virtual guint                  CallBackAction(void) { return 0; }
      virtual gchar *                ItemType(void)       { return "<LastBranch>"; }
};

#endif


syntax highlighted by Code2HTML, v. 0.9.1