home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / vos2-121.zip / v / srcos2 / vynreply.cpp < prev   
C/C++ Source or Header  |  1999-03-03  |  6KB  |  156 lines

  1. //===============================================================
  2. // vynreply.cxx - vYNReplyDialog class functions - X11R5
  3. //
  4. // Copyright (C) 1995,1996,1997,1998   Bruce E. Wampler
  5. //
  6. // This file is part of the V C++ GUI Framework, and is covered
  7. // under the terms of the GNU Library General Public License,
  8. // Version 2. This library has NO WARRANTY. See the source file
  9. // vapp.cxx for more complete information about license terms.
  10. //===============================================================
  11. #include <v/vos2.h>           // for OS/2 stuff
  12. #include <v/vynreply.h>       // our header
  13. #include<v/vicon.h>
  14.  
  15. // Define static data of the class
  16. #define prompt_width 32
  17. #define prompt_height 32
  18. static unsigned char prompt_bits[] = {
  19.    0x01, 0x00, 0x00, 0x40, 0xf8, 0xff, 0xff, 0x9f, 0x05, 0x00, 0x00, 0x20,
  20.    0xe4, 0xff, 0xff, 0xa7, 0x15, 0x00, 0x00, 0x28, 0x14, 0xc0, 0x01, 0xa8,
  21.    0x15, 0xe0, 0x03, 0x28, 0x14, 0x30, 0x06, 0xa8, 0x15, 0x30, 0x06, 0x28,
  22.    0x14, 0x00, 0x03, 0xa8, 0x15, 0x80, 0x01, 0x28, 0x14, 0xc0, 0x00, 0xa8,
  23.    0x15, 0xc0, 0x00, 0x28, 0x14, 0xc0, 0x00, 0xa8, 0x15, 0xc0, 0x00, 0x28,
  24.    0x14, 0x00, 0x00, 0xa8, 0x15, 0xc0, 0x00, 0x28, 0x14, 0x00, 0x00, 0xa8,
  25.    0xe5, 0xff, 0xff, 0x27, 0x04, 0x00, 0x00, 0xa0, 0xf9, 0xff, 0xff, 0x1f,
  26.    0xfe, 0xff, 0xff, 0x7f, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40,
  27.    0x02, 0x00, 0xe0, 0x47, 0x02, 0x00, 0x00, 0x40, 0xfa, 0xff, 0xff, 0x5f,
  28.    0xae, 0xaa, 0xaa, 0x6a, 0x56, 0x55, 0x55, 0x55, 0xab, 0xaa, 0xaa, 0xea,
  29.    0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00};
  30.     static vIcon prompt(&prompt_bits[0], prompt_height, prompt_width);
  31.     // =
  32.     //  {
  33.     //  BitMap, prompt_height, prompt_width, 1, // type, h, w, depth
  34.     //  (unsigned char*)&prompt_bits[0]
  35.     //  };
  36.  
  37.     CommandObject vYNReplyDialog::YNDialog[] =
  38.     {
  39.       // Modified: TEH 12/97
  40.       // Changed "C_Label" to "C_Text" to allow for multiple line messages.
  41.       // Modified: TEH Jan98
  42.       // Put icon + text in a frame so button is below frame.
  43.       // With many-line text displays, the button will always be below text.
  44.       // Also remove "Blanks" around buttons; not consistant with V look!
  45.       // Finally: made a member of vYNReplyDialog so is inheritable and
  46.       // modifiable (removed "static" modifier).
  47.       {C_Frame, 30, 0, "",NoList, CA_NoSpace | CA_NoBorder, isSens, NoFrame, 0, 0},
  48.       {C_Icon,  10, 0, "Pick?",(void*)&prompt, CA_None, isSens, 30, 0, 0},
  49.       {C_Text, 91, 0, "",NoList, CA_MainMsg | CA_NoBorder, isSens, 30, 10, 0},
  50.       {C_Button, M_Yes, M_Yes, " Yes ", NoList,CA_DefaultButton, isSens, NoFrame, 0, 30},
  51.       {C_Button, M_No, M_No, " No ",NoList, CA_None, isSens, NoFrame, M_Yes, 30},
  52.       {C_Button, M_Cancel, M_Cancel, " Cancel ", NoList,CA_None, isSens, NoFrame, M_No, 30},
  53.       {C_EndOfList, 0, 0, 0, 0, CA_None, 0, 0, 0}
  54.     };
  55.  
  56. //========================>>> vYNReplyDialog::AskYN <<<=======================
  57.   int vYNReplyDialog::AskYN(VCONST char* msg)
  58.   {
  59.     //  Show a message, ask user Yes/No/Cancel
  60.     //  returns < 0 for cancel, 0 for No, 1 for Yes
  61.  
  62.     int id, val;
  63.     YNDialog[1].title = msg;            // V:1.13
  64.     YNDialog[2].title = msg;            // V:1.13
  65.     if (!added)
  66.     {
  67.       AddDialogCmds(YNDialog);                // Set up standard dialog
  68.       added = 1;
  69.     }
  70.  
  71.     id = ShowModalDialog(msg, val);     // show and wait
  72. //    id = WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, msg, "", 0,
  73. //      MB_ICONQUESTION | MB_YESNOCANCEL | MB_MOVEABLE);
  74.  
  75.     switch (id)                         // convert to our system
  76.     {
  77.       case M_Yes:
  78. //      case MBID_YES:
  79.         return 1;
  80.       case M_No:
  81. //      case MBID_NO:
  82.         return 0;
  83.       case M_Cancel:
  84. //      case MBID_CANCEL:
  85.         return -1;
  86.     };
  87.     return -1;
  88.   }
  89.  
  90. //====================>>> vYNReplyDialog::DialogCommand <<<=======================
  91.   void vYNReplyDialog::DialogCommand(ItemVal id, ItemVal val, CmdType ctype)
  92.   {
  93.     vModalDialog::DialogCommand(id,val,ctype);
  94.     if (id == M_Yes || id == M_No)
  95.     CloseDialog();
  96.   }
  97.  
  98. //====================>>> vYNReplyDialog::DialogDisplayed <<<=======================
  99.   void vYNReplyDialog::DialogDisplayed()
  100.   {
  101.     // we want to keep the dialog 'margin' units away from the screen edges
  102.     const int margin = 25;
  103.     // center the dialog in the app window, the usual nightmare of
  104.     // os/2 and V coord transforms applies as always!
  105.     const LONG DisplayHeight = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
  106.     const LONG DisplayWidth = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
  107.     SWP swpApp, swpDlg;
  108.  
  109.     HWND ClientHwnd = WinQueryWindow(_wDialog, QW_OWNER);
  110.     if (ClientHwnd)
  111.       WinQueryWindowPos(ClientHwnd, &swpApp);
  112.     else // it seems modal-modals don't have an owner, so put in the middle!
  113.     {
  114.       swpApp.x=0;
  115.       swpApp.y=0;
  116.       swpApp.cx=0;
  117.       swpApp.cy=0;
  118.     }
  119.     WinQueryWindowPos(_wDialog, &swpDlg);
  120.  
  121.     int left, top;            // new dialog posn upper-left corner
  122.     if ( swpApp.cx > swpDlg.cx )
  123.       left = swpApp.x + (swpApp.cx - swpDlg.cx)/2;
  124.     else
  125.       left = swpApp.x;
  126.  
  127.     if ( swpApp.cy > swpDlg.cy )
  128.       top = (DisplayHeight - swpApp.y - swpApp.cy) + (swpApp.cy - swpDlg.cy)/2;
  129.     else
  130.       top = DisplayHeight - swpApp.y - swpApp.cy;
  131.  
  132.     // special case of no visible parent window, so center on screen instead
  133.     if ( swpApp.cx ==0 && swpApp.cy==0)
  134.     {
  135.       top = (DisplayHeight - swpDlg.cy)/2;
  136.       left = (DisplayWidth - swpDlg.cx)/2;
  137.     }
  138.  
  139.     // sanity checks!  Make sure dialog fits on the screen!
  140.     if ((top+swpDlg.cy+ margin) >  DisplayHeight)
  141.        top = DisplayHeight - swpDlg.cy - margin;
  142.     if ((left+swpDlg.cx+margin) >  DisplayWidth)
  143.        left = DisplayWidth - swpDlg.cx - margin;
  144.     // but don't overcorrect! If its bigger than the screen do the best you can
  145.     if (top < 0 )
  146.       top = 0;
  147.     if (left < 0 )
  148.       left = 0;
  149.  
  150.     // for this function, the position coords are relative to the screen, not the app
  151.     // and origin is upper left corner of screen (V coords)
  152.     SetDialogPosition (left, top);
  153.   }
  154.  
  155. // ---------------------------------------------------------------------
  156.