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

  1. //===============================================================
  2. // vnotice.cxx - vNoticeDialog class functions - Windows
  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/vnotice.h>        // our header
  13. #include <v/vicon.h>
  14.  
  15. // Define static data of the class
  16. #define bang_width 40
  17. #define bang_height 32
  18. static unsigned char bang_bits[] = {
  19.    0x55, 0x55, 0x3d, 0x55, 0x55, 0xaa, 0xaa, 0x7e, 0xaa, 0xaa, 0x55, 0x55,
  20.    0x7e, 0x55, 0x55, 0xaa, 0x2a, 0xe7, 0xaa, 0xaa, 0x55, 0x55, 0xc3, 0x54,
  21.    0x55, 0xaa, 0xaa, 0xc3, 0xa9, 0xaa, 0x55, 0xd5, 0x99, 0x53, 0x55, 0xaa,
  22.    0xca, 0x34, 0xab, 0xaa, 0x55, 0xe5, 0x6a, 0x57, 0x55, 0xaa, 0x72, 0x76,
  23.    0xae, 0xaa, 0x55, 0x75, 0x6a, 0x4e, 0x55, 0xaa, 0x3a, 0x76, 0x9c, 0xaa,
  24.    0x55, 0x19, 0x6a, 0x58, 0x55, 0xaa, 0x1c, 0x76, 0xb8, 0xaa, 0x55, 0x0e,
  25.    0x6a, 0x70, 0x55, 0xaa, 0x06, 0x76, 0x60, 0xaa, 0x55, 0x07, 0x6a, 0xe0,
  26.    0x54, 0xaa, 0x03, 0x76, 0xc0, 0xa9, 0x95, 0x03, 0x6a, 0xc0, 0x55, 0xca,
  27.    0x01, 0x76, 0x80, 0xab, 0xd5, 0x00, 0x6a, 0x00, 0x53, 0xea, 0x00, 0x34,
  28.    0x00, 0xa7, 0x75, 0x00, 0x18, 0x00, 0x4e, 0x72, 0x00, 0x00, 0x00, 0xae,
  29.    0x39, 0x00, 0x3c, 0x00, 0x5c, 0x1c, 0x00, 0x76, 0x00, 0xb8, 0x1d, 0x00,
  30.    0x6a, 0x00, 0x38, 0x0e, 0x00, 0x76, 0x00, 0xf0, 0x0f, 0x00, 0x3c, 0x00,
  31.    0x70, 0x1e, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xfc,
  32.    0xff, 0xff, 0xff, 0xbf};
  33.     static vIcon bang((unsigned char*)&bang_bits[0], bang_height, bang_width);
  34.  
  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.     static CommandObject NoticeDialog[] =
  40.     {
  41.       {C_Frame, 93, 0, "",NoList, CA_NoSpace | CA_NoBorder, isSens, NoFrame, 0, 0},
  42.       {C_Icon, 91, 0, "Notice", (void*)&bang, CA_None,isSens,93, 0, 0},
  43.       {C_Text, 92, 0, "",NoList, CA_MainMsg | CA_NoBorder, isSens, 93, 91, 0},
  44.       {C_Button, M_OK, M_OK, " OK ", NoList, CA_DefaultButton, isSens,NoFrame, 0, 93},
  45.       {C_EndOfList,0,0,0,0,CA_None,0,0,0}
  46.     };
  47.  
  48. //======================>>> vNoticeDialog::Notice <<<=======================
  49.   void vNoticeDialog::Notice(VCONST char* msg)
  50.   {
  51.     //  Show a message, and OK
  52.     //  no important return
  53.     int dummy;
  54.  
  55.     // TEH jan98; move before "if" as it is in vYNReplyDialog
  56.     NoticeDialog[2].title = msg;        // BEW: V:1.13
  57.     if (!_cmdsAdded)                // Only once
  58.     {
  59.       AddDialogCmds(NoticeDialog);        // Set up standard dialog
  60.       _cmdsAdded = 1;
  61.     }
  62.  
  63.     (void) ShowModalDialog(msg,dummy);          // show and wait
  64.   }
  65.  
  66. //====================>>> vNoticeDialog::DialogCommand <<<=======================
  67.   void vNoticeDialog::DialogCommand(ItemVal id, ItemVal val, CmdType ctype)
  68.   {
  69.     vModalDialog::DialogCommand(id,val,ctype);
  70.   }
  71.  
  72. // TEH Dec97
  73. // Added DialogDisplayed to handle the centering of the dialog in the app.
  74. //==================>>> vNoticeDialog::DialogDisplayed <<<=====================
  75.   void vNoticeDialog::DialogDisplayed()
  76.   {
  77.     // we want to keep the dialog 'margin' units away from the screen edges
  78.     const int margin = 25;
  79.     // center the dialog in the app window, the usual nightmare of
  80.     // os/2 and V coord transforms applies as always!
  81.     const LONG DisplayHeight = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
  82.     const LONG DisplayWidth = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
  83.     SWP swpApp, swpDlg;
  84.  
  85.     HWND ClientHwnd = WinQueryWindow(_wDialog, QW_OWNER);
  86.     if (ClientHwnd)
  87.       WinQueryWindowPos(ClientHwnd, &swpApp);
  88.     else // it seems modal-modals don't have an owner, so put in the middle!
  89.     {
  90.       swpApp.x=0;
  91.       swpApp.y=0;
  92.       swpApp.cx=0;
  93.       swpApp.cy=0;
  94.     }
  95.  
  96.     WinQueryWindowPos(_wDialog, &swpDlg);
  97.  
  98.     int left, top;            // new dialog posn upper-left corner
  99.     if ( swpApp.cx > swpDlg.cx )
  100.       left = swpApp.x + (swpApp.cx - swpDlg.cx)/2;
  101.     else
  102.       left = swpApp.x;
  103.     if ( swpApp.cy > swpDlg.cy )
  104.       top = (DisplayHeight - (swpApp.y+swpApp.cy) ) + (swpApp.cy - swpDlg.cy)/2;
  105.     else
  106.       top = DisplayHeight - (swpApp.y+swpApp.cy);
  107.  
  108.     // special case of no visible parent window, so center on screen instead
  109.     if ( swpApp.cx ==0 && swpApp.cy==0)
  110.     {
  111.       top = (DisplayHeight - swpDlg.cy)/2;
  112.       left = (DisplayWidth - swpDlg.cx)/2;
  113.     }
  114.  
  115.     // sanity checks!  Make sure dialog fits on the screen!
  116.     if ((top+swpDlg.cy+ margin) >  DisplayHeight)
  117.        top = DisplayHeight - swpDlg.cy - margin;
  118.     if ((left+swpDlg.cx+margin) >  DisplayWidth)
  119.        left = DisplayWidth - swpDlg.cx - margin;
  120.     // but don't overcorrect! If its bigger than the screen do the best you can
  121.     if (top < 0 )
  122.       top = 0;
  123.     if (left < 0 )
  124.       left = 0;
  125.  
  126.     // for this function, the position coords are relative to the screen, not the app
  127.     // and origin is upper left corner of screen (V coords)
  128.     SetDialogPosition (left, top);
  129.   }
  130.  
  131.  
  132. // ---------------------------------------------------------------------
  133.