1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
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 Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "ViewColumn.h"
22 TCHAR
*WndRegKeys
[4][5] = {
24 _T("POPUP BOTTOM RX"),
25 _T("POPUP BOTTOM RY"),
26 _T("POPUP BOTTOM CX"),
27 _T("POPUP BOTTOM CY"),
53 /////////////////////////////////////////////////////////////////////////////
57 ViewColumn::ViewColumn(CWnd
* pParent
/*=NULL*/)
58 : CDialog(ViewColumn::IDD
, pParent
)
60 //{{AFX_DATA_INIT(ViewColumn)
61 // NOTE: the ClassWizard will add member initialization here
64 nTiles
= sizetile_y
= 0;
67 MousePos
.x
= MousePos
.y
= 0;
71 void ViewColumn::DoDataExchange(CDataExchange
* pDX
)
73 CDialog::DoDataExchange(pDX
);
74 //{{AFX_DATA_MAP(ViewColumn)
75 // NOTE: the ClassWizard will add DDX and DDV calls here
80 BEGIN_MESSAGE_MAP(ViewColumn
, CDialog
)
81 //{{AFX_MSG_MAP(ViewColumn)
90 /////////////////////////////////////////////////////////////////////////////
91 // ViewColumn message handlers
93 void ViewColumn::OnPaint()
95 CPaintDC
dc(this); // device context for painting
97 // TODO: Add your message handler code here
98 RECT rect
,wndrect
; SCROLLINFO inf
;
99 int first
,scroll
,nInWnd
,cx
,cy
;
100 GetClientRect(&wndrect
);
103 GetScrollInfo(SB_VERT
,&inf
);
105 if ((nTiles
==0)||(nTiles
==1))
107 dc
.FillSolidRect (&wndrect
, 0xffffffff);
109 if (inf
.nPos
>(10000 - (int)inf
.nPage
)) inf
.nPos
= 10000 - inf
.nPage
- 1;
110 if (inf
.nPage
>=10000) inf
.nPage
= 10000 -1;
113 nInWnd
= (((rect
.bottom
- rect
.top
)/(sizetile_y
>>1))<<1)+2;
114 if (nTiles
>nInWnd
) first
= ((inf
.nPos
*((nTiles
-nInWnd
)>>1))/(10000 - inf
.nPage
))<<1;
116 int n
= (nTiles
+1)>>1;
117 scroll
= ((inf
.nPos
*((sizetile_y
>>1)*n
- (rect
.bottom
- rect
.top
)))/(10000 - inf
.nPage
));
118 if (scroll
>=0) scroll
-= (first
>>1)*(sizetile_y
>>1);
120 rect
.top
-= scroll
; rect
.bottom
-= scroll
;
122 cx
= (rect
.right
- rect
.left
)>>1;
130 cx
= (rect
.right
- rect
.left
);
134 nInWnd
= ((rect
.bottom
- rect
.top
)/sizetile_y
)+1;
135 if (nTiles
>nInWnd
) first
= ((inf
.nPos
*(nTiles
-nInWnd
))/(10000 - inf
.nPage
));
137 scroll
= ((inf
.nPos
*(sizetile_y
*nTiles
- (rect
.bottom
- rect
.top
)))/(10000 - inf
.nPage
));
138 if (scroll
<0) scroll
= 0;
139 else scroll
-=first
*sizetile_y
;
140 rect
.top
-= scroll
; rect
.bottom
-= scroll
;
142 cx
= (rect
.right
- rect
.left
);
146 while (rect
.top
<wndrect
.bottom
)
150 StretchDIBits(dc
,rect
.left
,rect
.top
,cx
,cy
,
151 0,0,list
[i
]->BmpInfo
.bmiHeader
.biWidth
,list
[i
]->BmpInfo
.bmiHeader
.biHeight
,
152 &*list
[i
]->Bits
.begin(),&list
[i
]->BmpInfo
,DIB_RGB_COLORS
,SRCCOPY
);
156 StretchDIBits(dc
,rect
.left
,rect
.top
,cx
,cy
,
158 0,0,DIB_RGB_COLORS
,WHITENESS
);
162 rect
.top
+= sizetile_y
;
163 rect
.bottom
+= sizetile_y
;
165 else if (nTileInWnd
==4)
182 // Do not call CDialog::OnPaint() for painting messages
185 BOOL
ViewColumn::OnInitDialog()
187 CDialog::OnInitDialog();
189 HKEY regkey
; int rx
=-1,ry
=-1,cx
=-1,cy
=-1;
190 if (RegOpenKey(HKEY_CURRENT_USER
,REGKEY_TILEDIT
,®key
)==ERROR_SUCCESS
)
193 RegQueryValueEx(regkey
, WndRegKeys
[pos
&3][0], 0, &value
, (LPBYTE
)&rx
, &value
);
194 RegQueryValueEx(regkey
, WndRegKeys
[pos
&3][1], 0, &value
, (LPBYTE
)&ry
, &value
);
195 RegQueryValueEx(regkey
, WndRegKeys
[pos
&3][2], 0, &value
, (LPBYTE
)&cx
, &value
);
196 RegQueryValueEx(regkey
, WndRegKeys
[pos
&3][3], 0, &value
, (LPBYTE
)&cy
, &value
);
197 RegQueryValueEx(regkey
, WndRegKeys
[pos
&3][4], 0, &value
, (LPBYTE
)&nTileInWnd
, &value
);
200 EnableScrollBar(SB_VERT
);
202 parent
->GetWindowRect(&rect
);
203 if (rx
==-1 || ry
==-1 || cx
==-1 || cy
==-1)
207 cx
= rect
.right
- rect
.left
;
208 cy
= rect
.bottom
- rect
.top
;
215 ry
-=rect
.bottom
- rect
.top
;
218 rx
-=rect
.right
- rect
.left
;
221 rx
+=rect
.right
- rect
.left
;
230 SetWindowPos(0,rx
,ry
,cx
,cy
,0);
232 SendMessage(WM_VSCROLL
,0,0);
233 // TODO: Add extra initialization here
234 return TRUE
; // return TRUE unless you set the focus to a control
235 // EXCEPTION: OCX Property Pages should return FALSE
238 void ViewColumn::OnVScroll(UINT nSBCode
, UINT nPos
, CScrollBar
* pScrollBar
)
240 // TODO: Add your message handler code here and/or call default
241 SCROLLINFO scroll
; RECT rect
;
242 scroll
.fMask
= SIF_TRACKPOS
| SIF_POS
;
243 GetScrollInfo(SB_VERT
,&scroll
);
244 scroll
.cbSize
= sizeof(SCROLLINFO
);
245 scroll
.fMask
= SIF_ALL
;
246 //scroll.nPos = scroll.nTrackPos;
249 GetClientRect(&rect
);
254 scroll
.nPage
= ((rect
.bottom
- rect
.top
)*10000)/(( (nTiles
>>1)+(nTiles
&1) )*(sizetile_y
>>1));
258 scroll
.nPage
= ((rect
.bottom
- rect
.top
)*10000)/(nTiles
*sizetile_y
);
261 else scroll
.nPage
= 10000;
266 scroll
.nPos
= 10000 - scroll
.nPage
;
269 scroll
.nPos
+= scroll
.nPage
/4;
272 scroll
.nPos
-= scroll
.nPage
/4;
275 scroll
.nPos
+= scroll
.nPage
;
278 scroll
.nPos
-= scroll
.nPage
;
280 case SB_THUMBPOSITION
:
282 scroll
.nPos
= scroll
.nTrackPos
;
288 scroll
.fMask
^=SIF_POS
;
293 else if (scroll
.nPos
> (10000 - (int)scroll
.nPage
))
294 scroll
.nPos
= 10000 - scroll
.nPage
- 1;
295 this->SetScrollInfo(SB_VERT
,&scroll
);
297 CDialog::OnVScroll(nSBCode
, nPos
, pScrollBar
);
300 void ViewColumn::OnClose()
302 // TODO: Add your message handler code here and/or call default
307 void ViewColumn::OnSize(UINT nType
, int cx
, int cy
)
309 CDialog::OnSize(nType
, cx
, cy
);
310 SendMessage(WM_VSCROLL
,0,0);
313 LRESULT
ViewColumn::WindowProc(UINT message
, WPARAM wParam
, LPARAM lParam
)
315 // TODO: Add your specialized code here and/or call the base class
316 if (message
==WM_CLOSE
|| message
==WM_DESTROY
)
319 if (RegCreateKey(HKEY_CURRENT_USER
,REGKEY_TILEDIT
,®key
)==ERROR_SUCCESS
)
322 RECT rect
; RECT rpopup
;
323 GetWindowRect(&rect
);
324 parent
->GetWindowRect(&rpopup
);
325 int rx
,ry
,cx
,cy
; //on sauvegarde les coordonnes de la wnd relativement a la fenetre popup principale
326 rx
= rect
.left
- rpopup
.left
;
327 ry
= rect
.top
- rpopup
.top
;
328 cx
= rect
.right
- rect
.left
;
329 cy
= rect
.bottom
- rect
.top
;
330 RegSetValueEx(regkey
,WndRegKeys
[pos
][0],0,REG_DWORD
,(unsigned char*)&rx
,4);
331 RegSetValueEx(regkey
,WndRegKeys
[pos
][1],0,REG_DWORD
,(unsigned char*)&ry
,4);
332 RegSetValueEx(regkey
,WndRegKeys
[pos
][2],0,REG_DWORD
,(unsigned char*)&cx
,4);
333 RegSetValueEx(regkey
,WndRegKeys
[pos
][3],0,REG_DWORD
,(unsigned char*)&cy
,4);
334 RegSetValueEx(regkey
,WndRegKeys
[pos
][4],0,REG_DWORD
,(unsigned char*)&nTileInWnd
,4);
338 else if (message
==WM_MOUSEMOVE
)
340 MousePos
.x
= LOWORD(lParam
);
341 MousePos
.y
= HIWORD(lParam
);
343 else if (message
==WM_ERASEBKGND
)
347 else if (message
==WM_MOUSEWHEEL
)
349 if ((short)(HIWORD(wParam
))<0)
350 SendMessage(WM_VSCROLL
,SB_LINEDOWN
,0);
352 SendMessage(WM_VSCROLL
,SB_LINEUP
,0);
354 else if (message
==WM_COMMAND
)
356 switch(LOWORD(wParam
))
362 SendMessage(WM_VSCROLL
,0,0);
369 SendMessage(WM_VSCROLL
,0,0);
374 parent
->GetWindowRect(&rect
);
378 cx
= rect
.right
- rect
.left
;
379 cy
= rect
.bottom
- rect
.top
;
386 ry
-=rect
.bottom
- rect
.top
;
389 rx
-=rect
.right
- rect
.left
;
392 rx
+=rect
.right
- rect
.left
;
395 SetWindowPos(0,rx
,ry
,cx
,cy
,0);
399 return CDialog::WindowProc(message
, wParam
, lParam
);
402 void ViewColumn::OnRButtonDown(UINT nFlags
, CPoint point
)
404 // TODO: Add your message handler code here and/or call default
406 popup
.CreatePopupMenu();
407 popup
.AppendMenu(MF_STRING
| (nTileInWnd
== 1 ? MF_CHECKED
:0), 10, _T("*1"));
408 popup
.AppendMenu(MF_STRING
| (nTileInWnd
== 4 ? MF_CHECKED
:0), 12, _T("*4"));
409 popup
.AppendMenu(MF_STRING
, 13, _T("Replace window"));
411 RECT rect
; GetWindowRect(&rect
);
412 popup
.TrackPopupMenu(TPM_LEFTALIGN
,MousePos
.x
+rect
.left
,MousePos
.y
+rect
.top
,this,NULL
);
413 CDialog::OnRButtonDown(nFlags
, point
);