source: GTP/branches/IllumWPdeliver2008dec/IlluminationWP/demos/Standalone/MultipleReflections [DirectX]/Common/DXUTgui.h @ 3255

Revision 3255, 48.1 KB checked in by szirmay, 16 years ago (diff)
Line 
1//--------------------------------------------------------------------------------------
2// File: DXUTgui.h
3//
4// Desc:
5//
6// Copyright (c) Microsoft Corporation. All rights reserved.
7//--------------------------------------------------------------------------------------
8#pragma once
9#ifndef DXUT_GUI_H
10#define DXUT_GUI_H
11
12#include <usp10.h>
13#include <dimm.h>
14
15
16//--------------------------------------------------------------------------------------
17// Defines and macros
18//--------------------------------------------------------------------------------------
19#define EVENT_BUTTON_CLICKED                0x0101
20#define EVENT_COMBOBOX_SELECTION_CHANGED    0x0201
21#define EVENT_RADIOBUTTON_CHANGED           0x0301
22#define EVENT_CHECKBOX_CHANGED              0x0401
23#define EVENT_SLIDER_VALUE_CHANGED          0x0501
24#define EVENT_EDITBOX_STRING                0x0601
25// EVENT_EDITBOX_CHANGE is sent when the listbox content changes
26// due to user input.
27#define EVENT_EDITBOX_CHANGE                0x0602
28#define EVENT_LISTBOX_ITEM_DBLCLK           0x0701
29// EVENT_LISTBOX_SELECTION is fired off when the selection changes in
30// a single selection list box.
31#define EVENT_LISTBOX_SELECTION             0x0702
32#define EVENT_LISTBOX_SELECTION_END         0x0703
33
34
35//--------------------------------------------------------------------------------------
36// Forward declarations
37//--------------------------------------------------------------------------------------
38class CDXUTDialogResourceManager;
39class CDXUTControl;
40class CDXUTButton;
41class CDXUTStatic;
42class CDXUTCheckBox;
43class CDXUTRadioButton;
44class CDXUTComboBox;
45class CDXUTSlider;
46class CDXUTEditBox;
47class CDXUTIMEEditBox;
48class CDXUTListBox;
49class CDXUTScrollBar;
50class CDXUTElement;
51struct DXUTElementHolder;
52struct DXUTTextureNode;
53struct DXUTFontNode;
54typedef VOID (CALLBACK *PCALLBACKDXUTGUIEVENT) ( UINT nEvent, int nControlID, CDXUTControl* pControl, void* pUserContext );
55
56
57//--------------------------------------------------------------------------------------
58// Enums for pre-defined control types
59//--------------------------------------------------------------------------------------
60enum DXUT_CONTROL_TYPE
61{
62    DXUT_CONTROL_BUTTON,
63    DXUT_CONTROL_STATIC,
64    DXUT_CONTROL_CHECKBOX,
65    DXUT_CONTROL_RADIOBUTTON,
66    DXUT_CONTROL_COMBOBOX,
67    DXUT_CONTROL_SLIDER,
68    DXUT_CONTROL_EDITBOX,
69    DXUT_CONTROL_IMEEDITBOX,
70    DXUT_CONTROL_LISTBOX,
71    DXUT_CONTROL_SCROLLBAR,
72};
73
74enum DXUT_CONTROL_STATE
75{
76    DXUT_STATE_NORMAL = 0,
77    DXUT_STATE_DISABLED,
78    DXUT_STATE_HIDDEN,
79    DXUT_STATE_FOCUS,
80    DXUT_STATE_MOUSEOVER,
81    DXUT_STATE_PRESSED,
82};
83
84#define MAX_CONTROL_STATES 6
85
86struct DXUTBlendColor
87{
88    void Init( D3DCOLOR defaultColor, D3DCOLOR disabledColor = D3DCOLOR_ARGB(200, 128, 128, 128), D3DCOLOR hiddenColor = 0 );
89    void Blend( UINT iState, float fElapsedTime, float fRate = 0.7f );
90   
91    D3DCOLOR  States[ MAX_CONTROL_STATES ]; // Modulate colors for all possible control states
92    D3DXCOLOR Current;
93};
94
95
96//-----------------------------------------------------------------------------
97// Contains all the display tweakables for a sub-control
98//-----------------------------------------------------------------------------
99class CDXUTElement
100{
101public:
102    void SetTexture( UINT iTexture, RECT* prcTexture, D3DCOLOR defaultTextureColor = D3DCOLOR_ARGB(255, 255, 255, 255) );
103    void SetFont( UINT iFont, D3DCOLOR defaultFontColor = D3DCOLOR_ARGB(255, 255, 255, 255), DWORD dwTextFormat = DT_CENTER | DT_VCENTER );
104   
105    void Refresh();
106   
107    UINT iTexture;          // Index of the texture for this Element
108    UINT iFont;             // Index of the font for this Element
109    DWORD dwTextFormat;     // The format argument to DrawText
110
111    RECT rcTexture;         // Bounding rect of this element on the composite texture
112   
113    DXUTBlendColor TextureColor;
114    DXUTBlendColor FontColor;
115};
116
117
118//-----------------------------------------------------------------------------
119// All controls must be assigned to a dialog, which handles
120// input and rendering for the controls.
121//-----------------------------------------------------------------------------
122class CDXUTDialog
123{
124    friend class CDXUTDialogResourceManager;
125
126public:
127    CDXUTDialog();
128    ~CDXUTDialog();
129
130    // Need to call this now
131    void Init( CDXUTDialogResourceManager* pManager, bool bRegisterDialog = true );
132    void Init( CDXUTDialogResourceManager* pManager, bool bRegisterDialog, LPCWSTR pszControlTextureFilename );
133    void Init( CDXUTDialogResourceManager* pManager, bool bRegisterDialog, LPCWSTR szControlTextureResourceName, HMODULE hControlTextureResourceModule );
134
135    // Windows message handler
136    bool MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
137
138    // Control creation
139    HRESULT AddStatic( int ID, LPCWSTR strText, int x, int y, int width, int height, bool bIsDefault=false, CDXUTStatic** ppCreated=NULL );
140    HRESULT AddButton( int ID, LPCWSTR strText, int x, int y, int width, int height, UINT nHotkey=0, bool bIsDefault=false, CDXUTButton** ppCreated=NULL );
141    HRESULT AddCheckBox( int ID, LPCWSTR strText, int x, int y, int width, int height, bool bChecked=false, UINT nHotkey=0, bool bIsDefault=false, CDXUTCheckBox** ppCreated=NULL );
142    HRESULT AddRadioButton( int ID, UINT nButtonGroup, LPCWSTR strText, int x, int y, int width, int height, bool bChecked=false, UINT nHotkey=0, bool bIsDefault=false, CDXUTRadioButton** ppCreated=NULL );
143    HRESULT AddComboBox( int ID, int x, int y, int width, int height, UINT nHotKey=0, bool bIsDefault=false, CDXUTComboBox** ppCreated=NULL );
144    HRESULT AddSlider( int ID, int x, int y, int width, int height, int min=0, int max=100, int value=50, bool bIsDefault=false, CDXUTSlider** ppCreated=NULL );
145    HRESULT AddEditBox( int ID, LPCWSTR strText, int x, int y, int width, int height, bool bIsDefault=false, CDXUTEditBox** ppCreated=NULL );
146    HRESULT AddIMEEditBox( int ID, LPCWSTR strText, int x, int y, int width, int height, bool bIsDefault=false, CDXUTIMEEditBox** ppCreated=NULL );
147    HRESULT AddListBox( int ID, int x, int y, int width, int height, DWORD dwStyle=0, CDXUTListBox** ppCreated=NULL );
148    HRESULT AddControl( CDXUTControl* pControl );
149    HRESULT InitControl( CDXUTControl* pControl );
150
151    // Control retrieval
152    CDXUTStatic*      GetStatic( int ID ) { return (CDXUTStatic*) GetControl( ID, DXUT_CONTROL_STATIC ); }
153    CDXUTButton*      GetButton( int ID ) { return (CDXUTButton*) GetControl( ID, DXUT_CONTROL_BUTTON ); }
154    CDXUTCheckBox*    GetCheckBox( int ID ) { return (CDXUTCheckBox*) GetControl( ID, DXUT_CONTROL_CHECKBOX ); }
155    CDXUTRadioButton* GetRadioButton( int ID ) { return (CDXUTRadioButton*) GetControl( ID, DXUT_CONTROL_RADIOBUTTON ); }
156    CDXUTComboBox*    GetComboBox( int ID ) { return (CDXUTComboBox*) GetControl( ID, DXUT_CONTROL_COMBOBOX ); }
157    CDXUTSlider*      GetSlider( int ID ) { return (CDXUTSlider*) GetControl( ID, DXUT_CONTROL_SLIDER ); }
158    CDXUTEditBox*     GetEditBox( int ID ) { return (CDXUTEditBox*) GetControl( ID, DXUT_CONTROL_EDITBOX ); }
159    CDXUTIMEEditBox*  GetIMEEditBox( int ID ) { return (CDXUTIMEEditBox*) GetControl( ID, DXUT_CONTROL_IMEEDITBOX ); }
160    CDXUTListBox*     GetListBox( int ID ) { return (CDXUTListBox*) GetControl( ID, DXUT_CONTROL_LISTBOX ); }
161
162    CDXUTControl* GetControl( int ID );
163    CDXUTControl* GetControl( int ID, UINT nControlType );
164    CDXUTControl* GetControlAtPoint( POINT pt );
165
166    bool GetControlEnabled( int ID );
167    void SetControlEnabled( int ID, bool bEnabled );
168
169    void ClearRadioButtonGroup( UINT nGroup );
170    void ClearComboBox( int ID );
171
172    // Access the default display Elements used when adding new controls
173    HRESULT       SetDefaultElement( UINT nControlType, UINT iElement, CDXUTElement* pElement );
174    CDXUTElement* GetDefaultElement( UINT nControlType, UINT iElement );
175
176    // Methods called by controls
177    void SendEvent( UINT nEvent, bool bTriggeredByUser, CDXUTControl* pControl );
178    void RequestFocus( CDXUTControl* pControl );
179
180    // Render helpers
181    HRESULT DrawRect( RECT* pRect, D3DCOLOR color );
182    HRESULT DrawPolyLine( POINT* apPoints, UINT nNumPoints, D3DCOLOR color );
183    HRESULT DrawSprite( CDXUTElement* pElement, RECT* prcDest );
184    HRESULT CalcTextRect( LPCWSTR strText, CDXUTElement* pElement, RECT* prcDest, int nCount = -1 );
185    HRESULT DrawText( LPCWSTR strText, CDXUTElement* pElement, RECT* prcDest, bool bShadow = false, int nCount = -1 );
186
187    // Attributes
188    bool GetVisible() { return m_bVisible; }
189    void SetVisible( bool bVisible ) { m_bVisible = bVisible; }
190    bool GetMinimized() { return m_bMinimized; }
191    void SetMinimized( bool bMinimized ) { m_bMinimized = bMinimized; }
192    void SetBackgroundColors( D3DCOLOR colorAllCorners ) { SetBackgroundColors( colorAllCorners, colorAllCorners, colorAllCorners, colorAllCorners ); }
193    void SetBackgroundColors( D3DCOLOR colorTopLeft, D3DCOLOR colorTopRight, D3DCOLOR colorBottomLeft, D3DCOLOR colorBottomRight );
194    void EnableCaption( bool bEnable ) { m_bCaption = bEnable; }
195    int GetCaptionHeight() const { return m_nCaptionHeight; }
196    void SetCaptionHeight( int nHeight ) { m_nCaptionHeight = nHeight; }
197    void SetCaptionText( const WCHAR *pwszText ) { StringCchCopy( m_wszCaption, sizeof(m_wszCaption)/sizeof(m_wszCaption[0]), pwszText); }
198    void GetLocation( POINT &Pt ) const { Pt.x = m_x; Pt.y = m_y; }
199    void SetLocation( int x, int y ) { m_x = x; m_y = y; }
200    void SetSize( int width, int height ) { m_width = width; m_height = height;  }
201    int GetWidth() { return m_width; }
202    int GetHeight() { return m_height; }
203
204    static void SetRefreshTime( float fTime ){ s_fTimeRefresh = fTime; }
205
206    static CDXUTControl* GetNextControl( CDXUTControl* pControl );
207    static CDXUTControl* GetPrevControl( CDXUTControl* pControl );
208
209    void RemoveControl( int ID );
210    void RemoveAllControls();
211
212    // Sets the callback used to notify the app of control events
213    void SetCallback( PCALLBACKDXUTGUIEVENT pCallback, void* pUserContext = NULL );
214    void EnableNonUserEvents( bool bEnable ) { m_bNonUserEvents = bEnable; }
215    void EnableKeyboardInput( bool bEnable ) { m_bKeyboardInput = bEnable; }
216    void EnableMouseInput( bool bEnable ) { m_bMouseInput = bEnable; }
217    bool IsKeyboardInputEnabled() const { return m_bKeyboardInput; }
218
219    // Device state notification
220    void Refresh();
221    HRESULT OnRender( float fElapsedTime );
222
223    // Shared resource access. Indexed fonts and textures are shared among
224    // all the controls.
225    HRESULT       SetFont( UINT index, LPCWSTR strFaceName, LONG height, LONG weight );
226    DXUTFontNode* GetFont( UINT index );
227
228    HRESULT          SetTexture( UINT index, LPCWSTR strFilename );
229    HRESULT          SetTexture( UINT index, LPCWSTR strResourceName, HMODULE hResourceModule );
230    DXUTTextureNode* GetTexture( UINT index );
231
232    CDXUTDialogResourceManager* GetManager() { return m_pManager; }
233
234    static void ClearFocus();
235    void FocusDefaultControl();
236
237    bool m_bNonUserEvents;
238    bool m_bKeyboardInput;
239    bool m_bMouseInput;
240
241
242
243private:
244    int m_nDefaultControlID;
245
246    static double s_fTimeRefresh;
247    double m_fTimeLastRefresh;
248
249    // Initialize default Elements
250    void InitDefaultElements();
251
252    // Windows message handlers
253    void OnMouseMove( POINT pt );
254    void OnMouseUp( POINT pt );
255
256    void SetNextDialog( CDXUTDialog* pNextDialog );
257
258    // Control events
259    bool OnCycleFocus( bool bForward );
260
261    static CDXUTControl* s_pControlFocus;        // The control which has focus
262    static CDXUTControl* s_pControlPressed;      // The control currently pressed
263
264    CDXUTControl* m_pControlMouseOver;           // The control which is hovered over
265
266    bool m_bVisible;
267    bool m_bCaption;
268    bool m_bMinimized;
269    bool m_bDrag;
270    WCHAR m_wszCaption[256];
271
272    int m_x;
273    int m_y;
274    int m_width;
275    int m_height;
276    int m_nCaptionHeight;
277
278    D3DCOLOR m_colorTopLeft;
279    D3DCOLOR m_colorTopRight;
280    D3DCOLOR m_colorBottomLeft;
281    D3DCOLOR m_colorBottomRight;
282
283    CDXUTDialogResourceManager* m_pManager;
284    PCALLBACKDXUTGUIEVENT m_pCallbackEvent;
285    void* m_pCallbackEventUserContext;
286
287    CGrowableArray< int > m_Textures;   // Index into m_TextureCache;
288    CGrowableArray< int > m_Fonts;      // Index into m_FontCache;
289
290    CGrowableArray< CDXUTControl* > m_Controls;
291    CGrowableArray< DXUTElementHolder* > m_DefaultElements;
292
293    CDXUTElement m_CapElement;  // Element for the caption
294
295    CDXUTDialog* m_pNextDialog;
296    CDXUTDialog* m_pPrevDialog;
297};
298
299
300//--------------------------------------------------------------------------------------
301// Structs for shared resources
302//--------------------------------------------------------------------------------------
303struct DXUTTextureNode
304{
305    bool bFileSource;  // True if this texture is loaded from a file. False if from resource.
306    HMODULE hResourceModule;
307    int nResourceID;   // Resource ID. If 0, string-based ID is used and stored in strFilename.
308    WCHAR strFilename[MAX_PATH];
309    IDirect3DTexture9* pTexture;
310    DWORD dwWidth;
311    DWORD dwHeight;
312};
313
314struct DXUTFontNode
315{
316    WCHAR strFace[MAX_PATH];
317    ID3DXFont* pFont;
318    LONG  nHeight;
319    LONG  nWeight;
320};
321
322
323//-----------------------------------------------------------------------------
324// Manages shared resources of dialogs
325//-----------------------------------------------------------------------------
326class CDXUTDialogResourceManager
327{
328public:
329    CDXUTDialogResourceManager();
330    ~CDXUTDialogResourceManager();
331
332    HRESULT     OnCreateDevice( LPDIRECT3DDEVICE9 pd3dDevice );
333    HRESULT     OnResetDevice();
334    void        OnLostDevice();
335    void        OnDestroyDevice();
336    bool        MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
337   
338    int AddFont( LPCWSTR strFaceName, LONG height, LONG weight );
339    int AddTexture( LPCWSTR strFilename );
340    int AddTexture( LPCWSTR strResourceName, HMODULE hResourceModule );
341
342    DXUTFontNode*     GetFontNode( int iIndex )     { return m_FontCache.GetAt( iIndex ); };
343    DXUTTextureNode*  GetTextureNode( int iIndex )  { return m_TextureCache.GetAt( iIndex ); };
344    IDirect3DDevice9* GetD3DDevice()                { return m_pd3dDevice; }
345
346    bool RegisterDialog( CDXUTDialog *pDialog );
347    void UnregisterDialog( CDXUTDialog *pDialog );
348    void EnableKeyboardInputForAllDialogs();
349
350    // Shared between all dialogs
351    IDirect3DStateBlock9* m_pStateBlock;
352    ID3DXSprite*          m_pSprite;          // Sprite used for drawing
353
354    CGrowableArray< CDXUTDialog* > m_Dialogs;            // Dialogs registered
355
356protected:
357    CGrowableArray< DXUTTextureNode* > m_TextureCache;   // Shared textures
358    CGrowableArray< DXUTFontNode* > m_FontCache;         // Shared fonts
359
360    IDirect3DDevice9* m_pd3dDevice;
361
362    // Resource creation helpers
363    HRESULT CreateFont( UINT index );
364    HRESULT CreateTexture( UINT index );
365};
366
367
368//-----------------------------------------------------------------------------
369// Base class for controls
370//-----------------------------------------------------------------------------
371class CDXUTControl
372{
373public:
374    CDXUTControl( CDXUTDialog *pDialog = NULL );
375    virtual ~CDXUTControl();
376
377    virtual HRESULT OnInit() { return S_OK; }
378    virtual void Refresh();
379    virtual void Render( IDirect3DDevice9* pd3dDevice, float fElapsedTime ) { };
380
381    // Windows message handler
382    virtual bool MsgProc( UINT uMsg, WPARAM wParam, LPARAM lParam ) { return false; }
383
384    virtual bool HandleKeyboard( UINT uMsg, WPARAM wParam, LPARAM lParam ) { return false; }
385    virtual bool HandleMouse( UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam ) { return false; }
386
387    virtual bool CanHaveFocus() { return false; }
388    virtual void OnFocusIn() { m_bHasFocus = true; }
389    virtual void OnFocusOut() { m_bHasFocus = false; }
390    virtual void OnMouseEnter() { m_bMouseOver = true; }
391    virtual void OnMouseLeave() { m_bMouseOver = false; }
392    virtual void OnHotkey() {}
393
394    virtual BOOL ContainsPoint( POINT pt ) { return PtInRect( &m_rcBoundingBox, pt ); }
395
396    virtual void SetEnabled( bool bEnabled ) { m_bEnabled = bEnabled; }
397    virtual bool GetEnabled() { return m_bEnabled; }
398    virtual void SetVisible( bool bVisible ) { m_bVisible = bVisible; }
399    virtual bool GetVisible() { return m_bVisible; }
400
401    UINT GetType() const { return m_Type; }
402
403    int  GetID() const { return m_ID; }
404    void SetID( int ID ) { m_ID = ID; }
405
406    void SetLocation( int x, int y ) { m_x = x; m_y = y; UpdateRects(); }
407    void SetSize( int width, int height ) { m_width = width; m_height = height; UpdateRects(); }
408
409    void SetHotkey( UINT nHotkey ) { m_nHotkey = nHotkey; }
410    UINT GetHotkey() { return m_nHotkey; }
411
412    void SetUserData( void *pUserData ) { m_pUserData = pUserData; }
413    void *GetUserData() const { return m_pUserData; }
414
415    virtual void SetTextColor( D3DCOLOR Color );
416    CDXUTElement* GetElement( UINT iElement ) { return m_Elements.GetAt( iElement ); }
417    HRESULT SetElement( UINT iElement, CDXUTElement* pElement);
418
419    bool m_bVisible;                // Shown/hidden flag
420    bool m_bMouseOver;              // Mouse pointer is above control
421    bool m_bHasFocus;               // Control has input focus
422    bool m_bIsDefault;              // Is the default control
423
424    // Size, scale, and positioning members
425    int m_x, m_y;
426    int m_width, m_height;
427
428    // These members are set by the container
429    CDXUTDialog* m_pDialog;    // Parent container
430    UINT m_Index;              // Index within the control list
431   
432    CGrowableArray< CDXUTElement* > m_Elements;  // All display elements
433
434protected:
435    virtual void UpdateRects();
436
437    int  m_ID;                 // ID number
438    DXUT_CONTROL_TYPE m_Type;  // Control type, set once in constructor 
439    UINT m_nHotkey;            // Virtual key code for this control's hotkey
440    void *m_pUserData;         // Data associated with this control that is set by user.
441   
442    bool m_bEnabled;           // Enabled/disabled flag
443   
444    RECT m_rcBoundingBox;      // Rectangle defining the active region of the control
445};
446
447
448//-----------------------------------------------------------------------------
449// Contains all the display information for a given control type
450//-----------------------------------------------------------------------------
451struct DXUTElementHolder
452{
453    UINT nControlType;
454    UINT iElement;
455
456    CDXUTElement Element;
457};
458
459
460//-----------------------------------------------------------------------------
461// Static control
462//-----------------------------------------------------------------------------
463class CDXUTStatic : public CDXUTControl
464{
465public:
466    CDXUTStatic( CDXUTDialog *pDialog = NULL );
467
468    virtual void Render( IDirect3DDevice9* pd3dDevice, float fElapsedTime );
469    virtual BOOL ContainsPoint( POINT pt ) { return false; }
470
471    HRESULT GetTextCopy( LPWSTR strDest, UINT bufferCount );
472    LPCWSTR GetText() { return m_strText; }
473    HRESULT SetText( LPCWSTR strText );
474
475
476protected:
477    WCHAR m_strText[MAX_PATH];      // Window text 
478};
479
480
481//-----------------------------------------------------------------------------
482// Button control
483//-----------------------------------------------------------------------------
484class CDXUTButton : public CDXUTStatic
485{
486public:
487    CDXUTButton( CDXUTDialog *pDialog = NULL );
488
489    virtual bool HandleKeyboard( UINT uMsg, WPARAM wParam, LPARAM lParam );
490    virtual bool HandleMouse( UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam );
491    virtual void OnHotkey() { if( m_pDialog->IsKeyboardInputEnabled() ) m_pDialog->RequestFocus( this ); m_pDialog->SendEvent( EVENT_BUTTON_CLICKED, true, this ); }
492   
493    virtual BOOL ContainsPoint( POINT pt ) { return PtInRect( &m_rcBoundingBox, pt ); }
494    virtual bool CanHaveFocus() { return (m_bVisible && m_bEnabled); }
495
496    virtual void Render( IDirect3DDevice9* pd3dDevice, float fElapsedTime );
497
498protected:
499    bool m_bPressed;
500};
501
502
503//-----------------------------------------------------------------------------
504// CheckBox control
505//-----------------------------------------------------------------------------
506class CDXUTCheckBox : public CDXUTButton
507{
508public:
509    CDXUTCheckBox( CDXUTDialog *pDialog = NULL );
510
511    virtual bool HandleKeyboard( UINT uMsg, WPARAM wParam, LPARAM lParam );
512    virtual bool HandleMouse( UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam );
513    virtual void OnHotkey() { if( m_pDialog->IsKeyboardInputEnabled() ) m_pDialog->RequestFocus( this ); SetCheckedInternal( !m_bChecked, true ); }
514
515    virtual BOOL ContainsPoint( POINT pt );
516    virtual void UpdateRects();
517
518    virtual void Render( IDirect3DDevice9* pd3dDevice, float fElapsedTime );
519
520    bool GetChecked() { return m_bChecked; }
521    void SetChecked( bool bChecked ) { SetCheckedInternal( bChecked, false ); }
522   
523protected:
524    virtual void SetCheckedInternal( bool bChecked, bool bFromInput );
525
526    bool m_bChecked;
527    RECT m_rcButton;
528    RECT m_rcText;
529};
530
531
532//-----------------------------------------------------------------------------
533// RadioButton control
534//-----------------------------------------------------------------------------
535class CDXUTRadioButton : public CDXUTCheckBox
536{
537public:
538    CDXUTRadioButton( CDXUTDialog *pDialog = NULL );
539
540    virtual bool HandleKeyboard( UINT uMsg, WPARAM wParam, LPARAM lParam );
541    virtual bool HandleMouse( UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam );
542    virtual void OnHotkey() { if( m_pDialog->IsKeyboardInputEnabled() ) m_pDialog->RequestFocus( this ); SetCheckedInternal( true, true, true ); }
543   
544    void SetChecked( bool bChecked, bool bClearGroup=true ) { SetCheckedInternal( bChecked, bClearGroup, false ); }
545    void SetButtonGroup( UINT nButtonGroup ) { m_nButtonGroup = nButtonGroup; }
546    UINT GetButtonGroup() { return m_nButtonGroup; }
547   
548protected:
549    virtual void SetCheckedInternal( bool bChecked, bool bClearGroup, bool bFromInput );
550    UINT m_nButtonGroup;
551};
552
553
554//-----------------------------------------------------------------------------
555// Scrollbar control
556//-----------------------------------------------------------------------------
557class CDXUTScrollBar : public CDXUTControl
558{
559public:
560    CDXUTScrollBar( CDXUTDialog *pDialog = NULL );
561    virtual ~CDXUTScrollBar();
562
563    virtual bool    HandleKeyboard( UINT uMsg, WPARAM wParam, LPARAM lParam );
564    virtual bool    HandleMouse( UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam );
565    virtual bool    MsgProc( UINT uMsg, WPARAM wParam, LPARAM lParam );
566
567    virtual void    Render( IDirect3DDevice9* pd3dDevice, float fElapsedTime );
568    virtual void    UpdateRects();
569
570    void SetTrackRange( int nStart, int nEnd );
571    int GetTrackPos() { return m_nPosition; }
572    void SetTrackPos( int nPosition ) { m_nPosition = nPosition; Cap(); UpdateThumbRect(); }
573    int GetPageSize() { return m_nPageSize; }
574    void SetPageSize( int nPageSize ) { m_nPageSize = nPageSize; Cap(); UpdateThumbRect(); }
575
576    void Scroll( int nDelta );    // Scroll by nDelta items (plus or minus)
577    void ShowItem( int nIndex );  // Ensure that item nIndex is displayed, scroll if necessary
578
579protected:
580    // ARROWSTATE indicates the state of the arrow buttons.
581    // CLEAR            No arrow is down.
582    // CLICKED_UP       Up arrow is clicked.
583    // CLICKED_DOWN     Down arrow is clicked.
584    // HELD_UP          Up arrow is held down for sustained period.
585    // HELD_DOWN        Down arrow is held down for sustained period.
586    enum ARROWSTATE { CLEAR, CLICKED_UP, CLICKED_DOWN, HELD_UP, HELD_DOWN };
587
588    void UpdateThumbRect();
589    void Cap();  // Clips position at boundaries. Ensures it stays within legal range.
590
591    bool m_bShowThumb;
592    bool m_bDrag;
593    RECT m_rcUpButton;
594    RECT m_rcDownButton;
595    RECT m_rcTrack;
596    RECT m_rcThumb;
597    int m_nPosition;  // Position of the first displayed item
598    int m_nPageSize;  // How many items are displayable in one page
599    int m_nStart;     // First item
600    int m_nEnd;       // The index after the last item
601    POINT m_LastMouse;// Last mouse position
602    ARROWSTATE m_Arrow; // State of the arrows
603    double m_dArrowTS;  // Timestamp of last arrow event.
604};
605
606
607//-----------------------------------------------------------------------------
608// ListBox control
609//-----------------------------------------------------------------------------
610struct DXUTListBoxItem
611{
612    WCHAR strText[256];
613    void*  pData;
614
615    RECT  rcActive;
616    bool  bSelected;
617};
618
619class CDXUTListBox : public CDXUTControl
620{
621public:
622    CDXUTListBox( CDXUTDialog *pDialog = NULL );
623    virtual ~CDXUTListBox();
624
625    virtual HRESULT OnInit() { return m_pDialog->InitControl( &m_ScrollBar ); }
626    virtual bool    CanHaveFocus() { return (m_bVisible && m_bEnabled); }
627    virtual bool    HandleKeyboard( UINT uMsg, WPARAM wParam, LPARAM lParam );
628    virtual bool    HandleMouse( UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam );
629    virtual bool    MsgProc( UINT uMsg, WPARAM wParam, LPARAM lParam );
630
631    virtual void    Render( IDirect3DDevice9* pd3dDevice, float fElapsedTime );
632    virtual void    UpdateRects();
633
634    DWORD GetStyle() const { return m_dwStyle; }
635    int GetSize() const { return m_Items.GetSize(); }
636    void SetStyle( DWORD dwStyle ) { m_dwStyle = dwStyle; }
637    int  GetScrollBarWidth() const { return m_nSBWidth; }
638    void SetScrollBarWidth( int nWidth ) { m_nSBWidth = nWidth; UpdateRects(); }
639    void SetBorder( int nBorder, int nMargin ) { m_nBorder = nBorder; m_nMargin = nMargin; }
640    HRESULT AddItem( const WCHAR *wszText, void *pData );
641    HRESULT InsertItem( int nIndex, const WCHAR *wszText, void *pData );
642    void RemoveItem( int nIndex );
643    void RemoveItemByText( WCHAR *wszText );
644    void RemoveItemByData( void *pData );
645    void RemoveAllItems();
646
647    DXUTListBoxItem *GetItem( int nIndex );
648    int GetSelectedIndex( int nPreviousSelected = -1 );
649    DXUTListBoxItem *GetSelectedItem( int nPreviousSelected = -1 ) { return GetItem( GetSelectedIndex( nPreviousSelected ) ); }
650    void SelectItem( int nNewIndex );
651
652    enum STYLE { MULTISELECTION = 1 };
653
654protected:
655    RECT m_rcText;      // Text rendering bound
656    RECT m_rcSelection; // Selection box bound
657    CDXUTScrollBar m_ScrollBar;
658    int m_nSBWidth;
659    int m_nBorder;
660    int m_nMargin;
661    int m_nTextHeight;  // Height of a single line of text
662    DWORD m_dwStyle;    // List box style
663    int m_nSelected;    // Index of the selected item for single selection list box
664    int m_nSelStart;    // Index of the item where selection starts (for handling multi-selection)
665    bool m_bDrag;       // Whether the user is dragging the mouse to select
666
667    CGrowableArray< DXUTListBoxItem* > m_Items;
668};
669
670
671//-----------------------------------------------------------------------------
672// ComboBox control
673//-----------------------------------------------------------------------------
674struct DXUTComboBoxItem
675{
676    WCHAR strText[256];
677    void*  pData;
678
679    RECT  rcActive;
680    bool  bVisible;
681};
682
683
684class CDXUTComboBox : public CDXUTButton
685{
686public:
687    CDXUTComboBox( CDXUTDialog *pDialog = NULL );
688    virtual ~CDXUTComboBox();
689   
690    virtual void SetTextColor( D3DCOLOR Color );
691    virtual HRESULT OnInit() { return m_pDialog->InitControl( &m_ScrollBar ); }
692
693    virtual bool HandleKeyboard( UINT uMsg, WPARAM wParam, LPARAM lParam );
694    virtual bool HandleMouse( UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam );
695    virtual void OnHotkey();
696
697    virtual bool CanHaveFocus() { return (m_bVisible && m_bEnabled); }
698    virtual void OnFocusOut();
699    virtual void Render( IDirect3DDevice9* pd3dDevice, float fElapsedTime );
700
701    virtual void UpdateRects();
702
703    HRESULT AddItem( const WCHAR* strText, void* pData );
704    void    RemoveAllItems();
705    void    RemoveItem( UINT index );
706    bool    ContainsItem( const WCHAR* strText, UINT iStart=0 );
707    int     FindItem( const WCHAR* strText, UINT iStart=0 );
708    void*   GetItemData( const WCHAR* strText );
709    void*   GetItemData( int nIndex );
710    void    SetDropHeight( UINT nHeight ) { m_nDropHeight = nHeight; UpdateRects(); }
711    int     GetScrollBarWidth() const { return m_nSBWidth; }
712    void    SetScrollBarWidth( int nWidth ) { m_nSBWidth = nWidth; UpdateRects(); }
713
714    void*   GetSelectedData();
715    DXUTComboBoxItem* GetSelectedItem();
716
717    UINT    GetNumItems() { return m_Items.GetSize(); }
718    DXUTComboBoxItem* GetItem( UINT index ) { return m_Items.GetAt( index ); }
719
720    HRESULT SetSelectedByIndex( UINT index );
721    HRESULT SetSelectedByText( const WCHAR* strText );
722    HRESULT SetSelectedByData( void* pData ); 
723
724protected:
725    int     m_iSelected;
726    int     m_iFocused;
727    int     m_nDropHeight;
728    CDXUTScrollBar m_ScrollBar;
729    int     m_nSBWidth;
730
731    bool    m_bOpened;
732
733    RECT m_rcText;
734    RECT m_rcButton;
735    RECT m_rcDropdown;
736    RECT m_rcDropdownText;
737
738   
739    CGrowableArray< DXUTComboBoxItem* > m_Items;
740};
741
742
743//-----------------------------------------------------------------------------
744// Slider control
745//-----------------------------------------------------------------------------
746class CDXUTSlider : public CDXUTControl
747{
748public:
749    CDXUTSlider( CDXUTDialog *pDialog = NULL );
750
751    virtual BOOL ContainsPoint( POINT pt );
752    virtual bool CanHaveFocus() { return (m_bVisible && m_bEnabled); }
753    virtual bool HandleKeyboard( UINT uMsg, WPARAM wParam, LPARAM lParam );
754    virtual bool HandleMouse( UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam );
755   
756    virtual void UpdateRects();
757
758    virtual void Render( IDirect3DDevice9* pd3dDevice, float fElapsedTime );
759
760    void SetValue( int nValue ) { SetValueInternal( nValue, false ); }
761    int  GetValue() const { return m_nValue; };
762
763    void GetRange( int &nMin, int &nMax ) const { nMin = m_nMin; nMax = m_nMax; }
764    void SetRange( int nMin, int nMax );
765
766protected:
767    void SetValueInternal( int nValue, bool bFromInput );
768    int  ValueFromPos( int x );
769
770    int m_nValue;
771
772    int m_nMin;
773    int m_nMax;
774
775    int m_nDragX;      // Mouse position at start of drag
776    int m_nDragOffset; // Drag offset from the center of the button
777    int m_nButtonX;
778
779    bool m_bPressed;
780    RECT m_rcButton;
781};
782
783
784//-----------------------------------------------------------------------------
785// CUniBuffer class for the edit control
786//-----------------------------------------------------------------------------
787class CUniBuffer
788{
789public:
790    CUniBuffer( int nInitialSize = 1 );
791    ~CUniBuffer();
792
793    static void Initialize();
794    static void Uninitialize();
795
796    int  GetBufferSize() { return m_nBufferSize; }
797    bool SetBufferSize( int nSize );
798    int  GetTextSize()  { return lstrlenW( m_pwszBuffer ); }
799    const WCHAR* GetBuffer() { return m_pwszBuffer; }
800    const WCHAR& operator[]( int n ) const { return m_pwszBuffer[n]; }
801    WCHAR& operator[]( int n );
802    DXUTFontNode* GetFontNode() { return m_pFontNode; }
803    void SetFontNode( DXUTFontNode *pFontNode ) { m_pFontNode = pFontNode; }
804    void Clear();
805
806    bool InsertChar( int nIndex, WCHAR wChar ); // Inserts the char at specified index. If nIndex == -1, insert to the end.
807    bool RemoveChar( int nIndex );  // Removes the char at specified index. If nIndex == -1, remove the last char.
808    bool InsertString( int nIndex, const WCHAR *pStr, int nCount = -1 );  // Inserts the first nCount characters of the string pStr at specified index.  If nCount == -1, the entire string is inserted. If nIndex == -1, insert to the end.
809    bool SetText( LPCWSTR wszText );
810
811    // Uniscribe
812    HRESULT CPtoX( int nCP, BOOL bTrail, int *pX );
813    HRESULT XtoCP( int nX, int *pCP, int *pnTrail );
814    void GetPriorItemPos( int nCP, int *pPrior );
815    void GetNextItemPos( int nCP, int *pPrior );
816
817private:
818    HRESULT Analyse();      // Uniscribe -- Analyse() analyses the string in the buffer
819
820    WCHAR* m_pwszBuffer;    // Buffer to hold text
821    int    m_nBufferSize;   // Size of the buffer allocated, in characters
822
823    // Uniscribe-specific
824    DXUTFontNode* m_pFontNode;          // Font node for the font that this buffer uses
825    bool m_bAnalyseRequired;            // True if the string has changed since last analysis.
826    SCRIPT_STRING_ANALYSIS m_Analysis;  // Analysis for the current string
827
828private:
829    // Empty implementation of the Uniscribe API
830    static HRESULT WINAPI Dummy_ScriptApplyDigitSubstitution( const SCRIPT_DIGITSUBSTITUTE*, SCRIPT_CONTROL*, SCRIPT_STATE* ) { return E_NOTIMPL; }
831    static HRESULT WINAPI Dummy_ScriptStringAnalyse( HDC, const void *, int, int, int, DWORD, int, SCRIPT_CONTROL*, SCRIPT_STATE*, const int*, SCRIPT_TABDEF*, const BYTE*, SCRIPT_STRING_ANALYSIS* ) { return E_NOTIMPL; }
832    static HRESULT WINAPI Dummy_ScriptStringCPtoX( SCRIPT_STRING_ANALYSIS, int, BOOL, int* ) { return E_NOTIMPL; }
833    static HRESULT WINAPI Dummy_ScriptStringXtoCP( SCRIPT_STRING_ANALYSIS, int, int*, int* ) { return E_NOTIMPL; }
834    static HRESULT WINAPI Dummy_ScriptStringFree( SCRIPT_STRING_ANALYSIS* ) { return E_NOTIMPL; }
835    static const SCRIPT_LOGATTR* WINAPI Dummy_ScriptString_pLogAttr( SCRIPT_STRING_ANALYSIS ) { return NULL; }
836    static const int* WINAPI Dummy_ScriptString_pcOutChars( SCRIPT_STRING_ANALYSIS ) { return NULL; }
837
838    // Function pointers
839    static HRESULT (WINAPI *_ScriptApplyDigitSubstitution)( const SCRIPT_DIGITSUBSTITUTE*, SCRIPT_CONTROL*, SCRIPT_STATE* );
840    static HRESULT (WINAPI *_ScriptStringAnalyse)( HDC, const void *, int, int, int, DWORD, int, SCRIPT_CONTROL*, SCRIPT_STATE*, const int*, SCRIPT_TABDEF*, const BYTE*, SCRIPT_STRING_ANALYSIS* );
841    static HRESULT (WINAPI *_ScriptStringCPtoX)( SCRIPT_STRING_ANALYSIS, int, BOOL, int* );
842    static HRESULT (WINAPI *_ScriptStringXtoCP)( SCRIPT_STRING_ANALYSIS, int, int*, int* );
843    static HRESULT (WINAPI *_ScriptStringFree)( SCRIPT_STRING_ANALYSIS* );
844    static const SCRIPT_LOGATTR* (WINAPI *_ScriptString_pLogAttr)( SCRIPT_STRING_ANALYSIS );
845    static const int* (WINAPI *_ScriptString_pcOutChars)( SCRIPT_STRING_ANALYSIS );
846
847    static HINSTANCE s_hDll;  // Uniscribe DLL handle
848
849};
850
851//-----------------------------------------------------------------------------
852// EditBox control
853//-----------------------------------------------------------------------------
854class CDXUTEditBox : public CDXUTControl
855{
856public:
857    CDXUTEditBox( CDXUTDialog *pDialog = NULL );
858    virtual ~CDXUTEditBox();
859
860    virtual bool HandleKeyboard( UINT uMsg, WPARAM wParam, LPARAM lParam );
861    virtual bool HandleMouse( UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam );
862    virtual bool MsgProc( UINT uMsg, WPARAM wParam, LPARAM lParam );
863    virtual void UpdateRects();
864    virtual bool CanHaveFocus() { return (m_bVisible && m_bEnabled); }
865    virtual void Render( IDirect3DDevice9* pd3dDevice, float fElapsedTime );
866    virtual void OnFocusIn();
867
868    void SetText( LPCWSTR wszText, bool bSelected = false );
869    LPCWSTR GetText() { return m_Buffer.GetBuffer(); }
870    int GetTextLength() { return m_Buffer.GetTextSize(); }  // Returns text length in chars excluding NULL.
871    HRESULT GetTextCopy( LPWSTR strDest, UINT bufferCount );
872    void ClearText();
873    virtual void SetTextColor( D3DCOLOR Color ) { m_TextColor = Color; }  // Text color
874    void SetSelectedTextColor( D3DCOLOR Color ) { m_SelTextColor = Color; }  // Selected text color
875    void SetSelectedBackColor( D3DCOLOR Color ) { m_SelBkColor = Color; }  // Selected background color
876    void SetCaretColor( D3DCOLOR Color ) { m_CaretColor = Color; }  // Caret color
877    void SetBorderWidth( int nBorder ) { m_nBorder = nBorder; UpdateRects(); }  // Border of the window
878    void SetSpacing( int nSpacing ) { m_nSpacing = nSpacing; UpdateRects(); }
879    void ParseFloatArray( float *pNumbers, int nCount );
880    void SetTextFloatArray( const float *pNumbers, int nCount );
881
882protected:
883    void PlaceCaret( int nCP );
884    void DeleteSelectionText();
885    void ResetCaretBlink();
886    void CopyToClipboard();
887    void PasteFromClipboard();
888
889    CUniBuffer m_Buffer;     // Buffer to hold text
890    int      m_nBorder;      // Border of the window
891    int      m_nSpacing;     // Spacing between the text and the edge of border
892    RECT     m_rcText;       // Bounding rectangle for the text
893    RECT     m_rcRender[9];  // Convenient rectangles for rendering elements
894    double   m_dfBlink;      // Caret blink time in milliseconds
895    double   m_dfLastBlink;  // Last timestamp of caret blink
896    bool     m_bCaretOn;     // Flag to indicate whether caret is currently visible
897    int      m_nCaret;       // Caret position, in characters
898    bool     m_bInsertMode;  // If true, control is in insert mode. Else, overwrite mode.
899    int      m_nSelStart;    // Starting position of the selection. The caret marks the end.
900    int      m_nFirstVisible;// First visible character in the edit control
901    D3DCOLOR m_TextColor;    // Text color
902    D3DCOLOR m_SelTextColor; // Selected text color
903    D3DCOLOR m_SelBkColor;   // Selected background color
904    D3DCOLOR m_CaretColor;   // Caret color
905
906    // Mouse-specific
907    bool m_bMouseDrag;       // True to indicate drag in progress
908
909    // Static
910    static bool s_bHideCaret;   // If true, we don't render the caret.
911};
912
913
914//-----------------------------------------------------------------------------
915// IME-enabled EditBox control
916//-----------------------------------------------------------------------------
917#define MAX_CANDLIST 10
918#define MAX_COMPSTRING_SIZE 256
919
920class CDXUTIMEEditBox : public CDXUTEditBox
921{
922protected:
923    // Empty implementation of the IMM32 API
924    static INPUTCONTEXT* WINAPI Dummy_ImmLockIMC( HIMC ) { return NULL; }
925    static BOOL WINAPI Dummy_ImmUnlockIMC( HIMC ) { return FALSE; }
926    static LPVOID WINAPI Dummy_ImmLockIMCC( HIMCC ) { return NULL; }
927    static BOOL WINAPI Dummy_ImmUnlockIMCC( HIMCC ) { return FALSE; }
928    static BOOL WINAPI Dummy_ImmDisableTextFrameService( DWORD ) { return TRUE; }
929    static LONG WINAPI Dummy_ImmGetCompositionStringW( HIMC, DWORD, LPVOID, DWORD ) { return IMM_ERROR_GENERAL; }
930    static DWORD WINAPI Dummy_ImmGetCandidateListW( HIMC, DWORD, LPCANDIDATELIST, DWORD ) { return 0; }
931    static HIMC WINAPI Dummy_ImmGetContext( HWND ) { return NULL; }
932    static BOOL WINAPI Dummy_ImmReleaseContext( HWND, HIMC ) { return FALSE; }
933    static HIMC WINAPI Dummy_ImmAssociateContext( HWND, HIMC ) { return NULL; }
934    static BOOL WINAPI Dummy_ImmGetOpenStatus( HIMC ) { return 0; }
935    static BOOL WINAPI Dummy_ImmSetOpenStatus( HIMC, BOOL ) { return 0; }
936    static BOOL WINAPI Dummy_ImmGetConversionStatus( HIMC, LPDWORD, LPDWORD ) { return 0; }
937    static HWND WINAPI Dummy_ImmGetDefaultIMEWnd( HWND ) { return NULL; }
938    static UINT WINAPI Dummy_ImmGetIMEFileNameA( HKL, LPSTR, UINT ) { return 0; }
939    static UINT WINAPI Dummy_ImmGetVirtualKey( HWND ) { return 0; }
940    static BOOL WINAPI Dummy_ImmNotifyIME( HIMC, DWORD, DWORD, DWORD ) { return FALSE; }
941    static BOOL WINAPI Dummy_ImmSetConversionStatus( HIMC, DWORD, DWORD ) { return FALSE; }
942    static BOOL WINAPI Dummy_ImmSimulateHotKey( HWND, DWORD ) { return FALSE; }
943    static BOOL WINAPI Dummy_ImmIsIME( HKL ) { return FALSE; }
944
945    // Traditional Chinese IME
946    static UINT WINAPI Dummy_GetReadingString( HIMC, UINT, LPWSTR, PINT, BOOL*, PUINT ) { return 0; }
947    static BOOL WINAPI Dummy_ShowReadingWindow( HIMC, BOOL ) { return FALSE; }
948
949    // Verion library imports
950    static BOOL APIENTRY Dummy_VerQueryValueA( const LPVOID, LPSTR, LPVOID *, PUINT ) { return 0; }
951    static BOOL APIENTRY Dummy_GetFileVersionInfoA( LPSTR, DWORD, DWORD, LPVOID ) { return 0; }
952    static DWORD APIENTRY Dummy_GetFileVersionInfoSizeA( LPSTR, LPDWORD ) { return 0; }
953
954    // Function pointers: IMM32
955    static INPUTCONTEXT* (WINAPI * _ImmLockIMC)( HIMC );
956    static BOOL (WINAPI * _ImmUnlockIMC)( HIMC );
957    static LPVOID (WINAPI * _ImmLockIMCC)( HIMCC );
958    static BOOL (WINAPI * _ImmUnlockIMCC)( HIMCC );
959    static BOOL (WINAPI * _ImmDisableTextFrameService)( DWORD );
960    static LONG (WINAPI * _ImmGetCompositionStringW)( HIMC, DWORD, LPVOID, DWORD );
961    static DWORD (WINAPI * _ImmGetCandidateListW)( HIMC, DWORD, LPCANDIDATELIST, DWORD );
962    static HIMC (WINAPI * _ImmGetContext)( HWND );
963    static BOOL (WINAPI * _ImmReleaseContext)( HWND, HIMC );
964    static HIMC (WINAPI * _ImmAssociateContext)( HWND, HIMC );
965    static BOOL (WINAPI * _ImmGetOpenStatus)( HIMC );
966    static BOOL (WINAPI * _ImmSetOpenStatus)( HIMC, BOOL );
967    static BOOL (WINAPI * _ImmGetConversionStatus)( HIMC, LPDWORD, LPDWORD );
968    static HWND (WINAPI * _ImmGetDefaultIMEWnd)( HWND );
969    static UINT (WINAPI * _ImmGetIMEFileNameA)( HKL, LPSTR, UINT );
970    static UINT (WINAPI * _ImmGetVirtualKey)( HWND );
971    static BOOL (WINAPI * _ImmNotifyIME)( HIMC, DWORD, DWORD, DWORD );
972    static BOOL (WINAPI * _ImmSetConversionStatus)( HIMC, DWORD, DWORD );
973    static BOOL (WINAPI * _ImmSimulateHotKey)( HWND, DWORD );
974    static BOOL (WINAPI * _ImmIsIME)( HKL );
975
976    // Function pointers: Traditional Chinese IME
977    static UINT (WINAPI * _GetReadingString)( HIMC, UINT, LPWSTR, PINT, BOOL*, PUINT );
978    static BOOL (WINAPI * _ShowReadingWindow)( HIMC, BOOL );
979
980    // Function pointers: Verion library imports
981    static BOOL (APIENTRY * _VerQueryValueA)( const LPVOID, LPSTR, LPVOID *, PUINT );
982    static BOOL (APIENTRY * _GetFileVersionInfoA)( LPSTR, DWORD, DWORD, LPVOID );
983    static DWORD (APIENTRY * _GetFileVersionInfoSizeA)( LPSTR, LPDWORD );
984
985public:
986    CDXUTIMEEditBox( CDXUTDialog *pDialog = NULL );
987    virtual ~CDXUTIMEEditBox();
988
989    static void Initialize();
990    static void Uninitialize();
991
992    static  HRESULT StaticOnCreateDevice();
993    static  bool StaticMsgProc( UINT uMsg, WPARAM wParam, LPARAM lParam );
994
995    static  void EnableImeSystem( bool bEnable );
996
997    virtual void Render( IDirect3DDevice9* pd3dDevice, float fElapsedTime );
998    virtual bool MsgProc( UINT uMsg, WPARAM wParam, LPARAM lParam );
999    virtual bool HandleMouse( UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam );
1000    virtual void UpdateRects();
1001    virtual void OnFocusIn();
1002    virtual void OnFocusOut();
1003
1004    void PumpMessage();
1005
1006    virtual void RenderCandidateReadingWindow( IDirect3DDevice9* pd3dDevice, float fElapsedTime, bool bReading );
1007    virtual void RenderComposition( IDirect3DDevice9* pd3dDevice, float fElapsedTime );
1008    virtual void RenderIndicator( IDirect3DDevice9* pd3dDevice, float fElapsedTime );
1009
1010protected:
1011    static WORD GetLanguage() { return LOWORD( s_hklCurrent ); }
1012    static WORD GetPrimaryLanguage() { return PRIMARYLANGID( LOWORD( s_hklCurrent ) ); }
1013    static WORD GetSubLanguage() { return SUBLANGID( LOWORD( s_hklCurrent ) ); }
1014    static void SendKey( BYTE nVirtKey );
1015    static DWORD GetImeId( UINT uIndex = 0 );
1016    static void CheckInputLocale();
1017    static void CheckToggleState();
1018    static void SetupImeApi();
1019    static void ResetCompositionString();
1020    void TruncateCompString( bool bUseBackSpace = true, int iNewStrLen = 0 );
1021    void FinalizeString( bool bSend );
1022    static void GetReadingWindowOrientation( DWORD dwId );
1023    static void GetPrivateReadingString();
1024
1025    void SendCompString();
1026
1027protected:
1028    enum { INDICATOR_NON_IME, INDICATOR_CHS, INDICATOR_CHT, INDICATOR_KOREAN, INDICATOR_JAPANESE };
1029    enum IMESTATE { IMEUI_STATE_OFF, IMEUI_STATE_ON, IMEUI_STATE_ENGLISH };
1030
1031    struct CCandList
1032    {
1033        WCHAR awszCandidate[MAX_CANDLIST][256];
1034        CUniBuffer HoriCand; // Candidate list string (for horizontal candidate window)
1035        int   nFirstSelected; // First character position of the selected string in HoriCand
1036        int   nHoriSelectedLen; // Length of the selected string in HoriCand
1037        DWORD dwCount;       // Number of valid entries in the candidate list
1038        DWORD dwSelection;   // Currently selected candidate entry relative to page top
1039        DWORD dwPageSize;
1040        int   nReadingError; // Index of the error character
1041        bool  bShowWindow;   // Whether the candidate list window is visible
1042        RECT  rcCandidate;   // Candidate rectangle computed and filled each time before rendered
1043    };
1044
1045    struct CInputLocale
1046    {
1047        HKL   m_hKL;            // Keyboard layout
1048        WCHAR m_wszLangAbb[3];  // Language abbreviation
1049        WCHAR m_wszLang[64];    // Localized language name
1050    };
1051
1052    // Application-wide data
1053    static HINSTANCE s_hDllImm32;         // IMM32 DLL handle
1054    static HINSTANCE s_hDllVer;           // Version DLL handle
1055    static HIMC      s_hImcDef;           // Default input context
1056
1057    static HKL     s_hklCurrent;          // Current keyboard layout of the process
1058    static bool    s_bVerticalCand;       // Indicates that the candidates are listed vertically
1059    static LPWSTR  s_wszCurrIndicator;    // Points to an indicator string that corresponds to current input locale
1060    static WCHAR   s_aszIndicator[5][3];  // String to draw to indicate current input locale
1061    static bool    s_bInsertOnType;       // Insert the character as soon as a key is pressed (Korean behavior)
1062    static HINSTANCE s_hDllIme;           // Instance handle of the current IME module
1063    static IMESTATE  s_ImeState;          // IME global state
1064    static bool    s_bEnableImeSystem;    // Whether the IME system is active
1065    static POINT   s_ptCompString;        // Composition string position. Updated every frame.
1066    static int     s_nCompCaret;          // Caret position of the composition string
1067    static int     s_nFirstTargetConv;    // Index of the first target converted char in comp string.  If none, -1.
1068    static CUniBuffer s_CompString;       // Buffer to hold the composition string (we fix its length)
1069    static BYTE    s_abCompStringAttr[MAX_COMPSTRING_SIZE];
1070    static DWORD   s_adwCompStringClause[MAX_COMPSTRING_SIZE];
1071    static WCHAR   s_wszReadingString[32];// Used only with horizontal reading window (why?)
1072    static CCandList s_CandList;          // Data relevant to the candidate list
1073    static bool    s_bShowReadingWindow;  // Indicates whether reading window is visible
1074    static bool    s_bHorizontalReading;  // Indicates whether the reading window is vertical or horizontal
1075    static bool    s_bChineseIME;
1076    static CGrowableArray< CInputLocale > s_Locale; // Array of loaded keyboard layout on system
1077
1078    // Color of various IME elements
1079    D3DCOLOR       m_ReadingColor;        // Reading string color
1080    D3DCOLOR       m_ReadingWinColor;     // Reading window color
1081    D3DCOLOR       m_ReadingSelColor;     // Selected character in reading string
1082    D3DCOLOR       m_ReadingSelBkColor;   // Background color for selected char in reading str
1083    D3DCOLOR       m_CandidateColor;      // Candidate string color
1084    D3DCOLOR       m_CandidateWinColor;   // Candidate window color
1085    D3DCOLOR       m_CandidateSelColor;   // Selected candidate string color
1086    D3DCOLOR       m_CandidateSelBkColor; // Selected candidate background color
1087    D3DCOLOR       m_CompColor;           // Composition string color
1088    D3DCOLOR       m_CompWinColor;        // Composition string window color
1089    D3DCOLOR       m_CompCaretColor;      // Composition string caret color
1090    D3DCOLOR       m_CompTargetColor;     // Composition string target converted color
1091    D3DCOLOR       m_CompTargetBkColor;   // Composition string target converted background
1092    D3DCOLOR       m_CompTargetNonColor;  // Composition string target non-converted color
1093    D3DCOLOR       m_CompTargetNonBkColor;// Composition string target non-converted background
1094    D3DCOLOR       m_IndicatorImeColor;   // Indicator text color for IME
1095    D3DCOLOR       m_IndicatorEngColor;   // Indicator text color for English
1096    D3DCOLOR       m_IndicatorBkColor;    // Indicator text background color
1097
1098    // Edit-control-specific data
1099    int            m_nIndicatorWidth;     // Width of the indicator symbol
1100    RECT           m_rcIndicator;         // Rectangle for drawing the indicator button
1101
1102#if defined(DEBUG) || defined(_DEBUG)
1103    static bool    m_bIMEStaticMsgProcCalled;
1104#endif
1105};
1106
1107
1108
1109#endif // DXUT_GUI_H
Note: See TracBrowser for help on using the repository browser.