Skip to main content
summaryrefslogtreecommitdiffstats
blob: edf3a9e69a19b959eae4df9ec00d4503c4abb10a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*******************************************************************************
 * Copyright (c) 2012 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v2.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/


#pragma once

#include "resource.h"
#include <Shlobj.h>
#include <ShlGuid.h>

#include "IECrossfireExtension.h"
#include "Util.h"
#include "Logger.h"

enum {
	STATE_DISCONNECTED,
	STATE_LISTENING,
	STATE_CONNECTED,
};

class ATL_NO_VTABLE ExplorerBar :
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<ExplorerBar, &CLSID_ExplorerBar>,
	public IClassFactory,
	public IObjectWithSite,
	public IPersistStream,
	public IDeskBand,
	public IInputObject {

public:
	DECLARE_REGISTRY_RESOURCEID(IDR_EXPLORERBAR)
	DECLARE_NOT_AGGREGATABLE(ExplorerBar)
	BEGIN_COM_MAP(ExplorerBar)
		COM_INTERFACE_ENTRY_IID(IID_IInputObject, IInputObject)
//		COM_INTERFACE_ENTRY(IExplorerBar)
		COM_INTERFACE_ENTRY(IClassFactory)
		COM_INTERFACE_ENTRY(IObjectWithSite)
		COM_INTERFACE_ENTRY(IPersistStream)
		COM_INTERFACE_ENTRY(IDeskBand)
	//	COM_INTERFACE_ENTRY(IInputObject)
	END_COM_MAP()
	DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct() {
		return S_OK;
	}

	void FinalRelease() {
	}

public:
	ExplorerBar();
	virtual ~ExplorerBar();

	/* IClassFactory */
	HRESULT STDMETHODCALLTYPE CreateInstance(IUnknown *pUnkOuter, REFIID riid, void **ppvObject);
    HRESULT STDMETHODCALLTYPE LockServer(BOOL fLock);

	/* IObjectWithSite */
	HRESULT STDMETHODCALLTYPE GetSite(REFIID riid, LPVOID *ppvReturn);
	HRESULT STDMETHODCALLTYPE SetSite(IUnknown *pUnkSite);

	/* IPersistStream */
	HRESULT STDMETHODCALLTYPE GetClassID(CLSID *pClassID);
	HRESULT STDMETHODCALLTYPE IsDirty();
	HRESULT STDMETHODCALLTYPE Load(IStream *pStm);
	HRESULT STDMETHODCALLTYPE Save(IStream *pStm, BOOL fClearDirty);
	HRESULT STDMETHODCALLTYPE GetSizeMax(ULARGE_INTEGER *pcbSize);

	/* IDeskBand */
	HRESULT STDMETHODCALLTYPE GetWindow(HWND *phwnd);
	HRESULT STDMETHODCALLTYPE ContextSensitiveHelp(BOOL fEnterMode);
	HRESULT STDMETHODCALLTYPE ShowDW(BOOL fShow);
	HRESULT STDMETHODCALLTYPE CloseDW(DWORD dwReserved);        
	HRESULT STDMETHODCALLTYPE ResizeBorderDW(LPCRECT prcBorder, IUnknown *punkToolbarSite, BOOL fReserved);    
	HRESULT STDMETHODCALLTYPE GetBandInfo(DWORD dwBandID, DWORD dwViewMode, DESKBANDINFO *pdbi);

	/* IInputObject */
    HRESULT STDMETHODCALLTYPE UIActivateIO(BOOL fActivate, LPMSG lpMsg);
    HRESULT STDMETHODCALLTYPE HasFocusIO();
    HRESULT STDMETHODCALLTYPE TranslateAcceleratorIO(LPMSG lpMsg);

private:
	bool createWindow();
	void createControls();
	bool initServer(bool startIfNeeded);
	void layoutControls();
	bool onCommand(HWND hWnd, WPARAM wParam, LPARAM lParam);
	bool onNCCreate(HWND hWnd, WPARAM wParam, LPARAM lParam);
//	bool onPaint(HWND hWnd, WPARAM wParam, LPARAM lParam);
	LRESULT onWndProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam);
	void onServerStateChanged(WPARAM wParam, LPARAM lParam);
	void setErrorText(wchar_t* text);

	bool m_bFocus;
	HINSTANCE g_hInst;
	HWND m_hWnd;
	HWND m_hWndParent;
	HWND m_messageWindow;
	POINT m_portTextSize;
	IInputObjectSite* m_pSite;
	ICrossfireServer* m_server;
	unsigned int m_serverPort;
	int m_serverState;
	WNDCLASS wc;

	/* controls */
	HWND m_button;
	HWND m_errorLabel;
	HWND m_portLabel;
	HWND m_portText;
	HWND m_portUpDown;
	HWND m_separator;
	HWND m_statusLabel;

	static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam);

	/* constants */
	static const UINT ServerStateChangeMsg;
	static const wchar_t* ServerWindowClass;
	static const wchar_t* WindowClass;

	static const int SEPARATOR_WIDTH = 5;
	static const int SPACING_WIDTH = 10;
};

OBJECT_ENTRY_AUTO(__uuidof(ExplorerBar), ExplorerBar)

Back to the top