| OLD | NEW |
| (Empty) |
| 1 // Copyright 2010 Google Inc. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 // you may not use this file except in compliance with the License. | |
| 5 // You may obtain a copy of the License at | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 // ======================================================================== | |
| 15 | |
| 16 #ifndef OMAHA_UI_SPLASH_SCREEN_H_ | |
| 17 #define OMAHA_UI_SPLASH_SCREEN_H_ | |
| 18 | |
| 19 #include "base/scoped_ptr.h" | |
| 20 #include "omaha/base/scoped_any.h" | |
| 21 #include "omaha/base/synchronized.h" | |
| 22 #include "omaha/base/thread.h" | |
| 23 #include "omaha/base/wtl_atlapp_wrapper.h" | |
| 24 | |
| 25 namespace omaha { | |
| 26 | |
| 27 // Displays a splash screen while lengthy operations occur. Before the lengthy | |
| 28 // operation, the caller creates an instance of this class and calls Show() | |
| 29 // function on it. The Show() function then creates a thread to display the | |
| 30 // splash screen. The caller must call Dismiss() function to hide and destroy | |
| 31 // the splash screen once the lengthy operation is done. | |
| 32 class SplashScreen | |
| 33 : public CAxDialogImpl<SplashScreen>, | |
| 34 public Runnable { | |
| 35 public: | |
| 36 explicit SplashScreen(const CString& bundle_name); | |
| 37 | |
| 38 // The desctructor waits up to 60 seconds for the message loop thread to exit | |
| 39 // if it is running. | |
| 40 virtual ~SplashScreen(); | |
| 41 | |
| 42 // The dialog resource ID as required by CAxDialogImpl. | |
| 43 const int IDD; | |
| 44 | |
| 45 // Spawns a thread which creates and shows the window. | |
| 46 void Show(); | |
| 47 | |
| 48 // Closes the window gradually if the window is visible. | |
| 49 void Dismiss(); | |
| 50 | |
| 51 // Runnable interface method. | |
| 52 virtual void Run(); | |
| 53 | |
| 54 BEGIN_MSG_MAP(SplashScreen) | |
| 55 MESSAGE_HANDLER(WM_TIMER, OnTimer) | |
| 56 MESSAGE_HANDLER(WM_CLOSE, OnClose) | |
| 57 MESSAGE_HANDLER(WM_DESTROY, OnDestroy) | |
| 58 END_MSG_MAP() | |
| 59 | |
| 60 private: | |
| 61 friend class SplashScreenTest; | |
| 62 | |
| 63 // States that help to determine the splash screen life cycle and | |
| 64 // allowed operations at each stage. | |
| 65 enum WindowState { | |
| 66 STATE_CREATED, | |
| 67 STATE_INITIALIZED, | |
| 68 STATE_SHOW_NORMAL, | |
| 69 STATE_FADING, | |
| 70 STATE_CLOSED, | |
| 71 }; | |
| 72 | |
| 73 // Creates the window and adjusts its size and apperance. | |
| 74 HRESULT Initialize(); | |
| 75 | |
| 76 void InitProgressBar(); | |
| 77 void EnableSystemButtons(bool enable); | |
| 78 | |
| 79 void SwitchToState(WindowState new_state); | |
| 80 | |
| 81 // Posts a WM_CLOSE message to close the window if the window is valid. | |
| 82 void Close(); | |
| 83 | |
| 84 // Message and command handlers. | |
| 85 LRESULT OnTimer(UINT msg, | |
| 86 WPARAM wparam, | |
| 87 LPARAM lparam, | |
| 88 BOOL& handled); // NOLINT(runtime/references) | |
| 89 LRESULT OnClose(UINT msg, | |
| 90 WPARAM wparam, | |
| 91 LPARAM lparam, | |
| 92 BOOL& handled); // NOLINT(runtime/references) | |
| 93 LRESULT OnDestroy(UINT msg, | |
| 94 WPARAM wparam, | |
| 95 LPARAM lparam, | |
| 96 BOOL& handled); // NOLINT(runtime/references) | |
| 97 | |
| 98 LLock lock_; // Lock for access synchronization of this object. | |
| 99 Thread thread_; // Thread that creats the window and runs the message loop. | |
| 100 WindowState state_; // State of the object. | |
| 101 | |
| 102 // Indicates whether timer for fading effect has been created. | |
| 103 bool timer_created_; | |
| 104 | |
| 105 int alpha_index_; // Array index of current alpha blending value. | |
| 106 | |
| 107 CString text_; // Message text shows on the window. | |
| 108 CString caption_; // Dialog title. | |
| 109 | |
| 110 // Handle to large icon to show when ALT-TAB | |
| 111 scoped_hicon hicon_; | |
| 112 | |
| 113 DISALLOW_COPY_AND_ASSIGN(SplashScreen); | |
| 114 }; | |
| 115 | |
| 116 } // namespace omaha | |
| 117 | |
| 118 #endif // OMAHA_UI_SPLASH_SCREEN_H_ | |
| 119 | |
| OLD | NEW |