Changeset 59

Show
Ignore:
Timestamp:
03/30/08 22:04:08 (7 months ago)
Author:
Chris Miller
Message:

Added ImageList?.images.addStrip.
More ToolBar? changes.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/win32/dfl/imagelist.d

    r47 r59  
    3434         
    3535         
     36        final void addStrip(Image img) 
     37        { 
     38            HGDIOBJ hgo; 
     39            if(1 != img._imgtype(&hgo)) 
     40            { 
     41                debug 
     42                { 
     43                    assert(0, "Image list: addStrip needs bitmap"); 
     44                } 
     45                _unableimg(); 
     46            } 
     47             
     48            auto sz = imageSize; 
     49            if(img.height != sz.height 
     50                || img.width % sz.width) 
     51            { 
     52                debug 
     53                { 
     54                    assert(0, "Image list: invalid image size"); 
     55                } 
     56                _unableimg(); 
     57            } 
     58            int num = img.width / sz.width; 
     59             
     60            /+ 
     61            if(1 == num) 
     62            { 
     63                add(img); 
     64                return; 
     65            } 
     66            +/ 
     67             
     68            auto _hdl = handle; // _addhbitmap needs the handle! Could avoid this in the future. 
     69            _addhbitmap(hgo); 
     70             
     71            int x = 0; 
     72            for(; num; num--) 
     73            { 
     74                auto sp = new StripPart(); 
     75                sp.origImg = img; 
     76                sp.hbm = hgo; 
     77                sp.partBounds = Rect(x, 0, sz.width, sz.height); 
     78                 
     79                _images ~= sp; 
     80                 
     81                x += sz.width; 
     82            } 
     83        } 
     84         
     85         
    3686        package: 
    3787         
    3888        Image[] _images; 
     89         
     90         
     91        static class StripPart: Image 
     92        { 
     93            override Size size() // getter 
     94            { 
     95                return partBounds.size; 
     96            } 
     97             
     98             
     99            override void draw(Graphics g, Point pt) 
     100            { 
     101                HDC memdc; 
     102                memdc = CreateCompatibleDC(g.handle); 
     103                try 
     104                { 
     105                    HGDIOBJ hgo; 
     106                    hgo = SelectObject(memdc, hbm); 
     107                    BitBlt(g.handle, pt.x, pt.y, partBounds.width, partBounds.height, memdc, partBounds.x, partBounds.y, SRCCOPY); 
     108                    SelectObject(memdc, hgo); // Old bitmap. 
     109                } 
     110                finally 
     111                { 
     112                    DeleteDC(memdc); 
     113                } 
     114            } 
     115             
     116             
     117            override void drawStretched(Graphics g, Rect r) 
     118            { 
     119                HDC memdc; 
     120                memdc = CreateCompatibleDC(g.handle); 
     121                try 
     122                { 
     123                    HGDIOBJ hgo; 
     124                    int lstretch; 
     125                    hgo = SelectObject(memdc, hbm); 
     126                    lstretch = SetStretchBltMode(g.handle, COLORONCOLOR); 
     127                    StretchBlt(g.handle, r.x, r.y, r.width, r.height, 
     128                        memdc, partBounds.x, partBounds.y, partBounds.width, partBounds.height, SRCCOPY); 
     129                    SetStretchBltMode(g.handle, lstretch); 
     130                    SelectObject(memdc, hgo); // Old bitmap. 
     131                } 
     132                finally 
     133                { 
     134                    DeleteDC(memdc); 
     135                } 
     136            } 
     137             
     138             
     139            Image origImg; // Hold this so the HBITMAP doesn't get collected. 
     140            HBITMAP hbm; 
     141            Rect partBounds; 
     142        } 
    39143         
    40144         
     
    146250        assert(!isHandleCreated); 
    147251         
     252        assert(sz.width && sz.height); 
     253         
    148254        _w = sz.width; 
    149255        _h = sz.height; 
     
    298404     
    299405     
    300     void _addimg(Image img) 
     406    int _addimg(Image img) 
    301407    { 
    302408        assert(isHandleCreated); 
     
    307413        { 
    308414            case 1: 
    309                 { 
    310                     COLORREF cr; 
    311                     if(_transcolor == Color.empty 
    312                         || _transcolor == Color.transparent) 
    313                     { 
    314                         cr = CLR_NONE; // ? 
    315                     } 
    316                     else 
    317                     { 
    318                         cr = _transcolor.toRgb(); 
    319                     } 
    320                     result = imageListAddMasked(_hil, cast(HBITMAP)hgo, cr); 
    321                 } 
     415                result = _addhbitmap(hgo); 
    322416                break; 
    323417             
     
    332426        //if(-1 == result) 
    333427        //  _unableimg(); 
     428        return result; 
     429    } 
     430     
     431    int _addhbitmap(HBITMAP hbm) 
     432    { 
     433        assert(isHandleCreated); 
     434         
     435        COLORREF cr; 
     436        if(_transcolor == Color.empty 
     437            || _transcolor == Color.transparent) 
     438        { 
     439            cr = CLR_NONE; // ? 
     440        } 
     441        else 
     442        { 
     443            cr = _transcolor.toRgb(); 
     444        } 
     445        return imageListAddMasked(_hil, cast(HBITMAP)hbm, cr); 
    334446    } 
    335447} 
  • trunk/win32/dfl/internal/winapi.d

    r58 r59  
    20882088        TB_BUTTONSTRUCTSIZE = WM_USER + 30, 
    20892089        TB_SETBUTTONSIZE = WM_USER + 31, 
     2090        TB_AUTOSIZE = WM_USER + 33, 
    20902091        TB_SETIMAGELIST = WM_USER + 48, 
    20912092        TB_INSERTBUTTONW = WM_USER + 67, 
    20922093        TB_ADDBUTTONSW = WM_USER + 68, 
     2094        TB_SETPADDING = WM_USER + 87, 
    20932095    } 
    20942096     
  • trunk/win32/dfl/toolbar.d

    r58 r59  
    568568        prevwproc(TB_BUTTONSTRUCTSIZE, TBBUTTON.sizeof, 0); 
    569569         
     570        //prevwproc(TB_SETPADDING, 0, MAKELPARAM(0, 0)); 
     571         
    570572        if(_imglist) 
    571573            prevwproc(TB_SETIMAGELIST, 0, cast(WPARAM)_imglist.handle); 
     
    575577            _ins(idx, tbb); 
    576578        } 
     579         
     580        //prevwproc(TB_AUTOSIZE, 0, 0); 
    577581    } 
    578582     
     
    619623        if(dfl.internal.utf.useUnicode) 
    620624        { 
    621             xtb.iString = cast(typeof(xtb.iString))dfl.internal.utf.toUnicodez(tbb._text); 
     625            if(tbb._text.length) 
     626                xtb.iString = cast(typeof(xtb.iString))dfl.internal.utf.toUnicodez(tbb._text); 
    622627            //prevwproc(TB_ADDBUTTONSW, 1, cast(LPARAM)&xtb); 
    623628            lresult = prevwproc(TB_INSERTBUTTONW, idx, cast(LPARAM)&xtb); 
     
    625630        else 
    626631        { 
    627             xtb.iString = cast(typeof(xtb.iString))dfl.internal.utf.toAnsiz(tbb._text); 
     632            if(tbb._text.length) 
     633                xtb.iString = cast(typeof(xtb.iString))dfl.internal.utf.toAnsiz(tbb._text); 
    628634            //prevwproc(TB_ADDBUTTONSA, 1, cast(LPARAM)&xtb); 
    629635            lresult = prevwproc(TB_INSERTBUTTONA, idx, cast(LPARAM)&xtb);