PixelLightAPI  .
GuiApplication.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: GuiApplication.h                              *
00003  *
00004  *  Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/)
00005  *
00006  *  This file is part of PixelLight.
00007  *
00008  *  PixelLight is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU Lesser General Public License as published by
00010  *  the Free Software Foundation, either version 3 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  PixelLight is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  *  GNU Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public License
00019  *  along with PixelLight. If not, see <http://www.gnu.org/licenses/>.
00020 \*********************************************************/
00021 
00022 
00023 #ifndef __PLGUI_GUI_APPLICATION_H__
00024 #define __PLGUI_GUI_APPLICATION_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include <PLCore/Application/CoreApplication.h>
00032 #include <PLCore/Base/Event/EventHandler.h>
00033 #include "PLGui/PLGui.h"
00034 
00035 
00036 //[-------------------------------------------------------]
00037 //[ Namespace                                             ]
00038 //[-------------------------------------------------------]
00039 namespace PLGui {
00040 
00041 
00042 //[-------------------------------------------------------]
00043 //[ Forward declarations                                  ]
00044 //[-------------------------------------------------------]
00045 class Widget;
00046 
00047 
00048 //[-------------------------------------------------------]
00049 //[ Classes                                               ]
00050 //[-------------------------------------------------------]
00051 /**
00052 *  @brief
00053 *    Gui application class
00054 *
00055 *  @remarks
00056 *    An application class for a typical GUI application. Runs a
00057 *    main loop that does the necessary message processing and
00058 *    provides methods to manage a main application window.
00059 */
00060 class GuiApplication : public PLCore::CoreApplication {
00061 
00062 
00063     //[-------------------------------------------------------]
00064     //[ RTTI interface                                        ]
00065     //[-------------------------------------------------------]
00066     pl_class(PLGUI_RTTI_EXPORT, GuiApplication, "PLGui", PLCore::CoreApplication, "Gui application class")
00067         #ifdef PLGUI_EXPORTS    // The following is only required when compiling PLGui
00068             // Constructors
00069             pl_constructor_0(DefaultConstructor,    "Default constructor",  "")
00070             // Methods
00071             pl_method_0(GetMainWindow,  pl_ret_type(Widget*),               "Get the main window. Returns pointer to the main window of the application, a null pointer on error.",                     "")
00072             pl_method_1(SetMainWindow,  pl_ret_type(void),      Widget*,    "Set the main window, pointer to the main window of the application (a null pointer is also valid) as first parameter.",    "")
00073         #endif
00074     pl_class_end
00075 
00076 
00077     //[-------------------------------------------------------]
00078     //[ Public functions                                      ]
00079     //[-------------------------------------------------------]
00080     public:
00081         /**
00082         *  @brief
00083         *    Constructor
00084         *
00085         *  @param[in] sGuiFilename
00086         *    Filename of GUI to load, can be empty
00087         */
00088         PLGUI_API GuiApplication(const PLCore::String &sGuiFilename = "");
00089 
00090         /**
00091         *  @brief
00092         *    Destructor
00093         */
00094         PLGUI_API virtual ~GuiApplication();
00095 
00096         /**
00097         *  @brief
00098         *    Get main window
00099         *
00100         *  @return
00101         *    Main window, can be a null pointer
00102         */
00103         PLGUI_API Widget *GetMainWindow() const;
00104 
00105         /**
00106         *  @brief
00107         *    Set main window
00108         *
00109         *  @param[in] pMainWindow
00110         *    Pointer to the main window of the application (a null pointer is also valid)
00111         */
00112         PLGUI_API void SetMainWindow(Widget *pMainWindow);
00113 
00114 
00115     //[-------------------------------------------------------]
00116     //[ Protected virtual PLCore::AbstractLifecycle functions ]
00117     //[-------------------------------------------------------]
00118     protected:
00119         /**
00120         *  @brief
00121         *    Initialization function that is called prior to OnInit()
00122         *
00123         *  @return
00124         *    'true' if all went fine, else 'false' which will stop the application
00125         *
00126         *  @remarks
00127         *    The default implementation does the following tasks:
00128         *    - Everything that CoreApplication::OnStart() does
00129         *    - Call OnCreateMainWindow()
00130         *    - Return and go on with OnInit()
00131         */
00132         PLGUI_API virtual bool OnStart() override;
00133 
00134         /**
00135         *  @brief
00136         *    De-initialization function that is called after OnDeInit()
00137         *
00138         *  @remarks
00139         *    The default implementation does the following tasks:
00140         *    - Everything that CoreApplication::OnStop() does
00141         *    - De-initialize system GUI
00142         */
00143         PLGUI_API virtual void OnStop() override;
00144 
00145 
00146     //[-------------------------------------------------------]
00147     //[ Protected virtual PLCore::CoreApplication functions   ]
00148     //[-------------------------------------------------------]
00149     protected:
00150         /**
00151         *  @brief
00152         *    Main function
00153         *
00154         *  @remarks
00155         *    The default implementation does the following tasks:
00156         *    - Run GUI main loop (processing GUI messages)
00157         *    - Exit loop when either the GUI or the application has been stopped
00158         */
00159         PLGUI_API virtual void Main() override;
00160 
00161 
00162     //[-------------------------------------------------------]
00163     //[ Protected virtual GuiApplication functions            ]
00164     //[-------------------------------------------------------]
00165     protected:
00166         /**
00167         *  @brief
00168         *    Called when application should open it's main window
00169         *
00170         *  @remarks
00171         *    Use this function to create a main window and set as pointer to it using SetMainWindow().
00172         *    The default implementation does the following tasks:
00173         *    - If a GUI filename is provided, create a window by loading that file
00174         *    - Otherwise, create an empty top-level window
00175         */
00176         PLGUI_API virtual void OnCreateMainWindow();
00177 
00178 
00179     //[-------------------------------------------------------]
00180     //[ Private functions                                     ]
00181     //[-------------------------------------------------------]
00182     private:
00183         /**
00184         *  @brief
00185         *    Called when main window was destroyed
00186         */
00187         void OnDestroyMainWindow();
00188 
00189 
00190     //[-------------------------------------------------------]
00191     //[ Protected data                                        ]
00192     //[-------------------------------------------------------]
00193     protected:
00194         // Event handlers
00195         PLCore::EventHandler<> EventHandlerOnDestroy;
00196 
00197         // Data
00198         Widget *m_pMainWindow;  /**< Main window of the application (can be a null pointer) */
00199 
00200 
00201 };
00202 
00203 
00204 //[-------------------------------------------------------]
00205 //[ Namespace                                             ]
00206 //[-------------------------------------------------------]
00207 } // PLGui
00208 
00209 
00210 #endif // __PLGUI_GUI_APPLICATION_H__


PixelLight PixelLight 0.9.11-R1
Copyright (C) 2002-2012 by The PixelLight Team
Last modified Thu Feb 23 2012 14:08:56
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported