summaryrefslogtreecommitdiffstats
path: root/Window.cpp
blob: af0357befc5f62c26721d65e2d457b40f30f784d (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
#include "Window.h"
#include "WindowManager.h"


gboolean Window::deleteEvent(GtkWidget *widget, GdkEvent *event, Window *window) {
  gtk_widget_hide(widget);
  
  window->manager->windowClosed(window);
  
  return TRUE;
}

Window::Window(GdkGLConfig *glconfig, WindowManager *manager)
  : uiManager(this), editor(this), drawer(this, glconfig), sidebar(&editor),
    fileManager(this)
{
  this->manager = manager;
  
  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_default_size(GTK_WINDOW(window), 640, 480);
  g_signal_connect(G_OBJECT(window), "delete-event", G_CALLBACK(deleteEvent), this);
  
  GtkWidget *vbox = gtk_vbox_new(FALSE, 0);
  gtk_container_add(GTK_CONTAINER(window), vbox);
  
  gtk_box_pack_start(GTK_BOX(vbox), uiManager.getMenu(), FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(vbox), uiManager.getToolbar(), FALSE, FALSE, 0);
  
  gtk_window_add_accel_group(GTK_WINDOW(window), uiManager.getAccels());
  
  GtkWidget *hPaned = gtk_hpaned_new();
  gtk_box_pack_end(GTK_BOX(vbox), hPaned, TRUE, TRUE, 0);
  
  gtk_paned_pack1(GTK_PANED(hPaned), drawer.getWidget(), TRUE, TRUE);
  
  gtk_paned_pack2(GTK_PANED(hPaned), sidebar.getWidget(), FALSE, TRUE);
  sidebar.update();
  
  gtk_widget_show_all(vbox);
}

Window::~Window() {
  gtk_widget_destroy(window);
}

void Window::show() {
  gtk_widget_show(window);
}

void Window::update() {
  drawer.update();
  sidebar.update();
}

void Window::handleAction(UIManager::Action action) {
  switch(action) {
    case UIManager::SAVE:
      fileManager.save(GTK_WINDOW(window));
      break;
      
    case UIManager::SAVE_AS:
      fileManager.saveAs(GTK_WINDOW(window));
      break;
      
    case UIManager::ZOOM_IN:
      drawer.zoom(2);
      break;
      
    case UIManager::ZOOM_OUT:
      drawer.zoom(-2);
  }
}