Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions | Variables
nsToolkit.cpp File Reference
#include "nsToolkit.h"
#include "nsWindow.h"
#include "prmon.h"
#include "prtime.h"
#include "nsGUIEvent.h"
#include "plevent.h"
#include "nsIServiceManager.h"
#include "nsIEventQueueService.h"
#include "nsIEventQueue.h"
#include "nsComponentManagerUtils.h"
#include "nsNativeCharsetUtils.h"
#include <objbase.h>
#include <initguid.h>
#include "aimm.h"
#include <unknwn.h>
#include "nsWindowAPI.h"

Go to the source code of this file.

Classes

struct  ThreadInitInfo

Defines

#define MAX_CLASS_NAME   128
#define MAX_MENU_NAME   128
#define MAX_FILTER_NAME   256

Functions

static NS_DEFINE_CID (kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID)
 DEFINE_GUID (IID_IActiveIMMApp, 0x08c0e040, 0x62d1, 0x11d1, 0x93, 0x26, 0x0, 0x60, 0xb0, 0x67, 0xb8, 0x6e)
 DEFINE_GUID (CLSID_CActiveIMM, 0x4955DD33, 0xB159, 0x11d0, 0x8F, 0xCF, 0x0, 0xAA, 0x00, 0x6B, 0xCC, 0x59)
 DEFINE_GUID (IID_IActiveIMMMessagePumpOwner, 0xb5cf2cfa, 0x8aeb, 0x11d1, 0x93, 0x64, 0x0, 0x60, 0xb0, 0x67, 0xb8, 0x6e)
BOOL APIENTRY DllMain (HINSTANCE hModule, DWORD reason, LPVOID lpReserved)
LRESULT CALLBACK DetectWindowMove (int code, WPARAM wParam, LPARAM lParam)
BOOL CallOpenSaveFileNameA (LPOPENFILENAMEW aFileNameW, BOOL aOpen)
BOOL WINAPI nsGetOpenFileName (LPOPENFILENAMEW aOpenFileNameW)
BOOL WINAPI nsGetSaveFileName (LPOPENFILENAMEW aSaveFileNameW)
int WINAPI nsGetClassName (HWND aWnd, LPWSTR aClassName, int aMaxCount)
HWND WINAPI nsCreateWindowEx (DWORD aExStyle, LPCWSTR aClassNameW, LPCWSTR aWindowNameW, DWORD aStyle, int aX, int aY, int aWidth, int aHeight, HWND aWndParent, HMENU aMenu, HINSTANCE aInstance, LPVOID aParam)
LRESULT WINAPI nsSendMessage (HWND aWnd, UINT aMsg, WPARAM awParam, LPARAM alParam)
ATOM WINAPI nsRegisterClass (const WNDCLASSW *aClassW)
BOOL WINAPI nsUnregisterClass (LPCWSTR aClassW, HINSTANCE aInst)
UINT WINAPI nsDragQueryFile (HDROP aDrop, UINT aCount, LPWSTR aFileW, UINT aLen)
BOOL WINAPI nsSHGetPathFromIDList (LPCITEMIDLIST aIdList, LPWSTR aPathW)
LPITEMIDLIST WINAPI nsSHBrowseForFolder (LPBROWSEINFOW aBiW)
void RunPump (void *arg)
NS_METHOD NS_GetCurrentToolkit (nsIToolkit **aResult)

Variables

static nsCOMPtr
< nsIEventQueueService
gEventQueueService
static PRBool gIsMovingWindow = PR_FALSE
static HHOOK nsMsgFilterHook = NULL
static PRUintn gToolkitTLSIndex = 0
PRBool gThreadState = PR_FALSE

Class Documentation

struct ThreadInitInfo

Definition at line 70 of file nsToolkit.cpp.

Collaboration diagram for ThreadInitInfo:
Class Members
PRMonitor * monitor
nsToolkit * toolkit

Define Documentation

Definition at line 189 of file nsToolkit.cpp.

Definition at line 191 of file nsToolkit.cpp.

#define MAX_MENU_NAME   128

Definition at line 190 of file nsToolkit.cpp.


Function Documentation

BOOL CallOpenSaveFileNameA ( LPOPENFILENAMEW  aFileNameW,
BOOL  aOpen 
)

Definition at line 193 of file nsToolkit.cpp.

