| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376 |
- /*
- ** Command & Conquer Generals Zero Hour(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- ////////////////////////////////////////////////////////////////////////////////
- // //
- // (c) 2001-2003 Electronic Arts Inc. //
- // //
- ////////////////////////////////////////////////////////////////////////////////
- // FILE: CheckBox.cpp /////////////////////////////////////////////////////////
- //-----------------------------------------------------------------------------
- //
- // Westwood Studios Pacific.
- //
- // Confidential Information
- // Copyright (C) 2001 - All Rights Reserved
- //
- //-----------------------------------------------------------------------------
- //
- // Project: RTS3
- //
- // File name: CheckBox.cpp
- //
- // Created: Colin Day, June 2001
- //
- // Desc: Checkbox GUI control
- //
- //-----------------------------------------------------------------------------
- ///////////////////////////////////////////////////////////////////////////////
- // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
- #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
- // USER INCLUDES //////////////////////////////////////////////////////////////
- #include "Common/Language.h"
- #include "GameClient/Gadget.h"
- #include "GameClient/GameWindowManager.h"
- #include "GameClient/Keyboard.h"
- // DEFINES ////////////////////////////////////////////////////////////////////
- // PRIVATE TYPES //////////////////////////////////////////////////////////////
- // PRIVATE DATA ///////////////////////////////////////////////////////////////
- // PUBLIC DATA ////////////////////////////////////////////////////////////////
- // PRIVATE PROTOTYPES /////////////////////////////////////////////////////////
- // PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////////
- // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////////
- // GadgetCheckBoxInput ========================================================
- /** Handle input for check box */
- //=============================================================================
- WindowMsgHandledType GadgetCheckBoxInput( GameWindow *window, UnsignedInt msg,
- WindowMsgData mData1, WindowMsgData mData2 )
- {
- WinInstanceData *instData = window->winGetInstanceData();
- switch( msg )
- {
- // ------------------------------------------------------------------------
- case GWM_MOUSE_ENTERING:
- {
- if( BitTest( instData->getStyle(), GWS_MOUSE_TRACK ) )
- {
- BitSet( instData->m_state, WIN_STATE_HILITED );
- TheWindowManager->winSendSystemMsg( window->winGetOwner(),
- GBM_MOUSE_ENTERING,
- (WindowMsgData)window,
- mData1 );
- //TheWindowManager->winSetFocus( window );
- } // end if
- break;
- } // end mouse entering
- // ------------------------------------------------------------------------
- case GWM_MOUSE_LEAVING:
- {
- if( BitTest( instData->getStyle(), GWS_MOUSE_TRACK ) )
- {
- BitClear( instData->m_state, WIN_STATE_HILITED );
- TheWindowManager->winSendSystemMsg( window->winGetOwner(),
- GBM_MOUSE_LEAVING,
- (WindowMsgData)window,
- mData1 );
- } // end if
- break;
- } // end mouse leaving
- // ------------------------------------------------------------------------
- case GWM_LEFT_DRAG:
- {
- TheWindowManager->winSendSystemMsg( window->winGetOwner(), GGM_LEFT_DRAG,
- (WindowMsgData)window, mData1 );
- break;
- } // end left drag
- // ------------------------------------------------------------------------
- case GWM_LEFT_DOWN:
- {
- break;
- } // end left down
- // ------------------------------------------------------------------------
- case GWM_LEFT_UP:
- {
- if( BitTest( instData->getState(), WIN_STATE_HILITED ) == FALSE )
- {
- // this up click was not meant for this button
- return MSG_IGNORED;
- }
- // Toggle the check state
- instData->m_state ^= WIN_STATE_SELECTED;
- TheWindowManager->winSendSystemMsg( window->winGetOwner(), GBM_SELECTED,
- (WindowMsgData)window, mData1 );
- break;
- } // end left up and left click
- // ------------------------------------------------------------------------
- case GWM_RIGHT_DOWN:
- {
- break;
- } // end right down
- //-------------------------------------------------------------------------
- case GWM_RIGHT_UP:
- {
- // Need to be specially marked to care about right mouse events
- if( BitTest( instData->getState(), WIN_STATE_SELECTED ) )
- {
- TheWindowManager->winSendSystemMsg( instData->getOwner(), GBM_SELECTED_RIGHT,
- (WindowMsgData)window, mData1 );
- BitClear( instData->m_state, WIN_STATE_SELECTED );
- }
- else
- {
- // this up click was not meant for this button
- return MSG_IGNORED;
- }
- break;
- } // end right up or right click
- // ------------------------------------------------------------------------
- case GWM_CHAR:
- {
- switch( mData1 )
- {
- // --------------------------------------------------------------------
- case KEY_ENTER:
- case KEY_SPACE:
- {
- if( BitTest( mData2, KEY_STATE_DOWN ) )
- {
- // Toggle the check state
- instData->m_state ^= WIN_STATE_SELECTED;
- TheWindowManager->winSendSystemMsg( window->winGetOwner(),
- GBM_SELECTED,
- (WindowMsgData)window,
- 0 );
- } //end if
- break;
- } // end enter/space
- // --------------------------------------------------------------------
- case KEY_DOWN:
- case KEY_RIGHT:
- case KEY_TAB:
- {
- if( BitTest( mData2, KEY_STATE_DOWN ) )
- TheWindowManager->winNextTab(window);
- break;
- } // end down, right, tab
- // --------------------------------------------------------------------
- case KEY_UP:
- case KEY_LEFT:
- {
- if( BitTest( mData2, KEY_STATE_DOWN ) )
- TheWindowManager->winPrevTab(window);
- break;
- } // end up, left
- // --------------------------------------------------------------------
- default:
- {
- return MSG_IGNORED;
- } // end default
- } // end switch
- break;
- } // end char msg
- // ------------------------------------------------------------------------
- default:
- {
- return MSG_IGNORED;
- } // end default
- } // end switch( msg )
- return MSG_HANDLED;
- } // end GadgetCheckBoxInput
- // GadgetCheckBoxSystem =======================================================
- /** Handle system messages for check box */
- //=============================================================================
- WindowMsgHandledType GadgetCheckBoxSystem( GameWindow *window, UnsignedInt msg,
- WindowMsgData mData1, WindowMsgData mData2 )
- {
- WinInstanceData *instData = window->winGetInstanceData();
- switch( msg )
- {
- // ------------------------------------------------------------------------
- case GGM_SET_LABEL:
- {
- window->winSetText( *(UnicodeString*)mData1 );
- break;
- }
- // ------------------------------------------------------------------------
- case GWM_CREATE:
- break;
- // ------------------------------------------------------------------------
- case GWM_DESTROY:
- break;
- // ------------------------------------------------------------------------
- case GWM_INPUT_FOCUS:
- if( mData1 == FALSE )
- BitClear( instData->m_state, WIN_STATE_HILITED );
- else
- BitSet( instData->m_state, WIN_STATE_HILITED );
- TheWindowManager->winSendSystemMsg( window->winGetOwner(),
- GGM_FOCUS_CHANGE,
- mData1,
- window->winGetWindowId() );
- if( mData1 == FALSE )
- *(Bool*)mData2 = FALSE;
- else
- *(Bool*)mData2 = TRUE;
-
- break;
- default:
- return MSG_IGNORED;
- } // end switch msg
- return MSG_HANDLED;
- } // end GadgetCheckBoxSystem
- // GadgetCheckBoxSetText ======================================================
- /** Set the text for the control */
- //=============================================================================
- void GadgetCheckBoxSetText( GameWindow *g, UnicodeString text )
- {
- // sanity
- if( g == NULL )
- return;
- TheWindowManager->winSendSystemMsg( g, GGM_SET_LABEL, (WindowMsgData)&text, 0 );
- } // end GadgetCheckBoxSetText
- // GadgetCheckBoxSetChecked ============================================
- //=============================================================================
- /** Set the check state for the check box */
- //=============================================================================
- void GadgetCheckBoxSetChecked( GameWindow *g, Bool isChecked)
- {
- WinInstanceData *instData = g->winGetInstanceData();
- if (isChecked)
- {
- BitSet(instData->m_state, WIN_STATE_SELECTED);
- }
- else
- {
- BitClear(instData->m_state, WIN_STATE_SELECTED);
- }
- TheWindowManager->winSendSystemMsg( g->winGetOwner(), GBM_SELECTED,
- (WindowMsgData)g, 0 );
- }
- // GadgetCheckBoxToggle ============================================
- //=============================================================================
- /** Toggle the check state for the check box */
- //=============================================================================
- void GadgetCheckBoxToggle( GameWindow *g)
- {
- WinInstanceData *instData = g->winGetInstanceData();
- Bool isChecked = BitTest(instData->m_state, WIN_STATE_SELECTED);
- if (isChecked)
- {
- BitClear(instData->m_state, WIN_STATE_SELECTED);
- }
- else
- {
- BitSet(instData->m_state, WIN_STATE_SELECTED);
- }
- TheWindowManager->winSendSystemMsg( g->winGetOwner(), GBM_SELECTED,
- (WindowMsgData)g, 0 );
- }
- // GadgetCheckBoxIsChecked ======================================================
- /** Check the check state */
- //=============================================================================
- Bool GadgetCheckBoxIsChecked( GameWindow *g )
- {
- WinInstanceData *instData = g->winGetInstanceData();
- return (BitTest(instData->m_state, WIN_STATE_SELECTED));
- }
|