1 /*
   2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include "jni_util.h"
  27 #include "awt.h"
  28 #include <jni.h>
  29 #include "awt_Taskbar.h"
  30 #include "java_awt_Taskbar.h"
  31 #include "awt_Window.h"
  32 
  33 
  34 #ifdef __cplusplus
  35 extern "C" {
  36 #endif
  37 
  38 /*
  39  * Class:     sun_awt_windows_WTaskbarPeer
  40  * Method:    nativeInit
  41  * Signature: ()Z
  42  */
  43 JNIEXPORT jboolean JNICALL Java_sun_awt_windows_WTaskbarPeer_nativeInit
  44   (JNIEnv *env, jclass)
  45 {
  46     if (SUCCEEDED(::CoInitialize(NULL)) 
  47             && SUCCEEDED(::CoCreateInstance(CLSID_TaskbarList, NULL,
  48             CLSCTX_INPROC_SERVER, IID_ITaskbarList, (LPVOID *)&m_Taskbar))) {
  49         return JNI_TRUE;
  50     } else {
  51         return JNI_FALSE;
  52     }
  53 }
  54     
  55 /*
  56  * Class:     sun_awt_windows_WTaskbarPeer
  57  * Method:    setProgressValue
  58  * Signature: (JI)V
  59  */
  60 JNIEXPORT void JNICALL Java_sun_awt_windows_WTaskbarPeer_setProgressValue
  61   (JNIEnv *, jobject, jlong window, jint value)
  62 {
  63     m_Taskbar->SetProgressValue((HWND)window, value, 100); 
  64 }
  65 
  66 /*
  67  * Class:     sun_awt_windows_WTaskbarPeer
  68  * Method:    setProgressState
  69  * Signature: (JI)V
  70  */
  71 JNIEXPORT void JNICALL Java_sun_awt_windows_WTaskbarPeer_setProgressState
  72   (JNIEnv *, jobject, jlong window, jint state)
  73 {
  74     TBPFLAG flag;
  75     switch (state) {
  76         case java_awt_Taskbar_STATE_OFF: flag = TBPF_NOPROGRESS; break;
  77         case java_awt_Taskbar_STATE_NORMAL: flag = TBPF_NORMAL; break;
  78         case java_awt_Taskbar_STATE_PAUSED: flag = TBPF_PAUSED; break;
  79         case java_awt_Taskbar_STATE_INDETERMINATE: flag = TBPF_INDETERMINATE; break;
  80         case java_awt_Taskbar_STATE_ERROR: flag = TBPF_ERROR; break;
  81     }
  82     m_Taskbar->SetProgressState((HWND)window, flag); 
  83     
  84 }
  85 
  86 /*
  87  * Class:     sun_awt_windows_WTaskbarPeer
  88  * Method:    flashWindow
  89  * Signature: (JZ)V
  90  */
  91 JNIEXPORT void JNICALL Java_sun_awt_windows_WTaskbarPeer_flashWindow
  92   (JNIEnv *, jobject, jlong window)
  93 {
  94     AwtWindow::FlashWindowEx((HWND) window, 3, 0, FLASHW_TIMERNOFG);
  95 }
  96 
  97 /*
  98  * Class:     sun_awt_windows_WTaskbarPeer
  99  * Method:    setOverlayIcon
 100  * Signature: (J[III)V
 101  */
 102 JNIEXPORT void JNICALL Java_sun_awt_windows_WTaskbarPeer_setOverlayIcon
 103   (JNIEnv *env, jobject, jlong window, jintArray buf, jint w, jint h)
 104 {
 105     HICON icon = CreateIconFromRaster(env, buf, w, h);
 106     m_Taskbar->SetOverlayIcon((HWND)window, icon, NULL);
 107     ::DestroyIcon(icon);
 108 }
 109 #ifdef __cplusplus
 110 }
 111 #endif