{
  BOOL rtn;
  OPENFILENAMEA ofnA;
  char filterA[MAX_FILTER_NAME+2];
  char customFilterA[MAX_FILTER_NAME+1];
  char fileA[FILE_BUFFER_SIZE+1];
  char fileTitleA[MAX_PATH+1];
  char initDirA[MAX_PATH+1];
  char titleA[MAX_PATH+1];
  char defExtA[MAX_PATH+1];
  char tempNameA[MAX_PATH+1];

  memset(&ofnA, 0, sizeof(OPENFILENAMEA));
  ofnA.lStructSize = sizeof(OPENFILENAME); 
  ofnA.hwndOwner = aFileNameW->hwndOwner; 
  ofnA.hInstance = aFileNameW->hInstance; 
  if (aFileNameW->lpstrFilter)  {
    // find the true filter length
    int len = 0;
    while ((aFileNameW->lpstrFilter[len]) ||
           (aFileNameW->lpstrFilter[len+1]))
    {
      ++len;
    }

    len = WideCharToMultiByte(CP_ACP, 0,
                              aFileNameW->lpstrFilter,
                              len,
                              filterA,
                              MAX_FILTER_NAME, NULL, NULL);
    filterA[len] = '\0';
    filterA[len+1] = '\0';
    ofnA.lpstrFilter = filterA; 
  }
  if (aFileNameW->lpstrCustomFilter)  {
    NS_ConvertWtoA(aFileNameW->lpstrCustomFilter, MAX_FILTER_NAME,
                   customFilterA, "?");
    ofnA.lpstrCustomFilter = customFilterA; 
    ofnA.nMaxCustFilter = MAX_FILTER_NAME;  
  }
  ofnA.nFilterIndex = aFileNameW->nFilterIndex; // Index of pair of filter strings. Should be ok.
  if (aFileNameW->lpstrFile)  {
    NS_ConvertWtoA(aFileNameW->lpstrFile, FILE_BUFFER_SIZE, fileA, "?");
    ofnA.lpstrFile = fileA;
    ofnA.nMaxFile = FILE_BUFFER_SIZE;
    if (strlen(fileA))  {
      // find last file offset
      ofnA.nFileOffset = strrchr(fileA, '\\') - fileA + 1; 
      // find last file extension offset
      ofnA.nFileExtension = strrchr(fileA, '.') - fileA + 1; 
    }
  }
  if (aFileNameW->lpstrFileTitle) {
    NS_ConvertWtoA(aFileNameW->lpstrFileTitle, MAX_PATH, fileTitleA, "?");
    ofnA.lpstrFileTitle = fileTitleA;
    ofnA.nMaxFileTitle = MAX_PATH;  
  }
  if (aFileNameW->lpstrInitialDir)  {
    NS_ConvertWtoA(aFileNameW->lpstrInitialDir, MAX_PATH, initDirA, "?");
    ofnA.lpstrInitialDir = initDirA; 
  }
  if (aFileNameW->lpstrTitle) {
    NS_ConvertWtoA(aFileNameW->lpstrTitle, MAX_PATH, titleA, "?");
    ofnA.lpstrTitle = titleA; 
  }
  ofnA.Flags = aFileNameW->Flags; 
  if (aFileNameW->lpstrDefExt)  {
    NS_ConvertWtoA(aFileNameW->lpstrDefExt, MAX_PATH, defExtA, "?");
    ofnA.lpstrDefExt = defExtA; 
  }
  // Warning:  No WtoA() is done to application-defined data 
  ofnA.lCustData = aFileNameW->lCustData; 
  ofnA.lpfnHook = aFileNameW->lpfnHook;   
  if (aFileNameW->lpTemplateName) {
    NS_ConvertWtoA(aFileNameW->lpTemplateName, MAX_PATH, tempNameA, "?");
    ofnA.lpTemplateName = tempNameA; 
  }
  
  if (aOpen)
    rtn = GetOpenFileNameA(&ofnA);
  else
    rtn = GetSaveFileNameA(&ofnA);

  if (!rtn)
    return 0;

  if (ofnA.lpstrFile) {
    if ((ofnA.Flags & OFN_ALLOWMULTISELECT) && (ofnA.Flags & OFN_EXPLORER)) {
      // lpstrFile contains the directory and file name strings 
      // which are NULL separated, with an extra NULL character after the last file name. 
      int lenA = 0;
      while ((ofnA.lpstrFile[lenA]) || (ofnA.lpstrFile[lenA+1]))
      {
        ++lenA;
      }
      // get the size of required Wide Char and make sure aFileNameW->lpstrFile has enough space
      int lenW = MultiByteToWideChar(CP_ACP, 0, ofnA.lpstrFile, lenA, 0, 0);
      if (aFileNameW->nMaxFile < lenW+2)
        return 0; // doesn't have enough allocated space
      MultiByteToWideChar(CP_ACP, 0, ofnA.lpstrFile, lenA, aFileNameW->lpstrFile, aFileNameW->nMaxFile);
      aFileNameW->lpstrFile[lenW] = '\0';
      aFileNameW->lpstrFile[lenW+1] = '\0';
    }
    else  { 
      NS_ConvertAtoW(ofnA.lpstrFile, aFileNameW->nMaxFile, aFileNameW->lpstrFile);
    }
  }

  aFileNameW->nFilterIndex = ofnA.nFilterIndex;

  return rtn;
}

