source: GTP/trunk/App/Demos/Illum/RayTraceEffects/Common/DXUTgui.h @ 755

Revision 755, 47.7 KB checked in by szirmay, 19 years ago (diff)

Added a folder remotely

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