/*
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
 */
#include "common.h"

#include "CommonDialogs_COM.h"
#include "CommonDialogs_Standard.h"

/*
 * JNI methods section
 *
 */

extern "C" {

/*
 * Class:     com_sun_glass_ui_win_WinCommonDialogs
 * Method:    _initIDs
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_com_sun_glass_ui_win_WinCommonDialogs__1initIDs
    (JNIEnv *env, jclass cls)
{
    cls = env->FindClass("com/sun/glass/ui/CommonDialogs$ExtensionFilter");
    ASSERT(cls);

    javaIDs.CommonDialogs.ExtensionFilter.getDescription = env->GetMethodID(cls,
                                         "getDescription", "()Ljava/lang/String;");
    ASSERT(javaIDs.CommonDialogs.ExtensionFilter.getDescription);

    javaIDs.CommonDialogs.ExtensionFilter.extensionsToArray = env->GetMethodID(cls,
                                         "extensionsToArray", "()[Ljava/lang/String;");
    ASSERT(javaIDs.CommonDialogs.ExtensionFilter.extensionsToArray);
}

/*
 * Class:     com_sun_glass_ui_win_WinCommonDialogs
 * Method:    _showFileChooser
 * Signature: (JLjava/lang/String;Ljava/lang/String;IZ[Lcom/sun/glass/ui/CommonDialogs$ExtensionFilter;)[Ljava/lang/String;
 */
JNIEXPORT jobjectArray JNICALL Java_com_sun_glass_ui_win_WinCommonDialogs__1showFileChooser
  (JNIEnv *env, jobject jThis, jlong owner, jstring jFolder, jstring jTitle, jint type,
        jboolean multipleMode, jobjectArray jFilters)
{
    JString folder(env, jFolder);
    JString title(env, jTitle);

    if (IS_WINVISTA) {
        return COMFileChooser_Show((HWND)jlong_to_ptr(owner), folder, title, type, multipleMode, jFilters);
    } else {
        return StandardFileChooser_Show((HWND)jlong_to_ptr(owner), folder, title, type, multipleMode, jFilters);
    }
}

/*
 * Class:     com_sun_glass_ui_win_WinCommonDialogs
 * Method:    _showFolderChooser
 * Signature: (JLjava/lang/String;Ljava/lang/String;)Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_com_sun_glass_ui_win_WinCommonDialogs__1showFolderChooser
  (JNIEnv *env, jclass cls, jlong owner, jstring jFolder, jstring jTitle)
{
    JString folder(env, jFolder);
    JString title(env, jTitle);

    if (IS_WINVISTA) {
        return COMFolderChooser_Show((HWND)jlong_to_ptr(owner), folder, title);
    } else {
        return StandardFolderChooser_Show((HWND)jlong_to_ptr(owner), folder, title);
    }
}

}   // extern "C"
