home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / Languages / python / PyObjC-0.47-MIHS / pyobjc-0.47-src / Demo / ObjC / AlertPanel / AlertPanel.m < prev    next >
Encoding:
Text File  |  1996-09-30  |  2.8 KB  |  147 lines

  1. /* Copyright (c) 1996 by Lele Gaifax.  All Rights Reserved
  2.  *
  3.  * This file is part of Nothing (yet).
  4.  *
  5.  * $RCSfile: AlertPanel.m,v $
  6.  * $Revision: 1.1.1.1 $
  7.  * $Date: 1996/09/30 06:06:48 $
  8.  *
  9.  * Created Wed Sep  4 15:27:34 1996.
  10.  */
  11.  
  12. #include <appkit/appkit.h>
  13. #include "AlertPanel.h"
  14.  
  15. #define CLASS_VERSION 0
  16.  
  17. @implementation AlertPanel
  18.  
  19. + (void) initialize
  20. {
  21.   if (self == [AlertPanel class])
  22.     {
  23.       [AlertPanel setVersion:CLASS_VERSION];
  24.     }
  25. }
  26.  
  27. - initWithTitle:(const char *) title
  28. {
  29.   return [self initWithTitle:title message:NULL];
  30. }
  31.  
  32. - initWithTitle:(const char *) title
  33.     message:(const char *) msg
  34. {
  35.   return [self initWithTitle:title
  36.            message:msg
  37.            defaultButton:NULL];
  38. }
  39.  
  40. - initWithTitle:(const char *) title
  41.     message:(const char *) msg
  42.   defaultButton:(const char *) defButton
  43. {
  44.   return [self initWithTitle:title
  45.            message:msg
  46.            defaultButton:defButton
  47.            altButton:NULL];
  48. }
  49.  
  50. - initWithTitle:(const char *) title
  51.     message:(const char *) msg
  52.   defaultButton:(const char *) defButton
  53.       altButton:(const char *) altButton
  54. {
  55.   return [self initWithTitle:title
  56.            message:msg
  57.            defaultButton:defButton
  58.            altButton:altButton
  59.            otherButton:NULL];
  60. }
  61.  
  62. - initWithTitle:(const char *) title
  63.     message:(const char *) msg
  64.   defaultButton:(const char *) defButton
  65.       altButton:(const char *) altButton
  66.     otherButton:(const char *) otherButton
  67. {
  68.   [super init];
  69.  
  70.   mainTitle = NXCopyStringBuffer (title);
  71.   if (msg)
  72.     message = NXCopyStringBuffer (msg);
  73.   if (defButton)
  74.     defaultButtonTitle = NXCopyStringBuffer (defButton);
  75.   if (altButton)
  76.     alternateButtonTitle = NXCopyStringBuffer (altButton);
  77.   if (otherButton)
  78.     otherButtonTitle = NXCopyStringBuffer (otherButton);
  79.  
  80.   return self;
  81. }
  82.  
  83. - (void) setAction:(id <PythonObject>) anAction
  84. {
  85.   if ([anAction callableCheck])
  86.     action = anAction;
  87.   else
  88.     NXLogError ("action should be a callable object");
  89. }
  90.  
  91. - (enum _alert_panel_status) status
  92. {
  93.   return status;
  94. }
  95.  
  96. - (enum _alert_panel_status) run
  97. {
  98.   if (status == ALERT_PANEL_READY)
  99.     {
  100.       [Application new];
  101.       
  102.       switch (NXRunAlertPanel (mainTitle,
  103.                    message,
  104.                    defaultButtonTitle,
  105.                    alternateButtonTitle,
  106.                    otherButtonTitle))
  107.     {
  108.     case NX_ALERTDEFAULT:
  109.       status = ALERT_PANEL_DEFAULT;
  110.       break;
  111.       
  112.     case NX_ALERTALTERNATE:
  113.       status = ALERT_PANEL_ALTERNATE;
  114.       break;
  115.       
  116.     case NX_ALERTOTHER:
  117.       status = ALERT_PANEL_OTHER;
  118.       break;
  119.     }
  120.  
  121.       if (action)
  122.     [action callableCallFunction:"i", status];
  123.     }
  124.   
  125.   return status;
  126. }  
  127.  
  128. - (const char *) buttonTitle
  129. {
  130.   switch (status)
  131.     {
  132.     case ALERT_PANEL_READY:
  133.       return "None";
  134.  
  135.     case ALERT_PANEL_DEFAULT:
  136.       return defaultButtonTitle;
  137.  
  138.     case ALERT_PANEL_ALTERNATE:
  139.       return alternateButtonTitle;
  140.  
  141.     case ALERT_PANEL_OTHER:
  142.       return otherButtonTitle;
  143.     }
  144. }
  145.  
  146. @end /* AlertPanel class implementation */
  147.