@@ -80,6 +80,7 @@ AppWindow::AppWindow():
8080 , txt_str_bot(" " )
8181 , txt_str_opr(" " )
8282 , txt_str_res(" " )
83+ , crnt_mode{CALC_MODE::ARG_A}
8384{
8485 set_title (" Simple Calculator" );
8586
@@ -100,11 +101,11 @@ AppWindow::AppWindow():
100101 btn_num_e_obj.signal_clicked ().connect (sigc::mem_fun (*this , &AppWindow::handle_btn_e), false );
101102 btn_num_f_obj.signal_clicked ().connect (sigc::mem_fun (*this , &AppWindow::handle_btn_f), false );
102103
103- // btn_op_add_obj.signal_clicked().connect(sigc::mem_fun(*this, &AppWindow::handle_op_add));
104- // btn_op_sub_obj.signal_clicked().connect(sigc::mem_fun(*this, &AppWindow::handle_op_sub));
105- // btn_op_mul_obj.signal_clicked().connect(sigc::mem_fun(*this, &AppWindow::handle_op_mul));
106- // btn_op_div_obj.signal_clicked().connect(sigc::mem_fun(*this, &AppWindow::handle_op_div));
107- // btn_op_mod_obj.signal_clicked().connect(sigc::mem_fun(*this, &AppWindow::handle_op_mod));
104+ btn_op_add_obj.signal_clicked ().connect (sigc::mem_fun (*this , &AppWindow::handle_op_add), false );
105+ btn_op_sub_obj.signal_clicked ().connect (sigc::mem_fun (*this , &AppWindow::handle_op_sub), false );
106+ btn_op_mul_obj.signal_clicked ().connect (sigc::mem_fun (*this , &AppWindow::handle_op_mul), false );
107+ btn_op_div_obj.signal_clicked ().connect (sigc::mem_fun (*this , &AppWindow::handle_op_div), false );
108+ btn_op_mod_obj.signal_clicked ().connect (sigc::mem_fun (*this , &AppWindow::handle_op_mod), false );
108109
109110 radix_slider_obj.set_digits (0 );
110111 radix_slider_obj.set_has_origin (true );
@@ -144,7 +145,7 @@ AppWindow::AppWindow():
144145 layout_buttons.attach (btn_alt_dot_obj, 1 , 4 , 1 , 1 );
145146 layout_buttons.attach (btn_alt_inv_obj, 4 , 4 , 1 , 1 );
146147
147- display_area.set_size_request (360 , 120 );
148+ display_area.set_size_request (25 , 120 );
148149 display_area.signal_draw ().connect (sigc::mem_fun (*this , &AppWindow::handle_display_update), false );
149150
150151 layout_display.pack_start (display_area);
@@ -288,23 +289,53 @@ bool AppWindow::handle_radix_change(
288289/* *
289290 * @brief { item_description }
290291 */
291- void AppWindow::handle_btn_0 ( )
292+ void AppWindow::write_digit ( char const * digit_str )
292293{
293- txt_str_top.append (" 0" );
294+ switch (crnt_mode)
295+ {
296+ case (CALC_MODE::ARG_A):
297+ {
298+ txt_str_top.append (digit_str);
299+ }
300+ break ;
301+
302+ case (CALC_MODE::ARG_B):
303+ {
304+ txt_str_bot.append (digit_str);
305+ }
306+ break ;
307+
308+ case (CALC_MODE::SOLVE):
309+ {}
310+ break ;
311+
312+ default :
313+ {}
314+ break ;
315+ }
294316
295317 display_area.queue_draw ();
296318
297319 return ;
298320}
299321
322+
300323/* *
301324 * @brief { item_description }
302325 */
303- void AppWindow::handle_btn_1 ()
326+ void AppWindow::handle_btn_0 ()
304327{
305- txt_str_top. append ( " 1 " );
328+ write_digit ( " 0 " );
306329
307- display_area.queue_draw ();
330+ return ;
331+ }
332+
333+ /* *
334+ * @brief { item_description }
335+ */
336+ void AppWindow::handle_btn_1 ()
337+ {
338+ write_digit (" 1" );
308339
309340 return ;
310341}
@@ -314,9 +345,7 @@ void AppWindow::handle_btn_1()
314345 */
315346void AppWindow::handle_btn_2 ()
316347{
317- txt_str_top.append (" 2" );
318-
319- display_area.queue_draw ();
348+ write_digit (" 2" );
320349
321350 return ;
322351}
@@ -326,9 +355,7 @@ void AppWindow::handle_btn_2()
326355 */
327356void AppWindow::handle_btn_3 ()
328357{
329- txt_str_top.append (" 3" );
330-
331- display_area.queue_draw ();
358+ write_digit (" 3" );
332359
333360 return ;
334361}
@@ -338,9 +365,7 @@ void AppWindow::handle_btn_3()
338365 */
339366void AppWindow::handle_btn_4 ()
340367{
341- txt_str_top.append (" 4" );
342-
343- display_area.queue_draw ();
368+ write_digit (" 4" );
344369
345370 return ;
346371}
@@ -350,9 +375,7 @@ void AppWindow::handle_btn_4()
350375 */
351376void AppWindow::handle_btn_5 ()
352377{
353- txt_str_top.append (" 5" );
354-
355- display_area.queue_draw ();
378+ write_digit (" 5" );
356379
357380 return ;
358381}
@@ -362,9 +385,7 @@ void AppWindow::handle_btn_5()
362385 */
363386void AppWindow::handle_btn_6 ()
364387{
365- txt_str_top.append (" 6" );
366-
367- display_area.queue_draw ();
388+ write_digit (" 6" );
368389
369390 return ;
370391}
@@ -374,9 +395,7 @@ void AppWindow::handle_btn_6()
374395 */
375396void AppWindow::handle_btn_7 ()
376397{
377- txt_str_top.append (" 7" );
378-
379- display_area.queue_draw ();
398+ write_digit (" 7" );
380399
381400 return ;
382401}
@@ -386,9 +405,7 @@ void AppWindow::handle_btn_7()
386405 */
387406void AppWindow::handle_btn_8 ()
388407{
389- txt_str_top.append (" 8" );
390-
391- display_area.queue_draw ();
408+ write_digit (" 8" );
392409
393410 return ;
394411}
@@ -398,9 +415,7 @@ void AppWindow::handle_btn_8()
398415 */
399416void AppWindow::handle_btn_9 ()
400417{
401- txt_str_top.append (" 9" );
402-
403- display_area.queue_draw ();
418+ write_digit (" 9" );
404419
405420 return ;
406421}
@@ -410,9 +425,7 @@ void AppWindow::handle_btn_9()
410425 */
411426void AppWindow::handle_btn_a ()
412427{
413- txt_str_top.append (" A" );
414-
415- display_area.queue_draw ();
428+ write_digit (" A" );
416429
417430 return ;
418431}
@@ -422,55 +435,164 @@ void AppWindow::handle_btn_a()
422435 */
423436void AppWindow::handle_btn_b ()
424437{
425- txt_str_top.append (" B" );
438+ write_digit (" B" );
439+
440+ return ;
441+ }
442+
443+ /* *
444+ * @brief { item_description }
445+ */
446+ void AppWindow::handle_btn_c ()
447+ {
448+ write_digit (" C" );
449+
450+ return ;
451+ }
452+
453+ /* *
454+ * @brief { item_description }
455+ */
456+ void AppWindow::handle_btn_d ()
457+ {
458+ write_digit (" D" );
459+
460+ return ;
461+ }
462+
463+ /* *
464+ * @brief { item_description }
465+ */
466+ void AppWindow::handle_btn_e ()
467+ {
468+ write_digit (" E" );
469+
470+ return ;
471+ }
472+
473+ /* *
474+ * @brief { item_description }
475+ */
476+ void AppWindow::handle_btn_f ()
477+ {
478+ write_digit (" F" );
479+
480+ return ;
481+ }
482+
483+
484+ /* *
485+ * @brief { item_description }
486+ */
487+ void AppWindow::determine_mode (char const *) // UNUSED ARGUMENT
488+ {
489+ switch (crnt_mode)
490+ {
491+ case (CALC_MODE::ARG_A):
492+ {
493+ crnt_mode = CALC_MODE::ARG_B;
494+ }
495+ break ;
496+
497+ case (CALC_MODE::ARG_B):
498+ {
499+ crnt_mode = CALC_MODE::SOLVE;
500+ }
501+ break ;
502+
503+ case (CALC_MODE::SOLVE):
504+ {
505+ crnt_mode = CALC_MODE::SOLVE;
506+ }
507+ break ;
508+
509+ default :
510+ {}
511+ break ;
512+ }
513+
514+ return ;
515+ }
516+
517+
518+ /* *
519+ * @brief { item_description }
520+ */
521+ void AppWindow::handle_op_add ()
522+ {
523+ char const * add_op = " +\0 " ;
524+
525+ txt_str_opr = (add_op);
526+
527+ determine_mode (add_op);
426528
427529 display_area.queue_draw ();
428530
429531 return ;
430532}
431533
534+
432535/* *
433536 * @brief { item_description }
434537 */
435- void AppWindow::handle_btn_c ()
538+ void AppWindow::handle_op_sub ()
436539{
437- txt_str_top.append (" C" );
540+ char const * sub_op = " -\0 " ;
541+
542+ txt_str_opr = (sub_op);
543+
544+ determine_mode (sub_op);
438545
439546 display_area.queue_draw ();
440547
441548 return ;
442549}
443550
551+
444552/* *
445553 * @brief { item_description }
446554 */
447- void AppWindow::handle_btn_d ()
555+ void AppWindow::handle_op_mul ()
448556{
449- txt_str_top.append (" D" );
557+ char const * mul_op = " x\0 " ;
558+
559+ txt_str_opr = (mul_op);
560+
561+ determine_mode (mul_op);
450562
451563 display_area.queue_draw ();
452564
453565 return ;
454566}
455567
568+
456569/* *
457570 * @brief { item_description }
458571 */
459- void AppWindow::handle_btn_e ()
572+ void AppWindow::handle_op_div ()
460573{
461- txt_str_top.append (" E" );
574+ char const * div_op = " /\0 " ;
575+
576+ txt_str_opr = (div_op);
577+
578+ determine_mode (div_op);
462579
463580 display_area.queue_draw ();
464581
465582 return ;
466583}
467584
585+
468586/* *
469587 * @brief { item_description }
470588 */
471- void AppWindow::handle_btn_f ()
589+ void AppWindow::handle_op_mod ()
472590{
473- txt_str_top.append (" F" );
591+ char const * mod_op = " %\0 " ;
592+
593+ txt_str_opr = (mod_op);
594+
595+ determine_mode (mod_op);
474596
475597 display_area.queue_draw ();
476598
0 commit comments