home *** CD-ROM | disk | FTP | other *** search
- //lRegen_FileHeading
- //lRegen_FileHeading
-
-
- /********************************************************************
- *
- * Source File: distance.c
- * Author: RC
- * Module: Module source file for dialog distance
- * Program Desc:
- * Date: Wed Jan 24 15:30:38 1996
- * Language: ANSI C
- *
- ********************************************************************/
-
- #include <windows.h>
- #include ".\travel.h"
-
-
- //lRegen_Variables
-
- #include <stdlib.h> // for atoi support
-
- void CalculateDistance(HWND);
- void CalcDist(LPSTR);
- void WalkList(HWND);
-
- void ClearAllItems();
- void RemoveUserData();
-
- void Push(LPSTR);
- void Pop(LPSTR);
- void EmptyStack();
-
- //lRegen_Variables
- //Lock
-
- static HWND hDlgdistance;
-
- BOOL CALLBACK EXPORT fndistanceDlgProc(HWND, UINT, WPARAM, LPARAM);
- int fndistance(HWND hParentWnd, UINT iData, void FAR *lpData)
- {
- int RetCode;
-
- //lRegen_InitDlg
- //lRegen_InitDlg
-
- if((RetCode = DialogBox(hInstance, MAKEINTRESOURCE(distance), hParentWnd, fndistanceDlgProc)) == -1)
- {
- MessageBox(NULL, "Unable to display dialog", "System Error",
- MB_SYSTEMMODAL | MB_ICONHAND | MB_OK);
- return FALSE;
- }
-
-
- //lRegen_TermDlg
- //lRegen_TermDlg
-
- return(RetCode);
- }
-
- BOOL CALLBACK EXPORT fndistanceDlgProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
- {
- WORD CtlId;
- WORD Notify;
- HWND CtlWnd;
- //lRegen_WindowProcVariables
- //lRegen_WindowProcVariables
-
- switch(uMessage)
- {
- //lRegen_WndProc
-
- case WM_DESTROY :
- RemoveUserData();
- break;
-
- //lRegen_WndProc
-
- case WM_INITDIALOG :
-
- //Regen_WM_InitDialog
- hDlgdistance = hWnd;
-
- {
- ENTITY entity;
-
- if(IsWindow(hIDO))
- {
- if(idoIterateEntityFirst(hIDO))
- while(idoIterateEntityNext(hIDO, &entity)) // extract the user names of all the entities
- {
- SendDlgItemMessage(hWnd, IDC_SOURCE, CB_ADDSTRING, 0, (LPARAM)(LPSTR)entity.name);
- SendDlgItemMessage(hWnd, IDC_DEST, CB_ADDSTRING, 0, (LPARAM)(LPSTR)entity.name);
- }
-
- SendDlgItemMessage(hWnd, IDC_SOURCE, CB_SETCURSEL, 0, 0L);
- SendDlgItemMessage(hWnd, IDC_DEST, CB_SETCURSEL, 0, 0L);
- }
-
- ClearAllItems();
- }
- //Regen_WM_InitDialog
-
- return TRUE;
-
- case WM_SHOWWINDOW :
- //Regen_WM_SHOWWINDOW
- //Regen_WM_SHOWWINDOW
- break;
-
- case WM_COMMAND :
- #ifdef WIN32
- CtlId = LOWORD(wParam);
- Notify = HIWORD(wParam);
- CtlWnd = (HWND)lParam;
- #else
- CtlId = wParam;
- Notify = HIWORD(lParam);
- CtlWnd = (HWND)LOWORD(lParam);
- #endif
- switch(CtlId)
- {
- case IDC_SOURCE :
- switch(Notify)
- {
- case CBN_SELCHANGE :
- //Regen_IDC_SOURCE_CBN_SELCHANGE
-
- CalculateDistance(hWnd);
-
- //Regen_IDC_SOURCE_CBN_SELCHANGE
- break;
-
- }
- break;
- case IDC_DEST :
- switch(Notify)
- {
- case CBN_SELCHANGE :
- //Regen_IDC_DEST_CBN_SELCHANGE
-
- CalculateDistance(hWnd);
-
- //Regen_IDC_DEST_CBN_SELCHANGE
- break;
-
- }
- break;
- case IDOK :
- //Regen_IDOK
- //Regen_IDOK
-
- EndDialog(hWnd, TRUE);
- return TRUE;
-
- case IDC_SHORT :
- //Regen_IDC_SHORT
- //Regen_IDC_SHORT
- break;
-
- case IDC_LIST :
- //Regen_IDC_LIST
- //Regen_IDC_LIST
- break;
-
- //lRegen_CustomCommand
- //lRegen_CustomCommand
-
- default :
- return FALSE;
-
- }
-
- case WM_SYSCOMMAND :
-
- //lRegen_SysCommand
- //lRegen_SysCommand
- switch(wParam & 0xFFF0)
- {
- case SC_CLOSE :
- EndDialog(hWnd, FALSE);
- return TRUE;
- }
- }
- return FALSE;
- }
-
- //Regen_CustomCode
-
- void ClearAllItems()
- {
- LPUSERDATA lpData;
- RELATION relation;
- ENTITY entity;
- long count;
-
-
- if(IsWindow(hIDO))
- {
- if(idoIterateEntityFirst(hIDO))
- while(idoIterateEntityNext(hIDO, &entity))
- {
- // if the object does not have a user data object, create one and store it
- lpData = idoEntityGetUserData(&entity);
- if(lpData == NULL)
- lpData = (LPUSERDATA)calloc(1, sizeof(USERDATA));
-
- lpData->lDistance = -1;
- lstrcpy(lpData->szNamePrevious, "");
-
- idoEntitySetUserData(&entity, lpData);
- idoEntitySetTextColor(&entity, RGB(0,0,0));
-
- // if the object has arrows pointing away, iterate through them
- // to reset their colors
- count = idoEntityGetRelationOutCount(&entity);
- if(count)
- {
- // iterate all the away arrows
- idoEntityIterateRelationOutFirst(&entity);
- while(idoEntityIterateRelationOutNext(&entity, &relation))
- idoRelationSetTextColor(&relation, RGB(0,0,0));
- }
- }
-
- InvalidateRect(hIDO, NULL, TRUE);
- UpdateWindow(hIDO);
- }
- }
-
- void CalculateDistance(HWND hDlg)
- {
- char szEntityName[100+1];
- LPUSERDATA lpData;
- ENTITY entity;
- UINT index;
-
-
- ClearAllItems();
-
- index = (UINT)SendDlgItemMessage(hDlg, IDC_SOURCE, CB_GETCURSEL, 0, 0L);
- SendDlgItemMessage(hDlg, IDC_SOURCE, CB_GETLBTEXT, (WPARAM)index, (LPARAM)(LPSTR)szEntityName);
- SendDlgItemMessage(hDlg, IDC_SHORT, LB_RESETCONTENT, 0, 0L);
-
- idoGetEntity(hIDO, 0, szEntityName, &entity);
- lpData = idoEntityGetUserData(&entity);
- if(lpData != NULL)
- lpData->lDistance = 0;
-
- EmptyStack();
- Push(szEntityName); // push entity name from the SOURCE combobox
-
- while(SendDlgItemMessage(hDlg, IDC_LIST, LB_GETCOUNT, 0, 0L)) // while the stack is not empty
- {
- Pop(szEntityName);
- CalcDist(szEntityName);
- }
-
- WalkList(hDlg);
- }
-
-
- // pass the name of the previous item here
- void CalcDist(LPSTR lpName)
- {
- LPUSERDATA lpData;
- RELATION relation;
- ENTITY this_entity;
- ENTITY next_entity;
- long count, Distance, CurrDist;
- char szText[50+1];
-
-
- idoGetEntity(hIDO, 0, lpName, &this_entity);
- lpData = idoEntityGetUserData(&this_entity);
- if(lpData != NULL)
- CurrDist = lpData->lDistance; // save the current distance.
-
-
- // if the object has arrows pointing away, iterate through them
- count = idoEntityGetRelationOutCount(&this_entity);
- if(count)
- {
- // iterate all the away arrows
- idoEntityIterateRelationOutFirst(&this_entity);
- while(idoEntityIterateRelationOutNext(&this_entity, &relation))
- {
- lstrcpy(szText, idoRelationGetText(&relation)); // get the line text
- Distance = (long)atoi(szText); // do a get prop for this
-
- idoRelationDestinationEntity(&relation, &next_entity);
- lpData = idoEntityGetUserData(&next_entity);
- if(lpData != NULL)
- {
- // if the distance to the prev item is less, do this
- if( (lpData->lDistance == -1) || (lpData->lDistance > Distance + CurrDist) )
- {
- lstrcpy(lpData->szNamePrevious, lpName);
- lstrcpy(lpData->szNamePreviousLine, (LPSTR)relation.name);
- lpData->lDistance = Distance + CurrDist;
- Push((LPSTR)next_entity.name);
- }
- }
- } // end WHILE
- }
-
- count = idoEntityGetRelationInCount(&this_entity);
- if(count)
- {
- //iterate all the arrows pointing to this entity
- idoEntityIterateRelationInFirst(&this_entity);
- while(idoEntityIterateRelationInNext(&this_entity, &relation))
-
- {
- lstrcpy(szText, idoRelationGetText(&relation)); // get the line text
- Distance = (long)atoi(szText); // do a get prop for this;
-
- idoRelationSourceEntity(&relation, &next_entity);
- lpData = idoEntityGetUserData(&next_entity);
- if(lpData != NULL)
- {
- // if the distance to the prev item is less, do this
- if( (lpData->lDistance == -1) || (lpData->lDistance > Distance + CurrDist) )
- {
- lstrcpy(lpData->szNamePrevious, lpName);
- lstrcpy(lpData->szNamePreviousLine, relation.name);
- lpData->lDistance = Distance + CurrDist;
- Push((LPSTR)next_entity.name);
- }
- }
-
- } // end WHILE
- } // end count
-
- }
-
-
- void WalkList(HWND hDlg)
- {
- char szEntityName[100+1];
- char szEntityText[100+1];
- char szSrc[99+1];
- char szText[199+1];
- long lDist;
- long total;
- UINT index;
- LPUSERDATA lpData;
- RELATION relation;
- ENTITY entity;
-
-
- total = 0; lDist = 0;
-
- // what is the destination name?
- index = (UINT)SendDlgItemMessage(hDlg, IDC_DEST, CB_GETCURSEL, 0, 0L);
- SendDlgItemMessage(hDlg, IDC_DEST, CB_GETLBTEXT, (WPARAM)index, (LPARAM)(LPSTR)szEntityName);
-
- // what is the source name?
- index = (UINT)SendDlgItemMessage(hDlg, IDC_SOURCE, CB_GETCURSEL, 0, 0L);
- SendDlgItemMessage(hDlg, IDC_SOURCE, CB_GETLBTEXT, (WPARAM)index, (LPARAM)(LPSTR)szSrc);
-
- while(TRUE)
- {
- idoGetEntity(hIDO, 0, szEntityName, &entity);
-
- idoEntitySetTextColor(&entity, RGB(255,0,0));
- lstrcpy(szEntityText, idoEntityGetText(&entity));
-
- wsprintf(szText,"%s - %li %li", (LPSTR)szEntityText, lDist, total);
- SendDlgItemMessage(hDlgdistance, IDC_SHORT, LB_INSERTSTRING, (WPARAM)0, (LPARAM)(LPSTR)szText);
-
- if(lstrcmp(szEntityName, szSrc)==0) // we are at the source entity
- break;
-
- lpData = idoEntityGetUserData(&entity);
- if(lpData == NULL)
- break;
-
- idoGetRelation(hIDO, 0, (LPSTR)lpData->szNamePreviousLine, &relation);
- idoRelationSetTextColor(&relation, RGB(255,0,0));
- lDist = lpData->lDistance;
- total += lDist;
-
- lstrcpy(szEntityName, lpData->szNamePrevious);
- }
-
- InvalidateRect(hIDO, NULL, TRUE);
- UpdateWindow(hIDO);
- }
-
-
- void RemoveUserData()
- {
- LPUSERDATA lpData;
- RELATION relation;
- ENTITY entity;
- long count;
-
-
- if(IsWindow(hIDO))
- {
- if(idoIterateEntityFirst(hIDO))
- while(idoIterateEntityNext(hIDO, &entity))
- {
- lpData = NULL;
- lpData = idoEntityGetUserData(&entity);
- if(lpData != NULL)
- free(lpData);
-
- idoEntitySetTextColor(&entity, RGB(0,0,0));
-
- // if the object has arrows pointing away, iterate through them
- // to reset their colors
- count = idoEntityGetRelationOutCount(&entity);
- if(count)
- {
- // iterate all the away arrows
- idoEntityIterateRelationOutFirst(&entity);
- while(idoEntityIterateRelationOutNext(&entity, &relation))
- idoRelationSetTextColor(&relation, RGB(0,0,0));
- }
- } // end WHILE
-
- InvalidateRect(hIDO, NULL, TRUE);
- UpdateWindow(hIDO);
- } // if IsWindow
- }
-
-
-
-
- void EmptyStack()
- {
- SendDlgItemMessage(hDlgdistance, IDC_LIST, LB_RESETCONTENT, 0, 0L);
- }
-
- void Push(LPSTR lpName)
- {
- SendDlgItemMessage(hDlgdistance, IDC_LIST, LB_INSERTSTRING, (WPARAM)-1, (LPARAM)lpName);
- }
-
- void Pop(LPSTR lpName)
- {
- SendDlgItemMessage(hDlgdistance, IDC_LIST, LB_GETTEXT, (WPARAM)0, (LPARAM)lpName);
- SendDlgItemMessage(hDlgdistance, IDC_LIST, LB_DELETESTRING, (WPARAM)0, 0L);
- }
- //Regen_CustomCode
-
-