// Create a new AwtChoice object and window.
AwtChoice*
AwtChoice::Create( jobject peer, jobject hParent )
{
    JNIEnv *env;
    if ( JVM->AttachCurrentThread( (void **)&env, 0 ) != 0 ) {
        return 0;
    }
    CHECK_NULL_RETURN( hParent, "null hParent" );
    AwtCanvas *parent = PDATA( AwtCanvas, hParent );
    CHECK_NULL_RETURN( parent, "null parent" );
    jobject target = env->GetObjectField( peer,
                                          WCachedIDs.PPCObjectPeer_targetFID );
    CHECK_NULL_RETURN( target, "null target" );

    AwtChoice *c = new AwtChoice();
    CHECK_NULL_RETURN( c, "AwtChoice() failed" );

#ifndef WINCE
    DWORD style = WS_CHILD | WS_CLIPSIBLINGS | WS_VSCROLL |
                  CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED;
#else
    // WINCE does not support OWNERDRAW combo boxes.
    DWORD style = WS_CHILD | WS_CLIPSIBLINGS | WS_VSCROLL |
                  CBS_DROPDOWNLIST;
#endif // !WINCE

    // In OWNER_DRAW, the size of the edit control part of the choice
    // must be determinded in its creation, when the parent cannot get
    // the choice's instance from its handle.  So record the pair of
    // the ID and the instance of the choice.
    UINT myId = parent->CreateControlID();
    ASSERT( myId > 0 );
    c->m_myControlID = myId;
    parent->PushChild( myId, c );

    c->CreateHWnd( TEXT(""), style, 0,
                   env->CallIntMethod( target,
                                       WCachedIDs.java_awt_Component_getXMID ),
                   env->CallIntMethod( target,
                                       WCachedIDs.java_awt_Component_getYMID ),
                   env->CallIntMethod( target,
                                       WCachedIDs.java_awt_Component_getWidthMID ),
                   env->CallIntMethod( target,
                                       WCachedIDs.java_awt_Component_getHeightMID ),
                   parent->GetHWnd(),
                   (HMENU)myId,
                   ::GetSysColor( COLOR_WINDOWTEXT ),
                   ::GetSysColor( COLOR_WINDOW ),
                   peer
                 );
    c->m_backgroundColorSet = TRUE;  // suppress inheriting parent's color.
    return c;
}
// 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;
}
// Create a new AwtTextField object and window.  
AwtTextField* AwtTextField::Create(jobject peer, jobject hParent)
{
   JNIEnv *env;
    
    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(peer, 
                                         WCachedIDs.PPCObjectPeer_targetFID);
    CHECK_NULL_RETURN(target, "null target");

    AwtTextField* c = new AwtTextField();
    CHECK_NULL_RETURN(c, "AwtTextField() failed");

    DWORD style = WS_CHILD | WS_CLIPSIBLINGS |
                  ES_LEFT | ES_AUTOHSCROLL | ES_NOHIDESEL | 
                  (IS_WIN4X ? 0 : WS_BORDER);
    DWORD exStyle = IS_WIN4X ? WS_EX_CLIENTEDGE : 0;
    c->CreateHWnd(TEXT(""), style, exStyle,
         (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_WINDOW),
                  peer
                 );

    c->m_backgroundColorSet = TRUE;  // suppress inheriting parent's color.
    return c;
}
예제 #4
0
AwtChoice* AwtChoice::Create(jobject peer, jobject parent) {


    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);

    jobject target = NULL;
    AwtChoice* c = NULL;
    RECT rc;

    try {
        if (env->EnsureLocalCapacity(1) < 0) {
	    return NULL;
	}
	AwtCanvas* awtParent;

	JNI_CHECK_NULL_GOTO(parent, "null parent", done);

	awtParent = (AwtCanvas*)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);

	c = new AwtChoice();

	{
	    DWORD style = WS_CHILD | WS_CLIPSIBLINGS | WS_VSCROLL |
	                  CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED;
	    DWORD exStyle = 0;
	    if (GetRTL()) {
	        exStyle |= WS_EX_RIGHT | WS_EX_LEFTSCROLLBAR;
		if (GetRTLReadingOrder())
		    exStyle |= WS_EX_RTLREADING;
	    }

	    /*
	     * In OWNER_DRAW, the size of the edit control part of the
	     * choice must be determinded in its creation, when the parent
	     * cannot get the choice's instance from its handle.  So
	     * record the pair of the ID and the instance of the choice.
	     */
	    UINT myId = awtParent->CreateControlID();
	    DASSERT(myId > 0);
	    c->m_myControlID = myId;
	    awtParent->PushChild(myId, c);

	    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);
	    
            jobject dimension = JNU_CallMethodByName(env, NULL, peer,
                                                     "preferredSize",
                                                     "()Ljava/awt/Dimension;").l;
            DASSERT(!safe_ExceptionOccurred(env));

            if (dimension != NULL && width == 0) {
                width = env->GetIntField(dimension, AwtDimension::widthID);
            }
	    c->CreateHWnd(env, L"", style, exStyle,
			  x, y, width, height,
			  awtParent->GetHWnd(),
			  reinterpret_cast<HMENU>(static_cast<INT_PTR>(myId)),
			  ::GetSysColor(COLOR_WINDOWTEXT),
			  ::GetSysColor(COLOR_WINDOW),
			  peer);

	    /* suppress inheriting parent's color. */
	    c->m_backgroundColorSet = TRUE;
            c->UpdateBackground(env, target);

            /* Bug 4255631 Solaris: Size returned by Choice.getSize() does not match
             * actual size
             * Fix: Set the Choice to its actual size in the component.
             */
            ::GetClientRect(c->GetHWnd(), &rc);
            env->SetIntField(target, AwtComponent::widthID,  (jint) rc.right);
            env->SetIntField(target, AwtComponent::heightID, (jint) rc.bottom);

            env->DeleteLocalRef(dimension);
	}
    } catch (...) {
        env->DeleteLocalRef(target);
	throw;
    }

