SOL9 Sample: ImageListView

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * ImageListView.cpp 
 * Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


// SOL++2000
// 2000.02.18

#include <sol\ApplicationView.h>
#include <sol\PaintDC.h>
#include <sol\Static.h>
#include <sol\ImageList.h>
#include "resource.h"

namespace SOL {

class ImageListView :public ApplicationView {
private:
  int      toppos;
  int      spacing;
  int      extent;
  int      draggingId;
  SmartPtr<ImageList> imglist;
  BOOL    dragging;
  Static    dropArea;

public:
  /**
   * Constructor
   */
  ImageListView(Application& applet, const TCHAR* label, Args& args)
  :ApplicationView(applet, label, args)
  {
    toppos = 20;
    spacing = 80;
    extent    = 32;

/*
#define ILC_MASK                0x00000001
#define ILC_COLOR               0x00000000
#define ILC_COLORDDB            0x000000FE
#define ILC_COLOR4              0x00000004
#define ILC_COLOR8              0x00000008
#define ILC_COLOR16             0x00000010
#define ILC_COLOR24             0x00000018
#define ILC_COLOR32             0x00000020
#define ILC_PALETTE             0x00000800      // (not implemented)
#if (_WIN32_WINNT >= 0x0501)
#define ILC_MIRROR              0x00002000    
#define ILC_PERITEMMIRROR       0x00008000   
#endif
#if _WIN32_WINNT >= 0x0600
#define ILC_ORIGINALSIZE        0x00010000 
#define ILC_HIGHQUALITYSCALE    0x00020000 
#endif
*/
    //2008/07/15
    imglist = new ImageList(extent, extent, ILC_COLORDDB|ILC_MASK, 5, 1);
    //imglist = new ImageList(extent, extent, ILC_COLOR32, 5, 1);

    //imglist = new ImageList(extent, extent, TRUE, 5, 1);

    imglist -> addIcon(LoadIcon(NULL,IDI_APPLICATION));
  
    imglist -> addIcon(LoadIcon(NULL,IDI_ASTERISK));
    imglist -> addIcon(LoadIcon(NULL,IDI_EXCLAMATION));
    imglist -> addIcon(LoadIcon(NULL,IDI_HAND));
    imglist -> addIcon(LoadIcon(NULL,IDI_QUESTION));
  
      dragging = FALSE;
    
    Args ar;
    ar.set(XmNexStyle, (ulong)WS_EX_CLIENTEDGE);
    ar.set(XmNstyle, (ulong)WS_BORDER|SS_ICON);
    dropArea.create(this, _T(""), ar);

    addEventHandler(WM_LBUTTONDOWN, this, 
      (Handler)&ImageListView::leftButtonDown, NULL);

    addEventHandler(WM_LBUTTONUP, this, 
      (Handler)&ImageListView::leftButtonUp, NULL);

    addEventHandler(WM_MOUSEMOVE, this, 
      (Handler)&ImageListView::mouseMove, NULL);

    addEventHandler(WM_PAINT, this, 
      (Handler)&ImageListView::paint, NULL);
    
    addCallback(XmNmenuCallback, IDM_EXIT, this,
      (Callback)&ImageListView::exit, NULL);
  }

public:
  ~ImageListView()
  {
  }

private:
  long ImageListView::size(Event& event) 
  {
    LPARAM l = event.getLParam();
    dropArea.reshape(2, 100, 100, 100); 
    return 0;
  }

/*
#define ILD_NORMAL              0x00000000
#define ILD_TRANSPARENT         0x00000001
#define ILD_MASK                0x00000010
#define ILD_IMAGE               0x00000020
#if (_WIN32_IE >= 0x0300)
#define ILD_ROP                 0x00000040
#endif
#define ILD_BLEND25             0x00000002
#define ILD_BLEND50             0x00000004
#define ILD_OVERLAYMASK         0x00000F00
#define INDEXTOOVERLAYMASK(i)   ((i) << 8)
#define ILD_PRESERVEALPHA       0x00001000  // This preserves the alpha channel in dest
#define ILD_SCALE               0x00002000  // Causes the image to be scaled to cx, cy instead of clipped
#define ILD_DPISCALE            0x00004000
#if _WIN32_WINNT >= 0x0600
#define ILD_ASYNC               0x00008000
#endif

#define ILD_SELECTED            ILD_BLEND50
#define ILD_FOCUS               ILD_BLEND25
#define ILD_BLEND               ILD_BLEND50
 */
private:
  long paint(Event& event)
  {
    PaintDC pdc(this);
    int num = imglist->getImageCount();

    for(int i = 0; i<num; i++) {
       imglist -> draw(i, &pdc, spacing*i, toppos, ILD_NORMAL);
       //imglist -> draw(i, &pdc, spacing*i, toppos, ILD_BLEND50);
    }
    return 0L;
  }

private:
  long leftButtonDown(Event& event) 
  {
    POINT pt;
    LPARAM l = event.getLParam();
    pt.x = LOWORD(l);
    pt.y = HIWORD(l);

    draggingId = -1;
    int num = imglist->getImageCount();

    for(int i = 0; i<num; i++) {
      RECT rc;
      rc.left = spacing*i;
      rc.top  = toppos;
      rc.right = rc.left+extent;
      rc.bottom = rc.top+extent;
      POINT px = pt;
      if(PtInRect(&rc, px) && dragging == FALSE) {
        dragging = TRUE;
        POINT hotSpot;
        hotSpot.x = (pt.x-rc.left);
        hotSpot.y = (pt.y-rc.top);
        imglist->beginDrag(i, hotSpot.x,hotSpot.y);

        showCursor(FALSE);
        capture();
    
        POINT xx = getCursorPosInWindow();
        imglist->dragEnter(this, xx.x, xx.y);
        dragging = TRUE;
        draggingId = i;
        break;
        }
    }
    return 0;
  }

private:
  long leftButtonUp(Event& event) 
  {
    if(dragging) {
      dragging = FALSE;
      releaseCapture();
      imglist->endDrag();
      showCursor(TRUE);
      POINT pt;
      getCursorPos(&pt);
      toClient(&pt);
      HWND child = childWindowFromPoint(pt);
      if(dropArea.isEqual(child)) {
        HICON hIcon = imglist->getIcon(draggingId,ILD_TRANSPARENT); 
        dropArea.setIcon(hIcon);
        dropArea.reshape(2, 100, 100, 100);

        dropArea.invalidate((RECT*)NULL);
        dropArea.update();
      }
      else {
        MessageBeep(MB_ICONHAND);
      }
    }
    return 0;
  }

private:
  long mouseMove(Event& event) 
  {
    if(dragging) {
      POINT pt = getCursorPosInWindow();
      imglist->dragMove(pt.x, pt.y);
    }
    return 0;
  }

private:
  POINT getCursorPosInWindow()
  {
    POINT pt;
    getCursorPos(&pt);
    RECT r;
    getWindowRect(&r);
    pt.x -= r.left;
    pt.y -= r.top;
    return pt;
  }
};

}

//
void  Main(int argc, TCHAR** argv)
{
  ModuleFileName module(argv[0]);
  const TCHAR* name = module.getFileName();
  try {
    Application applet(name, argc, argv);

    Args args;
    ImageListView imageListView(applet, name, args);
    imageListView.realize();

    applet.run();

  } catch (Exception& ex) {
    caught(ex);
  } catch (...) {
    caught(UnknownException());
  }
}


Last modified: 1 Feb 2017

Copyright (c) 2017 Antillia.com ALL RIGHTS RESERVED.