1 /* AbiWord
2  * Copyright (C) 2000 AbiSource, Inc.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301 USA.
18  */
19 
20 #include <windows.h>
21 
22 #include "ut_string.h"
23 #include "ut_assert.h"
24 #include "ut_debugmsg.h"
25 
26 #include "xap_App.h"
27 #include "xap_Win32App.h"
28 #include "xap_Win32FrameImpl.h"
29 
30 #include "ap_Strings.h"
31 #include "ap_Dialog_Id.h"
32 #include "ap_Dialog_Background.h"
33 #include "ap_Win32Dialog_Background.h"
34 #include "xap_Win32DialogHelper.h"
35 #include "ap_Win32Resources.rc2"
36 
37 /*****************************************************************/
38 
static_constructor(XAP_DialogFactory * pFactory,XAP_Dialog_Id id)39 XAP_Dialog * AP_Win32Dialog_Background::static_constructor(XAP_DialogFactory * pFactory,
40 													 XAP_Dialog_Id id)
41 {
42 	AP_Win32Dialog_Background * p = new AP_Win32Dialog_Background(pFactory,id);
43 	return p;
44 }
45 
AP_Win32Dialog_Background(XAP_DialogFactory * pDlgFactory,XAP_Dialog_Id id)46 AP_Win32Dialog_Background::AP_Win32Dialog_Background(XAP_DialogFactory * pDlgFactory,
47 										 XAP_Dialog_Id id)
48 	: AP_Dialog_Background(pDlgFactory,id)
49 {
50 }
51 
~AP_Win32Dialog_Background(void)52 AP_Win32Dialog_Background::~AP_Win32Dialog_Background(void)
53 {
54 }
55 
s_hookProc(HWND hdlg,UINT uiMsg,WPARAM,LPARAM lParam)56 UINT CALLBACK AP_Win32Dialog_Background::s_hookProc(HWND hdlg,UINT uiMsg,WPARAM /*wParam*/,LPARAM lParam)
57 {
58 	AP_Win32Dialog_Background * pThis = NULL;
59 	if (uiMsg==WM_INITDIALOG)
60 	{
61 		CHOOSECOLORW * pCC = NULL;
62 		pCC = (CHOOSECOLORW *) lParam;
63 		pThis = (AP_Win32Dialog_Background *)pCC->lCustData;
64 		SetWindowLongPtrW(hdlg, DWLP_USER, (LONG_PTR) pThis);
65 		pThis->m_hDlg = hdlg;
66 		pThis->_centerDialog();
67 		return 1;
68 	}
69 	else
70 	{
71 		pThis = (AP_Win32Dialog_Background *)GetWindowLongPtrW(hdlg, DWLP_USER);
72 	}
73 
74 	if (uiMsg==WM_HELP)
75 	{
76 		pThis->_callHelp();
77 		return 1;
78 	}
79 
80 	return 0;
81 }
82 
runModal(XAP_Frame * pFrame)83 void AP_Win32Dialog_Background::runModal(XAP_Frame * pFrame)
84 {
85 	UT_return_if_fail (pFrame);
86 
87 	const gchar *  pszC = getColor();
88 	UT_RGBColor rgbColor(255,255,255);
89 	if(strcmp(pszC,"transparent") != 0)
90 	{
91 		UT_parseColor(pszC,rgbColor);
92 	}
93 
94 
95 	CHOOSECOLORW cc;                 // common dialog box structure
96 	static COLORREF acrCustClr[16]; // array of custom colors
97 	DWORD rgbCurrent;				// initial color selection
98 
99 	rgbCurrent = RGB( rgbColor.m_red, rgbColor.m_grn, rgbColor.m_blu );
100 
101 	// Initialize CHOOSECOLOR
102 	ZeroMemory(&cc, sizeof(CHOOSECOLORW));
103 	cc.lStructSize = sizeof(CHOOSECOLORW);
104 	cc.hwndOwner = static_cast<XAP_Win32FrameImpl*>(pFrame->getFrameImpl())->getTopLevelWindow();
105 	cc.lpCustColors = (LPDWORD) acrCustClr;
106 	cc.rgbResult = rgbCurrent;
107 	cc.Flags = CC_RGBINIT |CC_ENABLEHOOK;
108 	cc.lpfnHook  = (LPCFHOOKPROC) &AP_Win32Dialog_Background::s_hookProc;
109 	cc.lCustData = (LPARAM)this;
110 
111 	if( ChooseColorW(&cc) )
112 	{
113 		rgbCurrent = cc.rgbResult;
114 
115 		UT_setColor( rgbColor, GetRValue(rgbCurrent), GetGValue(rgbCurrent), GetBValue(rgbCurrent) );
116 		setColor( rgbColor );
117 
118 		setAnswer( a_OK );
119 	}
120 	else
121 		setAnswer( a_CANCEL );
122 }
123 
_centerDialog()124 void AP_Win32Dialog_Background::_centerDialog()
125 {
126 	UT_return_if_fail (IsWindow(m_hDlg));
127 
128 	RECT 	rc, rcParent;
129 	int 	nWidth, nHeight;
130 	POINT 	pt;
131 
132     GetWindowRect(m_hDlg, &rc);
133 
134    	if (!GetParent(m_hDlg))
135 	  GetWindowRect (GetDesktopWindow(), &rcParent);
136 	else
137 	  GetClientRect (GetParent(m_hDlg), &rcParent);
138 
139 	nWidth = rc.right - rc.left;
140 	nHeight = rc.bottom - rc.top;
141 
142 	pt.x = (rcParent.right - rcParent.left) / 2;
143 	pt.y = (rcParent.bottom - rcParent.top) / 2;
144 
145 	if (!GetParent(m_hDlg))
146 	  ClientToScreen (GetDesktopWindow(), &pt);
147 	else
148 	  ClientToScreen (GetParent(m_hDlg), &pt);
149 
150 	pt.x -= nWidth / 2;
151 	pt.y -= nHeight / 2;
152 
153 	// Move your arse...
154 	MoveWindow (m_hDlg, pt.x, pt.y, nWidth, nHeight, TRUE);
155 }
156 
157 extern bool helpLocalizeAndOpenURL(const char* pathBeforeLang, const char* pathAfterLang, const char *remoteURLbase);
158 
_callHelp()159 void AP_Win32Dialog_Background::_callHelp()
160 {
161 	if ( getHelpUrl().size () > 0 )
162     {
163 		helpLocalizeAndOpenURL ("help", getHelpUrl().c_str(), "http://www.abisource.com/help/");
164     }
165 	else
166     {
167 		// TODO: warn no help on this topic
168 		// UT_DEBUGMSG(("NO HELP FOR THIS TOPIC!!\n"));
169     }
170 	return;
171 }
172 
173