home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / desklib / examples / DeskLib / Examples / Widget5 / !Widget5 / c / Misc < prev    next >
Encoding:
Text File  |  1995-05-10  |  4.0 KB  |  152 lines

  1. /************************************************************************
  2.  *                                                                      *
  3.  *        File: Misc.c                                                  *
  4.  *                                                                      *
  5.  *     Purpose: Provides miscellanous routines used by more than one    *
  6.  *              file in the program                                     *
  7.  *                                                                      *
  8.  ************************************************************************/
  9.  
  10. #include "DeskLib:WimpSWIs.h"          /* Low-level WIMP commands         */
  11. #include "DeskLib:Window.h"            /* Window handling automation      */
  12. #include "DeskLib:Icon.h"              /* Icon handling automation        */
  13. #include "DeskLib:Menu.h"              /* Menu create & show support      */
  14. #include "DeskLib:Screen.h"
  15.  
  16. #include "kernel.h"
  17.  
  18. #include <stdio.h>
  19.  
  20. #include "MySWIs.h"
  21.  
  22. extern void inc_icon(window_handle window, icon_handle icon, int upperlimit)
  23. {
  24.   int value;
  25.  
  26.   value = Icon_GetInteger(window, icon);
  27.  
  28.   if(value < upperlimit)
  29.      value++;
  30.  
  31.   Icon_SetInteger(window, icon, value);
  32. }
  33.  
  34. extern void dec_icon(window_handle window, icon_handle icon, int lowerlimit)
  35. {
  36.   int value;
  37.  
  38.   value = Icon_GetInteger(window, icon);
  39.  
  40.   if(value > lowerlimit)
  41.      value--;
  42.  
  43.   Icon_SetInteger(window, icon, value);
  44. }
  45.  
  46. extern void Icon_SetFileType(window_handle window, icon_handle icon, int filetype)
  47. {
  48.  /*
  49.   * set filetype of icon
  50.   */
  51.   icon_block icondata;
  52.   int topbits;
  53.   int middlebits;
  54.   int bottombits;
  55.  
  56.  
  57.   Wimp_GetIconState(window, icon, &icondata);
  58.   topbits = filetype >> 8;
  59.   middlebits = (filetype - (topbits << 8)) >> 4;
  60.   bottombits = filetype - (middlebits << 4) - (topbits << 8);
  61.   sprintf(icondata.data.indirecttext.validstring,
  62.           "sfile_%x%x%x", topbits, middlebits, bottombits);
  63.  
  64.  
  65. }
  66.  
  67. extern void Popup_menu(window_handle window, icon_handle icon, menu_ptr menu)
  68. {
  69.   int winx, winy, iconx, icony;
  70.   int block[20];
  71.   _kernel_swi_regs r;
  72.  
  73.   block[0] = window;
  74.   r.r[1] = (int) block; 
  75.   _kernel_swi( SWI_XOS_Bit | SWI_Wimp_GetWindowState, &r, &r );
  76.   winx = block[1];
  77.   winy = block[4];
  78.  
  79.   block[0] = window;
  80.   block[1] = icon;
  81.   r.r[1] = (int) block;
  82.   _kernel_swi( SWI_XOS_Bit | SWI_Wimp_GetIconState, &r, &r );
  83.   iconx = block[4];
  84.   icony = block[5];
  85.  
  86.   Menu_Show(menu, (iconx + winx + 64), (icony + winy));
  87. }
  88.  
  89. extern void Menu_MakeWarn(menu_ptr menu, int entry, BOOL yesno)
  90. {
  91.  /*
  92.   * makes the entry in the menu send a menuwarn message or not
  93.   * as yesno
  94.   */
  95.   menu_item *item = (menu_item *) (((int) menu) + sizeof(menu_block));
  96.  
  97.   item = &item[entry];
  98.   item->menuflags.data.notifysub = yesno;
  99.   if(yesno)
  100.      item->submenu.value = 1;
  101.   else
  102.      item->submenu.value = NULL;
  103.  
  104. }
  105.  
  106. extern void Window_GetPos(window_handle window, wimp_point *pos)
  107. {
  108.  /*
  109.   * gets the current position of the topleft corner of the window
  110.   */
  111.   window_state state;
  112.  
  113.   Wimp_GetWindowState(window, &state);
  114.  
  115.   pos->x = state.openblock.screenrect.min.x;
  116.   pos->y = state.openblock.screenrect.max.y;
  117.  
  118. }
  119.  
  120. extern void Window_ShowPos(window_handle window, wimp_point *openpos)
  121. {
  122.  /*
  123.   * Shows the window in the position openpos
  124.   */
  125.   window_state state;
  126.   int width;
  127.   int height;
  128.   wimp_point pos;
  129.  
  130.   pos.x = openpos->x;
  131.   pos.y = openpos->y;
  132.  
  133.   Wimp_GetWindowState(window, &state);
  134.   state.openblock.behind = -1;
  135.  
  136.   width = state.openblock.screenrect.max.x - state.openblock.screenrect.min.x;
  137.   height = state.openblock.screenrect.max.y - state.openblock.screenrect.min.y;
  138.  
  139.   if (pos.x < 0)  pos.x = 0;
  140.   if (pos.y < 64) pos.y = 64;
  141.   if (pos.x > screen_size.x - 96) pos.x = screen_size.x - 96;
  142.   if (pos.y > screen_size.y - 32) pos.y = screen_size.y - 32;
  143.  
  144.   state.openblock.screenrect.min.x = pos.x;
  145.   state.openblock.screenrect.max.x = state.openblock.screenrect.min.x + width;
  146.  
  147.   state.openblock.screenrect.max.y = pos.y;
  148.   state.openblock.screenrect.min.y = state.openblock.screenrect.max.y - height;
  149.  
  150.   Wimp_OpenWindow(&state.openblock);
  151. }
  152.