Mercurial > dwindows
comparison dwtest.c @ 191:634625c3239d
Fixes for dw_color_xxxx_set() to accept OS/2 style colors, and fixed a
problem with dw_window_set_font() on notebook controls.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 17 Jan 2003 20:31:06 +0000 |
parents | |
children | d946e329670c |
comparison
equal
deleted
inserted
replaced
190:f4c9fa77136a | 191:634625c3239d |
---|---|
1 #define INCL_DOS | |
2 #define INCL_WIN | |
3 | |
4 #include <stdlib.h> | |
5 #include <string.h> | |
6 #include <stdio.h> | |
7 #include "dw.h" | |
8 | |
9 | |
10 unsigned long flStyle = DW_FCF_SYSMENU | DW_FCF_TITLEBAR | | |
11 DW_FCF_SHELLPOSITION | DW_FCF_TASKLIST | DW_FCF_DLGBORDER; | |
12 | |
13 HWND mainwindow, | |
14 entryfield, | |
15 okbutton, | |
16 cancelbutton, | |
17 lbbox, | |
18 notebookbox, | |
19 notebookbox1, | |
20 notebookbox2, | |
21 notebook, | |
22 stext, | |
23 pagebox, | |
24 textbox1, textbox2, | |
25 buttonbox; | |
26 | |
27 int exit_callback(HWND window, void *data) | |
28 { | |
29 dw_window_destroy((HWND)data); | |
30 exit(0); | |
31 return -1; | |
32 } | |
33 | |
34 int test_callback(HWND window, void *data) | |
35 { | |
36 dw_window_destroy((HWND)data); | |
37 exit(0); | |
38 return -1; | |
39 } | |
40 int browse_callback(HWND window, void *data) | |
41 { | |
42 dw_file_browse("test string", NULL, "c", DW_FILE_OPEN ); | |
43 return 0; | |
44 } | |
45 | |
46 void archive_add(void) | |
47 { | |
48 HWND browsebutton, browsebox; | |
49 | |
50 lbbox = dw_box_new(BOXVERT, 10); | |
51 | |
52 dw_box_pack_start(notebookbox1, lbbox, 150, 70, TRUE, TRUE, 0); | |
53 | |
54 /* Archive Name */ | |
55 stext = dw_text_new("Archive Name", 0); | |
56 | |
57 dw_window_set_style(stext, DW_DT_VCENTER, DW_DT_VCENTER); | |
58 | |
59 dw_box_pack_start(lbbox, stext, 130, 15, TRUE, TRUE, 2); | |
60 | |
61 browsebox = dw_box_new(BOXHORZ, 0); | |
62 | |
63 dw_box_pack_start(lbbox, browsebox, 130, 15, TRUE, TRUE, 0); | |
64 | |
65 entryfield = dw_entryfield_new("", 100L); | |
66 | |
67 dw_box_pack_start(browsebox, entryfield, 100, 15, TRUE, TRUE, 4); | |
68 | |
69 browsebutton = dw_button_new("Browse", 1001L); | |
70 | |
71 dw_box_pack_start(browsebox, browsebutton, 30, 15, TRUE, TRUE, 0); | |
72 | |
73 dw_window_set_color(browsebox, DW_CLR_PALEGRAY, DW_CLR_PALEGRAY); | |
74 dw_window_set_font(browsebutton, "9.WarpSans"); | |
75 dw_window_set_font(stext, "9.WarpSans"); | |
76 dw_window_set_color(stext, DW_CLR_BLACK, DW_CLR_PALEGRAY); | |
77 dw_window_set_font(entryfield, "9.WarpSans"); | |
78 | |
79 /* Archive Description */ | |
80 stext = dw_text_new("Archive Description", 0); | |
81 | |
82 dw_window_set_style(stext, DW_DT_VCENTER, DW_DT_VCENTER); | |
83 | |
84 dw_box_pack_start(lbbox, stext, 130, 15, TRUE, TRUE, 4); | |
85 | |
86 entryfield = dw_entryfield_new("", 100L); | |
87 | |
88 dw_box_pack_start(lbbox, entryfield, 130, 15, TRUE, TRUE, 4); | |
89 | |
90 dw_window_set_font(stext, "9.WarpSans"); | |
91 dw_window_set_color(stext, DW_CLR_BLACK, DW_CLR_PALEGRAY); | |
92 dw_window_set_font(entryfield, "9.WarpSans"); | |
93 | |
94 /* Comments */ | |
95 stext = dw_text_new("Comments", 0); | |
96 | |
97 dw_window_set_style(stext, DW_DT_VCENTER, DW_DT_VCENTER); | |
98 | |
99 dw_box_pack_start(lbbox, stext, 130, 15, TRUE, TRUE, 4); | |
100 | |
101 entryfield = dw_entryfield_new("", 100L); | |
102 | |
103 dw_box_pack_start(lbbox, entryfield, 130, 15, TRUE, TRUE, 4); | |
104 | |
105 dw_window_set_font(stext, "9.WarpSans"); | |
106 dw_window_set_color(stext, DW_CLR_BLACK, DW_CLR_PALEGRAY); | |
107 dw_window_set_font(entryfield, "9.WarpSans"); | |
108 | |
109 /* Buttons */ | |
110 buttonbox = dw_box_new(BOXHORZ, 10); | |
111 | |
112 dw_box_pack_start(lbbox, buttonbox, 140, 210, TRUE, TRUE, 0); | |
113 | |
114 okbutton = dw_button_new("Ok", 1001L); | |
115 | |
116 dw_box_pack_start(buttonbox, okbutton, 130, 30, TRUE, TRUE, 2); | |
117 | |
118 cancelbutton = dw_button_new("Cancel", 1002L); | |
119 | |
120 dw_box_pack_start(buttonbox, cancelbutton, 130, 30, TRUE, TRUE, 2); | |
121 | |
122 /* Set some nice fonts and colors */ | |
123 dw_window_set_color(lbbox, DW_CLR_DARKCYAN, DW_CLR_PALEGRAY); | |
124 dw_window_set_color(buttonbox, DW_CLR_DARKCYAN, DW_CLR_PALEGRAY); | |
125 dw_window_set_color(okbutton, DW_CLR_PALEGRAY, DW_CLR_DARKCYAN); | |
126 dw_window_set_font(okbutton, "9.WarpSans"); | |
127 dw_window_set_font(cancelbutton, "9.WarpSans"); | |
128 | |
129 dw_signal_connect(browsebutton, "clicked", DW_SIGNAL_FUNC(browse_callback), (void *)notebookbox1); | |
130 dw_signal_connect(okbutton, "clicked", DW_SIGNAL_FUNC(test_callback), (void *)notebookbox1); | |
131 dw_signal_connect(cancelbutton, "clicked", DW_SIGNAL_FUNC(test_callback), (void *)notebookbox1); | |
132 } | |
133 | |
134 | |
135 int font_width = 9; | |
136 int font_height=6; | |
137 int rows=100,width1=6,width2=50; | |
138 | |
139 /* This gets called when a part of the graph needs to be repainted. */ | |
140 int text_expose(HWND hwnd, DWExpose *exp, void *data) | |
141 { | |
142 HPIXMAP hpm = (HPIXMAP)data; | |
143 | |
144 dw_pixmap_bitblt(hwnd, NULL, 0, 0, font_width*width1, font_height*rows, NULL, hpm, 0, 0 ); | |
145 } | |
146 | |
147 void text_add(void) | |
148 { | |
149 int i,x,y; | |
150 char buf[10]; | |
151 HPIXMAP text1pm,text2pm; | |
152 | |
153 pagebox = dw_box_new(BOXVERT, 5); | |
154 dw_box_pack_start( notebookbox2, pagebox, 1, 1, TRUE, TRUE, 0); | |
155 | |
156 textbox1 = dw_render_new( 100 ); | |
157 dw_box_pack_start( pagebox, textbox1, font_width*width1, font_height*rows, FALSE, TRUE, 4); | |
158 dw_window_set_font(textbox1, "9.WarpSans"); | |
159 | |
160 textbox2 = dw_render_new( 101 ); | |
161 dw_box_pack_start( pagebox, textbox2, font_width*width2, font_height*rows, TRUE, TRUE, 4); | |
162 dw_window_set_font(textbox2, "9.WarpSans"); | |
163 | |
164 text1pm = dw_pixmap_new( textbox1, font_width*width1, font_height*rows, 32 ); | |
165 text2pm = dw_pixmap_new( textbox2, font_width*width2, font_height*rows, 32 ); | |
166 | |
167 dw_color_foreground_set(DW_CLR_WHITE); | |
168 dw_draw_rect(0, text1pm, TRUE, 0, 0, font_width*width1, font_height*rows); | |
169 dw_draw_rect(0, text2pm, TRUE, 0, 0, font_width*width2, font_height*rows); | |
170 | |
171 dw_window_set_font(textbox1, "9.WarpSans"); | |
172 dw_font_text_extents( NULL, text1pm, "O", &font_width, &font_height ); | |
173 dw_messagebox("DWTest", "Width: %d Height: %d\n", font_width, font_height); | |
174 | |
175 dw_color_background_set( DW_CLR_WHITE ); | |
176 for ( i = 0;i < 100; i++) | |
177 { | |
178 y = i*font_height; | |
179 | |
180 dw_color_foreground_set( DW_CLR_BLACK ); | |
181 sprintf( buf, "%6.6d", i ); | |
182 dw_draw_text( NULL, text1pm, 0, y, buf); | |
183 dw_draw_text( NULL, text2pm, 0, y, buf); | |
184 } | |
185 dw_signal_connect(textbox1, "expose_event", DW_SIGNAL_FUNC(text_expose), text1pm); | |
186 dw_signal_connect(textbox2, "expose_event", DW_SIGNAL_FUNC(text_expose), text2pm); | |
187 dw_flush(); | |
188 } | |
189 | |
190 /* | |
191 * Let's demonstrate the functionality of this library. :) | |
192 */ | |
193 int main(int argc, char *argv[]) | |
194 { | |
195 ULONG notebookpage1; | |
196 ULONG notebookpage2; | |
197 | |
198 dw_init(TRUE, argc, argv); | |
199 | |
200 mainwindow = dw_window_new( HWND_DESKTOP, "dwindows test", flStyle | DW_FCF_SIZEBORDER | DW_FCF_MINMAX ); | |
201 | |
202 notebookbox = dw_box_new( BOXVERT, 5 ); | |
203 dw_box_pack_start( mainwindow, notebookbox, 1, 1, TRUE, TRUE, 0); | |
204 | |
205 notebook = dw_notebook_new( 1, TRUE ); | |
206 dw_box_pack_start( notebookbox, notebook, 100, 100, TRUE, TRUE, 0); | |
207 dw_window_set_font( notebook, "8.WarpSans"); | |
208 | |
209 notebookbox1 = dw_box_new( BOXVERT, 5 ); | |
210 notebookpage1 = dw_notebook_page_new( notebook, 0, TRUE ); | |
211 dw_notebook_pack( notebook, notebookpage1, notebookbox1 ); | |
212 fprintf( stderr, "page1: %d\n", notebookpage1 ); | |
213 dw_notebook_page_set_text( notebook, notebookpage1, "first page"); | |
214 archive_add(); | |
215 | |
216 notebookbox2 = dw_box_new( BOXVERT, 5 ); | |
217 notebookpage2 = dw_notebook_page_new( notebook, 1, FALSE ); | |
218 dw_notebook_pack( notebook, notebookpage2, notebookbox2 ); | |
219 fprintf( stderr, "page2: %d\n",notebookpage2); | |
220 dw_notebook_page_set_text( notebook, notebookpage2, "second page"); | |
221 text_add(); | |
222 | |
223 dw_signal_connect(mainwindow, "delete_event", DW_SIGNAL_FUNC(exit_callback), (void *)mainwindow); | |
224 dw_window_set_usize(mainwindow, 640, 480); | |
225 dw_window_show(mainwindow); | |
226 | |
227 dw_main(); | |
228 | |
229 return 0; | |
230 } |