1 /*$
2  Copyright (C) 2016-2020 Azel.
3 
4  This file is part of AzPainterB.
5 
6  AzPainterB is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  AzPainterB is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 $*/
19 
20 /*****************************************
21  * DockOption
22  *
23  * [Dock]オプション
24  *****************************************/
25 
26 #include "mDef.h"
27 #include "mContainerDef.h"
28 #include "mWidget.h"
29 #include "mDockWidget.h"
30 #include "mContainer.h"
31 #include "mEvent.h"
32 #include "mTab.h"
33 #include "mTrans.h"
34 
35 #include "defConfig.h"
36 #include "defWidgets.h"
37 #include "defDraw.h"
38 
39 #include "DockObject.h"
40 #include "DockOption_sub.h"
41 
42 #include "draw_main.h"
43 
44 #include "trgroup.h"
45 
46 
47 //------------------------
48 
49 #define _DOCKOPTION(p)  ((DockOption *)(p))
50 #define _DO_PTR         ((DockOption *)APP_WIDGETS->dockobj[DOCKWIDGET_OPTION])
51 
52 typedef struct
53 {
54 	DockObject obj;
55 
56 	mTab *tab;
57 	mWidget *mainct,
58 		*contents;	//タブ内容
59 }DockOption;
60 
61 //------------------------
62 
63 
64 
65 //========================
66 // sub
67 //========================
68 
69 
70 /** タブの内容ウィジェット作成 */
71 
_create_tab_contents(DockOption * p,mBool relayout)72 static void _create_tab_contents(DockOption *p,mBool relayout)
73 {
74 	mWidget *(*createfunc[3])(mWidget *) = {
75 		DockOption_createTab_tool, DockOption_createTab_rule, DockOption_createTab_headtail
76 	};
77 
78 	//現在のウィジェットを破棄
79 
80 	if(p->contents)
81 	{
82 		mWidgetDestroy(p->contents);
83 		p->contents = NULL;
84 	}
85 
86 	//作成
87 
88 	p->contents = (createfunc[APP_CONF->dockopt_tabno])(p->mainct);
89 
90 	//フォーカスを受け取らないようにする
91 
92 	if(p->contents && !DockObject_canTakeFocus(&p->obj))
93 		mWidgetNoTakeFocus_under(p->contents);
94 
95 	//再レイアウト
96 
97 	if(relayout)
98 		mWidgetReLayout(p->mainct);
99 }
100 
101 
102 //========================
103 
104 
105 /** イベント */
106 
_event_handle(mWidget * wg,mEvent * ev)107 static int _event_handle(mWidget *wg,mEvent *ev)
108 {
109 	DockOption *p = _DOCKOPTION(wg->param);
110 
111 	if(ev->type == MEVENT_NOTIFY)
112 	{
113 		if(ev->notify.widgetFrom == (mWidget *)p->tab
114 			&& ev->notify.type == MTAB_N_CHANGESEL)
115 		{
116 			//タブ選択変更
117 
118 			APP_CONF->dockopt_tabno = ev->notify.param1;
119 
120 			_create_tab_contents(p, TRUE);
121 		}
122 	}
123 
124 	return 1;
125 }
126 
127 /** メインコンテナの破棄ハンドラ */
128 
_destroy_handle(mWidget * wg)129 static void _destroy_handle(mWidget *wg)
130 {
131 	DockOption *p = _DO_PTR;
132 
133 	if(p) p->contents = NULL;
134 }
135 
136 /** mDockWidget ハンドラ : 内容作成 */
137 
_dock_func_create(mDockWidget * dockwg,int id,mWidget * parent)138 static mWidget *_dock_func_create(mDockWidget *dockwg,int id,mWidget *parent)
139 {
140 	DockOption *p = _DO_PTR;
141 	mWidget *ct;
142 	int i;
143 
144 	//メインコンテナ
145 
146 	ct = mContainerCreate(parent, MCONTAINER_TYPE_VERT, 0, 4, MLF_EXPAND_WH);
147 
148 	p->mainct = ct;
149 
150 	ct->destroy = _destroy_handle;
151 	ct->event = _event_handle;
152 	ct->notifyTarget = MWIDGET_NOTIFYTARGET_SELF;
153 	ct->param = (intptr_t)p;
154 	ct->margin.top = ct->margin.bottom = 2;
155 
156 	//タブ
157 
158 	p->tab = mTabCreate(ct, 0, MTAB_S_TOP | MTAB_S_HAVE_SEP | MTAB_S_FIT_SIZE,
159 			MLF_EXPAND_W, 0);
160 
161 	M_TR_G(TRGROUP_DOCK_OPTION);
162 
163 	for(i = 0; i < 3; i++)
164 		mTabAddItem(p->tab, M_TR_T(i), -1, i);
165 
166 	mTabSetSel_index(p->tab, APP_CONF->dockopt_tabno);
167 
168 	//タブ内容
169 
170 	_create_tab_contents(p, FALSE);
171 
172 	return ct;
173 }
174 
175 /** 作成 */
176 
DockOption_new(mDockWidgetState * state)177 void DockOption_new(mDockWidgetState *state)
178 {
179 	DockObject *p;
180 
181 	p = DockObject_new(DOCKWIDGET_OPTION,
182 			sizeof(DockOption), 0, 0,
183 			state, _dock_func_create);
184 
185 	mDockWidgetCreateWidget(p->dockwg);
186 }
187 
188 
189 //========================
190 // 外部からの呼び出し
191 //========================
192 
193 
194 /** ツール変更時 */
195 
DockOption_changeTool()196 void DockOption_changeTool()
197 {
198 	DockOption *p = _DO_PTR;
199 
200 	//「ツール」タブが選択されている場合、各ツールの内容に変更
201 
202 	if(APP_CONF->dockopt_tabno == 0 && DockObject_canDoWidget((DockObject *)p))
203 		_create_tab_contents(p, TRUE);
204 }
205 
206 /** ブラシ系ツールの半径値を変更 */
207 
DockOption_changeBrushRadius(int radius)208 void DockOption_changeBrushRadius(int radius)
209 {
210 	DockOption *p = _DO_PTR;
211 
212 	if(DockObject_canDoWidget((DockObject *)p)
213 		&& APP_CONF->dockopt_tabno == 0 && p->contents
214 		&& drawTool_isBrushTool())
215 	{
216 		DockOption_toolBrush_changeRadius((mWidget *)p->contents->param, radius);
217 	}
218 }
219 
220 /** スタンプイメージの変更時 */
221 
DockOption_changeStampImage()222 void DockOption_changeStampImage()
223 {
224 	DockOption *p = _DO_PTR;
225 
226 	if(DockObject_canDoWidget((DockObject *)p)
227 		&& APP_CONF->dockopt_tabno == 0 && p->contents
228 		&& APP_DRAW->tool.no == TOOL_STAMP)
229 	{
230 		DockOption_toolStamp_changeImage((mWidget *)p->contents->param);
231 	}
232 }
233