00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://mrpt.sourceforge.net/ | 00005 | | 00006 | Copyright (C) 2005-2010 University of Malaga | 00007 | | 00008 | This software was written by the Machine Perception and Intelligent | 00009 | Robotics Lab, University of Malaga (Spain). | 00010 | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> | 00011 | | 00012 | This file is part of the MRPT project. | 00013 | | 00014 | MRPT is free software: you can redistribute it and/or modify | 00015 | it under the terms of the GNU General Public License as published by | 00016 | the Free Software Foundation, either version 3 of the License, or | 00017 | (at your option) any later version. | 00018 | | 00019 | MRPT is distributed in the hope that it will be useful, | 00020 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 00021 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 00022 | GNU General Public License for more details. | 00023 | | 00024 | You should have received a copy of the GNU General Public License | 00025 | along with MRPT. If not, see <http://www.gnu.org/licenses/>. | 00026 | | 00027 +---------------------------------------------------------------------------+ */ 00028 #ifndef CBaseGUIWindow_H 00029 #define CBaseGUIWindow_H 00030 00031 #include <mrpt/synch.h> 00032 #include <mrpt/utils/CSerializable.h> 00033 #include <mrpt/utils/CObservable.h> 00034 #include <mrpt/utils/safe_pointers.h> 00035 #include <mrpt/gui/keycodes.h> 00036 00037 #include <mrpt/gui/link_pragmas.h> 00038 00039 00040 namespace mrpt 00041 { 00042 namespace gui 00043 { 00044 using namespace mrpt::utils; 00045 00046 class CWindowDialog; 00047 class CWindowDialogPlots; 00048 class C3DWindowDialog; 00049 00050 DEFINE_SERIALIZABLE_PRE_CUSTOM_LINKAGE( CBaseGUIWindow, GUI_IMPEXP ) 00051 00052 /** The base class for GUI window classes. 00053 * 00054 * This class can be observed (see mrpt::utils::CObserver) for the following events (see mrpt::utils::mrptEvent): 00055 * - mrpt::gui::mrptEventWindowChar 00056 * - mrpt::gui::mrptEventWindowResize 00057 * 00058 * IMPORTANTE NOTICE: Event handlers in your observer class will be invoked from the wxWidgets internal MRPT thread, 00059 * so all your code in the handler must be thread safe. 00060 * 00061 */ 00062 class GUI_IMPEXP CBaseGUIWindow : 00063 public mrpt::utils::CObject, 00064 public mrpt::utils::CObservable 00065 { 00066 // This must be added to any CSerializable derived class: 00067 DEFINE_VIRTUAL_SERIALIZABLE( CBaseGUIWindow ) 00068 00069 friend class CWindowDialog; 00070 friend class C3DWindowDialog; 00071 friend class CWindowDialogPlots; 00072 00073 private: 00074 const int m_CMD_CREATE_WIN; //!< can be 200,300,400... See WxSubsystem 00075 const int m_CMD_DESTROY_WIN; //!< can be 299,399,499... See WxSubsystem 00076 void* m_winobj_voidptr; 00077 00078 protected: 00079 synch::CSemaphore m_semThreadReady; //!< This semaphore will be signaled when the wx window is built and ready. 00080 synch::CSemaphore m_semWindowDestroyed; //!< This semaphore will be signaled when the wx window is destroyed. 00081 std::string m_caption; //!< The caption of the window 00082 void_ptr_noncopy m_hwnd; //!< The window handle 00083 00084 /* Auxiliary */ 00085 volatile bool m_keyPushed; 00086 volatile int m_keyPushedCode; 00087 volatile mrptKeyModifier m_keyPushedModifier; 00088 00089 void createWxWindow(unsigned int initialWidth, unsigned int initialHeight); //!< Must be called by child classes just within the constructor. 00090 00091 public: 00092 void * getWxObject() { return m_hwnd.get(); } //!< Read-only access to the wxDialog object. 00093 void notifyChildWindowDestruction(); //!< Called by wx main thread to set m_hwnd to NULL. 00094 void notifySemThreadReady(); //!< Called by wx main thread to signal the semaphore that the wx window is built and ready. 00095 00096 public: 00097 /** CMD_DESTROY_WIN can be 299,399,499... See WxSubsystem */ 00098 CBaseGUIWindow(void* winobj_voidptr, int CMD_CREATE_WIN, int CMD_DESTROY_WIN, const std::string &initial_caption = std::string() ); 00099 virtual ~CBaseGUIWindow(); 00100 00101 /** Returns false if the user has already closed the window. 00102 */ 00103 bool isOpen(); 00104 00105 /** Resizes the window, stretching the image to fit into the display area. 00106 */ 00107 virtual void resize( unsigned int width, unsigned int height ) = 0; 00108 00109 /** Changes the position of the window on the screen. 00110 */ 00111 virtual void setPos( int x, int y ) = 0; 00112 00113 /** Changes the window title text. 00114 */ 00115 virtual void setWindowTitle( const std::string &str )=0; 00116 00117 /** Waits for any key to be pushed on the image or the console, and returns the key code. 00118 * This method remove key strokes previous to its call, so it will always wait. To get 00119 * the latest pushed key, see 00120 * 00121 * \param ignoreControlKeys If set to false, any push of shift, cmd, control, etc... will make this method to return. 00122 * \param out_pushModifier If set to !=NULL, the modifiers of the key stroke will be saved here. 00123 * \return The virtual key code, as defined in mrptKeyCode (a replication of wxWidgets key codes). 00124 * 00125 * \sa getPushedKey, Key codes in the enum mrptKeyCode 00126 */ 00127 int waitForKey(bool ignoreControlKeys = true, mrptKeyModifier *out_pushModifier=NULL); 00128 00129 /** Returns true if a key has been pushed, without blocking waiting for a new key being pushed. 00130 * \sa waitForKey, clearKeyHitFlag 00131 */ 00132 bool keyHit() const { return m_keyPushed; } 00133 00134 /** Assure that "keyHit" will return false until the next pushed key. 00135 * \sa keyHit, waitForKey 00136 */ 00137 void clearKeyHitFlag() { m_keyPushed = false; } 00138 00139 /** Returns the latest pushed key, or 0 if there is no new key stroke. 00140 * \param out_pushModifier If set to !=NULL, the modifiers of the key stroke will be saved here. 00141 * \return The virtual key code, as defined in <mrpt/gui/keycodes.h> (a replication of wxWidgets key codes). 00142 * 00143 * \sa keyHit, waitForKey 00144 */ 00145 int getPushedKey(mrptKeyModifier *out_pushModifier=NULL); 00146 00147 00148 }; // End of class def. 00149 00150 00151 /** @name Events common to all GUI windows: 00152 @{ */ 00153 00154 /** An event sent by a window upon a char pressed by the user. 00155 * 00156 * IMPORTANTE NOTICE: Event handlers in your observer class will be invoked from the wxWidgets internal MRPT thread, 00157 * so all your code in the handler must be thread safe. 00158 */ 00159 class GUI_IMPEXP mrptEventWindowChar : public mrptEvent 00160 { 00161 protected: 00162 virtual void do_nothing() { } //!< Just to allow this class to be polymorphic 00163 public: 00164 inline mrptEventWindowChar( 00165 CBaseGUIWindow *obj, 00166 int _char_code, 00167 mrptKeyModifier _key_mod 00168 ) : source_object(obj), char_code(_char_code), key_modifiers(_key_mod) { } 00169 00170 CBaseGUIWindow *source_object; 00171 int char_code; //!< The virtual key code, as defined in <mrpt/gui/keycodes.h> (a replication of wxWidgets key codes). 00172 mrptKeyModifier key_modifiers; //!< Modifiers (Shift, Control, etc...) 00173 00174 00175 }; // End of class def. 00176 00177 /** An event sent by a window upon resize. 00178 * 00179 * IMPORTANTE NOTICE: Event handlers in your observer class will be invoked from the wxWidgets internal MRPT thread, 00180 * so all your code in the handler must be thread safe. 00181 */ 00182 class GUI_IMPEXP mrptEventWindowResize : public mrptEvent 00183 { 00184 protected: 00185 virtual void do_nothing() { } //!< Just to allow this class to be polymorphic 00186 public: 00187 inline mrptEventWindowResize( 00188 CBaseGUIWindow *obj, 00189 size_t _new_width, 00190 size_t _new_height) : source_object(obj), new_width(_new_width), new_height(_new_width) { } 00191 00192 CBaseGUIWindow *source_object; 00193 size_t new_width, new_height; 00194 00195 }; // End of class def. 00196 00197 00198 00199 /** @} */ 00200 00201 } // End of namespace 00202 00203 } // End of namespace 00204 00205 #endif
| Page generated by Doxygen 1.6.1 for MRPT 0.9.0 SVN: at Mon Jun 7 06:47:58 UTC 2010 |
