예제 #1
0
void AwtCheckbox::_SetLabel(void *param)
{
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);

    SetLabelStruct *sls = (SetLabelStruct *)param;
    jobject checkbox = sls->checkbox;
    jstring label = sls->label;

    int badAlloc = 0;
    AwtCheckbox *c = NULL;

    PDATA pData;
    JNI_CHECK_PEER_GOTO(checkbox, done);

    c = (AwtCheckbox *)pData;
    if (::IsWindow(c->GetHWnd()))
    {
        LPCTSTR labelStr = NULL;

        // By convension null label means empty string
        if (label == NULL)
        {
            labelStr = TEXT("");
        }
        else
        {
            labelStr = JNU_GetStringPlatformChars(env, label, JNI_FALSE);
        }

        if (labelStr == NULL)
        {
            badAlloc = 1;
        }
        else
        {
            c->SetText(labelStr);
            c->VerifyState();
            if (label != NULL) {
                JNU_ReleaseStringPlatformChars(env, label, labelStr);
            }
        }
    }

done:
    env->DeleteGlobalRef(checkbox);
    if (label != NULL)
    {
        env->DeleteGlobalRef(label);
    }

    delete sls;

    if (badAlloc) {
        throw std::bad_alloc();
    }
}
// Create a new AwtCheckbox object and window.  
AwtCheckbox* AwtCheckbox::Create(jobject self,
                                 jobject hParent)
{
    JNIEnv* env; 
    /* associate JNIEnv with the current thread */
    if (JVM -> AttachCurrentThread((void**) &env, 0) != 0) {
       return NULL;
    }

    CHECK_NULL_RETURN(hParent, "null hParent");
    AwtCanvas* parent = (AwtCanvas*) env->GetIntField(hParent, 
                  WCachedIDs.PPCObjectPeer_pDataFID); 
    CHECK_NULL_RETURN(parent, "null parent");

    jobject target = 
       env -> GetObjectField(self, WCachedIDs.PPCObjectPeer_targetFID);
    CHECK_NULL_RETURN(target, "null target");

    AwtCheckbox* checkbox = new AwtCheckbox();
    CHECK_NULL_RETURN(checkbox, "AwtCheckbox() failed");

    DWORD style = WS_CHILD | WS_CLIPSIBLINGS | BS_OWNERDRAW;

    jstring label = (jstring)env->CallObjectMethod(target,
                                  WCachedIDs.java_awt_Checkbox_getLabelMID); 

    TCHAR *sb;
    if (label == NULL) {
       sb = TEXT("");
    } else {
       JavaStringBuffer sb(env, label);
    }

    checkbox->CreateHWnd(sb, style, 0,
                  (int)env->CallIntMethod(target, 
                            WCachedIDs.java_awt_Component_getXMID),
                  (int)env->CallIntMethod(target,
                            WCachedIDs.java_awt_Component_getYMID),
                  (int)env->CallIntMethod(target,
                            WCachedIDs.java_awt_Component_getWidthMID),
                  (int)env->CallIntMethod(target, 
                            WCachedIDs.java_awt_Component_getHeightMID),
                  parent->GetHWnd(),
                  (HMENU)parent->CreateControlID(),
                  ::GetSysColor(COLOR_WINDOWTEXT),
                  ::GetSysColor(COLOR_BTNFACE),
                  self
                  );

    return checkbox;
}
예제 #3
0
void AwtCheckbox::_SetState(void *param)
{
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);

    SetStateStruct *sss = (SetStateStruct *)param;
    jobject checkbox = sss->checkbox;
    jboolean state = sss->state;

    AwtCheckbox *c = NULL;

    PDATA pData;
    JNI_CHECK_PEER_GOTO(checkbox, done);

    c = (AwtCheckbox *)pData;
    if (::IsWindow(c->GetHWnd()))
    {
        /*
         * when multifont and group checkbox receive setState native
         * method, it must be redraw to display correct check mark
         */
        jobject target = env->GetObjectField(checkbox, AwtObject::targetID);
        jobject group = env->GetObjectField(target, AwtCheckbox::groupID);
        HWND hWnd = c->GetHWnd();
        if (group != NULL) {
            RECT rect;
            VERIFY(::GetWindowRect(hWnd, &rect));
            VERIFY(::ScreenToClient(hWnd, (LPPOINT)&rect));
            VERIFY(::ScreenToClient(hWnd, ((LPPOINT)&rect) + 1));
            VERIFY(::InvalidateRect(hWnd, &rect,TRUE));
            VERIFY(::UpdateWindow(hWnd));
        } else {
            c->SendMessage(BM_SETCHECK, (WPARAM)(state ? BST_CHECKED : BST_UNCHECKED));
            VERIFY(::InvalidateRect(hWnd, NULL, FALSE));
        }
        c->VerifyState();
        env->DeleteLocalRef(target);
        env->DeleteLocalRef(group);
    }

