Changeset 216 for trunk/src


Ignore:
Timestamp:
Nov 9, 2009, 1:01:17 PM (16 years ago)
Author:
lpino
Message:
  • Process WM_PAINT to draw mini icons. This fixes the ControlExample where there were no images in the Label tab
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/plugins/org.eclipse.swt/Eclipse SWT/pm/org/eclipse/swt/widgets/Label.java

    r50 r216  
    1212 */
    1313
    14 //import org.eclipse.swt.internal.*;
    15 //import org.eclipse.swt.internal.win32.*;
    16 //import org.eclipse.swt.*;
    1714import org.eclipse.swt.graphics.*;
    1815import org.eclipse.swt.internal.*;
     
    460457}
    461458
     459
    462460//MRESULT WM_ERASEBKGND (int mp1, int mp2) {
    463461//      LRESULT result = super.WM_ERASEBKGND (wParam, lParam);
     
    483481//}
    484482//
    485 //MRESULT WM_GETFONT (int mp1, int mp2) {
    486 //      LRESULT result = super.WM_GETFONT (wParam, lParam);
    487 //      if (result != null) return result;
    488 //      /*
    489 //      * Bug in Windows.  When the style of a label is SS_BITMAP
    490 //      * or SS_ICON, the label does not remember the font that is
    491 //      * set in WM_SETFONT.  The fix is to remember the font and
    492 //      * return the font in WM_GETFONT.
    493 //      */
    494 //      if (font == 0) font = defaultFont ();
    495 //      return new LRESULT (font);
    496 //        System.out.println("WM_GETFONT");
    497 //        return null;
    498 //}
    499 //
    500 //MRESULT WM_SETFONT (int mp1, int mp2) {
    501 //      /*
    502 //      * Bug in Windows.  When the style of a label is SS_BITMAP
    503 //      * or SS_ICON, the label does not remember the font that is
    504 //      * set in WM_SETFONT.  The fix is to remember the font and
    505 //      * return the font in WM_GETFONT.
    506 //      */
    507 //      return super.WM_SETFONT (font = wParam, lParam);
    508 //        System.out.println("WM_SETFONT");
    509 //        return null;
    510 //}
    511 //
    512 //MRESULT WM_SIZE (int mp1, int mp2) {
    513 //      LRESULT result = super.WM_SIZE (wParam, lParam);
    514 //      /*
    515 //      * It is possible (but unlikely), that application
    516 //      * code could have disposed the widget in the resize
    517 //      * event.  If this happens, end the processing of the
    518 //      * Windows message by returning the result of the
    519 //      * WM_SIZE message.
    520 //      */
    521 //      if (isDisposed ()) return result;
     483
     484MRESULT WM_SIZE (int mp1, int mp2) {
     485        MRESULT result = super.WM_SIZE (mp1, mp2);
     486        /*
     487        * It is possible (but unlikely), that application
     488        * code could have disposed the widget in the resize
     489        * event.  If this happens, end the processing of the
     490        * Windows message by returning the result of the
     491        * WM_SIZE message.
     492        */
     493        if (isDisposed ()) return result;
    522494//      if ((style & SWT.SEPARATOR) != 0) {
    523495//              OS.InvalidateRect (handle, null, true);
    524496//              return result;
    525497//      }
    526 //     
     498       
    527499//      /*
    528500//      * Bug in Windows.  For some reason, a label with
     
    535507//              OS.InvalidateRect (handle, null, true);
    536508//      }
    537 //        System.out.println("WM_SIZE");
    538 //      return null;
    539 //}
    540 //
    541 //MRESULT wmDrawChild (int mp1, int mp2) {
     509        return result;
     510}
     511
     512MRESULT WM_PAINT (int mp1, int mp2) {
    542513//      DRAWITEMSTRUCT struct = new DRAWITEMSTRUCT ();
    543514//      OS.MoveMemory (struct, lParam, DRAWITEMSTRUCT.sizeof);
     
    557528//              OS.DrawEdge (struct.hDC, rect, flags, OS.BF_RIGHT);
    558529//      }
    559 //        System.out.println("wmDrawChild");
    560 //      return MRESULT.ZERO;
    561 //}
    562 
    563 }
     530        if (this.image == null) return null;
     531        if(this.image.getImageData().width != 16 && this.image.getImageData().width != 20) return null;
     532
     533        // hps is unitialized here, do some initializations
     534        if (hps == 0) hps = OS.WinGetPS (handle);
     535       
     536        OS.GpiSetMix (hps, OS.FM_OVERPAINT);
     537        OS.GpiSetBackMix (hps, OS.BM_OVERPAINT);
     538        OS.GpiSetPattern (hps, OS.PATSYM_BLANK);
     539        int hPalette = getDisplay ().hPalette;
     540        if (hPalette == 0)
     541            OS.GpiCreateLogColorTable (hps, 0, OS.LCOLF_RGB, 0, 0, null);
     542        else
     543            OS.GpiSelectPalette (hps, hPalette);
     544       
     545            Rectangle bounds = image.getBounds();
     546            int x = 0;
     547            int y = 0;
     548            if (image.type == SWT.ICON) {
     549                int hbmColor = image.handle;
     550                int hbmPointer = image.maskHandle;
     551                if (hbmPointer == 0) {
     552                    OS.WinDrawPointer (hps, x, y, hbmColor, OS.DP_NORMAL);
     553                } else {
     554                    OS.GpiSetColor (hps, (hPalette != 0) ? 15 : 0xFFFFFF);
     555                    OS.GpiSetBackColor (hps, 0);
     556                    /* draw AND mask */
     557                    OS.GpiWCBitBlt (hps, hbmPointer, 4,
     558                        new int[] {
     559                            x, y, x + bounds.width - 1, y + bounds.height - 1,
     560                            0, bounds.height, bounds.width, bounds.height << 1
     561                        },
     562                        OS.ROP_SRCAND, OS.BBO_IGNORE
     563                    );
     564                    /* draw icon */
     565                    OS.GpiWCBitBlt (hps, hbmColor, 4,
     566                        new int[] {
     567                            x, y, x + bounds.width - 1, y + bounds.height - 1,
     568                            0, 0, bounds.width, bounds.height
     569                        },
     570                        OS.ROP_SRCINVERT, OS.BBO_IGNORE
     571                    );
     572                    /* draw XOR mask */
     573                    OS.GpiWCBitBlt (hps, hbmPointer, 4,
     574                        new int[] {
     575                            x, y, x + bounds.width - 1, y + bounds.height - 1,
     576                            0, 0, bounds.width, bounds.height
     577                        },
     578                        OS.ROP_SRCINVERT, OS.BBO_IGNORE
     579                    );
     580                }
     581            }
     582        if (this.hps == 0) OS.WinReleasePS (hps);   
     583        return null;
     584}
     585
     586}
Note: See TracChangeset for help on using the changeset viewer.