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

[XaraXtreme-commits] Commit Complete



Commit by  : alex
Repository : xara
Revision   : 880
Date       : Tue Apr 25 14:07:02 BST 2006

Changed paths:
   M /Trunk/XaraLX/Kernel/ngcore.cpp
   M /Trunk/XaraLX/Kernel/ngcore.h
   M /Trunk/XaraLX/wxOil/Makefile.am
   A /Trunk/XaraLX/wxOil/ktimer.cpp
   A /Trunk/XaraLX/wxOil/ktimer.h

Implemented KernelTimer class


Diff:
Index: Trunk/XaraLX/Kernel/ngcore.cpp
===================================================================
--- Trunk/XaraLX/Kernel/ngcore.cpp	(revision 879)
+++ Trunk/XaraLX/Kernel/ngcore.cpp	(revision 880)
@@ -153,8 +153,7 @@
 // This line mustn't go before any CC_IMPLEMENT_... macros
 #define new CAM_DEBUG_NEW
 
-#define TIMER_ELAPSE	150
-#define TIMER_EVENT		505
+#define TIMER_ELAPSE 150
 
 // The one and only NameGallery object.
 NameGallery* NameGallery::m_pInstance = 0;
@@ -174,7 +173,8 @@
 	m_nRefresh(0),
 	m_nHiddenUpdates(0),
 	m_fMenusCreated(FALSE),
-	m_fChildChanges(FALSE)
+	m_fChildChanges(FALSE),
+	m_Timer(this)
 {
 	DlgResID = _R(IDD_NAMESGALLERY);
 	ERROR3IF(m_pInstance != 0, "NameGallery::NameGallery: instance already exists");
@@ -195,14 +195,6 @@
 
 NameGallery::~NameGallery()
 {
-PORTNOTE("other", "Removed Windows timer usage" )
-#if !defined(EXCLUDE_FROM_XARALX)
-	// Stop sending idle events if we are still claiming them.
-	if (m_nRefresh != 0)
-		//GetApplication()->RemoveIdleProcessor(IDLEPRIORITY_LOW, this);
-		KillTimer(TIMER_EVENT);
-#endif
-	
 	m_pInstance = 0;
 }
 
@@ -688,35 +680,17 @@
 	SeeAlso:	NameGallery::Message; NameGallery::OnIdleEvent
 ********************************************************************************************/
 
-
-PORTNOTE("other", "Removed MFC timer proc" )
-#if !defined(EXCLUDE_FROM_XARALX)
-void CALLBACK NameTimerProc(
-  HWND hwnd,     // handle of window for timer messages
-  UINT32 uMsg,     // WM_TIMER message
-  UINT32 idEvent,  // timer identifier
-  DWORD dwTime   // current system time
-)
-{
-	// a callback calls the timer event
-	NameGallery::Instance()->OnTimerEvent(idEvent);
-}
-#endif
-
 // the timer event adds the idle processor
 // which adds to the  latency. Ie we wait 150 ms, before waiting for a free cpu cycle (or 2) to do the scan.
 // So why do we have a timer in there too? Well the msgs that the name gallery reacts to tend to come in bursts
 // so putting a timer in hopes to minimise unneeded scans that are likely to occur when the msg burst occurs.
 // The idles were previously being called more optimistically than hoped. (sjk 6/10/00)
-BOOL NameGallery::OnTimerEvent(UINT32 TimerId)
+BOOL NameGallery::OnTimerEvent()
 {
 	if (m_nRefresh != 0)
 	{
 		GetApplication()->RegisterIdleProcessor(IDLEPRIORITY_LOW, this);
-PORTNOTE("other", "Removed Windows timer usage" )
-#if !defined(EXCLUDE_FROM_XARALX)
-		KillTimer(TimerId);
-#endif
+		m_Timer.Stop();
 	}
 
 	return TRUE;
@@ -736,14 +710,11 @@
 		return;
 	}
 
-PORTNOTE("other", "Removed Windows timer usage" )
-#if !defined(EXCLUDE_FROM_XARALX)
 	// If going from the clean to the dirty state then send the gallery high
 	// priority idle events.
 	// needs updating very soon now
 	if (m_nRefresh++ == 0)
-		SetTimer(TIMER_EVENT, TIMER_ELAPSE, NameTimerProc);
-#endif
+		m_Timer.Start(TIMER_ELAPSE, TRUE);
 }
 
 
