browse_tree.cc 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. /********************************************************************** <BR>
  2. This file is part of Crack dot Com's free source code release of
  3. Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
  4. information about compiling & licensing issues visit this URL</a>
  5. <PRE> If that doesn't help, contact Jonathan Clark at
  6. golgotha_source@usa.net (Subject should have "GOLG" in it)
  7. ***********************************************************************/
  8. #ifdef _MANGLE_INC
  9. #include "gui/BROWS~B4.HH"
  10. #else
  11. #include "gui/browse_tree.hh"
  12. #endif
  13. #include "window/style.hh"
  14. #include "window/colorwin.hh"
  15. #include "window/win_evt.hh"
  16. void i4_vertical_compact_window_class::compact()
  17. {
  18. sw32 my=0,largest_width=0;
  19. i4_parent_window_class::win_iter w;
  20. for (w=children.begin();
  21. w!=children.end(); ++w)
  22. if (w->width()>largest_width)
  23. largest_width=w->width();
  24. for (w=children.begin();
  25. w!=children.end(); ++w)
  26. {
  27. if (center)
  28. w->private_move(x() + largest_width/2-(sw32)w->width()/2 - w->x(), y() + my - w->y());
  29. else
  30. w->private_move(0, y() + my - w->y());
  31. my+=w->height();
  32. }
  33. if (width()!=largest_width || my!=height())
  34. resize(largest_width, my);
  35. }
  36. void i4_horizontal_compact_window_class::compact()
  37. {
  38. sw32 mx=0,largest_height=0;
  39. i4_parent_window_class::win_iter w;
  40. for (w=children.begin();
  41. w!=children.end(); ++w)
  42. if (w->height()>largest_height)
  43. largest_height=w->height();
  44. for (w=children.begin();
  45. w!=children.end(); ++w)
  46. {
  47. if (center)
  48. w->private_move(x() + mx - w->x(), y() + largest_height/2-(sw32)w->height()/2 - w->y());
  49. else
  50. w->private_move(x() + mx - w->x(), 0);
  51. mx+=w->width();
  52. }
  53. if (mx!=width() || largest_height!=height())
  54. resize(mx, largest_height);
  55. }
  56. void i4_vertical_compact_window_class::receive_event(i4_event *ev)
  57. {
  58. if (ev->type()==i4_event::WINDOW_MESSAGE)
  59. {
  60. CAST_PTR(mess,i4_window_message_class,ev);
  61. if (mess->sub_type==i4_window_message_class::NOTIFY_RESIZE)
  62. {
  63. CAST_PTR(res,i4_window_notify_resize_class,ev);
  64. sw32 ow=res->from()->width(), oh=res->from()->height();
  65. res->from()->private_resize(res->new_width, res->new_height);
  66. compact();
  67. res->from()->private_resize(ow, oh);
  68. note_undrawn(0,0, width()-1, height()-1);
  69. } else i4_parent_window_class::receive_event(ev);
  70. } else i4_parent_window_class::receive_event(ev);
  71. }
  72. void i4_vertical_compact_window_class::parent_draw(i4_draw_context_class &context)
  73. {
  74. i4_rect_list_class child_clip(&context.clip,0,0);
  75. child_clip.intersect_list(&undrawn_area);
  76. child_clip.swap(&context.clip);
  77. local_image->clear(color,context);
  78. child_clip.swap(&context.clip);
  79. }
  80. void i4_horizontal_compact_window_class::receive_event(i4_event *ev)
  81. {
  82. if (ev->type()==i4_event::WINDOW_MESSAGE)
  83. {
  84. CAST_PTR(mess,i4_window_message_class,ev);
  85. if (mess->sub_type==i4_window_message_class::NOTIFY_RESIZE)
  86. {
  87. CAST_PTR(res,i4_window_notify_resize_class,ev);
  88. sw32 ow=res->from()->width(), oh=res->from()->height();
  89. res->from()->private_resize(res->new_width, res->new_height);
  90. compact();
  91. res->from()->private_resize(ow, oh);
  92. note_undrawn(0,0, width()-1, height()-1);
  93. } else i4_parent_window_class::receive_event(ev);
  94. } else i4_parent_window_class::receive_event(ev);
  95. }
  96. void i4_horizontal_compact_window_class::parent_draw(i4_draw_context_class &context)
  97. {
  98. i4_rect_list_class child_clip(&context.clip,0,0);
  99. child_clip.intersect_list(&undrawn_area);
  100. child_clip.swap(&context.clip);
  101. local_image->clear(color,context);
  102. child_clip.swap(&context.clip);
  103. }
  104. class i4_browse_toggle_class : public i4_window_class
  105. {
  106. public:
  107. char *name() { return "browse_toggle"; }
  108. enum { EXPANDED, COMPACTED, NO_CHILDREN } state;
  109. i4_browse_window_class *browse_parent;
  110. i4_graphical_style_class *style;
  111. i4_browse_toggle_class(i4_graphical_style_class *style,
  112. i4_browse_window_class *browse_parent,
  113. i4_bool show_plus_minus,
  114. i4_bool expanded,
  115. i4_bool has_a_child)
  116. : i4_window_class(style->icon_hint->plus_icon->width()+4,
  117. style->icon_hint->plus_icon->height()),
  118. browse_parent(browse_parent),
  119. style(style)
  120. {
  121. if (show_plus_minus)
  122. {
  123. if (expanded)
  124. state=EXPANDED;
  125. else
  126. state=COMPACTED;
  127. }
  128. else
  129. state=NO_CHILDREN;
  130. }
  131. virtual void draw(i4_draw_context_class &context)
  132. {
  133. local_image->clear(style->color_hint->window.passive.medium, context);
  134. if (state!=NO_CHILDREN)
  135. {
  136. if (state==EXPANDED)
  137. style->icon_hint->plus_icon->put_image_trans(local_image, 0,0, 0, context);
  138. else
  139. style->icon_hint->minus_icon->put_image_trans(local_image, 0,0, 0, context);
  140. }
  141. }
  142. virtual void receive_event(i4_event *ev)
  143. {
  144. if (ev->type()==i4_event::MOUSE_BUTTON_DOWN && state!=NO_CHILDREN)
  145. {
  146. if (state==EXPANDED)
  147. {
  148. state=COMPACTED;
  149. browse_parent->compress();
  150. }
  151. else
  152. {
  153. state=EXPANDED;
  154. browse_parent->expand();
  155. }
  156. request_redraw();
  157. }
  158. }
  159. } ;
  160. void i4_browse_window_class::add_arranged_child(i4_window_class *child)
  161. {
  162. title_area->add_child(0,0,child);
  163. ((i4_horizontal_compact_window_class *)title_area)->compact();
  164. private_resize(0,0);
  165. arrange_right_down();
  166. if (child_object)
  167. child_object->move(x_start(), 0);
  168. resize_to_fit_children();
  169. }
  170. void i4_browse_window_class::compress()
  171. {
  172. if (child_object && expanded)
  173. {
  174. expanded=i4_F;
  175. i4_parent_window_class::remove_child(child_object);
  176. resize_to_fit_children();
  177. }
  178. }
  179. void i4_browse_window_class::expand()
  180. {
  181. if (child_object && !expanded)
  182. {
  183. expanded=i4_T;
  184. i4_parent_window_class::add_child(0,0,child_object);
  185. private_resize(0,0);
  186. arrange_right_down();
  187. if (child_object)
  188. child_object->move(x_start(), 0);
  189. resize_to_fit_children();
  190. }
  191. }
  192. void i4_browse_window_class::replace_object(i4_window_class *object)
  193. {
  194. if (child_object)
  195. {
  196. if (expanded)
  197. remove_child(child_object);
  198. delete child_object;
  199. child_object=0;
  200. /*
  201. if (((i4_browse_toggle_class *)toggle_button)->state == i4_browse_toggle_class::EXPANDED)
  202. ((i4_browse_toggle_class *)toggle_button)->state=i4_browse_toggle_class::COMPACTED;
  203. else if (((i4_browse_toggle_class *)toggle_button)->state == i4_browse_toggle_class::COMPACTED)
  204. ((i4_browse_toggle_class *)toggle_button)->state=i4_browse_toggle_class::EXPANDED;
  205. */
  206. toggle_button->request_redraw();
  207. private_resize(0,0);
  208. resize_to_fit_children();
  209. }
  210. if (object)
  211. {
  212. child_object=object;
  213. if (expanded)
  214. i4_parent_window_class::add_child(0,0,object);
  215. private_resize(0,0);
  216. arrange_right_down();
  217. object->move(x_start(), 0);
  218. resize_to_fit_children();
  219. }
  220. }
  221. class i4_browse_title_container_class : public i4_parent_window_class
  222. {
  223. public:
  224. i4_browse_title_container_class() : i4_parent_window_class(0,0) {}
  225. char *name() { return "browse title container"; }
  226. };
  227. i4_browse_window_class::i4_browse_window_class(i4_graphical_style_class *style,
  228. i4_window_class *title_object,
  229. i4_window_class *child_obj,
  230. i4_bool show_plus_minus,
  231. i4_bool expanded)
  232. : style(style),
  233. expanded(expanded),
  234. i4_parent_window_class(0,0)
  235. {
  236. toggle_button=0;
  237. child_object=0;
  238. title_area=new i4_horizontal_compact_window_class(style->color_hint->window.passive.medium,
  239. i4_T);
  240. ((i4_horizontal_compact_window_class *)title_area)->compact();
  241. i4_parent_window_class::add_child(0,0,title_area);
  242. toggle_button=new i4_browse_toggle_class(style, this,
  243. show_plus_minus,
  244. expanded,
  245. (i4_bool)(child_obj!=0));
  246. title_area->add_child(0,0,toggle_button);
  247. if (title_object)
  248. add_arranged_child(title_object);
  249. if (child_obj)
  250. replace_object(child_obj);
  251. }
  252. sw32 i4_browse_window_class::x_start()
  253. {
  254. return style->icon_hint->plus_icon->width() + 10;
  255. }
  256. void i4_browse_window_class::receive_event(i4_event *ev)
  257. {
  258. if (ev->type()==i4_event::WINDOW_MESSAGE)
  259. {
  260. CAST_PTR(mess,i4_window_message_class,ev);
  261. if (mess->sub_type==i4_window_message_class::NOTIFY_RESIZE)
  262. {
  263. CAST_PTR(resize,i4_window_notify_resize_class,ev);
  264. note_undrawn(0,0, width()-1, height()-1);
  265. w16 ow=resize->from()->width(),
  266. oh=resize->from()->height();
  267. resize->from()->private_resize(resize->new_width,resize->new_height);
  268. private_resize(0,0);
  269. arrange_right_down();
  270. if (child_object)
  271. child_object->move(x_start(), 0);
  272. resize_to_fit_children();
  273. note_undrawn(0,0, width()-1, height()-1);
  274. resize->from()->private_resize(ow, oh);
  275. }
  276. else
  277. i4_parent_window_class::receive_event(ev);
  278. }
  279. else i4_parent_window_class::receive_event(ev);
  280. }
  281. void i4_browse_window_class::parent_draw(i4_draw_context_class &context)
  282. {
  283. i4_rect_list_class child_clip(&context.clip,0,0);
  284. child_clip.intersect_list(&undrawn_area);
  285. child_clip.swap(&context.clip);
  286. local_image->clear(style->color_hint->window.passive.medium,context);
  287. child_clip.swap(&context.clip);
  288. }