SOL9 Sample: HyperlinkView

SOL9 2.0 Samples

1 Screenshot


2 Source code

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



// SOL9 
// 2008/09/15



#include <sol\ApplicationView.h>
#include <sol\Hyperlink.h>
#include "resource.h"

namespace SOL {

class HyperlinkView :public ApplicationView {
private:
  Hyperlink link[10];
  int      count;
private:

  long paint(Event& event)
  {
    PaintDC pdc(this);
    for (int i = 0; i<count; i++) {
      link[i].draw(&pdc);
    }
    return 0L;
  }

public:
  long mouseMove(Event& event) {
    //
    LPARAM lParam = event.getLParam();
    int x = (int)LOWORD(lParam);
    int y = (int)HIWORD(lParam);

    for (int i = 0; i<count; i++) {
      if (link[i].isMouseOver(x, y)) {
        break;
      }
    }  

    return 0;
  }

public:
  long lButtonDown(Event& event) {
    //
    LPARAM lParam = event.getLParam();
    int x = (int)LOWORD(lParam);
    int y = (int)HIWORD(lParam);
    for (int i = 0; i<count; i++) {
      if (link[i].isMouseOver(x, y)) {
        break;
      }
    }  

    return 0;
  }

public:
  long lButtonUp(Event& event) {
    //
    LPARAM lParam = event.getLParam();
    int x = (int)LOWORD(lParam);
    int y = (int)HIWORD(lParam);

    for (int i = 0; i<count; i++) {
      if (link[i].isMouseOver(x, y)) {
        link[i].execute();
        break;
      }
    }  
    return 0;
  }


public:

  /**
   * Constructor
   */
  HyperlinkView(Application& applet, const TCHAR* label, Args& args)
    :ApplicationView(applet, label, args)
  {
    count =0;
    Args ar;
    ar.set(XmNx, 10);
    ar.set(XmNy, 10);
    ar.set(XmNlink, _T("http://www.microsoft.com/"));
    link[count++].create(this, _T("Microsoft Corporation"), ar);

    ar.reset();
    ar.set(XmNx, 10);
    ar.set(XmNy, 10+40*count);
    ar.set(XmNlink, _T("http://www.google.com/"));
    link[count++].create(this, _T("Google"), ar);

    ar.reset();
    ar.set(XmNx, 10);
    ar.set(XmNy, 10+40*count);
    ar.set(XmNlink, _T("http://www.yahoo.com/"));
    link[count++].create(this, _T("Yahoo"), ar);

    ar.reset();
    ar.set(XmNx, 10);
    ar.set(XmNy, 10+40*count);
    ar.set(XmNlink, _T("http://www.apple.com/"));
    link[count++].create(this, _T("Apple Computer"), ar);

    ar.reset();
    ar.set(XmNx, 10);
    ar.set(XmNy, 10+40*count);
    ar.set(XmNlink, _T("http://www.asahi.com/"));
    link[count++].create(this, _T("Asahi Shimbun"), ar);

    ar.reset();
    ar.set(XmNx, 10);
    ar.set(XmNy, 10+40*count);
    ar.set(XmNlink, _T("http://www.antillia.com/"));
    link[count++].create(this, _T("Antilia.com"), ar);

    addEventHandler(WM_PAINT, this, (Handler)&HyperlinkView::paint, NULL);

    addEventHandler(WM_MOUSEMOVE, this, 
      (Handler)&HyperlinkView::mouseMove, NULL);
    addEventHandler(WM_LBUTTONDOWN, this, 
      (Handler)&HyperlinkView::lButtonDown, NULL);
    addEventHandler(WM_LBUTTONUP, this, 
      (Handler)&HyperlinkView::lButtonUp, NULL);

    addCallback(XmNmenuCallback, IDM_EXIT, this,
      (Callback)&HyperlinkView::exit, NULL);

    restorePlacement();
  }
};

}

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

    Args args;
    HyperlinkView linkView(applet, name, args);
    linkView.realize();
    applet.run();

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


Last modified: 1 Feb 2017

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