/*
* MdiChild.h
* Copyright (c) 2011 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// SOL++2000
// 2000.02.18
#pragma once
#include <sol\Composite.h>
#include <sol\Menubar.h>
#include <sol\MdiFrame.h>
#include <sol\MdiClient.h>
namespace SOL {
class MdiChild :public Composite {
private:
MenuBar* menuBar;
int subMenuId;
protected:
virtual long size(Event& event)
{
defaultProc(event);
justifyScrollRange();
return NULL;
}
protected:
virtual long mdiActivate(Event& event)
{
MdiClient* mdiClient = (MdiClient*)getParent();
MdiFrame* mdiFrame = (MdiFrame*)mdiClient->getParent();
HMENU hmenu = NULL;
HMENU subMenu = NULL;
WPARAM wParam = event.getWParam();
HWND active = (HWND)event.getLParam();
if(active == getWindow()) {
hmenu = menuBar -> get();
subMenu = ::GetSubMenu(hmenu, subMenuId);
}
else {
hmenu = mdiFrame-> getMenuBar() -> get();
subMenu = ::GetSubMenu(hmenu, mdiFrame -> getSubMenuId());
}
mdiClient -> setMenu(hmenu, subMenu);
::DrawMenuBar(mdiFrame->getWindow());
return NULL;
}
protected:
long destroy(Event& event)
{
MdiClient* mdiClient = (MdiClient*)getParent();
if(mdiClient) {
mdiClient -> destroy(event);
}
return NULL;
}
long defaultProc(Event& event)
{
return ::DefMDIChildProc(getWindow(),
event.getMessage(),
event.getWParam(),
event.getLParam());
}
public:
MdiChild(): Composite() { }
public:
MdiChild(MdiClient* parent, const TCHAR* title, Args& args)
:Composite(parent)
{
TCHAR* className = (TCHAR*)args.get(XmNclassName);
if(className == NULL) {
className = _T("MdiChild");
args.set(XmNclassName, className);
}
//Application::
registerClass(args);
MDICREATESTRUCT cs;
cs.szClass = className;
cs.szTitle = title;
cs.hOwner = GetModuleHandle(NULL);//Application::getInstance();
cs.x = (int) args.get(XmNx),
cs.y = (int) args.get(XmNy),
cs.cx = (int) args.get(XmNwidth),
cs.cy = (int) args.get(XmNheight),
cs.style = args.get(XmNstyle);
cs.lParam = NULL;
HWND hwnd = (HWND)parent -> send(WM_MDICREATE, 0, (LONG)&cs);
setWindow(hwnd);
Application::add(hwnd, this);
const TCHAR* menuName = (TCHAR*) args.get(XmNmenuName);
if(!menuName) {
menuName = title;
}
menuBar = new MenuBar(this, menuName);
subMenuId = (int) args.get(XmNmenuId);
setValues(args);
addEventHandler(WM_MDIACTIVATE, this,
(Handler)&MdiChild::mdiActivate, NULL);
addEventHandler(WM_MDIDESTROY, this,
(Handler)&MdiChild::destroy, NULL);
addEventHandler(WM_SIZE, this,
(Handler)&MdiChild::size, NULL);
addCallback(XmNhorizScrollCallback, (Key)hwnd, this,
(Callback)&Composite::doHorizScroll, NULL);
addCallback(XmNvertScrollCallback, (Key)hwnd, this,
(Callback)&Composite::doVertScroll, NULL);
parent -> activate(this);
}
public:
Boolean MdiChild::create(MdiClient* parent, const TCHAR* title, Args& args)
{
Boolean rc = False;
View::setParent(parent);
TCHAR* className = (TCHAR*)args.get(XmNclassName);
if(className == NULL) {
className = _T("MdiChild");
args.set(XmNclassName, className);
}
registerClass(args);
MDICREATESTRUCT cs;
cs.szClass = className;
cs.szTitle = title;
cs.hOwner = GetModuleHandle(NULL);//Application::getInstance();
cs.x = (int) args.get(XmNx),
cs.y = (int) args.get(XmNy),
cs.cx = (int) args.get(XmNwidth),
cs.cy = (int) args.get(XmNheight),
cs.style = args.get(XmNstyle);
cs.lParam = NULL;
HWND hwnd = (HWND)parent -> send(WM_MDICREATE, 0, (LONG)&cs);
if (hwnd) {
rc = True;
setWindow(hwnd);
Application::add(hwnd, this);
const TCHAR* menuName = (TCHAR*) args.get(XmNmenuName);
if(!menuName) {
menuName = title;
}
menuBar = new MenuBar(this, menuName);
subMenuId = (int) args.get(XmNmenuId);
setValues(args);
addEventHandler(WM_MDIACTIVATE, this,
(Handler)&MdiChild::mdiActivate, NULL);
addEventHandler(WM_MDIDESTROY, this,
(Handler)&MdiChild::destroy, NULL);
addEventHandler(WM_SIZE, this,
(Handler)&MdiChild::size, NULL);
addCallback(XmNhorizScrollCallback, (Key)hwnd, this,
(Callback)&Composite::doHorizScroll, NULL);
addCallback(XmNvertScrollCallback, (Key)hwnd, this,
(Callback)&Composite::doVertScroll, NULL);
parent -> activate(this);
}
return rc;
}
public:
MenuBar* getMenuBar() { return menuBar; }
public:
void setViewId(int vid)
{
int id = (int)getWindowLong(GWL_ID);
setId(id);
}
public:
MdiFrame* getMdiFrame()
{
View* parent = getParent();
MdiFrame* frame = NULL;
if(parent) {
frame = (MdiFrame*)(parent->getParent());
}
return frame;
}
};
}
|