~clint-fewbar/ubuntu/precise/squid3/ignore-sighup-early

« back to all changes in this revision

Viewing changes to lib/cppunit-1.10.0/src/msvc6/testrunner/DynamicWindow/cdxCDynamicControlsManager.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2006-11-11 10:32:06 UTC
  • Revision ID: james.westby@ubuntu.com-20061111103206-f3p0r9g0vq44rp3r
Tags: upstream-3.0.PRE5
ImportĀ upstreamĀ versionĀ 3.0.PRE5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// cdxCDynamicControlsManager.cpp: implementation of the cdxCDynamicControlsManager class.
 
2
//
 
3
//////////////////////////////////////////////////////////////////////
 
4
 
 
5
/*
 
6
 * you should define OEMRESOURCE
 
7
 * in your project settings (C/C++, General) !
 
8
 */
 
9
 
 
10
#include "stdafx.h"
 
11
#include "cdxCDynamicControlsManager.h"
 
12
 
 
13
#include        <winuser.h>
 
14
#include        <afxmt.h>
 
15
 
 
16
#ifndef OBM_SIZE
 
17
#define OBM_SIZE                32766
 
18
#pragma message("*** NOTE: cdxCDynamicControlsManager.cpp: Please define OEMRESOURCE in your project settings !")
 
19
// taken from WinresRc.h
 
20
// if not used for any reason
 
21
#endif
 
22
 
 
23
#ifdef _DEBUG
 
24
#define new DEBUG_NEW
 
25
#undef THIS_FILE
 
26
static char THIS_FILE[] = __FILE__;
 
27
#endif
 
28
 
 
29
/////////////////////////////////////////////////////////////////////////////
 
30
// Some static variables
 
31
/////////////////////////////////////////////////////////////////////////////
 
32
 
 
33
#define REGVAL_NOSTATE          -1
 
34
#define REGVAL_VISIBLE          1
 
35
#define REGVAL_HIDDEN           0
 
36
#define REGVAL_MAXIMIZED        1
 
37
#define REGVAL_ICONIC           0
 
38
#define REGVAL_INVALID          0
 
39
#define REGVAL_VALID            1
 
40
 
 
41
/*
 
42
 * registry value names
 
43
 * (for StoreWindowPosition()/RestoreWindowPosition())
 
44
 */
 
45
 
 
46
static LPCTSTR  lpszRegVal_Left         =       _T("Left"),
 
47
                                        lpszRegVal_Right                =       _T("Right"),
 
48
                                        lpszRegVal_Top                  =       _T("Top"),
 
49
                                        lpszRegVal_Bottom               =       _T("Bottom"),
 
50
                                        lpszRegVal_Visible      =       _T("Visibility"),
 
51
                                        lpszRegVal_State                =       _T("State"),
 
52
                                        lpszRegVal_Valid                =       _T("(valid)");
 
53
 
 
54
/////////////////////////////////////////////////////////////////////////////
 
55
// cdxCDynamicControlsManager::ControlData::ControlEntry
 
56
/////////////////////////////////////////////////////////////////////////////
 
57
 
 
58
/////////////////////////////////////////////////////////////////////////////
 
59
// construction/destruction
 
60
/////////////////////////////////////////////////////////////////////////////
 
61
 
 
62
cdxCDynamicControlsManager::ControlData::ControlEntry::ControlEntry(CWnd & ctrl, ControlData & rMaster)
 
63
:       m_rMaster(rMaster), m_rCtrl(ctrl)
 
64
{
 
65
        if(m_pNext = rMaster.m_pCtrl)
 
66
                m_pNext->m_pPrev        =       this;
 
67
        rMaster.m_pCtrl =       this;
 
68
        m_pPrev                         =       NULL;
 
69
 
 
70
        // raise total counter
 
71
        ++rMaster.m_rMaster.m_iTotalCnt;
 
72
}
 
73
 
 
74
cdxCDynamicControlsManager::ControlData::ControlEntry::~ControlEntry()
 
75
{
 
76
        if(m_pPrev)
 
77
        {
 
78
                if(m_pPrev->m_pNext = m_pNext)
 
79
                        m_pNext->m_pPrev        =       m_pPrev;
 
80
        }
 
81
        else
 
82
        {
 
83
                ASSERT( m_rMaster.m_pCtrl == this );
 
84
                if(m_rMaster.m_pCtrl = m_pNext)
 
85
                        m_pNext->m_pPrev        =       NULL;
 
86
        }
 
87
 
 
88
        // lower
 
89
        ASSERT( m_rMaster.m_rMaster.m_iTotalCnt > 0 );
 
90
        ++m_rMaster.m_rMaster.m_iTotalCnt;
 
91
}
 
