home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / intrvews / tut-code.lha / tut-code / patch / main.c < prev   
Encoding:
C/C++ Source or Header  |  1992-01-07  |  1.8 KB  |  88 lines

  1. #include <IV-look/kit.h>
  2. #include <InterViews/background.h>
  3. #include <InterViews/box.h>
  4. #include <InterViews/deck.h>
  5. #include <InterViews/label.h>
  6. #include <InterViews/glue.h>
  7. #include <InterViews/patch.h>
  8. #include <InterViews/place.h>
  9. #include <InterViews/session.h>
  10. #include <InterViews/style.h>
  11. #include <InterViews/window.h>
  12.  
  13. class App {
  14. public:
  15.     Glyph* make(Style*);
  16.     void next();
  17.     void prev();
  18. private:
  19.     Deck* deck_;
  20.     Patch* patch_;
  21.  
  22.     void flip(GlyphIndex);
  23. };
  24.  
  25. declare(ActionCallback,App)
  26. implement(ActionCallback,App)
  27.  
  28. Glyph* App::make(Style* s) {
  29.     const Font* f = s->font();
  30.     const Color* fg = s->foreground();
  31.     deck_ = new Deck;
  32.     deck_->append(new Label("Hi mom!", f, fg));
  33.     deck_->append(new Label("Big Bird", f, fg));
  34.     deck_->append(new Label("Oscar", f, fg));
  35.     deck_->flip_to(0);
  36.     patch_ = new Patch(deck_);
  37.     return patch_;
  38. }
  39.  
  40. void App::next() {
  41.     GlyphIndex cur = deck_->card() + 1;
  42.     flip(cur == deck_->count() ? 0 : cur);
  43. }
  44.  
  45. void App::prev() {
  46.     GlyphIndex cur = deck_->card() - 1;
  47.     flip(cur == -1 ? deck_->count() - 1 : cur);
  48. }
  49.  
  50. void App::flip(GlyphIndex cur) {
  51.     deck_->flip_to(cur);
  52.     patch_->redraw();
  53.     patch_->reallocate();
  54.     patch_->redraw();
  55. }
  56.  
  57. int main(int argc, char** argv) {
  58.     Session* session = new Session("Himom", argc, argv);
  59.     Style* style = session->style();
  60.     Kit* kit = Kit::instance();
  61.     App* a = new App;
  62.     session->run_window(
  63.     new ApplicationWindow(
  64.         new Background(
  65.         new Margin(
  66.             new TBBox(
  67.             new VCenter(a->make(style), 1.0),
  68.             new VGlue(5.0),
  69.             new LRBox(
  70.                 kit->simple_push_button(
  71.                 "Next", style,
  72.                 new ActionCallback(App)(a, &App::next)
  73.                 ),
  74.                 new HGlue(10.0),
  75.                 kit->simple_push_button(
  76.                 "Previous", style,
  77.                 new ActionCallback(App)(a, &App::prev)
  78.                 )
  79.             )
  80.             ),
  81.             10.0
  82.         ),
  83.         style->flat()
  84.         )
  85.     )
  86.     );
  87. }
  88.