/**
 * Reports a fatal error that cannot be handled in Java.
 * Must be called from a KNI method
 *
 */
void handleFatalError(void) {
    KNI_StartHandles(1);
    KNI_DeclareHandle(throwableObj);
    KNI_GetParameterAsObject(1, throwableObj);

    /* IMPL NOTE: Figure out what throwable class this is and log the error? */
    REPORT_CRIT1(LC_CORE, "handleFatalError: uncaught exception in "
        "isolate %d event processing thread", getCurrentIsolateId());
    
    KNI_EndHandles();

    if (getCurrentIsolateId() == midpGetAmsIsolateId()) {
        /* AMS isolate or SVM mode, terminate VM */
        midp_exitVM(-1);
    } else {
        MidpEvent event;

        /* Application isolate, notify the AMS isolate. */
        MIDP_EVENT_INITIALIZE(event);
        event.type = FATAL_ERROR_NOTIFICATION;
        event.intParam1 = getCurrentIsolateId();

        /* Send the shutdown event. */
        StoreMIDPEventInVmThread(event, midpGetAmsIsolateId());
    }

    KNI_ReturnVoid();
}
/** Reset the MIDlet proxy list for the next run of the VM. */
void midpMIDletProxyListReset() {
#if ENABLE_MULTIPLE_DISPLAYS
    int sizeInBytes = maxDisplays * sizeof(int);
    gForegroundDisplayIds = midpMalloc(sizeInBytes);
    memset(gForegroundDisplayIds, 0, sizeInBytes);
#else
    gForegroundDisplayId = -1;
#endif // ENABLE_MULTIPLE_DISPLAYS   
    gForegroundIsolateId = midpGetAmsIsolateId();
}
KNIEXPORT KNI_RETURNTYPE_VOID
KNIDECL(com_sun_midp_chameleon_skins_resources_LoadedSkinData_finalize) {
#if ENABLE_MULTIPLE_ISOLATES
    if ((JVM_CurrentIsolateID() == midpGetAmsIsolateId()) &&
        (skinProperties >= 0)) {
        SNI_DeleteReference(skinProperties);
        skinProperties = -1;
    }
#endif
    KNI_ReturnVoid();
}
/**
 * Get the current isolate id from VM in case of MVM mode. 
 * For SVM, simply return 0 as an isolate ID.
 *
 * @return isolated : Isolate ID
 * 
 */
int getCurrentIsolateId() {
    int amsIsolateId = midpGetAmsIsolateId();
    /*
     * midpGetAmsIsolateId() returns 0 when VM is not running at all. It 
     * also returns 0 when VM is running but it is in SVM mode. 
     *
     * When VM is running in MVM mode, midpGetAmsIsolateId() returns 
     * isolateID of an AMS isolate
     */
#if ENABLE_MULTIPLE_ISOLATES
    return ((amsIsolateId == 0)? 0:JVM_CurrentIsolateId());
#else
    return amsIsolateId;
#endif /* ENABLE_MULTIPLE_ISOLATES */
}
KNIEXPORT KNI_RETURNTYPE_BOOLEAN
KNIDECL(com_sun_midp_chameleon_skins_resources_SkinResourcesImpl_ifLoadAllResources0) {
    
#if ENABLE_MULTIPLE_ISOLATES
    /* 
     * There is no need to load all images for non AMS 
     * isolates, they are to be loaded later on demand
     */
    if (JVM_CurrentIsolateID() == midpGetAmsIsolateId()) {
        KNI_ReturnBoolean(KNI_TRUE);
    } else {
        KNI_ReturnBoolean(KNI_FALSE);
    }
#else
    KNI_ReturnBoolean(KNI_FALSE);
#endif

}
Exemple #6
0
/**
 * Handles window messages sent to the main window.
 */
