home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / Command.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  7.7 KB  |  248 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18. /* 
  19.    Command.h -- command definitions
  20.    Created: Chris Toshok <toshok@netscape.com>, 13-Aug-96.
  21.  */
  22.  
  23.  
  24.  
  25. #ifndef _xfe_command_h
  26. #define _xfe_command_h
  27.  
  28. #include <X11/Intrinsic.h> /* for the definition of XrmQuark. */
  29.  
  30. #undef Bool
  31. #include <xp_core.h>
  32.  
  33. #include "commands.h"
  34.  
  35. /* use this to pass the (useful) event info down to doCommand() callees */
  36. typedef enum 
  37. {
  38.     XFE_COMMAND_EVENT_NO_IDEA = 0,
  39.     XFE_COMMAND_EVENT_ACTION,
  40.     XFE_COMMAND_BUTTON_ACTIVATE,
  41.     XFE_COMMAND_REMOTE_ACTION
  42. } XFE_CommandEventType;
  43.  
  44. typedef struct XFE_CommandInfo
  45. {
  46. public:
  47.     XFE_CommandEventType type;
  48.     Widget    widget;
  49.     XEvent*   event;
  50.     String*   params;
  51.     Cardinal* nparams;
  52.     Cardinal  nparams_store;
  53.     XEvent    event_store;
  54.  
  55.     XFE_CommandInfo(XFE_CommandEventType t, Widget w, XEvent* e = NULL,
  56.                     String* p = NULL, Cardinal n = 0);
  57. } XFE_CommandInfo;
  58.  
  59. typedef char* CommandType;
  60.  
  61. class Command {
  62. public:
  63.     static CommandType intern(char* foo);
  64.     static CommandType convertOldRemote(char* foo);
  65.  
  66.     static char* getString(CommandType command) 
  67.     {
  68.         return (char*)command;
  69.     }
  70.  
  71.   static const char *commandArmedCallback;
  72.   static const char *commandDispatchedCallback;
  73.   static const char *commandDisarmedCallback;
  74.   static const char *doCommandCallback;
  75. };
  76.  
  77. struct XFE_CommandParameters
  78. {
  79.     char* name;
  80.     void* data;
  81. };
  82.  
  83. class XFE_View;
  84. class XFE_Frame;
  85.  
  86. class XFE_AbstractCommand
  87. {
  88. public:
  89.     virtual CommandType getId() = 0;
  90.     virtual char*       getName() = 0;
  91.  
  92.     virtual XP_Bool     isDynamic() = 0;
  93.     virtual XP_Bool     isSlow() = 0;
  94.  
  95.     //    Call these from a View.
  96.     virtual XP_Bool     isEnabled(XFE_View* view, XFE_CommandInfo*) = 0;
  97.     virtual XP_Bool     isSelected(XFE_View*, XFE_CommandInfo*) = 0;
  98.     virtual XP_Bool     isDeterminate(XFE_View*, XFE_CommandInfo*) = 0;
  99.  
  100.     virtual XFE_CommandParameters* getParameters(XFE_View*) = 0;
  101.     virtual int         getParameterIndex(XFE_View*) = 0;
  102.     virtual void        setParameterIndex(XFE_View*, unsigned) = 0;
  103.     virtual char*       getLabel(XFE_View*, XFE_CommandInfo*) = 0;
  104.     virtual char*       getTipString(XFE_View*, XFE_CommandInfo*) = 0;
  105.     virtual char*       getDocString(XFE_View*, XFE_CommandInfo*) = 0;
  106.  
  107.     virtual void        doCommand(XFE_View* view, XFE_CommandInfo*) = 0;
  108.  
  109.     //    Call these from a Frame.
  110.     virtual XP_Bool     isEnabled(XFE_Frame*, XFE_CommandInfo*) = 0;
  111.     virtual XP_Bool     isSelected(XFE_Frame*, XFE_CommandInfo*) = 0;
  112.     virtual XP_Bool     isDeterminate(XFE_Frame*, XFE_CommandInfo*) = 0;
  113.  
  114.     virtual XFE_CommandParameters* getParameters(XFE_Frame*) = 0;
  115.     virtual int         getParameterIndex(XFE_Frame*) = 0;
  116.     virtual void        setParameterIndex(XFE_Frame*, unsigned) = 0;
  117.     virtual char*       getLabel(XFE_Frame*, XFE_CommandInfo*) = 0;
  118.     virtual char*       getTipString(XFE_Frame*, XFE_CommandInfo*) = 0;
  119.     virtual char*       getDocString(XFE_Frame*, XFE_CommandInfo*) = 0;
  120.  
  121.     virtual void        doCommand(XFE_Frame* view, XFE_CommandInfo*) = 0;
  122.  
  123. };
  124.  
  125. class XFE_Command : public XFE_AbstractCommand
  126. {
  127. public:
  128.     CommandType getId() { return m_id; };
  129.     char*       getName();
  130.  
  131.     XP_Bool     isDynamic();
  132.     XP_Bool     isSlow();
  133.  
  134.     //    Call these from a View.
  135.     XP_Bool     isEnabled(XFE_View* view, XFE_CommandInfo*);
  136.     XP_Bool     isSelected(XFE_View*, XFE_CommandInfo*);
  137.     XP_Bool     isDeterminate(XFE_View*, XFE_CommandInfo*);
  138.  
  139.     XFE_CommandParameters* getParameters(XFE_View*);
  140.     int         getParameterIndex(XFE_View*);
  141.     void        setParameterIndex(XFE_View*, unsigned);
  142.     char*       getLabel(XFE_View*, XFE_CommandInfo*);
  143.     char*       getTipString(XFE_View*, XFE_CommandInfo*);
  144.     char*       getDocString(XFE_View*, XFE_CommandInfo*);
  145.  
  146.     //    Call these from a Frame.
  147.     XP_Bool     isEnabled(XFE_Frame*, XFE_CommandInfo*);
  148.     XP_Bool     isSelected(XFE_Frame*, XFE_CommandInfo*);
  149.     XP_Bool     isDeterminate(XFE_Frame*, XFE_CommandInfo*);
  150.  
  151.     XFE_CommandParameters* getParameters(XFE_Frame*);
  152.     int         getParameterIndex(XFE_Frame*);
  153.     void        setParameterIndex(XFE_Frame*, unsigned);
  154.     char*       getLabel(XFE_Frame*, XFE_CommandInfo*);
  155.     char*       getTipString(XFE_Frame*, XFE_CommandInfo*);
  156.     char*       getDocString(XFE_Frame*, XFE_CommandInfo*);
  157.  
  158. protected:    
  159.     XFE_Command(CommandType id);
  160.  
  161. private:
  162.     CommandType m_id;
  163. };
  164.  
  165. class XFE_ViewCommand : public XFE_Command
  166. {
  167. public:
  168.     //    These will forward to the view.
  169.     XP_Bool     isEnabled(XFE_Frame* view, XFE_CommandInfo*);
  170.     XP_Bool     isSelected(XFE_Frame*, XFE_CommandInfo*);
  171.     XP_Bool     isDeterminate(XFE_Frame*, XFE_CommandInfo*);
  172.  
  173.     XFE_CommandParameters* getParameters(XFE_Frame*);
  174.     int         getParameterIndex(XFE_Frame*);
  175.     void        setParameterIndex(XFE_Frame*, unsigned);
  176.     char*       getLabel(XFE_Frame*, XFE_CommandInfo*);
  177.     char*       getTipString(XFE_Frame*, XFE_CommandInfo*);
  178.     char*       getDocString(XFE_Frame*, XFE_CommandInfo*);
  179.  
  180.     void        doCommand(XFE_Frame* view, XFE_CommandInfo*);
  181.  
  182. protected:
  183.     XFE_ViewCommand(CommandType id) : XFE_Command(id) { };
  184.  
  185.     //
  186.     //    Handle utility for provide command hacker feedback, generates:
  187.     //    "Syntax error in command: setFontFace(moby dick)"
  188.     //
  189.     void        doSyntaxErrorAlert(XFE_View*,  XFE_CommandInfo*);
  190. };
  191.  
  192. class XFE_FrameCommand : public XFE_Command
  193. {
  194. public:
  195.     //    These will forward to your Frame dual.
  196.     XP_Bool     isEnabled(XFE_View* view, XFE_CommandInfo*);
  197.     XP_Bool     isSelected(XFE_View*, XFE_CommandInfo*);
  198.     XP_Bool     isDeterminate(XFE_View*, XFE_CommandInfo*);
  199.  
  200.     XFE_CommandParameters* getParameters(XFE_View*);
  201.     int         getParameterIndex(XFE_View*);
  202.     void        setParameterIndex(XFE_View*, unsigned);
  203.     char*       getLabel(XFE_View*, XFE_CommandInfo*);
  204.     char*       getTipString(XFE_View*, XFE_CommandInfo*);
  205.     char*       getDocString(XFE_View*, XFE_CommandInfo*);
  206.  
  207.     void        doCommand(XFE_View* view, XFE_CommandInfo*);
  208.  
  209. protected:
  210.     XFE_FrameCommand(CommandType id) : XFE_Command(id) { };
  211.  
  212.     XFE_Frame*  getFrame(XFE_View*);
  213.     void        doSyntaxErrorAlert(XFE_Frame*,  XFE_CommandInfo*);
  214. };
  215.  
  216. int
  217. XFE_commandMatchParameters(XFE_CommandParameters*, char*);
  218.  
  219. class XFE_CommandList {
  220. public:
  221.     friend XFE_Command*     findCommand(XFE_CommandList*, CommandType);
  222.     friend XFE_CommandList* registerCommand(XFE_CommandList*&, XFE_Command*);
  223. private:
  224.     XFE_CommandList(XFE_CommandList*, XFE_Command*);
  225.     XFE_CommandList* m_next;
  226.     XFE_Command*     m_command;
  227. };
  228.  
  229. //
  230. //    This class will help you impliment context sensitive commands.
  231. //    You must impliment a getObjectType() method. This should return
  232. //    a string token which is the type of context you are in now.
  233. //    Once this is implimented, use your sub-class to give you context
  234. //    sensitive translations, etc.. See uses of objectIs in the editor's
  235. //    resources...djw
  236. //
  237. class XFE_ObjectIsCommand : public XFE_ViewCommand
  238. {
  239. public:
  240.     XFE_ObjectIsCommand();
  241.  
  242.             void  doCommand(XFE_View* view, XFE_CommandInfo* info);
  243.     virtual char* getObjectType(XFE_View*) = 0;
  244. };
  245.  
  246. #endif /* _xfe_command_h */
  247.  
  248.