summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcommon/array.cpp143
-rwxr-xr-xcommon/array.h40
-rwxr-xr-xcommon/library.cpp136
-rwxr-xr-xcommon/library.h35
-rwxr-xr-xcommon/system.h1
-rw-r--r--win/LeoCAD.dsp8
-rw-r--r--win/LeoCAD.rc31
-rw-r--r--win/Piecebar.cpp726
-rw-r--r--win/Piecebar.h89
-rw-r--r--win/Piececmb.cpp19
-rw-r--r--win/Piecelst.cpp252
-rw-r--r--win/Piecelst.h25
-rw-r--r--win/System.cpp7
-rw-r--r--win/res/particon.bmpbin502 -> 630 bytes
-rw-r--r--win/resource.h12
-rw-r--r--win/transdlg.cpp53
-rw-r--r--win/transdlg.h51
17 files changed, 1188 insertions, 440 deletions
diff --git a/common/array.cpp b/common/array.cpp
index 3d58c55..76c9a30 100755
--- a/common/array.cpp
+++ b/common/array.cpp
@@ -1,105 +1,132 @@
//
-// Simple array class
+// Simple array classes
//
#include <stdlib.h>
#include <string.h>
template <class T>
-PtrArray<T>::PtrArray (int nSize)
+PtrArray<T>::PtrArray(int nSize)
{
- m_pData = NULL;
- m_nLength = 0;
- m_nAlloc = 0;
+ m_pData = NULL;
+ m_nLength = 0;
+ m_nAlloc = 0;
- if (nSize != 0)
- Expand (nSize);
+ if(nSize != 0)
+ Expand(nSize);
}
template <class T>
-PtrArray<T>::~PtrArray ()
+PtrArray<T>::~PtrArray()
{
- free (m_pData);
+ free(m_pData);
}
template <class T>
-void PtrArray<T>::Expand (int nGrow)
+void PtrArray<T>::Expand(int nGrow)
{
- if ((m_nLength + nGrow) > m_nAlloc)
- {
- m_pData = (T**)realloc (m_pData, (m_nLength + nGrow) * sizeof (T*));
- memset (m_pData + m_nLength, 0, nGrow * sizeof (T*));
- m_nAlloc = m_nLength + nGrow;
- }
+ if((m_nLength + nGrow) > m_nAlloc)
+ {
+ m_pData =(T**)realloc(m_pData,(m_nLength + nGrow) * sizeof(T*));
+ memset(m_pData + m_nLength, 0, nGrow * sizeof(T*));
+ m_nAlloc = m_nLength + nGrow;
+ }
}
template <class T>
-T* PtrArray<T>::RemoveIndex (int nIndex)
+void PtrArray<T>::RemoveAll()
{
- T* ret = NULL;
+ m_nLength = 0;
+}
- if (nIndex < m_nLength)
- {
- ret = m_pData[nIndex];
+template <class T>
+T* PtrArray<T>::RemoveIndex(int nIndex)
+{
+ T* ret = NULL;
- if (nIndex != m_nLength - 1)
- memmove (m_pData + nIndex, m_pData + nIndex + 1,
- sizeof (T*) * (m_nLength - nIndex - 1));
-
- m_nLength--;
- m_pData[m_nLength] = NULL;
- }
+ if(nIndex < m_nLength)
+ {
+ ret = m_pData[nIndex];
- return ret;
+ if(nIndex != m_nLength - 1)
+ memmove(m_pData + nIndex, m_pData + nIndex + 1, sizeof(T*) *(m_nLength - nIndex - 1));
+
+ m_nLength--;
+ m_pData[m_nLength] = NULL;
+ }
+
+ return ret;
}
template <class T>
-T* PtrArray<T>::RemovePointer (T* pObj)
+T* PtrArray<T>::RemovePointer(T* pObj)
{
- int i;
+ int i;
- for (i = 0; i < m_nLength; i++)
- if (m_pData[i] == pObj)
- return RemoveIndex (i);
+ for(i = 0; i < m_nLength; i++)
+ if(m_pData[i] == pObj)
+ return RemoveIndex(i);
- return NULL;
+ return NULL;
}
template <class T>
-void PtrArray<T>::Add (T* pObj)
+void PtrArray<T>::Add(T* pObj)
{
- Expand (1);
- m_pData[m_nLength++] = pObj;
+ Expand(1);
+ m_pData[m_nLength] = pObj;
+ m_nLength++;
}
template <class T>
-void PtrArray<T>::AddSorted (T* pObj, LC_PTRARRAY_COMPARE_FUNC pFunc, void* pData)
+void PtrArray<T>::AddSorted(T* pObj, LC_PTRARRAY_COMPARE_FUNC pFunc, void* pData)
{
- int i;
+ int i;
- for (i = 0; i < GetSize (); i++)
- if (pFunc (pObj, m_pData[i], pData) < 0)
- {
- InsertAt (i, pObj);
- return;
- }
+ for(i = 0; i < GetSize(); i++)
+ {
+ if(pFunc(pObj, m_pData[i], pData) < 0)
+ {
+ InsertAt(i, pObj);
+ return;
+ }
+ }
- Add (pObj);
+ Add(pObj);
}
template <class T>
-void PtrArray<T>::InsertAt (int nIndex, T* pObj)
+void PtrArray<T>::InsertAt(int nIndex, T* pObj)
{
- if (nIndex >= m_nLength)
- Expand (nIndex - m_nLength + 1);
- else
- Expand (1);
+ if(nIndex >= m_nLength)
+ Expand(nIndex - m_nLength + 1);
+ else
+ Expand(1);
m_nLength++;
- for (int i = m_nLength - 1; i > nIndex; i--)
- m_pData[i] = m_pData[i-1];
+ for(int i = m_nLength - 1; i > nIndex; i--)
+ m_pData[i] = m_pData[i-1];
+
+ m_pData[nIndex] = pObj;
+}
+
+template <class T>
+int PtrArray<T>::FindIndex(T* Obj) const
+{
+ for (int i = 0; i < m_nLength; i++)
+ if (m_pData[i] == Obj)
+ return i;
- m_pData[nIndex] = pObj;
+ return -1;
+}
+
+template <class T>
+PtrArray<T>& PtrArray<T>::operator=(const PtrArray<T>& Array)
+{
+ m_nLength = Array.m_nLength;
+ m_nAlloc = Array.m_nAlloc;
+ m_pData =(T**)realloc(m_pData, (m_nAlloc) * sizeof(T*));
+ memcpy(m_pData, Array.m_pData, (m_nAlloc) * sizeof(T*));
}
// ============================================================================
@@ -141,6 +168,12 @@ void ObjArray<T>::Expand(int Grow)
}
template <class T>
+void ObjArray<T>::RemoveAll()
+{
+ m_Length = 0;
+}
+
+template <class T>
void ObjArray<T>::RemoveIndex(int Index)
{
m_Length--;
diff --git a/common/array.h b/common/array.h
index c8adfbf..64f82f9 100755
--- a/common/array.h
+++ b/common/array.h
@@ -4,30 +4,33 @@
template <class T>
class PtrArray
{
- public:
- PtrArray (int nSize = 0);
- ~PtrArray ();
+public:
+ PtrArray(int nSize = 0);
+ ~PtrArray();
- typedef int (*LC_PTRARRAY_COMPARE_FUNC) (T* a, T* b, void* data);
+ typedef int (*LC_PTRARRAY_COMPARE_FUNC)(T* a, T* b, void* data);
- int GetSize () const
- { return m_nLength; }
+ int GetSize() const
+ { return m_nLength; }
- T* RemoveIndex (int nIndex);
- T* RemovePointer (T* pObj);
- void Add (T* pObj);
- void AddSorted (T* pObj, LC_PTRARRAY_COMPARE_FUNC pFunc, void* pData);
- void InsertAt (int nIndex, T* pObj);
+ T* RemoveIndex(int nIndex);
+ T* RemovePointer(T* pObj);
+ void RemoveAll();
+ void Add(T* pObj);
+ void AddSorted(T* pObj, LC_PTRARRAY_COMPARE_FUNC pFunc, void* pData);
+ void InsertAt(int nIndex, T* pObj);
+ int FindIndex(T* Obj) const;
- T* operator [](int nIndex) const
- { return m_pData[nIndex]; }
+ PtrArray<T>& operator=(const PtrArray<T>& Array);
+ T* operator [](int nIndex) const
+ { return m_pData[nIndex]; }
- protected:
- void Expand (int nGrow);
+protected:
+ void Expand(int nGrow);
- T** m_pData;
- int m_nLength;
- int m_nAlloc;
+ T** m_pData;
+ int m_nLength;
+ int m_nAlloc;
};
template <class T>
@@ -43,6 +46,7 @@ public:
{ return m_Length; }
void RemoveIndex(int Index);
+ void RemoveAll();
void Add(const T& Obj);
void AddSorted(const T& Obj, LC_OBJARRAY_COMPARE_FUNC Func, void* SortData);
void InsertAt(int Index, const T& Obj);
diff --git a/common/library.cpp b/common/library.cpp
index 3da1053..370b6df 100755
--- a/common/library.cpp
+++ b/common/library.cpp
@@ -198,6 +198,30 @@ bool PiecesLibrary::Load (const char *libpath)
idx.Close();
bin.Close();
+ // TODO: Load categories.
+
+ const int NumCategories = 34;
+ const char* DefaultCategories[] =
+ {
+ "Animal", "Antenna", "Arm", "Bar", "Baseplate", "Belville", "Boat", "Bracket", "Brick", "Car",
+ "Cone", "Container", "Crane", "Cylinder", "Door", "Flag", "Hinge", "Hose", "Magnet", "Minifig",
+ "Minifig Accessory", "Plane", "Plant", "Plate", "Propellor", "Rock", "Round", "Scala",
+ "Slope", "Space", "Support", "Technic", "Wheel", "Windscreen"
+ };
+
+
+ for (i = 0; i < NumCategories; i++)
+ {
+ PiecesLibraryCategory Cat;
+
+ Cat.Name = DefaultCategories[i];
+ Cat.Keywords = DefaultCategories[i];
+
+ m_Categories.Add(Cat);
+ }
+
+ SystemUpdateCategories(false);
+
m_bNeedsReload = false;
return true;
@@ -366,6 +390,118 @@ Texture* PiecesLibrary::GetTexture (int index) const
// =============================================================================
+void PiecesLibrary::GetCategoryEntries(int CategoryIndex, PtrArray<PieceInfo>& SinglePieces, PtrArray<PieceInfo>& GroupedPieces)
+{
+ bool m_bSubParts = false;
+
+ String& SearchString = m_Categories[CategoryIndex].Keywords;
+
+ SinglePieces.RemoveAll();
+ GroupedPieces.RemoveAll();
+
+ for (int i = 0; i < m_nPieceCount; i++)
+ {
+ PieceInfo* Info = &m_pPieceIdx[i];
+
+ // Skip subparts if the user doesn't want to see them.
+ if ((Info->m_strDescription[0] == '~') && !m_bSubParts)
+ continue;
+
+ // Check if the piece belongs to this category.
+ if (strncmp(Info->m_strDescription, (const char*)SearchString, strlen(SearchString)) != 0)
+ continue;
+
+ // Check if it's a patterned piece.
+ const char* Name = Info->m_strName;
+ while (*Name)
+ {
+ if (!*Name || *Name < '0' || *Name > '9')
+ break;
+
+ if (*Name == 'P')
+ break;
+
+ Name++;
+ }
+
+ if (*Name == 'P')
+ {
+ PieceInfo* Parent;
+
+ // Find the parent of this patterned piece.
+ char ParentName[9];
+ strcpy(ParentName, Info->m_strName);
+ ParentName[Name - Info->m_strName] = '\0';
+
+ Parent = FindPieceInfo(ParentName);
+
+ if (Parent)
+ {
+ // Check if the parent was added as a single piece.
+ int Index = SinglePieces.FindIndex(Parent);
+
+ if (Index != -1)
+ SinglePieces.RemoveIndex(Index);
+
+ Index = GroupedPieces.FindIndex(Parent);
+
+ if (Index == -1)
+ GroupedPieces.Add(Parent);
+ }
+ else
+ {
+ // Patterned pieces should have a parent but in case they don't just add them anyway.
+ SinglePieces.Add(Info);
+ }
+ }
+ else
+ {
+ // Check if this piece has already been added to this category by one of its children.
+ int Index = GroupedPieces.FindIndex(Info);
+
+ if (Index == -1)
+ SinglePieces.Add(Info);
+ }
+ }
+}
+
+void PiecesLibrary::GetPatternedPieces(PieceInfo* Parent, PtrArray<PieceInfo>& Pieces)
+{
+ char Name[9];
+ strcpy(Name, Parent->m_strName);
+ strcat(Name, "P");
+
+ Pieces.RemoveAll();
+
+ for (int i = 0; i < m_nPieceCount; i++)
+ {
+ PieceInfo* Info = &m_pPieceIdx[i];
+
+ if (strncmp(Name, Info->m_strName, strlen(Name)) == 0)
+ Pieces.Add(Info);
+ }
+}
+
+void PiecesLibrary::SetCategory(int Index, const String& Name, const String& Keywords)
+{
+ m_Categories[Index].Name = Name;
+ m_Categories[Index].Keywords = Keywords;
+
+ SystemUpdateCategories(true);
+}
+
+void PiecesLibrary::AddCategory(const String& Name, const String& Keywords)
+{
+ PiecesLibraryCategory Cat;
+
+ Cat.Name = Name;
+ Cat.Keywords = Keywords;
+
+ m_Categories.Add(Cat);
+
+ SystemUpdateCategories(true);
+}
+
unsigned long PiecesLibrary::GetDefaultPieceGroup (const char* name)
{
char tmp[9];
diff --git a/common/library.h b/common/library.h
index 54fd137..3ecdde9 100755
--- a/common/library.h
+++ b/common/library.h
@@ -3,6 +3,7 @@
#include "defines.h"
#include "str.h"
+#include "array.h"
class File;
class Texture;
@@ -10,6 +11,12 @@ class PieceInfo;
#define LC_PIECESLIB_MAXGROUPS 32
+typedef struct
+{
+ String Name;
+ String Keywords;
+} PiecesLibraryCategory;
+
class PiecesLibrary
{
public:
@@ -29,19 +36,40 @@ public:
bool NeedsReload () const
{ return m_bNeedsReload; }
+ // Categories.
+ void GetCategoryEntries(int CategoryIndex, PtrArray<PieceInfo>& SinglePieces, PtrArray<PieceInfo>& GroupedPieces);
+ void GetPatternedPieces(PieceInfo* Parent, PtrArray<PieceInfo>& Pieces);
+ void SetCategory(int Index, const String& Name, const String& Keywords);
+ void AddCategory(const String& Name, const String& Keywords);
+
+ const char* GetCategoryName(int Index) const
+ { return m_Categories[Index].Name; }
+
+ int GetNumCategories() const
+ { return m_Categories.GetSize(); }
+
+ int FindCategoryIndex(const String& CategoryName) const
+ {
+ for (int i = 0; i < m_Categories.GetSize(); i++)
+ if (m_Categories[i].Name == CategoryName)
+ return i;
+
+ return -1;
+ }
+
void CheckReload ();
bool Load (const char* libpath);
void Unload ();
bool LoadGroupConfig (const char* Filename);
- // Search for stuff
+ // Search for pieces.
PieceInfo* FindPieceInfo (const char* name) const;
PieceInfo* GetPieceInfo (int index) const;
int GetPieceIndex (PieceInfo *pInfo) const;
Texture* FindTexture (const char* name) const;
Texture* GetTexture (int index) const;
- // File operations
+ // File operations.
bool DeletePieces (char** names, int numpieces);
bool LoadUpdate (const char* update);
bool DeleteTextures (char** Names, int NumTextures);
@@ -60,6 +88,9 @@ protected:
int m_nTextureCount; // number of textures
Texture* m_pTextures; // textures array
+ // Categories.
+ ObjArray<PiecesLibraryCategory> m_Categories;
+
// Groups stuff
int m_nGroupCount;
String m_strGroups[LC_PIECESLIB_MAXGROUPS];
diff --git a/common/system.h b/common/system.h
index 415b30a..f8161ae 100755
--- a/common/system.h
+++ b/common/system.h
@@ -75,6 +75,7 @@ void SystemUpdateSnap(unsigned short MoveSnap, unsigned short RotateSnap);
void SystemUpdateSelected(unsigned long flags);
void SystemUpdatePaste(bool enable);
void SystemUpdatePlay(bool play, bool stop);
+void SystemUpdateCategories(bool SearchOnly);
void SystemInit();
void SystemFinish();
diff --git a/win/LeoCAD.dsp b/win/LeoCAD.dsp
index 7bf6a8d..ddf0f5b 100644
--- a/win/LeoCAD.dsp
+++ b/win/LeoCAD.dsp
@@ -344,6 +344,10 @@ SOURCE=.\Transbar.cpp
# End Source File
# Begin Source File
+SOURCE=.\transdlg.cpp
+# End Source File
+# Begin Source File
+
SOURCE=.\Wheelwnd.cpp
# End Source File
# Begin Source File
@@ -576,6 +580,10 @@ SOURCE=.\Transbar.h
# End Source File
# Begin Source File
+SOURCE=.\transdlg.h
+# End Source File
+# Begin Source File
+
SOURCE=.\WheelWnd.h
# End Source File
# Begin Source File
diff --git a/win/LeoCAD.rc b/win/LeoCAD.rc
index 00e291a..0958847 100644
--- a/win/LeoCAD.rc
+++ b/win/LeoCAD.rc
@@ -1401,6 +1401,29 @@ BEGIN
LTEXT "Shortcuts File:",IDC_STATIC,100,76,139,8
END
+IDD_TRANSFORM DIALOG DISCARDABLE 0, 0, 249, 84
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Transform"
+FONT 8, "MS Sans Serif"
+BEGIN
+ DEFPUSHBUTTON "OK",IDOK,201,7,41,14
+ PUSHBUTTON "Cancel",IDCANCEL,201,24,41,14
+ LTEXT "X:",IDC_STATIC,16,22,14,8
+ EDITTEXT IDC_TRANSDLG_GX,31,20,43,12,ES_AUTOHSCROLL
+ LTEXT "Y:",IDC_STATIC,16,39,14,8
+ EDITTEXT IDC_TRANSDLG_GY,31,37,43,12,ES_AUTOHSCROLL
+ LTEXT "Z:",IDC_STATIC,16,56,14,8
+ EDITTEXT IDC_TRANSDLG_GZ,31,54,43,12,ES_AUTOHSCROLL
+ GROUPBOX "Global",IDC_STATIC,7,7,80,68
+ LTEXT "X:",IDC_STATIC,114,22,14,8
+ EDITTEXT IDC_TRANSDLG_OX,129,20,43,12,ES_AUTOHSCROLL
+ LTEXT "Y:",IDC_STATIC,114,39,14,8
+ EDITTEXT IDC_TRANSDLG_OY,129,37,43,12,ES_AUTOHSCROLL
+ LTEXT "Z:",IDC_STATIC,114,56,14,8
+ EDITTEXT IDC_TRANSDLG_OZ,129,54,43,12,ES_AUTOHSCROLL
+ GROUPBOX "Offset",IDC_STATIC,105,7,80,68
+END
+
#ifndef _MAC
/////////////////////////////////////////////////////////////////////////////
@@ -1663,6 +1686,14 @@ BEGIN
TOPMARGIN, 7
BOTTOMMARGIN, 124
END
+
+ IDD_TRANSFORM, DIALOG
+ BEGIN
+ LEFTMARGIN, 7
+ RIGHTMARGIN, 242
+ TOPMARGIN, 7
+ BOTTOMMARGIN, 75
+ END
END
#endif // APSTUDIO_INVOKED
diff --git a/win/Piecebar.cpp b/win/Piecebar.cpp
index d54f52b..21283c9 100644
--- a/win/Piecebar.cpp
+++ b/win/Piecebar.cpp
@@ -5,6 +5,8 @@
#include "afxpriv.h" // for CDockContext
#include "resource.h"
#include "piecebar.h"
+#include "library.h"
+#include "pieceinf.h"
#include "project.h"
#include "globals.h"
@@ -30,13 +32,13 @@ CPiecesBar::CPiecesBar()
m_wndPiecePreview.m_bZoomPreview = (i & PIECEBAR_ZOOMPREVIEW) != 0;
m_nCurGroup = 1;
- m_sizeMin = CSize(222, 200);
- m_sizeHorz = CSize(200, 200);
- m_sizeVert = CSize(200, 200);
- m_sizeFloat = CSize(200, 200);
- m_bTracking = FALSE;
- m_bInRecalcNC = FALSE;
- m_cxEdge = 5;
+ m_sizeMin = CSize(222, 200);
+ m_sizeHorz = CSize(200, 200);
+ m_sizeVert = CSize(200, 200);
+ m_sizeFloat = CSize(200, 200);
+ m_bTracking = FALSE;
+ m_bInRecalcNC = FALSE;
+ m_cxEdge = 5;
m_bDragShowContent = FALSE;
m_nPreviewHeight = AfxGetApp()->GetProfileInt("Settings", "Preview Height", 93);
m_bNoContext = FALSE;
@@ -48,20 +50,20 @@ CPiecesBar::~CPiecesBar()
}
BEGIN_MESSAGE_MAP(CPiecesBar, CControlBar)
- //{{AFX_MSG_MAP(CPiecesBar)
- ON_WM_PAINT()
- ON_WM_NCPAINT()
- ON_WM_WINDOWPOSCHANGED()
- ON_WM_NCCALCSIZE()
- ON_WM_LBUTTONUP()
- ON_WM_MOUSEMOVE()
- ON_WM_NCLBUTTONDOWN()
- ON_WM_LBUTTONDOWN()
- ON_WM_LBUTTONDBLCLK()
+ //{{AFX_MSG_MAP(CPiecesBar)
+ ON_WM_PAINT()
+ ON_WM_NCPAINT()
+ ON_WM_WINDOWPOSCHANGED()
+ ON_WM_NCCALCSIZE()
+ ON_WM_LBUTTONUP()
+ ON_WM_MOUSEMOVE()
+ ON_WM_NCLBUTTONDOWN()
+ ON_WM_LBUTTONDOWN()
+ ON_WM_LBUTTONDBLCLK()
ON_WM_RBUTTONDOWN()
- ON_WM_CAPTURECHANGED()
- ON_WM_NCHITTEST()
- ON_WM_SETCURSOR()
+ ON_WM_CAPTURECHANGED()
+ ON_WM_NCHITTEST()
+ ON_WM_SETCURSOR()
ON_WM_SIZE()
ON_WM_CREATE()
ON_WM_CONTEXTMENU()
@@ -77,120 +79,113 @@ END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////
// CPiecesBar message handlers
-BOOL CPiecesBar::Create(LPCTSTR lpszWindowName, CWnd* pParentWnd,
- CSize sizeDefault, BOOL bHasGripper,
- UINT nID, DWORD dwStyle)
+BOOL CPiecesBar::Create(LPCTSTR lpszWindowName, CWnd* pParentWnd, CSize sizeDefault,
+ BOOL bHasGripper, UINT nID, DWORD dwStyle)
{
- ASSERT_VALID(pParentWnd); // must have a parent
- ASSERT (!((dwStyle & CBRS_SIZE_FIXED)
- && (dwStyle & CBRS_SIZE_DYNAMIC)));
+ ASSERT_VALID(pParentWnd); // must have a parent
+ ASSERT (!((dwStyle & CBRS_SIZE_FIXED) && (dwStyle & CBRS_SIZE_DYNAMIC)));
- // save the style
- SetBarStyle(dwStyle & CBRS_ALL);
+ // save the style
+ SetBarStyle(dwStyle & CBRS_ALL);
- CString wndclass = ::AfxRegisterWndClass(CS_DBLCLKS,
- ::LoadCursor(NULL, IDC_ARROW),
- ::GetSysColorBrush(COLOR_BTNFACE), 0);
+ CString wndclass = ::AfxRegisterWndClass(CS_DBLCLKS, ::LoadCursor(NULL, IDC_ARROW),
+ ::GetSysColorBrush(COLOR_BTNFACE), 0);
- dwStyle &= ~CBRS_ALL;
- dwStyle &= WS_VISIBLE | WS_CHILD;
- if (!CWnd::Create(wndclass, lpszWindowName, dwStyle, CRect(0,0,0,0),
- pParentWnd, nID))
- return FALSE;
+ dwStyle &= ~CBRS_ALL;
+ dwStyle &= WS_VISIBLE | WS_CHILD;
+ if (!CWnd::Create(wndclass, lpszWindowName, dwStyle, CRect(0,0,0,0),
+ pParentWnd, nID))
+ return FALSE;
- m_sizeHorz = sizeDefault;
- m_sizeVert = sizeDefault;
- m_sizeFloat = sizeDefault;
+ m_sizeHorz = sizeDefault;
+ m_sizeVert = sizeDefault;
+ m_sizeFloat = sizeDefault;
- m_bHasGripper = bHasGripper;
- m_cyGripper = m_bHasGripper ? 12 : 0;
+ m_bHasGripper = bHasGripper;
+ m_cyGripper = m_bHasGripper ? 12 : 0;
- return TRUE;
+ return TRUE;
}
BOOL CPiecesBar::IsHorzDocked() const
{
- return (m_nDockBarID == AFX_IDW_DOCKBAR_TOP ||
- m_nDockBarID == AFX_IDW_DOCKBAR_BOTTOM);
+ return (m_nDockBarID == AFX_IDW_DOCKBAR_TOP || m_nDockBarID == AFX_IDW_DOCKBAR_BOTTOM);
}
BOOL CPiecesBar::IsVertDocked() const
{
- return (m_nDockBarID == AFX_IDW_DOCKBAR_LEFT ||
- m_nDockBarID == AFX_IDW_DOCKBAR_RIGHT);
+ return (m_nDockBarID == AFX_IDW_DOCKBAR_LEFT || m_nDockBarID == AFX_IDW_DOCKBAR_RIGHT);
}
CSize CPiecesBar::CalcFixedLayout(BOOL bStretch, BOOL bHorz)
{
- CRect rc;
+ CRect rc;
- m_pDockSite->GetControlBar(AFX_IDW_DOCKBAR_TOP)->GetWindowRect(rc);
- int nHorzDockBarWidth = bStretch ? 32767 : rc.Width() + 4;
- m_pDockSite->GetControlBar(AFX_IDW_DOCKBAR_LEFT)->GetWindowRect(rc);
- int nVertDockBarHeight = bStretch ? 32767 : rc.Height() + 4;
+ m_pDockSite->GetControlBar(AFX_IDW_DOCKBAR_TOP)->GetWindowRect(rc);
+ int nHorzDockBarWidth = bStretch ? 32767 : rc.Width() + 4;
+ m_pDockSite->GetControlBar(AFX_IDW_DOCKBAR_LEFT)->GetWindowRect(rc);
+ int nVertDockBarHeight = bStretch ? 32767 : rc.Height() + 4;
- if (bHorz)
- return CSize(nHorzDockBarWidth, m_sizeHorz.cy);
- else
- return CSize(m_sizeVert.cx, nVertDockBarHeight);
+ if (bHorz)
+ return CSize(nHorzDockBarWidth, m_sizeHorz.cy);
+ else
+ return CSize(m_sizeVert.cx, nVertDockBarHeight);
}
CSize CPiecesBar::CalcDynamicLayout(int nLength, DWORD dwMode)
{
- if (dwMode & (LM_HORZDOCK | LM_VERTDOCK))
- {
- if (nLength == -1)
- GetDockingFrame()->DelayRecalcLayout();
- return CControlBar::CalcDynamicLayout(nLength,dwMode);
- }
+ if (dwMode & (LM_HORZDOCK | LM_VERTDOCK))
+ {
+ if (nLength == -1)
+ GetDockingFrame()->DelayRecalcLayout();
+ return CControlBar::CalcDynamicLayout(nLength,dwMode);
+ }
- if (dwMode & LM_MRUWIDTH)
- return m_sizeFloat;
+ if (dwMode & LM_MRUWIDTH)
+ return m_sizeFloat;
- if (dwMode & LM_COMMIT)
- {
- m_sizeFloat.cx = nLength;
- return m_sizeFloat;
- }
+ if (dwMode & LM_COMMIT)
+ {
+ m_sizeFloat.cx = nLength;
+ return m_sizeFloat;
+ }
- if (dwMode & LM_LENGTHY)
- return CSize(m_sizeFloat.cx,
- m_sizeFloat.cy = max(m_sizeMin.cy, nLength));
- else
- return CSize(max(m_sizeMin.cx, nLength), m_sizeFloat.cy);
+ if (dwMode & LM_LENGTHY)
+ return CSize(m_sizeFloat.cx,
+ m_sizeFloat.cy = max(m_sizeMin.cy, nLength));
+ else
+ return CSize(max(m_sizeMin.cx, nLength), m_sizeFloat.cy);
}
void CPiecesBar::OnWindowPosChanged(WINDOWPOS FAR* lpwndpos)
{
- CControlBar::OnWindowPosChanged(lpwndpos);
+ CControlBar::OnWindowPosChanged(lpwndpos);
- // Find on which side are we docked
- m_nDockBarID = GetParent()->GetDlgCtrlID();
+ // Find on which side are we docked
+ m_nDockBarID = GetParent()->GetDlgCtrlID();
- if (!m_bInRecalcNC)
- {
- m_bInRecalcNC = TRUE;
+ if (!m_bInRecalcNC)
+ {
+ m_bInRecalcNC = TRUE;
- // Force recalc the non-client area
- SetWindowPos(NULL, 0, 0, 0, 0,
- SWP_NOMOVE | SWP_NOSIZE |
- SWP_NOACTIVATE | SWP_NOZORDER |
- SWP_FRAMECHANGED);
+ // Force recalc the non-client area
+ SetWindowPos(NULL, 0, 0, 0, 0,
+ SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED);
- m_bInRecalcNC = FALSE;
- }
+ m_bInRecalcNC = FALSE;
+ }
}
BOOL CPiecesBar::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
- if ((nHitTest != HTSIZE) || m_bTracking)
- return CControlBar::OnSetCursor(pWnd, nHitTest, message);
+ if ((nHitTest != HTSIZE) || m_bTracking)
+ return CControlBar::OnSetCursor(pWnd, nHitTest, message);
- if (IsHorzDocked())
- ::SetCursor(::LoadCursor(NULL, IDC_SIZENS));
- else
- ::SetCursor(::LoadCursor(NULL, IDC_SIZEWE));
- return TRUE;
+ if (IsHorzDocked())
+ ::SetCursor(::LoadCursor(NULL, IDC_SIZENS));
+ else
+ ::SetCursor(::LoadCursor(NULL, IDC_SIZEWE));
+ return TRUE;
}
/////////////////////////////////////////////////////////////////////////
@@ -198,45 +193,45 @@ BOOL CPiecesBar::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
//
void CPiecesBar::OnLButtonDown(UINT nFlags, CPoint point)
{
- if (m_pDockBar != NULL)
- {
- // start the drag
- ASSERT(m_pDockContext != NULL);
- ClientToScreen(&point);
- m_pDockContext->StartDrag(point);
- }
- else
- CWnd::OnLButtonDown(nFlags, point);
+ if (m_pDockBar != NULL)
+ {
+ // start the drag
+ ASSERT(m_pDockContext != NULL);
+ ClientToScreen(&point);
+ m_pDockContext->StartDrag(point);
+ }
+ else
+ CWnd::OnLButtonDown(nFlags, point);
}
void CPiecesBar::OnLButtonDblClk(UINT nFlags, CPoint point)
{
- if (m_pDockBar != NULL)
- {
- // toggle docking
- ASSERT(m_pDockContext != NULL);
- m_pDockContext->ToggleDocking();
- }
- else
- CWnd::OnLButtonDblClk(nFlags, point);
+ if (m_pDockBar != NULL)
+ {
+ // toggle docking
+ ASSERT(m_pDockContext != NULL);
+ m_pDockContext->ToggleDocking();
+ }
+ else
+ CWnd::OnLButtonDblClk(nFlags, point);
}
void CPiecesBar::OnNcLButtonDown(UINT nHitTest, CPoint point)
{
- if (m_bTracking) return;
+ if (m_bTracking) return;
- if ((nHitTest == HTSIZE) && !IsFloating())
- StartTracking();
- else
- CControlBar::OnNcLButtonDown(nHitTest, point);
+ if ((nHitTest == HTSIZE) && !IsFloating())
+ StartTracking();
+ else
+ CControlBar::OnNcLButtonDown(nHitTest, point);
}
void CPiecesBar::OnLButtonUp(UINT nFlags, CPoint point)
{
- if (m_bTracking)
+ if (m_bTracking)
StopTracking(TRUE);
- CControlBar::OnLButtonUp(nFlags, point);
+ CControlBar::OnLButtonUp(nFlags, point);
}
void CPiecesBar::OnRButtonDown(UINT nFlags, CPoint point)
@@ -249,152 +244,151 @@ void CPiecesBar::OnRButtonDown(UINT nFlags, CPoint point)
void CPiecesBar::OnMouseMove(UINT nFlags, CPoint point)
{
- if (m_bTracking)
- {
+ if (m_bTracking)
+ {
ASSERT (!IsFloating());
CPoint pt = point;
ClientToScreen(&pt);
OnTrackUpdateSize(pt);
- }
+ }
- CControlBar::OnMouseMove(nFlags, point);
+ CControlBar::OnMouseMove(nFlags, point);
}
void CPiecesBar::OnCaptureChanged(CWnd *pWnd)
{
- if (m_bTracking && pWnd != this)
- StopTracking(FALSE); // cancel tracking
+ if (m_bTracking && pWnd != this)
+ StopTracking(FALSE); // cancel tracking
- CControlBar::OnCaptureChanged(pWnd);
+ CControlBar::OnCaptureChanged(pWnd);
}
void CPiecesBar::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp)
{
UNREFERENCED_PARAMETER(bCalcValidRects);
- // Compute the rectangle of the mobile edge
- GetWindowRect(m_rectBorder);
- m_rectBorder.OffsetRect(-m_rectBorder.left, -m_rectBorder.top);
- m_rectBorder.DeflateRect(1, 1);
-
- m_rectGripper = m_rectBorder;
- m_rectGripper.DeflateRect(5, 5);
- m_rectGripper.right -= m_cxEdge;
- m_rectGripper.bottom -= m_cxEdge;
- CRect rc = lpncsp->rgrc[0];
-
- DWORD dwBorderStyle = m_dwStyle | CBRS_BORDER_ANY;
-
- switch(m_nDockBarID)
- {
- case AFX_IDW_DOCKBAR_TOP:
- dwBorderStyle &= ~CBRS_BORDER_BOTTOM;
- rc.DeflateRect(m_cyGripper + 2, 2, 2, m_cxEdge + 2);
- m_rectBorder.top = m_rectBorder.bottom - m_cxEdge;
- break;
- case AFX_IDW_DOCKBAR_BOTTOM:
- dwBorderStyle &= ~CBRS_BORDER_TOP;
- rc.DeflateRect(m_cyGripper + 2, m_cxEdge + 2, 2, 2);
- m_rectBorder.bottom = m_rectBorder.top + m_cxEdge;
- m_rectGripper.OffsetRect(0, m_cxEdge);
- break;
- case AFX_IDW_DOCKBAR_LEFT:
- dwBorderStyle &= ~CBRS_BORDER_RIGHT;
- rc.DeflateRect(2, m_cyGripper + 2, m_cxEdge + 2, 6);
- m_rectBorder.left = m_rectBorder.right - m_cxEdge;
- break;
- case AFX_IDW_DOCKBAR_RIGHT:
- dwBorderStyle &= ~CBRS_BORDER_LEFT;
- rc.DeflateRect(m_cxEdge + 2, m_cyGripper + 2, 2, 6);
- m_rectBorder.right = m_rectBorder.left + m_cxEdge;
- m_rectGripper.OffsetRect(m_cxEdge, 0);
- break;
- default:
- m_rectBorder.SetRectEmpty();
- break;
- }
-
- lpncsp->rgrc[0] = rc;
-
- SetBarStyle(dwBorderStyle);
+ // Compute the rectangle of the mobile edge
+ GetWindowRect(m_rectBorder);
+ m_rectBorder.OffsetRect(-m_rectBorder.left, -m_rectBorder.top);
+ m_rectBorder.DeflateRect(1, 1);
+
+ m_rectGripper = m_rectBorder;
+ m_rectGripper.DeflateRect(5, 5);
+ m_rectGripper.right -= m_cxEdge;
+ m_rectGripper.bottom -= m_cxEdge;
+ CRect rc = lpncsp->rgrc[0];
+
+ DWORD dwBorderStyle = m_dwStyle | CBRS_BORDER_ANY;
+
+ switch(m_nDockBarID)
+ {
+ case AFX_IDW_DOCKBAR_TOP:
+ dwBorderStyle &= ~CBRS_BORDER_BOTTOM;
+ rc.DeflateRect(m_cyGripper + 2, 2, 2, m_cxEdge + 2);
+ m_rectBorder.top = m_rectBorder.bottom - m_cxEdge;
+ break;
+ case AFX_IDW_DOCKBAR_BOTTOM:
+ dwBorderStyle &= ~CBRS_BORDER_TOP;
+ rc.DeflateRect(m_cyGripper + 2, m_cxEdge + 2, 2, 2);
+ m_rectBorder.bottom = m_rectBorder.top + m_cxEdge;
+ m_rectGripper.OffsetRect(0, m_cxEdge);
+ break;
+ case AFX_IDW_DOCKBAR_LEFT:
+ dwBorderStyle &= ~CBRS_BORDER_RIGHT;
+ rc.DeflateRect(2, m_cyGripper + 2, m_cxEdge + 2, 6);
+ m_rectBorder.left = m_rectBorder.right - m_cxEdge;
+ break;
+ case AFX_IDW_DOCKBAR_RIGHT:
+ dwBorderStyle &= ~CBRS_BORDER_LEFT;
+ rc.DeflateRect(m_cxEdge + 2, m_cyGripper + 2, 2, 6);
+ m_rectBorder.right = m_rectBorder.left + m_cxEdge;
+ m_rectGripper.OffsetRect(m_cxEdge, 0);
+ break;
+ default:
+ m_rectBorder.SetRectEmpty();
+ break;
+ }
+
+ lpncsp->rgrc[0] = rc;
+
+ SetBarStyle(dwBorderStyle);
}
void CPiecesBar::OnNcPaint()
{
- // get window DC that is clipped to the non-client area
- CWindowDC dc(this);
- CRect rectClient;
- GetClientRect(rectClient);
- CRect rectWindow;
- GetWindowRect(rectWindow);
- ScreenToClient(rectWindow);
- rectClient.OffsetRect(-rectWindow.left, -rectWindow.top);
- dc.ExcludeClipRect(rectClient);
-
- // draw borders in non-client area
- rectWindow.OffsetRect(-rectWindow.left, -rectWindow.top);
- DrawBorders(&dc, rectWindow);
-
- // erase parts not drawn
- dc.IntersectClipRect(rectWindow);
-
- // erase NC background the hard way
- HBRUSH hbr = (HBRUSH)GetClassLong(m_hWnd, GCL_HBRBACKGROUND);
- ::FillRect(dc.m_hDC, rectWindow, hbr);
-
- // paint the mobile edge
- dc.Draw3dRect(m_rectBorder, ::GetSysColor(COLOR_BTNHIGHLIGHT),
- ::GetSysColor(COLOR_BTNSHADOW));
-
- if (m_bHasGripper)
- {
- // paint the gripper
- CRect gripper = m_rectGripper;
-
- if (IsHorzDocked())
- {
- // gripper at left
- gripper.right = gripper.left + 3;
- dc.Draw3dRect(gripper, ::GetSysColor(COLOR_BTNHIGHLIGHT),
- ::GetSysColor(COLOR_BTNSHADOW));
- gripper.OffsetRect(3, 0);
- dc.Draw3dRect(gripper, ::GetSysColor(COLOR_BTNHIGHLIGHT),
- ::GetSysColor(COLOR_BTNSHADOW));
- }
- else if (IsVertDocked())
- {
- // gripper at top
- gripper.bottom = gripper.top + 3;
- dc.Draw3dRect(gripper, ::GetSysColor(COLOR_BTNHIGHLIGHT),
- ::GetSysColor(COLOR_BTNSHADOW));
- gripper.OffsetRect(0, 3);
- dc.Draw3dRect(gripper, ::GetSysColor(COLOR_BTNHIGHLIGHT),
- ::GetSysColor(COLOR_BTNSHADOW));
- }
- }
-
- ReleaseDC(&dc);
+ // get window DC that is clipped to the non-client area
+ CWindowDC dc(this);
+ CRect rectClient;
+ GetClientRect(rectClient);
+ CRect rectWindow;
+ GetWindowRect(rectWindow);
+ ScreenToClient(rectWindow);
+ rectClient.OffsetRect(-rectWindow.left, -rectWindow.top);
+ dc.ExcludeClipRect(rectClient);
+
+ // draw borders in non-client area
+ rectWindow.OffsetRect(-rectWindow.left, -rectWindow.top);
+ DrawBorders(&dc, rectWindow);
+
+ // erase parts not drawn
+ dc.IntersectClipRect(rectWindow);
+
+ // erase NC background the hard way
+ HBRUSH hbr = (HBRUSH)GetClassLong(m_hWnd, GCL_HBRBACKGROUND);
+ ::FillRect(dc.m_hDC, rectWindow, hbr);
+
+ // paint the mobile edge
+ dc.Draw3dRect(m_rectBorder, ::GetSysColor(COLOR_BTNHIGHLIGHT), ::GetSysColor(COLOR_BTNSHADOW));
+
+ if (m_bHasGripper)
+ {
+ // paint the gripper
+ CRect gripper = m_rectGripper;
+
+ if (IsHorzDocked())
+ {
+ // gripper at left
+ gripper.right = gripper.left + 3;
+ dc.Draw3dRect(gripper, ::GetSysColor(COLOR_BTNHIGHLIGHT),
+ ::GetSysColor(COLOR_BTNSHADOW));
+ gripper.OffsetRect(3, 0);
+ dc.Draw3dRect(gripper, ::GetSysColor(COLOR_BTNHIGHLIGHT),
+ ::GetSysColor(COLOR_BTNSHADOW));
+ }
+ else if (IsVertDocked())
+ {
+ // gripper at top
+ gripper.bottom = gripper.top + 3;
+ dc.Draw3dRect(gripper, ::GetSysColor(COLOR_BTNHIGHLIGHT),
+ ::GetSysColor(COLOR_BTNSHADOW));
+ gripper.OffsetRect(0, 3);
+ dc.Draw3dRect(gripper, ::GetSysColor(COLOR_BTNHIGHLIGHT),
+ ::GetSysColor(COLOR_BTNSHADOW));
+ }
+ }
+
+ ReleaseDC(&dc);
}
void CPiecesBar::OnPaint()
{
- // overridden to skip border painting based on clientrect
- CPaintDC dc(this);
+ // overridden to skip border painting based on clientrect
+ CPaintDC dc(this);
}
UINT CPiecesBar::OnNcHitTest(CPoint point)
{
- if (IsFloating())
- return CControlBar::OnNcHitTest(point);
-
- CRect rc;
- GetWindowRect(rc);
- point.Offset(-rc.left, -rc.top);
- if (m_rectBorder.PtInRect(point))
- return HTSIZE;
- else
- return HTCLIENT;
+ if (IsFloating())
+ return CControlBar::OnNcHitTest(point);
+
+ CRect rc;
+ GetWindowRect(rc);
+ point.Offset(-rc.left, -rc.top);
+ if (m_rectBorder.PtInRect(point))
+ return HTSIZE;
+ else
+ return HTCLIENT;
}
/////////////////////////////////////////////////////////////////////////
@@ -402,27 +396,27 @@ UINT CPiecesBar::OnNcHitTest(CPoint point)
void CPiecesBar::StartTracking()
{
- SetCapture();
+ SetCapture();
+
+ // make sure no updates are pending
+ RedrawWindow(NULL, NULL, RDW_ALLCHILDREN | RDW_UPDATENOW);
- // make sure no updates are pending
- RedrawWindow(NULL, NULL, RDW_ALLCHILDREN | RDW_UPDATENOW);
-
m_bDragShowContent = QueryDragFullWindows();
-
+
if (!m_bDragShowContent)
- m_pDockSite->LockWindowUpdate();
+ m_pDockSite->LockWindowUpdate();
m_sizeOld = IsHorzDocked() ? m_sizeHorz : m_sizeVert;
CRect rect;
GetWindowRect(&rect);
- m_ptOld = m_rectBorder.CenterPoint() + rect.TopLeft();
+ m_ptOld = m_rectBorder.CenterPoint() + rect.TopLeft();
m_sizeMax = CalcMaxSize();
- m_bTracking = TRUE;
-
+ m_bTracking = TRUE;
+
if (!m_bDragShowContent)
- OnTrackInvertTracker();
+ OnTrackInvertTracker();
}
void CPiecesBar::StopTracking(BOOL bAccept)
@@ -430,50 +424,49 @@ void CPiecesBar::StopTracking(BOOL bAccept)
if (!m_bDragShowContent)
{
OnTrackInvertTracker();
- m_pDockSite->UnlockWindowUpdate();
+ m_pDockSite->UnlockWindowUpdate();
}
- m_bTracking = FALSE;
- ReleaseCapture();
-
- if (!bAccept) // resize canceled?
+ m_bTracking = FALSE;
+ ReleaseCapture();
+
+ if (!bAccept) // resize canceled?
{
// restore old size
if (IsHorzDocked())
- m_sizeHorz = m_sizeOld;
+ m_sizeHorz = m_sizeOld;
else
m_sizeVert = m_sizeOld;
}
- m_pDockSite->DelayRecalcLayout();
+ m_pDockSite->DelayRecalcLayout();
}
void CPiecesBar::OnTrackUpdateSize(CPoint& point)
{
BOOL bHorz = IsHorzDocked();
- CSize sizeNew = m_sizeOld;
-
- if ((m_nDockBarID == AFX_IDW_DOCKBAR_TOP) ||
+ CSize sizeNew = m_sizeOld;
+
+ if ((m_nDockBarID == AFX_IDW_DOCKBAR_TOP) ||
(m_nDockBarID == AFX_IDW_DOCKBAR_LEFT))
- sizeNew += point - m_ptOld;
+ sizeNew += point - m_ptOld;
else
- sizeNew -= point - m_ptOld;
+ sizeNew -= point - m_ptOld;
// check limits
- sizeNew.cx = max(m_sizeMin.cx, sizeNew.cx);
- sizeNew.cy = max(m_sizeMin.cy, sizeNew.cy);
- sizeNew.cx = min(m_sizeMax.cx, sizeNew.cx);
- sizeNew.cy = min(m_sizeMax.cy, sizeNew.cy);
+ sizeNew.cx = max(m_sizeMin.cx, sizeNew.cx);
+ sizeNew.cy = max(m_sizeMin.cy, sizeNew.cy);
+ sizeNew.cx = min(m_sizeMax.cx, sizeNew.cx);
+ sizeNew.cy = min(m_sizeMax.cy, sizeNew.cy);
- if ((sizeNew.cy == m_sizeHorz.cy) && bHorz ||
- (sizeNew.cx == m_sizeVert.cx) && !bHorz)
+ if ((sizeNew.cy == m_sizeHorz.cy) && bHorz || (sizeNew.cx == m_sizeVert.cx) && !bHorz)
return; // no size change
if (!m_bDragShowContent)
OnTrackInvertTracker();
- if (bHorz)
+ if (bHorz)
m_sizeHorz = sizeNew;
else
m_sizeVert = sizeNew;
@@ -481,7 +474,7 @@ void CPiecesBar::OnTrackUpdateSize(CPoint& point)
if (!m_bDragShowContent)
OnTrackInvertTracker();
else
- m_pDockSite->DelayRecalcLayout();
+ m_pDockSite->DelayRecalcLayout();
}
CSize CPiecesBar::CalcMaxSize()
@@ -525,22 +518,22 @@ CSize CPiecesBar::CalcMaxSize()
}
size -= CSize(4, 4);
- size += IsHorzDocked() ? m_sizeHorz : m_sizeVert;
+ size += IsHorzDocked() ? m_sizeHorz : m_sizeVert;
return size;
}
void CPiecesBar::OnTrackInvertTracker()
{
- ASSERT_VALID(this);
- ASSERT(m_bTracking);
+ ASSERT_VALID(this);
+ ASSERT(m_bTracking);
CRect rect = m_rectBorder;
- CRect rectBar, rectFrame;
- GetWindowRect(rectBar);
- rect.OffsetRect(rectBar.TopLeft());
- m_pDockSite->GetWindowRect(rectFrame);
- rect.OffsetRect(-rectFrame.left, -rectFrame.top);
+ CRect rectBar, rectFrame;
+ GetWindowRect(rectBar);
+ rect.OffsetRect(rectBar.TopLeft());
+ m_pDockSite->GetWindowRect(rectFrame);
+ rect.OffsetRect(-rectFrame.left, -rectFrame.top);
switch (m_nDockBarID)
{
@@ -554,24 +547,22 @@ void CPiecesBar::OnTrackInvertTracker()
rect.OffsetRect(m_sizeOld.cx - m_sizeVert.cx, 0); break;
}
if (IsVertDocked())
- rect.bottom -= 4;
- rect.DeflateRect(1, 1);
+ rect.bottom -= 4;
+ rect.DeflateRect(1, 1);
- CDC *pDC = m_pDockSite->GetDCEx(NULL,
- DCX_WINDOW|DCX_CACHE|DCX_LOCKWINDOWUPDATE);
+ CDC *pDC = m_pDockSite->GetDCEx(NULL, DCX_WINDOW|DCX_CACHE|DCX_LOCKWINDOWUPDATE);
- CBrush* pBrush = CDC::GetHalftoneBrush();
- HBRUSH hOldBrush = NULL;
- if (pBrush != NULL)
- hOldBrush = (HBRUSH)::SelectObject(pDC->m_hDC, pBrush->m_hObject);
+ CBrush* pBrush = CDC::GetHalftoneBrush();
+ HBRUSH hOldBrush = NULL;
+ if (pBrush != NULL)
+ hOldBrush = (HBRUSH)::SelectObject(pDC->m_hDC, pBrush->m_hObject);
- pDC->PatBlt(rect.left, rect.top,
- rect.Width(), rect.Height(), PATINVERT);
+ pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(), PATINVERT);
- if (hOldBrush != NULL)
- ::SelectObject(pDC->m_hDC, hOldBrush);
+ if (hOldBrush != NULL)
+ ::SelectObject(pDC->m_hDC, hOldBrush);
- m_pDockSite->ReleaseDC(pDC);
+ m_pDockSite->ReleaseDC(pDC);
}
BOOL CPiecesBar::QueryDragFullWindows() const
@@ -624,6 +615,7 @@ void CPiecesBar::OnSize(UINT nType, int cx, int cy)
{
m_wndSplitter.SetWindowPos (NULL, 5, m_nPreviewHeight+6, cx-10, 4, SWP_NOZORDER);
m_wndPiecesList.SetWindowPos (NULL, 5, m_nPreviewHeight+10, cx-10, cy-off-15-m_nPreviewHeight, SWP_NOZORDER);
+ m_PiecesTree.SetWindowPos (NULL, 5, m_nPreviewHeight+10, cx-10, cy-off-15-m_nPreviewHeight, SWP_NOZORDER);
m_wndPiecePreview.SetWindowPos (NULL, 5, 5, cx-10, m_nPreviewHeight, 0);
m_wndPiecePreview.EnableWindow (TRUE);
m_wndPiecePreview.ShowWindow (SW_SHOW);
@@ -657,6 +649,9 @@ void CPiecesBar::OnSize(UINT nType, int cx, int cy)
m_wndPiecesList.SetColumnWidth (0, rect.right - rect.left - GetSystemMetrics(SM_CXVSCROLL) -2);
m_wndPiecesCombo.ShowWindow ((m_bCombo) ? SW_SHOW : SW_HIDE);
+
+
+m_wndPiecesList.ShowWindow(FALSE);
}
void CPiecesBar::OnUpdateCmdUI(CFrameWnd * pTarget, BOOL bDisableIfNoHndler)
@@ -677,25 +672,28 @@ int CPiecesBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CControlBar::OnCreate(lpCreateStruct) == -1)
return -1;
-
- m_wndPiecesList.Create (LVS_SINGLESEL|LVS_SHOWSELALWAYS|LVS_AUTOARRANGE|
- LVS_SORTASCENDING|WS_VISIBLE|WS_TABSTOP|LVS_REPORT|WS_BORDER,
- CRect(0,0,0,0), this, IDW_PIECESLIST);
+
+ m_PiecesTree.Create(WS_VISIBLE|WS_TABSTOP|WS_BORDER|TVS_HASBUTTONS|TVS_DISABLEDRAGDROP|TVS_HASLINES|TVS_LINESATROOT,
+ CRect(0,0,0,0), this, IDW_PIECESTREE);
+
+ m_wndPiecesList.Create(LVS_SINGLESEL|LVS_SHOWSELALWAYS|LVS_AUTOARRANGE|
+ LVS_SORTASCENDING|WS_VISIBLE|WS_TABSTOP|LVS_REPORT|WS_BORDER,
+ CRect(0,0,0,0), this, IDW_PIECESLIST);
m_wndPiecesList.InsertColumn(0, "Description", LVCFMT_LEFT, 129, 0);
m_wndPiecesList.SubclassHeader();
if (m_bNumbers)
m_wndPiecesList.InsertColumn(1, "Number", LVCFMT_LEFT, 60, 1);
- m_wndColorsList.Create (LBS_MULTICOLUMN|LBS_NOINTEGRALHEIGHT|LBS_NOTIFY|
- LBS_OWNERDRAWFIXED|WS_VISIBLE|WS_TABSTOP|WS_CHILD|WS_BORDER,
- CRect (0,0,0,0), this, IDW_COLORSLIST);
+ m_wndColorsList.Create(LBS_MULTICOLUMN|LBS_NOINTEGRALHEIGHT|LBS_NOTIFY|
+ LBS_OWNERDRAWFIXED|WS_VISIBLE|WS_TABSTOP|WS_CHILD|WS_BORDER,
+ CRect (0,0,0,0), this, IDW_COLORSLIST);
for (int i = 0; i < LC_MAXCOLORS; i++)
m_wndColorsList.AddString("");
- m_wndPiecesCombo.Create (CBS_DROPDOWN|CBS_SORT|CBS_HASSTRINGS|WS_VISIBLE|WS_CHILD|
- WS_VSCROLL|WS_TABSTOP, CRect (0,0,0,0), this, IDW_PIECESCOMBO);
+ m_wndPiecesCombo.Create(CBS_DROPDOWN|CBS_SORT|CBS_HASSTRINGS|WS_VISIBLE|WS_CHILD|
+ WS_VSCROLL|WS_TABSTOP, CRect (0,0,0,0), this, IDW_PIECESCOMBO);
// Create a font for the combobox
LOGFONT logFont;
@@ -721,8 +719,8 @@ int CPiecesBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
CreateGroupsBar();
- CreateWindow("STATIC", "", WS_VISIBLE|WS_CHILD|SS_ETCHEDFRAME,
- 0,0,0,0, m_hWnd, (HMENU)IDW_PIECEBAR_SPLITTER, AfxGetInstanceHandle(), NULL);
+ CreateWindow("STATIC", "", WS_VISIBLE|WS_CHILD|SS_ETCHEDFRAME, 0, 0, 0, 0,
+ m_hWnd, (HMENU)IDW_PIECEBAR_SPLITTER, AfxGetInstanceHandle(), NULL);
// y-splitter
m_wndSplitter.BindWithControl(this, IDW_PIECEBAR_SPLITTER);
@@ -750,7 +748,7 @@ BOOL CPiecesBar::OnToolTipText(UINT, NMHDR* pNMHDR, LRESULT* pResult)
if (GetRoutingFrame() != NULL)
return FALSE;
-
+
TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
@@ -796,7 +794,7 @@ BOOL CPiecesBar::OnToolTipText(UINT, NMHDR* pNMHDR, LRESULT* pResult)
}
*/
*pResult = 0;
-
+
::SetWindowPos(pNMHDR->hwndFrom, HWND_TOP, 0, 0, 0, 0, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE);
return TRUE; // message was handled
@@ -886,7 +884,7 @@ void CPiecesBar::CreateGroupsBar()
strcpy (m_GroupNames[i], str);
}
}
-
+
m_wndGroupsBar.m_ToolbarData.dwStyle = TBSTYLE_FLAT;
m_wndGroupsBar.m_ToolbarData.idControl = IDW_GROUPSBAR;
m_wndGroupsBar.m_ToolbarData.idbDefault = IDB_PIECEBAR;
@@ -922,3 +920,133 @@ void CPiecesBar::OnContextMenu(CWnd* pWnd, CPoint point)
pMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON, point.x, point.y, AfxGetMainWnd());
}
}
+
+void CPiecesBar::UpdatePiecesTree(bool SearchOnly)
+{
+ PiecesLibrary *Lib = project->GetPiecesLibrary();
+
+ if (SearchOnly)
+ {
+ HTREEITEM Item = m_PiecesTree.GetChildItem(TVI_ROOT);
+
+ while (Item != NULL)
+ {
+ CString Name = m_PiecesTree.GetItemText(Item);
+
+ if (Name == "Search Results")
+ break;
+
+ Item = m_PiecesTree.GetNextSiblingItem(Item);
+ }
+
+ if (Item == NULL)
+ {
+ Item = m_PiecesTree.InsertItem(TVIF_CHILDREN|TVIF_PARAM|TVIF_TEXT, "Search Results", 0, 0, 0, 0, 0, TVI_ROOT, TVI_LAST);
+ }
+
+ m_PiecesTree.Expand(Item, TVE_COLLAPSE | TVE_COLLAPSERESET);
+ m_PiecesTree.EnsureVisible(Item);
+ m_PiecesTree.Expand(Item, TVE_EXPAND);
+ }
+ else
+ {
+ m_PiecesTree.SetRedraw(FALSE);
+ m_PiecesTree.DeleteAllItems();
+
+ for (int i = 0; i < Lib->GetNumCategories(); i++)
+ {
+ m_PiecesTree.InsertItem(TVIF_CHILDREN|TVIF_PARAM|TVIF_TEXT, Lib->GetCategoryName(i), 0, 0, 0, 0, 0, TVI_ROOT, TVI_SORT);
+ }
+
+ m_PiecesTree.InsertItem(TVIF_CHILDREN|TVIF_PARAM|TVIF_TEXT, "Search Results", 0, 0, 0, 0, 0, TVI_ROOT, TVI_LAST);
+
+ m_PiecesTree.SetRedraw(TRUE);
+ m_PiecesTree.Invalidate();
+ }
+}
+
+BOOL CPiecesBar::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
+{
+ if (wParam == IDW_PIECESTREE)
+ {
+ LPNMTREEVIEW Notify = (LPNMTREEVIEW)lParam;
+
+ if (Notify->hdr.code == TVN_SELCHANGED)
+ {
+ PieceInfo* Info = (PieceInfo*)Notify->itemNew.lParam;
+
+ if (Info != NULL)
+ {
+ project->SetCurrentPiece(Info);
+ m_wndPiecePreview.SetPieceInfo(Info);
+ m_wndPiecePreview.PostMessage(WM_PAINT);
+ }
+ }
+ else if (Notify->hdr.code == TVN_ITEMEXPANDING)
+ {
+ if (Notify->action == TVE_EXPAND)
+ {
+ PiecesLibrary *Lib = project->GetPiecesLibrary();
+
+ // Check if we're expanding a category item.
+ if (Notify->itemNew.lParam == NULL)
+ {
+ HTREEITEM CategoryItem = Notify->itemNew.hItem;
+ CString CategoryName = m_PiecesTree.GetItemText(CategoryItem);
+ int CategoryIndex = Lib->FindCategoryIndex((const char*)CategoryName);
+
+ if (CategoryIndex != -1)
+ {
+ PtrArray<PieceInfo> SinglePieces, GroupedPieces;
+ int i;
+
+ Lib->GetCategoryEntries(CategoryIndex, SinglePieces, GroupedPieces);
+
+ for (i = 0; i < SinglePieces.GetSize(); i++)
+ {
+ PieceInfo* Info = SinglePieces[i];
+ m_PiecesTree.InsertItem(TVIF_PARAM|TVIF_TEXT, Info->m_strDescription, 0, 0, 0, 0, (LPARAM)Info, CategoryItem, TVI_SORT);
+ }
+
+ for (i = 0; i < GroupedPieces.GetSize(); i++)
+ {
+ PieceInfo* Info = GroupedPieces[i];
+ m_PiecesTree.InsertItem(TVIF_CHILDREN|TVIF_PARAM|TVIF_TEXT, Info->m_strDescription, 0, 0, 0, 0, (LPARAM)Info, CategoryItem, TVI_SORT);
+ }
+
+ if (CategoryName == "Search Results")
+ {
+ // Let the user know if the search is empty.
+ if ((SinglePieces.GetSize() == 0) && (GroupedPieces.GetSize() == 0))
+ {
+ m_PiecesTree.InsertItem(TVIF_PARAM|TVIF_TEXT, "No pieces found", 0, 0, 0, 0, 0, CategoryItem, TVI_SORT);
+ }
+ }
+ }
+ }
+ else
+ {
+ PieceInfo* Parent = (PieceInfo*)Notify->itemNew.lParam;
+
+ PtrArray<PieceInfo> Pieces;
+ Lib->GetPatternedPieces(Parent, Pieces);
+
+ HTREEITEM ParentItem = Notify->itemNew.hItem;
+
+ for (int i = 0; i < Pieces.GetSize(); i++)
+ {
+ PieceInfo* Info = Pieces[i];
+ m_PiecesTree.InsertItem(TVIF_PARAM|TVIF_TEXT, Info->m_strDescription + strlen(Parent->m_strDescription) + 1, 0, 0, 0, 0, (LPARAM)Info, ParentItem, TVI_SORT);
+ }
+ }
+ }
+ else if (Notify->action == TVE_COLLAPSE)
+ {
+ // Remove all children.
+ m_PiecesTree.Expand(Notify->itemNew.hItem, TVE_COLLAPSE | TVE_COLLAPSERESET);
+ }
+ }
+ }
+
+ return CControlBar::OnNotify(wParam, lParam, pResult);
+}
diff --git a/win/Piecebar.h b/win/Piecebar.h
index 3da370d..c3a0b77 100644
--- a/win/Piecebar.h
+++ b/win/Piecebar.h
@@ -22,58 +22,59 @@
class CPiecesBar : public CControlBar
{
public:
- CPiecesBar();
+ CPiecesBar();
// Attributes
public:
- CSize m_sizeHorz;
- CSize m_sizeVert;
- CSize m_sizeFloat;
- BOOL IsHorzDocked() const;
- BOOL IsVertDocked() const;
+ CSize m_sizeHorz;
+ CSize m_sizeVert;
+ CSize m_sizeFloat;
+ BOOL IsHorzDocked() const;
+ BOOL IsVertDocked() const;
// Operations
public:
// Overrides
public:
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CPiecesBar)
- public:
- virtual BOOL Create(LPCTSTR lpszWindowName, CWnd* pParentWnd, CSize sizeDefault, BOOL bHasGripper, UINT nID, DWORD dwStyle = WS_CHILD | WS_VISIBLE | CBRS_TOP);
- virtual CSize CalcFixedLayout(BOOL bStretch, BOOL bHorz);
- virtual CSize CalcDynamicLayout(int nLength, DWORD dwMode);
+ // ClassWizard generated virtual function overrides
+ //{{AFX_VIRTUAL(CPiecesBar)
+public:
+ virtual BOOL Create(LPCTSTR lpszWindowName, CWnd* pParentWnd, CSize sizeDefault, BOOL bHasGripper, UINT nID, DWORD dwStyle = WS_CHILD | WS_VISIBLE | CBRS_TOP);
+ virtual CSize CalcFixedLayout(BOOL bStretch, BOOL bHorz);
+ virtual CSize CalcDynamicLayout(int nLength, DWORD dwMode);
+ virtual BOOL OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult);
//}}AFX_VIRTUAL
// Implementation
public:
- virtual ~CPiecesBar();
-
+ virtual ~CPiecesBar();
+
protected:
- // implementation helpers
- void StartTracking();
- void StopTracking(BOOL bAccept);
+ // implementation helpers
+ void StartTracking();
+ void StopTracking(BOOL bAccept);
void OnTrackUpdateSize(CPoint& point);
- void OnTrackInvertTracker();
+ void OnTrackInvertTracker();
virtual CSize CalcMaxSize();
virtual BOOL QueryDragFullWindows() const;
protected:
// used for resizing
- CSize m_sizeMin;
- CSize m_sizeMax;
+ CSize m_sizeMin;
+ CSize m_sizeMax;
CPoint m_ptOld;
- CRect m_rectBorder;
- BOOL m_bTracking;
+ CRect m_rectBorder;
+ BOOL m_bTracking;
BOOL m_bDragShowContent;
CSize m_sizeOld;
- BOOL m_bInRecalcNC;
- UINT m_nDockBarID;
- int m_cxEdge;
- BOOL m_bHasGripper;
- int m_cyGripper;
- CRect m_rectGripper;
+ BOOL m_bInRecalcNC;
+ UINT m_nDockBarID;
+ int m_cxEdge;
+ BOOL m_bHasGripper;
+ int m_cyGripper;
+ CRect m_rectGripper;
public:
void CreateGroupsBar();
@@ -89,9 +90,13 @@ public:
CTransToolBar m_wndGroupsBar;
CySplitterWnd m_wndSplitter;
+ CTreeCtrl m_PiecesTree;
+
char m_GroupNames[32][33];
int m_nCurGroup;
+ void UpdatePiecesTree(bool SearchOnly);
+
// Generated message map functions
protected:
BOOL m_bNoContext;
@@ -99,20 +104,20 @@ protected:
int m_nPreviewHeight;
void OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler);
void OnSelChangeColor();
- //{{AFX_MSG(CPiecesBar)
- afx_msg void OnPaint();
- afx_msg void OnNcPaint();
- afx_msg void OnWindowPosChanged(WINDOWPOS FAR* lpwndpos);
- afx_msg void OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp);
- afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
- afx_msg void OnMouseMove(UINT nFlags, CPoint point);
- afx_msg void OnNcLButtonDown(UINT nHitTest, CPoint point);
- afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
- afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
+ //{{AFX_MSG(CPiecesBar)
+ afx_msg void OnPaint();
+ afx_msg void OnNcPaint();
+ afx_msg void OnWindowPosChanged(WINDOWPOS FAR* lpwndpos);
+ afx_msg void OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp);
+ afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
+ afx_msg void OnMouseMove(UINT nFlags, CPoint point);
+ afx_msg void OnNcLButtonDown(UINT nHitTest, CPoint point);
+ afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
+ afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
- afx_msg void OnCaptureChanged(CWnd *pWnd);
- afx_msg UINT OnNcHitTest(CPoint point);
- afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
+ afx_msg void OnCaptureChanged(CWnd *pWnd);
+ afx_msg UINT OnNcHitTest(CPoint point);
+ afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
@@ -122,7 +127,7 @@ protected:
afx_msg LONG OnSplitterMoved(UINT lParam, LONG wParam);
void OnPieceGroupClicked(UINT nID);
- DECLARE_MESSAGE_MAP()
+ DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////
diff --git a/win/Piececmb.cpp b/win/Piececmb.cpp
index 3e02b7e..0bb3b31 100644
--- a/win/Piececmb.cpp
+++ b/win/Piececmb.cpp
@@ -125,9 +125,26 @@ BOOL CPiecesCombo::PreTranslateMessage(MSG* pMsg)
int nVirtKey = (int) pMsg->wParam;
if (nVirtKey == VK_DELETE || nVirtKey == VK_BACK)
{
-// if enter pressed, add piece (postmessage to mainwnd)
m_bAutoComplete = FALSE;
}
+ else if (nVirtKey == VK_RETURN)
+ {
+ PiecesLibrary* Lib = project->GetPiecesLibrary();
+ CString str;
+
+ GetWindowText(str);
+
+ int Index = Lib->FindCategoryIndex("Search Results");
+
+ if (Index == -1)
+ {
+ Lib->AddCategory("Search Results", (const char*)str);
+ }
+ else
+ {
+ Lib->SetCategory(Index, "Search Results", (const char*)str);
+ }
+ }
}
return CComboBox::PreTranslateMessage(pMsg);
diff --git a/win/Piecelst.cpp b/win/Piecelst.cpp
index a4f14bb..9586529 100644
--- a/win/Piecelst.cpp
+++ b/win/Piecelst.cpp
@@ -48,6 +48,7 @@ CPiecesList::CPiecesList()
CPiecesList::~CPiecesList()
{
+ ClearGroups();
// TODO: save m_nLastPieces to registry
}
@@ -160,49 +161,227 @@ void CPiecesList::OnItemchanged(NMHDR* pNMHDR, LRESULT* pResult)
*pResult = 0;
}
-void CPiecesList::UpdateList()
+void CPiecesList::ClearGroups()
+{
+ for (int i = 0; i < m_Groups.GetSize(); i++)
+ delete m_Groups[i];
+
+ m_Groups.RemoveAll();
+ m_Pieces.RemoveAll();
+}
+
+void CPiecesList::UpdateGroups()
+{
+ CPiecesBar* Bar = (CPiecesBar*)GetParent();
+ PiecesLibrary *Lib = project->GetPiecesLibrary();
+ int i, j;
+
+ ClearGroups();
+
+ for (i = 0; i < Lib->GetPieceCount(); i++)
+ {
+ PieceInfo* Info = Lib->GetPieceInfo(i);
+
+ // Skip subparts if the user doesn't want to see them.
+ if ((Info->m_strDescription[0] == '~') && !Bar->m_bSubParts)
+ continue;
+
+ // Skip pieces not in the current category.
+ if (Bar->m_bGroups && ((Info->m_nGroups & (DWORD)(1 << Bar->m_nCurGroup)) == 0))
+ continue;
+
+ // There's nothing else to check if we're not grouping patterned pieces together.
+ if (!m_GroupPatterns)
+ {
+ m_Pieces.Add(Info);
+ continue;
+ }
+
+ // Check if it's a patterned piece.
+ const char* Name = Info->m_strName;
+ while (*Name)
+ {
+ if (!*Name || *Name < '0' || *Name > '9')
+ break;
+
+ if (*Name == 'P')
+ break;
+
+ Name++;
+ }
+
+ if (*Name == 'P')
+ {
+ PieceListGroup* Group = NULL;
+ PieceInfo* Parent;
+
+ char ParentName[9];
+ strcpy(ParentName, Info->m_strName);
+ ParentName[Name - Info->m_strName] = '\0';
+
+ Parent = Lib->FindPieceInfo(ParentName);
+
+ if (Parent)
+ {
+ // Search for the parent's group.
+ for (j = 0; j < m_Groups.GetSize(); j++)
+ {
+ if (m_Groups[j]->Parent == Parent)
+ {
+ Group = m_Groups[j];
+ break;
+ }
+ }
+
+ // Check if the parent wasn't added as a single piece.
+ if (!Group)
+ {
+ for (j = 0; j < m_Pieces.GetSize(); j++)
+ {
+ if (m_Pieces[j] == Parent)
+ {
+ m_Pieces.RemoveIndex(j);
+
+ Group = new PieceListGroup();
+ Group->Parent = Parent;
+ Group->Collapsed = true;
+ m_Groups.Add(Group);
+
+ break;
+ }
+ }
+ }
+
+ // Create a new group for the parent.
+ if (!Group)
+ {
+ Group = new PieceListGroup();
+ Group->Parent = Parent;
+ Group->Collapsed = true;
+ m_Groups.Add(Group);
+ }
+
+ Group->Children.Add(Info);
+ }
+ else
+ {
+ m_Pieces.Add(Info);
+ }
+ }
+ else
+ {
+ bool Found = false;
+
+ // Add piece to the list if it's not there already,
+ // this could be the parent whose child was added earlier.
+ for (j = 0; j < m_Groups.GetSize(); j++)
+ {
+ if (m_Groups[j]->Parent == Info)
+ {
+ Found = true;
+ break;
+ }
+ }
+
+ if (!Found)
+ {
+ m_Pieces.Add(Info);
+ }
+ }
+ }
+}
+
+void CPiecesList::AddPiece(PieceInfo* Info, int ImageIndex)
+{
+ LV_ITEM lvi;
+
+ if (ImageIndex == -1)
+ lvi.mask = LVIF_TEXT | LVIF_PARAM;
+ else
+ lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE;
+
+ TCHAR tmp[65], tmp2[10];
+ strcpy(tmp, Info->m_strDescription);
+ lvi.iImage = ImageIndex;
+ lvi.iItem = 0;
+ lvi.iSubItem = 0;
+ lvi.pszText = tmp;
+ lvi.lParam = (LPARAM)Info;
+ int idx = InsertItem(&lvi);
+
+ strcpy(tmp2, Info->m_strName);
+ SetItemText(idx, 1, tmp2);
+}
+
+void CPiecesList::UpdateList(bool Repopulate)
{
CWaitCursor wc;
- CPiecesBar* pBar = (CPiecesBar*)GetParent();
- PiecesLibrary *pLib = project->GetPiecesLibrary ();
+ int i;
+
+ if (Repopulate)
+ UpdateGroups();
- SetRedraw (FALSE);
+ SetRedraw(FALSE);
DeleteAllItems();
- LV_ITEM lvi;
- lvi.mask = LVIF_TEXT | LVIF_PARAM;
+/*
+ PiecesLibrary *pLib = project->GetPiecesLibrary();
for (int i = 0; i < pLib->GetPieceCount(); i++)
{
PieceInfo* pInfo = pLib->GetPieceInfo(i);
+ // Skip subparts if the user doesn't want to see them.
if ((pInfo->m_strDescription[0] == '~') && !pBar->m_bSubParts)
continue;
- if ((!pBar->m_bGroups) ||
- ((pInfo->m_nGroups & (DWORD)(1 << pBar->m_nCurGroup)) != 0))
+ // Skip pieces not in the current category.
+ if (pBar->m_bGroups && ((pInfo->m_nGroups & (DWORD)(1 << pBar->m_nCurGroup)) == 0))
+ continue;
+
+ TCHAR tmp[65], tmp2[10];
+ strcpy(tmp, pInfo->m_strDescription);
+ lvi.iItem = 0;
+ lvi.iSubItem = 0;
+ lvi.pszText = tmp;
+ lvi.lParam = (LPARAM)pInfo;
+ lvi.iImage = 1;
+ int idx = InsertItem(&lvi);
+
+ strcpy(tmp2, pInfo->m_strName);
+ SetItemText(idx, 1, tmp2);
+ }
+*/
+
+ for (i = 0; i < m_Groups.GetSize(); i++)
+ {
+ PieceListGroup* Group = m_Groups[i];
+
+ AddPiece(Group->Parent, (Group->Collapsed) ? 0 : 1);
+
+ if (!Group->Collapsed)
{
- TCHAR tmp[65], tmp2[10];
- strcpy (tmp, pInfo->m_strDescription);
- lvi.iItem = 0;
- lvi.iSubItem = 0;
- lvi.pszText = tmp;
- lvi.lParam = (LPARAM)pInfo;
- int idx = InsertItem(&lvi);
-
- strcpy (tmp2, pInfo->m_strName);
- SetItemText(idx, 1, tmp2);
+ for (int j = 0; j < Group->Children.GetSize(); j++)
+ {
+ AddPiece(Group->Children[j], 3);
+ }
}
}
+ for (i = 0; i < m_Pieces.GetSize(); i++)
+ {
+ AddPiece(m_Pieces[i], 3);
+ }
+
if (m_bAscending)
SortItems((PFNLVCOMPARE)ListViewCompareProc, m_nSortedCol);
else
SortItems((PFNLVCOMPARE)ListViewCompareProc, m_nSortedCol|0xF0);
+ CPiecesBar* pBar = (CPiecesBar*)GetParent();
EnsureVisible(m_nLastPieces[pBar->m_nCurGroup], FALSE);
- SetItemState (m_nLastPieces[pBar->m_nCurGroup], LVIS_SELECTED | LVIS_FOCUSED , LVIS_SELECTED | LVIS_FOCUSED);
- SetRedraw (TRUE);
+ SetItemState(m_nLastPieces[pBar->m_nCurGroup], LVIS_SELECTED | LVIS_FOCUSED , LVIS_SELECTED | LVIS_FOCUSED);
+ SetRedraw(TRUE);
Invalidate();
}
@@ -289,6 +468,9 @@ int CPiecesList::OnCreate(LPCREATESTRUCT lpCreateStruct)
if (CListCtrl::OnCreate(lpCreateStruct) == -1)
return -1;
+ m_Images.Create(IDB_PARTICONS, 16, 0, RGB (0,128,128));
+ SetImageList(&m_Images, LVSIL_SMALL);
+
m_TitleTip.Create(this);
return 0;
@@ -304,6 +486,36 @@ void CPiecesList::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
CView* pView = pFrame->GetActiveView();
pView->SetFocus();
}
+ else if (nChar == VK_RIGHT)
+ {
+ int Index = GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
+ PieceInfo* Info = (PieceInfo*)GetItemData(Index);
+
+ for (int i = 0; i < m_Groups.GetSize(); i++)
+ {
+ PieceListGroup* Group = m_Groups[i];
+
+ if (Group->Parent == Info)
+ Group->Collapsed = false;
+ }
+
+ UpdateList(false);
+ }
+ else if (nChar == VK_LEFT)
+ {
+ int Index = GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
+ PieceInfo* Info = (PieceInfo*)GetItemData(Index);
+
+ for (int i = 0; i < m_Groups.GetSize(); i++)
+ {
+ PieceListGroup* Group = m_Groups[i];
+
+ if (Group->Parent == Info)
+ Group->Collapsed = true;
+ }
+
+ UpdateList(false);
+ }
else
CListCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
}
diff --git a/win/Piecelst.h b/win/Piecelst.h
index e756dcc..180986d 100644
--- a/win/Piecelst.h
+++ b/win/Piecelst.h
@@ -9,10 +9,13 @@
#include "TitleTip.h"
#include "SortHead.h"
+#include "array.h"
/////////////////////////////////////////////////////////////////////////////
// CPiecesList window
+class PieceInfo;
+
class CPiecesList : public CListCtrl
{
// Construction
@@ -33,9 +36,11 @@ public:
// Implementation
public:
- void UpdateList();
virtual ~CPiecesList();
+ void ChangeGroup();
+ void UpdateList(bool Repopulate = true);
+
// Generated message map functions
protected:
UINT m_nLastPieces[32];
@@ -47,6 +52,24 @@ protected:
CTitleTip m_TitleTip;
CSortHeaderCtrl m_HeaderCtrl;
+ void AddPiece(PieceInfo* Info, int ImageIndex);
+
+ // Variables for grouping patterned pieces together.
+ typedef struct
+ {
+ PieceInfo* Parent;
+ PtrArray<PieceInfo> Children;
+ bool Collapsed;
+ } PieceListGroup;
+
+ CImageList m_Images;
+ bool m_GroupPatterns;
+ PtrArray<PieceListGroup> m_Groups;
+ PtrArray<PieceInfo> m_Pieces;
+
+ void UpdateGroups();
+ void ClearGroups();
+
//{{AFX_MSG(CPiecesList)
afx_msg void OnColumnclick(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnItemchanged(NMHDR* pNMHDR, LRESULT* pResult);
diff --git a/win/System.cpp b/win/System.cpp
index acaba02..c581e83 100644
--- a/win/System.cpp
+++ b/win/System.cpp
@@ -798,6 +798,13 @@ void SystemUpdateCameraMenu(Camera* pCamera)
((CMainFrame*)AfxGetMainWnd())->UpdateMenuAccelerators();
}
+void SystemUpdateCategories(bool SearchOnly)
+{
+ CFrameWnd* pFrame = (CFrameWnd*)AfxGetMainWnd();
+ CPiecesBar* pBar = (CPiecesBar*)pFrame->GetControlBar(ID_VIEW_PIECES_BAR);
+ pBar->UpdatePiecesTree(SearchOnly);
+}
+
extern UINT AFXAPI AfxGetFileTitle(LPCTSTR lpszPathName, LPTSTR lpszTitle, UINT nMax);
extern UINT AFXAPI AfxGetFileName(LPCTSTR lpszPathName, LPTSTR lpszTitle, UINT nMax);
diff --git a/win/res/particon.bmp b/win/res/particon.bmp
index 9d947b0..2f65b1f 100644
--- a/win/res/particon.bmp
+++ b/win/res/particon.bmp
Binary files differ
diff --git a/win/resource.h b/win/resource.h
index 9b2bff2..b5cd772 100644
--- a/win/resource.h
+++ b/win/resource.h
@@ -21,6 +21,7 @@
#define IDW_PIECESCOMBO 108
#define IDW_COLORSLIST 109
#define IDW_PIECEBAR_SPLITTER 110
+#define IDW_PIECESTREE 111
#define IDS_CANNOT_OPEN_CLIPBOARD 111
#define IDS_CANNOT_GET_CLIPBOARD_DATA 112
#define IDS_CANCEL_PROMPT 113
@@ -135,6 +136,7 @@
#define IDD_EDIT_GROUPS 231
#define IDD_LIBRARY_TEXTURES 234
#define IDD_PREFKEYBOARD 235
+#define IDD_TRANSFORM 236
#define IDC_SELDLG_LIST 1000
#define IDC_SELDLG_ALL 1001
#define IDC_SELDLG_NONE 1002
@@ -380,14 +382,18 @@
#define IDC_EDIT1 1210
#define IDC_MF_HANDR 1211
#define IDC_TEROPT_FLAT 1211
+#define IDC_TRANSDLG_GY 1211
#define IDC_MF_TOOLL 1212
#define IDC_EDIT2 1212
#define IDC_SCNDLG_SOLID 1212
+#define IDC_TRANSDLG_GZ 1212
#define IDC_MF_TOOLR 1213
#define IDC_SCNDLG_GRADIENT 1213
+#define IDC_TRANSDLG_OY 1213
#define IDC_MF_HIPS 1214
#define IDC_SCNDLG_IMAGE 1214
#define IDC_TREE 1214
+#define IDC_TRANSDLG_OZ 1214
#define IDC_MF_LEGL 1215
#define IDC_MODDLG_PLANESSTATIC 1215
#define IDC_MF_LEGR 1216
@@ -436,6 +442,8 @@
#define IDC_MF_SHOELSPIN 1244
#define IDC_GENDLG_UPDATES 1244
#define IDC_MF_SHOERSPIN 1245
+#define IDC_TRANSDLG_GX 1245
+#define IDC_TRANSDLG_OX 1246
#define ID_EDIT_SELECTALL 32772
#define ID_EDIT_SELECTNONE 32773
#define ID_EDIT_SELECTINVERT 32774
@@ -669,9 +677,9 @@
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_3D_CONTROLS 1
-#define _APS_NEXT_RESOURCE_VALUE 235
+#define _APS_NEXT_RESOURCE_VALUE 237
#define _APS_NEXT_COMMAND_VALUE 33158
-#define _APS_NEXT_CONTROL_VALUE 1245
+#define _APS_NEXT_CONTROL_VALUE 1246
#define _APS_NEXT_SYMED_VALUE 121
#endif
#endif
diff --git a/win/transdlg.cpp b/win/transdlg.cpp
new file mode 100644
index 0000000..fb7cb18
--- /dev/null
+++ b/win/transdlg.cpp
@@ -0,0 +1,53 @@
+// transdlg.cpp : implementation file
+//
+
+#include "stdafx.h"
+#include "leocad.h"
+#include "transdlg.h"
+
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#undef THIS_FILE
+static char THIS_FILE[] = __FILE__;
+#endif
+
+/////////////////////////////////////////////////////////////////////////////
+// CTransformDlg dialog
+
+
+CTransformDlg::CTransformDlg(CWnd* pParent /*=NULL*/)
+ : CDialog(CTransformDlg::IDD, pParent)
+{
+ //{{AFX_DATA_INIT(CTransformDlg)
+ m_GlobalX = 0.0f;
+ m_GlobalY = 0.0f;
+ m_GlobalZ = 0.0f;
+ m_OffsetX = 0.0f;
+ m_OffsetY = 0.0f;
+ m_OffsetZ = 0.0f;
+ //}}AFX_DATA_INIT
+}
+
+
+void CTransformDlg::DoDataExchange(CDataExchange* pDX)
+{
+ CDialog::DoDataExchange(pDX);
+ //{{AFX_DATA_MAP(CTransformDlg)
+ DDX_Text(pDX, IDC_TRANSDLG_GX, m_GlobalX);
+ DDX_Text(pDX, IDC_TRANSDLG_GY, m_GlobalY);
+ DDX_Text(pDX, IDC_TRANSDLG_GZ, m_GlobalZ);
+ DDX_Text(pDX, IDC_TRANSDLG_OX, m_OffsetX);
+ DDX_Text(pDX, IDC_TRANSDLG_OY, m_OffsetY);
+ DDX_Text(pDX, IDC_TRANSDLG_OZ, m_OffsetZ);
+ //}}AFX_DATA_MAP
+}
+
+
+BEGIN_MESSAGE_MAP(CTransformDlg, CDialog)
+ //{{AFX_MSG_MAP(CTransformDlg)
+ // NOTE: the ClassWizard will add message map macros here
+ //}}AFX_MSG_MAP
+END_MESSAGE_MAP()
+
+/////////////////////////////////////////////////////////////////////////////
+// CTransformDlg message handlers
diff --git a/win/transdlg.h b/win/transdlg.h
new file mode 100644
index 0000000..b536e16
--- /dev/null
+++ b/win/transdlg.h
@@ -0,0 +1,51 @@
+#if !defined(AFX_TRANSDLG_H__FF6D1B48_BEEA_4A5F_9A00_48FD3ABE72C4__INCLUDED_)
+#define AFX_TRANSDLG_H__FF6D1B48_BEEA_4A5F_9A00_48FD3ABE72C4__INCLUDED_
+
+#if _MSC_VER > 1000
+#pragma once
+#endif // _MSC_VER > 1000
+// transdlg.h : header file
+//
+
+/////////////////////////////////////////////////////////////////////////////
+// CTransformDlg dialog
+
+class CTransformDlg : public CDialog
+{
+// Construction
+public:
+ CTransformDlg(CWnd* pParent = NULL); // standard constructor
+
+// Dialog Data
+ //{{AFX_DATA(CTransformDlg)
+ enum { IDD = IDD_TRANSFORM };
+ float m_GlobalX;
+ float m_GlobalY;
+ float m_GlobalZ;
+ float m_OffsetX;
+ float m_OffsetY;
+ float m_OffsetZ;
+ //}}AFX_DATA
+
+
+// Overrides
+ // ClassWizard generated virtual function overrides
+ //{{AFX_VIRTUAL(CTransformDlg)
+ protected:
+ virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
+ //}}AFX_VIRTUAL
+
+// Implementation
+protected:
+
+ // Generated message map functions
+ //{{AFX_MSG(CTransformDlg)
+ // NOTE: the ClassWizard will add member functions here
+ //}}AFX_MSG
+ DECLARE_MESSAGE_MAP()
+};
+
+//{{AFX_INSERT_LOCATION}}
+// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
+
+#endif // !defined(AFX_TRANSDLG_H__FF6D1B48_BEEA_4A5F_9A00_48FD3ABE72C4__INCLUDED_)