frame.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #if defined(Hiro_Frame)
  2. @implementation CocoaFrame : NSBox
  3. -(id) initWith:(hiro::mFrame&)frameReference {
  4. if(self = [super initWithFrame:NSMakeRect(0, 0, 0, 0)]) {
  5. frame = &frameReference;
  6. [self setTitle:@""];
  7. }
  8. return self;
  9. }
  10. @end
  11. namespace hiro {
  12. auto pFrame::construct() -> void {
  13. @autoreleasepool {
  14. cocoaView = cocoaFrame = [[CocoaFrame alloc] initWith:self()];
  15. pWidget::construct();
  16. setText(state().text);
  17. }
  18. }
  19. auto pFrame::destruct() -> void {
  20. @autoreleasepool {
  21. [cocoaView removeFromSuperview];
  22. [cocoaView release];
  23. }
  24. }
  25. auto pFrame::append(sSizable sizable) -> void {
  26. }
  27. auto pFrame::remove(sSizable sizable) -> void {
  28. }
  29. auto pFrame::setEnabled(bool enabled) -> void {
  30. pWidget::setEnabled(enabled);
  31. if(auto& sizable = state().sizable) sizable->setEnabled(enabled);
  32. }
  33. auto pFrame::setFont(const Font& font) -> void {
  34. @autoreleasepool {
  35. [cocoaView setTitleFont:pFont::create(font)];
  36. }
  37. if(auto& sizable = state().sizable) sizable->setFont(font);
  38. }
  39. auto pFrame::setGeometry(Geometry geometry) -> void {
  40. bool empty = !state().text;
  41. Size size = pFont::size(self().font(true), state().text);
  42. pWidget::setGeometry({
  43. geometry.x() - 3, geometry.y() - (empty ? size.height() - 2 : 1),
  44. geometry.width() + 6, geometry.height() + (empty ? size.height() + 2 : 5)
  45. });
  46. if(auto& sizable = state().sizable) {
  47. sizable->setGeometry({
  48. geometry.x() + 1, geometry.y() + (empty ? 1 : size.height() - 2),
  49. geometry.width() - 2, geometry.height() - (empty ? 1 : size.height() - 1)
  50. });
  51. }
  52. }
  53. auto pFrame::setText(const string& text) -> void {
  54. @autoreleasepool {
  55. [cocoaView setTitle:[NSString stringWithUTF8String:text]];
  56. }
  57. }
  58. auto pFrame::setVisible(bool visible) -> void {
  59. pWidget::setVisible(visible);
  60. if(auto& sizable = state().sizable) sizable->setVisible(visible);
  61. }
  62. }
  63. #endif