source: GTP/trunk/App/Demos/Illum/Standalone/StochasticIteration [DirectX]/Common/DXUTgui.h @ 1808

Revision 1808, 47.4 KB checked in by szirmay, 18 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
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    void 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
322protected:
323    friend CDXUTDialogResourceManager* DXUTGetGlobalDialogResourceManager();
324    friend HRESULT DXUTInitialize3DEnvironment();
325    friend HRESULT DXUTReset3DEnvironment();
326    friend void DXUTCleanup3DEnvironment( bool bReleaseSettings );
327
328    // Use DXUTGetGlobalDialogResourceManager() to get access to the global instance
329    CDXUTDialogResourceManager();
330
331    // The sample framework uses the global instance and automatically calls the device events
332    HRESULT     OnCreateDevice( LPDIRECT3DDEVICE9 pd3dDevice );
333    HRESULT     OnResetDevice();
334    void        OnLostDevice();
335    void        OnDestroyDevice();
336
337    CGrowableArray< DXUTTextureNode* > m_TextureCache;   // Shared textures
338    CGrowableArray< DXUTFontNode* > m_FontCache;         // Shared fonts
339   
340    IDirect3DDevice9* m_pd3dDevice;
341
342    // Resource creation helpers
343    HRESULT CreateFont( UINT index );
344    HRESULT CreateTexture( UINT index );
345};
346
347CDXUTDialogResourceManager* DXUTGetGlobalDialogResourceManager();
348
349
350//-----------------------------------------------------------------------------
351// Base class for controls
352//-----------------------------------------------------------------------------
353class CDXUTControl
354{
355public:
356    CDXUTControl( CDXUTDialog *pDialog = NULL );
357    virtual ~CDXUTControl();
358
359    virtual HRESULT OnInit() { return S_OK; }
360    virtual void Refresh();
361    virtual void Render( IDirect3DDevice9* pd3dDevice, float fElapsedTime ) { };
362
363    // Windows message handler
364    virtual bool MsgProc( UINT uMsg, WPARAM wParam, LPARAM lParam ) { return false; }
365
366    virtual bool HandleKeyboard( UINT uMsg, WPARAM wParam, LPARAM lParam ) { return false; }
367    virtual bool HandleMouse( UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam ) { return false; }
368
369    virtual bool CanHaveFocus() { return false; }
370    virtual void OnFocusIn() { m_bHasFocus = true; }
371    virtual void OnFocusOut() { m_bHasFocus = false; }
372    virtual void OnMouseEnter() { m_bMouseOver = true; }
373    virtual void OnMouseLeave() { m_bMouseOver = false; }
374    virtual void OnHotkey() {}
375
376    virtual BOOL ContainsPoint( POINT pt ) { return PtInRect( &m_rcBoundingBox, pt ); }
377
378    virtual void SetEnabled( bool bEnabled ) { m_bEnabled = bEnabled; }
379    virtual bool GetEnabled() { return m_bEnabled; }
380    virtual void SetVisible( bool bVisible ) { m_bVisible = bVisible; }
381    virtual bool GetVisible() { return m_bVisible; }
382
383    UINT GetType() const { return m_Type; }
384
385    int  GetID() const { return m_ID; }
386    void SetID( int ID ) { m_ID = ID; }
387
388    void SetLocation( int x, int y ) { m_x = x; m_y = y; UpdateRects(); }
389    void SetSize( int width, int height ) { m_width = width; m_height = height; UpdateRects(); }
390
391    void SetHotkey( UINT nHotkey ) { m_nHotkey = nHotkey; }
392    UINT GetHotkey() { return m_nHotkey; }
393
394    void SetUserData( void *pUserData ) { m_pUserData = pUserData; }
395    void *GetUserData() const { return m_pUserData; }
396
397    virtual void SetTextColor( D3DCOLOR Color );
398    CDXUTElement* GetElement( UINT iElement ) { return m_Elements.GetAt( iElement ); }
399    HRESULT SetElement( UINT iElement, CDXUTElement* pElement);
400
401    bool m_bVisible;                // Shown/hidden flag
402    bool m_bMouseOver;              // Mouse pointer is above control
403    bool m_bHasFocus;               // Control has input focus
404    bool m_bIsDefault;              // Is the default control
405
406    // Size, scale, and positioning members
407    int m_x, m_y;
408    int m_width, m_height;
409
410    // These members are set by the container
411    CDXUTDialog* m_pDialog;    // Parent container
412    UINT m_Index;              // Index within the control list
413   
414    CGrowableArray< CDXUTElement* > m_Elements;  // All display elements
415
416protected:
417    virtual void UpdateRects();
418
419    int  m_ID;                 // ID number
420    DXUT_CONTROL_TYPE m_Type;  // Control type, set once in constructor 
421    UINT m_nHotkey;            // Virtual key code for this control's hotkey
422    void *m_pUserData;         // Data associated with this control that is set by user.
423   
424    bool m_bEnabled;           // Enabled/disabled flag
425   
426    RECT m_rcBoundingBox;      // Rectangle defining the active region of the control
427};
428
429
430//-----------------------------------------------------------------------------
431// Contains all the display information for a given control type
432//-----------------------------------------------------------------------------
433struct DXUTElementHolder
434{
435    UINT nControlType;
436    UINT iElement;
437
438    CDXUTElement Element;
439};
440
441
442//-----------------------------------------------------------------------------
443// Static control
444//-----------------------------------------------------------------------------
445class CDXUTStatic : public CDXUTControl
446{
447public:
448    CDXUTStatic( CDXUTDialog *pDialog = NULL );
449
450    virtual void Render( IDirect3DDevice9* pd3dDevice, float fElapsedTime );
451    virtual BOOL ContainsPoint( POINT pt ) { return false; }
452
453    HRESULT GetTextCopy( LPWSTR strDest, UINT bufferCount );
454    LPCWSTR GetText() { return m_strText; }
455    HRESULT SetText( LPCWSTR strText );
456
457
458protected:
459    WCHAR m_strText[MAX_PATH];      // Window text 
460};
461
462
463//-----------------------------------------------------------------------------
464// Button control
465//-----------------------------------------------------------------------------
466class CDXUTButton : public CDXUTStatic
467{
468public:
469    CDXUTButton( CDXUTDialog *pDialog = NULL );
470
471    virtual bool HandleKeyboard( UINT uMsg, WPARAM wParam, LPARAM lParam );
472    virtual bool HandleMouse( UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam );
473    virtual void OnHotkey() { m_pDialog->SendEvent( EVENT_BUTTON_CLICKED, true, this ); }
474   
475    virtual BOOL ContainsPoint( POINT pt ) { return PtInRect( &m_rcBoundingBox, pt ); }
476    virtual bool CanHaveFocus() { return (m_bVisible && m_bEnabled); }
477
478    virtual void Render( IDirect3DDevice9* pd3dDevice, float fElapsedTime );
479
480protected:
481    bool m_bPressed;
482};
483
484
485//-----------------------------------------------------------------------------
486// CheckBox control
487//-----------------------------------------------------------------------------
488class CDXUTCheckBox : public CDXUTButton
489{
490public:
491    CDXUTCheckBox( CDXUTDialog *pDialog = NULL );
492
493    virtual bool HandleKeyboard( UINT uMsg, WPARAM wParam, LPARAM lParam );
494    virtual bool HandleMouse( UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam );
495    virtual void OnHotkey() { SetCheckedInternal( !m_bChecked, true ); }
496
497    virtual BOOL ContainsPoint( POINT pt );
498    virtual void UpdateRects();
499
500    virtual void Render( IDirect3DDevice9* pd3dDevice, float fElapsedTime );
501
502    bool GetChecked() { return m_bChecked; }
503    void SetChecked( bool bChecked ) { SetCheckedInternal( bChecked, false ); }
504   
505protected:
506    virtual void SetCheckedInternal( bool bChecked, bool bFromInput );
507
508    bool m_bChecked;
509    RECT m_rcButton;
510    RECT m_rcText;
511};
512
513
514//-----------------------------------------------------------------------------
515// RadioButton control
516//-----------------------------------------------------------------------------
517class CDXUTRadioButton : public CDXUTCheckBox
518{
519public:
520    CDXUTRadioButton( CDXUTDialog *pDialog = NULL );
521
522    virtual bool HandleKeyboard( UINT uMsg, WPARAM wParam, LPARAM lParam );
523    virtual bool HandleMouse( UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam );
524    virtual void OnHotkey() { SetCheckedInternal( true, true, true ); }
525   
526    void SetChecked( bool bChecked, bool bClearGroup=true ) { SetCheckedInternal( bChecked, bClearGroup, false ); }
527    void SetButtonGroup( UINT nButtonGroup ) { m_nButtonGroup = nButtonGroup; }
528    UINT GetButtonGroup() { return m_nButtonGroup; }
529   
530protected:
531    virtual void SetCheckedInternal( bool bChecked, bool bClearGroup, bool bFromInput );
532    UINT m_nButtonGroup;
533};
534
535
536//-----------------------------------------------------------------------------
537// Scrollbar control
538//-----------------------------------------------------------------------------
539class CDXUTScrollBar : public CDXUTControl
540{
541public:
542    CDXUTScrollBar( CDXUTDialog *pDialog = NULL );
543    virtual ~CDXUTScrollBar();
544
545    virtual bool    HandleKeyboard( UINT uMsg, WPARAM wParam, LPARAM lParam );
546    virtual bool    HandleMouse( UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam );
547
548    virtual void Render( IDirect3DDevice9* pd3dDevice, float fElapsedTime );
549    virtual void    UpdateRects();
550
551    void SetTrackRange( int nStart, int nEnd );
552    int GetTrackPos() { return m_nPosition; }
553    void SetTrackPos( int nPosition ) { m_nPosition = nPosition; Cap(); UpdateThumbRect(); }
554    int GetPageSize() { return m_nPageSize; }
555    void SetPageSize( int nPageSize ) { m_nPageSize = nPageSize; Cap(); UpdateThumbRect(); }
556
557    void Scroll( int nDelta );    // Scroll by nDelta items (plus or minus)
558    void ShowItem( int nIndex );  // Ensure that item nIndex is displayed, scroll if necessary
559
560protected:
561    // ARROWSTATE indicates the state of the arrow buttons.
562    // CLEAR            No arrow is down.
563    // CLICKED_UP       Up arrow is clicked.
564    // CLICKED_DOWN     Down arrow is clicked.
565    // HELD_UP          Up arrow is held down for sustained period.
566    // HELD_DOWN        Down arrow is held down for sustained period.
567    enum ARROWSTATE { CLEAR, CLICKED_UP, CLICKED_DOWN, HELD_UP, HELD_DOWN };
568
569    void UpdateThumbRect();
570    void Cap();  // Clips position at boundaries. Ensures it stays within legal range.
571
572    bool m_bShowThumb;
573    RECT m_rcUpButton;
574    RECT m_rcDownButton;
575    RECT m_rcTrack;
576    RECT m_rcThumb;
577    int m_nPosition;  // Position of the first displayed item
578    int m_nPageSize;  // How many items are displayable in one page
579    int m_nStart;     // First item
580    int m_nEnd;       // The index after the last item
581    POINT m_LastMouse;// Last mouse position
582    ARROWSTATE m_Arrow; // State of the arrows
583    double m_dArrowTS;  // Timestamp of last arrow event.
584};
585
586
587//-----------------------------------------------------------------------------
588// ListBox control
589//-----------------------------------------------------------------------------
590struct DXUTListBoxItem
591{
592    WCHAR strText[256];
593    void*  pData;
594
595    RECT  rcActive;
596    bool  bSelected;
597};
598
599class CDXUTListBox : public CDXUTControl
600{
601public:
602    CDXUTListBox( CDXUTDialog *pDialog = NULL );
603    virtual ~CDXUTListBox();
604
605    virtual HRESULT OnInit() { return m_pDialog->InitControl( &m_ScrollBar ); }
606    virtual bool    CanHaveFocus() { return (m_bVisible && m_bEnabled); }
607    virtual bool    HandleKeyboard( UINT uMsg, WPARAM wParam, LPARAM lParam );
608    virtual bool    HandleMouse( UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam );
609
610    virtual void Render( IDirect3DDevice9* pd3dDevice, float fElapsedTime );
611    virtual void    UpdateRects();
612
613    DWORD GetStyle() const { return m_dwStyle; }
614    int GetSize() const { return m_Items.GetSize(); }
615    void SetStyle( DWORD dwStyle ) { m_dwStyle = dwStyle; }
616    void SetScrollBarWidth( int nWidth ) { m_nSBWidth = nWidth; UpdateRects(); }
617    void SetBorder( int nBorder, int nMargin ) { m_nBorder = nBorder; m_nMargin = nMargin; }
618    HRESULT AddItem( const WCHAR *wszText, void *pData );
619    HRESULT InsertItem( int nIndex, const WCHAR *wszText, void *pData );
620    void RemoveItem( int nIndex );
621    void RemoveItemByText( WCHAR *wszText );
622    void RemoveItemByData( void *pData );
623    void RemoveAllItems();
624
625    DXUTListBoxItem *GetItem( int nIndex );
626    int GetSelectedIndex( int nPreviousSelected = -1 );
627    DXUTListBoxItem *GetSelectedItem( int nPreviousSelected = -1 ) { return GetItem( GetSelectedIndex( nPreviousSelected ) ); }
628    void SelectItem( int nNewIndex );
629
630    enum STYLE { MULTISELECTION = 1 };
631
632protected:
633    RECT m_rcText;      // Text rendering bound
634    RECT m_rcSelection; // Selection box bound
635    CDXUTScrollBar m_ScrollBar;
636    int m_nSBWidth;
637    int m_nBorder;
638    int m_nMargin;
639    int m_nTextHeight;  // Height of a single line of text
640    DWORD m_dwStyle;    // List box style
641    int m_nSelected;    // Index of the selected item for single selection list box
642    int m_nSelStart;    // Index of the item where selection starts (for handling multi-selection)
643    bool m_bDrag;       // Whether the user is dragging the mouse to select
644
645    CGrowableArray< DXUTListBoxItem* > m_Items;
646};
647
648
649//-----------------------------------------------------------------------------
650// ComboBox control
651//-----------------------------------------------------------------------------
652struct DXUTComboBoxItem
653{
654    WCHAR strText[256];
655    void*  pData;
656
657    RECT  rcActive;
658    bool  bVisible;
659};
660
661
662class CDXUTComboBox : public CDXUTButton
663{
664public:
665    CDXUTComboBox( CDXUTDialog *pDialog = NULL );
666    virtual ~CDXUTComboBox();
667   
668    virtual void SetTextColor( D3DCOLOR Color );
669    virtual HRESULT OnInit() { return m_pDialog->InitControl( &m_ScrollBar ); }
670
671    virtual bool HandleKeyboard( UINT uMsg, WPARAM wParam, LPARAM lParam );
672    virtual bool HandleMouse( UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam );
673    virtual void OnHotkey();
674
675    virtual bool CanHaveFocus() { return (m_bVisible && m_bEnabled); }
676    virtual void OnFocusOut();
677    virtual void Render( IDirect3DDevice9* pd3dDevice, float fElapsedTime );
678
679    virtual void UpdateRects();
680
681    HRESULT AddItem( const WCHAR* strText, void* pData );
682    void    RemoveAllItems();
683    void    RemoveItem( UINT index );
684    bool    ContainsItem( const WCHAR* strText, UINT iStart=0 );
685    int     FindItem( const WCHAR* strText, UINT iStart=0 );
686    void*   GetItemData( const WCHAR* strText );
687    void*   GetItemData( int nIndex );
688    void    SetDropHeight( UINT nHeight ) { m_nDropHeight = nHeight; UpdateRects(); }
689    void    SetScrollBarWidth( int nWidth ) { m_nSBWidth = nWidth; UpdateRects(); }
690
691    void*   GetSelectedData();
692    DXUTComboBoxItem* GetSelectedItem();
693
694    UINT    GetNumItems() { return m_Items.GetSize(); }
695    DXUTComboBoxItem* GetItem( UINT index ) { return m_Items.GetAt( index ); }
696
697    HRESULT SetSelectedByIndex( UINT index );
698    HRESULT SetSelectedByText( const WCHAR* strText );
699    HRESULT SetSelectedByData( void* pData ); 
700
701protected:
702    int     m_iSelected;
703    int     m_iFocused;
704    int     m_nDropHeight;
705    CDXUTScrollBar m_ScrollBar;
706    int     m_nSBWidth;
707
708    bool    m_bOpened;
709
710    RECT m_rcText;
711    RECT m_rcButton;
712    RECT m_rcDropdown;
713    RECT m_rcDropdownText;
714
715   
716    CGrowableArray< DXUTComboBoxItem* > m_Items;
717};
718
719
720//-----------------------------------------------------------------------------
721// Slider control
722//-----------------------------------------------------------------------------
723class CDXUTSlider : public CDXUTControl
724{
725public:
726    CDXUTSlider( CDXUTDialog *pDialog = NULL );
727
728    virtual BOOL ContainsPoint( POINT pt );
729    virtual bool CanHaveFocus() { return (m_bVisible && m_bEnabled); }
730    virtual bool HandleKeyboard( UINT uMsg, WPARAM wParam, LPARAM lParam );
731    virtual bool HandleMouse( UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam );
732   
733    virtual void UpdateRects();
734
735    virtual void Render( IDirect3DDevice9* pd3dDevice, float fElapsedTime );
736
737    void SetValue( int nValue ) { SetValueInternal( nValue, false ); }
738    int  GetValue() const { return m_nValue; };
739
740    void GetRange( int &nMin, int &nMax ) const { nMin = m_nMin; nMax = m_nMax; }
741    void SetRange( int nMin, int nMax );
742
743protected:
744    void SetValueInternal( int nValue, bool bFromInput );
745    int  ValueFromPos( int x );
746
747    int m_nValue;
748
749    int m_nMin;
750    int m_nMax;
751
752    int m_nDragX;      // Mouse position at start of drag
753    int m_nDragOffset; // Drag offset from the center of the button
754    int m_nButtonX;
755
756    bool m_bPressed;
757    RECT m_rcButton;
758};
759
760
761//-----------------------------------------------------------------------------
762// EditBox control
763//-----------------------------------------------------------------------------
764#define UNISCRIBE_DLLNAME L"\\usp10.dll"
765
766#define GETPROCADDRESS( Module, APIName, Temp ) \
767    Temp = GetProcAddress( Module, #APIName ); \
768    if( Temp ) \
769        *(FARPROC*)&_##APIName = Temp
770
771#define PLACEHOLDERPROC( APIName ) \
772    _##APIName = Dummy_##APIName
773
774class CDXUTEditBox : public CDXUTControl
775{
776    friend class CExternalApiInitializer;
777
778public:
779    CDXUTEditBox( CDXUTDialog *pDialog = NULL );
780    virtual ~CDXUTEditBox();
781
782    virtual bool HandleKeyboard( UINT uMsg, WPARAM wParam, LPARAM lParam );
783    virtual bool HandleMouse( UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam );
784    virtual bool MsgProc( UINT uMsg, WPARAM wParam, LPARAM lParam );
785    virtual void UpdateRects();
786    virtual bool CanHaveFocus() { return (m_bVisible && m_bEnabled); }
787    virtual void Render( IDirect3DDevice9* pd3dDevice, float fElapsedTime );
788    virtual void    OnFocusIn();
789
790    void SetText( LPCWSTR wszText, bool bSelected = false );
791    LPCWSTR GetText() { return m_Buffer.GetBuffer(); }
792    int GetTextLength() { return m_Buffer.GetTextSize(); }  // Returns text length in chars excluding NULL.
793    HRESULT GetTextCopy( LPWSTR strDest, UINT bufferCount );
794    void ClearText();
795    virtual void SetTextColor( D3DCOLOR Color ) { m_TextColor = Color; }  // Text color
796    void SetSelectedTextColor( D3DCOLOR Color ) { m_SelTextColor = Color; }  // Selected text color
797    void SetSelectedBackColor( D3DCOLOR Color ) { m_SelBkColor = Color; }  // Selected background color
798    void SetCaretColor( D3DCOLOR Color ) { m_CaretColor = Color; }  // Caret color
799    void SetBorderWidth( int nBorder ) { m_nBorder = nBorder; UpdateRects(); }  // Border of the window
800    void SetSpacing( int nSpacing ) { m_nSpacing = nSpacing; UpdateRects(); }
801    void ParseFloatArray( float *pNumbers, int nCount );
802    void SetTextFloatArray( const float *pNumbers, int nCount );
803
804public:
805    //-----------------------------------------------------------------------------
806    // CUniBuffer class for the edit control
807    //-----------------------------------------------------------------------------
808    class CUniBuffer
809    {
810        friend class CExternalApiInitializer;
811
812        // static member
813
814        // Empty implementation of the Uniscribe API
815        static HRESULT WINAPI Dummy_ScriptApplyDigitSubstitution( const SCRIPT_DIGITSUBSTITUTE*, SCRIPT_CONTROL*, SCRIPT_STATE* ) { return E_NOTIMPL; }
816        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; }
817        static HRESULT WINAPI Dummy_ScriptStringCPtoX( SCRIPT_STRING_ANALYSIS, int, BOOL, int* ) { return E_NOTIMPL; }
818        static HRESULT WINAPI Dummy_ScriptStringXtoCP( SCRIPT_STRING_ANALYSIS, int, int*, int* ) { return E_NOTIMPL; }
819        static HRESULT WINAPI Dummy_ScriptStringFree( SCRIPT_STRING_ANALYSIS* ) { return E_NOTIMPL; }
820        static const SCRIPT_LOGATTR* WINAPI Dummy_ScriptString_pLogAttr( SCRIPT_STRING_ANALYSIS ) { return NULL; }
821        static const int* WINAPI Dummy_ScriptString_pcOutChars( SCRIPT_STRING_ANALYSIS ) { return NULL; }
822
823        // Function pointers
824        static HRESULT (WINAPI *_ScriptApplyDigitSubstitution)( const SCRIPT_DIGITSUBSTITUTE*, SCRIPT_CONTROL*, SCRIPT_STATE* );
825        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* );
826        static HRESULT (WINAPI *_ScriptStringCPtoX)( SCRIPT_STRING_ANALYSIS, int, BOOL, int* );
827        static HRESULT (WINAPI *_ScriptStringXtoCP)( SCRIPT_STRING_ANALYSIS, int, int*, int* );
828        static HRESULT (WINAPI *_ScriptStringFree)( SCRIPT_STRING_ANALYSIS* );
829        static const SCRIPT_LOGATTR* (WINAPI *_ScriptString_pLogAttr)( SCRIPT_STRING_ANALYSIS );
830        static const int* (WINAPI *_ScriptString_pcOutChars)( SCRIPT_STRING_ANALYSIS );
831
832        static void InitializeUniscribe();
833        static void UninitializeUniscribe();
834
835        static HINSTANCE s_hDll;  // Uniscribe DLL handle
836
837    // Instance data
838    private:
839        WCHAR *m_pwszBuffer;    // Buffer to hold text
840        int    m_nBufferSize;   // Size of the buffer allocated, in characters
841        // Uniscribe-specific
842        DXUTFontNode* m_pFontNode; // Font node for the font that this buffer uses
843        bool m_bAnalyseRequired;// True if the string has changed since last analysis.
844        SCRIPT_STRING_ANALYSIS m_Analysis;  // Analysis for the current string
845
846    private:
847        bool Grow( int nNewSize = -1 );
848
849        // Uniscribe -- Analyse() analyses the string in the buffer
850        HRESULT Analyse();
851
852    public:
853        CUniBuffer( int nInitialSize = 1 );
854        ~CUniBuffer();
855        int GetBufferSize() { return m_nBufferSize; }
856        bool SetBufferSize( int nSize );
857        int GetTextSize() { return lstrlenW( m_pwszBuffer ); }
858        const WCHAR *GetBuffer() { return m_pwszBuffer; }
859        const WCHAR &operator[]( int n ) const { return m_pwszBuffer[n]; }
860        WCHAR &operator[]( int n );
861        DXUTFontNode *GetFontNode() { return m_pFontNode; }
862        void SetFontNode( DXUTFontNode *pFontNode ) { m_pFontNode = pFontNode; }
863        void Clear();
864
865        // Inserts the char at specified index.
866        // If nIndex == -1, insert to the end.
867        bool InsertChar( int nIndex, WCHAR wChar );
868
869        // Removes the char at specified index.
870        // If nIndex == -1, remove the last char.
871        bool RemoveChar( int nIndex );
872
873        // Inserts the first nCount characters of the string pStr at specified index.
874        // If nCount == -1, the entire string is inserted.
875        // If nIndex == -1, insert to the end.
876        bool InsertString( int nIndex, const WCHAR *pStr, int nCount = -1 );
877
878        bool SetText( LPCWSTR wszText );
879
880        // Uniscribe
881        HRESULT CPtoX( int nCP, BOOL bTrail, int *pX );
882        HRESULT XtoCP( int nX, int *pCP, int *pnTrail );
883        void GetPriorItemPos( int nCP, int *pPrior );
884        void GetNextItemPos( int nCP, int *pPrior );
885    };
886
887protected:
888    void PlaceCaret( int nCP );
889    void DeleteSelectionText();
890    void ResetCaretBlink();
891    void CopyToClipboard();
892    void PasteFromClipboard();
893
894    CUniBuffer m_Buffer;     // Buffer to hold text
895    int      m_nBorder;      // Border of the window
896    int      m_nSpacing;     // Spacing between the text and the edge of border
897    RECT     m_rcText;       // Bounding rectangle for the text
898    RECT     m_rcRender[9];  // Convenient rectangles for rendering elements
899    double   m_dfBlink;      // Caret blink time in milliseconds
900    double   m_dfLastBlink;  // Last timestamp of caret blink
901    bool     m_bCaretOn;     // Flag to indicate whether caret is currently visible
902    int      m_nCaret;       // Caret position, in characters
903    bool     m_bInsertMode;  // If true, control is in insert mode. Else, overwrite mode.
904    int      m_nSelStart;    // Starting position of the selection. The caret marks the end.
905    int      m_nFirstVisible;// First visible character in the edit control
906    D3DCOLOR m_TextColor;    // Text color
907    D3DCOLOR m_SelTextColor; // Selected text color
908    D3DCOLOR m_SelBkColor;   // Selected background color
909    D3DCOLOR m_CaretColor;   // Caret color
910
911    // Mouse-specific
912    bool m_bMouseDrag;       // True to indicate drag in progress
913
914    // Static
915    static bool     s_bHideCaret;   // If true, we don't render the caret.
916};
917
918
919//-----------------------------------------------------------------------------
920// IME-enabled EditBox control
921//-----------------------------------------------------------------------------
922#define IMM32_DLLNAME L"\\imm32.dll"
923#define VER_DLLNAME L"\\version.dll"
924#define MAX_CANDLIST 10
925#define MAX_COMPSTRING_SIZE 256
926
927class CDXUTIMEEditBox : public CDXUTEditBox
928{
929    friend class CExternalApiInitializer;
930
931    static void InitializeImm();
932    static void UninitializeImm();
933
934    static HINSTANCE s_hDllImm32;  // IMM32 DLL handle
935    static HINSTANCE s_hDllVer;    // Version DLL handle
936    static HIMC      s_hImcDef;    // Default input context
937
938protected:
939    // Empty implementation of the IMM32 API
940    static INPUTCONTEXT* WINAPI Dummy_ImmLockIMC( HIMC ) { return NULL; }
941    static BOOL WINAPI Dummy_ImmUnlockIMC( HIMC ) { return FALSE; }
942    static LPVOID WINAPI Dummy_ImmLockIMCC( HIMCC ) { return NULL; }
943    static BOOL WINAPI Dummy_ImmUnlockIMCC( HIMCC ) { return FALSE; }
944    static BOOL WINAPI Dummy_ImmDisableTextFrameService( DWORD ) { return TRUE; }
945    static LONG WINAPI Dummy_ImmGetCompositionStringW( HIMC, DWORD, LPVOID, DWORD ) { return IMM_ERROR_GENERAL; }
946    static DWORD WINAPI Dummy_ImmGetCandidateListW( HIMC, DWORD, LPCANDIDATELIST, DWORD ) { return 0; }
947    static HIMC WINAPI Dummy_ImmGetContext( HWND ) { return NULL; }
948    static BOOL WINAPI Dummy_ImmReleaseContext( HWND, HIMC ) { return FALSE; }
949    static HIMC WINAPI Dummy_ImmAssociateContext( HWND, HIMC ) { return NULL; }
950    static BOOL WINAPI Dummy_ImmGetOpenStatus( HIMC ) { return 0; }
951    static BOOL WINAPI Dummy_ImmSetOpenStatus( HIMC, BOOL ) { return 0; }
952    static BOOL WINAPI Dummy_ImmGetConversionStatus( HIMC, LPDWORD, LPDWORD ) { return 0; }
953    static HWND WINAPI Dummy_ImmGetDefaultIMEWnd( HWND ) { return NULL; }
954    static UINT WINAPI Dummy_ImmGetIMEFileNameA( HKL, LPSTR, UINT ) { return 0; }
955    static UINT WINAPI Dummy_ImmGetVirtualKey( HWND ) { return 0; }
956    static BOOL WINAPI Dummy_ImmNotifyIME( HIMC, DWORD, DWORD, DWORD ) { return FALSE; }
957    static BOOL WINAPI Dummy_ImmSetConversionStatus( HIMC, DWORD, DWORD ) { return FALSE; }
958    static BOOL WINAPI Dummy_ImmSimulateHotKey( HWND, DWORD ) { return FALSE; }
959    static BOOL WINAPI Dummy_ImmIsIME( HKL ) { return FALSE; }
960
961    // Traditional Chinese IME
962    static UINT WINAPI Dummy_GetReadingString( HIMC, UINT, LPWSTR, PINT, BOOL*, PUINT ) { return 0; }
963    static BOOL WINAPI Dummy_ShowReadingWindow( HIMC, BOOL ) { return FALSE; }
964
965    // Verion library imports
966    static BOOL APIENTRY Dummy_VerQueryValueA( const LPVOID, LPSTR, LPVOID *, PUINT ) { return 0; }
967    static BOOL APIENTRY Dummy_GetFileVersionInfoA( LPSTR, DWORD, DWORD, LPVOID ) { return 0; }
968    static DWORD APIENTRY Dummy_GetFileVersionInfoSizeA( LPSTR, LPDWORD ) { return 0; }
969
970    // Function pointers: IMM32
971    static INPUTCONTEXT* (WINAPI * _ImmLockIMC)( HIMC );
972    static BOOL (WINAPI * _ImmUnlockIMC)( HIMC );
973    static LPVOID (WINAPI * _ImmLockIMCC)( HIMCC );
974    static BOOL (WINAPI * _ImmUnlockIMCC)( HIMCC );
975    static BOOL (WINAPI * _ImmDisableTextFrameService)( DWORD );
976    static LONG (WINAPI * _ImmGetCompositionStringW)( HIMC, DWORD, LPVOID, DWORD );
977    static DWORD (WINAPI * _ImmGetCandidateListW)( HIMC, DWORD, LPCANDIDATELIST, DWORD );
978    static HIMC (WINAPI * _ImmGetContext)( HWND );
979    static BOOL (WINAPI * _ImmReleaseContext)( HWND, HIMC );
980    static HIMC (WINAPI * _ImmAssociateContext)( HWND, HIMC );
981    static BOOL (WINAPI * _ImmGetOpenStatus)( HIMC );
982    static BOOL (WINAPI * _ImmSetOpenStatus)( HIMC, BOOL );
983    static BOOL (WINAPI * _ImmGetConversionStatus)( HIMC, LPDWORD, LPDWORD );
984    static HWND (WINAPI * _ImmGetDefaultIMEWnd)( HWND );
985    static UINT (WINAPI * _ImmGetIMEFileNameA)( HKL, LPSTR, UINT );
986    static UINT (WINAPI * _ImmGetVirtualKey)( HWND );
987    static BOOL (WINAPI * _ImmNotifyIME)( HIMC, DWORD, DWORD, DWORD );
988    static BOOL (WINAPI * _ImmSetConversionStatus)( HIMC, DWORD, DWORD );
989    static BOOL (WINAPI * _ImmSimulateHotKey)( HWND, DWORD );
990    static BOOL (WINAPI * _ImmIsIME)( HKL );
991
992    // Function pointers: Traditional Chinese IME
993    static UINT (WINAPI * _GetReadingString)( HIMC, UINT, LPWSTR, PINT, BOOL*, PUINT );
994    static BOOL (WINAPI * _ShowReadingWindow)( HIMC, BOOL );
995
996    // Function pointers: Verion library imports
997    static BOOL (APIENTRY * _VerQueryValueA)( const LPVOID, LPSTR, LPVOID *, PUINT );
998    static BOOL (APIENTRY * _GetFileVersionInfoA)( LPSTR, DWORD, DWORD, LPVOID );
999    static DWORD (APIENTRY * _GetFileVersionInfoSizeA)( LPSTR, LPDWORD );
1000
1001public:
1002    CDXUTIMEEditBox( CDXUTDialog *pDialog = NULL );
1003    virtual ~CDXUTIMEEditBox();
1004
1005    static  HRESULT StaticOnCreateDevice();
1006    static  bool StaticMsgProc( UINT uMsg, WPARAM wParam, LPARAM lParam );
1007
1008    static  void EnableImeSystem( bool bEnable );
1009
1010    virtual void Render( IDirect3DDevice9* pd3dDevice, float fElapsedTime );
1011    virtual bool MsgProc( UINT uMsg, WPARAM wParam, LPARAM lParam );
1012    virtual bool HandleMouse( UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam );
1013    virtual void UpdateRects();
1014    virtual void OnFocusIn();
1015    virtual void OnFocusOut();
1016
1017    void PumpMessage();
1018
1019    virtual void RenderCandidateReadingWindow( IDirect3DDevice9* pd3dDevice, float fElapsedTime, bool bReading );
1020    virtual void RenderComposition( IDirect3DDevice9* pd3dDevice, float fElapsedTime );
1021    virtual void RenderIndicator( IDirect3DDevice9* pd3dDevice, float fElapsedTime );
1022
1023protected:
1024    static WORD GetLanguage() { return LOWORD( s_hklCurrent ); }
1025    static WORD GetPrimaryLanguage() { return PRIMARYLANGID( LOWORD( s_hklCurrent ) ); }
1026    static WORD GetSubLanguage() { return SUBLANGID( LOWORD( s_hklCurrent ) ); }
1027    static void SendKey( BYTE nVirtKey );
1028    static DWORD GetImeId( UINT uIndex = 0 );
1029    static void CheckInputLocale();
1030    static void CheckToggleState();
1031    static void SetupImeApi();
1032    static void ResetCompositionString();
1033    void TruncateCompString( bool bUseBackSpace = true, int iNewStrLen = 0 );
1034    void FinalizeString( bool bSend );
1035    static void GetReadingWindowOrientation( DWORD dwId );
1036    static void GetPrivateReadingString();
1037
1038    void SendCompString();
1039
1040protected:
1041    enum { INDICATOR_NON_IME, INDICATOR_CHS, INDICATOR_CHT, INDICATOR_KOREAN, INDICATOR_JAPANESE };
1042    enum IMESTATE { IMEUI_STATE_OFF, IMEUI_STATE_ON, IMEUI_STATE_ENGLISH };
1043
1044    struct CCandList
1045    {
1046        WCHAR awszCandidate[MAX_CANDLIST][256];
1047        CUniBuffer HoriCand; // Candidate list string (for horizontal candidate window)
1048        int   nFirstSelected; // First character position of the selected string in HoriCand
1049        int   nHoriSelectedLen; // Length of the selected string in HoriCand
1050        DWORD dwCount;       // Number of valid entries in the candidate list
1051        DWORD dwSelection;   // Currently selected candidate entry relative to page top
1052        DWORD dwPageSize;
1053        int   nReadingError; // Index of the error character
1054        bool  bShowWindow;   // Whether the candidate list window is visible
1055        RECT  rcCandidate;   // Candidate rectangle computed and filled each time before rendered
1056    };
1057
1058    struct CInputLocale
1059    {
1060        HKL   m_hKL;            // Keyboard layout
1061        WCHAR m_wszLangAbb[3];  // Language abbreviation
1062        WCHAR m_wszLang[64];    // Localized language name
1063    };
1064
1065    // Application-wide data
1066    static HKL     s_hklCurrent;          // Current keyboard layout of the process
1067    static bool    s_bVerticalCand;       // Indicates that the candidates are listed vertically
1068    static LPWSTR  s_wszCurrIndicator;    // Points to an indicator string that corresponds to current input locale
1069    static WCHAR   s_aszIndicator[5][3];  // String to draw to indicate current input locale
1070    static bool    s_bInsertOnType;       // Insert the character as soon as a key is pressed (Korean behavior)
1071    static HINSTANCE s_hDllIme;           // Instance handle of the current IME module
1072    static IMESTATE  s_ImeState;          // IME global state
1073    static bool    s_bEnableImeSystem;    // Whether the IME system is active
1074    static POINT   s_ptCompString;        // Composition string position. Updated every frame.
1075    static int     s_nCompCaret;          // Caret position of the composition string
1076    static int     s_nFirstTargetConv;    // Index of the first target converted char in comp string.  If none, -1.
1077    static CUniBuffer s_CompString;       // Buffer to hold the composition string (we fix its length)
1078    static BYTE    s_abCompStringAttr[MAX_COMPSTRING_SIZE];
1079    static DWORD   s_adwCompStringClause[MAX_COMPSTRING_SIZE];
1080    static WCHAR   s_wszReadingString[32];// Used only with horizontal reading window (why?)
1081    static CCandList s_CandList;          // Data relevant to the candidate list
1082    static bool    s_bShowReadingWindow;  // Indicates whether reading window is visible
1083    static bool    s_bHorizontalReading;  // Indicates whether the reading window is vertical or horizontal
1084    static bool    s_bChineseIME;
1085    static CGrowableArray< CInputLocale > s_Locale; // Array of loaded keyboard layout on system
1086
1087    // Color of various IME elements
1088    D3DCOLOR       m_ReadingColor;        // Reading string color
1089    D3DCOLOR       m_ReadingWinColor;     // Reading window color
1090    D3DCOLOR       m_ReadingSelColor;     // Selected character in reading string
1091    D3DCOLOR       m_ReadingSelBkColor;   // Background color for selected char in reading str
1092    D3DCOLOR       m_CandidateColor;      // Candidate string color
1093    D3DCOLOR       m_CandidateWinColor;   // Candidate window color
1094    D3DCOLOR       m_CandidateSelColor;   // Selected candidate string color
1095    D3DCOLOR       m_CandidateSelBkColor; // Selected candidate background color
1096    D3DCOLOR       m_CompColor;           // Composition string color
1097    D3DCOLOR       m_CompWinColor;        // Composition string window color
1098    D3DCOLOR       m_CompCaretColor;      // Composition string caret color
1099    D3DCOLOR       m_CompTargetColor;     // Composition string target converted color
1100    D3DCOLOR       m_CompTargetBkColor;   // Composition string target converted background
1101    D3DCOLOR       m_CompTargetNonColor;  // Composition string target non-converted color
1102    D3DCOLOR       m_CompTargetNonBkColor;// Composition string target non-converted background
1103    D3DCOLOR       m_IndicatorImeColor;   // Indicator text color for IME
1104    D3DCOLOR       m_IndicatorEngColor;   // Indicator text color for English
1105    D3DCOLOR       m_IndicatorBkColor;    // Indicator text background color
1106
1107    // Edit-control-specific data
1108    int            m_nIndicatorWidth;     // Width of the indicator symbol
1109    RECT           m_rcIndicator;         // Rectangle for drawing the indicator button
1110};
1111
1112
1113
1114#endif // DXUT_GUI_H
Note: See TracBrowser for help on using the repository browser.