sbGtkWindowMoveService.h
Go to the documentation of this file.
1 /*
2  *=BEGIN SONGBIRD GPL
3  *
4  * This file is part of the Songbird web player.
5  *
6  * Copyright(c) 2005-2009 POTI, Inc.
7  * http://www.songbirdnest.com
8  *
9  * This file may be licensed under the terms of of the
10  * GNU General Public License Version 2 (the ``GPL'').
11  *
12  * Software distributed under the License is distributed
13  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
14  * express or implied. See the GPL for the specific language
15  * governing rights and limitations.
16  *
17  * You should have received a copy of the GPL along with this
18  * program. If not, go to http://www.gnu.org/licenses/gpl.html
19  * or write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  *=END SONGBIRD GPL
23  */
24 
25 #ifndef sbGtkWindowMoveService_h_
26 #define sbGtkWindowMoveService_h_
27 
28 #include <sbIWindowMoveService.h>
29 #include <nsITimer.h>
30 #include <nsAutoPtr.h>
31 #include <nsCOMPtr.h>
32 #include <gtk/gtk.h>
33 #include <map>
34 
35 
36 //==============================================================================
37 //
38 // @inteface sbGtkWindowContext
39 // @brief An interface for stashing (x,y) coordinates and a listener callback.
40 //
41 //==============================================================================
42 
44 {
45 public:
47  PRInt32 aPreviousX,
48  PRInt32 aPreviousY,
49  PRInt32 aConfigureHandlerID,
50  PRInt32 aDestroyHandlerID);
51  virtual ~sbGtkWindowContext();
52 
53  //
54  // @brief Inform the window context that a frame event has occured. If a
55  // move has been detected, the listener will be notified and a timer
56  // will be set to notify the listener when the move has stopped.
57  // @param aEvent The GDK event class from the move signal.
58  //
59  nsresult OnFrameEvent(GdkEvent *aEvent);
60 
61  //
62  // @brief Call this method when the listening window is destroyed so that
63  // any existing listeners and timers can be cleaned up.
64  //
65  nsresult OnWindowDestroyed();
66 
67  //
68  // @brief Get the handler IDs used to connect a signal to the window that
69  // was used when this context was created.
70  // @param aOutConfigureHandlerID The "configure-event" handler ID.
71  // @parma aOutDestroyHandlerID The "destroy" handler ID.
72  //
73  nsresult GetSignalHandlerIDs(PRInt32 *aOutConfigureHandlerID,
74  PRInt32 *aOutDestroyHandlerID);
75 
77  NS_DECL_NSITIMERCALLBACK
78 
79 private:
80  nsCOMPtr<sbIWindowMoveListener> mListener;
81  nsCOMPtr<nsITimer> mTimer;
82  PRBool mIsTimerSet;
83  PRBool mShouldReArmTimer;
84  PRInt32 mPreviousX;
85  PRInt32 mPreviousY;
86  PRInt32 mConfigureHandlerID;
87  PRInt32 mDestroyHandlerID;
88 };
89 
90 typedef std::map<GtkWindow *, nsRefPtr<sbGtkWindowContext> > sbGtkWindowContextMap;
91 typedef sbGtkWindowContextMap::value_type sbGtkWindowContextMapPair;
92 typedef sbGtkWindowContextMap::iterator sbGtkWindowMoveServiceIter;
93 
94 
95 //==============================================================================
96 //
97 // @interface sbGtkWindowMoveService
98 // @brief GTK window move service implementation.
99 //
100 //==============================================================================
101 
103 {
104 public:
106  virtual ~sbGtkWindowMoveService();
107 
109  NS_DECL_SBIWINDOWMOVESERVICE
110 
111  nsresult OnWindowFrameCallback(GtkWindow *aWindow, GdkEvent *aEvent);
112  nsresult OnWindowDestroyed(GtkWindow *aWindow);
113 
114 private:
115  sbGtkWindowContextMap mWindowContextMap;
116 };
117 
118 #endif // sbGtkWindowMoveService_h_
119 
sbGtkWindowContextMap::iterator sbGtkWindowMoveServiceIter
sbGtkWindowContext(sbIWindowMoveListener *aListener, PRInt32 aPreviousX, PRInt32 aPreviousY, PRInt32 aConfigureHandlerID, PRInt32 aDestroyHandlerID)
nsresult OnFrameEvent(GdkEvent *aEvent)
nsresult GetSignalHandlerIDs(PRInt32 *aOutConfigureHandlerID, PRInt32 *aOutDestroyHandlerID)
std::map< GtkWindow *, nsRefPtr< sbGtkWindowContext > > sbGtkWindowContextMap
nsresult OnWindowDestroyed(GtkWindow *aWindow)
sbGtkWindowContextMap::value_type sbGtkWindowContextMapPair
nsITimerCallback
NS_DECL_ISUPPORTS NS_DECL_SBIWINDOWMOVESERVICE nsresult OnWindowFrameCallback(GtkWindow *aWindow, GdkEvent *aEvent)