LRESULT CALLBACK winceapp_wndproc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
    PAINTSTRUCT ps;
    HDC hdc;
    int cmd;
    DWORD err;
    static int ignoreCancelMode = 0;

    switch (msg) {
    case WM_CREATE:
        {
            SHMENUBARINFO mbi;

            /* Create the menu bar with two simple soft buttons */
            ZeroMemory(&mbi, sizeof(SHMENUBARINFO));
            mbi.cbSize = sizeof(SHMENUBARINFO);
            mbi.hwndParent = hwnd;
            mbi.nToolBarId = ID_MENU_SIMPLE;
            mbi.hInstRes = instanceMain;

            if (SHCreateMenuBar(&mbi) == FALSE) {
                /* Couldn't create the menu bar.  Fail creation of the window. */
                return -1;
            } else {
                hwndMenuBarSimple = mbi.hwndMB;

                /* In order to make the Back button work properly,
                 * it's necessary to override it and then call the
                 * appropriate SH API
                 */
                SendMessage(mbi.hwndMB, SHCMBM_OVERRIDEKEY, VK_TBACK,
                            MAKELPARAM(SHMBOF_NODEFAULT | SHMBOF_NOTIFY,
                                       SHMBOF_NODEFAULT | SHMBOF_NOTIFY));
            }

            /* Create the menu bar with a popup menu. This is used if
             * the current MIDP screen has more than 2 Commands.
             */
            ZeroMemory(&mbi, sizeof(SHMENUBARINFO));
            mbi.cbSize = sizeof(SHMENUBARINFO);
            mbi.hwndParent = hwnd;
            mbi.nToolBarId = ID_MENU_POPUP;
            mbi.hInstRes = instanceMain;

            if (SHCreateMenuBar(&mbi) == FALSE) {
                /* Couldn't create the menu bar.  Fail creation of the window. */
                return -1;
            } else {
              hwndMenuBarPopup = mbi.hwndMB;

                /* Get a handle to the popup menu, which will host the
                 * Commands of the current MIDP screen.
                 */
                TBBUTTONINFO tbbi = {0};
                tbbi.cbSize = sizeof(tbbi);
                tbbi.dwMask = TBIF_LPARAM;


                if (!SendMessage(hwndMenuBarPopup, TB_GETBUTTONINFO, IDM_SOFTBTN_0, (LPARAM)&tbbi)) {
                  err = GetLastError();
                }

                hmenuPopup = (HMENU)tbbi.lParam;

                /* In order to make the Back button work properly,
                 * it's necessary to override it and then call the
                 * appropriate SH API
                 */
                SendMessage(mbi.hwndMB, SHCMBM_OVERRIDEKEY, VK_TBACK,
                            MAKELPARAM(SHMBOF_NODEFAULT | SHMBOF_NOTIFY,
                                       SHMBOF_NODEFAULT | SHMBOF_NOTIFY));
            }

            hwndMenuBar = hwndMenuBarSimple;
            ShowWindow(hwndMenuBarSimple, SW_SHOW);
            ShowWindow(hwndMenuBarPopup, SW_HIDE);
        }
        return 0;

    case WM_HOTKEY:
        /* If back key is overriden, back button messages are sent in
         * a WM_HOTKEY to the menu bar with the id VK_TBACK in the
         * LPARAM.
         */
        if (HIWORD(lp) == VK_TBACK && (LOWORD(lp) & MOD_KEYUP)) {
            if (editBoxShown) {
                SendMessage(hwndTextActive, WM_CHAR, VK_BACK, 0);
            } else {
#if ENABLE_MULTIPLE_ISOLATES
                if (gForegroundIsolateId == midpGetAmsIsolateId()) {
                    SHNavigateBack();
                } else {
                    pMidpEventResult->type = SELECT_FOREGROUND_EVENT;
                    pSignalResult->waitingFor = AMS_SIGNAL;
                }
#else
                SHNavigateBack();
#endif
            }
        }
        return 1;

    case WM_SETTINGCHANGE: {
        updateVisibleDesktop();
        updateEditorForRotation();
        lastWmSettingChangeTick = GetTickCount();
        /* Handle Virtual Keyboard change */
        RECT virtualKeyboardRect = {0, 0};
        HWND hWndInputPanel = FindWindow(TEXT("SipWndClass"), NULL);
        if (hWndInputPanel != NULL) {
            if (IsWindowVisible(hWndInputPanel)) {
                GetWindowRect(hWndInputPanel, &virtualKeyboardRect);
            }
        }
        virtualKeyboardHeight = virtualKeyboardRect.bottom - virtualKeyboardRect.top;
    }
        return DefWindowProc(hwnd, msg, wp, lp);

    case WM_TIMER:
        if (wp == EVENT_TIMER_ID+1) {
            KillTimer(hwndMain, EVENT_TIMER_ID+1);
            process_skipped_refresh();
        }
        return 0;

    case WM_COMMAND:
        switch ((cmd = GET_WM_COMMAND_ID(wp, lp))) {
        case IDOK:
#if ENABLE_MULTIPLE_ISOLATES
            /* On PocketPC devices that don't have a lot of hardware
             * buttons, this is a good way for implementing
             * the 'task switch' event - click on the OK button on
             * the window title
             */
            if (gForegroundIsolateId == midpGetAmsIsolateId()) {
                SetForegroundWindow(GetDesktopWindow());
                /* SHNavigateBack(); */
            } else {
                pMidpEventResult->type = SELECT_FOREGROUND_EVENT;
                pSignalResult->waitingFor = AMS_SIGNAL;
            }
#else
            /* IMPL_NOTE: we ask the user if the current Midlet should be
             * terminated.
             */
            SendMessage(hwnd, WM_CLOSE, 0, 0);
#endif
            /* for some reason windows has already sent us a CANCELMODE message
             * before we come to here. Let's re-enable painting.
             */
            if (!midpPaintAllowed) {
                enablePaint();
            }
            return 0;
        case IDM_SOFTBTN_0:
        case IDM_SOFTBTN_1:
            pMidpEventResult->type = MIDP_KEY_EVENT;
            pMidpEventResult->CHR = (cmd==IDM_SOFTBTN_0) ? 
                KEYMAP_KEY_SOFT1:KEYMAP_KEY_SOFT2;
            pMidpEventResult->ACTION = KEYMAP_STATE_RELEASED;
            pSignalResult->waitingFor = UI_SIGNAL;             
            pMidpEventResult->DISPLAY = gForegroundDisplayId;
            sendMidpKeyEvent(pMidpEventResult, sizeof(*pMidpEventResult));

            /* for some reason windows will send us a CANCELMODE message
             * afterwards
             */
            ignoreCancelMode ++;
            return 0;
        default:
            /* IMPL_NOTE The events from the menu are not transfer up to 
             *  java without displaying and addition menu.  
             * Only a MIDP_COMMAND_EVENT should be used.  Disabling this feature for now.
             */
            if (cmd >= ID_DYNAMIC_MENU) {
                pMidpEventResult->type = MIDP_KEY_EVENT;
                pMidpEventResult->CHR = ((cmd - ID_DYNAMIC_MENU)==IDM_SOFTBTN_0)
                                           ? KEYMAP_KEY_SOFT1:KEYMAP_KEY_SOFT2;
                pMidpEventResult->ACTION = KEYMAP_STATE_RELEASED;
                pSignalResult->waitingFor = UI_SIGNAL;
                pMidpEventResult->DISPLAY = gForegroundDisplayId;
                sendMidpKeyEvent(pMidpEventResult, sizeof(*pMidpEventResult));
                /* This command comes from a menu item dynamically
                 * created in the native method
                 */
                /* Disabled
                 SoftButtonLayer.setNativePopupMenu()
                 pMidpEventResult->type = MIDP_COMMAND_EVENT;
                 pMidpEventResult->COMMAND = (cmd - ID_DYNAMIC_MENU);
                 pSignalResult->waitingFor = UI_SIGNAL;
                 pMidpEventResult->DISPLAY = gForegroundDisplayId;
                 sendMidpKeyEvent(pMidpEventResult, sizeof(*pMidpEventResult));
                */  
                /* for some reason windows will send us a CANCELMODE message
                 * afterwards
                 */
                ignoreCancelMode ++;
                return 0;
            } else {
                return DefWindowProc(hwnd, msg, wp, lp);
            }
        }
        break;

    case WM_ACTIVATE:
        if (LOWORD(wp)) { /* active */
            enablePaint();
            if (editBoxShown) {
                SetFocus(hwndTextActive);
            }
        } else { /* inactive */
#if ENABLE_MULTIPLE_ISOLATES
            pMidpEventResult->type = SELECT_FOREGROUND_EVENT;
            pSignalResult->waitingFor = AMS_SIGNAL;
#endif
            disablePaint();
        }
        return DefWindowProc(hwnd, msg, wp, lp);

    case WM_EXITMENULOOP:
        enablePaint();
        return DefWindowProc(hwnd, msg, wp, lp);

    case WM_CANCELMODE:
        if (!ignoreCancelMode) {
            disablePaint();
        } else {
            ignoreCancelMode --;
        }
        /* We have to do this, or else windows is unhappy. */
        return DefWindowProc(hwnd, msg, wp, lp);

    case WM_PAINT:
        hdc = BeginPaint(hwnd, &ps);
        EndPaint(hwnd, &ps);
        enablePaint();
        if (editBoxShown) {
            SetFocus(hwndTextActive);
        }
        return 0;

    case WM_CLOSE:
        return DefWindowProc(hwnd, msg, wp, lp);

    case WM_DESTROY:
        PostQuitMessage(0);
        exit(0);
        return 0;

    case WM_MOUSEMOVE:
    case WM_LBUTTONDOWN:
    case WM_LBUTTONUP:
        {
            lastUserInputTick = GetTickCount();

            POINT pen_position ={LOWORD(lp), HIWORD(lp)};
            if (msg == WM_MOUSEMOVE) {
                pMidpEventResult->ACTION = KEYMAP_STATE_DRAGGED;
            } else if (msg == WM_LBUTTONUP) {
                pMidpEventResult->ACTION = KEYMAP_STATE_RELEASED;
            } else {
                pMidpEventResult->ACTION = KEYMAP_STATE_PRESSED;
            }
            pMidpEventResult->type = MIDP_PEN_EVENT;
            pMidpEventResult->X_POS = pen_position.x;
            pMidpEventResult->Y_POS = pen_position.y;

            pSignalResult->waitingFor = UI_SIGNAL;
            pMidpEventResult->DISPLAY = gForegroundDisplayId;
            sendMidpKeyEvent(pMidpEventResult, sizeof(*pMidpEventResult));
        }
        return 0;

    case WM_KEYDOWN: /* fall through */
    case WM_KEYUP:
        return process_key(hwnd, msg, wp, lp);
    default:
        return DefWindowProc(hwnd, msg, wp, lp);
    }
    return DefWindowProc(hwnd, msg, wp, lp);
}