OSDN Git Service

サムネイル・ツールバーを実装してみた。
[wintimer/wintimer.git] / wintimer / taskbar.h
1 #pragma once
2
3 /*
4   ==============================================================================
5
6    This file is part of the mini timer
7    Copyright 2005-10 by Satoshi Fujiwara.
8
9    mini timer can be redistributed and/or modified under the terms of the
10    GNU General Public License, as published by the Free Software Foundation;
11    either version 2 of the License, or (at your option) any later version.
12
13    mini timer is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with mini timer; if not, visit www.gnu.org/licenses or write to the
20    Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
21    Boston, MA 02111-1307 USA
22
23   ==============================================================================
24 */
25
26 #include "exception.h"
27 #include "icon.h"
28
29 namespace sf
30 {
31   
32   ///** インターフェース */
33   //struct thumb_button : boost::noncopyable
34   //{
35   //  typedef std::shared_ptr<thumb_button> ptr;
36   //  static ptr create_thumb_button();
37   //  virtual void show()  = 0;
38   //  virtual void hide()  = 0;
39   //  virtual void enable() = 0;
40   //  virtual void disable() = 0;
41   //private:
42   //  thumb_button();
43   //};
44
45   struct taskbar;
46
47   /** サムネイルボタン管理 */
48   struct thumb_button_manager
49   {
50     friend struct taskbar;
51     // Thumb Buttonは最大7個まで
52     static const int THUMB_BUTTON_MAX = 7;
53
54     // THUMBBUTTON構造体操作クラス
55     struct thumb_button {
56
57       // コンストラクタ
58       thumb_button(uint32_t id ,const icon& i,const std::wstring& tool_tip,THUMBBUTTON& t) : thumb_(t)
59       {
60         BOOST_ASSERT(tool_tip.size() < 259);
61         memset(&thumb_,0,sizeof(THUMBBUTTON));
62         thumb_.dwMask = THB_ICON | THB_TOOLTIP | THB_FLAGS;
63         thumb_.hIcon = i.get();
64         thumb_.iId = id;
65         std::copy(tool_tip.begin(),tool_tip.end(),thumb_.szTip);
66         //thumb_.szTip = const_cast<wchar_t*>(tool_tip_.c_str());
67       }
68       
69       /** アイコン */
70       thumb_button& set_icon(icon& ic) {thumb_.hIcon = ic.get(); return *this;};
71       /** IDのセット */
72       thumb_button& id(uint32_t v) {thumb_.iId = v; return *this;}
73       /** ツールチップ */
74       thumb_button& tool_tip(const std::wstring& v) {
75         BOOST_ASSERT(v.size() < 259);
76         std::copy(v.begin(),v.end(),thumb_.szTip);
77         thumb_.szTip[v.size()] = L'\0';
78         return *this;
79       }
80       /** 有効化・無効化 */
81       thumb_button& enable(bool v){v?(thumb_.dwFlags &= ~THBF_ENABLED):(thumb_.dwFlags |= THBF_DISABLED); return *this;}
82       /** クリックされたらサムネイルを閉じるか */
83       thumb_button& dismission_click(bool v){ v?(thumb_.dwFlags |= THBF_DISMISSONCLICK):(thumb_.dwFlags &= ~THBF_DISMISSONCLICK); return *this;}
84       /** ボタンの外枠を描画するかどうか */
85       thumb_button& no_background(bool v){v?(thumb_.dwFlags |= THBF_NOBACKGROUND):(thumb_.dwFlags &= ~THBF_NOBACKGROUND);return *this;}
86       /** 隠すか・表示するか */
87       thumb_button& hidden(bool v){v?(thumb_.dwFlags |= THBF_HIDDEN):(thumb_.dwFlags &= ~ THBF_HIDDEN);return *this;}
88       /** ボタンアクションを起こすかどうか。ボタンを通知目的で使用する際に用いる。*/
89       thumb_button& no_interacive(bool v){v?(thumb_.dwFlags |= THBF_NONINTERACTIVE):(thumb_.dwFlags &= ~THBF_NONINTERACTIVE);return *this;}
90
91     private:
92       THUMBBUTTON& thumb_;
93     };
94     
95     thumb_button_manager() : is_added(false) {}
96
97     // Thumb Buttonは7個までに制限されている
98     thumb_button&  add_thumb_button(uint32_t id,const icon& i,const std::wstring& str)
99     {
100       // 事前条件
101       BOOST_ASSERT(thumb_buttons_.size() < 7 && is_added == false);
102       if(!is_added){
103         thumbbuttons_.push_back(THUMBBUTTON());
104         thumb_buttons_.push_back(thumb_button(id,i,str, (thumbbuttons_.at(thumbbuttons_.size() - 1))));
105       }
106       return thumb_buttons_.at(thumb_buttons_.size() - 1);
107     }
108
109     thumb_button& at(uint32_t i){
110       BOOST_ASSERT(i < thumb_buttons_.size());
111       return thumb_buttons_.at(i);
112     }
113
114     size_t size() const {return thumb_buttons_.size();}
115   private:
116     mutable bool is_added;
117     // メモリ配列を合わせるためにこうした。
118     std::vector<THUMBBUTTON> thumbbuttons_;
119     std::vector<thumb_button> thumb_buttons_;
120     //typedef boost::ptr_vector<thumb_button> thumb_buttons;
121   };
122
123   /** タスクバーAPIのラップクラス。本来であればインターフェースにする方が良いかもしれないけれど */
124   struct taskbar : boost::noncopyable
125   {
126     struct exception
127      : public sf::win32_error_exception 
128     {
129       exception(uint32_t hr) : win32_error_exception(hr) {};
130       exception() : win32_error_exception() {} ;
131     };
132
133      taskbar();
134     ~taskbar();
135     void create();
136     void discard();
137     void overlay_icon(const sf::base_window& w,const icon& ic,const std::wstring& description);
138     void progress_state(const sf::base_window& w,int state);
139     void progress_value(const sf::base_window& w,boost::uint64_t completed, boost::uint64_t total);
140
141     void add_thumb_buttons(const sf::base_window& w,const thumb_button_manager& tm);
142     void update_thumb_buttons(const sf::base_window& w,const thumb_button_manager& tm);
143     bool is_create() const;
144
145     static long register_message();
146
147     static const int none;
148     static const int indeterminate;
149     static const int normal;
150     static const int error;
151     static const int paused;
152
153   private:
154     struct impl;
155     std::shared_ptr<impl> impl_;
156     friend struct impl;
157   };
158
159 }
160