#include "GuiTextAutoComplete.h"
#include "../GuiTextCommonInterface.h"
#include "../../ListControlPackage/GuiTextListControls.h"
#include "../../Templates/GuiThemeStyleFactory.h"
namespace
{
namespace
{
namespace
{
using
namespace
collections
;
GuiTextBoxAutoCompleteBase
::
::
(
<
templates
::
>
)
{
=
new
(
theme
::
::
);
if
(
)
{
->
(
);
}
->
SetHorizontalAlwaysVisible
(
false
);
->
(
false
);
}
GuiTextBoxAutoCompleteBase
::
::
()
{
}
*
GuiTextBoxAutoCompleteBase
::
::
()
{
return
;
}
*
GuiTextBoxAutoCompleteBase
::
::
()
{
return
;
}
void
GuiTextBoxAutoCompleteBase
::
::
(
const
collections
::
<
>&
)
{
->
().
();
FOREACH(AutoCompleteItem, item, items)
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
>&
= ::
vl
::
collections
::
(
);
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
;
__foreach_iterator__
.
(
item
);)
{
->
().
(
new
list
::
(
item
.
text
));
}
}
GuiTextBoxAutoCompleteBase
::
::
()
{
return
->
().
();
}
GuiTextBoxAutoCompleteBase
::
::
(
)
{
return
->
()
]
();
}
bool
GuiTextBoxAutoCompleteBase
::
(
const
&
,
const
&
)
{
if
(
.
()>=
.
())
{
if(INVLOC.Compare(prefix, candidate.Sub(0, prefix.Length()), Locale::IgnoreCase)==0)
if
(
vl
::
::
().
(
,
.
(
0
,
.
()),
::
)==
0
)
{
return
true
;
}
}
return
false
;
}
GuiTextBoxAutoCompleteBase
::
GuiTextBoxAutoCompleteBase
(
<
IAutoCompleteControlProvider
>
_autoCompleteControlProvider
)
:element(
0
)
, elementModifyLock(
0
)
, ownerComposition(
0
)
, autoCompleteControlProvider(
_autoCompleteControlProvider
)
{
if
(!
autoCompleteControlProvider
)
{
autoCompleteControlProvider
new
;
}
autoCompleteControlProvider
()->
()->
(
(
0
,
0
,
0
,
0
));
=
new
(
theme
::
::
);
->
(
autoCompleteControlProvider
());
}
GuiTextBoxAutoCompleteBase
::
~
GuiTextBoxAutoCompleteBase
()
{
delete
;
}
void
GuiTextBoxAutoCompleteBase
::
(
elements
::
*
,
&
,
compositions
::
*
,
)
{
if
(
)
{
SPIN_LOCK(_elementModifyLock)
if
(
bool
=
true
)
for
(
const
::
&
=
;
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
{
=
;
=&
;
=
;
}
}
}
void
GuiTextBoxAutoCompleteBase
::
()
{
if
(
&&
)
{
SPIN_LOCK(*elementModifyLock)
if
(
bool
=
true
)
for
(
const
::
&
= *
;
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
{
=
0
;
=
0
;
}
}
}
void
GuiTextBoxAutoCompleteBase
::
(
&
)
{
}
void
GuiTextBoxAutoCompleteBase
::
(
const
&
)
{
if
(
&&
)
{
if
(
())
{
=
();
=
.
;
=
->
().
(
begin
,
end
);
(
editingText
);
}
}
}
void
GuiTextBoxAutoCompleteBase
::
(
const
&
)
{
}
void
GuiTextBoxAutoCompleteBase
::
(
)
{
}
bool
GuiTextBoxAutoCompleteBase
::
()
{
return
->
();
}
void
GuiTextBoxAutoCompleteBase
::
(
)
{
if
(
&&
)
{
autoCompleteStartPosition
;
=
->
().
(
);
=
->
();
*
=
->
();
=
->
();
=
ownerControl
->
()->
();
=
compositionBounds
.
-
controlBounds
.
-
viewPosition
.
;
=
compositionBounds
.
-
controlBounds
.
-
viewPosition
.
;
bounds
.
+=
px
;
bounds
.
+=
px
;
bounds
.
+=
py
+
5
;
bounds
.
+=
py
+
5
;
->
(
ownerControl
,
bounds
,
true
);
}
}
void
GuiTextBoxAutoCompleteBase
::
()
{
->
();
}
void
GuiTextBoxAutoCompleteBase
::
(
const
collections
::
<
>&
)
{
if
(
.
()==
0
)
{
();
}
<
>
;
(
sortedItems
,
(
)
.
([](
const
&
,
const
&
)
{
return INVLOC.Compare(a.text, b.text, Locale::IgnoreCase);
return
vl
::
::
().
(
a
.
text
,
b
.
text
,
::
);
})
);
autoCompleteControlProvider
(
sortedItems
);
autoCompleteControlProvider
()->
()->
(
(
200
,
200
));
}
GuiTextBoxAutoCompleteBase
::
()
{
return
autoCompleteStartPosition
;
}
bool
GuiTextBoxAutoCompleteBase
::
()
{
if
(!
())
return
false
;
if
(
autoCompleteControlProvider
()->
().
()==
0
)
{
autoCompleteControlProvider
()->
(
0
,
true
);
}
else
{
=
autoCompleteControlProvider
()->
()
0
];
if
(
index
>
0
)
index
--;
autoCompleteControlProvider
()->
(
index
,
true
);
autoCompleteControlProvider
()->
(
index
);
}
return
true
;
}
bool
GuiTextBoxAutoCompleteBase
::
()
{
if
(!
())
return
false
;
if
(
autoCompleteControlProvider
()->
().
() ==
0
)
{
autoCompleteControlProvider
()->
(
0
,
true
);
}
else
{
=
autoCompleteControlProvider
()->
()
0
];
if
(
index
<
autoCompleteControlProvider
() -
1
)
index
++;
autoCompleteControlProvider
()->
(
index
,
true
);
autoCompleteControlProvider
()->
(
index
);
}
return
true
;
}
bool
GuiTextBoxAutoCompleteBase
::
()
{
if
(!
())
return
false
;
if
(!
)
return
false
;
const
auto
&
=
autoCompleteControlProvider
()->
();
if
(
selectedItems
.
() ==
0
)
return
false
;
GuiTextBoxCommonInterface
*
=
dynamic_cast
<
GuiTextBoxCommonInterface
*>(
->
());
if
(!
ci
)
return
false
;
=
selectedItems
0
];
=
autoCompleteControlProvider
(
index
);
=
autoCompleteStartPosition
;
=
ci
->
();
ci
->
(
begin
,
end
);
ci
->
(
selectedItem
);
();
return
true
;
}
GuiTextBoxAutoCompleteBase
::
()
{
if
(!
())
return
L""
;
const
auto
&
=
autoCompleteControlProvider
()->
();
if
(
selectedItems
.
() ==
0
)
return
L""
;
=
selectedItems
0
];
return
autoCompleteControlProvider
(
index
);
}
void
GuiTextBoxAutoCompleteBase
::
(
const
&
)
{
if
(
())
{
=
0
;
=
autoCompleteControlProvider
() -
1
;
=-
1
;
while
(
first
<=
last
)
{
= (
first
+
last
) /
2
;
=
autoCompleteControlProvider
(
middle
);
if
(
(
,
text
))
{
selected
=
middle
;
break
;
}
vint result = INVLOC.Compare(editingText, text, Locale::IgnoreCase);
if
(
result
<=
0
)
{
last
=
middle
-
1
;
}
else
{
first
=
middle
+
1
;
}
}
while
(
selected
>
0
)
{
=
autoCompleteControlProvider
(
selected
-
1
);
if
(
(
,
text
))
{
selected
--;
}
else
{
break
;
}
}
if
(
selected
!=-
1
)
{
autoCompleteControlProvider
()->
(
selected
,
true
);
autoCompleteControlProvider
()->
(
selected
);
}
}
}
}
}
}