Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/woip/app/WikiApp.m
blob: 6509d264c0782684e7c32a700b0edb4198149c27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#import <CoreFoundation/CoreFoundation.h>
#import <Foundation/Foundation.h>
#import <UIKit/CDStructures.h>
#import <UIKit/UIPushButton.h>
#import <UIKit/UIThreePartButton.h>
#import <UIKit/UINavigationBar.h>
#import <UIKit/UIWindow.h>
#import <UIKit/UIView-Hierarchy.h>
#import <UIKit/UIHardware.h>

#import "WebKitView.h"
#import "WikiApp.h"

@implementation WikiApp

-(UINavigationBar *) createNavBar: (struct CGRect) rect {
  struct CGSize s = [UINavigationBar defaultSize];
  UINavigationBar *bar = [[UINavigationBar alloc] 
                            initWithFrame: CGRectMake(0, 0, s.width, s.height)];
  [bar setDelegate: self];
  [bar enableAnimation];

  return bar;
}

-(void) updateNavBar {
  switch(currentView) {
    case ARTICLE_VIEW:
      [navBar showButtonsWithLeftTitle: @"Search" rightTitle: NULL leftBack: YES];
      break;
    case SEARCH_VIEW:
      [navBar showButtonsWithLeftTitle: NULL rightTitle: @"Article"];
      break;
  }
}

-(void) switchToArticle {
  currentView = ARTICLE_VIEW;
  [self updateNavBar];
  [tf hide];
  [contentView transition: 1 toView: aview];
}

-(void) switchToSearch {
  currentView = SEARCH_VIEW;
  [self updateNavBar];
  [contentView transition: 2 toView: sview];
  [tf show];
}

-(void) navigationBar: (UINavigationBar *) bar buttonClicked: (int) button {
  NSLog(@"Button clicked: %d", button);

  switch(button) {
    case 0:
      [self switchToArticle];
      break;
    case 1:
      [self switchToSearch];
      break;
  }
}

-(void) logText: (id) not {
  NSString *str = [[not object] text];
  NSLog(@"text changed: %@", not);
  NSLog(@"text is now '%@'", str);
 
  if(str != nil)
    [sview setNeedle: str];
}

-(void) createSearchField {
  tf = [[SearchBar alloc] initWithFrame: (CGRectMake(5, 6, 240, 30))];

  [[NSNotificationCenter defaultCenter]
    addObserver: self
    selector: @selector(logText:)
    name: UITextFieldTextDidChangeNotification 
    object: tf];

  [navBar addSubview: tf];
}

-(void) createArticleView: (struct CGRect) r {
  aview = [[ArticleView alloc] initWithFrame: r];
}

-(void) createSearchView: (struct CGRect) r {
  sview = [[SearchView alloc] initWithFrame: r];
  [sview setParent: self];
}

-(void) setupUI {
  currentView = SEARCH_VIEW;

  rect = [UIHardware fullScreenApplicationContentRect];
  rect.origin.x = rect.origin.y = 0.0f;

  window = [[UIWindow alloc] initWithContentRect: [UIHardware fullScreenApplicationContentRect]];

  mainView = [[UITransitionView alloc] initWithFrame: rect];

  CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
  float bgColor[4] = {0.2, 0.2, 0.2, 1};
  CGColorRef bgRef = CGColorCreate(colorSpace, bgColor);
  [mainView setBackgroundColor: bgRef];

  navBar = [self createNavBar: rect];
  [mainView addSubview: navBar];

  struct CGSize s = [UINavigationBar defaultSize];
  struct CGRect r = CGRectMake(0, 0, rect.size.width, rect.size.height - s.height);
  contentView = [[UITransitionView alloc] 
                  initWithFrame: CGRectMake(0, s.height, rect.size.width, rect.size.height - s.height)];
  [mainView addSubview: contentView];

  [self createSearchField];

  [self updateNavBar];
  [window orderFront: self];
  [window makeKey: self];
  [window _setHidden: NO];
  [window setContentView: mainView];

  [self createSearchView: r];
  [self createArticleView: r];
  [sview setArticleView: aview];
  [contentView addSubview: sview];
}

- (void) applicationDidFinishLaunching: (id) unused
{
  [self setupUI];

  [aview updateHTML: @"<html><body></body></html>"];
}

@end