92
 
 
93
/////////////////////////////////////////////////////////////////////////////
 
94
// cdxCDynamicControlsManager::ControlData
 
95
/////////////////////////////////////////////////////////////////////////////
 
96
 
 
97
/////////////////////////////////////////////////////////////////////////////
 
98
// construction/destruction
 
99
/////////////////////////////////////////////////////////////////////////////
 
100
 
 
101
/*
 
102
 * constructor
 
103
 * copies all paramaters and gets the controls initial position using
 
104
 * GetWindowPos().
 
105
 *
 
106
 * NOTE that the constructor need ctrl.m_hWnd to exist (in contrast to
 
107
 * Add()
 
108
 */
 
109
 
 
110
cdxCDynamicControlsManager::ControlData::ControlData(cdxCDynamicControlsManager & rMaster, CWnd & ctrl, const PositionSetup & rPosSetup)
 
111
:       m_rMaster(rMaster), m_pCtrl(NULL),
 
112
        m_pNext(NULL), m_pPrev(NULL),
 
113
        m_posSetup(rPosSetup)
 
114
{
 
115
        ASSERT(::IsWindow(ctrl.m_hWnd));                // control must have already been created !
 
116
        ASSERT(rPosSetup.IsValid());
 
117
 
 
118
        //
 
119
        // get initial values
 
120
        //
 
121
 
 
122
        WINDOWPLACEMENT wpl;
 
123
        VERIFY( ctrl.GetWindowPlacement(&wpl) );
 
124
 
 
125
        m_rectOriginal  =       wpl.rcNormalPosition;
 
126
 
 
127
        //
 
128
        // remember control
 
129
        //
 
130
 
 
131
        new ControlEntry(ctrl,*this);
 
132
        ASSERT(m_pCtrl != NULL);
 
133
 
 
134
        //
 
135
        // link us to the cdxCDynamicControlsManager's list
 
136
        //
 
137
 
 
138
        if(m_pNext = m_rMaster.m_pFirst)
 
139
                m_pNext->m_pPrev        =       this;
 
140
        m_pPrev =       NULL;
 
141
        m_rMaster.m_pFirst      =       this;
 
142
}
 
143
 
 
144
/*
 
145
 * detach from list
 
146
 * The m_Ctrl deletes all children by itself
 
147
 */
 
148
 
 
149
cdxCDynamicControlsManager::ControlData::~ControlData()
 
150
{
 
151
        //
 
152
        // delete all control references
 
153
        //
 
154
 
 
155
        while(m_pCtrl)
 
156
                delete m_pCtrl;
 
157
 
 
158
        //
 
159
        // unlink from list
 
160
        //
 
161
 
 
162
        if(m_pPrev)
 
163
        {
 
164
                if(m_pPrev->m_pNext = m_pNext)
 
165
                        m_pNext->m_pPrev        =       m_pPrev;
 
166
        }
 
167
        else
 
168
        {
 
169
                ASSERT(m_rMaster.m_pFirst == this);
 
170
                if(m_rMaster.m_pFirst = m_pNext)
 
171
                        m_pNext->m_pPrev        =       NULL;
 
172
        }
 
173
}
 
174
 
 
175
/////////////////////////////////////////////////////////////////////////////
 
176
// cdxCDynamicControlsManager::ControlData virtuals
 
177
/////////////////////////////////////////////////////////////////////////////
 
178
 
 
179
/*
 
180
 * checks whether the CWnd is part of this control data
 
181
 */
 
182
 
 
183
bool cdxCDynamicControlsManager::ControlData::IsMember(CWnd & ctrl) const
 
184
{
 
185
        for(const ControlEntry *pEntry = m_pCtrl; pEntry; pEntry = pEntry->GetNext())
 
186
                if(*pEntry == ctrl)
 
187
                        return true;
 
188
 
 
189
        return false;
 
190
}
 
191
 
 
192
/*
 
193
 * removes a CWnd from this chain
 
194
 */
 
195
 
 
196
bool cdxCDynamicControlsManager::ControlData::Rem(CWnd & ctrl)
 
197
{
 
198
        for(ControlEntry *pEntry = m_pCtrl; pEntry; pEntry = pEntry->GetNext())
 
199
                if(*pEntry == ctrl)
 
200
                {
 
201
                        delete pEntry;
 
202
                        return true;
 
203
                }
 
204
 
 
205
        return false;
 
206
}
 
