Boost logo

Boost :

From: E. Gladyshev (egladysh_at_[hidden])
Date: 2003-07-25 15:36:07


The library itself would be portable, the physical
layer (Win32 or else) is specified as a data type with
a bunch of static functions. It is similar to data
type traits in STL. In other words the physical layer
is a data type that is used as a template parameter.
If you need to adopt the GUI/GDI template library to
another system, all you'll need to do is to create a
data type which defines the predefined traits.

Here is a simple example of the Bitmap and ImageList
templates and Win32 traits that demonstrates this
idea. Note: I have not tried to compile this code yet.

template < typename Tr = WinGdiTraits >
class Bitmap : public GdiObj< Tr::BitmapHnd, Tr >
{
public:
        _bool create( const Resource& r )
        {
                m_hnd = Traits::load_bitmap( r );
                if( !m_hnd ) return FALSE;
                return TRUE;
        }

        inline Size size( )
        {
                return Traits::get_bmpsize( m_hnd );
        }
};

template < typename Tr=WinGdiTraits >
class ImageList : public GdiObj< Tr::ImageListHnd, Tr
>
{
public:
        typedef int iterator;

        _bool create( const Resource& r, const Color&
transp_color, int imgnum )
        {
                Bitmap<Tr> bmp;
                if( !bmp.create(r) ) return FALSE;
                m_hnd = Traits::create_imglist( bmp, transp_color,
bmp.size()/imgnum );
                if( !m_hnd ) return FALSE;
                return TRUE;
        }

        inline iterator begin () { return 0; }
        inline iterator end () { return size(); }
        inline int size () { return
Traits::get_imglist_size( m_hnd ); }
};

        // Win32 traits
        //=============

class WinTypes
{
public:
        typedef HWND WinHnd;
        typedef HGDIOBJ GdiHnd;
        typedef HBITMAP BitmapHnd;
        typedef HIMAGELIST ImageListHnd;

        typedef SIZE Size;
        typedef POINT Point;
        typedef RECT Rect;

        typedef WinRes Resource;

        typedef COLORREF Color;
};

//----
class WinGdiTraits : public WinTypes
{
public:
        typedef GdiHnd Hnd;

        static void destroy ( Hnd h ) { ::DeleteObject( h
); }
        static void destroy ( BitmapHnd h ) {
::DeleteObject( (Hnd)h ); }
        static void destroy ( ImageListHnd h ) {
::ImageList_Destroy( h ); }

        //bitmap functions
        static BitmapHnd load_bitmap( const Resource& r )
        {
                return ::LoadBitmap( r.m_hinst, r.m_res }
        }
        static Size get_bmpsize( BitmapHnd h )
        {
                Size s;
                BITMAP bmp;
                assert( h );
                ::GetObject( h, sizeof(BITMAP), &bmp);
                s.cx = bmp.bmWidth;
                s.cy = gmp.bmHeight;
                return s;
        }

        //image list
        static ImageListHnd create_imglist( BitmapHnd hb,
const Color& transp_color, int image_cx )
        {
                ImageListHnd h;
                Size s;
                get_bmpsize( hb, s );

                h = ImageList_Create( image_cx, s.cy, ILC_MASK |
ILC_COLOR32, 0, 1);
                if( !h ) return NULL;

                // Add the bitmap into the image list
                ImageList_AddMasked( h, hb, transp_color );

                return h;
        }

        static int get_imglist_size( ImageListHnd h )
        {
                return ImageList_GetImageCount( h );
        }
};

Eugene

--- iad929 <iad929_at_[hidden]> wrote:
> Do you mean that your librry is directed to MS
> Windows?
>
>
> Mohammed
> ----- Original Message -----
> From: E. Gladyshev <egladysh_at_[hidden]>
> To: <boost_at_[hidden]>
> Sent: Friday, July 25, 2003 9:11 PM
> Subject: [boost] GUI/GDI template library
>
>
> > I was thinking about designing a GUI/GDI template
> > library.
> >
> > The main ideas are:
> > 1. Create a portable template abstraction for
> standard
> > GUI/GDI elements and dialog boxes.
> > 2. Design an "iterator-like" interface.
> > 3. The most important goal is design a natural
> > connection between STL containers and GUI
> elements, so
> > that STL data can be easily presented in the GUI
> > environment.
> >
> > For example
> > template < typename IT, typename PhysicalGuiLayer
> >
> > class ListControl
> > {
> > public:
> > template < typename Filter, typename Format >
> > void push_back( IT& FirstIt,
> > IT& EndIt,
> > Filter& filter,
> > Format& format )
> > {
> > for( IT it = FirstIt; it < EndIt; ++it )
> > {
> > if( filter(it) )
> > {
> >
> sicalGuiLayer::list_add_item(
> > m_hnd,
> > format.get_list_item(it)
> > );
> > }
> > }
> > }
> > };
> >
> > Does something similar exist already?
> > It seems like a challenging project. If anybody is
> > interested, let me know.
> >
> > Eugene
> >
> >
> > __________________________________
> > Do you Yahoo!?
> > Yahoo! SiteBuilder - Free, easy-to-use web site
> design software
> > http://sitebuilder.yahoo.com
> > _______________________________________________
> > Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>
>
>
> _______________________________________________
> Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk