| 1 |
#include "stdafx.h" |
| 2 |
#include "CEditCtrl.h" |
| 3 |
#include "CSkinPlugin.h" |
| 4 |
#include "CInterfaceMode.h" |
| 5 |
|
| 6 |
// 内部グローバル |
| 7 |
float g_SkinFileIconRect[4] = {0.875f, 0.75f, 0.125f, 0.125f}; // ファイルアイコン領域 |
| 8 |
|
| 9 |
/* |
| 10 |
* コンストラクタ |
| 11 |
*/ |
| 12 |
CTreeFileElement::CTreeFileElement( |
| 13 |
char *str, // 文字列 |
| 14 |
CTreeDirElement *p, // 親 |
| 15 |
CPluginTree *ctrl, // ツリーコントロール |
| 16 |
CPlugin *pi // プラグイン |
| 17 |
): |
| 18 |
CTreeElement(str, p, ctrl) // 基本クラス |
| 19 |
{ |
| 20 |
m_CommandType = CMD_PITVELEM; |
| 21 |
m_Plugin = pi; |
| 22 |
} |
| 23 |
|
| 24 |
/* |
| 25 |
* リネーム可能か |
| 26 |
*/ |
| 27 |
bool CTreeFileElement::IsRenamable(){ |
| 28 |
return m_Plugin && m_Plugin->IsRenamable(); |
| 29 |
} |
| 30 |
|
| 31 |
/* |
| 32 |
* リネーム確認 |
| 33 |
*/ |
| 34 |
bool CTreeFileElement::ConfirmRename( |
| 35 |
string &newname // 新規名 |
| 36 |
){ |
| 37 |
return m_Plugin && m_Plugin->ConfirmRename(newname); |
| 38 |
} |
| 39 |
|
| 40 |
/* |
| 41 |
* デリート可能か |
| 42 |
*/ |
| 43 |
bool CTreeFileElement::IsDeletable(){ |
| 44 |
return m_Plugin && m_Plugin->IsDeletable(); |
| 45 |
} |
| 46 |
|
| 47 |
/* |
| 48 |
* リストビューに要素を追加 |
| 49 |
*/ |
| 50 |
void CTreeFileElement::PushListElement( |
| 51 |
CPluginListView *lv // リストビュー |
| 52 |
){ |
| 53 |
int index = lv->GetItemNum(); |
| 54 |
LPTEX8 icon = m_Plugin->GetIconTexture(); |
| 55 |
CListElement *le = lv->InsertItem(index, (char *)m_Plugin->m_Name.c_str(), |
| 56 |
icon, icon ? m_Plugin->GetIconRect() : g_SkinFileIconRect); |
| 57 |
le->SetData((DWORD)this); |
| 58 |
le->SetString(1, (char *)m_Plugin->m_ID.c_str()); |
| 59 |
le->SetString(2, (char *)m_Plugin->m_Author.c_str()); |
| 60 |
} |
| 61 |
|
| 62 |
/* |
| 63 |
* 保存 |
| 64 |
*/ |
| 65 |
void CTreeFileElement::Save( |
| 66 |
FILE *file, // ファイル |
| 67 |
string indent // インデント量 |
| 68 |
){ |
| 69 |
fprintf(file, "%sFile = %s, \"%s\";\n", |
| 70 |
indent.c_str(), m_Plugin->DirName(), m_Plugin->SaveString()); |
| 71 |
} |
| 72 |
|
| 73 |
/* |
| 74 |
* アイテムカウント |
| 75 |
*/ |
| 76 |
int CTreeFileElement::CountItem( |
| 77 |
int sum, // それまでの合計 |
| 78 |
int *fcp, // フォーカスアイテムの位置 |
| 79 |
bool exflag // 展開されているもののみ |
| 80 |
){ |
| 81 |
if(fcp && m_Owner->GetFocusItem()==this) *fcp = sum; |
| 82 |
return 1; |
| 83 |
} |
| 84 |
|
| 85 |
/* |
| 86 |
* 入力チェック |
| 87 |
*/ |
| 88 |
int CTreeFileElement::ScanInput( |
| 89 |
int x, int y, // 座標 |
| 90 |
int cnt, // 表示カウント |
| 91 |
int begin, // 開始位置 |
| 92 |
int end // 終了位置 |
| 93 |
){ |
| 94 |
if(m_Owner->GetFocusItem()==this) ms_FocusNext = this; |
| 95 |
else if(!ms_FocusNext) ms_FocusPrev = this; |
| 96 |
else if(ms_FocusNext==m_Owner->GetFocusItem()) ms_FocusNext = this; |
| 97 |
POINT pos = g_Cursor.GetPos(); |
| 98 |
if(m_EditBox && !IsInsideItem(x, y, pos.x, pos.y) |
| 99 |
&& GetButton(DIM_LEFT)==S_PUSH) EndRename(true); |
| 100 |
if(m_EditBox){ |
| 101 |
switch(m_EditBox->ScanInput()){ |
| 102 |
case EDIT_OK: |
| 103 |
EndRename(true); |
| 104 |
break; |
| 105 |
case EDIT_CANCEL: |
| 106 |
EndRename(false); |
| 107 |
break; |
| 108 |
} |
| 109 |
} |
| 110 |
if(cnt<begin || end<=cnt) return 1; |
| 111 |
if(m_RenameWait && GetFrameCount()-m_ClickTime==DBLCLK_FRAME && m_Parent |
| 112 |
&& m_Owner->IsFocus() && m_Owner->GetFocusItem()==this){ |
| 113 |
m_ClickTime = 0; |
| 114 |
BeginRename(); |
| 115 |
}else if(IsInsideItem(x, y, pos.x, pos.y)){ |
| 116 |
switch(GetButton(DIM_LEFT)){ |
| 117 |
case S_PUSH: |
| 118 |
m_RenameWait = false; |
| 119 |
if(m_Owner->IsFocus() && m_Owner->GetFocusItem()==this){ |
| 120 |
if(m_EditBox){ |
| 121 |
EndRename(true); |
| 122 |
m_State = 2; |
| 123 |
}else{ |
| 124 |
m_State = 3; |
| 125 |
} |
| 126 |
}else{ |
| 127 |
m_State = 2; |
| 128 |
} |
| 129 |
m_Owner->SetFocusItem(this); |
| 130 |
m_Owner->GiveFocus(); |
| 131 |
m_Owner->m_PushedItem = this; |
| 132 |
m_DownPos = pos; |
| 133 |
break; |
| 134 |
case S_HOLD: |
| 135 |
if(CDragContainer::GetType()==DRAG_PLUGIN) m_Owner->SetDropItem( |
| 136 |
m_Owner->GetFocusItem()!=m_Parent ? m_Parent : NULL); |
| 137 |
if(m_Parent && m_State && Manhattan(pos, m_DownPos)>DRAG_THD |
| 138 |
&& !CDragContainer::IsDragging()) PrepareDrag(); |
| 139 |
break; |
| 140 |
default: |
| 141 |
if(CDragContainer::GetType()==DRAG_PLUGIN |
| 142 |
&& (!m_Owner->IsFocus() || m_Owner->GetFocusItem()!=m_Parent)){ |
| 143 |
m_Parent->Drop(); |
| 144 |
return true; |
| 145 |
} |
| 146 |
switch(m_State){ |
| 147 |
case 2: |
| 148 |
m_ClickTime = GetFrameCount(); |
| 149 |
break; |
| 150 |
case 3: |
| 151 |
if(GetFrameCount()-m_ClickTime<DBLCLK_FRAME){ |
| 152 |
m_ClickTime = 0; |
| 153 |
m_Owner->m_Commander->DoubleClick(m_CommandType, (DWORD)GetPlugin()); |
| 154 |
g_Skin->MouseUp(); |
| 155 |
}else{ |
| 156 |
m_RenameWait = true; |
| 157 |
m_ClickTime = GetFrameCount(); |
| 158 |
} |
| 159 |
break; |
| 160 |
} |
| 161 |
m_State = 0; |
| 162 |
break; |
| 163 |
} |
| 164 |
if(m_Owner->m_Commander && GetButton(DIM_RIGHT)==S_PUSH){ |
| 165 |
CPopMenu *pop = m_Owner->m_Commander->Dispatch(m_CommandType, (DWORD)GetPlugin()); |
| 166 |
if(pop){ |
| 167 |
m_Owner->SetFocusItem(this); |
| 168 |
m_Owner->GiveFocus(false); |
| 169 |
pop->Popup(pos.x, pos.y); |
| 170 |
} |
| 171 |
} |
| 172 |
}else if(m_State){ |
| 173 |
switch(GetButton(DIM_LEFT)){ |
| 174 |
case S_HOLD: |
| 175 |
if(m_Parent && Manhattan(pos, m_DownPos)>DRAG_THD |
| 176 |
&& !CDragContainer::IsDragging()) PrepareDrag(); |
| 177 |
break; |
| 178 |
default: |
| 179 |
m_State = 0; |
| 180 |
break; |
| 181 |
} |
| 182 |
} |
| 183 |
return 1; |
| 184 |
} |
| 185 |
|
| 186 |
/* |
| 187 |
* レンダリング |
| 188 |
*/ |
| 189 |
int CTreeFileElement::Render( |
| 190 |
int x, int y, // 座標 |
| 191 |
int cnt, // 表示カウント |
| 192 |
int begin, // 開始位置 |
| 193 |
int end // 終了位置 |
| 194 |
){ |
| 195 |
if(m_EditBox && (!m_Owner->IsFocus() || m_Owner->GetFocusItem()!=this)) |
| 196 |
EndRename(true); |
| 197 |
if(cnt<begin) return 1; |
| 198 |
CStringDrawer *sd = g_StrTex->DrawString(m_String.c_str(), 0); |
| 199 |
D3DCOLOR *bc = m_Owner->GetFocusItem()==this |
| 200 |
? g_Skin->m_PluginTreeData.m_SelectedBaseColor |
| 201 |
: g_Skin->m_PluginTreeData.m_DefaultBaseColor; |
| 202 |
if(m_Width<0) m_Width = sd->GetWidth(); |
| 203 |
if(*bc){ |
| 204 |
devSetTexture(0, NULL); |
| 205 |
Grad2DRect(x+TILE_UNIT+TREE_ICON_OFS, y, x+TILE_UNIT+TREE_ICON_OFS |
| 206 |
+TREE_ICON_MARGIN*2+m_Width, y+TILE_UNIT, bc); |
| 207 |
} |
| 208 |
if(m_Owner->IsFocus() && m_Owner->GetFocusItem()==this) |
| 209 |
Draw2DRect(x+TILE_UNIT+TREE_ICON_OFS, y, x+TILE_UNIT+TREE_ICON_OFS |
| 210 |
+TREE_ICON_MARGIN*2+m_Width, y+TILE_UNIT, |
| 211 |
g_Skin->m_PluginTreeData.m_FocusFrameColor); |
| 212 |
m_Plugin->SetIconTexture(); |
| 213 |
TexMap2DRect(x, y, x+TILE_UNIT, y+TILE_UNIT, 0xffffffff); |
| 214 |
if(m_EditBox){ |
| 215 |
m_EditBox->SetPos( |
| 216 |
x+TILE_UNIT+TREE_ICON_OFS+EB_OFSX, y+FontY(TILE_UNIT)); |
| 217 |
m_EditBox->Render(); |
| 218 |
}else{ |
| 219 |
sd->RenderLeft(x+TILE_UNIT |
| 220 |
+TREE_ICON_OFS+TREE_ICON_MARGIN, y+FontY(TILE_UNIT), |
| 221 |
g_Skin->m_PluginTreeData.m_DefaultFontColor); |
| 222 |
} |
| 223 |
return 1; |
| 224 |
} |