Index: Trunk/XaraLX/Kernel/ngcore.h
===================================================================
--- Trunk/XaraLX/Kernel/ngcore.h	(revision 879)
+++ Trunk/XaraLX/Kernel/ngcore.h	(revision 880)
@@ -104,6 +104,8 @@
 #define NGCORE_H
 
 #include "sgallery.h"
+#include "ktimer.h"
+
 #include <list>
 
 class SGNameGroup;
@@ -165,7 +167,7 @@
 	BOOL PreTriggerEdit(UndoableOperation* pOp, ObjChangeParam* pParam, Node* pNode);
 	BOOL PostTriggerEdit(UndoableOperation* pOp, ObjChangeParam* pParam);
 
-	BOOL OnTimerEvent(UINT32 TimerId);
+	BOOL OnTimerEvent();
 
 protected:
 	// Event & redraw handlers.
@@ -197,8 +199,8 @@
 	// Data.
 	SGUsedNames*		m_pUsedNames;			// cached ptr to 'Used Names' display group
 	INT32					m_nPropertyIndex;		// type of item property being displayed
-	unsigned			m_nRefresh;				// non-zero if gallery display needs redrawing
-	unsigned			m_nHiddenUpdates;		// non-zero if doc changed while gallery hidden
+	UINT32				m_nRefresh;				// non-zero if gallery display needs redrawing
+	UINT32				m_nHiddenUpdates;		// non-zero if doc changed while gallery hidden
 	BOOL				m_fMenusCreated;		// TRUE if menus have been created
 	BOOL				m_fChildChanges;		// TRUE if must send child-change messages
 	UndoableOperation*	m_LastOpUsed;			// the ptr to the op given in PreTrigger and reused in PostTrigger
@@ -226,6 +228,16 @@
 	BYTE  GetBSTTriggeredBar(INT32 Index) { if (Index < MAX_BARS) { return m_BarSize[Index].TriggeredBar; } else { ERROR3("Out of range m_BarSize[] index!"); return 0; }};
 	BYTE  GetBSTHasABackBar(INT32 Index)  { if (Index < MAX_BARS) { return m_BarSize[Index].HasABackBar;  } else { ERROR3("Out of range m_BarSize[] index!"); return 0; }};
 
+private:
+	class NameGalleryTimer : public KernelTimer
+	{
+	public:
+		NameGalleryTimer(NameGallery * pOwner) : m_pOwner(pOwner) {}
+		virtual void Notify() {m_pOwner->OnTimerEvent();}
+		NameGallery * m_pOwner;
+	};
+	NameGalleryTimer m_Timer;
+
 	CC_DECLARE_DYNCREATE(NameGallery)
 };
 
