Update to v098r09 release.

byuu says:

Changelog:
- fixed major nall/vector/prepend bug
- renamed hiro/ListView to hiro/TableView
- added new hiro/ListView control which is a simplified abstraction of
  hiro/TableView
- updated higan's cheat database window and icarus' scan dialog to use
  the new ListView control
- compilation works once again on all platforms (Windows, Cocoa, GTK,
  Qt)
- the loki skeleton compiles once again (removed nall/DSP references;
  updated port/device ID names)

Small catch: need to capture layout resize events internally in Windows
to call resizeColumns. For now, just resize the icarus window to get it
to use the full window width for list view items.
This commit is contained in:
Tim Allen 2016-05-04 20:07:13 +10:00
parent 0955295475
commit 6ae0abe3d3
108 changed files with 2299 additions and 2081 deletions

View File

@ -8,7 +8,7 @@ using namespace nall;
namespace Emulator { namespace Emulator {
static const string Name = "higan"; static const string Name = "higan";
static const string Version = "098.08"; static const string Version = "098.09";
static const string Author = "byuu"; static const string Author = "byuu";
static const string License = "GPLv3"; static const string License = "GPLv3";
static const string Website = "http://byuu.org/"; static const string Website = "http://byuu.org/";

View File

@ -98,7 +98,7 @@ auto SDD1::mmcRead(uint24 addr) -> uint8 {
//map address=00-3f,80-bf:8000-ffff //map address=00-3f,80-bf:8000-ffff
//map address=c0-ff:0000-ffff //map address=c0-ff:0000-ffff
auto SDD1::mcuromRead(uint24 addr, uint8 data) -> uint8 { auto SDD1::mcuromRead(uint24 addr, uint8 data) -> uint8 {
//map address=00-3f,80-bf:8000-ffff mask=0x808000 => 00-1f:0000-ffff //map address=00-3f,80-bf:8000-ffff
if(!addr.bit(22)) { if(!addr.bit(22)) {
if(!addr.bit(23) && addr.bit(21) && r4805.bit(7)) addr.bit(21) = 0; //20-3f:8000-ffff if(!addr.bit(23) && addr.bit(21) && r4805.bit(7)) addr.bit(21) = 0; //20-3f:8000-ffff
if( addr.bit(23) && addr.bit(21) && r4807.bit(7)) addr.bit(21) = 0; //a0-bf:8000-ffff if( addr.bit(23) && addr.bit(21) && r4807.bit(7)) addr.bit(21) = 0; //a0-bf:8000-ffff

View File

@ -60,12 +60,7 @@ auto Program::videoRefresh(const uint32* data, uint pitch, uint width, uint heig
} }
auto Program::audioSample(int16 left, int16 right) -> void { auto Program::audioSample(int16 left, int16 right) -> void {
int samples[] = {left, right}; audio->sample(left, right);
dsp.sample(samples);
while(dsp.pending()) {
dsp.read(samples);
audio->sample(samples[0], samples[1]);
}
} }
auto Program::inputPoll(uint port, uint device, uint input) -> int16 { auto Program::inputPoll(uint port, uint device, uint input) -> int16 {
@ -79,8 +74,8 @@ auto Program::inputPoll(uint port, uint device, uint input) -> int16 {
} }
} }
if(port == (uint)SFC::Device::Port::Controller1) { if(port == (uint)SFC::Port::Controller1) {
if(device == (uint)SFC::Device::ID::Gamepad) { if(device == (uint)SFC::Device::Gamepad) {
#define map(id, name) \ #define map(id, name) \
case id: \ case id: \
if(auto code = keyboard->buttons().find(name)) { \ if(auto code = keyboard->buttons().find(name)) { \

View File

@ -22,19 +22,15 @@ auto Program::loadMedia(Emulator::Interface::Media& media, string location) -> v
emulator->set("Color Emulation", false); emulator->set("Color Emulation", false);
emulator->set("Scanline Emulation", false); emulator->set("Scanline Emulation", false);
emulator->connect((uint)SFC::Device::Port::Controller1, (uint)SFC::Device::ID::Gamepad); Emulator::audio.reset();
emulator->connect((uint)SFC::Device::Port::Controller2, (uint)SFC::Device::ID::None); Emulator::audio.setFrequency(audio->get(Audio::Frequency).get<uint>());
emulator->connect((uint)SFC::Device::Port::Expansion, (uint)SFC::Device::ID::None); emulator->connect((uint)SFC::Port::Controller1, (uint)SFC::Device::Gamepad);
emulator->connect((uint)SFC::Port::Controller2, (uint)SFC::Device::None);
emulator->connect((uint)SFC::Port::Expansion, (uint)SFC::Device::None);
emulator->load(media.id); emulator->load(media.id);
emulator->power(); emulator->power();
dsp.setResampler(DSP::ResampleEngine::Sinc);
dsp.setResamplerFrequency(96000.0);
double inputRatio = emulator->audioFrequency() / emulator->videoFrequency();
double outputRatio = 96000.0 / 60.0;
dsp.setFrequency(inputRatio / outputRatio * 96000.0);
presentation->setTitle(emulator->title()); presentation->setTitle(emulator->title());
} }

View File

@ -21,7 +21,6 @@ struct Program : Emulator::Interface::Bind {
auto path(uint group) -> string override; auto path(uint group) -> string override;
auto notify(string text) -> void override; auto notify(string text) -> void override;
DSP dsp;
vector<shared_pointer<HID::Device>> devices; vector<shared_pointer<HID::Device>> devices;
vector<string> mediaPaths; vector<string> mediaPaths;
vector<string> folderPaths; vector<string> folderPaths;

View File

@ -15,7 +15,7 @@ HotkeySettings::HotkeySettings(TabFrame* parent) : TabFrameItem(parent) {
}); });
eraseButton.setText("Erase").onActivate([&] { eraseButton.setText("Erase").onActivate([&] {
if(auto item = mappingList.selected()) { if(auto item = mappingList.selected()) {
inputManager->hotkeys[item->offset()]->unbind(); inputManager->hotkeys[item.offset()]->unbind();
refreshMappings(); refreshMappings();
} }
}); });
@ -26,16 +26,16 @@ HotkeySettings::HotkeySettings(TabFrame* parent) : TabFrameItem(parent) {
auto HotkeySettings::reloadMappings() -> void { auto HotkeySettings::reloadMappings() -> void {
mappingList.reset(); mappingList.reset();
mappingList.append(ListViewHeader().setVisible() mappingList.append(TableViewHeader().setVisible()
.append(ListViewColumn().setText("Name")) .append(TableViewColumn().setText("Name"))
.append(ListViewColumn().setText("Mapping").setExpandable()) .append(TableViewColumn().setText("Mapping").setExpandable())
.append(ListViewColumn().setText("Device").setAlignment(1.0).setForegroundColor({0, 128, 0})) .append(TableViewColumn().setText("Device").setAlignment(1.0).setForegroundColor({0, 128, 0}))
); );
for(auto& hotkey : inputManager->hotkeys) { for(auto& hotkey : inputManager->hotkeys) {
mappingList.append(ListViewItem() mappingList.append(TableViewItem()
.append(ListViewCell().setText(hotkey->name)) .append(TableViewCell().setText(hotkey->name))
.append(ListViewCell()) .append(TableViewCell())
.append(ListViewCell()) .append(TableViewCell())
); );
} }
mappingList.resizeColumns(); mappingList.resizeColumns();
@ -44,8 +44,8 @@ auto HotkeySettings::reloadMappings() -> void {
auto HotkeySettings::refreshMappings() -> void { auto HotkeySettings::refreshMappings() -> void {
uint position = 0; uint position = 0;
for(auto& hotkey : inputManager->hotkeys) { for(auto& hotkey : inputManager->hotkeys) {
mappingList.item(position)->cell(1)->setText(hotkey->assignmentName()); mappingList.item(position).cell(1).setText(hotkey->assignmentName());
mappingList.item(position)->cell(2)->setText(hotkey->deviceName()); mappingList.item(position).cell(2).setText(hotkey->deviceName());
position++; position++;
} }
mappingList.resizeColumns(); mappingList.resizeColumns();
@ -55,7 +55,7 @@ auto HotkeySettings::assignMapping() -> void {
inputManager->poll(); //clear any pending events first inputManager->poll(); //clear any pending events first
if(auto item = mappingList.selected()) { if(auto item = mappingList.selected()) {
activeMapping = inputManager->hotkeys[item->offset()]; activeMapping = inputManager->hotkeys[item.offset()];
settingsManager->layout.setEnabled(false); settingsManager->layout.setEnabled(false);
settingsManager->statusBar.setText({"Press a key or button to map [", activeMapping->name, "] ..."}); settingsManager->statusBar.setText({"Press a key or button to map [", activeMapping->name, "] ..."});
} }

View File

@ -30,7 +30,7 @@ InputSettings::InputSettings(TabFrame* parent) : TabFrameItem(parent) {
}); });
eraseButton.setText("Erase").onActivate([&] { eraseButton.setText("Erase").onActivate([&] {
if(auto mapping = mappingList.selected()) { if(auto mapping = mappingList.selected()) {
activeDevice().mappings[mapping->offset()]->unbind(); activeDevice().mappings[mapping.offset()]->unbind();
refreshMappings(); refreshMappings();
} }
}); });
@ -45,7 +45,7 @@ auto InputSettings::updateControls() -> void {
assignMouse3.setVisible(false); assignMouse3.setVisible(false);
if(auto mapping = mappingList.selected()) { if(auto mapping = mappingList.selected()) {
auto input = activeDevice().mappings[mapping->offset()]; auto input = activeDevice().mappings[mapping.offset()];
if(input->isDigital()) { if(input->isDigital()) {
assignMouse1.setVisible().setText("Mouse Left"); assignMouse1.setVisible().setText("Mouse Left");
@ -92,16 +92,16 @@ auto InputSettings::reloadDevices() -> void {
auto InputSettings::reloadMappings() -> void { auto InputSettings::reloadMappings() -> void {
eraseButton.setEnabled(false); eraseButton.setEnabled(false);
mappingList.reset(); mappingList.reset();
mappingList.append(ListViewHeader().setVisible() mappingList.append(TableViewHeader().setVisible()
.append(ListViewColumn().setText("Name")) .append(TableViewColumn().setText("Name"))
.append(ListViewColumn().setText("Mapping").setExpandable()) .append(TableViewColumn().setText("Mapping").setExpandable())
.append(ListViewColumn().setText("Device").setAlignment(1.0).setForegroundColor({0, 128, 0})) .append(TableViewColumn().setText("Device").setAlignment(1.0).setForegroundColor({0, 128, 0}))
); );
for(auto& mapping : activeDevice().mappings) { for(auto& mapping : activeDevice().mappings) {
mappingList.append(ListViewItem() mappingList.append(TableViewItem()
.append(ListViewCell().setText(mapping->name)) .append(TableViewCell().setText(mapping->name))
.append(ListViewCell()) .append(TableViewCell())
.append(ListViewCell()) .append(TableViewCell())
); );
} }
refreshMappings(); refreshMappings();
@ -110,8 +110,8 @@ auto InputSettings::reloadMappings() -> void {
auto InputSettings::refreshMappings() -> void { auto InputSettings::refreshMappings() -> void {
uint position = 0; uint position = 0;
for(auto& mapping : activeDevice().mappings) { for(auto& mapping : activeDevice().mappings) {
mappingList.item(position)->cell(1)->setText(mapping->assignmentName()); mappingList.item(position).cell(1).setText(mapping->assignmentName());
mappingList.item(position)->cell(2)->setText(mapping->deviceName()); mappingList.item(position).cell(2).setText(mapping->deviceName());
position++; position++;
} }
mappingList.resizeColumns(); mappingList.resizeColumns();

View File

@ -90,7 +90,7 @@ struct InputSettings : TabFrameItem {
ComboButton emulatorList{&selectionLayout, Size{~0, 0}}; ComboButton emulatorList{&selectionLayout, Size{~0, 0}};
ComboButton portList{&selectionLayout, Size{~0, 0}}; ComboButton portList{&selectionLayout, Size{~0, 0}};
ComboButton deviceList{&selectionLayout, Size{~0, 0}}; ComboButton deviceList{&selectionLayout, Size{~0, 0}};
ListView mappingList{&layout, Size{~0, ~0}}; TableView mappingList{&layout, Size{~0, ~0}};
HorizontalLayout controlLayout{&layout, Size{~0, 0}}; HorizontalLayout controlLayout{&layout, Size{~0, 0}};
Button assignMouse1{&controlLayout, Size{100, 0}}; Button assignMouse1{&controlLayout, Size{100, 0}};
Button assignMouse2{&controlLayout, Size{100, 0}}; Button assignMouse2{&controlLayout, Size{100, 0}};
@ -111,7 +111,7 @@ struct HotkeySettings : TabFrameItem {
Timer timer; Timer timer;
VerticalLayout layout{this}; VerticalLayout layout{this};
ListView mappingList{&layout, Size{~0, ~0}}; TableView mappingList{&layout, Size{~0, ~0}};
HorizontalLayout controlLayout{&layout, Size{~0, 0}}; HorizontalLayout controlLayout{&layout, Size{~0, 0}};
Widget spacer{&controlLayout, Size{~0, 0}}; Widget spacer{&controlLayout, Size{~0, 0}};
Button resetButton{&controlLayout, Size{80, 0}}; Button resetButton{&controlLayout, Size{80, 0}};

View File

@ -3,17 +3,15 @@ CheatDatabase::CheatDatabase() {
layout.setMargin(5); layout.setMargin(5);
selectAllButton.setText("Select All").onActivate([&] { selectAllButton.setText("Select All").onActivate([&] {
for(auto& item : cheatList.items()) item.cell(0).setChecked(true); for(auto& item : cheatList.items()) item.setChecked(true);
}); });
unselectAllButton.setText("Unselect All").onActivate([&] { unselectAllButton.setText("Unselect All").onActivate([&] {
for(auto& item : cheatList.items()) item.cell(0).setChecked(false); for(auto& item : cheatList.items()) item.setChecked(false);
}); });
addCodesButton.setText("Add Codes").onActivate([&] { addCodes(); }); addCodesButton.setText("Add Codes").onActivate([&] { addCodes(); });
setSize({800, 400}); setSize({800, 400});
setAlignment({0.5, 1.0}); setAlignment({0.5, 1.0});
onSize([&] { cheatList.resizeColumns(); });
} }
auto CheatDatabase::findCodes() -> void { auto CheatDatabase::findCodes() -> void {
@ -28,19 +26,13 @@ auto CheatDatabase::findCodes() -> void {
codes.reset(); codes.reset();
cheatList.reset(); cheatList.reset();
cheatList.append(ListViewHeader().setVisible(false)
.append(ListViewColumn().setExpandable())
);
for(auto cheat : cartridge.find("cheat")) { for(auto cheat : cartridge.find("cheat")) {
codes.append(cheat["code"].text()); codes.append(cheat["code"].text());
cheatList.append(ListViewItem() cheatList.append(ListViewItem().setCheckable().setText(cheat["description"].text()));
.append(ListViewCell().setCheckable().setText(cheat["description"].text()))
);
} }
setTitle(cartridge["name"].text()); setTitle(cartridge["name"].text());
setVisible(); setVisible();
cheatList.resizeColumns();
return; return;
} }
@ -49,10 +41,10 @@ auto CheatDatabase::findCodes() -> void {
auto CheatDatabase::addCodes() -> void { auto CheatDatabase::addCodes() -> void {
for(auto& item : cheatList.items()) { for(auto& item : cheatList.items()) {
if(!item.cell(0).checked()) continue; if(!item.checked()) continue;
string code = codes(item.offset(), ""); string code = codes(item.offset(), "");
string description = item.cell(0).text(); string description = item.text();
if(toolsManager->cheatEditor.addCode(code, description) == false) { if(toolsManager->cheatEditor.addCode(code, description) == false) {
MessageDialog().setParent(*this).setText("Free slots exhausted. Not all codes could be added.").warning(); MessageDialog().setParent(*this).setText("Free slots exhausted. Not all codes could be added.").warning();
break; break;

View File

@ -3,20 +3,20 @@ CheatEditor::CheatEditor(TabFrame* parent) : TabFrameItem(parent) {
setText("Cheat Editor"); setText("Cheat Editor");
layout.setMargin(5); layout.setMargin(5);
cheatList.append(ListViewHeader().setVisible() cheatList.append(TableViewHeader().setVisible()
.append(ListViewColumn().setText("Slot").setForegroundColor({0, 128, 0}).setAlignment(1.0)) .append(TableViewColumn().setText("Slot").setForegroundColor({0, 128, 0}).setAlignment(1.0))
.append(ListViewColumn().setText("Code(s)")) .append(TableViewColumn().setText("Code(s)"))
.append(ListViewColumn().setText("Description").setExpandable()) .append(TableViewColumn().setText("Description").setExpandable())
); );
for(auto slot : range(Slots)) { for(auto slot : range(Slots)) {
cheatList.append(ListViewItem() cheatList.append(TableViewItem()
.append(ListViewCell().setCheckable().setText(1 + slot)) .append(TableViewCell().setCheckable().setText(1 + slot))
.append(ListViewCell()) .append(TableViewCell())
.append(ListViewCell()) .append(TableViewCell())
); );
} }
cheatList.onChange([&] { doChangeSelected(); }); cheatList.onChange([&] { doChangeSelected(); });
cheatList.onToggle([&](ListViewCell cell) { cheatList.onToggle([&](TableViewCell cell) {
cheats[cell.parent().offset()].enabled = cell.checked(); cheats[cell.parent().offset()].enabled = cell.checked();
synchronizeCodes(); synchronizeCodes();
}); });

View File

@ -3,14 +3,14 @@ StateManager::StateManager(TabFrame* parent) : TabFrameItem(parent) {
setText("State Manager"); setText("State Manager");
layout.setMargin(5); layout.setMargin(5);
stateList.append(ListViewHeader().setVisible() stateList.append(TableViewHeader().setVisible()
.append(ListViewColumn().setText("Slot").setForegroundColor({0, 128, 0}).setAlignment(1.0)) .append(TableViewColumn().setText("Slot").setForegroundColor({0, 128, 0}).setAlignment(1.0))
.append(ListViewColumn().setText("Description").setExpandable()) .append(TableViewColumn().setText("Description").setExpandable())
); );
for(auto slot : range(Slots)) { for(auto slot : range(Slots)) {
stateList.append(ListViewItem() stateList.append(TableViewItem()
.append(ListViewCell().setText(1 + slot)) .append(TableViewCell().setText(1 + slot))
.append(ListViewCell()) .append(TableViewCell())
); );
} }
stateList.onActivate([&] { doLoad(); }); stateList.onActivate([&] { doLoad(); });

View File

@ -36,7 +36,7 @@ struct CheatEditor : TabFrameItem {
Cheat cheats[Slots]; Cheat cheats[Slots];
VerticalLayout layout{this}; VerticalLayout layout{this};
ListView cheatList{&layout, Size{~0, ~0}}; TableView cheatList{&layout, Size{~0, ~0}};
HorizontalLayout codeLayout{&layout, Size{~0, 0}}; HorizontalLayout codeLayout{&layout, Size{~0, 0}};
Label codeLabel{&codeLayout, Size{70, 0}}; Label codeLabel{&codeLayout, Size{70, 0}};
LineEdit codeValue{&codeLayout, Size{~0, 0}}; LineEdit codeValue{&codeLayout, Size{~0, 0}};
@ -64,7 +64,7 @@ struct StateManager : TabFrameItem {
auto doErase() -> void; auto doErase() -> void;
VerticalLayout layout{this}; VerticalLayout layout{this};
ListView stateList{&layout, Size{~0, ~0}}; TableView stateList{&layout, Size{~0, ~0}};
HorizontalLayout descriptionLayout{&layout, Size{~0, 0}}; HorizontalLayout descriptionLayout{&layout, Size{~0, 0}};
Label descriptionLabel{&descriptionLayout, Size{70, 0}}; Label descriptionLabel{&descriptionLayout, Size{70, 0}};
LineEdit descriptionValue{&descriptionLayout, Size{~0, 0}}; LineEdit descriptionValue{&descriptionLayout, Size{~0, 0}};

View File

@ -1,6 +1,14 @@
#define decimal CocoaDecimal #define decimal decimal_cocoa
#define uint8 uint8_cocoa
#define uint16 uint16_cocoa
#define uint32 uint32_cocoa
#define uint64 uint64_cocoa
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#import <Carbon/Carbon.h> #import <Carbon/Carbon.h>
#undef decimal #undef decimal
#undef uint8
#undef uint16
#undef uint32
#undef uint64
#include <nall/run.hpp> #include <nall/run.hpp>

View File

@ -42,16 +42,16 @@
#include "widget/horizontal-slider.cpp" #include "widget/horizontal-slider.cpp"
#include "widget/label.cpp" #include "widget/label.cpp"
#include "widget/line-edit.cpp" #include "widget/line-edit.cpp"
#include "widget/list-view.cpp"
#include "widget/list-view-header.cpp"
#include "widget/list-view-column.cpp"
#include "widget/list-view-item.cpp"
#include "widget/list-view-cell.cpp"
#include "widget/progress-bar.cpp" #include "widget/progress-bar.cpp"
#include "widget/radio-button.cpp" #include "widget/radio-button.cpp"
#include "widget/radio-label.cpp" #include "widget/radio-label.cpp"
#include "widget/tab-frame.cpp" #include "widget/tab-frame.cpp"
#include "widget/tab-frame-item.cpp" #include "widget/tab-frame-item.cpp"
#include "widget/table-view.cpp"
#include "widget/table-view-header.cpp"
#include "widget/table-view-column.cpp"
#include "widget/table-view-item.cpp"
#include "widget/table-view-cell.cpp"
#include "widget/text-edit.cpp" #include "widget/text-edit.cpp"
#include "widget/vertical-scroll-bar.cpp" #include "widget/vertical-scroll-bar.cpp"
#include "widget/vertical-slider.cpp" #include "widget/vertical-slider.cpp"

View File

@ -54,16 +54,16 @@ namespace hiro {
#include "widget/horizontal-slider.hpp" #include "widget/horizontal-slider.hpp"
#include "widget/label.hpp" #include "widget/label.hpp"
#include "widget/line-edit.hpp" #include "widget/line-edit.hpp"
#include "widget/list-view.hpp"
#include "widget/list-view-header.hpp"
#include "widget/list-view-column.hpp"
#include "widget/list-view-item.hpp"
#include "widget/list-view-cell.hpp"
#include "widget/progress-bar.hpp" #include "widget/progress-bar.hpp"
#include "widget/radio-button.hpp" #include "widget/radio-button.hpp"
#include "widget/radio-label.hpp" #include "widget/radio-label.hpp"
#include "widget/tab-frame.hpp" #include "widget/tab-frame.hpp"
#include "widget/tab-frame-item.hpp" #include "widget/tab-frame-item.hpp"
#include "widget/table-view.hpp"
#include "widget/table-view-header.hpp"
#include "widget/table-view-column.hpp"
#include "widget/table-view-item.hpp"
#include "widget/table-view-cell.hpp"
#include "widget/text-edit.hpp" #include "widget/text-edit.hpp"
#include "widget/vertical-scroll-bar.hpp" #include "widget/vertical-scroll-bar.hpp"
#include "widget/vertical-slider.hpp" #include "widget/vertical-slider.hpp"

View File

@ -21,7 +21,7 @@
-(BOOL) performDragOperation:(id<NSDraggingInfo>)sender { -(BOOL) performDragOperation:(id<NSDraggingInfo>)sender {
lstring paths = DropPaths(sender); lstring paths = DropPaths(sender);
if(paths.empty()) return NO; if(!paths) return NO;
canvas->doDrop(paths); canvas->doDrop(paths);
return YES; return YES;
} }

View File

@ -1,50 +0,0 @@
#if defined(Hiro_ListView)
namespace hiro {
auto pListViewCell::construct() -> void {
}
auto pListViewCell::destruct() -> void {
}
auto pListViewCell::setAlignment(Alignment alignment) -> void {
}
auto pListViewCell::setBackgroundColor(Color color) -> void {
}
auto pListViewCell::setCheckable(bool checkable) -> void {
}
auto pListViewCell::setChecked(bool checked) -> void {
}
auto pListViewCell::setForegroundColor(Color color) -> void {
}
auto pListViewCell::setIcon(const image& icon) -> void {
}
auto pListViewCell::setText(const string& text) -> void {
@autoreleasepool {
if(auto pListView = _grandparent()) {
[[pListView->cocoaView content] reloadData];
}
}
}
auto pListViewCell::_grandparent() -> maybe<pListView&> {
if(auto parent = _parent()) return parent->_parent();
}
auto pListViewCell::_parent() -> maybe<pListViewItem&> {
if(auto parent = self().parentListViewItem()) {
if(auto self = parent->self()) return *self;
}
return nothing;
}
}
#endif

View File

@ -1,87 +0,0 @@
#if defined(Hiro_ListView)
namespace hiro {
auto pListViewColumn::construct() -> void {
@autoreleasepool {
if(auto listView = _grandparent()) {
[listView->cocoaView reloadColumns];
}
}
}
auto pListViewColumn::destruct() -> void {
@autoreleasepool {
if(auto listView = _grandparent()) {
[listView->cocoaView reloadColumns];
}
}
}
auto pListViewColumn::setActive() -> void {
}
auto pListViewColumn::setAlignment(Alignment alignment) -> void {
}
auto pListViewColumn::setBackgroundColor(Color color) -> void {
}
auto pListViewColumn::setEditable(bool editable) -> void {
}
auto pListViewColumn::setExpandable(bool expandable) -> void {
}
auto pListViewColumn::setFont(const Font& font) -> void {
}
auto pListViewColumn::setForegroundColor(Color color) -> void {
}
auto pListViewColumn::setHorizontalAlignment(double alignment) -> void {
}
auto pListViewColumn::setIcon(const image& icon) -> void {
}
auto pListViewColumn::setResizable(bool resizable) -> void {
}
auto pListViewColumn::setSortable(bool sortable) -> void {
}
auto pListViewColumn::setText(const string& text) -> void {
@autoreleasepool {
if(auto pListView = _grandparent()) {
NSTableColumn* tableColumn = [[pListView->cocoaView content] tableColumnWithIdentifier:[[NSNumber numberWithInteger:self().offset()] stringValue]];
[[tableColumn headerCell] setStringValue:[NSString stringWithUTF8STring:text]];
[[pListView->cocoaView headerView] setNeedsDisplay:YES];
}
}
}
auto pListViewColumn::setVerticalAlignment(double alignment) -> void {
}
auto pListViewColumn::setVisible(bool visible) -> void {
}
auto pListViewColumn::setWidth(signed width) -> void {
}
auto pListViewColumn::_grandparent() -> maybe<pListView&> {
if(auto parent = _parent()) return parent->_parent();
return nothing;
}
auto pListViewColumn::_parent() -> maybe<pListViewHeader&> {
if(auto parent = self().parentListViewHeader()) {
if(auto self = parent->self()) return *self;
}
return nothing;
}
}
#endif

View File

@ -1,38 +0,0 @@
#if defined(Hiro_ListView)
namespace hiro {
auto pListViewHeader::construct() -> void {
}
auto pListViewHeader::destruct() -> void {
}
auto pListViewHeader::append(sListViewColumn column) -> void {
}
auto pListViewHeader::remove(sListViewColumn column) -> void {
}
auto pListViewHeader::setVisible(bool visible) -> void {
@autoreleasepool {
if(auto pListView = _parent()) {
if(visible) {
[[pListView->cocoaView content] setHeaderView:[[[NSTableHeaderView alloc] init] autorelease]];
} else {
[[pListView->cocoaView content] setHeaderView:nil];
}
}
}
}
auto pListViewHeader::_parent() -> maybe<pListView&> {
if(auto parent = self().parentListView()) {
if(auto self = parent->self()) return *self;
}
return nothing;
}
}
#endif

View File

@ -1,17 +0,0 @@
#if defined(Hiro_ListView)
namespace hiro {
struct pListViewHeader : pObject {
Declare(ListViewHeader, Object)
auto append(sListViewColumn column) -> void;
auto remove(sListViewColumn column) -> void;
auto setVisible(bool visible) -> void override;
auto _parent() -> maybe<pListView&>;
};
}
#endif

View File

@ -1,51 +0,0 @@
#if defined(Hiro_ListView)
namespace hiro {
auto pListViewItem::construct() -> void {
}
auto pListViewItem::destruct() -> void {
}
auto pListViewItem::append(sListViewCell cell) -> void {
@autoreleasepool {
if(auto listView = _parent()) {
[[listView->cocoaView content] reloadData];
}
}
}
auto pListViewItem::remove(sListViewCell cell) -> void {
@autoreleasepool {
if(auto listView = _parent()) {
[[listView->cocoaView content] reloadData];
}
}
}
auto pListViewItem::setAlignment(Alignment alignment) -> void {
}
auto pListViewItem::setBackgroundColor(Color color) -> void {
}
auto pListViewItem::setFocused() -> void {
}
auto pListViewItem::setForegroundColor(Color color) -> void {
}
auto pListViewItem::setSelected(bool selected) -> void {
}
auto pListViewItem::_parent() -> maybe<pListView&> {
if(auto parent = self().parentListView()) {
if(auto self = parent->self()) return *self;
}
return nothing;
}
}
#endif

View File

@ -0,0 +1,50 @@
#if defined(Hiro_TableView)
namespace hiro {
auto pTableViewCell::construct() -> void {
}
auto pTableViewCell::destruct() -> void {
}
auto pTableViewCell::setAlignment(Alignment alignment) -> void {
}
auto pTableViewCell::setBackgroundColor(Color color) -> void {
}
auto pTableViewCell::setCheckable(bool checkable) -> void {
}
auto pTableViewCell::setChecked(bool checked) -> void {
}
auto pTableViewCell::setForegroundColor(Color color) -> void {
}
auto pTableViewCell::setIcon(const image& icon) -> void {
}
auto pTableViewCell::setText(const string& text) -> void {
@autoreleasepool {
if(auto pTableView = _grandparent()) {
[[pTableView->cocoaView content] reloadData];
}
}
}
auto pTableViewCell::_grandparent() -> maybe<pTableView&> {
if(auto parent = _parent()) return parent->_parent();
}
auto pTableViewCell::_parent() -> maybe<pTableViewItem&> {
if(auto parent = self().parentTableViewItem()) {
if(auto self = parent->self()) return *self;
}
return nothing;
}
}
#endif

View File

@ -1,9 +1,9 @@
#if defined(Hiro_ListView) #if defined(Hiro_TableView)
namespace hiro { namespace hiro {
struct pListViewCell : pObject { struct pTableViewCell : pObject {
Declare(ListViewCell, Object) Declare(TableViewCell, Object)
auto setAlignment(Alignment alignment) -> void; auto setAlignment(Alignment alignment) -> void;
auto setBackgroundColor(Color color) -> void; auto setBackgroundColor(Color color) -> void;
@ -13,8 +13,8 @@ struct pListViewCell : pObject {
auto setIcon(const image& icon) -> void; auto setIcon(const image& icon) -> void;
auto setText(const string& text) -> void; auto setText(const string& text) -> void;
auto _grandparent() -> maybe<pListView&>; auto _grandparent() -> maybe<pTableView&>;
auto _parent() -> maybe<pListViewItem&>; auto _parent() -> maybe<pTableViewItem&>;
}; };
} }

View File

@ -0,0 +1,87 @@
#if defined(Hiro_TableView)
namespace hiro {
auto pTableViewColumn::construct() -> void {
@autoreleasepool {
if(auto tableView = _grandparent()) {
[tableView->cocoaView reloadColumns];
}
}
}
auto pTableViewColumn::destruct() -> void {
@autoreleasepool {
if(auto tableView = _grandparent()) {
[tableView->cocoaView reloadColumns];
}
}
}
auto pTableViewColumn::setActive() -> void {
}
auto pTableViewColumn::setAlignment(Alignment alignment) -> void {
}
auto pTableViewColumn::setBackgroundColor(Color color) -> void {
}
auto pTableViewColumn::setEditable(bool editable) -> void {
}
auto pTableViewColumn::setExpandable(bool expandable) -> void {
}
auto pTableViewColumn::setFont(const Font& font) -> void {
}
auto pTableViewColumn::setForegroundColor(Color color) -> void {
}
auto pTableViewColumn::setHorizontalAlignment(double alignment) -> void {
}
auto pTableViewColumn::setIcon(const image& icon) -> void {
}
auto pTableViewColumn::setResizable(bool resizable) -> void {
}
auto pTableViewColumn::setSortable(bool sortable) -> void {
}
auto pTableViewColumn::setText(const string& text) -> void {
@autoreleasepool {
if(auto pTableView = _grandparent()) {
NSTableColumn* tableColumn = [[pTableView->cocoaView content] tableColumnWithIdentifier:[[NSNumber numberWithInteger:self().offset()] stringValue]];
[[tableColumn headerCell] setStringValue:[NSString stringWithUTF8STring:text]];
[[pTableView->cocoaView headerView] setNeedsDisplay:YES];
}
}
}
auto pTableViewColumn::setVerticalAlignment(double alignment) -> void {
}
auto pTableViewColumn::setVisible(bool visible) -> void {
}
auto pTableViewColumn::setWidth(signed width) -> void {
}
auto pTableViewColumn::_grandparent() -> maybe<pTableView&> {
if(auto parent = _parent()) return parent->_parent();
return nothing;
}
auto pTableViewColumn::_parent() -> maybe<pTableViewHeader&> {
if(auto parent = self().parentTableViewHeader()) {
if(auto self = parent->self()) return *self;
}
return nothing;
}
}
#endif

View File

@ -1,9 +1,9 @@
#if defined(Hiro_ListView) #if defined(Hiro_TableView)
namespace hiro { namespace hiro {
struct pListViewColumn : pObject { struct pTableViewColumn : pObject {
Declare(ListViewColumn, Object) Declare(TableViewColumn, Object)
auto setActive() -> void; auto setActive() -> void;
auto setAlignment(Alignment alignment) -> void; auto setAlignment(Alignment alignment) -> void;
@ -21,8 +21,8 @@ struct pListViewColumn : pObject {
auto setVisible(bool visible) -> void override; auto setVisible(bool visible) -> void override;
auto setWidth(signed width) -> void; auto setWidth(signed width) -> void;
auto _grandparent() -> maybe<pListView&>; auto _grandparent() -> maybe<pTableView&>;
auto _parent() -> maybe<pListViewHeader&>; auto _parent() -> maybe<pTableViewHeader&>;
}; };
} }

View File

@ -0,0 +1,38 @@
#if defined(Hiro_TableView)
namespace hiro {
auto pTableViewHeader::construct() -> void {
}
auto pTableViewHeader::destruct() -> void {
}
auto pTableViewHeader::append(sTableViewColumn column) -> void {
}
auto pTableViewHeader::remove(sTableViewColumn column) -> void {
}
auto pTableViewHeader::setVisible(bool visible) -> void {
@autoreleasepool {
if(auto pTableView = _parent()) {
if(visible) {
[[pTableView->cocoaView content] setHeaderView:[[[NSTableHeaderView alloc] init] autorelease]];
} else {
[[pTableView->cocoaView content] setHeaderView:nil];
}
}
}
}
auto pTableViewHeader::_parent() -> maybe<pTableView&> {
if(auto parent = self().parentTableView()) {
if(auto self = parent->self()) return *self;
}
return nothing;
}
}
#endif

View File

@ -0,0 +1,17 @@
#if defined(Hiro_TableView)
namespace hiro {
struct pTableViewHeader : pObject {
Declare(TableViewHeader, Object)
auto append(sTableViewColumn column) -> void;
auto remove(sTableViewColumn column) -> void;
auto setVisible(bool visible) -> void override;
auto _parent() -> maybe<pTableView&>;
};
}
#endif

View File

@ -0,0 +1,51 @@
#if defined(Hiro_TableView)
namespace hiro {
auto pTableViewItem::construct() -> void {
}
auto pTableViewItem::destruct() -> void {
}
auto pTableViewItem::append(sTableViewCell cell) -> void {
@autoreleasepool {
if(auto tableView = _parent()) {
[[tableView->cocoaView content] reloadData];
}
}
}
auto pTableViewItem::remove(sTableViewCell cell) -> void {
@autoreleasepool {
if(auto tableView = _parent()) {
[[tableView->cocoaView content] reloadData];
}
}
}
auto pTableViewItem::setAlignment(Alignment alignment) -> void {
}
auto pTableViewItem::setBackgroundColor(Color color) -> void {
}
auto pTableViewItem::setFocused() -> void {
}
auto pTableViewItem::setForegroundColor(Color color) -> void {
}
auto pTableViewItem::setSelected(bool selected) -> void {
}
auto pTableViewItem::_parent() -> maybe<pTableView&> {
if(auto parent = self().parentTableView()) {
if(auto self = parent->self()) return *self;
}
return nothing;
}
}
#endif

View File

@ -1,19 +1,19 @@
#if defined(Hiro_ListView) #if defined(Hiro_TableView)
namespace hiro { namespace hiro {
struct pListViewItem : pObject { struct pTableViewItem : pObject {
Declare(ListViewItem, Object) Declare(TableViewItem, Object)
auto append(sListViewCell cell) -> void; auto append(sTableViewCell cell) -> void;
auto remove(sListViewCell cell) -> void; auto remove(sTableViewCell cell) -> void;
auto setAlignment(Alignment alignment) -> void; auto setAlignment(Alignment alignment) -> void;
auto setBackgroundColor(Color color) -> void; auto setBackgroundColor(Color color) -> void;
auto setFocused() -> void; auto setFocused() -> void;
auto setForegroundColor(Color color) -> void; auto setForegroundColor(Color color) -> void;
auto setSelected(bool selected) -> void; auto setSelected(bool selected) -> void;
auto _parent() -> maybe<pListView&>; auto _parent() -> maybe<pTableView&>;
}; };
} }

View File

@ -1,11 +1,11 @@
#if defined(Hiro_ListView) #if defined(Hiro_TableView)
@implementation CocoaListView : NSScrollView @implementation CocoaTableView : NSScrollView
-(id) initWith:(hiro::mListView&)listViewReference { -(id) initWith:(hiro::mTableView&)tableViewReference {
if(self = [super initWithFrame:NSMakeRect(0, 0, 0, 0)]) { if(self = [super initWithFrame:NSMakeRect(0, 0, 0, 0)]) {
listView = &listViewReference; tableView = &tableViewReference;
content = [[CocoaListViewContent alloc] initWithFrame:NSMakeRect(0, 0, 0, 0)]; content = [[CocoaTableViewContent alloc] initWithFrame:NSMakeRect(0, 0, 0, 0)];
[self setDocumentView:content]; [self setDocumentView:content];
[self setBorderType:NSBezelBorder]; [self setBorderType:NSBezelBorder];
@ -34,7 +34,7 @@
[super dealloc]; [super dealloc];
} }
-(CocoaListViewContent*) content { -(CocoaTableViewContent*) content {
return content; return content;
} }
@ -59,13 +59,13 @@
[content removeTableColumn:[[content tableColumns] lastObject]]; [content removeTableColumn:[[content tableColumns] lastObject]];
} }
if(auto listViewHeader = listView->state.header) { if(auto tableViewHeader = tableView->state.header) {
for(auto& listViewColumn : listViewHeader->state.columns) { for(auto& tableViewColumn : tableViewHeader->state.columns) {
auto column = listViewColumn->offset(); auto column = tableViewColumn->offset();
NSTableColumn* tableColumn = [[NSTableColumn alloc] initWithIdentifier:[[NSNumber numberWithInteger:column] stringValue]]; NSTableColumn* tableColumn = [[NSTableColumn alloc] initWithIdentifier:[[NSNumber numberWithInteger:column] stringValue]];
NSTableHeaderCell* headerCell = [[NSTableHeaderCell alloc] initTextCell:[NSString stringWithUTF8String:listViewColumn->state.text]]; NSTableHeaderCell* headerCell = [[NSTableHeaderCell alloc] initTextCell:[NSString stringWithUTF8String:tableViewColumn->state.text]];
CocoaListViewCell* dataCell = [[CocoaListViewCell alloc] initWith:*listView]; CocoaTableViewCell* dataCell = [[CocoaTableViewCell alloc] initWith:*tableView];
[dataCell setEditable:NO]; [dataCell setEditable:NO];
@ -79,13 +79,13 @@
} }
-(NSInteger) numberOfRowsInTableView:(NSTableView*)table { -(NSInteger) numberOfRowsInTableView:(NSTableView*)table {
return listView->state.items.size(); return tableView->state.items.size();
} }
-(id) tableView:(NSTableView*)table objectValueForTableColumn:(NSTableColumn*)tableColumn row:(NSInteger)row { -(id) tableView:(NSTableView*)table objectValueForTableColumn:(NSTableColumn*)tableColumn row:(NSInteger)row {
if(auto listViewItem = listView->item(row)) { if(auto tableViewItem = tableView->item(row)) {
if(auto listViewCell = listViewItem->cell([[tableColumn identifier] integerValue])) { if(auto tableViewCell = tableViewItem->cell([[tableColumn identifier] integerValue])) {
NSString* text = [NSString stringWithUTF8String:listViewCell->state.text]; NSString* text = [NSString stringWithUTF8String:tableViewCell->state.text];
return @{ @"text":text }; //used by type-ahead return @{ @"text":text }; //used by type-ahead
} }
} }
@ -105,14 +105,14 @@
} }
-(void) tableViewSelectionDidChange:(NSNotification*)notification { -(void) tableViewSelectionDidChange:(NSNotification*)notification {
for(auto& listViewItem : listView->state.items) { for(auto& tableViewItem : tableView->state.items) {
listViewItem->state.selected = listViewItem->offset() == [content selectedRow]; tableViewItem->state.selected = tableViewItem->offset() == [content selectedRow];
} }
listView->doChange(); tableView->doChange();
} }
-(IBAction) activate:(id)sender { -(IBAction) activate:(id)sender {
listView->doActivate(); tableView->doActivate();
} }
-(IBAction) doubleAction:(id)sender { -(IBAction) doubleAction:(id)sender {
@ -123,7 +123,7 @@
@end @end
@implementation CocoaListViewContent : NSTableView @implementation CocoaTableViewContent : NSTableView
-(void) keyDown:(NSEvent*)event { -(void) keyDown:(NSEvent*)event {
auto character = [[event characters] characterAtIndex:0]; auto character = [[event characters] characterAtIndex:0];
@ -139,11 +139,11 @@
@end @end
@implementation CocoaListViewCell : NSCell @implementation CocoaTableViewCell : NSCell
-(id) initWith:(hiro::mListView&)listViewReference { -(id) initWith:(hiro::mTableView&)tableViewReference {
if(self = [super initTextCell:@""]) { if(self = [super initTextCell:@""]) {
listView = &listViewReference; tableView = &tableViewReference;
buttonCell = [[NSButtonCell alloc] initTextCell:@""]; buttonCell = [[NSButtonCell alloc] initTextCell:@""];
[buttonCell setButtonType:NSSwitchButton]; [buttonCell setButtonType:NSSwitchButton];
[buttonCell setControlSize:NSSmallControlSize]; [buttonCell setControlSize:NSSmallControlSize];
@ -159,27 +159,27 @@
} }
-(void) drawWithFrame:(NSRect)frame inView:(NSView*)view { -(void) drawWithFrame:(NSRect)frame inView:(NSView*)view {
if(auto listViewItem = listView->item([view rowAtPoint:frame.origin])) { if(auto tableViewItem = tableView->item([view rowAtPoint:frame.origin])) {
if(auto listViewCell = listViewItem->cell([view columnAtPoint:frame.origin])) { if(auto tableViewCell = tableViewItem->cell([view columnAtPoint:frame.origin])) {
NSColor* backgroundColor = nil; NSColor* backgroundColor = nil;
if([self isHighlighted]) backgroundColor = [NSColor alternateSelectedControlColor]; if([self isHighlighted]) backgroundColor = [NSColor alternateSelectedControlColor];
else if(!listView->enabled(true)) backgroundColor = [NSColor controlBackgroundColor]; else if(!tableView->enabled(true)) backgroundColor = [NSColor controlBackgroundColor];
else if(auto color = listViewCell->state.backgroundColor) backgroundColor = NSMakeColor(color); else if(auto color = tableViewCell->state.backgroundColor) backgroundColor = NSMakeColor(color);
else backgroundColor = [NSColor controlBackgroundColor]; else backgroundColor = [NSColor controlBackgroundColor];
[backgroundColor set]; [backgroundColor set];
[NSBezierPath fillRect:frame]; [NSBezierPath fillRect:frame];
if(listViewCell->state.checkable) { if(tableViewCell->state.checkable) {
[buttonCell setHighlighted:YES]; [buttonCell setHighlighted:YES];
[buttonCell setState:(listViewCell->state.checked ? NSOnState : NSOffState)]; [buttonCell setState:(tableViewCell->state.checked ? NSOnState : NSOffState)];
[buttonCell drawWithFrame:frame inView:view]; [buttonCell drawWithFrame:frame inView:view];
frame.origin.x += frame.size.height + 2; frame.origin.x += frame.size.height + 2;
frame.size.width -= frame.size.height + 2; frame.size.width -= frame.size.height + 2;
} }
if(listViewCell->state.icon) { if(tableViewCell->state.icon) {
NSImage* image = NSMakeImage(listViewCell->state.icon, frame.size.height, frame.size.height); NSImage* image = NSMakeImage(tableViewCell->state.icon, frame.size.height, frame.size.height);
[[NSGraphicsContext currentContext] saveGraphicsState]; [[NSGraphicsContext currentContext] saveGraphicsState];
NSRect targetRect = NSMakeRect(frame.origin.x, frame.origin.y, frame.size.height, frame.size.height); NSRect targetRect = NSMakeRect(frame.origin.x, frame.origin.y, frame.size.height, frame.size.height);
NSRect sourceRect = NSMakeRect(0, 0, [image size].width, [image size].height); NSRect sourceRect = NSMakeRect(0, 0, [image size].width, [image size].height);
@ -189,21 +189,21 @@
frame.size.width -= frame.size.height + 2; frame.size.width -= frame.size.height + 2;
} }
if(listViewCell->state.text) { if(tableViewCell->state.text) {
NSMutableParagraphStyle* paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; NSMutableParagraphStyle* paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
paragraphStyle.alignment = NSTextAlignmentCenter; paragraphStyle.alignment = NSTextAlignmentCenter;
if(listViewCell->state.alignment.horizontal() < 0.333) paragraphStyle.alignment = NSTextAlignmentLeft; if(tableViewCell->state.alignment.horizontal() < 0.333) paragraphStyle.alignment = NSTextAlignmentLeft;
if(listViewCell->state.alignment.horizontal() > 0.666) paragraphStyle.alignment = NSTextAlignmentRight; if(tableViewCell->state.alignment.horizontal() > 0.666) paragraphStyle.alignment = NSTextAlignmentRight;
NSColor* foregroundColor = nil; NSColor* foregroundColor = nil;
if([self isHighlighted]) foregroundColor = [NSColor alternateSelectedControlTextColor]; if([self isHighlighted]) foregroundColor = [NSColor alternateSelectedControlTextColor];
else if(!listView->enabled(true)) foregroundColor = [NSColor disabledControlTextColor]; else if(!tableView->enabled(true)) foregroundColor = [NSColor disabledControlTextColor];
else if(auto color = listViewCell->state.foregroundColor) foregroundColor = NSMakeColor(color); else if(auto color = tableViewCell->state.foregroundColor) foregroundColor = NSMakeColor(color);
else foregroundColor = [NSColor textColor]; else foregroundColor = [NSColor textColor];
NSString* text = [NSString stringWithUTF8String:listViewCell->state.text]; NSString* text = [NSString stringWithUTF8String:tableViewCell->state.text];
[text drawInRect:frame withAttributes:@{ [text drawInRect:frame withAttributes:@{
NSBackgroundColorAttributeName:backgroundColor, NSBackgroundColorAttributeName:backgroundColor,
NSForegroundColorAttributeName:foregroundColor, NSForegroundColorAttributeName:foregroundColor,
NSFontAttributeName:hiro::pFont::create(listViewCell->font(true)), NSFontAttributeName:hiro::pFont::create(tableViewCell->font(true)),
NSParagraphStyleAttributeName:paragraphStyle NSParagraphStyleAttributeName:paragraphStyle
}]; }];
} }
@ -233,10 +233,10 @@
NSPoint point = [view convertPointFromBase:[nextEvent locationInWindow]]; NSPoint point = [view convertPointFromBase:[nextEvent locationInWindow]];
NSRect rect = NSMakeRect(frame.origin.x, frame.origin.y, frame.size.height, frame.size.height); NSRect rect = NSMakeRect(frame.origin.x, frame.origin.y, frame.size.height, frame.size.height);
if(NSMouseInRect(point, rect, [view isFlipped])) { if(NSMouseInRect(point, rect, [view isFlipped])) {
if(auto listViewItem = listView->item([view rowAtPoint:point])) { if(auto tableViewItem = tableView->item([view rowAtPoint:point])) {
if(auto listViewCell = listViewItem->cell([view columnAtPoint:point])) { if(auto tableViewCell = tableViewItem->cell([view columnAtPoint:point])) {
listViewCell->state.checked = !listViewCell->state.checked; tableViewCell->state.checked = !tableViewCell->state.checked;
listView->doToggle(listViewCell->instance); tableView->doToggle(tableViewCell->instance);
} }
} }
} }
@ -255,9 +255,9 @@
namespace hiro { namespace hiro {
auto pListView::construct() -> void { auto pTableView::construct() -> void {
@autoreleasepool { @autoreleasepool {
cocoaView = cocoaListView = [[CocoaListView alloc] initWith:self()]; cocoaView = cocoaTableView = [[CocoaTableView alloc] initWith:self()];
pWidget::construct(); pWidget::construct();
setAlignment(state().alignment); setAlignment(state().alignment);
@ -269,14 +269,14 @@ auto pListView::construct() -> void {
} }
} }
auto pListView::destruct() -> void { auto pTableView::destruct() -> void {
@autoreleasepool { @autoreleasepool {
[cocoaView removeFromSuperview]; [cocoaView removeFromSuperview];
[cocoaView release]; [cocoaView release];
} }
} }
auto pListView::append(sListViewHeader header) -> void { auto pTableView::append(sTableViewHeader header) -> void {
@autoreleasepool { @autoreleasepool {
[cocoaView reloadColumns]; [cocoaView reloadColumns];
@ -284,25 +284,25 @@ auto pListView::append(sListViewHeader header) -> void {
} }
} }
auto pListView::append(sListViewItem item) -> void { auto pTableView::append(sTableViewItem item) -> void {
@autoreleasepool { @autoreleasepool {
[[cocoaView content] reloadData]; [[cocoaView content] reloadData];
} }
} }
auto pListView::remove(sListViewHeader header) -> void { auto pTableView::remove(sTableViewHeader header) -> void {
@autoreleasepool { @autoreleasepool {
[cocoaView reloadColumns]; [cocoaView reloadColumns];
} }
} }
auto pListView::remove(sListViewItem item) -> void { auto pTableView::remove(sTableViewItem item) -> void {
@autoreleasepool { @autoreleasepool {
[[cocoaView content] reloadData]; [[cocoaView content] reloadData];
} }
} }
auto pListView::resizeColumns() -> void { auto pTableView::resizeColumns() -> void {
@autoreleasepool { @autoreleasepool {
if(auto& header = state().header) { if(auto& header = state().header) {
vector<int> widths; vector<int> widths;
@ -333,71 +333,71 @@ auto pListView::resizeColumns() -> void {
} }
} }
auto pListView::setAlignment(Alignment alignment) -> void { auto pTableView::setAlignment(Alignment alignment) -> void {
} }
auto pListView::setBackgroundColor(Color color) -> void { auto pTableView::setBackgroundColor(Color color) -> void {
} }
auto pListView::setBatchable(bool batchable) -> void { auto pTableView::setBatchable(bool batchable) -> void {
@autoreleasepool { @autoreleasepool {
[[cocoaView content] setAllowsMultipleSelection:(batchable ? YES : NO)]; [[cocoaView content] setAllowsMultipleSelection:(batchable ? YES : NO)];
} }
} }
auto pListView::setBordered(bool bordered) -> void { auto pTableView::setBordered(bool bordered) -> void {
} }
auto pListView::setEnabled(bool enabled) -> void { auto pTableView::setEnabled(bool enabled) -> void {
pWidget::setEnabled(enabled); pWidget::setEnabled(enabled);
@autoreleasepool { @autoreleasepool {
[[cocoaView content] setEnabled:enabled]; [[cocoaView content] setEnabled:enabled];
} }
} }
auto pListView::setFont(const Font& font) -> void { auto pTableView::setFont(const Font& font) -> void {
@autoreleasepool { @autoreleasepool {
[cocoaView setFont:pFont::create(font)]; [cocoaView setFont:pFont::create(font)];
} }
} }
auto pListView::setForegroundColor(Color color) -> void { auto pTableView::setForegroundColor(Color color) -> void {
} }
auto pListView::_cellWidth(uint row, uint column) -> uint { auto pTableView::_cellWidth(uint row, uint column) -> uint {
uint width = 8; uint width = 8;
if(auto pListViewItem = self().item(row)) { if(auto pTableViewItem = self().item(row)) {
if(auto pListViewCell = pListViewItem->cell(column)) { if(auto pTableViewCell = pTableViewItem->cell(column)) {
if(pListViewCell->state.checkable) { if(pTableViewCell->state.checkable) {
width += 24; width += 24;
} }
if(auto& icon = pListViewCell->state.icon) { if(auto& icon = pTableViewCell->state.icon) {
width += icon.width() + 2; width += icon.width() + 2;
} }
if(auto& text = pListViewCell->state.text) { if(auto& text = pTableViewCell->state.text) {
width += pFont::size(pListViewCell->font(true), text).width(); width += pFont::size(pTableViewCell->font(true), text).width();
} }
} }
} }
return width; return width;
} }
auto pListView::_columnWidth(uint column) -> uint { auto pTableView::_columnWidth(uint column) -> uint {
uint width = 8; uint width = 8;
if(auto& header = state().header) { if(auto& header = state().header) {
if(auto pListViewColumn = header->column(column)) { if(auto pTableViewColumn = header->column(column)) {
if(auto& icon = pListViewColumn->state.icon) { if(auto& icon = pTableViewColumn->state.icon) {
width += icon.width() + 2; width += icon.width() + 2;
} }
if(auto& text = pListViewColumn->state.text) { if(auto& text = pTableViewColumn->state.text) {
width += pFont::size(pListViewColumn->font(true), text).width(); width += pFont::size(pTableViewColumn->font(true), text).width();
} }
} }
} }
return width; return width;
} }
auto pListView::_width(uint column) -> uint { auto pTableView::_width(uint column) -> uint {
if(auto& header = state().header) { if(auto& header = state().header) {
if(auto width = header->column(column).width()) return width; if(auto width = header->column(column).width()) return width;
uint width = 1; uint width = 1;
@ -412,20 +412,20 @@ auto pListView::_width(uint column) -> uint {
} }
/* /*
auto pListView::autoSizeColumns() -> void { auto pTableView::autoSizeColumns() -> void {
@autoreleasepool { @autoreleasepool {
if(listView.state.checkable) { if(tableView.state.checkable) {
NSTableColumn* tableColumn = [[cocoaView content] tableColumnWithIdentifier:@"check"]; NSTableColumn* tableColumn = [[cocoaView content] tableColumnWithIdentifier:@"check"];
[tableColumn setWidth:20.0]; [tableColumn setWidth:20.0];
} }
unsigned height = [[cocoaView content] rowHeight]; unsigned height = [[cocoaView content] rowHeight];
for(unsigned column = 0; column < max(1u, listView.state.headerText.size()); column++) { for(unsigned column = 0; column < max(1u, tableView.state.headerText.size()); column++) {
NSTableColumn* tableColumn = [[cocoaView content] tableColumnWithIdentifier:[[NSNumber numberWithInteger:column] stringValue]]; NSTableColumn* tableColumn = [[cocoaView content] tableColumnWithIdentifier:[[NSNumber numberWithInteger:column] stringValue]];
unsigned minimumWidth = pFont::size([[tableColumn headerCell] font], listView.state.headerText(column)).width + 4; unsigned minimumWidth = pFont::size([[tableColumn headerCell] font], tableView.state.headerText(column)).width + 4;
for(unsigned row = 0; row < listView.state.text.size(); row++) { for(unsigned row = 0; row < tableView.state.text.size(); row++) {
unsigned width = pFont::size([cocoaView font], listView.state.text(row)(column)).width + 2; unsigned width = pFont::size([cocoaView font], tableView.state.text(row)(column)).width + 2;
if(listView.state.image(row)(height).empty() == false) width += height + 2; if(tableView.state.image(row)(height).empty() == false) width += height + 2;
if(width > minimumWidth) minimumWidth = width; if(width > minimumWidth) minimumWidth = width;
} }
[tableColumn setWidth:minimumWidth]; [tableColumn setWidth:minimumWidth];
@ -435,7 +435,7 @@ auto pListView::autoSizeColumns() -> void {
} }
} }
auto pListView::setSelected(bool selected) -> void { auto pTableView::setSelected(bool selected) -> void {
@autoreleasepool { @autoreleasepool {
if(selected == false) { if(selected == false) {
[[cocoaView content] deselectAll:nil]; [[cocoaView content] deselectAll:nil];
@ -443,7 +443,7 @@ auto pListView::setSelected(bool selected) -> void {
} }
} }
auto pListView::setSelection(unsigned selection) -> void { auto pTableView::setSelection(unsigned selection) -> void {
@autoreleasepool { @autoreleasepool {
[[cocoaView content] selectRowIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(selection, 1)] byExtendingSelection:NO]; [[cocoaView content] selectRowIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(selection, 1)] byExtendingSelection:NO];
} }

View File

@ -1,16 +1,16 @@
#if defined(Hiro_ListView) #if defined(Hiro_TableView)
@class CocoaListViewContent; @class CocoaTableViewContent;
@interface CocoaListView : NSScrollView <NSTableViewDelegate, NSTableViewDataSource> { @interface CocoaTableView : NSScrollView <NSTableViewDelegate, NSTableViewDataSource> {
@public @public
hiro::mListView* listView; hiro::mTableView* tableView;
CocoaListViewContent* content; CocoaTableViewContent* content;
NSFont* font; NSFont* font;
} }
-(id) initWith:(hiro::mListView&)listView; -(id) initWith:(hiro::mTableView&)tableView;
-(void) dealloc; -(void) dealloc;
-(CocoaListViewContent*) content; -(CocoaTableViewContent*) content;
-(NSFont*) font; -(NSFont*) font;
-(void) setFont:(NSFont*)font; -(void) setFont:(NSFont*)font;
-(void) reloadColumns; -(void) reloadColumns;
@ -24,16 +24,16 @@
-(IBAction) doubleAction:(id)sender; -(IBAction) doubleAction:(id)sender;
@end @end
@interface CocoaListViewContent : NSTableView { @interface CocoaTableViewContent : NSTableView {
} }
-(void) keyDown:(NSEvent*)event; -(void) keyDown:(NSEvent*)event;
@end @end
@interface CocoaListViewCell : NSCell { @interface CocoaTableViewCell : NSCell {
hiro::mListView* listView; hiro::mTableView* tableView;
NSButtonCell* buttonCell; NSButtonCell* buttonCell;
} }
-(id) initWith:(hiro::mListView&)listViewReference; -(id) initWith:(hiro::mTableView&)tableViewReference;
-(NSString*) stringValue; -(NSString*) stringValue;
-(void) drawWithFrame:(NSRect)frame inView:(NSView*)view; -(void) drawWithFrame:(NSRect)frame inView:(NSView*)view;
-(NSUInteger) hitTestForEvent:(NSEvent*)event inRect:(NSRect)frame ofView:(NSView*)view; -(NSUInteger) hitTestForEvent:(NSEvent*)event inRect:(NSRect)frame ofView:(NSView*)view;
@ -43,13 +43,13 @@
namespace hiro { namespace hiro {
struct pListView : pWidget { struct pTableView : pWidget {
Declare(ListView, Widget) Declare(TableView, Widget)
auto append(sListViewHeader header) -> void; auto append(sTableViewHeader header) -> void;
auto append(sListViewItem item) -> void; auto append(sTableViewItem item) -> void;
auto remove(sListViewHeader header) -> void; auto remove(sTableViewHeader header) -> void;
auto remove(sListViewItem item) -> void; auto remove(sTableViewItem item) -> void;
auto resizeColumns() -> void; auto resizeColumns() -> void;
auto setAlignment(Alignment alignment) -> void; auto setAlignment(Alignment alignment) -> void;
auto setBackgroundColor(Color color) -> void; auto setBackgroundColor(Color color) -> void;
@ -63,7 +63,7 @@ struct pListView : pWidget {
auto _columnWidth(uint column) -> uint; auto _columnWidth(uint column) -> uint;
auto _width(uint column) -> uint; auto _width(uint column) -> uint;
CocoaListView* cocoaListView = nullptr; CocoaTableView* cocoaTableView = nullptr;
}; };
} }

View File

@ -24,7 +24,7 @@
-(BOOL) performDragOperation:(id<NSDraggingInfo>)sender { -(BOOL) performDragOperation:(id<NSDraggingInfo>)sender {
lstring paths = DropPaths(sender); lstring paths = DropPaths(sender);
if(paths.empty()) return NO; if(!paths) return NO;
viewport->doDrop(paths); viewport->doDrop(paths);
return YES; return YES;
} }

View File

@ -122,7 +122,7 @@
-(BOOL) performDragOperation:(id<NSDraggingInfo>)sender { -(BOOL) performDragOperation:(id<NSDraggingInfo>)sender {
lstring paths = DropPaths(sender); lstring paths = DropPaths(sender);
if(paths.empty()) return NO; if(!paths) return NO;
window->doDrop(paths); window->doDrop(paths);
return YES; return YES;
} }

View File

@ -62,12 +62,12 @@
#define Hiro_IconView #define Hiro_IconView
#define Hiro_Label #define Hiro_Label
#define Hiro_LineEdit #define Hiro_LineEdit
#define Hiro_ListView
#define Hiro_ProgressBar #define Hiro_ProgressBar
#define Hiro_RadioButton #define Hiro_RadioButton
#define Hiro_RadioLabel #define Hiro_RadioLabel
#define Hiro_SourceEdit #define Hiro_SourceEdit
#define Hiro_TabFrame #define Hiro_TabFrame
#define Hiro_TableView
#define Hiro_TextEdit #define Hiro_TextEdit
#define Hiro_TreeView #define Hiro_TreeView
#define Hiro_VerticalScrollBar #define Hiro_VerticalScrollBar
@ -89,10 +89,14 @@
#undef Hiro_HexEdit #undef Hiro_HexEdit
#endif #endif
#if defined(Hiro_TableView)
#define Hiro_ListView
#endif
#if defined(Hiro_Button) && defined(Hiro_Canvas) && defined(Hiro_Label) #if defined(Hiro_Button) && defined(Hiro_Canvas) && defined(Hiro_Label)
#define Hiro_MessageDialog #define Hiro_MessageDialog
#endif #endif
#if defined(Hiro_Button) && defined(Hiro_ComboButton) && defined(Hiro_LineEdit) && defined(Hiro_ListView) && defined(Hiro_MessageDialog) #if defined(Hiro_Button) && defined(Hiro_ComboButton) && defined(Hiro_LineEdit) && defined(Hiro_TableView) && defined(Hiro_MessageDialog)
#define Hiro_BrowserDialog #define Hiro_BrowserDialog
#endif #endif

View File

@ -86,17 +86,17 @@ namespace hiro {
#include "widget/icon-view-item.cpp" #include "widget/icon-view-item.cpp"
#include "widget/label.cpp" #include "widget/label.cpp"
#include "widget/line-edit.cpp" #include "widget/line-edit.cpp"
#include "widget/list-view.cpp"
#include "widget/list-view-header.cpp"
#include "widget/list-view-column.cpp"
#include "widget/list-view-item.cpp"
#include "widget/list-view-cell.cpp"
#include "widget/progress-bar.cpp" #include "widget/progress-bar.cpp"
#include "widget/radio-button.cpp" #include "widget/radio-button.cpp"
#include "widget/radio-label.cpp" #include "widget/radio-label.cpp"
#include "widget/source-edit.cpp" #include "widget/source-edit.cpp"
#include "widget/tab-frame.cpp" #include "widget/tab-frame.cpp"
#include "widget/tab-frame-item.cpp" #include "widget/tab-frame-item.cpp"
#include "widget/table-view.cpp"
#include "widget/table-view-header.cpp"
#include "widget/table-view-column.cpp"
#include "widget/table-view-item.cpp"
#include "widget/table-view-cell.cpp"
#include "widget/text-edit.cpp" #include "widget/text-edit.cpp"
#include "widget/tree-view.cpp" #include "widget/tree-view.cpp"
#include "widget/tree-view-item.cpp" #include "widget/tree-view-item.cpp"

View File

@ -67,17 +67,17 @@ Declare(IconView)
Declare(IconViewItem) Declare(IconViewItem)
Declare(Label) Declare(Label)
Declare(LineEdit) Declare(LineEdit)
Declare(ListView)
Declare(ListViewHeader)
Declare(ListViewColumn)
Declare(ListViewItem)
Declare(ListViewCell)
Declare(ProgressBar) Declare(ProgressBar)
Declare(RadioButton) Declare(RadioButton)
Declare(RadioLabel) Declare(RadioLabel)
Declare(SourceEdit) Declare(SourceEdit)
Declare(TabFrame) Declare(TabFrame)
Declare(TabFrameItem) Declare(TabFrameItem)
Declare(TableView)
Declare(TableViewHeader)
Declare(TableViewColumn)
Declare(TableViewItem)
Declare(TableViewCell)
Declare(TextEdit) Declare(TextEdit)
Declare(TreeView) Declare(TreeView)
Declare(TreeViewItem) Declare(TreeViewItem)
@ -575,15 +575,15 @@ struct mObject {
auto parentFrame(bool recursive = false) const -> mFrame*; auto parentFrame(bool recursive = false) const -> mFrame*;
auto parentIconView(bool recursive = false) const -> mIconView*; auto parentIconView(bool recursive = false) const -> mIconView*;
auto parentLayout(bool recursive = false) const -> mLayout*; auto parentLayout(bool recursive = false) const -> mLayout*;
auto parentListView(bool recursive = false) const -> mListView*;
auto parentListViewHeader(bool recursive = false) const -> mListViewHeader*;
auto parentListViewItem(bool recursive = false) const -> mListViewItem*;
auto parentMenu(bool recursive = false) const -> mMenu*; auto parentMenu(bool recursive = false) const -> mMenu*;
auto parentMenuBar(bool recursive = false) const -> mMenuBar*; auto parentMenuBar(bool recursive = false) const -> mMenuBar*;
auto parentPopupMenu(bool recursive = false) const -> mPopupMenu*; auto parentPopupMenu(bool recursive = false) const -> mPopupMenu*;
auto parentSizable(bool recursive = false) const -> mSizable*; auto parentSizable(bool recursive = false) const -> mSizable*;
auto parentTabFrame(bool recursive = false) const -> mTabFrame*; auto parentTabFrame(bool recursive = false) const -> mTabFrame*;
auto parentTabFrameItem(bool recursive = false) const -> mTabFrameItem*; auto parentTabFrameItem(bool recursive = false) const -> mTabFrameItem*;
auto parentTableView(bool recursive = false) const -> mTableView*;
auto parentTableViewHeader(bool recursive = false) const -> mTableViewHeader*;
auto parentTableViewItem(bool recursive = false) const -> mTableViewItem*;
auto parentTreeView(bool recursive = false) const -> mTreeView*; auto parentTreeView(bool recursive = false) const -> mTreeView*;
auto parentTreeViewItem(bool recursive = false) const -> mTreeViewItem*; auto parentTreeViewItem(bool recursive = false) const -> mTreeViewItem*;
auto parentWidget(bool recursive = false) const -> mWidget*; auto parentWidget(bool recursive = false) const -> mWidget*;
@ -1356,205 +1356,6 @@ struct mLineEdit : mWidget {
}; };
#endif #endif
#if defined(Hiro_ListView)
struct mListView : mWidget {
Declare(ListView)
using mObject::remove;
auto alignment() const -> Alignment;
auto append(sListViewHeader column) -> type&;
auto append(sListViewItem item) -> type&;
auto backgroundColor() const -> Color;
auto batchable() const -> bool;
auto batched() const -> vector<ListViewItem>;
auto bordered() const -> bool;
auto doActivate() const -> void;
auto doChange() const -> void;
auto doContext() const -> void;
auto doEdit(sListViewCell cell) const -> void;
auto doSort(sListViewColumn column) const -> void;
auto doToggle(sListViewCell cell) const -> void;
auto foregroundColor() const -> Color;
auto header() const -> ListViewHeader;
auto item(unsigned position) const -> ListViewItem;
auto itemCount() const -> unsigned;
auto items() const -> vector<ListViewItem>;
auto onActivate(const function<void ()>& callback = {}) -> type&;
auto onChange(const function<void ()>& callback = {}) -> type&;
auto onContext(const function<void ()>& callback = {}) -> type&;
auto onEdit(const function<void (ListViewCell)>& callback = {}) -> type&;
auto onSort(const function<void (ListViewColumn)>& callback = {}) -> type&;
auto onToggle(const function<void (ListViewCell)>& callback = {}) -> type&;
auto remove(sListViewHeader column) -> type&;
auto remove(sListViewItem item) -> type&;
auto reset() -> type&;
auto resizeColumns() -> type&;
auto selected() const -> ListViewItem;
auto setAlignment(Alignment alignment = {}) -> type&;
auto setBackgroundColor(Color color = {}) -> type&;
auto setBatchable(bool batchable = true) -> type&;
auto setBordered(bool bordered = true) -> type&;
auto setForegroundColor(Color color = {}) -> type&;
auto setParent(mObject* parent = nullptr, signed offset = -1) -> type& override;
//private:
struct State {
unsigned activeColumn = 0;
Alignment alignment;
Color backgroundColor;
bool batchable = false;
bool bordered = false;
Color foregroundColor;
sListViewHeader header;
vector<sListViewItem> items;
function<void ()> onActivate;
function<void ()> onChange;
function<void ()> onContext;
function<void (ListViewCell)> onEdit;
function<void (ListViewColumn)> onSort;
function<void (ListViewCell)> onToggle;
} state;
auto destruct() -> void override;
};
#endif
#if defined(Hiro_ListView)
struct mListViewHeader : mObject {
Declare(ListViewHeader)
auto append(sListViewColumn column) -> type&;
auto column(unsigned position) const -> ListViewColumn;
auto columnCount() const -> unsigned;
auto columns() const -> vector<ListViewColumn>;
auto remove() -> type& override;
auto remove(sListViewColumn column) -> type&;
auto setParent(mObject* parent = nullptr, signed offset = -1) -> type& override;
//private:
struct State {
vector<sListViewColumn> columns;
} state;
};
#endif
#if defined(Hiro_ListView)
struct mListViewColumn : mObject {
Declare(ListViewColumn)
auto active() const -> bool;
auto alignment() const -> Alignment;
auto backgroundColor() const -> Color;
auto editable() const -> bool;
auto expandable() const -> bool;
auto foregroundColor() const -> Color;
auto horizontalAlignment() const -> double;
auto icon() const -> image;
auto remove() -> type& override;
auto resizable() const -> bool;
auto setActive() -> type&;
auto setAlignment(Alignment alignment = {}) -> type&;
auto setBackgroundColor(Color color = {}) -> type&;
auto setEditable(bool editable = true) -> type&;
auto setExpandable(bool expandable = true) -> type&;
auto setForegroundColor(Color color = {}) -> type&;
auto setHorizontalAlignment(double alignment = 0.0) -> type&;
auto setIcon(const image& icon = {}) -> type&;
auto setResizable(bool resizable = true) -> type&;
auto setSortable(bool sortable = true) -> type&;
auto setText(const string& text = "") -> type&;
auto setVerticalAlignment(double alignment = 0.5) -> type&;
auto setVisible(bool visible = true) -> type&;
auto setWidth(signed width = 0) -> type&;
auto sortable() const -> bool;
auto text() const -> string;
auto verticalAlignment() const -> double;
auto width() const -> signed;
//private:
struct State {
Alignment alignment;
Color backgroundColor;
bool editable = false;
bool expandable = false;
Color foregroundColor;
double horizontalAlignment = 0.0;
image icon;
bool resizable = true;
bool sortable = false;
string text;
double verticalAlignment = 0.5;
bool visible = true;
signed width = 0;
} state;
};
#endif
#if defined(Hiro_ListView)
struct mListViewItem : mObject {
Declare(ListViewItem)
auto alignment() const -> Alignment;
auto append(sListViewCell cell) -> type&;
auto backgroundColor() const -> Color;
auto cell(unsigned position) const -> ListViewCell;
auto cellCount() const -> unsigned;
auto cells() const -> vector<ListViewCell>;
auto foregroundColor() const -> Color;
auto remove() -> type& override;
auto remove(sListViewCell cell) -> type&;
auto selected() const -> bool;
auto setAlignment(Alignment alignment = {}) -> type&;
auto setBackgroundColor(Color color = {}) -> type&;
auto setFocused() -> type& override;
auto setForegroundColor(Color color = {}) -> type&;
auto setParent(mObject* parent = nullptr, signed offset = -1) -> type& override;
auto setSelected(bool selected = true) -> type&;
//private:
struct State {
Alignment alignment;
Color backgroundColor;
vector<sListViewCell> cells;
Color foregroundColor;
bool selected = false;
} state;
};
#endif
#if defined(Hiro_ListView)
struct mListViewCell : mObject {
Declare(ListViewCell)
auto alignment(bool recursive = false) const -> Alignment;
auto backgroundColor(bool recursive = false) const -> Color;
auto checkable() const -> bool;
auto checked() const -> bool;
auto font(bool recursive = false) const -> Font;
auto foregroundColor(bool recursive = false) const -> Color;
auto icon() const -> image;
auto setAlignment(Alignment alignment = {}) -> type&;
auto setBackgroundColor(Color color = {}) -> type&;
auto setCheckable(bool checkable = true) -> type&;
auto setChecked(bool checked = true) -> type&;
auto setForegroundColor(Color color = {}) -> type&;
auto setIcon(const image& icon = {}) -> type&;
auto setText(const string& text = "") -> type&;
auto text() const -> string;
//private:
struct State {
Alignment alignment;
Color backgroundColor;
bool checkable = false;
bool checked = false;
Color foregroundColor;
image icon;
string text;
} state;
};
#endif
#if defined(Hiro_ProgressBar) #if defined(Hiro_ProgressBar)
struct mProgressBar : mWidget { struct mProgressBar : mWidget {
Declare(ProgressBar) Declare(ProgressBar)
@ -1718,6 +1519,207 @@ struct mTabFrameItem : mObject {
}; };
#endif #endif
#if defined(Hiro_TableView)
struct mTableView : mWidget {
Declare(TableView)
using mObject::remove;
auto alignment() const -> Alignment;
auto append(sTableViewHeader column) -> type&;
auto append(sTableViewItem item) -> type&;
auto backgroundColor() const -> Color;
auto batchable() const -> bool;
auto batched() const -> vector<TableViewItem>;
auto bordered() const -> bool;
auto doActivate() const -> void;
auto doChange() const -> void;
auto doContext() const -> void;
auto doEdit(sTableViewCell cell) const -> void;
auto doSort(sTableViewColumn column) const -> void;
auto doToggle(sTableViewCell cell) const -> void;
auto foregroundColor() const -> Color;
auto header() const -> TableViewHeader;
auto item(unsigned position) const -> TableViewItem;
auto itemCount() const -> unsigned;
auto items() const -> vector<TableViewItem>;
auto onActivate(const function<void ()>& callback = {}) -> type&;
auto onChange(const function<void ()>& callback = {}) -> type&;
auto onContext(const function<void ()>& callback = {}) -> type&;
auto onEdit(const function<void (TableViewCell)>& callback = {}) -> type&;
auto onSort(const function<void (TableViewColumn)>& callback = {}) -> type&;
auto onToggle(const function<void (TableViewCell)>& callback = {}) -> type&;
auto remove(sTableViewHeader column) -> type&;
auto remove(sTableViewItem item) -> type&;
auto reset() -> type&;
auto resizeColumns() -> type&;
auto selected() const -> TableViewItem;
auto setAlignment(Alignment alignment = {}) -> type&;
auto setBackgroundColor(Color color = {}) -> type&;
auto setBatchable(bool batchable = true) -> type&;
auto setBordered(bool bordered = true) -> type&;
auto setForegroundColor(Color color = {}) -> type&;
auto setParent(mObject* parent = nullptr, signed offset = -1) -> type& override;
//private:
struct State {
unsigned activeColumn = 0;
Alignment alignment;
Color backgroundColor;
bool batchable = false;
bool bordered = false;
Color foregroundColor;
sTableViewHeader header;
vector<sTableViewItem> items;
function<void ()> onActivate;
function<void ()> onChange;
function<void ()> onContext;
function<void (TableViewCell)> onEdit;
function<void (TableViewColumn)> onSort;
function<void (TableViewCell)> onToggle;
} state;
auto destruct() -> void override;
};
#endif
#if defined(Hiro_TableView)
struct mTableViewHeader : mObject {
Declare(TableViewHeader)
auto append(sTableViewColumn column) -> type&;
auto column(unsigned position) const -> TableViewColumn;
auto columnCount() const -> unsigned;
auto columns() const -> vector<TableViewColumn>;
auto remove() -> type& override;
auto remove(sTableViewColumn column) -> type&;
auto reset() -> type&;
auto setParent(mObject* parent = nullptr, signed offset = -1) -> type& override;
//private:
struct State {
vector<sTableViewColumn> columns;
} state;
};
#endif
#if defined(Hiro_TableView)
struct mTableViewColumn : mObject {
Declare(TableViewColumn)
auto active() const -> bool;
auto alignment() const -> Alignment;
auto backgroundColor() const -> Color;
auto editable() const -> bool;
auto expandable() const -> bool;
auto foregroundColor() const -> Color;
auto horizontalAlignment() const -> double;
auto icon() const -> image;
auto remove() -> type& override;
auto resizable() const -> bool;
auto setActive() -> type&;
auto setAlignment(Alignment alignment = {}) -> type&;
auto setBackgroundColor(Color color = {}) -> type&;
auto setEditable(bool editable = true) -> type&;
auto setExpandable(bool expandable = true) -> type&;
auto setForegroundColor(Color color = {}) -> type&;
auto setHorizontalAlignment(double alignment = 0.0) -> type&;
auto setIcon(const image& icon = {}) -> type&;
auto setResizable(bool resizable = true) -> type&;
auto setSortable(bool sortable = true) -> type&;
auto setText(const string& text = "") -> type&;
auto setVerticalAlignment(double alignment = 0.5) -> type&;
auto setVisible(bool visible = true) -> type&;
auto setWidth(signed width = 0) -> type&;
auto sortable() const -> bool;
auto text() const -> string;
auto verticalAlignment() const -> double;
auto width() const -> signed;
//private:
struct State {
Alignment alignment;
Color backgroundColor;
bool editable = false;
bool expandable = false;
Color foregroundColor;
double horizontalAlignment = 0.0;
image icon;
bool resizable = true;
bool sortable = false;
string text;
double verticalAlignment = 0.5;
bool visible = true;
signed width = 0;
} state;
};
#endif
#if defined(Hiro_TableView)
struct mTableViewItem : mObject {
Declare(TableViewItem)
auto alignment() const -> Alignment;
auto append(sTableViewCell cell) -> type&;
auto backgroundColor() const -> Color;
auto cell(unsigned position) const -> TableViewCell;
auto cellCount() const -> unsigned;
auto cells() const -> vector<TableViewCell>;
auto foregroundColor() const -> Color;
auto remove() -> type& override;
auto remove(sTableViewCell cell) -> type&;
auto reset() -> type&;
auto selected() const -> bool;
auto setAlignment(Alignment alignment = {}) -> type&;
auto setBackgroundColor(Color color = {}) -> type&;
auto setFocused() -> type& override;
auto setForegroundColor(Color color = {}) -> type&;
auto setParent(mObject* parent = nullptr, signed offset = -1) -> type& override;
auto setSelected(bool selected = true) -> type&;
//private:
struct State {
Alignment alignment;
Color backgroundColor;
vector<sTableViewCell> cells;
Color foregroundColor;
bool selected = false;
} state;
};
#endif
#if defined(Hiro_TableView)
struct mTableViewCell : mObject {
Declare(TableViewCell)
auto alignment(bool recursive = false) const -> Alignment;
auto backgroundColor(bool recursive = false) const -> Color;
auto checkable() const -> bool;
auto checked() const -> bool;
auto font(bool recursive = false) const -> Font;
auto foregroundColor(bool recursive = false) const -> Color;
auto icon() const -> image;
auto setAlignment(Alignment alignment = {}) -> type&;
auto setBackgroundColor(Color color = {}) -> type&;
auto setCheckable(bool checkable = true) -> type&;
auto setChecked(bool checked = true) -> type&;
auto setForegroundColor(Color color = {}) -> type&;
auto setIcon(const image& icon = {}) -> type&;
auto setText(const string& text = "") -> type&;
auto text() const -> string;
//private:
struct State {
Alignment alignment;
Color backgroundColor;
bool checkable = false;
bool checked = false;
Color foregroundColor;
image icon;
string text;
} state;
};
#endif
#if defined(Hiro_TextEdit) #if defined(Hiro_TextEdit)
struct mTextEdit : mWidget { struct mTextEdit : mWidget {
Declare(TextEdit) Declare(TextEdit)

View File

@ -130,36 +130,6 @@ auto mObject::parentLayout(bool recursive) const -> mLayout* {
} }
#endif #endif
#if defined(Hiro_ListView)
auto mObject::parentListView(bool recursive) const -> mListView* {
if(auto listView = dynamic_cast<mListView*>(parent())) return listView;
if(recursive) {
if(auto object = parent()) return object->parentListView(true);
}
return nullptr;
}
#endif
#if defined(Hiro_ListView)
auto mObject::parentListViewHeader(bool recursive) const -> mListViewHeader* {
if(auto listViewHeader = dynamic_cast<mListViewHeader*>(parent())) return listViewHeader;
if(recursive) {
if(auto object = parent()) return object->parentListViewHeader(true);
}
return nullptr;
}
#endif
#if defined(Hiro_ListView)
auto mObject::parentListViewItem(bool recursive) const -> mListViewItem* {
if(auto listViewItem = dynamic_cast<mListViewItem*>(parent())) return listViewItem;
if(recursive) {
if(auto object = parent()) return object->parentListViewItem(true);
}
return nullptr;
}
#endif
#if defined(Hiro_Menu) #if defined(Hiro_Menu)
auto mObject::parentMenu(bool recursive) const -> mMenu* { auto mObject::parentMenu(bool recursive) const -> mMenu* {
if(auto menu = dynamic_cast<mMenu*>(parent())) return menu; if(auto menu = dynamic_cast<mMenu*>(parent())) return menu;
@ -220,6 +190,36 @@ auto mObject::parentTabFrameItem(bool recursive) const -> mTabFrameItem* {
} }
#endif #endif
#if defined(Hiro_TableView)
auto mObject::parentTableView(bool recursive) const -> mTableView* {
if(auto tableView = dynamic_cast<mTableView*>(parent())) return tableView;
if(recursive) {
if(auto object = parent()) return object->parentTableView(true);
}
return nullptr;
}
#endif
#if defined(Hiro_TableView)
auto mObject::parentTableViewHeader(bool recursive) const -> mTableViewHeader* {
if(auto tableViewHeader = dynamic_cast<mTableViewHeader*>(parent())) return tableViewHeader;
if(recursive) {
if(auto object = parent()) return object->parentTableViewHeader(true);
}
return nullptr;
}
#endif
#if defined(Hiro_TableView)
auto mObject::parentTableViewItem(bool recursive) const -> mTableViewItem* {
if(auto tableViewItem = dynamic_cast<mTableViewItem*>(parent())) return tableViewItem;
if(recursive) {
if(auto object = parent()) return object->parentTableViewItem(true);
}
return nullptr;
}
#endif
#if defined(Hiro_TreeView) #if defined(Hiro_TreeView)
auto mObject::parentTreeView(bool recursive) const -> mTreeView* { auto mObject::parentTreeView(bool recursive) const -> mTreeView* {
if(auto treeView = dynamic_cast<mTreeView*>(parent())) return treeView; if(auto treeView = dynamic_cast<mTreeView*>(parent())) return treeView;

View File

@ -485,136 +485,6 @@ struct LineEdit : sLineEdit {
}; };
#endif #endif
#if defined(Hiro_ListView)
struct ListViewColumn : sListViewColumn {
DeclareSharedObject(ListViewColumn)
using internalType = mListViewColumn;
auto active() const { return self().active(); }
auto alignment() const { return self().alignment(); }
auto backgroundColor() const { return self().backgroundColor(); }
auto editable() const { return self().editable(); }
auto expandable() const { return self().expandable(); }
auto foregroundColor() const { return self().foregroundColor(); }
auto horizontalAlignment() const { return self().horizontalAlignment(); }
auto icon() const { return self().icon(); }
auto resizable() const { return self().resizable(); }
auto setActive() { return self().setActive(), *this; }
auto setAlignment(Alignment alignment = {}) { return self().setAlignment(alignment), *this; }
auto setBackgroundColor(Color color = {}) { return self().setBackgroundColor(color), *this; }
auto setEditable(bool editable = true) { return self().setEditable(editable), *this; }
auto setExpandable(bool expandable = true) { return self().setExpandable(expandable), *this; }
auto setForegroundColor(Color color = {}) { return self().setForegroundColor(color), *this; }
auto setIcon(const image& icon = {}) { return self().setIcon(icon), *this; }
auto setResizable(bool resizable = true) { return self().setResizable(resizable), *this; }
auto setSortable(bool sortable = true) { return self().setSortable(sortable), *this; }
auto setText(const string& text = "") { return self().setText(text), *this; }
auto setWidth(signed width = 0) { return self().setWidth(width), *this; }
auto sortable() const { return self().sortable(); }
auto text() const { return self().text(); }
auto verticalAlignment() const { return self().verticalAlignment(); }
auto width() const { return self().width(); }
};
#endif
#if defined(Hiro_ListView)
struct ListViewHeader : sListViewHeader {
DeclareSharedObject(ListViewHeader)
using internalType = mListViewHeader;
auto append(sListViewColumn column) { return self().append(column), *this; }
auto column(unsigned position) const { return self().column(position); }
auto columnCount() const { return self().columnCount(); }
auto columns() const { return self().columns(); }
auto remove(sListViewColumn column) { return self().remove(column), *this; }
};
#endif
#if defined(Hiro_ListView)
struct ListViewCell : sListViewCell {
DeclareSharedObject(ListViewCell)
using internalType = mListViewCell;
auto alignment() const { return self().alignment(); }
auto backgroundColor() const { return self().backgroundColor(); }
auto checkable() const { return self().checkable(); }
auto checked() const { return self().checked(); }
auto foregroundColor() const { return self().foregroundColor(); }
auto icon() const { return self().icon(); }
auto setAlignment(Alignment alignment = {}) { return self().setAlignment(alignment), *this; }
auto setBackgroundColor(Color color = {}) { return self().setBackgroundColor(color), *this; }
auto setCheckable(bool checkable = true) const { return self().setCheckable(checkable), *this; }
auto setChecked(bool checked = true) const { return self().setChecked(checked), *this; }
auto setForegroundColor(Color color = {}) { return self().setForegroundColor(color), *this; }
auto setIcon(const image& icon = {}) { return self().setIcon(icon), *this; }
auto setText(const string& text = "") { return self().setText(text), *this; }
auto text() const { return self().text(); }
};
#endif
#if defined(Hiro_ListView)
struct ListViewItem : sListViewItem {
DeclareSharedObject(ListViewItem)
using internalType = mListViewItem;
auto alignment() const { return self().alignment(); }
auto append(sListViewCell cell) { return self().append(cell), *this; }
auto backgroundColor() const { return self().backgroundColor(); }
auto cell(unsigned position) const { return self().cell(position); }
auto cellCount() const { return self().cellCount(); }
auto cells() const { return self().cells(); }
auto foregroundColor() const { return self().foregroundColor(); }
auto remove(sListViewCell cell) { return self().remove(cell), *this; }
auto selected() const { return self().selected(); }
auto setAlignment(Alignment alignment = {}) { return self().setAlignment(alignment), *this; }
auto setBackgroundColor(Color color = {}) { return self().setBackgroundColor(color), *this; }
auto setForegroundColor(Color color = {}) { return self().setForegroundColor(color), *this; }
auto setSelected(bool selected = true) { return self().setSelected(selected), *this; }
};
#endif
#if defined(Hiro_ListView)
struct ListView : sListView {
DeclareSharedWidget(ListView)
using internalType = mListView;
auto alignment() const { return self().alignment(); }
auto append(sListViewHeader header) { return self().append(header), *this; }
auto append(sListViewItem item) { return self().append(item), *this; }
auto backgroundColor() const { return self().backgroundColor(); }
auto batchable() const { return self().batchable(); }
auto batched() const { return self().batched(); }
auto bordered() const { return self().bordered(); }
auto doActivate() const { return self().doActivate(); }
auto doChange() const { return self().doChange(); }
auto doContext() const { return self().doContext(); }
auto doEdit(sListViewCell cell) const { return self().doEdit(cell); }
auto doSort(sListViewColumn column) const { return self().doSort(column); }
auto doToggle(sListViewCell cell) const { return self().doToggle(cell); }
auto foregroundColor() const { return self().foregroundColor(); }
auto header() const { return self().header(); }
auto item(unsigned position) const { return self().item(position); }
auto itemCount() const { return self().itemCount(); }
auto items() const { return self().items(); }
auto onActivate(const function<void ()>& callback = {}) { return self().onActivate(callback), *this; }
auto onChange(const function<void ()>& callback = {}) { return self().onChange(callback), *this; }
auto onContext(const function<void ()>& callback = {}) { return self().onContext(callback), *this; }
auto onEdit(const function<void (ListViewCell)>& callback = {}) { return self().onEdit(callback), *this; }
auto onSort(const function<void (ListViewColumn)>& callback = {}) { return self().onSort(callback), *this; }
auto onToggle(const function<void (ListViewCell)>& callback = {}) { return self().onToggle(callback), *this; }
auto remove(sListViewHeader header) { return self().remove(header), *this; }
auto remove(sListViewItem item) { return self().remove(item), *this; }
auto reset() { return self().reset(), *this; }
auto resizeColumns() { return self().resizeColumns(), *this; }
auto selected() const { return self().selected(); }
auto setAlignment(Alignment alignment = {}) { return self().setAlignment(alignment), *this; }
auto setBackgroundColor(Color color = {}) { return self().setBackgroundColor(color), *this; }
auto setBatchable(bool batchable = true) { return self().setBatchable(batchable), *this; }
auto setBordered(bool bordered = true) { return self().setBordered(bordered), *this; }
auto setForegroundColor(Color color = {}) { return self().setForegroundColor(color), *this; }
};
#endif
#if defined(Hiro_ProgressBar) #if defined(Hiro_ProgressBar)
struct ProgressBar : sProgressBar { struct ProgressBar : sProgressBar {
DeclareSharedWidget(ProgressBar) DeclareSharedWidget(ProgressBar)
@ -722,6 +592,138 @@ struct TabFrame : sTabFrame {
}; };
#endif #endif
#if defined(Hiro_TableView)
struct TableViewColumn : sTableViewColumn {
DeclareSharedObject(TableViewColumn)
using internalType = mTableViewColumn;
auto active() const { return self().active(); }
auto alignment() const { return self().alignment(); }
auto backgroundColor() const { return self().backgroundColor(); }
auto editable() const { return self().editable(); }
auto expandable() const { return self().expandable(); }
auto foregroundColor() const { return self().foregroundColor(); }
auto horizontalAlignment() const { return self().horizontalAlignment(); }
auto icon() const { return self().icon(); }
auto resizable() const { return self().resizable(); }
auto setActive() { return self().setActive(), *this; }
auto setAlignment(Alignment alignment = {}) { return self().setAlignment(alignment), *this; }
auto setBackgroundColor(Color color = {}) { return self().setBackgroundColor(color), *this; }
auto setEditable(bool editable = true) { return self().setEditable(editable), *this; }
auto setExpandable(bool expandable = true) { return self().setExpandable(expandable), *this; }
auto setForegroundColor(Color color = {}) { return self().setForegroundColor(color), *this; }
auto setIcon(const image& icon = {}) { return self().setIcon(icon), *this; }
auto setResizable(bool resizable = true) { return self().setResizable(resizable), *this; }
auto setSortable(bool sortable = true) { return self().setSortable(sortable), *this; }
auto setText(const string& text = "") { return self().setText(text), *this; }
auto setWidth(signed width = 0) { return self().setWidth(width), *this; }
auto sortable() const { return self().sortable(); }
auto text() const { return self().text(); }
auto verticalAlignment() const { return self().verticalAlignment(); }
auto width() const { return self().width(); }
};
#endif
#if defined(Hiro_TableView)
struct TableViewHeader : sTableViewHeader {
DeclareSharedObject(TableViewHeader)
using internalType = mTableViewHeader;
auto append(sTableViewColumn column) { return self().append(column), *this; }
auto column(unsigned position) const { return self().column(position); }
auto columnCount() const { return self().columnCount(); }
auto columns() const { return self().columns(); }
auto remove(sTableViewColumn column) { return self().remove(column), *this; }
auto reset() { return self().reset(), *this; }
};
#endif
#if defined(Hiro_TableView)
struct TableViewCell : sTableViewCell {
DeclareSharedObject(TableViewCell)
using internalType = mTableViewCell;
auto alignment() const { return self().alignment(); }
auto backgroundColor() const { return self().backgroundColor(); }
auto checkable() const { return self().checkable(); }
auto checked() const { return self().checked(); }
auto foregroundColor() const { return self().foregroundColor(); }
auto icon() const { return self().icon(); }
auto setAlignment(Alignment alignment = {}) { return self().setAlignment(alignment), *this; }
auto setBackgroundColor(Color color = {}) { return self().setBackgroundColor(color), *this; }
auto setCheckable(bool checkable = true) const { return self().setCheckable(checkable), *this; }
auto setChecked(bool checked = true) const { return self().setChecked(checked), *this; }
auto setForegroundColor(Color color = {}) { return self().setForegroundColor(color), *this; }
auto setIcon(const image& icon = {}) { return self().setIcon(icon), *this; }
auto setText(const string& text = "") { return self().setText(text), *this; }
auto text() const { return self().text(); }
};
#endif
#if defined(Hiro_TableView)
struct TableViewItem : sTableViewItem {
DeclareSharedObject(TableViewItem)
using internalType = mTableViewItem;
auto alignment() const { return self().alignment(); }
auto append(sTableViewCell cell) { return self().append(cell), *this; }
auto backgroundColor() const { return self().backgroundColor(); }
auto cell(unsigned position) const { return self().cell(position); }
auto cellCount() const { return self().cellCount(); }
auto cells() const { return self().cells(); }
auto foregroundColor() const { return self().foregroundColor(); }
auto remove(sTableViewCell cell) { return self().remove(cell), *this; }
auto reset() { return self().reset(), *this; }
auto selected() const { return self().selected(); }
auto setAlignment(Alignment alignment = {}) { return self().setAlignment(alignment), *this; }
auto setBackgroundColor(Color color = {}) { return self().setBackgroundColor(color), *this; }
auto setForegroundColor(Color color = {}) { return self().setForegroundColor(color), *this; }
auto setSelected(bool selected = true) { return self().setSelected(selected), *this; }
};
#endif
#if defined(Hiro_TableView)
struct TableView : sTableView {
DeclareSharedWidget(TableView)
using internalType = mTableView;
auto alignment() const { return self().alignment(); }
auto append(sTableViewHeader header) { return self().append(header), *this; }
auto append(sTableViewItem item) { return self().append(item), *this; }
auto backgroundColor() const { return self().backgroundColor(); }
auto batchable() const { return self().batchable(); }
auto batched() const { return self().batched(); }
auto bordered() const { return self().bordered(); }
auto doActivate() const { return self().doActivate(); }
auto doChange() const { return self().doChange(); }
auto doContext() const { return self().doContext(); }
auto doEdit(sTableViewCell cell) const { return self().doEdit(cell); }
auto doSort(sTableViewColumn column) const { return self().doSort(column); }
auto doToggle(sTableViewCell cell) const { return self().doToggle(cell); }
auto foregroundColor() const { return self().foregroundColor(); }
auto header() const { return self().header(); }
auto item(unsigned position) const { return self().item(position); }
auto itemCount() const { return self().itemCount(); }
auto items() const { return self().items(); }
auto onActivate(const function<void ()>& callback = {}) { return self().onActivate(callback), *this; }
auto onChange(const function<void ()>& callback = {}) { return self().onChange(callback), *this; }
auto onContext(const function<void ()>& callback = {}) { return self().onContext(callback), *this; }
auto onEdit(const function<void (TableViewCell)>& callback = {}) { return self().onEdit(callback), *this; }
auto onSort(const function<void (TableViewColumn)>& callback = {}) { return self().onSort(callback), *this; }
auto onToggle(const function<void (TableViewCell)>& callback = {}) { return self().onToggle(callback), *this; }
auto remove(sTableViewHeader header) { return self().remove(header), *this; }
auto remove(sTableViewItem item) { return self().remove(item), *this; }
auto reset() { return self().reset(), *this; }
auto resizeColumns() { return self().resizeColumns(), *this; }
auto selected() const { return self().selected(); }
auto setAlignment(Alignment alignment = {}) { return self().setAlignment(alignment), *this; }
auto setBackgroundColor(Color color = {}) { return self().setBackgroundColor(color), *this; }
auto setBatchable(bool batchable = true) { return self().setBatchable(batchable), *this; }
auto setBordered(bool bordered = true) { return self().setBordered(bordered), *this; }
auto setForegroundColor(Color color = {}) { return self().setForegroundColor(color), *this; }
};
#endif
#if defined(Hiro_TextEdit) #if defined(Hiro_TextEdit)
struct TextEdit : sTextEdit { struct TextEdit : sTextEdit {
DeclareSharedWidget(TextEdit) DeclareSharedWidget(TextEdit)

View File

@ -1,153 +0,0 @@
#if defined(Hiro_ListView)
auto mListViewColumn::allocate() -> pObject* {
return new pListViewColumn(*this);
}
//
auto mListViewColumn::active() const -> bool {
if(auto listView = parentListView()) return listView->state.activeColumn == offset();
return false;
}
auto mListViewColumn::alignment() const -> Alignment {
return state.alignment;
}
auto mListViewColumn::backgroundColor() const -> Color {
return state.backgroundColor;
}
auto mListViewColumn::editable() const -> bool {
return state.editable;
}
auto mListViewColumn::expandable() const -> bool {
return state.expandable;
}
auto mListViewColumn::foregroundColor() const -> Color {
return state.foregroundColor;
}
auto mListViewColumn::horizontalAlignment() const -> double {
return state.horizontalAlignment;
}
auto mListViewColumn::icon() const -> image {
return state.icon;
}
auto mListViewColumn::remove() -> type& {
if(auto listView = parentListViewHeader()) listView->remove(*this);
return *this;
}
auto mListViewColumn::resizable() const -> bool {
return state.resizable;
}
auto mListViewColumn::setActive() -> type& {
if(auto listView = parentListView()) listView->state.activeColumn = offset();
signal(setActive);
return *this;
}
auto mListViewColumn::setAlignment(Alignment alignment) -> type& {
state.alignment = alignment;
signal(setAlignment, alignment);
return *this;
}
auto mListViewColumn::setBackgroundColor(Color color) -> type& {
state.backgroundColor = color;
signal(setBackgroundColor, color);
return *this;
}
auto mListViewColumn::setEditable(bool editable) -> type& {
state.editable = editable;
signal(setEditable, editable);
return *this;
}
auto mListViewColumn::setExpandable(bool expandable) -> type& {
state.expandable = expandable;
signal(setExpandable, expandable);
return *this;
}
auto mListViewColumn::setForegroundColor(Color color) -> type& {
state.foregroundColor = color;
signal(setForegroundColor, color);
return *this;
}
auto mListViewColumn::setHorizontalAlignment(double alignment) -> type& {
alignment = max(0.0, min(1.0, alignment));
state.horizontalAlignment = alignment;
signal(setHorizontalAlignment, alignment);
return *this;
}
auto mListViewColumn::setIcon(const image& icon) -> type& {
state.icon = icon;
signal(setIcon, icon);
return *this;
}
auto mListViewColumn::setResizable(bool resizable) -> type& {
state.resizable = resizable;
signal(setResizable, resizable);
return *this;
}
auto mListViewColumn::setSortable(bool sortable) -> type& {
state.sortable = sortable;
signal(setSortable, sortable);
return *this;
}
auto mListViewColumn::setText(const string& text) -> type& {
state.text = text;
signal(setText, text);
return *this;
}
auto mListViewColumn::setVerticalAlignment(double alignment) -> type& {
alignment = max(0.0, min(1.0, alignment));
state.verticalAlignment = alignment;
signal(setVerticalAlignment, alignment);
return *this;
}
auto mListViewColumn::setVisible(bool visible) -> type& {
state.visible = visible;
signal(setVisible, visible);
return *this;
}
auto mListViewColumn::setWidth(signed width) -> type& {
state.width = max(0, width);
signal(setWidth, width);
return *this;
}
auto mListViewColumn::sortable() const -> bool {
return state.sortable;
}
auto mListViewColumn::text() const -> string {
return state.text;
}
auto mListViewColumn::verticalAlignment() const -> double {
return state.verticalAlignment;
}
auto mListViewColumn::width() const -> signed {
return state.width;
}
#endif

View File

@ -1,53 +0,0 @@
#if defined(Hiro_ListView)
auto mListViewHeader::allocate() -> pObject* {
return new pListViewHeader(*this);
}
//
auto mListViewHeader::append(sListViewColumn column) -> type& {
state.columns.append(column);
column->setParent(this, columnCount() - 1);
signal(append, column);
return *this;
}
auto mListViewHeader::column(unsigned position) const -> ListViewColumn {
if(position < columnCount()) return state.columns[position];
return {};
}
auto mListViewHeader::columnCount() const -> unsigned {
return state.columns.size();
}
auto mListViewHeader::columns() const -> vector<ListViewColumn> {
vector<ListViewColumn> columns;
for(auto& column : state.columns) columns.append(column);
return columns;
}
auto mListViewHeader::remove() -> type& {
if(auto listView = parentListView()) listView->remove(*this);
return *this;
}
auto mListViewHeader::remove(sListViewColumn column) -> type& {
signal(remove, column);
state.columns.remove(column->offset());
for(auto n : range(column->offset(), columnCount())) {
state.columns[n]->adjustOffset(-1);
}
column->setParent();
return *this;
}
auto mListViewHeader::setParent(mObject* parent, signed offset) -> type& {
for(auto& column : state.columns) column->destruct();
mObject::setParent(parent, offset);
for(auto& column : state.columns) column->setParent(this, column->offset());
return *this;
}
#endif

View File

@ -1,98 +0,0 @@
#if defined(Hiro_ListView)
auto mListViewItem::allocate() -> pObject* {
return new pListViewItem(*this);
}
//
auto mListViewItem::alignment() const -> Alignment {
return state.alignment;
}
auto mListViewItem::append(sListViewCell cell) -> type& {
state.cells.append(cell);
cell->setParent(this, cellCount() - 1);
signal(append, cell);
return *this;
}
auto mListViewItem::backgroundColor() const -> Color {
return state.backgroundColor;
}
auto mListViewItem::cell(unsigned position) const -> ListViewCell {
if(position < cellCount()) return state.cells[position];
return {};
}
auto mListViewItem::cellCount() const -> unsigned {
return state.cells.size();
}
auto mListViewItem::cells() const -> vector<ListViewCell> {
vector<ListViewCell> cells;
for(auto& cell : state.cells) cells.append(cell);
return cells;
}
auto mListViewItem::foregroundColor() const -> Color {
return state.foregroundColor;
}
auto mListViewItem::remove() -> type& {
if(auto listView = parentListView()) listView->remove(*this);
return *this;
}
auto mListViewItem::remove(sListViewCell cell) -> type& {
signal(remove, cell);
state.cells.remove(cell->offset());
for(auto n : range(cell->offset(), cellCount())) {
state.cells[n]->adjustOffset(-1);
}
cell->setParent();
return *this;
}
auto mListViewItem::selected() const -> bool {
return state.selected;
}
auto mListViewItem::setAlignment(Alignment alignment) -> type& {
state.alignment = alignment;
signal(setAlignment, alignment);
return *this;
}
auto mListViewItem::setBackgroundColor(Color color) -> type& {
state.backgroundColor = color;
signal(setBackgroundColor, color);
return *this;
}
auto mListViewItem::setFocused() -> type& {
signal(setFocused);
return *this;
}
auto mListViewItem::setForegroundColor(Color color) -> type& {
state.foregroundColor = color;
signal(setForegroundColor, color);
return *this;
}
auto mListViewItem::setParent(mObject* parent, signed offset) -> type& {
for(auto& cell : state.cells) cell->destruct();
mObject::setParent(parent, offset);
for(auto& cell : state.cells) cell->setParent(this, cell->offset());
return *this;
}
auto mListViewItem::setSelected(bool selected) -> type& {
state.selected = selected;
signal(setSelected, selected);
return *this;
}
#endif

View File

@ -1,17 +1,17 @@
#if defined(Hiro_ListView) #if defined(Hiro_TableView)
auto mListViewCell::allocate() -> pObject* { auto mTableViewCell::allocate() -> pObject* {
return new pListViewCell(*this); return new pTableViewCell(*this);
} }
// //
auto mListViewCell::alignment(bool recursive) const -> Alignment { auto mTableViewCell::alignment(bool recursive) const -> Alignment {
if(auto alignment = state.alignment) return alignment; if(auto alignment = state.alignment) return alignment;
if(recursive) { if(recursive) {
if(auto parent = parentListViewItem()) { if(auto parent = parentTableViewItem()) {
if(auto alignment = parent->state.alignment) return alignment; if(auto alignment = parent->state.alignment) return alignment;
if(auto grandparent = parent->parentListView()) { if(auto grandparent = parent->parentTableView()) {
if(auto header = grandparent->state.header) { if(auto header = grandparent->state.header) {
if(offset() < header->columnCount()) { if(offset() < header->columnCount()) {
if(auto column = header->state.columns[offset()]) { if(auto column = header->state.columns[offset()]) {
@ -26,12 +26,12 @@ auto mListViewCell::alignment(bool recursive) const -> Alignment {
return {}; return {};
} }
auto mListViewCell::backgroundColor(bool recursive) const -> Color { auto mTableViewCell::backgroundColor(bool recursive) const -> Color {
if(auto color = state.backgroundColor) return color; if(auto color = state.backgroundColor) return color;
if(recursive) { if(recursive) {
if(auto parent = parentListViewItem()) { if(auto parent = parentTableViewItem()) {
if(auto color = parent->state.backgroundColor) return color; if(auto color = parent->state.backgroundColor) return color;
if(auto grandparent = parent->parentListView()) { if(auto grandparent = parent->parentTableView()) {
if(auto header = grandparent->state.header) { if(auto header = grandparent->state.header) {
if(offset() < header->columnCount()) { if(offset() < header->columnCount()) {
if(auto column = header->state.columns[offset()]) { if(auto column = header->state.columns[offset()]) {
@ -46,20 +46,20 @@ auto mListViewCell::backgroundColor(bool recursive) const -> Color {
return {}; return {};
} }
auto mListViewCell::checkable() const -> bool { auto mTableViewCell::checkable() const -> bool {
return state.checkable; return state.checkable;
} }
auto mListViewCell::checked() const -> bool { auto mTableViewCell::checked() const -> bool {
return state.checkable && state.checked; return state.checkable && state.checked;
} }
auto mListViewCell::font(bool recursive) const -> Font { auto mTableViewCell::font(bool recursive) const -> Font {
if(auto font = mObject::font()) return font; if(auto font = mObject::font()) return font;
if(recursive) { if(recursive) {
if(auto parent = parentListViewItem()) { if(auto parent = parentTableViewItem()) {
if(auto font = parent->font()) return font; if(auto font = parent->font()) return font;
if(auto grandparent = parent->parentListView()) { if(auto grandparent = parent->parentTableView()) {
if(auto header = grandparent->state.header) { if(auto header = grandparent->state.header) {
if(offset() < header->columnCount()) { if(offset() < header->columnCount()) {
if(auto column = header->state.columns[offset()]) { if(auto column = header->state.columns[offset()]) {
@ -74,12 +74,12 @@ auto mListViewCell::font(bool recursive) const -> Font {
return {}; return {};
} }
auto mListViewCell::foregroundColor(bool recursive) const -> Color { auto mTableViewCell::foregroundColor(bool recursive) const -> Color {
if(auto color = state.foregroundColor) return color; if(auto color = state.foregroundColor) return color;
if(recursive) { if(recursive) {
if(auto parent = parentListViewItem()) { if(auto parent = parentTableViewItem()) {
if(auto color = parent->state.foregroundColor) return color; if(auto color = parent->state.foregroundColor) return color;
if(auto grandparent = parent->parentListView()) { if(auto grandparent = parent->parentTableView()) {
if(auto header = grandparent->state.header) { if(auto header = grandparent->state.header) {
if(offset() < header->columnCount()) { if(offset() < header->columnCount()) {
if(auto column = header->state.columns[offset()]) { if(auto column = header->state.columns[offset()]) {
@ -94,54 +94,54 @@ auto mListViewCell::foregroundColor(bool recursive) const -> Color {
return state.foregroundColor; return state.foregroundColor;
} }
auto mListViewCell::icon() const -> image { auto mTableViewCell::icon() const -> image {
return state.icon; return state.icon;
} }
auto mListViewCell::setAlignment(Alignment alignment) -> type& { auto mTableViewCell::setAlignment(Alignment alignment) -> type& {
state.alignment = alignment; state.alignment = alignment;
signal(setAlignment, alignment); signal(setAlignment, alignment);
return *this; return *this;
} }
auto mListViewCell::setBackgroundColor(Color color) -> type& { auto mTableViewCell::setBackgroundColor(Color color) -> type& {
state.backgroundColor = color; state.backgroundColor = color;
signal(setBackgroundColor, color); signal(setBackgroundColor, color);
return *this; return *this;
} }
auto mListViewCell::setCheckable(bool checkable) -> type& { auto mTableViewCell::setCheckable(bool checkable) -> type& {
state.checkable = checkable; state.checkable = checkable;
signal(setCheckable, checkable); signal(setCheckable, checkable);
return *this; return *this;
} }
auto mListViewCell::setChecked(bool checked) -> type& { auto mTableViewCell::setChecked(bool checked) -> type& {
setCheckable(true); setCheckable(true);
state.checked = checked; state.checked = checked;
signal(setChecked, checked); signal(setChecked, checked);
return *this; return *this;
} }
auto mListViewCell::setForegroundColor(Color color) -> type& { auto mTableViewCell::setForegroundColor(Color color) -> type& {
state.foregroundColor = color; state.foregroundColor = color;
signal(setForegroundColor, color); signal(setForegroundColor, color);
return *this; return *this;
} }
auto mListViewCell::setIcon(const image& icon) -> type& { auto mTableViewCell::setIcon(const image& icon) -> type& {
state.icon = icon; state.icon = icon;
signal(setIcon, icon); signal(setIcon, icon);
return *this; return *this;
} }
auto mListViewCell::setText(const string& text) -> type& { auto mTableViewCell::setText(const string& text) -> type& {
state.text = text; state.text = text;
signal(setText, text); signal(setText, text);
return *this; return *this;
} }
auto mListViewCell::text() const -> string { auto mTableViewCell::text() const -> string {
return state.text; return state.text;
} }

View File

@ -0,0 +1,153 @@
#if defined(Hiro_TableView)
auto mTableViewColumn::allocate() -> pObject* {
return new pTableViewColumn(*this);
}
//
auto mTableViewColumn::active() const -> bool {
if(auto tableView = parentTableView()) return tableView->state.activeColumn == offset();
return false;
}
auto mTableViewColumn::alignment() const -> Alignment {
return state.alignment;
}
auto mTableViewColumn::backgroundColor() const -> Color {
return state.backgroundColor;
}
auto mTableViewColumn::editable() const -> bool {
return state.editable;
}
auto mTableViewColumn::expandable() const -> bool {
return state.expandable;
}
auto mTableViewColumn::foregroundColor() const -> Color {
return state.foregroundColor;
}
auto mTableViewColumn::horizontalAlignment() const -> double {
return state.horizontalAlignment;
}
auto mTableViewColumn::icon() const -> image {
return state.icon;
}
auto mTableViewColumn::remove() -> type& {
if(auto tableView = parentTableViewHeader()) tableView->remove(*this);
return *this;
}
auto mTableViewColumn::resizable() const -> bool {
return state.resizable;
}
auto mTableViewColumn::setActive() -> type& {
if(auto tableView = parentTableView()) tableView->state.activeColumn = offset();
signal(setActive);
return *this;
}
auto mTableViewColumn::setAlignment(Alignment alignment) -> type& {
state.alignment = alignment;
signal(setAlignment, alignment);
return *this;
}
auto mTableViewColumn::setBackgroundColor(Color color) -> type& {
state.backgroundColor = color;
signal(setBackgroundColor, color);
return *this;
}
auto mTableViewColumn::setEditable(bool editable) -> type& {
state.editable = editable;
signal(setEditable, editable);
return *this;
}
auto mTableViewColumn::setExpandable(bool expandable) -> type& {
state.expandable = expandable;
signal(setExpandable, expandable);
return *this;
}
auto mTableViewColumn::setForegroundColor(Color color) -> type& {
state.foregroundColor = color;
signal(setForegroundColor, color);
return *this;
}
auto mTableViewColumn::setHorizontalAlignment(double alignment) -> type& {
alignment = max(0.0, min(1.0, alignment));
state.horizontalAlignment = alignment;
signal(setHorizontalAlignment, alignment);
return *this;
}
auto mTableViewColumn::setIcon(const image& icon) -> type& {
state.icon = icon;
signal(setIcon, icon);
return *this;
}
auto mTableViewColumn::setResizable(bool resizable) -> type& {
state.resizable = resizable;
signal(setResizable, resizable);
return *this;
}
auto mTableViewColumn::setSortable(bool sortable) -> type& {
state.sortable = sortable;
signal(setSortable, sortable);
return *this;
}
auto mTableViewColumn::setText(const string& text) -> type& {
state.text = text;
signal(setText, text);
return *this;
}
auto mTableViewColumn::setVerticalAlignment(double alignment) -> type& {
alignment = max(0.0, min(1.0, alignment));
state.verticalAlignment = alignment;
signal(setVerticalAlignment, alignment);
return *this;
}
auto mTableViewColumn::setVisible(bool visible) -> type& {
state.visible = visible;
signal(setVisible, visible);
return *this;
}
auto mTableViewColumn::setWidth(signed width) -> type& {
state.width = max(0, width);
signal(setWidth, width);
return *this;
}
auto mTableViewColumn::sortable() const -> bool {
return state.sortable;
}
auto mTableViewColumn::text() const -> string {
return state.text;
}
auto mTableViewColumn::verticalAlignment() const -> double {
return state.verticalAlignment;
}
auto mTableViewColumn::width() const -> signed {
return state.width;
}
#endif

View File

@ -0,0 +1,58 @@
#if defined(Hiro_TableView)
auto mTableViewHeader::allocate() -> pObject* {
return new pTableViewHeader(*this);
}
//
auto mTableViewHeader::append(sTableViewColumn column) -> type& {
state.columns.append(column);
column->setParent(this, columnCount() - 1);
signal(append, column);
return *this;
}
auto mTableViewHeader::column(unsigned position) const -> TableViewColumn {
if(position < columnCount()) return state.columns[position];
return {};
}
auto mTableViewHeader::columnCount() const -> unsigned {
return state.columns.size();
}
auto mTableViewHeader::columns() const -> vector<TableViewColumn> {
vector<TableViewColumn> columns;
for(auto& column : state.columns) columns.append(column);
return columns;
}
auto mTableViewHeader::remove() -> type& {
if(auto tableView = parentTableView()) tableView->remove(*this);
return *this;
}
auto mTableViewHeader::remove(sTableViewColumn column) -> type& {
signal(remove, column);
state.columns.remove(column->offset());
for(auto n : range(column->offset(), columnCount())) {
state.columns[n]->adjustOffset(-1);
}
column->setParent();
return *this;
}
auto mTableViewHeader::reset() -> type& {
for(auto n : rrange(state.columns)) remove(state.columns[n]);
return *this;
}
auto mTableViewHeader::setParent(mObject* parent, signed offset) -> type& {
for(auto& column : state.columns) column->destruct();
mObject::setParent(parent, offset);
for(auto& column : state.columns) column->setParent(this, column->offset());
return *this;
}
#endif

View File

@ -0,0 +1,103 @@
#if defined(Hiro_TableView)
auto mTableViewItem::allocate() -> pObject* {
return new pTableViewItem(*this);
}
//
auto mTableViewItem::alignment() const -> Alignment {
return state.alignment;
}
auto mTableViewItem::append(sTableViewCell cell) -> type& {
state.cells.append(cell);
cell->setParent(this, cellCount() - 1);
signal(append, cell);
return *this;
}
auto mTableViewItem::backgroundColor() const -> Color {
return state.backgroundColor;
}
auto mTableViewItem::cell(unsigned position) const -> TableViewCell {
if(position < cellCount()) return state.cells[position];
return {};
}
auto mTableViewItem::cellCount() const -> unsigned {
return state.cells.size();
}
auto mTableViewItem::cells() const -> vector<TableViewCell> {
vector<TableViewCell> cells;
for(auto& cell : state.cells) cells.append(cell);
return cells;
}
auto mTableViewItem::foregroundColor() const -> Color {
return state.foregroundColor;
}
auto mTableViewItem::remove() -> type& {
if(auto tableView = parentTableView()) tableView->remove(*this);
return *this;
}
auto mTableViewItem::remove(sTableViewCell cell) -> type& {
signal(remove, cell);
state.cells.remove(cell->offset());
for(auto n : range(cell->offset(), cellCount())) {
state.cells[n]->adjustOffset(-1);
}
cell->setParent();
return *this;
}
auto mTableViewItem::reset() -> type& {
for(auto n : rrange(state.cells)) remove(state.cells[n]);
return *this;
}
auto mTableViewItem::selected() const -> bool {
return state.selected;
}
auto mTableViewItem::setAlignment(Alignment alignment) -> type& {
state.alignment = alignment;
signal(setAlignment, alignment);
return *this;
}
auto mTableViewItem::setBackgroundColor(Color color) -> type& {
state.backgroundColor = color;
signal(setBackgroundColor, color);
return *this;
}
auto mTableViewItem::setFocused() -> type& {
signal(setFocused);
return *this;
}
auto mTableViewItem::setForegroundColor(Color color) -> type& {
state.foregroundColor = color;
signal(setForegroundColor, color);
return *this;
}
auto mTableViewItem::setParent(mObject* parent, signed offset) -> type& {
for(auto& cell : state.cells) cell->destruct();
mObject::setParent(parent, offset);
for(auto& cell : state.cells) cell->setParent(this, cell->offset());
return *this;
}
auto mTableViewItem::setSelected(bool selected) -> type& {
state.selected = selected;
signal(setSelected, selected);
return *this;
}
#endif

View File

@ -1,10 +1,10 @@
#if defined(Hiro_ListView) #if defined(Hiro_TableView)
auto mListView::allocate() -> pObject* { auto mTableView::allocate() -> pObject* {
return new pListView(*this); return new pTableView(*this);
} }
auto mListView::destruct() -> void { auto mTableView::destruct() -> void {
for(auto& item : state.items) item->destruct(); for(auto& item : state.items) item->destruct();
if(auto& header = state.header) header->destruct(); if(auto& header = state.header) header->destruct();
mWidget::destruct(); mWidget::destruct();
@ -12,11 +12,11 @@ auto mListView::destruct() -> void {
// //
auto mListView::alignment() const -> Alignment { auto mTableView::alignment() const -> Alignment {
return state.alignment; return state.alignment;
} }
auto mListView::append(sListViewHeader header) -> type& { auto mTableView::append(sTableViewHeader header) -> type& {
if(auto& header = state.header) remove(header); if(auto& header = state.header) remove(header);
state.header = header; state.header = header;
header->setParent(this, 0); header->setParent(this, 0);
@ -24,118 +24,118 @@ auto mListView::append(sListViewHeader header) -> type& {
return *this; return *this;
} }
auto mListView::append(sListViewItem item) -> type& { auto mTableView::append(sTableViewItem item) -> type& {
state.items.append(item); state.items.append(item);
item->setParent(this, itemCount() - 1); item->setParent(this, itemCount() - 1);
signal(append, item); signal(append, item);
return *this; return *this;
} }
auto mListView::backgroundColor() const -> Color { auto mTableView::backgroundColor() const -> Color {
return state.backgroundColor; return state.backgroundColor;
} }
auto mListView::batchable() const -> bool { auto mTableView::batchable() const -> bool {
return state.batchable; return state.batchable;
} }
auto mListView::batched() const -> vector<ListViewItem> { auto mTableView::batched() const -> vector<TableViewItem> {
vector<ListViewItem> items; vector<TableViewItem> items;
for(auto& item : state.items) { for(auto& item : state.items) {
if(item->selected()) items.append(item); if(item->selected()) items.append(item);
} }
return items; return items;
} }
auto mListView::bordered() const -> bool { auto mTableView::bordered() const -> bool {
return state.bordered; return state.bordered;
} }
auto mListView::doActivate() const -> void { auto mTableView::doActivate() const -> void {
if(state.onActivate) return state.onActivate(); if(state.onActivate) return state.onActivate();
} }
auto mListView::doChange() const -> void { auto mTableView::doChange() const -> void {
if(state.onChange) return state.onChange(); if(state.onChange) return state.onChange();
} }
auto mListView::doContext() const -> void { auto mTableView::doContext() const -> void {
if(state.onContext) return state.onContext(); if(state.onContext) return state.onContext();
} }
auto mListView::doEdit(sListViewCell cell) const -> void { auto mTableView::doEdit(sTableViewCell cell) const -> void {
if(state.onEdit) return state.onEdit(cell); if(state.onEdit) return state.onEdit(cell);
} }
auto mListView::doSort(sListViewColumn column) const -> void { auto mTableView::doSort(sTableViewColumn column) const -> void {
if(state.onSort) return state.onSort(column); if(state.onSort) return state.onSort(column);
} }
auto mListView::doToggle(sListViewCell cell) const -> void { auto mTableView::doToggle(sTableViewCell cell) const -> void {
if(state.onToggle) return state.onToggle(cell); if(state.onToggle) return state.onToggle(cell);
} }
auto mListView::foregroundColor() const -> Color { auto mTableView::foregroundColor() const -> Color {
return state.foregroundColor; return state.foregroundColor;
} }
auto mListView::header() const -> ListViewHeader { auto mTableView::header() const -> TableViewHeader {
return state.header; return state.header;
} }
auto mListView::item(unsigned position) const -> ListViewItem { auto mTableView::item(unsigned position) const -> TableViewItem {
if(position < itemCount()) return state.items[position]; if(position < itemCount()) return state.items[position];
return {}; return {};
} }
auto mListView::itemCount() const -> unsigned { auto mTableView::itemCount() const -> unsigned {
return state.items.size(); return state.items.size();
} }
auto mListView::items() const -> vector<ListViewItem> { auto mTableView::items() const -> vector<TableViewItem> {
vector<ListViewItem> items; vector<TableViewItem> items;
for(auto& item : state.items) items.append(item); for(auto& item : state.items) items.append(item);
return items; return items;
} }
auto mListView::onActivate(const function<void ()>& callback) -> type& { auto mTableView::onActivate(const function<void ()>& callback) -> type& {
state.onActivate = callback; state.onActivate = callback;
return *this; return *this;
} }
auto mListView::onChange(const function<void ()>& callback) -> type& { auto mTableView::onChange(const function<void ()>& callback) -> type& {
state.onChange = callback; state.onChange = callback;
return *this; return *this;
} }
auto mListView::onContext(const function<void ()>& callback) -> type& { auto mTableView::onContext(const function<void ()>& callback) -> type& {
state.onContext = callback; state.onContext = callback;
return *this; return *this;
} }
auto mListView::onEdit(const function<void (ListViewCell)>& callback) -> type& { auto mTableView::onEdit(const function<void (TableViewCell)>& callback) -> type& {
state.onEdit = callback; state.onEdit = callback;
return *this; return *this;
} }
auto mListView::onSort(const function<void (ListViewColumn)>& callback) -> type& { auto mTableView::onSort(const function<void (TableViewColumn)>& callback) -> type& {
state.onSort = callback; state.onSort = callback;
return *this; return *this;
} }
auto mListView::onToggle(const function<void (ListViewCell)>& callback) -> type& { auto mTableView::onToggle(const function<void (TableViewCell)>& callback) -> type& {
state.onToggle = callback; state.onToggle = callback;
return *this; return *this;
} }
auto mListView::remove(sListViewHeader header) -> type& { auto mTableView::remove(sTableViewHeader header) -> type& {
signal(remove, header); signal(remove, header);
header->setParent(); header->setParent();
state.header.reset(); state.header.reset();
return *this; return *this;
} }
auto mListView::remove(sListViewItem item) -> type& { auto mTableView::remove(sTableViewItem item) -> type& {
signal(remove, item); signal(remove, item);
state.items.remove(item->offset()); state.items.remove(item->offset());
for(auto n : range(item->offset(), itemCount())) { for(auto n : range(item->offset(), itemCount())) {
@ -145,55 +145,55 @@ auto mListView::remove(sListViewItem item) -> type& {
return *this; return *this;
} }
auto mListView::reset() -> type& { auto mTableView::reset() -> type& {
for(auto n : rrange(state.items)) remove(state.items[n]); for(auto n : rrange(state.items)) remove(state.items[n]);
if(auto& header = state.header) remove(header); if(auto& header = state.header) remove(header);
return *this; return *this;
} }
auto mListView::resizeColumns() -> type& { auto mTableView::resizeColumns() -> type& {
signal(resizeColumns); signal(resizeColumns);
return *this; return *this;
} }
auto mListView::selected() const -> ListViewItem { auto mTableView::selected() const -> TableViewItem {
for(auto& item : state.items) { for(auto& item : state.items) {
if(item->selected()) return item; if(item->selected()) return item;
} }
return {}; return {};
} }
auto mListView::setAlignment(Alignment alignment) -> type& { auto mTableView::setAlignment(Alignment alignment) -> type& {
state.alignment = alignment; state.alignment = alignment;
signal(setAlignment, alignment); signal(setAlignment, alignment);
return *this; return *this;
} }
auto mListView::setBackgroundColor(Color color) -> type& { auto mTableView::setBackgroundColor(Color color) -> type& {
state.backgroundColor = color; state.backgroundColor = color;
signal(setBackgroundColor, color); signal(setBackgroundColor, color);
return *this; return *this;
} }
auto mListView::setBatchable(bool batchable) -> type& { auto mTableView::setBatchable(bool batchable) -> type& {
state.batchable = batchable; state.batchable = batchable;
signal(setBatchable, batchable); signal(setBatchable, batchable);
return *this; return *this;
} }
auto mListView::setBordered(bool bordered) -> type& { auto mTableView::setBordered(bool bordered) -> type& {
state.bordered = bordered; state.bordered = bordered;
signal(setBordered, bordered); signal(setBordered, bordered);
return *this; return *this;
} }
auto mListView::setForegroundColor(Color color) -> type& { auto mTableView::setForegroundColor(Color color) -> type& {
state.foregroundColor = color; state.foregroundColor = color;
signal(setForegroundColor, color); signal(setForegroundColor, color);
return *this; return *this;
} }
auto mListView::setParent(mObject* parent, signed offset) -> type& { auto mTableView::setParent(mObject* parent, signed offset) -> type& {
for(auto n : rrange(state.items)) state.items[n]->destruct(); for(auto n : rrange(state.items)) state.items[n]->destruct();
if(auto& header = state.header) header->destruct(); if(auto& header = state.header) header->destruct();
mObject::setParent(parent, offset); mObject::setParent(parent, offset);

View File

@ -18,7 +18,7 @@ private:
Button pathRefresh{&pathLayout, Size{0, 0}, 0}; Button pathRefresh{&pathLayout, Size{0, 0}, 0};
Button pathHome{&pathLayout, Size{0, 0}, 0}; Button pathHome{&pathLayout, Size{0, 0}, 0};
Button pathUp{&pathLayout, Size{0, 0}, 0}; Button pathUp{&pathLayout, Size{0, 0}, 0};
ListView view{&layout, Size{~0, ~0}, 5}; TableView view{&layout, Size{~0, ~0}, 5};
HorizontalLayout controlLayout{&layout, Size{~0, 0}}; HorizontalLayout controlLayout{&layout, Size{~0, 0}};
ComboButton filterList{&controlLayout, Size{120, 0}, 5}; ComboButton filterList{&controlLayout, Size{120, 0}, 5};
LineEdit fileName{&controlLayout, Size{~0, 0}, 5}; LineEdit fileName{&controlLayout, Size{~0, 0}, 5};
@ -30,7 +30,7 @@ private:
}; };
//accept button clicked, or enter pressed on file name line edit //accept button clicked, or enter pressed on file name line edit
//also called by list view activate after special case handling //also called by table view activate after special case handling
auto BrowserDialogWindow::accept() -> void { auto BrowserDialogWindow::accept() -> void {
auto batched = view.batched(); auto batched = view.batched();
@ -71,7 +71,7 @@ auto BrowserDialogWindow::accept() -> void {
if(state.response) window.setModal(false); if(state.response) window.setModal(false);
} }
//list view item double-clicked, or enter pressed on selected list view item //table view item double-clicked, or enter pressed on selected table view item
auto BrowserDialogWindow::activate() -> void { auto BrowserDialogWindow::activate() -> void {
auto selectedItem = view.selected(); auto selectedItem = view.selected();
@ -89,7 +89,7 @@ auto BrowserDialogWindow::activate() -> void {
accept(); accept();
} }
//list view item changed //table view item changed
auto BrowserDialogWindow::change() -> void { auto BrowserDialogWindow::change() -> void {
fileName.setText(""); fileName.setText("");
if(state.action == "saveFile") { if(state.action == "saveFile") {
@ -162,8 +162,8 @@ auto BrowserDialogWindow::setPath(string path) -> void {
pathName.setText(state.path = path); pathName.setText(state.path = path);
view.reset(); view.reset();
view.append(ListViewHeader().setVisible(false) view.append(TableViewHeader().setVisible(false)
.append(ListViewColumn().setExpandable()) .append(TableViewColumn().setExpandable())
); );
auto contents = directory::icontents(path); auto contents = directory::icontents(path);
@ -174,8 +174,8 @@ auto BrowserDialogWindow::setPath(string path) -> void {
content.rtrim("/"); content.rtrim("/");
if(folderMode && isMatch(content)) continue; if(folderMode && isMatch(content)) continue;
view.append(ListViewItem() view.append(TableViewItem()
.append(ListViewCell().setText(content).setIcon(Icon::Emblem::Folder)) .append(TableViewCell().setText(content).setIcon(Icon::Emblem::Folder))
); );
} }
@ -184,8 +184,8 @@ auto BrowserDialogWindow::setPath(string path) -> void {
content.rtrim("/"); content.rtrim("/");
if(!isMatch(content)) continue; if(!isMatch(content)) continue;
view.append(ListViewItem() view.append(TableViewItem()
.append(ListViewCell().setText(content).setIcon(folderMode ? Icon::Action::Open : Icon::Emblem::File)) .append(TableViewCell().setText(content).setIcon(folderMode ? Icon::Action::Open : Icon::Emblem::File))
); );
} }

View File

@ -6,6 +6,8 @@ namespace hiro {
#include "fixed-layout.cpp" #include "fixed-layout.cpp"
#include "horizontal-layout.cpp" #include "horizontal-layout.cpp"
#include "vertical-layout.cpp" #include "vertical-layout.cpp"
#include "list-view-item.cpp"
#include "list-view.cpp"
#include "browser-dialog.cpp" #include "browser-dialog.cpp"
#include "message-dialog.cpp" #include "message-dialog.cpp"
} }

View File

@ -3,6 +3,8 @@ namespace hiro {
#include "fixed-layout.hpp" #include "fixed-layout.hpp"
#include "horizontal-layout.hpp" #include "horizontal-layout.hpp"
#include "vertical-layout.hpp" #include "vertical-layout.hpp"
#include "list-view-item.hpp"
#include "list-view.hpp"
#include "shared.hpp" #include "shared.hpp"
#include "browser-dialog.hpp" #include "browser-dialog.hpp"
#include "message-dialog.hpp" #include "message-dialog.hpp"

View File

@ -0,0 +1,49 @@
#if defined(Hiro_ListView)
mListViewItem::mListViewItem() {
append(TableViewCell());
}
auto mListViewItem::checkable() const -> bool {
return cell(0).checkable();
}
auto mListViewItem::checked() const -> bool {
return cell(0).checked();
}
auto mListViewItem::icon() const -> image {
return cell(0).icon();
}
auto mListViewItem::reset() -> type& {
mTableViewItem::reset();
append(TableViewCell());
return *this;
}
auto mListViewItem::setCheckable(bool checkable) -> type& {
cell(0).setCheckable(checkable);
return *this;
}
auto mListViewItem::setChecked(bool checked) -> type& {
cell(0).setChecked(checked);
return *this;
}
auto mListViewItem::setIcon(const image& icon) -> type& {
cell(0).setIcon(icon);
return *this;
}
auto mListViewItem::setText(const string& text) -> type& {
cell(0).setText(text);
return *this;
}
auto mListViewItem::text() const -> string {
return cell(0).text();
}
#endif

View File

@ -0,0 +1,24 @@
#if defined(Hiro_ListView)
struct ListViewItem;
struct mListViewItem;
using sListViewItem = shared_pointer<mListViewItem>;
struct mListViewItem : mTableViewItem {
using type = mListViewItem;
using mTableViewItem::append;
using mTableViewItem::remove;
mListViewItem();
auto checkable() const -> bool;
auto checked() const -> bool;
auto icon() const -> image;
auto reset() -> type&;
auto setCheckable(bool checkable) -> type&;
auto setChecked(bool checked) -> type&;
auto setIcon(const image& icon = {}) -> type&;
auto setText(const string& text) -> type&;
auto text() const -> string;
};
#endif

View File

@ -0,0 +1,51 @@
#if defined(Hiro_ListView)
mListView::mListView() {
mTableView::onToggle([&](TableViewCell cell) {
if(auto item = cell->parentTableViewItem()) {
if(auto shared = item->instance.acquire()) {
doToggle(ListViewItem{shared});
}
}
});
append(TableViewHeader().setVisible(false).append(TableViewColumn().setExpandable()));
}
auto mListView::batched() const -> vector<ListViewItem> {
auto batched = mTableView::batched();
vector<ListViewItem> result;
for(auto item : batched) result.append(ListViewItem{item});
return result;
}
auto mListView::doToggle(ListViewItem item) const -> void {
if(state.onToggle) state.onToggle(item);
}
auto mListView::item(uint position) const -> ListViewItem {
return ListViewItem{mTableView::item(position)};
}
auto mListView::items() const -> vector<ListViewItem> {
auto items = mTableView::items();
vector<ListViewItem> result;
for(auto item : items) result.append(ListViewItem{item});
return result;
}
auto mListView::onToggle(const function<void (ListViewItem)>& callback) -> type& {
state.onToggle = callback;
return *this;
}
auto mListView::reset() -> type& {
mTableView::reset();
append(TableViewHeader().setVisible(false).append(TableViewColumn().setExpandable()));
return *this;
}
auto mListView::selected() const -> ListViewItem {
return ListViewItem{mTableView::selected()};
}
#endif

View File

@ -0,0 +1,27 @@
#if defined(Hiro_ListView)
struct ListView;
struct mListView;
using sListView = shared_pointer<mListView>;
struct mListView : mTableView {
using type = mListView;
using mTableView::append;
using mTableView::remove;
mListView();
auto batched() const -> vector<ListViewItem>;
auto doToggle(ListViewItem) const -> void;
auto item(uint position) const -> ListViewItem;
auto items() const -> vector<ListViewItem>;
auto onToggle(const function<void (ListViewItem)>& callback) -> type&;
auto reset() -> type& override;
auto selected() const -> ListViewItem;
//private:
struct State {
function<void (ListViewItem)> onToggle;
} state;
};
#endif

View File

@ -33,3 +33,56 @@ struct VerticalLayout : sVerticalLayout {
auto setSpacing(signed spacing = 5) { return self().setSpacing(spacing), *this; } auto setSpacing(signed spacing = 5) { return self().setSpacing(spacing), *this; }
}; };
#endif #endif
#if defined(Hiro_ListView)
struct ListViewItem : sListViewItem {
DeclareSharedObject(ListViewItem)
auto alignment() const { return self().alignment(); }
auto backgroundColor() const { return self().backgroundColor(); }
auto checkable() const { return self().checkable(); }
auto checked() const { return self().checked(); }
auto foregroundColor() const { return self().foregroundColor(); }
auto icon() const { return self().icon(); }
auto reset() { return self().reset(), *this; }
auto setAlignment(Alignment alignment = {}) { return self().setAlignment(alignment), *this; }
auto setBackgroundColor(Color color = {}) { return self().setBackgroundColor(color), *this; }
auto setCheckable(bool checkable = true) { return self().setCheckable(checkable), *this; }
auto setChecked(bool checked = true) { return self().setChecked(checked), *this; }
auto setForegroundColor(Color color = {}) { return self().setForegroundColor(color), *this; }
auto setIcon(const image& icon = {}) { return self().setIcon(icon), *this; }
auto setText(const string& text = "") { return self().setText(text), *this; }
auto text() const { return self().text(); }
};
#endif
#if defined(Hiro_ListView)
struct ListView : sListView {
DeclareSharedWidget(ListView)
auto alignment() const { return self().alignment(); }
auto append(sListViewItem item) { return self().append(item), *this; }
auto backgroundColor() const { return self().backgroundColor(); }
auto batchable() const { return self().batchable(); }
auto batched() const { return self().batched(); }
auto doActivate() const { return self().doActivate(); }
auto doChange() const { return self().doChange(); }
auto doContext() const { return self().doContext(); }
auto doToggle(ListViewItem item) const { return self().doToggle(item); }
auto foregroundColor() const { return self().foregroundColor(); }
auto item(uint position) const { return self().item(position); }
auto itemCount() const { return self().itemCount(); }
auto items() const { return self().items(); }
auto onActivate(const function<void ()>& callback = {}) { return self().onActivate(callback), *this; }
auto onChange(const function<void ()>& callback = {}) { return self().onChange(callback), *this; }
auto onContext(const function<void ()>& callback = {}) { return self().onContext(callback), *this; }
auto onToggle(const function<void (ListViewItem)>& callback = {}) { return self().onToggle(callback), *this; }
auto remove(sListViewItem item) { return self().remove(item), *this; }
auto reset() { return self().reset(), *this; }
auto selected() { return self().selected(); }
auto setAlignment(Alignment alignment = {}) { return self().setAlignment(alignment), *this; }
auto setBackgroundColor(Color color = {}) { return self().setBackgroundColor(color), *this; }
auto setBatchable(bool batchable = true) { return self().setBatchable(batchable), *this; }
auto setForegroundColor(Color color = {}) { return self().setForegroundColor(color), *this; }
};
#endif

View File

@ -44,17 +44,17 @@
#include "widget/icon-view-item.cpp" #include "widget/icon-view-item.cpp"
#include "widget/label.cpp" #include "widget/label.cpp"
#include "widget/line-edit.cpp" #include "widget/line-edit.cpp"
#include "widget/list-view.cpp"
#include "widget/list-view-header.cpp"
#include "widget/list-view-column.cpp"
#include "widget/list-view-item.cpp"
#include "widget/list-view-cell.cpp"
#include "widget/progress-bar.cpp" #include "widget/progress-bar.cpp"
#include "widget/radio-button.cpp" #include "widget/radio-button.cpp"
#include "widget/radio-label.cpp" #include "widget/radio-label.cpp"
#include "widget/source-edit.cpp" #include "widget/source-edit.cpp"
#include "widget/tab-frame.cpp" #include "widget/tab-frame.cpp"
#include "widget/tab-frame-item.cpp" #include "widget/tab-frame-item.cpp"
#include "widget/table-view.cpp"
#include "widget/table-view-header.cpp"
#include "widget/table-view-column.cpp"
#include "widget/table-view-item.cpp"
#include "widget/table-view-cell.cpp"
#include "widget/text-edit.cpp" #include "widget/text-edit.cpp"
#include "widget/tree-view.cpp" #include "widget/tree-view.cpp"
#include "widget/tree-view-item.cpp" #include "widget/tree-view-item.cpp"

View File

@ -55,17 +55,17 @@ namespace hiro {
#include "widget/icon-view-item.hpp" #include "widget/icon-view-item.hpp"
#include "widget/label.hpp" #include "widget/label.hpp"
#include "widget/line-edit.hpp" #include "widget/line-edit.hpp"
#include "widget/list-view.hpp"
#include "widget/list-view-header.hpp"
#include "widget/list-view-column.hpp"
#include "widget/list-view-item.hpp"
#include "widget/list-view-cell.hpp"
#include "widget/progress-bar.hpp" #include "widget/progress-bar.hpp"
#include "widget/radio-button.hpp" #include "widget/radio-button.hpp"
#include "widget/radio-label.hpp" #include "widget/radio-label.hpp"
#include "widget/source-edit.hpp" #include "widget/source-edit.hpp"
#include "widget/tab-frame.hpp" #include "widget/tab-frame.hpp"
#include "widget/tab-frame-item.hpp" #include "widget/tab-frame-item.hpp"
#include "widget/table-view.hpp"
#include "widget/table-view-header.hpp"
#include "widget/table-view-column.hpp"
#include "widget/table-view-item.hpp"
#include "widget/table-view-cell.hpp"
#include "widget/text-edit.hpp" #include "widget/text-edit.hpp"
#include "widget/tree-view.hpp" #include "widget/tree-view.hpp"
#include "widget/tree-view-item.hpp" #include "widget/tree-view-item.hpp"

View File

@ -1,41 +0,0 @@
#if defined(Hiro_ListView)
namespace hiro {
auto pListViewHeader::construct() -> void {
_setState();
}
auto pListViewHeader::destruct() -> void {
}
auto pListViewHeader::append(sListViewColumn column) -> void {
_setState();
}
auto pListViewHeader::remove(sListViewColumn column) -> void {
}
auto pListViewHeader::setVisible(bool visible) -> void {
_setState();
}
auto pListViewHeader::_parent() -> maybe<pListView&> {
if(auto parent = self().parentListView()) {
if(auto self = parent->self()) return *self;
}
return nothing;
}
auto pListViewHeader::_setState() -> void {
if(auto parent = _parent()) {
gtk_tree_view_set_headers_visible(parent->gtkTreeView, self().visible());
for(auto& column : state().columns) {
if(auto self = column->self()) self->_setState();
}
}
}
}
#endif

View File

@ -1,18 +0,0 @@
#if defined(Hiro_ListView)
namespace hiro {
struct pListViewHeader : pObject {
Declare(ListViewHeader, Object)
auto append(sListViewColumn column) -> void;
auto remove(sListViewColumn column) -> void;
auto setVisible(bool visible) -> void override;
auto _parent() -> maybe<pListView&>;
auto _setState() -> void;
};
}
#endif

View File

@ -1,51 +1,51 @@
#if defined(Hiro_ListView) #if defined(Hiro_TableView)
namespace hiro { namespace hiro {
auto pListViewCell::construct() -> void { auto pTableViewCell::construct() -> void {
_setState(); _setState();
} }
auto pListViewCell::destruct() -> void { auto pTableViewCell::destruct() -> void {
} }
auto pListViewCell::setAlignment(Alignment alignment) -> void { auto pTableViewCell::setAlignment(Alignment alignment) -> void {
} }
auto pListViewCell::setBackgroundColor(Color color) -> void { auto pTableViewCell::setBackgroundColor(Color color) -> void {
} }
auto pListViewCell::setCheckable(bool checkable) -> void { auto pTableViewCell::setCheckable(bool checkable) -> void {
} }
auto pListViewCell::setChecked(bool checked) -> void { auto pTableViewCell::setChecked(bool checked) -> void {
_setState(); _setState();
} }
auto pListViewCell::setForegroundColor(Color color) -> void { auto pTableViewCell::setForegroundColor(Color color) -> void {
} }
auto pListViewCell::setIcon(const image& icon) -> void { auto pTableViewCell::setIcon(const image& icon) -> void {
_setState(); _setState();
} }
auto pListViewCell::setText(const string& text) -> void { auto pTableViewCell::setText(const string& text) -> void {
_setState(); _setState();
} }
auto pListViewCell::_grandparent() -> maybe<pListView&> { auto pTableViewCell::_grandparent() -> maybe<pTableView&> {
if(auto parent = _parent()) return parent->_parent(); if(auto parent = _parent()) return parent->_parent();
return nothing; return nothing;
} }
auto pListViewCell::_parent() -> maybe<pListViewItem&> { auto pTableViewCell::_parent() -> maybe<pTableViewItem&> {
if(auto parent = self().parentListViewItem()) { if(auto parent = self().parentTableViewItem()) {
if(auto self = parent->self()) return *self; if(auto self = parent->self()) return *self;
} }
return nothing; return nothing;
} }
auto pListViewCell::_setState() -> void { auto pTableViewCell::_setState() -> void {
if(auto parent = _parent()) { if(auto parent = _parent()) {
if(auto grandparent = _grandparent()) { if(auto grandparent = _grandparent()) {
grandparent->lock(); grandparent->lock();

View File

@ -1,9 +1,9 @@
#if defined(Hiro_ListView) #if defined(Hiro_TableView)
namespace hiro { namespace hiro {
struct pListViewCell : pObject { struct pTableViewCell : pObject {
Declare(ListViewCell, Object) Declare(TableViewCell, Object)
auto setAlignment(Alignment alignment) -> void; auto setAlignment(Alignment alignment) -> void;
auto setBackgroundColor(Color color) -> void; auto setBackgroundColor(Color color) -> void;
@ -13,8 +13,8 @@ struct pListViewCell : pObject {
auto setIcon(const image& icon) -> void; auto setIcon(const image& icon) -> void;
auto setText(const string& text) -> void; auto setText(const string& text) -> void;
auto _grandparent() -> maybe<pListView&>; auto _grandparent() -> maybe<pTableView&>;
auto _parent() -> maybe<pListViewItem&>; auto _parent() -> maybe<pTableViewItem&>;
auto _setState() -> void; auto _setState() -> void;
}; };

View File

@ -1,8 +1,8 @@
#if defined(Hiro_ListView) #if defined(Hiro_TableView)
namespace hiro { namespace hiro {
auto pListViewColumn::construct() -> void { auto pTableViewColumn::construct() -> void {
if(auto grandparent = _grandparent()) { if(auto grandparent = _grandparent()) {
auto handle = grandparent.data(); auto handle = grandparent.data();
unsigned offset = self().offset(); unsigned offset = self().offset();
@ -23,21 +23,21 @@ auto pListViewColumn::construct() -> void {
gtkCellToggle = gtk_cell_renderer_toggle_new(); gtkCellToggle = gtk_cell_renderer_toggle_new();
gtk_tree_view_column_pack_start(gtkColumn, gtkCellToggle, false); gtk_tree_view_column_pack_start(gtkColumn, gtkCellToggle, false);
gtk_tree_view_column_set_attributes(gtkColumn, gtkCellToggle, "active", 3 * offset + 0, nullptr); gtk_tree_view_column_set_attributes(gtkColumn, gtkCellToggle, "active", 3 * offset + 0, nullptr);
gtk_tree_view_column_set_cell_data_func(gtkColumn, GTK_CELL_RENDERER(gtkCellToggle), (GtkTreeCellDataFunc)ListView_dataFunc, (gpointer)handle, nullptr); gtk_tree_view_column_set_cell_data_func(gtkColumn, GTK_CELL_RENDERER(gtkCellToggle), (GtkTreeCellDataFunc)TableView_dataFunc, (gpointer)handle, nullptr);
gtkCellIcon = gtk_cell_renderer_pixbuf_new(); gtkCellIcon = gtk_cell_renderer_pixbuf_new();
gtk_tree_view_column_pack_start(gtkColumn, gtkCellIcon, false); gtk_tree_view_column_pack_start(gtkColumn, gtkCellIcon, false);
gtk_tree_view_column_set_attributes(gtkColumn, gtkCellIcon, "pixbuf", 3 * offset + 1, nullptr); gtk_tree_view_column_set_attributes(gtkColumn, gtkCellIcon, "pixbuf", 3 * offset + 1, nullptr);
gtk_tree_view_column_set_cell_data_func(gtkColumn, GTK_CELL_RENDERER(gtkCellIcon), (GtkTreeCellDataFunc)ListView_dataFunc, (gpointer)handle, nullptr); gtk_tree_view_column_set_cell_data_func(gtkColumn, GTK_CELL_RENDERER(gtkCellIcon), (GtkTreeCellDataFunc)TableView_dataFunc, (gpointer)handle, nullptr);
gtkCellText = gtk_cell_renderer_text_new(); gtkCellText = gtk_cell_renderer_text_new();
gtk_tree_view_column_pack_start(gtkColumn, gtkCellText, true); //text must expand to cell width for horizontal alignment to work gtk_tree_view_column_pack_start(gtkColumn, gtkCellText, true); //text must expand to cell width for horizontal alignment to work
gtk_tree_view_column_set_attributes(gtkColumn, gtkCellText, "text", 3 * offset + 2, nullptr); gtk_tree_view_column_set_attributes(gtkColumn, gtkCellText, "text", 3 * offset + 2, nullptr);
gtk_tree_view_column_set_cell_data_func(gtkColumn, GTK_CELL_RENDERER(gtkCellText), (GtkTreeCellDataFunc)ListView_dataFunc, (gpointer)handle, nullptr); gtk_tree_view_column_set_cell_data_func(gtkColumn, GTK_CELL_RENDERER(gtkCellText), (GtkTreeCellDataFunc)TableView_dataFunc, (gpointer)handle, nullptr);
g_signal_connect(G_OBJECT(gtkColumn), "clicked", G_CALLBACK(ListView_headerActivate), (gpointer)handle); g_signal_connect(G_OBJECT(gtkColumn), "clicked", G_CALLBACK(TableView_headerActivate), (gpointer)handle);
g_signal_connect(G_OBJECT(gtkCellText), "edited", G_CALLBACK(ListView_edit), (gpointer)handle); g_signal_connect(G_OBJECT(gtkCellText), "edited", G_CALLBACK(TableView_edit), (gpointer)handle);
g_signal_connect(G_OBJECT(gtkCellToggle), "toggled", G_CALLBACK(ListView_toggle), (gpointer)handle); g_signal_connect(G_OBJECT(gtkCellToggle), "toggled", G_CALLBACK(TableView_toggle), (gpointer)handle);
gtk_tree_view_append_column(grandparent->gtkTreeView, gtkColumn); gtk_tree_view_append_column(grandparent->gtkTreeView, gtkColumn);
gtk_widget_show_all(gtkHeader); gtk_widget_show_all(gtkHeader);
@ -47,7 +47,7 @@ auto pListViewColumn::construct() -> void {
} }
} }
auto pListViewColumn::destruct() -> void { auto pTableViewColumn::destruct() -> void {
if(auto grandparent = _grandparent()) { if(auto grandparent = _grandparent()) {
gtk_tree_view_remove_column(grandparent->gtkTreeView, gtkColumn); gtk_tree_view_remove_column(grandparent->gtkTreeView, gtkColumn);
gtkColumn = nullptr; gtkColumn = nullptr;
@ -55,33 +55,33 @@ auto pListViewColumn::destruct() -> void {
} }
} }
auto pListViewColumn::setActive() -> void { auto pTableViewColumn::setActive() -> void {
_setState(); _setState();
} }
auto pListViewColumn::setAlignment(Alignment alignment) -> void { auto pTableViewColumn::setAlignment(Alignment alignment) -> void {
} }
auto pListViewColumn::setBackgroundColor(Color color) -> void { auto pTableViewColumn::setBackgroundColor(Color color) -> void {
} }
auto pListViewColumn::setEditable(bool editable) -> void { auto pTableViewColumn::setEditable(bool editable) -> void {
g_object_set(G_OBJECT(gtkCellText), "editable", editable ? true : false, nullptr); g_object_set(G_OBJECT(gtkCellText), "editable", editable ? true : false, nullptr);
} }
auto pListViewColumn::setExpandable(bool expandable) -> void { auto pTableViewColumn::setExpandable(bool expandable) -> void {
if(auto grandparent = _grandparent()) { if(auto grandparent = _grandparent()) {
grandparent->resizeColumns(); grandparent->resizeColumns();
} }
} }
auto pListViewColumn::setFont(const Font& font) -> void { auto pTableViewColumn::setFont(const Font& font) -> void {
} }
auto pListViewColumn::setForegroundColor(Color color) -> void { auto pTableViewColumn::setForegroundColor(Color color) -> void {
} }
auto pListViewColumn::setIcon(const image& icon) -> void { auto pTableViewColumn::setIcon(const image& icon) -> void {
if(icon) { if(icon) {
gtk_image_set_from_pixbuf(GTK_IMAGE(gtkHeaderIcon), CreatePixbuf(icon)); gtk_image_set_from_pixbuf(GTK_IMAGE(gtkHeaderIcon), CreatePixbuf(icon));
} else { } else {
@ -89,41 +89,41 @@ auto pListViewColumn::setIcon(const image& icon) -> void {
} }
} }
auto pListViewColumn::setResizable(bool resizable) -> void { auto pTableViewColumn::setResizable(bool resizable) -> void {
_setState(); _setState();
} }
auto pListViewColumn::setSortable(bool sortable) -> void { auto pTableViewColumn::setSortable(bool sortable) -> void {
_setState(); _setState();
} }
auto pListViewColumn::setText(const string& text) -> void { auto pTableViewColumn::setText(const string& text) -> void {
_setState(); _setState();
} }
auto pListViewColumn::setVisible(bool visible) -> void { auto pTableViewColumn::setVisible(bool visible) -> void {
_setState(); _setState();
} }
auto pListViewColumn::setWidth(signed width) -> void { auto pTableViewColumn::setWidth(signed width) -> void {
if(auto grandparent = _grandparent()) { if(auto grandparent = _grandparent()) {
grandparent->resizeColumns(); grandparent->resizeColumns();
} }
} }
auto pListViewColumn::_grandparent() -> maybe<pListView&> { auto pTableViewColumn::_grandparent() -> maybe<pTableView&> {
if(auto parent = _parent()) return parent->_parent(); if(auto parent = _parent()) return parent->_parent();
return nothing; return nothing;
} }
auto pListViewColumn::_parent() -> maybe<pListViewHeader&> { auto pTableViewColumn::_parent() -> maybe<pTableViewHeader&> {
if(auto parent = self().parentListViewHeader()) { if(auto parent = self().parentTableViewHeader()) {
if(auto self = parent->self()) return *self; if(auto self = parent->self()) return *self;
} }
return nothing; return nothing;
} }
auto pListViewColumn::_setState() -> void { auto pTableViewColumn::_setState() -> void {
if(auto grandparent = _grandparent()) { if(auto grandparent = _grandparent()) {
gtk_tree_view_set_search_column(grandparent->gtkTreeView, 3 * self().offset() + 2); gtk_tree_view_set_search_column(grandparent->gtkTreeView, 3 * self().offset() + 2);
gtk_tree_view_column_set_resizable(gtkColumn, state().resizable); gtk_tree_view_column_set_resizable(gtkColumn, state().resizable);

View File

@ -1,9 +1,9 @@
#if defined(Hiro_ListView) #if defined(Hiro_TableView)
namespace hiro { namespace hiro {
struct pListViewColumn : pObject { struct pTableViewColumn : pObject {
Declare(ListViewColumn, Object) Declare(TableViewColumn, Object)
auto setActive() -> void; auto setActive() -> void;
auto setAlignment(Alignment alignment) -> void; auto setAlignment(Alignment alignment) -> void;
@ -21,8 +21,8 @@ struct pListViewColumn : pObject {
auto setVisible(bool visible) -> void override; auto setVisible(bool visible) -> void override;
auto setWidth(signed width) -> void; auto setWidth(signed width) -> void;
auto _grandparent() -> maybe<pListView&>; auto _grandparent() -> maybe<pTableView&>;
auto _parent() -> maybe<pListViewHeader&>; auto _parent() -> maybe<pTableViewHeader&>;
auto _setState() -> void; auto _setState() -> void;
GtkTreeViewColumn* gtkColumn = nullptr; GtkTreeViewColumn* gtkColumn = nullptr;

View File

@ -0,0 +1,41 @@
#if defined(Hiro_TableView)
namespace hiro {
auto pTableViewHeader::construct() -> void {
_setState();
}
auto pTableViewHeader::destruct() -> void {
}
auto pTableViewHeader::append(sTableViewColumn column) -> void {
_setState();
}
auto pTableViewHeader::remove(sTableViewColumn column) -> void {
}
auto pTableViewHeader::setVisible(bool visible) -> void {
_setState();
}
auto pTableViewHeader::_parent() -> maybe<pTableView&> {
if(auto parent = self().parentTableView()) {
if(auto self = parent->self()) return *self;
}
return nothing;
}
auto pTableViewHeader::_setState() -> void {
if(auto parent = _parent()) {
gtk_tree_view_set_headers_visible(parent->gtkTreeView, self().visible());
for(auto& column : state().columns) {
if(auto self = column->self()) self->_setState();
}
}
}
}
#endif

View File

@ -0,0 +1,18 @@
#if defined(Hiro_TableView)
namespace hiro {
struct pTableViewHeader : pObject {
Declare(TableViewHeader, Object)
auto append(sTableViewColumn column) -> void;
auto remove(sTableViewColumn column) -> void;
auto setVisible(bool visible) -> void override;
auto _parent() -> maybe<pTableView&>;
auto _setState() -> void;
};
}
#endif

View File

@ -1,8 +1,8 @@
#if defined(Hiro_ListView) #if defined(Hiro_TableView)
namespace hiro { namespace hiro {
auto pListViewItem::construct() -> void { auto pTableViewItem::construct() -> void {
if(auto parent = _parent()) { if(auto parent = _parent()) {
parent->lock(); parent->lock();
gtk_list_store_append(parent->gtkListStore, &gtkIter); gtk_list_store_append(parent->gtkListStore, &gtkIter);
@ -11,7 +11,7 @@ auto pListViewItem::construct() -> void {
} }
} }
auto pListViewItem::destruct() -> void { auto pTableViewItem::destruct() -> void {
if(auto parent = _parent()) { if(auto parent = _parent()) {
parent->lock(); parent->lock();
gtk_list_store_remove(parent->gtkListStore, &gtkIter); gtk_list_store_remove(parent->gtkListStore, &gtkIter);
@ -20,19 +20,19 @@ auto pListViewItem::destruct() -> void {
} }
} }
auto pListViewItem::append(sListViewCell cell) -> void { auto pTableViewItem::append(sTableViewCell cell) -> void {
} }
auto pListViewItem::remove(sListViewCell cell) -> void { auto pTableViewItem::remove(sTableViewCell cell) -> void {
} }
auto pListViewItem::setAlignment(Alignment alignment) -> void { auto pTableViewItem::setAlignment(Alignment alignment) -> void {
} }
auto pListViewItem::setBackgroundColor(Color color) -> void { auto pTableViewItem::setBackgroundColor(Color color) -> void {
} }
auto pListViewItem::setFocused() -> void { auto pTableViewItem::setFocused() -> void {
if(auto parent = _parent()) { if(auto parent = _parent()) {
GtkTreePath* path = gtk_tree_path_new_from_string(string{self().offset()}); GtkTreePath* path = gtk_tree_path_new_from_string(string{self().offset()});
gtk_tree_view_set_cursor(parent->gtkTreeView, path, nullptr, false); gtk_tree_view_set_cursor(parent->gtkTreeView, path, nullptr, false);
@ -41,21 +41,21 @@ auto pListViewItem::setFocused() -> void {
} }
} }
auto pListViewItem::setForegroundColor(Color color) -> void { auto pTableViewItem::setForegroundColor(Color color) -> void {
} }
auto pListViewItem::setSelected(bool selected) -> void { auto pTableViewItem::setSelected(bool selected) -> void {
_setState(); _setState();
} }
auto pListViewItem::_parent() -> maybe<pListView&> { auto pTableViewItem::_parent() -> maybe<pTableView&> {
if(auto parent = self().parentListView()) { if(auto parent = self().parentTableView()) {
if(auto self = parent->self()) return *self; if(auto self = parent->self()) return *self;
} }
return nothing; return nothing;
} }
auto pListViewItem::_setState() -> void { auto pTableViewItem::_setState() -> void {
if(auto parent = _parent()) { if(auto parent = _parent()) {
parent->lock(); parent->lock();
if(state().selected) { if(state().selected) {

View File

@ -1,19 +1,19 @@
#if defined(Hiro_ListView) #if defined(Hiro_TableView)
namespace hiro { namespace hiro {
struct pListViewItem : pObject { struct pTableViewItem : pObject {
Declare(ListViewItem, Object) Declare(TableViewItem, Object)
auto append(sListViewCell cell) -> void; auto append(sTableViewCell cell) -> void;
auto remove(sListViewCell cell) -> void; auto remove(sTableViewCell cell) -> void;
auto setAlignment(Alignment alignment) -> void; auto setAlignment(Alignment alignment) -> void;
auto setBackgroundColor(Color color) -> void; auto setBackgroundColor(Color color) -> void;
auto setFocused() -> void; auto setFocused() -> void;
auto setForegroundColor(Color color) -> void; auto setForegroundColor(Color color) -> void;
auto setSelected(bool selected) -> void; auto setSelected(bool selected) -> void;
auto _parent() -> maybe<pListView&>; auto _parent() -> maybe<pTableView&>;
auto _setState() -> void; auto _setState() -> void;
GtkTreeIter gtkIter; GtkTreeIter gtkIter;

View File

@ -1,21 +1,21 @@
#if defined(Hiro_ListView) #if defined(Hiro_TableView)
namespace hiro { namespace hiro {
static auto ListView_activate(GtkTreeView*, GtkTreePath*, GtkTreeViewColumn*, pListView* p) -> void { return p->_doActivate(); } static auto TableView_activate(GtkTreeView*, GtkTreePath*, GtkTreeViewColumn*, pTableView* p) -> void { return p->_doActivate(); }
static auto ListView_buttonEvent(GtkTreeView* treeView, GdkEventButton* event, pListView* p) -> signed { return p->_doEvent(event); } static auto TableView_buttonEvent(GtkTreeView* treeView, GdkEventButton* event, pTableView* p) -> signed { return p->_doEvent(event); }
static auto ListView_change(GtkTreeSelection*, pListView* p) -> void { return p->_doChange(); } static auto TableView_change(GtkTreeSelection*, pTableView* p) -> void { return p->_doChange(); }
static auto ListView_edit(GtkCellRendererText* renderer, const char* path, const char* text, pListView* p) -> void { return p->_doEdit(renderer, path, text); } static auto TableView_edit(GtkCellRendererText* renderer, const char* path, const char* text, pTableView* p) -> void { return p->_doEdit(renderer, path, text); }
static auto ListView_headerActivate(GtkTreeViewColumn* column, pListView* p) -> void { return p->_doHeaderActivate(column); } static auto TableView_headerActivate(GtkTreeViewColumn* column, pTableView* p) -> void { return p->_doHeaderActivate(column); }
static auto ListView_mouseMoveEvent(GtkWidget*, GdkEvent*, pListView* p) -> signed { return p->_doMouseMove(); } static auto TableView_mouseMoveEvent(GtkWidget*, GdkEvent*, pTableView* p) -> signed { return p->_doMouseMove(); }
static auto ListView_popup(GtkTreeView*, pListView* p) -> void { return p->_doContext(); } static auto TableView_popup(GtkTreeView*, pTableView* p) -> void { return p->_doContext(); }
static auto ListView_dataFunc(GtkTreeViewColumn* column, GtkCellRenderer* renderer, GtkTreeModel* model, GtkTreeIter* iter, pListView* p) -> void { return p->_doDataFunc(column, renderer, iter); } static auto TableView_dataFunc(GtkTreeViewColumn* column, GtkCellRenderer* renderer, GtkTreeModel* model, GtkTreeIter* iter, pTableView* p) -> void { return p->_doDataFunc(column, renderer, iter); }
static auto ListView_toggle(GtkCellRendererToggle* toggle, const char* path, pListView* p) -> void { return p->_doToggle(toggle, path); } static auto TableView_toggle(GtkCellRendererToggle* toggle, const char* path, pTableView* p) -> void { return p->_doToggle(toggle, path); }
//gtk_tree_view_set_rules_hint(gtkTreeView, true); //gtk_tree_view_set_rules_hint(gtkTreeView, true);
auto pListView::construct() -> void { auto pTableView::construct() -> void {
gtkWidget = gtk_scrolled_window_new(0, 0); gtkWidget = gtk_scrolled_window_new(0, 0);
gtkScrolledWindow = GTK_SCROLLED_WINDOW(gtkWidget); gtkScrolledWindow = GTK_SCROLLED_WINDOW(gtkWidget);
gtk_scrolled_window_set_policy(gtkScrolledWindow, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_policy(gtkScrolledWindow, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
@ -35,38 +35,38 @@ auto pListView::construct() -> void {
setFont(self().font(true)); setFont(self().font(true));
setForegroundColor(state().foregroundColor); setForegroundColor(state().foregroundColor);
g_signal_connect(G_OBJECT(gtkTreeView), "button-press-event", G_CALLBACK(ListView_buttonEvent), (gpointer)this); g_signal_connect(G_OBJECT(gtkTreeView), "button-press-event", G_CALLBACK(TableView_buttonEvent), (gpointer)this);
g_signal_connect(G_OBJECT(gtkTreeView), "button-release-event", G_CALLBACK(ListView_buttonEvent), (gpointer)this); g_signal_connect(G_OBJECT(gtkTreeView), "button-release-event", G_CALLBACK(TableView_buttonEvent), (gpointer)this);
g_signal_connect(G_OBJECT(gtkTreeView), "motion-notify-event", G_CALLBACK(ListView_mouseMoveEvent), (gpointer)this); g_signal_connect(G_OBJECT(gtkTreeView), "motion-notify-event", G_CALLBACK(TableView_mouseMoveEvent), (gpointer)this);
g_signal_connect(G_OBJECT(gtkTreeView), "popup-menu", G_CALLBACK(ListView_popup), (gpointer)this); g_signal_connect(G_OBJECT(gtkTreeView), "popup-menu", G_CALLBACK(TableView_popup), (gpointer)this);
g_signal_connect(G_OBJECT(gtkTreeView), "row-activated", G_CALLBACK(ListView_activate), (gpointer)this); g_signal_connect(G_OBJECT(gtkTreeView), "row-activated", G_CALLBACK(TableView_activate), (gpointer)this);
g_signal_connect(G_OBJECT(gtkTreeSelection), "changed", G_CALLBACK(ListView_change), (gpointer)this); g_signal_connect(G_OBJECT(gtkTreeSelection), "changed", G_CALLBACK(TableView_change), (gpointer)this);
pWidget::construct(); pWidget::construct();
} }
auto pListView::destruct() -> void { auto pTableView::destruct() -> void {
gtk_widget_destroy(gtkWidgetChild); gtk_widget_destroy(gtkWidgetChild);
gtk_widget_destroy(gtkWidget); gtk_widget_destroy(gtkWidget);
} }
auto pListView::append(sListViewHeader header) -> void { auto pTableView::append(sTableViewHeader header) -> void {
} }
auto pListView::append(sListViewItem item) -> void { auto pTableView::append(sTableViewItem item) -> void {
} }
auto pListView::focused() const -> bool { auto pTableView::focused() const -> bool {
return GTK_WIDGET_HAS_FOCUS(gtkTreeView); return GTK_WIDGET_HAS_FOCUS(gtkTreeView);
} }
auto pListView::remove(sListViewHeader header) -> void { auto pTableView::remove(sTableViewHeader header) -> void {
} }
auto pListView::remove(sListViewItem item) -> void { auto pTableView::remove(sTableViewItem item) -> void {
} }
auto pListView::resizeColumns() -> void { auto pTableView::resizeColumns() -> void {
lock(); lock();
if(auto& header = state().header) { if(auto& header = state().header) {
@ -102,23 +102,23 @@ auto pListView::resizeColumns() -> void {
unlock(); unlock();
} }
auto pListView::setAlignment(Alignment alignment) -> void { auto pTableView::setAlignment(Alignment alignment) -> void {
} }
auto pListView::setBackgroundColor(Color color) -> void { auto pTableView::setBackgroundColor(Color color) -> void {
GdkColor gdkColor = CreateColor(color); GdkColor gdkColor = CreateColor(color);
gtk_widget_modify_base(gtkWidgetChild, GTK_STATE_NORMAL, color ? &gdkColor : nullptr); gtk_widget_modify_base(gtkWidgetChild, GTK_STATE_NORMAL, color ? &gdkColor : nullptr);
} }
auto pListView::setBatchable(bool batchable) -> void { auto pTableView::setBatchable(bool batchable) -> void {
gtk_tree_selection_set_mode(gtkTreeSelection, batchable ? GTK_SELECTION_MULTIPLE : GTK_SELECTION_SINGLE); gtk_tree_selection_set_mode(gtkTreeSelection, batchable ? GTK_SELECTION_MULTIPLE : GTK_SELECTION_SINGLE);
} }
auto pListView::setBordered(bool bordered) -> void { auto pTableView::setBordered(bool bordered) -> void {
gtk_tree_view_set_grid_lines(gtkTreeView, bordered ? GTK_TREE_VIEW_GRID_LINES_BOTH : GTK_TREE_VIEW_GRID_LINES_NONE); gtk_tree_view_set_grid_lines(gtkTreeView, bordered ? GTK_TREE_VIEW_GRID_LINES_BOTH : GTK_TREE_VIEW_GRID_LINES_NONE);
} }
auto pListView::setFocused() -> void { auto pTableView::setFocused() -> void {
//gtk_widget_grab_focus() will select the first item if nothing is currently selected //gtk_widget_grab_focus() will select the first item if nothing is currently selected
//this behavior is undesirable. detect selection state first, and restore if required //this behavior is undesirable. detect selection state first, and restore if required
lock(); lock();
@ -128,18 +128,18 @@ auto pListView::setFocused() -> void {
unlock(); unlock();
} }
auto pListView::setFont(const Font& font) -> void { auto pTableView::setFont(const Font& font) -> void {
if(auto& header = state().header) { if(auto& header = state().header) {
if(auto self = header->self()) self->_setState(); if(auto self = header->self()) self->_setState();
} }
} }
auto pListView::setForegroundColor(Color color) -> void { auto pTableView::setForegroundColor(Color color) -> void {
GdkColor gdkColor = CreateColor(color); GdkColor gdkColor = CreateColor(color);
gtk_widget_modify_text(gtkWidgetChild, GTK_STATE_NORMAL, color ? &gdkColor : nullptr); gtk_widget_modify_text(gtkWidgetChild, GTK_STATE_NORMAL, color ? &gdkColor : nullptr);
} }
auto pListView::setGeometry(Geometry geometry) -> void { auto pTableView::setGeometry(Geometry geometry) -> void {
pWidget::setGeometry(geometry); pWidget::setGeometry(geometry);
if(auto& header = state().header) { if(auto& header = state().header) {
for(auto& column : header->state.columns) { for(auto& column : header->state.columns) {
@ -148,7 +148,7 @@ auto pListView::setGeometry(Geometry geometry) -> void {
} }
} }
auto pListView::_cellWidth(unsigned _row, unsigned _column) -> unsigned { auto pTableView::_cellWidth(unsigned _row, unsigned _column) -> unsigned {
unsigned width = 8; unsigned width = 8;
if(auto item = self().item(_row)) { if(auto item = self().item(_row)) {
if(auto cell = item->cell(_column)) { if(auto cell = item->cell(_column)) {
@ -166,7 +166,7 @@ auto pListView::_cellWidth(unsigned _row, unsigned _column) -> unsigned {
return width; return width;
} }
auto pListView::_columnWidth(unsigned _column) -> unsigned { auto pTableView::_columnWidth(unsigned _column) -> unsigned {
unsigned width = 8; unsigned width = 8;
if(auto& header = state().header) { if(auto& header = state().header) {
if(auto column = header->column(_column)) { if(auto column = header->column(_column)) {
@ -181,7 +181,7 @@ auto pListView::_columnWidth(unsigned _column) -> unsigned {
return width; return width;
} }
auto pListView::_createModel() -> void { auto pTableView::_createModel() -> void {
gtk_tree_view_set_model(gtkTreeView, nullptr); gtk_tree_view_set_model(gtkTreeView, nullptr);
gtkListStore = nullptr; gtkListStore = nullptr;
gtkTreeModel = nullptr; gtkTreeModel = nullptr;
@ -204,19 +204,19 @@ auto pListView::_createModel() -> void {
gtk_tree_view_set_model(gtkTreeView, gtkTreeModel); gtk_tree_view_set_model(gtkTreeView, gtkTreeModel);
} }
auto pListView::_doActivate() -> void { auto pTableView::_doActivate() -> void {
if(!locked()) self().doActivate(); if(!locked()) self().doActivate();
} }
auto pListView::_doChange() -> void { auto pTableView::_doChange() -> void {
if(!locked()) _updateSelected(); if(!locked()) _updateSelected();
} }
auto pListView::_doContext() -> void { auto pTableView::_doContext() -> void {
if(!locked()) self().doContext(); if(!locked()) self().doContext();
} }
auto pListView::_doDataFunc(GtkTreeViewColumn* gtkColumn, GtkCellRenderer* renderer, GtkTreeIter* iter) -> void { auto pTableView::_doDataFunc(GtkTreeViewColumn* gtkColumn, GtkCellRenderer* renderer, GtkTreeIter* iter) -> void {
auto path = gtk_tree_model_get_string_from_iter(gtkTreeModel, iter); auto path = gtk_tree_model_get_string_from_iter(gtkTreeModel, iter);
auto row = natural(path); auto row = natural(path);
g_free(path); g_free(path);
@ -266,7 +266,7 @@ auto pListView::_doDataFunc(GtkTreeViewColumn* gtkColumn, GtkCellRenderer* rende
} }
} }
auto pListView::_doEdit(GtkCellRendererText* gtkCellRendererText, const char* path, const char* text) -> void { auto pTableView::_doEdit(GtkCellRendererText* gtkCellRendererText, const char* path, const char* text) -> void {
if(auto& header = state().header) { if(auto& header = state().header) {
for(auto& column : header->state.columns) { for(auto& column : header->state.columns) {
if(auto delegate = column->self()) { if(auto delegate = column->self()) {
@ -287,12 +287,12 @@ auto pListView::_doEdit(GtkCellRendererText* gtkCellRendererText, const char* pa
} }
} }
auto pListView::_doEvent(GdkEventButton* event) -> signed { auto pTableView::_doEvent(GdkEventButton* event) -> signed {
GtkTreePath* path = nullptr; GtkTreePath* path = nullptr;
gtk_tree_view_get_path_at_pos(gtkTreeView, event->x, event->y, &path, nullptr, nullptr, nullptr); gtk_tree_view_get_path_at_pos(gtkTreeView, event->x, event->y, &path, nullptr, nullptr, nullptr);
if(event->type == GDK_BUTTON_PRESS) { if(event->type == GDK_BUTTON_PRESS) {
//when clicking in empty space below the last list view item; GTK+ does not deselect all items; //when clicking in empty space below the last table view item; GTK+ does not deselect all items;
//below code enables this functionality, to match behavior with all other UI toolkits (and because it's very convenient to have) //below code enables this functionality, to match behavior with all other UI toolkits (and because it's very convenient to have)
if(path == nullptr && gtk_tree_selection_count_selected_rows(gtkTreeSelection) > 0) { if(path == nullptr && gtk_tree_selection_count_selected_rows(gtkTreeSelection) > 0) {
for(auto& item : state().items) item->setSelected(false); for(auto& item : state().items) item->setSelected(false);
@ -316,7 +316,7 @@ auto pListView::_doEvent(GdkEventButton* event) -> signed {
return false; return false;
} }
auto pListView::_doHeaderActivate(GtkTreeViewColumn* gtkTreeViewColumn) -> void { auto pTableView::_doHeaderActivate(GtkTreeViewColumn* gtkTreeViewColumn) -> void {
if(auto& header = state().header) { if(auto& header = state().header) {
for(auto& column : header->state.columns) { for(auto& column : header->state.columns) {
if(auto delegate = column->self()) { if(auto delegate = column->self()) {
@ -330,15 +330,15 @@ auto pListView::_doHeaderActivate(GtkTreeViewColumn* gtkTreeViewColumn) -> void
} }
//GtkTreeView::cursor-changed and GtkTreeSelection::changed do not send signals for changes during rubber-banding selection //GtkTreeView::cursor-changed and GtkTreeSelection::changed do not send signals for changes during rubber-banding selection
//so here we capture motion-notify-event, and if the selections have changed, invoke ListView::onChange //so here we capture motion-notify-event, and if the selections have changed, invoke TableView::onChange
auto pListView::_doMouseMove() -> signed { auto pTableView::_doMouseMove() -> signed {
if(gtk_tree_view_is_rubber_banding_active(gtkTreeView)) { if(gtk_tree_view_is_rubber_banding_active(gtkTreeView)) {
if(!locked()) _updateSelected(); if(!locked()) _updateSelected();
} }
return false; return false;
} }
auto pListView::_doToggle(GtkCellRendererToggle* gtkCellRendererToggle, const char* path) -> void { auto pTableView::_doToggle(GtkCellRendererToggle* gtkCellRendererToggle, const char* path) -> void {
if(auto& header = state().header) { if(auto& header = state().header) {
for(auto& column : header->state.columns) { for(auto& column : header->state.columns) {
if(auto delegate = column->self()) { if(auto delegate = column->self()) {
@ -361,7 +361,7 @@ auto pListView::_doToggle(GtkCellRendererToggle* gtkCellRendererToggle, const ch
//if different, invoke the onChange callback unless locked, and cache current selection //if different, invoke the onChange callback unless locked, and cache current selection
//this prevents firing an onChange event when the actual selection has not changed //this prevents firing an onChange event when the actual selection has not changed
//this is particularly important for the motion-notify-event binding //this is particularly important for the motion-notify-event binding
auto pListView::_updateSelected() -> void { auto pTableView::_updateSelected() -> void {
vector<unsigned> selected; vector<unsigned> selected;
GList* list = gtk_tree_selection_get_selected_rows(gtkTreeSelection, &gtkTreeModel); GList* list = gtk_tree_selection_get_selected_rows(gtkTreeSelection, &gtkTreeModel);
@ -402,7 +402,7 @@ auto pListView::_updateSelected() -> void {
if(!locked()) self().doChange(); if(!locked()) self().doChange();
} }
auto pListView::_width(unsigned column) -> unsigned { auto pTableView::_width(unsigned column) -> unsigned {
if(auto& header = state().header) { if(auto& header = state().header) {
if(auto width = header->column(column).width()) return width; if(auto width = header->column(column).width()) return width;
unsigned width = 1; unsigned width = 1;

View File

@ -1,15 +1,15 @@
#if defined(Hiro_ListView) #if defined(Hiro_TableView)
namespace hiro { namespace hiro {
struct pListView : pWidget { struct pTableView : pWidget {
Declare(ListView, Widget) Declare(TableView, Widget)
auto append(sListViewHeader column) -> void; auto append(sTableViewHeader column) -> void;
auto append(sListViewItem item) -> void; auto append(sTableViewItem item) -> void;
auto focused() const -> bool override; auto focused() const -> bool override;
auto remove(sListViewHeader column) -> void; auto remove(sTableViewHeader column) -> void;
auto remove(sListViewItem item) -> void; auto remove(sTableViewItem item) -> void;
auto resizeColumns() -> void; auto resizeColumns() -> void;
auto setAlignment(Alignment alignment) -> void; auto setAlignment(Alignment alignment) -> void;
auto setBackgroundColor(Color color) -> void; auto setBackgroundColor(Color color) -> void;

View File

@ -47,16 +47,16 @@
#include "widget/icon-view.cpp" #include "widget/icon-view.cpp"
#include "widget/label.cpp" #include "widget/label.cpp"
#include "widget/line-edit.cpp" #include "widget/line-edit.cpp"
#include "widget/list-view.cpp"
#include "widget/list-view-header.cpp"
#include "widget/list-view-column.cpp"
#include "widget/list-view-item.cpp"
#include "widget/list-view-cell.cpp"
#include "widget/progress-bar.cpp" #include "widget/progress-bar.cpp"
#include "widget/radio-button.cpp" #include "widget/radio-button.cpp"
#include "widget/radio-label.cpp" #include "widget/radio-label.cpp"
#include "widget/tab-frame.cpp" #include "widget/tab-frame.cpp"
#include "widget/tab-frame-item.cpp" #include "widget/tab-frame-item.cpp"
#include "widget/table-view.cpp"
#include "widget/table-view-header.cpp"
#include "widget/table-view-column.cpp"
#include "widget/table-view-item.cpp"
#include "widget/table-view-cell.cpp"
#include "widget/text-edit.cpp" #include "widget/text-edit.cpp"
#include "widget/vertical-scroll-bar.cpp" #include "widget/vertical-scroll-bar.cpp"
#include "widget/vertical-slider.cpp" #include "widget/vertical-slider.cpp"

View File

@ -48,16 +48,16 @@
#include "widget/horizontal-slider.hpp" #include "widget/horizontal-slider.hpp"
#include "widget/label.hpp" #include "widget/label.hpp"
#include "widget/line-edit.hpp" #include "widget/line-edit.hpp"
#include "widget/list-view.hpp"
#include "widget/list-view-header.hpp"
#include "widget/list-view-column.hpp"
#include "widget/list-view-item.hpp"
#include "widget/list-view-cell.hpp"
#include "widget/progress-bar.hpp" #include "widget/progress-bar.hpp"
#include "widget/radio-button.hpp" #include "widget/radio-button.hpp"
#include "widget/radio-label.hpp" #include "widget/radio-label.hpp"
#include "widget/tab-frame.hpp" #include "widget/tab-frame.hpp"
#include "widget/tab-frame-item.hpp" #include "widget/tab-frame-item.hpp"
#include "widget/table-view.hpp"
#include "widget/table-view-header.hpp"
#include "widget/table-view-column.hpp"
#include "widget/table-view-item.hpp"
#include "widget/table-view-cell.hpp"
#include "widget/text-edit.hpp" #include "widget/text-edit.hpp"
#include "widget/vertical-scroll-bar.hpp" #include "widget/vertical-scroll-bar.hpp"
#include "widget/vertical-slider.hpp" #include "widget/vertical-slider.hpp"

View File

@ -1,3 +1,5 @@
//moc-qt4 -i -o qt.moc qt.hpp
/* /*
Qt requires moc in order to bind callbacks, which causes many complications. Qt requires moc in order to bind callbacks, which causes many complications.
@ -194,30 +196,6 @@ public slots:
}; };
#endif #endif
#if defined(Hiro_ListView)
struct QtListView : public QTreeWidget {
Q_OBJECT
public:
QtListView(pListView& p) : p(p) {}
auto mousePressEvent(QMouseEvent*) -> void override;
auto resizeEvent(QResizeEvent*) -> void override;
auto showEvent(QShowEvent*) -> void override;
pListView& p;
public slots:
void onActivate();
void onChange();
void onContext();
void onSort(int column);
void onToggle(QTreeWidgetItem* item, int column);
};
struct QtListViewDelegate : public QStyledItemDelegate {
QtListViewDelegate(pListView& p);
auto paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const -> void;
pListView& p;
};
#endif
#if defined(Hiro_RadioLabel) #if defined(Hiro_RadioLabel)
struct QtRadioLabel : public QRadioButton { struct QtRadioLabel : public QRadioButton {
Q_OBJECT Q_OBJECT
@ -252,6 +230,30 @@ public slots:
}; };
#endif #endif
#if defined(Hiro_TableView)
struct QtTableView : public QTreeWidget {
Q_OBJECT
public:
QtTableView(pTableView& p) : p(p) {}
auto mousePressEvent(QMouseEvent*) -> void override;
auto resizeEvent(QResizeEvent*) -> void override;
auto showEvent(QShowEvent*) -> void override;
pTableView& p;
public slots:
void onActivate();
void onChange();
void onContext();
void onSort(int column);
void onToggle(QTreeWidgetItem* item, int column);
};
struct QtTableViewDelegate : public QStyledItemDelegate {
QtTableViewDelegate(pTableView& p);
auto paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const -> void;
pTableView& p;
};
#endif
#if defined(Hiro_TextEdit) #if defined(Hiro_TextEdit)
struct QtTextEdit : public QTextEdit { struct QtTextEdit : public QTextEdit {
Q_OBJECT Q_OBJECT

View File

@ -1031,90 +1031,6 @@ int hiro::QtLineEdit::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
} }
return _id; return _id;
} }
static const uint qt_meta_data_hiro__QtListView[] = {
// content:
6, // revision
0, // classname
0, 0, // classinfo
5, 14, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
0, // flags
0, // signalCount
// slots: signature, parameters, type, tag, flags
17, 30, 30, 30, 0x0a,
31, 30, 30, 30, 0x0a,
42, 30, 30, 30, 0x0a,
54, 66, 30, 30, 0x0a,
73, 104, 30, 30, 0x0a,
0 // eod
};
static const char qt_meta_stringdata_hiro__QtListView[] = {
"hiro::QtListView\0onActivate()\0\0"
"onChange()\0onContext()\0onSort(int)\0"
"column\0onToggle(QTreeWidgetItem*,int)\0"
"item,column\0"
};
void hiro::QtListView::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
{
if (_c == QMetaObject::InvokeMetaMethod) {
Q_ASSERT(staticMetaObject.cast(_o));
QtListView *_t = static_cast<QtListView *>(_o);
switch (_id) {
case 0: _t->onActivate(); break;
case 1: _t->onChange(); break;
case 2: _t->onContext(); break;
case 3: _t->onSort((*reinterpret_cast< int(*)>(_a[1]))); break;
case 4: _t->onToggle((*reinterpret_cast< QTreeWidgetItem*(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break;
default: ;
}
}
}
const QMetaObjectExtraData hiro::QtListView::staticMetaObjectExtraData = {
0, qt_static_metacall
};
const QMetaObject hiro::QtListView::staticMetaObject = {
{ &QTreeWidget::staticMetaObject, qt_meta_stringdata_hiro__QtListView,
qt_meta_data_hiro__QtListView, &staticMetaObjectExtraData }
};
#ifdef Q_NO_DATA_RELOCATION
const QMetaObject &hiro::QtListView::getStaticMetaObject() { return staticMetaObject; }
#endif //Q_NO_DATA_RELOCATION
const QMetaObject *hiro::QtListView::metaObject() const
{
return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject;
}
void *hiro::QtListView::qt_metacast(const char *_clname)
{
if (!_clname) return 0;
if (!strcmp(_clname, qt_meta_stringdata_hiro__QtListView))
return static_cast<void*>(const_cast< QtListView*>(this));
return QTreeWidget::qt_metacast(_clname);
}
int hiro::QtListView::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
_id = QTreeWidget::qt_metacall(_c, _id, _a);
if (_id < 0)
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
if (_id < 5)
qt_static_metacall(this, _c, _id, _a);
_id -= 5;
}
return _id;
}
static const uint qt_meta_data_hiro__QtRadioLabel[] = { static const uint qt_meta_data_hiro__QtRadioLabel[] = {
// content: // content:
@ -1337,6 +1253,90 @@ int hiro::QtTabFrame::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
} }
return _id; return _id;
} }
static const uint qt_meta_data_hiro__QtTableView[] = {
// content:
6, // revision
0, // classname
0, 0, // classinfo
5, 14, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
0, // flags
0, // signalCount
// slots: signature, parameters, type, tag, flags
18, 31, 31, 31, 0x0a,
32, 31, 31, 31, 0x0a,
43, 31, 31, 31, 0x0a,
55, 67, 31, 31, 0x0a,
74, 105, 31, 31, 0x0a,
0 // eod
};
static const char qt_meta_stringdata_hiro__QtTableView[] = {
"hiro::QtTableView\0onActivate()\0\0"
"onChange()\0onContext()\0onSort(int)\0"
"column\0onToggle(QTreeWidgetItem*,int)\0"
"item,column\0"
};
void hiro::QtTableView::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
{
if (_c == QMetaObject::InvokeMetaMethod) {
Q_ASSERT(staticMetaObject.cast(_o));
QtTableView *_t = static_cast<QtTableView *>(_o);
switch (_id) {
case 0: _t->onActivate(); break;
case 1: _t->onChange(); break;
case 2: _t->onContext(); break;
case 3: _t->onSort((*reinterpret_cast< int(*)>(_a[1]))); break;
case 4: _t->onToggle((*reinterpret_cast< QTreeWidgetItem*(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break;
default: ;
}
}
}
const QMetaObjectExtraData hiro::QtTableView::staticMetaObjectExtraData = {
0, qt_static_metacall
};
const QMetaObject hiro::QtTableView::staticMetaObject = {
{ &QTreeWidget::staticMetaObject, qt_meta_stringdata_hiro__QtTableView,
qt_meta_data_hiro__QtTableView, &staticMetaObjectExtraData }
};
#ifdef Q_NO_DATA_RELOCATION
const QMetaObject &hiro::QtTableView::getStaticMetaObject() { return staticMetaObject; }
#endif //Q_NO_DATA_RELOCATION
const QMetaObject *hiro::QtTableView::metaObject() const
{
return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject;
}
void *hiro::QtTableView::qt_metacast(const char *_clname)
{
if (!_clname) return 0;
if (!strcmp(_clname, qt_meta_stringdata_hiro__QtTableView))
return static_cast<void*>(const_cast< QtTableView*>(this));
return QTreeWidget::qt_metacast(_clname);
}
int hiro::QtTableView::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
_id = QTreeWidget::qt_metacall(_c, _id, _a);
if (_id < 0)
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
if (_id < 5)
qt_static_metacall(this, _c, _id, _a);
_id -= 5;
}
return _id;
}
static const uint qt_meta_data_hiro__QtTextEdit[] = { static const uint qt_meta_data_hiro__QtTextEdit[] = {
// content: // content:

View File

@ -1,99 +0,0 @@
#if defined(Hiro_ListView)
namespace hiro {
auto pListViewColumn::construct() -> void {
}
auto pListViewColumn::destruct() -> void {
}
auto pListViewColumn::setActive() -> void {
//unsupported
}
auto pListViewColumn::setAlignment(Alignment alignment) -> void {
_setState();
}
auto pListViewColumn::setBackgroundColor(Color color) -> void {
_setState();
}
auto pListViewColumn::setEditable(bool editable) -> void {
//unsupported
}
auto pListViewColumn::setExpandable(bool expandable) -> void {
_setState();
}
auto pListViewColumn::setFont(const Font& font) -> void {
_setState();
}
auto pListViewColumn::setForegroundColor(Color color) -> void {
_setState();
}
auto pListViewColumn::setHorizontalAlignment(double alignment) -> void {
_setState();
}
auto pListViewColumn::setIcon(const image& icon) -> void {
//unsupported
}
auto pListViewColumn::setResizable(bool resizable) -> void {
_setState();
}
auto pListViewColumn::setSortable(bool sortable) -> void {
_setState();
}
auto pListViewColumn::setText(const string& text) -> void {
_setState();
}
auto pListViewColumn::setVerticalAlignment(double alignment) -> void {
_setState();
}
auto pListViewColumn::setVisible(bool visible) -> void {
_setState();
}
auto pListViewColumn::setWidth(signed width) -> void {
_setState();
}
auto pListViewColumn::_parent() -> maybe<pListViewHeader&> {
if(auto parent = self().parentListViewHeader()) {
if(auto delegate = parent->self()) return *delegate;
}
return nothing;
}
auto pListViewColumn::_setState() -> void {
if(auto header = _parent()) {
if(auto parent = header->_parent()) {
parent->qtListView->header()->setResizeMode(self().offset(), state().resizable ? QHeaderView::Interactive : QHeaderView::Fixed);
bool clickable = false;
for(auto& column : header->state().columns) clickable |= column->state.sortable;
parent->qtListView->header()->setClickable(clickable);
parent->qtListView->headerItem()->setText(self().offset(), QString::fromUtf8(state().text));
parent->qtListView->setColumnHidden(self().offset(), !self().visible());
for(auto& item : parent->state().items) {
if(auto cell = item->cell(self().offset())) {
if(auto self = cell->self()) self->_setState();
}
}
}
}
}
}
#endif

View File

@ -1,43 +0,0 @@
#if defined(Hiro_ListView)
namespace hiro {
auto pListViewHeader::construct() -> void {
}
auto pListViewHeader::destruct() -> void {
}
auto pListViewHeader::append(sListViewColumn column) -> void {
_setState();
}
auto pListViewHeader::remove(sListViewColumn column) -> void {
_setState();
}
auto pListViewHeader::setVisible(bool visible) -> void {
_setState();
}
auto pListViewHeader::_parent() -> maybe<pListView&> {
if(auto parent = self().parentListView()) {
if(auto delegate = parent->self()) return *delegate;
}
return nothing;
}
auto pListViewHeader::_setState() -> void {
if(auto parent = _parent()) {
//parent->qtListView->setAlternatingRowColors(self().columnCount() >= 2);
parent->qtListView->setColumnCount(self().columnCount());
parent->qtListView->setHeaderHidden(!self().visible());
for(auto& column : state().columns) {
if(auto self = column->self()) self->_setState();
}
}
}
}
#endif

View File

@ -1,18 +0,0 @@
#if defined(Hiro_ListView)
namespace hiro {
struct pListViewHeader : pObject {
Declare(ListViewHeader, Object)
auto append(sListViewColumn column) -> void;
auto remove(sListViewColumn column) -> void;
auto setVisible(bool visible) -> void override;
auto _parent() -> maybe<pListView&>;
auto _setState() -> void;
};
}
#endif

View File

@ -1,64 +0,0 @@
#if defined(Hiro_ListView)
namespace hiro {
auto pListViewItem::construct() -> void {
}
auto pListViewItem::destruct() -> void {
if(auto parent = _parent()) parent->lock();
if(qtItem) {
delete qtItem;
qtItem = nullptr;
}
if(auto parent = _parent()) parent->unlock();
}
auto pListViewItem::append(sListViewCell cell) -> void {
}
auto pListViewItem::remove(sListViewCell cell) -> void {
}
auto pListViewItem::setAlignment(Alignment alignment) -> void {
_setState();
}
auto pListViewItem::setBackgroundColor(Color color) -> void {
_setState();
}
auto pListViewItem::setFont(const Font& font) -> void {
_setState();
}
auto pListViewItem::setForegroundColor(Color color) -> void {
_setState();
}
auto pListViewItem::setSelected(bool selected) -> void {
_setState();
}
auto pListViewItem::_parent() -> maybe<pListView&> {
if(auto parent = self().parentListView()) {
if(auto delegate = parent->self()) return *delegate;
}
return nothing;
}
auto pListViewItem::_setState() -> void {
if(auto parent = _parent()) {
qtItem->setSelected(state().selected);
if(state().selected) {
parent->qtListView->setCurrentItem(qtItem);
}
for(auto& cell : state().cells) {
if(auto self = cell->self()) self->_setState();
}
}
}
}
#endif

View File

@ -1,53 +1,53 @@
#if defined(Hiro_ListView) #if defined(Hiro_TableView)
namespace hiro { namespace hiro {
auto pListViewCell::construct() -> void { auto pTableViewCell::construct() -> void {
} }
auto pListViewCell::destruct() -> void { auto pTableViewCell::destruct() -> void {
} }
auto pListViewCell::setAlignment(Alignment alignment) -> void { auto pTableViewCell::setAlignment(Alignment alignment) -> void {
_setState(); _setState();
} }
auto pListViewCell::setBackgroundColor(Color color) -> void { auto pTableViewCell::setBackgroundColor(Color color) -> void {
_setState(); _setState();
} }
auto pListViewCell::setCheckable(bool checkable) -> void { auto pTableViewCell::setCheckable(bool checkable) -> void {
_setState(); _setState();
} }
auto pListViewCell::setChecked(bool checked) -> void { auto pTableViewCell::setChecked(bool checked) -> void {
_setState(); _setState();
} }
auto pListViewCell::setFont(const string& font) -> void { auto pTableViewCell::setFont(const string& font) -> void {
_setState(); _setState();
} }
auto pListViewCell::setForegroundColor(Color color) -> void { auto pTableViewCell::setForegroundColor(Color color) -> void {
_setState(); _setState();
} }
auto pListViewCell::setIcon(const image& icon) -> void { auto pTableViewCell::setIcon(const image& icon) -> void {
_setState(); _setState();
} }
auto pListViewCell::setText(const string& text) -> void { auto pTableViewCell::setText(const string& text) -> void {
_setState(); _setState();
} }
auto pListViewCell::_parent() -> maybe<pListViewItem&> { auto pTableViewCell::_parent() -> maybe<pTableViewItem&> {
if(auto parent = self().parentListViewItem()) { if(auto parent = self().parentTableViewItem()) {
if(auto delegate = parent->self()) return *delegate; if(auto delegate = parent->self()) return *delegate;
} }
return nothing; return nothing;
} }
auto pListViewCell::_setState() -> void { auto pTableViewCell::_setState() -> void {
if(auto parent = _parent()) { if(auto parent = _parent()) {
if(auto grandparent = parent->_parent()) { if(auto grandparent = parent->_parent()) {
grandparent->lock(); grandparent->lock();

View File

@ -1,9 +1,9 @@
#if defined(Hiro_ListView) #if defined(Hiro_TableView)
namespace hiro { namespace hiro {
struct pListViewCell : pObject { struct pTableViewCell : pObject {
Declare(ListViewCell, Object) Declare(TableViewCell, Object)
auto setAlignment(Alignment alignment) -> void; auto setAlignment(Alignment alignment) -> void;
auto setBackgroundColor(Color color) -> void; auto setBackgroundColor(Color color) -> void;
@ -14,7 +14,7 @@ struct pListViewCell : pObject {
auto setIcon(const image& icon) -> void; auto setIcon(const image& icon) -> void;
auto setText(const string& text) -> void; auto setText(const string& text) -> void;
auto _parent() -> maybe<pListViewItem&>; auto _parent() -> maybe<pTableViewItem&>;
auto _setState() -> void; auto _setState() -> void;
}; };

View File

@ -0,0 +1,99 @@
#if defined(Hiro_TableView)
namespace hiro {
auto pTableViewColumn::construct() -> void {
}
auto pTableViewColumn::destruct() -> void {
}
auto pTableViewColumn::setActive() -> void {
//unsupported
}
auto pTableViewColumn::setAlignment(Alignment alignment) -> void {
_setState();
}
auto pTableViewColumn::setBackgroundColor(Color color) -> void {
_setState();
}
auto pTableViewColumn::setEditable(bool editable) -> void {
//unsupported
}
auto pTableViewColumn::setExpandable(bool expandable) -> void {
_setState();
}
auto pTableViewColumn::setFont(const Font& font) -> void {
_setState();
}
auto pTableViewColumn::setForegroundColor(Color color) -> void {
_setState();
}
auto pTableViewColumn::setHorizontalAlignment(double alignment) -> void {
_setState();
}
auto pTableViewColumn::setIcon(const image& icon) -> void {
//unsupported
}
auto pTableViewColumn::setResizable(bool resizable) -> void {
_setState();
}
auto pTableViewColumn::setSortable(bool sortable) -> void {
_setState();
}
auto pTableViewColumn::setText(const string& text) -> void {
_setState();
}
auto pTableViewColumn::setVerticalAlignment(double alignment) -> void {
_setState();
}
auto pTableViewColumn::setVisible(bool visible) -> void {
_setState();
}
auto pTableViewColumn::setWidth(signed width) -> void {
_setState();
}
auto pTableViewColumn::_parent() -> maybe<pTableViewHeader&> {
if(auto parent = self().parentTableViewHeader()) {
if(auto delegate = parent->self()) return *delegate;
}
return nothing;
}
auto pTableViewColumn::_setState() -> void {
if(auto header = _parent()) {
if(auto parent = header->_parent()) {
parent->qtTableView->header()->setResizeMode(self().offset(), state().resizable ? QHeaderView::Interactive : QHeaderView::Fixed);
bool clickable = false;
for(auto& column : header->state().columns) clickable |= column->state.sortable;
parent->qtTableView->header()->setClickable(clickable);
parent->qtTableView->headerItem()->setText(self().offset(), QString::fromUtf8(state().text));
parent->qtTableView->setColumnHidden(self().offset(), !self().visible());
for(auto& item : parent->state().items) {
if(auto cell = item->cell(self().offset())) {
if(auto self = cell->self()) self->_setState();
}
}
}
}
}
}
#endif

View File

@ -1,9 +1,9 @@
#if defined(Hiro_ListView) #if defined(Hiro_TableView)
namespace hiro { namespace hiro {
struct pListViewColumn : pObject { struct pTableViewColumn : pObject {
Declare(ListViewColumn, Object) Declare(TableViewColumn, Object)
auto setActive() -> void; auto setActive() -> void;
auto setAlignment(Alignment alignment) -> void; auto setAlignment(Alignment alignment) -> void;
@ -21,7 +21,7 @@ struct pListViewColumn : pObject {
auto setVisible(bool visible) -> void; auto setVisible(bool visible) -> void;
auto setWidth(signed width) -> void; auto setWidth(signed width) -> void;
auto _parent() -> maybe<pListViewHeader&>; auto _parent() -> maybe<pTableViewHeader&>;
auto _setState() -> void; auto _setState() -> void;
}; };

View File

@ -0,0 +1,43 @@
#if defined(Hiro_TableView)
namespace hiro {
auto pTableViewHeader::construct() -> void {
}
auto pTableViewHeader::destruct() -> void {
}
auto pTableViewHeader::append(sTableViewColumn column) -> void {
_setState();
}
auto pTableViewHeader::remove(sTableViewColumn column) -> void {
_setState();
}
auto pTableViewHeader::setVisible(bool visible) -> void {
_setState();
}
auto pTableViewHeader::_parent() -> maybe<pTableView&> {
if(auto parent = self().parentTableView()) {
if(auto delegate = parent->self()) return *delegate;
}
return nothing;
}
auto pTableViewHeader::_setState() -> void {
if(auto parent = _parent()) {
//parent->qtTableView->setAlternatingRowColors(self().columnCount() >= 2);
parent->qtTableView->setColumnCount(self().columnCount());
parent->qtTableView->setHeaderHidden(!self().visible());
for(auto& column : state().columns) {
if(auto self = column->self()) self->_setState();
}
}
}
}
#endif

View File

@ -0,0 +1,18 @@
#if defined(Hiro_TableView)
namespace hiro {
struct pTableViewHeader : pObject {
Declare(TableViewHeader, Object)
auto append(sTableViewColumn column) -> void;
auto remove(sTableViewColumn column) -> void;
auto setVisible(bool visible) -> void override;
auto _parent() -> maybe<pTableView&>;
auto _setState() -> void;
};
}
#endif

View File

@ -0,0 +1,66 @@
#if defined(Hiro_TableView)
namespace hiro {
auto pTableViewItem::construct() -> void {
}
auto pTableViewItem::destruct() -> void {
if(auto parent = _parent()) parent->lock();
if(qtItem) {
delete qtItem;
qtItem = nullptr;
}
if(auto parent = _parent()) parent->unlock();
}
auto pTableViewItem::append(sTableViewCell cell) -> void {
_setState();
}
auto pTableViewItem::remove(sTableViewCell cell) -> void {
_setState();
}
auto pTableViewItem::setAlignment(Alignment alignment) -> void {
_setState();
}
auto pTableViewItem::setBackgroundColor(Color color) -> void {
_setState();
}
auto pTableViewItem::setFont(const Font& font) -> void {
_setState();
}
auto pTableViewItem::setForegroundColor(Color color) -> void {
_setState();
}
auto pTableViewItem::setSelected(bool selected) -> void {
_setState();
}
auto pTableViewItem::_parent() -> maybe<pTableView&> {
if(auto parent = self().parentTableView()) {
if(auto delegate = parent->self()) return *delegate;
}
return nothing;
}
auto pTableViewItem::_setState() -> void {
if(auto parent = _parent()) {
qtItem->setSelected(state().selected);
if(state().selected) {
parent->qtTableView->setCurrentItem(qtItem);
}
for(auto& cell : state().cells) {
if(auto self = cell->self()) self->_setState();
}
}
}
}
#endif

View File

@ -1,19 +1,19 @@
#if defined(Hiro_ListView) #if defined(Hiro_TableView)
namespace hiro { namespace hiro {
struct pListViewItem : pObject { struct pTableViewItem : pObject {
Declare(ListViewItem, Object) Declare(TableViewItem, Object)
auto append(sListViewCell cell) -> void; auto append(sTableViewCell cell) -> void;
auto remove(sListViewCell cell) -> void; auto remove(sTableViewCell cell) -> void;
auto setAlignment(Alignment alignment) -> void; auto setAlignment(Alignment alignment) -> void;
auto setBackgroundColor(Color color) -> void; auto setBackgroundColor(Color color) -> void;
auto setFont(const Font& font) -> void override; auto setFont(const Font& font) -> void override;
auto setForegroundColor(Color color) -> void; auto setForegroundColor(Color color) -> void;
auto setSelected(bool selected) -> void; auto setSelected(bool selected) -> void;
auto _parent() -> maybe<pListView&>; auto _parent() -> maybe<pTableView&>;
auto _setState() -> void; auto _setState() -> void;
QTreeWidgetItem* qtItem = nullptr; QTreeWidgetItem* qtItem = nullptr;

View File

@ -1,23 +1,23 @@
#if defined(Hiro_ListView) #if defined(Hiro_TableView)
namespace hiro { namespace hiro {
auto pListView::construct() -> void { auto pTableView::construct() -> void {
qtWidget = qtListView = new QtListView(*this); qtWidget = qtTableView = new QtTableView(*this);
qtListView->setAllColumnsShowFocus(true); qtTableView->setAllColumnsShowFocus(true);
qtListView->setContextMenuPolicy(Qt::CustomContextMenu); qtTableView->setContextMenuPolicy(Qt::CustomContextMenu);
qtListView->setRootIsDecorated(false); qtTableView->setRootIsDecorated(false);
qtListView->setHeaderHidden(true); qtTableView->setHeaderHidden(true);
qtListView->header()->setMovable(false); qtTableView->header()->setMovable(false);
qtListViewDelegate = new QtListViewDelegate(*this); qtTableViewDelegate = new QtTableViewDelegate(*this);
qtListView->setItemDelegate(qtListViewDelegate); qtTableView->setItemDelegate(qtTableViewDelegate);
qtListView->connect(qtListView, SIGNAL(itemActivated(QTreeWidgetItem*, int)), SLOT(onActivate())); qtTableView->connect(qtTableView, SIGNAL(itemActivated(QTreeWidgetItem*, int)), SLOT(onActivate()));
qtListView->connect(qtListView, SIGNAL(itemSelectionChanged()), SLOT(onChange())); qtTableView->connect(qtTableView, SIGNAL(itemSelectionChanged()), SLOT(onChange()));
qtListView->connect(qtListView, SIGNAL(customContextMenuRequested(const QPoint&)), SLOT(onContext())); qtTableView->connect(qtTableView, SIGNAL(customContextMenuRequested(const QPoint&)), SLOT(onContext()));
qtListView->connect(qtListView->header(), SIGNAL(sectionClicked(int)), SLOT(onSort(int))); qtTableView->connect(qtTableView->header(), SIGNAL(sectionClicked(int)), SLOT(onSort(int)));
qtListView->connect(qtListView, SIGNAL(itemChanged(QTreeWidgetItem*, int)), SLOT(onToggle(QTreeWidgetItem*, int))); qtTableView->connect(qtTableView, SIGNAL(itemChanged(QTreeWidgetItem*, int)), SLOT(onToggle(QTreeWidgetItem*, int)));
setBackgroundColor(state().backgroundColor); setBackgroundColor(state().backgroundColor);
setBatchable(state().batchable); setBatchable(state().batchable);
@ -27,14 +27,14 @@ auto pListView::construct() -> void {
pWidget::construct(); pWidget::construct();
} }
auto pListView::destruct() -> void { auto pTableView::destruct() -> void {
delete qtListViewDelegate; delete qtTableViewDelegate;
delete qtListView; delete qtTableView;
qtWidget = qtListView = nullptr; qtWidget = qtTableView = nullptr;
qtListViewDelegate = nullptr; qtTableViewDelegate = nullptr;
} }
auto pListView::append(sListViewHeader header) -> void { auto pTableView::append(sTableViewHeader header) -> void {
lock(); lock();
if(auto self = header->self()) { if(auto self = header->self()) {
self->_setState(); self->_setState();
@ -42,22 +42,22 @@ auto pListView::append(sListViewHeader header) -> void {
unlock(); unlock();
} }
auto pListView::append(sListViewItem item) -> void { auto pTableView::append(sTableViewItem item) -> void {
lock(); lock();
if(auto self = item->self()) { if(auto self = item->self()) {
self->qtItem = new QTreeWidgetItem(qtListView); self->qtItem = new QTreeWidgetItem(qtTableView);
self->_setState(); self->_setState();
} }
unlock(); unlock();
} }
auto pListView::remove(sListViewHeader header) -> void { auto pTableView::remove(sTableViewHeader header) -> void {
} }
auto pListView::remove(sListViewItem item) -> void { auto pTableView::remove(sTableViewItem item) -> void {
} }
auto pListView::resizeColumns() -> void { auto pTableView::resizeColumns() -> void {
lock(); lock();
if(auto& header = state().header) { if(auto& header = state().header) {
@ -72,7 +72,7 @@ auto pListView::resizeColumns() -> void {
} }
signed maximumWidth = self().geometry().width() - 6; signed maximumWidth = self().geometry().width() - 6;
if(auto scrollBar = qtListView->verticalScrollBar()) { if(auto scrollBar = qtTableView->verticalScrollBar()) {
if(scrollBar->isVisible()) maximumWidth -= scrollBar->geometry().width(); if(scrollBar->isVisible()) maximumWidth -= scrollBar->geometry().width();
} }
@ -84,50 +84,50 @@ auto pListView::resizeColumns() -> void {
for(auto column : range(header->columnCount())) { for(auto column : range(header->columnCount())) {
signed width = widths[column]; signed width = widths[column];
if(header->column(column).expandable()) width += expandWidth; if(header->column(column).expandable()) width += expandWidth;
qtListView->setColumnWidth(column, width); qtTableView->setColumnWidth(column, width);
} }
} }
unlock(); unlock();
} }
auto pListView::setAlignment(Alignment alignment) -> void { auto pTableView::setAlignment(Alignment alignment) -> void {
} }
auto pListView::setBackgroundColor(Color color) -> void { auto pTableView::setBackgroundColor(Color color) -> void {
if(color) { if(color) {
QPalette palette = qtListView->palette(); QPalette palette = qtTableView->palette();
palette.setColor(QPalette::Base, QColor(color.red(), color.green(), color.blue())); palette.setColor(QPalette::Base, QColor(color.red(), color.green(), color.blue()));
palette.setColor(QPalette::AlternateBase, QColor(max(0, (signed)color.red() - 17), max(0, (signed)color.green() - 17), max(0, (signed)color.blue() - 17))); palette.setColor(QPalette::AlternateBase, QColor(max(0, (signed)color.red() - 17), max(0, (signed)color.green() - 17), max(0, (signed)color.blue() - 17)));
qtListView->setPalette(palette); qtTableView->setPalette(palette);
qtListView->setAutoFillBackground(true); qtTableView->setAutoFillBackground(true);
} else { } else {
//todo: set default color //todo: set default color
} }
} }
auto pListView::setBatchable(bool batchable) -> void { auto pTableView::setBatchable(bool batchable) -> void {
lock(); lock();
qtListView->setSelectionMode(batchable ? QAbstractItemView::ExtendedSelection : QAbstractItemView::SingleSelection); qtTableView->setSelectionMode(batchable ? QAbstractItemView::ExtendedSelection : QAbstractItemView::SingleSelection);
unlock(); unlock();
} }
auto pListView::setBordered(bool bordered) -> void { auto pTableView::setBordered(bool bordered) -> void {
qtListView->repaint(); qtTableView->repaint();
} }
auto pListView::setForegroundColor(Color color) -> void { auto pTableView::setForegroundColor(Color color) -> void {
if(color) { if(color) {
QPalette palette = qtListView->palette(); QPalette palette = qtTableView->palette();
palette.setColor(QPalette::Text, QColor(color.red(), color.green(), color.blue())); palette.setColor(QPalette::Text, QColor(color.red(), color.green(), color.blue()));
qtListView->setPalette(palette); qtTableView->setPalette(palette);
} else { } else {
//todo: set default color //todo: set default color
} }
} }
//called on resize/show events //called on resize/show events
auto pListView::_onSize() -> void { auto pTableView::_onSize() -> void {
//resize columns only if at least one column is expandable //resize columns only if at least one column is expandable
if(auto& header = state().header) { if(auto& header = state().header) {
for(auto& column : header->state.columns) { for(auto& column : header->state.columns) {
@ -136,7 +136,7 @@ auto pListView::_onSize() -> void {
} }
} }
auto pListView::_width(unsigned column) -> unsigned { auto pTableView::_width(unsigned column) -> unsigned {
if(auto& header = state().header) { if(auto& header = state().header) {
if(auto width = header->column(column).width()) return width; if(auto width = header->column(column).width()) return width;
unsigned width = 1; unsigned width = 1;
@ -150,12 +150,12 @@ auto pListView::_width(unsigned column) -> unsigned {
return 1; return 1;
} }
auto pListView::_widthOfColumn(unsigned _column) -> unsigned { auto pTableView::_widthOfColumn(unsigned _column) -> unsigned {
unsigned width = 8; unsigned width = 8;
if(auto& header = state().header) { if(auto& header = state().header) {
if(auto column = header->column(_column)) { if(auto column = header->column(_column)) {
if(auto& icon = column->state.icon) { if(auto& icon = column->state.icon) {
width += icon.width() + 2; width += icon.width() + 4;
} }
if(auto& text = column->state.text) { if(auto& text = column->state.text) {
width += pFont::size(column->font(true), text).width(); width += pFont::size(column->font(true), text).width();
@ -165,15 +165,15 @@ auto pListView::_widthOfColumn(unsigned _column) -> unsigned {
return width; return width;
} }
auto pListView::_widthOfCell(unsigned _row, unsigned _column) -> unsigned { auto pTableView::_widthOfCell(unsigned _row, unsigned _column) -> unsigned {
unsigned width = 8; unsigned width = 8;
if(auto item = self().item(_row)) { if(auto item = self().item(_row)) {
if(auto cell = item->cell(_column)) { if(auto cell = item->cell(_column)) {
if(cell->state.checkable) { if(cell->state.checkable) {
width += 16 + 2; width += 16 + 4;
} }
if(auto& icon = cell->state.icon) { if(auto& icon = cell->state.icon) {
width += icon.width() + 2; width += icon.width() + 4;
} }
if(auto& text = cell->state.text) { if(auto& text = cell->state.text) {
width += pFont::size(cell->font(true), text).width(); width += pFont::size(cell->font(true), text).width();
@ -183,11 +183,11 @@ auto pListView::_widthOfCell(unsigned _row, unsigned _column) -> unsigned {
return width; return width;
} }
auto QtListView::onActivate() -> void { auto QtTableView::onActivate() -> void {
if(!p.locked()) p.self().doActivate(); if(!p.locked()) p.self().doActivate();
} }
auto QtListView::onChange() -> void { auto QtTableView::onChange() -> void {
for(auto& item : p.state().items) { for(auto& item : p.state().items) {
item->state.selected = false; item->state.selected = false;
if(auto self = item->self()) { if(auto self = item->self()) {
@ -197,11 +197,11 @@ auto QtListView::onChange() -> void {
if(!p.locked()) p.self().doChange(); if(!p.locked()) p.self().doChange();
} }
auto QtListView::onContext() -> void { auto QtTableView::onContext() -> void {
if(!p.locked()) p.self().doContext(); if(!p.locked()) p.self().doContext();
} }
auto QtListView::onSort(int columnNumber) -> void { auto QtTableView::onSort(int columnNumber) -> void {
if(auto& header = p.state().header) { if(auto& header = p.state().header) {
if(auto column = header->column(columnNumber)) { if(auto column = header->column(columnNumber)) {
if(!p.locked() && column.sortable()) p.self().doSort(column); if(!p.locked() && column.sortable()) p.self().doSort(column);
@ -209,7 +209,7 @@ auto QtListView::onSort(int columnNumber) -> void {
} }
} }
auto QtListView::onToggle(QTreeWidgetItem* qtItem, int column) -> void { auto QtTableView::onToggle(QTreeWidgetItem* qtItem, int column) -> void {
for(auto& item : p.state().items) { for(auto& item : p.state().items) {
if(auto self = item->self()) { if(auto self = item->self()) {
if(qtItem == self->qtItem) { if(qtItem == self->qtItem) {
@ -222,25 +222,25 @@ auto QtListView::onToggle(QTreeWidgetItem* qtItem, int column) -> void {
} }
} }
auto QtListView::mousePressEvent(QMouseEvent* event) -> void { auto QtTableView::mousePressEvent(QMouseEvent* event) -> void {
QTreeWidget::mousePressEvent(event); QTreeWidget::mousePressEvent(event);
if(event->button() == Qt::RightButton) onContext(); if(event->button() == Qt::RightButton) onContext();
} }
auto QtListView::resizeEvent(QResizeEvent* event) -> void { auto QtTableView::resizeEvent(QResizeEvent* event) -> void {
QTreeWidget::resizeEvent(event); QTreeWidget::resizeEvent(event);
p._onSize(); p._onSize();
} }
auto QtListView::showEvent(QShowEvent* event) -> void { auto QtTableView::showEvent(QShowEvent* event) -> void {
QTreeWidget::showEvent(event); QTreeWidget::showEvent(event);
p._onSize(); p._onSize();
} }
QtListViewDelegate::QtListViewDelegate(pListView& p) : QStyledItemDelegate(p.qtListView), p(p) { QtTableViewDelegate::QtTableViewDelegate(pTableView& p) : QStyledItemDelegate(p.qtTableView), p(p) {
} }
auto QtListViewDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const -> void { auto QtTableViewDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const -> void {
QStyledItemDelegate::paint(painter, option, index); QStyledItemDelegate::paint(painter, option, index);
if(p.state().bordered) { if(p.state().bordered) {
QPen pen; QPen pen;

View File

@ -1,14 +1,14 @@
#if defined(Hiro_ListView) #if defined(Hiro_TableView)
namespace hiro { namespace hiro {
struct pListView : pWidget { struct pTableView : pWidget {
Declare(ListView, Widget) Declare(TableView, Widget)
auto append(sListViewHeader header) -> void; auto append(sTableViewHeader header) -> void;
auto append(sListViewItem item) -> void; auto append(sTableViewItem item) -> void;
auto remove(sListViewHeader header) -> void; auto remove(sTableViewHeader header) -> void;
auto remove(sListViewItem item) -> void; auto remove(sTableViewItem item) -> void;
auto resizeColumns() -> void; auto resizeColumns() -> void;
auto setAlignment(Alignment alignment) -> void; auto setAlignment(Alignment alignment) -> void;
auto setBackgroundColor(Color color) -> void; auto setBackgroundColor(Color color) -> void;
@ -21,8 +21,8 @@ struct pListView : pWidget {
auto _widthOfColumn(unsigned column) -> unsigned; auto _widthOfColumn(unsigned column) -> unsigned;
auto _widthOfCell(unsigned row, unsigned column) -> unsigned; auto _widthOfCell(unsigned row, unsigned column) -> unsigned;
QtListView* qtListView = nullptr; QtTableView* qtTableView = nullptr;
QtListViewDelegate* qtListViewDelegate = nullptr; QtTableViewDelegate* qtTableViewDelegate = nullptr;
}; };
} }

View File

@ -163,10 +163,10 @@ static auto Application_keyboardProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM
if(msg == WM_KEYDOWN) { if(msg == WM_KEYDOWN) {
if(0); if(0);
#if defined(Hiro_ListView) #if defined(Hiro_TableView)
else if(auto listView = dynamic_cast<mListView*>(object)) { else if(auto tableView = dynamic_cast<mTableView*>(object)) {
if(wparam == VK_RETURN) { if(wparam == VK_RETURN) {
if(listView->selected()) return true; //returning true generates LVN_ITEMACTIVATE message if(tableView->selected()) return true; //returning true generates LVN_ITEMACTIVATE message
} }
} }
#endif #endif

View File

@ -41,11 +41,11 @@
#include "widget/horizontal-slider.cpp" #include "widget/horizontal-slider.cpp"
#include "widget/label.cpp" #include "widget/label.cpp"
#include "widget/line-edit.cpp" #include "widget/line-edit.cpp"
#include "widget/list-view.cpp" #include "widget/table-view.cpp"
#include "widget/list-view-header.cpp" #include "widget/table-view-header.cpp"
#include "widget/list-view-column.cpp" #include "widget/table-view-column.cpp"
#include "widget/list-view-item.cpp" #include "widget/table-view-item.cpp"
#include "widget/list-view-cell.cpp" #include "widget/table-view-cell.cpp"
#include "widget/progress-bar.cpp" #include "widget/progress-bar.cpp"
#include "widget/radio-button.cpp" #include "widget/radio-button.cpp"
#include "widget/radio-label.cpp" #include "widget/radio-label.cpp"

View File

@ -10,9 +10,9 @@ struct pWidget;
struct AppMessage { struct AppMessage {
enum : unsigned { enum : unsigned {
None = WM_APP, None = WM_APP,
ListView_doPaint, TableView_doPaint,
ListView_onActivate, TableView_onActivate,
ListView_onChange, TableView_onChange,
}; };
}; };
@ -70,16 +70,16 @@ static vector<wObject> windows;
#include "widget/horizontal-slider.hpp" #include "widget/horizontal-slider.hpp"
#include "widget/label.hpp" #include "widget/label.hpp"
#include "widget/line-edit.hpp" #include "widget/line-edit.hpp"
#include "widget/list-view.hpp"
#include "widget/list-view-header.hpp"
#include "widget/list-view-column.hpp"
#include "widget/list-view-item.hpp"
#include "widget/list-view-cell.hpp"
#include "widget/progress-bar.hpp" #include "widget/progress-bar.hpp"
#include "widget/radio-button.hpp" #include "widget/radio-button.hpp"
#include "widget/radio-label.hpp" #include "widget/radio-label.hpp"
#include "widget/tab-frame.hpp" #include "widget/tab-frame.hpp"
#include "widget/tab-frame-item.hpp" #include "widget/tab-frame-item.hpp"
#include "widget/table-view.hpp"
#include "widget/table-view-header.hpp"
#include "widget/table-view-column.hpp"
#include "widget/table-view-item.hpp"
#include "widget/table-view-cell.hpp"
#include "widget/text-edit.hpp" #include "widget/text-edit.hpp"
#include "widget/vertical-scroll-bar.hpp" #include "widget/vertical-scroll-bar.hpp"
#include "widget/vertical-slider.hpp" #include "widget/vertical-slider.hpp"

View File

@ -298,31 +298,31 @@ static auto CALLBACK Shared_windowProc(WindowProc windowProc, HWND hwnd, UINT ms
auto object = (mObject*)GetWindowLongPtr((HWND)header->hwndFrom, GWLP_USERDATA); auto object = (mObject*)GetWindowLongPtr((HWND)header->hwndFrom, GWLP_USERDATA);
if(!object) break; if(!object) break;
#if defined(Hiro_ListView) #if defined(Hiro_TableView)
if(auto listView = dynamic_cast<mListView*>(object)) { if(auto tableView = dynamic_cast<mTableView*>(object)) {
if(header->code == LVN_ITEMACTIVATE) { if(header->code == LVN_ITEMACTIVATE) {
listView->self()->onActivate(lparam); tableView->self()->onActivate(lparam);
break; break;
} }
if(header->code == LVN_ITEMCHANGED) { if(header->code == LVN_ITEMCHANGED) {
listView->self()->onChange(lparam); tableView->self()->onChange(lparam);
break; break;
} }
if(header->code == LVN_COLUMNCLICK) { if(header->code == LVN_COLUMNCLICK) {
if(isWindowCallback) listView->self()->onSort(lparam); if(isWindowCallback) tableView->self()->onSort(lparam);
break; break;
} }
if(header->code == NM_CLICK || header->code == NM_DBLCLK) { if(header->code == NM_CLICK || header->code == NM_DBLCLK) {
//onToggle performs the test to ensure the ListViewItem clicked was checkable //onToggle performs the test to ensure the TableViewItem clicked was checkable
if(isWindowCallback) listView->self()->onToggle(lparam); if(isWindowCallback) tableView->self()->onToggle(lparam);
break; break;
} }
if(header->code == NM_RCLICK) { if(header->code == NM_RCLICK) {
if(isWindowCallback) listView->self()->onContext(lparam); if(isWindowCallback) tableView->self()->onContext(lparam);
break; break;
} }
if(header->code == NM_CUSTOMDRAW) { if(header->code == NM_CUSTOMDRAW) {
return listView->self()->onCustomDraw(lparam); return tableView->self()->onCustomDraw(lparam);
} }
} }
#endif #endif
@ -339,21 +339,21 @@ static auto CALLBACK Shared_windowProc(WindowProc windowProc, HWND hwnd, UINT ms
break; break;
} }
#if defined(Hiro_ListView) #if defined(Hiro_TableView)
case AppMessage::ListView_doPaint: { case AppMessage::TableView_doPaint: {
if(auto listView = (mListView*)lparam) { if(auto tableView = (mTableView*)lparam) {
if(auto self = listView->self()) InvalidateRect(self->hwnd, nullptr, true); if(auto self = tableView->self()) InvalidateRect(self->hwnd, nullptr, true);
} }
break; break;
} }
case AppMessage::ListView_onActivate: { case AppMessage::TableView_onActivate: {
if(auto listView = (mListView*)lparam) listView->doActivate(); if(auto tableView = (mTableView*)lparam) tableView->doActivate();
break; break;
} }
case AppMessage::ListView_onChange: { case AppMessage::TableView_onChange: {
if(auto listView = (mListView*)lparam) listView->doChange(); if(auto tableView = (mTableView*)lparam) tableView->doChange();
} }
#endif #endif

View File

@ -151,7 +151,8 @@ auto pCanvas::_rasterize() -> void {
} }
if(width <= 0 || height <= 0) return; if(width <= 0 || height <= 0) return;
pixels.reallocate(width * height); pixels.reset();
pixels.resize(width * height);
if(auto& icon = state().icon) { if(auto& icon = state().icon) {
memory::copy(pixels.data(), icon.data(), width * height * sizeof(uint32)); memory::copy(pixels.data(), icon.data(), width * height * sizeof(uint32));

View File

@ -1,72 +0,0 @@
#if defined(Hiro_ListView)
namespace hiro {
auto pListViewCell::construct() -> void {
}
auto pListViewCell::destruct() -> void {
}
auto pListViewCell::setAlignment(Alignment alignment) -> void {
}
auto pListViewCell::setBackgroundColor(Color color) -> void {
_repaint();
}
auto pListViewCell::setCheckable(bool checkable) -> void {
_repaint();
}
auto pListViewCell::setChecked(bool checked) -> void {
_repaint();
}
auto pListViewCell::setForegroundColor(Color color) -> void {
_repaint();
}
auto pListViewCell::setIcon(const image& icon) -> void {
_repaint();
}
auto pListViewCell::setText(const string& text) -> void {
_repaint();
}
auto pListViewCell::_parent() -> maybe<pListViewItem&> {
if(auto parent = self().parentListViewItem()) {
if(auto self = parent->self()) return *self;
}
return nothing;
}
auto pListViewCell::_repaint() -> void {
if(auto parent = _parent()) {
if(auto listView = parent->_parent()) {
//ListView uses a custom drawing routine; so we need to tell the control to repaint itself manually
PostMessageOnce(listView->_parentHandle(), AppMessage::ListView_doPaint, 0, (LPARAM)&listView->reference);
}
}
}
auto pListViewCell::_setState() -> void {
if(auto item = _parent()) {
if(auto parent = item->_parent()) {
parent->lock();
wchar_t text[] = L"";
LVITEM lvItem;
lvItem.mask = LVIF_TEXT;
lvItem.iItem = item->self().offset();
lvItem.iSubItem = self().offset();
lvItem.pszText = text;
ListView_SetItem(parent->hwnd, &lvItem);
parent->unlock();
}
}
}
}
#endif

View File

@ -1,18 +0,0 @@
#if defined(Hiro_ListView)
namespace hiro {
struct pListViewHeader : pObject {
Declare(ListViewHeader, Object)
auto append(sListViewColumn column) -> void;
auto remove(sListViewColumn column) -> void;
auto setVisible(bool visible) -> void override;
auto _parent() -> maybe<pListView&>;
auto _setState() -> void;
};
}
#endif

View File

@ -0,0 +1,72 @@
#if defined(Hiro_TableView)
namespace hiro {
auto pTableViewCell::construct() -> void {
}
auto pTableViewCell::destruct() -> void {
}
auto pTableViewCell::setAlignment(Alignment alignment) -> void {
}
auto pTableViewCell::setBackgroundColor(Color color) -> void {
_repaint();
}
auto pTableViewCell::setCheckable(bool checkable) -> void {
_repaint();
}
auto pTableViewCell::setChecked(bool checked) -> void {
_repaint();
}
auto pTableViewCell::setForegroundColor(Color color) -> void {
_repaint();
}
auto pTableViewCell::setIcon(const image& icon) -> void {
_repaint();
}
auto pTableViewCell::setText(const string& text) -> void {
_repaint();
}
auto pTableViewCell::_parent() -> maybe<pTableViewItem&> {
if(auto parent = self().parentTableViewItem()) {
if(auto self = parent->self()) return *self;
}
return nothing;
}
auto pTableViewCell::_repaint() -> void {
if(auto parent = _parent()) {
if(auto tableView = parent->_parent()) {
//TableView uses a custom drawing routine; so we need to tell the control to repaint itself manually
PostMessageOnce(tableView->_parentHandle(), AppMessage::TableView_doPaint, 0, (LPARAM)&tableView->reference);
}
}
}
auto pTableViewCell::_setState() -> void {
if(auto item = _parent()) {
if(auto parent = item->_parent()) {
parent->lock();
wchar_t text[] = L"";
LVITEM lvItem;
lvItem.mask = LVIF_TEXT;
lvItem.iItem = item->self().offset();
lvItem.iSubItem = self().offset();
lvItem.pszText = text;
ListView_SetItem(parent->hwnd, &lvItem);
parent->unlock();
}
}
}
}
#endif

View File

@ -1,9 +1,9 @@
#if defined(Hiro_ListView) #if defined(Hiro_TableView)
namespace hiro { namespace hiro {
struct pListViewCell : pObject { struct pTableViewCell : pObject {
Declare(ListViewCell, Object) Declare(TableViewCell, Object)
auto setAlignment(Alignment alignment) -> void; auto setAlignment(Alignment alignment) -> void;
auto setBackgroundColor(Color color) -> void; auto setBackgroundColor(Color color) -> void;
@ -13,7 +13,7 @@ struct pListViewCell : pObject {
auto setIcon(const image& icon) -> void; auto setIcon(const image& icon) -> void;
auto setText(const string& text) -> void; auto setText(const string& text) -> void;
auto _parent() -> maybe<pListViewItem&>; auto _parent() -> maybe<pTableViewItem&>;
auto _repaint() -> void; auto _repaint() -> void;
auto _setState() -> void; auto _setState() -> void;
}; };

View File

@ -1,8 +1,8 @@
#if defined(Hiro_ListView) #if defined(Hiro_TableView)
namespace hiro { namespace hiro {
auto pListViewColumn::construct() -> void { auto pTableViewColumn::construct() -> void {
if(auto grandparent = _grandparent()) { if(auto grandparent = _grandparent()) {
grandparent->lock(); grandparent->lock();
wchar_t text[] = L""; wchar_t text[] = L"";
@ -17,7 +17,7 @@ auto pListViewColumn::construct() -> void {
} }
} }
auto pListViewColumn::destruct() -> void { auto pTableViewColumn::destruct() -> void {
if(auto grandparent = _grandparent()) { if(auto grandparent = _grandparent()) {
grandparent->lock(); grandparent->lock();
ListView_DeleteColumn(grandparent->hwnd, self().offset()); ListView_DeleteColumn(grandparent->hwnd, self().offset());
@ -25,65 +25,65 @@ auto pListViewColumn::destruct() -> void {
} }
} }
auto pListViewColumn::setActive() -> void { auto pTableViewColumn::setActive() -> void {
//unsupported //unsupported
} }
auto pListViewColumn::setAlignment(Alignment alignment) -> void { auto pTableViewColumn::setAlignment(Alignment alignment) -> void {
} }
auto pListViewColumn::setBackgroundColor(Color color) -> void { auto pTableViewColumn::setBackgroundColor(Color color) -> void {
} }
auto pListViewColumn::setEditable(bool editable) -> void { auto pTableViewColumn::setEditable(bool editable) -> void {
//unsupported //unsupported
} }
auto pListViewColumn::setExpandable(bool expandable) -> void { auto pTableViewColumn::setExpandable(bool expandable) -> void {
} }
auto pListViewColumn::setForegroundColor(Color color) -> void { auto pTableViewColumn::setForegroundColor(Color color) -> void {
} }
auto pListViewColumn::setHorizontalAlignment(double alignment) -> void { auto pTableViewColumn::setHorizontalAlignment(double alignment) -> void {
_setState(); _setState();
} }
auto pListViewColumn::setIcon(const image& icon) -> void { auto pTableViewColumn::setIcon(const image& icon) -> void {
_setState(); _setState();
} }
auto pListViewColumn::setResizable(bool resizable) -> void { auto pTableViewColumn::setResizable(bool resizable) -> void {
_setState(); _setState();
} }
auto pListViewColumn::setSortable(bool sortable) -> void { auto pTableViewColumn::setSortable(bool sortable) -> void {
} }
auto pListViewColumn::setText(const string& text) -> void { auto pTableViewColumn::setText(const string& text) -> void {
_setState(); _setState();
} }
auto pListViewColumn::setVerticalAlignment(double alignment) -> void { auto pTableViewColumn::setVerticalAlignment(double alignment) -> void {
} }
auto pListViewColumn::setWidth(signed width) -> void { auto pTableViewColumn::setWidth(signed width) -> void {
_setState(); _setState();
} }
auto pListViewColumn::_grandparent() -> maybe<pListView&> { auto pTableViewColumn::_grandparent() -> maybe<pTableView&> {
if(auto parent = _parent()) return parent->_parent(); if(auto parent = _parent()) return parent->_parent();
return nothing; return nothing;
} }
auto pListViewColumn::_parent() -> maybe<pListViewHeader&> { auto pTableViewColumn::_parent() -> maybe<pTableViewHeader&> {
if(auto parent = self().parentListViewHeader()) { if(auto parent = self().parentTableViewHeader()) {
if(auto self = parent->self()) return *self; if(auto self = parent->self()) return *self;
} }
return nothing; return nothing;
} }
auto pListViewColumn::_setState() -> void { auto pTableViewColumn::_setState() -> void {
if(auto grandparent = _grandparent()) { if(auto grandparent = _grandparent()) {
grandparent->lock(); grandparent->lock();
grandparent->_setIcons(); grandparent->_setIcons();

View File

@ -1,9 +1,9 @@
#if defined(Hiro_ListView) #if defined(Hiro_TableView)
namespace hiro { namespace hiro {
struct pListViewColumn : pObject { struct pTableViewColumn : pObject {
Declare(ListViewColumn, Object) Declare(TableViewColumn, Object)
auto setActive() -> void; auto setActive() -> void;
auto setAlignment(Alignment alignment) -> void; auto setAlignment(Alignment alignment) -> void;
@ -19,11 +19,11 @@ struct pListViewColumn : pObject {
auto setVerticalAlignment(double alignment) -> void; auto setVerticalAlignment(double alignment) -> void;
auto setWidth(signed width) -> void; auto setWidth(signed width) -> void;
auto _grandparent() -> maybe<pListView&>; auto _grandparent() -> maybe<pTableView&>;
auto _parent() -> maybe<pListViewHeader&>; auto _parent() -> maybe<pTableViewHeader&>;
auto _setState() -> void; auto _setState() -> void;
signed _width = 128; //computed width (via ListView::resizeColumns) signed _width = 128; //computed width (via TableView::resizeColumns)
}; };
} }

View File

@ -1,32 +1,32 @@
#if defined(Hiro_ListView) #if defined(Hiro_TableView)
namespace hiro { namespace hiro {
auto pListViewHeader::construct() -> void { auto pTableViewHeader::construct() -> void {
_setState(); _setState();
} }
auto pListViewHeader::destruct() -> void { auto pTableViewHeader::destruct() -> void {
} }
auto pListViewHeader::append(sListViewColumn column) -> void { auto pTableViewHeader::append(sTableViewColumn column) -> void {
} }
auto pListViewHeader::remove(sListViewColumn column) -> void { auto pTableViewHeader::remove(sTableViewColumn column) -> void {
} }
auto pListViewHeader::setVisible(bool visible) -> void { auto pTableViewHeader::setVisible(bool visible) -> void {
_setState(); _setState();
} }
auto pListViewHeader::_parent() -> maybe<pListView&> { auto pTableViewHeader::_parent() -> maybe<pTableView&> {
if(auto parent = self().parentListView()) { if(auto parent = self().parentTableView()) {
if(auto self = parent->self()) return *self; if(auto self = parent->self()) return *self;
} }
return nothing; return nothing;
} }
auto pListViewHeader::_setState() -> void { auto pTableViewHeader::_setState() -> void {
if(auto parent = _parent()) { if(auto parent = _parent()) {
auto style = GetWindowLong(parent->hwnd, GWL_STYLE); auto style = GetWindowLong(parent->hwnd, GWL_STYLE);
self().visible() ? style &=~ LVS_NOCOLUMNHEADER : style |= LVS_NOCOLUMNHEADER; self().visible() ? style &=~ LVS_NOCOLUMNHEADER : style |= LVS_NOCOLUMNHEADER;

View File

@ -0,0 +1,18 @@
#if defined(Hiro_TableView)
namespace hiro {
struct pTableViewHeader : pObject {
Declare(TableViewHeader, Object)
auto append(sTableViewColumn column) -> void;
auto remove(sTableViewColumn column) -> void;
auto setVisible(bool visible) -> void override;
auto _parent() -> maybe<pTableView&>;
auto _setState() -> void;
};
}
#endif

View File

@ -1,8 +1,8 @@
#if defined(Hiro_ListView) #if defined(Hiro_TableView)
namespace hiro { namespace hiro {
auto pListViewItem::construct() -> void { auto pTableViewItem::construct() -> void {
if(auto parent = _parent()) { if(auto parent = _parent()) {
parent->lock(); parent->lock();
wchar_t text[] = L""; wchar_t text[] = L"";
@ -17,7 +17,7 @@ auto pListViewItem::construct() -> void {
} }
} }
auto pListViewItem::destruct() -> void { auto pTableViewItem::destruct() -> void {
if(auto parent = _parent()) { if(auto parent = _parent()) {
parent->lock(); parent->lock();
ListView_DeleteItem(parent->hwnd, self().offset()); ListView_DeleteItem(parent->hwnd, self().offset());
@ -25,19 +25,19 @@ auto pListViewItem::destruct() -> void {
} }
} }
auto pListViewItem::append(sListViewCell cell) -> void { auto pTableViewItem::append(sTableViewCell cell) -> void {
} }
auto pListViewItem::remove(sListViewCell cell) -> void { auto pTableViewItem::remove(sTableViewCell cell) -> void {
} }
auto pListViewItem::setAlignment(Alignment alignment) -> void { auto pTableViewItem::setAlignment(Alignment alignment) -> void {
} }
auto pListViewItem::setBackgroundColor(Color color) -> void { auto pTableViewItem::setBackgroundColor(Color color) -> void {
} }
auto pListViewItem::setFocused() -> void { auto pTableViewItem::setFocused() -> void {
if(auto parent = _parent()) { if(auto parent = _parent()) {
parent->lock(); parent->lock();
ListView_SetItemState(parent->hwnd, self().offset(), LVIS_FOCUSED, LVIS_FOCUSED); ListView_SetItemState(parent->hwnd, self().offset(), LVIS_FOCUSED, LVIS_FOCUSED);
@ -45,21 +45,21 @@ auto pListViewItem::setFocused() -> void {
} }
} }
auto pListViewItem::setForegroundColor(Color color) -> void { auto pTableViewItem::setForegroundColor(Color color) -> void {
} }
auto pListViewItem::setSelected(bool selected) -> void { auto pTableViewItem::setSelected(bool selected) -> void {
_setState(); _setState();
} }
auto pListViewItem::_parent() -> maybe<pListView&> { auto pTableViewItem::_parent() -> maybe<pTableView&> {
if(auto parent = self().parentListView()) { if(auto parent = self().parentTableView()) {
if(auto self = parent->self()) return *self; if(auto self = parent->self()) return *self;
} }
return nothing; return nothing;
} }
auto pListViewItem::_setState() -> void { auto pTableViewItem::_setState() -> void {
if(auto parent = _parent()) { if(auto parent = _parent()) {
parent->lock(); parent->lock();
ListView_SetItemState(parent->hwnd, self().offset(), state().selected ? LVIS_SELECTED : 0, LVIS_SELECTED); ListView_SetItemState(parent->hwnd, self().offset(), state().selected ? LVIS_SELECTED : 0, LVIS_SELECTED);

Some files were not shown because too many files have changed in this diff Show More