First import of xlaunch frontend for Xming
This commit is contained in:
parent
de5d24a200
commit
f02440dfa3
|
@ -0,0 +1,25 @@
|
||||||
|
|
||||||
|
Copyright (c) 2005 Alexander Gottwald
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
copy of this software and associated documentation files (the "Software"),
|
||||||
|
to deal in the Software without restriction, including without limitation
|
||||||
|
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||||
|
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
Except as contained in this notice, the name(s) of the above copyright
|
||||||
|
holders shall not be used in advertising or otherwise to promote the sale,
|
||||||
|
use or other dealings in this Software without prior written authorization.
|
||||||
|
|
|
@ -0,0 +1,79 @@
|
||||||
|
#
|
||||||
|
# Copyright (c) 2005 Alexander Gottwald
|
||||||
|
#
|
||||||
|
# Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
# copy of this software and associated documentation files (the "Software"),
|
||||||
|
# to deal in the Software without restriction, including without limitation
|
||||||
|
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
# and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
# Software is furnished to do so, subject to the following conditions:
|
||||||
|
#
|
||||||
|
# The above copyright notice and this permission notice shall be included in
|
||||||
|
# all copies or substantial portions of the Software.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
# THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||||
|
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
# DEALINGS IN THE SOFTWARE.
|
||||||
|
#
|
||||||
|
# Except as contained in this notice, the name(s) of the above copyright
|
||||||
|
# holders shall not be used in advertising or otherwise to promote the sale,
|
||||||
|
# use or other dealings in this Software without prior written authorization.
|
||||||
|
#
|
||||||
|
WINDRES=windres
|
||||||
|
|
||||||
|
TARGET=mingw
|
||||||
|
#DEBUG_FLAGS=-D_DEBUG
|
||||||
|
|
||||||
|
OS_FLAGS_mingw=-mno-cygwin
|
||||||
|
OS_FLAGS=$(OS_FLAGS_$(TARGET)) $(DEBUG_FLAGS)
|
||||||
|
|
||||||
|
X11_DIR_$(TARGET)=/usr/X11R6
|
||||||
|
X11_DIR_mingw=../../../../../exports
|
||||||
|
X11_DIR=$(X11_DIR_$(TARGET))
|
||||||
|
X11_INCLUDE=-I$(X11_DIR)/include
|
||||||
|
X11_LIBDIR=-L$(X11_DIR)/lib
|
||||||
|
X11_LIBS_$(TARGET)=-lX11
|
||||||
|
X11_LIBS_mingw=-lX11 -lwsock32
|
||||||
|
X11_LIBS=$(X11_LIBS_$(TARGET))
|
||||||
|
|
||||||
|
PROGRAMFILES:=$(shell cygpath -u $(PROGRAMFILES))
|
||||||
|
#MSXML_DIR=$(PROGRAMFILES)/MSXML 4.0
|
||||||
|
MSXML_DIR=$(PROGRAMFILES)/Microsoft XML Parser SDK
|
||||||
|
MSXML_INCLUDE="-I$(MSXML_DIR)/inc"
|
||||||
|
MSXML_LIBDIR="-L$(MSXML_DIR)/lib"
|
||||||
|
MSXML_LIBS=
|
||||||
|
|
||||||
|
|
||||||
|
CXXFLAGS=-g $(OS_FLAGS) $(X11_INCLUDE) $(MSXML_INCLUDE)
|
||||||
|
LDFLAGS=-mwindows $(X11_LIBDIR) $(MSXML_LIBDIR)
|
||||||
|
LIBS=-lcomctl32 -lole32 -loleaut32 $(X11_LIBS) $(MSXML_LIBS)
|
||||||
|
all:xlaunch.exe
|
||||||
|
%.res: %.rc
|
||||||
|
$(WINDRES) -O coff -o $@ $<
|
||||||
|
|
||||||
|
WINDOW_PARTS=window util dialog wizard
|
||||||
|
WINDOW_OBJECTS=$(foreach file,$(WINDOW_PARTS),window/$(file).o)
|
||||||
|
|
||||||
|
RESOURCES_IMAGES=resources/multiwindow.bmp resources/fullscreen.bmp \
|
||||||
|
resources/windowed.bmp resources/nodecoration.bmp
|
||||||
|
|
||||||
|
resources/resources.res: resources/resources.rc resources/resources.h \
|
||||||
|
resources/images.rc resources/dialog.rc resources/strings.rc \
|
||||||
|
$(RESOURCES_IMAGES)
|
||||||
|
xlaunch.exe: $(WINDOW_OBJECTS) main.o config.o resources/resources.res
|
||||||
|
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
|
||||||
|
|
||||||
|
|
||||||
|
window/dialog.o: window/dialog.cc window/dialog.h window/window.h window/util.h
|
||||||
|
window/frame.o: window/frame.cc window/frame.h window/window.h
|
||||||
|
window/util.o: window/util.cc window/util.h
|
||||||
|
window/window.o: window/window.cc window/window.h window/util.h
|
||||||
|
window/wizard.o: window/wizard.cc window/wizard.h window/dialog.h \
|
||||||
|
window/window.h window/util.h
|
||||||
|
main.o: main.cc window/util.h window/wizard.h window/dialog.h \
|
||||||
|
window/window.h resources/resources.h config.h
|
||||||
|
config.o: config.cc config.h
|
|
@ -0,0 +1,279 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2005 Alexander Gottwald
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
* to deal in the Software without restriction, including without limitation
|
||||||
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
* and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
* Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||||
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
* DEALINGS IN THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* Except as contained in this notice, the name(s) of the above copyright
|
||||||
|
* holders shall not be used in advertising or otherwise to promote the sale,
|
||||||
|
* use or other dealings in this Software without prior written authorization.
|
||||||
|
*/
|
||||||
|
#include "config.h"
|
||||||
|
#include "window/util.h"
|
||||||
|
#include <msxml2.h>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
const CLSID CLSID_DOMDocument40 = {0x88d969c0,0xf192,0x11d4,0xa6,0x5f,0x00,0x40,0x96,0x32,0x51,0xe5};
|
||||||
|
const CLSID CLSID_DOMDocument30 = {0xf5078f32,0xc551,0x11d3,0x89,0xb9,0x00,0x00,0xf8,0x1f,0xe2,0x21};
|
||||||
|
const IID IID_IXMLDOMDocument2 = {0x2933BF95,0x7B36,0x11d2,0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60};
|
||||||
|
|
||||||
|
#define HRCALL(x, msg) if (FAILED(x)) { throw std::runtime_error("OLE Error:" msg " failed"); };
|
||||||
|
|
||||||
|
char *wcconvert(const wchar_t *wstr)
|
||||||
|
{
|
||||||
|
int chars = WideCharToMultiByte(CP_ACP, 0, wstr, -1, NULL, 0, NULL, NULL);
|
||||||
|
if (chars == 0)
|
||||||
|
throw win32_error("WideCharToMultiByte");
|
||||||
|
char *mbstr = new char[chars];
|
||||||
|
chars = WideCharToMultiByte(CP_ACP, 0, wstr, -1, mbstr, chars, NULL, NULL);
|
||||||
|
if (chars == 0)
|
||||||
|
throw win32_error("WideCharToMultiByte");
|
||||||
|
return mbstr;
|
||||||
|
}
|
||||||
|
|
||||||
|
wchar_t *mbconvert(const char *mbstr)
|
||||||
|
{
|
||||||
|
int chars = MultiByteToWideChar(CP_ACP, 0, mbstr, -1, NULL, 0);
|
||||||
|
if (chars == 0)
|
||||||
|
throw win32_error("MultiByteToWideChar");
|
||||||
|
wchar_t *wstr = new wchar_t[chars];
|
||||||
|
chars = MultiByteToWideChar(CP_ACP, 0, mbstr, -1, wstr, chars);
|
||||||
|
if (chars == 0)
|
||||||
|
throw win32_error("MultiByteToWideChar");
|
||||||
|
return wstr;
|
||||||
|
}
|
||||||
|
|
||||||
|
VARIANT VariantString(const char *filename)
|
||||||
|
{
|
||||||
|
|
||||||
|
wchar_t *str = mbconvert(filename);
|
||||||
|
|
||||||
|
VARIANT var;
|
||||||
|
VariantInit(&var);
|
||||||
|
V_BSTR(&var) = SysAllocString(str);
|
||||||
|
V_VT(&var) = VT_BSTR;
|
||||||
|
|
||||||
|
delete [] str;
|
||||||
|
return var;
|
||||||
|
}
|
||||||
|
|
||||||
|
VARIANT VariantString(const wchar_t *str)
|
||||||
|
{
|
||||||
|
VARIANT var;
|
||||||
|
VariantInit(&var);
|
||||||
|
V_BSTR(&var) = SysAllocString(str);
|
||||||
|
V_VT(&var) = VT_BSTR;
|
||||||
|
return var;
|
||||||
|
}
|
||||||
|
|
||||||
|
IXMLDOMDocument2 *CreateDocument()
|
||||||
|
{
|
||||||
|
IXMLDOMDocument2 *doc = NULL;
|
||||||
|
|
||||||
|
CoInitialize(NULL);
|
||||||
|
|
||||||
|
HRCALL(CoCreateInstance(CLSID_DOMDocument40, NULL, CLSCTX_INPROC_SERVER,
|
||||||
|
IID_IXMLDOMDocument2, (void**)&doc), "CoCreateInstance");
|
||||||
|
|
||||||
|
try {
|
||||||
|
HRCALL(doc->put_async(VARIANT_FALSE), "put_async");
|
||||||
|
HRCALL(doc->put_validateOnParse(VARIANT_FALSE), "put_validateOnParse");
|
||||||
|
HRCALL(doc->put_resolveExternals(VARIANT_FALSE), "put_resolveExternals");
|
||||||
|
|
||||||
|
IXMLDOMProcessingInstruction *pi = NULL;
|
||||||
|
IXMLDOMElement *root = NULL;
|
||||||
|
BSTR xml = SysAllocString(L"xml");
|
||||||
|
BSTR ver = SysAllocString(L"version='1.0'");
|
||||||
|
HRCALL(doc->createProcessingInstruction(xml,ver, &pi),
|
||||||
|
"createProcessingInstruction");
|
||||||
|
HRCALL(doc->appendChild(pi, NULL),
|
||||||
|
"appendChild");
|
||||||
|
pi->Release();
|
||||||
|
SysFreeString(xml);
|
||||||
|
SysFreeString(ver);
|
||||||
|
|
||||||
|
BSTR elemname = SysAllocString(L"XLaunch");
|
||||||
|
HRCALL(doc->createElement(elemname, &root), "createElement");
|
||||||
|
HRCALL(doc->appendChild(root, NULL), "appendChild");
|
||||||
|
SysFreeString(elemname);
|
||||||
|
} catch (...)
|
||||||
|
{
|
||||||
|
doc->Release();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setAttribute(IXMLDOMElement *elem, const wchar_t *name, const wchar_t *value)
|
||||||
|
{
|
||||||
|
BSTR str = SysAllocString(name);
|
||||||
|
VARIANT var = VariantString(value);
|
||||||
|
HRCALL(elem->setAttribute(str, var), "setAttribute");
|
||||||
|
VariantClear(&var);
|
||||||
|
SysFreeString(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setAttribute(IXMLDOMElement *elem, const wchar_t *name, const char *value)
|
||||||
|
{
|
||||||
|
wchar_t *wstr = mbconvert(value);
|
||||||
|
setAttribute(elem, name, wstr);
|
||||||
|
delete [] wstr;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CConfig::Save(const char *filename)
|
||||||
|
{
|
||||||
|
IXMLDOMDocument2 *doc = CreateDocument();
|
||||||
|
IXMLDOMElement *root = NULL;
|
||||||
|
|
||||||
|
HRCALL(doc->get_documentElement(&root), "get_documentElement");
|
||||||
|
|
||||||
|
switch (window)
|
||||||
|
{
|
||||||
|
case MultiWindow:
|
||||||
|
setAttribute(root, L"WindowMode", L"MultiWindow");
|
||||||
|
break;
|
||||||
|
case Fullscreen:
|
||||||
|
setAttribute(root, L"WindowMode", L"Fullscreen");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
case Windowed:
|
||||||
|
setAttribute(root, L"WindowMode", L"Windowed");
|
||||||
|
break;
|
||||||
|
case Nodecoration:
|
||||||
|
setAttribute(root, L"WindowMode", L"Nodecoration");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
switch (client)
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
case NoClient:
|
||||||
|
setAttribute(root, L"ClientMode", L"NoClient");
|
||||||
|
break;
|
||||||
|
case StartProgram:
|
||||||
|
setAttribute(root, L"ClientMode", L"StartProgram");
|
||||||
|
break;
|
||||||
|
case XDMCP:
|
||||||
|
setAttribute(root, L"ClientMode", L"XDMCP");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
setAttribute(root, L"LocalClient", local?L"True":L"False");
|
||||||
|
setAttribute(root, L"Display", display.c_str());
|
||||||
|
setAttribute(root, L"Program", program.c_str());
|
||||||
|
setAttribute(root, L"RemoteProtocol", protocol.c_str());
|
||||||
|
setAttribute(root, L"RemoteHost", host.c_str());
|
||||||
|
setAttribute(root, L"RemoteUser", user.c_str());
|
||||||
|
setAttribute(root, L"XDMCPHost", xdmcp_host.c_str());
|
||||||
|
setAttribute(root, L"XDMCPBroadcast", broadcast?L"True":L"False");
|
||||||
|
setAttribute(root, L"XDMCPIndirect", indirect?L"True":L"False");
|
||||||
|
|
||||||
|
VARIANT var = VariantString(filename);
|
||||||
|
HRCALL(doc->save(var), "save");
|
||||||
|
VariantClear(&var);
|
||||||
|
|
||||||
|
|
||||||
|
root->Release();
|
||||||
|
doc->Release();
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL getAttribute(IXMLDOMElement *elem, const wchar_t *name, std::string &ret)
|
||||||
|
{
|
||||||
|
VARIANT var;
|
||||||
|
HRCALL(elem->getAttribute((OLECHAR*)name, &var), "getAttribute");
|
||||||
|
if (V_VT(&var) != VT_NULL && V_VT(&var) == VT_BSTR)
|
||||||
|
{
|
||||||
|
char *str = wcconvert(V_BSTR(&var));
|
||||||
|
ret = str;
|
||||||
|
delete [] str;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL getAttributeBool(IXMLDOMElement *elem, const wchar_t *name, bool &ret)
|
||||||
|
{
|
||||||
|
std::string str;
|
||||||
|
if (getAttribute(elem, name, str))
|
||||||
|
{
|
||||||
|
if (str == "True")
|
||||||
|
ret = true;
|
||||||
|
else
|
||||||
|
ret = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CConfig::Load(const char *filename)
|
||||||
|
{
|
||||||
|
IXMLDOMDocument2 *doc = CreateDocument();
|
||||||
|
IXMLDOMElement *root = NULL;
|
||||||
|
|
||||||
|
VARIANT var = VariantString(filename);
|
||||||
|
VARIANT_BOOL status;
|
||||||
|
HRCALL(doc->load(var, &status), "load");
|
||||||
|
VariantClear(&var);
|
||||||
|
|
||||||
|
if (status == VARIANT_FALSE)
|
||||||
|
{
|
||||||
|
doc->Release();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
HRCALL(doc->get_documentElement(&root), "get_documentElement");
|
||||||
|
|
||||||
|
std::string windowMode;
|
||||||
|
std::string clientMode;
|
||||||
|
|
||||||
|
if (getAttribute(root, L"WindowMode", windowMode))
|
||||||
|
{
|
||||||
|
if (windowMode == "MultiWindow")
|
||||||
|
window = MultiWindow;
|
||||||
|
else if (windowMode == "Fullscreen")
|
||||||
|
window = Fullscreen;
|
||||||
|
else if (windowMode == "Windowed")
|
||||||
|
window = Windowed;
|
||||||
|
else if (windowMode == "Nodecoration")
|
||||||
|
window = Nodecoration;
|
||||||
|
}
|
||||||
|
if (getAttribute(root, L"ClientMode", clientMode))
|
||||||
|
{
|
||||||
|
if (clientMode == "NoClient")
|
||||||
|
client = NoClient;
|
||||||
|
else if (clientMode == "StartProgram")
|
||||||
|
client = StartProgram;
|
||||||
|
else if (clientMode == "XDMCP")
|
||||||
|
client = XDMCP;
|
||||||
|
}
|
||||||
|
|
||||||
|
getAttributeBool(root, L"LocalClient", local);
|
||||||
|
getAttribute(root, L"Display", display);
|
||||||
|
getAttribute(root, L"Program", program);
|
||||||
|
getAttribute(root, L"RemoteProtocol", protocol);
|
||||||
|
getAttribute(root, L"RemoteHost", host);
|
||||||
|
getAttribute(root, L"RemoteUser", user);
|
||||||
|
getAttribute(root, L"XDMCPHost", xdmcp_host);
|
||||||
|
getAttributeBool(root, L"XDMCPBroadcast", broadcast);
|
||||||
|
getAttributeBool(root, L"XDMCPIndirect", indirect);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
doc->Release();
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2005 Alexander Gottwald
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
* to deal in the Software without restriction, including without limitation
|
||||||
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
* and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
* Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||||
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
* DEALINGS IN THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* Except as contained in this notice, the name(s) of the above copyright
|
||||||
|
* holders shall not be used in advertising or otherwise to promote the sale,
|
||||||
|
* use or other dealings in this Software without prior written authorization.
|
||||||
|
*/
|
||||||
|
#ifndef __CONFIG_H__
|
||||||
|
#define __CONFIG_H__
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
struct CConfig
|
||||||
|
{
|
||||||
|
enum {MultiWindow, Fullscreen, Windowed, Nodecoration} window;
|
||||||
|
enum {NoClient, StartProgram, XDMCP} client;
|
||||||
|
bool local;
|
||||||
|
std::string display;
|
||||||
|
std::string protocol;
|
||||||
|
std::string program;
|
||||||
|
std::string host;
|
||||||
|
std::string user;
|
||||||
|
bool broadcast;
|
||||||
|
bool indirect;
|
||||||
|
std::string xdmcp_host;
|
||||||
|
#ifdef _DEBUG
|
||||||
|
CConfig() : window(MultiWindow), client(StartProgram), local(false), display("1"),
|
||||||
|
protocol("Putty"), program("xterm"), host("lupus"), user("ago"),
|
||||||
|
broadcast(false), indirect(false), xdmcp_host("lupus") {};
|
||||||
|
#else
|
||||||
|
CConfig() : window(MultiWindow), client(StartProgram), local(false), display("0"),
|
||||||
|
protocol("Putty"), program("xterm"), host(""), user(""),
|
||||||
|
broadcast(true), indirect(false), xdmcp_host("") {};
|
||||||
|
#endif
|
||||||
|
void Load(const char* filename);
|
||||||
|
void Save(const char* filename);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,672 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2005 Alexander Gottwald
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
* to deal in the Software without restriction, including without limitation
|
||||||
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
* and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
* Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||||
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
* DEALINGS IN THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* Except as contained in this notice, the name(s) of the above copyright
|
||||||
|
* holders shall not be used in advertising or otherwise to promote the sale,
|
||||||
|
* use or other dealings in this Software without prior written authorization.
|
||||||
|
*/
|
||||||
|
#include "window/util.h"
|
||||||
|
#include "window/wizard.h"
|
||||||
|
#include "resources/resources.h"
|
||||||
|
#include "config.h"
|
||||||
|
#include <prsht.h>
|
||||||
|
#include <commctrl.h>
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
#include <X11/Xlib.h>
|
||||||
|
|
||||||
|
/// @brief Send WM_ENDSESSION to all program windows.
|
||||||
|
/// This will shutdown the started xserver
|
||||||
|
BOOL CALLBACK KillWindowsProc(HWND hwnd, LPARAM lParam)
|
||||||
|
{
|
||||||
|
SendMessage(hwnd, WM_ENDSESSION, 0, 0);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @brief Actual wizard implementation.
|
||||||
|
/// This is based on generic CWizard but handles the special dialogs
|
||||||
|
class CMyWizard : public CWizard
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
private:
|
||||||
|
CConfig config; /// Storage for config options.
|
||||||
|
public:
|
||||||
|
/// @brief Constructor.
|
||||||
|
/// Set wizard pages.
|
||||||
|
CMyWizard() : CWizard()
|
||||||
|
{
|
||||||
|
AddPage(IDD_DISPLAY, IDS_DISPLAY_TITLE, IDS_DISPLAY_SUBTITLE);
|
||||||
|
AddPage(IDD_CLIENTS, IDS_CLIENTS_TITLE, IDS_CLIENTS_SUBTITLE);
|
||||||
|
AddPage(IDD_PROGRAM, IDS_PROGRAM_TITLE, IDS_PROGRAM_SUBTITLE);
|
||||||
|
AddPage(IDD_XDMCP, IDS_XDMCP_TITLE, IDS_XDMCP_SUBTITLE);
|
||||||
|
//AddPage(IDD_FONTPATH, IDS_FONTPATH_TITLE, IDS_FONTPATH_SUBTITLE);
|
||||||
|
AddPage(IDD_FINISH, IDS_FINISH_TITLE, IDS_FINISH_SUBTITLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void LoadConfig(const char *filename)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
config.Load(filename);
|
||||||
|
} catch (std::runtime_error &e)
|
||||||
|
{
|
||||||
|
printf("Fehler: %s\n", e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @brief Handle the PSN_WIZNEXT message.
|
||||||
|
/// @param hwndDlg Handle to active page dialog.
|
||||||
|
/// @param index Index of current page.
|
||||||
|
/// @return TRUE if the message was handled. FALSE otherwise.
|
||||||
|
virtual BOOL WizardNext(HWND hwndDlg, unsigned index)
|
||||||
|
{
|
||||||
|
#ifdef _DEBUG
|
||||||
|
printf("%s %d\n", __FUNCTION__, index);
|
||||||
|
#endif
|
||||||
|
switch (PageID(index))
|
||||||
|
{
|
||||||
|
case IDD_DISPLAY:
|
||||||
|
// Check for select window mode
|
||||||
|
if (IsDlgButtonChecked(hwndDlg, IDC_MULTIWINDOW))
|
||||||
|
config.window = CConfig::MultiWindow;
|
||||||
|
else if (IsDlgButtonChecked(hwndDlg, IDC_FULLSCREEN))
|
||||||
|
config.window = CConfig::Fullscreen;
|
||||||
|
else if (IsDlgButtonChecked(hwndDlg, IDC_WINDOWED))
|
||||||
|
config.window = CConfig::Windowed;
|
||||||
|
else if (IsDlgButtonChecked(hwndDlg, IDC_NODECORATION))
|
||||||
|
config.window = CConfig::Nodecoration;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetWindowLong(hwndDlg, DWL_MSGRESULT, -1);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
// Get selected display number
|
||||||
|
{
|
||||||
|
char buffer[512];
|
||||||
|
GetDlgItemText(hwndDlg, IDC_DISPLAY, buffer, 512);
|
||||||
|
buffer[511] = 0;
|
||||||
|
config.display = buffer;
|
||||||
|
}
|
||||||
|
// Check for valid input
|
||||||
|
if (config.display.empty())
|
||||||
|
SetWindowLong(hwndDlg, DWL_MSGRESULT, -1);
|
||||||
|
else
|
||||||
|
SetWindowLong(hwndDlg, DWL_MSGRESULT, IDD_CLIENTS);
|
||||||
|
return TRUE;
|
||||||
|
case IDD_CLIENTS:
|
||||||
|
// Check for select client startup method
|
||||||
|
if (IsDlgButtonChecked(hwndDlg, IDC_CLIENT))
|
||||||
|
{
|
||||||
|
config.client = CConfig::StartProgram;
|
||||||
|
SetWindowLong(hwndDlg, DWL_MSGRESULT, IDD_PROGRAM);
|
||||||
|
} else if (IsDlgButtonChecked(hwndDlg, IDC_XDMCP))
|
||||||
|
{
|
||||||
|
config.client = CConfig::XDMCP;
|
||||||
|
SetWindowLong(hwndDlg, DWL_MSGRESULT, IDD_XDMCP);
|
||||||
|
} else if (IsDlgButtonChecked(hwndDlg, IDC_CLIENT_NONE))
|
||||||
|
{
|
||||||
|
config.client = CConfig::NoClient;
|
||||||
|
SetWindowLong(hwndDlg, DWL_MSGRESULT, IDD_FINISH);
|
||||||
|
} else
|
||||||
|
SetWindowLong(hwndDlg, DWL_MSGRESULT, -1);
|
||||||
|
return TRUE;
|
||||||
|
case IDD_PROGRAM:
|
||||||
|
// Check wether local or remote client should be started
|
||||||
|
if (IsDlgButtonChecked(hwndDlg, IDC_CLIENT_LOCAL))
|
||||||
|
config.local = true;
|
||||||
|
else if (IsDlgButtonChecked(hwndDlg, IDC_CLIENT_REMOTE))
|
||||||
|
config.local = false;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetWindowLong(hwndDlg, DWL_MSGRESULT, -1);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
// Read program, user and host name
|
||||||
|
{
|
||||||
|
char buffer[512];
|
||||||
|
GetDlgItemText(hwndDlg, IDC_CLIENT_USER, buffer, 512);
|
||||||
|
buffer[511] = 0;
|
||||||
|
config.user = buffer;
|
||||||
|
GetDlgItemText(hwndDlg, IDC_CLIENT_HOST, buffer, 512);
|
||||||
|
buffer[511] = 0;
|
||||||
|
config.host = buffer;
|
||||||
|
GetDlgItemText(hwndDlg, IDC_CLIENT_PROGRAM, buffer, 512);
|
||||||
|
buffer[511] = 0;
|
||||||
|
config.program = buffer;
|
||||||
|
}
|
||||||
|
// Check for valid input
|
||||||
|
if (!config.local && (config.host.empty() || config.program.empty()))
|
||||||
|
SetWindowLong(hwndDlg, DWL_MSGRESULT, -1);
|
||||||
|
else
|
||||||
|
SetWindowLong(hwndDlg, DWL_MSGRESULT, IDD_FINISH);
|
||||||
|
return TRUE;
|
||||||
|
case IDD_XDMCP:
|
||||||
|
// Check for broadcast
|
||||||
|
if (IsDlgButtonChecked(hwndDlg, IDC_XDMCP_BROADCAST))
|
||||||
|
config.broadcast = true;
|
||||||
|
else if (IsDlgButtonChecked(hwndDlg, IDC_XDMCP_QUERY))
|
||||||
|
config.broadcast = false;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetWindowLong(hwndDlg, DWL_MSGRESULT, -1);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
// Check for indirect mode
|
||||||
|
if (IsDlgButtonChecked(hwndDlg, IDC_XDMCP_INDIRECT))
|
||||||
|
config.indirect = true;
|
||||||
|
else
|
||||||
|
config.indirect = false;
|
||||||
|
// Read hostname
|
||||||
|
{
|
||||||
|
char buffer[512];
|
||||||
|
GetDlgItemText(hwndDlg, IDC_XDMCP_HOST, buffer, 512);
|
||||||
|
buffer[511] = 0;
|
||||||
|
config.xdmcp_host = buffer;
|
||||||
|
}
|
||||||
|
// Check for valid input
|
||||||
|
if (!config.broadcast && config.xdmcp_host.empty())
|
||||||
|
SetWindowLong(hwndDlg, DWL_MSGRESULT, -1);
|
||||||
|
else
|
||||||
|
SetWindowLong(hwndDlg, DWL_MSGRESULT, IDD_FINISH);
|
||||||
|
return TRUE;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
/// @brief Handle PSN_WIZFINISH message.
|
||||||
|
/// @param hwndDlg Handle to active page dialog.
|
||||||
|
/// @param index Index of current page.
|
||||||
|
/// @return TRUE if the message was handled. FALSE otherwise.
|
||||||
|
virtual BOOL WizardFinish(HWND hwndDlg, unsigned index)
|
||||||
|
{
|
||||||
|
#ifdef _DEBUG
|
||||||
|
printf("finish %d\n", index);
|
||||||
|
#endif
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
/// @brief Handle PSN_WIZBACK message.
|
||||||
|
/// Basicly handles switching to proper page (skipping XDMCP or program page
|
||||||
|
/// if required).
|
||||||
|
/// @param hwndDlg Handle to active page dialog.
|
||||||
|
/// @param index Index of current page.
|
||||||
|
/// @return TRUE if the message was handled. FALSE otherwise.
|
||||||
|
virtual BOOL WizardBack(HWND hwndDlg, unsigned index)
|
||||||
|
{
|
||||||
|
switch (PageID(index))
|
||||||
|
{
|
||||||
|
case IDD_PROGRAM:
|
||||||
|
case IDD_XDMCP:
|
||||||
|
SetWindowLong(hwndDlg, DWL_MSGRESULT, IDD_CLIENTS);
|
||||||
|
return TRUE;
|
||||||
|
case IDD_FONTPATH:
|
||||||
|
case IDD_FINISH: // temporary. fontpath is disabled
|
||||||
|
switch (config.client)
|
||||||
|
{
|
||||||
|
case CConfig::NoClient:
|
||||||
|
SetWindowLong(hwndDlg, DWL_MSGRESULT, IDD_CLIENTS);
|
||||||
|
return TRUE;
|
||||||
|
case CConfig::StartProgram:
|
||||||
|
SetWindowLong(hwndDlg, DWL_MSGRESULT, IDD_PROGRAM);
|
||||||
|
return TRUE;
|
||||||
|
case CConfig::XDMCP:
|
||||||
|
SetWindowLong(hwndDlg, DWL_MSGRESULT, IDD_XDMCP);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
/// @brief Handle PSN_SETACTIVE message.
|
||||||
|
/// @param hwndDlg Handle to active page dialog.
|
||||||
|
/// @param index Index of current page.
|
||||||
|
/// @return TRUE if the message was handled. FALSE otherwise.
|
||||||
|
virtual BOOL WizardActivate(HWND hwndDlg, unsigned index)
|
||||||
|
{
|
||||||
|
#ifdef _DEBUG
|
||||||
|
printf("%s %d\n", __FUNCTION__, index);
|
||||||
|
#endif
|
||||||
|
switch (PageID(index))
|
||||||
|
{
|
||||||
|
case IDD_CLIENTS:
|
||||||
|
// Enable or disable XDMCP radiobutton and text
|
||||||
|
EnableWindow(GetDlgItem(hwndDlg, IDC_XDMCP), config.window != CConfig::MultiWindow);
|
||||||
|
EnableWindow(GetDlgItem(hwndDlg, IDC_XDMCP_DESC), config.window != CConfig::MultiWindow);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
protected:
|
||||||
|
/// @brief Enable or disable the control for remote clients.
|
||||||
|
/// @param hwndDlg Handle to active page dialog.
|
||||||
|
/// @param state State of control group.
|
||||||
|
void EnableRemoteProgramGroup(HWND hwndDlg, BOOL state)
|
||||||
|
{
|
||||||
|
EnableWindow(GetDlgItem(hwndDlg, IDC_CLIENT_PROTOCOL), state);
|
||||||
|
EnableWindow(GetDlgItem(hwndDlg, IDC_CLIENT_HOST), state);
|
||||||
|
EnableWindow(GetDlgItem(hwndDlg, IDC_CLIENT_USER), state);
|
||||||
|
EnableWindow(GetDlgItem(hwndDlg, IDC_CLIENT_PROTOCOL_DESC), state);
|
||||||
|
EnableWindow(GetDlgItem(hwndDlg, IDC_CLIENT_HOST_DESC), state);
|
||||||
|
EnableWindow(GetDlgItem(hwndDlg, IDC_CLIENT_USER_DESC), state);
|
||||||
|
}
|
||||||
|
/// @brief Enable or disable the control for XDMCP connection.
|
||||||
|
/// @param hwndDlg Handle to active page dialog.
|
||||||
|
/// @param state State of control group.
|
||||||
|
void EnableXDMCPQueryGroup(HWND hwndDlg, BOOL state)
|
||||||
|
{
|
||||||
|
EnableWindow(GetDlgItem(hwndDlg, IDC_XDMCP_HOST), state);
|
||||||
|
EnableWindow(GetDlgItem(hwndDlg, IDC_XDMCP_INDIRECT), state);
|
||||||
|
}
|
||||||
|
/// @brief Fill program box with default values.
|
||||||
|
/// @param hwndDlg Handle to active page dialog.
|
||||||
|
void FillProgramBox(HWND hwndDlg)
|
||||||
|
{
|
||||||
|
HWND cbwnd = GetDlgItem(hwndDlg, IDC_CLIENT_PROGRAM);
|
||||||
|
if (cbwnd == NULL)
|
||||||
|
return;
|
||||||
|
SendMessage(cbwnd, CB_RESETCONTENT, 0, 0);
|
||||||
|
SendMessage(cbwnd, CB_ADDSTRING, 0, (LPARAM) "xterm");
|
||||||
|
SendMessage(cbwnd, CB_ADDSTRING, 0, (LPARAM) "startkde");
|
||||||
|
SendMessage(cbwnd, CB_ADDSTRING, 0, (LPARAM) "gnome-session");
|
||||||
|
SendMessage(cbwnd, CB_ADDSTRING, 0, (LPARAM) ".xinitrc");
|
||||||
|
SendMessage(cbwnd, CB_ADDSTRING, 0, (LPARAM) "wmaker");
|
||||||
|
SendMessage(cbwnd, CB_SETCURSEL, 0, 0);
|
||||||
|
}
|
||||||
|
/// @brief Fill protocol box with default values.
|
||||||
|
/// @param hwndDlg Handle to active page dialog.
|
||||||
|
void FillProtocolBox(HWND hwndDlg)
|
||||||
|
{
|
||||||
|
HWND cbwnd = GetDlgItem(hwndDlg, IDC_CLIENT_PROTOCOL);
|
||||||
|
if (cbwnd == NULL)
|
||||||
|
return;
|
||||||
|
SendMessage(cbwnd, CB_RESETCONTENT, 0, 0);
|
||||||
|
SendMessage(cbwnd, CB_ADDSTRING, 0, (LPARAM) "Putty");
|
||||||
|
//SendMessage(cbwnd, CB_ADDSTRING, 0, (LPARAM) "OpenSSH");
|
||||||
|
SendMessage(cbwnd, CB_SETCURSEL, 0, 0);
|
||||||
|
}
|
||||||
|
void ShowSaveDialog(HWND parent)
|
||||||
|
{
|
||||||
|
char szTitle[512];
|
||||||
|
char szFilter[512];
|
||||||
|
char szFileTitle[512];
|
||||||
|
char szFile[MAX_PATH];
|
||||||
|
HINSTANCE hInst = GetModuleHandle(NULL);
|
||||||
|
|
||||||
|
LoadString(hInst, IDS_SAVE_TITLE, szTitle, sizeof(szTitle));
|
||||||
|
LoadString(hInst, IDS_SAVE_FILETITLE, szFileTitle, sizeof(szFileTitle));
|
||||||
|
LoadString(hInst, IDS_SAVE_FILTER, szFilter, sizeof(szFilter));
|
||||||
|
for (unsigned i=0; szFilter[i]; i++)
|
||||||
|
if (szFilter[i] == '%')
|
||||||
|
szFilter[i] = '\0';
|
||||||
|
|
||||||
|
strcpy(szFile, "config.xlaunch");
|
||||||
|
|
||||||
|
OPENFILENAME ofn;
|
||||||
|
memset(&ofn, 0, sizeof(OPENFILENAME));
|
||||||
|
ofn.lStructSize = sizeof(OPENFILENAME);
|
||||||
|
ofn.hwndOwner = parent;
|
||||||
|
ofn.lpstrFilter = szFilter;
|
||||||
|
ofn.lpstrFile= szFile;
|
||||||
|
ofn.nMaxFile = sizeof(szFile)/ sizeof(*szFile);
|
||||||
|
ofn.lpstrFileTitle = szFileTitle;
|
||||||
|
ofn.nMaxFileTitle = sizeof(szFileTitle);
|
||||||
|
ofn.lpstrInitialDir = (LPSTR)NULL;
|
||||||
|
ofn.Flags = OFN_SHOWHELP | OFN_OVERWRITEPROMPT;
|
||||||
|
ofn.lpstrTitle = szTitle;
|
||||||
|
|
||||||
|
if (GetSaveFileName(&ofn))
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
config.Save(ofn.lpstrFile);
|
||||||
|
} catch (std::runtime_error &e)
|
||||||
|
{
|
||||||
|
printf("Fehler: %s\n", e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public:
|
||||||
|
|
||||||
|
/// @brief Handle messages fo the dialog pages.
|
||||||
|
/// @param hwndDlg Handle of active dialog.
|
||||||
|
/// @param uMsg Message code.
|
||||||
|
/// @param wParam Message parameter.
|
||||||
|
/// @param lParam Message parameter.
|
||||||
|
/// @param psp Handle to sheet paramters.
|
||||||
|
virtual INT_PTR PageDispatch(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam, PROPSHEETPAGE *psp)
|
||||||
|
{
|
||||||
|
HWND hwnd;
|
||||||
|
switch (uMsg)
|
||||||
|
{
|
||||||
|
case WM_INITDIALOG:
|
||||||
|
switch (PageID(PageIndex(psp)))
|
||||||
|
{
|
||||||
|
case IDD_DISPLAY:
|
||||||
|
// Init display dialog. Enable correct check buttons
|
||||||
|
switch (config.window)
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
case CConfig::MultiWindow:
|
||||||
|
CheckRadioButton(hwndDlg, IDC_MULTIWINDOW, IDC_NODECORATION, IDC_MULTIWINDOW);
|
||||||
|
break;
|
||||||
|
case CConfig::Fullscreen:
|
||||||
|
CheckRadioButton(hwndDlg, IDC_MULTIWINDOW, IDC_NODECORATION, IDC_FULLSCREEN);
|
||||||
|
break;
|
||||||
|
case CConfig::Windowed:
|
||||||
|
CheckRadioButton(hwndDlg, IDC_MULTIWINDOW, IDC_NODECORATION, IDC_WINDOWED);
|
||||||
|
break;
|
||||||
|
case CConfig::Nodecoration:
|
||||||
|
CheckRadioButton(hwndDlg, IDC_MULTIWINDOW, IDC_NODECORATION, IDC_NODECORATION);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// Set display number
|
||||||
|
SetDlgItemText(hwndDlg, IDC_DISPLAY, config.display.c_str());
|
||||||
|
break;
|
||||||
|
case IDD_CLIENTS:
|
||||||
|
// Init client dialog. Enable correct check buttons
|
||||||
|
switch (config.client)
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
case CConfig::NoClient:
|
||||||
|
CheckRadioButton(hwndDlg, IDC_CLIENT_NONE, IDC_CLIENT, IDC_CLIENT_NONE);
|
||||||
|
break;
|
||||||
|
case CConfig::StartProgram:
|
||||||
|
CheckRadioButton(hwndDlg, IDC_CLIENT_NONE, IDC_CLIENT, IDC_CLIENT);
|
||||||
|
break;
|
||||||
|
case CConfig::XDMCP:
|
||||||
|
CheckRadioButton(hwndDlg, IDC_CLIENT_NONE, IDC_CLIENT, IDC_XDMCP);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case IDD_PROGRAM:
|
||||||
|
// Init program dialog. Check local and remote buttons
|
||||||
|
CheckRadioButton(hwndDlg, IDC_CLIENT_LOCAL, IDC_CLIENT_REMOTE, config.local?IDC_CLIENT_LOCAL:IDC_CLIENT_REMOTE);
|
||||||
|
EnableRemoteProgramGroup(hwndDlg, config.local?FALSE:TRUE);
|
||||||
|
// Fill combo boxes
|
||||||
|
FillProgramBox(hwndDlg);
|
||||||
|
FillProtocolBox(hwndDlg);
|
||||||
|
// Set edit fields
|
||||||
|
if (!config.program.empty())
|
||||||
|
SetDlgItemText(hwndDlg, IDC_CLIENT_PROGRAM, config.program.c_str());
|
||||||
|
SetDlgItemText(hwndDlg, IDC_CLIENT_USER, config.user.c_str());
|
||||||
|
SetDlgItemText(hwndDlg, IDC_CLIENT_HOST, config.host.c_str());
|
||||||
|
break;
|
||||||
|
case IDD_XDMCP:
|
||||||
|
// Init XDMCP dialog. Check broadcast and indirect button
|
||||||
|
CheckRadioButton(hwndDlg, IDC_XDMCP_QUERY, IDC_XDMCP_BROADCAST, config.broadcast?IDC_XDMCP_BROADCAST:IDC_XDMCP_QUERY);
|
||||||
|
CheckDlgButton(hwndDlg, IDC_XDMCP_INDIRECT, config.indirect?BST_CHECKED:BST_UNCHECKED);
|
||||||
|
EnableXDMCPQueryGroup(hwndDlg, config.broadcast?FALSE:TRUE);
|
||||||
|
// Set hostname
|
||||||
|
SetDlgItemText(hwndDlg, IDC_XDMCP_HOST, config.xdmcp_host.c_str());
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
case WM_COMMAND:
|
||||||
|
// Handle control messages
|
||||||
|
switch (LOWORD(wParam))
|
||||||
|
{
|
||||||
|
// Handle clicks on images. Check proper radiobutton
|
||||||
|
case IDC_MULTIWINDOW_IMG:
|
||||||
|
case IDC_FULLSCREEN_IMG:
|
||||||
|
case IDC_WINDOWED_IMG:
|
||||||
|
case IDC_NODECORATION_IMG:
|
||||||
|
CheckRadioButton(hwndDlg, IDC_MULTIWINDOW, IDC_NODECORATION, LOWORD(wParam)-4);
|
||||||
|
SetFocus(GetDlgItem(hwndDlg, LOWORD(wParam)-4));
|
||||||
|
break;
|
||||||
|
// Disable unavailable controls
|
||||||
|
case IDC_CLIENT_REMOTE:
|
||||||
|
case IDC_CLIENT_LOCAL:
|
||||||
|
EnableRemoteProgramGroup(hwndDlg, LOWORD(wParam) == IDC_CLIENT_REMOTE);
|
||||||
|
break;
|
||||||
|
case IDC_XDMCP_QUERY:
|
||||||
|
case IDC_XDMCP_BROADCAST:
|
||||||
|
EnableXDMCPQueryGroup(hwndDlg, LOWORD(wParam) == IDC_XDMCP_QUERY);
|
||||||
|
break;
|
||||||
|
case IDC_FINISH_SAVE:
|
||||||
|
ShowSaveDialog(hwndDlg);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// pass messages to parent
|
||||||
|
return CWizard::PageDispatch(hwndDlg, uMsg, wParam, lParam, psp);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @brief Try to connect to server.
|
||||||
|
/// Repeat until successful, server died or maximum number of retries
|
||||||
|
/// reached.
|
||||||
|
Display *WaitForServer(HANDLE serverProcess)
|
||||||
|
{
|
||||||
|
int ncycles = 120; /* # of cycles to wait */
|
||||||
|
int cycles; /* Wait cycle count */
|
||||||
|
Display *xd;
|
||||||
|
|
||||||
|
for (cycles = 0; cycles < ncycles; cycles++) {
|
||||||
|
if ((xd = XOpenDisplay(NULL))) {
|
||||||
|
return xd;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (WaitForSingleObject(serverProcess, 1000) == WAIT_TIMEOUT)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @brief Do the actual start of Xming and clients
|
||||||
|
void StartUp()
|
||||||
|
{
|
||||||
|
std::string buffer;
|
||||||
|
std::string client;
|
||||||
|
|
||||||
|
// Construct display strings
|
||||||
|
std::string display_id = ":" + config.display;
|
||||||
|
std::string display = "localhost" + display_id + ":0";
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
// Debug only: Switch to Xming installation directory
|
||||||
|
SetCurrentDirectory("C:\\Programme\\Xming");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Build Xming commandline
|
||||||
|
buffer = "Xming " + display_id + " ";
|
||||||
|
switch (config.window)
|
||||||
|
{
|
||||||
|
case CConfig::MultiWindow:
|
||||||
|
buffer += "-multiwindow ";
|
||||||
|
break;
|
||||||
|
case CConfig::Fullscreen:
|
||||||
|
buffer += "-fullscreen ";
|
||||||
|
break;
|
||||||
|
case CConfig::Nodecoration:
|
||||||
|
buffer += "-nodecoration ";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// Add XDMCP parameter
|
||||||
|
if (config.client == CConfig::XDMCP)
|
||||||
|
{
|
||||||
|
if (config.broadcast)
|
||||||
|
buffer += "-broadcast ";
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (config.indirect)
|
||||||
|
buffer += "-indirect ";
|
||||||
|
else
|
||||||
|
buffer += "-query ";
|
||||||
|
buffer += config.xdmcp_host;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Construct client commandline
|
||||||
|
if (config.client == CConfig::StartProgram)
|
||||||
|
{
|
||||||
|
if (!config.local)
|
||||||
|
{
|
||||||
|
char cmdline[512];
|
||||||
|
std::string host = config.host;
|
||||||
|
if (!config.user.empty())
|
||||||
|
host = config.user + "@" + config.host;
|
||||||
|
if (config.protocol == "Putty")
|
||||||
|
snprintf(cmdline,512,"plink -X %s %s",
|
||||||
|
host.c_str(),config.program.c_str());
|
||||||
|
else
|
||||||
|
snprintf(cmdline,512,"ssh -Y %s %s",
|
||||||
|
host.c_str(),config.program.c_str());
|
||||||
|
client += cmdline;
|
||||||
|
} else
|
||||||
|
client += config.program.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepare program startup
|
||||||
|
STARTUPINFO si, sic;
|
||||||
|
PROCESS_INFORMATION pi, pic;
|
||||||
|
HANDLE handles[2];
|
||||||
|
DWORD hcount = 0;
|
||||||
|
Display *dpy = NULL;
|
||||||
|
|
||||||
|
ZeroMemory( &si, sizeof(si) );
|
||||||
|
si.cb = sizeof(si);
|
||||||
|
ZeroMemory( &pi, sizeof(pi) );
|
||||||
|
ZeroMemory( &sic, sizeof(sic) );
|
||||||
|
sic.cb = sizeof(sic);
|
||||||
|
ZeroMemory( &pic, sizeof(pic) );
|
||||||
|
|
||||||
|
// Start Xming process.
|
||||||
|
#ifdef _DEBUG
|
||||||
|
printf("%s\n", buffer.c_str());
|
||||||
|
#endif
|
||||||
|
if( !CreateProcess( NULL, (CHAR*)buffer.c_str(), NULL, NULL,
|
||||||
|
FALSE, 0, NULL, NULL, &si, &pi ))
|
||||||
|
throw win32_error("CreateProcess failed");
|
||||||
|
handles[hcount++] = pi.hProcess;
|
||||||
|
|
||||||
|
if (!client.empty())
|
||||||
|
{
|
||||||
|
// Set DISPLAY variable
|
||||||
|
SetEnvironmentVariable("DISPLAY",display.c_str());
|
||||||
|
|
||||||
|
// Wait for server to startup
|
||||||
|
dpy = WaitForServer(pi.hProcess);
|
||||||
|
if (dpy == NULL)
|
||||||
|
{
|
||||||
|
while (hcount--)
|
||||||
|
TerminateProcess(handles[hcount], (DWORD)-1);
|
||||||
|
throw std::runtime_error("Connection to server failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
printf("%s\n", client.c_str());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Hide a console window
|
||||||
|
// FIXME: This may make it impossible to enter the password
|
||||||
|
sic.dwFlags = STARTF_USESHOWWINDOW;
|
||||||
|
sic.wShowWindow = SW_HIDE;
|
||||||
|
|
||||||
|
// Start the child process.
|
||||||
|
if( !CreateProcess( NULL, (CHAR*)client.c_str(), NULL, NULL,
|
||||||
|
FALSE, 0, NULL, NULL, &sic, &pic ))
|
||||||
|
{
|
||||||
|
DWORD err = GetLastError();
|
||||||
|
while (hcount--)
|
||||||
|
TerminateProcess(handles[hcount], (DWORD)-1);
|
||||||
|
throw win32_error("CreateProcess failed", err);
|
||||||
|
}
|
||||||
|
handles[hcount++] = pic.hProcess;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait until any child process exits.
|
||||||
|
DWORD ret = WaitForMultipleObjects(hcount, handles, FALSE, INFINITE );
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
printf("killing process!\n");
|
||||||
|
#endif
|
||||||
|
// Check if Xming is still running
|
||||||
|
DWORD exitcode;
|
||||||
|
GetExitCodeProcess(pi.hProcess, &exitcode);
|
||||||
|
unsigned counter = 0;
|
||||||
|
while (exitcode == STILL_ACTIVE)
|
||||||
|
{
|
||||||
|
if (++counter > 10)
|
||||||
|
TerminateProcess(pi.hProcess, (DWORD)-1);
|
||||||
|
else
|
||||||
|
// Shutdown Xming (the soft way!)
|
||||||
|
EnumThreadWindows(pi.dwThreadId, KillWindowsProc, 0);
|
||||||
|
Sleep(500);
|
||||||
|
GetExitCodeProcess(pi.hProcess, &exitcode);
|
||||||
|
}
|
||||||
|
// Kill the client
|
||||||
|
TerminateProcess(pic.hProcess, (DWORD)-1);
|
||||||
|
|
||||||
|
// Close process and thread handles.
|
||||||
|
CloseHandle( pi.hProcess );
|
||||||
|
CloseHandle( pi.hThread );
|
||||||
|
CloseHandle( pic.hProcess );
|
||||||
|
CloseHandle( pic.hThread );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
InitCommonControls();
|
||||||
|
CMyWizard dialog;
|
||||||
|
|
||||||
|
bool skip_wizard = false;
|
||||||
|
|
||||||
|
for (int i = 1; i < argc; i++)
|
||||||
|
{
|
||||||
|
if (argv[i] == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
std::string arg(argv[i]);
|
||||||
|
if (arg == "-load" && i + 1 < argc)
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
dialog.LoadConfig(argv[i]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (arg == "-run" && i + 1 < argc)
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
dialog.LoadConfig(argv[i]);
|
||||||
|
skip_wizard = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int ret = 0;
|
||||||
|
if (skip_wizard || (ret =dialog.ShowModal()) != 0)
|
||||||
|
dialog.StartUp();
|
||||||
|
#ifdef _DEBUG
|
||||||
|
printf("return %d\n", ret);
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
} catch (std::runtime_error &e)
|
||||||
|
{
|
||||||
|
printf("Fehler: %s\n", e.what());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,113 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2005 Alexander Gottwald
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
* to deal in the Software without restriction, including without limitation
|
||||||
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
* and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
* Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||||
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
* DEALINGS IN THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* Except as contained in this notice, the name(s) of the above copyright
|
||||||
|
* holders shall not be used in advertising or otherwise to promote the sale,
|
||||||
|
* use or other dealings in this Software without prior written authorization.
|
||||||
|
*/
|
||||||
|
#include <windows.h>
|
||||||
|
#include "resources.h"
|
||||||
|
|
||||||
|
#ifndef STR_CAPTION_DISPLAY
|
||||||
|
#include "strings.rc"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IDD_DISPLAY DIALOGEX 0, 0, 317, 143
|
||||||
|
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU | DS_CENTERMOUSE
|
||||||
|
CAPTION STR_CAPTION_DISPLAY
|
||||||
|
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
||||||
|
BEGIN
|
||||||
|
AUTORADIOBUTTON STR_MULTIWINDOW,IDC_MULTIWINDOW,7,25,70,24,BS_MULTILINE|BS_TOP
|
||||||
|
AUTORADIOBUTTON STR_FULLSCREEN,IDC_FULLSCREEN,157,25,70,24,BS_MULTILINE|BS_TOP
|
||||||
|
AUTORADIOBUTTON STR_WINDOWED,IDC_WINDOWED,7,75,70,24,BS_MULTILINE|BS_TOP
|
||||||
|
AUTORADIOBUTTON STR_NODECORATION,IDC_NODECORATION,157,75,70,24,BS_MULTILINE|BS_TOP
|
||||||
|
|
||||||
|
CONTROL "IMG_MULTIWINDOW",IDC_MULTIWINDOW_IMG,"Static",SS_BITMAP | SS_NOTIFY,80,10,0,0
|
||||||
|
CONTROL "IMG_FULLSCREEN",IDC_FULLSCREEN_IMG,"Static",SS_BITMAP | SS_NOTIFY,230,10,0,0
|
||||||
|
CONTROL "IMG_WINDOWED",IDC_WINDOWED_IMG,"Static",SS_BITMAP | SS_NOTIFY,80,60,0,0
|
||||||
|
CONTROL "IMG_NODECORATION",IDC_NODECORATION_IMG,"Static",SS_BITMAP | SS_NOTIFY,230,60,0,0
|
||||||
|
|
||||||
|
LTEXT STR_DISPLAY_DESC,IDC_DISPLAY_DESC,7,120,64,12
|
||||||
|
EDITTEXT IDC_DISPLAY,80,118,67,12,ES_NUMBER
|
||||||
|
END
|
||||||
|
|
||||||
|
IDD_CLIENTS DIALOGEX 0, 0, 317, 143
|
||||||
|
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU | DS_CENTERMOUSE
|
||||||
|
CAPTION STR_CAPTION_CLIENTS
|
||||||
|
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
||||||
|
BEGIN
|
||||||
|
AUTORADIOBUTTON STR_CLIENT_NONE,IDC_CLIENT_NONE,7,14,300,10
|
||||||
|
AUTORADIOBUTTON STR_CLIENT,IDC_CLIENT,7,56,300,10
|
||||||
|
AUTORADIOBUTTON STR_XDMCP,IDC_XDMCP,7,98,300,10
|
||||||
|
|
||||||
|
LTEXT STR_CLIENT_NONE_DESC,IDC_CLIENT_NONE_DESC,19,28,280,27
|
||||||
|
LTEXT STR_CLIENT_DESC,IDC_CLIENT_DESC,19,70,280,27
|
||||||
|
LTEXT STR_XDMCP_DESC,IDC_XDMCP_DESC,19,112,280,27
|
||||||
|
END
|
||||||
|
|
||||||
|
IDD_PROGRAM DIALOGEX 0, 0, 317, 143
|
||||||
|
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU | DS_CENTERMOUSE
|
||||||
|
CAPTION STR_CAPTION_PROGRAM
|
||||||
|
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
||||||
|
BEGIN
|
||||||
|
LTEXT STR_CLIENT_PROGRAM_DESC,IDC_CLIENT_PROGRAM_DESC,7,14,64,10
|
||||||
|
COMBOBOX IDC_CLIENT_PROGRAM,70,12,64,54,CBS_DROPDOWN | WS_VSCROLL
|
||||||
|
|
||||||
|
AUTORADIOBUTTON STR_CLIENT_LOCAL,IDC_CLIENT_LOCAL,7,28,300,10
|
||||||
|
AUTORADIOBUTTON STR_CLIENT_REMOTE,IDC_CLIENT_REMOTE,7,42,300,10
|
||||||
|
|
||||||
|
LTEXT STR_CLIENT_PROTOCOL_DESC,IDC_CLIENT_PROTOCOL_DESC,19,56,70,10
|
||||||
|
COMBOBOX IDC_CLIENT_PROTOCOL,100,54,64,54,CBS_DROPDOWNLIST | WS_VSCROLL
|
||||||
|
|
||||||
|
LTEXT STR_CLIENT_HOST_DESC,IDC_CLIENT_HOST_DESC,19,70,70,10
|
||||||
|
LTEXT STR_CLIENT_USER_DESC,IDC_CLIENT_USER_DESC,19,84,70,10
|
||||||
|
EDITTEXT IDC_CLIENT_HOST,100,68,64,12
|
||||||
|
EDITTEXT IDC_CLIENT_USER,100,82,64,12
|
||||||
|
END
|
||||||
|
|
||||||
|
IDD_XDMCP DIALOGEX 0, 0, 317, 143
|
||||||
|
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU | DS_CENTERMOUSE
|
||||||
|
CAPTION STR_CAPTION_XDMCP
|
||||||
|
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
||||||
|
BEGIN
|
||||||
|
AUTORADIOBUTTON STR_XDMCP_QUERY, IDC_XDMCP_QUERY,7,14,64,10
|
||||||
|
EDITTEXT IDC_XDMCP_HOST,78,12,64,12
|
||||||
|
AUTOCHECKBOX STR_XDMCP_INDIRECT,IDC_XDMCP_INDIRECT,19,28,280,10
|
||||||
|
AUTORADIOBUTTON STR_XDMCP_BROADCAST, IDC_XDMCP_BROADCAST,7,42,300,10
|
||||||
|
LTEXT STR_XDMCP_QUERY_DESC,IDC_XDMCP_QUERY_DESC,7,56,300,42
|
||||||
|
END
|
||||||
|
|
||||||
|
IDD_FONTPATH DIALOGEX 0, 0, 317, 143
|
||||||
|
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU | DS_CENTERMOUSE
|
||||||
|
CAPTION STR_CAPTION_FONTPATH
|
||||||
|
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
||||||
|
BEGIN
|
||||||
|
END
|
||||||
|
|
||||||
|
IDD_FINISH DIALOGEX 0, 0, 317, 143
|
||||||
|
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU | DS_CENTERMOUSE
|
||||||
|
CAPTION STR_CAPTION_FINISH
|
||||||
|
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
||||||
|
BEGIN
|
||||||
|
LTEXT STR_FINISH_DESC,IDC_FINISH_DESC,7,14,300,28
|
||||||
|
LTEXT STR_FINISH_SAVE_DESC,IDC_FINISH_SAVE_DESC,7,56,300,12
|
||||||
|
PUSHBUTTON STR_FINISH_SAVE,IDC_FINISH_SAVE,7,68,75,14
|
||||||
|
END
|
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2005 Alexander Gottwald
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
* to deal in the Software without restriction, including without limitation
|
||||||
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
* and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
* Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||||
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
* DEALINGS IN THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* Except as contained in this notice, the name(s) of the above copyright
|
||||||
|
* holders shall not be used in advertising or otherwise to promote the sale,
|
||||||
|
* use or other dealings in this Software without prior written authorization.
|
||||||
|
*/
|
||||||
|
IMG_MULTIWINDOW BITMAP "resources\\multiwindow.bmp"
|
||||||
|
IMG_WINDOWED BITMAP "resources\\windowed.bmp"
|
||||||
|
IMG_FULLSCREEN BITMAP "resources\\fullscreen.bmp"
|
||||||
|
IMG_NODECORATION BITMAP "resources\\nodecoration.bmp"
|
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
|
@ -0,0 +1,91 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2005 Alexander Gottwald
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
* to deal in the Software without restriction, including without limitation
|
||||||
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
* and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
* Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||||
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
* DEALINGS IN THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* Except as contained in this notice, the name(s) of the above copyright
|
||||||
|
* holders shall not be used in advertising or otherwise to promote the sale,
|
||||||
|
* use or other dealings in this Software without prior written authorization.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define IDC_STATIC -1
|
||||||
|
|
||||||
|
#define IDD_WELCOME 100
|
||||||
|
#define IDD_FINISH 101
|
||||||
|
#define IDD_DISPLAY 102
|
||||||
|
#define IDD_CLIENTS 103
|
||||||
|
#define IDD_PROGRAM 104
|
||||||
|
#define IDD_XDMCP 105
|
||||||
|
#define IDD_FONTPATH 106
|
||||||
|
|
||||||
|
#define IDS_DISPLAY_TITLE 300
|
||||||
|
#define IDS_DISPLAY_SUBTITLE 301
|
||||||
|
#define IDS_CLIENTS_TITLE 302
|
||||||
|
#define IDS_CLIENTS_SUBTITLE 303
|
||||||
|
#define IDS_PROGRAM_TITLE 304
|
||||||
|
#define IDS_PROGRAM_SUBTITLE 305
|
||||||
|
#define IDS_XDMCP_TITLE 306
|
||||||
|
#define IDS_XDMCP_SUBTITLE 307
|
||||||
|
#define IDS_FONTPATH_TITLE 308
|
||||||
|
#define IDS_FONTPATH_SUBTITLE 309
|
||||||
|
#define IDS_FINISH_TITLE 310
|
||||||
|
#define IDS_FINISH_SUBTITLE 311
|
||||||
|
#define IDS_SAVE_TITLE 320
|
||||||
|
#define IDS_SAVE_FILETITLE 321
|
||||||
|
#define IDS_SAVE_FILTER 322
|
||||||
|
|
||||||
|
#define IDC_MULTIWINDOW 200
|
||||||
|
#define IDC_WINDOWED 201
|
||||||
|
#define IDC_FULLSCREEN 202
|
||||||
|
#define IDC_NODECORATION 203
|
||||||
|
#define IDC_MULTIWINDOW_IMG 204
|
||||||
|
#define IDC_WINDOWED_IMG 205
|
||||||
|
#define IDC_FULLSCREEN_IMG 206
|
||||||
|
#define IDC_NODECORATION_IMG 207
|
||||||
|
#define IDC_DISPLAY 208
|
||||||
|
#define IDC_DISPLAY_DESC 209
|
||||||
|
|
||||||
|
#define IDC_CLIENT_NONE 210
|
||||||
|
#define IDC_XDMCP 211
|
||||||
|
#define IDC_CLIENT 212
|
||||||
|
#define IDC_CLIENT_LOCAL 213
|
||||||
|
#define IDC_CLIENT_REMOTE 214
|
||||||
|
#define IDC_CLIENT_HOST 215
|
||||||
|
#define IDC_CLIENT_USER 216
|
||||||
|
#define IDC_CLIENT_PROTOCOL 217
|
||||||
|
#define IDC_CLIENT_CONFIGURE 218
|
||||||
|
#define IDC_CLIENT_PROGRAM 219
|
||||||
|
#define IDC_XDMCP_QUERY 220
|
||||||
|
#define IDC_XDMCP_BROADCAST 221
|
||||||
|
#define IDC_XDMCP_INDIRECT 222
|
||||||
|
#define IDC_XDMCP_HOST 223
|
||||||
|
#define IDC_CLIENT_NONE_DESC 224
|
||||||
|
#define IDC_XDMCP_DESC 225
|
||||||
|
#define IDC_CLIENT_DESC 226
|
||||||
|
#define IDC_XDMCP_QUERY_DESC 227
|
||||||
|
#define IDC_CLIENT_PROGRAM_DESC 228
|
||||||
|
#define IDC_CLIENT_HOST_DESC 229
|
||||||
|
#define IDC_CLIENT_USER_DESC 230
|
||||||
|
#define IDC_CLIENT_PROTOCOL_DESC 231
|
||||||
|
|
||||||
|
#define IDC_FONTPATH_DESC 240
|
||||||
|
|
||||||
|
#define IDC_FINISH_DESC 250
|
||||||
|
#define IDC_FINISH_SAVE 251
|
||||||
|
#define IDC_FINISH_SAVE_DESC 252
|
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2005 Alexander Gottwald
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
* to deal in the Software without restriction, including without limitation
|
||||||
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
* and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
* Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||||
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
* DEALINGS IN THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* Except as contained in this notice, the name(s) of the above copyright
|
||||||
|
* holders shall not be used in advertising or otherwise to promote the sale,
|
||||||
|
* use or other dealings in this Software without prior written authorization.
|
||||||
|
*/
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
#include "resources.h"
|
||||||
|
#include "images.rc"
|
||||||
|
#include "dialog.rc"
|
|
@ -0,0 +1,99 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2005 Alexander Gottwald
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
* to deal in the Software without restriction, including without limitation
|
||||||
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
* and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
* Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||||
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
* DEALINGS IN THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* Except as contained in this notice, the name(s) of the above copyright
|
||||||
|
* holders shall not be used in advertising or otherwise to promote the sale,
|
||||||
|
* use or other dealings in this Software without prior written authorization.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define STR_CAPTION_DISPLAY "Display settings"
|
||||||
|
#define STR_MULTIWINDOW "Multiple windows"
|
||||||
|
#define STR_FULLSCREEN "Fullscreen"
|
||||||
|
#define STR_WINDOWED "One large window"
|
||||||
|
#define STR_NODECORATION "One window without titlebar"
|
||||||
|
#define STR_DISPLAY_DESC "Display number"
|
||||||
|
|
||||||
|
#define STR_CAPTION_CLIENTS "Client startup"
|
||||||
|
#define STR_CLIENT_NONE "Start no client"
|
||||||
|
#define STR_CLIENT_NONE_DESC "This will just start the xserver. You will be able to start local clients later."
|
||||||
|
#define STR_CLIENT "Start a program"
|
||||||
|
#define STR_CLIENT_DESC "This will start a local or remote program which will connect to the xserver. You will be able to start local clients later too. Remote programs are started using SSH."
|
||||||
|
#define STR_XDMCP "Open session via XDMCP"
|
||||||
|
#define STR_XDMCP_DESC "This will start a remote XDMCP session. Starting local clients later is limited. This option is not available with the ""Multiple windows"" mode."
|
||||||
|
|
||||||
|
#define STR_CAPTION_PROGRAM "Start program"
|
||||||
|
#define STR_CLIENT_PROGRAM_DESC "Start program"
|
||||||
|
#define STR_CLIENT_LOCAL "Start program on this computer"
|
||||||
|
#define STR_CLIENT_REMOTE "Start program on remote computer"
|
||||||
|
#define STR_CLIENT_PROTOCOL_DESC "Connect using"
|
||||||
|
#define STR_CLIENT_HOST_DESC "Connect to computer"
|
||||||
|
#define STR_CLIENT_USER_DESC "Login as user"
|
||||||
|
|
||||||
|
|
||||||
|
#define STR_CAPTION_XDMCP "XDMCP settings"
|
||||||
|
#define STR_XDMCP_QUERY "Connect to host"
|
||||||
|
#define STR_XDMCP_INDIRECT "Use indirect connect"
|
||||||
|
#define STR_XDMCP_BROADCAST "Search for hosts (broadcast)"
|
||||||
|
#define STR_XDMCP_QUERY_DESC "Some XDMCP servers must be configured to allow remote connections. Please check the documentation about configuring XDMCP servers."
|
||||||
|
|
||||||
|
|
||||||
|
#define STR_CAPTION_FONTPATH "Fontpath settings"
|
||||||
|
|
||||||
|
#define STR_CAPTION_FINISH "Finish configuration"
|
||||||
|
#define STR_FINISH_DESC "Configuration is complete. Clish Finish to start Xming."
|
||||||
|
#define STR_FINISH_SAVE_DESC "You may also save the configuration for later use."
|
||||||
|
#define STR_FINISH_SAVE "Save configuration"
|
||||||
|
|
||||||
|
#define STR_DISPLAY_TITLE "Select display settings"
|
||||||
|
#define STR_DISPLAY_SUBTITLE "Choose how Xming display programs"
|
||||||
|
#define STR_CLIENTS_TITLE "Select how to start clients"
|
||||||
|
#define STR_CLIENTS_SUBTITLE ""
|
||||||
|
#define STR_PROGRAM_TITLE "Specify the program to start"
|
||||||
|
#define STR_PROGRAM_SUBTITLE ""
|
||||||
|
#define STR_XDMCP_TITLE "Configure a remote XDMCP connection"
|
||||||
|
#define STR_XDMCP_SUBTITLE ""
|
||||||
|
#define STR_FONTPATH_TITLE "Define font locations"
|
||||||
|
#define STR_FONTPATH_SUBTITLE ""
|
||||||
|
#define STR_FINISH_TITLE "Configuration complete"
|
||||||
|
#define STR_FINISH_SUBTITLE ""
|
||||||
|
|
||||||
|
#define STR_SAVE_TITLE "Save configuration"
|
||||||
|
#define STR_SAVE_FILETITLE "Filename"
|
||||||
|
#define STR_SAVE_FILTER "Xlaunch Files (*.xlaunch)%*.xlaunch%%"
|
||||||
|
|
||||||
|
STRINGTABLE
|
||||||
|
BEGIN
|
||||||
|
IDS_DISPLAY_TITLE STR_DISPLAY_TITLE
|
||||||
|
IDS_DISPLAY_SUBTITLE STR_DISPLAY_SUBTITLE
|
||||||
|
IDS_CLIENTS_TITLE STR_CLIENTS_TITLE
|
||||||
|
IDS_CLIENTS_SUBTITLE STR_CLIENTS_SUBTITLE
|
||||||
|
IDS_PROGRAM_TITLE STR_PROGRAM_TITLE
|
||||||
|
IDS_PROGRAM_SUBTITLE STR_PROGRAM_SUBTITLE
|
||||||
|
IDS_XDMCP_TITLE STR_XDMCP_TITLE
|
||||||
|
IDS_XDMCP_SUBTITLE STR_XDMCP_SUBTITLE
|
||||||
|
IDS_FONTPATH_TITLE STR_FONTPATH_TITLE
|
||||||
|
IDS_FONTPATH_SUBTITLE STR_FONTPATH_SUBTITLE
|
||||||
|
IDS_FINISH_TITLE STR_FINISH_TITLE
|
||||||
|
IDS_FINISH_SUBTITLE STR_FINISH_SUBTITLE
|
||||||
|
IDS_SAVE_TITLE STR_SAVE_TITLE
|
||||||
|
IDS_SAVE_FILETITLE STR_SAVE_FILETITLE
|
||||||
|
IDS_SAVE_FILTER STR_SAVE_FILTER
|
||||||
|
END
|
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
|
@ -0,0 +1,86 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2005 Alexander Gottwald
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
* to deal in the Software without restriction, including without limitation
|
||||||
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
* and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
* Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||||
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
* DEALINGS IN THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* Except as contained in this notice, the name(s) of the above copyright
|
||||||
|
* holders shall not be used in advertising or otherwise to promote the sale,
|
||||||
|
* use or other dealings in this Software without prior written authorization.
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "dialog.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
CBaseDialog::CBaseDialog() : CWindow(""), result(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CDialog::CDialog(const char *res) : CBaseDialog(), resourcename(res)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
HWND CDialog::CreateWindowHandle()
|
||||||
|
{
|
||||||
|
HWND ret = CreateDialog(
|
||||||
|
GetModuleHandle(NULL),
|
||||||
|
resourcename.c_str(),
|
||||||
|
NULL,
|
||||||
|
DialogProc);
|
||||||
|
if (ret == NULL)
|
||||||
|
throw win32_error("CreateDialog failed");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
INT_PTR CALLBACK CBaseDialog::DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
|
{
|
||||||
|
MessageDebug::debug(hwndDlg, uMsg, wParam, lParam, __FUNCTION__);
|
||||||
|
CBaseDialog* dialog = (CDialog*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
|
||||||
|
if (dialog != NULL)
|
||||||
|
return dialog->DlgDispatch(hwndDlg, uMsg, wParam, lParam);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
INT_PTR CBaseDialog::DlgDispatch(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
|
{
|
||||||
|
switch (uMsg)
|
||||||
|
{
|
||||||
|
case WM_COMMAND:
|
||||||
|
switch (LOWORD(wParam))
|
||||||
|
{
|
||||||
|
case IDOK:
|
||||||
|
case IDCANCEL:
|
||||||
|
result = wParam;
|
||||||
|
EndDialog(hwndDlg, wParam);
|
||||||
|
DestroyWindow(hwndDlg);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
INT_PTR CDialog::DlgDispatch(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
|
{
|
||||||
|
return CBaseDialog::DlgDispatch(hwndDlg, uMsg, wParam, lParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
int CBaseDialog::Execute()
|
||||||
|
{
|
||||||
|
return CWindow::ShowModal();
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2005 Alexander Gottwald
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
* to deal in the Software without restriction, including without limitation
|
||||||
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
* and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
* Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||||
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
* DEALINGS IN THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* Except as contained in this notice, the name(s) of the above copyright
|
||||||
|
* holders shall not be used in advertising or otherwise to promote the sale,
|
||||||
|
* use or other dealings in this Software without prior written authorization.
|
||||||
|
*/
|
||||||
|
#ifndef __DIALOG_H__
|
||||||
|
#define __DIALOG_H__
|
||||||
|
|
||||||
|
#include "window.h"
|
||||||
|
class CBaseDialog : public CWindow
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
int result;
|
||||||
|
protected:
|
||||||
|
static INT_PTR CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||||
|
virtual INT_PTR DlgDispatch(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||||
|
public:
|
||||||
|
CBaseDialog();
|
||||||
|
int Execute();
|
||||||
|
};
|
||||||
|
|
||||||
|
class CDialog : public CBaseDialog
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
std::string resourcename;
|
||||||
|
protected:
|
||||||
|
virtual INT_PTR DlgDispatch(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||||
|
virtual HWND CreateWindowHandle();
|
||||||
|
public:
|
||||||
|
CDialog(const char *res);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,53 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2005 Alexander Gottwald
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
* to deal in the Software without restriction, including without limitation
|
||||||
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
* and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
* Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||||
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
* DEALINGS IN THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* Except as contained in this notice, the name(s) of the above copyright
|
||||||
|
* holders shall not be used in advertising or otherwise to promote the sale,
|
||||||
|
* use or other dealings in this Software without prior written authorization.
|
||||||
|
*/
|
||||||
|
#ifndef __UTIL_H__
|
||||||
|
#define __UTIL_H__
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
|
||||||
|
class win32_error : public std::runtime_error
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static std::string message(DWORD code);
|
||||||
|
DWORD errorcode;
|
||||||
|
win32_error(const std::string &msg,DWORD code = GetLastError()) : std::runtime_error(msg + ":" + message(code)), errorcode(code) {};
|
||||||
|
};
|
||||||
|
|
||||||
|
#define MESSAGE_NAMES_LEN 1024
|
||||||
|
#define NOTIFY_NAMES_LEN 0
|
||||||
|
class MessageDebug
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
static const char * message_names[MESSAGE_NAMES_LEN];
|
||||||
|
static const char * notify_names[NOTIFY_NAMES_LEN];
|
||||||
|
public:
|
||||||
|
static void debug(HWND handle, UINT uMsg, WPARAM wParam, LPARAM lParam, const char *prefix);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,284 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2005 Alexander Gottwald
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
* to deal in the Software without restriction, including without limitation
|
||||||
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
* and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
* Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||||
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
* DEALINGS IN THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* Except as contained in this notice, the name(s) of the above copyright
|
||||||
|
* holders shall not be used in advertising or otherwise to promote the sale,
|
||||||
|
* use or other dealings in this Software without prior written authorization.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "window.h"
|
||||||
|
#include "util.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
CWindow::CWindowClass CWindow::windowClass("CWINDOWCLASS", DefWindowProc);
|
||||||
|
|
||||||
|
CWindow::CWindowClass::CWindowClass(const char *_name, WNDPROC _wndproc) :
|
||||||
|
wndproc(_wndproc), atom(0), classname(_name)
|
||||||
|
{
|
||||||
|
Register();
|
||||||
|
}
|
||||||
|
|
||||||
|
CWindow::CWindowClass::~CWindowClass()
|
||||||
|
{
|
||||||
|
UnregisterClass(classname.c_str(), GetModuleHandle(NULL));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CWindow::CWindowClass::Register()
|
||||||
|
{
|
||||||
|
WNDCLASSEX wndclass;
|
||||||
|
memset(&wndclass, 0, sizeof(wndclass));
|
||||||
|
wndclass.cbSize = sizeof(wndclass);
|
||||||
|
wndclass.style = 0;
|
||||||
|
wndclass.lpfnWndProc = wndproc;
|
||||||
|
wndclass.cbClsExtra = 0;
|
||||||
|
wndclass.cbWndExtra = 0;
|
||||||
|
wndclass.hInstance = GetModuleHandle(NULL);
|
||||||
|
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
|
||||||
|
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||||
|
wndclass.hbrBackground = (HBRUSH)(1 + COLOR_BTNFACE);
|
||||||
|
wndclass.lpszMenuName = NULL;
|
||||||
|
wndclass.lpszClassName = classname.c_str();
|
||||||
|
wndclass.hIconSm = NULL;
|
||||||
|
atom = RegisterClassEx(&wndclass);
|
||||||
|
if (atom == 0)
|
||||||
|
throw win32_error("RegisterClassEx failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
CWindow::CWindow(const char *_title) : title(_title), hwnd(NULL), parent(NULL), bounds(), owndproc(NULL), showing(FALSE)
|
||||||
|
{
|
||||||
|
style = WS_CHILD;
|
||||||
|
exstyle = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
HWND CWindow::CreateWindowHandle()
|
||||||
|
{
|
||||||
|
HWND ret = CreateWindowEx(
|
||||||
|
exstyle,
|
||||||
|
GetClassName(),
|
||||||
|
title.c_str(),
|
||||||
|
style,
|
||||||
|
bounds.left,
|
||||||
|
bounds.top,
|
||||||
|
bounds.width,
|
||||||
|
bounds.height,
|
||||||
|
parent,
|
||||||
|
NULL,
|
||||||
|
GetModuleHandle(NULL),
|
||||||
|
0
|
||||||
|
);
|
||||||
|
if (ret == NULL)
|
||||||
|
throw win32_error("CreateWindowEx failed");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CWindow::Create()
|
||||||
|
{
|
||||||
|
if (hwnd != NULL)
|
||||||
|
return;
|
||||||
|
hwnd = CreateWindowHandle();
|
||||||
|
if (hwnd == NULL)
|
||||||
|
throw win32_error("Could not create window");
|
||||||
|
|
||||||
|
// Reset the error code
|
||||||
|
DWORD err = 0;
|
||||||
|
SetLastError(err);
|
||||||
|
|
||||||
|
// Attach the object reference to the window handle
|
||||||
|
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)this);
|
||||||
|
err = GetLastError();
|
||||||
|
if (err != 0)
|
||||||
|
throw win32_error("SetWindowLongPtr failed",err);
|
||||||
|
|
||||||
|
// Set the window proc
|
||||||
|
owndproc = (WNDPROC)SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)WindowProc);
|
||||||
|
err = GetLastError();
|
||||||
|
if (err != 0)
|
||||||
|
throw win32_error("SetWindowLongPtr failed",err);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *CWindow::GetClassName()
|
||||||
|
{
|
||||||
|
return windowClass.GetClassName();
|
||||||
|
}
|
||||||
|
|
||||||
|
LRESULT CALLBACK CWindow::WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
|
{
|
||||||
|
MessageDebug::debug(hwnd, uMsg, wParam, lParam, __FUNCTION__);
|
||||||
|
CWindow* window = (CWindow*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
|
||||||
|
if (window != NULL)
|
||||||
|
return window->Dispatch(hwnd, uMsg, wParam, lParam);
|
||||||
|
return DefWindowProc(hwnd, uMsg, wParam, lParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
LRESULT CWindow::Dispatch(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
|
{
|
||||||
|
switch (uMsg)
|
||||||
|
{
|
||||||
|
case WM_SIZE:
|
||||||
|
bounds.width = LOWORD(lParam);
|
||||||
|
bounds.height = LOWORD(lParam);
|
||||||
|
break;
|
||||||
|
case WM_MOVE:
|
||||||
|
bounds.left = LOWORD(lParam);
|
||||||
|
bounds.top = LOWORD(lParam);
|
||||||
|
break;
|
||||||
|
case WM_DESTROY:
|
||||||
|
showing = FALSE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (owndproc)
|
||||||
|
return CallWindowProc(owndproc, hwnd, uMsg, wParam, lParam);
|
||||||
|
else
|
||||||
|
return DefWindowProc(hwnd, uMsg, wParam, lParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CWindow::Show()
|
||||||
|
{
|
||||||
|
if (hwnd == NULL)
|
||||||
|
Create();
|
||||||
|
ShowWindow(hwnd, SW_SHOWNORMAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
int CWindow::ShowModal()
|
||||||
|
{
|
||||||
|
MSG msg;
|
||||||
|
BOOL bRet;
|
||||||
|
showing = TRUE;
|
||||||
|
Show();
|
||||||
|
|
||||||
|
while( showing && (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)
|
||||||
|
{
|
||||||
|
if (bRet == -1)
|
||||||
|
{
|
||||||
|
// handle the error and possibly exit
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TranslateMessage(&msg);
|
||||||
|
DispatchMessage(&msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CWindow::SetLeft(int left)
|
||||||
|
{
|
||||||
|
bounds.left = left;
|
||||||
|
if (hwnd)
|
||||||
|
if (!SetWindowPos(hwnd, NULL,
|
||||||
|
bounds.left, bounds.top,
|
||||||
|
0, 0,
|
||||||
|
SWP_NOZORDER | SWP_NOSIZE))
|
||||||
|
throw win32_error("SetWindowPos failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
void CWindow::SetTop(int top)
|
||||||
|
{
|
||||||
|
bounds.top = top;
|
||||||
|
if (hwnd)
|
||||||
|
if (!SetWindowPos(hwnd, NULL,
|
||||||
|
bounds.left, bounds.top,
|
||||||
|
0, 0,
|
||||||
|
SWP_NOZORDER | SWP_NOSIZE))
|
||||||
|
throw win32_error("SetWindowPos failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
void CWindow::SetWidth(int width)
|
||||||
|
{
|
||||||
|
bounds.width = width;
|
||||||
|
if (hwnd)
|
||||||
|
if (!SetWindowPos(hwnd, NULL,
|
||||||
|
0, 0,
|
||||||
|
bounds.width, bounds.height,
|
||||||
|
SWP_NOZORDER | SWP_NOMOVE))
|
||||||
|
throw win32_error("SetWindowPos failed");
|
||||||
|
}
|
||||||
|
void CWindow::SetHeight(int height)
|
||||||
|
{
|
||||||
|
bounds.height = height;
|
||||||
|
if (hwnd)
|
||||||
|
if (!SetWindowPos(hwnd, NULL,
|
||||||
|
0, 0,
|
||||||
|
bounds.width, bounds.height,
|
||||||
|
SWP_NOZORDER | SWP_NOMOVE))
|
||||||
|
throw win32_error("SetWindowPos failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
void CWindow::SetBounds(int left, int top, int width, int height)
|
||||||
|
{
|
||||||
|
bounds = CBoundary(left, top, width, height);
|
||||||
|
if (hwnd)
|
||||||
|
if (!SetWindowPos(hwnd, NULL,
|
||||||
|
bounds.left, bounds.top,
|
||||||
|
bounds.width, bounds.height,
|
||||||
|
SWP_NOZORDER))
|
||||||
|
throw win32_error("SetWindowPos failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
void CWindow::SetBounds(const RECT &rect)
|
||||||
|
{
|
||||||
|
bounds = rect;
|
||||||
|
if (hwnd)
|
||||||
|
if (!SetWindowPos(hwnd, NULL,
|
||||||
|
bounds.left, bounds.top,
|
||||||
|
bounds.width, bounds.height,
|
||||||
|
SWP_NOZORDER))
|
||||||
|
throw win32_error("SetWindowPos failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
HWND CWindow::GetHandle()
|
||||||
|
{
|
||||||
|
if (hwnd == NULL)
|
||||||
|
Create();
|
||||||
|
return hwnd;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CWindow::SetParent(CWindow *window)
|
||||||
|
{
|
||||||
|
parent = window->GetHandle();
|
||||||
|
if (hwnd != NULL)
|
||||||
|
if (::SetParent(hwnd, parent) == NULL)
|
||||||
|
throw win32_error("SetParent failed");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void CWindow::SetStyle(DWORD style)
|
||||||
|
{
|
||||||
|
this->style = style;
|
||||||
|
SetLastError(0);
|
||||||
|
if (hwnd)
|
||||||
|
SetWindowLong(hwnd, GWL_STYLE, style);
|
||||||
|
int err = GetLastError();
|
||||||
|
if (err != 0)
|
||||||
|
throw win32_error("SetWindowLong failed", err);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CWindow::SetExStyle(DWORD exstyle)
|
||||||
|
{
|
||||||
|
this->exstyle = exstyle;
|
||||||
|
SetLastError(0);
|
||||||
|
if (hwnd)
|
||||||
|
SetWindowLong(hwnd, GWL_EXSTYLE, exstyle);
|
||||||
|
int err = GetLastError();
|
||||||
|
if (err != 0)
|
||||||
|
throw win32_error("SetWindowWLong failed", err);
|
||||||
|
}
|
|
@ -0,0 +1,114 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2005 Alexander Gottwald
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
* to deal in the Software without restriction, including without limitation
|
||||||
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
* and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
* Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||||
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
* DEALINGS IN THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* Except as contained in this notice, the name(s) of the above copyright
|
||||||
|
* holders shall not be used in advertising or otherwise to promote the sale,
|
||||||
|
* use or other dealings in this Software without prior written authorization.
|
||||||
|
*/
|
||||||
|
#ifndef __WINDOW_H__
|
||||||
|
#define __WINDOW_H__
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class CDialog;
|
||||||
|
class CWindow
|
||||||
|
{
|
||||||
|
friend class CDialog;
|
||||||
|
public:
|
||||||
|
struct CBoundary
|
||||||
|
{
|
||||||
|
int left;
|
||||||
|
int top;
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
CBoundary() :
|
||||||
|
left(0), top(0), width(0), height(0) {};
|
||||||
|
CBoundary(int x, int y, int w, int h) :
|
||||||
|
left(x), top(y), width(w), height(h) {};
|
||||||
|
CBoundary(const RECT &r) :
|
||||||
|
left(r.left), top(r.top), width(r.right-r.left), height(r.bottom-r.top) {};
|
||||||
|
};
|
||||||
|
class CWindowClass
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
WNDPROC wndproc;
|
||||||
|
ATOM atom;
|
||||||
|
std::string classname;
|
||||||
|
protected:
|
||||||
|
void Register();
|
||||||
|
public:
|
||||||
|
CWindowClass(const char *name, WNDPROC wndproc);
|
||||||
|
~CWindowClass();
|
||||||
|
const char *GetClassName() { return classname.c_str(); };
|
||||||
|
};
|
||||||
|
private:
|
||||||
|
static CWindowClass windowClass;
|
||||||
|
|
||||||
|
std::string title;
|
||||||
|
DWORD exstyle;
|
||||||
|
DWORD style;
|
||||||
|
CBoundary bounds;
|
||||||
|
HWND hwnd;
|
||||||
|
HWND parent;
|
||||||
|
WNDPROC owndproc;
|
||||||
|
|
||||||
|
BOOL showing;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
virtual const char *GetClassName();
|
||||||
|
virtual HWND CreateWindowHandle();
|
||||||
|
static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||||
|
public:
|
||||||
|
CWindow(const char *title);
|
||||||
|
virtual void Create();
|
||||||
|
|
||||||
|
virtual int ShowModal();
|
||||||
|
|
||||||
|
void Show();
|
||||||
|
void Hide();
|
||||||
|
|
||||||
|
void SetWidth(int width);
|
||||||
|
void SetHeight(int height);
|
||||||
|
void SetLeft(int left);
|
||||||
|
void SetTop(int top);
|
||||||
|
int GetWidth() { return bounds.width; };
|
||||||
|
int GetHeight() { return bounds.height; };
|
||||||
|
int GetLeft() { return bounds.left; };
|
||||||
|
int GetTop() { return bounds.top; };
|
||||||
|
|
||||||
|
void SetBounds(int left, int top, int width, int height);
|
||||||
|
void SetBounds(const RECT &rect);
|
||||||
|
|
||||||
|
void SetStyle(DWORD style);
|
||||||
|
DWORD GetStyle() { return style; };
|
||||||
|
|
||||||
|
void SetExStyle(DWORD exstyle);
|
||||||
|
DWORD GetExStyle() { return exstyle; };
|
||||||
|
|
||||||
|
HWND GetHandle();
|
||||||
|
void SetParent(CWindow *window);
|
||||||
|
|
||||||
|
virtual LRESULT Dispatch(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,244 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2005 Alexander Gottwald
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
* to deal in the Software without restriction, including without limitation
|
||||||
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
* and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
* Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||||
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
* DEALINGS IN THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* Except as contained in this notice, the name(s) of the above copyright
|
||||||
|
* holders shall not be used in advertising or otherwise to promote the sale,
|
||||||
|
* use or other dealings in this Software without prior written authorization.
|
||||||
|
*/
|
||||||
|
#include "wizard.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
CWizard::CWizard() : pages()
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
void CWizard::AddPage(const PROPSHEETPAGE &page)
|
||||||
|
{
|
||||||
|
pages.push_back(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CWizard::AddPage(const char *page, HINSTANCE instance)
|
||||||
|
{
|
||||||
|
PROPSHEETPAGE psp;
|
||||||
|
if (instance == NULL)
|
||||||
|
instance = GetModuleHandle(NULL);
|
||||||
|
|
||||||
|
memset(&psp, 0, sizeof(psp));
|
||||||
|
psp.dwSize = sizeof(PROPSHEETPAGE);
|
||||||
|
psp.dwFlags = PSP_DEFAULT;
|
||||||
|
psp.hInstance = instance;
|
||||||
|
psp.pszTemplate = page;
|
||||||
|
psp.pfnDlgProc = WizardDialogProc;
|
||||||
|
psp.lParam = (LPARAM)this;
|
||||||
|
|
||||||
|
AddPage(psp);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CWizard::AddPage(DWORD id, DWORD title, DWORD subtitle, HINSTANCE instance)
|
||||||
|
{
|
||||||
|
PROPSHEETPAGE psp;
|
||||||
|
if (instance == NULL)
|
||||||
|
instance = GetModuleHandle(NULL);
|
||||||
|
|
||||||
|
memset(&psp, 0, sizeof(psp));
|
||||||
|
psp.dwSize = sizeof(PROPSHEETPAGE);
|
||||||
|
psp.dwFlags = PSP_DEFAULT;
|
||||||
|
#if _WIN32_IE >= 0x0500
|
||||||
|
if (title != 0)
|
||||||
|
{
|
||||||
|
psp.dwFlags |= PSP_USEHEADERTITLE;
|
||||||
|
psp.pszHeaderTitle = MAKEINTRESOURCE(title);
|
||||||
|
}
|
||||||
|
if (subtitle != 0)
|
||||||
|
{
|
||||||
|
psp.dwFlags |= PSP_USEHEADERSUBTITLE;
|
||||||
|
psp.pszHeaderSubTitle = MAKEINTRESOURCE(subtitle);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
psp.hInstance = instance;
|
||||||
|
psp.pszTemplate = MAKEINTRESOURCE(id);
|
||||||
|
psp.pfnDlgProc = WizardDialogProc;
|
||||||
|
psp.lParam = (LPARAM)this;
|
||||||
|
|
||||||
|
AddPage(psp);
|
||||||
|
}
|
||||||
|
|
||||||
|
HWND CWizard::CreateWindowHandle()
|
||||||
|
{
|
||||||
|
PROPSHEETHEADER psh;
|
||||||
|
HWND ret;
|
||||||
|
|
||||||
|
PrepareSheetHeader(psh, FALSE);
|
||||||
|
ret = (HWND)PropertySheet(&psh);
|
||||||
|
free(psh.phpage);
|
||||||
|
if (ret == NULL)
|
||||||
|
throw win32_error("PropertySheet failed");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CWizard::ShowModal()
|
||||||
|
{
|
||||||
|
PROPSHEETHEADER psh;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
PrepareSheetHeader(psh, TRUE);
|
||||||
|
ret = PropertySheet(&psh);
|
||||||
|
free(psh.phpage);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CWizard::PrepareSheetHeader(PROPSHEETHEADER &psh, BOOL modal)
|
||||||
|
{
|
||||||
|
HPROPSHEETPAGE *phpage = (HPROPSHEETPAGE*)malloc(pages.size() * sizeof(HPROPSHEETPAGE));
|
||||||
|
DWORD modeflag;
|
||||||
|
|
||||||
|
if (modal)
|
||||||
|
modeflag = 0;
|
||||||
|
else
|
||||||
|
modeflag = PSH_MODELESS;
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < pages.size(); i++)
|
||||||
|
{
|
||||||
|
phpage[i] = CreatePropertySheetPage(&pages[i]);
|
||||||
|
if (phpage[i] == NULL)
|
||||||
|
{
|
||||||
|
DWORD err = GetLastError();
|
||||||
|
free(phpage);
|
||||||
|
throw win32_error("CreatePropertySheetPage failed", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(&psh, 0, sizeof(psh));
|
||||||
|
psh.dwSize = sizeof(PROPSHEETHEADER);
|
||||||
|
#if _WIN32_IE >= 0x0500
|
||||||
|
psh.dwFlags = PSH_WIZARD97 | modeflag;
|
||||||
|
#else
|
||||||
|
psh.dwFlags = PSH_WIZARD | modeflag;
|
||||||
|
#endif
|
||||||
|
psh.hwndParent = NULL;
|
||||||
|
psh.hInstance = GetModuleHandle(NULL);
|
||||||
|
psh.pszIcon = NULL;
|
||||||
|
psh.pszCaption = (LPSTR) "Cell Properties";
|
||||||
|
psh.nPages = pages.size();
|
||||||
|
psh.nStartPage = 0;
|
||||||
|
psh.phpage = phpage;
|
||||||
|
psh.pfnCallback = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
DWORD CWizard::PageID(unsigned index)
|
||||||
|
{
|
||||||
|
if (index < pages.size() && IS_INTRESOURCE(pages[index].pszTemplate))
|
||||||
|
return (DWORD)pages[index].pszTemplate;
|
||||||
|
return (DWORD)-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned CWizard::PageIndex(PROPSHEETPAGE *psp)
|
||||||
|
{
|
||||||
|
for (unsigned i = 0; i < pages.size(); i++)
|
||||||
|
{
|
||||||
|
if (IS_INTRESOURCE(psp->pszTemplate) || IS_INTRESOURCE(pages[i].pszTemplate ))
|
||||||
|
{
|
||||||
|
if (psp->pszTemplate == pages[i].pszTemplate)
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
else if (psp->pszTemplate && pages[i].pszTemplate)
|
||||||
|
{
|
||||||
|
if (strcmp(psp->pszTemplate, pages[i].pszTemplate) == 0)
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (unsigned)-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
INT_PTR CWizard::DlgDispatch(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
|
{
|
||||||
|
return CBaseDialog::DlgDispatch(hwndDlg, uMsg, wParam, lParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
INT_PTR CWizard::PageDispatch(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam, PROPSHEETPAGE *psp)
|
||||||
|
{
|
||||||
|
LPNMHDR pnmh = (LPNMHDR)lParam;
|
||||||
|
DWORD flags;
|
||||||
|
unsigned pageindex;
|
||||||
|
switch (uMsg)
|
||||||
|
{
|
||||||
|
case WM_NOTIFY:
|
||||||
|
switch (pnmh->code)
|
||||||
|
{
|
||||||
|
case PSN_SETACTIVE:
|
||||||
|
#ifdef _DEBUG
|
||||||
|
printf("PSN_SETACTIVE %d\n", PageIndex(psp));
|
||||||
|
#endif
|
||||||
|
pageindex = PageIndex(psp);
|
||||||
|
if (pageindex != (unsigned)-1)
|
||||||
|
{
|
||||||
|
flags = 0;
|
||||||
|
if (pageindex > 0)
|
||||||
|
flags |= PSWIZB_BACK;
|
||||||
|
if ((unsigned)pageindex + 1 == pages.size())
|
||||||
|
flags |= PSWIZB_FINISH;
|
||||||
|
if ((unsigned)pageindex + 1 < pages.size())
|
||||||
|
flags |= PSWIZB_NEXT;
|
||||||
|
PropSheet_SetWizButtons(GetParent(hwndDlg), flags);
|
||||||
|
}
|
||||||
|
WizardActivate(hwndDlg, pageindex);
|
||||||
|
break;
|
||||||
|
case PSN_WIZNEXT:
|
||||||
|
if (WizardNext(hwndDlg, PageIndex(psp)))
|
||||||
|
return TRUE;
|
||||||
|
break;
|
||||||
|
case PSN_WIZBACK:
|
||||||
|
if (WizardBack(hwndDlg, PageIndex(psp)))
|
||||||
|
return TRUE;
|
||||||
|
break;
|
||||||
|
case PSN_WIZFINISH:
|
||||||
|
if (WizardFinish(hwndDlg, PageIndex(psp)))
|
||||||
|
return TRUE;
|
||||||
|
DestroyWindow(GetParent(hwndDlg));
|
||||||
|
case PSN_RESET:
|
||||||
|
if (WizardReset(hwndDlg, PageIndex(psp)))
|
||||||
|
return TRUE;
|
||||||
|
DestroyWindow(GetParent(hwndDlg));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return DlgDispatch(hwndDlg, uMsg, wParam, lParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
INT_PTR CALLBACK CWizard::WizardDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
|
{
|
||||||
|
MessageDebug::debug(hwndDlg, uMsg, wParam, lParam, __FUNCTION__);
|
||||||
|
PROPSHEETPAGE *psp = (PROPSHEETPAGE*)lParam;
|
||||||
|
switch (uMsg)
|
||||||
|
{
|
||||||
|
case WM_INITDIALOG:
|
||||||
|
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)psp);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
psp = (PROPSHEETPAGE*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
|
||||||
|
CWizard* wizard = psp?(CWizard*)psp->lParam:NULL;
|
||||||
|
if (wizard != NULL)
|
||||||
|
return wizard->PageDispatch(hwndDlg, uMsg, wParam, lParam, psp);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2005 Alexander Gottwald
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
* to deal in the Software without restriction, including without limitation
|
||||||
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
* and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
* Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||||
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
* DEALINGS IN THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* Except as contained in this notice, the name(s) of the above copyright
|
||||||
|
* holders shall not be used in advertising or otherwise to promote the sale,
|
||||||
|
* use or other dealings in this Software without prior written authorization.
|
||||||
|
*/
|
||||||
|
#ifndef __WIZARD_H__
|
||||||
|
#define __WIZARD_H__
|
||||||
|
|
||||||
|
#include "dialog.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#define _WIN32_IE 0x0500
|
||||||
|
#include <prsht.h>
|
||||||
|
|
||||||
|
class CWizard : public CBaseDialog
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
std::vector<PROPSHEETPAGE> pages;
|
||||||
|
void PrepareSheetHeader(PROPSHEETHEADER &psh, BOOL modal);
|
||||||
|
protected:
|
||||||
|
virtual HWND CreateWindowHandle();
|
||||||
|
static INT_PTR CALLBACK WizardDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||||
|
virtual INT_PTR DlgDispatch(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||||
|
virtual INT_PTR PageDispatch(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam, PROPSHEETPAGE *psp);
|
||||||
|
virtual unsigned PageIndex(PROPSHEETPAGE *psp);
|
||||||
|
virtual DWORD PageID(unsigned index);
|
||||||
|
virtual BOOL WizardNext(HWND hwndDlg, unsigned index) { return FALSE; }
|
||||||
|
virtual BOOL WizardBack(HWND hwndDlg, unsigned index) { return FALSE; }
|
||||||
|
virtual BOOL WizardFinish(HWND hwndDlg, unsigned index) { return FALSE; }
|
||||||
|
virtual BOOL WizardReset(HWND hwndDlg, unsigned index) { return FALSE; }
|
||||||
|
virtual BOOL WizardActivate(HWND hwndDlg, unsigned index) { return FALSE; }
|
||||||
|
public:
|
||||||
|
CWizard();
|
||||||
|
void AddPage(const PROPSHEETPAGE &page);
|
||||||
|
void AddPage(const char *page, HINSTANCE instance = NULL);
|
||||||
|
void AddPage(DWORD id, DWORD title, DWORD subtitle, HINSTANCE instance = NULL);
|
||||||
|
virtual int ShowModal();
|
||||||
|
};
|
||||||
|
#endif
|
Loading…
Reference in New Issue