예제 #1
0
static pascal OSStatus NPClientDialogEventHandler (EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData)
{
	OSStatus	err, result = eventNotHandledErr;

	switch (GetEventClass(inEvent))
	{
		case kEventClassCommand:
			switch (GetEventKind(inEvent))
			{
				HICommand	tHICommand;

				case kEventCommandUpdateStatus:
					err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &tHICommand);
					if (err == noErr && tHICommand.commandID == 'clos')
					{
						UpdateMenuCommandStatus(false);
						result = noErr;
					}

					break;

				case kEventCommandProcess:
					err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &tHICommand);
					if (err == noErr)
					{
						switch (tHICommand.commandID)
						{
							case 'OK__':
								CFStringRef	ref;
								HIViewRef	ctl, root;
								HIViewID	cid;

								root = HIViewGetRoot(mRef);
								cid.id = 0;

								cid.signature = 'SVIP';
								HIViewFindByID(root, cid, &ctl);
								GetEditTextCStr(ctl, npclient.serverIP);
								DeactivateControl(ctl);
								if (npclient.serverIP[0] == 0)
									strcpy(npclient.serverIP, "127.0.0.1");
								strcpy(npServerIP, npclient.serverIP);
								printf("%s\n", npServerIP);

								cid.signature = 'CLNM';
								HIViewFindByID(root, cid, &ctl);
								CopyEditTextCFString(ctl, &ref);
								DeactivateControl(ctl);
								if (ref)
								{
									Boolean	r;

									r = CFStringGetCString(ref, npclient.name, 256, kCFStringEncodingUTF8);
									if (!r)
										strcpy(npclient.name, "unknown");
									else
									if (npclient.name[0] == 0)
										strcpy(npclient.name, "Guest");

									CFRelease(ref);
								}
								else
									strcpy(npclient.name, "unknown");
								strcpy(npName, npclient.name);
								printf("%s\n", npName);

								cid.signature = 'OK__';
								HIViewFindByID(root, cid, &ctl);
								DeactivateControl(ctl);

								cid.signature = 'NOT_';
								HIViewFindByID(root, cid, &ctl);
								DeactivateControl(ctl);

								npclient.dialogcancel  = false;
								npclient.dialogprocess = kNPCDialogConnect;

								result = noErr;
								break;

							case 'NOT_':
								npclient.dialogcancel  = true;
								npclient.dialogprocess = kNPCDialogCancel;

								result = noErr;
								break;

							case 'NvDn':
								npclient.dialogcancel  = false;
								npclient.dialogprocess = kNPCDialogOpenEnd;

								result = noErr;
								break;
						}
					}

					break;
			}

			break;
	}

	return (result);
}
예제 #2
0
static pascal OSStatus NPClientDialogEventHandler(EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData)
{
	#pragma unused (inHandlerRef, inUserData)

	OSStatus	err, result = eventNotHandledErr;

	switch (GetEventClass(inEvent))
	{
		case kEventClassCommand:
			switch (GetEventKind(inEvent))
			{
				case kEventCommandProcess:
					HICommand	tHICommand;

					err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, nil, sizeof(HICommand), nil, &tHICommand);
					if (err == noErr)
					{
						switch (tHICommand.commandID)
						{
							case 'OK__':
								CFStringRef		ref;
								HIViewRef		ctl, root;
								HIViewID		cid;
								unsigned char   pstr[256];

								root = HIViewGetRoot(mRef);
								cid.id = 0;

								cid.signature = 'SVIP';
								HIViewFindByID(root, cid, &ctl);
								GetEditTextText(ctl, pstr);
								DeactivateControl(ctl);
								ConvertPString(pstr, npclient.serverIP);
								if (strlen(npclient.serverIP) == 0)
									strcpy(npclient.serverIP, "127.0.0.1");
								strcpy(npServerIP, npclient.serverIP);
								printf("%s\n", npServerIP);

								cid.signature = 'CLNM';
								HIViewFindByID(root, cid, &ctl);
								CopyEditTextCFString(ctl, &ref);
								DeactivateControl(ctl);
								if (ref)
								{
									Boolean	r;

									r = CFStringGetCString(ref, npclient.name, 256, MAC_PATH_ENCODING);
									if (!r)
										strcpy(npclient.name, "unknown");
									else	
									if (strlen(npclient.name) == 0)
										strcpy(npclient.name, "Guest");

									CFRelease(ref);
								}
								else
									strcpy(npclient.name, "unknown");
								strcpy(npName, npclient.name);
								printf("%s\n", npName);

								cid.signature = 'OK__';
								HIViewFindByID(root, cid, &ctl);
								DeactivateControl(ctl);

								cid.signature = 'NOT_';
								HIViewFindByID(root, cid, &ctl);
								DeactivateControl(ctl);

								npclient.dialogcancel  = false;
								npclient.dialogprocess = kNPCDialogConnect;

								result = noErr;
								break;
								
							case 'NOT_':
								npclient.dialogcancel  = true;
								npclient.dialogprocess = kNPCDialogCancel;

								result = noErr;
								break;
								
							case 'NvDn':
								npclient.dialogcancel  = false;
								npclient.dialogprocess = kNPCDialogOpenEnd;

								result = noErr;
						}
					}
			}
	}

	return (result);
}