done:
    env->DeleteGlobalRef(checkbox);

    delete sss;
}
예제 #4
0
void AwtCheckbox::_SetCheckboxGroup(void *param)
{
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);

    jobject *jos = (jobject *)param;
    jobject checkbox = jos[0];
    jobject group = jos[1];

    AwtCheckbox *c = NULL;

    PDATA pData;
    JNI_CHECK_PEER_GOTO(checkbox, done);

    c = (AwtCheckbox *)pData;
    if (::IsWindow(c->GetHWnd()))
    {
/*
#ifdef DEBUG
        if (group != NULL) {
            DASSERT(IsInstanceOf((HObject*)group, "java/awt/CheckboxGroup"));
        }
#endif
*/
        long style = c->GetStyle();
        if (group == NULL) {
            style = style & ~BS_AUTORADIOBUTTON;
            style = style | BS_AUTOCHECKBOX;
        } else {
            style = style & ~BS_AUTOCHECKBOX;
            style = style | BS_AUTORADIOBUTTON;
        }
        c->SetStyle(style);
        c->SendMessage(BM_SETSTYLE, (WPARAM)BS_OWNERDRAW, (LPARAM)TRUE);
        c->VerifyState();
    }

done:
    env->DeleteGlobalRef(checkbox);
    if (group != NULL) {
      env->DeleteGlobalRef(group);
    }

    delete[] jos;
}
예제 #5
0
AwtCheckbox* AwtCheckbox::Create(jobject peer, jobject parent)
{
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);

    jstring label = NULL;
    jobject target = NULL;
    AwtCheckbox *checkbox = NULL;

    try {
        if (env->EnsureLocalCapacity(2) < 0) {
            return NULL;
        }

        AwtComponent* awtParent;
        JNI_CHECK_NULL_GOTO(parent, "null parent", done);

        awtParent = (AwtComponent*)JNI_GET_PDATA(parent);
        JNI_CHECK_NULL_GOTO(awtParent, "null awtParent", done);

        target = env->GetObjectField(peer, AwtObject::targetID);
        JNI_CHECK_NULL_GOTO(target, "null target", done);

        checkbox = new AwtCheckbox();

        {
            DWORD style = WS_CHILD | WS_CLIPSIBLINGS | BS_OWNERDRAW;
            LPCWSTR defaultLabelStr = L"";
            LPCWSTR labelStr = defaultLabelStr;
            DWORD exStyle = 0;

            if (GetRTL()) {
                exStyle |= WS_EX_RIGHT;
                if (GetRTLReadingOrder())
                    exStyle |= WS_EX_RTLREADING;
            }

            label = (jstring)env->GetObjectField(target, AwtCheckbox::labelID);
            if (label != NULL) {
                labelStr = JNU_GetStringPlatformChars(env, label, 0);
            }
            if (labelStr != 0) {
                jint x = env->GetIntField(target, AwtComponent::xID);
                jint y = env->GetIntField(target, AwtComponent::yID);
                jint width = env->GetIntField(target, AwtComponent::widthID);
                jint height = env->GetIntField(target, AwtComponent::heightID);
                checkbox->CreateHWnd(env, labelStr, style, exStyle,
                                     x, y, width, height,
                                     awtParent->GetHWnd(),
                                     reinterpret_cast<HMENU>(static_cast<INT_PTR>(
                         awtParent->CreateControlID())),
                                     ::GetSysColor(COLOR_WINDOWTEXT),
                                     ::GetSysColor(COLOR_BTNFACE),
                                     peer);

                if (labelStr != defaultLabelStr) {
                    JNU_ReleaseStringPlatformChars(env, label, labelStr);
                }
            } else {
                throw std::bad_alloc();
            }
        }
    } catch (...) {
        env->DeleteLocalRef(label);
        env->DeleteLocalRef(target);
        throw;
    }

done:
    env->DeleteLocalRef(label);
    env->DeleteLocalRef(target);

    return checkbox;
}