/*
* Anchor.h
* Copyright (c) 2011 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// SOL++2000
// 2000.02.18
// SOL++2000
// 2000.02.18
#pragma once
#include <sol\Primitive.h>
#include <sol\Resource.h>
#include <sol\BitmapFile.h>
#include <sol\Anchor.h>
#include <sol\Bitmap.h>
#include <sol\Icon.h>
#include <sol\PaintDC.h>
#include <sol\ClientDC.h>
#include <shellapi.h>
#include <sol/UnderlineFont.h>
#include <sol/String.h>
namespace SOL {
class Anchor :public Primitive {
private:
// int labelType;
int width;
int height;
BOOL recomputeSize;
UnderlineFont ufont;
String url;
protected:
long leftButtonUp(Event& event)
{
//MessageBox(NULL, (const TCHAR*)url, _T("DEBUG"), MB_OK);
if ((const TCHAR*)url) {
SHELLEXECUTEINFO sei;
::ZeroMemory(&sei, sizeof(SHELLEXECUTEINFO));
sei.cbSize = sizeof(SHELLEXECUTEINFO);
sei.lpFile = (const TCHAR*)url;
sei.nShow = SW_SHOWNORMAL;
::ShellExecuteEx(&sei);
}
return 0L;
}
protected:
long size(Event& event)
{
int x, y, w, h;
getGeometry(x, y, w, h);
if(recomputeSize == TRUE) {
reshape(x, y, width, height);
}
return NULL;
}
protected:
long paint(Event& event)
{
int x, y;
int w, h;
PaintDC pdc(this);
getGeometry(x, y, w, h);
RECT rect;
getWindowRect(&rect);
HDC hdc = pdc.get();
TCHAR text[256];
getText(text, 256);
pdc.setBkMode(TRANSPARENT);
Size size;
HFONT hfont = ufont.getFont();
hfont = (HFONT)pdc.select(hfont);
pdc.setTextColor(RGB(128, 128, 255));
DWORD ext = pdc.getTextExtent(text, strlen(text), &size);
int hh = size.cy;
int ww = size.cx;
pdc.textOut(2, (h-hh)/2, text, strlen(text));
pdc.select(hfont);
return 0L;
}
public:
Anchor():Primitive()
{
url = _T("");
}
public:
/**
* Constructor
*/
Anchor(View* parent, const TCHAR* name, Args& args)
:Primitive(parent, name,
args.set(XmNstyle, (ulong)WS_GROUP)
.set(XmNbackground, (ulong)GetStockObject(NULL_BRUSH))
.set(XmNclassName, _T("Anchor"))
.set(XmNuseDefaultFont, _T("false"))
.set(XmNclassStyle, (ulong)CS_VREDRAW|CS_HREDRAW)
.set(XmNcursor, (ulong)LoadCursor(NULL, IDC_HAND)))
{
addEventHandler(WM_PAINT, this,
(Handler)&Anchor::paint, NULL);
addEventHandler(WM_SIZE, this,
(Handler)&Anchor::size, NULL);
addEventHandler(WM_LBUTTONUP, this,
(Handler)&Anchor::leftButtonUp, NULL);
recomputeSize = TRUE;
url = _T("");
setValues(args);
ufont.create(9);
}
public:
~Anchor()
{
}
public:
virtual Boolean create(View* parent, const TCHAR* name, Args& args)
{
Boolean rc = Primitive::create(parent, name,
args.set(XmNstyle, (ulong)WS_GROUP)
.set(XmNbackground, (ulong)GetStockObject(NULL_BRUSH))
.set(XmNclassName, _T("Anchor"))
.set(XmNuseDefaultFont, "false")
.set(XmNclassStyle, (ulong)CS_VREDRAW|CS_HREDRAW)
.set(XmNcursor, (ulong)LoadCursor(NULL, IDC_HAND)) );
addEventHandler(WM_PAINT, this,
(Handler)&Anchor::paint, NULL);
addEventHandler(WM_SIZE, this,
(Handler)&Anchor::size, NULL);
addEventHandler(WM_LBUTTONUP, this,
(Handler)&Anchor::leftButtonUp, NULL);
recomputeSize = TRUE;
setValues(args);
ufont.create(9);
return rc;
}
public:
void getValues(Args& args)
{
Primitive::getValues(args);
int num = args.getCount();
Arg* arg = args.getArgList();
for (int j = 0; j<num; j++) {
const TCHAR* name = arg[j].name;
ulong* val = (ulong*)arg[j].value;
if(name == XmNrecomputeSize) {
*val = recomputeSize;
continue;
}
/*
if(name == XmNlabelType) {
*val = labelType;
continue;
}
*/
}
}
public:
void setValues(Args& args)
{
Primitive::setValues(args);
TCHAR label[256];
getText(label, 256);
url = _T("");
const TCHAR* turl = (const TCHAR*)args.get(XmNurl);
if (turl) {
url = turl;
}
ClientDC cdc(this);
HFONT hfont = ufont.getFont();
hfont = (HFONT)cdc.select(hfont);
Size size;
cdc.getTextExtent(label, strlen(label), &size);
if (hfont) {
cdc.select(hfont);
}
height = size.cy + 4;
width = size.cx + 4;
width++;
height++;
ulong val;
if (args.get(XmNrecomputeSize, &val)) {
recomputeSize = (BOOL)val;
}
if (recomputeSize == TRUE) {
send(WM_SIZE, 0, 0L);
}
update(NULL);
}
public:
void setAnchor(const TCHAR* label, const TCHAR* turl)
{
ClientDC cdc(this);
ulong val;
get(XmNinstance, &val);
Size size;
cdc.getTextExtent(label, strlen(label), &size);
height = size.cy + 4;
width = size.cx + 4;
if (turl) {
url = turl;
}
}
public:
const TCHAR* geUrl()
{
return (const TCHAR*)url;
}
public:
void getSize(int* width1, int* height1)
{
*width1 = width;
*height1 = height;
}
};
}
|