207
 
 
208
/*
 
209
 * Get current position
 
210
 */
 
211
 
 
212
CRect cdxCDynamicControlsManager::ControlData::GetCurrentPosition() const
 
213
{
 
214
        if(!IsUsed())
 
215
        {
 
216
                ASSERT(false);                  // all sub-controls have been deleted
 
217
                return CRect(0,0,0,0);
 
218
        }
 
219
 
 
220
        WINDOWPLACEMENT wpl;
 
221
        VERIFY( m_pCtrl->GetCWnd().GetWindowPlacement(&wpl) );
 
222
        return CRect(wpl.rcNormalPosition);
 
223
}
 
224
 
 
225
/*
 
226
 * modify initial setup
 
227
 * NOTE: this function does not move the controls.
 
228
 * You habe to call cdxCDynamicControlsManager::ReorganizeControls past
 
229
 * using this function
 
230
 */
 
231
 
 
232
bool cdxCDynamicControlsManager::ControlData::Modify(const CRect & rectOriginal, const PositionSetup & rSetup)
 
233
{
 
234
        if((rectOriginal.left > rectOriginal.right) ||
 
235
                (rectOriginal.top > rectOriginal.bottom) ||
 
236
                !rSetup.IsValid())
 
237
        {
 
238
                ASSERT(false);                  // bad function call
 
239
                return false;
 
240
        }
 
241
 
 
242
        m_rectOriginal  =       rectOriginal;
 
243
        m_posSetup              =       rSetup;
 
244
        return true;
 
245
}
 
246
 
 
247
/////////////////////////////////////////////////////////////////////////////
 
248
// cdxCDynamicControlsManager
 
249
/////////////////////////////////////////////////////////////////////////////
 
250
 
 
251
/////////////////////////////////////////////////////////////////////////////
 
252
// handling events from CWnd
 
253
/////////////////////////////////////////////////////////////////////////////
 
254
 
 
255
/*
 
256
 * this function initializes the following members:
 
257
 * m_pWnd                       -       the window handle
 
258
 * m_szCurrent          -       the current window's size
 
259
 * m_szMin                      -       the minimum window's size (taken from current size)
 
260
 * m_szMax                      -       the maximum window's size (set to (0,0) <=> don't change maximum)
 
261
 * m_wndSizeIcon        -       the icon (if wanted)
 
262
 *
 
263
 * parameters:
 
264
 * rWnd                         -       the window to supervise
 
265
 * fd                                   -       in which directions can we size the window (does only apply to user-sizing)
 
266
 * bSizeIcon            -       do you want a sizable icon ?
 
267
 * pBaseClientSize-     if non-zero, this defines the real (normal) size of the
 
268
 *                                                      window relative to all furher calculations will be made.
 
269
 *                                                      if zero, the current window's size will be taken.
 
270
 */
 
271
 
 
272
void cdxCDynamicControlsManager::DoInitWindow(CWnd & rWnd, Freedom fd, bool bSizeIcon, const CSize * pBaseClientSize)
 
273
{
 
274
        ASSERT(m_pWnd == NULL);                                 // you MUST NOT call this function twice !
 
275
        ASSERT(::IsWindow(rWnd.m_hWnd));                // rWnd MUST already exist !!
 
276
 
 
277
        m_pWnd          =       &rWnd;
 
278
        m_Freedom       =       fd;
 
279
 
 
280
        //
 
281
        // get current's window size
 
282
        //
 
283
 
 
284
        CRect                   rect;
 
285
        m_pWnd->GetWindowRect(&rect);
 
286
        CRect                   rectClient;
 
287
        m_pWnd->GetClientRect(&rectClient);
 
288
 
 
289
        if(!pBaseClientSize)
 
290
        {
 
291
                m_szClientRelative.cx   =       rectClient.Width();
 
292
                m_szClientRelative.cy   =       rectClient.Height();
 
293
 
 
294
                m_szMin.cx      =       rect.Width();
 
295
                m_szMin.cy      =       rect.Height();
 
296
        }
 
297
        else
 
298
        {
 
299
                ASSERT((pBaseClientSize->cx > 0) && (pBaseClientSize->cy > 0));
 
300
 
 
301
                m_szClientRelative      =       *pBaseClientSize;
 
302
                m_szMin.cx                              =       m_szClientRelative.cx + (rect.Width() - rectClient.Width());
 
303
                m_szMin.cy                              =       m_szClientRelative.cy + (rect.Height() - rectClient.Height());
 
304
        }
 
305
 
 
306
        m_szMax.cx      =       0;
 
307
        m_szMax.cy      =       0;
 
308
 
 
309
        //
 
310
        // set up icon if wanted
 
311
        //
 
312
 
 
313
        if(bSizeIcon)
 
314
        {
 
315
                VERIFY( m_pWndSizeIcon = new cdxCSizeIconCtrl );
 
316
                VERIFY( m_pWndSizeIcon->Create(m_pWnd,m_idSizeIcon) );  // creates my control; id is SIZE_CONTROL_ID
 
317
 
 
318
                AddSzControl(*m_pWndSizeIcon,mdRepos,mdRepos);
 
319
                m_pWndSizeIcon->ShowWindow(SW_SHOW);            // finally - show it
 
320
        }
 
321
}
 
