Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions
utils.cpp File Reference
#include <os2.h>
#include <string.h>
#include "plugin.h"

Go to the source code of this file.

Defines

#define INCL_GPI
#define INCL_WIN

Functions

BOOL IsNewMimeType (PSZ mime)
static int getWindowStringLength (HWND hWnd, PSZ lpsz)
void SetDlgItemTextWrapped (HWND hWnd, int iID, PSZ szText)

Define Documentation

Definition at line 38 of file utils.cpp.

Definition at line 39 of file utils.cpp.


Function Documentation

static int getWindowStringLength ( HWND  hWnd,
PSZ  lpsz 
) [static]

Definition at line 64 of file utils.cpp.

{
  HPS hPS = WinGetPS(hWnd);

  POINTL ptls[5];
  GpiQueryTextBox(hPS, strlen(lpsz), lpsz, 5, ptls);
  POINTL pt;
  pt.x = ptls[TXTBOX_CONCAT].x;
  pt.y = ptls[TXTBOX_TOPLEFT].y - ptls[TXTBOX_BOTTOMLEFT].y;
  WinReleasePS(hPS);
  return (int)pt.x;
}

Here is the caller graph for this function:

BOOL IsNewMimeType ( PSZ  mime)

Definition at line 46 of file utils.cpp.

{
  ULONG keysize = 512;
  char keybuf[512];

  PrfQueryProfileString(HINI_USERPROFILE, OS2INI_PLACE, mime, "", keybuf, keysize);
  if (keybuf[0] != '\0') {
    return FALSE;
  }
  else 
  {
    if (!(PrfWriteProfileString(HINI_USERPROFILE, OS2INI_PLACE, mime, "(none)")))
      WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, "Error adding MIME type value", "Default Plugin", 0, MB_OK);
    return TRUE;
  }
}

Here is the caller graph for this function:

void SetDlgItemTextWrapped ( HWND  hWnd,
int  iID,
PSZ  szText 
)

Definition at line 85 of file utils.cpp.

{
  HWND hWndStatic = WinWindowFromID(hWnd, iID);
  if(!szText || !*szText)
  {
    WinSetDlgItemText(hWnd, iID, "");
    return;
  }

  RECTL rc;
  WinQueryWindowRect(hWndStatic, &rc);

  int iStaticLength = rc.xRight - rc.xLeft;
  int iStringLength = getWindowStringLength(hWndStatic, szText);

  if(iStringLength <= iStaticLength)
  {
    WinSetDlgItemText(hWnd, iID, szText);
    return;
  }

  int iBreaks = iStringLength/iStaticLength;
  if(iBreaks <= 0)
    return;

  char * pBuf = new char[iStringLength + iBreaks + 1];
  if(pBuf == NULL)
    return;

  strcpy(pBuf, "");

  int iStart = 0;
  int iLines = 0;
  for(int i = 0; i < iStringLength; i++)
  {
    char * sz = &szText[iStart];
    int iIndex = i - iStart;
    char ch = sz[iIndex + 1];

    sz[iIndex + 1] = '\0';

    int iLength = getWindowStringLength(hWndStatic, sz);

    if(iLength < iStaticLength)
    {
      sz[iIndex + 1] = ch;
      if(iLines == iBreaks)
      {
        strcat(pBuf, sz);
        break;
      }
      continue;
    }

    sz[iIndex + 1] = ch;  // restore zeroed element
    i--;                  // go one step back

    ch = sz[iIndex];
    sz[iIndex] = '\0';    // terminate string one char shorter

    strcat(pBuf, sz);    // append the string
    strcat(pBuf, " ");   // append space character for successful wrapping

    iStart += strlen(sz);// shift new start position
    sz[iIndex] = ch;      // restore zeroed element
    iLines++;             // count lines
  }

  WinSetDlgItemText(hWnd, iID, pBuf);

  delete [] pBuf;
}

Here is the caller graph for this function: