Beispiel #1
0
/**
 * Class:     sun_awt_windows_WInputMethod
 * Method:    getNativeIMMDescription
 * Signature: ()Ljava/lang/String;
 * 
 * This method tries to get the information about the input method associated with
 * the current active thread.
 *
 */
JNIEXPORT jstring JNICALL Java_sun_awt_windows_WInputMethod_getNativeIMMDescription
  (JNIEnv *env, jobject self) {

    TRY;

    // Get the keyboard layout of the active thread.
    HKL hkl = AwtComponent::GetKeyboardLayout();
    LPTSTR szImmDescription = NULL;
    UINT buffSize = 0;
    jstring infojStr = NULL;
  
    if ((buffSize = ::ImmGetDescription(hkl, szImmDescription, 0)) > 0) {
	szImmDescription = (LPTSTR) safe_Malloc(buffSize * sizeof(TCHAR));

	if (szImmDescription != NULL) {
	    ImmGetDescription(hkl, szImmDescription, buffSize);

	    infojStr = JNU_NewStringPlatform(env, szImmDescription);
      
	    free(szImmDescription);
	}
    }
  
    return infojStr;

    CATCH_BAD_ALLOC_RET(NULL);
}
JNIEXPORT jboolean JNICALL
Java_sun_awt_windows_WPrintDialogPeer__1show(JNIEnv *env, jobject peer)
{
    TRY;

    DASSERT(peer != NULL);
    jobject target = env->GetObjectField(peer, AwtObject::targetID);
    DASSERT(target != NULL);
    jobject parent = env->GetObjectField(peer, AwtPrintDialog::parentID);
    DASSERT(parent != NULL);
    jobject control = env->GetObjectField(target, AwtPrintDialog::controlID);
    DASSERT(control != NULL);

    AwtComponent *awtParent = (AwtComponent *)JNI_GET_PDATA(parent);
    DASSERT(awtParent != NULL);
    
    PRINTDLG pd;
    memset(&pd, 0, sizeof(PRINTDLG));
    pd.lStructSize = sizeof(PRINTDLG);
    AwtPrintControl::InitPrintDialog(env, control, pd);
    pd.lpfnPrintHook = (LPPRINTHOOKPROC)PrintDialogHookProc;
    pd.lpfnSetupHook = (LPSETUPHOOKPROC)PrintDialogHookProc;
    pd.Flags |= PD_ENABLESETUPHOOK | PD_ENABLEPRINTHOOK;    
    AwtDialog::ModalDisable(NULL);
    BOOL ret = AwtPrintDialog::PrintDlg(&pd);
    AwtDialog::ModalEnable(NULL);
    AwtDialog::ModalNextWindowToFront(awtParent->GetHWnd());
    if (ret) {
        AwtPrintControl::UpdateAttributes(env, control, pd);
    }

    return ret;

    CATCH_BAD_ALLOC_RET(0);
}
Beispiel #3
0
/*
 * Class:     sun_awt_windows_WClipboard
 * Method:    getClipboardFormats
 * Signature: ()[J
 */
JNIEXPORT jlongArray JNICALL
Java_sun_awt_windows_WClipboard_getClipboardFormats
    (JNIEnv *env, jobject self)
{
    TRY;

    DASSERT(::GetOpenClipboardWindow() == AwtToolkit::GetInstance().GetHWnd());

    jsize nFormats = ::CountClipboardFormats();
    jlongArray formats = env->NewLongArray(nFormats);
    if (formats == NULL) {
        throw std::bad_alloc();
    }
    if (nFormats == 0) {
        return formats;
    }
    jboolean isCopy;
    jlong *lFormats = env->GetLongArrayElements(formats, &isCopy),
        *saveFormats = lFormats;
    UINT num = 0;

    for (jsize i = 0; i < nFormats; i++, lFormats++) {
        *lFormats = num = ::EnumClipboardFormats(num);
    }

    env->ReleaseLongArrayElements(formats, saveFormats, 0);

    return formats;

    CATCH_BAD_ALLOC_RET(NULL);
}
Beispiel #4
0
jint JAWTOffscreenDrawingSurfaceInfo::Init(JAWTOffscreenDrawingSurface* parent)
{
    TRY;

    return JAWT_LOCK_ERROR;

    CATCH_BAD_ALLOC_RET(JAWT_LOCK_ERROR);
}
Beispiel #5
0
void* AwtPanel::Restack(void * param) {
    TRY;

    JNIEnv* env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
    jobjectArray peers = (jobjectArray)param;

    int peerCount = env->GetArrayLength(peers);
    if (peerCount < 1) {
        env->DeleteGlobalRef(peers);
        return AWTPANEL_RESTACK_MSG_1;
    }

    jobject self = env->GetObjectArrayElement(peers, 0);
    // It's entirely possible that our native resources have been destroyed
    // before our java peer - if we're dispose()d, for instance.
    // Alert caller w/ IllegalComponentStateException.
    if (self == NULL) {
        env->DeleteGlobalRef(peers);
        return AWTPANEL_RESTACK_MSG_2;
    }
    PDATA pData = JNI_GET_PDATA(self);
    if (pData == NULL) {
        env->DeleteGlobalRef(peers);
        env->DeleteLocalRef(self);
        return AWTPANEL_RESTACK_MSG_3;
    }

    AwtPanel* panel = (AwtPanel*)pData;

    HWND prevWindow = 0;

    for (int i = 1; i < peerCount; i++) {
        jobject peer = env->GetObjectArrayElement(peers, i);
        if (peer == NULL) {
            // Nonsense
            env->DeleteGlobalRef(peers);
            env->DeleteLocalRef(self);
            return  AWTPANEL_RESTACK_MSG_4;
        }
        PDATA child_pData = JNI_GET_PDATA(peer);
        if (child_pData == NULL) {
            env->DeleteLocalRef(peer);
            env->DeleteGlobalRef(peers);
            env->DeleteLocalRef(self);
            return AWTPANEL_RESTACK_MSG_3;
        }
        AwtComponent* child_comp = (AwtComponent*)child_pData;
        ::SetWindowPos(child_comp->GetHWnd(), prevWindow, 0, 0, 0, 0,
                       SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_DEFERERASE | SWP_ASYNCWINDOWPOS);
        prevWindow = child_comp->GetHWnd();
        env->DeleteLocalRef(peer);
    }
    env->DeleteGlobalRef(peers);
    env->DeleteLocalRef(self);

    CATCH_BAD_ALLOC_RET("Allocation error");
    return NULL;
}
JNIEXPORT jint JNICALL Java_sun_awt_windows_WRobotPeer_getRGBPixelImpl(
    JNIEnv * env, jobject self, jint x, jint y)
{
    TRY;

    return AwtRobot::GetRobot(self)->GetRGBPixel(x, y);

    CATCH_BAD_ALLOC_RET(0);
}
Beispiel #7
0
/*
 * Class:     sun_awt_windows_WInputMethodDescriptor
 * Method:    getNativeAvailableLocales
 * Signature: ()[Ljava/util/Locale;
 */
JNIEXPORT jobjectArray JNICALL Java_sun_awt_windows_WInputMethodDescriptor_getNativeAvailableLocales
  (JNIEnv *env, jclass self) 
{
    TRY;

    // get list of available HKLs
    int layoutCount = ::GetKeyboardLayoutList(0, NULL);
    HKL FAR * hKLList = (HKL FAR *)safe_Malloc(sizeof(HKL)*layoutCount);
    DASSERT(!safe_ExceptionOccurred(env));
    ::GetKeyboardLayoutList(layoutCount, hKLList);
    
    // get list of Java locale names while getting rid of duplicates
    int srcIndex = 0;
    int destIndex = 0;
    int javaLocaleNameCount = 0;
    int current = 0;
    const char ** javaLocaleNames = (const char **)safe_Malloc(sizeof(char *)*layoutCount);
    DASSERT(!safe_ExceptionOccurred(env));
    for (; srcIndex < layoutCount; srcIndex++) {
	const char * srcLocaleName = getJavaIDFromLangID(LOWORD(hKLList[srcIndex]));

	if (srcLocaleName == NULL) {
	    // could not find corresponding Java locale name for this HKL.
	    continue;
	}
	
	for (current = 0; current < destIndex; current++) {
	    if (strcmp(javaLocaleNames[current], srcLocaleName) == 0) {
	        // duplicated. ignore this HKL
		break;
	    }
	}

	if (current == destIndex) {
	    javaLocaleNameCount++;
	    destIndex++;
	    javaLocaleNames[current] = srcLocaleName;
	}
    }
	
    // convert it to an array of Java locale objects 
    jclass localeClass = env->FindClass("java/util/Locale");
    jobjectArray locales = env->NewObjectArray(javaLocaleNameCount, localeClass, NULL); 
    for (current = 0; current < javaLocaleNameCount; current++) {
        env->SetObjectArrayElement(locales, 
	                           current, 
				   CreateLocaleObject(env, javaLocaleNames[current]));
    }
    DASSERT(!safe_ExceptionOccurred(env));
    
    env->DeleteLocalRef(localeClass);
    free(hKLList);
    free(javaLocaleNames);
    return locales;

    CATCH_BAD_ALLOC_RET(NULL);
}
Beispiel #8
0
/*
 * Class:     sun_awt_KeyboardFocusManagerPeerImpl
 * Method:    getNativeFocusOwner
 * Signature: ()Ljava/awt/Component;
 */
JNIEXPORT jobject JNICALL
Java_sun_awt_KeyboardFocusManagerPeerImpl_getNativeFocusOwner
    (JNIEnv *env, jclass cls)
{
    TRY;

    return getNativeFocusState(env, AwtComponent::GetNativeFocusOwner);

    CATCH_BAD_ALLOC_RET(NULL);
}
Beispiel #9
0
/*
 * Class:     sun_awt_windows_WKeyboardFocusManagerPeer
 * Method:    getNativeFocusedWindow
 * Signature: ()Ljava/awt/Window;
 */
JNIEXPORT jobject JNICALL
Java_sun_awt_windows_WKeyboardFocusManagerPeer_getNativeFocusedWindow
    (JNIEnv *env, jclass cls)
{
    TRY;

    return getNativeFocusState(env, AwtComponent::GetNativeFocusedWindow);

    CATCH_BAD_ALLOC_RET(NULL);
}
Beispiel #10
0
/*
 * Class:     sun_awt_windows_WCustomCursor
 * Method:    getCursorHeight
 * Signature: ()I
 */
JNIEXPORT jint JNICALL
Java_sun_awt_windows_WCustomCursor_getCursorHeight(JNIEnv *, jclass)
{
    TRY;

    DTRACE_PRINTLN("WCustomCursor.getCursorHeight()");
    return (jint)::GetSystemMetrics(SM_CYCURSOR);

    CATCH_BAD_ALLOC_RET(0);
}
Beispiel #11
0
/*
 * Class:     sun_awt_windows_WInputMethod
 * Method:    createNativeContext
 * Signature: ()I
 */
JNIEXPORT jint JNICALL
Java_sun_awt_windows_WInputMethod_createNativeContext(JNIEnv *env, jobject self)
{
    TRY;

    // use special message to call ImmCreateContext() in main thread.
    return (jint)AwtToolkit::GetInstance().SendMessage(WM_AWT_CREATECONTEXT);

    CATCH_BAD_ALLOC_RET(0);
}
Beispiel #12
0
JNIEXPORT jobjectArray JNICALL
Java_sun_print_Win32PrintServiceLookup_getAllPrinterNames(JNIEnv *env,
                                                          jobject peer)
{
    TRY;

    DWORD cbNeeded = 0;
    DWORD cReturned = 0;
    LPBYTE pPrinterEnum = NULL;

    jstring utf_str;
    jclass clazz = env->FindClass("java/lang/String");
    if (clazz == NULL) {
        return NULL;
    }
    jobjectArray nameArray;

    try {
        ::EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS,
                       NULL, 4, NULL, 0, &cbNeeded, &cReturned);
        pPrinterEnum = new BYTE[cbNeeded];
        ::EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS,
                       NULL, 4, pPrinterEnum, cbNeeded, &cbNeeded,
                       &cReturned);

        if (cReturned > 0) {
            nameArray = env->NewObjectArray(cReturned, clazz, NULL);
            if (nameArray == NULL) {
                throw std::bad_alloc();
            }
        } else {
            nameArray = NULL;
        }


        for (DWORD i = 0; i < cReturned; i++) {
            PRINTER_INFO_4 *info4 = (PRINTER_INFO_4 *)
                (pPrinterEnum + i * sizeof(PRINTER_INFO_4));
            utf_str = JNU_NewStringPlatform(env, info4->pPrinterName);
            if (utf_str == NULL) {
                throw std::bad_alloc();
            }
            env->SetObjectArrayElement(nameArray, i, utf_str);
            env->DeleteLocalRef(utf_str);
        }
    } catch (std::bad_alloc&) {
        delete [] pPrinterEnum;
        throw;
    }

    delete [] pPrinterEnum;
    return nameArray;

    CATCH_BAD_ALLOC_RET(NULL);
}
/*
 * Class:     sun_awt_windows_WScrollPanePeer
 * Method:    _getVScrollbarWidth
 * Signature: ()I
 */
JNIEXPORT jint JNICALL
Java_sun_awt_windows_WScrollPanePeer__1getVScrollbarWidth(JNIEnv *env,
                                                          jobject self)
{
    TRY;

    DTRACE_PRINTLN1("%x: WScrollPanePeer._getVScrollbarHeight()", self);
    return ::GetSystemMetrics(SM_CXVSCROLL);

    CATCH_BAD_ALLOC_RET(0);
}
Beispiel #14
0
/*
 * Class:     sun_awt_windows_WInputMethod
 * Method:    getConversionStatus
 * Signature: (I)Z
 */
JNIEXPORT jboolean JNICALL
Java_sun_awt_windows_WInputMethod_getOpenStatus(JNIEnv *env, jobject self, jint context)
{
    TRY;

    // use special message to call ImmSetConversionStatus() in main thread.
    return (jboolean)(AwtToolkit::GetInstance().SendMessage(
						       WM_AWT_GETOPENSTATUS, 
						       context, 0));
    CATCH_BAD_ALLOC_RET(0);
}
Beispiel #15
0
BOOL CALLBACK PrintDlgHook(HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
    TRY;

    if (iMsg == WM_INITDIALOG) {
        SetForegroundWindow(hDlg);
        return FALSE;
    }
    return FALSE;

    CATCH_BAD_ALLOC_RET(TRUE);
}
Beispiel #16
0
/*
 * Class:     sun_awt_windows_WGlobalCursorManager
 * Method:    getLocationOnScreen
 * Signature: (L/java/awt/Component;)L/java/awt/Point
 */
JNIEXPORT jobject JNICALL
Java_sun_awt_windows_WGlobalCursorManager_getLocationOnScreen(
    JNIEnv *env, jobject, jobject component)
{
    TRY;

    JNI_CHECK_NULL_RETURN_NULL(component, "null component");
    jobject point =
        env->CallObjectMethod(component, AwtComponent::getLocationOnScreenMID);
    return point;

    CATCH_BAD_ALLOC_RET(NULL);
}
    /*
     * Class:     sun_awt_windows_WTextComponentPeer
     * Method:    getSelectionEnd
     * Signature: ()I
     */
    JNIEXPORT jint JNICALL
    Java_sun_awt_windows_WTextComponentPeer_getSelectionEnd(JNIEnv *env,
            jobject self)
    {
        TRY;

        return static_cast<jint>(reinterpret_cast<INT_PTR>(AwtToolkit::GetInstance().SyncCall(
                                     (void *(*)(void *))AwtTextComponent::_GetSelectionEnd,
                                     env->NewGlobalRef(self))));
        // global ref is deleted in _GetSelectionEnd()

        CATCH_BAD_ALLOC_RET(0);
    }
Beispiel #18
0
/*
 * Class:     sun_awt_windows_WColor
 * Method:    getDefaultColor
 * Signature: (I)Ljava/awt/Color;
 */
JNIEXPORT jobject JNICALL
Java_sun_awt_windows_WColor_getDefaultColor(JNIEnv *env, jclass cls,
					    jint index) 
{
    TRY;
  
    int iColor = 0;
    switch(index) {

    case sun_awt_windows_WColor_WINDOW_BKGND: 
        iColor = COLOR_WINDOW; 
        break;
    case sun_awt_windows_WColor_WINDOW_TEXT:
        iColor = COLOR_WINDOWTEXT; 
        break;
    case sun_awt_windows_WColor_FRAME:
        iColor = COLOR_WINDOWFRAME; 
        break;
    case sun_awt_windows_WColor_SCROLLBAR:
        iColor = COLOR_SCROLLBAR; 
        break;
    case sun_awt_windows_WColor_MENU_BKGND:
        iColor = COLOR_MENU; 
        break;
    case sun_awt_windows_WColor_MENU_TEXT:
        iColor = COLOR_MENUTEXT; 
        break;
    case sun_awt_windows_WColor_BUTTON_BKGND:
        iColor = (IS_NT) ? COLOR_BTNFACE : COLOR_3DFACE; 
        break;
    case sun_awt_windows_WColor_BUTTON_TEXT:
        iColor = COLOR_BTNTEXT; 
        break;
    case sun_awt_windows_WColor_HIGHLIGHT:
        iColor = COLOR_HIGHLIGHT; 
        break;

    default:
	return NULL;
    }
    DWORD c = ::GetSysColor(iColor);
   
    jobject wColor = JNU_NewObjectByName(env, "java/awt/Color", "(III)V",
					 GetRValue(c), GetGValue(c), 
					 GetBValue(c));

    DASSERT(!safe_ExceptionOccurred(env));
    return wColor;

    CATCH_BAD_ALLOC_RET(NULL);
}
Beispiel #19
0
static UINT_PTR CALLBACK
PrintDialogHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);

    TRY;

    switch(uiMsg) {
        case WM_INITDIALOG: {
            PRINTDLG *pd = (PRINTDLG *)lParam;
            jobject peer = (jobject)(pd->lCustData);
            env->CallVoidMethod(peer, AwtPrintDialog::setHWndMID,
                                (jlong)hdlg);
	    ::SetProp(hdlg, ModalDialogPeerProp, reinterpret_cast<HANDLE>(peer));

            // fix for 4632159 - disable CS_SAVEBITS
            DWORD style = ::GetClassLong(hdlg, GCL_STYLE); 
            ::SetClassLong(hdlg,GCL_STYLE, style & ~CS_SAVEBITS); 

            ::SetFocus(hdlg);

            // set appropriate icon for parentless dialogs
            jobject awtParent = env->GetObjectField(peer, AwtPrintDialog::parentID); 
            if (awtParent == NULL) {
                ::PostMessage(hdlg, WM_SETICON, (WPARAM)ICON_BIG,
                              (LPARAM)AwtToolkit::GetInstance().GetAwtIcon());
            } else {
                env->DeleteLocalRef(awtParent);
            }

            // subclass dialog's parent to receive additional messages
            WNDPROC lpfnWndProc = ComCtl32Util::GetInstance().SubclassHWND(hdlg, 
                                                     PrintDialogWndProc); 
            ::SetProp(hdlg, NativeDialogWndProcProp, reinterpret_cast<HANDLE>(lpfnWndProc));

            break;
        }
        case WM_DESTROY: {
            WNDPROC lpfnWndProc = (WNDPROC)(::GetProp(hdlg, NativeDialogWndProcProp));
            ComCtl32Util::GetInstance().UnsubclassHWND(hdlg, 
                                                       PrintDialogWndProc, 
                                                       lpfnWndProc); 
            ::RemoveProp(hdlg, ModalDialogPeerProp); 
            ::RemoveProp(hdlg, NativeDialogWndProcProp);
            break;
        }
    }
    return FALSE;

    CATCH_BAD_ALLOC_RET(TRUE);
}
JNIEXPORT jintArray JNICALL
Java_sun_print_Win32PrintService_getAllMediaSizes(JNIEnv *env,
                                                  jobject peer,
                                                  jstring printer,
                                                  jstring port)
{
  TRY;

  LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env,
                                                          printer, NULL);
  LPTSTR printerPort = (LPTSTR)JNU_GetStringPlatformChars(env, port, NULL);

  jintArray mediaArray = NULL;

  SAVE_CONTROLWORD
  int nPapers = ::DeviceCapabilities(printerName, printerPort,
                                      DC_PAPERSIZE,   NULL, NULL) ;
  RESTORE_CONTROLWORD
  if (nPapers > 0) {
    mediaArray = env->NewIntArray(nPapers*2);
    if (mediaArray == NULL) {
      throw std::bad_alloc();
    }

    jboolean isCopy;
    jint *jpcIndices = env->GetIntArrayElements(mediaArray,
                                          &isCopy), *saveFormats = jpcIndices;

    LPTSTR buf = (LPTSTR)new char[nPapers * sizeof(POINT)]; // array of POINTs

    if (::DeviceCapabilities(printerName, printerPort,
                             DC_PAPERSIZE, buf, NULL) != -1) {

      POINT *pDim = (POINT *)buf;
      for (int i = 0; i < nPapers; i++) {
        jpcIndices[i*2] = (pDim+i)->x;
        jpcIndices[i*2+1] = (pDim+i)->y;
      }
    }
    RESTORE_CONTROLWORD
    delete[] buf;
    env->ReleaseIntArrayElements(mediaArray, saveFormats, 0);
  }

  JNU_ReleaseStringPlatformChars(env, printer, printerName);
  JNU_ReleaseStringPlatformChars(env, port, printerPort);
  return mediaArray;

  CATCH_BAD_ALLOC_RET(NULL);
}
Beispiel #21
0
/*
 * Class:     sun_awt_windows_WListPeer
 * Method:    getMaxWidth
 * Signature: ()I
 */