322
 
 
323
/////////////////////////////////////////////////////////////////////////////
 
324
 
 
325
/*
 
326
 * fill in MINMAXINFO as requested
 
327
 * Call your CWnd's OnGetMinMaxInfo first !
 
328
 *
 
329
 * changed due to a but report by Michel Wassink <mww@mitutoyo.nl>
 
330
 */
 
331
 
 
332
void cdxCDynamicControlsManager::DoOnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
 
333
{
 
334
        if(IsReady() && !IsDisabled())
 
335
        {
 
336
                lpMMI->ptMinTrackSize.x =       m_szMin.cx;
 
337
                lpMMI->ptMinTrackSize.y =       m_szMin.cy;
 
338
 
 
339
                if(m_Freedom & fdHoriz)
 
340
                {
 
341
                        if(m_szMax.cx)
 
342
                                lpMMI->ptMaxTrackSize.x =       m_szMax.cx;
 
343
                }
 
344
                else
 
345
                        lpMMI->ptMaxTrackSize.x =       m_szMin.cx;
 
346
 
 
347
                if(m_Freedom & fdVert)
 
348
                {
 
349
                        if(m_szMax.cy)
 
350
                                lpMMI->ptMaxTrackSize.y =       m_szMax.cy;
 
351
                }
 
352
                else
 
353
                        lpMMI->ptMaxTrackSize.y =       m_szMin.cy;
 
354
        }
 
355
}
 
356
 
 
357
/*
 
358
 * handle OnSize - we can't rely on cx,cy being client dimensions
 
359
 * as stated in the documentation ...
 
360
 */
 
361
 
 
362
void cdxCDynamicControlsManager::DoOnSize(UINT nType, int cx, int cy)
 
363
{
 
364
        if(IsReady() && (nType != SIZE_MINIMIZED) && !IsDisabled())
 
365
                ReorganizeControls(true);
 
366
}
 
367
 
 
368
/*
 
369
 * free all memory
 
370
 * after having called this function, you can reuse the object
 
371
 * although I wouldn't recommend to do so :)
 
372
 */
 
373
 
 
374
void cdxCDynamicControlsManager::DoDestroyWindow()
 
375
{
 
376
        while(m_pFirst)
 
377
        {
 
378
                OnDeleteControlPosition(*m_pFirst);
 
379
                delete m_pFirst;
 
380
        }
 
381
 
 
382
        if(m_pWndSizeIcon)
 
383
        {
 
384
                if(::IsWindow(m_pWndSizeIcon->m_hWnd))
 
385
                        m_pWndSizeIcon->DestroyWindow();
 
386
                delete m_pWndSizeIcon;
 
387
                m_pWndSizeIcon  =       NULL;
 
388
        }
 
389
 
 
390
        m_pWnd = NULL;
 
391
}
 
392
 
 
393
/////////////////////////////////////////////////////////////////////////////
 
394
// control positioning
 
395
/////////////////////////////////////////////////////////////////////////////
 
396
 
 
397
/*
 
398
 * Reposition (without current rectangle size)
 
399
 *
 
400
 * rectWin              -       window rectangle (including border)
 
401
 * rectClient   -       window rectangle (client area)
 
402
 *                Note that since release 6, rectClient.left and .top might be > zero
 
403
 *                                         (for scrolling)
 
404
 * bRedraw              -       invalidate & update window
 
405
 */
 
406
 
 
407
void cdxCDynamicControlsManager::ReorganizeControlsAdvanced(const CRect & rectWin, CRect rectClient, bool bRedraw)
 
