home *** CD-ROM | disk | FTP | other *** search
/ Executor 2.0 / executorv2.0.iso / pc / dos / extra / source / browser / browser.hqx / Browser / view.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-13  |  3.3 KB  |  178 lines

  1. #include "go.h"
  2. #include "display.h"
  3. #include <stdlib.h>
  4. #include <packages.h>
  5.  
  6. #include "view.proto.h"
  7. #include "misc.proto.h"
  8.  
  9. void
  10. changeview (short view, Rect * r)
  11. {
  12.   WindowPtr wp;
  13.   ControlHandle c;
  14.   opendirinfo **ih;
  15.  
  16.   wp = FrontWindow ();
  17.   ih = (opendirinfo **) ((WindowPeek) wp)->refCon;
  18.   (*ih)->view = view;
  19.   for (c = ((WindowPeek) wp)->controlList; c != (ControlHandle) 0;
  20.        c = (*c)->nextControl)
  21.     {
  22.       if (c != (*ih)->sbar)
  23.     {
  24.       MoveControl (c, 0, -5000);
  25.       (*(item **) (*c)->contrlData)->view = view;
  26.       SizeControl (c, r->right, r->bottom);
  27.     }
  28.     }
  29.   straightenwindow (wp);
  30.   ValidRect (&wp->portRect);
  31. }
  32.  
  33. void
  34. iconview (void)
  35. {
  36.   Rect r;
  37.  
  38.   SetRect (&r, 0, 0, ICONWIDTHUSED, ICONHEIGHTUSED);
  39.   changeview (ICONVIEW, &r);
  40. }
  41.  
  42. void
  43. icsview (void)
  44. {
  45.   Rect r;
  46.  
  47.   SetRect (&r, 0, 0, ICSWIDTHUSED, ICSHEIGHTUSED);
  48.   changeview (ICSVIEW, &r);
  49. }
  50.  
  51. void
  52. listingview (void)
  53. {
  54.   Rect r;
  55.  
  56.   SetRect (&r, 0, 0, LISTWIDTHUSED, LISTHEIGHTUSED);
  57.   changeview (LISTVIEW, &r);
  58. }
  59.  
  60. #if 0
  61. void
  62. updatewin (...)
  63. {
  64.   infoh = (opendirinfo **) ((WindowPeek) wp)->refCon;
  65.   for (i = 0; i < (*infoh)->numitems; i++)
  66.     {
  67.       dir->hFileInfo.ioDirID = (*infoh)->iodirid;
  68.       e = PBGetCatInfo (dir, false);
  69.     }
  70. }
  71. #endif /* 0 */
  72.  
  73. void
  74. sortwin (WindowPtr wp, int (*f) (const void *, const void *), short order)
  75. {
  76.   opendirinfo **infoh;
  77.   bandinfo *p;
  78.   unsigned char state;
  79.  
  80.   if (wp == g_hotband)
  81.     {
  82.       p = &bands[g_currentband];
  83.       p->sortorder = order;
  84.       state = HGetState ((Handle) p->items);
  85.       HLock ((Handle) p->items);
  86.       qsort (**p->items, p->numitems, sizeof (ControlHandle), f);
  87.       HSetState ((Handle) p->items, state);
  88.       setband (g_currentband);
  89.     }
  90.   else
  91.     {
  92.       infoh = (opendirinfo **) ((WindowPeek) wp)->refCon;
  93.       (*infoh)->sortorder = order;
  94.       state = HGetState ((Handle) (*infoh)->items);
  95.       HLock ((Handle) (*infoh)->items);
  96.       qsort (**(*infoh)->items, (*infoh)->numitems, sizeof (ControlHandle), f);
  97.       HSetState ((Handle) (*infoh)->items, state);
  98.       straightenwindow (wp);
  99.     }
  100. }
  101.  
  102. int
  103. namecmp (const void *x, const void *y)
  104. {
  105.   return RelString ((**(ControlHandle *) x)->contrlTitle,
  106.             (**(ControlHandle *) y)->contrlTitle, false, false);
  107. }
  108.  
  109. void
  110. namesort (void)
  111. {
  112.   sortwin (FrontWindow (), namecmp, ALPHABETIC);
  113. }
  114.  
  115. int
  116. datecmp (const void *x, const void *y)
  117. {
  118.   long xval, yval;
  119.  
  120.   xval = (*(item **) (**(ControlHandle *) x)->contrlData)->moddate;
  121.   yval = (*(item **) (**(ControlHandle *) y)->contrlData)->moddate;
  122.   if (xval > yval)
  123.     return -1;
  124.   else
  125.     return xval < yval;
  126. }
  127.  
  128. void
  129. moddatesort (void)
  130. {
  131.   sortwin (FrontWindow (), datecmp, MODDATE);
  132. }
  133.  
  134. int
  135. sizecmp (const void *x, const void *y)
  136. {
  137.   long xval, yval;
  138.  
  139.   xval = (*(item **) (**(ControlHandle *) x)->contrlData)->size;
  140.   yval = (*(item **) (**(ControlHandle *) y)->contrlData)->size;
  141.   if (xval > yval)
  142.     return -1;
  143.   else
  144.     return xval < yval;
  145. }
  146.  
  147. void
  148. sizesort (void)
  149. {
  150.   sortwin (FrontWindow (), sizecmp, SIZE);
  151. }
  152.  
  153. void
  154. defaultsort (void)
  155. {
  156.   WindowPtr wp;
  157.   short order;
  158.  
  159.   wp = FrontWindow ();
  160.   if (wp == g_hotband)
  161.     order = bands[g_currentband].sortorder;
  162.   else
  163.     order = (*(opendirinfo **) ((WindowPeek) wp)->refCon)->sortorder;
  164.  
  165.   switch (order)
  166.     {
  167.     case ALPHABETIC:
  168.       namesort ();
  169.       break;
  170.     case SIZE:
  171.       sizesort ();
  172.       break;
  173.     case MODDATE:
  174.       moddatesort ();
  175.       break;
  176.     }
  177. }
  178.