/* Copyright 1997 Acorn Computers Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/***************************************************/
/* File   : Global.c                               */
/*                                                 */
/* Purpose: Holds all of the browser's globals.    */
/*                                                 */
/* Author : A.D.Hodgkinson                         */
/*                                                 */
/* History: 12-Nov-96: Created.                    */
/***************************************************/

#include "setjmp.h"

#include "wimp.h"
#include "event.h"

#include "svcprint.h"
#include "Global.h"
#include "Utils.h"

#ifdef TRACE

  /********************************************************/
  /* Trace level, for debug purposes only.                */
  /*                                                      */
  /* All trace output is done through the Printf function */
  /* which has an identical API to printf. This is        */
  /* commonly used for TML card output but any debug      */
  /* library can be linked in provided it provides the    */
  /* Printf interface.                                    */
  /*                                                      */
  /* Some debug output takes advantage of 16 colour modes */
  /* on the debug machine and sends VDU codes to change   */
  /* the text colour. This may influence the approach     */
  /* taken if authoring an alternative debugging library. */
  /*                                                      */
  /* Debug output is only available if the entire project */
  /* is compiled with TRACE defined in the compiler.      */
  /*                                                      */
  /* Some extra error messages (such as missing component */
  /* IDs) will be raised in TRACE builds. Even more may   */
  /* be raised by defining STRICT_PARSER in the compiler; */
  /* this ensures any image processing errors are         */
  /* reported and (e.g.) badly nested framesets will      */
  /* generate an appropriate complaint. STRICT_PARSER     */
  /* browser-owned errors are defined in the Messages     */
  /* file; TRACE errors are hard coded.                   */
  /*                                                      */
  /* Bit  Purpose                                    Arg  */
  /*                                                      */
  /* 0    MessageTrans related messages              MsgT */
  /* 1    Toolbar handler messages                   TBar */
  /* 2    Null claim/release messages                Null */
  /* 3    Browser window created/deleted             Wind */
  /* 4    Menu handler messages                      Menu */
  /* 5    Routine start, poll, exit                  Rout */
  /* 6    Fetcher functions                          Fetc */
  /* 7    Memory handling function calls             Memo */
  /* 8    Reformatter functions                      Refo */
  /* 9    Redraw functions                           Redr */
  /* 10   Font library functions                     Font */
  /* 11   Bounding box info for redraws              BBox */
  /* 12   Low level memory tracing                   LMem */
  /* 13   Running malloc/free count                  CMal */
  /* 14   Running flex alloc/free count              CFle */
  /* 15   Image handling code                        Imag */
  /* 16   History (both local and global)            Hist */
  /* 17   Frames                                     Fram */
  /* 18   Stream and memcpy/memmove trace            Stre */
  /* 19   Indications of special tags                Circ */
  /* 20   Table parsing information                  Tabl */
  /* 21   URI handler interfacing                    URIH */
  /* 22   Keyboard control functions                 KeyC */
  /* 23   Redraw rectangle display                   RBox */
  /* 24   JavaScript functions                       JScr */
  /* 25   Hotlist manager                            Hotl */
  /* 26   Save functions                             Save */
  /* 27   Dragging (for dashed outlines etc.)        Drag */
  /* 28   Message protocol tracing                   MsgP */
  /* 29   Choices dialogue functions                 Choi */
  /* 30   Plug-In protocol / Object handling         Plug */
  /*                                                      */
  /* To use, put -debug or -d into the command line args  */
  /* for running !RunImage, followed by a series of comma */
  /* separated values which are as given above. Use 'All' */
  /* for everything, though with caution (large amounts   */
  /* of output will be generated!). For example:          */
  /*                                                      */
  /*         Run !RunImage -d MsgT,Menu,Rout %%*0         */
  /********************************************************/

  unsigned int    tl;
  int             malloccount               = 0;
  int             flexcount                 = 0;

#endif

jmp_buf           env;                                         /* Used for error handler, so it can jump back to poll look if  */
                                                               /* the user selects OK rather than Cancel                       */

int               quit;                                        /* Set to 1 to indicate a successful exit should occur          */
int               modechanged;                                 /* Set to 1 immediately after a mode change                     */
int               printing;                                    /* Set to 1 during a printing loop, else 0                      */
int               drag_in_progress;                            /* Somebody somewhere in the browser is doing a drag operation  */
int               authorising;                                 /* Set to 1 during authorisation of a fetch (all fetches stop)  */

int               wimp_version;
int               nested_wimp;                                 /* Wimp version, flag to say the nested window manager is       */
int               task_handle;                                 /* present, Wimp task handle, pointer to sprite block.          */
int               sprite_block;

int               taskmodule_ds_registered;                    /* Set to 1 if the dialler status service call is being watched */
int               uri_module_present;                          /* Set to 1 if the URI module is present and may be used        */

_kernel_oserror   erb;                                         /* Global error block for custom errors                         */

MessagesFD        meb;                                         /* MessageTrans Messages file control block                     */
MessagesFD      * chb                       = NULL;            /* MessageTrans Choices file control block allocated in RMA     */
MessagesFD      * cob                       = NULL;            /* Similarly, control block for the Controls file               */
char              tokens                    [Limits_Message];  /* lookup_token/choice puts looked up data in here              */
char              lasttokn                  [Limits_Token];    /* The last token looked up is stored here for future reference */

char              program_name              [Limits_TaskName]; /* _TaskName token contents put in here, for the flex library   */
char            * task_dir                  = NULL;            /* Application path, recorded at startup (in Main.c).           */

int               messages_list             [] = {0};
int               event_code_list           [] = {0};
IdBlock           idb;                                         /* For all Toolbox-registered event handlers                    */
WimpPollBlock     b;                                           /* For Toolbox-registered Wimp event handlers                   */

int               bullets;                                     /* Number of bullet sprites available                           */
unsigned int      animation_frames;                            /* Holds the number of animation frames in the Sprites file     */
int               null_counter;                                /* When zero, null events will be disabled, else enabled. For   */
                                                               /* each time something wants to claim nulls, it increments this */
                                                               /* and decrements it when finished                              */


browser_data    * highlight_frame           = NULL;            /* The currently highlighted frame (if any)                     */
browser_data    * last_browser;                                /* Points to the last browser_data structure in the linked list */
                                                               /* of structures associated with all browser windows, or NULL   */
                                                               /* there are no browser windows. The structure is defined in    */
                                                               /* Global.h                                                     */

global_choices    choices;                                     /* To store user-configurable choices (from Choices file)       */
global_controls   controls;                                    /* To store non user-configurable controls (from Controls file) */
global_choices  * new_choices               = NULL;            /* Temporary store for Choices dialogue                         */
ObjectId          choices_windowid          = NULL_ObjectId;   /* Choices dialogue main window object ID                       */

menu_source       menusrc                   = Menu_None;       /* For Wimp menus - opened from forms, from history icons, etc. */
void            * menuhdl;                                     /* For any extra info needed with a menu                        */

char            * authorise                 = NULL;            /* Flex block to hold authorisation data                        */

#ifndef SINGLE_USER

  userdef         user;                                        /* For multiuser builds, holds details of the current user      */
  int             logged_in;                                   /* Flags for the front-end - user is logged in.                 */
  int             re_login;                                    /* Flags for the front-end - need to re-prompt for login        */

#endif