test: persctl.cpp Source File

Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

# persctl.cpp

Go to the documentation of this file.

    00001 //
    00002 // CResizeControl
    00003 //
    00004 // FelixA
    00005 //
    00006 // Resize controls
    00007
    00008 #include "pch.h"
    00009
    00010 #include "persctl.h"
    00011 #include "debug.h"
    00012 #define ABS(x) (x<0?-x:x)
    00013
    00015 //
    00016 //  Chesshire cat the controls.
    00017 //
    00018 //
    00019 // Need to catagorize controls - re-sizing and non-resizing controls
    00020 // use a registry based mapping from classname to object.
    00021 //
    00022 CResizeControl::CResizeControl(HWND hC,CParentInfo & pi)
    00023 {
    00024         // Get the classname for the control.
    00025         TCHAR szClassName[64];
    00026         m_pC=NULL;
    00027         ::GetClassName(hC,szClassName,sizeof(szClassName));
    00028
    00029         /*
    00030         // See what class can persist this type of control.
    00031         // can use lookup in the registry to determin.
    00032         if(lstrcmpi(szClassName,"Edit")==0)
    00033                 m_pC= new CResizeEditControl(hC, pi);
    00034         if(lstrcmpi(szClassName,"Button")==0)
    00035                 m_pC= new CResizeButtonControl(hC, pi);
    00036         // if(lstrcmpi(szClassName,"ComboBox")==0)
    00037         //      m_pC= new CResizeComboControl(hC, pi);
    00038         */
    00039
    00040         // There is no Resize form of this control.
    00041         if(!m_pC)
    00042         {
    00043                 // OutputDebugString("Cannot persist:");
    00044                 // OutputDebugString(szClassName);
    00045                 // OutputDebugString("\n");
    00046                 //
    00047                 // We need to map it though.
    00048                 //
    00049                 m_pC=new CResizeControlGeneric( hC, pi, this );
    00050         }
    00051 }
    00052
    00053
    00054 //
    00055 // Work out where we are on the dialog.
    00056 //
    00057 BOOL CResizeControlGeneric::DeterminLeftAttatchments()
    00058 {
    00059         m_pLeftEdge             = m_Parent.AddEdge( GetLeftGap(), LEFT_AT, IsGrowsWide() );
    00060         return FALSE;
    00061 }
    00062
    00063
    00064 //
    00065 // We determin the attachements differently for each edge - not sure if this is
    00066 // correct, or even good.
    00067 //
    00068 BOOL CResizeControlGeneric::DeterminRightAttatchments()
    00069 {
    00070         m_pRightEdge=NULL;
    00071         /*
    00072         TRACE(L"Control %08d %s - Determin Location \n", GetDlgCtrlID( GetControl() ), GetClassName() );
    00073         TRACE(L"Right Size is %03d\n", GetLeftGap() + GetWidth() ,m_RightSlop);
    00074         */
    00075
    00076         m_pRightEdge    = m_Parent.AddEdge( GetLeftGap() + GetWidth(), RIGHT_AT, IsGrowsWide(), m_RightSlop );
    00077
    00078 #ifdef _DEBUG
    00079         if( m_pRightEdge->GetPosition() != GetLeftGap() + GetWidth() )
    00080                 TRACE(L"RIGHT EDGE WRONG - In actuality %03d should be %03d\n", m_pRightEdge->GetPosition() , GetLeftGap() + GetWidth());
    00081 #endif
    00082
    00083         return FALSE;
    00084 }
    00085
    00086 BOOL CResizeControlGeneric::DeterminTopAttatchments()
    00087 {
    00088         m_pTopEdge              = m_Parent.AddEdge( GetTopGap(), TOP_AT, IsGrowsHigh(), 0 );
    00089         return FALSE;
    00090 }
    00091
    00092 BOOL CResizeControlGeneric::DeterminBottomAttatchments()
    00093 {
    00094         m_pBottomEdge   = m_Parent.AddEdge( GetTopGap()+GetHeight(), BOTTOM_AT, IsGrowsHigh(), 0 );
    00095         return FALSE;
    00096 }
    00097
    00098 //
    00099 // We resize the control, related to the width and height provided.
    00100 // The width and height come from the parent (for now).
    00101 //
    00102 BOOL CResizeControlGeneric::Resize(WORD width, WORD height)
    00103 {
    00104         //
    00105         // A control is deliniated by its guides
    00106         //
    00107         if(true)
    00108         {
    00109                 int x,y,w,h;
    00110                 x=m_pLeftEdge->GetPosition();
    00111                 w=m_pRightEdge->GetPosition() - x;
    00112                 y=m_pTopEdge->GetPosition();
    00113                 h=m_pBottomEdge->GetPosition() - y;
    00114
    00115                 BOOL bMove=true;
    00116                 BOOL bSize=true;
    00117                 SetWindowPos( GetControl(), NULL,
    00118                 x, y, w, h,
    00119                 (bMove ? 0: SWP_NOMOVE) |       (bSize ? 0: SWP_NOSIZE) | SWP_NOZORDER );
    00120
    00121                 return true;
    00122         }
    00123
    00124 //
    00125 // N O T   U S E D
    00126 //
    00127         //
    00128         // Hmm, interesting, a button bound on the bottom to a movable thing,
    00129         // but its top is not bound.
    00130         //
    00131         BOOL bMove=FALSE;
    00132         int     x,y,w,h;
    00133
    00134         x=m_pLeftEdge->GetPosition();
    00135
    00136         if( IsGrowsWide() == FALSE )
    00137         {
    00138                 if( m_pLeftEdge->GetFlexible() == TRUE )
    00139                 {
    00140                         bMove|=TRUE;
    00141                 }
    00142                 else
    00143                 {
    00144                         //
    00145                         // The left guide isn't movable.
    00146                         //
    00147                         bMove|=m_pBottomEdge->GetFlexible();
    00148                         if( m_pRightEdge->GetGuide() != m_pLeftEdge->GetGuide() )
    00149                                 x=m_pRightEdge->GetPosition() - GetWidth();
    00150                 }
    00151         }
    00152
    00153         y=m_pTopEdge->GetPosition();
    00154         if( m_pTopEdge->GetFlexible() == TRUE )
    00155         {
    00156                 bMove|=TRUE;
    00157         }
    00158         else
    00159         {
    00160                 bMove|=m_pBottomEdge->GetFlexible();
    00161                 y=m_pBottomEdge->GetPosition() - GetHeight();
    00162         }
    00163
    00164         //
    00165         // We've done some calculation to work out new edges ... verify this.
    00166         //
    00167         BOOL bSize=FALSE;
    00168         w = m_pRightEdge->GetPosition() -x ;
    00169         h = m_pBottomEdge->GetPosition() - y;
    00170         if((w != GetWidth()) || ( h != GetHeight() ))
    00171                 bSize=TRUE;
    00172
    00173
    00174         //
    00175         //
    00176         //
    00177         x=m_pLeftEdge->GetPosition();
    00178         w=m_pRightEdge->GetPosition() - x;
    00179         y=m_pTopEdge->GetPosition();
    00180         h=m_pBottomEdge->GetPosition() - y;
    00181
    00182         if( !IsGrowsWide() && ( w != GetWidth() ) )
    00183         {
    00184                 //
    00185                 // We're trying to widen this control,
    00186                 //
    00187                 //
    00188                 // Could be because the right edge has moved.
    00189                 //
    00190                 TRACE(L"Left edge off by %03d\n", w-GetWidth() );
    00191                 CGuide * pGuide=m_pLeftEdge->GetGuide();
    00192                 // BB is equal
    00193                 if( pGuide == m_Parent.GetLeftEdge()->GetGuide() )
    00194                 {
    00195                         //
    00196                         // Left edge is fixed to border, leave it.
    00197                         //
    00198                         int i=5;
    00199                 }
    00200                 else
    00201                 {
    00202                         // BB move method
    00203                         pGuide->Adjust( w-GetWidth() );
    00204                         bSize=FALSE;
    00205                 }
    00206         }
    00207
    00208         if( !IsGrowsHigh() && ( h!=GetHeight() ) )
    00209         {
    00210                 TRACE(L"Top edge off by %03d\n", h-GetHeight() );
    00211                 CGuide * pGuide=m_pTopEdge->GetGuide();
    00212                 pGuide->Adjust( h-GetHeight() );
    00213                 bSize=FALSE;
    00214         }
    00215
    00216         if( (GetLeftGap() == x) && (GetTopGap()==y ))
    00217                 bMove=FALSE;
    00218         else
    00219                 bMove=TRUE;
    00220
    00221         //
    00222         // We now have the resize calculated.
    00223         //
    00224         if( bMove || bSize )
    00225         {
    00226                 SetWindowPos( GetControl(), NULL,
    00227                 x, y, w, h,
    00228                 (bMove ? 0: SWP_NOMOVE) |       (bSize ? 0: SWP_NOSIZE) | SWP_NOZORDER );
    00229
    00230                 SetX( x );
    00231                 SetY( y );
    00232                 SetTempWidth( w );
    00233                 SetTempHeight( h );
    00234                 return TRUE;            // yes we-resized.
    00235         }
    00236
    00237         return FALSE;
    00238 }
    00239
    00240 //
    00241 // GetOur position on the screen.
    00242 //
    00243 void CResizeControlGeneric::DeterminLocation()
    00244 {
    00245         /*
    00246         TRACE(L"Control %08d %s - Determin Location \n", GetDlgCtrlID( GetControl() ), GetClassName() );
    00247         */
    00248         GetWindowRect( GetControl(), &m_Location);
    00249
    00250         //
    00251         // Our location relative to our parents. ???
    00252         //
    00253         m_Location.left -= m_Parent.GetLeft();
    00254         m_Location.right -= m_Parent.GetLeft();
    00255         m_Location.top -= m_Parent.GetTop();
    00256         m_Location.bottom -= m_Parent.GetTop();
    00257
    00258         MapWindowPoints( NULL, m_Parent.GetWindow(), (LPPOINT)&m_Location, 2);
    00259
    00260         TRACE(L"L:%03d R:%03d T:%03d B:%03d\n", m_Location.left, m_Location.right, m_Location.top, m_Location.bottom );
    00261         m_PreferredSize.Width=m_Location.right - m_Location.left;
    00262         m_PreferredSize.Height=m_Location.bottom - m_Location.top;
    00263
    00264         // REVIEW - slop is a %age of width
    00265         // right slop is 3% of my width.
    00266         // m_RightSlop = GetWidth() * 3 / 100;
    00267         m_RightSlop=3;
    00268
    00269         // REVIEW - if wide, make resizable IanEl
    00270         // things get wider if they are 66% the width of the screen.
    00271
    00272         if(false)
    00273         {
    00274                 m_GrowsWide = ((GetWidth() * 100 / m_Parent.GetWidth() ) > 66);
    00275                 m_GrowsHigh = ((GetHeight() * 100 / m_Parent.GetHeight() ) > 66);
    00276         }
    00277         else
    00278         {
    00279                 m_GrowsWide=TRUE;
    00280                 m_GrowsHigh=TRUE;
    00281                 TRACE(L"Class %s",GetClassName());
    00282                 if( lstrcmp( GetClassName(), L"Button") ==0)
    00283                 {
    00284                         //
    00285                         // Check box button is OK though.
    00286                         //
    00287                         int ibs=GetWindowStyle( GetControl() );
    00288                         switch( ibs & 0xf)
    00289                         {
    00290                         case BS_CHECKBOX:
    00291                         case BS_AUTOCHECKBOX:
    00292                                 m_GrowsWide=FALSE;              // TRUE; what dialog things checks get wider
    00293                                 m_GrowsHigh=FALSE;
    00294                                 break;
    00295
    00296                         case BS_GROUPBOX:
    00297                         default:
    00298                                 m_GrowsHigh=FALSE;
    00299                                 m_GrowsWide=FALSE;
    00300                         }
    00301                         TRACE(L"Button style 0x%08x\n", ibs );
    00302                 }
    00303                 else
    00304                 if(lstrcmp( GetClassName(), L"Static")==0 )
    00305                 {
    00306                         int iss=GetWindowStyle( GetControl() ); // SS_
    00307
    00308                         //
    00309                         // Wrong check to see if it's multi line. All statics are multiline
    00310                         //
    00311                         /*
    00312                         if(iss & ES_MULTILINE ) // ???
    00313                         {
    00314                                 m_GrowsHigh=TRUE;
    00315                                 m_GrowsWide=TRUE;
    00316                         }
    00317                         else
    00318                         */
    00319                         {
    00320                                 m_GrowsHigh=FALSE;
    00321                                 m_GrowsWide=TRUE;               // statics can always get wider.
    00322                                 m_GrowsWide=FALSE;              // statics can always get wider.
    00323                         }
    00324                 }
    00325                 else
    00326                 if( lstrcmp( GetClassName(), L"ComboBox")==0)
    00327                 {
    00328                         m_GrowsHigh=FALSE;
    00329                 }
    00330                 else
    00331                 if( lstrcmp( GetClassName(), L"SysTabControl32") == 0 )
    00332                 {
    00333                         m_GrowsHigh=FALSE;      // alas we can't size the inside of these
    00334                         m_GrowsWide=FALSE;
    00335                 }
    00336                 else
    00337                 if( lstrcmp( GetClassName(), L"Edit")==0)
    00338                 {
    00339                         int ies=GetWindowStyle( GetControl() );
    00340                         if(!(ies & ES_MULTILINE ))
    00341                                 m_GrowsHigh=FALSE;
    00342                 }
    00343                 else
    00344                 {
    00345                         if( *GetClassName() == '#' )
    00346                         {
    00347                                 TRACE(L"Punting unknown class %s\n", GetClassName() );
    00348                                 m_GrowsHigh=FALSE;      // alas we can't size the inside of these
    00349                                 m_GrowsWide=FALSE;
    00350                         }
    00351                 }
    00352         }
    00353 }
    00354
    00355
    00356 //
    00357 // We attatch this control to its guides.
    00358 //
    00359 BOOL CResizeControlGeneric::SetControlAssociations()
    00360 {
    00361         m_pRightEdge->Attatch(m_pUs);
    00362         m_pLeftEdge->Attatch(m_pUs);
    00363         m_pTopEdge->Attatch(m_pUs);
    00364         m_pBottomEdge->Attatch(m_pUs);
    00365
    00366         /*
    00367         TRACE(L"Control %08d %s - EdgePos, Guides, GuidePos\n", GetDlgCtrlID( GetControl() ), GetClassName() );
    00368         TRACE( "[%08d %08d %08d %08d] {0x%08lx 0x%08lx 0x%08lx 0x%08lx}\n(%08d %08d %08d %08d)\n",
    00369                 m_pLeftEdge->GetPosition(),
    00370                 m_pRightEdge->GetPosition(),
    00371                 m_pTopEdge->GetPosition(),
    00372                 m_pBottomEdge->GetPosition(),
    00373
    00374                 m_pLeftEdge->GetGuide(),
    00375                 m_pRightEdge->GetGuide(),
    00376                 m_pTopEdge->GetGuide(),
    00377                 m_pBottomEdge->GetGuide(),
    00378
    00379                 m_pLeftEdge->GetGuide()->GetPosition(),
    00380                 m_pRightEdge->GetGuide()->GetPosition(),
    00381                 m_pTopEdge->GetGuide()->GetPosition(),
    00382                 m_pBottomEdge->GetGuide()->GetPosition()
    00383                 );
    00384         */
    00385         return TRUE;
    00386 }
    00387
    00388 //
    00389 // Constructor for a generic control.
    00390 //
    00391 CResizeControlGeneric::CResizeControlGeneric(HWND hC, CParentInfo & pi, CResizeControl * pUs)
    00392         : m_hC(hC), m_Parent(pi), m_pLeftEdge(NULL), m_pRightEdge(NULL), m_pTopEdge(NULL),
    00393         m_pBottomEdge(NULL), m_GrowsWide(FALSE), m_GrowsHigh(FALSE),
    00394         m_RightSlop(0), m_pUs(pUs)
    00395 {
    00396         TCHAR szClassName[256];
    00397         int iSize=::GetClassName(hC,szClassName,sizeof(szClassName));
    00398         m_ClassName=new TCHAR[iSize+1];
    00399         lstrcpy( m_ClassName, szClassName);
    00400         //
    00401         // Remember the initial size, this is its preferred size.
    00402         //
    00403         DeterminLocation();
    00404
    00405 }
    00406
    00407 CResizeControlGeneric::~CResizeControlGeneric()
    00408 {
    00409         delete m_ClassName;
    00410 }
    00411
    00412
    00413 //
    00414 // Returns a bitfield where the guide is attatched.
    00415 //
    00416 int CResizeControlGeneric::Attatchment(CGuide * pGuide)
    00417 {
    00418         int iRet=0;
    00419         if( pGuide->IsEqual( m_pLeftEdge->GetGuide() ) )
    00420                 iRet |= LEFT_AT;
    00421         if( pGuide->IsEqual( m_pRightEdge->GetGuide() ) )
    00422                 iRet |= RIGHT_AT;
    00423         if( pGuide->IsEqual( m_pTopEdge->GetGuide() ) )
    00424                 iRet |= TOP_AT;
    00425         if( pGuide->IsEqual( m_pBottomEdge->GetGuide() ) )
    00426                 iRet |= BOTTOM_AT;
    00427         return iRet;
    00428 }