done:
    env->DeleteLocalRef(target);

    return c;
}
/* Create a new AwtTextArea or AwtTextField object and window.   */
AwtTextComponent* AwtTextComponent::Create(jobject peer, jobject parent, BOOL isMultiline)
{
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);

    jobject target = NULL;
    AwtTextComponent* c = NULL;

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

        PDATA pData;
        AwtCanvas* awtParent;
        JNI_CHECK_PEER_GOTO(parent, done);

        awtParent = (AwtCanvas*)pData;
        JNI_CHECK_NULL_GOTO(awtParent, "null awtParent", done);

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

        if(isMultiline) {
            c = new AwtTextArea();
        } else {
            c = new AwtTextField();
        }

        {
            /* Adjust style for scrollbar visibility and word wrap  */
            DWORD scroll_style;

            if(isMultiline) {

                jint scrollbarVisibility =
                    env->GetIntField(target, AwtTextArea::scrollbarVisibilityID);

                switch (scrollbarVisibility) {
                case java_awt_TextArea_SCROLLBARS_NONE:
                    scroll_style = ES_AUTOVSCROLL;
                    break;
                case java_awt_TextArea_SCROLLBARS_VERTICAL_ONLY:
                    scroll_style = WS_VSCROLL | ES_AUTOVSCROLL;
                    break;
                case java_awt_TextArea_SCROLLBARS_HORIZONTAL_ONLY:
                    scroll_style = WS_HSCROLL | ES_AUTOHSCROLL | ES_AUTOVSCROLL;
                    break;
                case java_awt_TextArea_SCROLLBARS_BOTH:
                    scroll_style = WS_VSCROLL | WS_HSCROLL |
                                   ES_AUTOVSCROLL | ES_AUTOHSCROLL;
                    break;
                }
            }

            DWORD style = WS_CHILD | WS_CLIPSIBLINGS | ES_LEFT;

            /*
             * Specify ES_DISABLENOSCROLL - RichEdit control style to disable
             * scrollbars instead of hiding them when not needed.
             */
            style |= isMultiline ?  ES_MULTILINE | ES_WANTRETURN | scroll_style
                     | ES_DISABLENOSCROLL : ES_AUTOHSCROLL;


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


            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);

            c->CreateHWnd(env, L"", style, exStyle,
                          x, y, width, height,
                          awtParent->GetHWnd(),
                          reinterpret_cast<HMENU>(static_cast<INT_PTR>(
                                  awtParent->CreateControlID())),
                          ::GetSysColor(COLOR_WINDOWTEXT),
                          ::GetSysColor(COLOR_WINDOW),
                          peer);

            // Fix for 4753116.
            // If it is not win95 (we are using Richedit 2.0)
            // we set plain text mode, in which the control is
            // similar to a standard edit control:
            //  - The text in a plain text control can have only
            //    one format.
            //  - The user cannot paste rich text formats, such as RTF
            //    or embedded objects into a plain text control.
            //  - Rich text mode controls always have a default
            //    end-of-document marker or carriage return,
            //    to format paragraphs.
            // [email protected]
            c->SendMessage(EM_SETTEXTMODE, TM_PLAINTEXT, 0);

            c->m_backgroundColorSet = TRUE;
            /* suppress inheriting parent's color. */
            c->UpdateBackground(env, target);
            c->SendMessage(EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN,
                           MAKELPARAM(1, 1));
            /*
             * Fix for BugTraq Id 4260109.
             * Set the text limit to the maximum.
             * Use EM_EXLIMITTEXT for RichEdit controls.
             * For some reason RichEdit 1.0 becomes read-only if the
             * specified limit is greater than 0x7FFFFFFD.
             */
            c->SendMessage(EM_EXLIMITTEXT, 0, 0x7FFFFFFD);

            /* Unregister RichEdit built-in drop target. */
            VERIFY(::RevokeDragDrop(c->GetHWnd()) != DRAGDROP_E_INVALIDHWND);

            /* To enforce CF_TEXT format for paste operations. */
            VERIFY(c->SendMessage(EM_SETOLECALLBACK, 0,
                                  (LPARAM)&GetOleCallback()));

            c->SendMessage(EM_SETEVENTMASK, 0, ENM_CHANGE);
        }
    } catch (...) {
        env->DeleteLocalRef(target);
        throw;
    }