408
{
 
409
        ASSERT(IsReady());
 
410
 
 
411
        if(!GetTotalChildCnt())
 
412
                return;
 
413
 
 
414
        //
 
415
        // we won't go smaller with the whole window than
 
416
        // m_szMin
 
417
        //
 
418
 
 
419
        if(rectWin.Width() < m_szMin.cx)
 
420
                rectClient.right        +=      (m_szMin.cx - rectWin.Width());
 
421
        if(rectWin.Height() < m_szMin.cy)
 
422
                rectClient.bottom       +=      (m_szMin.cy - rectWin.Height());
 
423
 
 
424
        //
 
425
        // we new replace all controls
 
426
        //
 
427
 
 
428
        CSize   szDelta;
 
429
        szDelta.cx      =       rectClient.Width() - m_szClientRelative.cx;
 
430
        szDelta.cy      =       rectClient.Height() - m_szClientRelative.cy;
 
431
 
 
432
        CPoint  pntOffset       =       rectClient.TopLeft();
 
433
 
 
434
        // newly added code by Rodger Bernstein
 
435
 
 
436
        AFX_SIZEPARENTPARAMS layout;
 
437
        ControlData                             *sz;
 
438
        bool                                            bManual =       true;
 
439
 
 
440
        if(!( layout.hDWP = ::BeginDeferWindowPos(GetTotalChildCnt()) ))
 
441
        {
 
442
                TRACE(_T("*** ERROR[cdxCDynamicControlsManager::ReorganizeControlsAdvanced()]: BeginDeferWindowPos() failed.\n"));
 
443
        }
 
444
        else
 
445
        {
 
446
                for(sz = m_pFirst; sz; sz = sz->GetNext())
 
447
                        sz->OnSize(szDelta, &layout, &pntOffset);
 
448
 
 
449
                if(!::EndDeferWindowPos(layout.hDWP))
 
450
                {
 
451
                        TRACE(_T("*** ERROR[cdxCDynamicControlsManager::ReorganizeControlsAdvanced()]: EndDeferWindowPos() failed.\n"));
 
452
                }
 
453
                else
 
454
                        bManual =       false;
 
455
        }
 
456
 
 
457
        if(bManual)
 
458
                for(sz = m_pFirst; sz; sz = sz->GetNext())
 
459
                        sz->OnSize(szDelta, NULL);
 
460
 
 
461
        if(bRedraw && m_pWnd->IsWindowVisible())
 
462
        {
 
463
                m_pWnd->RedrawWindow(NULL, NULL, RDW_UPDATENOW | RDW_NOERASE);
 
464
        }
 
465
}
 
466
 
 
467
/////////////////////////////////////////////////////////////////////////////
 
468
// misc
 
469
/////////////////////////////////////////////////////////////////////////////
 
470
 
 
471
/*
 
472
 * change minimum and maximum height of window.
 
473
 *
 
474
 * szMin                                                -       new minimum size (use GetMinSize() to leave it as being before)
 
475
 * szMax                                                -       new maximum size ( "  GetMaxSize() ")
 
476
 *                                                                      Set to CSize(0,0) if you don't want a maximum size.
 
477
 * bResizeIfNecessary   -       call FixWindowSize() past calculating new sizes.
 
478
 *
 
479
 * returns false if szMin and szMax are illegal (e.g. szMin > szMax)
 
480
 */
 
481
 
 
482
bool cdxCDynamicControlsManager::SetMinMaxSize(const CSize & szMin, const CSize & szMax, bool bResizeIfNecessary)
 
483
{
 
484
        ASSERT(IsReady());                      // DoInitWindow() not called ?
 
485
 
 
486
        if((szMax.cx && (szMin.cx > szMax.cx)) ||
 
487
                (szMax.cy && (szMin.cy > szMax.cy)))
 
488
        {
 
489
                return false;
 
490
        }
 
491
 
 
492
        m_szMin =       szMin;
 
493
        m_szMax =       szMax;
 
494
 
 
495
        if(bResizeIfNecessary)
 
496
                FixWindowSize();
 
497
 
 
498
        return true;
 
499
}
 
500
 
 
501
/*
 
502
 * this function ensure that the window's size is between m_szMin and m_szMax.
 
503
 * returns true if window size has been changed
 
504
 */
 
505
 
 
506
bool cdxCDynamicControlsManager::FixWindowSize()
 
507
{
 
508
        ASSERT(IsReady());                      // use DoInitWindow() first !
 
509
 
 
510
        CSize   szCurrent       =       GetWindowSize(*m_pWnd),
 
511
                        szDelta;
 
512
 
 
513
        if(m_szMax.cx && (szCurrent.cx > m_szMax.cx))
 
514
                szDelta.cx              =       m_szMax.cx - szCurrent.cx;              // is negative
 
515
        else
 
516
                if(szCurrent.cx < m_szMin.cx)
 
517
                        szDelta.cx      =       m_szMin.cx - szCurrent.cx;              // is positive
 
518
                else
 
519
                        szDelta.cx      =       0;
 
520
 
 
521
        if(m_szMax.cy && (szCurrent.cy > m_szMax.cy))
 
522
                szDelta.cy              =       m_szMax.cy - szCurrent.cy;              // is negative
 
523
        else
 
524
                if(szCurrent.cy < m_szMin.cy)
 
525
                        szDelta.cy      =       m_szMin.cy - szCurrent.cy;              // is positive
 
526
                else
 
527
                        szDelta.cy      =       0;
 
528
 
 
529
        if(!szDelta.cx && !szDelta.cy)
 
530
                return false;                   // nothing to do
 
531
 
 
532
        StretchWindow(*m_pWnd,szDelta);
 
533
        return true;
 
534
}
 
535
 
 
536
/////////////////////////////////////////////////////////////////////////////
 
537
 
 
538
/*
 
539
 * hide and show icon
 
540
 */
 
541
 
 
542
void cdxCDynamicControlsManager::HideSizeIcon()
 
543
{
 
544
        if(m_pWndSizeIcon && ::IsWindow(m_pWndSizeIcon->m_hWnd))
 
545
                m_pWndSizeIcon->ShowWindow(SW_HIDE);
 
546
}
 
547
 
 
548
void cdxCDynamicControlsManager::ShowSizeIcon()
 
549
{
 
550
        if(m_pWndSizeIcon && ::IsWindow(m_pWndSizeIcon->m_hWnd))
 
551
                m_pWndSizeIcon->ShowWindow(SW_SHOW);
 
552
}
 
553
 
 
554
/////////////////////////////////////////////////////////////////////////////
 
555
// static functions: window sizing
 
556
/////////////////////////////////////////////////////////////////////////////
 
557
 
 
558
/*
 
559
 * stretches the window by szDelta (i.e. if szDelta is 100, the window is enlarged by 100 pixels)
 
560
 * stretching means that the center point of the window remains
 
561
 *
 
562
 * returns false if the window would be smaller than (1,1)
 
563
 *
 
564
 * NOTE: this function does NOT care of the min/max dimensions of a window
 
565
 *                      Use MoveWindow() if you need to take care of it.
 
566
 *
 
567
 * STATIC
 
568
 */
 
569
 
 
570
bool cdxCDynamicControlsManager::StretchWindow(CWnd & rWnd, const CSize & szDelta)
 
571
{
 
572
        ASSERT(::IsWindow(rWnd.m_hWnd));
 
573
 
 
574
        WINDOWPLACEMENT wpl;
 
575
        rWnd.GetWindowPlacement(&wpl);
 
576
 
 
577
        wpl.rcNormalPosition.left               -=      szDelta.cx / 2;
 
578
        wpl.rcNormalPosition.right              +=      (szDelta.cx + 1) / 2;
 
579
        wpl.rcNormalPosition.top                -=      szDelta.cy / 2;
 
580
        wpl.rcNormalPosition.bottom     +=      (szDelta.cy + 1) / 2;
 
581
//      wpl.flags       =       SW_SHOWNA|SW_SHOWNOACTIVATE;
 
582
 
 
583
        if((wpl.rcNormalPosition.left >= wpl.rcNormalPosition.right) ||
 
584
                (wpl.rcNormalPosition.top >= wpl.rcNormalPosition.bottom))
 
585
                return false;
 
586
 
 
587
        VERIFY( rWnd.SetWindowPos(      NULL,
 
588
                                                                                wpl.rcNormalPosition.left,
 
589
                                                                                wpl.rcNormalPosition.top,
 
590
                                                                                wpl.rcNormalPosition.right - wpl.rcNormalPosition.left,
 
591
                                                                                wpl.rcNormalPosition.bottom - wpl.rcNormalPosition.top,
 
592
                                                                                SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOZORDER) );
 
593
 
 
594
        return true;
 
595
}
 
596
 
 
597
/*
 
598
 * stretch window by a percent value
 
599
 * the algorithm calculates the new size for both dimensions by:
 
600
 *
 
601
 *  newWid = oldWid + (oldWid * iAddPcnt) / 100
 
602
 *
 
603
 * NOTE: iAddPcnt may even be nagtive, but it MUST be greater than -100.
 
604
 * NOTE: this function does NOT care of the min/max dimensions of a window
 
605
 *
 
606
 * The function will return false if the new size would be empty.
 
607
 *
 
608
 * STATIC
 
609
 */
 
