• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2005 The Android Open Source Project
3 //
4 // Window with simulated phone.
5 //
6 #ifndef _SIM_PHONE_WINDOW_H
7 #define _SIM_PHONE_WINDOW_H
8 
9 #include "PhoneData.h"
10 #include "DeviceManager.h"
11 #include "DeviceWindow.h"
12 #include <ui/KeycodeLabels.h>
13 
14 class MainFrame;
15 
16 /*
17  * This window displays the simulated phone views, and handles keyboard and
18  * mouse input.
19  *
20  * If we switch to a different "mode", we may display different "views",
21  * but the set of "displays" remains the same.  (Got that?)
22  *
23  * We can't just do these things in the main frame because we can't easily
24  * grab the keyboard input.
25  */
26 class PhoneWindow : public wxDialog {
27 public:
28     PhoneWindow(wxWindow* parent, const wxPoint& posn);
29     virtual ~PhoneWindow(void);
30 
31     /* call this initially, and after a mode change */
32     bool Setup(int phoneIdx);
33 
IsReady(void)34     bool IsReady(void) const {
35         return (mNumViewInfo > 0 && mpViewInfo != NULL);
36     }
37 
38     PhoneData* GetPhoneData(void) const;
39 
GetCurrentMode(void)40     const wxString& GetCurrentMode(void) const { return mCurrentMode; }
SetCurrentMode(const wxString & mode)41     void SetCurrentMode(const wxString& mode) { mCurrentMode = mode; }
SetCurrentMode(const char * mode)42     void SetCurrentMode(const char* mode) { mCurrentMode = wxString::FromAscii(mode); }
43 
GetDeviceManager(void)44     DeviceManager* GetDeviceManager(void) { return &mDeviceManager; }
45 
46     /* this is called when the phone data is reloaded */
47     void DevicesRescanned(void);
48 
49     void Vibrate(int vibrateOn);
50 
51 private:
52     /*
53      * Hold some information about the "views" being shown in our window.
54      */
55     class ViewInfo {
56     public:
ViewInfo(void)57         ViewInfo(void)
58             : mX(-1), mY(-1), mDisplayX(-1), mDisplayY(-1),
59               mWidth(-1), mHeight(-1), mDisplayIndex(-1)
60         {}
~ViewInfo(void)61         ~ViewInfo(void) {}
62 
GetX(void)63         int GetX(void) const { return mX; }
GetY(void)64         int GetY(void) const { return mY; }
GetDisplayX(void)65         int GetDisplayX(void) const { return mDisplayX; }
GetDisplayY(void)66         int GetDisplayY(void) const { return mDisplayY; }
GetWidth(void)67         int GetWidth(void) const { return mWidth; }
GetHeight(void)68         int GetHeight(void) const { return mHeight; }
GetDisplayIndex(void)69         int GetDisplayIndex(void) const { return mDisplayIndex; }
70 
SetX(int val)71         void SetX(int val) { mX = val; }
SetY(int val)72         void SetY(int val) { mY = val; }
SetDisplayX(int val)73         void SetDisplayX(int val) { mDisplayX = val; }
SetDisplayY(int val)74         void SetDisplayY(int val) { mDisplayY = val; }
SetWidth(int val)75         void SetWidth(int val) { mWidth = val; }
SetHeight(int val)76         void SetHeight(int val) { mHeight = val; }
SetDisplayIndex(int val)77         void SetDisplayIndex(int val) { mDisplayIndex = val; }
78 
79     private:
80         int     mX, mY;                 // view offset within PhoneWindow
81         int     mDisplayX, mDisplayY;   // display offset within view
82         int     mWidth, mHeight;        // view dimensions
83 
84         int     mDisplayIndex;          // index into mpDeviceWindow
85     };
86 
87     /*
88      * Hold information about currently pressed keys.
89      */
90     class KeyInfo {
91     public:
KeyInfo(void)92         KeyInfo(void) : mKeyCode(AKEYCODE_UNKNOWN) {}
KeyInfo(const KeyInfo & src)93         KeyInfo(const KeyInfo& src) {
94             mKeyCode = src.mKeyCode;
95         }
~KeyInfo(void)96         ~KeyInfo(void) {}
97 
98         KeyInfo& operator=(const KeyInfo& src) {
99             if (this != &src) {
100                 mKeyCode = src.mKeyCode;
101             }
102             return *this;
103         }
104 
GetKeyCode(void)105         int32_t GetKeyCode(void) const { return mKeyCode; }
SetKeyCode(int32_t keyCode)106         void SetKeyCode(int32_t keyCode) { mKeyCode = keyCode; }
107 
108         //PhoneButton* GetPhoneButton(void) const { return mpButton; }
109         //void SetPhoneButton(PhoneButton* pButton) { mpButton = pButton; }
110 
111     private:
112         int32_t mKeyCode;
113         //PhoneButton*        mpButton;
114     };
115 
116     void OnActivate(wxActivateEvent& event);
117     void OnMove(wxMoveEvent& event);
118     void OnClose(wxCloseEvent& event);
119     void OnTimer(wxTimerEvent& event);
120     void OnKeyDown(wxKeyEvent& event);
121     void OnKeyUp(wxKeyEvent& event);
122     void OnErase(wxEraseEvent& event);
123     void OnPaint(wxPaintEvent& WXUNUSED(event));
124     void OnMouseLeftDown(wxMouseEvent& event);
125     void OnMouseLeftUp(wxMouseEvent& event);
126     void OnMouseRightDown(wxMouseEvent& event);
127     void OnMouseRightUp(wxMouseEvent& event);
128     void OnMouseMotion(wxMouseEvent& event);
129     void OnMouseLeaveWindow(wxMouseEvent& WXUNUSED(event));
130     bool GetTouchPosition(const wxMouseEvent& event, int* pScreenX,
131         int* pScreenY);
132 
133     bool GetDimensions(PhoneData* pPhoneData, PhoneView* pPhoneView,
134         ViewInfo* pDim);
135     int ConvertKeyCode(int wxKeyCode) const;
136 
137     /* press a key on the device */
138     void AddPressedKey(int32_t keyCode);
139     /* release a key on the device */
140     void RemovePressedKey(int32_t keyCode);
141     /* "raise" all keys */
142     void ClearPressedKeys(void);
143     /* determine whether a key is down */
144     bool IsKeyPressed(int32_t keyCode);
145 
146     /* manage the device runtime */
147     DeviceManager   mDeviceManager;
148 
149     /* button mouse-over highlight handling */
150     int             mpMOHViewIndex;     // mouse is in this view
151     PhoneButton*    mpMOHButton;        //   over this button
152     int32_t         mMouseKeySent;     // to handle "key up" for mouse button
153 
154     /* handle multiple simultaneous key presses */
155     android::List<KeyInfo>  mPressedKeys;
156     typedef android::List<KeyInfo>::iterator ListIter;
157 
158     /* ViewInfos, 1:1 with PhoneView entries for the current mode */
159     ViewInfo*       mpViewInfo;         // array of view data
160     int             mNumViewInfo;       // #of elements in mpViewInfo
161 
162     /* DeviceWindows, 1:1 with PhoneDisplay entries for this device */
163     DeviceWindow**  mpDeviceWindow;     // array of pointers to device windows
164     int             mNumDeviceWindows;  // #of device windows
165 
166     /* state */
167     int             mPhoneModel;        // index into model list
168     wxString        mCurrentMode;
169 
170     bool            mPlacementChecked;  // leave it offscreen if they want
171 
172     MainFrame*      mpParent;           // retain pointer to parent window
173 
174     enum { kVibrateTimerId = 1010 };
175     wxTimer         mTimer;
176     int             mVibrateX;
177 
178     /* touchscreen simulation */
179     bool            mTrackingTouch;
180     int             mTouchX;
181     int             mTouchY;
182 
183     DECLARE_EVENT_TABLE()
184 };
185 
186 #endif // _SIM_PHONE_WINDOW_H
187