Index: Trunk/XaraLX/wxOil/ktimer.h
===================================================================
--- Trunk/XaraLX/wxOil/ktimer.h	(revision 0)
+++ Trunk/XaraLX/wxOil/ktimer.h	(revision 880)
@@ -0,0 +1,216 @@
+// $Id: ktimer.h 869 2006-04-24 14:03:18Z alex $
+/* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
+================================XARAHEADERSTART===========================
+ 
+               Xara LX, a vector drawing and manipulation program.
+                    Copyright (C) 1993-2006 Xara Group Ltd.
+       Copyright on certain contributions may be held in joint with their
+              respective authors. See AUTHORS file for details.
+
+LICENSE TO USE AND MODIFY SOFTWARE
+----------------------------------
+
+This file is part of Xara LX.
+
+Xara LX is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License version 2 as published
+by the Free Software Foundation.
+
+Xara LX and its component source files are distributed in the hope
+that it will be useful, but WITHOUT ANY WARRANTY; without even the
+implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with Xara LX (see the file GPL in the root directory of the
+distribution); if not, write to the Free Software Foundation, Inc., 51
+Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+
+
+ADDITIONAL RIGHTS
+-----------------
+
+Conditional upon your continuing compliance with the GNU General Public
+License described above, Xara Group Ltd grants to you certain additional
+rights. 
+
+The additional rights are to use, modify, and distribute the software
+together with the wxWidgets library, the wxXtra library, and the "CDraw"
+library and any other such library that any version of Xara LX relased
+by Xara Group Ltd requires in order to compile and execute, including
+the static linking of that library to XaraLX. In the case of the
+"CDraw" library, you may satisfy obligation under the GNU General Public
+License to provide source code by providing a binary copy of the library
+concerned and a copy of the license accompanying it.
+
+Nothing in this section restricts any of the rights you have under
+the GNU General Public License.
+
+
+SCOPE OF LICENSE
+----------------
+
+This license applies to this program (XaraLX) and its constituent source
+files only, and does not necessarily apply to other Xara products which may
+in part share the same code base, and are subject to their own licensing
+terms.
+
+This license does not apply to files in the wxXtra directory, which
+are built into a separate library, and are subject to the wxWindows
+license contained within that directory in the file "WXXTRA-LICENSE".
+
+This license does not apply to the binary libraries (if any) within
+the "libs" directory, which are subject to a separate license contained
+within that directory in the file "LIBS-LICENSE".
+
+
+ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
+----------------------------------------------
+
+Subject to the terms of the GNU Public License (see above), you are
+free to do whatever you like with your modifications. However, you may
+(at your option) wish contribute them to Xara's source tree. You can
+find details of how to do this at:
+  http://www.xaraxtreme.org/developers/
+
+Prior to contributing your modifications, you will need to complete our
+contributor agreement. This can be found at:
+  http://www.xaraxtreme.org/developers/contribute/
+
+Please note that Xara will not accept modifications which modify any of
+the text between the start and end of this header (marked
+XARAHEADERSTART and XARAHEADEREND).
+
+
+MARKS
+-----
+
+Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
+designs are registered or unregistered trademarks, design-marks, and/or
+service marks of Xara Group Ltd. All rights in these marks are reserved.
+
+
+      Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
+                        http://www.xara.com/
+
+=================================XARAHEADEREND============================
+ */
+
+#ifndef INC_KTIMER
+#define	INC_KTIMER
+
+class KernelTimer;
+
+/********************************************************************************************
+
+>	class TimerMsg: public Msg
+
+	Author:		Simon_Maneggio (Xara Group Ltd) <camelotdev@xxxxxxxx>
+	Created:	23/3/94
+	Purpose:	This message is sent whenever something happens to an operation
+	SeeAlso:	-
+
+********************************************************************************************/
+
+class TimerMsg: public Msg
+{
+	CC_DECLARE_DYNAMIC(TimerMsg);
+public:
+
+	enum TimerMsgType
+	{
+		NOTIFY			// A timer event has occurred 
+	};
+
+	TimerMsgType m_MsgType;
+	KernelTimer* m_pTimer; // A pointer to the timer concerned
+
+	TimerMsg(TimerMsgType MsgType=TimerMsg::NOTIFY, KernelTimer * pTimer = NULL)
+	  : m_MsgType(MsgType), m_pTimer(pTimer)
+		{ /* empty */ }
+};
+
+
+/*******************************************************************************************
+
+>	class KernelTimer : public CCObject
+
+	Author:		Alex_Bligh <alex@xxxxxxxxxxx>
+	Created:	25/04/2005
+	Purpose:	A class exposing a timer to the kernel
+	Notes:		In the OIL
+	See Also:	
+
+This class provides a kernel timer object, with an OIL-layer independent interface layer.
+Currently it uses wxTimer, though any timer interface could be used.
+
+There are two main ways of using this class:
+1. As is, in which case it will broadcast timer events
+2. By deriving a class from it, and overriding Notify()
+
+If you know exactly where the notifcation should go, then in your class definition
+do something like the following, which will avoid any broadcasts.
+
+	class MyClass : public CCObject
+	{
+		MyClass() : m_Timer(this);
+		void OnTimer();
+
+	private:
+		class MyTimer : public KernelTimer
+		{
+		public:
+			MyTimer(MyClass * pOwner) : m_pOwner(pOwner);
+			virtual void Notify() {m_pOwner->OnTimer();}
+			MyClass * m_pOwner;
+		};
+		MyTimer m_Timer;
+	}
+
+********************************************************************************************/
+
+class KernelTimer : public CCObject
+{
+	CC_DECLARE_DYNAMIC(KernelTimer);
+
+private:
+	CCRuntimeClass* m_BroadcastClass;
+
+public:
+	KernelTimer(CCRuntimeClass * BroadcastClass = NULL) : m_BroadcastClass (BroadcastClass), m_Timer(this) {}
+	~KernelTimer() {}
+
+	void SetBroadcastClass (CCRuntimeClass * BroadcastClass) {m_BroadcastClass = BroadcastClass;}
+	CCRuntimeClass * GetBroadcastClass () const {return m_BroadcastClass;}
+
+protected:
+	virtual void Notify()
+	{
+		Msg * pMsg = new TimerMsg(TimerMsg::NOTIFY, this);
+		if (pMsg)
+			MessageHandler::Broadcast(pMsg, m_BroadcastClass);
+	}
+
+private:
+
+	class CamTimer : public wxTimer
+	{
+	public:
+		CamTimer(KernelTimer * pKTimer = NULL) : m_pKTimer(pKTimer) {};
+		~CamTimer() {};
+		KernelTimer * m_pKTimer;
+		virtual void Notify() {if (m_pKTimer) { m_pKTimer->Notify();}}
+	};
+
+	CamTimer m_Timer;
+
+public:
+	INT32 GetInterval() const { return m_Timer.GetInterval(); }
+	BOOL IsOneShost() const { return m_Timer.IsOneShot(); }
+	BOOL IsRunning() const { return m_Timer.IsRunning(); }
+	BOOL Start(INT32 milliseconds = -1, BOOL OneShot = FALSE) { return m_Timer.Start(milliseconds, OneShot); }
+	void Stop() { m_Timer.Stop(); }
+};
+
+#endif
+
Index: Trunk/XaraLX/wxOil/ktimer.cpp
===================================================================
--- Trunk/XaraLX/wxOil/ktimer.cpp	(revision 0)
+++ Trunk/XaraLX/wxOil/ktimer.cpp	(revision 880)
@@ -0,0 +1,253 @@
+// $Id: cartctl.cpp 869 2006-04-24 14:03:18Z alex $
+/* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
+================================XARAHEADERSTART===========================
+ 
+               Xara LX, a vector drawing and manipulation program.
+                    Copyright (C) 1993-2006 Xara Group Ltd.
+       Copyright on certain contributions may be held in joint with their
+              respective authors. See AUTHORS file for details.
+
+LICENSE TO USE AND MODIFY SOFTWARE
+----------------------------------
+
+This file is part of Xara LX.
+
+Xara LX is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License version 2 as published
+by the Free Software Foundation.
+
+Xara LX and its component source files are distributed in the hope
+that it will be useful, but WITHOUT ANY WARRANTY; without even the
+implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with Xara LX (see the file GPL in the root directory of the
+distribution); if not, write to the Free Software Foundation, Inc., 51
+Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+
+
+ADDITIONAL RIGHTS
+-----------------
+
+Conditional upon your continuing compliance with the GNU General Public
+License described above, Xara Group Ltd grants to you certain additional
+rights. 
+
+The additional rights are to use, modify, and distribute the software
+together with the wxWidgets library, the wxXtra library, and the "CDraw"
+library and any other such library that any version of Xara LX relased
+by Xara Group Ltd requires in order to compile and execute, including
+the static linking of that library to XaraLX. In the case of the
+"CDraw" library, you may satisfy obligation under the GNU General Public
+License to provide source code by providing a binary copy of the library
+concerned and a copy of the license accompanying it.
+
+Nothing in this section restricts any of the rights you have under
+the GNU General Public License.
+
+
+SCOPE OF LICENSE
+----------------
+
+This license applies to this program (XaraLX) and its constituent source
+files only, and does not necessarily apply to other Xara products which may
+in part share the same code base, and are subject to their own licensing
+terms.
+
+This license does not apply to files in the wxXtra directory, which
+are built into a separate library, and are subject to the wxWindows
+license contained within that directory in the file "WXXTRA-LICENSE".
+
+This license does not apply to the binary libraries (if any) within
+the "libs" directory, which are subject to a separate license contained
+within that directory in the file "LIBS-LICENSE".
+
+
+ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
+----------------------------------------------
+
+Subject to the terms of the GNU Public License (see above), you are
+free to do whatever you like with your modifications. However, you may
+(at your option) wish contribute them to Xara's source tree. You can
+find details of how to do this at:
+  http://www.xaraxtreme.org/developers/
+
+Prior to contributing your modifications, you will need to complete our
+contributor agreement. This can be found at:
+  http://www.xaraxtreme.org/developers/contribute/
+
+Please note that Xara will not accept modifications which modify any of
+the text between the start and end of this header (marked
+XARAHEADERSTART and XARAHEADEREND).
+
+
+MARKS
+-----
+
+Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
+designs are registered or unregistered trademarks, design-marks, and/or
+service marks of Xara Group Ltd. All rights in these marks are reserved.
+
+
+      Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
+                        http://www.xara.com/
+
+=================================XARAHEADEREND============================
+ */
+
+
+#include "camtypes.h"
+
+#include "ktimer.h"
+
+CC_IMPLEMENT_DYNAMIC(KernelTimer, CCObject);
+CC_IMPLEMENT_DYNAMIC(TimerMsg, Msg);
+
+// Note all the implementation is in the .h file, so this is really just IMPLEMENT_DYNAMIC and some
+// documentation
+
+/********************************************************************************************
+
+>	KernelTimer::KernelTimer(CCRuntimeClass * BroadcastClass = NULL)
+
+	Author:		Alex_Bligh <alex@xxxxxxxxxxx>
+	Created:	25/04/2005
+	Inputs:		BroadcastClass - the class to broadcast to, or NULL for all
+	Outputs:	None
+	Returns:	-
+	Purpose:	Constructor
+	Errors:		-
+	SeeAlso:	-
+
+Use BroadcastClass to restrict the amount of broadcast traffic, e.g.
+	KernelTimer MyTimer(CC_RUNTIME_CLASS(DialogOp));
+
+********************************************************************************************/
+
+/********************************************************************************************
+
+>	void KernelTimer::SetBroadcastClass (CCRuntimeClass * BroadcastClass)
+
+	Author:		Alex_Bligh <alex@xxxxxxxxxxx>
+	Created:	25/04/2005
+	Inputs:		BroadcastClass - the class to broadcast to, or NULL for all
+	Outputs:	None
+	Returns:	-
+	Purpose:	Change the broadcast class
+	Errors:		-
+	SeeAlso:	-
+
+********************************************************************************************/
+
+/********************************************************************************************
+
+>	CCRuntimeClass * KernelTimer::GetBroadcastClass () const
+
+	Author:		Alex_Bligh <alex@xxxxxxxxxxx>
+	Created:	25/04/2005
+	Inputs:		None
+	Outputs:	None
+	Returns:	The current broadcast class
+	Purpose:	Return the current broadcast class
+	Errors:		-
+	SeeAlso:	-
+
+********************************************************************************************/
+
+/********************************************************************************************
+
+>	virtual void KernelTimer::Notify()
+
+	Author:		Alex_Bligh <alex@xxxxxxxxxxx>
+	Created:	25/04/2005
+	Inputs:		None
+	Outputs:	None
+	Returns:	None
+	Purpose:	Called when a timer event occurs
+	Errors:		-
+	SeeAlso:	-
+
+This function by default broadcasts a TimerMsg::Notify to all message handlers (or
+to the subset set up in the constructor or KernelTimer::SetBroadcast). It can be
+overridden to do something else (or something additional).
+
+********************************************************************************************/
+
+/********************************************************************************************
+
+>	virtual void KernelTimer::GetInterval()
+
+	Author:		Alex_Bligh <alex@xxxxxxxxxxx>
+	Created:	25/04/2005
+	Inputs:		None
+	Outputs:	None
+	Returns:	Current interval
+	Purpose:	Returns the current interval that has been set
+	Errors:		-
+	SeeAlso:	-
+
+********************************************************************************************/
+
+/********************************************************************************************
+
+>	BOOL KernelTimer::IsOneShost() const
+
+	Author:		Alex_Bligh <alex@xxxxxxxxxxx>
+	Created:	25/04/2005
+	Inputs:		None
+	Outputs:	None
+	Returns:	TRUE if the timer is one shot, FALSE if the timer repeats
+	Purpose:	-
+	Errors:		-
+	SeeAlso:	-
+
+********************************************************************************************/
+
+/********************************************************************************************
+
+>	BOOL KernelTimer::IsRunning() const
+
+	Author:		Alex_Bligh <alex@xxxxxxxxxxx>
+	Created:	25/04/2005
+	Inputs:		None
+	Outputs:	None
+	Returns:	TRUE if the timer is running, FALSE otherwise
+	Purpose:	-
+	Errors:		-
+	SeeAlso:	-
+
+********************************************************************************************/
+
+/********************************************************************************************
+
+>	BOOL KernelTimer::Start(INT32 milliseconds = -1, BOOL OneShot = FALSE)
+
+	Author:		Alex_Bligh <alex@xxxxxxxxxxx>
+	Created:	25/04/2005
+	Inputs:		milliseconds - number of ms until the next timer events (or between events)
+							   or -1 to use the previous value
+				OneShot - TRUE to make it a one shot rather than repeating timer
+	Outputs:	None
+	Returns:	TRUE if the timer was successfully started
+	Purpose:	-
+	Errors:		-
+	SeeAlso:	-
+
+********************************************************************************************/
+
+/********************************************************************************************
+
+>	BOOL void KernelTimer::Stop()
+
+	Author:		Alex_Bligh <alex@xxxxxxxxxxx>
+	Created:	25/04/2005
+	Inputs:		None
+	Outputs:	None
+	Returns:	TRUE if the timer was successfully stopped
+	Purpose:	-
+	Errors:		-
+	SeeAlso:	-
+
+********************************************************************************************/
+
Index: Trunk/XaraLX/wxOil/Makefile.am
===================================================================
--- Trunk/XaraLX/wxOil/Makefile.am	(revision 879)
+++ Trunk/XaraLX/wxOil/Makefile.am	(revision 880)
@@ -40,7 +40,7 @@
 	dlgevt.cpp cartprov.cpp cartctl.cpp colourmat.cpp menucmds.cpp menupref.cpp \
 	rendwnd.cpp scroller.cpp helpuser.cpp oilprefs.cpp dragtrgt.cpp \
 	ctrllist.cpp dlgcol.cpp thumb.cpp dragmgr.cpp ccolbar.cpp dragcol.cpp \
-	drawctl.cpp filedlgs.cpp fileutil.cpp \
+	drawctl.cpp filedlgs.cpp fileutil.cpp ktimer.cpp \
 	outptdib.cpp outptpng.cpp outptgif.cpp gpalopt.cpp bmpfiltr.cpp giffiltr.cpp \
 	fontbase.cpp ftfonts.cpp textfuns.cpp \
 	resources.cpp


Xara