2 * PROJECT: ReactOS Character Map
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/charmap/GridView.cpp
5 * PURPOSE: Class for for the window which contains the font matrix
6 * COPYRIGHT: Copyright 2015 Ged Murphy <gedmurphy@reactos.org>
15 /* DATA *****************************************************/
17 extern HINSTANCE g_hInstance
;
20 /* PUBLIC METHODS **********************************************/
22 CGridView::CGridView() :
26 m_szMapWndClass
= L
"CharGridWClass";
29 CGridView::~CGridView()
39 wc
.style
= CS_DBLCLKS
;
40 wc
.lpfnWndProc
= MapWndProc
;
41 wc
.cbWndExtra
= sizeof(CGridView
*);
42 wc
.hInstance
= g_hInstance
;
43 wc
.hCursor
= LoadCursorW(NULL
, (LPWSTR
)IDC_ARROW
);
44 wc
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
45 wc
.lpszClassName
= m_szMapWndClass
;
47 if (RegisterClassW(&wc
))
49 m_hwnd
= CreateWindowExW(0,
52 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| WS_VSCROLL
,
61 return !!(m_hwnd
!= NULL
);
65 CGridView::UpdateGridLayout(
68 // Go through all the cells and calculate
69 // their coordinates within the grid
70 for (int y
= 0; y
< m_yNumCells
; y
++)
71 for (int x
= 0; x
< m_xNumCells
; x
++)
74 CellCoordinates
.left
= x
* m_CellSize
.cx
+ 1;
75 CellCoordinates
.top
= y
* m_CellSize
.cy
+ 1;
76 CellCoordinates
.right
= (x
+ 1) * m_CellSize
.cx
+ 2;
77 CellCoordinates
.bottom
= (y
+ 1) * m_CellSize
.cy
+ 2;
79 m_Cells
[y
][x
]->SetCellCoordinates(CellCoordinates
);
94 // C++ doesn't allow : "CCells ***C = new CCell***[x * y]"
95 // so we have to build the 2d array up manually
96 m_Cells
= new CCell
**[m_yNumCells
]; // rows
97 for (int i
= 0; i
< m_yNumCells
; i
++)
98 m_Cells
[i
] = new CCell
*[m_xNumCells
]; // columns
100 for (int y
= 0; y
< m_yNumCells
; y
++)
101 for (int x
= 0; x
< m_xNumCells
; x
++)
103 m_Cells
[y
][x
] = new CCell(m_hwnd
);
106 // Give the first cell focus
107 SetCellFocus(m_Cells
[0][0]);
118 // Get the client area of the main dialog
120 GetClientRect(m_hParent
, &ParentRect
);
122 // Calculate the grid size using the parent
123 m_ClientCoordinates
.left
= ParentRect
.left
+ 25;
124 m_ClientCoordinates
.top
= ParentRect
.top
+ 50;
125 m_ClientCoordinates
.right
= ParentRect
.right
- m_ClientCoordinates
.left
- 10;
126 m_ClientCoordinates
.bottom
= ParentRect
.bottom
- m_ClientCoordinates
.top
- 70;
130 m_ClientCoordinates
.left
,
131 m_ClientCoordinates
.top
,
132 m_ClientCoordinates
.right
,
133 m_ClientCoordinates
.bottom
,
134 SWP_NOZORDER
| SWP_SHOWWINDOW
);
136 // Get the client area we can draw on. The position we set above
137 // includes a scrollbar. GetClientRect gives us the size without
138 // the scroll, and it more efficient than getting the scroll
139 // metrics and calculating the size
141 GetClientRect(m_hwnd
, &ClientRect
);
142 m_CellSize
.cx
= ClientRect
.right
/ m_xNumCells
;
143 m_CellSize
.cy
= ClientRect
.bottom
/ m_yNumCells
;
155 PAINTSTRUCT PaintStruct
= { 0 };
157 BOOL bSuccess
= FALSE
;
159 // Check if we were passed a DC
162 // We weren't, let's get one
163 LocalHdc
= BeginPaint(m_hwnd
, &PaintStruct
);
164 if (LocalHdc
) bSuccess
= TRUE
;
168 // Use the existing DC and just get the region to paint
169 bSuccess
= GetUpdateRect(m_hwnd
,
170 &PaintStruct
.rcPaint
,
174 // Update the struct with the DC we were passed
175 PaintStruct
.hdc
= (HDC
)hdc
;
181 DrawGrid(&PaintStruct
);
185 EndPaint(m_hwnd
, &PaintStruct
);
194 CGridView::MapWndProc(
204 // Get the object pointer from window context
205 This
= (CGridView
*)GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
208 // Check that this isn't a create message
209 if (uMsg
!= WM_CREATE
)
211 // Don't handle null info pointer
212 goto HandleDefaultMessage
;
220 // Get the object pointer from the create param
221 This
= (CGridView
*)((LPCREATESTRUCT
)lParam
)->lpCreateParams
;
223 // Store the pointer in the window's global user data
224 SetWindowLongPtr(hwnd
, GWLP_USERDATA
, (LONG_PTR
)This
);
226 This
->OnCreate(hwnd
, ((LPCREATESTRUCTW
)lParam
)->hwndParent
);
233 Width
= LOWORD(lParam
);
234 Height
= HIWORD(lParam
);
236 This
->OnSize(Width
, Height
);
242 This
->OnPaint((HDC
)wParam
);
254 HandleDefaultMessage
:
255 RetCode
= DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
266 _In_ LPPAINTSTRUCT PaintStruct
269 // Traverse all the cells and tell them to paint themselves
270 for (int y
= 0; y
< m_yNumCells
; y
++)
271 for (int x
= 0; x
< m_xNumCells
; x
++)
273 m_Cells
[y
][x
]->OnPaint(*PaintStruct
);
278 CGridView::DeleteCells()
280 if (m_Cells
== nullptr)
283 // Free cells withing the 2d array
284 for (int i
= 0; i
< m_yNumCells
; i
++)
292 CGridView::SetCellFocus(
293 _In_ CCell
* NewActiveCell
298 // Remove focus from any existing cell
299 m_ActiveCell
->SetFocus(false);
302 // Set the new active cell and give it focus
303 m_ActiveCell
= NewActiveCell
;
304 m_ActiveCell
->SetFocus(true);