home *** CD-ROM | disk | FTP | other *** search
- /*
- GIK/2 1.0.1 EWYNAAH.C 5621-432 (C) COPYRIGHT IBM CORP 1993. ALL RIGHTS RESERVED. LICENSED MATERIALS - PROPERTY OF IBM.
- */
- /**********************************************************************/
- /* */
- /* MODULE PROLOGUE */
- /* */
- /* COMPONENT NAME: AIRPLANE EXAMPLE */
- /* */
- /* MODULE NAME: EWYNAAH.C */
- /* */
- /* DESCRIPTIVE NAME: Graphics Interface Kit/2 - Airplane Example */
- /* */
- /* PURPOSE: Customizing code, action handler functions */
- /* */
- /* COPYRIGHT: (C) 1993 IBM Corporation */
- /* */
- /* DISCLAIMER OF WARRANTIES. The following [enclosed] code is */
- /* sample code created by IBM Corporation. This sample code is not */
- /* part of any standard or IBM product and is provided to you solely */
- /* for the purpose of assisting you in the development of your */
- /* applications. The code is provided "AS IS", without */
- /* warranty of any kind. IBM shall not be liable for any damages */
- /* arising out of your use of the sample code, even if they have been */
- /* advised of the possibility of such damages. */
- /* */
- /**********************************************************************/
- /*--------------------------------------------------------------------*/
- /* INCLUDE RELATED DEFINES */
- /*--------------------------------------------------------------------*/
-
- #define INCL_DOS /* OS/2 definitions */
- #define INCL_PM /* PM definitions */
-
- /*--------------------------------------------------------------------*/
- /* HEADER FILES */
- /*--------------------------------------------------------------------*/
-
- #include <os2.h> /* OS/2 header file */
- #include <ewyga.h> /* GIK/2 header file */
- #include "EWYNADF.H" /* Generated header file */
- #include "ewyna.h" /* Header file */
- #include "ewynarc.h" /* RC-file header */
- #include <math.h> /* C library */
- #include <errno.h> /* C library */
- #include <string.h> /* C library */
- #include <stdlib.h> /* C library */
-
- /*--------------------------------------------------------------------*/
- /* LOCAL FUNCTION PROTOTYPES */
- /*--------------------------------------------------------------------*/
-
- SHORT GSENTRY ActionHandler(DHND,USHORT,MPARAM,MPARAM);
-
- /**********************************************************************/
- /* ActionHandler */
- /* */
- /* Parameters: */
- /* DHND dhnd (I): Diagram handle. */
- /* USHORT menu_id (I): Action selected by user. */
- /* MPARAM mparam1 (I): PM-data. */
- /* MPARAM mparam2 (I): PM-data. */
- /* */
- /* Returns: */
- /* GS_OK */
- /* */
- /* Description: */
- /* The function handles all non-generic actions. */
- /**********************************************************************/
-
- SHORT GSENTRY ActionHandler(DHND dhnd,USHORT menu_id,MPARAM mparam1,
- MPARAM mparam2)
- {
- PFLIGHT pFlight = NULL; // diagram object data pointer
- PFLIGHT_ENV pEnv = NULL; // diagram environment data ptr
- PASS_ID passId; // passenger id
- SHND shnd; // symbol handle
- HWND hwndClient; // client window handle
- SHORT index; // array index
- BOOL found; // found flag
- SHORT symType; // symbol type
- HMODULE hmodCustomCode; // custom code module
-
- switch (menu_id)
- {
-
- /*----------------------------------------------------------------*/
- /* Open new diagram. */
- /*----------------------------------------------------------------*/
-
- case MID_FLIGHT_OPEN : /* ~Open... */
-
- /*--------------------------------------------------------------*/
- /* Trigger generic open action GS_OPEN. */
- /*--------------------------------------------------------------*/
-
- GsTriggerGenericAction(dhnd, GE_OPEN, NULL);
-
- /*--------------------------------------------------------------*/
- /* Init airplane symbol handle from diagram data. */
- /*--------------------------------------------------------------*/
-
- GsGetDiagPointerN(dhnd, 0, (VOID **)&pEnv);
- GsCollectSym(dhnd, GS_NODE, GS_ANY_SYM, GS_UPPER_FIRST);
- while (GsGetCollectedSym(dhnd, &shnd) != GSE_COLLECTION_EMPTY)
- {
- GsGetSymType(dhnd, shnd, &symType);
- if (symType == SYM_AIRPLANE)
- {
- pEnv->shndPlane = shnd;
- GsEndSymCollection(dhnd);
- break;
- }
- }
- break;
-
- /*--------------------------------------------------------------*/
- /* Select all passengers matching the user specified criteria. */
- /* Note: The last name has to be fully specified. The first name*/
- /* has to be fully specified or left blank for any. */
- /*--------------------------------------------------------------*/
-
- case MID_FIND : /* ~Find */
-
- /*--------------------------------------------------------------*/
- /* Retrive diagram object and environment data pointers. */
- /*--------------------------------------------------------------*/
-
- GsGetDiagObjectData(dhnd, (PVOID *)&pFlight);
- GsGetDiagPointerN(dhnd, 0, (VOID **)&pEnv);
-
- /*--------------------------------------------------------------*/
- /* Initialize data for dialog */
- /*--------------------------------------------------------------*/
-
- strcpy(passId.lastName, "");
- strcpy(passId.firstName, "");
- GsGetHwnd(dhnd, GS_WIN_MAIN, 0, FID_CLIENT, &hwndClient);
- GsGetCcModuleHandle(dhnd, &hmodCustomCode);
- memcpy(&pEnv->passId, &passId, sizeof(PASSENGER));
-
- /*--------------------------------------------------------------*/
- /* If passenger name has been entered */
- /*--------------------------------------------------------------*/
-
- if (WinDlgBox(HWND_DESKTOP, //
- hwndClient, //
- (PFNWP)ViewDlgProc, //
- hmodCustomCode, //
- D_ID_FIND, //
- (MPARAM)&dhnd) == TRUE)
- {
-
- /*------------------------------------------------------------*/
- /* Retrieve dialog data. */
- /*------------------------------------------------------------*/
-
- memcpy(&passId, &(pEnv->passId), sizeof(PASSENGER));
-
- /*------------------------------------------------------------*/
- /* Deselect all passengers. */
- /*------------------------------------------------------------*/
-
- GsPutAllSymSelection(dhnd, GS_OFF);
-
- /*------------------------------------------------------------*/
- /* Do for each seat on the plane: if the seat is reserved and */
- /* passenger matches the specified criteria, select it. */
- /*------------------------------------------------------------*/
-
- for (index = 0, found = FALSE; index < MAX_NO_SEATS; index++)
- {
- if ((pFlight->seat[index].status == RESERVED) && //
- (strcmp(passId.lastName, //
- pFlight->seat[index].passId.lastName) == 0) && //
- ((strcmp(passId.firstName, //
- pFlight->seat[index].passId.firstName) == 0) || //
- BlanksEmpty(passId.firstName)))
- {
- GsPutSymSelection(dhnd, //
- pFlight->seat[index].shndPass, //
- GS_ON);
- found = TRUE;
- }
- }
-
- /*------------------------------------------------------------*/
- /* Display the message if no passenger has been found. */
- /*------------------------------------------------------------*/
-
- if (!found)
- {
- GsMessageBox(dhnd,
- "There are no passengers with a given name.", //
- PRG_TITLE, MB_OK, NULL);
- }
- }
- break;
-
- /*--------------------------------------------------------------*/
- /* For each selected passenger, invoke passenger details dialog.*/
- /*--------------------------------------------------------------*/
-
- case MID_PASSENGER_DETAILS : /* ~Details */
- GsCollectSym(dhnd, GS_NODE, GS_SYM_SELECTED, GS_UPPER_FIRST);
- while (GsGetCollectedSym(dhnd, &shnd) != GSE_COLLECTION_EMPTY)
- PassDetails(dhnd, shnd);
- GsPutAllSymSelection(dhnd, GS_OFF);
- break;
-
- /*--------------------------------------------------------------*/
- /* Set status of selected passengers to confirmed. */
- /*--------------------------------------------------------------*/
-
- case MID_PASSENGER_CONFIRMED : /* ~Confirmed */
- SetSelPassStatusForm(dhnd, PASS_OK);
- break;
-
- /*--------------------------------------------------------------*/
- /* Set status of selected passengers to reserved (not */
- /* confirmed). */
- /*--------------------------------------------------------------*/
-
- case MID_PASSENGER_NCONFIRMED : /* ~Not Confirmed */
- SetSelPassStatusForm(dhnd, PASS_RESERVED);
- break;
- }
- return GS_OK;
- }
-
- /**********************************************************************/
- /* ViewDlgProc */
- /* */
- /* Parameters: */
- /* HWND hDlg */
- /* USHORT msg */
- /* MPARM mp1 */
- /* MPARM mp2 */
- /* */
- /* Returns for WM_COMMAND message: */
- /* TRUE Passenger name has been entered. */
- /* FALSE Dialog has been canceled. */
- /* */
- /* Description: */
- /* Passenger name entry dialog. */
- /**********************************************************************/
-
- MRESULT GSENTRY ViewDlgProc(HWND hDlg, //
- USHORT msg, //
- MPARAM mp1, //
- MPARAM mp2)
- {
- HWND hwnd; // window handle
- DHND *pdhnd; // diagram handle pointer
- PFLIGHT_ENV pEnv = NULL; // environment data pointer
-
- switch (msg)
- {
-
- /*----------------------------------------------------------------*/
- /* Initialize dialog. */
- /*----------------------------------------------------------------*/
-
- case WM_INITDLG :
- pdhnd = (DHND *)mp2;
- WinSetWindowPtr(hDlg,
- QWL_USER,
- (PVOID)pdhnd);
- GsGetDiagPointerN(*pdhnd, 0, (VOID **)&pEnv);
- WinSendDlgItemMsg(hDlg,
- ID_LAST_NAME,
- EM_SETTEXTLIMIT,
- MPFROM2SHORT(MAX_LAST_NAME,
- 0),
- NULL);
- WinSendDlgItemMsg(hDlg,
- ID_FIRST_NAME,
- EM_SETTEXTLIMIT,
- MPFROM2SHORT(MAX_FIRST_NAME,
- 0),
- NULL);
- hwnd = WinWindowFromID(hDlg,
- ID_OK);
- WinEnableWindow(hwnd,
- FALSE);
- return FALSE;
-
- /*--------------------------------------------------------------*/
- /* Disable FIND (OK) push button if no last name has been */
- /* entered. */
- /*--------------------------------------------------------------*/
-
- case WM_CONTROL :
- if ((SHORT1FROMMP(mp1) == ID_LAST_NAME || //
- SHORT1FROMMP(mp1) == ID_FIRST_NAME) && //
- SHORT2FROMMP(mp1) == EN_CHANGE)
- {
- pdhnd = (DHND *)WinQueryWindowPtr(hDlg,
- QWL_USER);
- GsGetDiagPointerN(*pdhnd, 0, (VOID **)&pEnv);
- WinQueryDlgItemText(hDlg,
- ID_LAST_NAME,
- MAX_LAST_NAME,
- pEnv->passId.lastName);
- WinQueryDlgItemText(hDlg,
- ID_FIRST_NAME,
- MAX_FIRST_NAME,
- pEnv->passId.firstName);
- hwnd = WinWindowFromID(hDlg,
- ID_OK);
- if (BlanksEmpty(pEnv->passId.lastName))
- WinEnableWindow(hwnd,
- FALSE);
- else
- WinEnableWindow(hwnd,
- TRUE);
- }
- return 0L;
- case WM_COMMAND :
- pdhnd = (DHND *)WinQueryWindowPtr(hDlg,
- QWL_USER);
- GsGetDiagPointerN(*pdhnd, 0, (VOID **)&pEnv);
-
- /*--------------------------------------------------------------*/
- /* Process according to PUSH button pressed: */
- /*--------------------------------------------------------------*/
-
- switch (SHORT1FROMMP(mp1))
- {
-
- /*------------------------------------------------------------*/
- /* FIND (OK) - Set pasenger name and exit dialog. */
- /*------------------------------------------------------------*/
-
- case ID_OK :
- WinQueryDlgItemText(hDlg,
- ID_LAST_NAME,
- MAX_LAST_NAME,
- pEnv->passId.lastName);
- RemLeadTrailB(pEnv->passId.lastName);
- WinQueryDlgItemText(hDlg,
- ID_FIRST_NAME,
- MAX_FIRST_NAME,
- pEnv->passId.firstName);
- RemLeadTrailB(pEnv->passId.firstName);
- WinDismissDlg(hDlg,
- TRUE);
- break;
-
- /*----------------------------------------------------------*/
- /* CANCEL - Cancel dialog. */
- /*----------------------------------------------------------*/
-
- case ID_CANCEL :
- WinDismissDlg(hDlg,
- FALSE);
- break;
- }
- return NULL;
- default :
- break;
- }
- return WinDefDlgProc(hDlg,
- msg,
- mp1,
- mp2);
- }