SOL9 Sample: IconList

SOL9 2.0 Samples

1 Screenshot


2 Source code

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


// SOL++2000
// 2000.02.18

#include <sol\ApplicationView.h>
#include <sol\OwnerDrawListBox.h>
#include <sol\Icon.h>
#include "resource.h"

namespace SOL {

class IconList :public ApplicationView {
  OwnerDrawListBox  listbox;
  int    num;
  Icon*  icons[10];


public:
  /**
   * Constructor
   */
  IconList(Application& applet, const TCHAR* name, Args& args)
  :ApplicationView(applet, name, args)
  {
    addEventHandler(WM_CLOSE, this,
      (Handler)&IconList::close, NULL);

    addEventHandler(WM_DRAWITEM, this,
      (Handler)&IconList::drawItem, NULL);
    addEventHandler(WM_MEASUREITEM, this,
      (Handler)&IconList::measureItem, NULL);
    addEventHandler(WM_DELETEITEM, this,
      (Handler)&IconList::deleteItem, NULL);
    addEventHandler(WM_COMPAREITEM, this,
      (Handler)&IconList::compareItem, NULL);

    Args ar;
    ar.set(XmNstyle, (ulong)WS_HSCROLL|LBS_SORT|LBS_MULTICOLUMN);
    listbox.create(this, _T(""), ar);
  // Add this listbox to the defaultLayoutManager.
    add(listbox);

    int width = ::GetSystemMetrics(SM_CXICON);
    listbox.setColumnWidth(width*3);

    num = 0;
    icons[num++] = new Icon(_T("Application"),LoadIcon(NULL,IDI_APPLICATION));
    icons[num++] = new Icon(_T("Asterisk"),LoadIcon(NULL,IDI_ASTERISK));
    icons[num++] = new Icon(_T("Exclamation"),LoadIcon(NULL,IDI_EXCLAMATION));
    icons[num++] = new Icon(_T("Hand"),  LoadIcon(NULL,IDI_HAND));
    icons[num++] = new Icon(_T("Question"), LoadIcon(NULL,IDI_QUESTION));
    for(int i = 0; i<num; i++) {
      listbox.add(icons[i]);
    }
    addCallback(XmNmenuCallback, IDM_EXIT, this,
      (Callback)&IconList::exit, NULL);
  }

private:
  long close(Event& event)
  {
    listbox.resetContent();
    return defaultProc(event);
  }


  long compareItem(Event& event)
  {
    LPARAM lParam = event.getLParam();
    LPCOMPAREITEMSTRUCT ptr = (LPCOMPAREITEMSTRUCT)lParam;

    Icon* icon1 = (Icon*)(LPSTR) ptr -> itemData1;
    Icon* icon2 = (Icon*)(LPSTR) ptr -> itemData2;

    return strcmp(icon1->getName(), icon2->getName());
  }


  long deleteItem(Event& event)
  {
    LPARAM lParam = event.getLParam();
    LPDELETEITEMSTRUCT ptr = (LPDELETEITEMSTRUCT)lParam;
    Icon* icon = (Icon*)ptr->itemData;
    delete icon;
    return TRUE;
  }


  long drawItem(Event& event)
  {
    LPARAM lParam = event.getLParam();
    LPDRAWITEMSTRUCT ptr = (LPDRAWITEMSTRUCT)lParam;
    if(ptr->itemAction == ODA_DRAWENTIRE) {
      RECT rc    = ptr->rcItem;
      Icon* icon = (Icon*) ptr->itemData;
      icon -> draw(ptr->hDC, rc.left+20, rc.top+4);
    }
    return TRUE;
  }


  long measureItem(Event& event)
  {
    LPARAM lParam = event.getLParam();
    LPMEASUREITEMSTRUCT ptr = (LPMEASUREITEMSTRUCT)lParam;
    int height = ::GetSystemMetrics(SM_CYICON);
    ptr -> itemHeight = height*2;
    return TRUE;
  }

};

}


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

    Args  args;
    IconList iconList(applet, name, args);
    iconList.realize();

    applet.run();

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


Last modified: 1 Feb 2017

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