//====START_GENERATED_PROLOG======================================
//
//
//   COMPONENT_NAME: odother
//
//   CLASSES: none
//
//   ORIGINS: 27
//
//
//   (C) COPYRIGHT International Business Machines Corp. 1995,1996
//   All Rights Reserved
//   Licensed Materials - Property of IBM
//   US Government Users Restricted Rights - Use, duplication or
//   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
//
//   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
//   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
//   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
//   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
//   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
//   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
//   OR PERFORMANCE OF THIS SOFTWARE.
//
//====END_GENERATED_PROLOG========================================
//
// @(#) 1.1 nt/src/samples/JavaPart/dialog.cpp, odjavapart, od96nt, odnt9712d 10/23/96 03:06:10 [ 3/21/97 17:41:04 ]

#ifndef IBMSample_DIALOG
#include "Dialog.h"
#endif

#include <qprintf.h>


/*-------------------------------------------------------------------+
|                         Dialog::Dialog ()                          |
| ================================================================== |
|                                                                    |
| Function:    Dialog default constructor                            |
|                                                                    |
| Algorithm:   o  Set default values...                              |
|                                                                    |
+-------------------------------------------------------------------*/
Dialog::Dialog (HWND parentWindow, WORD resource) :
	fWND (parentWindow),
	fResource (MAKEINTRESOURCE(resource))
{
}


/*-------------------------------------------------------------------+
|                        Dialog::Display ()                          |
| ================================================================== |
|                                                                    |
| Function:    Display the properties dialog and return values...    |
|                                                                    |
| Returns:     (0)  Successfull                                      |
|              (-1) An error occurred                                |
|                                                                    |
+-------------------------------------------------------------------*/
int Dialog::Display ()
{
	HINSTANCE instance = (HINSTANCE) LoadLibrary ("iodjava.dll");

	return DialogBoxParam (instance, 
			       fResource,
			       fWND, 
			       (DLGPROC) ProcessWindowsMessages,
			       (LPARAM) this);
}


/*-------------------------------------------------------------------+
|                    Dialog::ProcessMessages ()                      |
| ================================================================== |
|                                                                    |
| Function:    Process the dialog messages...                        |
|                                                                    |
| Returns:     (TRUE)   - message handled                            |
|              (FALSE)  - did not handle message                     |
|                                                                    |
+-------------------------------------------------------------------*/
BOOL Dialog::ProcessMessages (HWND hWnd, 
	UINT iMsg, WPARAM wParam, LPARAM lParam)
{
	switch (iMsg) {

	/*
	 *  Display the current values on the dialog box...
	 */
	case WM_INITDIALOG :
		this->Init (hWnd);
		break;

	case WM_COMMAND:

		/*
		 *  Give a derived class a chance to handle command messages..
		 */
		if (this->ProcessCommands (hWnd, iMsg, wParam, lParam))
			return TRUE;

		switch (LOWORD (wParam)) {

		/*
		 *  "OK" button was pressed, get new values...
		 */
		case IDOK:
			this->Ok (hWnd);

			EndDialog (hWnd, 1);

			return TRUE;

		/*
		 *  "Cancel" button was pressed, ignore new values...
		 */
		case IDCANCEL:
			this->Cancel (hWnd);

			EndDialog (hWnd, 0);

			return TRUE;

		default:
			break;
		}
		break;

	default:
		break;
	}
	return FALSE;
}


/*-------------------------------------------------------------------+
|                     ProcessWindowsMessages ()                      |
| ================================================================== |
|                                                                    |
| Function:    Sends all messages to a Dialog instance...            |
|                                                                    |
| Returns:     (TRUE)   - message handled                            |
|              (FALSE)  - did not handle message                     |
|                                                                    |
+-------------------------------------------------------------------*/
BOOL CALLBACK ProcessWindowsMessages (HWND hWnd, UINT iMsg, 
				WPARAM wParam, LPARAM lParam)
{
	Dialog* props;

	switch (iMsg) {

	/*
	 *  Save a pointer to the Dialog object...
	 */
	case WM_INITDIALOG :
		SetWindowLong (hWnd, GWL_USERDATA, lParam);

	default:
		props = (Dialog*) 
			GetWindowLong (hWnd, GWL_USERDATA);

		/*
		 *  Send all messages to the Dialog object...
		 */
		return props->ProcessMessages (hWnd, iMsg, wParam, 
					      lParam);
	}

	return FALSE;
}


/*-------------------------------------------------------------------+
|                    Dialog::ProcessCommands ()                      |
| ================================================================== |
|                                                                    |
| Function:    Process the dialog messages (a derived class may      |
|              override this)...                                     |
|                                                                    |
| Returns:     (FALSE)  - did not handle message                     |
|                                                                    |
+-------------------------------------------------------------------*/
BOOL Dialog::ProcessCommands (HWND hWnd, UINT iMsg, WPARAM wParam, 
	LPARAM lParam)
{
	return FALSE;
}

