SOL9 Sample: Tab

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * Tab.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\tab.h>
#include <sol\stdio.h>
#include <sol\DrawingArea.h>
#include <sol/Pen.h>
#include "resource.h"

namespace SOL {

class Canvas : public DrawingArea {
private:
  int shape;

public:
  Canvas()
  {
  }

public:
  /**
   * Constructor
   */
  Canvas(View* parent, const TCHAR* name, Args& args)
  :DrawingArea(parent, name, args) 
  {
    shape = 0;
    addCallback(XmNexposeCallback, this,
      (Callback)&Canvas::expose, NULL);
  }


private:
  void expose(Action& action)
  {
    int  i;
    DC* dc = (DC*)action.getValue();
    switch(shape) {
    case 0:
      for(i = 0; i<30; i++) {
        dc->select(GetStockObject(NULL_BRUSH));

        dc->rectangle(10, 10, 10+10*i, 10+10*i);
      }
      break;
    case 1:
      for(i = 0; i<30; i++) {
        dc->select(GetStockObject(NULL_BRUSH));
        dc->ellipse(10, 10, 10+10*i, 10+10*i);
      }
      break;
    case 2:
      for(i = 0; i<30; i++) {
        dc->moveTo(10, 10);
        dc->lineTo(300, 10+10*i);
      }
      for(i = 0; i<30; i++) {
        dc->moveTo(10, 10);
        dc->lineTo(10+10*i, 300);
      }

      break;

    default:
      break;
    }
  }

public:
  Boolean create(View* parent, const TCHAR* name, Args& args)
  {
    Boolean rc = DrawingArea::create(parent, name, args); 

    shape = 0;
    addCallback(XmNexposeCallback, this,
      (Callback)&Canvas::expose, NULL);

    return rc;
  }

  
public:
  void setShapeType(int type)
  {
    shape = type;
    //invalidate(NULL);
    update(NULL);
  }

};

// 
class AppView :public ApplicationView {
private:
  Tab    tab;
  Canvas  canvas;

private:
  long size(Event& event) 
  {
    LPARAM l = event.getLParam();
    tab.reshape(10, 10, LOWORD(l)-20, HIWORD(l)-20);
    RECT r;
    tab.getClientRect(&r);
    canvas.reshape(10, 50, r.right -20, r.bottom -60);
    return 0;
  }

private:
  void select(Action& action)
  {
    int indx = tab.getCurFocus();
    canvas.setShapeType(indx);
  }

public:
  AppView(Application& applet, const TCHAR* label, Args& args)
  :ApplicationView(applet, label, 
    args.set(XmNbackground, (ulong)(COLOR_BTNFACE+1)))
  {
    Args ar;
    ar.reset();
    tab.create(this, NULL, ar);
    tab.setItemSize(50, 20);

    ar.reset();
    ar.set(XmNexStyle, (ulong)WS_EX_CLIENTEDGE);
    canvas.create(&tab, NULL, ar);

    static TCHAR* tabLabels[] = {
      _T("Rectangle"), _T("Circle"), _T("Line"),
    };

    for(int i = 0; i<XtNumber(tabLabels); i++) {
         tab.addItem(tabLabels[i]);
    }

    tab.setCurFocus(0);
    tab.addCallback(XmNselChangeCallback, this,
      (Callback)&AppView::select, NULL);
    canvas.setShapeType(0);
    
    addCallback(XmNmenuCallback, IDM_EXIT, this,
      (Callback)&AppView::exit, NULL);
  }
};

}

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

    Args args;
    AppView appview(applet, name, args);
    appview.realize();

    applet.run();

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


Last modified: 1 Feb 2017

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