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

  1. //===============================================================
  2. // vreply.cxx - vReplyDialog 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 Win 32 stuff
  12. #include <v/vreply.h>   // our header
  13. #include <v/vicon.h>    // icons
  14.  
  15. // Define static data of the class
  16. #define prompt_depth 1
  17. #define prompt_width 32
  18. #define prompt_height 32
  19. static unsigned char prompt_bits[] = {
  20.    0x01, 0x00, 0x00, 0x40, 0xf8, 0xff, 0xff, 0x9f, 0x05, 0x00, 0x00, 0x20,
  21.    0xe4, 0xff, 0xff, 0xa7, 0x15, 0x00, 0x00, 0x28, 0x14, 0xc0, 0x01, 0xa8,
  22.    0x15, 0xe0, 0x03, 0x28, 0x14, 0x30, 0x06, 0xa8, 0x15, 0x30, 0x06, 0x28,
  23.    0x14, 0x00, 0x03, 0xa8, 0x15, 0x80, 0x01, 0x28, 0x14, 0xc0, 0x00, 0xa8,
  24.    0x15, 0xc0, 0x00, 0x28, 0x14, 0xc0, 0x00, 0xa8, 0x15, 0xc0, 0x00, 0x28,
  25.    0x14, 0x00, 0x00, 0xa8, 0x15, 0xc0, 0x00, 0x28, 0x14, 0x00, 0x00, 0xa8,
  26.    0xe5, 0xff, 0xff, 0x27, 0x04, 0x00, 0x00, 0xa0, 0xf9, 0xff, 0xff, 0x1f,
  27.    0xfe, 0xff, 0xff, 0x7f, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40,
  28.    0x02, 0x00, 0xe0, 0x47, 0x02, 0x00, 0x00, 0x40, 0xfa, 0xff, 0xff, 0x5f,
  29.    0xae, 0xaa, 0xaa, 0x6a, 0x56, 0x55, 0x55, 0x55, 0xab, 0xaa, 0xaa, 0xea,
  30.    0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00};
  31.   static vIcon prompt((unsigned char*)&prompt_bits[0], prompt_height,
  32.     prompt_width, prompt_depth);
  33.  
  34.   static CommandObject ReplyDialog[] =
  35.   {
  36.     // Modified: TEH Jan98
  37.     // Put icon + text in a frame so button is below frame.
  38.     // With many-line text displays, the button will always be below text.
  39.     // Also remove "Blanks" around buttons; not consistant with V look!
  40.     // Put OK button to left, and Cancel to right for proper style.
  41.     {C_Frame, 30, 0, "",NoList, CA_NoSpace | CA_NoBorder, isSens, NoFrame, 0, 0},
  42.     {C_Icon,  10, 0, "Reply?", (void*)&prompt, CA_None, isSens, 30, 0, 0},
  43.     {C_Label, 91, 91, "", NoList,CA_MainMsg ,isSens, 30, 10,0},
  44.     {C_TextIn, 92, 92, "", NoList, CA_Large, isSens, NoFrame, 0, 10},
  45.     {C_Button, M_OK, M_OK, " OK ",NoList, CA_DefaultButton, isSens, NoFrame, 0, 92},
  46.     {C_Button, M_Cancel, M_Cancel, " Cancel ",NoList, CA_None, isSens, NoFrame, M_OK, 92},
  47.     {C_EndOfList,0,0,0,0,CA_None,0,0,0}  };
  48.  
  49. //======================>>> vReplyDialog::Reply <<<=======================
  50.   int vReplyDialog::Reply(VCONST char* msg, char* reply, int maxlen,
  51.     VCONST char* dflt)
  52.   {
  53.     //  Show a message, wait for a reply
  54.     //  no important return
  55.  
  56.     int ans;
  57.  
  58.     // TEH jan98; move before "if" as it is in vYNReplyDialog
  59.     ReplyDialog[2].title = (char *)msg;
  60.     // TEH jan98; added ability to have a "default" reply to display
  61.     ReplyDialog[3].title = dflt;
  62.  
  63.     if (!added)
  64.     {
  65.       AddDialogCmds(ReplyDialog);             // Set up standard dialog
  66.       added = 1;
  67.     }
  68.  
  69.     int rv = ShowModalDialog((char*)msg, ans);    // show and wait
  70.  
  71.     reply[0] = 0;
  72.  
  73.     if (rv != M_Cancel)
  74.       (void) GetTextIn(92, reply, maxlen);
  75.  
  76.     return rv;
  77.   }
  78.  
  79. //====================>>> vReplyDialog::DialogCommand <<<=======================
  80.   void vReplyDialog::DialogCommand(ItemVal id, ItemVal val, CmdType ctype)
  81.   {
  82. //    if (id == M_OK || id == M_Cancel)
  83. //      CloseDialog();
  84.     vModalDialog::DialogCommand(id, val, ctype);
  85.   }
  86.  
  87. // TEH Dec97
  88. // Added DialogDisplayed to handle the centering of the dialog in the app.
  89. //====================>>> vReplyDialog::DialogDisplayed <<<=======================
  90.   void vReplyDialog::DialogDisplayed()
  91.   {
  92.     // we want to keep the dialog 'margin' units away from the screen edges
  93.     const int margin = 25;
  94.     // center the dialog in the app window, the usual nightmare of
  95.     // os/2 and V coord transforms applies as always!
  96.     const LONG DisplayHeight = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
  97.     const LONG DisplayWidth = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
  98.     SWP swpApp, swpDlg;
  99.  
  100.     HWND ClientHwnd = WinQueryWindow(_wDialog, QW_OWNER);
  101.     if (ClientHwnd)
  102.       WinQueryWindowPos(ClientHwnd, &swpApp);
  103.     else // it seems modal-modals don't have an owner, so put in the middle!
  104.     {
  105.       swpApp.x=0;
  106.       swpApp.y=0;
  107.       swpApp.cx=0;
  108.       swpApp.cy=0;
  109.     }
  110.     WinQueryWindowPos(_wDialog, &swpDlg);
  111.  
  112.     int left, top;            // new dialog posn upper-left corner
  113.     if ( swpApp.cx > swpDlg.cx )
  114.       left = swpApp.x + (swpApp.cx - swpDlg.cx)/2;
  115.     else
  116.       left = swpApp.x;
  117.  
  118.     if ( swpApp.cy > swpDlg.cy )
  119.       top = (DisplayHeight - swpApp.y - swpApp.cy) + (swpApp.cy - swpDlg.cy)/2;
  120.     else
  121.       top = DisplayHeight - swpApp.y - swpApp.cy;
  122.  
  123.     // special case of no visible parent window, so center on screen instead
  124.     if ( swpApp.cx ==0 && swpApp.cy==0)
  125.     {
  126.       top = (DisplayHeight - swpDlg.cy)/2;
  127.       left = (DisplayWidth - swpDlg.cx)/2;
  128.     }
  129.     // sanity checks!  Make sure dialog fits on the screen!
  130.     if ((top+swpDlg.cy+ margin) >  DisplayHeight)
  131.        top = DisplayHeight - swpDlg.cy - margin;
  132.     if ((left+swpDlg.cx+margin) >  DisplayWidth)
  133.        left = DisplayWidth - swpDlg.cx - margin;
  134.     // but don't overcorrect! If its bigger than the screen do the best you can
  135.     if (top < 0 )
  136.       top = 0;
  137.     if (left < 0 )
  138.       left = 0;
  139.  
  140.     // for this function, the position coords are relative to the screen, not the app
  141.     // and origin is upper left corner of screen (V coords)
  142.     SetDialogPosition (left, top);
  143.   }
  144.  
  145. // ---------------------------------------------------------------------
  146.