Changeset 42:6a40adae94d5

Show
Ignore:
Timestamp:
02/01/08 16:20:30 (1 year ago)
Author:
Frank Benoit <benoit@tionex.de>
branch:
default
Message:

Caret

Files:

Legend:

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

    r38 r42  
    1313module dwt.widgets.Caret; 
    1414 
    15 import dwt.widgets.Widget; 
    16 import dwt.graphics.Font; 
    17  
    18 class Caret : Widget { 
    19     this( Widget, int ); 
    20 bool isFocusCaret () ; 
    21 void killFocus () ; 
    22 void setFocus () ; 
    23 public void setFont (Font font) ; 
    24 void setIMEFont () ; 
    25 void resizeIME () ; 
    26 
    27 /++ 
     15 
     16 
    2817import dwt.DWT; 
    2918import dwt.DWTException; 
     
    3221import dwt.graphics.Point; 
    3322import dwt.graphics.Rectangle; 
    34 import dwt.internal.win32.COMPOSITIONFORM; 
    35 import dwt.internal.win32.LOGFONT; 
    36 import dwt.internal.win32.LOGFONTA; 
    37 import dwt.internal.win32.LOGFONTW; 
    3823import dwt.internal.win32.OS; 
    39 import dwt.internal.win32.POINT; 
    40 import dwt.internal.win32.RECT; 
     24 
     25import dwt.widgets.Widget; 
     26import dwt.widgets.Canvas; 
     27 
     28import dwt.dwthelper.utils; 
    4129 
    4230/** 
     
    5543 */ 
    5644 
    57 public class Caret extends Widget { 
     45public class Caret : Widget { 
    5846    Canvas parent; 
    5947    int x, y, width, height; 
    6048    bool moved, resized; 
    61     bool isVisible
     49    bool isVisible_
    6250    Image image; 
    6351    Font font; 
    64     LOGFONT oldFont; 
     52    LOGFONT* oldFont; 
    6553 
    6654/** 
     
    9280 * @see Widget#getStyle 
    9381 */ 
    94 public Caret (Canvas parent, int style) { 
     82public this (Canvas parent, int style) { 
    9583    super (parent, style); 
    9684    this.parent = parent; 
     
    9987 
    10088void createWidget () { 
    101     isVisible = true; 
     89    isVisible_ = true; 
    10290    if (parent.getCaret () is null) { 
    10391        parent.setCaret (this); 
     
    10593} 
    10694 
    107 int defaultFont () { 
    108     int hwnd = parent.handle; 
    109     int hwndIME = OS.ImmGetDefaultIMEWnd (hwnd); 
    110     int hFont = 0
    111     if (hwndIME !is 0) { 
    112         hFont = OS.SendMessage (hwndIME, OS.WM_GETFONT, 0, 0); 
    113     } 
    114     if (hFont is 0) { 
    115         hFont = OS.SendMessage (hwnd, OS.WM_GETFONT, 0, 0); 
    116     } 
    117     if (hFont is 0) return parent.defaultFont (); 
     95HFONT defaultFont () { 
     96    auto hwnd = parent.handle; 
     97    auto hwndIME = OS.ImmGetDefaultIMEWnd (hwnd); 
     98    HFONT hFont
     99    if (hwndIME !is null) { 
     100        hFont = cast(HFONT) OS.SendMessage (hwndIME, OS.WM_GETFONT, 0, 0); 
     101    } 
     102    if (hFont is null) { 
     103        hFont = cast(HFONT) OS.SendMessage (hwnd, OS.WM_GETFONT, 0, 0); 
     104    } 
     105    if (hFont is null) return parent.defaultFont (); 
    118106    return hFont; 
    119107} 
     
    152140    checkWidget(); 
    153141    if (font is null) { 
    154         int hFont = defaultFont (); 
     142        HFONT hFont = defaultFont (); 
    155143        return Font.win32_new (display, hFont); 
    156144    } 
     
    242230public bool getVisible () { 
    243231    checkWidget(); 
    244     return isVisible
     232    return isVisible_
    245233} 
    246234 
     
    269257public bool isVisible () { 
    270258    checkWidget(); 
    271     return isVisible && parent.isVisible () && hasFocus (); 
     259    return isVisible_ && parent.isVisible () && hasFocus (); 
    272260} 
    273261 
     
    285273void resizeIME () { 
    286274    if (!OS.IsDBLocale) return; 
    287     POINT ptCurrentPos = new POINT ()
    288     if (!OS.GetCaretPos (ptCurrentPos)) return; 
    289     int hwnd = parent.handle; 
    290     RECT rect = new RECT ()
    291     OS.GetClientRect (hwnd, rect); 
    292     COMPOSITIONFORM lpCompForm = new COMPOSITIONFORM ()
     275    POINT ptCurrentPos
     276    if (!OS.GetCaretPos (&ptCurrentPos)) return; 
     277    auto hwnd = parent.handle; 
     278    RECT rect
     279    OS.GetClientRect (hwnd, &rect); 
     280    COMPOSITIONFORM lpCompForm
    293281    lpCompForm.dwStyle = OS.CFS_RECT; 
    294     lpCompForm.x = ptCurrentPos.x; 
    295     lpCompForm.y = ptCurrentPos.y; 
    296     lpCompForm.left = rect.left; 
    297     lpCompForm.right = rect.right; 
    298     lpCompForm.top = rect.top; 
    299     lpCompForm.bottom = rect.bottom; 
    300     int hIMC = OS.ImmGetContext (hwnd); 
    301     OS.ImmSetCompositionWindow (hIMC, lpCompForm); 
     282    lpCompForm.ptCurrentPos.x = ptCurrentPos.x; 
     283    lpCompForm.ptCurrentPos.y = ptCurrentPos.y; 
     284    lpCompForm.rcArea.left = rect.left; 
     285    lpCompForm.rcArea.right = rect.right; 
     286    lpCompForm.rcArea.top = rect.top; 
     287    lpCompForm.rcArea.bottom = rect.bottom; 
     288    auto hIMC = OS.ImmGetContext (hwnd); 
     289    OS.ImmSetCompositionWindow (hIMC, &lpCompForm); 
    302290    OS.ImmReleaseContext (hwnd, hIMC); 
    303291} 
     
    318306void resize () { 
    319307    resized = false; 
    320     int hwnd = parent.handle; 
     308    auto hwnd = parent.handle; 
    321309    OS.DestroyCaret (); 
    322     int hBitmap = image !is null ? image.handle : 0
     310    auto hBitmap = image !is null ? image.handle : null
    323311    OS.CreateCaret (hwnd, hBitmap, width, height); 
    324312    OS.SetCaretPos (x, y); 
     
    330318    if (!OS.IsDBLocale) return; 
    331319    if (oldFont is null) return; 
    332     int hwnd = parent.handle; 
    333     int hIMC = OS.ImmGetContext (hwnd); 
     320    auto hwnd = parent.handle; 
     321    auto hIMC = OS.ImmGetContext (hwnd); 
    334322    OS.ImmSetCompositionFont (hIMC, oldFont); 
    335323    OS.ImmReleaseContext (hwnd, hIMC); 
     
    362350    if (sameExtent) { 
    363351        moved = true; 
    364         if (isVisible && hasFocus ()) move (); 
     352        if (isVisible_ && hasFocus ()) move (); 
    365353    } else { 
    366354        resized = true; 
    367         if (isVisible && hasFocus ()) resize (); 
     355        if (isVisible_ && hasFocus ()) resize (); 
    368356    } 
    369357} 
     
    388376 
    389377void setFocus () { 
    390     int hwnd = parent.handle; 
    391     int hBitmap = 0
     378    auto hwnd = parent.handle; 
     379    HBITMAP hBitmap
    392380    if (image !is null) hBitmap = image.handle; 
    393381    OS.CreateCaret (hwnd, hBitmap, width, height); 
    394382    move (); 
    395383    setIMEFont (); 
    396     if (isVisible) OS.ShowCaret (hwnd); 
     384    if (isVisible_) OS.ShowCaret (hwnd); 
    397385} 
    398386 
     
    442430    } 
    443431    this.image = image; 
    444     if (isVisible && hasFocus ()) resize (); 
     432    if (isVisible_ && hasFocus ()) resize (); 
    445433} 
    446434 
    447435void setIMEFont () { 
    448436    if (!OS.IsDBLocale) return; 
    449     int hFont = 0
     437    HFONT hFont
    450438    if (font !is null) hFont = font.handle; 
    451     if (hFont is 0) hFont = defaultFont (); 
    452     int hwnd = parent.handle; 
    453     int hIMC = OS.ImmGetContext (hwnd); 
     439    if (hFont is null) hFont = defaultFont (); 
     440    auto hwnd = parent.handle; 
     441    auto hIMC = OS.ImmGetContext (hwnd); 
    454442    /* Save the current IME font */ 
    455443    if (oldFont is null) { 
    456         oldFont = OS.IsUnicode ? (LOGFONT) new LOGFONTW () : new LOGFONTA ()
     444        oldFont = new LOGFONT
    457445        if (!OS.ImmGetCompositionFont (hIMC, oldFont)) oldFont = null; 
    458446    } 
    459447    /* Set new IME font */ 
    460     LOGFONT logFont = OS.IsUnicode ? (LOGFONT) new LOGFONTW () : new LOGFONTA ()
    461     if (OS.GetObject (hFont, LOGFONT.sizeof, logFont) !is 0) { 
    462         OS.ImmSetCompositionFont (hIMC, logFont); 
     448    LOGFONT logFont
     449    if (OS.GetObject (hFont, LOGFONT.sizeof, &logFont) !is 0) { 
     450        OS.ImmSetCompositionFont (hIMC, &logFont); 
    463451    } 
    464452    OS.ImmReleaseContext (hwnd, hIMC); 
     
    483471    this.x = x;  this.y = y; 
    484472    moved = true; 
    485     if (isVisible && hasFocus ()) move (); 
     473    if (isVisible_ && hasFocus ()) move (); 
    486474} 
    487475 
     
    520508    this.width = width;  this.height = height; 
    521509    resized = true; 
    522     if (isVisible && hasFocus ()) resize (); 
     510    if (isVisible_ && hasFocus ()) resize (); 
    523511} 
    524512 
     
    560548public void setVisible (bool visible) { 
    561549    checkWidget(); 
    562     if (visible is isVisible) return; 
    563     isVisible = visible; 
    564     int hwnd = parent.handle; 
     550    if (visible is isVisible_) return; 
     551    isVisible_ = visible; 
     552    auto hwnd = parent.handle; 
    565553    if (OS.GetFocus () !is hwnd) return; 
    566     if (!isVisible) { 
     554    if (!isVisible_) { 
    567555        OS.HideCaret (hwnd); 
    568556    } else { 
     
    577565 
    578566} 
    579 ++/