610
 
 
611
bool cdxCDynamicControlsManager::StretchWindow(CWnd & rWnd, int iAddPcnt)
 
612
{
 
613
        ASSERT(::IsWindow(rWnd.m_hWnd));
 
614
 
 
615
        CSize   szDelta =       GetWindowSize(rWnd);
 
616
 
 
617
        szDelta.cx      =       (szDelta.cx * iAddPcnt) / 100;
 
618
        szDelta.cy      =       (szDelta.cy * iAddPcnt) / 100;
 
619
 
 
620
        return StretchWindow(rWnd,szDelta);
 
621
}
 
622
 
 
623
/*
 
624
 * get current window's size
 
625
 *
 
626
 * STATIC
 
627
 */
 
628
 
 
629
CSize cdxCDynamicControlsManager::GetWindowSize(CWnd & rWnd)
 
630
{
 
631
        ASSERT(::IsWindow(rWnd.m_hWnd));
 
632
 
 
633
        CRect   rect;
 
634
        rWnd.GetWindowRect(&rect);
 
635
        return CSize(rect.Width(),rect.Height());
 
636
}
 
637
 
 
638
/////////////////////////////////////////////////////////////////////////////
 
639
// static functions: window & registry
 
640
/////////////////////////////////////////////////////////////////////////////
 
641
 
 
642
/*
 
643
 * stores a window's position and visiblity to the registry.
 
644
 *
 
645
 *      return false if any error occured
 
646
 *
 
647
 * STATIC
 
648
 */
 
649
 
 
650
bool cdxCDynamicControlsManager::StoreWindowPosition(CWnd & rWnd, LPCTSTR lpszProfile)
 
651
{
 
652
        ASSERT(::IsWindow(rWnd.m_hWnd) && lpszProfile && *lpszProfile);
 
653
        // can't use an empty profile section string; see CWinApp::GetProfileInt() for further information
 
654
 
 
655
        WINDOWPLACEMENT wpl;
 
656
        VERIFY( rWnd.GetWindowPlacement(&wpl) );
 
657
        BOOL    bVisible        =       rWnd.IsWindowVisible();
 
658
        int     iState  =       REGVAL_NOSTATE;
 
659
 
 
660
        if(rWnd.IsIconic())
 
661
                iState  =       REGVAL_ICONIC;
 
662
        else
 
663
                if(rWnd.IsZoomed())
 
664
                        iState  =       REGVAL_MAXIMIZED;
 
665
 
 
666
        return  AfxGetApp()->WriteProfileInt(lpszProfile,       lpszRegVal_Valid,       REGVAL_INVALID) &&      // invalidate first
 
667
                                AfxGetApp()->WriteProfileInt(lpszProfile,       lpszRegVal_Left,                wpl.rcNormalPosition.left) &&
 
668
                                AfxGetApp()->WriteProfileInt(lpszProfile,       lpszRegVal_Right,               wpl.rcNormalPosition.right) &&
 
669
                                AfxGetApp()->WriteProfileInt(lpszProfile,       lpszRegVal_Top,         wpl.rcNormalPosition.top) &&
 
670
                                AfxGetApp()->WriteProfileInt(lpszProfile,       lpszRegVal_Bottom,      wpl.rcNormalPosition.bottom) &&
 
671
                                AfxGetApp()->WriteProfileInt(lpszProfile,       lpszRegVal_Visible,     bVisible ? REGVAL_VISIBLE : REGVAL_HIDDEN) &&
 
672
                                AfxGetApp()->WriteProfileInt(lpszProfile,       lpszRegVal_State,               iState) &&
 
673
                                AfxGetApp()->WriteProfileInt(lpszProfile,       lpszRegVal_Valid,       REGVAL_VALID);          // validate position
 
674
}
 
675
 
 
676
/*
 
677
 * load the registry data stored by StoreWindowPosition()
 
678
 * returns true if data have been found in the registry
 
679
 *
 
680
 * STATIC
 
681
 */
 
682
 
 
683
bool cdxCDynamicControlsManager::RestoreWindowPosition(CWnd & rWnd, LPCTSTR lpszProfile, UINT restoreFlags)
 
