예제 #1
0
파일: dialog.c 프로젝트: posva/msnake
void enter_string(char *title, char *content, int lines, int posy, int posx, char *buf, int length) {
  WINDOW *win = create_dialog_window(title);
  int i;
  int pos = 0;
  int ch = 0;

  //print out the content
  for(i = 0; i < lines; i++) {
    mvwprintw(win, i + 3, 1, "%s", &content[i * CONTENT_WIDTH]);
  }

  // - let the user input a string
  // read a char until we receive a line break 
  while((ch = mvwgetch(win, posy, posx + pos)) && ch != '\n') {
    // prevent a buffer overflow
    if(ch == KEY_BACKSPACE || ch == 127) {
      // delete the character at the current position from the screen and the buffer
      buf[pos] = '\0';
      mvwprintw(win, posy, posx + pos, " ");

      // go 1 back in the buffer but not under 0
      if(pos > 0) {
        pos--;
      }

      // delete the last typed character from the screen and the buffer
      mvwprintw(win, posy, posx + pos, " ");
      buf[pos] = '\0';
    
    // check if it is a letter
    } else if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {
      // print the character to the screen
      mvwprintw(win, posy, posx + pos, "%c", ch);

      // write the typed key into the buffer
      buf[pos] = ch; 
      // move forward in the buffer but not over the length - 1
      if(pos < length - 1) {
        pos++;
      }
    }
  }

  buf[length - 1] = '\0';
  // delete the dialog
  delwin(win);
}
예제 #2
0
파일: dialog.c 프로젝트: posva/msnake
// creates a simple dialog with content, you can press 'enter' to close the dialog
int create_enter_dialog(const char *title, const char *contents, int lines) {
  WINDOW *win = create_dialog_window(title);
  int i;

  // insert the stuff in "contents" into the dialog
  for(i = 0; i < lines; i++) {
    mvwprintw(win, i + 3, 1, "%s", &contents[i * CONTENT_WIDTH]);
  }

  // display the dialog
  wrefresh(win);

  // wait for 'enter'
  wait_return(win);
  
  // free the allocated memory of the window
  delwin(win);
  return 0;
}
예제 #3
0
파일: dialog.c 프로젝트: posva/msnake
// creates a dialog with menu entries, you can press numbers to select a menu entry and close the dialog
int create_numbered_dialog(const char *title, const char *contents, int lines) {
  WINDOW *win = create_dialog_window(title);
  int i, ch, number = 0;

  // insert menu entries into the dialog
  for(i = 0; i < lines; i++) {
    mvwprintw(win, i + 3, 1, &contents[i * CONTENT_WIDTH], i + 1);
  }

  // display the dialog
  wrefresh(win);

  // wait for some input
  while((ch = wgetch(win))) {
    // error? begin again.
    if(ch == ERR) continue;

    // select the first menu entry if enter is pressed
    if(ch == '\n') ch = '1';
    // a number pressed?
    if(ch >= '0' && ch <= '9') {
      number = ch - '0';
      // prevent from handling numbers which are > than the number of menu entries
      if(ch - '0' <= lines) {
        // get out of the loop
        break;
      }
    }
  }

  // delete the window
  delwin(win);

  // return the number pressed
  return number;
}
예제 #4
0
GtkWindow* create_modal_dialog_window(GtkWindow* parent, const char* title, ModalDialog& dialog, int default_w, int default_h)
{
  return create_dialog_window(parent, title, G_CALLBACK(modal_dialog_delete), &dialog, default_w, default_h);
}
예제 #5
0
파일: build.cpp 프로젝트: raynorpat/cake
GtkWindow* BuildMenuDialog_construct(ModalDialog& modal, ProjectList& projectList)
{
  GtkWindow* window = create_dialog_window(MainFrame_getWindow(), "Build Menu", G_CALLBACK(dialog_delete_callback), &modal, -1, 400);

  GtkWidget* buildView = 0;

  {
    GtkTable* table1 = create_dialog_table(2, 2, 4, 4, 4);
    gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(table1));
    {
      GtkVBox* vbox = create_dialog_vbox(4);
      gtk_table_attach(table1, GTK_WIDGET(vbox), 1, 2, 0, 1,
                        (GtkAttachOptions) (GTK_FILL),
                        (GtkAttachOptions) (GTK_FILL), 0, 0);
      {
        GtkButton* button = create_dialog_button("OK", G_CALLBACK(dialog_button_ok), &modal);
        gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(button), FALSE, FALSE, 0);
      }
      {
        GtkButton* button = create_dialog_button("Cancel", G_CALLBACK(dialog_button_cancel), &modal);
        gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(button), FALSE, FALSE, 0);
      }
    }
    {
      GtkFrame* frame = create_dialog_frame("Build menu");
      gtk_table_attach(table1, GTK_WIDGET(frame), 0, 1, 0, 1,
                        (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                        (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0);
      {
        GtkScrolledWindow* scr = create_scrolled_window(GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC, 4);
        gtk_container_add(GTK_CONTAINER(frame), GTK_WIDGET(scr));

        {
          GtkListStore* store = gtk_list_store_new(1, G_TYPE_STRING);

          GtkWidget* view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
          gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);

          GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
          object_set_boolean_property(G_OBJECT(renderer), "editable", TRUE);
          g_signal_connect(renderer, "edited", G_CALLBACK(project_cell_edited), &projectList);
 
          GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes("", renderer, "text", 0, 0);
          gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);

          GtkTreeSelection* selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(view));
          gtk_tree_selection_set_mode(selection, GTK_SELECTION_BROWSE);

          gtk_widget_show(view);

          buildView = view;
          projectList.m_store = store;
          gtk_container_add(GTK_CONTAINER (scr), view);
  
          g_signal_connect(G_OBJECT(view), "key_press_event", G_CALLBACK(project_key_press), &projectList);

          g_object_unref(G_OBJECT(store));
        }
      }
    }
    {
      GtkFrame* frame = create_dialog_frame("Commandline");
      gtk_table_attach(table1, GTK_WIDGET(frame), 0, 1, 1, 2,
                        (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                        (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0);
      {
        GtkScrolledWindow* scr = create_scrolled_window(GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC, 4);
        gtk_container_add(GTK_CONTAINER(frame), GTK_WIDGET(scr));

        {
          GtkListStore* store = gtk_list_store_new(1, G_TYPE_STRING);

          GtkWidget* view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
          gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);

          GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
          object_set_boolean_property(G_OBJECT(renderer), "editable", TRUE);
          g_signal_connect(renderer, "edited", G_CALLBACK(commands_cell_edited), store);
 
          GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes("", renderer, "text", 0, 0);
          gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);

          GtkTreeSelection* selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(view));
          gtk_tree_selection_set_mode(selection, GTK_SELECTION_BROWSE);

          gtk_widget_show(view);

          gtk_container_add(GTK_CONTAINER (scr), view);
  
          g_object_unref(G_OBJECT(store));

          g_signal_connect(G_OBJECT(view), "key_press_event", G_CALLBACK(commands_key_press), store);
         
          g_signal_connect(G_OBJECT(gtk_tree_view_get_selection(GTK_TREE_VIEW(buildView))), "changed", G_CALLBACK(project_selection_changed), store);
        }
      }
    }
  }

  BSPCommandList_Construct(projectList.m_store, g_build_project);

  return window;
}