done:
    env->DeleteLocalRef(target);

    return c;
}
예제 #6
0
/* Create a new AwtScrollbar object and window.   */
AwtScrollbar *
AwtScrollbar::Create(jobject peer, jobject parent)
{
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);

    jobject target = NULL;
    AwtScrollbar* c = NULL;

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

        PDATA pData;
        AwtCanvas* awtParent;
        JNI_CHECK_PEER_GOTO(parent, done);

        awtParent = (AwtCanvas*)pData;
        JNI_CHECK_NULL_GOTO(awtParent, "null awtParent", done);

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

        c = new AwtScrollbar();

        {
            jint orientation =
                env->GetIntField(target, AwtScrollbar::orientationID);
            c->m_orientation = (orientation == java_awt_Scrollbar_VERTICAL) ?
                SB_VERT : SB_HORZ;
            c->m_lineIncr =
                env->GetIntField(target, AwtScrollbar::lineIncrementID);
            c->m_pageIncr =
                env->GetIntField(target, AwtScrollbar::pageIncrementID);

            DWORD style = WS_CHILD | WS_CLIPSIBLINGS |
                c->m_orientation;/* Note: SB_ and SBS_ are the same here */

            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);

            c->CreateHWnd(env, L"", style, 0,
                          x, y, width, height,
                          awtParent->GetHWnd(),
                          reinterpret_cast<HMENU>(static_cast<INT_PTR>(
                awtParent->CreateControlID())),
                          ::GetSysColor(COLOR_SCROLLBAR),
                          ::GetSysColor(COLOR_SCROLLBAR),
                          peer);
            c->m_backgroundColorSet = TRUE;
            /* suppress inheriting parent's color. */
            c->UpdateBackground(env, target);
        }
    } catch (...) {
        env->DeleteLocalRef(target);
        throw;
    }

done:
    env->DeleteLocalRef(target);
    return c;
}
/* Create a new AwtTextField object and window.   */
AwtTextField* AwtTextField::Create(jobject peer, jobject parent)
{
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);

    jobject target = NULL;
    AwtTextField* c = NULL;

    try {
        PDATA pData;
        AwtCanvas* awtParent;
        JNI_CHECK_PEER_GOTO(parent, done);
        awtParent = (AwtCanvas*)pData;

        JNI_CHECK_NULL_GOTO(awtParent, "null awtParent", done);

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

        c = new AwtTextField();

        {
            DWORD style = WS_CHILD | WS_CLIPSIBLINGS |
                ES_LEFT | ES_AUTOHSCROLL |
                (IS_WIN4X ? 0 : WS_BORDER);
            DWORD exStyle = IS_WIN4X ? WS_EX_CLIENTEDGE : 0;
            if (GetRTL()) {
                exStyle |= WS_EX_RIGHT | WS_EX_LEFTSCROLLBAR;
                if (GetRTLReadingOrder())
                    exStyle |= WS_EX_RTLREADING;
            }

            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);

            c->CreateHWnd(env, L"", style, exStyle,
                          x, y, width, height,
                          awtParent->GetHWnd(),
                          reinterpret_cast<HMENU>(static_cast<INT_PTR>(
                awtParent->CreateControlID())),
                          ::GetSysColor(COLOR_WINDOWTEXT),
                          ::GetSysColor(COLOR_WINDOW),
                          peer);

            c->m_backgroundColorSet = TRUE;
            /* suppress inheriting parent's color. */
            c->UpdateBackground(env, target);
            c->SendMessage(EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN,
                           MAKELPARAM(1, 1));
            /*
             * Fix for BugTraq Id 4260109.
             * Set the text limit to the maximum.
             */
            c->SendMessage(EM_SETLIMITTEXT);

        }
    } catch (...) {
        env->DeleteLocalRef(target);
        throw;
    }

done:
    env->DeleteLocalRef(target);

    return c;
}