JNIEXPORT jint JNICALL
Java_sun_awt_windows_WListPeer_getMaxWidth(JNIEnv *env, jobject self)
{
    TRY;

    jobject selfGlobalRef = env->NewGlobalRef(self);

    return (jint)AwtToolkit::GetInstance().SyncCall(
        (void *(*)(void *))AwtList::_GetMaxWidth,
        (void *)selfGlobalRef);
    // selfGlobalRef is deleted in _GetMaxWidth

    CATCH_BAD_ALLOC_RET(0);
}
Beispiel #22
0
JAWT_DrawingSurfaceInfo* JNICALL JAWTDrawingSurface::GetDSI
    (JAWT_DrawingSurface* ds)
{
    TRY;

    if (ds == NULL) {
        DTRACE_PRINTLN("Drawing Surface is NULL");
        return NULL;
    }
    JAWTDrawingSurface* pds = static_cast<JAWTDrawingSurface*>(ds);
    return &(pds->info);

    CATCH_BAD_ALLOC_RET(NULL);
}
JNIEXPORT jstring JNICALL
Java_sun_print_Win32PrintServiceLookup_getDefaultPrinterName(JNIEnv *env,
                                                             jobject peer)
{
    TRY;

    TCHAR cBuffer[250];
    OSVERSIONINFO osv;
    PRINTER_INFO_2 *ppi2 = NULL;
    DWORD dwNeeded = 0;
    DWORD dwReturned = 0;
    LPTSTR pPrinterName = NULL;
    jstring jPrinterName;

    // What version of Windows are you running?
    osv.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    GetVersionEx(&osv);

    // If Windows 2000, XP, Vista
    if (osv.dwPlatformId == VER_PLATFORM_WIN32_NT) {

       // Retrieve the default string from Win.ini (the registry).
       // String will be in form "printername,drivername,portname".

       if (GetProfileString(TEXT("windows"), TEXT("device"), TEXT(",,,"),
                            cBuffer, 250) <= 0) {
           return NULL;
       }
       // Copy printer name into passed-in buffer...
       int index = 0;
       int len = lstrlen(cBuffer);
       while ((index < len) && cBuffer[index] != _T(',')) {
              index++;
       }
       if (index==0) {
         return NULL;
       }

       pPrinterName = (LPTSTR)GlobalAlloc(GPTR, (index+1)*sizeof(TCHAR));
       lstrcpyn(pPrinterName, cBuffer, index+1);
       jPrinterName = JNU_NewStringPlatform(env, pPrinterName);
       GlobalFree(pPrinterName);
       return jPrinterName;
    } else {
        return NULL;
    }

    CATCH_BAD_ALLOC_RET(NULL);
}
/*
 * Class:     sun_awt_windows_WDataTransferer
 * Method:    registerClipboardFormat
 * Signature: (Ljava/lang/String;)J
 */