Here is the call graph for this function:

Here is the caller graph for this function:

DEFINE_GUID ( IID_IActiveIMMApp  ,
0x08c0e040  ,
0x62d1  ,
0x11d1  ,
0x93  ,
0x26  ,
0x0  ,
0x60  ,
0xb0  ,
0x67  ,
0xb8  ,
0x6e   
)
DEFINE_GUID ( CLSID_CActiveIMM  ,
0x4955DD33  ,
0xB159  ,
0x11d0  ,
0x8F  ,
0xCF  ,
0x0  ,
0xAA  ,
0x00  ,
0x6B  ,
0xCC  ,
0x59   
)
DEFINE_GUID ( IID_IActiveIMMMessagePumpOwner  ,
0xb5cf2cfa  ,
0x8aeb  ,
0x11d1  ,
0x93  ,
0x64  ,
0x0  ,
0x60  ,
0xb0  ,
0x67  ,
0xb8  ,
0x6e   
)
LRESULT CALLBACK DetectWindowMove ( int  code,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 161 of file nsToolkit.cpp.

{
    /* This msg filter is required to determine when the user has
     * clicked in the window title bar and is moving the window. 
     */

    CWPSTRUCT* sysMsg = (CWPSTRUCT*)lParam;
    if (sysMsg) {
      if (sysMsg->message == WM_ENTERSIZEMOVE) {
        gIsMovingWindow = PR_TRUE; 
        // Notify xpcom that it should favor interactivity
        // over performance because the user is moving a 
        // window
        PL_FavorPerformanceHint(PR_FALSE, 0);
      } else if (sysMsg->message == WM_EXITSIZEMOVE) {
        gIsMovingWindow = PR_FALSE;
        // Notify xpcom that it should go back to its 
        // previous performance setting which may favor
        // performance over interactivity
        PL_FavorPerformanceHint(PR_TRUE, 0);
      }
    }
    return CallNextHookEx(nsMsgFilterHook, code, wParam, lParam);
}

Here is the call graph for this function:

BOOL APIENTRY DllMain ( HINSTANCE  hModule,
DWORD  reason,
LPVOID  lpReserved 
)

Definition at line 117 of file nsToolkit.cpp.

{
    switch( reason ) {
        case DLL_PROCESS_ATTACH:
            nsToolkit::Startup(hModule);
            break;

        case DLL_THREAD_ATTACH:
            break;
    
        case DLL_THREAD_DETACH:
            break;
    
        case DLL_PROCESS_DETACH:
            nsToolkit::Shutdown();
            break;

    }

    return TRUE;
}

Here is the call graph for this function:

Definition at line 883 of file nsToolkit.cpp.

{
  nsIToolkit* toolkit = nsnull;
  nsresult rv = NS_OK;
  PRStatus status;

  // Create the TLS index the first time through...
  if (0 == gToolkitTLSIndex) {
    status = PR_NewThreadPrivateIndex(&gToolkitTLSIndex, NULL);
    if (PR_FAILURE == status) {
      rv = NS_ERROR_FAILURE;
    }
  }

  if (NS_SUCCEEDED(rv)) {
    toolkit = (nsIToolkit*)PR_GetThreadPrivate(gToolkitTLSIndex);

    //
    // Create a new toolkit for this thread...
    //
    if (!toolkit) {
      toolkit = new nsToolkit();

      if (!toolkit) {
        rv = NS_ERROR_OUT_OF_MEMORY;
      } else {
        NS_ADDREF(toolkit);
        toolkit->Init(PR_GetCurrentThread());
        //
        // The reference stored in the TLS is weak.  It is removed in the
        // nsToolkit destructor...
        //
        PR_SetThreadPrivate(gToolkitTLSIndex, (void*)toolkit);
      }
    } else {
      NS_ADDREF(toolkit);
    }
    *aResult = toolkit;
  }

  return rv;
}

Here is the call graph for this function:

HWND WINAPI nsCreateWindowEx ( DWORD  aExStyle,
LPCWSTR  aClassNameW,
LPCWSTR  aWindowNameW,
DWORD  aStyle,
int  aX,
int  aY,
int  aWidth,
int  aHeight,
HWND  aWndParent,
HMENU  aMenu,
HINSTANCE  aInstance,
LPVOID  aParam 
)

Definition at line 329 of file nsToolkit.cpp.

{
  char classNameA [MAX_CLASS_NAME];
  char windowNameA[MAX_CLASS_NAME];

  // Convert class name and Window name from Unicode to ANSI
  if (aClassNameW)
      NS_ConvertWtoA(aClassNameW, MAX_CLASS_NAME, classNameA, "?");
  if (aWindowNameW)
      NS_ConvertWtoA(aWindowNameW, MAX_CLASS_NAME, windowNameA, "?");
  
  // so far only NULL is passed
  if (aParam != NULL) {
    NS_ASSERTION(0 , "non-NULL lParam is provided in CreateWindowExA");
    return NULL;
  }

  return CreateWindowExA(aExStyle, classNameA, windowNameA,
      aStyle, aX, aY, aWidth, aHeight, aWndParent, aMenu, aInstance, aParam) ;
}
UINT WINAPI nsDragQueryFile ( HDROP  aDrop,
UINT  aCount,
LPWSTR  aFileW,
UINT  aLen 
)

Definition at line 421 of file nsToolkit.cpp.

{
  char fileA[MAX_PATH+1];

  // query a count of file?
  if (aCount == 0xFFFFFFFF)
    return DragQueryFileA(aDrop, aCount, NULL, 0);

  aLen = DragQueryFileA(aDrop, aCount, fileA, MAX_PATH);
  if (!aLen)
    return 0;

  aLen = NS_ConvertAtoW(fileA, aFileW ? MAX_PATH : 0, aFileW);
  return aLen ? aLen - 1 : 0;
}
int WINAPI nsGetClassName ( HWND  aWnd,
LPWSTR  aClassName,
int  aMaxCount 
)

Definition at line 317 of file nsToolkit.cpp.

{
  char classNameA[MAX_CLASS_NAME];

  if (!GetClassNameA(aWnd, classNameA, MAX_CLASS_NAME))
    return 0;

  aMaxCount = NS_ConvertAtoW(classNameA, MAX_CLASS_NAME, aClassName);

  return aMaxCount;
}
BOOL WINAPI nsGetOpenFileName ( LPOPENFILENAMEW  aOpenFileNameW)

Definition at line 307 of file nsToolkit.cpp.

{
  return CallOpenSaveFileNameA(aOpenFileNameW, TRUE);
}

Here is the call graph for this function:

BOOL WINAPI nsGetSaveFileName ( LPOPENFILENAMEW  aSaveFileNameW)

Definition at line 312 of file nsToolkit.cpp.

{
  return CallOpenSaveFileNameA(aSaveFileNameW, FALSE);
}

Here is the call graph for this function:

ATOM WINAPI nsRegisterClass ( const WNDCLASSW *  aClassW)

Definition at line 379 of file nsToolkit.cpp.

{
  WNDCLASSA wClass;
  char classNameA[MAX_CLASS_NAME];
  char menuNameA[MAX_MENU_NAME];

  // Set up ANSI version of class struct
  wClass.cbClsExtra   = aClassW->cbClsExtra;
  wClass.cbWndExtra   = aClassW->cbWndExtra;
  wClass.hbrBackground= aClassW->hbrBackground;
  wClass.hCursor      = aClassW->hCursor;
  wClass.hIcon        = aClassW->hIcon;
  wClass.hInstance    = aClassW->hInstance;
  wClass.lpfnWndProc  = aClassW->lpfnWndProc;
  wClass.style        = aClassW->style;

  if (NULL == aClassW->lpszClassName)
    return 0 ;

  wClass.lpszClassName = classNameA;
  if (aClassW->lpszClassName)
    NS_ConvertWtoA(aClassW->lpszClassName, MAX_CLASS_NAME, classNameA, "?");
  
  wClass.lpszMenuName = menuNameA; 
  if (aClassW->lpszMenuName)
    NS_ConvertWtoA(aClassW->lpszMenuName, MAX_MENU_NAME, menuNameA, "?");

  return RegisterClassA(&wClass);
}
LRESULT WINAPI nsSendMessage ( HWND  aWnd,
UINT  aMsg,
WPARAM  awParam,
LPARAM  alParam 
)

Definition at line 361 of file nsToolkit.cpp.

{
  // ************ Developers **********************************************
  // As far as I am aware, WM_SETTEXT is the only text related message 
  // we call to SendMessage().  When you need to send other text related message,
  // please use appropriate converters.
  NS_ASSERTION((WM_SETTEXT == aMsg || WM_SETICON == aMsg || WM_SETFONT == aMsg), 
                     "Warning. Make sure sending non-Unicode string to ::SendMessage().");
  if (WM_SETTEXT == aMsg)  {
    char title[MAX_PATH];
    if (alParam) // Note: Window titles are truncated to 159 chars by Windows
      NS_ConvertWtoA((LPCWSTR)alParam, MAX_PATH, title, "?");
    return SendMessageA(aWnd, aMsg, awParam, (LPARAM)&title);
  }

  return SendMessageA(aWnd, aMsg, awParam, alParam);
}
LPITEMIDLIST WINAPI nsSHBrowseForFolder ( LPBROWSEINFOW  aBiW)

Definition at line 452 of file nsToolkit.cpp.

{
  BROWSEINFO biA;
  LPITEMIDLIST itemIdList;
  char displayNameA[MAX_PATH];
  char titleA[MAX_PATH];

  memset(&biA, 0, sizeof(BROWSEINFO));
  biA.hwndOwner = aBiW->hwndOwner;
  biA.pidlRoot = aBiW->pidlRoot;
  if (aBiW->pszDisplayName)  {
    NS_ConvertWtoA(aBiW->pszDisplayName, MAX_PATH, displayNameA, "?");
    biA.pszDisplayName = displayNameA; 
  }
  if (aBiW->lpszTitle)  {
    NS_ConvertWtoA(aBiW->lpszTitle, MAX_PATH, titleA, "?");
    biA.lpszTitle = titleA; 
  }
  biA.ulFlags = aBiW->ulFlags;
  biA.lpfn = aBiW->lpfn;
  biA.lParam = aBiW->lParam;
  biA.iImage = aBiW->iImage;

  itemIdList = SHBrowseForFolderA(&biA);
  if (biA.pszDisplayName)  {
    NS_ConvertAtoW(biA.pszDisplayName, MAX_PATH, aBiW->pszDisplayName);
  }
  return itemIdList;
}

Here is the call graph for this function:

Here is the caller graph for this function:

BOOL WINAPI nsSHGetPathFromIDList ( LPCITEMIDLIST  aIdList,
LPWSTR  aPathW 
)

Definition at line 437 of file nsToolkit.cpp.

{
  char pathA[MAX_PATH+1];

  if (aPathW)  {
    NS_ConvertWtoA(aPathW, MAX_PATH, pathA, "?");
    if (SHGetPathFromIDListA(aIdList, pathA)) {
      NS_ConvertAtoW(pathA, MAX_PATH, aPathW);
      return TRUE;
    }
  }

  return FALSE;
}

Here is the caller graph for this function:

BOOL WINAPI nsUnregisterClass ( LPCWSTR  aClassW,
HINSTANCE  aInst 
)

Definition at line 409 of file nsToolkit.cpp.

{
  char classA[MAX_PATH+1];

  if (aClassW)  {
    NS_ConvertWtoA(aClassW, MAX_PATH, classA, "?");
    return UnregisterClassA((LPCSTR)classA, aInst);
  }
  return FALSE;
}
void RunPump ( void arg)

Definition at line 505 of file nsToolkit.cpp.

{
    ThreadInitInfo *info = (ThreadInitInfo*)arg;
    ::PR_EnterMonitor(info->monitor);

    // Start Active Input Method Manager on this thread
    if(nsToolkit::gAIMMApp)
        nsToolkit::gAIMMApp->Activate(TRUE);

    // do registration and creation in this thread
    info->toolkit->CreateInternalWindow(PR_GetCurrentThread());

    gThreadState = PR_TRUE;

    ::PR_Notify(info->monitor);
    ::PR_ExitMonitor(info->monitor);

    delete info;

    // Process messages
    MSG msg;
    while (nsToolkit::mGetMessage(&msg, NULL, 0, 0)) {
        TranslateMessage(&msg);
        nsToolkit::mDispatchMessage(&msg);
    }
}

Here is the call graph for this function:


Variable Documentation

Definition at line 66 of file nsToolkit.cpp.

Definition at line 71 of file nsToolkit.cpp.

Definition at line 151 of file nsToolkit.cpp.

PRUintn gToolkitTLSIndex = 0 [static]

Definition at line 81 of file nsToolkit.cpp.

HHOOK nsMsgFilterHook = NULL [static]

Definition at line 75 of file nsToolkit.cpp.