home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / unix / riscbsd / 1_2_beta / bootloader / RiscBSD / !BtRiscBSD / c / desktop < prev   
Encoding:
Text File  |  1996-07-14  |  11.8 KB  |  434 lines

  1. /*
  2.  * Copyright (c) 1995 Mark Brinicombe.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by Mark Brinicombe.
  16.  * 4. The name of the company nor the name of the author may be used to
  17.  *    endorse or promote products derived from this software without specific
  18.  *    prior written permission.
  19.  *
  20.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  21.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  22.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  23.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  24.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25.  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26.  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  27.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29.  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30.  *
  31.  * RiscBSD kernel project
  32.  *
  33.  * desktop.c
  34.  *
  35.  * Bootloader front end
  36.  *
  37.  * Created      : 26/04/95
  38.  * Last updated : 13/07/96
  39.  */
  40.  
  41. /* Include standard header files */
  42.  
  43. #include <stdio.h>
  44. #include <stdlib.h>
  45. #include <string.h>
  46.  
  47. #include "wimp.h"
  48. #include "Event.h"       /* Event despatcher                             */
  49. #include "EventMsg.h"    /* Wimp Message event dispatcher                */
  50. #include "Error.h"       /* Error despatcher                             */
  51. #include "Resource.h"    /* Handles finding resource files in home dir.  */
  52. #include "Template.h"    /* Template loading and cacheing                */
  53. #include "Window.h"      /* Window handling automation                   */
  54. #include "Icon.h"        /* Icon handling automation                     */
  55. #include "Msgs.h"        /* Message translation code                     */
  56. #include "Handler.h"     /* Default event handlers                       */
  57. #include "WimpSWIs.h"    /* Default event handlers                       */
  58. #include "Menu.h"        /* Menu handling                                */
  59. #include "Screen.h"      /* Getting screen size info, etc   */
  60. #include "Swi.h"
  61. #include "swiv.h"
  62. #include "dragaspr.h"
  63.  
  64. #include "prototypes.h"
  65. #include "icons.h"
  66. #include "config.h"
  67.  
  68. /* Define symbols */
  69.  
  70. #define MAX_FILENAME_LENGTH 255
  71.  
  72. /* Declare global variables */
  73.  
  74. menu_ptr main_menu;
  75. icon_handle iconbar_icon = -1;
  76. int iconboot = 0;
  77.  
  78. /* Declare external variabes */
  79.  
  80. extern window_handle config_window;
  81. extern window_handle config_backing;
  82. extern Config config;
  83.  
  84. /* Local function prototypes */
  85.  
  86. BOOL Iconbar_MenuSelect(event_pollblock *event, void *reference);
  87. BOOL Iconbar_MenuSubWindow(event_pollblock *event, void *reference);
  88. BOOL Iconbar_Click(event_pollblock *event, void *reference);
  89. BOOL Message_Filename(event_pollblock *event, void *reference);
  90. BOOL App_ModeChange(event_pollblock *event, void *reference);
  91. void Exit_Handler(void);
  92.  
  93. /* Now for the main code */
  94.  
  95. int main(int argc, char *argv[])
  96.   {
  97.     char application_name[64];
  98.     int loop;
  99.  
  100. /*
  101.  *  Add exit handler
  102.  */
  103.  
  104.     atexit(Exit_Handler);
  105.  
  106. /*
  107.  *  Tell Resource (and thereby Template, Msgs, etc) where our resource
  108.  *  directory is: "<Config$Dir>"
  109.  */
  110.  
  111.     Resource_Initialise("BtRiscBSD");
  112.  
  113. /*
  114.  *  Load and cache the messages. Find out the application name.
  115.  */
  116.  
  117.     Msgs_LoadFile("messages");
  118.     Msgs_Lookup("app.name:BtRiscBSD", application_name, 64);
  119.  
  120. /*
  121.  *  Initialise the Wimp and Event Manager.
  122.  *  The task name shown on the task display and error reports is set from
  123.  *  the string "appname" fetched previously from the messages file.
  124.  */
  125.  
  126.     Event_Initialise(application_name);
  127.     EventMsg_Initialise();
  128.  
  129. /*
  130.  *  Read and remember the current screen mode information
  131.  *  (width and height, eig-factors, delta-x and delta-y, etc.)
  132.  *  This is needed by the Menu code to get menu widths correct.
  133.  */
  134.  
  135.     Screen_CacheModeInfo();
  136.  
  137. /*
  138.  *  Add a handler function to a "screen mode changing" Wimp message, so
  139.  *  that the information provided by the "Screen" functions is always
  140.  *  correct.
  141.  *  NOTE that the new Handler_ModeChange should also ensure that outline
  142.  *  fonts will work if we change between lo-res and hi-res screen modes.
  143.  */
  144.  
  145.     EventMsg_Claim(message_MODECHANGE, event_ANY, App_ModeChange, NULL);
  146.  
  147. /*
  148.  *  Place the Handler_ module skeleton default handlers on all
  149.  *  Redraw and Open-window request events (Application-wide defaults)
  150.  */
  151.  
  152. /*    Event_Claim(event_REDRAW, event_ANY, event_ANY, Handler_NullRedraw, NULL);*/
  153.     Event_Claim(event_OPEN, event_ANY, event_ANY, Handler_OpenWindow, NULL);
  154.  
  155. /*
  156.  *  Load in and cache our window templates from the file
  157.  *  "<Tester$Dir>.Templates" (Templates utilise the "Resource Directory")
  158.  */
  159.  
  160.     Template_Initialise();
  161. /*    Template_UseOutlineFonts();*/
  162.     Template_LoadFile("Templates");
  163.  
  164. /*
  165.  *  Claim window-close events
  166.  *  Use the Window_Delete() handler rather than the Wimp_CloseWindow() one
  167.  *  so that the window is closed and deleted and all memory and event
  168.  *  claims are released whenever the user hits the close icon.
  169.  */
  170.  
  171.     Event_Claim(event_CLOSE, event_ANY, event_ANY, Handler_DeleteWindow, NULL);
  172.  
  173. /*
  174.  *  Claim DATALOAD and DATAOPEN messages
  175.  */
  176.  
  177.     EventMsg_Claim(message_DATALOAD, event_ANY, Message_Filename, NULL);
  178.     EventMsg_Claim(message_DATAOPEN, event_ANY, Message_Filename, NULL);
  179.  
  180.     Event_Claim(event_USERMESSAGEACK, event_ANY, event_ANY, Message_Ack, NULL);
  181.     Event_Claim(event_KEY, event_ANY, event_ANY, Config_Keypress, NULL);
  182.  
  183. /*
  184.  *  Add the Window_HelpHandler message handler so that help requests
  185.  *  for the windows and the iconbar icon are automatically handled
  186.  */
  187.  
  188.     Window_AutoHelp(event_ANY, event_ANY);
  189.  
  190. /*  Create main menu */
  191.  
  192.     main_menu = Menu_CreateMenu("Config", ">Info,Configuration,Quit");
  193.     if (!main_menu) Msgs_ReportFatal(0x00000000, "err.0", "Main");
  194.  
  195. /* Initialise other modules */
  196.  
  197.     Desktop_CreateIcon();
  198.  
  199.     Config_Initialise();
  200.  
  201.     for (loop = 1; loop < argc; ++loop) {
  202.       if (strcmp(argv[loop], "-open") == 0)
  203.         Config_OpenWindow();
  204.  
  205.       if (strcmp(argv[loop], "-iconboot") == 0)
  206.         iconboot = 1;
  207.       if (strcmp(argv[loop], "-noiconboot") == 0)
  208.         iconboot = 0;
  209.     }
  210.  
  211. /*  Main event handling loop. Let Event_ do all the work for us!
  212.  */
  213.  
  214.     while (TRUE)
  215.       Event_Poll();
  216.  
  217.     exit(0);
  218.   }
  219.  
  220.  
  221. void Exit_Handler(void)
  222.   {
  223.   }
  224.  
  225.  
  226. /*
  227.  *  Menu selection handler
  228.  */
  229.  
  230. BOOL Iconbar_MenuSelect(event_pollblock *event, void *reference)
  231.   {
  232.     window_handle info_window;
  233.  
  234.     switch (event->data.words[0])
  235.       {
  236.         case MAIN_MENU_OPTION_INFO :
  237.           info_window = Window_CreateAndShow("infowindow", 0,
  238.             open_UNDERPOINTER);
  239.           if (info_window)
  240.             {
  241.               Icon_SetText(info_window, INFO_WINDOW_ICON_VERSION,
  242.                 VERSION_STRING);
  243.               Menu_HandleDbox(info_window);
  244.               Window_Delete(info_window);
  245.             }
  246.           else
  247.             Msgs_Report(0x00000000, "err.1", "info");
  248.           break;
  249.  
  250.         case MAIN_MENU_OPTION_CONFIG :
  251.           Config_OpenWindow();
  252.           break;
  253.  
  254.         case MAIN_MENU_OPTION_QUIT :
  255.           exit(0);
  256.           break;
  257.       }
  258.     return(1);
  259.   }
  260.  
  261.  
  262. /*
  263.  *  Menu Sub window handler
  264.  */
  265.  
  266. BOOL Iconbar_MenuSubWindow(event_pollblock *event, void *reference)
  267.   {
  268.     window_handle info_window;
  269.  
  270.     switch (event->data.message.data.menuwarn.selection[0])
  271.       {
  272.         case MAIN_MENU_OPTION_INFO :
  273.           info_window = Window_Create("infowindow", 0);
  274.           if (info_window)
  275.             {
  276.               Icon_SetText(info_window, INFO_WINDOW_ICON_VERSION,
  277.                 VERSION_STRING);
  278.               Wimp_CreateSubMenu((menu_block *)info_window,
  279.                 event->data.message.data.menuwarn.openpos.x,
  280.                 event->data.message.data.menuwarn.openpos.y);
  281.               Menu_HandleDbox(info_window);
  282.             }
  283.           else
  284.             Msgs_Report(0x00000000, "err.1", "info");
  285.           break;
  286.       }
  287.     return(1);
  288.   }
  289.  
  290.  
  291. BOOL Iconbar_Click(event_pollblock *event, void *reference)
  292.   {
  293.     if (iconboot)
  294.       Config_Confirm(NULL, (void *)0x01);
  295.     else
  296.       Config_OpenWindow();
  297.     return(1);
  298.   }
  299.  
  300.  
  301. void Desktop_CreateIcon(void)
  302.   {
  303. /*
  304.  *  Plonk an icon onto the iconbar
  305.  */
  306.  
  307.     iconbar_icon = Icon_BarIcon("!BtRiscBSD", iconbar_RIGHT);
  308.  
  309. /*
  310.  *  Claim mouse click events
  311.  */
  312.     Event_Claim(event_CLICK, iconbar_LEFT, iconbar_icon, Iconbar_Click, NULL);
  313.  
  314.     Menu_AttachMenu(main_menu, iconbar_LEFT, iconbar_icon, Iconbar_MenuSelect,
  315.       Iconbar_MenuSubWindow, NULL, NULL);
  316.   }
  317.  
  318.  
  319. BOOL Close_Window(event_pollblock *event, void *reference)
  320.   {
  321.     window_handle *window = (window_handle *) reference;
  322.  
  323.     Window_Delete(*window);
  324.     *window = NULL;
  325.     return(1);
  326.   }
  327.  
  328.  
  329. BOOL App_ModeChange(event_pollblock *event, void *reference)
  330.   {
  331.     window_state wstate;
  332.     event_pollblock ev;
  333.  
  334.     Handler_ModeChange(event, reference);
  335.     
  336.     if (config_backing)
  337.       {
  338.         Wimp_GetWindowState(config_backing, &wstate);
  339.         ev.data.openblock = wstate.openblock;
  340.         Config_PaneHandler(&ev, NULL);
  341.       }
  342.     
  343.     return(0);
  344.   }
  345.  
  346.  
  347. BOOL Message_Filename(event_pollblock *event, void *reference)
  348.   {
  349.     message_block message;
  350.     int filetype;
  351.     char *filename;
  352.  
  353. /* Get the file type and filename from the message block */
  354.  
  355.     filetype = event->data.message.data.dataload.filetype;
  356.     filename = (char *)&event->data.message.data.dataload.filename;
  357.  
  358.     if (event->data.message.header.action == message_DATAOPEN)
  359.       {
  360.         if (filetype != FILETYPE_UNIX)
  361.           return(1);
  362.         else
  363.           {
  364.             message.header.size = sizeof(message_header);
  365.             message.header.yourref = event->data.message.header.myref;
  366.             message.header.action = message_DATALOADACK;
  367.             message.header.sender = event_taskhandle;
  368.  
  369.             Wimp_SendMessage(event_SEND, &message,
  370.               event->data.message.header.sender, 0);
  371.           }
  372.       }
  373.  
  374.     if (filetype != FILETYPE_UNIX && filetype != FILETYPE_DATA
  375.      && filetype != FILETYPE_DOS)
  376.       {
  377.         Msgs_Report(0x00000000, "err.3");
  378.         return(1);
  379.       }
  380.  
  381. /* Check the name */
  382.  
  383.     if (strlen(filename) > MAX_FILENAME_LENGTH)
  384.       {
  385.         Msgs_Report(0x00000000, "err.2");
  386.         return(1);
  387.       }
  388.     else
  389.       {
  390. /* Ok we either have a a.out file to boot or a configuration file */
  391.  
  392.         if (Config_Load(filename) == 0)
  393.           {
  394.             if (config_window)
  395.               Config_SetIcons();
  396.           }
  397.         else
  398.           {
  399. /*
  400.  * Make sure the config structure is uptodate if the window is open as we
  401.  * may be about to boot.
  402.  */
  403.             if (config_window)
  404.               {
  405.                 Config_GetIcons();
  406.                 strcpy(config.kernel, filename);
  407.                 config.flags &= ~FLAG_NATIVE;
  408.                 Config_SetIcons();
  409.               }
  410.             else
  411.               {
  412.                 strcpy(config.kernel, filename);
  413.                 config.flags &= ~FLAG_NATIVE;
  414.                }
  415.             
  416.           }
  417.       }
  418.  
  419. /*
  420.  * If it was a DATAOPEN message or a DATALOAD to the iconbar
  421.  * then we try booting the file
  422.  */
  423.  
  424.     if (event->data.message.header.action == message_DATAOPEN
  425.      || event->data.message.data.dataload.window == window_ICONBAR)
  426.       Config_Confirm(NULL, (void *)0x01);
  427.  
  428. /* Indicate load is completed */
  429.  
  430.     return(1);
  431.   }
  432.  
  433. /* End of desktop.c */
  434.