//====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.3 nt/src/samples/JavaPart/prefdlg.cpp, odjavapart, od96nt, odnt9714c 3/19/97 04:00:32 [ 4/2/97 17:55:04 ]

#ifndef IBMSample_PREFERENCESDIALOG
#include "PrefDlg.h"
#endif

#ifndef IBMSample_JAVAPART
#include "IODJava.h"
#endif

#ifndef IBMSample_TAG
#include "Tag.h"
#endif

#ifndef IBMSample_MISC
#include "Misc.h"
#endif

#include "IODJava.h"

#include <qprintf.h>

/*-------------------------------------------------------------------+
|              PreferencesDialog::PreferencesDialog ()               |
| ================================================================== |
|                                                                    |
| Function:    PreferencesDialog default constructor                 |
|                                                                    |
| Algorithm:   o  Set default values...                              |
|                                                                    |
+-------------------------------------------------------------------*/
PreferencesDialog::PreferencesDialog (HWND parentWindow) :
	Dialog (parentWindow, PreferencesDialogResource)
{
	fProxyHost = fProxyPort = fProxySet = fInitialUrl = NULL;
}


/*-------------------------------------------------------------------+
|                    PreferencesDialog::Show ()                      |
| ================================================================== |
|                                                                    |
| Function:    Display the properties dialog and allow change them   |
|                                                                    |
| Returns:     (0)  Successfull                                      |
|              (-1) An error occurred                                |
|                                                                    |
+-------------------------------------------------------------------*/
void PreferencesDialog::Show ()
{
	fProxyHost = new char [255];
	fProxyPort = new char [10];
	fProxySet  = new char [6];

	GetProxy (fProxyHost, fProxyPort, fProxySet);

	if (Display () == TRUE) {
		SetProxy (fProxyHost, fProxyPort, fProxySet);

		if (fInitialUrl)
			SetDefaultURL (fInitialUrl);
	}
}


/*-------------------------------------------------------------------+
|                    PreferencesDialog::Init ()                      |
| ================================================================== |
|                                                                    |
| Function:    Initialize the properties dialog...                   |
|                                                                    |
+-------------------------------------------------------------------*/
void PreferencesDialog::Init (HWND window) 
{
	fDialogWindow = window;

	/*
	 *  Fill in "Initial Applet" section...
	 */
	AppletTag* tag = new AppletTag ((char*) GetDefaultURL ());
	if (tag) {

		/*
		 *  Remove .class extension...
		 */
		char* p = strstr (tag->fCode, ".class");
		if (p != NULL) *p = '\0';

		SetDlgItemText (window, ID_INITIAL_APPLET, tag->fCode);
	}

	/*
	 *  Fill in "Network" section...
	 */
	SetDlgItemText (window, ID_PROXY_SERVER, fProxyHost);
	SetDlgItemText (window, ID_PROXY_PORT, fProxyPort);
      CheckDlgButton (window, ID_USE_PROXY, strcmp(fProxySet, "true")==0);
}


/*-------------------------------------------------------------------+
|                     PreferencesDialog::Ok ()                       |
| ================================================================== |
|                                                                    |
| Function:    "Ok" button was pressed, take action...               |
|                                                                    |
+-------------------------------------------------------------------*/
void PreferencesDialog::Ok (HWND window) 
{
	GetDlgItemText (window, ID_PROXY_SERVER, fProxyHost, 255);
	GetDlgItemText (window, ID_PROXY_PORT, fProxyPort, 10);
      strcpy(fProxySet, IsDlgButtonChecked(window, ID_USE_PROXY) ?
         "true" : "false");
}


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

	/*
	 *  "OK" button was pressed, get new values...
	 */
	case ID_SET_INITIAL_APPLET:
		{
			AppletTag* tag = SelectApplet ("Select Initial Applet");
			if (tag) {
				/*
				 *  Remove .class extension...
				 */
				char* p = strstr (tag->fCode, ".class");
				if (p != NULL) *p = '\0';

				/*
				 *  Update preferences dialog...
				 */
				SetDlgItemText (fDialogWindow, 
					ID_INITIAL_APPLET, tag->fCode);

				/*
				 *  Remember the url...
				 */
				fInitialUrl = new char [strlen (tag->fUrl) + 1];
				strcpy (fInitialUrl, tag->fUrl);

				delete tag;
			}
		}
		return TRUE;

	default:
		break;
	}

	return FALSE;
}
