[Date Prev][Date Next][Thread Prev][Thread Next][Thread Index]

[XaraXtreme-commits] Commit Complete



Commit by  : alex
Repository : xara
Revision   : 1243
Date       : Sun Jun  4 20:41:41 BST 2006

Changed paths:
   M /Trunk/XaraLX/Kernel/coldlog.cpp
   M /Trunk/XaraLX/Kernel/coldlog.h
   M /Trunk/XaraLX/wxOil/colpick.cpp
   M /Trunk/XaraLX/wxOil/colpick.h
   M /Trunk/XaraLX/wxOil/dlgmgr.cpp
   M /Trunk/XaraLX/wxOil/dlgtypes.h
   M /Trunk/XaraLX/wxOil/drawctl.cpp
   M /Trunk/XaraLX/wxOil/drawctl.h
   M /Trunk/XaraLX/wxOil/xrc/EN/colordlg.xrc

First hack at colour editor sizing code


Diff:
Index: Trunk/XaraLX/Kernel/coldlog.h
===================================================================
--- Trunk/XaraLX/Kernel/coldlog.h	(revision 1242)
+++ Trunk/XaraLX/Kernel/coldlog.h	(revision 1243)
@@ -559,6 +559,8 @@
 	BOOL m_NeedsResize;
 	void NeedsResize() {m_NeedsResize = TRUE;}
 
+	virtual BOOL OnIdleEvent();
+
 private:
 	void LoseKeyboardFocus(void);
 		// Lobs the keyboard focus back into the document
Index: Trunk/XaraLX/Kernel/coldlog.cpp
===================================================================
--- Trunk/XaraLX/Kernel/coldlog.cpp	(revision 1242)
+++ Trunk/XaraLX/Kernel/coldlog.cpp	(revision 1243)
@@ -669,6 +669,7 @@
 
 	m_bDoingSetGadget = FALSE;
 	m_NeedsResize = FALSE;
+	GetApplication()->RegisterIdleProcessor(IDLEPRIORITY_LOW, this);
 }
 
 
@@ -690,6 +691,7 @@
 
 ColourEditDlg::~ColourEditDlg()
 {
+	GetApplication()->RemoveIdleProcessor(IDLEPRIORITY_LOW, this);
 	EndTimedProcessing();
 
 	if (EditingColour != NULL)
@@ -1098,6 +1100,25 @@
 	}
 }
 
+/*****************************************************************************
+>	BOOL ColourEditDlg::OnIdleEvent()
+
+	Author:		Alex Bligh
+	Created:	30/5/2005
+	Purpose:	Idle event handler for the colour dialog
+				
+	Returns:	FALSE (to indicate we want no more idle events)
+				The wakeup from the timer will create one for us
+	Errors:		-
+
+
+*****************************************************************************/
+
+BOOL ColourEditDlg::OnIdleEvent()
+{
+	return ColourPicker::OnIdleEvent(WindowID);
+}
+
 /********************************************************************************************
 
 >	void ColourEditDlg::HideOrShowColourPicker()
@@ -3084,6 +3105,7 @@
 			break;
 
 		case DIM_CREATE:
+			ColourPicker::OnCreate(WindowID);
 			SetGadgetBitmaps(_R(IDC_EDIT_DROPMENU), 0, 0);
 			#ifndef WEBSTER
 			SetGadgetBitmaps(_R(IDC_EDIT_MAKESTYLE), 0, 0);
@@ -3109,6 +3131,8 @@
 			SetUnitGroupDefaults(DisplayModel);	// and defaults are set
 			SetControls();				// ...and update them
 
+			ColourPicker::RelayoutDialog(WindowID);
+
 			// And then lob away the input focus again - put it back into the mainframe
 			LockLoseFocus = FALSE;		// Ensure the focus lock is reset to off whenever we open
 			LoseFocusFromEditControls = FALSE;
@@ -3157,8 +3181,13 @@
 		}
  		return(OK);					// ... making sure the base class handler is NOT called (it blows up)
 
+		case DIM_CTRL_RESIZED:
+		{
+			if (Msg->GadgetID == _R(IDC_EDIT_PICKER))
+				ColourPicker::OnSize(WindowID);
+		}
+		break;
 
-
 		case DIM_REDRAW:				// Kernel-redraw of colour patch or picker controls
 		{
 			RenderControl(Msg->GadgetID, (ReDrawInfoType*) Msg->DlgMsgParam);
Index: Trunk/XaraLX/wxOil/drawctl.h
===================================================================
--- Trunk/XaraLX/wxOil/drawctl.h	(revision 1242)
+++ Trunk/XaraLX/wxOil/drawctl.h	(revision 1243)
@@ -172,6 +172,7 @@
 	void Init() {
 					m_CamDrawControlStyle=wxCDCS_DEFAULT;
 					m_OpDesc=wxString(_T(""));
+					m_Frozen=0;
 				}
 
 	// Constructors
@@ -189,9 +190,13 @@
 
 	// EventHandlers
 	void OnPaint(wxPaintEvent & event);
+	void OnSize(wxSizeEvent & event);
 	void OnMouseEvent(wxMouseEvent & event);
 	void OnInvoke(wxCamDrawControlEvent& event);
 
+	virtual void Freeze() {m_Frozen++;}
+	virtual void Thaw() {if (m_Frozen) m_Frozen--;}
+
 	virtual void SetStyle(wxCamDrawControlStyle style) { m_CamDrawControlStyle=style; }
 	virtual wxCamDrawControlStyle GetStyle() { return m_CamDrawControlStyle;}
 
@@ -202,6 +207,8 @@
 
 	wxString m_OpDesc;
 
+	INT32 m_Frozen;
+
 	void Invoke();
 
 };
Index: Trunk/XaraLX/wxOil/colpick.h
===================================================================
--- Trunk/XaraLX/wxOil/colpick.h	(revision 1242)
+++ Trunk/XaraLX/wxOil/colpick.h	(revision 1243)
@@ -251,7 +251,20 @@
 													INT32 EditWidth[]);
 
 	static void RelayoutDialog(CWindowID WindowID);
+	static void OnSize(CWindowID WindowID);
+	static void RecursiveBestSize(wxWindow * pwxWindow);
+	static BOOL OnIdleEvent(CWindowID WindowID);
+	static void OnCreate(CWindowID WindowID);
+	static void ArtificialSizeEvents(CWindowID WindowID);
 
+private:
+	static wxSize s_LastSize;
+	static wxSize s_UserSize;
+	static wxSize s_MinSize;
+	static BOOL s_InColourDialogLayout;
+	static BOOL s_JustCreated;
+	static INT32 s_IdleCounter;
+
 };
 
 
Index: Trunk/XaraLX/wxOil/colpick.cpp
===================================================================
--- Trunk/XaraLX/wxOil/colpick.cpp	(revision 1242)
+++ Trunk/XaraLX/wxOil/colpick.cpp	(revision 1243)
@@ -118,8 +118,13 @@
 //#include "richard3.h"
 //#include "ed.h"
 
+wxSize ColourPicker::s_LastSize = wxDefaultSize;
+wxSize ColourPicker::s_UserSize = wxSize(245,245);
+wxSize ColourPicker::s_MinSize = wxSize(180,100);
+BOOL ColourPicker::s_InColourDialogLayout = FALSE;
+BOOL ColourPicker::s_JustCreated = FALSE;
+INT32 ColourPicker::s_IdleCounter = 0;
 
-
 CC_IMPLEMENT_MEMDUMP(ColourPicker, CCObject)
 
 #define new CAM_DEBUG_NEW
@@ -2844,6 +2849,56 @@
 
 /********************************************************************************************
 
+>	static void ColourPicker::RecursiveBestSize(wxWindow * pwxWindow)
+
+
+	Author:		Alex_Bligh <alex@xxxxxxxxxxx>
+	Created:	02/12/2005
+	Inputs:		pWindow - pointer to window to process
+	Outputs:	None
+	Returns:	None
+	Purpose:	Initialize platform dependent resources
+	Errors:		-
+	SeeAlso:	-
+
+********************************************************************************************/
+
+void ColourPicker::RecursiveBestSize(wxWindow * pwxWindow)
+{
+	if (pwxWindow->IsShown())
+	{
+		// Now process children if any
+		wxWindowList::Node * pNode = pwxWindow->GetChildren().GetFirst();
+		while (pNode)
+		{
+			RecursiveBestSize(pNode->GetData());
+			pNode = pNode->GetNext();
+		}
+	}
+
+	pwxWindow->InvalidateBestSize();
+
+	wxSizer * s=pwxWindow->GetSizer();
+
+	// Shrink this window around any sizer it contains
+	pwxWindow->Layout();
+	pwxWindow->Fit();
+	if (s)
+		s->SetSizeHints(pwxWindow);
+
+	if (pwxWindow->IsShown())
+		if ((s_UserSize != wxDefaultSize) && ((ResourceID)(pwxWindow->GetId()) == _R(IDC_EDIT_PICKER)))
+			pwxWindow->SetSize(s_UserSize);
+		else
+			pwxWindow->SetSize(pwxWindow->GetMinSize());
+	else
+		pwxWindow->SetSize(wxSize(1,1));
+
+	return;
+}
+
+/********************************************************************************************
+
 >	void ColourPicker::RelayoutDialog(CWindowID WindowID)
 
 	Author:		Alex Bligh
@@ -2856,22 +2911,205 @@
 
 void ColourPicker::RelayoutDialog(CWindowID WindowID)
 {
-	CWindowID pPanel=DialogManager::GetGadget(WindowID, _R(IDC_EDIT_ADVANCEDPANEL));
-	if (pPanel)
+	static INT32 flag=0;
+
+	if (s_InColourDialogLayout)
 	{
-		pPanel->Layout();
-		pPanel->Fit();
-		pPanel->GetSizer()->SetSizeHints(pPanel);
+		TRACEUSER("amb", _T("Recursive colour dialog layout"));
+		return; // this should not happen
+	}
 
-		static INT32 flag=0;
-		if (!flag)
+	s_InColourDialogLayout = TRUE;
+
+	wxWindow * pPicker=DialogManager::GetGadget(WindowID, _R(IDC_EDIT_PICKER));
+	if (pPicker)
+		pPicker->Freeze();
+	WindowID->Freeze();
+
+	if (pPicker && (s_UserSize != wxDefaultSize))
+	{
+		// Ensure no amount of sizing uses a different size for the picker to the one we want
+		pPicker->SetSize(pPicker->GetSize().GetWidth()+1, pPicker->GetSize().GetHeight()+1); // cause a resize
+		WindowID->Layout();
+		WindowID->Fit();
+		WindowID->GetSizer()->SetSizeHints(WindowID);
+		pPicker->SetMinSize(s_UserSize);
+		pPicker->SetMaxSize(s_UserSize);
+		pPicker->SetSize(s_UserSize);
+	}
+
+	RecursiveBestSize(WindowID);
+
+	ArtificialSizeEvents(WindowID);
+	if (!flag)
+	{
+		flag++;
+		::wxYield();
+		flag--;
+	}
+
+	// And now do it again with the minimum size for the colour picker restored so the dialog
+	// can shrink
+
+	if (pPicker && (s_UserSize != wxDefaultSize))
+	{
+		// If s_JustCreated is set, use s_UserSize
+		pPicker->SetMinSize((s_JustCreated && (s_UserSize != wxDefaultSize))?s_UserSize:s_MinSize);
+		pPicker->SetMaxSize(wxDefaultSize);
+	}
+
+	RecursiveBestSize(WindowID);
+
+	ArtificialSizeEvents(WindowID);
+	if (!flag)
+	{
+		flag++;
+		::wxYield();
+		flag--;
+	}
+
+	WindowID->Thaw();
+	if (pPicker)
+	{
+		pPicker->Thaw();
+		pPicker->Refresh();
+	}
+
+	// Now, even having done the above, believe it or not some of the GTK sizing code seems
+	// to run off idles. So we have to ignore some OnSize events because the idle events
+	// may not be out the system yet. Sigh... Why can't GTK resize sychronously?
+
+	s_IdleCounter = 3; // 3 more idle counts before we use an OnSize (somewhat arbitrary)
+	GetApplication()->NeedMoreIdles(); // wake up idle system
+	s_InColourDialogLayout = FALSE;
+}
+
+/********************************************************************************************
+
+>	void ColourPicker::ArtificialSizeEvents(CWindowID WindowID)
+
+	Author:		Alex Bligh
+	Created:	30/5/2005
+	Inputs:		-
+	Purpose:	Produce artificial size events recursively
+	Scope:		Protected
+
+On GTK at least, sizing does not occur synchronously. Some of it happens on size
+events from a gtk_window_size_callback. For various reasons (like the necessity
+for a wxyield) this is not great). So we produce them ourselves.
+
+********************************************************************************************/
+
+void ColourPicker::ArtificialSizeEvents(CWindowID WindowID)
+{
+	if (!WindowID->IsShown())
+		return;
+
+	// size children first
+	wxWindowList::Node * pNode = WindowID->GetChildren().GetFirst();
+	while (pNode)
+	{
+		ArtificialSizeEvents(pNode->GetData());
+		pNode = pNode->GetNext();
+	}
+
+	wxSizeEvent event( WindowID->GetSize(), WindowID->GetId() );
+	event.SetEventObject( WindowID );
+	WindowID->GetEventHandler()->ProcessEvent( event );
+}
+
+/********************************************************************************************
+
+>	void ColourPicker::OnSize(CWindowID WindowID)
+
+	Author:		Alex Bligh
+	Created:	30/5/2005
+	Inputs:		-
+	Purpose:	Respond to size events
+	Scope:		Protected
+
+********************************************************************************************/
+
+void ColourPicker::OnSize(CWindowID WindowID)
+{
+	wxWindow * pGadget = DialogManager::GetGadget(WindowID, _R(IDC_EDIT_PICKER));
+	if (pGadget)
+	{
+		wxSize NewSize = pGadget->GetSize();
+		
+		if (s_LastSize != NewSize)
 		{
-			flag++;
-			::wxYield();
-			flag--;
+			// Record the new size
+			s_LastSize = NewSize;
+			if (!s_InColourDialogLayout && !s_IdleCounter && WindowID->IsShown())
+			{
+				// It must have been user initiated
+				s_UserSize = NewSize;
+			}
 		}
 	}
-	WindowID->Layout();
-	WindowID->Fit();
-	WindowID->GetSizer()->SetSizeHints(WindowID);
 }
+
+/********************************************************************************************
+
+>	BOOL ColourPicker::OnIdleEvent(CWindowID WindowID)
+
+	Author:		Alex Bligh
+	Created:	30/5/2005
+	Inputs:		-
+	Purpose:	Respond idle events
+	Scope:		Protected
+
+********************************************************************************************/
+
+BOOL ColourPicker::OnIdleEvent(CWindowID WindowID)
+{
+	if (s_InColourDialogLayout)
+		return FALSE; // That's not a real idle
+
+	if (s_IdleCounter>0)
+	{
+		s_IdleCounter--;
+	}
+
+	if (s_JustCreated && !s_IdleCounter)
+	{
+		// We've just been created so we need to do a post open resize
+		s_JustCreated=FALSE;
+		RelayoutDialog(WindowID);
+	}
+
+	return (s_IdleCounter!=0); // we want more events
+}
+
+/********************************************************************************************
+
+>	void ColourPicker::OnCreate(CWindowID WindowID)
+
+	Author:		Alex Bligh
+	Created:	30/5/2005
+	Inputs:		-
+	Purpose:	Respond to size events
+	Scope:		Protected
+
+********************************************************************************************/
+
+void ColourPicker::OnCreate(CWindowID WindowID)
+{
+	s_IdleCounter=0;
+	s_JustCreated=TRUE;
+
+	// Fix the window size so Open doesn't overwrite it (grrrr)
+	wxWindow * pPicker=DialogManager::GetGadget(WindowID, _R(IDC_EDIT_PICKER));
+	if (pPicker && (s_UserSize != wxDefaultSize))
+	{
+		// Ensure no amount of sizing uses a different size for the picker to the one we want
+		pPicker->SetSize(pPicker->GetSize().GetWidth()+1, pPicker->GetSize().GetHeight()+1); // cause a resize
+		WindowID->Layout();
+		WindowID->Fit();
+		WindowID->GetSizer()->SetSizeHints(WindowID);
+		pPicker->SetMinSize(s_UserSize);
+		pPicker->SetMaxSize(s_UserSize);
+		pPicker->SetSize(s_UserSize);
+	}
+}
Index: Trunk/XaraLX/wxOil/drawctl.cpp
===================================================================
--- Trunk/XaraLX/wxOil/drawctl.cpp	(revision 1242)
+++ Trunk/XaraLX/wxOil/drawctl.cpp	(revision 1243)
@@ -118,6 +118,7 @@
 	EVT_CAMDRAWCONTROL_INVOKE(wxID_ANY, wxCamDrawControl::OnInvoke)
 	EVT_PAINT(wxCamDrawControl::OnPaint)
 	EVT_MOUSE_EVENTS(wxCamDrawControl::OnMouseEvent)
+	EVT_SIZE(wxCamDrawControl::OnSize)
 END_EVENT_TABLE();
 
 IMPLEMENT_DYNAMIC_CLASS( wxCamDrawControlXmlHandler, wxXmlResourceHandler)
@@ -179,12 +180,43 @@
 
 void wxCamDrawControl::OnPaint(wxPaintEvent & event)
 {
-	wxCamDialogEvent RedrawEvent(wxEVT_CAMDIALOG_REDRAW, GetId());
+	if (!m_Frozen)
+	{
+		wxCamDialogEvent RedrawEvent(wxEVT_CAMDIALOG_REDRAW, GetId());
+		wxWindow * pParent=GetParent();
+		if (pParent)
+			pParent->GetEventHandler()->ProcessEvent(RedrawEvent);	
+	}
+}
+
+/********************************************************************************************
+
+>	void wxCamDrawControl::OnSize(wxSizeEvent & event)
+
+
+	Author:		Alex_Bligh <alex@xxxxxxxxxxx>
+	Created:	30/12/2005
+	Inputs:		event - the event
+	Outputs:	-
+	Returns:	-
+	Purpose:	Handles resizing of a control
+	Errors:		-
+	SeeAlso:	-
+
+This is passed to the containing window's event handler for information
+
+********************************************************************************************/
+
+void wxCamDrawControl::OnSize(wxSizeEvent & event)
+{
 	wxWindow * pParent=GetParent();
 	if (pParent)
-		pParent->GetEventHandler()->ProcessEvent(RedrawEvent);	
+		pParent->GetEventHandler()->ProcessEvent(event);	
+
+	event.Skip();	// Pretend we didn't handle it
 }
 
+
 /********************************************************************************************
 
 >	void wxCamDrawControl::OnMouseEvent(wxMouseEvent & event)
Index: Trunk/XaraLX/wxOil/xrc/EN/colordlg.xrc
===================================================================
--- Trunk/XaraLX/wxOil/xrc/EN/colordlg.xrc	(revision 1242)
+++ Trunk/XaraLX/wxOil/xrc/EN/colordlg.xrc	(revision 1243)
@@ -69,24 +69,42 @@
                         <flag>wxGROW|wxALL</flag>
                         <border>1</border>
                         <option>100</option>
-                        <minsize>120,150</minsize>
+                        <minsize>245,245</minsize>
                         <object class="wxCamDrawControl" name="IDC_EDIT_PICKER">
                             <style>wxFULL_REPAINT_ON_RESIZE</style>
-                            <size>120,150</size>
+                            <size>245,245</size>
+                            <bestsize>245,245</bestsize>
                             </object>
                     </object>
                 </object>
             </object>
             <object class="sizeritem">
                 <flag>wxGROW</flag>
-                <border>0</border>
+                <border>1</border>
                 <object class="wxPanel" name="IDC_EDIT_ADVANCEDPANEL">
                     <style>wxNO_BORDER|wxTAB_TRAVERSAL</style>
                     <hidden>1</hidden>
+                    <border>0</border>
                     <object class="wxBoxSizer">
                         <orient>wxVERTICAL</orient>
+                        <border>0</border>
+
                         <object class="sizeritem">
                             <flag>wxGROW|wxALL</flag>
+                            <border>0</border>
+                            <object class="wxBoxSizer">
+                                <orient>wxHORIZONTAL</orient>
+                                <object class="spacer">
+                                    <flag>wxALIGN_CENTER_VERTICAL|wxALL</flag>
+                                    <border>1</border>
+                                    <option>100</option>
+                                    <size>245,1</size>
+                                </object>
+                            </object>
+                        </object>
+
+                        <object class="sizeritem">
+                            <flag>wxGROW|wxALL</flag>
                             <border>1</border>
                             <object class="wxBoxSizer">
                                 <orient>wxHORIZONTAL</orient>
Index: Trunk/XaraLX/wxOil/dlgtypes.h
===================================================================
--- Trunk/XaraLX/wxOil/dlgtypes.h	(revision 1242)
+++ Trunk/XaraLX/wxOil/dlgtypes.h	(revision 1243)
@@ -224,7 +224,10 @@
 					DIM_MOUSEWHEEL_DOWN,			// mousewheel scroll downwards (towards user)
 					DIM_MID_BN_DOWN,				// middle button down
 					DIM_MID_BN_UP,					// middle button up
-					DIM_MID_BN_CLICKED				// middle button pressed
+					DIM_MID_BN_CLICKED,				// middle button pressed
+
+					DIM_CTRL_RESIZED				// A control within the dialog has been resized
+
 				};	
 
 enum CDlgMode { MODAL, MODELESS }; 	// Mode of dialog box     
Index: Trunk/XaraLX/wxOil/dlgmgr.cpp
===================================================================
--- Trunk/XaraLX/wxOil/dlgmgr.cpp	(revision 1242)
+++ Trunk/XaraLX/wxOil/dlgmgr.cpp	(revision 1243)
@@ -870,11 +870,10 @@
 	if (id) pGadget = GetGadget(pEvtHandler->pwxWindow, id);
 
 	// We tend to get this second-hand from our child, we handle this differently
-	if( NULL == pGadget &&
-		EventType == wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED )
+	if( !pGadget && (event.GetEventObject() != pEvtHandler->pwxWindow))
 	{
 		pGadget = (wxWindow *)event.GetEventObject();
-		TRACEUSER( "jlh92", _T("Notebook = %s
"), PCTSTR(pGadget->GetClassInfo()->GetClassName()) );
+		id = pGadget->GetId();
 	}
 
 	// Try and find-out whether our control is part of a tabbed dialog page
@@ -1150,8 +1149,17 @@
 		(EventType == wxEVT_SIZE) ||
 		FALSE)
 	{
-		msg.DlgMsg = DIM_DLG_RESIZED;
-		HandleMessage = TRUE;
+		if (event.GetEventObject() != pEvtHandler->pwxWindow)
+		{
+			Defer = FALSE;
+			msg.DlgMsg = DIM_CTRL_RESIZED;
+			HandleMessage = TRUE;	
+		}
+		else
+		{
+			msg.DlgMsg = DIM_DLG_RESIZED;
+			HandleMessage = TRUE;
+		}
 	}
 	else if (
 		(EventType == wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED) &&


Xara