📄 getipdlg.c
字号:
/* * * Copyright (C) 2003 Xiangbin Lee <honeycombs@sina.com> <honeycombs@263.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation. */ #include "getipdlg.h"/*---------------- dialog get ip ---------------*//*1.dialog preview: ______________________________________________________/v| IP input dialog: _ X \--------------------------------------------------------| Please input ip address: || ______ ______ ______ ______ || |______| . |______| . |______| . |______| || |-------------------------------------------------------| __________ __________ || | OK | | Cancle | || ---------- ---------- |-------------------------------------------------------2.main gtk ctrl relations : +vbox |+ipframe | |+hbbox | |-input(ip1) | |-label('.') | |-input(ip2) | |-label('.') | |-input(ip3) | |-label('.') | |-input(ip4) | |+hbbox |-button OK |-button Cancle */void ipdialog_ondestroy(GtkWidget *widget){ }void ipdialog_destroy(IPDLG_PARAM *lparam){ /* check param*/ if((lparam!=NULL)&&(lparam->regsignal==GTK_WIDGET_REG)) { if(lparam->userfun!=NULL) lparam->userfun(lparam,lparam->fundata); gtk_grab_remove(lparam->window); gtk_widget_destroy(lparam->window); free(lparam); }}void ipdialog_click_ok(GtkWidget *widget,IPDLG_PARAM *lparam){ if((lparam!=NULL)&&(lparam->regsignal==GTK_WIDGET_REG)) { guchar ips[5]; gchar *itemsg; lparam->ifsetip=1; itemsg=(gchar *)gtk_entry_get_text(GTK_ENTRY(lparam->text_ip1)); ips[0]=(guchar)atoi(itemsg); itemsg=(gchar *)gtk_entry_get_text(GTK_ENTRY(lparam->text_ip2)); ips[1]=(guchar)atoi(itemsg); itemsg=(gchar *)gtk_entry_get_text(GTK_ENTRY(lparam->text_ip3)); ips[2]=(guchar)atoi(itemsg); itemsg=(gchar *)gtk_entry_get_text(GTK_ENTRY(lparam->text_ip4)); ips[3]=(guchar)atoi(itemsg); lparam->ip=(ips[0]<<24)|(ips[1]<<16)|(ips[2]<<8)|(ips[3]); sprintf(lparam->ips,"%d.%d.%d.%d",ips[0],ips[1],ips[2],ips[3]); ipdialog_destroy(lparam); }}void ipdialog_click_cancle(GtkWidget *widget,IPDLG_PARAM *lparam){ if(lparam!=NULL) { lparam->ip=0; lparam->ifsetip=0; memset(lparam->ips,0,12); ipdialog_destroy(lparam); }}gulong ipdialog_getip(IPDLG_PARAM *lparam, gchar *ips){ if(lparam==NULL||lparam->regsignal!=GTK_WIDGET_REG) return 0; if(ips!=NULL) strcpy(ips,lparam->ips); return lparam->ip; }IPDLG_PARAM* ipdialog_new(void (*userfun)(IPDLG_PARAM*, gpointer ), gpointer fundata){ GtkWidget *hWin, *text_ip, *vbox, *hbbox, *ipframe, *label, *button; IPDLG_PARAM* lparam=malloc(sizeof(IPDLG_PARAM)); memset(lparam,0,sizeof(IPDLG_PARAM)); lparam->regsignal=GTK_WIDGET_REG; lparam->userfun=userfun; lparam->fundata=fundata; /* Create a new window */ hWin = gtk_window_new (GTK_WINDOW_TOPLEVEL); lparam->window=hWin; gtk_window_set_title (GTK_WINDOW (hWin), "IP Dialog"); /* Here we connect the "destroy" event to a signal handler */ gtk_window_set_position(GTK_WINDOW(hWin),GTK_WIN_POS_CENTER); g_signal_connect(GTK_OBJECT(hWin), "delete_event", GTK_SIGNAL_FUNC(ipdialog_ondestroy), GTK_OBJECT(hWin)); gtk_grab_add(hWin); /* Sets the border width of the window. */ gtk_container_set_border_width (GTK_CONTAINER(hWin), 10); /* ------------------- add extra code here --------------------- */ vbox=gtk_vbox_new (FALSE, 0); gtk_container_set_border_width (GTK_CONTAINER (vbox), 1); gtk_container_add (GTK_CONTAINER (hWin), vbox); /* create ip frame and text to vbox */ // insert ipframe to vbox ipframe=gtk_frame_new("Please input internet address:"); gtk_box_pack_start (GTK_BOX (vbox),ipframe, TRUE, TRUE, 1); // create box and insert to frame hbbox=gtk_hbox_new(FALSE, 0); gtk_container_set_border_width (GTK_CONTAINER (hbbox), 4); gtk_container_add (GTK_CONTAINER (ipframe), hbbox); // insert new text area and label to button box text_ip = gtk_entry_new (); gtk_entry_set_max_length (GTK_ENTRY (text_ip), 3); gtk_widget_set_size_request (GTK_WIDGET (text_ip), 40, 22); gtk_entry_set_text (GTK_ENTRY (text_ip), ""); lparam->text_ip1=text_ip; gtk_box_pack_start (GTK_BOX (hbbox),text_ip, TRUE, TRUE, 1); label=gtk_label_new ("."); gtk_box_pack_start (GTK_BOX (hbbox),label, TRUE, TRUE, 1); text_ip = gtk_entry_new (); gtk_entry_set_max_length (GTK_ENTRY (text_ip), 3); gtk_widget_set_size_request (GTK_WIDGET (text_ip), 40, 22); gtk_entry_set_text (GTK_ENTRY (text_ip), ""); lparam->text_ip2=text_ip; gtk_box_pack_start (GTK_BOX (hbbox),text_ip, TRUE, TRUE, 1); label=gtk_label_new ("."); gtk_box_pack_start (GTK_BOX (hbbox),label, TRUE, TRUE, 1); text_ip = gtk_entry_new (); gtk_entry_set_max_length (GTK_ENTRY (text_ip), 3); gtk_widget_set_size_request (GTK_WIDGET (text_ip), 40, 22); gtk_entry_set_text (GTK_ENTRY (text_ip), ""); lparam->text_ip3=text_ip; gtk_box_pack_start (GTK_BOX (hbbox),text_ip, TRUE, TRUE, 1); label=gtk_label_new ("."); gtk_box_pack_start (GTK_BOX (hbbox),label, TRUE, TRUE, 1); text_ip = gtk_entry_new (); gtk_entry_set_max_length (GTK_ENTRY (text_ip), 3); gtk_widget_set_size_request (GTK_WIDGET (text_ip), 40, 22); gtk_entry_set_text (GTK_ENTRY (text_ip), ""); lparam->text_ip4=text_ip; gtk_box_pack_start (GTK_BOX (hbbox),text_ip, TRUE, TRUE, 1); /* create button box for buttons, and insert to main vbox*/ // create button box hbbox=gtk_hbutton_box_new(); gtk_container_set_border_width (GTK_CONTAINER (hbbox), 20); gtk_button_box_set_layout (GTK_BUTTON_BOX (hbbox), GTK_BUTTONBOX_SPREAD); gtk_box_set_spacing (GTK_BOX (hbbox), 20); gtk_box_pack_start (GTK_BOX (vbox),hbbox, TRUE, TRUE, 1); // insert buttons // button OK button=gtk_button_new_from_stock(GTK_STOCK_OK); g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (ipdialog_click_ok), lparam); gtk_container_add (GTK_CONTAINER (hbbox), button); // button Cancle button=gtk_button_new_from_stock(GTK_STOCK_CANCEL); g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (ipdialog_click_cancle), lparam); gtk_container_add (GTK_CONTAINER (hbbox), button); /* ------------------------------------------------------------- */ gtk_widget_show_all(hWin); return lparam;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -