home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / toollib_2 / Examples / Tree / Builds / c / treewindow < prev   
Encoding:
Text File  |  1996-06-13  |  2.4 KB  |  100 lines

  1. /*** treewindow.c ***/
  2. /* A (shared) window containing a tree
  3.  * The tree is drawn from the lines in line_store
  4.  * (c) Paul Field 1995
  5.  * v1.00 - 22/11/1995
  6.  * v1.01 - 23/11/1995 : Saves tree as Draw file
  7.  */
  8.  
  9. #include "treewindow.h"
  10.  
  11. #include <assert.h>
  12. #include "toolbox.h"
  13. #include "wimp.h"
  14. #include "window.h"
  15.  
  16. #include "exception.h"
  17. #include "nev_wimp.h"
  18. #include "saver.h"
  19.  
  20. #include "diagram_save.h"
  21. #include "line_plotter.h"
  22. #include "line_storer.h"
  23.  
  24.  
  25. /* The handle of the tree window */
  26.  
  27. static toolbox_o tree_window_id;
  28.  
  29.  
  30. static nevent_result tree_window_redraw(wimp_event_no event_code, wimp_block *event, toolbox_block *id_block, void *handle)
  31.  { assert(event_code == wimp_REDRAW_WINDOW_REQUEST);
  32.    NOT_USED(event_code);
  33.    NOT_USED(handle);
  34.  
  35.    try
  36.     { wimp_window_state state;
  37.       bool              more;
  38.       wimp_draw         block;
  39.       int               origin_x;
  40.       int            origin_y;
  41.  
  42.       /* Calculate where the work area origin is on screen (or off screen) */
  43.       state.w = event->redraw.w;
  44.       wimp_get_window_state(&state);
  45.  
  46.       origin_x = state.visible.x0 - state.xscroll;
  47.       origin_y = state.visible.y1 - state.yscroll;
  48.       line_plotter_origin(origin_x, origin_y);
  49.  
  50.       /* Repeatedly ask the Wimp for an area of window to redraw and then plot the sprite */
  51.       block.w = event->redraw.w;
  52.       more = wimp_redraw_window(&block);
  53.       while (more)
  54.        { line_storer_process_lines(&line_plotter);
  55.          more = wimp_get_rectangle(&block);
  56.        }
  57.     }
  58.    catch
  59.     { /* If there's an error during redraw then we could run into an infinite loop
  60.        * if the error report window covers up the window and so causes another redraw and another error.
  61.        * To avoid this happening, we hide the window
  62.        */
  63.       toolbox_hide_object(0, id_block->this_obj);
  64.       throw();
  65.     }
  66.    catch_end
  67.  
  68.    return nevent_HANDLED;
  69.  }
  70.  
  71.  
  72.  
  73.  
  74. static void tree_window_save(toolbox_o save_as_id)
  75.  { NOT_USED(save_as_id);
  76.  
  77.    diagram_save();
  78.  }
  79.  
  80.  
  81.  
  82.  
  83. void tree_window_initialise(void)
  84.  { tree_window_id = toolbox_create_object(0, (toolbox_id)"TreeWindow");
  85.    nevent_wimp_register_handler(tree_window_id, wimp_REDRAW_WINDOW_REQUEST, tree_window_redraw, NULL);
  86.  
  87.    saver_create(toolbox_create_object(0, (toolbox_id)"SaveTree"), tree_window_save);
  88.  }
  89.  
  90.  
  91.  
  92.  
  93. void tree_window_update(void)
  94.  { os_box    extent;
  95.  
  96.    /* Redraw whole window */
  97.    window_get_extent(0, tree_window_id, &extent);
  98.    window_force_redraw(0, tree_window_id, &extent);
  99.  }
  100.