Changeset 51:6e4e3a8e4971

Show
Ignore:
Timestamp:
02/02/08 21:43:52 (1 year ago)
Author:
Frank Benoit <benoit@tionex.de>
branch:
default
Message:

Label

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • dwt/widgets/Label.d

    r31 r51  
    1313module dwt.widgets.Label; 
    1414 
    15 import dwt.widgets.Control; 
    16 import dwt.widgets.Composite; 
    17 class Label : Control { 
    18     this (Composite parent, int style) ; 
    19 
    20 /++ 
     15 
    2116import dwt.DWT; 
    2217import dwt.DWTException; 
     
    2621import dwt.graphics.Point; 
    2722import dwt.graphics.Rectangle; 
    28 import dwt.internal.win32.DRAWITEMSTRUCT; 
    29 import dwt.internal.win32.LRESULT; 
    3023import dwt.internal.win32.OS; 
    31 import dwt.internal.win32.PAINTSTRUCT; 
    32 import dwt.internal.win32.RECT
    33 import dwt.internal.win32.TCHAR
    34 import dwt.internal.win32.TEXTMETRIC
    35 import dwt.internal.win32.TEXTMETRICA
    36 import dwt.internal.win32.TEXTMETRICW; 
    37 import dwt.internal.win32.WNDCLASS
     24 
     25import dwt.widgets.Control
     26import dwt.widgets.Composite
     27import dwt.widgets.Display
     28import dwt.widgets.Event
     29 
     30import dwt.dwthelper.utils
    3831 
    3932/** 
     
    5952 * </p> 
    6053 */ 
    61 public class Label extends Control { 
    62     String text = ""; 
     54public class Label : Control { 
     55    char[] text = ""; 
    6356    Image image; 
    64     static final int MARGIN = 4; 
    65     static final bool IMAGE_AND_TEXT = false; 
    66     static final int LabelProc; 
    67     static final TCHAR LabelClass = new TCHAR (0, "STATIC", true)
    68     static
    69         WNDCLASS lpWndClass = new WNDCLASS ()
    70         OS.GetClassInfo (0, LabelClass, lpWndClass); 
     57    static const int MARGIN = 4; 
     58    static const bool IMAGE_AND_TEXT = false; 
     59    static const WNDPROC LabelProc; 
     60    static const TCHAR[] LabelClass = "STATIC\0"
     61    static this()
     62        WNDCLASS lpWndClass
     63        OS.GetClassInfo (null, LabelClass.ptr, &lpWndClass); 
    7164        LabelProc = lpWndClass.lpfnWndProc; 
    7265    } 
     
    109102 * @see Widget#getStyle 
    110103 */ 
    111 public Label (Composite parent, int style) { 
     104public this (Composite parent, int style) { 
    112105    super (parent, checkStyle (style)); 
    113106} 
    114107 
    115 int callWindowProc (int hwnd, int msg, int wParam, int lParam) { 
    116     if (handle is 0) return 0
    117     return OS.CallWindowProc (LabelProc, hwnd, msg, wParam, lParam); 
     108LRESULT callWindowProc (HWND hwnd, int msg, int wParam, int lParam) { 
     109    if (handle is null) return LRESULT.NULL
     110    return cast(LRESULT) OS.CallWindowProc (LabelProc, hwnd, msg, wParam, lParam); 
    118111} 
    119112 
     
    151144            height += rect.height; 
    152145            if (IMAGE_AND_TEXT) { 
    153                 if (text.length () !is 0) width += MARGIN; 
     146                if (text.length !is 0) width += MARGIN; 
    154147            } else { 
    155148                drawText = false; 
     
    158151    } 
    159152    if (drawText) { 
    160         int hDC = OS.GetDC (handle); 
    161         int newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); 
    162         int oldFont = OS.SelectObject (hDC, newFont); 
     153        auto hDC = OS.GetDC (handle); 
     154        auto newFont = cast(HFONT) OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); 
     155        auto oldFont = OS.SelectObject (hDC, newFont); 
    163156        int length = OS.GetWindowTextLength (handle); 
    164157        if (length is 0) { 
    165             TEXTMETRIC tm = OS.IsUnicode ? (TEXTMETRIC) new TEXTMETRICW () : new TEXTMETRICA ()
    166             OS.GetTextMetrics (hDC, tm); 
     158            TEXTMETRIC tm
     159            OS.GetTextMetrics (hDC, &tm); 
    167160            height = Math.max (height, tm.tmHeight); 
    168161        } else { 
    169             RECT rect = new RECT ()
     162            RECT rect
    170163            int flags = OS.DT_CALCRECT | OS.DT_EDITCONTROL | OS.DT_EXPANDTABS; 
    171164            if ((style & DWT.WRAP) !is 0 && wHint !is DWT.DEFAULT) { 
     
    173166                rect.right = Math.max (0, wHint - width); 
    174167            } 
    175             TCHAR buffer = new TCHAR (getCodePage (), length + 1)
    176             OS.GetWindowText (handle, buffer, length + 1); 
    177             OS.DrawText (hDC, buffer, length, rect, flags); 
     168            TCHAR[] buffer = new TCHAR [/+getCodePage (),+/ length + 1]
     169            OS.GetWindowText (handle, buffer.ptr, length + 1); 
     170            OS.DrawText (hDC, buffer.ptr, length, &rect, flags); 
    178171            width += rect.right - rect.left; 
    179172            height = Math.max (height, rect.bottom - rect.top); 
    180173        } 
    181         if (newFont !is 0) OS.SelectObject (hDC, oldFont); 
     174        if (newFont !is null) OS.SelectObject (hDC, oldFont); 
    182175        OS.ReleaseDC (handle, hDC); 
    183176    } 
     
    240233} 
    241234 
    242 String getNameText () { 
     235char[] getNameText () { 
    243236    return getText (); 
    244237} 
     
    256249 * </ul> 
    257250 */ 
    258 public String getText () { 
     251public char[] getText () { 
    259252    checkWidget (); 
    260253    if ((style & DWT.SEPARATOR) !is 0) return ""; 
     
    262255} 
    263256 
    264 bool mnemonicHit (char key) { 
     257bool mnemonicHit (wchar key) { 
    265258    Composite control = this.parent; 
    266259    while (control !is null) { 
     
    280273} 
    281274 
    282 bool mnemonicMatch (char key) { 
    283     char mnemonic = findMnemonic (getText ()); 
     275bool mnemonicMatch (wchar key) { 
     276    wchar mnemonic = findMnemonic (getText ()); 
    284277    if (mnemonic is '\0') return false; 
    285     return Character.toUpperCase (key) is Character.toUpperCase (mnemonic); 
     278    return CharacterToUpper (key) is CharacterToUpper (mnemonic); 
    286279} 
    287280 
     
    383376 * </ul> 
    384377 */ 
    385 public void setText (String string) { 
     378public void setText (char[] string) { 
    386379    checkWidget (); 
    387380    if (string is null) error (DWT.ERROR_NULL_ARGUMENT); 
     
    393386    * nothing. 
    394387    */ 
    395     if (string.equals (text)) return; 
     388    if (string==/*eq*/text) return; 
    396389    text = string; 
    397390    if (image is null || !IMAGE_AND_TEXT) { 
     
    410403    } 
    411404    string = Display.withCrLf (string); 
    412     TCHAR buffer = new TCHAR (getCodePage (), string, true); 
     405    TCHAR* buffer = StrToTCHARz (/+getCodePage (),+/ string); 
    413406    OS.SetWindowText (handle, buffer); 
    414407    /* 
     
    443436} 
    444437 
    445 TCHAR windowClass () { 
    446     return LabelClass
     438char[] windowClass () { 
     439    return TCHARsToStr( LabelClass )
    447440} 
    448441 
    449442int windowProc () { 
    450     return LabelProc; 
     443    return cast(int) LabelProc; 
    451444} 
    452445 
    453446LRESULT WM_ERASEBKGND (int wParam, int lParam) { 
    454447    LRESULT result = super.WM_ERASEBKGND (wParam, lParam); 
    455     if (result !is null) return result; 
     448    if (result !is LRESULT.NULL) return result; 
    456449    int bits = OS.GetWindowLong (handle, OS.GWL_STYLE); 
    457450    if ((bits & OS.SS_OWNERDRAW) is OS.SS_OWNERDRAW) { 
     
    468461    if (OS.COMCTL32_MAJOR < 6 || !OS.IsAppThemed ()) { 
    469462        if (findImageControl () !is null) { 
    470             drawBackground (wParam); 
     463            drawBackground (cast(HANDLE)wParam); 
    471464            return LRESULT.ONE; 
    472465        } 
     
    522515        OS.InvalidateRect (handle, null, false); 
    523516        int code = OS.DefWindowProc (handle, OS.WM_UPDATEUISTATE, wParam, lParam); 
    524         return new LRESULT (code); 
     517        return cast(LRESULT) (code); 
    525518    } 
    526519    return result; 
     
    541534        if ((bits & OS.SS_OWNERDRAW) !is OS.SS_OWNERDRAW) { 
    542535            if (findImageControl () !is null) { 
    543                 OS.SetBkMode (wParam, OS.TRANSPARENT); 
    544                 return new LRESULT (OS.GetStockObject (OS.NULL_BRUSH)); 
     536                OS.SetBkMode ( cast(HANDLE) wParam, OS.TRANSPARENT); 
     537                return cast(LRESULT) (OS.GetStockObject (OS.NULL_BRUSH)); 
    545538            } 
    546539        } 
     
    554547        bool drawSeparator = (style & DWT.SEPARATOR) !is 0 && (style & DWT.SHADOW_NONE) is 0; 
    555548        if (drawImage || drawSeparator) { 
    556             LRESULT result = null
    557             PAINTSTRUCT ps = new PAINTSTRUCT ()
     549            LRESULT result = LRESULT.NULL
     550            PAINTSTRUCT ps
    558551            GCData data = new GCData (); 
    559             data.ps = ps; 
     552            data.ps = &ps; 
    560553            data.hwnd = handle; 
    561554            GC gc = new_GC (data); 
    562555            if (gc !is null) { 
    563556                drawBackground (gc.handle); 
    564                 RECT clientRect = new RECT()
    565                 OS.GetClientRect (handle, clientRect); 
     557                RECT clientRect
     558                OS.GetClientRect (handle, &clientRect); 
    566559                if (drawSeparator) { 
    567                     RECT rect = new RECT ()
     560                    RECT rect
    568561                    int lineWidth = OS.GetSystemMetrics (OS.SM_CXBORDER); 
    569562                    int flags = (style & DWT.SHADOW_IN) !is 0 ? OS.EDGE_SUNKEN : OS.EDGE_ETCHED; 
    570563                    if ((style & DWT.HORIZONTAL) !is 0) { 
    571564                        int bottom = clientRect.top + Math.max (lineWidth * 2, (clientRect.bottom - clientRect.top) / 2); 
    572                         OS.SetRect (rect, clientRect.left, clientRect.top, clientRect.right, bottom); 
    573                         OS.DrawEdge (gc.handle, rect, flags, OS.BF_BOTTOM); 
     565                        OS.SetRect (&rect, clientRect.left, clientRect.top, clientRect.right, bottom); 
     566                        OS.DrawEdge (gc.handle, &rect, flags, OS.BF_BOTTOM); 
    574567                    } else { 
    575568                        int right = clientRect.left + Math.max (lineWidth * 2, (clientRect.right - clientRect.left) / 2); 
    576                         OS.SetRect (rect, clientRect.left, clientRect.top, right, clientRect.bottom); 
    577                         OS.DrawEdge (gc.handle, rect, flags, OS.BF_RIGHT); 
     569                        OS.SetRect (&rect, clientRect.left, clientRect.top, right, clientRect.bottom); 
     570                        OS.DrawEdge (gc.handle, &rect, flags, OS.BF_RIGHT); 
    578571                    } 
    579572                    result = LRESULT.ONE; 
     
    592585                    result = LRESULT.ONE; 
    593586                } 
    594                 int width = ps.right - ps.left; 
    595                 int height = ps.bottom - ps.top; 
     587                int width = ps.rcPaint.right - ps.rcPaint.left; 
     588                int height = ps.rcPaint.bottom - ps.rcPaint.top; 
    596589                if (width !is 0 && height !is 0) { 
    597590                    Event event = new Event (); 
    598591                    event.gc = gc; 
    599                     event.x = ps.left; 
    600                     event.y = ps.top; 
     592                    event.x = ps.rcPaint.left; 
     593                    event.y = ps.rcPaint.top; 
    601594                    event.width = width; 
    602595                    event.height = height; 
     
    614607 
    615608LRESULT wmDrawChild (int wParam, int lParam) { 
    616     DRAWITEMSTRUCT struct = new DRAWITEMSTRUCT (); 
    617     OS.MoveMemory (struct, lParam, DRAWITEMSTRUCT.sizeof); 
    618     drawBackground (struct.hDC); 
     609    DRAWITEMSTRUCT* struct_ = cast(DRAWITEMSTRUCT*)lParam; 
     610    drawBackground (struct_.hDC); 
    619611    if ((style & DWT.SEPARATOR) !is 0) { 
    620         if ((style & DWT.SHADOW_NONE) !is 0) return null
    621         RECT rect = new RECT ()
     612        if ((style & DWT.SHADOW_NONE) !is 0) return LRESULT.NULL
     613        RECT rect
    622614        int lineWidth = OS.GetSystemMetrics (OS.SM_CXBORDER); 
    623615        int flags = (style & DWT.SHADOW_IN) !is 0 ? OS.EDGE_SUNKEN : OS.EDGE_ETCHED; 
    624616        if ((style & DWT.HORIZONTAL) !is 0) { 
    625             int bottom = struct.top + Math.max (lineWidth * 2, (struct.bottom - struct.top) / 2); 
    626             OS.SetRect (rect, struct.left, struct.top, struct.right, bottom); 
    627             OS.DrawEdge (struct.hDC, rect, flags, OS.BF_BOTTOM); 
     617            int bottom = struct_.rcItem.top + Math.max (lineWidth * 2, (struct_.rcItem.bottom - struct_.rcItem.top) / 2); 
     618            OS.SetRect (&rect, struct_.rcItem.left, struct_.rcItem.top, struct_.rcItem.right, bottom); 
     619            OS.DrawEdge (struct_.hDC, &rect, flags, OS.BF_BOTTOM); 
    628620        } else { 
    629             int right = struct.left + Math.max (lineWidth * 2, (struct.right - struct.left) / 2); 
    630             OS.SetRect (rect, struct.left, struct.top, right, struct.bottom); 
    631             OS.DrawEdge (struct.hDC, rect, flags, OS.BF_RIGHT); 
     621            int right = struct_.rcItem.left + Math.max (lineWidth * 2, (struct_.rcItem.right - struct_.rcItem.left) / 2); 
     622            OS.SetRect (&rect, struct_.rcItem.left, struct_.rcItem.top, right, struct_.rcItem.bottom); 
     623            OS.DrawEdge (struct_.hDC, &rect, flags, OS.BF_RIGHT); 
    632624        } 
    633625    } else { 
    634         int width = struct.right - struct.left; 
    635         int height = struct.bottom - struct.top; 
     626        int width = struct_.rcItem.right - struct_.rcItem.left; 
     627        int height = struct_.rcItem.bottom - struct_.rcItem.top; 
    636628        if (width !is 0 && height !is 0) { 
    637629            bool drawImage = image !is null; 
    638             bool drawText = IMAGE_AND_TEXT && text.length () !is 0; 
     630            bool drawText = IMAGE_AND_TEXT && text.length !is 0; 
    639631            int margin = drawText && drawImage ? MARGIN : 0; 
    640632            int imageWidth = 0, imageHeight = 0; 
     
    644636                imageHeight = rect.height; 
    645637            } 
    646             RECT rect = null
    647             TCHAR buffer = null; 
     638            RECT rect
     639            TCHAR* buffer = null; 
    648640            int textWidth = 0, textHeight = 0, flags = 0; 
    649641            if (drawText) { 
    650                 rect = new RECT (); 
     642                //rect = new RECT (); 
    651643                flags = OS.DT_CALCRECT | OS.DT_EDITCONTROL | OS.DT_EXPANDTABS; 
    652644                if ((style & DWT.LEFT) !is 0) flags |= OS.DT_LEFT; 
     
    657649                    rect.right = Math.max (0, width - imageWidth - margin); 
    658650                } 
    659                 buffer = new TCHAR (getCodePage (), text, true); 
    660                 OS.DrawText (struct.hDC, buffer, -1, rect, flags); 
     651                buffer = StrToTCHARz (/+getCodePage (),+/ text); 
     652                OS.DrawText (struct_.hDC, buffer, -1, &rect, flags); 
    661653                textWidth = rect.right - rect.left; 
    662654                textHeight = rect.bottom - rect.top; 
     
    673665                GCData data = new GCData(); 
    674666                data.device = display; 
    675                 GC gc = GC.win32_new (struct.hDC, data); 
     667                GC gc = GC.win32_new (struct_.hDC, data); 
    676668                Image image = getEnabled () ? this.image : new Image (display, this.image, DWT.IMAGE_DISABLE); 
    677669                gc.drawImage (image, x, Math.max (0, (height - imageHeight) / 2)); 
     
    686678                rect.top = Math.max (0, (height - textHeight) / 2); 
    687679                rect.bottom += rect.top; 
    688                 OS.DrawText (struct.hDC, buffer, -1, rect, flags); 
    689             } 
    690         } 
    691     } 
    692     return null
    693 } 
    694  
    695 } 
    696 ++/ 
     680                OS.DrawText (struct_.hDC, buffer, -1, &rect, flags); 
     681            } 
     682        } 
     683    } 
     684    return LRESULT.NULL
     685} 
     686 
     687} 
     688