home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool.zip / OOL / source / xmsgbox.cpp < prev    next >
C/C++ Source or Header  |  1997-04-04  |  9KB  |  208 lines

  1. #include "XMsgBox.h"
  2. #include "XxtMsgBx.h"
  3. #include "XString.h"
  4. #include "XResLib.h"
  5. #include "XIcon.h"
  6.  
  7. #include <stdlib.h>
  8.  
  9.  
  10. /*@ XMessageBox::GetCommand()
  11. @group misc
  12. @remarks Returns the ID of the users action.
  13. @returns USHORT id    The ID of the button the user pressed:
  14.                                 <t '°' c=1>
  15.                         °MDID_OK
  16.                         °MDID_CANCEL
  17.                         °MDID_ABORT
  18.                         °MDID_RETRY
  19.                         °MDID_IGNORE
  20.                         °MDID_YES
  21.                         °MDID_NO
  22.                         °MDID_HELP
  23.                         °MDID_ENTER
  24.                         °MDID_ERROR
  25.                             </t>
  26. */
  27.  
  28.  
  29. /*@ XMessageBox :: XMessageBox(const char *s1, const char *s2, const ULONG style, const XWindow * owner, const ULONG id)
  30. @group constructors/destructors
  31. @remarks Construct a message box.
  32. @parameters <t '°' c=2>
  33.                 °char * content     °the content of the message box
  34.            °char * title       °the title of the message box
  35.            °ULONG style        °the style, possible values are:
  36.                                             <t '°' c=1>
  37.                                     °MBOX_OK
  38.                                     °MBOX_OKCANCEL
  39.                                     °MBOX_RETRYCANCEL
  40.                                     °MBOX_ABORTRETRYIGNORE
  41.                                     °MBOX_YESNO
  42.                                     °MBOX_YESNOCANCEL
  43.                                     °MBOX_CANCEL
  44.                                     °MBOX_ENTER
  45.                                     °MBOX_ENTERCANCEL
  46.                                     °MBOX_NOICON
  47.                                     °MBOX_CUANOTIFICATION
  48.                                     °MBOX_CUAWARNING
  49.                                     °MBOX_ICONQUESTION
  50.                                     °MBOX_ICONEXCLAMATION
  51.                                     °MBOX_ICONASTERISK
  52.                                     °MBOX_ICONHAND
  53.                                     °MBOX_CUACRITICAL
  54.                                     °MBOX_QUERY
  55.                                     °MBOX_WARNING
  56.                                     °MBOX_INFORMATION
  57.                                     °MBOX_CRITICAL
  58.                                     °MBOX_ERROR
  59.                                     °MBOX_CUSTOMICON
  60.                                     °MBOX_DEFBUTTON1
  61.                                     °MBOX_DEFBUTTON2
  62.                                     °MBOX_DEFBUTTON3
  63.                                     °MBOX_APPLMODAL
  64.                                     °MBOX_SYSTEMMODAL
  65.                                     °MBOX_HELP
  66.                                     °MBOX_MOVEABLE
  67.                                     °MBOX_NONMODAL
  68.                                         </t>
  69.                               Can be or-ed.
  70.            °XWindow * owner    °owner-window of the message box. If owner is set, the
  71.                               message box is modal for the owner-window.
  72.            °ULONG id           °ID for the message-box. If MBOX_HELP is set this value identifies the help-resource in your help-file.
  73.                               Therefore the messagebox must have an owner-window and the owner-window must be related with an instance
  74.                               of XHelpInstance.
  75.                 </t>
  76. */
  77. XMessageBox :: XMessageBox(const char *s1, const char *s2, const ULONG style, const XWindow * owner, const ULONG id)
  78. {
  79. //   if(id) style |= MB_HELP;
  80.     res = WinMessageBox(HWND_DESKTOP, owner ? owner->GetHandle() : HWND_DESKTOP, (PSZ) s1, (PSZ) (s2 ? s2 : ""), id, style);
  81. }
  82.  
  83.  
  84. /*@ XMessageBox :: XMessageBox(const XResource * ms1, const XResource * ms2, const ULONG style, const XWindow * owner, const ULONG id)
  85. @group constructors/destructors
  86. @remarks Construct a message box.
  87. @parameters <t '°' c=2>
  88.                 °XResource * content     °resource which point to a string in the application resources to load and display as the messagebox content
  89.            °XResource * title       °resource which point to a string in the application resources to load and display as the messagebox title
  90.            °ULONG style        °the style, possible values are:
  91.                                             <t '°' c=1>
  92.                                     °MBOX_OK
  93.                                     °MBOX_OKCANCEL
  94.                                     °MBOX_RETRYCANCEL
  95.                                     °MBOX_ABORTRETRYIGNORE
  96.                                     °MBOX_YESNO
  97.                                     °MBOX_YESNOCANCEL
  98.                                     °MBOX_CANCEL
  99.                                     °MBOX_ENTER
  100.                                     °MBOX_ENTERCANCEL
  101.                                     °MBOX_NOICON
  102.                                     °MBOX_CUANOTIFICATION
  103.                                     °MBOX_CUAWARNING
  104.                                     °MBOX_ICONQUESTION
  105.                                     °MBOX_ICONEXCLAMATION
  106.                                     °MBOX_ICONASTERISK
  107.                                     °MBOX_ICONHAND
  108.                                     °MBOX_CUACRITICAL
  109.                                     °MBOX_QUERY
  110.                                     °MBOX_WARNING
  111.                                     °MBOX_INFORMATION
  112.                                     °MBOX_CRITICAL
  113.                                     °MBOX_ERROR
  114.                                     °MBOX_CUSTOMICON
  115.                                     °MBOX_DEFBUTTON1
  116.                                     °MBOX_DEFBUTTON2
  117.                                     °MBOX_DEFBUTTON3
  118.                                     °MBOX_APPLMODAL
  119.                                     °MBOX_SYSTEMMODAL
  120.                                     °MBOX_HELP
  121.                                     °MBOX_MOVEABLE
  122.                                     °MBOX_NONMODAL
  123.                                         </t>
  124.                               Can be or-ed.
  125.            °XWindow * owner    °owner-window of the message box. If owner is set, the
  126.                               message box is modal for the owner-window.
  127.            °ULONG id           °ID for the message-box. If MBOX_HELP is set this value identifies the help-resource in your help-file.
  128.                               Therefore the messagebox must have an owner-window and the owner-window must be related with an instance
  129.                               of XHelpInstance.
  130.                 </t>
  131. */
  132. XMessageBox :: XMessageBox(const XResource * ms1, const XResource * ms2, const ULONG style, const XWindow * owner, const ULONG id)
  133. {
  134.     XString s1, s2;
  135.  
  136.     ms1->GetResourceLibrary()->LoadString(&s1, ms1->GetID());
  137.     if (ms2)
  138.     {
  139.         if (ms2->GetID() > 0)
  140.             ms2->GetResourceLibrary()->LoadString(&s2, ms2->GetID());
  141.     }
  142.     res = WinMessageBox(HWND_DESKTOP, owner ? owner->GetHandle() : HWND_DESKTOP, (PSZ) (char *) s1, (PSZ) (char *) s2, id, style);
  143. }
  144.  
  145.  
  146. XExtendedMessageBox :: XExtendedMessageBox(const char *s1, const char *s2, const ULONG style, const SHORT buttonCount, const XMessageButton ** buttonList, const XIcon * icon, const XWindow * owner, const ULONG id)
  147. {
  148.     MB2INFO *info = (MB2INFO *) malloc(sizeof(MB2INFO) + (buttonCount - 1) * sizeof(MB2D));
  149.  
  150.     memset(info, 0, sizeof(info));
  151.     info->cb = sizeof(MB2INFO) + (buttonCount > 0 ? (buttonCount - 1) * sizeof(MB2D) : 0);
  152.     info->flStyle = style;
  153.     info->cButtons = buttonCount;
  154.  
  155.     if (buttonCount)
  156.     {
  157.         int i;
  158.  
  159.         for (i = 0; i < buttonCount; i++)
  160.             memcpy(&info->mb2d[i], &buttonList[i]->info, sizeof(MB2D));
  161.     }
  162.  
  163.     if (icon)
  164.     {
  165.         info->flStyle |= MB_CUSTOMICON;
  166.         info->hIcon = icon->GetHandle();
  167.     }
  168.  
  169.     res = WinMessageBox2(HWND_DESKTOP, owner ? owner->GetHandle() : HWND_DESKTOP, (PSZ) s1, (PSZ) (s2 ? s2 : ""), id, info);
  170.  
  171.     free(info);
  172. }
  173.  
  174.  
  175. XExtendedMessageBox :: XExtendedMessageBox(const XResource * ms1, const XResource * ms2, const ULONG style, const SHORT buttonCount, const XMessageButton ** buttonList, const XIcon * icon, const XWindow * owner, const ULONG id)
  176. {
  177.     XString s1, s2 = "";
  178.  
  179.     MB2INFO *info = (MB2INFO *) malloc(sizeof(MB2INFO) + (buttonCount - 1) * sizeof(MB2D));
  180.  
  181.     memset(info, 0, sizeof(info));
  182.     info->cb = sizeof(MB2INFO) + (buttonCount > 0 ? (buttonCount - 1) * sizeof(MB2D) : 0);
  183.     info->flStyle = style;
  184.     info->cButtons = buttonCount;
  185.  
  186.     if (buttonCount)
  187.     {
  188.         int i;
  189.  
  190.         for (i = 0; i < buttonCount; i++)
  191.             memcpy(&info->mb2d[i], &buttonList[i]->info, sizeof(MB2D));
  192.     }
  193.  
  194.     if (icon)
  195.     {
  196.         info->flStyle |= MB_CUSTOMICON;
  197.         info->hIcon = icon->GetHandle();
  198.     }
  199.  
  200.     ms1->GetResourceLibrary()->LoadString(&s1, ms1->GetID());
  201.  
  202.     if (ms2->GetID() > 0)
  203.         ms2->GetResourceLibrary()->LoadString(&s2, ms2->GetID());
  204.  
  205.     res = WinMessageBox2(HWND_DESKTOP, owner ? owner->GetHandle() : HWND_DESKTOP, (PSZ) (char *) s1, (PSZ) (char *) s2, id, info);
  206.     free(info);
  207. }
  208.