home *** CD-ROM | disk | FTP | other *** search
- //===============================================================
- // vreply.cxx - vReplyDialog class functions - X11R5
- //
- // Copyright (C) 1995,1996,1997,1998 Bruce E. Wampler
- //
- // This file is part of the V C++ GUI Framework, and is covered
- // under the terms of the GNU Library General Public License,
- // Version 2. This library has NO WARRANTY. See the source file
- // vapp.cxx for more complete information about license terms.
- //===============================================================
- #include <v/vos2.h> // for Win 32 stuff
- #include <v/vreply.h> // our header
- #include <v/vicon.h> // icons
-
- // Define static data of the class
- #define prompt_depth 1
- #define prompt_width 32
- #define prompt_height 32
- static unsigned char prompt_bits[] = {
- 0x01, 0x00, 0x00, 0x40, 0xf8, 0xff, 0xff, 0x9f, 0x05, 0x00, 0x00, 0x20,
- 0xe4, 0xff, 0xff, 0xa7, 0x15, 0x00, 0x00, 0x28, 0x14, 0xc0, 0x01, 0xa8,
- 0x15, 0xe0, 0x03, 0x28, 0x14, 0x30, 0x06, 0xa8, 0x15, 0x30, 0x06, 0x28,
- 0x14, 0x00, 0x03, 0xa8, 0x15, 0x80, 0x01, 0x28, 0x14, 0xc0, 0x00, 0xa8,
- 0x15, 0xc0, 0x00, 0x28, 0x14, 0xc0, 0x00, 0xa8, 0x15, 0xc0, 0x00, 0x28,
- 0x14, 0x00, 0x00, 0xa8, 0x15, 0xc0, 0x00, 0x28, 0x14, 0x00, 0x00, 0xa8,
- 0xe5, 0xff, 0xff, 0x27, 0x04, 0x00, 0x00, 0xa0, 0xf9, 0xff, 0xff, 0x1f,
- 0xfe, 0xff, 0xff, 0x7f, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40,
- 0x02, 0x00, 0xe0, 0x47, 0x02, 0x00, 0x00, 0x40, 0xfa, 0xff, 0xff, 0x5f,
- 0xae, 0xaa, 0xaa, 0x6a, 0x56, 0x55, 0x55, 0x55, 0xab, 0xaa, 0xaa, 0xea,
- 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00};
- static vIcon prompt((unsigned char*)&prompt_bits[0], prompt_height,
- prompt_width, prompt_depth);
-
- static CommandObject ReplyDialog[] =
- {
- // Modified: TEH Jan98
- // Put icon + text in a frame so button is below frame.
- // With many-line text displays, the button will always be below text.
- // Also remove "Blanks" around buttons; not consistant with V look!
- // Put OK button to left, and Cancel to right for proper style.
- {C_Frame, 30, 0, "",NoList, CA_NoSpace | CA_NoBorder, isSens, NoFrame, 0, 0},
- {C_Icon, 10, 0, "Reply?", (void*)&prompt, CA_None, isSens, 30, 0, 0},
- {C_Label, 91, 91, "", NoList,CA_MainMsg ,isSens, 30, 10,0},
- {C_TextIn, 92, 92, "", NoList, CA_Large, isSens, NoFrame, 0, 10},
- {C_Button, M_OK, M_OK, " OK ",NoList, CA_DefaultButton, isSens, NoFrame, 0, 92},
- {C_Button, M_Cancel, M_Cancel, " Cancel ",NoList, CA_None, isSens, NoFrame, M_OK, 92},
- {C_EndOfList,0,0,0,0,CA_None,0,0,0} };
-
- //======================>>> vReplyDialog::Reply <<<=======================
- int vReplyDialog::Reply(VCONST char* msg, char* reply, int maxlen,
- VCONST char* dflt)
- {
- // Show a message, wait for a reply
- // no important return
-
- int ans;
-
- // TEH jan98; move before "if" as it is in vYNReplyDialog
- ReplyDialog[2].title = (char *)msg;
- // TEH jan98; added ability to have a "default" reply to display
- ReplyDialog[3].title = dflt;
-
- if (!added)
- {
- AddDialogCmds(ReplyDialog); // Set up standard dialog
- added = 1;
- }
-
- int rv = ShowModalDialog((char*)msg, ans); // show and wait
-
- reply[0] = 0;
-
- if (rv != M_Cancel)
- (void) GetTextIn(92, reply, maxlen);
-
- return rv;
- }
-
- //====================>>> vReplyDialog::DialogCommand <<<=======================
- void vReplyDialog::DialogCommand(ItemVal id, ItemVal val, CmdType ctype)
- {
- // if (id == M_OK || id == M_Cancel)
- // CloseDialog();
- vModalDialog::DialogCommand(id, val, ctype);
- }
-
- // TEH Dec97
- // Added DialogDisplayed to handle the centering of the dialog in the app.
- //====================>>> vReplyDialog::DialogDisplayed <<<=======================
- void vReplyDialog::DialogDisplayed()
- {
- // we want to keep the dialog 'margin' units away from the screen edges
- const int margin = 25;
- // center the dialog in the app window, the usual nightmare of
- // os/2 and V coord transforms applies as always!
- const LONG DisplayHeight = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
- const LONG DisplayWidth = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
- SWP swpApp, swpDlg;
-
- HWND ClientHwnd = WinQueryWindow(_wDialog, QW_OWNER);
- if (ClientHwnd)
- WinQueryWindowPos(ClientHwnd, &swpApp);
- else // it seems modal-modals don't have an owner, so put in the middle!
- {
- swpApp.x=0;
- swpApp.y=0;
- swpApp.cx=0;
- swpApp.cy=0;
- }
- WinQueryWindowPos(_wDialog, &swpDlg);
-
- int left, top; // new dialog posn upper-left corner
- if ( swpApp.cx > swpDlg.cx )
- left = swpApp.x + (swpApp.cx - swpDlg.cx)/2;
- else
- left = swpApp.x;
-
- if ( swpApp.cy > swpDlg.cy )
- top = (DisplayHeight - swpApp.y - swpApp.cy) + (swpApp.cy - swpDlg.cy)/2;
- else
- top = DisplayHeight - swpApp.y - swpApp.cy;
-
- // special case of no visible parent window, so center on screen instead
- if ( swpApp.cx ==0 && swpApp.cy==0)
- {
- top = (DisplayHeight - swpDlg.cy)/2;
- left = (DisplayWidth - swpDlg.cx)/2;
- }
- // sanity checks! Make sure dialog fits on the screen!
- if ((top+swpDlg.cy+ margin) > DisplayHeight)
- top = DisplayHeight - swpDlg.cy - margin;
- if ((left+swpDlg.cx+margin) > DisplayWidth)
- left = DisplayWidth - swpDlg.cx - margin;
- // but don't overcorrect! If its bigger than the screen do the best you can
- if (top < 0 )
- top = 0;
- if (left < 0 )
- left = 0;
-
- // for this function, the position coords are relative to the screen, not the app
- // and origin is upper left corner of screen (V coords)
- SetDialogPosition (left, top);
- }
-
- // ---------------------------------------------------------------------
-