684
{
 
685
        ASSERT(::IsWindow(rWnd.m_hWnd) && lpszProfile && *lpszProfile);
 
686
        // can't use an empty profile section string; see CWinApp::GetProfileInt() for further information
 
687
 
 
688
        //
 
689
        // first, we check whether the position had been saved successful any time before
 
690
        //
 
691
 
 
692
        if( AfxGetApp()->GetProfileInt(lpszProfile,lpszRegVal_Valid,REGVAL_INVALID) != REGVAL_VALID )
 
693
                return false;
 
694
 
 
695
        //
 
696
        // get old position
 
697
        //
 
698
 
 
699
        WINDOWPLACEMENT wpl;
 
700
        VERIFY( rWnd.GetWindowPlacement(&wpl) );
 
701
 
 
702
        //
 
703
        // read registry
 
704
        //
 
705
 
 
706
        int     iState  =       AfxGetApp()->GetProfileInt(lpszProfile, lpszRegVal_State, REGVAL_NOSTATE);
 
707
 
 
708
        //
 
709
        // get window's previous normal position
 
710
        //
 
711
 
 
712
        wpl.rcNormalPosition.left               =       AfxGetApp()->GetProfileInt(lpszProfile, lpszRegVal_Left,                wpl.rcNormalPosition.left);
 
713
        wpl.rcNormalPosition.right              =       AfxGetApp()->GetProfileInt(lpszProfile, lpszRegVal_Right,               wpl.rcNormalPosition.right);
 
714
        wpl.rcNormalPosition.top                =       AfxGetApp()->GetProfileInt(lpszProfile, lpszRegVal_Top,         wpl.rcNormalPosition.top);
 
715
        wpl.rcNormalPosition.bottom     =       AfxGetApp()->GetProfileInt(lpszProfile, lpszRegVal_Bottom,      wpl.rcNormalPosition.bottom);
 
716
 
 
717
        if(wpl.rcNormalPosition.left > wpl.rcNormalPosition.right)
 
718
        {
 
719
                long    l       =       wpl.rcNormalPosition.right;
 
720
                wpl.rcNormalPosition.right      =       wpl.rcNormalPosition.left;
 
721
                wpl.rcNormalPosition.left       =       l;
 
722
        }
 
723
        if(wpl.rcNormalPosition.top > wpl.rcNormalPosition.bottom)
 
724
        {
 
725
                long    l       =       wpl.rcNormalPosition.bottom;
 
726
                wpl.rcNormalPosition.bottom     =       wpl.rcNormalPosition.top;
 
727
                wpl.rcNormalPosition.top        =       l;
 
728
        }
 
729
 
 
730
        //
 
731
        // get restore stuff
 
732
        //
 
733
 
 
734
        UINT    showCmd =       SW_SHOWNA;
 
735
        
 
736
        if(restoreFlags & rflg_state)
 
737
        {
 
738
                if(iState == REGVAL_MAXIMIZED)
 
739
                        showCmd =       SW_MAXIMIZE;
 
740
                else
 
741
                        if(iState == REGVAL_ICONIC)
 
742
                                showCmd =       SW_MINIMIZE;
 
743
        }
 
744
 
 
745
        //
 
746
        // use MoveWindow() which takes care of WM_GETMINMAXINFO
 
747
        //
 
748
 
 
749
        rWnd.MoveWindow(        wpl.rcNormalPosition.left,wpl.rcNormalPosition.top,
 
750
                                                        wpl.rcNormalPosition.right - wpl.rcNormalPosition.left,
 
751
                                                        wpl.rcNormalPosition.bottom - wpl.rcNormalPosition.top,
 
752
                                                        showCmd == SW_SHOWNA);
 
753
 
 
754
        if(showCmd != SW_SHOWNA)
 
755
        {
 
756
                // read updated position
 
757
 
 
758
                VERIFY( rWnd.GetWindowPlacement(&wpl) );
 
759
                wpl.showCmd     =       showCmd;
 
760
                rWnd.SetWindowPlacement(&wpl);
 
761
        }
 
762
        
 
763
        //
 
764
        // get visiblity
 
765
        //
 
766
 
 
767
        if(restoreFlags & rflg_visibility)
 
768
        {
 
769
                int     i       =       AfxGetApp()->GetProfileInt(lpszProfile, lpszRegVal_Visible, REGVAL_NOSTATE);
 
770
                if(i == REGVAL_VISIBLE)
 
771
                        rWnd.ShowWindow(SW_SHOW);
 
772
                else
 
773
                        if(i == REGVAL_HIDDEN)
 
774
                                rWnd.ShowWindow(SW_HIDE);
 
775
        }
 
776
 
 
777
        return true;
 
778
}
 
779