Exemple #1
0
void iupdrvFontGetMultiLineStringSize(Ihandle* ih, const char* str, int *w, int *h)
{
  int max_w = 0;

  IwinFont* winfont = winFontGet(ih);
  if (!winfont)
  {
    if (w) *w = 0;
    if (h) *h = 0;
    return;
  }

  if (!str)
  {
    if (w) *w = 0;
    if (h) *h = winfont->charheight * 1;
    return;
  }

  if (str[0])
  {
    SIZE size;
    int len, wlen;
    const char *nextstr;
    const char *curstr = str;

    HDC hdc = winFontGetDC(ih);
    HFONT oldhfont = (HFONT)SelectObject(hdc, winfont->hFont);
    TCHAR* wstr = iupwinStrToSystem(str);

    do
    {
      nextstr = iupStrNextLine(curstr, &len);
      if (len)
      {
#ifdef UNICODE
        wlen = MultiByteToWideChar(iupwinStrGetUTF8Mode()? CP_UTF8: CP_ACP, 0, curstr, len, 0, 0);
#else
        wlen = len;
#endif

        size.cx = 0;
        GetTextExtentPoint32(hdc, wstr, wlen, &size);
        max_w = iupMAX(max_w, size.cx);

        wstr += wlen+1;
      }

      curstr = nextstr;
    } while(*nextstr);

    SelectObject(hdc, oldhfont);
    winFontReleaseDC(ih, hdc);
  }

  if (w) *w = max_w;
  if (h) *h = winfont->charheight * iupStrLineCount(str);
}
char* iupdrvGetGlobal(const char* name)
{
  if (iupStrEqual(name, "VIRTUALSCREEN"))
  {
    int x = GetSystemMetrics(SM_XVIRTUALSCREEN); 
    int y = GetSystemMetrics(SM_YVIRTUALSCREEN);
    int w = GetSystemMetrics(SM_CXVIRTUALSCREEN); 
    int h = GetSystemMetrics(SM_CYVIRTUALSCREEN);
    return iupStrReturnStrf("%d %d %d %d", x, y, w, h);
  }
  if (iupStrEqual(name, "MONITORSINFO"))
  {
    int i;
    int monitors_count = GetSystemMetrics(SM_CMONITORS);
    RECT* monitors_rect = malloc(monitors_count*sizeof(RECT));
    char* str = iupStrGetMemory(monitors_count*50);
    char* pstr = str;

    win_monitor_index = 0;
    EnumDisplayMonitors(NULL, NULL, winGlobalMonitorInfoEnum, (LPARAM)monitors_rect);

    for (i=0; i < monitors_count; i++)
      pstr += sprintf(pstr, "%d %d %d %d\n", (int)monitors_rect[i].left, (int)monitors_rect[i].top, (int)(monitors_rect[i].right-monitors_rect[i].left), (int)(monitors_rect[i].bottom-monitors_rect[i].top));

    free(monitors_rect);
    return str;
  }
  if (iupStrEqual(name, "TRUECOLORCANVAS"))
  {
    return iupStrReturnBoolean(iupdrvGetScreenDepth() > 8);
  }
  if (iupStrEqual(name, "UTF8MODE"))
  {
    return iupStrReturnBoolean(iupwinStrGetUTF8Mode());
  }
  if (iupStrEqual(name, "UTF8MODE_FILE"))
  {
    return iupStrReturnBoolean(iupwinStrGetUTF8ModeFile());
  }
  if (iupStrEqual(name, "DLL_HINSTANCE"))
  {
    return (char*)iupwin_dll_hinstance;
  }
  if (iupStrEqual(name, "COMCTL32VER6"))
  {
    return iupStrReturnBoolean(iupwin_comctl32ver6);
  }
  if (iupStrEqual(name, "SYSTEMCODEPAGE"))
  {
    CPINFOEX info;
    GetCPInfoEx(CP_ACP, 0, &info);
    return iupStrReturnInt(info.CodePage);
  }
  if (iupStrEqual(name, "LASTERROR"))
  {
    DWORD error = GetLastError();
    if (error)
    {
      LPTSTR lpMsgBuf = NULL;
      FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|
                    FORMAT_MESSAGE_FROM_SYSTEM|
                    FORMAT_MESSAGE_IGNORE_INSERTS,
                    NULL, error, 0, 
                    (LPTSTR)&lpMsgBuf,  /* weird but that's correct */
                    0, NULL);
      if (lpMsgBuf)
      {
        char* str = iupStrReturnStr(iupwinStrFromSystem(lpMsgBuf));
        LocalFree(lpMsgBuf);
        return str;
      }
      else
        return "Unknown Error";
    }
  }
  if (iupStrEqual(name, "DWM_COMPOSITION"))
  {
    typedef HRESULT(STDAPICALLTYPE *PtrDwmIsCompositionEnabled)(BOOL*);
    static PtrDwmIsCompositionEnabled dwmIsCompositionEnabled = NULL;
    if (dwmIsCompositionEnabled == NULL) 
    {
      HMODULE dwmLibrary = LoadLibrary(TEXT("dwmapi.dll"));
      if (dwmLibrary)
        dwmIsCompositionEnabled = (PtrDwmIsCompositionEnabled)GetProcAddress(dwmLibrary, "DwmIsCompositionEnabled");
    }
    if (dwmIsCompositionEnabled != NULL) 
    {
      /* windows vista or higher (has aero): see if disabled */
      BOOL enabled;
      dwmIsCompositionEnabled(&enabled);
      return iupStrReturnBoolean(enabled);
    }
    else
      return NULL;
  }
  return NULL;
}