home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / Demos / DE_MesaAR1 / Examples / API / MAPIDemoCode / MyObject.m < prev    next >
Encoding:
Text File  |  1992-07-09  |  3.2 KB  |  158 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import "MyObject.h"
  5. #import <appkit/Application.h>
  6. #import <appkit/Matrix.h>
  7. #import <appkit/TextField.h>
  8. #import <libc.h>
  9. #import <math.h>
  10. #import "MesaAPI.h"
  11. #import <appkit/OpenPanel.h>
  12. #import "MyListen.h"
  13. #import <appkit/NXImage.h>
  14.  
  15. #define MY_DELAY 2000
  16. #define rows 3
  17.  
  18. @implementation MyObject
  19.  
  20. - doWalk:sender
  21. {
  22.     [self perform:@selector(startWalk:) with:self afterDelay:MY_DELAY cancelPrevious:NO];
  23.     
  24.     return self;
  25. }
  26.  
  27. - startWalk:sender
  28. {
  29.     int x,num;
  30.     id t;
  31.     double d,d1;
  32.     char *stocks[rows];
  33.     const char *p;
  34.     MAPIValue values[rows],*mv,*mv2;
  35.     int ur,uc,lr,lc,r,c;
  36.     id myImage;
  37.     NXPoint np;
  38.     
  39.     if (!sender) return self;
  40.     
  41.     for (x = 0,num = 0; x < rows; x++) {
  42.         p = [[stockMatrix cellAt:x :0] stringValue];
  43.         if (strlen((char *) p) && (d = [(t = [stockMatrix cellAt:x :1]) doubleValue])) {
  44.             d1 = d * 0.1;
  45.             d1 *= (double) ((double) random() / (double) 2147483647);
  46.             d1 -= d * 0.05;
  47.             d += d1;
  48.             if (d < 10) d = 10;
  49.             [t setDoubleValue:rint(d)];
  50.             stocks[num] = (char *) p;
  51.             values[num].type = numberMAPIValue;
  52.             values[num].values.number = rint(d);
  53.             num++;
  54.             }
  55.         }
  56.     
  57.     if (num) {
  58.         [mapi associateLabel:"prices" withItems:stocks andValues:values offset:1 numItems:num
  59.             orientation:verticalOrientation];
  60.             
  61.         [mapi recalc];
  62.         
  63.         if ([mapi getValues:&mv forLabel:"summary" num:&num upperRow:&ur col:&uc
  64.             lowerRow:&lr col:&lc] == MAPISuccess) {
  65.             
  66.             for (x = 0; x < rows; x++) {
  67.                 [[portMatrix cellAt:x :0] setStringValue:""];
  68.                 [[portMatrix cellAt:x :1] setStringValue:""];
  69.                 }
  70.             
  71.             for (x = 0,mv2 = mv; x < num; x++,mv2++) {
  72.                 r = mv2 -> row - ur;
  73.                 c = mv2 -> col - uc;
  74.                 if (r < rows && c < 2) {
  75.                     t = [portMatrix cellAt:r :c];
  76.                     if (mv2 -> type == stringMAPIValue) [t setStringValue:mv2 -> values.string];
  77.                     else if (mv2 -> type == numberMAPIValue)
  78.                         [t setDoubleValue:mv2 -> values.number];
  79.                     }
  80.                 }
  81.             
  82.             freeMAPIValue(num,mv);
  83.             }
  84.             
  85.         [mapi getEPSForLabel:"summary" in:&myImage];
  86.         if (myImage) {
  87.             [theView lockFocus];
  88.             np.x = np.y = 0;
  89.             [myImage composite:NX_COPY toPoint:&np];
  90.             [theView unlockFocus];
  91.             [myImage free];
  92.             }
  93.             
  94.         [mapi getEPSForGraph:"Graph 1" in:&myImage];
  95.         if (myImage) {
  96.             [theGraph lockFocus];
  97.             np.x = np.y = 0;
  98.             [myImage composite:NX_COPY toPoint:&np];
  99.             [theGraph unlockFocus];
  100.             [myImage free];
  101.             }
  102.             
  103.         
  104.         }
  105.         
  106.     [self perform:@selector(startWalk:) with:self afterDelay:MY_DELAY cancelPrevious:NO];
  107.     
  108.     return self;
  109.     
  110. }
  111.  
  112. - endWalk:sender
  113. {
  114.      [self perform:@selector(startWalk:) with:NULL afterDelay:0 cancelPrevious:YES];
  115.    return self;
  116. }
  117.  
  118. - appDidInit:sender
  119. {
  120.     id op;
  121.     static char *types[] = {"Mesa",NULL};
  122.     char tmp[2000];
  123.     char **fn;
  124.     
  125.     op = [OpenPanel new];
  126.     [op allowMultipleFiles:NO];
  127.     if ([op runModalForTypes:types]) {
  128.         if ((fn = (char **) [op filenames])) {
  129.             sprintf(tmp,"%s/%s",[op directory],fn[0]);
  130.             mapi = [[MesaAPI alloc] initToWorksheet:tmp];
  131.             }
  132.         }
  133.     else [NXApp terminate:self];
  134.     
  135.     listen = [[MyListen alloc] initToPort:"LowValue"];
  136.     [listen setMatrix:listenMatrix];
  137.     
  138.     return self;
  139.     }
  140.     
  141. - appWillTerminate:sender
  142. {
  143.     [NXApp setDelegate:NULL];
  144.     [listen free];
  145.     [mapi free];
  146.     [self free];
  147.     
  148.     return sender;
  149.     }
  150.  
  151. - printTheReport:sender
  152. {
  153.     [mapi printReport:"Portfolio"];
  154.     
  155.     return self;
  156.     }
  157. @end
  158.