/***************************************************************************
 * Program:     GUI for UAV controller                                     *
 * Modul:       UnitCommon.cpp                                             *
 * Description: Common functions for dialogs and other units               *
 * Dependency:  C++ Builder 4.0                                            *
 ***************************************************************************/
#include <vcl.h>
#pragma hdrstop
#include <windows.h>

#include "UnitCommon.h"

#include "localiser/locale_set.h"
#ifdef __gettext__
 #define UTF8		16384
#endif


//---------------------------------------------------------------------------
#pragma package(smart_init)


/** Display message box and block automatic window closing when modal window is active.
 * @param[in] Str	Message string to be displayed.
 * @param[in] Hdr	Caption of message. */
int _fastcall MessageBoxFix(const char *Str, const char *Hdr, int Parameters, HWND hWnd)
{
int ret = 0;
  //ProcessMesgInProgress++;		//Block main form's timer eraser
  try
  {
#ifdef __gettext__
    if(CodePage==UTF8)
    {
      int len = MultiByteToWideChar(CP_UTF8, 0, Str, -1, NULL, 0);
      wchar_t *WStr = (wchar_t*)malloc(2*len+2);
      if(WStr!=NULL)
      {
        MultiByteToWideChar(CP_UTF8, 0, Str, -1, WStr, len+1);

        int lenH = MultiByteToWideChar(CP_UTF8, 0, Hdr, -1, NULL, 0);
        wchar_t *WStrH = NULL;
	if(lenH>0)
	{
	  WStrH = (wchar_t*)malloc(2*lenH+2);
	  MultiByteToWideChar(CP_UTF8, 0, Hdr, -1, WStrH, lenH+1);
        }

        ret = MessageBoxW(hWnd, WStr, WStrH, Parameters|MB_SETFOREGROUND|MB_TOPMOST);
        free(WStr);
        if(WStrH) free(WStrH);
      }
    }
    else
#endif
    ret = MessageBox(hWnd, Str, Hdr, Parameters|MB_SETFOREGROUND|MB_TOPMOST);
  }
  catch(...) {ret=ID_ABORT;}
  //ProcessMesgInProgress--;		//Enable main form's timer eraser
return ret;
}