JNIEXPORT jlong JNICALL
Java_sun_awt_windows_WDataTransferer_registerClipboardFormat(JNIEnv *env,
                                                             jclass cls,
                                                             jstring str)
{
    TRY;

    LPCTSTR cStr = JNU_GetStringPlatformChars(env, str, NULL);
    jlong value = ::RegisterClipboardFormat(cStr);
    JNU_ReleaseStringPlatformChars(env, str, cStr);

    return value;

    CATCH_BAD_ALLOC_RET(0);
}
Beispiel #25
0
extern "C" JNIEXPORT JAWT_DrawingSurface* JNICALL DSGetDrawingSurface
    (JNIEnv* env, jobject target)
{
    TRY;

    // See if the target component is a java.awt.Component
    if (env->IsInstanceOf(target, jawtComponentClass)) {
        return new JAWTDrawingSurface(env, target);
    }

    DTRACE_PRINTLN("GetDrawingSurface target must be a Component");
    return NULL;

    CATCH_BAD_ALLOC_RET(NULL);
}
JNIEXPORT jintArray JNICALL
Java_sun_print_Win32PrintService_getAllMediaTrays(JNIEnv *env,
                                                  jobject peer,
                                                  jstring printer,
                                                  jstring port)
{
  TRY;

  LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env,
                                                          printer, NULL);
  LPTSTR printerPort = (LPTSTR)JNU_GetStringPlatformChars(env, port, NULL);

  jintArray mediaTrayArray = NULL;

  SAVE_CONTROLWORD
  int nBins = ::DeviceCapabilities(printerName, printerPort,
                                   DC_BINS,   NULL, NULL) ;
  RESTORE_CONTROLWORD
  if (nBins > 0) {
    mediaTrayArray = env->NewIntArray(nBins);
    if (mediaTrayArray == NULL) {
      throw std::bad_alloc();
    }

    jboolean isCopy;
    jint *jpcIndices = env->GetIntArrayElements(mediaTrayArray,
                                           &isCopy), *saveFormats = jpcIndices;

    LPTSTR buf = (LPTSTR)new char[nBins * sizeof(WORD)];

    if (::DeviceCapabilities(printerName, printerPort,
                             DC_BINS, buf, NULL) != -1) {
      RESTORE_CONTROLWORD
      WORD *pBins = (WORD *)buf;
      for (int i = 0; i < nBins; i++) {
        jpcIndices[i] = *(pBins+i);
      }
    }
    delete[] buf;
    env->ReleaseIntArrayElements(mediaTrayArray, saveFormats, 0);
  }

  JNU_ReleaseStringPlatformChars(env, printer, printerName);
  JNU_ReleaseStringPlatformChars(env, port, printerPort);
  return mediaTrayArray;

  CATCH_BAD_ALLOC_RET(NULL);
}
Beispiel #27
0
/*
 * Class:     sun_awt_windows_WListPeer
 * Method:    isSelected
 * Signature: (I)Z
 */
JNIEXPORT jboolean JNICALL
Java_sun_awt_windows_WListPeer_isSelected(JNIEnv *env, jobject self,
                                          jint index)
{
    TRY;

    SelectElementStruct *ses = new SelectElementStruct;
    ses->list = env->NewGlobalRef(self);
    ses->index = index;

    return (jboolean)AwtToolkit::GetInstance().SyncCall(
        (void *(*)(void *))AwtList::_IsSelected, ses);
    // global ref and ses are deleted in _IsSelected

    CATCH_BAD_ALLOC_RET(FALSE);
}
/*
 * Class:     sun_awt_windows_WScrollPanePeer
 * Method:    getOffset
 * Signature: (I)I
 */
