IdwThread.cpp
author sl
Mon, 17 Mar 2014 12:38:39 +0100
changeset 3 d5f6b2119a13
parent 2 558712318e1b
permissions -rw-r--r--
Fixing init result issue.
     1 //------------------------------------------------------------------------------
     2 #include "IdwThread.h"
     3 #include "iMONDisplayAPI.h"
     4 //------------------------------------------------------------------------------
     5 #define CLASSNAME TEXT("IDW_IMON_COM_WNDCLASS")
     6 //------------------------------------------------------------------------------
     7 #define WM_IDW_IMON                (WM_USER + 1)
     8 #define WM_IDW_INIT                (WM_USER + 2)
     9 #define WM_IDW_UNINIT              (WM_USER + 3)
    10 #define WM_IDW_ISINITED            (WM_USER + 4)
    11 #define WM_IDW_ISPLUGINMODEENABLED (WM_USER + 5)
    12 #define WM_IDW_SETVFDTEXT          (WM_USER + 6)
    13 #define WM_IDW_SETVFDEQ            (WM_USER + 7)
    14 #define WM_IDW_SETLCDTEXT          (WM_USER + 8)
    15 #define WM_IDW_SETLCDEQ            (WM_USER + 9)
    16 #define WM_IDW_SETLCDALLICONS      (WM_USER + 10)
    17 #define WM_IDW_SETLCDORANGEICON    (WM_USER + 11)
    18 #define WM_IDW_SETLCDMEDIATYPEICON (WM_USER + 12)
    19 #define WM_IDW_SETLCDSPEAKERICON   (WM_USER + 13)
    20 #define WM_IDW_SETLCDVIDEOCODEC    (WM_USER + 14)
    21 #define WM_IDW_SETLCDAUDIOCODEC    (WM_USER + 15)
    22 #define WM_IDW_SETLCDASPECTRATIO   (WM_USER + 16)
    23 #define WM_IDW_SETLCDETCICON       (WM_USER + 17)
    24 #define WM_IDW_SETLCDPROGRESS      (WM_USER + 18)
    25 #define WM_IDW_STATUS			   (WM_USER + 19)
    26 #define WM_IDW_INTERRUPT           (WM_USER + 100)
    27 //------------------------------------------------------------------------------
    28 
    29 /**
    30 iMON Display initialization request.
    31 */
    32 class IdwImonInitRequest : public WindowEvent
    33 	{
    34 public:
    35 	IdwImonInitRequest(HWND aWnd, UINT aMsg): WindowEvent(aWnd,aMsg) {} 
    36 	//from WindowEvent
    37 	virtual LRESULT DoExecute();
    38 	void HandleImonNotifications(WPARAM wParam, LPARAM lParam);
    39 public:
    40 	DSPNotifyCode iNotification;
    41 	DSPResult iResult;
    42 	DSPNInitResult iInitResult;
    43 	DSPType iDspType;
    44 	static const UINT KMsgIdImonNotification = WM_IDW_IMON;
    45 	};
    46 
    47 
    48 /**
    49 iMON Display status request.
    50 Retrieve the latest iMON notification code.
    51 */
    52 class IdwImonStatusRequest : public WindowEvent
    53 	{
    54 public:
    55 	IdwImonStatusRequest(HWND aWnd, UINT aMsg): WindowEvent(aWnd,aMsg) {} 
    56 	//from WindowEvent
    57 	virtual LRESULT DoExecute();
    58 public:
    59 	DSPResult iResult;
    60 	DSPNotifyCode iNotification;
    61 	};
    62 
    63 struct IdwSetVfdText
    64 {
    65   DSPResult result;
    66   LPCWSTR pszLine1;
    67   LPCWSTR pszLine2;
    68 };
    69 struct IdwSetVfdEq
    70 {
    71   DSPResult result;
    72   PDSPEQDATA pEqData;
    73 };
    74 struct IdwSetLcdText
    75 {
    76   DSPResult result;
    77   LPCWSTR pszLine1;
    78 };
    79 struct IdwSetLcdEq
    80 {
    81   DSPResult result;
    82   PDSPEQDATA pEqDataL;
    83   PDSPEQDATA pEqDataR;
    84 };
    85 struct IdwSetLcdAllIcons
    86 {
    87   DSPResult result;
    88   BOOL bOn;
    89 };
    90 struct IdwSetLcdIcons
    91 {
    92   DSPResult result;
    93   BYTE btIconData;
    94 };
    95 struct IdwSetLcdIcons2
    96 {
    97   DSPResult result;
    98   BYTE btIconData1;
    99   BYTE btIconData2;
   100 };
   101 struct IdwSetLcdProgress
   102 {
   103   DSPResult result;
   104   int nCurPos;
   105 	int nTotal;
   106 };
   107 //------------------------------------------------------------------------------
   108 IdwThread::IdwThread(HINSTANCE hInstance)
   109 : m_hInstance(hInstance)
   110 , m_hWnd(NULL)
   111 {
   112 }
   113 //------------------------------------------------------------------------------
   114 IdwThread::~IdwThread()
   115 {
   116 }
   117 //------------------------------------------------------------------------------
   118 void IdwThread::Interrupt()
   119 {
   120   if (!WaitForWindow())
   121     return;
   122   PostMessage(m_hWnd, WM_IDW_INTERRUPT, 0, 0);
   123 }
   124 
   125 /**
   126 Issue iMON initialization request.
   127 @param [in, out] Contains our request results on return.
   128 */
   129 DSPResult IdwThread::Init(IDW_INITRESULT* pInitResult)
   130 {
   131   if (!WaitForWindow())
   132     return DSP_E_FAIL;
   133 
   134   IdwImonInitRequest request(m_hWnd, WM_IDW_INIT);
   135   request.Post();
   136   request.Await();
   137   if (pInitResult != NULL)
   138   {
   139     pInitResult->iInitResult = request.iInitResult;
   140     pInitResult->iDspType = request.iDspType;
   141 	pInitResult->iNotification = request.iNotification;
   142   }
   143 
   144   return request.iResult;
   145 }
   146 //------------------------------------------------------------------------------
   147 DSPResult IdwThread::Uninit()
   148 {
   149   if (!WaitForWindow())
   150     return DSP_E_FAIL;
   151 
   152   DSPResult result;  
   153   Event finished;
   154   PostMessage(m_hWnd, WM_IDW_UNINIT, (WPARAM)&result, (LPARAM)&finished);
   155   finished.Await();
   156 
   157   return result;
   158 }
   159 //------------------------------------------------------------------------------
   160 DSPResult IdwThread::IsInitialized()
   161 {
   162   if (!WaitForWindow())
   163     return DSP_E_FAIL;
   164 
   165   DSPResult result;  
   166   Event finished;
   167   PostMessage(m_hWnd, WM_IDW_ISINITED, (WPARAM)&result, (LPARAM)&finished);
   168   finished.Await();
   169 
   170   return result;
   171 }
   172 
   173 /**
   174 Issue iMON initialization request.
   175 @param [in, out] Contains our request results on return.
   176 */
   177 DSPResult IdwThread::GetStatus(IDW_STATUS* aStatus)
   178 	{
   179 	if (!WaitForWindow())
   180 		{
   181 		return DSP_E_FAIL;
   182 		}
   183 
   184 	IdwImonStatusRequest request(m_hWnd, WM_IDW_STATUS);
   185 	request.Post();
   186 	request.Await();
   187 	if (aStatus != NULL)
   188 		{
   189 		aStatus->iNotification = request.iNotification;
   190 		}
   191 
   192 	return request.iResult;
   193 	}
   194 
   195 //------------------------------------------------------------------------------
   196 DSPResult IdwThread::IsPluginModeEnabled()
   197 {
   198   if (!WaitForWindow())
   199     return DSP_E_FAIL;
   200 
   201   DSPResult result;  
   202   Event finished;
   203   PostMessage(m_hWnd, WM_IDW_ISPLUGINMODEENABLED, (WPARAM)&result,
   204               (LPARAM)&finished);
   205   finished.Await();
   206 
   207   return result;
   208 }
   209 //------------------------------------------------------------------------------
   210 DSPResult IdwThread::SetVfdText(LPCWSTR lpszLine1, LPCWSTR lpszLine2)
   211 {
   212   if (!WaitForWindow())
   213     return DSP_E_FAIL;
   214 
   215   IdwSetVfdText text;
   216   text.pszLine1 = lpszLine1;
   217   text.pszLine2 = lpszLine2;
   218   Event finished;
   219   PostMessage(m_hWnd, WM_IDW_SETVFDTEXT, (WPARAM)&text, (LPARAM)&finished);
   220   finished.Await();
   221 
   222   return text.result;
   223 }
   224 //------------------------------------------------------------------------------
   225 DSPResult IdwThread::SetVfdEqData(PDSPEQDATA pEqData)
   226 {
   227   if (!WaitForWindow())
   228     return DSP_E_FAIL;
   229 
   230   IdwSetVfdEq eq;
   231   eq.pEqData = pEqData;
   232   Event finished;
   233   PostMessage(m_hWnd, WM_IDW_SETVFDEQ, (WPARAM)&eq, (LPARAM)&finished);
   234   finished.Await();
   235 
   236   return eq.result;
   237 }
   238 //------------------------------------------------------------------------------
   239 DSPResult IdwThread::SetLcdText(LPCWSTR lpszLine1)
   240 {
   241   if (!WaitForWindow())
   242     return DSP_E_FAIL;
   243 
   244   IdwSetLcdText text;
   245   text.pszLine1 = lpszLine1;
   246   Event finished;
   247   PostMessage(m_hWnd, WM_IDW_SETLCDTEXT, (WPARAM)&text, (LPARAM)&finished);
   248   finished.Await();
   249 
   250   return text.result;
   251 }
   252 //------------------------------------------------------------------------------
   253 DSPResult IdwThread::SetLcdEqData(PDSPEQDATA pEqDataL, PDSPEQDATA pEqDataR)
   254 {
   255   if (!WaitForWindow())
   256     return DSP_E_FAIL;
   257 
   258   IdwSetLcdEq eq;
   259   eq.pEqDataL = pEqDataL;
   260   eq.pEqDataR = pEqDataR;
   261   Event finished;
   262   PostMessage(m_hWnd, WM_IDW_SETLCDEQ, (WPARAM)&eq, (LPARAM)&finished);
   263   finished.Await();
   264 
   265   return eq.result;
   266 }
   267 //------------------------------------------------------------------------------
   268 DSPResult IdwThread::SetLcdAllIcons(BOOL bOn)
   269 {
   270   if (!WaitForWindow())
   271     return DSP_E_FAIL;
   272 
   273   IdwSetLcdAllIcons allIcons;
   274   allIcons.bOn = bOn;
   275   Event finished;
   276   PostMessage(m_hWnd, WM_IDW_SETLCDALLICONS, 
   277 		(WPARAM)&allIcons, (LPARAM)&finished);
   278   finished.Await();
   279 
   280   return allIcons.result;
   281 }
   282 //------------------------------------------------------------------------------
   283 DSPResult IdwThread::SetLcdOrangeIcon(BYTE btIconData1, BYTE btIconData2)
   284 {
   285   if (!WaitForWindow())
   286     return DSP_E_FAIL;
   287 
   288   IdwSetLcdIcons2 iconData;
   289   iconData.btIconData1 = btIconData1;
   290   iconData.btIconData2 = btIconData2;
   291   Event finished;
   292   PostMessage(m_hWnd, WM_IDW_SETLCDORANGEICON, 
   293 		(WPARAM)&iconData, (LPARAM)&finished);
   294   finished.Await();
   295 
   296   return iconData.result;
   297 }
   298 //------------------------------------------------------------------------------
   299 DSPResult IdwThread::SetLcdMediaTypeIcon(BYTE btIconData)
   300 {
   301   if (!WaitForWindow())
   302     return DSP_E_FAIL;
   303 
   304   IdwSetLcdIcons iconData;
   305   iconData.btIconData = btIconData;
   306   Event finished;
   307   PostMessage(m_hWnd, WM_IDW_SETLCDMEDIATYPEICON, 
   308 		(WPARAM)&iconData, (LPARAM)&finished);
   309   finished.Await();
   310 
   311   return iconData.result;
   312 }
   313 //------------------------------------------------------------------------------
   314 DSPResult IdwThread::SetLcdSpeakerIcon(BYTE btIconData1, BYTE btIconData2)
   315 {
   316   if (!WaitForWindow())
   317     return DSP_E_FAIL;
   318 
   319   IdwSetLcdIcons2 iconData;
   320   iconData.btIconData1 = btIconData1;
   321   iconData.btIconData2 = btIconData2;
   322   Event finished;
   323   PostMessage(m_hWnd, WM_IDW_SETLCDSPEAKERICON, 
   324 		(WPARAM)&iconData, (LPARAM)&finished);
   325   finished.Await();
   326 
   327   return iconData.result;
   328 }
   329 //------------------------------------------------------------------------------
   330 DSPResult IdwThread::SetLcdVideoCodecIcon(BYTE btIconData)
   331 {
   332   if (!WaitForWindow())
   333     return DSP_E_FAIL;
   334 
   335   IdwSetLcdIcons iconData;
   336   iconData.btIconData = btIconData;
   337   Event finished;
   338   PostMessage(m_hWnd, WM_IDW_SETLCDVIDEOCODEC, 
   339 		(WPARAM)&iconData, (LPARAM)&finished);
   340   finished.Await();
   341 
   342   return iconData.result;
   343 }
   344 //------------------------------------------------------------------------------
   345 DSPResult IdwThread::SetLcdAudioCodecIcon(BYTE btIconData)
   346 {
   347   if (!WaitForWindow())
   348     return DSP_E_FAIL;
   349 
   350   IdwSetLcdIcons iconData;
   351   iconData.btIconData = btIconData;
   352   Event finished;
   353   PostMessage(m_hWnd, WM_IDW_SETLCDAUDIOCODEC, 
   354 		(WPARAM)&iconData, (LPARAM)&finished);
   355   finished.Await();
   356 
   357   return iconData.result;
   358 }
   359 //------------------------------------------------------------------------------
   360 DSPResult IdwThread::SetLcdAspectRatioIcon(BYTE btIconData)
   361 {
   362   if (!WaitForWindow())
   363     return DSP_E_FAIL;
   364 
   365   IdwSetLcdIcons iconData;
   366   iconData.btIconData = btIconData;
   367   Event finished;
   368   PostMessage(m_hWnd, WM_IDW_SETLCDASPECTRATIO, 
   369 		(WPARAM)&iconData, (LPARAM)&finished);
   370   finished.Await();
   371 
   372   return iconData.result;
   373 }
   374 //------------------------------------------------------------------------------
   375 DSPResult IdwThread::SetLcdEtcIcon(BYTE btIconData)
   376 {
   377   if (!WaitForWindow())
   378     return DSP_E_FAIL;
   379 
   380   IdwSetLcdIcons iconData;
   381   iconData.btIconData = btIconData;
   382   Event finished;
   383   PostMessage(m_hWnd, WM_IDW_SETLCDETCICON, 
   384 		(WPARAM)&iconData, (LPARAM)&finished);
   385   finished.Await();
   386 
   387   return iconData.result;
   388 }
   389 //------------------------------------------------------------------------------
   390 DSPResult IdwThread::SetLcdProgress(int nCurPos, int nTotal)
   391 {
   392   if (!WaitForWindow())
   393     return DSP_E_FAIL;
   394 
   395   IdwSetLcdProgress progressData;
   396   progressData.nCurPos = nCurPos;
   397 	progressData.nTotal = nTotal;
   398   Event finished;
   399   PostMessage(m_hWnd, WM_IDW_SETLCDPROGRESS, 
   400 		(WPARAM)&progressData, (LPARAM)&finished);
   401   finished.Await();
   402 
   403   return progressData.result;
   404 }
   405 //------------------------------------------------------------------------------
   406 void IdwThread::Run()
   407 {
   408   if (!RegisterClass())
   409   {
   410     m_eventWindowCreationDone.Signal();
   411     return;
   412   }
   413   if (!CreateMessageWindow())
   414   {
   415     m_eventWindowCreationDone.Signal();
   416     return;
   417   }
   418   AllowImonMessages();
   419 
   420   m_eventWindowCreationDone.Signal();
   421 
   422   MSG msg;
   423   BOOL fGotMessage;
   424   while ((fGotMessage = GetMessage(&msg, (HWND) NULL, 0, 0)) != 0
   425        && fGotMessage != -1) 
   426   { 
   427     TranslateMessage(&msg); 
   428     DispatchMessage(&msg); 
   429   } 
   430 }
   431 //------------------------------------------------------------------------------
   432 bool IdwThread::RegisterClass()
   433 {
   434   WNDCLASSEX wc;
   435   if (GetClassInfoEx(m_hInstance, CLASSNAME, &wc))
   436   {
   437     return true;
   438   }
   439 
   440   wc.cbSize = sizeof(wc);
   441   wc.style = CS_HREDRAW | CS_VREDRAW;
   442   wc.lpfnWndProc = IdwThread::WndProc;
   443   wc.cbClsExtra = 0;
   444   wc.cbWndExtra = 0;
   445   wc.hInstance = m_hInstance;
   446   wc.hIcon = NULL;
   447   wc.hCursor = NULL;
   448   wc.hbrBackground = NULL;
   449   wc.lpszMenuName =  NULL;
   450   wc.lpszClassName = CLASSNAME;
   451   wc.hIconSm = NULL;
   452   if (::RegisterClassEx(&wc))
   453   {
   454     return true;
   455   }
   456   return false;
   457 }
   458 //------------------------------------------------------------------------------
   459 bool IdwThread::CreateMessageWindow()
   460 {
   461   m_hWnd = CreateWindow( 
   462     CLASSNAME,
   463     TEXT("MP iMON MessageWindow"),
   464     0,
   465     0, 0, 0, 0,
   466     HWND_MESSAGE,
   467     NULL,
   468     m_hInstance,
   469     NULL);
   470  
   471   if (!m_hWnd) 
   472     return false;
   473   return true; 
   474 }
   475 //------------------------------------------------------------------------------
   476 void IdwThread::AllowImonMessages()
   477 {
   478   // Determine OS
   479   OSVERSIONINFO version;
   480   version.dwOSVersionInfoSize = sizeof(version);
   481   GetVersionEx(&version);
   482   if (version.dwMajorVersion < 6)
   483   {
   484     return;
   485   }
   486 
   487   // Determine and allow iMON message number
   488   UINT iMonMsg =
   489     RegisterWindowMessage(
   490     TEXT("iMonMessage-431F1DC6-F31A-4AC6-A1FA-A4BB9C44FF10"));
   491   ChangeWindowMessageFilter(iMonMsg, MSGFLT_ADD);  
   492 }
   493 //------------------------------------------------------------------------------
   494 bool IdwThread::WaitForWindow()
   495 {
   496   m_eventWindowCreationDone.Await();
   497   if (m_hWnd == NULL)
   498     return false;
   499   return true;
   500 }
   501 //------------------------------------------------------------------------------
   502 LRESULT CALLBACK IdwThread::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
   503 {  
   504   static IdwImonInitRequest* initRequest = NULL;
   505   static DSPNotifyCode notification = DSPNM_PLUGIN_FAILED;
   506   DSPResult* pResult;
   507   Event* pFinished;
   508 
   509   switch (uMsg) 
   510   { 
   511     case WM_CREATE: 
   512       return 0; 
   513  
   514     case WM_DESTROY:
   515       PostQuitMessage(0);
   516       return 0;
   517 
   518 	//Notifications from iMON Display API
   519 	case IdwImonInitRequest::KMsgIdImonNotification:
   520 		notification=(DSPNotifyCode)wParam; //Keep track of our current status
   521 		if (initRequest)
   522 			{
   523 			initRequest->HandleImonNotifications(wParam,lParam);
   524 			initRequest=NULL;
   525 			}
   526 		return 0;
   527 
   528     case WM_IDW_INIT:
   529 		{
   530 		initRequest = (IdwImonInitRequest*)wParam;
   531 		LRESULT res=initRequest->Execute(uMsg);
   532 		if (res==1)
   533 			{
   534 			//Request has been completed
   535 			initRequest=NULL;
   536 			}
   537 		return 0;
   538 		}
   539 
   540     case WM_IDW_UNINIT:
   541       pResult = (DSPResult*)wParam;
   542       pFinished = (Event*)lParam;
   543       *pResult = IMON_Display_Uninit();
   544       pFinished->Signal();
   545       return 0;
   546 
   547     case WM_IDW_ISINITED:
   548       pResult = (DSPResult*)wParam;
   549       pFinished = (Event*)lParam;
   550       *pResult = IMON_Display_IsInited();
   551       pFinished->Signal();
   552       return 0;
   553 
   554     case WM_IDW_ISPLUGINMODEENABLED:
   555       pResult = (DSPResult*)wParam;
   556       pFinished = (Event*)lParam;
   557       *pResult = IMON_Display_IsPluginModeEnabled();
   558       pFinished->Signal();
   559       return 0;
   560 
   561     case WM_IDW_STATUS:
   562 		{
   563 		IdwImonStatusRequest* request = (IdwImonStatusRequest*)wParam;
   564 		request->iNotification = notification; //Get our notification code
   565 		request->iResult = DSP_SUCCEEDED;
   566 		LRESULT res=request->Execute(uMsg);
   567 		return 0;
   568 		}
   569 
   570     case WM_IDW_SETVFDTEXT:
   571 			{
   572 				IdwSetVfdText* pSetVfdText = (IdwSetVfdText*)wParam;			
   573 				WCHAR szLine1[20];
   574 				WCHAR szLine2[20];
   575 				pFinished = (Event*)lParam;
   576 				MapChars(szLine1, pSetVfdText->pszLine1, 16);
   577 				MapChars(szLine2, pSetVfdText->pszLine2, 16);
   578 				pSetVfdText->result = IMON_Display_SetVfdText(szLine1, szLine2);
   579 				pFinished->Signal();
   580 				return 0;
   581 			}
   582 
   583     case WM_IDW_SETVFDEQ:
   584 			{
   585 				IdwSetVfdEq* pSetVfdEq = (IdwSetVfdEq*)wParam;
   586 				pFinished = (Event*)lParam;
   587 				pSetVfdEq->result = IMON_Display_SetVfdEqData(pSetVfdEq->pEqData);
   588 				pFinished->Signal();
   589 				return 0;
   590 			}
   591 
   592     case WM_IDW_SETLCDTEXT:
   593 			{
   594 				IdwSetLcdText* pSetLcdText = (IdwSetLcdText*)wParam;
   595 				pFinished = (Event*)lParam;
   596 				pSetLcdText->result = IMON_Display_SetLcdText(pSetLcdText->pszLine1);
   597 				pFinished->Signal();
   598 				return 0;
   599 			}
   600 
   601     case WM_IDW_SETLCDEQ:
   602 			{
   603 				IdwSetLcdEq* pSetLcdEq = (IdwSetLcdEq*)wParam;
   604 				pFinished = (Event*)lParam;
   605 				pSetLcdEq->result = 
   606 					IMON_Display_SetLcdEqData(pSetLcdEq->pEqDataL, pSetLcdEq->pEqDataR);
   607 				pFinished->Signal();
   608 				return 0;
   609 			}
   610 
   611 		case WM_IDW_SETLCDALLICONS:
   612 			{
   613 				IdwSetLcdAllIcons* pSetLcdAllIcons = (IdwSetLcdAllIcons*)wParam;
   614 				pFinished = (Event*)lParam;
   615 				pSetLcdAllIcons->result = 
   616 					IMON_Display_SetLcdAllIcons(pSetLcdAllIcons->bOn);
   617 				pFinished->Signal();
   618 				return 0;
   619 			}
   620 
   621 		case WM_IDW_SETLCDORANGEICON:
   622 			{
   623 				IdwSetLcdIcons2* pSetLcdIcons2 = (IdwSetLcdIcons2*)wParam;
   624 				pFinished = (Event*)lParam;
   625 				pSetLcdIcons2->result = IMON_Display_SetLcdOrangeIcon(
   626 					pSetLcdIcons2->btIconData1, pSetLcdIcons2->btIconData2);
   627 				pFinished->Signal();
   628 				return 0;
   629 			}
   630 
   631 	  case WM_IDW_SETLCDMEDIATYPEICON:
   632 			{
   633 				IdwSetLcdIcons* pSetLcdIcons = (IdwSetLcdIcons*)wParam;
   634 				pFinished = (Event*)lParam;
   635 				pSetLcdIcons->result = 
   636 					IMON_Display_SetLcdMediaTypeIcon(pSetLcdIcons->btIconData);
   637 				pFinished->Signal();
   638 				return 0;
   639 			}
   640 
   641 		case WM_IDW_SETLCDSPEAKERICON:
   642 			{
   643 				IdwSetLcdIcons2* pSetLcdIcons2 = (IdwSetLcdIcons2*)wParam;
   644 				pFinished = (Event*)lParam;
   645 				pSetLcdIcons2->result = IMON_Display_SetLcdSpeakerIcon(
   646 					pSetLcdIcons2->btIconData1, pSetLcdIcons2->btIconData2);
   647 				pFinished->Signal();
   648 				return 0;
   649 			}
   650 
   651 	  case WM_IDW_SETLCDVIDEOCODEC:
   652 			{
   653 				IdwSetLcdIcons* pSetLcdIcons = (IdwSetLcdIcons*)wParam;
   654 				pFinished = (Event*)lParam;
   655 				pSetLcdIcons->result = 
   656 					IMON_Display_SetLcdVideoCodecIcon(pSetLcdIcons->btIconData);
   657 				pFinished->Signal();
   658 				return 0;
   659 			}
   660 
   661 		case WM_IDW_SETLCDAUDIOCODEC:
   662 			{
   663 				IdwSetLcdIcons* pSetLcdIcons = (IdwSetLcdIcons*)wParam;
   664 				pFinished = (Event*)lParam;
   665 				pSetLcdIcons->result = 
   666 					IMON_Display_SetLcdAudioCodecIcon(pSetLcdIcons->btIconData);
   667 				pFinished->Signal();
   668 				return 0;
   669 			}
   670 
   671 		case WM_IDW_SETLCDASPECTRATIO:
   672 			{
   673 				IdwSetLcdIcons* pSetLcdIcons = (IdwSetLcdIcons*)wParam;
   674 				pFinished = (Event*)lParam;
   675 				pSetLcdIcons->result = 
   676 					IMON_Display_SetLcdAspectRatioIcon(pSetLcdIcons->btIconData);
   677 				pFinished->Signal();
   678 				return 0;
   679 			}
   680 
   681 		case WM_IDW_SETLCDETCICON:
   682 			{
   683 				IdwSetLcdIcons* pSetLcdIcons = (IdwSetLcdIcons*)wParam;
   684 				pFinished = (Event*)lParam;
   685 				pSetLcdIcons->result = 
   686 					IMON_Display_SetLcdEtcIcon(pSetLcdIcons->btIconData);
   687 				pFinished->Signal();
   688 				return 0;
   689 			}
   690 
   691 		case WM_IDW_SETLCDPROGRESS:
   692 			{
   693 				IdwSetLcdProgress* pSetLcdProgress = (IdwSetLcdProgress*)wParam;
   694 				pFinished = (Event*)lParam;
   695 				pSetLcdProgress->result = IMON_Display_SetLcdProgress(
   696 					pSetLcdProgress->nCurPos, pSetLcdProgress->nTotal);
   697 				pFinished->Signal();
   698 				return 0;
   699 			}
   700 
   701     case WM_IDW_INTERRUPT:
   702       DestroyWindow(hwnd);
   703       return 0;
   704 	}
   705   return DefWindowProc(hwnd, uMsg, wParam, lParam);
   706 }
   707 //------------------------------------------------------------------------------
   708 void IdwThread::MapChars(LPWSTR lpszTarget, LPCWSTR lpszSource,
   709                          int nMaxLength)
   710 {
   711   int len = (int)wcslen(lpszSource);
   712   if ((nMaxLength > 0) && (len > nMaxLength))
   713     len = nMaxLength;
   714   lpszTarget[len] = 0;
   715   for (int i = 0; i < len; ++i)
   716   {
   717     wchar_t ch = lpszSource[i];
   718     lpszTarget[i] = MapChar(ch);
   719   }
   720 }
   721 //------------------------------------------------------------------------------
   722 #define IN_RANGE(ch, s, e) ((ch >= s) && (ch <= e))
   723 #define IS(ch, c) (ch == c)
   724 wchar_t IdwThread::MapChar(wchar_t ch)
   725 {
   726   if (IN_RANGE(ch, 0x0020, 0x005B)
   727    || IN_RANGE(ch, 0x005D, 0x007D)
   728    || IS(ch, 0x0401)
   729    || IS(ch, 0x0404)
   730    || IN_RANGE(ch, 0x0406, 0x0407)
   731    || IN_RANGE(ch, 0x0410, 0x044F)
   732    || IS(ch, 0x0451)
   733    || IS(ch, 0x0454)
   734    || IN_RANGE(ch, 0x0456, 0x0457)
   735    || IN_RANGE(ch, 0x0490, 0x0491))
   736     return ch;
   737 
   738   switch (ch)
   739   {
   740   case 0x5C:
   741     return 0x8C;
   742   case 0x7E:
   743     return 0x8E;
   744   case 0x7F:
   745     return 0x20;
   746   case 0xA2:
   747     return 0xEC;
   748   case 0xA3:
   749     return 0x92;
   750   case 0xA5:
   751     return 0x5C;
   752   case 0xA6:
   753     return 0x98;
   754   case 0xA7:
   755     return 0x8F;
   756   case 0xB0:
   757     return 0xDF;
   758   case 0xB5:
   759     return 0xE4;
   760   case 0xC2:
   761     return 0x82;
   762   case 0xC4:
   763     return 0x80;
   764   case 0xC5:
   765     return 0x81;
   766   case 0xC6:
   767     return 0x90;
   768   case 0xC7:
   769     return 0x99;
   770   case 0xD1:
   771     return 0xEE;
   772   case 0xD6:
   773     return 0x86;
   774   case 0xD8:
   775     return 0x88;
   776   case 0xDC:
   777     return 0x8A;
   778   case 0xDE:
   779     return 0xF0;
   780   case 0xDF:
   781     return 0xE2;
   782   case 0xE1:
   783     return 0x83;
   784   case 0xE4:
   785     return 0xE1;
   786   case 0xE5:
   787     return 0x84;
   788   case 0xE7:
   789     return 0x99;
   790   case 0xF1:
   791     return 0xD1;
   792   case 0xF6:
   793     return 0x87;
   794   case 0xF7:
   795     return 0xFD;
   796   case 0xF8:
   797     return 0x89;
   798   case 0xFC:
   799     return 0x8B;
   800   case 0xFE:
   801     return 0xF0;
   802   default:
   803     return L'#';
   804   }
   805 }
   806 
   807 /**
   808 Handle iMON notifications
   809 */
   810 void IdwImonInitRequest::HandleImonNotifications(WPARAM wParam, LPARAM lParam)
   811 	{
   812 	iNotification=(DSPNotifyCode)wParam;
   813 	iDspType=DSPN_DSP_NONE;
   814 	iResult= DSP_SUCCEEDED;
   815 
   816 	switch (iNotification)
   817 		{
   818 	case DSPNM_PLUGIN_SUCCEED:
   819 	case DSPNM_IMON_RESTARTED:
   820 	case DSPNM_HW_CONNECTED:
   821 		//lParam is display type
   822 		iDspType = (DSPType)lParam;
   823 		iInitResult = DSPN_SUCCEEDED;
   824 		break;
   825 	case DSPNM_PLUGIN_FAILED:
   826 	case DSPNM_HW_DISCONNECTED:
   827 	case DSPNM_IMON_CLOSED:
   828 		//lParam is error
   829 		iInitResult = (DSPNInitResult)lParam;
   830 		break;
   831 	case DSPNM_LCD_TEXT_SCROLL_DONE:
   832 		//That should not happen, report an error
   833 		iResult = DSP_E_FAIL;
   834 		break;
   835 		}
   836 	
   837 	//Complete our request
   838 	Signal();
   839 	}
   840 
   841 
   842 /**
   843 Run our display initialization.
   844 */
   845 LRESULT IdwImonInitRequest::DoExecute()
   846 	{
   847 	iResult = IMON_Display_Init(iWnd, KMsgIdImonNotification);
   848     if (iResult != DSP_SUCCEEDED)
   849 		{
   850 		iNotification = DSPNM_PLUGIN_FAILED;
   851         iInitResult = DSPN_ERR_UNKNOWN;
   852         iDspType = DSPN_DSP_NONE;
   853         Signal();
   854 		return 1;
   855 		}
   856 
   857 	return 0;
   858 	}
   859 
   860 
   861 /**
   862 */
   863 LRESULT IdwImonStatusRequest::DoExecute()
   864 	{
   865 	Signal();
   866 	return 0;
   867 	}