1 /* AbiWord
2 * Copyright (C) 2002 Jordi Mas i Hern�ndez <jmas@softcatala.org>
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 <stdlib.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 #include "xap_Win32Toolbar_Icons.h"
30 #include "xap_Win32DialogHelper.h"
31
32 #include "ap_Strings.h"
33 #include "ap_Dialog_Id.h"
34 #include "ap_Dialog_SplitCells.h"
35 #include "ap_Win32Dialog_SplitCells.h"
36 #include "ap_Win32Resources.rc2"
37
38
39 #define BITMAP_WITDH 50
40 #define BITMAP_HEIGHT 50
41
42
static_constructor(XAP_DialogFactory * pFactory,XAP_Dialog_Id id)43 XAP_Dialog * AP_Win32Dialog_SplitCells::static_constructor(XAP_DialogFactory * pFactory,
44 XAP_Dialog_Id id)
45 {
46 AP_Win32Dialog_SplitCells * p = new AP_Win32Dialog_SplitCells(pFactory,id);
47 return p;
48 }
49
AP_Win32Dialog_SplitCells(XAP_DialogFactory * pDlgFactory,XAP_Dialog_Id id)50 AP_Win32Dialog_SplitCells::AP_Win32Dialog_SplitCells(XAP_DialogFactory * pDlgFactory,
51 XAP_Dialog_Id id)
52 : AP_Dialog_SplitCells(pDlgFactory,id)
53 {
54 m_hBitmapAbove = NULL;
55 m_hBitmapHoriMid = NULL;
56 m_hBitmapBelow = NULL;
57 m_hBitmapLeft = NULL;
58 m_hBitmapVertMid = NULL;
59 m_hBitmapRight = NULL;
60 }
61
~AP_Win32Dialog_SplitCells(void)62 AP_Win32Dialog_SplitCells::~AP_Win32Dialog_SplitCells(void)
63 {
64 if (m_hBitmapAbove) DeleteObject(m_hBitmapAbove);
65 if (m_hBitmapHoriMid) DeleteObject(m_hBitmapHoriMid);
66 if (m_hBitmapBelow) DeleteObject(m_hBitmapBelow);
67 if (m_hBitmapLeft) DeleteObject(m_hBitmapLeft);
68 if (m_hBitmapVertMid) DeleteObject(m_hBitmapVertMid);
69 if (m_hBitmapRight) DeleteObject(m_hBitmapRight);
70 }
71
runModeless(XAP_Frame * pFrame)72 void AP_Win32Dialog_SplitCells::runModeless(XAP_Frame * pFrame)
73 {
74 UT_return_if_fail (pFrame);
75 UT_return_if_fail (m_id == AP_DIALOG_ID_SPLIT_CELLS);
76
77 createModeless(pFrame, MAKEINTRESOURCEW(AP_RID_DIALOG_SPLITCELLS));
78
79 // Save dialog the ID number and pointer to the widget
80 UT_sint32 sid =(UT_sint32) getDialogId();
81 m_pApp->rememberModelessId( sid, (XAP_Dialog_Modeless *) m_pDialog);
82
83 startUpdater();
84 }
85
86
87 #define _DS(c,s) setDlgItemText(AP_RID_DIALOG_SPLITCELLS_##c,pSS->getValue(AP_STRING_ID_##s))
88 #define _DSX(c,s) setDlgItemText(AP_RID_DIALOG_SPLITCELLS_##c,pSS->getValue(XAP_STRING_ID_##s))
89
90
91 // This handles the WM_INITDIALOG message for the top-level dialog.
_onInitDialog(HWND hWnd,WPARAM,LPARAM)92 BOOL AP_Win32Dialog_SplitCells::_onInitDialog(HWND hWnd, WPARAM /*wParam*/, LPARAM /*lParam*/)
93 {
94 RECT rect;
95 DWORD dwColor = GetSysColor(COLOR_BTNFACE);
96 UT_RGBColor Color(GetRValue(dwColor),GetGValue(dwColor),GetBValue(dwColor));
97 const XAP_StringSet * pSS = m_pApp->getStringSet();
98
99 // Localise caption
100 setDialogTitle (pSS->getValue(AP_STRING_ID_DLG_SplitCellsTitle));
101
102
103 // localise controls
104 _DS(TEXT_LEFT, DLG_SplitCells_Left);
105 _DS(TEXT_VERTMID, DLG_SplitCells_VertMid);
106 _DS(TEXT_RIGHT, DLG_SplitCells_Right);
107 _DS(TEXT_ABOVE, DLG_SplitCells_Above);
108 _DS(TEXT_HORIMID, DLG_SplitCells_HoriMid);
109 _DS(TEXT_BELOW, DLG_SplitCells_Below);
110 _DS(TEXT_FRAME, DLG_SplitCells_Frame);
111 _DSX(BTN_CANCEL, DLG_Close);
112
113
114 // The six items are the same size
115 GetClientRect(GetDlgItem(hWnd, AP_RID_DIALOG_SPLITCELLS_BMP_LEFT), &rect);
116
117 // Load the bitmaps into the dialog box
118 m_hBitmapLeft = XAP_Win32DialogHelper::s_loadBitmap(hWnd,AP_RID_DIALOG_SPLITCELLS_BMP_LEFT, "SPLITLEFT", BITMAP_WITDH, BITMAP_HEIGHT, Color);
119 m_hBitmapRight = XAP_Win32DialogHelper::s_loadBitmap(hWnd,AP_RID_DIALOG_SPLITCELLS_BMP_VERTMID, "SPLITVERTMID", BITMAP_WITDH, BITMAP_HEIGHT, Color);
120 m_hBitmapRight = XAP_Win32DialogHelper::s_loadBitmap(hWnd,AP_RID_DIALOG_SPLITCELLS_BMP_RIGHT, "SPLITRIGHT", BITMAP_WITDH, BITMAP_HEIGHT, Color);
121 m_hBitmapAbove = XAP_Win32DialogHelper::s_loadBitmap(hWnd,AP_RID_DIALOG_SPLITCELLS_BMP_ABOVE, "SPLITABOVE", BITMAP_WITDH, BITMAP_HEIGHT, Color);
122 m_hBitmapAbove = XAP_Win32DialogHelper::s_loadBitmap(hWnd,AP_RID_DIALOG_SPLITCELLS_BMP_HORIMID, "SPLITHORIMID", BITMAP_WITDH, BITMAP_HEIGHT, Color);
123 m_hBitmapBelow = XAP_Win32DialogHelper::s_loadBitmap(hWnd,AP_RID_DIALOG_SPLITCELLS_BMP_BELOW, "SPLITBELOW", BITMAP_WITDH, BITMAP_HEIGHT, Color);
124
125 setAllSensitivities();
126 centerDialog();
127
128 SetFocus(GetDlgItem(hWnd,AP_RID_DIALOG_SPLITCELLS_BTN_CANCEL));
129 return 0; // 0 because we called SetFocus
130 }
131
132
133
setSensitivity(AP_CellSplitType splitThis,bool bSens)134 void AP_Win32Dialog_SplitCells::setSensitivity(AP_CellSplitType splitThis, bool bSens)
135 {
136 switch(splitThis)
137 {
138 case hori_left:
139 EnableWindow(GetDlgItem(m_hDlg, AP_RID_DIALOG_SPLITCELLS_BMP_LEFT), bSens);
140 EnableWindow(GetDlgItem(m_hDlg, AP_RID_DIALOG_SPLITCELLS_TEXT_LEFT), bSens);
141 break;
142 case hori_mid:
143 EnableWindow(GetDlgItem(m_hDlg, AP_RID_DIALOG_SPLITCELLS_BMP_HORIMID), bSens);
144 EnableWindow(GetDlgItem(m_hDlg, AP_RID_DIALOG_SPLITCELLS_TEXT_HORIMID), bSens);
145 break;
146 case hori_right:
147 EnableWindow(GetDlgItem(m_hDlg, AP_RID_DIALOG_SPLITCELLS_BMP_RIGHT), bSens);
148 EnableWindow(GetDlgItem(m_hDlg, AP_RID_DIALOG_SPLITCELLS_TEXT_RIGHT), bSens);
149 break;
150 case vert_above:
151 EnableWindow(GetDlgItem(m_hDlg, AP_RID_DIALOG_SPLITCELLS_BMP_ABOVE), bSens);
152 EnableWindow(GetDlgItem(m_hDlg, AP_RID_DIALOG_SPLITCELLS_TEXT_ABOVE), bSens);
153 break;
154 case vert_mid:
155 EnableWindow(GetDlgItem(m_hDlg, AP_RID_DIALOG_SPLITCELLS_BMP_VERTMID), bSens);
156 EnableWindow(GetDlgItem(m_hDlg, AP_RID_DIALOG_SPLITCELLS_TEXT_VERTMID), bSens);
157 break;
158 case vert_below:
159 EnableWindow(GetDlgItem(m_hDlg, AP_RID_DIALOG_SPLITCELLS_BMP_BELOW), bSens);
160 EnableWindow(GetDlgItem(m_hDlg, AP_RID_DIALOG_SPLITCELLS_TEXT_BELOW), bSens);
161 break;
162 default:
163 break;
164 }
165
166 }
167
event_Close(void)168 void AP_Win32Dialog_SplitCells::event_Close(void)
169 {
170 m_answer = a_CANCEL;
171 destroy();
172 }
173
174
notifyActiveFrame(XAP_Frame * pFrame)175 void AP_Win32Dialog_SplitCells::notifyActiveFrame(XAP_Frame *pFrame)
176 {
177 if((HWND)GetWindowLongPtrW(m_hDlg, GWLP_HWNDPARENT) != static_cast<XAP_Win32FrameImpl*>(pFrame->getFrameImpl())->getTopLevelWindow())
178 {
179 ConstructWindowName();
180 setDialogTitle (m_WindowName);
181
182 SetWindowLongPtrW(m_hDlg, GWLP_HWNDPARENT, (LONG_PTR)static_cast<XAP_Win32FrameImpl*>(pFrame->getFrameImpl())->getTopLevelWindow());
183 SetWindowPos(m_hDlg, NULL, 0, 0, 0, 0,
184 SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
185 }
186 setAllSensitivities();
187 }
188
_onCommand(HWND,WPARAM wParam,LPARAM)189 BOOL AP_Win32Dialog_SplitCells::_onCommand(HWND /*hWnd*/, WPARAM wParam, LPARAM /*lParam*/)
190 {
191 WORD wId = LOWORD(wParam);
192
193 switch (wId)
194 {
195 case AP_RID_DIALOG_SPLITCELLS_BMP_LEFT:
196 {
197 setSplitType(hori_left);
198 onSplit();
199 return 1;
200 }
201 case AP_RID_DIALOG_SPLITCELLS_BMP_HORIMID:
202 {
203 setSplitType(hori_mid);
204 onSplit();
205 return 1;
206 }
207 case AP_RID_DIALOG_SPLITCELLS_BMP_RIGHT:
208 {
209 setSplitType(hori_right);
210 onSplit();
211 return 1;
212 }
213
214 case AP_RID_DIALOG_SPLITCELLS_BMP_ABOVE:
215 {
216 setSplitType(vert_above);
217 onSplit();
218 return 1;
219 }
220 case AP_RID_DIALOG_SPLITCELLS_BMP_VERTMID:
221 {
222 setSplitType(vert_mid);
223 onSplit();
224 return 1;
225 }
226 case AP_RID_DIALOG_SPLITCELLS_BMP_BELOW:
227 {
228 setSplitType(vert_below);
229 onSplit();
230 return 1;
231 }
232
233 case AP_RID_DIALOG_SPLITCELLS_BTN_CANCEL:
234 m_answer = a_CANCEL;
235 destroy();
236 return 1;
237
238 default: // we did not handle this notification
239 UT_DEBUGMSG(("WM_Command for id %ld\n",wId));
240 return 0; // return zero to let windows take care of it.
241 }
242 }
243
244
245
destroy(void)246 void AP_Win32Dialog_SplitCells::destroy(void)
247 {
248 finalize();
249
250 UT_DebugOnly<int> iResult = DestroyWindow( m_hDlg );
251 UT_ASSERT_HARMLESS((iResult != 0));
252 }
activate(void)253 void AP_Win32Dialog_SplitCells::activate(void)
254 {
255 ConstructWindowName();
256 setDialogTitle (m_WindowName);
257
258 setAllSensitivities();
259 }
260