JNIEXPORT jint JNICALL
Java_sun_awt_windows_WScrollPanePeer_getOffset(JNIEnv *env, jobject self,
                                               jint orient)
{
    TRY;

    GetOffsetStruct *gos = new GetOffsetStruct;
    gos->scrollpane = env->NewGlobalRef(self);
    gos->orient = orient;

    return static_cast<jint>(reinterpret_cast<INT_PTR>(AwtToolkit::GetInstance().SyncCall(
        (void *(*)(void *))AwtScrollPane::_GetOffset, gos)));
    // global ref and gos are deleted in _GetOffset()

    CATCH_BAD_ALLOC_RET(0);
}
Beispiel #29
0
/*
 * Class:     sun_awt_windows_WInputMethod
 * Method:    setNativeLocale
 * Signature: (Ljava/lang/String;Z)Z
 */
JNIEXPORT jboolean JNICALL Java_sun_awt_windows_WInputMethod_setNativeLocale
  (JNIEnv *env, jclass cls, jstring localeString, jboolean onActivate)
{
    TRY;

    // check if current language ID is the requested one.  Note that the
    // current language ID (returned from 'getJavaIDFromLangID') is in 
    // ASCII encoding, so we use 'GetStringUTFChars' to retrieve requested 
    // language ID from the 'localeString' object.
    const char * current = getJavaIDFromLangID(AwtComponent::GetInputLanguage());
    jboolean isCopy;
    const char * requested = env->GetStringUTFChars(localeString, &isCopy);
    if ((current != NULL) && (strcmp(current, requested) == 0)) {
	env->ReleaseStringUTFChars(localeString, requested);
	return JNI_TRUE;
    }
    
    // get list of available HKLs.  Adding the user's preferred layout on top of the layout
    // list which is returned by GetKeyboardLayoutList ensures to match first when 
    // looking up suitable layout.
    int layoutCount = ::GetKeyboardLayoutList(0, NULL) + 1;  // +1 for user's preferred HKL
    HKL FAR * hKLList = (HKL FAR *)safe_Malloc(sizeof(HKL)*layoutCount);
    DASSERT(!safe_ExceptionOccurred(env));
    ::GetKeyboardLayoutList(layoutCount - 1, &(hKLList[1]));
    hKLList[0] = getDefaultKeyboardLayout(); // put user's preferred layout on top of the list
    
    // lookup matching LangID 
    jboolean retValue = JNI_FALSE;
    for (int i = 0; i < layoutCount; i++) {
        const char * supported = getJavaIDFromLangID(LOWORD(hKLList[i]));
	if ((supported != NULL) && (strcmp(supported, requested) == 0)) {
	    // use special message to call ActivateKeyboardLayout() in main thread.
            if (AwtToolkit::GetInstance().SendMessage(WM_AWT_ACTIVATEKEYBOARDLAYOUT, (WPARAM)onActivate, (LPARAM)hKLList[i])) {
                //also need to change the same keyboard layout for the Java AWT-EventQueue thread
                AwtToolkit::activateKeyboardLayout(hKLList[i]);
	        retValue = JNI_TRUE;
	    }
	    break;
	}
    }

    env->ReleaseStringUTFChars(localeString, requested);
    free(hKLList);
    return retValue;
	
    CATCH_BAD_ALLOC_RET(JNI_FALSE);
}
/*
 * Class:     sun_awt_windows_WScrollPanePeer
 * Method:    getOffset
 * Signature: (I)I
 */
JNIEXPORT jint JNICALL 
Java_sun_awt_windows_WScrollPanePeer_getOffset(JNIEnv *env, jobject self,
					       jint orient)
{
    TRY;

    DTRACE_PRINTLN2("%x: WScrollPanePeer.getOffset(%d)", self, orient);

    PDATA pData;
    JNI_CHECK_PEER_RETURN_NULL(self);
    AwtScrollPane* pane = (AwtScrollPane *)pData;
    pane->VerifyState();
    int nBar = (orient == java_awt_Adjustable_HORIZONTAL) ? SB_HORZ : SB_VERT;
    return pane->GetScrollPos(nBar);

    CATCH_BAD_ALLOC_RET(0);
}